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

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: REBASE + Workaround to ensure MediaStreamAudioProcessor is destroyed on the main thread. Created 4 years, 7 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 <memory>
9
10 #include "base/atomicops.h"
8 #include "base/callback.h" 11 #include "base/callback.h"
9 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h"
16 #include "content/renderer/media/media_stream_audio_deliverer.h"
10 #include "content/renderer/media/media_stream_track.h" 17 #include "content/renderer/media/media_stream_track.h"
11 18
12 namespace webrtc {
13 class AudioTrackInterface;
14 } // namespace webrtc
15
16 namespace content { 19 namespace content {
17 20
18 class MediaStreamAudioSink; 21 class MediaStreamAudioSink;
22 class MediaStreamAudioSource;
19 23
20 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will 24 // Provides the part of the audio pipeline delivering audio from a
21 // take on the functionality of managing sink connections and the audio data 25 // MediaStreamAudioSource to one or more MediaStreamAudioSinks. An instance of
22 // flow between source and sinks. The WebRTC-specific elements will then be 26 // this class is owned by blink::WebMediaStreamTrack, and clients should use
23 // moved into a subclass. http://crbug.com/577874 27 // From() to gain access to a MediaStreamAudioTrack.
24 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { 28 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
25 public: 29 public:
26 explicit MediaStreamAudioTrack(bool is_local_track); 30 explicit MediaStreamAudioTrack(bool is_local_track);
27 31
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; 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
60 media::AudioParameters GetOutputFormat() const;
56 61
57 // Called to notify this track that the flow of audio data has started from 62 // Halts the flow of audio data from the source (and to the sinks), and then
58 // the source. |stop_callback| is run by Stop() when the source must halt the 63 // notifies all sinks of the "ended" state.
59 // flow of audio data to this track. 64 void Stop() final;
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
73 private:
74 friend class MediaStreamAudioSource;
75 friend class MediaStreamAudioDeliverer<MediaStreamAudioTrack>;
76
77 // Called by MediaStreamAudioSource to notify this track that the flow of
78 // audio data has started from the source. |stop_callback| is run by Stop()
79 // when the source must halt the flow of audio data to this track.
60 void Start(const base::Closure& stop_callback); 80 void Start(const base::Closure& stop_callback);
61 81
62 // Halts the flow of audio data from the source (and to the sinks), and then 82 // Called by the MediaStreamAudioDeliverer to notify this track of an audio
63 // invokes OnStop() to perform any additional actions. 83 // format change. In turn, all MediaStreamAudioSinks will be notified before
64 void Stop() final; 84 // the next chunk of audio is delivered to them.
85 void OnSetFormat(const media::AudioParameters& params);
65 86
66 protected: 87 // Called by the MediaStreamAudioDeliverer to deliver audio data to this
67 // Called by Stop() after the source has halted the flow of audio data. 88 // track, which in turn delivers the audio to one or more
68 virtual void OnStop(); 89 // MediaStreamAudioSinks. While this track is disabled, silent audio will be
90 // delivered to the sinks instead of the content of |audio_bus|.
91 void OnData(const media::AudioBus& audio_bus, base::TimeTicks reference_time);
69 92
70 private: 93 private:
94 // In debug builds, check that all methods that could cause object graph
95 // or data flow changes are being called on the main thread.
96 base::ThreadChecker thread_checker_;
97
71 // Callback provided to Start() which is run when the audio flow must halt. 98 // Callback provided to Start() which is run when the audio flow must halt.
72 base::Closure stop_callback_; 99 base::Closure stop_callback_;
73 100
101 // Manages sinks connected to this track and the audio format and data flow.
102 MediaStreamAudioDeliverer<MediaStreamAudioSink> deliverer_;
103
104 // While false (0), silent audio is delivered to the sinks.
105 base::subtle::Atomic32 is_enabled_;
106
107 // Buffer used to deliver silent audio data while this track is disabled.
108 std::unique_ptr<media::AudioBus> silent_bus_;
109
110 // Provides weak pointers that are valid until Stop() is called.
111 base::WeakPtrFactory<MediaStreamAudioTrack> weak_factory_;
112
74 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); 113 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack);
75 }; 114 };
76 115
77 } // namespace content 116 } // namespace content
78 117
79 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ 118 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_source.cc ('k') | content/renderer/media/media_stream_audio_track.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698