henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [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 +0000 | [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 |
| 14 | // interfaces must be used only with PeerConnection. PeerConnectionManager |
| 15 | // interface provides the factory methods to create MediaStream and MediaTracks. |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #ifndef API_MEDIASTREAMINTERFACE_H_ |
| 18 | #define API_MEDIASTREAMINTERFACE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
pbos | 9baddf2 | 2017-01-02 06:44:41 -0800 | [diff] [blame] | 20 | #include <stddef.h> |
| 21 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 25 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "api/video/video_frame.h" |
Niels Möller | c6ce9c5 | 2018-05-11 11:15:30 +0200 | [diff] [blame] | 27 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 28 | #include "api/video/video_source_interface.h" |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 29 | #include "modules/audio_processing/include/audio_processing_statistics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "rtc_base/refcount.h" |
| 31 | #include "rtc_base/scoped_ref_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | namespace webrtc { |
| 34 | |
| 35 | // Generic observer interface. |
| 36 | class ObserverInterface { |
| 37 | public: |
| 38 | virtual void OnChanged() = 0; |
| 39 | |
| 40 | protected: |
| 41 | virtual ~ObserverInterface() {} |
| 42 | }; |
| 43 | |
| 44 | class NotifierInterface { |
| 45 | public: |
| 46 | virtual void RegisterObserver(ObserverInterface* observer) = 0; |
| 47 | virtual void UnregisterObserver(ObserverInterface* observer) = 0; |
| 48 | |
| 49 | virtual ~NotifierInterface() {} |
| 50 | }; |
| 51 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 52 | // Base class for sources. A MediaStreamTrack has an underlying source that |
| 53 | // provides media. A source can be shared by multiple tracks. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 54 | class MediaSourceInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | public NotifierInterface { |
| 56 | public: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 57 | enum SourceState { kInitializing, kLive, kEnded, kMuted }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 59 | virtual SourceState state() const = 0; |
| 60 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 61 | virtual bool remote() const = 0; |
| 62 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 64 | ~MediaSourceInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 67 | // C++ version of MediaStreamTrack. |
| 68 | // See: https://www.w3.org/TR/mediacapture-streams/#mediastreamtrack |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 69 | class MediaStreamTrackInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | public NotifierInterface { |
| 71 | public: |
| 72 | enum TrackState { |
perkj | c8f952d | 2016-03-23 00:33:56 -0700 | [diff] [blame] | 73 | kLive, |
| 74 | kEnded, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 77 | static const char kAudioKind[]; |
| 78 | static const char kVideoKind[]; |
| 79 | |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 80 | // The kind() method must return kAudioKind only if the object is a |
| 81 | // subclass of AudioTrackInterface, and kVideoKind only if the |
| 82 | // object is a subclass of VideoTrackInterface. It is typically used |
| 83 | // to protect a static_cast<> to the corresponding subclass. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | virtual std::string kind() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 85 | |
| 86 | // Track identifier. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | virtual std::string id() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 88 | |
| 89 | // A disabled track will produce silence (if audio) or black frames (if |
| 90 | // video). Can be disabled and re-enabled. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | virtual bool enabled() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | virtual bool set_enabled(bool enable) = 0; |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 +0000 | [diff] [blame] | 93 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 94 | // Live or ended. A track will never be live again after becoming ended. |
| 95 | virtual TrackState state() const = 0; |
| 96 | |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 +0000 | [diff] [blame] | 97 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 98 | ~MediaStreamTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 101 | // VideoTrackSourceInterface is a reference counted source used for |
| 102 | // VideoTracks. The same source can be used by multiple VideoTracks. |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 103 | // VideoTrackSourceInterface is designed to be invoked on the signaling thread |
| 104 | // except for rtc::VideoSourceInterface<VideoFrame> methods that will be invoked |
| 105 | // on the worker thread via a VideoTrack. A custom implementation of a source |
| 106 | // can inherit AdaptedVideoTrackSource instead of directly implementing this |
| 107 | // interface. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 108 | class VideoTrackSourceInterface : public MediaSourceInterface, |
| 109 | public rtc::VideoSourceInterface<VideoFrame> { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 110 | public: |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 111 | struct Stats { |
| 112 | // Original size of captured frame, before video adaptation. |
| 113 | int input_width; |
| 114 | int input_height; |
| 115 | }; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 116 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 117 | // Indicates that parameters suitable for screencasts should be automatically |
| 118 | // applied to RtpSenders. |
| 119 | // TODO(perkj): Remove these once all known applications have moved to |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 120 | // explicitly setting suitable parameters for screencasts and don't need this |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 121 | // implicit behavior. |
| 122 | virtual bool is_screencast() const = 0; |
| 123 | |
Per | c0d31e9 | 2016-03-31 17:23:39 +0200 | [diff] [blame] | 124 | // Indicates that the encoder should denoise video before encoding it. |
| 125 | // If it is not set, the default configuration is used which is different |
| 126 | // depending on video codec. |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 127 | // TODO(perkj): Remove this once denoising is done by the source, and not by |
| 128 | // the encoder. |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 129 | virtual absl::optional<bool> needs_denoising() const = 0; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 130 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 131 | // Returns false if no stats are available, e.g, for a remote source, or a |
| 132 | // source which has not seen its first frame yet. |
| 133 | // |
| 134 | // Implementation should avoid blocking. |
nisse | fcc640f | 2016-04-01 01:10:42 -0700 | [diff] [blame] | 135 | virtual bool GetStats(Stats* stats) = 0; |
| 136 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 137 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 138 | ~VideoTrackSourceInterface() override = default; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 139 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 141 | // VideoTrackInterface is designed to be invoked on the signaling thread except |
| 142 | // for rtc::VideoSourceInterface<VideoFrame> methods that must be invoked |
| 143 | // on the worker thread. |
| 144 | // PeerConnectionFactory::CreateVideoTrack can be used for creating a VideoTrack |
| 145 | // that ensures thread safety and that all methods are called on the right |
| 146 | // thread. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 147 | class VideoTrackInterface : public MediaStreamTrackInterface, |
| 148 | public rtc::VideoSourceInterface<VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | public: |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 150 | // Video track content hint, used to override the source is_screencast |
| 151 | // property. |
Harald Alvestrand | c19ab07 | 2018-06-18 08:53:10 +0200 | [diff] [blame] | 152 | // See https://crbug.com/653531 and https://w3c.github.io/mst-content-hint. |
| 153 | enum class ContentHint { kNone, kFluid, kDetailed, kText }; |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 154 | |
mbonadei | 539d104 | 2017-07-10 02:40:49 -0700 | [diff] [blame] | 155 | // Register a video sink for this track. Used to connect the track to the |
| 156 | // underlying video engine. |
| 157 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 158 | const rtc::VideoSinkWants& wants) override {} |
| 159 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {} |
| 160 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 161 | virtual VideoTrackSourceInterface* GetSource() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 163 | virtual ContentHint content_hint() const; |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 164 | virtual void set_content_hint(ContentHint hint) {} |
| 165 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 167 | ~VideoTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 170 | // Interface for receiving audio data from a AudioTrack. |
| 171 | class AudioTrackSinkInterface { |
| 172 | public: |
| 173 | virtual void OnData(const void* audio_data, |
| 174 | int bits_per_sample, |
| 175 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 176 | size_t number_of_channels, |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 177 | size_t number_of_frames) = 0; |
| 178 | |
| 179 | protected: |
| 180 | virtual ~AudioTrackSinkInterface() {} |
| 181 | }; |
| 182 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | // AudioSourceInterface is a reference counted source used for AudioTracks. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 184 | // The same source can be used by multiple AudioTracks. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | class AudioSourceInterface : public MediaSourceInterface { |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 186 | public: |
| 187 | class AudioObserver { |
| 188 | public: |
| 189 | virtual void OnSetVolume(double volume) = 0; |
| 190 | |
| 191 | protected: |
| 192 | virtual ~AudioObserver() {} |
| 193 | }; |
| 194 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 195 | // TODO(deadbeef): Makes all the interfaces pure virtual after they're |
| 196 | // implemented in chromium. |
| 197 | |
| 198 | // Sets the volume of the source. |volume| is in the range of [0, 10]. |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 199 | // TODO(tommi): This method should be on the track and ideally volume should |
| 200 | // 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 +0000 | [diff] [blame] | 201 | virtual void SetVolume(double volume) {} |
| 202 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 203 | // Registers/unregisters observers to the audio source. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 204 | virtual void RegisterAudioObserver(AudioObserver* observer) {} |
| 205 | virtual void UnregisterAudioObserver(AudioObserver* observer) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 207 | // TODO(tommi): Make pure virtual. |
| 208 | virtual void AddSink(AudioTrackSinkInterface* sink) {} |
| 209 | virtual void RemoveSink(AudioTrackSinkInterface* sink) {} |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 212 | // Interface of the audio processor used by the audio track to collect |
| 213 | // statistics. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 214 | class AudioProcessorInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 215 | public: |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 216 | // Deprecated, use AudioProcessorStatistics instead. |
| 217 | // TODO(ivoc): Remove this when all implementations have switched to the new |
| 218 | // GetStats function. See b/67926135. |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 219 | struct AudioProcessorStats { |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 220 | AudioProcessorStats() |
| 221 | : typing_noise_detected(false), |
| 222 | echo_return_loss(0), |
| 223 | echo_return_loss_enhancement(0), |
| 224 | echo_delay_median_ms(0), |
| 225 | echo_delay_std_ms(0), |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 226 | residual_echo_likelihood(0.0f), |
| 227 | residual_echo_likelihood_recent_max(0.0f), |
| 228 | aec_divergent_filter_fraction(0.0) {} |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 229 | ~AudioProcessorStats() {} |
| 230 | |
| 231 | bool typing_noise_detected; |
| 232 | int echo_return_loss; |
| 233 | int echo_return_loss_enhancement; |
| 234 | int echo_delay_median_ms; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 235 | int echo_delay_std_ms; |
ivoc | 8c63a82 | 2016-10-21 04:10:03 -0700 | [diff] [blame] | 236 | float residual_echo_likelihood; |
ivoc | 4e477a1 | 2017-01-15 08:29:46 -0800 | [diff] [blame] | 237 | float residual_echo_likelihood_recent_max; |
Minyue | 2a8a78c | 2016-04-07 16:48:15 +0200 | [diff] [blame] | 238 | float aec_divergent_filter_fraction; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 239 | }; |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 240 | // This struct maintains the optionality of the stats, and will replace the |
| 241 | // regular stats struct when all users have been updated. |
| 242 | struct AudioProcessorStatistics { |
| 243 | bool typing_noise_detected = false; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 244 | AudioProcessingStats apm_statistics; |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 245 | }; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 246 | |
| 247 | // Get audio processor statistics. |
Ivo Creusen | 21eb9fc | 2017-12-12 10:45:51 +0100 | [diff] [blame] | 248 | virtual void GetStats(AudioProcessorStats* stats); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 249 | |
Ivo Creusen | ae02609 | 2017-11-20 13:07:16 +0100 | [diff] [blame] | 250 | // Get audio processor statistics. The |has_remote_tracks| argument should be |
| 251 | // set if there are active remote tracks (this would usually be true during |
| 252 | // a call). If there are no remote tracks some of the stats will not be set by |
| 253 | // the AudioProcessor, because they only make sense if there is at least one |
| 254 | // remote track. |
| 255 | // TODO(ivoc): Make pure virtual when all implementions are updated. |
| 256 | virtual AudioProcessorStatistics GetStats(bool has_remote_tracks); |
| 257 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 258 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 259 | ~AudioProcessorInterface() override = default; |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 262 | class AudioTrackInterface : public MediaStreamTrackInterface { |
| 263 | public: |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 264 | // TODO(deadbeef): Figure out if the following interface should be const or |
| 265 | // not. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 266 | virtual AudioSourceInterface* GetSource() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 267 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 268 | // Add/Remove a sink that will receive the audio data from the track. |
| 269 | virtual void AddSink(AudioTrackSinkInterface* sink) = 0; |
| 270 | virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 271 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 272 | // Get the signal level from the audio track. |
| 273 | // Return true on success, otherwise false. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 274 | // TODO(deadbeef): Change the interface to int GetSignalLevel() and pure |
| 275 | // virtual after it's implemented in chromium. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 276 | virtual bool GetSignalLevel(int* level); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 277 | |
deadbeef | 8d60a94 | 2017-02-27 14:47:33 -0800 | [diff] [blame] | 278 | // Get the audio processor used by the audio track. Return null if the track |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 279 | // does not have any processor. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 280 | // TODO(deadbeef): Make the interface pure virtual. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 281 | virtual rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor(); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 282 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 283 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 284 | ~AudioTrackInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | }; |
| 286 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 287 | typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > AudioTrackVector; |
| 288 | typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > VideoTrackVector; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 290 | // C++ version of https://www.w3.org/TR/mediacapture-streams/#mediastream. |
| 291 | // |
| 292 | // A major difference is that remote audio/video tracks (received by a |
| 293 | // PeerConnection/RtpReceiver) are not synchronized simply by adding them to |
| 294 | // the same stream; a session description with the correct "a=msid" attributes |
| 295 | // must be pushed down. |
| 296 | // |
| 297 | // Thus, this interface acts as simply a container for tracks. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 298 | class MediaStreamInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 299 | public NotifierInterface { |
| 300 | public: |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 301 | virtual std::string id() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | |
| 303 | virtual AudioTrackVector GetAudioTracks() = 0; |
| 304 | virtual VideoTrackVector GetVideoTracks() = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 305 | virtual rtc::scoped_refptr<AudioTrackInterface> FindAudioTrack( |
| 306 | const std::string& track_id) = 0; |
| 307 | virtual rtc::scoped_refptr<VideoTrackInterface> FindVideoTrack( |
| 308 | const std::string& track_id) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | |
| 310 | virtual bool AddTrack(AudioTrackInterface* track) = 0; |
| 311 | virtual bool AddTrack(VideoTrackInterface* track) = 0; |
| 312 | virtual bool RemoveTrack(AudioTrackInterface* track) = 0; |
| 313 | virtual bool RemoveTrack(VideoTrackInterface* track) = 0; |
| 314 | |
| 315 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 316 | ~MediaStreamInterface() override = default; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | } // namespace webrtc |
| 320 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 321 | #endif // API_MEDIASTREAMINTERFACE_H_ |