ARDExternalSampleCapturer.m (2071B)
1 /* 2 * Copyright 2018 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #import "ARDExternalSampleCapturer.h" 12 13 #import "sdk/objc/api/video_frame_buffer/RTCNativeI420Buffer.h" 14 #import "sdk/objc/api/video_frame_buffer/RTCNativeMutableI420Buffer.h" 15 #import "sdk/objc/base/RTCI420Buffer.h" 16 #import "sdk/objc/base/RTCMutableI420Buffer.h" 17 #import "sdk/objc/base/RTCMutableYUVPlanarBuffer.h" 18 #import "sdk/objc/base/RTCVideoFrameBuffer.h" 19 #import "sdk/objc/base/RTCYUVPlanarBuffer.h" 20 #import "sdk/objc/components/video_frame_buffer/RTCCVPixelBuffer.h" 21 22 @implementation ARDExternalSampleCapturer 23 24 - (instancetype)initWithDelegate: 25 (__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate { 26 return [super initWithDelegate:delegate]; 27 } 28 29 #pragma mark - ARDExternalSampleDelegate 30 31 - (void)didCaptureSampleBuffer:(CMSampleBufferRef)sampleBuffer { 32 if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || 33 !CMSampleBufferIsValid(sampleBuffer) || 34 !CMSampleBufferDataIsReady(sampleBuffer)) { 35 return; 36 } 37 38 CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 39 if (pixelBuffer == nil) { 40 return; 41 } 42 43 RTC_OBJC_TYPE(RTCCVPixelBuffer) *rtcPixelBuffer = 44 [[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:pixelBuffer]; 45 int64_t timeStampNs = 46 CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * 47 NSEC_PER_SEC; 48 RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame = 49 [[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:rtcPixelBuffer 50 rotation:RTCVideoRotation_0 51 timeStampNs:timeStampNs]; 52 [self.delegate capturer:self didCaptureVideoFrame:videoFrame]; 53 } 54 55 @end