| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/mac/audio_auhal_mac.h" | 5 #include "media/audio/mac/audio_auhal_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/mac_logging.h" | 12 #include "base/mac/mac_logging.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 17 #include "media/audio/mac/audio_manager_mac.h" | 16 #include "media/audio/mac/audio_manager_mac.h" |
| 18 #include "media/base/audio_pull_fifo.h" | 17 #include "media/base/audio_pull_fifo.h" |
| 19 | 18 |
| 20 namespace media { | 19 namespace media { |
| 21 | 20 |
| 22 static void WrapBufferList(AudioBufferList* buffer_list, | 21 static void WrapBufferList(AudioBufferList* buffer_list, |
| 23 AudioBus* bus, | 22 AudioBus* bus, |
| 24 int frames) { | 23 int frames) { |
| 25 DCHECK(buffer_list); | 24 DCHECK(buffer_list); |
| 26 DCHECK(bus); | 25 DCHECK(bus); |
| 27 const int channels = bus->channels(); | 26 const int channels = bus->channels(); |
| 28 const int buffer_list_channels = buffer_list->mNumberBuffers; | 27 const int buffer_list_channels = buffer_list->mNumberBuffers; |
| 29 CHECK_EQ(channels, buffer_list_channels); | 28 CHECK_EQ(channels, buffer_list_channels); |
| 30 | 29 |
| 31 // Copy pointers from AudioBufferList. | 30 // Copy pointers from AudioBufferList. |
| 32 for (int i = 0; i < channels; ++i) { | 31 for (int i = 0; i < channels; ++i) { |
| 33 bus->SetChannelData( | 32 bus->SetChannelData( |
| 34 i, static_cast<float*>(buffer_list->mBuffers[i].mData)); | 33 i, static_cast<float*>(buffer_list->mBuffers[i].mData)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 // Finally set the actual length. | 36 // Finally set the actual length. |
| 38 bus->set_frames(frames); | 37 bus->set_frames(frames); |
| 39 } | 38 } |
| 40 | 39 |
| 41 AUHALStream::AUHALStream(AudioManagerMac* manager, | 40 AUHALStream::AUHALStream(AudioManagerMac* manager, |
| 42 const AudioParameters& params, | 41 const AudioParameters& params, |
| 43 AudioDeviceID device, | 42 AudioDeviceID device) |
| 44 const AudioManager::LogCallback& log_callback) | |
| 45 : manager_(manager), | 43 : manager_(manager), |
| 46 params_(params), | 44 params_(params), |
| 47 output_channels_(params_.channels()), | 45 output_channels_(params_.channels()), |
| 48 number_of_frames_(params_.frames_per_buffer()), | 46 number_of_frames_(params_.frames_per_buffer()), |
| 49 number_of_frames_requested_(0), | 47 number_of_frames_requested_(0), |
| 50 source_(NULL), | 48 source_(NULL), |
| 51 device_(device), | 49 device_(device), |
| 52 audio_unit_(0), | 50 audio_unit_(0), |
| 53 volume_(1), | 51 volume_(1), |
| 54 hardware_latency_frames_(0), | 52 hardware_latency_frames_(0), |
| 55 stopped_(true), | 53 stopped_(true), |
| 56 current_hardware_pending_bytes_(0), | 54 current_hardware_pending_bytes_(0), |
| 57 current_lost_frames_(0), | 55 current_lost_frames_(0), |
| 58 last_sample_time_(0.0), | 56 last_sample_time_(0.0), |
| 59 last_number_of_frames_(0), | 57 last_number_of_frames_(0), |
| 60 total_lost_frames_(0), | 58 total_lost_frames_(0), |
| 61 largest_glitch_frames_(0), | 59 largest_glitch_frames_(0), |
| 62 glitches_detected_(0), | 60 glitches_detected_(0) { |
| 63 log_callback_(log_callback) { | |
| 64 // We must have a manager. | 61 // We must have a manager. |
| 65 DCHECK(manager_); | 62 DCHECK(manager_); |
| 66 DCHECK(!log_callback_.Equals(AudioManager::LogCallback())); | |
| 67 | 63 |
| 68 DVLOG(1) << "ctor"; | 64 DVLOG(1) << "ctor"; |
| 69 DVLOG(1) << "device ID: 0x" << std::hex << device; | 65 DVLOG(1) << "device ID: 0x" << std::hex << device; |
| 70 DVLOG(1) << "buffer size: " << number_of_frames_; | 66 DVLOG(1) << "buffer size: " << number_of_frames_; |
| 71 DVLOG(1) << "output channels: " << output_channels_; | 67 DVLOG(1) << "output channels: " << output_channels_; |
| 72 DVLOG(1) << "sample rate: " << params_.sample_rate(); | 68 DVLOG(1) << "sample rate: " << params_.sample_rate(); |
| 73 } | 69 } |
| 74 | 70 |
| 75 AUHALStream::~AUHALStream() { | 71 AUHALStream::~AUHALStream() { |
| 76 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 return; // No stats gathered to report. | 383 return; // No stats gathered to report. |
| 388 | 384 |
| 389 // A value of 0 indicates that we got the buffer size we asked for. | 385 // A value of 0 indicates that we got the buffer size we asked for. |
| 390 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.FramesRequested", | 386 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.FramesRequested", |
| 391 number_of_frames_requested_); | 387 number_of_frames_requested_); |
| 392 // Even if there aren't any glitches, we want to record it to get a feel for | 388 // Even if there aren't any glitches, we want to record it to get a feel for |
| 393 // how often we get no glitches vs the alternative. | 389 // how often we get no glitches vs the alternative. |
| 394 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.Audio.Render.Glitches", glitches_detected_, | 390 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.Audio.Render.Glitches", glitches_detected_, |
| 395 0, 999999, 100); | 391 0, 999999, 100); |
| 396 | 392 |
| 397 auto lost_frames_ms = (total_lost_frames_ * 1000) / params_.sample_rate(); | |
| 398 std::string log_message = base::StringPrintf( | |
| 399 "AU out: Total glitches=%d. Total frames lost=%d (%d ms).", | |
| 400 glitches_detected_, total_lost_frames_, lost_frames_ms); | |
| 401 log_callback_.Run(log_message); | |
| 402 | |
| 403 if (glitches_detected_ != 0) { | 393 if (glitches_detected_ != 0) { |
| 394 auto lost_frames_ms = (total_lost_frames_ * 1000) / params_.sample_rate(); |
| 404 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LostFramesInMs", lost_frames_ms); | 395 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LostFramesInMs", lost_frames_ms); |
| 405 auto largest_glitch_ms = | 396 auto largest_glitch_ms = |
| 406 (largest_glitch_frames_ * 1000) / params_.sample_rate(); | 397 (largest_glitch_frames_ * 1000) / params_.sample_rate(); |
| 407 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LargestGlitchMs", | 398 UMA_HISTOGRAM_COUNTS("Media.Audio.Render.LargestGlitchMs", |
| 408 largest_glitch_ms); | 399 largest_glitch_ms); |
| 409 DLOG(WARNING) << log_message; | 400 DLOG(WARNING) << "Total glitches=" << glitches_detected_ |
| 401 << ". Total frames lost=" << total_lost_frames_ << " (" |
| 402 << lost_frames_ms; |
| 410 } | 403 } |
| 411 | 404 |
| 412 number_of_frames_requested_ = 0; | 405 number_of_frames_requested_ = 0; |
| 413 glitches_detected_ = 0; | 406 glitches_detected_ = 0; |
| 414 last_sample_time_ = 0; | 407 last_sample_time_ = 0; |
| 415 last_number_of_frames_ = 0; | 408 last_number_of_frames_ = 0; |
| 416 total_lost_frames_ = 0; | 409 total_lost_frames_ = 0; |
| 417 largest_glitch_frames_ = 0; | 410 largest_glitch_frames_ = 0; |
| 418 } | 411 } |
| 419 | 412 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 OSStatus result = AudioUnitUninitialize(audio_unit_); | 548 OSStatus result = AudioUnitUninitialize(audio_unit_); |
| 556 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 549 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 557 << "AudioUnitUninitialize() failed."; | 550 << "AudioUnitUninitialize() failed."; |
| 558 result = AudioComponentInstanceDispose(audio_unit_); | 551 result = AudioComponentInstanceDispose(audio_unit_); |
| 559 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 552 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 560 << "AudioComponentInstanceDispose() failed."; | 553 << "AudioComponentInstanceDispose() failed."; |
| 561 audio_unit_ = 0; | 554 audio_unit_ = 0; |
| 562 } | 555 } |
| 563 | 556 |
| 564 } // namespace media | 557 } // namespace media |
| OLD | NEW |