Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jib, jesup draft
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Wed, 26 Oct 2016 18:08:18 +0800
changeset 429666 73b577db58085413cb1be4b0ec4f852f4e0f7575
parent 429594 f9f3cc95d7282f1fd83f66dd74acbcdbfe821915
child 429667 e0ee8b23b2196fb01b491e8c184cee495bda45a0
child 430133 9e930bb832628972333da6a57267448b42cd6d41
push id33632
push usermchiang@mozilla.com
push dateWed, 26 Oct 2016 10:09:46 +0000
reviewersjib, jesup
bugs1308412
milestone52.0a1
Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jib, jesup 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