[vlc-commits] videotoolbox: store cvpx in picture context

Thomas Guillem git at videolan.org
Fri Jun 2 18:44:04 CEST 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu May 11 18:11:34 2017 +0200| [e88f20eed58c33a1e412d4f127c34b19e8e4d1a4] | committer: Thomas Guillem

videotoolbox: store cvpx in picture context

cvpx buffers don't need the vout to be allocated.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e88f20eed58c33a1e412d4f127c34b19e8e4d1a4
---

 modules/codec/videotoolbox.m                 | 19 +------
 modules/video_chroma/cvpx.c                  | 26 +++------
 modules/video_output/opengl/converter_cvpx.c | 82 ++--------------------------
 3 files changed, 17 insertions(+), 110 deletions(-)

diff --git a/modules/codec/videotoolbox.m b/modules/codec/videotoolbox.m
index e4b9499e5f..c1d6a64a8e 100644
--- a/modules/codec/videotoolbox.m
+++ b/modules/codec/videotoolbox.m
@@ -32,6 +32,7 @@
 #import "hxxx_helper.h"
 #import <vlc_bits.h>
 #import <vlc_boxes.h>
+#import "vt_utils.h"
 #import "../packetizer/h264_nal.h"
 #import "../packetizer/h264_slice.h"
 #import "../packetizer/hxxx_nal.h"
@@ -99,10 +100,6 @@ static void copy420YpCbCr8Planar(picture_t *, CVPixelBufferRef buffer,
 static BOOL deviceSupportsAdvancedProfiles();
 static BOOL deviceSupportsAdvancedLevels();
 
-struct picture_sys_t {
-    CFTypeRef pixelBuffer;
-};
-
 typedef struct frame_info_t frame_info_t;
 
 struct frame_info_t
@@ -1562,22 +1559,12 @@ static void DecoderCallback(void *decompressionOutputRefCon,
             return;
         }
 
-        if (unlikely(!p_pic->p_sys)) {
-            vlc_mutex_lock(&p_sys->lock);
-            p_dec->p_sys->b_abort = true;
-            vlc_mutex_unlock(&p_sys->lock);
-            picture_Release(p_pic);
+        if (cvpxpic_attach(p_pic, imageBuffer) != VLC_SUCCESS)
+        {
             free(p_info);
             return;
         }
 
-        /* Can happen if the pic was discarded */
-        if (p_pic->p_sys->pixelBuffer != nil)
-            CFRelease(p_pic->p_sys->pixelBuffer);
-
-        /* will be freed by the vout */
-        p_pic->p_sys->pixelBuffer = CVPixelBufferRetain(imageBuffer);
-
         p_info->p_picture = p_pic;
 
         p_pic->date = pts.value;
diff --git a/modules/video_chroma/cvpx.c b/modules/video_chroma/cvpx.c
index e0b19c6e87..246d60bb6c 100644
--- a/modules/video_chroma/cvpx.c
+++ b/modules/video_chroma/cvpx.c
@@ -21,7 +21,6 @@
  *****************************************************************************/
 
 #include <QuartzCore/QuartzCore.h>
-#include <VideoToolbox/VideoToolbox.h>
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -31,12 +30,9 @@
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
 #include <vlc_picture.h>
+#include "../codec/vt_utils.h"
 #include "copy.h"
 
-struct picture_sys_t {
-    CVPixelBufferRef pixelBuffer;
-};
-
 static int  Activate(vlc_object_t *);
 
 vlc_module_begin ()
@@ -48,16 +44,12 @@ vlc_module_end ()
 static void CVPX_I420(filter_t *p_filter, picture_t *src, picture_t *dst)
 {
     VLC_UNUSED(p_filter);
-    picture_sys_t *picsys = src->p_sys;
-
-    if (picsys == NULL)
-        return;
+    assert(src->context != NULL);
 
-    if (picsys->pixelBuffer == nil)
-        return;
+    CVPixelBufferRef pixelBuffer = cvpxpic_get_ref(src);
 
-    unsigned width = CVPixelBufferGetWidthOfPlane(picsys->pixelBuffer, 0);
-    unsigned height = CVPixelBufferGetHeightOfPlane(picsys->pixelBuffer, 0);
+    unsigned width = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0);
+    unsigned height = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0);
 
     if (width == 0 || height == 0)
         return;
@@ -65,11 +57,11 @@ static void CVPX_I420(filter_t *p_filter, picture_t *src, picture_t *dst)
     uint8_t *pp_plane[2];
     size_t pi_pitch[2];
 
-    CVPixelBufferLockBaseAddress(picsys->pixelBuffer, kCVPixelBufferLock_ReadOnly);
+    CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
 
     for (int i = 0; i < 2; i++) {
-        pp_plane[i] = CVPixelBufferGetBaseAddressOfPlane(picsys->pixelBuffer, i);
-        pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(picsys->pixelBuffer, i);
+        pp_plane[i] = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, i);
+        pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, i);
     }
 
     copy_cache_t cache;
@@ -81,7 +73,7 @@ static void CVPX_I420(filter_t *p_filter, picture_t *src, picture_t *dst)
 
     CopyCleanCache(&cache);
 
-    CVPixelBufferUnlockBaseAddress(picsys->pixelBuffer, kCVPixelBufferLock_ReadOnly);
+    CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
 }
 
 VIDEO_FILTER_WRAPPER(CVPX_I420)
