blob: 486ca937718c39feb8b3e7aa003fbecb95257518 [file] [log] [blame]
Jon Hjellef6c318e2016-01-11 14:39:01 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCVideoSource+Private.h"
Jon Hjellef6c318e2016-01-11 14:39:01 -080012
Markus Handella1b82012021-05-26 18:56:30 +020013#include "pc/video_track_source_proxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#include "sdk/objc/native/src/objc_video_track_source.h"
tkchind4bfbfc2016-08-30 11:56:05 -070016
Anders Carlsson9823ee42018-03-07 10:32:03 +010017static webrtc::ObjCVideoTrackSource *getObjCVideoSource(
Magnus Jedvert9932e252017-06-07 16:31:06 +020018 const rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> nativeSource) {
19 webrtc::VideoTrackSourceProxy *proxy_source =
20 static_cast<webrtc::VideoTrackSourceProxy *>(nativeSource.get());
Anders Carlsson9823ee42018-03-07 10:32:03 +010021 return static_cast<webrtc::ObjCVideoTrackSource *>(proxy_source->internal());
Magnus Jedvert9932e252017-06-07 16:31:06 +020022}
23
Anders Carlsson9823ee42018-03-07 10:32:03 +010024// TODO(magjed): Refactor this class and target ObjCVideoTrackSource only once
magjedabb84b82017-03-28 01:56:41 -070025// RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more
26// info.
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020027@implementation RTC_OBJC_TYPE (RTCVideoSource) {
perkja3ede6c2016-03-08 01:27:48 +010028 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080029}
30
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020031- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
Yura Yaroshevich01cee072018-07-11 15:35:40 +030032 nativeVideoSource:
33 (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
34 RTC_DCHECK(factory);
tkchind4bfbfc2016-08-30 11:56:05 -070035 RTC_DCHECK(nativeVideoSource);
Yura Yaroshevich01cee072018-07-11 15:35:40 +030036 if (self = [super initWithFactory:factory
37 nativeMediaSource:nativeVideoSource
38 type:RTCMediaSourceTypeVideo]) {
tkchind4bfbfc2016-08-30 11:56:05 -070039 _nativeVideoSource = nativeVideoSource;
40 }
41 return self;
42}
43
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020044- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
Yura Yaroshevich01cee072018-07-11 15:35:40 +030045 nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
46 type:(RTCMediaSourceType)type {
Artem Titovd3251962021-11-15 16:57:07 +010047 RTC_DCHECK_NOTREACHED();
tkchind4bfbfc2016-08-30 11:56:05 -070048 return nil;
Jon Hjellef6c318e2016-01-11 14:39:01 -080049}
50
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020051- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
Yura Yaroshevich01cee072018-07-11 15:35:40 +030052 signalingThread:(rtc::Thread *)signalingThread
53 workerThread:(rtc::Thread *)workerThread {
Saúl Ibarra Corretgé4d0760e2021-08-06 16:17:12 +020054 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öllerac0d1832022-01-17 15:26:54 +010064 rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource =
65 rtc::make_ref_counted<webrtc::ObjCVideoTrackSource>(isScreenCast);
Anders Carlsson9823ee42018-03-07 10:32:03 +010066
Yura Yaroshevich01cee072018-07-11 15:35:40 +030067 return [self initWithFactory:factory
68 nativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
69 signalingThread, workerThread, objCVideoTrackSource)];
Anders Carlsson9823ee42018-03-07 10:32:03 +010070}
71
Jon Hjellef6c318e2016-01-11 14:39:01 -080072- (NSString *)description {
tkchind4bfbfc2016-08-30 11:56:05 -070073 NSString *stateString = [[self class] stringForState:self.state];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020074 return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCVideoSource)( %p ): %@", self, stateString];
Jon Hjellef6c318e2016-01-11 14:39:01 -080075}
76
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020077- (void)capturer:(RTC_OBJC_TYPE(RTCVideoCapturer) *)capturer
78 didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame {
Anders Carlsson9823ee42018-03-07 10:32:03 +010079 getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
magjedabb84b82017-03-28 01:56:41 -070080}
81
82- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
Anders Carlsson9823ee42018-03-07 10:32:03 +010083 getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
magjedabb84b82017-03-28 01:56:41 -070084}
85
Jon Hjellef6c318e2016-01-11 14:39:01 -080086#pragma mark - Private
87
perkja3ede6c2016-03-08 01:27:48 +010088- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
Jon Hjelle065aacc2016-01-20 13:25:44 -080089 return _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080090}
91
Jon Hjellef6c318e2016-01-11 14:39:01 -080092@end