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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_audio_track.h
diff --git a/content/renderer/media/media_stream_audio_track.h b/content/renderer/media/media_stream_audio_track.h
index 2175b4e186f47fefc982e097a1691dac1fdd7383..c523203bb368b363a7104360d5e2e2a091258071 100644
--- a/content/renderer/media/media_stream_audio_track.h
+++ b/content/renderer/media/media_stream_audio_track.h
@@ -5,36 +5,51 @@
#ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_
#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_
+#include <vector>
+
+#include "base/callback.h"
#include "base/macros.h"
+#include "base/synchronization/lock.h"
#include "content/renderer/media/media_stream_track.h"
-
-namespace webrtc {
-class AudioTrackInterface;
-} // namespace webrtc
+#include "media/audio/audio_parameters.h"
namespace content {
class MediaStreamAudioSink;
+class MediaStreamAudioSource;
+// Provides the part of the audio pipeline delivering audio from a
+// MediaStreamAudioSource to one or more MediaStreamAudioSinks. An instance of
+// this class is owned by blink::WebMediaStreamTrack, and clients should use
+// Get() to gain access to a MediaStreamAudioTrack.
class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
public:
explicit MediaStreamAudioTrack(bool is_local_track);
+
~MediaStreamAudioTrack() override;
- static MediaStreamAudioTrack* GetTrack(
- const blink::WebMediaStreamTrack& track);
+ // Accessor to the MediaStreamAudioTrack instance owned (as extraData) by the
+ // given WebMediaStreamTrack.
+ static MediaStreamAudioTrack* Get(const blink::WebMediaStreamTrack& track);
- // Add a sink to the track. This function will trigger a OnSetFormat()
- // call on the |sink|.
- // Called on the main render thread.
- virtual void AddSink(MediaStreamAudioSink* sink) = 0;
+ // When Stop() is called on this track, |stop_callback| will be run. This is
+ // generally used to notify the source that the track cannot accept more
+ // data.
+ void AddStopObserver(const base::Closure& stop_callback);
- // Remove a sink from the track.
- // Called on the main render thread.
- virtual void RemoveSink(MediaStreamAudioSink* sink) = 0;
+ // Adds |sink| as another destination of audio flow. Calls
+ // MediaStreamAudioSink::OnReadyStateChanged() to notify the sink it is live.
+ void AddSink(MediaStreamAudioSink* sink);
+
+ // Removes |sink| as a receiver of audio flow. When this method returns, the
+ // sink's OnSetFormat() and OnData() methods will not be called again on any
+ // thread. Calls MediaStreamAudioSink::OnReadyStateChanged() to notify the
+ // sink it is no longer live.
+ void RemoveSink(MediaStreamAudioSink* sink);
- // TODO(tommi, xians): Remove this method.
- virtual webrtc::AudioTrackInterface* GetAudioAdapter();
+ // MediaStreamTrack implementation.
+ void SetEnabled(bool enabled) override;
+ void Stop() final;
// Returns the output format of the capture source. May return an invalid
// AudioParameters if the format is not yet available.
@@ -42,9 +57,52 @@ class CONTENT_EXPORT MediaStreamAudioTrack : public MediaStreamTrack {
// TODO(tommi): This method appears to only be used by Pepper and in fact
// does not appear to be necessary there. We should remove it since it adds
// to the complexity of all types of audio tracks+source implementations.
- virtual media::AudioParameters GetOutputFormat() const = 0;
+ // http://crbug.com/577874
+ media::AudioParameters GetOutputFormat() const;
+
+ // Returns a unique class identifier. Some subclasses override and use this
+ // method to provide safe down-casting to their type.
+ virtual void* GetClassIdentifier() const;
+
+ protected:
+ friend class MediaStreamAudioSource;
+
+ // Called by the MediaStreamAudioSource to notify this track of an audio
+ // format change. In turn, all MediaStreamAudioSinks will be notified before
+ // the next chunk of audio is delivered to them.
+ void SetFormat(const media::AudioParameters& params);
+
+ // Called by the MediaStreamAudioSource to deliver audio data to this track,
+ // which in turn delivers the audio to one or more MediaStreamAudioSinks.
+ void DeliverDataToSinks(const media::AudioBus& audio_bus,
+ base::TimeTicks reference_time);
private:
+ // These are run after this track has been stopped. Even if Stop() is called
+ // multiple times, the |stop_callbacks_| are only run the first time.
+ std::vector<base::Closure> stop_callbacks_;
+
+ // The current format of the audio passing through this track.
+ media::AudioParameters params_;
+
+ // Lock protects concurrent access to the sink lists below and the
+ // |is_enabled_| state, between the main thread and the audio thread.
+ mutable base::Lock lock_;
+
+ // Any sinks needing a call to MediaStreamAudioSink::OnSetFormat(), to be
+ // notified of the changed audio format, are placed in this list. This
+ // includes sinks added via AddSink() that need to have an initial
+ // OnSetFormat() call before audio data is first delivered. Sinks are moved
+ // from this list to |sinks_|.
+ std::vector<MediaStreamAudioSink*> pending_sinks_;
+
+ // Sinks that are up-to-date on the current audio format and are receiving
+ // audio data are placed in this list.
+ std::vector<MediaStreamAudioSink*> sinks_;
+
+ // When false, delivery of audio data is temporarily halted to the sinks.
+ bool is_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack);
};
« 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