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.
This commit is contained in:
Ole André Vadla Ravnås 2010-11-08 15:08:19 +01:00
parent 6867ec5627
commit b4654f537f
3 changed files with 17 additions and 5 deletions

View 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;

View 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);

View file

@ -52,6 +52,11 @@ enum _CVPixelFormatType
kCVPixelFormatType_422YpCbCr8 = '2vuy'
};
enum _CVPixelBufferLockFlags
{
kCVPixelBufferLock_ReadOnly = 0x00000001
};
struct _GstCVApi
{
GstDynApi parent;