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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 13 | #include "api/video_track_source_proxy.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 15 | #include "sdk/objc/native/src/objc_video_track_source.h" |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 16 | |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 17 | static webrtc::ObjCVideoTrackSource *getObjCVideoSource( |
Magnus Jedvert | 9932e25 | 2017-06-07 16:31:06 +0200 | [diff] [blame] | 18 | const rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> nativeSource) { |
| 19 | webrtc::VideoTrackSourceProxy *proxy_source = |
| 20 | static_cast<webrtc::VideoTrackSourceProxy *>(nativeSource.get()); |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 21 | return static_cast<webrtc::ObjCVideoTrackSource *>(proxy_source->internal()); |
Magnus Jedvert | 9932e25 | 2017-06-07 16:31:06 +0200 | [diff] [blame] | 22 | } |
| 23 | |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 24 | // TODO(magjed): Refactor this class and target ObjCVideoTrackSource only once |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 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 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 31 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 32 | nativeVideoSource: |
| 33 | (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
| 34 | RTC_DCHECK(factory); |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 35 | RTC_DCHECK(nativeVideoSource); |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 36 | if (self = [super initWithFactory:factory |
| 37 | nativeMediaSource:nativeVideoSource |
| 38 | type:RTCMediaSourceTypeVideo]) { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 39 | _nativeVideoSource = nativeVideoSource; |
| 40 | } |
| 41 | return self; |
| 42 | } |
| 43 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 44 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 45 | nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource |
| 46 | type:(RTCMediaSourceType)type { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 47 | RTC_NOTREACHED(); |
| 48 | return nil; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 51 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 52 | signalingThread:(rtc::Thread *)signalingThread |
| 53 | workerThread:(rtc::Thread *)workerThread { |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 54 | rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource( |
| 55 | new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>()); |
| 56 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 57 | return [self initWithFactory:factory |
| 58 | nativeVideoSource:webrtc::VideoTrackSourceProxy::Create( |
| 59 | signalingThread, workerThread, objCVideoTrackSource)]; |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 62 | - (NSString *)description { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 63 | NSString *stateString = [[self class] stringForState:self.state]; |
| 64 | return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString]; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 65 | } |
| 66 | |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 67 | - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame { |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 68 | getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame); |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | - (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 72 | getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps); |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 75 | #pragma mark - Private |
| 76 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 77 | - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 78 | return _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 81 | @end |