[vlc-devel] [PATCH 17/48] vdpau: context structure for video surfaces

Rémi Denis-Courmont remi at remlab.net
Tue Jul 2 19:51:43 CEST 2013


---
 modules/hw/vdpau/picture.c   | 63 ++++++++++++++++++++++++++++++++++++++++++++
 modules/hw/vdpau/vlc_vdpau.h | 15 +++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 modules/hw/vdpau/picture.c

diff --git a/modules/hw/vdpau/picture.c b/modules/hw/vdpau/picture.c
new file mode 100644
index 0000000..bcd4fd2
--- /dev/null
+++ b/modules/hw/vdpau/picture.c
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * picture.c: VDPAU instance management for VLC
+ *****************************************************************************
+ * Copyright (C) 2013 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <vlc_common.h>
+#include <vlc_picture.h>
+#include "vlc_vdpau.h"
+
+#pragma GCC visibility push(default)
+
+static void SurfaceDestroy(void *opaque)
+{
+    vlc_vdp_video_t *ctx = opaque;
+    VdpStatus err;
+
+    err = vdp_video_surface_destroy(ctx->vdp, ctx->surface);
+    if (err != VDP_STATUS_OK)
+        fprintf(stderr, "video surface destruction failure: %s\n",
+                vdp_get_error_string(ctx->vdp, err));
+    vdp_release_x11(ctx->vdp);
+    free(ctx);
+}
+
+VdpStatus vlc_vdp_video_attach(vdp_t *vdp, VdpVideoSurface surface,
+                               picture_t *pic)
+{
+    vlc_vdp_video_t *ctx = malloc(sizeof (*ctx));
+    if (unlikely(ctx == NULL))
+    {
+        vdp_video_surface_destroy(vdp, surface);
+        return VDP_STATUS_RESOURCES;
+    }
+
+    ctx->destroy = SurfaceDestroy;
+    ctx->surface = surface;
+    ctx->vdp = vdp_hold_x11(vdp, &ctx->device);
+    assert(pic->context == NULL);
+    pic->context = ctx;
+    return VDP_STATUS_OK;
+}
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index 9645bfc..a10a241 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -244,4 +244,19 @@ struct picture_sys_t
     VdpDevice device;
     const vdp_t *vdp;
 };
+
+typedef struct vlc_vdp_video
+{
+    void (*destroy)(void *); /* must be first @ref picture_Release() */
+    VdpVideoSurface surface;
+    VdpDevice device;
+    vdp_t *vdp;
+} vlc_vdp_video_t;
+
+/**
+ * Attaches a VDPAU video surface as context of a VLC picture.
+ * @note In case of error, the surface is destroyed immediately. Otherwise,
+ * it will be destroyed at the same time as the picture it was attached to.
+ */
+VdpStatus vlc_vdp_video_attach(vdp_t *, VdpVideoSurface, picture_t *);
 #endif
-- 
1.8.3.2




More information about the vlc-devel mailing list