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 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 17 | #ifndef WEBRTC_API_MEDIASTREAMINTERFACE_H_ |
| 18 | #define WEBRTC_API_MEDIASTREAMINTERFACE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 23 | #include "webrtc/base/basictypes.h" |
| 24 | #include "webrtc/base/refcount.h" |
| 25 | #include "webrtc/base/scoped_ref_ptr.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 26 | #include "webrtc/media/base/mediachannel.h" |
nisse | e73afba | 2016-01-28 04:47:08 -0800 | [diff] [blame] | 27 | #include "webrtc/media/base/videosinkinterface.h" |
nisse | db25d2e | 2016-02-26 01:24:58 -0800 | [diff] [blame] | 28 | #include "webrtc/media/base/videosourceinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
| 30 | namespace cricket { |
| 31 | |
| 32 | class AudioRenderer; |
| 33 | class VideoCapturer; |
| 34 | class VideoRenderer; |
| 35 | class VideoFrame; |
| 36 | |
| 37 | } // namespace cricket |
| 38 | |
| 39 | namespace webrtc { |
| 40 | |
| 41 | // Generic observer interface. |
| 42 | class ObserverInterface { |
| 43 | public: |
| 44 | virtual void OnChanged() = 0; |
| 45 | |
| 46 | protected: |
| 47 | virtual ~ObserverInterface() {} |
| 48 | }; |
| 49 | |
| 50 | class NotifierInterface { |
| 51 | public: |
| 52 | virtual void RegisterObserver(ObserverInterface* observer) = 0; |
| 53 | virtual void UnregisterObserver(ObserverInterface* observer) = 0; |
| 54 | |
| 55 | virtual ~NotifierInterface() {} |
| 56 | }; |
| 57 | |
| 58 | // Base class for sources. A MediaStreamTrack have an underlying source that |
| 59 | // provide media. A source can be shared with multiple tracks. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 60 | class MediaSourceInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | public NotifierInterface { |
| 62 | public: |
| 63 | enum SourceState { |
| 64 | kInitializing, |
| 65 | kLive, |
| 66 | kEnded, |
| 67 | kMuted |
| 68 | }; |
| 69 | |
| 70 | virtual SourceState state() const = 0; |
| 71 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 72 | virtual bool remote() const = 0; |
| 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | protected: |
| 75 | virtual ~MediaSourceInterface() {} |
| 76 | }; |
| 77 | |
| 78 | // Information about a track. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 79 | class MediaStreamTrackInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | public NotifierInterface { |
| 81 | public: |
| 82 | enum TrackState { |
perkj | c8f952d | 2016-03-23 00:33:56 -0700 | [diff] [blame] | 83 | kLive, |
| 84 | kEnded, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 87 | static const char kAudioKind[]; |
| 88 | static const char kVideoKind[]; |
| 89 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | virtual std::string kind() const = 0; |
| 91 | virtual std::string id() const = 0; |
| 92 | virtual bool enabled() const = 0; |
| 93 | virtual TrackState state() const = 0; |
| 94 | virtual bool set_enabled(bool enable) = 0; |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 +0000 | [diff] [blame] | 95 | |
| 96 | protected: |
| 97 | virtual ~MediaStreamTrackInterface() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 100 | // VideoTrackSourceInterface is a reference counted source used for VideoTracks. |
| 101 | // The same source can be used in multiple VideoTracks. |
| 102 | class VideoTrackSourceInterface |
| 103 | : public MediaSourceInterface, |
| 104 | public rtc::VideoSourceInterface<cricket::VideoFrame> { |
| 105 | public: |
| 106 | // Get access to the source implementation of cricket::VideoCapturer. |
| 107 | // This can be used for receiving frames and state notifications. |
| 108 | // But it should not be used for starting or stopping capturing. |
| 109 | // TODO(perkj): We are currently trying to replace all internal use of |
| 110 | // cricket::VideoCapturer with rtc::VideoSourceInterface. Once that |
| 111 | // refactoring is done, |
| 112 | // remove this method. |
| 113 | virtual cricket::VideoCapturer* GetVideoCapturer() = 0; |
| 114 | |
| 115 | virtual void Stop() = 0; |
| 116 | virtual void Restart() = 0; |
| 117 | |
perkj | 0d3eef2 | 2016-03-09 02:39:17 +0100 | [diff] [blame] | 118 | // Indicates that parameters suitable for screencasts should be automatically |
| 119 | // applied to RtpSenders. |
| 120 | // TODO(perkj): Remove these once all known applications have moved to |
| 121 | // explicitly setting suitable parameters for screencasts and dont' need this |
| 122 | // implicit behavior. |
| 123 | virtual bool is_screencast() const = 0; |
| 124 | |
| 125 | // Indicates that the encoder should denoise the video before encoding it. |
| 126 | // TODO(perkj): Remove this once denoising is done by the source, and not by |
| 127 | // the encoder. |
| 128 | virtual bool needs_denoising() const = 0; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 129 | |
| 130 | protected: |
| 131 | virtual ~VideoTrackSourceInterface() {} |
| 132 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | |
nisse | db25d2e | 2016-02-26 01:24:58 -0800 | [diff] [blame] | 134 | class VideoTrackInterface |
| 135 | : public MediaStreamTrackInterface, |
| 136 | public rtc::VideoSourceInterface<cricket::VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | public: |
nisse | db25d2e | 2016-02-26 01:24:58 -0800 | [diff] [blame] | 138 | // Register a video sink for this track. |
| 139 | void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, |
| 140 | const rtc::VideoSinkWants& wants) override{}; |
| 141 | void RemoveSink( |
| 142 | rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override{}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 144 | virtual VideoTrackSourceInterface* GetSource() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | |
| 146 | protected: |
| 147 | virtual ~VideoTrackInterface() {} |
| 148 | }; |
| 149 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 150 | // Interface for receiving audio data from a AudioTrack. |
| 151 | class AudioTrackSinkInterface { |
| 152 | public: |
| 153 | virtual void OnData(const void* audio_data, |
| 154 | int bits_per_sample, |
| 155 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 156 | size_t number_of_channels, |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 157 | size_t number_of_frames) = 0; |
| 158 | |
| 159 | protected: |
| 160 | virtual ~AudioTrackSinkInterface() {} |
| 161 | }; |
| 162 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | // AudioSourceInterface is a reference counted source used for AudioTracks. |
| 164 | // The same source can be used in multiple AudioTracks. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | class AudioSourceInterface : public MediaSourceInterface { |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 166 | public: |
| 167 | class AudioObserver { |
| 168 | public: |
| 169 | virtual void OnSetVolume(double volume) = 0; |
| 170 | |
| 171 | protected: |
| 172 | virtual ~AudioObserver() {} |
| 173 | }; |
| 174 | |
| 175 | // TODO(xians): Makes all the interface pure virtual after Chrome has their |
| 176 | // implementations. |
| 177 | // Sets the volume to the source. |volume| is in the range of [0, 10]. |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 178 | // TODO(tommi): This method should be on the track and ideally volume should |
| 179 | // 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] | 180 | virtual void SetVolume(double volume) {} |
| 181 | |
| 182 | // Registers/unregisters observer to the audio source. |
| 183 | virtual void RegisterAudioObserver(AudioObserver* observer) {} |
| 184 | virtual void UnregisterAudioObserver(AudioObserver* observer) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 186 | // TODO(tommi): Make pure virtual. |
| 187 | virtual void AddSink(AudioTrackSinkInterface* sink) {} |
| 188 | virtual void RemoveSink(AudioTrackSinkInterface* sink) {} |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 191 | // Interface of the audio processor used by the audio track to collect |
| 192 | // statistics. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 193 | class AudioProcessorInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 194 | public: |
| 195 | struct AudioProcessorStats { |
| 196 | AudioProcessorStats() : typing_noise_detected(false), |
| 197 | echo_return_loss(0), |
| 198 | echo_return_loss_enhancement(0), |
| 199 | echo_delay_median_ms(0), |
| 200 | aec_quality_min(0.0), |
| 201 | echo_delay_std_ms(0) {} |
| 202 | ~AudioProcessorStats() {} |
| 203 | |
| 204 | bool typing_noise_detected; |
| 205 | int echo_return_loss; |
| 206 | int echo_return_loss_enhancement; |
| 207 | int echo_delay_median_ms; |
| 208 | float aec_quality_min; |
| 209 | int echo_delay_std_ms; |
| 210 | }; |
| 211 | |
| 212 | // Get audio processor statistics. |
| 213 | virtual void GetStats(AudioProcessorStats* stats) = 0; |
| 214 | |
| 215 | protected: |
| 216 | virtual ~AudioProcessorInterface() {} |
| 217 | }; |
| 218 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | class AudioTrackInterface : public MediaStreamTrackInterface { |
| 220 | public: |
| 221 | // TODO(xians): Figure out if the following interface should be const or not. |
| 222 | virtual AudioSourceInterface* GetSource() const = 0; |
| 223 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 224 | // Add/Remove a sink that will receive the audio data from the track. |
| 225 | virtual void AddSink(AudioTrackSinkInterface* sink) = 0; |
| 226 | virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 227 | |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 228 | // Get the signal level from the audio track. |
| 229 | // Return true on success, otherwise false. |
| 230 | // TODO(xians): Change the interface to int GetSignalLevel() and pure virtual |
| 231 | // after Chrome has the correct implementation of the interface. |
| 232 | virtual bool GetSignalLevel(int* level) { return false; } |
| 233 | |
| 234 | // Get the audio processor used by the audio track. Return NULL if the track |
| 235 | // does not have any processor. |
| 236 | // TODO(xians): Make the interface pure virtual. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 237 | virtual rtc::scoped_refptr<AudioProcessorInterface> |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 238 | GetAudioProcessor() { return NULL; } |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 239 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | protected: |
| 241 | virtual ~AudioTrackInterface() {} |
| 242 | }; |
| 243 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 244 | typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | AudioTrackVector; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 246 | typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | VideoTrackVector; |
| 248 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 249 | class MediaStreamInterface : public rtc::RefCountInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 250 | public NotifierInterface { |
| 251 | public: |
| 252 | virtual std::string label() const = 0; |
| 253 | |
| 254 | virtual AudioTrackVector GetAudioTracks() = 0; |
| 255 | virtual VideoTrackVector GetVideoTracks() = 0; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 256 | virtual rtc::scoped_refptr<AudioTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | FindAudioTrack(const std::string& track_id) = 0; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 258 | virtual rtc::scoped_refptr<VideoTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 259 | FindVideoTrack(const std::string& track_id) = 0; |
| 260 | |
| 261 | virtual bool AddTrack(AudioTrackInterface* track) = 0; |
| 262 | virtual bool AddTrack(VideoTrackInterface* track) = 0; |
| 263 | virtual bool RemoveTrack(AudioTrackInterface* track) = 0; |
| 264 | virtual bool RemoveTrack(VideoTrackInterface* track) = 0; |
| 265 | |
| 266 | protected: |
| 267 | virtual ~MediaStreamInterface() {} |
| 268 | }; |
| 269 | |
| 270 | } // namespace webrtc |
| 271 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 272 | #endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_ |