You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #import "ARDExternalSampleCapturer.h"
  11. #import <WebRTC/RTCCVPixelBuffer.h>
  12. #import <WebRTC/RTCVideoFrameBuffer.h>
  13. @implementation ARDExternalSampleCapturer
  14. - (instancetype)initWithDelegate:(__weak id<RTCVideoCapturerDelegate>)delegate {
  15. return [super initWithDelegate:delegate];
  16. }
  17. #pragma mark - ARDExternalSampleDelegate
  18. - (void)didCaptureSampleBuffer:(CMSampleBufferRef)sampleBuffer {
  19. if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || !CMSampleBufferIsValid(sampleBuffer) ||
  20. !CMSampleBufferDataIsReady(sampleBuffer)) {
  21. return;
  22. }
  23. CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  24. if (pixelBuffer == nil) {
  25. return;
  26. }
  27. RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:pixelBuffer];
  28. int64_t timeStampNs =
  29. CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * NSEC_PER_SEC;
  30. RTCVideoFrame *videoFrame = [[RTCVideoFrame alloc] initWithBuffer:rtcPixelBuffer
  31. rotation:RTCVideoRotation_0
  32. timeStampNs:timeStampNs];
  33. [self.delegate capturer:self didCaptureVideoFrame:videoFrame];
  34. }
  35. @end