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

Side by Side Diff: content/renderer/media/media_stream_audio_track.h

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/synchronization/lock.h"
10 #include "content/renderer/media/media_stream_track.h" 14 #include "content/renderer/media/media_stream_track.h"
11 15 #include "media/audio/audio_parameters.h"
12 namespace webrtc {
13 class AudioTrackInterface;
14 } // namespace webrtc
15 16
16 namespace content { 17 namespace content {
17 18
18 class MediaStreamAudioSink; 19 class MediaStreamAudioSink;
20 class MediaStreamAudioSource;
19 21
20 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will 22 // Provides the part of the audio pipeline delivering audio from a
21 // take on the functionality of managing sink connections and the audio data 23 // MediaStreamAudioSource to one or more MediaStreamAudioSinks. An instance of
22 // flow between source and sinks. The WebRTC-specific elements will then be 24 // this class is owned by blink::WebMediaStreamTrack, and clients should use
23 // moved into a subclass. http://crbug.com/577874 25 // From() to gain access to a MediaStreamAudioTrack.
24 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { 26 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
25 public: 27 public:
26 explicit MediaStreamAudioTrack(bool is_local_track); 28 explicit MediaStreamAudioTrack(bool is_local_track);
27 29
28 // Subclasses must ensure the track is stopped (i.e., Stop() has been called 30 // Subclasses must ensure the track is stopped (i.e., Stop() has been called
29 // at least once) before this destructor is invoked. 31 // at least once) before this destructor is invoked.
30 ~MediaStreamAudioTrack() override; 32 ~MediaStreamAudioTrack() override;
31 33
32 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| 34 // Returns the MediaStreamAudioTrack instance owned by the given blink |track|
33 // or null. 35 // or null.
34 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); 36 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track);
35 37
38 // Provides a weak reference to this MediaStreamAudioTrack which is
39 // invalidated when Stop() is called. The weak pointer may only be
40 // dereferenced on the main thread.
41 base::WeakPtr<MediaStreamAudioTrack> GetWeakPtr() {
42 return weak_factory_.GetWeakPtr();
43 }
44
36 // Add a sink to the track. This function will trigger a OnSetFormat() 45 // Add a sink to the track. This function will trigger a OnSetFormat()
37 // call on the |sink|. 46 // call on the |sink| before the first chunk of audio is delivered.
38 // Called on the main render thread. 47 void AddSink(MediaStreamAudioSink* sink);
39 virtual void AddSink(MediaStreamAudioSink* sink) = 0;
40 48
41 // Remove a sink from the track. 49 // Remove a sink from the track. When this method returns, the sink's
42 // Called on the main render thread. 50 // OnSetFormat() and OnData() methods will not be called again on any thread.
43 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; 51 void RemoveSink(MediaStreamAudioSink* sink);
44
45 // TODO(tommi, xians): Remove this method.
46 // TODO(miu): See class-level TODO comment. ;-)
47 virtual webrtc::AudioTrackInterface* GetAudioAdapter();
48 52
49 // 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
50 // AudioParameters if the format is not yet available. 54 // AudioParameters if the format is not yet available.
51 // Called on the main render thread. 55 // Called on the main render thread.
52 // 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
53 // 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
54 // to the complexity of all types of audio tracks+source implementations. 58 // to the complexity of all types of audio tracks+source implementations.
55 virtual media::AudioParameters GetOutputFormat() const = 0; 59 // http://crbug.com/577874
56 60 media::AudioParameters GetOutputFormat() const;
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 61
62 // Halts the flow of audio data from the source (and to the sinks), and then 62 // Halts the flow of audio data from the source (and to the sinks), and then
63 // invokes OnStop() to perform any additional actions. 63 // invokes OnStop() to perform any additional actions.
64 void Stop() final; 64 void Stop() final;
65 65
66 // MediaStreamTrack override.
67 void SetEnabled(bool enabled) override;
68
69 // Returns a unique class identifier. Some subclasses override and use this
70 // method to provide safe down-casting to their type.
71 virtual void* GetClassIdentifier() const;
72
66 protected: 73 protected:
67 // Called by Stop() after the source has halted the flow of audio data. 74 // Called by Stop() after the source has halted the flow of audio data.
68 virtual void OnStop(); 75 virtual void OnStop();
69 76
70 private: 77 private:
78 friend class MediaStreamAudioSource;
79
80 // Called by MediaStreamAudioSource to notify this track that the flow of
81 // audio data has started from the source. |stop_callback| is run by Stop()
82 // when the source must halt the flow of audio data to this track.
83 void Start(const base::Closure& stop_callback);
84
85 // Called by the MediaStreamAudioSource to notify this track of an audio
86 // format change. In turn, all MediaStreamAudioSinks will be notified before
87 // the next chunk of audio is delivered to them.
88 void SetFormat(const media::AudioParameters& params);
89
90 // Called by the MediaStreamAudioSource to deliver audio data to this track,
91 // which in turn delivers the audio to one or more MediaStreamAudioSinks.
92 void DeliverDataToSinks(const media::AudioBus& audio_bus,
93 base::TimeTicks reference_time);
94
95 private:
71 // Callback provided to Start() which is run when the audio flow must halt. 96 // Callback provided to Start() which is run when the audio flow must halt.
72 base::Closure stop_callback_; 97 base::Closure stop_callback_;
73 98
99 // The current format of the audio passing through this track.
100 media::AudioParameters params_;
101
102 // Lock protects concurrent access to the sink lists below and the
103 // |is_enabled_| state, between the main thread and the audio thread.
104 mutable base::Lock lock_;
105
106 // Any sinks needing a call to MediaStreamAudioSink::OnSetFormat(), to be
107 // notified of the changed audio format, are placed in this list. This
108 // includes sinks added via AddSink() that need to have an initial
109 // OnSetFormat() call before audio data is first delivered. Sinks are moved
110 // from this list to |sinks_|.
111 std::vector<MediaStreamAudioSink*> pending_sinks_;
112
113 // Sinks that are up-to-date on the current audio format and are receiving
114 // audio data are placed in this list.
115 std::vector<MediaStreamAudioSink*> sinks_;
116
117 // When false, delivery of audio data is temporarily halted to the sinks.
118 bool is_enabled_;
119
120 // Provides weak pointers that are valid until Stop() is called.
121 base::WeakPtrFactory<MediaStreamAudioTrack> weak_factory_;
122
74 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); 123 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack);
75 }; 124 };
76 125
77 } // namespace content 126 } // namespace content
78 127
79 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ 128 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698