diff --git a/modules/video_output/opengl/converter_cvpx.c b/modules/video_output/opengl/converter_cvpx.c
index bf070054e0..6486469eec 100644
--- a/modules/video_output/opengl/converter_cvpx.c
+++ b/modules/video_output/opengl/converter_cvpx.c
@@ -23,7 +23,7 @@
 #endif
 
 #include "internal.h"
-#include <VideoToolbox/VideoToolbox.h>
+#include "../../codec/vt_utils.h"
 
 #if TARGET_OS_IPHONE
 #include <OpenGLES/ES2/gl.h>
@@ -41,11 +41,6 @@ struct gl_sys
 };
 #endif
 
-struct picture_sys_t
-{
-    CVPixelBufferRef pixelBuffer;
-};
-
 struct priv
 {
     picture_t *last_pic;
@@ -54,58 +49,6 @@ struct priv
 #endif
 };
 
-static void
-pic_destroy_cb(picture_t *pic)
-{
-    if (pic->p_sys->pixelBuffer != NULL)
-        CFRelease(pic->p_sys->pixelBuffer);
-
-    free(pic->p_sys);
-    free(pic);
-}
-
-static picture_pool_t *
-tc_cvpx_get_pool(const opengl_tex_converter_t *tc, const video_format_t *fmt,
-                 unsigned requested_count)
-{
-    (void) tc;
-    picture_t *picture[VLCGL_PICTURE_MAX] = {NULL, };
-    unsigned count;
-
-    for (count = 0; count < requested_count; count++)
-    {
-        picture_sys_t *p_picsys = calloc(1, sizeof(*p_picsys));
-        if (unlikely(p_picsys == NULL))
-            goto error;
-        picture_resource_t rsc = {
-            .p_sys = p_picsys,
-            .pf_destroy = pic_destroy_cb,
-        };
-
-        picture[count] = picture_NewFromResource(fmt, &rsc);
-        if (!picture[count])
-        {
-            free(p_picsys);
-            goto error;
-        }
-    }
-
-    /* Wrap the pictures into a pool */
-    picture_pool_configuration_t pool_cfg = {
-        .picture_count = requested_count,
-        .picture       = picture,
-    };
-    picture_pool_t *pool = picture_pool_NewExtended(&pool_cfg);
-    if (!pool)
-        goto error;
-
-    return pool;
-error:
-    for (unsigned i = 0; i < count; i++)
-        picture_Release(picture[i]);
-    return NULL;
-}
-
 #if TARGET_OS_IPHONE
 /* CVOpenGLESTextureCache version (ios) */
 static int
@@ -115,9 +58,8 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures,
 {
     (void) plane_offset;
     struct priv *priv = tc->priv;
-    picture_sys_t *picsys = pic->p_sys;
 
-    assert(picsys->pixelBuffer != NULL);
+    CVPixelBufferRef pixelBuffer = cvpxpic_get_ref(pic);
 
     for (unsigned i = 0; i < tc->tex_count; ++i)
     {
@@ -126,7 +68,7 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures,
 
         CVOpenGLESTextureRef texture;
         CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(
-            kCFAllocatorDefault, priv->cache, picsys->pixelBuffer, NULL,
+            kCFAllocatorDefault, priv->cache, pixelBuffer, NULL,
             tc->tex_target, tc->texs[i].internal, tex_width[i], tex_height[i],
             tc->texs[i].format, tc->texs[i].type, i, &texture);
         if (err != noErr)
@@ -149,13 +91,7 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures,
     if (priv->last_pic != pic)
     {
         if (priv->last_pic != NULL)
-        {
-            picture_sys_t *picsys = priv->last_pic->p_sys;
-            assert(picsys->pixelBuffer != NULL);
-            CFRelease(picsys->pixelBuffer);
-            picsys->pixelBuffer = NULL;
             picture_Release(priv->last_pic);
-        }
         priv->last_pic = picture_Hold(pic);
     }
     return VLC_SUCCESS;
@@ -171,11 +107,10 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures,
     (void) plane_offset;
     struct priv *priv = tc->priv;
     struct gl_sys *glsys = tc->gl->sys;
-    picture_sys_t *picsys = pic->p_sys;
 
-    assert(picsys->pixelBuffer != NULL);
+    CVPixelBufferRef pixelBuffer = cvpxpic_get_ref(pic);
 
-    IOSurfaceRef surface = CVPixelBufferGetIOSurface(picsys->pixelBuffer);
+    IOSurfaceRef surface = CVPixelBufferGetIOSurface(pixelBuffer);
 
     for (unsigned i = 0; i < tc->tex_count; ++i)
     {
@@ -201,13 +136,7 @@ tc_cvpx_update(const opengl_tex_converter_t *tc, GLuint *textures,
     if (priv->last_pic != pic)
     {
         if (priv->last_pic != NULL)
-        {
-            picture_sys_t *picsys = priv->last_pic->p_sys;
-            assert(picsys->pixelBuffer != NULL);
-            CFRelease(picsys->pixelBuffer);
-            picsys->pixelBuffer = NULL;
             picture_Release(priv->last_pic);
-        }
         priv->last_pic = picture_Hold(pic);
     }
 
@@ -307,7 +236,6 @@ opengl_tex_converter_cvpx_init(video_format_t *fmt, opengl_tex_converter_t *tc)
     }
 
     tc->priv              = priv;
-    tc->pf_get_pool       = tc_cvpx_get_pool;
     tc->pf_update         = tc_cvpx_update;
     tc->pf_release        = tc_cvpx_release;
 



More information about the vlc-commits mailing list