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

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

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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
10 #include "base/callback.h"
8 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
9 #include "content/renderer/media/media_stream_track.h" 13 #include "content/renderer/media/media_stream_track.h"
10 14 #include "media/audio/audio_parameters.h"
11 namespace webrtc {
12 class AudioTrackInterface;
13 } // namespace webrtc
14 15
15 namespace content { 16 namespace content {
16 17
17 class MediaStreamAudioSink; 18 class MediaStreamAudioSink;
19 class MediaStreamAudioSource;
18 20
21 // Provides the part of the audio pipeline delivering audio from a
22 // MediaStreamAudioSource to one or more MediaStreamAudioSinks. An instance of
23 // this class is owned by blink::WebMediaStreamTrack, and clients should use
24 // Get() to gain access to a MediaStreamAudioTrack.
19 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack { 25 class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
20 public: 26 public:
21 explicit MediaStreamAudioTrack(bool is_local_track); 27 explicit MediaStreamAudioTrack(bool is_local_track);
28
22 ~MediaStreamAudioTrack() override; 29 ~MediaStreamAudioTrack() override;
23 30
24 static MediaStreamAudioTrack* GetTrack( 31 // Accessor to the MediaStreamAudioTrack instance owned (as extraData) by the
25 const blink::WebMediaStreamTrack& track); 32 // given WebMediaStreamTrack.
33 static MediaStreamAudioTrack* Get(const blink::WebMediaStreamTrack& track);
26 34
27 // Add a sink to the track. This function will trigger a OnSetFormat() 35 // When Stop() is called on this track, |stop_callback| will be run. This is
28 // call on the |sink|. 36 // generally used to notify the source that the track cannot accept more
29 // Called on the main render thread. 37 // data.
30 virtual void AddSink(MediaStreamAudioSink* sink) = 0; 38 void AddStopObserver(const base::Closure& stop_callback);
31 39
32 // Remove a sink from the track. 40 // Adds |sink| as another destination of audio flow. Calls
33 // Called on the main render thread. 41 // MediaStreamAudioSink::OnReadyStateChanged() to notify the sink it is live.
34 virtual void RemoveSink(MediaStreamAudioSink* sink) = 0; 42 void AddSink(MediaStreamAudioSink* sink);
35 43
36 // TODO(tommi, xians): Remove this method. 44 // Removes |sink| as a receiver of audio flow. When this method returns, the
37 virtual webrtc::AudioTrackInterface* GetAudioAdapter(); 45 // sink's OnSetFormat() and OnData() methods will not be called again on any
46 // thread. Calls MediaStreamAudioSink::OnReadyStateChanged() to notify the
47 // sink it is no longer live.
48 void RemoveSink(MediaStreamAudioSink* sink);
49
50 // MediaStreamTrack implementation.
51 void SetEnabled(bool enabled) override;
52 void Stop() final;
38 53
39 // Returns the output format of the capture source. May return an invalid 54 // Returns the output format of the capture source. May return an invalid
40 // AudioParameters if the format is not yet available. 55 // AudioParameters if the format is not yet available.
41 // Called on the main render thread. 56 // Called on the main render thread.
42 // TODO(tommi): This method appears to only be used by Pepper and in fact 57 // 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 58 // 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. 59 // to the complexity of all types of audio tracks+source implementations.
45 virtual media::AudioParameters GetOutputFormat() const = 0; 60 // http://crbug.com/577874
61 media::AudioParameters GetOutputFormat() const;
62
63 // Returns a unique class identifier. Some subclasses override and use this
64 // method to provide safe down-casting to their type.
65 virtual void* GetClassIdentifier() const;
66
67 protected:
68 friend class MediaStreamAudioSource;
69
70 // Called by the MediaStreamAudioSource to notify this track of an audio
71 // format change. In turn, all MediaStreamAudioSinks will be notified before
72 // the next chunk of audio is delivered to them.
73 void SetFormat(const media::AudioParameters& params);
74
75 // Called by the MediaStreamAudioSource to deliver audio data to this track,
76 // which in turn delivers the audio to one or more MediaStreamAudioSinks.
77 void DeliverDataToSinks(const media::AudioBus& audio_bus,
78 base::TimeTicks reference_time);
46 79
47 private: 80 private:
81 // These are run after this track has been stopped. Even if Stop() is called
82 // multiple times, the |stop_callbacks_| are only run the first time.
83 std::vector<base::Closure> stop_callbacks_;
84
85 // The current format of the audio passing through this track.
86 media::AudioParameters params_;
87
88 // Lock protects concurrent access to the sink lists below and the
89 // |is_enabled_| state, between the main thread and the audio thread.
90 mutable base::Lock lock_;
91
92 // Any sinks needing a call to MediaStreamAudioSink::OnSetFormat(), to be
93 // notified of the changed audio format, are placed in this list. This
94 // includes sinks added via AddSink() that need to have an initial
95 // OnSetFormat() call before audio data is first delivered. Sinks are moved
96 // from this list to |sinks_|.
97 std::vector<MediaStreamAudioSink*> pending_sinks_;
98
99 // Sinks that are up-to-date on the current audio format and are receiving
100 // audio data are placed in this list.
101 std::vector<MediaStreamAudioSink*> sinks_;
102
103 // When false, delivery of audio data is temporarily halted to the sinks.
104 bool is_enabled_;
105
48 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); 106 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack);
49 }; 107 };
50 108
51 } // namespace content 109 } // namespace content
52 110
53 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ 111 #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