| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/win/core_audio_util_win.h" | 5 #include "media/audio/win/core_audio_util_win.h" |
| 6 | 6 |
| 7 #include <audioclient.h> | 7 #include <audioclient.h> |
| 8 #include <devicetopology.h> | 8 #include <devicetopology.h> |
| 9 #include <functiondiscoverykeys_devpkey.h> | 9 #include <functiondiscoverykeys_devpkey.h> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/win/scoped_co_mem.h" | 15 #include "base/win/scoped_co_mem.h" |
| 16 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 17 #include "base/win/scoped_propvariant.h" | 17 #include "base/win/scoped_propvariant.h" |
| 18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 19 #include "media/base/media_switches.h" | 19 #include "media/base/media_switches.h" |
| 20 | 20 |
| 21 using base::win::ScopedCoMem; | 21 using base::win::ScopedCoMem; |
| 22 using base::win::ScopedHandle; | 22 using base::win::ScopedHandle; |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 // See header file for documentation. |
| 27 // {BE39AF4F-087C-423F-9303-234EC1E5B8EE} |
| 28 const GUID kCommunicationsSessionId = { |
| 29 0xbe39af4f, 0x87c, 0x423f, { 0x93, 0x3, 0x23, 0x4e, 0xc1, 0xe5, 0xb8, 0xee } |
| 30 }; |
| 31 |
| 26 enum { KSAUDIO_SPEAKER_UNSUPPORTED = 0 }; | 32 enum { KSAUDIO_SPEAKER_UNSUPPORTED = 0 }; |
| 27 | 33 |
| 28 // Converts Microsoft's channel configuration to ChannelLayout. | 34 // Converts Microsoft's channel configuration to ChannelLayout. |
| 29 // This mapping is not perfect but the best we can do given the current | 35 // This mapping is not perfect but the best we can do given the current |
| 30 // ChannelLayout enumerator and the Windows-specific speaker configurations | 36 // ChannelLayout enumerator and the Windows-specific speaker configurations |
| 31 // defined in ksmedia.h. Don't assume that the channel ordering in | 37 // defined in ksmedia.h. Don't assume that the channel ordering in |
| 32 // ChannelLayout is exactly the same as the Windows specific configuration. | 38 // ChannelLayout is exactly the same as the Windows specific configuration. |
| 33 // As an example: KSAUDIO_SPEAKER_7POINT1_SURROUND is mapped to | 39 // As an example: KSAUDIO_SPEAKER_7POINT1_SURROUND is mapped to |
| 34 // CHANNEL_LAYOUT_7_1 but the positions of Back L, Back R and Side L, Side R | 40 // CHANNEL_LAYOUT_7_1 but the positions of Back L, Back R and Side L, Side R |
| 35 // speakers are different in these two definitions. | 41 // speakers are different in these two definitions. |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 if (!client || FAILED(GetSharedModeMixFormat(client, &format))) | 734 if (!client || FAILED(GetSharedModeMixFormat(client, &format))) |
| 729 return 0; | 735 return 0; |
| 730 | 736 |
| 731 return static_cast<ChannelConfig>(format.dwChannelMask); | 737 return static_cast<ChannelConfig>(format.dwChannelMask); |
| 732 } | 738 } |
| 733 | 739 |
| 734 HRESULT CoreAudioUtil::SharedModeInitialize(IAudioClient* client, | 740 HRESULT CoreAudioUtil::SharedModeInitialize(IAudioClient* client, |
| 735 const WAVEFORMATPCMEX* format, | 741 const WAVEFORMATPCMEX* format, |
| 736 HANDLE event_handle, | 742 HANDLE event_handle, |
| 737 uint32* endpoint_buffer_size) { | 743 uint32* endpoint_buffer_size) { |
| 744 return SharedModeInitializeWithSession( |
| 745 client, format, event_handle, endpoint_buffer_size, NULL); |
| 746 } |
| 747 |
| 748 HRESULT CoreAudioUtil::SharedModeInitializeWithSession( |
| 749 IAudioClient* client, const WAVEFORMATPCMEX* format, HANDLE event_handle, |
| 750 uint32* endpoint_buffer_size, const GUID* session_guid) { |
| 738 DCHECK(IsSupported()); | 751 DCHECK(IsSupported()); |
| 739 | 752 |
| 740 // Use default flags (i.e, dont set AUDCLNT_STREAMFLAGS_NOPERSIST) to | 753 // Use default flags (i.e, dont set AUDCLNT_STREAMFLAGS_NOPERSIST) to |
| 741 // ensure that the volume level and muting state for a rendering session | 754 // ensure that the volume level and muting state for a rendering session |
| 742 // are persistent across system restarts. The volume level and muting | 755 // are persistent across system restarts. The volume level and muting |
| 743 // state for a capture session are never persistent. | 756 // state for a capture session are never persistent. |
| 744 DWORD stream_flags = 0; | 757 DWORD stream_flags = 0; |
| 745 | 758 |
| 746 // Enable event-driven streaming if a valid event handle is provided. | 759 // Enable event-driven streaming if a valid event handle is provided. |
| 747 // After the stream starts, the audio engine will signal the event handle | 760 // After the stream starts, the audio engine will signal the event handle |
| 748 // to notify the client each time a buffer becomes ready to process. | 761 // to notify the client each time a buffer becomes ready to process. |
| 749 // Event-driven buffering is supported for both rendering and capturing. | 762 // Event-driven buffering is supported for both rendering and capturing. |
| 750 // Both shared-mode and exclusive-mode streams can use event-driven buffering. | 763 // Both shared-mode and exclusive-mode streams can use event-driven buffering. |
| 751 bool use_event = (event_handle != NULL && | 764 bool use_event = (event_handle != NULL && |
| 752 event_handle != INVALID_HANDLE_VALUE); | 765 event_handle != INVALID_HANDLE_VALUE); |
| 753 if (use_event) | 766 if (use_event) |
| 754 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK; | 767 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK; |
| 755 DVLOG(2) << "stream_flags: 0x" << std::hex << stream_flags; | 768 DVLOG(2) << "stream_flags: 0x" << std::hex << stream_flags; |
| 756 | 769 |
| 757 // Initialize the shared mode client for minimal delay. | 770 // Initialize the shared mode client for minimal delay. |
| 758 HRESULT hr = client->Initialize(AUDCLNT_SHAREMODE_SHARED, | 771 HRESULT hr = client->Initialize(AUDCLNT_SHAREMODE_SHARED, |
| 759 stream_flags, | 772 stream_flags, |
| 760 0, | 773 0, |
| 761 0, | 774 0, |
| 762 reinterpret_cast<const WAVEFORMATEX*>(format), | 775 reinterpret_cast<const WAVEFORMATEX*>(format), |
| 763 NULL); | 776 session_guid); |
| 764 if (FAILED(hr)) { | 777 if (FAILED(hr)) { |
| 765 DVLOG(1) << "IAudioClient::Initialize: " << std::hex << hr; | 778 DVLOG(1) << "IAudioClient::Initialize: " << std::hex << hr; |
| 766 return hr; | 779 return hr; |
| 767 } | 780 } |
| 768 | 781 |
| 769 if (use_event) { | 782 if (use_event) { |
| 770 hr = client->SetEventHandle(event_handle); | 783 hr = client->SetEventHandle(event_handle); |
| 771 if (FAILED(hr)) { | 784 if (FAILED(hr)) { |
| 772 DVLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr; | 785 DVLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr; |
| 773 return hr; | 786 return hr; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 return false; | 855 return false; |
| 843 | 856 |
| 844 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to | 857 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to |
| 845 // explicitly write silence data to the rendering buffer. | 858 // explicitly write silence data to the rendering buffer. |
| 846 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; | 859 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; |
| 847 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, | 860 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, |
| 848 AUDCLNT_BUFFERFLAGS_SILENT)); | 861 AUDCLNT_BUFFERFLAGS_SILENT)); |
| 849 } | 862 } |
| 850 | 863 |
| 851 } // namespace media | 864 } // namespace media |
| OLD | NEW |