henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_VIDEO_TRACK_H_ |
| 12 | #define PC_VIDEO_TRACK_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "api/media_stream_interface.h" |
Harald Alvestrand | 9cb42c8 | 2020-10-11 13:03:47 | [diff] [blame] | 18 | #include "api/media_stream_track.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 20 | #include "api/sequence_checker.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 21 | #include "api/video/video_frame.h" |
| 22 | #include "api/video/video_sink_interface.h" |
| 23 | #include "api/video/video_source_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "media/base/video_source_base.h" |
Tommi | 09f5713 | 2022-02-17 12:19:55 | [diff] [blame] | 25 | #include "pc/video_track_source_proxy.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 26 | #include "rtc_base/system/no_unique_address.h" |
Yves Gerey | 2e00abc | 2018-10-05 13:39:24 | [diff] [blame] | 27 | #include "rtc_base/thread.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 28 | #include "rtc_base/thread_annotations.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
Tommi | 09f5713 | 2022-02-17 12:19:55 | [diff] [blame] | 32 | // TODO(tommi): Instead of inheriting from `MediaStreamTrack<>`, implement the |
| 33 | // properties directly in this class. `MediaStreamTrack` doesn't guard against |
| 34 | // conflicting access, so we'd need to override those methods anyway in this |
| 35 | // class in order to make sure things are correctly checked. |
perkj | d6c3954 | 2016-03-17 09:35:23 | [diff] [blame] | 36 | class VideoTrack : public MediaStreamTrack<VideoTrackInterface>, |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 37 | public rtc::VideoSourceBaseGuarded, |
perkj | c8f952d | 2016-03-23 07:33:56 | [diff] [blame] | 38 | public ObserverInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 39 | public: |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 40 | static rtc::scoped_refptr<VideoTrack> Create( |
Niels Möller | c397fc6 | 2022-05-30 09:26:40 | [diff] [blame] | 41 | absl::string_view label, |
Niels Möller | 769de49 | 2022-03-21 09:40:09 | [diff] [blame] | 42 | rtc::scoped_refptr<VideoTrackSourceInterface> source, |
perkj | 773be36 | 2017-08-01 06:22:01 | [diff] [blame] | 43 | rtc::Thread* worker_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 44 | |
nisse | acd935b | 2016-11-11 11:55:13 | [diff] [blame] | 45 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
nisse | db25d2e | 2016-02-26 09:24:58 | [diff] [blame] | 46 | const rtc::VideoSinkWants& wants) override; |
nisse | acd935b | 2016-11-11 11:55:13 | [diff] [blame] | 47 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
Markus Handell | dbef2bd | 2021-12-22 09:47:27 | [diff] [blame] | 48 | void RequestRefreshFrame() override; |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 49 | VideoTrackSourceInterface* GetSource() const override; |
nisse | db25d2e | 2016-02-26 09:24:58 | [diff] [blame] | 50 | |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 51 | ContentHint content_hint() const override; |
| 52 | void set_content_hint(ContentHint hint) override; |
nisse | ef8b61e | 2016-04-29 13:09:15 | [diff] [blame] | 53 | bool set_enabled(bool enable) override; |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 54 | bool enabled() const override; |
| 55 | MediaStreamTrackInterface::TrackState state() const override; |
nisse | ef8b61e | 2016-04-29 13:09:15 | [diff] [blame] | 56 | std::string kind() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | |
Tommi | 34cd1d3 | 2022-02-17 12:28:57 | [diff] [blame] | 58 | // Direct access to the non-proxied source object for internal implementation. |
| 59 | VideoTrackSourceInterface* GetSourceInternal() const; |
| 60 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 61 | protected: |
Tommi | 09f5713 | 2022-02-17 12:19:55 | [diff] [blame] | 62 | VideoTrack( |
Niels Möller | c397fc6 | 2022-05-30 09:26:40 | [diff] [blame] | 63 | absl::string_view id, |
Tommi | 09f5713 | 2022-02-17 12:19:55 | [diff] [blame] | 64 | rtc::scoped_refptr< |
| 65 | VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> source, |
| 66 | rtc::Thread* worker_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 67 | ~VideoTrack(); |
| 68 | |
| 69 | private: |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 70 | // Implements ObserverInterface. Observes `video_source_` state. |
perkj | c8f952d | 2016-03-23 07:33:56 | [diff] [blame] | 71 | void OnChanged() override; |
| 72 | |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 73 | RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker signaling_thread_; |
perkj | 773be36 | 2017-08-01 06:22:01 | [diff] [blame] | 74 | rtc::Thread* const worker_thread_; |
Tommi | 09f5713 | 2022-02-17 12:19:55 | [diff] [blame] | 75 | const rtc::scoped_refptr< |
| 76 | VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> |
| 77 | video_source_; |
Tomas Gunnarsson | dfd69c2 | 2022-02-15 12:56:50 | [diff] [blame] | 78 | ContentHint content_hint_ RTC_GUARDED_BY(&signaling_thread_); |
Tomas Gunnarsson | 250c31d | 2022-02-14 22:48:41 | [diff] [blame] | 79 | // Cached `enabled` state for the worker thread. This is kept in sync with |
| 80 | // the state maintained on the signaling thread via set_enabled() but can |
| 81 | // be queried without blocking on the worker thread by callers that don't |
| 82 | // use an api proxy to call the `enabled()` method. |
| 83 | bool enabled_w_ RTC_GUARDED_BY(worker_thread_) = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace webrtc |
| 87 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 88 | #endif // PC_VIDEO_TRACK_H_ |