Index: media/audio/audio_output_mixer.h |
=================================================================== |
--- media/audio/audio_output_mixer.h (revision 0) |
+++ media/audio/audio_output_mixer.h (revision 0) |
@@ -0,0 +1,83 @@ |
+// 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. |
+ |
+// AudioOutputMixer is a class that implements browser-side audio mixer. |
+// AudioOutputMixer implements both AudioOutputDispatcher and |
+// AudioSourceCallback interfaces. |
+ |
+#ifndef MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_ |
+#define MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_ |
+ |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/synchronization/lock.h" |
+#include "base/timer.h" |
+#include "media/audio/audio_io.h" |
+#include "media/audio/audio_manager.h" |
+#include "media/audio/audio_output_dispatcher.h" |
+#include "media/audio/audio_parameters.h" |
+ |
+class MEDIA_EXPORT AudioOutputMixer |
+ : public AudioOutputDispatcher, |
+ public AudioOutputStream::AudioSourceCallback { |
+ public: |
+ AudioOutputMixer(AudioManager* audio_manager, |
+ const AudioParameters& params, |
+ base::TimeDelta close_delay); |
+ |
+ // AudioOutputDispatcher interface. |
+ virtual bool StreamOpened() OVERRIDE; |
+ virtual AudioOutputStream* StreamStarted( |
+ AudioOutputStream::AudioSourceCallback* callback, |
+ AudioOutputProxy* stream_proxy) OVERRIDE; |
+ virtual void StreamStopped(AudioOutputStream* physical_stream, |
+ AudioOutputProxy* stream_proxy) OVERRIDE; |
+ virtual void StreamVolumeSet(AudioOutputStream* physical_stream, |
+ double volume) OVERRIDE; |
+ virtual void StreamClosed(AudioOutputProxy* stream_proxy) OVERRIDE; |
+ virtual void Shutdown() OVERRIDE; |
+ |
+ // AudioSourceCallback interface. |
+ virtual uint32 OnMoreData(AudioOutputStream* stream, |
+ uint8* dest, |
+ uint32 max_size, |
+ AudioBuffersState buffers_state) OVERRIDE; |
+ virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; |
+ virtual void WaitTillDataReady() OVERRIDE; |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<AudioOutputMixer>; |
+ ~AudioOutputMixer(); |
tommi (sloooow) - chröme
2012/04/03 13:47:51
virtual
enal1
2012/04/04 18:46:55
Done.
|
+ |
+ // Called by |close_timer_|. Closes physical stream. |
+ void ClosePhysicalStream(); |
+ |
+ // The |lock_| must be acquired whenever we modify |proxies_| in the audio |
+ // manager thread or accessing it in the hardware audio thread. Read in the |
+ // audio manager thread is safe. |
+ base::Lock lock_; |
+ |
+ // List of audio output proxies. |
+ typedef std::vector<AudioOutputProxy*> ProxyList; |
vrk (LEFT CHROMIUM)
2012/03/30 22:25:58
Instead of a vector of AudioOutputProxies, please
enal1
2012/04/04 18:46:55
AudioOutputProxy needs to store volume, as it is p
|
+ ProxyList proxies_; |
+ |
+ // Physical stream for this mixer. |
+ scoped_ptr<AudioOutputStream> physical_stream_; |
+ |
+ // Temporary buffer used when mixing. Allocated in the constructor |
+ // to avoid constant allocation/deallocation in the callback. |
+ scoped_array<uint8> mixer_data_; |
+ |
+ // Used to post delayed tasks to ourselves that we cancel inside Shutdown(). |
+ base::WeakPtrFactory<AudioOutputMixer> weak_this_; |
+ base::DelayTimer<AudioOutputMixer> close_timer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputMixer); |
+}; |
+ |
+#endif // MEDIA_AUDIO_AUDIO_OUTPUT_MIXER_H_ |