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); |
29 | |
30 // Subclasses must ensure the track is stopped before this destructor is | |
31 // invoked. | |
22 ~MediaStreamAudioTrack() override; | 32 ~MediaStreamAudioTrack() override; |
23 | 33 |
24 static MediaStreamAudioTrack* GetTrack( | 34 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| |
25 const blink::WebMediaStreamTrack& track); | 35 // or null. |
36 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); | |
37 | |
38 // The first time Stop() is called on this track, each |stop_callback| will be | |
39 // run. This is generally used by sources to be notified that the audio data | |
40 // flow to the track should halt. | |
41 void AddStopObserver(const base::Closure& stop_callback); | |
26 | 42 |
27 // Add a sink to the track. This function will trigger a OnSetFormat() | 43 // Add a sink to the track. This function will trigger a OnSetFormat() |
28 // call on the |sink|. | 44 // call on the |sink|. |
29 // Called on the main render thread. | 45 // Called on the main render thread. |
30 virtual void AddSink(MediaStreamAudioSink* sink) = 0; | 46 virtual void AddSink(MediaStreamAudioSink* sink) = 0; |
31 | 47 |
32 // Remove a sink from the track. | 48 // Remove a sink from the track. |
33 // Called on the main render thread. | 49 // Called on the main render thread. |
34 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; | 50 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; |
35 | 51 |
36 // TODO(tommi, xians): Remove this method. | 52 // TODO(tommi, xians): Remove this method. |
53 // TODO(miu): See class-level TODO comment. ;-) | |
37 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); | 54 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); |
38 | 55 |
39 // Returns the output format of the capture source. May return an invalid | 56 // Returns the output format of the capture source. May return an invalid |
40 // AudioParameters if the format is not yet available. | 57 // AudioParameters if the format is not yet available. |
41 // Called on the main render thread. | 58 // Called on the main render thread. |
42 // TODO(tommi): This method appears to only be used by Pepper and in fact | 59 // 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 | 60 // 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. | 61 // to the complexity of all types of audio tracks+source implementations. |
45 virtual media::AudioParameters GetOutputFormat() const = 0; | 62 virtual media::AudioParameters GetOutputFormat() const = 0; |
46 | 63 |
64 // Subclasses must override this method and must call WillStopTrack() to | |
65 // ensure the stop callbacks are run. | |
66 void Stop() override = 0; | |
67 | |
68 protected: | |
69 // Runs the stop callbacks. | |
70 void WillStopTrack(); | |
o1ka
2016/03/01 14:18:59
NotifyStopObservers() maybe?
miu
2016/03/02 01:12:50
Acknowledged. This got re-worked, as explained in
| |
71 | |
47 private: | 72 private: |
73 // These are run after this track has been stopped. Even if Stop() is called | |
o1ka
2016/03/01 14:18:59
The comment needs some makeover now, probably some
miu
2016/03/02 01:12:50
Acknowledged. This also got re-worked, as explain
| |
74 // multiple times, the |stop_callbacks_| are only run the first time. | |
75 std::vector<base::Closure> stop_callbacks_; | |
76 | |
48 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); | 77 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); |
49 }; | 78 }; |
50 | 79 |
51 } // namespace content | 80 } // namespace content |
52 | 81 |
53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 82 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
OLD | NEW |