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 | |
Markus Handell | a1b8201 | 2021-05-26 18:56:30 +0200 | [diff] [blame] | 13 | #include "pc/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. |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 27 | @implementation RTC_OBJC_TYPE (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 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 31 | - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 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 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 44 | - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 45 | nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource |
| 46 | type:(RTCMediaSourceType)type { |
Artem Titov | d325196 | 2021-11-15 16:57:07 +0100 | [diff] [blame] | 47 | RTC_DCHECK_NOTREACHED(); |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 48 | return nil; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 51 | - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 52 | signalingThread:(rtc::Thread *)signalingThread |
| 53 | workerThread:(rtc::Thread *)workerThread { |
Saúl Ibarra Corretgé | 4d0760e | 2021-08-06 16:17:12 +0200 | [diff] [blame] | 54 | return [self initWithFactory:factory |
| 55 | signalingThread:signalingThread |
| 56 | workerThread:workerThread |
| 57 | isScreenCast:NO]; |
| 58 | } |
| 59 | |
| 60 | - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
| 61 | signalingThread:(rtc::Thread *)signalingThread |
| 62 | workerThread:(rtc::Thread *)workerThread |
| 63 | isScreenCast:(BOOL)isScreenCast { |
Niels Möller | ac0d183 | 2022-01-17 15:26:54 +0100 | [diff] [blame^] | 64 | rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource = |
| 65 | rtc::make_ref_counted<webrtc::ObjCVideoTrackSource>(isScreenCast); |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 66 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 67 | return [self initWithFactory:factory |
| 68 | nativeVideoSource:webrtc::VideoTrackSourceProxy::Create( |
| 69 | signalingThread, workerThread, objCVideoTrackSource)]; |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 72 | - (NSString *)description { |
tkchin | d4bfbfc | 2016-08-30 11:56:05 -0700 | [diff] [blame] | 73 | NSString *stateString = [[self class] stringForState:self.state]; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 74 | return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCVideoSource)( %p ): %@", self, stateString]; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 77 | - (void)capturer:(RTC_OBJC_TYPE(RTCVideoCapturer) *)capturer |
| 78 | didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame { |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 79 | getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame); |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | - (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { |
Anders Carlsson | 9823ee4 | 2018-03-07 10:32:03 +0100 | [diff] [blame] | 83 | getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps); |
magjed | abb84b8 | 2017-03-28 01:56:41 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 86 | #pragma mark - Private |
| 87 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 88 | - (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { |
Jon Hjelle | 065aacc | 2016-01-20 13:25:44 -0800 | [diff] [blame] | 89 | return _nativeVideoSource; |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Jon Hjelle | f6c318e | 2016-01-11 14:39:01 -0800 | [diff] [blame] | 92 | @end |