[vlc-commits] videotoolbox: switch to RO locking when copying pixel buffers and add sanity checks

Felix Paul Kühne git at videolan.org
Fri Sep 9 19:14:29 CEST 2016


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Sep  9 19:14:10 2016 +0200| [ec53b8968ed6226903c0f4f793ac4f4d41f7333a] | committer: Felix Paul Kühne

videotoolbox: switch to RO locking when copying pixel buffers and add sanity checks

This improves runtime efficiency

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

 modules/codec/videotoolbox.m     |  6 +++---
 modules/video_chroma/cvpx_i420.c | 13 +++++++++----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/codec/videotoolbox.m b/modules/codec/videotoolbox.m
index dcfac97..a3eeb77 100644
--- a/modules/codec/videotoolbox.m
+++ b/modules/codec/videotoolbox.m
@@ -961,10 +961,10 @@ static void copy420YpCbCr8Planar(picture_t *p_pic,
     uint8_t *pp_plane[2];
     size_t pi_pitch[2];
 
-    if (!buffer)
+    if (!buffer || i_width == 0 || i_height == 0)
         return;
 
-    CVPixelBufferLockBaseAddress(buffer, 0);
+    CVPixelBufferLockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
 
     for (int i = 0; i < 2; i++) {
         pp_plane[i] = CVPixelBufferGetBaseAddressOfPlane(buffer, i);
@@ -973,7 +973,7 @@ static void copy420YpCbCr8Planar(picture_t *p_pic,
 
     CopyFromNv12ToI420(p_pic, pp_plane, pi_pitch, i_height);
 
-    CVPixelBufferUnlockBaseAddress(buffer, 0);
+    CVPixelBufferUnlockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
 }
 
 #pragma mark - actual decoding
diff --git a/modules/video_chroma/cvpx_i420.c b/modules/video_chroma/cvpx_i420.c
index 81fffd8..22827a1 100644
--- a/modules/video_chroma/cvpx_i420.c
+++ b/modules/video_chroma/cvpx_i420.c
@@ -78,18 +78,23 @@ static void CVPX_I420(filter_t *p_filter, picture_t *sourcePicture, picture_t *d
     if (picsys->pixelBuffer == nil)
         return;
 
+    unsigned width = CVPixelBufferGetWidthOfPlane(picsys->pixelBuffer, 0);
+    unsigned height = CVPixelBufferGetHeightOfPlane(picsys->pixelBuffer, 0);
+
+    if (width == 0 || height == 0)
+        return;
+
     uint8_t *pp_plane[2];
     size_t pi_pitch[2];
 
-    CVPixelBufferLockBaseAddress(picsys->pixelBuffer, 0);
+    CVPixelBufferLockBaseAddress(picsys->pixelBuffer, kCVPixelBufferLock_ReadOnly);
 
     for (int i = 0; i < 2; i++) {
         pp_plane[i] = CVPixelBufferGetBaseAddressOfPlane(picsys->pixelBuffer, i);
         pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(picsys->pixelBuffer, i);
     }
 
-    CopyFromNv12ToI420(destinationPicture, pp_plane, pi_pitch,
-                       sourcePicture->format.i_height);
+    CopyFromNv12ToI420(destinationPicture, pp_plane, pi_pitch, height);
 
-    CVPixelBufferUnlockBaseAddress(picsys->pixelBuffer, 0);
+    CVPixelBufferUnlockBaseAddress(picsys->pixelBuffer, kCVPixelBufferLock_ReadOnly);
 }



More information about the vlc-commits mailing list