blob: 789c8436e54a08421d0facc58cc32f0bf86957ff [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
Steve Anton10542f22019-01-11 09:11:00 -080013#include "api/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.
Jon Hjelle065aacc2016-01-20 13:25:44 -080027@implementation RTCVideoSource {
perkja3ede6c2016-03-08 01:27:48 +010028 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080029}
30
Yura Yaroshevich01cee072018-07-11 15:35:40 +030031- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
32 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
Yura Yaroshevich01cee072018-07-11 15:35:40 +030044- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
45 nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
46 type:(RTCMediaSourceType)type {
tkchind4bfbfc2016-08-30 11:56:05 -070047 RTC_NOTREACHED();
48 return nil;
Jon Hjellef6c318e2016-01-11 14:39:01 -080049}
50
Yura Yaroshevich01cee072018-07-11 15:35:40 +030051- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
52 signalingThread:(rtc::Thread *)signalingThread
53 workerThread:(rtc::Thread *)workerThread {
Anders Carlsson9823ee42018-03-07 10:32:03 +010054 rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource(
55 new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>());
56
Yura Yaroshevich01cee072018-07-11 15:35:40 +030057 return [self initWithFactory:factory
58 nativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
59 signalingThread, workerThread, objCVideoTrackSource)];
Anders Carlsson9823ee42018-03-07 10:32:03 +010060}
61
Jon Hjellef6c318e2016-01-11 14:39:01 -080062- (NSString *)description {
tkchind4bfbfc2016-08-30 11:56:05 -070063 NSString *stateString = [[self class] stringForState:self.state];
64 return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString];
Jon Hjellef6c318e2016-01-11 14:39:01 -080065}
66
magjedabb84b82017-03-28 01:56:41 -070067- (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame {
Anders Carlsson9823ee42018-03-07 10:32:03 +010068 getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
magjedabb84b82017-03-28 01:56:41 -070069}
70
71- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
Anders Carlsson9823ee42018-03-07 10:32:03 +010072 getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
magjedabb84b82017-03-28 01:56:41 -070073}
74
Jon Hjellef6c318e2016-01-11 14:39:01 -080075#pragma mark - Private
76
perkja3ede6c2016-03-08 01:27:48 +010077- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
Jon Hjelle065aacc2016-01-20 13:25:44 -080078 return _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080079}
80
Jon Hjellef6c318e2016-01-11 14:39:01 -080081@end