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 | |
| 11 | // This file contains interfaces for MediaStream, MediaTrack and MediaSource. |
| 12 | // These interfaces are used for implementing MediaStream and MediaTrack as |
| 13 | // defined in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These |
Niels Möller | e942b14 | 2019-09-17 12:30:41 | [diff] [blame] | 14 | // interfaces must be used only with PeerConnection. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 15 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 16 | #ifndef API_MEDIA_STREAM_INTERFACE_H_ |
| 17 | #define API_MEDIA_STREAM_INTERFACE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | |
pbos | 9baddf2 | 2017-01-02 14:44:41 | [diff] [blame] | 19 | #include <stddef.h> |
| 20 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 24 | #include "absl/types/optional.h" |
Piotr (Peter) Slatala | 95ca6e1 | 2018-11-13 15:57:07 | [diff] [blame] | 25 | #include "api/audio_options.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 26 | #include "api/scoped_refptr.h" |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 27 | #include "api/video/recordable_encoded_frame.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 28 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 09:15:30 | [diff] [blame] | 29 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 12:09:31 | [diff] [blame] | 30 | #include "api/video/video_source_interface.h" |
Markus Handell | 6fa9e68 | 2021-10-13 20:50:53 | [diff] [blame] | 31 | #include "api/video_track_source_constraints.h" |
Ivo Creusen | 56d46090 | 2017-11-24 16:29:59 | [diff] [blame] | 32 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 33 | #include "rtc_base/ref_count.h" |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 34 | #include "rtc_base/system/rtc_export.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 35 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 36 | namespace webrtc { |
| 37 | |
| 38 | // Generic observer interface. |
| 39 | class ObserverInterface { |
| 40 | public: |
| 41 | virtual void OnChanged() = 0; |
| 42 | |
| 43 | protected: |
| 44 | virtual ~ObserverInterface() {} |
| 45 | }; |
| 46 | |
| 47 | class NotifierInterface { |
| 48 | public: |
| 49 | virtual void RegisterObserver(ObserverInterface* observer) = 0; |
| 50 | virtual void UnregisterObserver(ObserverInterface* observer) = 0; |
| 51 | |
| 52 | virtual ~NotifierInterface() {} |
| 53 | }; |
| 54 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 55 | // Base class for sources. A MediaStreamTrack has an underlying source that |
| 56 | // provides media. A source can be shared by multiple tracks. |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 57 | class RTC_EXPORT MediaSourceInterface : public rtc::RefCountInterface, |
| 58 | public NotifierInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 60 | enum SourceState { kInitializing, kLive, kEnded, kMuted }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 61 | |
| 62 | virtual SourceState state() const = 0; |
| 63 | |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 64 | virtual bool remote() const = 0; |
| 65 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 66 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 67 | ~MediaSourceInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 68 | }; |
| 69 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 70 | // C++ version of MediaStreamTrack. |
| 71 | // See: https://www.w3.org/TR/mediacapture-streams/#mediastreamtrack |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 72 | class RTC_EXPORT MediaStreamTrackInterface : public rtc::RefCountInterface, |
| 73 | public NotifierInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 74 | public: |
| 75 | enum TrackState { |
perkj | c8f952d | 2016-03-23 07:33:56 | [diff] [blame] | 76 | kLive, |
| 77 | kEnded, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | }; |
| 79 | |
Niels Möller | 6dcd4dc | 2019-08-26 08:45:28 | [diff] [blame] | 80 | static const char* const kAudioKind; |
| 81 | static const char* const kVideoKind; |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 82 | |
nisse | fcc640f | 2016-04-01 08:10:42 | [diff] [blame] | 83 | // The kind() method must return kAudioKind only if the object is a |
| 84 | // subclass of AudioTrackInterface, and kVideoKind only if the |
| 85 | // object is a subclass of VideoTrackInterface. It is typically used |
| 86 | // to protect a static_cast<> to the corresponding subclass. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 87 | virtual std::string kind() const = 0; |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 88 | |
| 89 | // Track identifier. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 90 | virtual std::string id() const = 0; |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 91 | |
| 92 | // A disabled track will produce silence (if audio) or black frames (if |
| 93 | // video). Can be disabled and re-enabled. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | virtual bool enabled() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 95 | virtual bool set_enabled(bool enable) = 0; |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 | [diff] [blame] | 96 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 97 | // Live or ended. A track will never be live again after becoming ended. |
| 98 | virtual TrackState state() const = 0; |
| 99 | |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 | [diff] [blame] | 100 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 101 | ~MediaStreamTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 102 | }; |
| 103 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 104 | // VideoTrackSourceInterface is a reference counted source used for |
| 105 | // VideoTracks. The same source can be used by multiple VideoTracks. |
perkj | 773be36 | 2017-08-01 06:22:01 | [diff] [blame] | 106 | // VideoTrackSourceInterface is designed to be invoked on the signaling thread |
| 107 | // except for rtc::VideoSourceInterface<VideoFrame> methods that will be invoked |
| 108 | // on the worker thread via a VideoTrack. A custom implementation of a source |
| 109 | // can inherit AdaptedVideoTrackSource instead of directly implementing this |
| 110 | // interface. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 111 | class VideoTrackSourceInterface : public MediaSourceInterface, |
| 112 | public rtc::VideoSourceInterface<VideoFrame> { |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 113 | public: |
nisse | fcc640f | 2016-04-01 08:10:42 | [diff] [blame] | 114 | struct Stats { |
| 115 | // Original size of captured frame, before video adaptation. |
| 116 | int input_width; |
| 117 | int input_height; |
| 118 | }; |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 119 | |
perkj | 0d3eef2 | 2016-03-09 01:39:17 | [diff] [blame] | 120 | // Indicates that parameters suitable for screencasts should be automatically |
| 121 | // applied to RtpSenders. |
| 122 | // TODO(perkj): Remove these once all known applications have moved to |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 123 | // explicitly setting suitable parameters for screencasts and don't need this |
perkj | 0d3eef2 | 2016-03-09 01:39:17 | [diff] [blame] | 124 | // implicit behavior. |
| 125 | virtual bool is_screencast() const = 0; |
| 126 | |
Per | c0d31e9 | 2016-03-31 15:23:39 | [diff] [blame] | 127 | // Indicates that the encoder should denoise video before encoding it. |
| 128 | // If it is not set, the default configuration is used which is different |
| 129 | // depending on video codec. |
perkj | 0d3eef2 | 2016-03-09 01:39:17 | [diff] [blame] | 130 | // TODO(perkj): Remove this once denoising is done by the source, and not by |
| 131 | // the encoder. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 132 | virtual absl::optional<bool> needs_denoising() const = 0; |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 133 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 134 | // Returns false if no stats are available, e.g, for a remote source, or a |
| 135 | // source which has not seen its first frame yet. |
| 136 | // |
| 137 | // Implementation should avoid blocking. |
nisse | fcc640f | 2016-04-01 08:10:42 | [diff] [blame] | 138 | virtual bool GetStats(Stats* stats) = 0; |
| 139 | |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 140 | // Returns true if encoded output can be enabled in the source. |
Markus Handell | 6efc14b | 2020-05-05 18:11:13 | [diff] [blame] | 141 | virtual bool SupportsEncodedOutput() const = 0; |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 142 | |
| 143 | // Reliably cause a key frame to be generated in encoded output. |
| 144 | // TODO(bugs.webrtc.org/11115): find optimal naming. |
Markus Handell | 6efc14b | 2020-05-05 18:11:13 | [diff] [blame] | 145 | virtual void GenerateKeyFrame() = 0; |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 146 | |
| 147 | // Add an encoded video sink to the source and additionally cause |
| 148 | // a key frame to be generated from the source. The sink will be |
| 149 | // invoked from a decoder queue. |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 150 | virtual void AddEncodedSink( |
Markus Handell | 6efc14b | 2020-05-05 18:11:13 | [diff] [blame] | 151 | rtc::VideoSinkInterface<RecordableEncodedFrame>* sink) = 0; |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 152 | |
| 153 | // Removes an encoded video sink from the source. |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 154 | virtual void RemoveEncodedSink( |
Markus Handell | 6efc14b | 2020-05-05 18:11:13 | [diff] [blame] | 155 | rtc::VideoSinkInterface<RecordableEncodedFrame>* sink) = 0; |
Markus Handell | 9982efa | 2019-11-21 10:56:50 | [diff] [blame] | 156 | |
Markus Handell | 6fa9e68 | 2021-10-13 20:50:53 | [diff] [blame] | 157 | // Notify about constraints set on the source. The information eventually gets |
| 158 | // routed to attached sinks via VideoSinkInterface<>::OnConstraintsChanged. |
| 159 | // The call is expected to happen on the network thread. |
| 160 | // TODO(crbug/1255737): make pure virtual once downstream project adapts. |
| 161 | virtual void ProcessConstraints( |
| 162 | const webrtc::VideoTrackSourceConstraints& constraints) {} |
| 163 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 164 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 165 | ~VideoTrackSourceInterface() override = default; |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 166 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 167 | |
perkj | 773be36 | 2017-08-01 06:22:01 | [diff] [blame] | 168 | // VideoTrackInterface is designed to be invoked on the signaling thread except |
| 169 | // for rtc::VideoSourceInterface<VideoFrame> methods that must be invoked |
| 170 | // on the worker thread. |
| 171 | // PeerConnectionFactory::CreateVideoTrack can be used for creating a VideoTrack |
| 172 | // that ensures thread safety and that all methods are called on the right |
| 173 | // thread. |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 174 | class RTC_EXPORT VideoTrackInterface |
| 175 | : public MediaStreamTrackInterface, |
| 176 | public rtc::VideoSourceInterface<VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 177 | public: |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 178 | // Video track content hint, used to override the source is_screencast |
| 179 | // property. |
Harald Alvestrand | c19ab07 | 2018-06-18 06:53:10 | [diff] [blame] | 180 | // See https://crbug.com/653531 and https://w3c.github.io/mst-content-hint. |
| 181 | enum class ContentHint { kNone, kFluid, kDetailed, kText }; |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 182 | |
mbonadei | 539d104 | 2017-07-10 09:40:49 | [diff] [blame] | 183 | // Register a video sink for this track. Used to connect the track to the |
| 184 | // underlying video engine. |
| 185 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 186 | const rtc::VideoSinkWants& wants) override {} |
| 187 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {} |
| 188 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 189 | virtual VideoTrackSourceInterface* GetSource() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 190 | |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 191 | virtual ContentHint content_hint() const; |
pbos | 5214a0a | 2016-12-16 23:39:11 | [diff] [blame] | 192 | virtual void set_content_hint(ContentHint hint) {} |
| 193 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 194 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 195 | ~VideoTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 196 | }; |
| 197 | |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 198 | // Interface for receiving audio data from a AudioTrack. |
| 199 | class AudioTrackSinkInterface { |
| 200 | public: |
| 201 | virtual void OnData(const void* audio_data, |
| 202 | int bits_per_sample, |
| 203 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-13 00:26:35 | [diff] [blame] | 204 | size_t number_of_channels, |
Minyue Li | 99d6d81 | 2020-01-29 09:25:12 | [diff] [blame] | 205 | size_t number_of_frames) { |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 206 | RTC_DCHECK_NOTREACHED() << "This method must be overridden, or not used."; |
Minyue Li | 99d6d81 | 2020-01-29 09:25:12 | [diff] [blame] | 207 | } |
| 208 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 209 | // In this method, `absolute_capture_timestamp_ms`, when available, is |
Minyue Li | 99d6d81 | 2020-01-29 09:25:12 | [diff] [blame] | 210 | // supposed to deliver the timestamp when this audio frame was originally |
| 211 | // captured. This timestamp MUST be based on the same clock as |
| 212 | // rtc::TimeMillis(). |
| 213 | virtual void OnData(const void* audio_data, |
| 214 | int bits_per_sample, |
| 215 | int sample_rate, |
| 216 | size_t number_of_channels, |
| 217 | size_t number_of_frames, |
| 218 | absl::optional<int64_t> absolute_capture_timestamp_ms) { |
| 219 | // TODO(bugs.webrtc.org/10739): Deprecate the old OnData and make this one |
| 220 | // pure virtual. |
| 221 | return OnData(audio_data, bits_per_sample, sample_rate, number_of_channels, |
| 222 | number_of_frames); |
| 223 | } |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 224 | |
Gustaf Ullberg | 46ea5d7 | 2020-12-15 14:12:16 | [diff] [blame] | 225 | // Returns the number of channels encoded by the sink. This can be less than |
| 226 | // the number_of_channels if down-mixing occur. A value of -1 means an unknown |
| 227 | // number. |
| 228 | virtual int NumPreferredChannels() const { return -1; } |
| 229 | |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 230 | protected: |
| 231 | virtual ~AudioTrackSinkInterface() {} |
| 232 | }; |
| 233 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 234 | // AudioSourceInterface is a reference counted source used for AudioTracks. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 235 | // The same source can be used by multiple AudioTracks. |
Mirko Bonadei | 66e7679 | 2019-04-02 09:33:59 | [diff] [blame] | 236 | class RTC_EXPORT AudioSourceInterface : public MediaSourceInterface { |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 237 | public: |
| 238 | class AudioObserver { |
| 239 | public: |
| 240 | virtual void OnSetVolume(double volume) = 0; |
| 241 | |
| 242 | protected: |
| 243 | virtual ~AudioObserver() {} |
| 244 | }; |
| 245 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 246 | // TODO(deadbeef): Makes all the interfaces pure virtual after they're |
| 247 | // implemented in chromium. |
| 248 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 249 | // Sets the volume of the source. `volume` is in the range of [0, 10]. |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 250 | // TODO(tommi): This method should be on the track and ideally volume should |
| 251 | // be applied in the track in a way that does not affect clones of the track. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 252 | virtual void SetVolume(double volume) {} |
| 253 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 254 | // Registers/unregisters observers to the audio source. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 255 | virtual void RegisterAudioObserver(AudioObserver* observer) {} |
| 256 | virtual void UnregisterAudioObserver(AudioObserver* observer) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 257 | |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 258 | // TODO(tommi): Make pure virtual. |
| 259 | virtual void AddSink(AudioTrackSinkInterface* sink) {} |
| 260 | virtual void RemoveSink(AudioTrackSinkInterface* sink) {} |
Piotr (Peter) Slatala | 95ca6e1 | 2018-11-13 15:57:07 | [diff] [blame] | 261 | |
| 262 | // Returns options for the AudioSource. |
| 263 | // (for some of the settings this approach is broken, e.g. setting |
| 264 | // audio network adaptation on the source is the wrong layer of abstraction). |
| 265 | virtual const cricket::AudioOptions options() const; |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 | [diff] [blame] | 266 | }; |
| 267 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 268 | // Interface of the audio processor used by the audio track to collect |
| 269 | // statistics. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 270 | class AudioProcessorInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 271 | public: |
Ivo Creusen | ae026096 | 2017-11-20 12:07:16 | [diff] [blame] | 272 | struct AudioProcessorStatistics { |
| 273 | bool typing_noise_detected = false; |
Ivo Creusen | 56d46090 | 2017-11-24 16:29:59 | [diff] [blame] | 274 | AudioProcessingStats apm_statistics; |
Ivo Creusen | ae026096 | 2017-11-20 12:07:16 | [diff] [blame] | 275 | }; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 276 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 277 | // Get audio processor statistics. The `has_remote_tracks` argument should be |
Ivo Creusen | ae026096 | 2017-11-20 12:07:16 | [diff] [blame] | 278 | // set if there are active remote tracks (this would usually be true during |
| 279 | // a call). If there are no remote tracks some of the stats will not be set by |
| 280 | // the AudioProcessor, because they only make sense if there is at least one |
| 281 | // remote track. |
Sam Zackrisson | 2812763 | 2018-11-01 10:37:15 | [diff] [blame] | 282 | virtual AudioProcessorStatistics GetStats(bool has_remote_tracks) = 0; |
Ivo Creusen | ae026096 | 2017-11-20 12:07:16 | [diff] [blame] | 283 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 284 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 285 | ~AudioProcessorInterface() override = default; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 286 | }; |
| 287 | |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 288 | class RTC_EXPORT AudioTrackInterface : public MediaStreamTrackInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 289 | public: |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 290 | // TODO(deadbeef): Figure out if the following interface should be const or |
| 291 | // not. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 292 | virtual AudioSourceInterface* GetSource() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 293 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 294 | // Add/Remove a sink that will receive the audio data from the track. |
| 295 | virtual void AddSink(AudioTrackSinkInterface* sink) = 0; |
| 296 | virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 | [diff] [blame] | 297 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 298 | // Get the signal level from the audio track. |
| 299 | // Return true on success, otherwise false. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 300 | // TODO(deadbeef): Change the interface to int GetSignalLevel() and pure |
| 301 | // virtual after it's implemented in chromium. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 302 | virtual bool GetSignalLevel(int* level); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 303 | |
deadbeef | 8d60a94 | 2017-02-27 22:47:33 | [diff] [blame] | 304 | // Get the audio processor used by the audio track. Return null if the track |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 305 | // does not have any processor. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 306 | // TODO(deadbeef): Make the interface pure virtual. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 307 | virtual rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor(); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 | [diff] [blame] | 308 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 309 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 310 | ~AudioTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 311 | }; |
| 312 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 313 | typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > AudioTrackVector; |
| 314 | typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > VideoTrackVector; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 315 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 316 | // C++ version of https://www.w3.org/TR/mediacapture-streams/#mediastream. |
| 317 | // |
| 318 | // A major difference is that remote audio/video tracks (received by a |
| 319 | // PeerConnection/RtpReceiver) are not synchronized simply by adding them to |
| 320 | // the same stream; a session description with the correct "a=msid" attributes |
| 321 | // must be pushed down. |
| 322 | // |
| 323 | // Thus, this interface acts as simply a container for tracks. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 324 | class MediaStreamInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 325 | public NotifierInterface { |
| 326 | public: |
Seth Hampson | 13b8bad | 2018-03-13 23:05:28 | [diff] [blame] | 327 | virtual std::string id() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 328 | |
| 329 | virtual AudioTrackVector GetAudioTracks() = 0; |
| 330 | virtual VideoTrackVector GetVideoTracks() = 0; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 331 | virtual rtc::scoped_refptr<AudioTrackInterface> FindAudioTrack( |
| 332 | const std::string& track_id) = 0; |
| 333 | virtual rtc::scoped_refptr<VideoTrackInterface> FindVideoTrack( |
| 334 | const std::string& track_id) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 335 | |
Niels Möller | e7cc883 | 2022-01-04 14:20:03 | [diff] [blame] | 336 | // Takes ownership of added tracks. |
Harald Alvestrand | 2f7ad28 | 2022-04-21 11:35:43 | [diff] [blame] | 337 | // Note: Default implementations are for avoiding link time errors in |
| 338 | // implementations that mock this API. |
| 339 | // TODO(bugs.webrtc.org/13980): Remove default implementations. |
| 340 | virtual bool AddTrack(rtc::scoped_refptr<AudioTrackInterface> track) { |
| 341 | RTC_CHECK_NOTREACHED(); |
| 342 | } |
| 343 | virtual bool AddTrack(rtc::scoped_refptr<VideoTrackInterface> track) { |
| 344 | RTC_CHECK_NOTREACHED(); |
| 345 | } |
| 346 | virtual bool RemoveTrack(rtc::scoped_refptr<AudioTrackInterface> track) { |
| 347 | RTC_CHECK_NOTREACHED(); |
| 348 | } |
| 349 | virtual bool RemoveTrack(rtc::scoped_refptr<VideoTrackInterface> track) { |
| 350 | RTC_CHECK_NOTREACHED(); |
| 351 | } |
| 352 | // Deprecated: Should use scoped_refptr versions rather than pointers. |
| 353 | [[deprecated("Pass a scoped_refptr")]] virtual bool AddTrack( |
| 354 | AudioTrackInterface* track) { |
| 355 | return AddTrack(rtc::scoped_refptr<AudioTrackInterface>(track)); |
| 356 | } |
| 357 | [[deprecated("Pass a scoped_refptr")]] virtual bool AddTrack( |
| 358 | VideoTrackInterface* track) { |
| 359 | return AddTrack(rtc::scoped_refptr<VideoTrackInterface>(track)); |
| 360 | } |
| 361 | [[deprecated("Pass a scoped_refptr")]] virtual bool RemoveTrack( |
| 362 | AudioTrackInterface* track) { |
| 363 | return RemoveTrack(rtc::scoped_refptr<AudioTrackInterface>(track)); |
| 364 | } |
| 365 | [[deprecated("Pass a scoped_refptr")]] virtual bool RemoveTrack( |
| 366 | VideoTrackInterface* track) { |
| 367 | return RemoveTrack(rtc::scoped_refptr<VideoTrackInterface>(track)); |
| 368 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 369 | |
| 370 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 08:38:31 | [diff] [blame] | 371 | ~MediaStreamInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | } // namespace webrtc |
| 375 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 376 | #endif // API_MEDIA_STREAM_INTERFACE_H_ |