Author:
hen...@chromium.org
Date: Wed Nov 14 06:54:56 2012
New Revision: 167674
Log:
Removed IMMNotification from WASAPIAudioOutputStream.
The implementation of IMMNotification has been disabled since we started to use a separate IMMNotification implementation in AudioDeviceListenerWin. It means that some code has been "dead" and it was my task to remove the non-used code.
BUG=none
TEST=manual tests in Chrome to verify that device switch still works using the existing framework.
Review URL:
https://chromiumcodereview.appspot.com/11366241
Modified:
trunk/src/media/audio/win/audio_low_latency_output_win.cc
trunk/src/media/audio/win/audio_low_latency_output_win.h
Modified: trunk/src/media/audio/win/audio_low_latency_output_win.cc
==============================================================================
--- trunk/src/media/audio/win/audio_low_latency_output_win.cc (original)
+++ trunk/src/media/audio/win/audio_low_latency_output_win.cc Wed Nov 14 06:54:56 2012
@@ -239,10 +239,6 @@
// Create the event which will be set in Stop() when capturing shall stop.
stop_render_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL));
DCHECK(stop_render_event_.IsValid());
-
- // Create the event which will be set when a stream switch shall take place.
- stream_switch_event_.Set(CreateEvent(NULL, FALSE, FALSE, NULL));
- DCHECK(stream_switch_event_.IsValid());
}
WASAPIAudioOutputStream::~WASAPIAudioOutputStream() {}
@@ -484,7 +480,6 @@
bool playing = true;
bool error = false;
HANDLE wait_array[] = { stop_render_event_,
- stream_switch_event_,
audio_samples_render_event_ };
UINT64 device_frequency = 0;
@@ -518,15 +513,6 @@
playing = false;
break;
case WAIT_OBJECT_0 + 1:
- // |stream_switch_event_| has been set. Stop rendering and try to
- // re-start the session using a new endpoint device.
- if (!RestartRenderingUsingNewDefaultDevice()) {
- // Abort the thread since stream switching failed.
- playing = false;
- error = true;
- }
- break;
- case WAIT_OBJECT_0 + 2:
{
// |audio_samples_render_event_| has been set.
UINT32 num_queued_frames = 0;
@@ -942,82 +928,6 @@
return hr;
}
-ULONG WASAPIAudioOutputStream::AddRef() {
- NOTREACHED() << "IMMNotificationClient should not use this method.";
- return 1;
-}
-
-ULONG WASAPIAudioOutputStream::Release() {
- NOTREACHED() << "IMMNotificationClient should not use this method.";
- return 1;
-}
-
-HRESULT WASAPIAudioOutputStream::QueryInterface(REFIID iid, void** object) {
- NOTREACHED() << "IMMNotificationClient should not use this method.";
- if (iid == IID_IUnknown || iid == __uuidof(IMMNotificationClient)) {
- *object = static_cast < IMMNotificationClient*>(this);
- } else {
- return E_NOINTERFACE;
- }
- return S_OK;
-}
-
-STDMETHODIMP WASAPIAudioOutputStream::OnDeviceStateChanged(LPCWSTR device_id,
- DWORD new_state) {
-#ifndef NDEBUG
- std::string device_name = GetDeviceName(device_id);
- std::string device_state;
-
- switch (new_state) {
- case DEVICE_STATE_ACTIVE:
- device_state = "ACTIVE";
- break;
- case DEVICE_STATE_DISABLED:
- device_state = "DISABLED";
- break;
- case DEVICE_STATE_NOTPRESENT:
- device_state = "NOTPRESENT";
- break;
- case DEVICE_STATE_UNPLUGGED:
- device_state = "UNPLUGGED";
- break;
- default:
- break;
- }
-
- DVLOG(1) << "-> State changed to " << device_state
- << " for device: " << device_name;
-#endif
- return S_OK;
-}
-
-HRESULT WASAPIAudioOutputStream::OnDefaultDeviceChanged(
- EDataFlow flow, ERole role, LPCWSTR new_default_device_id) {
- if (new_default_device_id == NULL) {
- // The user has removed or disabled the default device for our
- // particular role, and no other device is available to take that role.
- DLOG(ERROR) << "All devices are disabled.";
- return E_FAIL;
- }
-
- if (flow == eRender && role == device_role_) {
- // Log the name of the new default device for our configured role.
- std::string new_default_device = GetDeviceName(new_default_device_id);
- DVLOG(1) << "-> New default device: " << new_default_device;
-
- // Initiate a stream switch if not already initiated by signaling the
- // stream-switch event to inform the render thread that it is OK to
- // re-initialize the active audio renderer. All the action takes place
- // on the WASAPI render thread.
- if (!restart_rendering_mode_) {
- restart_rendering_mode_ = true;
- SetEvent(stream_switch_event_.Get());
- }
- }
-
- return S_OK;
-}
-
std::string WASAPIAudioOutputStream::GetDeviceName(LPCWSTR device_id) const {
std::string name;
ScopedComPtr<IMMDevice> audio_device;
@@ -1043,67 +953,4 @@
return name;
}
-bool WASAPIAudioOutputStream::RestartRenderingUsingNewDefaultDevice() {
- DCHECK(base::PlatformThread::CurrentId() == render_thread_->tid());
- DCHECK(restart_rendering_mode_);
-
- // The |restart_rendering_mode_| event has been signaled which means that
- // we must stop the current renderer and start a new render session using
- // the new default device with the configured role.
-
- // Stop the current rendering.
- HRESULT hr = audio_client_->Stop();
- if (FAILED(hr)) {
- restart_rendering_mode_ = false;
- return false;
- }
-
- // Release acquired interfaces (IAudioRenderClient, IAudioClient, IMMDevice).
- audio_render_client_.Release();
- audio_client_.Release();
- endpoint_device_.Release();
-
- // Retrieve the new default render audio endpoint (IMMDevice) for the
- // specified role.
- hr = device_enumerator_->GetDefaultAudioEndpoint(
- eRender, device_role_, endpoint_device_.Receive());
- if (FAILED(hr)) {
- restart_rendering_mode_ = false;
- return false;
- }
-
- // Re-create an IAudioClient interface.
- hr = ActivateRenderDevice();
- if (FAILED(hr)) {
- restart_rendering_mode_ = false;
- return false;
- }
-
- // Retrieve the new mix format and ensure that it is supported given
- // the predefined format set at construction.
- base::win::ScopedCoMem<WAVEFORMATEX> new_audio_engine_mix_format;
- hr = audio_client_->GetMixFormat(&new_audio_engine_mix_format);
- if (FAILED(hr) || !DesiredFormatIsSupported()) {
- restart_rendering_mode_ = false;
- return false;
- }
-
- // Re-initialize the audio engine using the new audio endpoint.
- // This method will create a new IAudioRenderClient interface.
- hr = InitializeAudioEngine();
- if (FAILED(hr)) {
- restart_rendering_mode_ = false;
- return false;
- }
-
- // All released interfaces (IAudioRenderClient, IAudioClient, IMMDevice)
- // are now re-initiated and it is now possible to re-start audio rendering.
-
- // Start rendering again using the new default audio endpoint.
- hr = audio_client_->Start();
-
- restart_rendering_mode_ = false;
- return SUCCEEDED(hr);
-}
-
} // namespace media
Modified: trunk/src/media/audio/win/audio_low_latency_output_win.h
==============================================================================
--- trunk/src/media/audio/win/audio_low_latency_output_win.h (original)
+++ trunk/src/media/audio/win/audio_low_latency_output_win.h Wed Nov 14 06:54:56 2012
@@ -32,29 +32,6 @@
// o Endpoint buffer (~20 ms to ensure glitch-free rendering).
// - Note that, if the user selects a packet size of e.g. 100 ms, the total
// delay will be approximately 115 ms (10 + 5 + 100).
-// - Supports device events using the IMMNotificationClient Interface. If
-// streaming has started, a so-called stream switch will take place in the
-// following situations:
-// o The user enables or disables an audio endpoint device from Device
-// Manager or from the Windows multimedia control panel, Mmsys.cpl.
-// o The user adds an audio adapter to the system or removes an audio
-// adapter from the system.
-// o The user plugs an audio endpoint device into an audio jack with
-// jack-presence detection, or removes an audio endpoint device from
-// such a jack.
-// o The user changes the device role that is assigned to a device.
-// o The value of a property of a device changes.
-// Practical/typical example: A user has two audio devices A and B where
-// A is a built-in device configured as Default Communication and B is a
-// USB device set as Default device. Audio rendering starts and audio is
-// played through the device B since the eConsole role is used by the audio
-// manager in Chrome today. If the user now removes the USB device (B), it
-// will be detected and device A will instead be defined as the new default
-// device. Rendering will automatically stop, all resources will be released
-// and a new session will be initialized and started using device A instead.
-// The net effect for the user is that audio will automatically switch from
-// device B to device A. Same thing will happen if the user now re-inserts
-// the USB device again.
//
// Implementation notes:
//
@@ -94,9 +71,6 @@
// - Audio-rendering endpoint devices can have three roles:
// Console (eConsole), Communications (eCommunications), and Multimedia
// (eMultimedia). Search for "Device Roles" on MSDN for more details.
-// - The actual stream-switch is executed on the audio-render thread but it
-// is triggered by an internal MMDevice thread using callback methods
-// in the IMMNotificationClient interface.
//
// Threading details:
//
@@ -108,8 +82,6 @@
// class, and the AudioSourceCallback::OnMoreData() method will be called
// from this thread. Stream switching also takes place on the audio-render
// thread.
-// - All callback methods from the IMMNotificationClient interface will be
-// called on a Windows-internal MMDevice thread.
//
// Experimental exclusive mode:
//
@@ -136,7 +108,6 @@
#define MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_OUTPUT_WIN_H_
#include <Audioclient.h>
-#include <audiopolicy.h>
#include <MMDeviceAPI.h>
#include <string>
@@ -158,11 +129,7 @@
class AudioManagerWin;
// AudioOutputStream implementation using Windows Core Audio APIs.
-// TODO(henrika): Remove IMMNotificationClient implementation now that we have
-// AudioDeviceListenerWin; currently just disabled since extraction is extremely
-// advanced.
-class MEDIA_EXPORT WASAPIAudioOutputStream
- : public IMMNotificationClient,
+class MEDIA_EXPORT WASAPIAudioOutputStream :
public AudioOutputStream,
public base::DelegateSimpleThread::Delegate {
public:
@@ -171,6 +138,7 @@
WASAPIAudioOutputStream(AudioManagerWin* manager,
const AudioParameters& params,
ERole device_role);
+
// The dtor is typically called by the AudioManager only and it is usually
// triggered by calling AudioOutputStream::Close().
virtual ~WASAPIAudioOutputStream();
@@ -209,37 +177,6 @@
int GetEndpointChannelCountForTesting() { return format_.Format.nChannels; }
private:
- // 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()
- // and QueryInterface() are not needed here.
- STDMETHOD_(ULONG, AddRef)();
- STDMETHOD_(ULONG, Release)();
- STDMETHOD(QueryInterface)(REFIID iid, void** object);
-
- // Implementation of the abstract interface IMMNotificationClient.
- // Provides notifications when an audio endpoint device is added or removed,
- // when the state or properties of a device change, or when there is a
- // change in the default role assigned to a device. See
- //
msdn.microsoft.com/en-us/library/windows/desktop/dd371417(v=vs.85).aspx
- // for more details about the IMMNotificationClient interface.
-
- // The default audio endpoint device for a particular role has changed.
- // This method is only used for diagnostic purposes.
- STDMETHOD(OnDeviceStateChanged)(LPCWSTR device_id, DWORD new_state);
-
- // Indicates that the state of an audio endpoint device has changed.
- STDMETHOD(OnDefaultDeviceChanged)(EDataFlow flow, ERole role,
- LPCWSTR new_default_device_id);
-
- // These IMMNotificationClient methods are currently not utilized.
- STDMETHOD(OnDeviceAdded)(LPCWSTR device_id) { return S_OK; }
- STDMETHOD(OnDeviceRemoved)(LPCWSTR device_id) { return S_OK; }
- STDMETHOD(OnPropertyValueChanged)(LPCWSTR device_id,
- const PROPERTYKEY key) {
- return S_OK;
- }
-
// DelegateSimpleThread::Delegate implementation.
virtual void Run() OVERRIDE;
@@ -263,13 +200,6 @@
// Converts unique endpoint ID to user-friendly device name.
std::string GetDeviceName(LPCWSTR device_id) const;
- // Called on the audio render thread when the current audio stream must
- // be re-initialized because the default audio device has changed. This
- // method: stops the current renderer, releases and re-creates all WASAPI
- // interfaces, creates a new IMMDevice and re-starts rendering using the
- // new default audio device.
- bool RestartRenderingUsingNewDefaultDevice();
-
// Contains the thread ID of the creating thread.
base::PlatformThreadId creating_thread_id_;
@@ -358,9 +288,6 @@
// This event will be signaled when rendering shall stop.
base::win::ScopedHandle stop_render_event_;
- // This event will be signaled when stream switching shall take place.
- base::win::ScopedHandle stream_switch_event_;
-
// Container for retrieving data from AudioSourceCallback::OnMoreData().
scoped_ptr<AudioBus> audio_bus_;