Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jesup,jib
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Wed, 26 Oct 2016 18:08:18 +0800
changeset 319724 0680e3176fa56b00a75d187b9b338546371486a8
parent 319723 1509b970b24f6b97a26c3a5b9afa89d0fad6a5cd
child 319725 0b1ae9f4f07bd823d91fadc1b2eac168e37363ca
push id20748
push userphilringnalda@gmail.com
push dateFri, 28 Oct 2016 03:39:55 +0000
treeherderfx-team@715360440695 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, jib
bugs1308412
milestone52.0a1
Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jesup,jib 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