applemedia: lock CVPixelBuffer read-only
authorOle André Vadla Ravnås <oravnas@cisco.com>
Mon, 8 Nov 2010 14:08:19 +0000 (15:08 +0100)
committerOle André Vadla Ravnås <oravnas@cisco.com>
Mon, 8 Nov 2010 22:58:24 +0000 (23:58 +0100)
As per Apple's docs, this may improve performance by avoiding redundant
invalidations of existing caches of the buffer contents.

sys/applemedia/coremediabuffer.c
sys/applemedia/corevideobuffer.c
sys/applemedia/cvapi.h

index 44c101f..216f79e 100644 (file)
@@ -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;
index 7b90a70..b605e1d 100644 (file)
@@ -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);
index 3d99e38..444ded0 100644 (file)
@@ -52,6 +52,11 @@ enum _CVPixelFormatType
   kCVPixelFormatType_422YpCbCr8                   = '2vuy'
 };
 
+enum _CVPixelBufferLockFlags
+{
+  kCVPixelBufferLock_ReadOnly = 0x00000001
+};
+
 struct _GstCVApi
 {
   GstDynApi parent;