blob: 13a51c454bac70c8e6d17ef22858c4e52b070098 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.org28e20752013-07-10 00:45:369 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_VIDEO_TRACK_H_
12#define PC_VIDEO_TRACK_H_
henrike@webrtc.org28e20752013-07-10 00:45:3613
14#include <string>
15
Harald Alvestrandc24a2182022-02-23 13:44:5916#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 17:11:0017#include "api/media_stream_interface.h"
Harald Alvestrand9cb42c82020-10-11 13:03:4718#include "api/media_stream_track.h"
Mirko Bonadeid9708072019-01-25 19:26:4819#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 13:31:2420#include "api/sequence_checker.h"
Yves Gerey3e707812018-11-28 15:47:4921#include "api/video/video_frame.h"
22#include "api/video/video_sink_interface.h"
23#include "api/video/video_source_interface.h"
Steve Anton10542f22019-01-11 17:11:0024#include "media/base/video_source_base.h"
Tommi09f57132022-02-17 12:19:5525#include "pc/video_track_source_proxy.h"
Harald Alvestrandc24a2182022-02-23 13:44:5926#include "rtc_base/system/no_unique_address.h"
Yves Gerey2e00abc2018-10-05 13:39:2427#include "rtc_base/thread.h"
Yves Gerey3e707812018-11-28 15:47:4928#include "rtc_base/thread_annotations.h"
henrike@webrtc.org28e20752013-07-10 00:45:3629
30namespace webrtc {
31
Tommi09f57132022-02-17 12:19:5532// 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.
perkjd6c39542016-03-17 09:35:2336class VideoTrack : public MediaStreamTrack<VideoTrackInterface>,
Tommi816134a2021-05-24 14:54:4137 public rtc::VideoSourceBaseGuarded,
perkjc8f952d2016-03-23 07:33:5638 public ObserverInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3639 public:
perkja3ede6c2016-03-08 00:27:4840 static rtc::scoped_refptr<VideoTrack> Create(
Niels Möllerc397fc62022-05-30 09:26:4041 absl::string_view label,
Niels Möller769de492022-03-21 09:40:0942 rtc::scoped_refptr<VideoTrackSourceInterface> source,
perkj773be362017-08-01 06:22:0143 rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:3644
nisseacd935b2016-11-11 11:55:1345 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
nissedb25d2e2016-02-26 09:24:5846 const rtc::VideoSinkWants& wants) override;
nisseacd935b2016-11-11 11:55:1347 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
Markus Handelldbef2bd2021-12-22 09:47:2748 void RequestRefreshFrame() override;
Tommi816134a2021-05-24 14:54:4149 VideoTrackSourceInterface* GetSource() const override;
nissedb25d2e2016-02-26 09:24:5850
pbos5214a0a2016-12-16 23:39:1151 ContentHint content_hint() const override;
52 void set_content_hint(ContentHint hint) override;
nisseef8b61e2016-04-29 13:09:1553 bool set_enabled(bool enable) override;
Tommi816134a2021-05-24 14:54:4154 bool enabled() const override;
55 MediaStreamTrackInterface::TrackState state() const override;
nisseef8b61e2016-04-29 13:09:1556 std::string kind() const override;
henrike@webrtc.org28e20752013-07-10 00:45:3657
Tommi34cd1d32022-02-17 12:28:5758 // Direct access to the non-proxied source object for internal implementation.
59 VideoTrackSourceInterface* GetSourceInternal() const;
60
henrike@webrtc.org28e20752013-07-10 00:45:3661 protected:
Tommi09f57132022-02-17 12:19:5562 VideoTrack(
Niels Möllerc397fc62022-05-30 09:26:4063 absl::string_view id,
Tommi09f57132022-02-17 12:19:5564 rtc::scoped_refptr<
65 VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>> source,
66 rtc::Thread* worker_thread);
henrike@webrtc.org28e20752013-07-10 00:45:3667 ~VideoTrack();
68
69 private:
Artem Titov880fa812021-07-30 20:30:2370 // Implements ObserverInterface. Observes `video_source_` state.
perkjc8f952d2016-03-23 07:33:5671 void OnChanged() override;
72
Tommi816134a2021-05-24 14:54:4173 RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker signaling_thread_;
perkj773be362017-08-01 06:22:0174 rtc::Thread* const worker_thread_;
Tommi09f57132022-02-17 12:19:5575 const rtc::scoped_refptr<
76 VideoTrackSourceProxyWithInternal<VideoTrackSourceInterface>>
77 video_source_;
Tomas Gunnarssondfd69c22022-02-15 12:56:5078 ContentHint content_hint_ RTC_GUARDED_BY(&signaling_thread_);
Tomas Gunnarsson250c31d2022-02-14 22:48:4179 // 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.org28e20752013-07-10 00:45:3684};
85
86} // namespace webrtc
87
Steve Anton10542f22019-01-11 17:11:0088#endif // PC_VIDEO_TRACK_H_