Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: media/audio/audio_output_device.cc

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review fixes. Loads of files updated due to interface changes. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/threading/thread_restrictions.h" 8 #include "base/threading/thread_restrictions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 10 matching lines...) Expand all
21 public: 21 public:
22 AudioThreadCallback(const AudioParameters& audio_parameters, 22 AudioThreadCallback(const AudioParameters& audio_parameters,
23 base::SharedMemoryHandle memory, 23 base::SharedMemoryHandle memory,
24 int memory_length, 24 int memory_length,
25 AudioRendererSink::RenderCallback* render_callback); 25 AudioRendererSink::RenderCallback* render_callback);
26 ~AudioThreadCallback() override; 26 ~AudioThreadCallback() override;
27 27
28 void MapSharedMemory() override; 28 void MapSharedMemory() override;
29 29
30 // Called whenever we receive notifications about pending data. 30 // Called whenever we receive notifications about pending data.
31 void Process(uint32 pending_data) override; 31 void Process(uint32_t pending_data, uint32_t frames_skipped) override;
32 32
33 private: 33 private:
34 AudioRendererSink::RenderCallback* render_callback_; 34 AudioRendererSink::RenderCallback* render_callback_;
35 scoped_ptr<AudioBus> output_bus_; 35 scoped_ptr<AudioBus> output_bus_;
36 uint64 callback_num_; 36 uint64 callback_num_;
37
38 // Stores the number of frames skipped by the consumer. Increased in
39 // FramesSkipped(). Used and cleared in Process().
40 uint32_t frames_skipped_;
41
37 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 42 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
38 }; 43 };
39 44
40 AudioOutputDevice::AudioOutputDevice( 45 AudioOutputDevice::AudioOutputDevice(
41 scoped_ptr<AudioOutputIPC> ipc, 46 scoped_ptr<AudioOutputIPC> ipc,
42 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 47 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
43 int session_id, 48 int session_id,
44 const std::string& device_id, 49 const std::string& device_id,
45 const url::Origin& security_origin) 50 const url::Origin& security_origin)
46 : ScopedTaskRunnerObserver(io_task_runner), 51 : ScopedTaskRunnerObserver(io_task_runner),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // details. 352 // details.
348 { 353 {
349 base::AutoLock auto_lock(audio_thread_lock_); 354 base::AutoLock auto_lock(audio_thread_lock_);
350 if (stopping_hack_) 355 if (stopping_hack_)
351 return; 356 return;
352 357
353 DCHECK(audio_thread_.IsStopped()); 358 DCHECK(audio_thread_.IsStopped());
354 audio_callback_.reset(new AudioOutputDevice::AudioThreadCallback( 359 audio_callback_.reset(new AudioOutputDevice::AudioThreadCallback(
355 audio_parameters_, handle, length, callback_)); 360 audio_parameters_, handle, length, callback_));
356 audio_thread_.Start(audio_callback_.get(), socket_handle, 361 audio_thread_.Start(audio_callback_.get(), socket_handle,
357 "AudioOutputDevice", true); 362 "AudioOutputDevice", true, false);
358 state_ = PAUSED; 363 state_ = PAUSED;
359 364
360 // We handle the case where Play() and/or Pause() may have been called 365 // We handle the case where Play() and/or Pause() may have been called
361 // multiple times before OnStreamCreated() gets called. 366 // multiple times before OnStreamCreated() gets called.
362 if (play_on_start_) 367 if (play_on_start_)
363 PlayOnIOThread(); 368 PlayOnIOThread();
364 } 369 }
365 } 370 }
366 371
367 void AudioOutputDevice::OnIPCClosed() { 372 void AudioOutputDevice::OnIPCClosed() {
(...skipping 12 matching lines...) Expand all
380 385
381 // AudioOutputDevice::AudioThreadCallback 386 // AudioOutputDevice::AudioThreadCallback
382 387
383 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback( 388 AudioOutputDevice::AudioThreadCallback::AudioThreadCallback(
384 const AudioParameters& audio_parameters, 389 const AudioParameters& audio_parameters,
385 base::SharedMemoryHandle memory, 390 base::SharedMemoryHandle memory,
386 int memory_length, 391 int memory_length,
387 AudioRendererSink::RenderCallback* render_callback) 392 AudioRendererSink::RenderCallback* render_callback)
388 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1), 393 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length, 1),
389 render_callback_(render_callback), 394 render_callback_(render_callback),
390 callback_num_(0) {} 395 callback_num_(0),
396 frames_skipped_(0) {}
391 397
392 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() { 398 AudioOutputDevice::AudioThreadCallback::~AudioThreadCallback() {
393 } 399 }
394 400
395 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() { 401 void AudioOutputDevice::AudioThreadCallback::MapSharedMemory() {
396 CHECK_EQ(total_segments_, 1); 402 CHECK_EQ(total_segments_, 1);
397 CHECK(shared_memory_.Map(memory_length_)); 403 CHECK(shared_memory_.Map(memory_length_));
398 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_)); 404 DCHECK_EQ(memory_length_, AudioBus::CalculateMemorySize(audio_parameters_));
399 405
400 output_bus_ = 406 output_bus_ =
401 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory()); 407 AudioBus::WrapMemory(audio_parameters_, shared_memory_.memory());
402 } 408 }
403 409
404 // Called whenever we receive notifications about pending data. 410 // Called whenever we receive notifications about pending data.
405 void AudioOutputDevice::AudioThreadCallback::Process(uint32 pending_data) { 411 void AudioOutputDevice::AudioThreadCallback::Process(uint32_t pending_data,
412 uint32_t frames_skipped) {
406 // Convert the number of pending bytes in the render buffer into milliseconds. 413 // Convert the number of pending bytes in the render buffer into milliseconds.
407 int audio_delay_milliseconds = pending_data / bytes_per_ms_; 414 int audio_delay_milliseconds = pending_data / bytes_per_ms_;
408 415
409 callback_num_++; 416 callback_num_++;
410 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback", 417 TRACE_EVENT1("audio", "AudioOutputDevice::FireRenderCallback",
411 "callback_num", callback_num_); 418 "callback_num", callback_num_);
412 419
413 // When playback starts, we get an immediate callback to Process to make sure 420 // When playback starts, we get an immediate callback to Process to make sure
414 // that we have some data, we'll get another one after the device is awake and 421 // that we have some data, we'll get another one after the device is awake and
415 // ingesting data, which is what we want to track with this trace. 422 // ingesting data, which is what we want to track with this trace.
416 if (callback_num_ == 2) { 423 if (callback_num_ == 2) {
417 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this); 424 TRACE_EVENT_ASYNC_END0("audio", "StartingPlayback", this);
418 } 425 }
419 426
420 // Update the audio-delay measurement then ask client to render audio. Since 427 // Update the audio-delay measurement, inform about the number of skipped
421 // |output_bus_| is wrapping the shared memory the Render() call is writing 428 // frames, and ask client to render audio. Since |output_bus_| is wrapping
422 // directly into the shared memory. 429 // the shared memory the Render() call is writing directly into the shared
423 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds); 430 // memory.
431 render_callback_->Render(output_bus_.get(), audio_delay_milliseconds,
432 frames_skipped);
424 } 433 }
425 434
426 } // namespace media. 435 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698