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

Side by Side Diff: content/browser/renderer_host/media/audio_sync_reader.cc

Issue 11975031: Track UMA stats for when the renderer side audio device wasn't ready. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months 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 | Annotate | Revision Log
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 "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_wasnt_ready_(0) {
24 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size()); 30 packet_size_ = media::PacketSizeInBytes(shared_memory_->created_size());
25 int input_memory_size = 0; 31 int input_memory_size = 0;
26 int output_memory_size = AudioBus::CalculateMemorySize(params); 32 int output_memory_size = AudioBus::CalculateMemorySize(params);
27 if (input_channels_ > 0) { 33 if (input_channels_ > 0) {
28 // The input storage is after the output storage. 34 // The input storage is after the output storage.
29 int frames = params.frames_per_buffer(); 35 int frames = params.frames_per_buffer();
30 input_memory_size = AudioBus::CalculateMemorySize(input_channels_, frames); 36 input_memory_size = AudioBus::CalculateMemorySize(input_channels_, frames);
31 char* input_data = 37 char* input_data =
32 static_cast<char*>(shared_memory_->memory()) + output_memory_size; 38 static_cast<char*>(shared_memory_->memory()) + output_memory_size;
33 input_bus_ = AudioBus::WrapMemory(input_channels_, frames, input_data); 39 input_bus_ = AudioBus::WrapMemory(input_channels_, frames, input_data);
34 } 40 }
35 DCHECK_EQ(packet_size_, output_memory_size + input_memory_size); 41 DCHECK_EQ(packet_size_, output_memory_size + input_memory_size);
36 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory()); 42 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory());
37 } 43 }
38 44
39 AudioSyncReader::~AudioSyncReader() { 45 AudioSyncReader::~AudioSyncReader() {
46 // Only log if we had to wait at least 3 times.
47 bool waited_too_many_times = renderer_wasnt_ready_ > 3;
Chris Rogers 2013/01/17 02:22:25 nit: should define a constant for this, something
48
49 #if defined(OS_LINUX)
50 UMA_HISTOGRAM_BOOLEAN(
51 "Media.AudioRendererWasNotReadyLinux", waited_too_many_times);
Chris Rogers 2013/01/17 02:22:25 how about "WasNotReady" -> "MissedDeadline"?
52 #elif defined(OS_MACOSX)
53 UMA_HISTOGRAM_BOOLEAN(
54 "Media.AudioRendererWasNotReadyOSX", waited_too_many_times);
55 #elif defined(OS_WIN)
56 if (CoreAudioUtil::IsSupported()) {
57 UMA_HISTOGRAM_BOOLEAN(
58 "Media.AudioRendererWasNotReadyWinWASAPI", waited_too_many_times);
Chris Rogers 2013/01/17 02:22:25 can we shorten "WinWASAPI" to just "WASAPI"?
59 } else {
60 UMA_HISTOGRAM_BOOLEAN(
61 "Media.AudioRendererWasNotReadyWinWaveOut", waited_too_many_times);
Chris Rogers 2013/01/17 02:22:25 can we shorten "WinWaveOut" to just "WaveOut"?
62 }
63 #elif defined(OS_CHROMEOS)
64 UMA_HISTOGRAM_BOOLEAN(
65 "Media.AudioRendererWasNotReadyChromeOS", waited_too_many_times);
66 #endif
40 } 67 }
41 68
42 bool AudioSyncReader::DataReady() { 69 bool AudioSyncReader::DataReady() {
43 return !media::IsUnknownDataSize(shared_memory_, packet_size_); 70 return !media::IsUnknownDataSize(shared_memory_, packet_size_);
44 } 71 }
45 72
46 // media::AudioOutputController::SyncReader implementations. 73 // media::AudioOutputController::SyncReader implementations.
47 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { 74 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) {
48 if (bytes != static_cast<uint32>(media::kPauseMark)) { 75 if (bytes != static_cast<uint32>(media::kPauseMark)) {
49 // Store unknown length of data into buffer, so we later 76 // Store unknown length of data into buffer, so we later
50 // can find out if data became available. 77 // can find out if data became available.
51 media::SetUnknownDataSize(shared_memory_, packet_size_); 78 media::SetUnknownDataSize(shared_memory_, packet_size_);
52 } 79 }
53 80
54 if (socket_.get()) { 81 if (socket_.get()) {
55 socket_->Send(&bytes, sizeof(bytes)); 82 socket_->Send(&bytes, sizeof(bytes));
56 } 83 }
57 } 84 }
58 85
59 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) { 86 int AudioSyncReader::Read(AudioBus* source, AudioBus* dest) {
87 if (!DataReady())
88 ++renderer_wasnt_ready_;
89
60 // Copy optional synchronized live audio input for consumption by renderer 90 // Copy optional synchronized live audio input for consumption by renderer
61 // process. 91 // process.
62 if (source && input_bus_.get()) { 92 if (source && input_bus_.get()) {
63 DCHECK_EQ(source->channels(), input_bus_->channels()); 93 DCHECK_EQ(source->channels(), input_bus_->channels());
64 DCHECK_LE(source->frames(), input_bus_->frames()); 94 DCHECK_LE(source->frames(), input_bus_->frames());
65 source->CopyTo(input_bus_.get()); 95 source->CopyTo(input_bus_.get());
66 } 96 }
67 97
68 // Retrieve the actual number of bytes available from the shared memory. If 98 // 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 99 // the renderer has not completed rendering this value will be invalid (still
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 base::FileDescriptor* foreign_handle) { 162 base::FileDescriptor* foreign_handle) {
133 foreign_handle->fd = foreign_socket_->handle(); 163 foreign_handle->fd = foreign_socket_->handle();
134 foreign_handle->auto_close = false; 164 foreign_handle->auto_close = false;
135 if (foreign_handle->fd != -1) 165 if (foreign_handle->fd != -1)
136 return true; 166 return true;
137 return false; 167 return false;
138 } 168 }
139 #endif 169 #endif
140 170
141 } // namespace content 171 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698