OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "base/callback.h" | |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
9 #include "content/renderer/media/media_stream_track.h" | 12 #include "content/renderer/media/media_stream_track.h" |
10 | 13 |
11 namespace webrtc { | 14 namespace webrtc { |
12 class AudioTrackInterface; | 15 class AudioTrackInterface; |
13 } // namespace webrtc | 16 } // namespace webrtc |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 | 19 |
17 class MediaStreamAudioSink; | 20 class MediaStreamAudioSink; |
18 | 21 |
22 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will | |
23 // take on the functionality of managing sink connections and the audio data | |
24 // flow between source and sinks. The WebRTC-specific elements will then be | |
25 // moved into a subclass. http://crbug.com/577874 | |
19 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { | 26 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { |
20 public: | 27 public: |
21 explicit MediaStreamAudioTrack(bool is_local_track); | 28 explicit MediaStreamAudioTrack(bool is_local_track); |
22 ~MediaStreamAudioTrack() override; | 29 ~MediaStreamAudioTrack() override; |
23 | 30 |
24 static MediaStreamAudioTrack* GetTrack( | 31 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| |
25 const blink::WebMediaStreamTrack& track); | 32 // or null. |
33 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); | |
34 | |
35 // The first time Stop() is called on this track, each |stop_callback| will be | |
36 // run. This is generally used by sources to be notified that the audio data | |
37 // flow to the track should halt. | |
38 void AddStopObserver(const base::Closure& stop_callback); | |
26 | 39 |
27 // Add a sink to the track. This function will trigger a OnSetFormat() | 40 // Add a sink to the track. This function will trigger a OnSetFormat() |
28 // call on the |sink|. | 41 // call on the |sink|. |
29 // Called on the main render thread. | 42 // Called on the main render thread. |
30 virtual void AddSink(MediaStreamAudioSink* sink) = 0; | 43 virtual void AddSink(MediaStreamAudioSink* sink) = 0; |
31 | 44 |
32 // Remove a sink from the track. | 45 // Remove a sink from the track. |
33 // Called on the main render thread. | 46 // Called on the main render thread. |
34 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; | 47 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; |
35 | 48 |
36 // TODO(tommi, xians): Remove this method. | 49 // TODO(tommi, xians): Remove this method. |
50 // TODO(miu): See class-level TODO comment. ;-) | |
37 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); | 51 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); |
38 | 52 |
39 // Returns the output format of the capture source. May return an invalid | 53 // Returns the output format of the capture source. May return an invalid |
40 // AudioParameters if the format is not yet available. | 54 // AudioParameters if the format is not yet available. |
41 // Called on the main render thread. | 55 // Called on the main render thread. |
42 // TODO(tommi): This method appears to only be used by Pepper and in fact | 56 // TODO(tommi): This method appears to only be used by Pepper and in fact |
43 // does not appear to be necessary there. We should remove it since it adds | 57 // does not appear to be necessary there. We should remove it since it adds |
44 // to the complexity of all types of audio tracks+source implementations. | 58 // to the complexity of all types of audio tracks+source implementations. |
45 virtual media::AudioParameters GetOutputFormat() const = 0; | 59 virtual media::AudioParameters GetOutputFormat() const = 0; |
46 | 60 |
61 // The final implementation of the Stop() method. Subclasses that wish to | |
62 // extend this functionality should use AddStopObserver() instead. | |
63 void Stop() final; | |
64 | |
47 private: | 65 private: |
66 // These are run after this track has been stopped. Even if Stop() is called | |
67 // multiple times, the |stop_callbacks_| are only run the first time. | |
68 std::vector<base::Closure> stop_callbacks_; | |
mcasas
2016/02/26 01:28:19
Use base::ObserverList ? Meh could be worse
since
miu
2016/02/27 03:46:36
Took a look. Yeah, I just have a dirt-simple case
| |
69 | |
48 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); | 70 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); |
49 }; | 71 }; |
50 | 72 |
51 } // namespace content | 73 } // namespace content |
52 | 74 |
53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 75 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
OLD | NEW |