Chromium Code Reviews| 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 "content/browser/renderer_host/media/audio_sync_reader.h" | 5 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | |
| 9 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 10 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 11 #include "media/audio/audio_buffers_state.h" | 12 #include "media/audio/audio_buffers_state.h" |
| 12 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 13 #include "media/audio/shared_memory_util.h" | 14 #include "media/audio/shared_memory_util.h" |
| 14 | 15 |
| 16 #if defined(OS_WIN) | |
| 17 #include "media/audio/win/core_audio_util_win.h" | |
| 18 #endif | |
| 19 | |
| 15 using media::AudioBus; | 20 using media::AudioBus; |
| 16 | 21 |
| 17 namespace content { | 22 namespace content { |
| 18 | 23 |
| 19 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, | 24 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, |
| 20 const media::AudioParameters& params, | 25 const media::AudioParameters& params, |
| 21 int input_channels) | 26 int input_channels) |
| 22 : shared_memory_(shared_memory), | 27 : shared_memory_(shared_memory), |
| 23 input_channels_(input_channels) { | 28 input_channels_(input_channels), |
| 29 renderer_callback_count_(0), | |
| 30 renderer_missed_callback_count_(0) { | |
| 24 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size()); | 31 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size()); |
| 25 int input_memory_size = 0; | 32 int input_memory_size = 0; |
| 26 int output_memory_size = AudioBus::CalculateMemorySize(params); | 33 int output_memory_size = AudioBus::CalculateMemorySize(params); |
| 27 if (input_channels_ > 0) { | 34 if (input_channels_ > 0) { |
| 28 // The input storage is after the output storage. | 35 // The input storage is after the output storage. |
| 29 int frames = params.frames_per_buffer(); | 36 int frames = params.frames_per_buffer(); |
| 30 input_memory_size = AudioBus::CalculateMemorySize(input_channels_, frames); | 37 input_memory_size = AudioBus::CalculateMemorySize(input_channels_, frames); |
| 31 char* input_data = | 38 char* input_data = |
| 32 static_cast<char*>(shared_memory_->memory()) + output_memory_size; | 39 static_cast<char*>(shared_memory_->memory()) + output_memory_size; |
| 33 input_bus_ = AudioBus::WrapMemory(input_channels_, frames, input_data); | 40 input_bus_ = AudioBus::WrapMemory(input_channels_, frames, input_data); |
| 34 } | 41 } |
| 35 DCHECK_EQ(packet_size_, output_memory_size + input_memory_size); | 42 DCHECK_EQ(packet_size_, output_memory_size + input_memory_size); |
| 36 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory()); | 43 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory()); |
| 37 } | 44 } |
| 38 | 45 |
| 39 AudioSyncReader::~AudioSyncReader() { | 46 AudioSyncReader::~AudioSyncReader() { |
| 47 if (!renderer_callback_count_) | |
| 48 return; | |
| 49 | |
| 50 // Reduce renderer callback percentage to 10% intervals. |percentage_missed| | |
| 51 // is a number from 0-10 representing the 10% interval index. I.e., 0 = 0%, | |
| 52 // 1 = 10%, 2 = 20%, ..., 10 = 100%. | |
|
scherkus (not reviewing)
2013/01/24 23:34:39
OOC why not UMA_HISTOGRAM_PERCENTAGE()?
If there'
| |
| 53 const int kMissedMax = 11; | |
| 54 int percentage_missed = 0.5 + 10 * (static_cast<double>( | |
| 55 renderer_missed_callback_count_) / renderer_callback_count_); | |
| 56 | |
| 57 // Recording the percentage of deadline misses gives us a rough overview of | |
| 58 // how many users might be running into audio glitches. | |
| 59 #if defined(OS_LINUX) | |
| 60 UMA_HISTOGRAM_ENUMERATION( | |
| 61 "Media.AudioRendererMissedDeadlineLinux", percentage_missed, kMissedMax); | |
| 62 #elif defined(OS_MACOSX) | |
| 63 UMA_HISTOGRAM_ENUMERATION( | |
| 64 "Media.AudioRendererMissedDeadlineOSX", percentage_missed, kMissedMax); | |
|
scherkus (not reviewing)
2013/01/24 23:34:39
do we need to have 5 different buckets? UMA alread
DaleCurtis
2013/01/26 01:02:55
Great point. I totally forgot about the OS based f
| |
| 65 #elif defined(OS_WIN) | |
| 66 if (CoreAudioUtil::IsSupported()) { | |
| 67 UMA_HISTOGRAM_ENUMERATION( | |
| 68 "Media.AudioRendererMissedDeadlineWASAPI", percentage_missed, | |
| 69 kMissedMax); | |
| 70 } else { | |
| 71 UMA_HISTOGRAM_ENUMERATION( | |
| 72 "Media.AudioRendererMissedDeadlineWaveOut", percentage_missed, | |
| 73 kMissedMax); | |
| 74 } | |
| 75 #elif defined(OS_CHROMEOS) | |
| 76 UMA_HISTOGRAM_ENUMERATION( | |
| 77 "Media.AudioRendererMissedDeadlineChromeOS", percentage_missed, | |
| 78 kMissedMax); | |
| 79 #endif | |
| 40 } | 80 } |
| 41 | 81 |
| 42 bool AudioSyncReader::DataReady() { | 82 bool AudioSyncReader::DataReady() { |
| 43 return !media::IsUnknownDataSize(shared_memory_, packet_size_); | 83 return !media::IsUnknownDataSize(shared_memory_, packet_size_); |
| 44 } | 84 } |
| 45 | 85 |
| 46 // media::AudioOutputController::SyncReader implementations. | 86 // media::AudioOutputController::SyncReader implementations. |
| 47 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { | 87 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { |
| 48 if (bytes != static_cast<uint32>(media::kPauseMark)) { | 88 if (bytes != static_cast<uint32>(media::kPauseMark)) { |
| 49 // Store unknown length of data into buffer, so we later | 89 // Store unknown length of data into buffer, so we later |
| 50 // can find out if data became available. | 90 // can find out if data became available. |
| 51 media::SetUnknownDataSize(shared_memory_, packet_size_); | 91 media::SetUnknownDataSize(shared_memory_, packet_size_); |
| 52 } | 92 } |
| 53 | 93 |
| 54 if (socket_.get()) { | 94 if (socket_.get()) { |
| 55 socket_->Send(&bytes, sizeof(bytes)); | 95 socket_->Send(&bytes, sizeof(bytes)); |
| 56 } | 96 } |
| 57 } | 97 } |
| 58 | 98 |
| 59 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { | 99 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { |
| 100 ++renderer_callback_count_; | |
| 101 if (!DataReady()) | |
| 102 ++renderer_missed_callback_count_; | |
| 103 | |
| 60 // Copy optional synchronized live audio input for consumption by renderer | 104 // Copy optional synchronized live audio input for consumption by renderer |
| 61 // process. | 105 // process. |
| 62 if (source && input_bus_.get()) { | 106 if (source && input_bus_.get()) { |
| 63 DCHECK_EQ(source->channels(), input_bus_->channels()); | 107 DCHECK_EQ(source->channels(), input_bus_->channels()); |
| 64 DCHECK_LE(source->frames(), input_bus_->frames()); | 108 DCHECK_LE(source->frames(), input_bus_->frames()); |
| 65 source->CopyTo(input_bus_.get()); | 109 source->CopyTo(input_bus_.get()); |
| 66 } | 110 } |
| 67 | 111 |
| 68 // Retrieve the actual number of bytes available from the shared memory. If | 112 // Retrieve the actual number of bytes available from the shared memory. If |
| 69 // the renderer has not completed rendering this value will be invalid (still | 113 // the renderer has not completed rendering this value will be invalid (still |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 base::FileDescriptor* foreign_handle) { | 176 base::FileDescriptor* foreign_handle) { |
| 133 foreign_handle->fd = foreign_socket_->handle(); | 177 foreign_handle->fd = foreign_socket_->handle(); |
| 134 foreign_handle->auto_close = false; | 178 foreign_handle->auto_close = false; |
| 135 if (foreign_handle->fd != -1) | 179 if (foreign_handle->fd != -1) |
| 136 return true; | 180 return true; |
| 137 return false; | 181 return false; |
| 138 } | 182 } |
| 139 #endif | 183 #endif |
| 140 | 184 |
| 141 } // namespace content | 185 } // namespace content |
| OLD | NEW |