xref: /aosp_15_r20/external/webrtc/sdk/objc/api/peerconnection/RTCVideoSource.mm (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker/*
2*d9f75844SAndroid Build Coastguard Worker *  Copyright 2015 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker *
4*d9f75844SAndroid Build Coastguard Worker *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker */
10*d9f75844SAndroid Build Coastguard Worker
11*d9f75844SAndroid Build Coastguard Worker#import "RTCVideoSource+Private.h"
12*d9f75844SAndroid Build Coastguard Worker
13*d9f75844SAndroid Build Coastguard Worker#include "pc/video_track_source_proxy.h"
14*d9f75844SAndroid Build Coastguard Worker#include "rtc_base/checks.h"
15*d9f75844SAndroid Build Coastguard Worker#include "sdk/objc/native/src/objc_video_track_source.h"
16*d9f75844SAndroid Build Coastguard Worker
17*d9f75844SAndroid Build Coastguard Workerstatic webrtc::ObjCVideoTrackSource *getObjCVideoSource(
18*d9f75844SAndroid Build Coastguard Worker    const rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> nativeSource) {
19*d9f75844SAndroid Build Coastguard Worker  webrtc::VideoTrackSourceProxy *proxy_source =
20*d9f75844SAndroid Build Coastguard Worker      static_cast<webrtc::VideoTrackSourceProxy *>(nativeSource.get());
21*d9f75844SAndroid Build Coastguard Worker  return static_cast<webrtc::ObjCVideoTrackSource *>(proxy_source->internal());
22*d9f75844SAndroid Build Coastguard Worker}
23*d9f75844SAndroid Build Coastguard Worker
24*d9f75844SAndroid Build Coastguard Worker// TODO(magjed): Refactor this class and target ObjCVideoTrackSource only once
25*d9f75844SAndroid Build Coastguard Worker// RTCAVFoundationVideoSource is gone. See http://crbug/webrtc/7177 for more
26*d9f75844SAndroid Build Coastguard Worker// info.
27*d9f75844SAndroid Build Coastguard Worker@implementation RTC_OBJC_TYPE (RTCVideoSource) {
28*d9f75844SAndroid Build Coastguard Worker  rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
29*d9f75844SAndroid Build Coastguard Worker}
30*d9f75844SAndroid Build Coastguard Worker
31*d9f75844SAndroid Build Coastguard Worker- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
32*d9f75844SAndroid Build Coastguard Worker              nativeVideoSource:
33*d9f75844SAndroid Build Coastguard Worker                  (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
34*d9f75844SAndroid Build Coastguard Worker  RTC_DCHECK(factory);
35*d9f75844SAndroid Build Coastguard Worker  RTC_DCHECK(nativeVideoSource);
36*d9f75844SAndroid Build Coastguard Worker  if (self = [super initWithFactory:factory
37*d9f75844SAndroid Build Coastguard Worker                  nativeMediaSource:nativeVideoSource
38*d9f75844SAndroid Build Coastguard Worker                               type:RTCMediaSourceTypeVideo]) {
39*d9f75844SAndroid Build Coastguard Worker    _nativeVideoSource = nativeVideoSource;
40*d9f75844SAndroid Build Coastguard Worker  }
41*d9f75844SAndroid Build Coastguard Worker  return self;
42*d9f75844SAndroid Build Coastguard Worker}
43*d9f75844SAndroid Build Coastguard Worker
44*d9f75844SAndroid Build Coastguard Worker- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
45*d9f75844SAndroid Build Coastguard Worker              nativeMediaSource:(rtc::scoped_refptr<webrtc::MediaSourceInterface>)nativeMediaSource
46*d9f75844SAndroid Build Coastguard Worker                           type:(RTCMediaSourceType)type {
47*d9f75844SAndroid Build Coastguard Worker  RTC_DCHECK_NOTREACHED();
48*d9f75844SAndroid Build Coastguard Worker  return nil;
49*d9f75844SAndroid Build Coastguard Worker}
50*d9f75844SAndroid Build Coastguard Worker
51*d9f75844SAndroid Build Coastguard Worker- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
52*d9f75844SAndroid Build Coastguard Worker                signalingThread:(rtc::Thread *)signalingThread
53*d9f75844SAndroid Build Coastguard Worker                   workerThread:(rtc::Thread *)workerThread {
54*d9f75844SAndroid Build Coastguard Worker  return [self initWithFactory:factory
55*d9f75844SAndroid Build Coastguard Worker               signalingThread:signalingThread
56*d9f75844SAndroid Build Coastguard Worker                  workerThread:workerThread
57*d9f75844SAndroid Build Coastguard Worker                  isScreenCast:NO];
58*d9f75844SAndroid Build Coastguard Worker}
59*d9f75844SAndroid Build Coastguard Worker
60*d9f75844SAndroid Build Coastguard Worker- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
61*d9f75844SAndroid Build Coastguard Worker                signalingThread:(rtc::Thread *)signalingThread
62*d9f75844SAndroid Build Coastguard Worker                   workerThread:(rtc::Thread *)workerThread
63*d9f75844SAndroid Build Coastguard Worker                   isScreenCast:(BOOL)isScreenCast {
64*d9f75844SAndroid Build Coastguard Worker  rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource =
65*d9f75844SAndroid Build Coastguard Worker      rtc::make_ref_counted<webrtc::ObjCVideoTrackSource>(isScreenCast);
66*d9f75844SAndroid Build Coastguard Worker
67*d9f75844SAndroid Build Coastguard Worker  return [self initWithFactory:factory
68*d9f75844SAndroid Build Coastguard Worker             nativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
69*d9f75844SAndroid Build Coastguard Worker                                   signalingThread, workerThread, objCVideoTrackSource)];
70*d9f75844SAndroid Build Coastguard Worker}
71*d9f75844SAndroid Build Coastguard Worker
72*d9f75844SAndroid Build Coastguard Worker- (NSString *)description {
73*d9f75844SAndroid Build Coastguard Worker  NSString *stateString = [[self class] stringForState:self.state];
74*d9f75844SAndroid Build Coastguard Worker  return [NSString stringWithFormat:@"RTC_OBJC_TYPE(RTCVideoSource)( %p ): %@", self, stateString];
75*d9f75844SAndroid Build Coastguard Worker}
76*d9f75844SAndroid Build Coastguard Worker
77*d9f75844SAndroid Build Coastguard Worker- (void)capturer:(RTC_OBJC_TYPE(RTCVideoCapturer) *)capturer
78*d9f75844SAndroid Build Coastguard Worker    didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame {
79*d9f75844SAndroid Build Coastguard Worker  getObjCVideoSource(_nativeVideoSource)->OnCapturedFrame(frame);
80*d9f75844SAndroid Build Coastguard Worker}
81*d9f75844SAndroid Build Coastguard Worker
82*d9f75844SAndroid Build Coastguard Worker- (void)adaptOutputFormatToWidth:(int)width height:(int)height fps:(int)fps {
83*d9f75844SAndroid Build Coastguard Worker  getObjCVideoSource(_nativeVideoSource)->OnOutputFormatRequest(width, height, fps);
84*d9f75844SAndroid Build Coastguard Worker}
85*d9f75844SAndroid Build Coastguard Worker
86*d9f75844SAndroid Build Coastguard Worker#pragma mark - Private
87*d9f75844SAndroid Build Coastguard Worker
88*d9f75844SAndroid Build Coastguard Worker- (rtc::scoped_refptr<webrtc::VideoTrackSourceInterface>)nativeVideoSource {
89*d9f75844SAndroid Build Coastguard Worker  return _nativeVideoSource;
90*d9f75844SAndroid Build Coastguard Worker}
91*d9f75844SAndroid Build Coastguard Worker
92*d9f75844SAndroid Build Coastguard Worker@end
93