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/audio_output_device.h" | 5 #include "media/audio/audio_output_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "media/audio/audio_device_description.h" | 21 #include "media/audio/audio_device_description.h" |
22 #include "media/audio/audio_output_controller.h" | 22 #include "media/audio/audio_output_controller.h" |
23 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 | 26 |
27 static const int kMaxFramesPerCompressedAudioBuffer = 4096; | |
DaleCurtis
2016/11/01 23:05:13
This needs to be a property of the AudioParameters
AndyWu
2016/11/04 18:04:24
Done, thanks for your help.
| |
28 | |
27 // Takes care of invoking the render callback on the audio thread. | 29 // Takes care of invoking the render callback on the audio thread. |
28 // An instance of this class is created for each capture stream in | 30 // An instance of this class is created for each capture stream in |
29 // OnStreamCreated(). | 31 // OnStreamCreated(). |
30 class AudioOutputDevice::AudioThreadCallback | 32 class AudioOutputDevice::AudioThreadCallback |
31 : public AudioDeviceThread::Callback { | 33 : public AudioDeviceThread::Callback { |
32 public: | 34 public: |
33 AudioThreadCallback(const AudioParameters& audio_parameters, | 35 AudioThreadCallback(const AudioParameters& audio_parameters, |
34 base::SharedMemoryHandle memory, | 36 base::SharedMemoryHandle memory, |
35 int memory_length, | 37 int memory_length, |
36 AudioRendererSink::RenderCallback* render_callback); | 38 AudioRendererSink::RenderCallback* render_callback); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 // Read and reset the number of frames skipped. | 471 // Read and reset the number of frames skipped. |
470 AudioOutputBuffer* buffer = | 472 AudioOutputBuffer* buffer = |
471 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); | 473 reinterpret_cast<AudioOutputBuffer*>(shared_memory_.memory()); |
472 uint32_t frames_skipped = buffer->params.frames_skipped; | 474 uint32_t frames_skipped = buffer->params.frames_skipped; |
473 buffer->params.frames_skipped = 0; | 475 buffer->params.frames_skipped = 0; |
474 | 476 |
475 DVLOG(4) << __func__ << " pending_data:" << pending_data | 477 DVLOG(4) << __func__ << " pending_data:" << pending_data |
476 << " frames_delayed(pre-round):" << frames_delayed | 478 << " frames_delayed(pre-round):" << frames_delayed |
477 << " frames_skipped:" << frames_skipped; | 479 << " frames_skipped:" << frames_skipped; |
478 | 480 |
481 output_bus_->set_is_raw_format(audio_parameters_.IsRawFormat()); | |
482 if (audio_parameters_.IsRawFormat()) { | |
483 // Reset the data size and frame count. | |
484 // For compressed audio formats, the data size and frame count will be | |
485 // updated by |render_callback_|. | |
486 output_bus_->set_data_size(0); | |
487 output_bus_->set_frames(kMaxFramesPerCompressedAudioBuffer); | |
488 } | |
479 // Update the audio-delay measurement, inform about the number of skipped | 489 // Update the audio-delay measurement, inform about the number of skipped |
480 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 490 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
481 // the shared memory the Render() call is writing directly into the shared | 491 // the shared memory the Render() call is writing directly into the shared |
482 // memory. | 492 // memory. |
483 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 493 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
484 frames_skipped); | 494 frames_skipped); |
495 buffer->params.frames = output_bus_->frames(); | |
496 buffer->params.data_size = output_bus_->data_size(); | |
485 } | 497 } |
486 | 498 |
487 bool AudioOutputDevice::AudioThreadCallback:: | 499 bool AudioOutputDevice::AudioThreadCallback:: |
488 CurrentThreadIsAudioDeviceThread() { | 500 CurrentThreadIsAudioDeviceThread() { |
489 return thread_checker_.CalledOnValidThread(); | 501 return thread_checker_.CalledOnValidThread(); |
490 } | 502 } |
491 | 503 |
492 } // namespace media | 504 } // namespace media |
OLD | NEW |