From b4654f537f2d0cf0ff2ccc068c446edbc5a3d3f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Mon, 8 Nov 2010 15:08:19 +0100 Subject: [PATCH] applemedia: lock CVPixelBuffer read-only As per Apple's docs, this may improve performance by avoiding redundant invalidations of existing caches of the buffer contents. --- sys/applemedia/coremediabuffer.c | 7 +++++-- sys/applemedia/corevideobuffer.c | 10 +++++++--- sys/applemedia/cvapi.h | 5 +++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sys/applemedia/coremediabuffer.c b/sys/applemedia/coremediabuffer.c index 44c101f..216f79e9 100644 --- a/sys/applemedia/coremediabuffer.c +++ b/sys/applemedia/coremediabuffer.c @@ -34,7 +34,8 @@ gst_core_media_buffer_finalize (GstMiniObject * mini_object) if (self->image_buf != NULL) { GstCVApi *cv = self->ctx->cv; - cv->CVPixelBufferUnlockBaseAddress (self->image_buf, 0); + cv->CVPixelBufferUnlockBaseAddress (self->image_buf, + kCVPixelBufferLock_ReadOnly); } self->ctx->cm->FigSampleBufferRelease (self->sample_buf); g_object_unref (self->ctx); @@ -64,8 +65,10 @@ gst_core_media_buffer_new (GstCoreMediaCtx * ctx, CMSampleBufferRef sample_buf) CFGetTypeID (image_buf) == cv->CVPixelBufferGetTypeID ()) { pixel_buf = (CVPixelBufferRef) image_buf; - if (cv->CVPixelBufferLockBaseAddress (pixel_buf, 0) != kCVReturnSuccess) + if (cv->CVPixelBufferLockBaseAddress (pixel_buf, + kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { goto error; + } if (cv->CVPixelBufferIsPlanar (pixel_buf)) { gint plane_count, plane_idx; diff --git a/sys/applemedia/corevideobuffer.c b/sys/applemedia/corevideobuffer.c index 7b90a70..b605e1d 100644 --- a/sys/applemedia/corevideobuffer.c +++ b/sys/applemedia/corevideobuffer.c @@ -33,8 +33,10 @@ gst_core_video_buffer_finalize (GstMiniObject * mini_object) GstCoreVideoBuffer *self = GST_CORE_VIDEO_BUFFER_CAST (mini_object); GstCVApi *cv = self->ctx->cv; - if (self->pixbuf != NULL) - cv->CVPixelBufferUnlockBaseAddress (self->pixbuf, 0); + if (self->pixbuf != NULL) { + cv->CVPixelBufferUnlockBaseAddress (self->pixbuf, + kCVPixelBufferLock_ReadOnly); + } cv->CVBufferRelease (self->cvbuf); @@ -56,8 +58,10 @@ gst_core_video_buffer_new (GstCoreMediaCtx * ctx, CVBufferRef cvbuf) if (CFGetTypeID (cvbuf) == cv->CVPixelBufferGetTypeID ()) { pixbuf = (CVPixelBufferRef) cvbuf; - if (cv->CVPixelBufferLockBaseAddress (pixbuf, 0) != kCVReturnSuccess) + if (cv->CVPixelBufferLockBaseAddress (pixbuf, + kCVPixelBufferLock_ReadOnly) != kCVReturnSuccess) { goto error; + } data = cv->CVPixelBufferGetBaseAddress (pixbuf); size = cv->CVPixelBufferGetBytesPerRow (pixbuf) * cv->CVPixelBufferGetHeight (pixbuf); diff --git a/sys/applemedia/cvapi.h b/sys/applemedia/cvapi.h index 3d99e38..444ded0 100644 --- a/sys/applemedia/cvapi.h +++ b/sys/applemedia/cvapi.h @@ -52,6 +52,11 @@ enum _CVPixelFormatType kCVPixelFormatType_422YpCbCr8 = '2vuy' }; +enum _CVPixelBufferLockFlags +{ + kCVPixelBufferLock_ReadOnly = 0x00000001 +}; + struct _GstCVApi { GstDynApi parent; -- 2.7.4