blob: fccf92e2e28cd72947539c024886b8486608a2d0 [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"
15#include "sdk/objc/Framework/Classes/Video/objcvideotracksource.h"
tkchind4bfbfc2016-08-30 11:56:05 -070016
Magnus Jedvert9932e252017-06-07 16:31:06 +020017static webrtc::ObjcVideoTrackSource *getObjcVideoSource(
18 const rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> nativeSource) {
19 webrtc::VideoTrackSourceProxy *proxy_source =
20 static_cast<webrtc::VideoTrackSourceProxy *>(nativeSource.get());
21 return static_cast<webrtc::ObjcVideoTrackSource *>(proxy_source->internal());
22}
23
magjedabb84b82017-03-28 01:56:41 -070024// TODO(magjed): Refactor this class and target ObjcVideoTrackSource only once
25// 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
48- (NSString *)description {
tkchind4bfbfc2016-08-30 11:56:05 -070049 NSString *stateString = [[self class] stringForState:self.state];
50 return [NSString stringWithFormat:@"RTCVideoSource( %p ): %@", self, stateString];
Jon Hjellef6c318e2016-01-11 14:39:01 -080051}
52
magjedabb84b82017-03-28 01:56:41 -070053- (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame {
Magnus Jedvert9932e252017-06-07 16:31:06 +020054 getObjcVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
magjedabb84b82017-03-28 01:56:41 -070055}
56
57- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
Magnus Jedvert9932e252017-06-07 16:31:06 +020058 getObjcVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
magjedabb84b82017-03-28 01:56:41 -070059}
60
Jon Hjellef6c318e2016-01-11 14:39:01 -080061#pragma mark - Private
62
perkja3ede6c2016-03-08 01:27:48 +010063- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
Jon Hjelle065aacc2016-01-20 13:25:44 -080064 return _nativeVideoSource;
Jon Hjellef6c318e2016-01-11 14:39:01 -080065}
66
Jon Hjellef6c318e2016-01-11 14:39:01 -080067@end