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

Unified Diff: media/audio/virtual_audio_input_stream.h

Issue 11298006: Browser-wide audio mirroring for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments, some unit tests, move attach/detach into virtual audio output stream Created 8 years, 1 month 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: media/audio/virtual_audio_input_stream.h
diff --git a/media/audio/virtual_audio_input_stream.h b/media/audio/virtual_audio_input_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..7e85b67231fd76b7e2eb4e2231ebdf731ae78b9d
--- /dev/null
+++ b/media/audio/virtual_audio_input_stream.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_
+#define MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_
+
+#include <map>
+#include <set>
+
+#include "base/cancelable_callback.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/audio/audio_io.h"
+#include "media/audio/audio_manager_base.h"
+#include "media/audio/audio_parameters.h"
+#include "media/base/audio_converter.h"
+
+namespace media {
+
+class LoopbackAudioConverter;
+class VirtualAudioOutputStream;
+
+// Virtual audio input stream which is used for audio mirroring through the
+// TabCaptureApi. This audio stream uses virtual audio output streams as input
Alpha Left Google 2012/11/28 01:04:47 No need to mention TabCaptureApi, just say this is
justinlin 2012/11/28 14:30:31 Done.
+// and will mix them together to render audio. It will continuously render
+// audio until the audio mirroring session is ended.
+class MEDIA_EXPORT VirtualAudioInputStream
+ : public AudioInputStream {
+ public:
+ static VirtualAudioInputStream* MakeStream(AudioManagerBase* manager,
+ const AudioParameters& params);
+
+ // AudioInputStream:
+ virtual bool Open() OVERRIDE;
+ virtual void Start(AudioInputCallback* callback) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual double GetMaxVolume() OVERRIDE;
+ virtual void SetVolume(double volume) OVERRIDE;
+ virtual double GetVolume() OVERRIDE;
+ virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
+ virtual bool GetAutomaticGainControl() OVERRIDE;
+
+ // Attaches a virtual audio output stream to be used as input.
+ void AddOutputStream(
Alpha Left Google 2012/11/28 01:04:47 Mention ownership here, is VAOS owned by this clas
justinlin 2012/11/28 14:30:31 Done. I think it's common that all streams are own
+ VirtualAudioOutputStream* stream, const AudioParameters& params);
+ // Detaches a virtual audio output stream that went away (i.e. video closed).
Alpha Left Google 2012/11/28 01:04:47 nit: empty line before comments. It's confusing to
justinlin 2012/11/28 14:30:31 Done.
+ void RemoveOutputStream(VirtualAudioOutputStream* stream);
+
+protected:
+ friend class VirtualAudioInputStreamTest;
+ FRIEND_TEST_ALL_PREFIXES(AudioOutputControllerTest,
+ VirtualStreamsTriggerDeviceChange);
+
+ typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap;
+ typedef std::map<AudioOutputStream*, AudioParameters> OutputStreamParams;
+
+ void DoCallback();
Alpha Left Google 2012/11/28 01:04:47 Need more detailed comments.
justinlin 2012/11/28 14:30:31 Done.
+
+ VirtualAudioInputStream(AudioManagerBase* manager,
+ const AudioParameters& params);
+
+ virtual ~VirtualAudioInputStream();
+
+ AudioManagerBase* audio_manager_;
+ AudioInputCallback* callback_;
+ const int buffer_duration_ms_;
+ base::Time next_read_time_;
+ scoped_array<uint8> buffer_;
+ AudioParameters params_;
+ scoped_ptr<AudioBus> audio_bus_;
+ base::CancelableClosure on_more_data_cb_;
+ // AudioConverters associated with the attached virtual audio output streams,
Alpha Left Google 2012/11/28 01:04:47 nit: empty line before comments.
justinlin 2012/11/28 14:30:31 Done.
+ // partitioned by common AudioParameters.
+ AudioConvertersMap converters_;
+ // AudioConverter that takes all the audio converters and mixes them into one
Alpha Left Google 2012/11/28 01:04:47 nit: empty line before comments.
justinlin 2012/11/28 14:30:31 Done.
+ // final audio stream.
+ AudioConverter mixer_;
+ // Maps attached output streams to their parameters. We need this later to
Alpha Left Google 2012/11/28 01:04:47 nit: empty line before comments.
justinlin 2012/11/28 14:30:31 Done.
+ // remove the virtual output stream from the right AudioConverter.
+ OutputStreamParams output_params_;
+ int num_attached_outputs_streams_;
+
+ DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698