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> |
(...skipping 23 matching lines...) Expand all Loading... |
34 base::SharedMemoryHandle memory, | 34 base::SharedMemoryHandle memory, |
35 int memory_length, | 35 int memory_length, |
36 AudioRendererSink::RenderCallback* render_callback); | 36 AudioRendererSink::RenderCallback* render_callback); |
37 ~AudioThreadCallback() override; | 37 ~AudioThreadCallback() override; |
38 | 38 |
39 void MapSharedMemory() override; | 39 void MapSharedMemory() override; |
40 | 40 |
41 // Called whenever we receive notifications about pending data. | 41 // Called whenever we receive notifications about pending data. |
42 void Process(uint32_t pending_data) override; | 42 void Process(uint32_t pending_data) override; |
43 | 43 |
| 44 // Returns whether the current thread is the audio device thread or not. |
| 45 // Will always return true if DCHECKs are not enabled. |
| 46 bool CurrentThreadIsAudioDeviceThread(); |
| 47 |
44 private: | 48 private: |
45 AudioRendererSink::RenderCallback* render_callback_; | 49 AudioRendererSink::RenderCallback* render_callback_; |
46 std::unique_ptr<AudioBus> output_bus_; | 50 std::unique_ptr<AudioBus> output_bus_; |
47 uint64_t callback_num_; | 51 uint64_t callback_num_; |
48 | 52 |
49 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); | 53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); |
50 }; | 54 }; |
51 | 55 |
52 AudioOutputDevice::AudioOutputDevice( | 56 AudioOutputDevice::AudioOutputDevice( |
53 std::unique_ptr<AudioOutputIPC> ipc, | 57 std::unique_ptr<AudioOutputIPC> ipc, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() { | 151 OutputDeviceInfo AudioOutputDevice::GetOutputDeviceInfo() { |
148 CHECK(!task_runner()->BelongsToCurrentThread()); | 152 CHECK(!task_runner()->BelongsToCurrentThread()); |
149 did_receive_auth_.Wait(); | 153 did_receive_auth_.Wait(); |
150 return OutputDeviceInfo(AudioDeviceDescription::UseSessionIdToSelectDevice( | 154 return OutputDeviceInfo(AudioDeviceDescription::UseSessionIdToSelectDevice( |
151 session_id_, device_id_) | 155 session_id_, device_id_) |
152 ? matched_device_id_ | 156 ? matched_device_id_ |
153 : device_id_, | 157 : device_id_, |
154 device_status_, output_params_); | 158 device_status_, output_params_); |
155 } | 159 } |
156 | 160 |
| 161 bool AudioOutputDevice::CurrentThreadIsRenderingThread() { |
| 162 // Since this function is supposed to be called on the rendering thread, |
| 163 // it's safe to access |audio_callback_| here. It will always be valid when |
| 164 // the rendering thread is running. |
| 165 return audio_callback_->CurrentThreadIsAudioDeviceThread(); |
| 166 } |
| 167 |
157 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { | 168 void AudioOutputDevice::RequestDeviceAuthorizationOnIOThread() { |
158 DCHECK(task_runner()->BelongsToCurrentThread()); | 169 DCHECK(task_runner()->BelongsToCurrentThread()); |
159 DCHECK_EQ(state_, IDLE); | 170 DCHECK_EQ(state_, IDLE); |
160 state_ = AUTHORIZING; | 171 state_ = AUTHORIZING; |
161 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, | 172 ipc_->RequestDeviceAuthorization(this, session_id_, device_id_, |
162 security_origin_); | 173 security_origin_); |
163 | 174 |
164 // Create the timer on the thread it's used on. It's guaranteed to be | 175 // Create the timer on the thread it's used on. It's guaranteed to be |
165 // deleted on the same thread since users must call Stop() before deleting | 176 // deleted on the same thread since users must call Stop() before deleting |
166 // AudioOutputDevice; see ShutDownOnIOThread(). | 177 // AudioOutputDevice; see ShutDownOnIOThread(). |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 << " frames_skipped:" << frames_skipped; | 481 << " frames_skipped:" << frames_skipped; |
471 | 482 |
472 // Update the audio-delay measurement, inform about the number of skipped | 483 // Update the audio-delay measurement, inform about the number of skipped |
473 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 484 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
474 // the shared memory the Render() call is writing directly into the shared | 485 // the shared memory the Render() call is writing directly into the shared |
475 // memory. | 486 // memory. |
476 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 487 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
477 frames_skipped); | 488 frames_skipped); |
478 } | 489 } |
479 | 490 |
| 491 bool AudioOutputDevice::AudioThreadCallback:: |
| 492 CurrentThreadIsAudioDeviceThread() { |
| 493 return thread_checker_.CalledOnValidThread(); |
| 494 } |
| 495 |
480 } // namespace media | 496 } // namespace media |
OLD | NEW |