1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2012 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 #ifndef PC_VIDEO_TRACK_H_ 12*d9f75844SAndroid Build Coastguard Worker #define PC_VIDEO_TRACK_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <string> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h" 17*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_interface.h" 18*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_track.h" 19*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h" 20*d9f75844SAndroid Build Coastguard Worker #include "api/sequence_checker.h" 21*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_frame.h" 22*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_sink_interface.h" 23*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_source_interface.h" 24*d9f75844SAndroid Build Coastguard Worker #include "media/base/video_source_base.h" 25*d9f75844SAndroid Build Coastguard Worker #include "pc/video_track_source_proxy.h" 26*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/no_unique_address.h" 27*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h" 28*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread_annotations.h" 29*d9f75844SAndroid Build Coastguard Worker 30*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 31*d9f75844SAndroid Build Coastguard Worker 32*d9f75844SAndroid Build Coastguard Worker // TODO(tommi): Instead of inheriting from `MediaStreamTrack<>`, implement the 33*d9f75844SAndroid Build Coastguard Worker // properties directly in this class. `MediaStreamTrack` doesn't guard against 34*d9f75844SAndroid Build Coastguard Worker // conflicting access, so we'd need to override those methods anyway in this 35*d9f75844SAndroid Build Coastguard Worker // class in order to make sure things are correctly checked. 36*d9f75844SAndroid Build Coastguard Worker class VideoTrack : public MediaStreamTrack<VideoTrackInterface>, 37*d9f75844SAndroid Build Coastguard Worker public rtc::VideoSourceBaseGuarded, 38*d9f75844SAndroid Build Coastguard Worker public ObserverInterface { 39*d9f75844SAndroid Build Coastguard Worker public: 40*d9f75844SAndroid Build Coastguard Worker static rtc::scoped_refptr<VideoTrack> Create( 41*d9f75844SAndroid Build Coastguard Worker absl::string_view label, 42*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackSourceInterface> source, 43*d9f75844SAndroid Build Coastguard Worker rtc::Thread* worker_thread); 44*d9f75844SAndroid Build Coastguard Worker 45*d9f75844SAndroid Build Coastguard Worker void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 46*d9f75844SAndroid Build Coastguard Worker const rtc::VideoSinkWants& wants) override; 47*d9f75844SAndroid Build Coastguard Worker void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; 48*d9f75844SAndroid Build Coastguard Worker void RequestRefreshFrame() override; 49*d9f75844SAndroid Build Coastguard Worker VideoTrackSourceInterface* GetSource() const override; 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker ContentHint content_hint() const override; 52*d9f75844SAndroid Build Coastguard Worker void set_content_hint(ContentHint hint) override; 53*d9f75844SAndroid Build Coastguard Worker bool set_enabled(bool enable) override; 54*d9f75844SAndroid Build Coastguard Worker bool enabled() const override; 55*d9f75844SAndroid Build Coastguard Worker MediaStreamTrackInterface::TrackState state() const override; 56*d9f75844SAndroid Build Coastguard Worker std::string kind() const override; 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker // Direct access to the non-proxied source object for internal implementation. 59*d9f75844SAndroid Build Coastguard Worker VideoTrackSourceInterface* GetSourceInternal() const; 60*d9f75844SAndroid Build Coastguard Worker 61*d9f75844SAndroid Build Coastguard Worker protected: 62*d9f75844SAndroid Build Coastguard Worker VideoTrack( 63*d9f75844SAndroid Build Coastguard Worker absl::string_view id, 64*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr< 65*d9f75844SAndroid Build Coastguard Worker VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> source, 66*d9f75844SAndroid Build Coastguard Worker rtc::Thread* worker_thread); 67*d9f75844SAndroid Build Coastguard Worker ~VideoTrack(); 68*d9f75844SAndroid Build Coastguard Worker 69*d9f75844SAndroid Build Coastguard Worker private: 70*d9f75844SAndroid Build Coastguard Worker // Implements ObserverInterface. Observes `video_source_` state. 71*d9f75844SAndroid Build Coastguard Worker void OnChanged() override; 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker signaling_thread_; 74*d9f75844SAndroid Build Coastguard Worker rtc::Thread* const worker_thread_; 75*d9f75844SAndroid Build Coastguard Worker const rtc::scoped_refptr< 76*d9f75844SAndroid Build Coastguard Worker VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> 77*d9f75844SAndroid Build Coastguard Worker video_source_; 78*d9f75844SAndroid Build Coastguard Worker ContentHint content_hint_ RTC_GUARDED_BY(&signaling_thread_); 79*d9f75844SAndroid Build Coastguard Worker // Cached `enabled` state for the worker thread. This is kept in sync with 80*d9f75844SAndroid Build Coastguard Worker // the state maintained on the signaling thread via set_enabled() but can 81*d9f75844SAndroid Build Coastguard Worker // be queried without blocking on the worker thread by callers that don't 82*d9f75844SAndroid Build Coastguard Worker // use an api proxy to call the `enabled()` method. 83*d9f75844SAndroid Build Coastguard Worker bool enabled_w_ RTC_GUARDED_BY(worker_thread_) = true; 84*d9f75844SAndroid Build Coastguard Worker }; 85*d9f75844SAndroid Build Coastguard Worker 86*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 87*d9f75844SAndroid Build Coastguard Worker 88*d9f75844SAndroid Build Coastguard Worker #endif // PC_VIDEO_TRACK_H_ 89