Bug 1308412 - retrieve CVImageBuffer from CMSampleBuffer if it doesn't contain any CMBlockBuffer; r=jib, jesup
MozReview-Commit-ID: BERDnKJ0i3t
--- 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