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/audio_low_latency_output_win.h" | 5 #include "media/audio/win/audio_low_latency_output_win.h" |
6 | 6 |
7 #include <Functiondiscoverykeys_devpkey.h> | 7 #include <Functiondiscoverykeys_devpkey.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 manager_(manager), | 331 manager_(manager), |
332 opened_(false), | 332 opened_(false), |
333 started_(false), | 333 started_(false), |
334 restart_rendering_mode_(false), | 334 restart_rendering_mode_(false), |
335 volume_(1.0), | 335 volume_(1.0), |
336 endpoint_buffer_size_frames_(0), | 336 endpoint_buffer_size_frames_(0), |
337 device_role_(device_role), | 337 device_role_(device_role), |
338 share_mode_(GetShareMode()), | 338 share_mode_(GetShareMode()), |
339 client_channel_count_(params.channels()), | 339 client_channel_count_(params.channels()), |
340 num_written_frames_(0), | 340 num_written_frames_(0), |
341 source_(NULL) { | 341 source_(NULL), |
| 342 audio_bus_(AudioBus::Create(params)) { |
342 CHECK(com_init_.succeeded()); | 343 CHECK(com_init_.succeeded()); |
343 DCHECK(manager_); | 344 DCHECK(manager_); |
344 | 345 |
345 // Load the Avrt DLL if not already loaded. Required to support MMCSS. | 346 // Load the Avrt DLL if not already loaded. Required to support MMCSS. |
346 bool avrt_init = avrt::Initialize(); | 347 bool avrt_init = avrt::Initialize(); |
347 DCHECK(avrt_init) << "Failed to load the avrt.dll"; | 348 DCHECK(avrt_init) << "Failed to load the avrt.dll"; |
348 | 349 |
349 if (share_mode_ == AUDCLNT_SHAREMODE_EXCLUSIVE) { | 350 if (share_mode_ == AUDCLNT_SHAREMODE_EXCLUSIVE) { |
350 VLOG(1) << ">> Note that EXCLUSIVE MODE is enabled <<"; | 351 VLOG(1) << ">> Note that EXCLUSIVE MODE is enabled <<"; |
351 } | 352 } |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 // A time stamp is also stored in the AudioBuffersState. This | 815 // A time stamp is also stored in the AudioBuffersState. This |
815 // time stamp can be used at the client side to compensate for | 816 // time stamp can be used at the client side to compensate for |
816 // the delay between the usage of the delay value and the time | 817 // the delay between the usage of the delay value and the time |
817 // of generation. | 818 // of generation. |
818 | 819 |
819 uint32 num_filled_bytes = 0; | 820 uint32 num_filled_bytes = 0; |
820 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3; | 821 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3; |
821 | 822 |
822 if (channel_factor() == 1) { | 823 if (channel_factor() == 1) { |
823 // Case I: no up-mixing. | 824 // Case I: no up-mixing. |
824 num_filled_bytes = source_->OnMoreData( | 825 int frames_filled = source_->OnMoreData( |
825 audio_data, packet_size_bytes_, | 826 audio_bus_.get(), AudioBuffersState(0, audio_delay_bytes)); |
826 AudioBuffersState(0, audio_delay_bytes)); | 827 num_filled_bytes = frames_filled * frame_size_; |
| 828 DCHECK_LE(num_filled_bytes, packet_size_bytes_); |
| 829 audio_bus_->ToInterleaved( |
| 830 frames_filled, bytes_per_sample, audio_data); |
827 } else { | 831 } else { |
828 // Case II: up-mixing. | 832 // Case II: up-mixing. |
829 const int audio_source_size_bytes = | 833 const int audio_source_size_bytes = |
830 packet_size_bytes_ / channel_factor(); | 834 packet_size_bytes_ / channel_factor(); |
831 scoped_array<uint8> buffer; | 835 scoped_array<uint8> buffer; |
832 buffer.reset(new uint8[audio_source_size_bytes]); | 836 buffer.reset(new uint8[audio_source_size_bytes]); |
833 | 837 |
834 num_filled_bytes = source_->OnMoreData( | 838 int frames_filled = source_->OnMoreData( |
835 buffer.get(), audio_source_size_bytes, | 839 audio_bus_.get(), AudioBuffersState(0, audio_delay_bytes)); |
836 AudioBuffersState(0, audio_delay_bytes)); | 840 num_filled_bytes = |
| 841 frames_filled * bytes_per_sample * audio_bus_->channels(); |
| 842 DCHECK_LE(num_filled_bytes, |
| 843 static_cast<size_t>(audio_source_size_bytes)); |
| 844 audio_bus_->ToInterleaved( |
| 845 frames_filled, bytes_per_sample, buffer.get()); |
837 | 846 |
838 // Do channel up-mixing on 16-bit PCM samples. | 847 // Do channel up-mixing on 16-bit PCM samples. |
839 num_filled_bytes = ChannelUpMix(buffer.get(), | 848 num_filled_bytes = ChannelUpMix(buffer.get(), |
840 &audio_data[0], | 849 &audio_data[0], |
841 client_channel_count_, | 850 client_channel_count_, |
842 endpoint_channel_count(), | 851 endpoint_channel_count(), |
843 num_filled_bytes, | 852 num_filled_bytes, |
844 bytes_per_sample); | 853 bytes_per_sample); |
845 } | 854 } |
846 | 855 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 // are now re-initiated and it is now possible to re-start audio rendering. | 1327 // are now re-initiated and it is now possible to re-start audio rendering. |
1319 | 1328 |
1320 // Start rendering again using the new default audio endpoint. | 1329 // Start rendering again using the new default audio endpoint. |
1321 hr = audio_client_->Start(); | 1330 hr = audio_client_->Start(); |
1322 | 1331 |
1323 restart_rendering_mode_ = false; | 1332 restart_rendering_mode_ = false; |
1324 return SUCCEEDED(hr); | 1333 return SUCCEEDED(hr); |
1325 } | 1334 } |
1326 | 1335 |
1327 } // namespace media | 1336 } // namespace media |
OLD | NEW |