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 "api/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_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 rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource( 55 new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>()); 56 57 return [self initWithFactory:factory 58 nativeVideoSource:webrtc::VideoTrackSourceProxy::Create( 59 signalingThread, workerThread, objCVideoTrackSource)]; 60} 61 62- (NSString *)description { 63 NSString *stateString = [[self class] stringForState:self.state]; 64 return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCVideoSource)( %p ): %@", self, stateString]; 65} 66 67- (void)capturer:(RTC_OBJC_TYPE(RTCVideoCapturer) *)capturer 68 didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame { 69 getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame); 70} 71 72- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps { 73 getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps); 74} 75 76#pragma mark - Private 77 78- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource { 79 return _nativeVideoSource; 80} 81 82@end 83