| 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/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "content/browser/media/audio_output_impl.h" |
| 20 #include "content/browser/mojo/mojo_application_host.h" |
| 21 #include "content/renderer/media/audio_output_client.h" |
| 19 #include "media/audio/audio_output_controller.h" | 22 #include "media/audio/audio_output_controller.h" |
| 20 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
| 21 | 24 |
| 22 namespace media { | 25 namespace media { |
| 23 | 26 |
| 24 // Takes care of invoking the render callback on the audio thread. | 27 // Takes care of invoking the render callback on the audio thread. |
| 25 // An instance of this class is created for each capture stream in | 28 // An instance of this class is created for each capture stream in |
| 26 // OnStreamCreated(). | 29 // OnStreamCreated(). |
| 27 class AudioOutputDevice::AudioThreadCallback | 30 class AudioOutputDevice::AudioThreadCallback |
| 28 : public AudioDeviceThread::Callback { | 31 : public AudioDeviceThread::Callback { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // Closing IPC forces a Signal(), so no clients are locked waiting | 306 // Closing IPC forces a Signal(), so no clients are locked waiting |
| 304 // indefinitely after this method returns. | 307 // indefinitely after this method returns. |
| 305 ipc_->CloseStream(); | 308 ipc_->CloseStream(); |
| 306 OnIPCClosed(); | 309 OnIPCClosed(); |
| 307 if (callback_) | 310 if (callback_) |
| 308 callback_->OnRenderError(); | 311 callback_->OnRenderError(); |
| 309 } | 312 } |
| 310 } | 313 } |
| 311 | 314 |
| 312 void AudioOutputDevice::OnStreamCreated( | 315 void AudioOutputDevice::OnStreamCreated( |
| 316 content::mojom::AudioOutputStreamPtr* stream, |
| 313 base::SharedMemoryHandle handle, | 317 base::SharedMemoryHandle handle, |
| 314 base::SyncSocket::Handle socket_handle, | 318 base::SyncSocket::Handle socket_handle, |
| 315 int length) { | 319 int length) { |
| 316 DCHECK(task_runner()->BelongsToCurrentThread()); | 320 DCHECK(task_runner()->BelongsToCurrentThread()); |
| 317 DCHECK(base::SharedMemory::IsHandleValid(handle)); | 321 DCHECK(base::SharedMemory::IsHandleValid(handle)); |
| 318 #if defined(OS_WIN) | 322 #if defined(OS_WIN) |
| 319 DCHECK(socket_handle); | 323 DCHECK(socket_handle); |
| 320 #else | 324 #else |
| 321 DCHECK_GE(socket_handle, 0); | 325 DCHECK_GE(socket_handle, 0); |
| 322 #endif | 326 #endif |
| 323 DCHECK_GT(length, 0); | 327 DCHECK_GT(length, 0); |
| 324 | 328 |
| 329 stream_ = stream; |
| 330 |
| 325 if (state_ != CREATING_STREAM) | 331 if (state_ != CREATING_STREAM) |
| 326 return; | 332 return; |
| 327 | 333 |
| 328 // We can receive OnStreamCreated() on the IO thread after the client has | 334 // We can receive OnStreamCreated() on the IO thread after the client has |
| 329 // called Stop() but before ShutDownOnIOThread() is processed. In such a | 335 // called Stop() but before ShutDownOnIOThread() is processed. In such a |
| 330 // situation |callback_| might point to freed memory. Instead of starting | 336 // situation |callback_| might point to freed memory. Instead of starting |
| 331 // |audio_thread_| do nothing and wait for ShutDownOnIOThread() to get called. | 337 // |audio_thread_| do nothing and wait for ShutDownOnIOThread() to get called. |
| 332 // | 338 // |
| 333 // TODO(scherkus): The real fix is to have sane ownership semantics. The fact | 339 // TODO(scherkus): The real fix is to have sane ownership semantics. The fact |
| 334 // that |callback_| (which should own and outlive this object!) can point to | 340 // that |callback_| (which should own and outlive this object!) can point to |
| (...skipping 28 matching lines...) Expand all Loading... |
| 363 | 369 |
| 364 // Signal to unblock any blocked threads waiting for parameters | 370 // Signal to unblock any blocked threads waiting for parameters |
| 365 did_receive_auth_.Signal(); | 371 did_receive_auth_.Signal(); |
| 366 } | 372 } |
| 367 | 373 |
| 368 void AudioOutputDevice::WillDestroyCurrentMessageLoop() { | 374 void AudioOutputDevice::WillDestroyCurrentMessageLoop() { |
| 369 LOG(ERROR) << "IO loop going away before the audio device has been stopped"; | 375 LOG(ERROR) << "IO loop going away before the audio device has been stopped"; |
| 370 ShutDownOnIOThread(); | 376 ShutDownOnIOThread(); |
| 371 } | 377 } |
| 372 | 378 |
| 379 AudioOutputIPC* AudioOutputDevice::getIPC() { |
| 380 return ipc_.get(); |
| 381 } |
| 373 // AudioOutputDevice::AudioThreadCallback | 382 // AudioOutputDevice::AudioThreadCallback |
| 374 | 383 |
| 375 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( | 384 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( |
| 376 const AudioParameters& audio_parameters, | 385 const AudioParameters& audio_parameters, |
| 377 base::SharedMemoryHandle memory, | 386 base::SharedMemoryHandle memory, |
| 378 int memory_length, | 387 int memory_length, |
| 379 AudioRendererSink::RenderCallback* render_callback) | 388 AudioRendererSink::RenderCallback* render_callback) |
| 380 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), | 389 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), |
| 381 render_callback_(render_callback), | 390 render_callback_(render_callback), |
| 382 callback_num_(0) {} | 391 callback_num_(0) {} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 433 |
| 425 // Update the audio-delay measurement, inform about the number of skipped | 434 // Update the audio-delay measurement, inform about the number of skipped |
| 426 // frames, and ask client to render audio. Since |output_bus_| is wrapping | 435 // frames, and ask client to render audio. Since |output_bus_| is wrapping |
| 427 // the shared memory the Render() call is writing directly into the shared | 436 // the shared memory the Render() call is writing directly into the shared |
| 428 // memory. | 437 // memory. |
| 429 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), | 438 render_callback_->Render(output_bus_.get(), std::round(frames_delayed), |
| 430 frames_skipped); | 439 frames_skipped); |
| 431 } | 440 } |
| 432 | 441 |
| 433 } // namespace media | 442 } // namespace media |
| OLD | NEW |