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" | |
9 #include "base/macros.h" | 8 #include "base/macros.h" |
10 #include "content/renderer/media/media_stream_track.h" | 9 #include "content/renderer/media/media_stream_track.h" |
11 | 10 |
12 namespace webrtc { | 11 namespace webrtc { |
13 class AudioTrackInterface; | 12 class AudioTrackInterface; |
14 } // namespace webrtc | 13 } // namespace webrtc |
15 | 14 |
16 namespace content { | 15 namespace content { |
17 | 16 |
18 class MediaStreamAudioSink; | 17 class MediaStreamAudioSink; |
19 | 18 |
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 | |
24 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { | 19 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { |
25 public: | 20 public: |
26 explicit MediaStreamAudioTrack(bool is_local_track); | 21 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. | |
30 ~MediaStreamAudioTrack() override; | 22 ~MediaStreamAudioTrack() override; |
31 | 23 |
32 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| | 24 static MediaStreamAudioTrack* GetTrack( |
33 // or null. | 25 const blink::WebMediaStreamTrack& track); |
34 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); | |
35 | 26 |
36 // Add a sink to the track. This function will trigger a OnSetFormat() | 27 // Add a sink to the track. This function will trigger a OnSetFormat() |
37 // call on the |sink|. | 28 // call on the |sink|. |
38 // Called on the main render thread. | 29 // Called on the main render thread. |
39 virtual void AddSink(MediaStreamAudioSink* sink) = 0; | 30 virtual void AddSink(MediaStreamAudioSink* sink) = 0; |
40 | 31 |
41 // Remove a sink from the track. | 32 // Remove a sink from the track. |
42 // Called on the main render thread. | 33 // Called on the main render thread. |
43 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; | 34 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; |
44 | 35 |
45 // TODO(tommi, xians): Remove this method. | 36 // TODO(tommi, xians): Remove this method. |
46 // TODO(miu): See class-level TODO comment. ;-) | |
47 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); | 37 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); |
48 | 38 |
49 // Returns the output format of the capture source. May return an invalid | 39 // Returns the output format of the capture source. May return an invalid |
50 // AudioParameters if the format is not yet available. | 40 // AudioParameters if the format is not yet available. |
51 // Called on the main render thread. | 41 // Called on the main render thread. |
52 // TODO(tommi): This method appears to only be used by Pepper and in fact | 42 // TODO(tommi): This method appears to only be used by Pepper and in fact |
53 // does not appear to be necessary there. We should remove it since it adds | 43 // does not appear to be necessary there. We should remove it since it adds |
54 // to the complexity of all types of audio tracks+source implementations. | 44 // to the complexity of all types of audio tracks+source implementations. |
55 virtual media::AudioParameters GetOutputFormat() const = 0; | 45 virtual media::AudioParameters GetOutputFormat() const = 0; |
56 | 46 |
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 | |
70 private: | 47 private: |
71 // Callback provided to Start() which is run when the audio flow must halt. | |
72 base::Closure stop_callback_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); | 48 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); |
75 }; | 49 }; |
76 | 50 |
77 } // namespace content | 51 } // namespace content |
78 | 52 |
79 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
OLD | NEW |