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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" |
14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "base/win/scoped_propvariant.h" | 16 #include "base/win/scoped_propvariant.h" |
16 #include "media/audio/audio_device_description.h" | 17 #include "media/audio/audio_device_description.h" |
17 #include "media/audio/win/audio_manager_win.h" | 18 #include "media/audio/win/audio_manager_win.h" |
18 #include "media/audio/win/avrt_wrapper_win.h" | 19 #include "media/audio/win/avrt_wrapper_win.h" |
19 #include "media/audio/win/core_audio_util_win.h" | 20 #include "media/audio/win/core_audio_util_win.h" |
20 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
21 #include "media/base/media_switches.h" | 22 #include "media/base/media_switches.h" |
22 | 23 |
23 using base::win::ScopedComPtr; | 24 using base::win::ScopedComPtr; |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 528 |
528 // Derive the actual delay value which will be fed to the | 529 // Derive the actual delay value which will be fed to the |
529 // render client using the OnMoreData() callback. | 530 // render client using the OnMoreData() callback. |
530 audio_delay_bytes = (pos_last_sample_written_frames - | 531 audio_delay_bytes = (pos_last_sample_written_frames - |
531 pos_sample_playing_frames) * format_.Format.nBlockAlign; | 532 pos_sample_playing_frames) * format_.Format.nBlockAlign; |
532 } | 533 } |
533 | 534 |
534 // Read a data packet from the registered client source and | 535 // Read a data packet from the registered client source and |
535 // deliver a delay estimate in the same callback to the client. | 536 // deliver a delay estimate in the same callback to the client. |
536 | 537 |
537 int frames_filled = | 538 int frames_filled = source_->OnMoreData(audio_bus_.get(), audio_delay_bytes, |
538 source_->OnMoreData(audio_bus_.get(), audio_delay_bytes, 0); | 539 base::TimeDelta(), 0); |
539 uint32_t num_filled_bytes = frames_filled * format_.Format.nBlockAlign; | 540 uint32_t num_filled_bytes = frames_filled * format_.Format.nBlockAlign; |
540 DCHECK_LE(num_filled_bytes, packet_size_bytes_); | 541 DCHECK_LE(num_filled_bytes, packet_size_bytes_); |
541 | 542 |
542 // Note: If this ever changes to output raw float the data must be | 543 // Note: If this ever changes to output raw float the data must be |
543 // clipped and sanitized since it may come from an untrusted | 544 // clipped and sanitized since it may come from an untrusted |
544 // source such as NaCl. | 545 // source such as NaCl. |
545 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3; | 546 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3; |
546 audio_bus_->Scale(volume_); | 547 audio_bus_->Scale(volume_); |
547 audio_bus_->ToInterleaved( | 548 audio_bus_->ToInterleaved( |
548 frames_filled, bytes_per_sample, audio_data); | 549 frames_filled, bytes_per_sample, audio_data); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 DVLOG(1) << "IAudioClient::GetBufferSize: " << std::hex << hr; | 635 DVLOG(1) << "IAudioClient::GetBufferSize: " << std::hex << hr; |
635 return hr; | 636 return hr; |
636 } | 637 } |
637 | 638 |
638 *endpoint_buffer_size = buffer_size_in_frames; | 639 *endpoint_buffer_size = buffer_size_in_frames; |
639 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; | 640 DVLOG(2) << "endpoint buffer size: " << buffer_size_in_frames; |
640 return hr; | 641 return hr; |
641 } | 642 } |
642 | 643 |
643 void WASAPIAudioOutputStream::StopThread() { | 644 void WASAPIAudioOutputStream::StopThread() { |
644 if (render_thread_ ) { | 645 if (render_thread_) { |
645 if (render_thread_->HasBeenStarted()) { | 646 if (render_thread_->HasBeenStarted()) { |
646 // Wait until the thread completes and perform cleanup. | 647 // Wait until the thread completes and perform cleanup. |
647 SetEvent(stop_render_event_.Get()); | 648 SetEvent(stop_render_event_.Get()); |
648 render_thread_->Join(); | 649 render_thread_->Join(); |
649 } | 650 } |
650 | 651 |
651 render_thread_.reset(); | 652 render_thread_.reset(); |
652 | 653 |
653 // Ensure that we don't quit the main thread loop immediately next | 654 // Ensure that we don't quit the main thread loop immediately next |
654 // time Start() is called. | 655 // time Start() is called. |
655 ResetEvent(stop_render_event_.Get()); | 656 ResetEvent(stop_render_event_.Get()); |
656 } | 657 } |
657 | 658 |
658 source_ = NULL; | 659 source_ = NULL; |
659 } | 660 } |
660 | 661 |
661 } // namespace media | 662 } // namespace media |
OLD | NEW |