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

Unified Diff: media/audio/win/audio_low_latency_output_win.h

Issue 10823100: Adds support for multi-channel output audio for the low-latency path in Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added more mixing cases and improved the tests Created 8 years, 5 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: media/audio/win/audio_low_latency_output_win.h
diff --git a/media/audio/win/audio_low_latency_output_win.h b/media/audio/win/audio_low_latency_output_win.h
index 2c217ccf976b1e3023ad71fd68f53e3abfd57ce1..83e457119c894136bd346d0b01a9ecd50314cb6f 100644
--- a/media/audio/win/audio_low_latency_output_win.h
+++ b/media/audio/win/audio_low_latency_output_win.h
@@ -72,6 +72,12 @@
// supported format (X) and the new default device - to which we would like
// to switch - uses another format (Y), which is not supported given the
// configured audio parameters.
+// - The audio device is always opened with the same number of channels as
+// it supports natively (see HardwareChannelCount()). Channel up-mixing will
+// take place if the |params| parameter in the constructor contains a lower
+// number of channels than the number of native channels. As an example: if
+// the clients provides a channel count of 2 and a 7.1 headset is detected,
+// then 2 -> 7.1 up-mixing will take place for each OnMoreData() callback.
scherkus (not reviewing) 2012/08/02 17:14:14 what about opening up 8 channels when HardwareChan
henrika (OOO until Aug 14) 2012/08/03 14:55:56 Added comment about that we don't support it. Als
//
// Core Audio API details:
//
@@ -115,7 +121,7 @@
// Experimental exclusive mode:
//
// - It is possible to open up a stream in exclusive mode by using the
-// --enable-exclusive-mode command line flag.
+// --enable-exclusive-audio command line flag.
// - The internal buffering scheme is less flexible for exclusive streams.
// Hence, some manual tuning will be required before deciding what frame
// size to use. See the WinAudioOutputTest unit test for more details.
@@ -143,6 +149,7 @@
#include <string>
#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
#include "base/win/scoped_co_mem.h"
@@ -156,6 +163,7 @@
namespace media {
class AudioManagerWin;
+class WASAPIAudioOutputStreamTest;
scherkus (not reviewing) 2012/08/02 17:14:14 AFAIK you don't need to fwd decl this for FRIEND_T
henrika (OOO until Aug 14) 2012/08/03 14:55:56 Correct. Thanks ;-)
// AudioOutputStream implementation using Windows Core Audio APIs.
// The IMMNotificationClient interface enables device event notifications
@@ -182,9 +190,19 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
virtual void SetVolume(double volume) OVERRIDE;
virtual void GetVolume(double* volume) OVERRIDE;
- // Retrieves the stream format that the audio engine uses for its internal
- // processing/mixing of shared-mode streams.
- // This method should not be used in combination with exclusive-mode streams.
+ // Retrieves the number of channels the audio engine uses for its internal
+ // processing/mixing of shared-mode streams for the default endpoint device.
+ static int HardwareChannelCount();
+
+ // Retrieves the channel layout the audio engine uses for its internal
+ // processing/mixing of shared-mode streams for the default endpoint device.
+ // Note that we convert an internal channel layout mask (see ChannelMask())
+ // into a Chrome-specific channel layout enumerator in this method, hence
+ // the match might not be perfect.
+ static ChannelLayout HardwareChannelLayout();
+
+ // Retrieves the sample rate the audio engine uses for its internal
+ // processing/mixing of shared-mode streams for the default endpoint device.
static int HardwareSampleRate(ERole device_role);
// Returns AUDCLNT_SHAREMODE_EXCLUSIVE if --enable-exclusive-mode is used
@@ -194,6 +212,8 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
bool started() const { return started_; }
private:
+ FRIEND_TEST_ALL_PREFIXES(WASAPIAudioOutputStreamTest, HardwareChannelCount);
+
// Implementation of IUnknown (trivial in this case). See
// msdn.microsoft.com/en-us/library/windows/desktop/dd371403(v=vs.85).aspx
// for details regarding why proper implementations of AddRef(), Release()
@@ -255,7 +275,15 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
// new default audio device.
bool RestartRenderingUsingNewDefaultDevice();
- AUDCLNT_SHAREMODE share_mode() const { return share_mode_; }
+ // Returns the number of channels the audio engine uses for its internal
+ // processing/mixing of shared-mode streams for the default endpoint device.
+ int endpoint_channel_count() { return format_.Format.nChannels; }
+
+ // The ratio between the the number of native audio channels used by the
+ // audio device and the number of audio channels from the client.
+ int channel_factor() const {
+ return (format_.Format.nChannels / client_channel_count_);
+ }
// Initializes the COM library for use by the calling thread and sets the
// thread's concurrency model to multi-threaded.
@@ -272,12 +300,14 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
base::DelegateSimpleThread* render_thread_;
// Contains the desired audio format which is set up at construction.
- WAVEFORMATEX format_;
+ // Extended PCM waveform format structure based on WAVEFORMATEXTENSIBLE.
+ // Use this for multiple channel and hi-resolution PCM data.
+ WAVEFORMATPCMEX format_;
// Copy of the audio format which we know the audio engine supports.
// It is recommended to ensure that the sample rate in |format_| is identical
// to the sample rate in |audio_engine_mix_format_|.
- base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format_;
+ base::win::ScopedCoMem<WAVEFORMATPCMEX> audio_engine_mix_format_;
bool opened_;
bool started_;
@@ -316,6 +346,11 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
// where AUDCLNT_SHAREMODE_SHARED is the default.
AUDCLNT_SHAREMODE share_mode_;
+ // The channel count set by the client in |params| which is provided to the
+ // constructor. The client must feed the AudioSourceCallback::OnMoreData()
+ // callback with PCM-data that contains this number of channels.
+ int client_channel_count_;
+
// Counts the number of audio frames written to the endpoint buffer.
UINT64 num_written_frames_;

Powered by Google App Engine
This is Rietveld 408576698