[vlc-commits] vdpau/instance: return the created instance directly
Steve Lhomme
git at videolan.org
Wed Nov 27 12:47:02 CET 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Nov 27 11:30:16 2019 +0100| [5dcdbd73e545938fda75251ce3ef0561e95f5519] | committer: Steve Lhomme
vdpau/instance: return the created instance directly
And only finish initializing the structure if it was created successfully.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5dcdbd73e545938fda75251ce3ef0561e95f5519
---
modules/hw/vdpau/instance.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/modules/hw/vdpau/instance.c b/modules/hw/vdpau/instance.c
index c55bbcb787..4a6d27fe5f 100644
--- a/modules/hw/vdpau/instance.c
+++ b/modules/hw/vdpau/instance.c
@@ -45,29 +45,25 @@ typedef struct vdp_instance
char name[]; /**< X11 display name */
} vdp_instance_t;
-static VdpStatus vdp_instance_create(const char *name, int num,
- vdp_instance_t **pp)
+static vdp_instance_t *vdp_instance_create(const char *name, int num)
{
size_t namelen = strlen(name) + 1;
vdp_instance_t *vi = malloc(sizeof (*vi) + namelen);
if (unlikely(vi == NULL))
- return VDP_STATUS_RESOURCES;
+ return NULL;
vi->display = XOpenDisplay(name);
if (vi->display == NULL)
{
free(vi);
- return VDP_STATUS_ERROR;
+ return NULL;
}
- vi->next = NULL;
- memcpy(vi->name, name, namelen);
if (num >= 0)
vi->num = num;
else
vi->num = XDefaultScreen(vi->display);
- vi->refs = 1;
VdpStatus err = vdp_create_x11(vi->display, vi->num,
&vi->vdp, &vi->device);
@@ -75,10 +71,14 @@ static VdpStatus vdp_instance_create(const char *name, int num,
{
XCloseDisplay(vi->display);
free(vi);
- return err;
+ return NULL;
}
- *pp = vi;
- return VDP_STATUS_OK;
+
+ vi->next = NULL;
+ memcpy(vi->name, name, namelen);
+ vi->refs = 1;
+
+ return vi;
}
static void vdp_instance_destroy(vdp_instance_t *vi)
@@ -130,7 +130,6 @@ VdpStatus vdp_get_x11(const char *display_name, int snum,
vdp_t **restrict vdpp, VdpDevice *restrict devicep)
{
vdp_instance_t *vi, *vi2;
- VdpStatus err = VDP_STATUS_RESOURCES;
if (display_name == NULL)
{
@@ -145,9 +144,9 @@ VdpStatus vdp_get_x11(const char *display_name, int snum,
if (vi != NULL)
goto found;
- err = vdp_instance_create(display_name, snum, &vi);
- if (err != VDP_STATUS_OK)
- return err;
+ vi = vdp_instance_create(display_name, snum);
+ if (vi == NULL)
+ return VDP_STATUS_ERROR;
pthread_mutex_lock(&lock);
vi2 = vdp_instance_lookup(display_name, snum);
More information about the vlc-commits
mailing list