Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCVideoSource+Private.h" |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 12 | |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 13 | #include "webrtc/base/checks.h" |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 14 | #include "webrtc/sdk/objc/Framework/Classes/objcvideotracksource.h" |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 15 | |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 16 | // TODO(magjed): Refactor this class and target ObjcVideoTrackSource only once |
| 17 | // RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more |
| 18 | // info. |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 19 | @implementation RTCVideoSource { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 20 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 21 | } |
| 22 | |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 23 | - (instancetype)initWithNativeVideoSource: |
| 24 | (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
| 25 | RTC_DCHECK(nativeVideoSource); |
| 26 | if (self = [super initWithNativeMediaSource:nativeVideoSource |
| 27 | type:RTCMediaSourceTypeVideo]) { |
| 28 | _nativeVideoSource = nativeVideoSource; |
| 29 | } |
| 30 | return self; |
| 31 | } |
| 32 | |
| 33 | - (instancetype)initWithNativeMediaSource: |
| 34 | (rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource |
| 35 | type:(RTCMediaSourceType)type { |
| 36 | RTC_NOTREACHED(); |
| 37 | return nil; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | - (NSString *)description { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 41 | NSString *stateString = [[self class] stringForState:self.state]; |
| 42 | return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString]; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 43 | } |
| 44 | |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 45 | - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame { |
| 46 | static_cast<webrtc::ObjcVideoTrackSource *>(_nativeVideoSource.get())->OnCapturedFrame(frame); |
| 47 | } |
| 48 | |
| 49 | - (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { |
| 50 | static_cast<webrtc::ObjcVideoTrackSource *>(_nativeVideoSource.get()) |
| 51 | ->OnOutputFormatRequest(width, height, fps); |
| 52 | } |
| 53 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 54 | #pragma mark - Private |
| 55 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 56 | - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 57 | return _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 60 | @end |