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

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

Issue 1966043006: Revert of 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, 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"
11 #include "base/callback.h" 8 #include "base/callback.h"
12 #include "base/macros.h" 9 #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"
17 #include "content/renderer/media/media_stream_track.h" 10 #include "content/renderer/media/media_stream_track.h"
18 11
12 namespace webrtc {
13 class AudioTrackInterface;
14 } // namespace webrtc
15
19 namespace content { 16 namespace content {
20 17
21 class MediaStreamAudioSink; 18 class MediaStreamAudioSink;
22 class MediaStreamAudioSource;
23 19
24 // Provides the part of the audio pipeline delivering audio from a 20 // TODO(miu): In a soon-upcoming set of refactoring changes, this class will
25 // MediaStreamAudioSource to one or more MediaStreamAudioSinks. An instance of 21 // take on the functionality of managing sink connections and the audio data
26 // this class is owned by blink::WebMediaStreamTrack, and clients should use 22 // flow between source and sinks. The WebRTC-specific elements will then be
27 // From() to gain access to a MediaStreamAudioTrack. 23 // moved into a subclass. http://crbug.com/577874
28 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { 24 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
29 public: 25 public:
30 explicit MediaStreamAudioTrack(bool is_local_track); 26 explicit MediaStreamAudioTrack(bool is_local_track);
31 27
28 // Subclasses must ensure the track is stopped (i.e., Stop() has been called
29 // at least once) before this destructor is invoked.
32 ~MediaStreamAudioTrack() override; 30 ~MediaStreamAudioTrack() override;
33 31
34 // Returns the MediaStreamAudioTrack instance owned by the given blink |track| 32 // Returns the MediaStreamAudioTrack instance owned by the given blink |track|
35 // or null. 33 // or null.
36 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track); 34 static MediaStreamAudioTrack* From(const blink::WebMediaStreamTrack& track);
37 35
38 // Provides a weak reference to this MediaStreamAudioTrack which is 36 // Add a sink to the track. This function will trigger a OnSetFormat()
39 // invalidated when Stop() is called. The weak pointer may only be 37 // call on the |sink|.
40 // dereferenced on the main thread. 38 // Called on the main render thread.
41 base::WeakPtr<MediaStreamAudioTrack> GetWeakPtr() { 39 virtual void AddSink(MediaStreamAudioSink* sink) = 0;
42 return weak_factory_.GetWeakPtr();
43 }
44 40
45 // Add a sink to the track. This function will trigger a OnSetFormat() 41 // Remove a sink from the track.
46 // call on the |sink| before the first chunk of audio is delivered. 42 // Called on the main render thread.
47 void AddSink(MediaStreamAudioSink* sink); 43 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0;
48 44
49 // Remove a sink from the track. When this method returns, the sink's 45 // TODO(tommi, xians): Remove this method.
50 // OnSetFormat() and OnData() methods will not be called again on any thread. 46 // TODO(miu): See class-level TODO comment. ;-)
51 void RemoveSink(MediaStreamAudioSink* sink); 47 virtual webrtc::AudioTrackInterface* GetAudioAdapter();
52 48
53 // 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
54 // AudioParameters if the format is not yet available. 50 // AudioParameters if the format is not yet available.
55 // Called on the main render thread. 51 // Called on the main render thread.
56 // 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
57 // 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
58 // to the complexity of all types of audio tracks+source implementations. 54 // to the complexity of all types of audio tracks+source implementations.
59 // http://crbug.com/577874 55 virtual media::AudioParameters GetOutputFormat() const = 0;
60 media::AudioParameters GetOutputFormat() const; 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 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 // notifies all sinks of the "ended" state. 63 // invokes OnStop() to perform any additional actions.
64 void Stop() final; 64 void Stop() final;
65 65
66 // MediaStreamTrack override. 66 protected:
67 void SetEnabled(bool enabled) override; 67 // Called by Stop() after the source has halted the flow of audio data.
68 68 virtual void OnStop();
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 69
73 private: 70 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.
80 void Start(const base::Closure& stop_callback);
81
82 // Called by the MediaStreamAudioDeliverer to notify this track of an audio
83 // format change. In turn, all MediaStreamAudioSinks will be notified before
84 // the next chunk of audio is delivered to them.
85 void OnSetFormat(const media::AudioParameters& params);
86
87 // Called by the MediaStreamAudioDeliverer to deliver audio data to this
88 // track, which in turn delivers the audio to one or more
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);
92
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
98 // Callback provided to Start() which is run when the audio flow must halt. 71 // Callback provided to Start() which is run when the audio flow must halt.
99 base::Closure stop_callback_; 72 base::Closure stop_callback_;
100 73
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
113 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); 74 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack);
114 }; 75 };
115 76
116 } // namespace content 77 } // namespace content
117 78
118 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ 79 #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