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 11#import "RTCVideoSource+Private.h" 12 13#include "pc/video_track_source_proxy.h" 14#include "rtc_base/checks.h" 15#include "sdk/objc/native/src/objc_video_track_source.h" 16 17static 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 24// TODO(magjed): Refactor this class and target ObjCVideoTrackSource only once 25// RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more 26// info. 27@implementation RTC_OBJC_TYPE (RTCVideoSource) { 28 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource; 29} 30 31- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory 32 nativeVideoSource: 33 (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { 34 RTC_DCHECK(factory); 35 RTC_DCHECK(nativeVideoSource); 36 if (self = [super initWithFactory:factory 37 nativeMediaSource:nativeVideoSource 38 type:RTCMediaSourceTypeVideo]) { 39 _nativeVideoSource = nativeVideoSource; 40 } 41 return self; 42} 43 44- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory 45 nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource 46 type:(RTCMediaSourceType)type { 47 RTC_DCHECK_NOTREACHED(); 48 return nil; 49} 50 51- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory 52 signalingThread:(rtc::Thread *)signalingThread 53 workerThread:(rtc::Thread *)workerThread { 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 { 64 rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource = 65 rtc::make_ref_counted<webrtc::ObjCVideoTrackSource>(isScreenCast); 66 67 return [self initWithFactory:factory 68 nativeVideoSource:webrtc::VideoTrackSourceProxy::Create( 69 signalingThread, workerThread, objCVideoTrackSource)]; 70} 71 72- (NSString *)description { 73 NSString *stateString = [[self class] stringForState:self.state]; 74 return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCVideoSource)( %p ): %@", self, stateString]; 75} 76 77- (void)capturer:(RTC_OBJC_TYPE(RTCVideoCapturer) *)capturer 78 didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame { 79 getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame); 80} 81 82- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { 83 getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps); 84} 85 86#pragma mark - Private 87 88- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { 89 return _nativeVideoSource; 90} 91 92@end 93