Anders Carlsson | 358f2e0 | 2018-06-04 10:24:37 +0200 | [diff] [blame] | 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 | |
Mirko Bonadei | 19640aa | 2020-10-19 16:12:43 +0200 | [diff] [blame] | 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" |
Anders Carlsson | 358f2e0 | 2018-06-04 10:24:37 +0200 | [diff] [blame] | 21 | |
| 22 | @implementation ARDExternalSampleCapturer |
| 23 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 24 | - (instancetype)initWithDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate { |
Anders Carlsson | 358f2e0 | 2018-06-04 10:24:37 +0200 | [diff] [blame] | 25 | return [super initWithDelegate:delegate]; |
| 26 | } |
| 27 | |
| 28 | #pragma mark - ARDExternalSampleDelegate |
| 29 | |
| 30 | - (void)didCaptureSampleBuffer:(CMSampleBufferRef)sampleBuffer { |
| 31 | if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || !CMSampleBufferIsValid(sampleBuffer) || |
| 32 | !CMSampleBufferDataIsReady(sampleBuffer)) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); |
| 37 | if (pixelBuffer == nil) { |
| 38 | return; |
| 39 | } |
| 40 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 41 | RTC_OBJC_TYPE(RTCCVPixelBuffer) *rtcPixelBuffer = |
| 42 | [[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:pixelBuffer]; |
Anders Carlsson | 358f2e0 | 2018-06-04 10:24:37 +0200 | [diff] [blame] | 43 | int64_t timeStampNs = |
| 44 | CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * NSEC_PER_SEC; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 45 | RTC_OBJC_TYPE(RTCVideoFrame) *videoFrame = |
| 46 | [[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:rtcPixelBuffer |
| 47 | rotation:RTCVideoRotation_0 |
| 48 | timeStampNs:timeStampNs]; |
Anders Carlsson | 358f2e0 | 2018-06-04 10:24:37 +0200 | [diff] [blame] | 49 | [self.delegate capturer:self didCaptureVideoFrame:videoFrame]; |
| 50 | } |
| 51 | |
| 52 | @end |