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 "base/callback.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "content/renderer/media/media_stream_track.h" | 10 #include "content/renderer/media/media_stream_track.h" |
10 | 11 |
11 namespace webrtc { | 12 namespace webrtc { |
12 class AudioTrackInterface; | 13 class AudioTrackInterface; |
13 } // namespace webrtc | 14 } // namespace webrtc |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 class MediaStreamAudioSink; | 18 class MediaStreamAudioSink; |
18 | 19 |
| 20 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will |
| 21 // take on the functionality of managing sink connections and the audio data |
| 22 // flow between source and sinks. The WebRTC-specific elements will then be |
| 23 // moved into a subclass. http://crbug.com/577874 |
19 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { | 24 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { |
20 public: | 25 public: |
21 explicit MediaStreamAudioTrack(bool is_local_track); | 26 explicit MediaStreamAudioTrack(bool is_local_track); |
| 27 |
| 28 // Subclasses must ensure the track is stopped (i.e., Stop() has been called |
| 29 // at least once) before this destructor is invoked. |
22 ~MediaStreamAudioTrack() override; | 30 ~MediaStreamAudioTrack() override; |
23 | 31 |
24 static MediaStreamAudioTrack* GetTrack( | 32 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| |
25 const blink::WebMediaStreamTrack& track); | 33 // or null. |
| 34 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); |
26 | 35 |
27 // Add a sink to the track. This function will trigger a OnSetFormat() | 36 // Add a sink to the track. This function will trigger a OnSetFormat() |
28 // call on the |sink|. | 37 // call on the |sink|. |
29 // Called on the main render thread. | 38 // Called on the main render thread. |
30 virtual void AddSink(MediaStreamAudioSink* sink) = 0; | 39 virtual void AddSink(MediaStreamAudioSink* sink) = 0; |
31 | 40 |
32 // Remove a sink from the track. | 41 // Remove a sink from the track. |
33 // Called on the main render thread. | 42 // Called on the main render thread. |
34 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; | 43 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; |
35 | 44 |
36 // TODO(tommi, xians): Remove this method. | 45 // TODO(tommi, xians): Remove this method. |
| 46 // TODO(miu): See class-level TODO comment. ;-) |
37 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); | 47 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); |
38 | 48 |
39 // Returns the output format of the capture source. May return an invalid | 49 // Returns the output format of the capture source. May return an invalid |
40 // AudioParameters if the format is not yet available. | 50 // AudioParameters if the format is not yet available. |
41 // Called on the main render thread. | 51 // Called on the main render thread. |
42 // TODO(tommi): This method appears to only be used by Pepper and in fact | 52 // 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 | 53 // 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. | 54 // to the complexity of all types of audio tracks+source implementations. |
45 virtual media::AudioParameters GetOutputFormat() const = 0; | 55 virtual media::AudioParameters GetOutputFormat() const = 0; |
46 | 56 |
| 57 // Called to notify this track that the flow of audio data has started from |
| 58 // the source. |stop_callback| is run by Stop() when the source must halt the |
| 59 // flow of audio data to this track. |
| 60 void Start(const base::Closure& stop_callback); |
| 61 |
| 62 // Halts the flow of audio data from the source (and to the sinks), and then |
| 63 // invokes OnStop() to perform any additional actions. |
| 64 void Stop() final; |
| 65 |
| 66 protected: |
| 67 // Called by Stop() after the source has halted the flow of audio data. |
| 68 virtual void OnStop(); |
| 69 |
47 private: | 70 private: |
| 71 // Callback provided to Start() which is run when the audio flow must halt. |
| 72 base::Closure stop_callback_; |
| 73 |
48 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); | 74 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); |
49 }; | 75 }; |
50 | 76 |
51 } // namespace content | 77 } // namespace content |
52 | 78 |
53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 79 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
OLD | NEW |