blob: 1ea094b71454aaa2ff337b49a4da9534d3bdc1f3 [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"
perkja3ede6c2016-03-08 01:27:48 +010026#include "webrtc/media/base/mediachannel.h"
nissee73afba2016-01-28 04:47:08 -080027#include "webrtc/media/base/videosinkinterface.h"
nissedb25d2e2016-02-26 01:24:58 -080028#include "webrtc/media/base/videosourceinterface.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30namespace cricket {
31
32class AudioRenderer;
33class VideoCapturer;
34class VideoRenderer;
35class VideoFrame;
36
37} // namespace cricket
38
39namespace webrtc {
40
41// Generic observer interface.
42class ObserverInterface {
43 public:
44 virtual void OnChanged() = 0;
45
46 protected:
47 virtual ~ObserverInterface() {}
48};
49
50class 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.orgd4e598d2014-07-29 17:36:52 +000060class MediaSourceInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 public NotifierInterface {
62 public:
63 enum SourceState {
64 kInitializing,
65 kLive,
66 kEnded,
67 kMuted
68 };
69
70 virtual SourceState state() const = 0;
71
tommi6eca7e32015-12-15 04:27:11 -080072 virtual bool remote() const = 0;
73
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 protected:
75 virtual ~MediaSourceInterface() {}
76};
77
78// Information about a track.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000079class MediaStreamTrackInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 public NotifierInterface {
81 public:
82 enum TrackState {
perkjc8f952d2016-03-23 00:33:56 -070083 kLive,
84 kEnded,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 };
86
deadbeeffac06552015-11-25 11:26:01 -080087 static const char kAudioKind[];
88 static const char kVideoKind[];
89
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 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;
perkj7ca142e2016-03-24 14:19:08 +010095 // TODO(perkj): Remove when Chrome tests doesn't rely on this method.
96 virtual bool set_state(TrackState state) { return true;}
fischman@webrtc.org32001ef2013-08-12 23:26:21 +000097
98 protected:
99 virtual ~MediaStreamTrackInterface() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100};
101
perkja3ede6c2016-03-08 01:27:48 +0100102// VideoTrackSourceInterface is a reference counted source used for VideoTracks.
103// The same source can be used in multiple VideoTracks.
104class VideoTrackSourceInterface
105 : public MediaSourceInterface,
106 public rtc::VideoSourceInterface<cricket::VideoFrame> {
107 public:
108 // Get access to the source implementation of cricket::VideoCapturer.
109 // This can be used for receiving frames and state notifications.
110 // But it should not be used for starting or stopping capturing.
111 // TODO(perkj): We are currently trying to replace all internal use of
112 // cricket::VideoCapturer with rtc::VideoSourceInterface. Once that
113 // refactoring is done,
114 // remove this method.
115 virtual cricket::VideoCapturer* GetVideoCapturer() = 0;
116
117 virtual void Stop() = 0;
118 virtual void Restart() = 0;
119
perkj0d3eef22016-03-09 02:39:17 +0100120 // 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
123 // explicitly setting suitable parameters for screencasts and dont' need this
124 // implicit behavior.
125 virtual bool is_screencast() const = 0;
126
127 // Indicates that the encoder should denoise the video before encoding it.
128 // TODO(perkj): Remove this once denoising is done by the source, and not by
129 // the encoder.
130 virtual bool needs_denoising() const = 0;
perkja3ede6c2016-03-08 01:27:48 +0100131
132 protected:
133 virtual ~VideoTrackSourceInterface() {}
134};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135
nissedb25d2e2016-02-26 01:24:58 -0800136class VideoTrackInterface
137 : public MediaStreamTrackInterface,
138 public rtc::VideoSourceInterface<cricket::VideoFrame> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 public:
nissedb25d2e2016-02-26 01:24:58 -0800140 // Register a video sink for this track.
141 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink,
142 const rtc::VideoSinkWants& wants) override{};
143 void RemoveSink(
144 rtc::VideoSinkInterface<cricket::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
148 protected:
149 virtual ~VideoTrackInterface() {}
150};
151
tommi6eca7e32015-12-15 04:27:11 -0800152// Interface for receiving audio data from a AudioTrack.
153class AudioTrackSinkInterface {
154 public:
155 virtual void OnData(const void* audio_data,
156 int bits_per_sample,
157 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -0800158 size_t number_of_channels,
tommi6eca7e32015-12-15 04:27:11 -0800159 size_t number_of_frames) = 0;
160
161 protected:
162 virtual ~AudioTrackSinkInterface() {}
163};
164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165// AudioSourceInterface is a reference counted source used for AudioTracks.
166// The same source can be used in multiple AudioTracks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167class AudioSourceInterface : public MediaSourceInterface {
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000168 public:
169 class AudioObserver {
170 public:
171 virtual void OnSetVolume(double volume) = 0;
172
173 protected:
174 virtual ~AudioObserver() {}
175 };
176
177 // TODO(xians): Makes all the interface pure virtual after Chrome has their
178 // implementations.
179 // Sets the volume to the source. |volume| is in the range of [0, 10].
Tommif888bb52015-12-12 01:37:01 +0100180 // TODO(tommi): This method should be on the track and ideally volume should
181 // be applied in the track in a way that does not affect clones of the track.
wu@webrtc.orgb9a088b2014-02-13 23:18:49 +0000182 virtual void SetVolume(double volume) {}
183
184 // Registers/unregisters observer to the audio source.
185 virtual void RegisterAudioObserver(AudioObserver* observer) {}
186 virtual void UnregisterAudioObserver(AudioObserver* observer) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187
tommi6eca7e32015-12-15 04:27:11 -0800188 // TODO(tommi): Make pure virtual.
189 virtual void AddSink(AudioTrackSinkInterface* sink) {}
190 virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000191};
192
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000193// Interface of the audio processor used by the audio track to collect
194// statistics.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000195class AudioProcessorInterface : public rtc::RefCountInterface {
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000196 public:
197 struct AudioProcessorStats {
198 AudioProcessorStats() : typing_noise_detected(false),
199 echo_return_loss(0),
200 echo_return_loss_enhancement(0),
201 echo_delay_median_ms(0),
202 aec_quality_min(0.0),
203 echo_delay_std_ms(0) {}
204 ~AudioProcessorStats() {}
205
206 bool typing_noise_detected;
207 int echo_return_loss;
208 int echo_return_loss_enhancement;
209 int echo_delay_median_ms;
210 float aec_quality_min;
211 int echo_delay_std_ms;
212 };
213
214 // Get audio processor statistics.
215 virtual void GetStats(AudioProcessorStats* stats) = 0;
216
217 protected:
218 virtual ~AudioProcessorInterface() {}
219};
220
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221class AudioTrackInterface : public MediaStreamTrackInterface {
222 public:
223 // TODO(xians): Figure out if the following interface should be const or not.
224 virtual AudioSourceInterface* GetSource() const = 0;
225
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000226 // Add/Remove a sink that will receive the audio data from the track.
227 virtual void AddSink(AudioTrackSinkInterface* sink) = 0;
228 virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0;
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000229
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000230 // Get the signal level from the audio track.
231 // Return true on success, otherwise false.
232 // TODO(xians): Change the interface to int GetSignalLevel() and pure virtual
233 // after Chrome has the correct implementation of the interface.
234 virtual bool GetSignalLevel(int* level) { return false; }
235
236 // Get the audio processor used by the audio track. Return NULL if the track
237 // does not have any processor.
238 // TODO(xians): Make the interface pure virtual.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000239 virtual rtc::scoped_refptr<AudioProcessorInterface>
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000240 GetAudioProcessor() { return NULL; }
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000241
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 protected:
243 virtual ~AudioTrackInterface() {}
244};
245
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000246typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 AudioTrackVector;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> >
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 VideoTrackVector;
250
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000251class MediaStreamInterface : public rtc::RefCountInterface,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 public NotifierInterface {
253 public:
254 virtual std::string label() const = 0;
255
256 virtual AudioTrackVector GetAudioTracks() = 0;
257 virtual VideoTrackVector GetVideoTracks() = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 virtual rtc::scoped_refptr<AudioTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 FindAudioTrack(const std::string& track_id) = 0;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000260 virtual rtc::scoped_refptr<VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 FindVideoTrack(const std::string& track_id) = 0;
262
263 virtual bool AddTrack(AudioTrackInterface* track) = 0;
264 virtual bool AddTrack(VideoTrackInterface* track) = 0;
265 virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
266 virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
267
268 protected:
269 virtual ~MediaStreamInterface() {}
270};
271
272} // namespace webrtc
273
Henrik Kjellander15583c12016-02-10 10:53:12 +0100274#endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_