blob: eb51633e2baed7cc011667f99304db319d12b6d0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
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 Kjellander15583c12016-02-10 10:53:12 +010017#ifndef WEBRTC_API_MEDIASTREAMINTERFACE_H_
18#define WEBRTC_API_MEDIASTREAMINTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
20#include <string>
21#include <vector>
22
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000023#include "webrtc/base/basictypes.h"
24#include "webrtc/base/refcount.h"
25#include "webrtc/base/scoped_ref_ptr.h"
Perc0d31e92016-03-31 17:23:39 +020026#include "webrtc/base/optional.h"
perkja3ede6c2016-03-08 01:27:48 +010027#include "webrtc/media/base/mediachannel.h"
nissee73afba2016-01-28 04:47:08 -080028#include "webrtc/media/base/videosinkinterface.h"
nissedb25d2e2016-02-26 01:24:58 -080029#include "webrtc/media/base/videosourceinterface.h"
nisseacd935b2016-11-11 03:55:13 -080030#include "webrtc/video_frame.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032namespace webrtc {
33
34// Generic observer interface.
35class ObserverInterface {
36 public:
37 virtual void OnChanged() = 0;
38
39 protected:
40 virtual ~ObserverInterface() {}
41};
42
43class NotifierInterface {
44 public:
45 virtual void RegisterObserver(ObserverInterface* observer) = 0;
46 virtual void UnregisterObserver(ObserverInterface* observer) = 0;
47
48 virtual ~NotifierInterface() {}
49};
50
51// Base class for sources. A MediaStreamTrack have an underlying source that
52// provide media. A source can be shared with multiple tracks.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053class MediaSourceInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 public NotifierInterface {
55 public:
56 enum SourceState {
57 kInitializing,
58 kLive,
59 kEnded,
60 kMuted
61 };
62
63 virtual SourceState state() const = 0;
64
tommi6eca7e32015-12-15 04:27:11 -080065 virtual bool remote() const = 0;
66
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 protected:
68 virtual ~MediaSourceInterface() {}
69};
70
71// Information about a track.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000072class MediaStreamTrackInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 public NotifierInterface {
74 public:
75 enum TrackState {
perkjc8f952d2016-03-23 00:33:56 -070076 kLive,
77 kEnded,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 };
79
deadbeeffac06552015-11-25 11:26:01 -080080 static const char kAudioKind[];
81 static const char kVideoKind[];
82
nissefcc640f2016-04-01 01:10:42 -070083 // 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.org28e20752013-07-10 00:45:36 +000087 virtual std::string kind() const = 0;
88 virtual std::string id() const = 0;
89 virtual bool enabled() const = 0;
90 virtual TrackState state() const = 0;
91 virtual bool set_enabled(bool enable) = 0;
fischman@webrtc.org32001ef2013-08-12 23:26:21 +000092
93 protected:
94 virtual ~MediaStreamTrackInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095};
96
perkja3ede6c2016-03-08 01:27:48 +010097// VideoTrackSourceInterface is a reference counted source used for VideoTracks.
98// The same source can be used in multiple VideoTracks.
99class VideoTrackSourceInterface
100 : public MediaSourceInterface,
nisseacd935b2016-11-11 03:55:13 -0800101 public rtc::VideoSourceInterface<VideoFrame> {
perkja3ede6c2016-03-08 01:27:48 +0100102 public:
nissefcc640f2016-04-01 01:10:42 -0700103 struct Stats {
104 // Original size of captured frame, before video adaptation.
105 int input_width;
106 int input_height;
107 };
perkja3ede6c2016-03-08 01:27:48 +0100108
perkj0d3eef22016-03-09 02:39:17 +0100109 // Indicates that parameters suitable for screencasts should be automatically
110 // applied to RtpSenders.
111 // TODO(perkj): Remove these once all known applications have moved to
112 // explicitly setting suitable parameters for screencasts and dont' need this
113 // implicit behavior.
114 virtual bool is_screencast() const = 0;
115
Perc0d31e92016-03-31 17:23:39 +0200116 // Indicates that the encoder should denoise video before encoding it.
117 // If it is not set, the default configuration is used which is different
118 // depending on video codec.
perkj0d3eef22016-03-09 02:39:17 +0100119 // TODO(perkj): Remove this once denoising is done by the source, and not by
120 // the encoder.
Perc0d31e92016-03-31 17:23:39 +0200121 virtual rtc::Optional<bool> needs_denoising() const = 0;
perkja3ede6c2016-03-08 01:27:48 +0100122
nissefcc640f2016-04-01 01:10:42 -0700123 // Returns false if no stats are available, e.g, for a remote
124 // source, or a source which has not seen its first frame yet.
125 // Should avoid blocking.
126 virtual bool GetStats(Stats* stats) = 0;
127
perkja3ede6c2016-03-08 01:27:48 +0100128 protected:
129 virtual ~VideoTrackSourceInterface() {}
130};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
nissedb25d2e2016-02-26 01:24:58 -0800132class VideoTrackInterface
133 : public MediaStreamTrackInterface,
nisseacd935b2016-11-11 03:55:13 -0800134 public rtc::VideoSourceInterface<VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 public:
pbos5214a0a2016-12-16 15:39:11 -0800136 // Video track content hint, used to override the source is_screencast
137 // property.
138 // See https://crbug.com/653531 and https://github.com/WICG/mst-content-hint.
139 enum class ContentHint { kNone, kFluid, kDetailed };
140
nissedb25d2e2016-02-26 01:24:58 -0800141 // Register a video sink for this track.
nisseacd935b2016-11-11 03:55:13 -0800142 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
pbos5214a0a2016-12-16 15:39:11 -0800143 const rtc::VideoSinkWants& wants) override {}
144 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145
perkja3ede6c2016-03-08 01:27:48 +0100146 virtual VideoTrackSourceInterface* GetSource() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147
pbos5214a0a2016-12-16 15:39:11 -0800148 virtual ContentHint content_hint() const { return ContentHint::kNone; }
149 virtual void set_content_hint(ContentHint hint) {}
150
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 protected:
152 virtual ~VideoTrackInterface() {}
153};
154
tommi6eca7e32015-12-15 04:27:11 -0800155// Interface for receiving audio data from a AudioTrack.
156class AudioTrackSinkInterface {
157 public:
158 virtual void OnData(const void* audio_data,
159 int bits_per_sample,
160 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -0800161 size_t number_of_channels,
tommi6eca7e32015-12-15 04:27:11 -0800162 size_t number_of_frames) = 0;
163
164 protected:
165 virtual ~AudioTrackSinkInterface() {}
166};
167
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168// AudioSourceInterface is a reference counted source used for AudioTracks.
169// The same source can be used in multiple AudioTracks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170class AudioSourceInterface : public MediaSourceInterface {
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000171 public:
172 class AudioObserver {
173 public:
174 virtual void OnSetVolume(double volume) = 0;
175
176 protected:
177 virtual ~AudioObserver() {}
178 };
179
180 // TODO(xians): Makes all the interface pure virtual after Chrome has their
181 // implementations.
182 // Sets the volume to the source. |volume| is in the range of [0, 10].
Tommif888bb52015-12-12 01:37:01 +0100183 // TODO(tommi): This method should be on the track and ideally volume should
184 // be applied in the track in a way that does not affect clones of the track.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000185 virtual void SetVolume(double volume) {}
186
187 // Registers/unregisters observer to the audio source.
188 virtual void RegisterAudioObserver(AudioObserver* observer) {}
189 virtual void UnregisterAudioObserver(AudioObserver* observer) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190
tommi6eca7e32015-12-15 04:27:11 -0800191 // TODO(tommi): Make pure virtual.
192 virtual void AddSink(AudioTrackSinkInterface* sink) {}
193 virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000194};
195
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000196// Interface of the audio processor used by the audio track to collect
197// statistics.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000198class AudioProcessorInterface : public rtc::RefCountInterface {
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000199 public:
200 struct AudioProcessorStats {
201 AudioProcessorStats() : typing_noise_detected(false),
202 echo_return_loss(0),
203 echo_return_loss_enhancement(0),
204 echo_delay_median_ms(0),
Minyue2a8a78c2016-04-07 16:48:15 +0200205 echo_delay_std_ms(0),
ivoc8c63a822016-10-21 04:10:03 -0700206 aec_quality_min(0.0),
207 residual_echo_likelihood(0.0f),
Minyue2a8a78c2016-04-07 16:48:15 +0200208 aec_divergent_filter_fraction(0.0) {}
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000209 ~AudioProcessorStats() {}
210
211 bool typing_noise_detected;
212 int echo_return_loss;
213 int echo_return_loss_enhancement;
214 int echo_delay_median_ms;
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000215 int echo_delay_std_ms;
ivoc8c63a822016-10-21 04:10:03 -0700216 float aec_quality_min;
217 float residual_echo_likelihood;
Minyue2a8a78c2016-04-07 16:48:15 +0200218 float aec_divergent_filter_fraction;
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000219 };
220
221 // Get audio processor statistics.
222 virtual void GetStats(AudioProcessorStats* stats) = 0;
223
224 protected:
225 virtual ~AudioProcessorInterface() {}
226};
227
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228class AudioTrackInterface : public MediaStreamTrackInterface {
229 public:
230 // TODO(xians): Figure out if the following interface should be const or not.
231 virtual AudioSourceInterface* GetSource() const = 0;
232
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000233 // Add/Remove a sink that will receive the audio data from the track.
234 virtual void AddSink(AudioTrackSinkInterface* sink) = 0;
235 virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0;
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000236
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000237 // Get the signal level from the audio track.
238 // Return true on success, otherwise false.
239 // TODO(xians): Change the interface to int GetSignalLevel() and pure virtual
240 // after Chrome has the correct implementation of the interface.
241 virtual bool GetSignalLevel(int* level) { return false; }
242
243 // Get the audio processor used by the audio track. Return NULL if the track
244 // does not have any processor.
245 // TODO(xians): Make the interface pure virtual.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000246 virtual rtc::scoped_refptr<AudioProcessorInterface>
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000247 GetAudioProcessor() { return NULL; }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000248
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 protected:
250 virtual ~AudioTrackInterface() {}
251};
252
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000253typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 AudioTrackVector;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000255typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 VideoTrackVector;
257
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258class MediaStreamInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 public NotifierInterface {
260 public:
261 virtual std::string label() const = 0;
262
263 virtual AudioTrackVector GetAudioTracks() = 0;
264 virtual VideoTrackVector GetVideoTracks() = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000265 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 FindAudioTrack(const std::string& track_id) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000267 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 FindVideoTrack(const std::string& track_id) = 0;
269
270 virtual bool AddTrack(AudioTrackInterface* track) = 0;
271 virtual bool AddTrack(VideoTrackInterface* track) = 0;
272 virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
273 virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
274
275 protected:
276 virtual ~MediaStreamInterface() {}
277};
278
279} // namespace webrtc
280
Henrik Kjellander15583c12016-02-10 10:53:12 +0100281#endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_