blob: f380af4558c7c78ee52548bc7c1e83e6236acdf7 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "api/videosourceproxy.h"
14#include "rtc_base/checks.h"
Anders Carlsson9823ee42018-03-07 10:32:03 +010015#include "sdk/objc/Framework/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
tkchind4bfbfc2016-08-30 11:56:05 -070031- (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 Hjellef6c318e2016-01-11 14:39:01 -080046}
47
Anders Carlsson9823ee42018-03-07 10:32:03 +010048- (instancetype)initWithSignalingThread:(rtc::Thread *)signalingThread
49 workerThread:(rtc::Thread *)workerThread {
50 rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource(
51 new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>());
52
53 return [self initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
54 signalingThread, workerThread, objCVideoTrackSource)];
55}
56
Jon Hjellef6c318e2016-01-11 14:39:01 -080057- (NSString *)description {
tkchind4bfbfc2016-08-30 11:56:05 -070058 NSString *stateString = [[self class] stringForState:self.state];
59 return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString];
Jon Hjellef6c318e2016-01-11 14:39:01 -080060}
61
magjedabb84b82017-03-28 01:56:41 -070062- (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame {
Anders Carlsson9823ee42018-03-07 10:32:03 +010063 getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
magjedabb84b82017-03-28 01:56:41 -070064}
65
66- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
Anders Carlsson9823ee42018-03-07 10:32:03 +010067 getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
magjedabb84b82017-03-28 01:56:41 -070068}
69
Jon Hjellef6c318e2016-01-11 14:39:01 -080070#pragma mark - Private
71
perkja3ede6c2016-03-08 01:27:48 +010072- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
Jon Hjelle065aacc2016-01-20 13:25:44 -080073 return _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080074}
75
Jon Hjellef6c318e2016-01-11 14:39:01 -080076@end