Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: talk/app/webrtc/mediastreaminterface.h

Issue 1610243002: Move talk/app/webrtc to webrtc/api (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed processing of api.gyp for Chromium builds Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/mediastreamhandler.cc ('k') | talk/app/webrtc/mediastreamobserver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2012 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 // This file contains interfaces for MediaStream, MediaTrack and MediaSource.
29 // These interfaces are used for implementing MediaStream and MediaTrack as
30 // defined in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These
31 // interfaces must be used only with PeerConnection. PeerConnectionManager
32 // interface provides the factory methods to create MediaStream and MediaTracks.
33
34 #ifndef TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_
35 #define TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_
36
37 #include <string>
38 #include <vector>
39
40 #include "webrtc/base/basictypes.h"
41 #include "webrtc/base/refcount.h"
42 #include "webrtc/base/scoped_ref_ptr.h"
43 #include "webrtc/media/base/videosinkinterface.h"
44
45 namespace cricket {
46
47 class AudioRenderer;
48 class VideoCapturer;
49 class VideoRenderer;
50 class VideoFrame;
51
52 } // namespace cricket
53
54 namespace webrtc {
55
56 // Generic observer interface.
57 class ObserverInterface {
58 public:
59 virtual void OnChanged() = 0;
60
61 protected:
62 virtual ~ObserverInterface() {}
63 };
64
65 class NotifierInterface {
66 public:
67 virtual void RegisterObserver(ObserverInterface* observer) = 0;
68 virtual void UnregisterObserver(ObserverInterface* observer) = 0;
69
70 virtual ~NotifierInterface() {}
71 };
72
73 // Base class for sources. A MediaStreamTrack have an underlying source that
74 // provide media. A source can be shared with multiple tracks.
75 class MediaSourceInterface : public rtc::RefCountInterface,
76 public NotifierInterface {
77 public:
78 enum SourceState {
79 kInitializing,
80 kLive,
81 kEnded,
82 kMuted
83 };
84
85 virtual SourceState state() const = 0;
86
87 virtual bool remote() const = 0;
88
89 protected:
90 virtual ~MediaSourceInterface() {}
91 };
92
93 // Information about a track.
94 class MediaStreamTrackInterface : public rtc::RefCountInterface,
95 public NotifierInterface {
96 public:
97 enum TrackState {
98 kInitializing, // Track is beeing negotiated.
99 kLive = 1, // Track alive
100 kEnded = 2, // Track have ended
101 kFailed = 3, // Track negotiation failed.
102 };
103
104 static const char kAudioKind[];
105 static const char kVideoKind[];
106
107 virtual std::string kind() const = 0;
108 virtual std::string id() const = 0;
109 virtual bool enabled() const = 0;
110 virtual TrackState state() const = 0;
111 virtual bool set_enabled(bool enable) = 0;
112 // These methods should be called by implementation only.
113 virtual bool set_state(TrackState new_state) = 0;
114
115 protected:
116 virtual ~MediaStreamTrackInterface() {}
117 };
118
119 // Interface for rendering VideoFrames from a VideoTrack
120 class VideoRendererInterface
121 : public rtc::VideoSinkInterface<cricket::VideoFrame> {
122 public:
123 // |frame| may have pending rotation. For clients which can't apply rotation,
124 // |frame|->GetCopyWithRotationApplied() will return a frame that has the
125 // rotation applied.
126 virtual void RenderFrame(const cricket::VideoFrame* frame) = 0;
127 // Intended to replace RenderFrame.
128 void OnFrame(const cricket::VideoFrame& frame) override {
129 RenderFrame(&frame);
130 }
131
132 protected:
133 // The destructor is protected to prevent deletion via the interface.
134 // This is so that we allow reference counted classes, where the destructor
135 // should never be public, to implement the interface.
136 virtual ~VideoRendererInterface() {}
137 };
138
139 class VideoSourceInterface;
140
141 class VideoTrackInterface : public MediaStreamTrackInterface {
142 public:
143 // Register a renderer that will render all frames received on this track.
144 virtual void AddRenderer(VideoRendererInterface* renderer) = 0;
145 // Deregister a renderer.
146 virtual void RemoveRenderer(VideoRendererInterface* renderer) = 0;
147
148 virtual VideoSourceInterface* GetSource() const = 0;
149
150 // Return the track input sink. I.e., frames sent to this sink are
151 // propagated to all renderers registered with the track. The
152 // returned sink must not change between calls. Currently, this
153 // method is used for remote tracks (VideoRtpReceiver); further
154 // refactoring is planned for this path, it's unclear if this method
155 // belongs here long term.
156
157 // We do this instead of simply implementing the
158 // VideoSourceInterface directly, because if we did the latter, we'd
159 // need an OnFrame method in VideoTrackProxy, with a thread jump on
160 // each call.
161
162 // TODO(nisse): It has a default implementation so that mock
163 // objects, in particular, chrome's MockWebRtcVideoTrack, doesn't
164 // need to know about it. Consider removing the implementation (or
165 // this comment) after refactoring dust settles.
166 virtual rtc::VideoSinkInterface<cricket::VideoFrame>* GetSink() {
167 return nullptr;
168 };
169
170 protected:
171 virtual ~VideoTrackInterface() {}
172 };
173
174 // Interface for receiving audio data from a AudioTrack.
175 class AudioTrackSinkInterface {
176 public:
177 virtual void OnData(const void* audio_data,
178 int bits_per_sample,
179 int sample_rate,
180 size_t number_of_channels,
181 size_t number_of_frames) = 0;
182
183 protected:
184 virtual ~AudioTrackSinkInterface() {}
185 };
186
187 // AudioSourceInterface is a reference counted source used for AudioTracks.
188 // The same source can be used in multiple AudioTracks.
189 class AudioSourceInterface : public MediaSourceInterface {
190 public:
191 class AudioObserver {
192 public:
193 virtual void OnSetVolume(double volume) = 0;
194
195 protected:
196 virtual ~AudioObserver() {}
197 };
198
199 // TODO(xians): Makes all the interface pure virtual after Chrome has their
200 // implementations.
201 // Sets the volume to the source. |volume| is in the range of [0, 10].
202 // TODO(tommi): This method should be on the track and ideally volume should
203 // be applied in the track in a way that does not affect clones of the track.
204 virtual void SetVolume(double volume) {}
205
206 // Registers/unregisters observer to the audio source.
207 virtual void RegisterAudioObserver(AudioObserver* observer) {}
208 virtual void UnregisterAudioObserver(AudioObserver* observer) {}
209
210 // TODO(tommi): Make pure virtual.
211 virtual void AddSink(AudioTrackSinkInterface* sink) {}
212 virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
213 };
214
215 // Interface of the audio processor used by the audio track to collect
216 // statistics.
217 class AudioProcessorInterface : public rtc::RefCountInterface {
218 public:
219 struct AudioProcessorStats {
220 AudioProcessorStats() : typing_noise_detected(false),
221 echo_return_loss(0),
222 echo_return_loss_enhancement(0),
223 echo_delay_median_ms(0),
224 aec_quality_min(0.0),
225 echo_delay_std_ms(0) {}
226 ~AudioProcessorStats() {}
227
228 bool typing_noise_detected;
229 int echo_return_loss;
230 int echo_return_loss_enhancement;
231 int echo_delay_median_ms;
232 float aec_quality_min;
233 int echo_delay_std_ms;
234 };
235
236 // Get audio processor statistics.
237 virtual void GetStats(AudioProcessorStats* stats) = 0;
238
239 protected:
240 virtual ~AudioProcessorInterface() {}
241 };
242
243 class AudioTrackInterface : public MediaStreamTrackInterface {
244 public:
245 // TODO(xians): Figure out if the following interface should be const or not.
246 virtual AudioSourceInterface* GetSource() const = 0;
247
248 // Add/Remove a sink that will receive the audio data from the track.
249 virtual void AddSink(AudioTrackSinkInterface* sink) = 0;
250 virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0;
251
252 // Get the signal level from the audio track.
253 // Return true on success, otherwise false.
254 // TODO(xians): Change the interface to int GetSignalLevel() and pure virtual
255 // after Chrome has the correct implementation of the interface.
256 virtual bool GetSignalLevel(int* level) { return false; }
257
258 // Get the audio processor used by the audio track. Return NULL if the track
259 // does not have any processor.
260 // TODO(xians): Make the interface pure virtual.
261 virtual rtc::scoped_refptr<AudioProcessorInterface>
262 GetAudioProcessor() { return NULL; }
263
264 protected:
265 virtual ~AudioTrackInterface() {}
266 };
267
268 typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> >
269 AudioTrackVector;
270 typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> >
271 VideoTrackVector;
272
273 class MediaStreamInterface : public rtc::RefCountInterface,
274 public NotifierInterface {
275 public:
276 virtual std::string label() const = 0;
277
278 virtual AudioTrackVector GetAudioTracks() = 0;
279 virtual VideoTrackVector GetVideoTracks() = 0;
280 virtual rtc::scoped_refptr<AudioTrackInterface>
281 FindAudioTrack(const std::string& track_id) = 0;
282 virtual rtc::scoped_refptr<VideoTrackInterface>
283 FindVideoTrack(const std::string& track_id) = 0;
284
285 virtual bool AddTrack(AudioTrackInterface* track) = 0;
286 virtual bool AddTrack(VideoTrackInterface* track) = 0;
287 virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
288 virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
289
290 protected:
291 virtual ~MediaStreamInterface() {}
292 };
293
294 } // namespace webrtc
295
296 #endif // TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_
OLDNEW
« no previous file with comments | « talk/app/webrtc/mediastreamhandler.cc ('k') | talk/app/webrtc/mediastreamobserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698