Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jesup,jib a=lizzard
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Wed, 26 Oct 2016 18:08:18 +0800
changeset 359274 62cd1c0a577044ee52ee8f90d8c6e6289c7240c8
parent 359273 f06afa54549bff3f2f03a8510334046c1050465a
child 359275 ed5b9c0678b09a183f947d71a12a4a9bb20a45fb
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, jib, lizzard
bugs1308412
milestone51.0
Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jesup,jib a=lizzard MozReview-Commit-ID: BERDnKJ0i3t
media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_objc.mm
--- a/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_objc.mm
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_objc.mm
@@ -233,50 +233,54 @@ using namespace videocapturemodule;
          fromConnection:(AVCaptureConnection *)connection {
 
   [_lock lock];
   if (!_owner) {
     [_lock unlock];
     return;
   }
 
+  CMFormatDescriptionRef formatDescription =
+      CMSampleBufferGetFormatDescription(sampleBuffer);
+  webrtc::RawVideoType rawType =
+      [VideoCaptureMacAVFoundationUtility fourCCToRawVideoType:CMFormatDescriptionGetMediaSubType(formatDescription)];
+  CMVideoDimensions dimensions =
+      CMVideoFormatDescriptionGetDimensions(formatDescription);
+
   VideoCaptureCapability tempCaptureCapability;
-  tempCaptureCapability.width = _frameWidth;
-  tempCaptureCapability.height = _frameHeight;
+  tempCaptureCapability.width = dimensions.width;
+  tempCaptureCapability.height = dimensions.height;
   tempCaptureCapability.maxFPS = _frameRate;
-  tempCaptureCapability.rawType = _rawType;
-
-  if (webrtc::kVideoMJPEG == _rawType) {
-    CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
+  tempCaptureCapability.rawType = rawType;
 
-    if (blockBuffer) {
-      char* baseAddress;
-      size_t frameSize;
-      size_t lengthAtOffset;
-      CMBlockBufferGetDataPointer(blockBuffer, 0, &lengthAtOffset, &frameSize, &baseAddress);
+  CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
 
-      NSAssert(lengthAtOffset == frameSize, @"lengthAtOffset != frameSize)");
+  if (blockBuffer) {
+    char* baseAddress;
+    size_t frameSize;
+    size_t lengthAtOffset;
+    CMBlockBufferGetDataPointer(blockBuffer, 0, &lengthAtOffset, &frameSize, &baseAddress);
 
-      _owner->IncomingFrame((unsigned char*)baseAddress, frameSize,
+    NSAssert(lengthAtOffset == frameSize, @"lengthAtOffset != frameSize)");
+
+    _owner->IncomingFrame((unsigned char*)baseAddress, frameSize,
                             tempCaptureCapability, 0);
-    }
   } else {
     // Get a CMSampleBuffer's Core Video image buffer for the media data
     CVImageBufferRef videoFrame = CMSampleBufferGetImageBuffer(sampleBuffer);
 
-    const int kFlags = 0;
-    if (CVPixelBufferLockBaseAddress(videoFrame, kFlags) == kCVReturnSuccess) {
+    if (CVPixelBufferLockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly) == kCVReturnSuccess) {
       void* baseAddress = CVPixelBufferGetBaseAddress(videoFrame);
       size_t bytesPerRow = CVPixelBufferGetBytesPerRow(videoFrame);
       size_t frameHeight = CVPixelBufferGetHeight(videoFrame);
       size_t frameSize = bytesPerRow * frameHeight;
 
       _owner->IncomingFrame((unsigned char*)baseAddress, frameSize,
                             tempCaptureCapability, 0);
-      CVPixelBufferUnlockBaseAddress(videoFrame, kFlags);
+      CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly);
     }
   }
   [_lock unlock];
   _framesDelivered++;
   _framesRendered++;
 }
 
 @end