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