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

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

Issue 2458973002: Audio input traces for Mac (browser-side) (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_input_sync_writer.h" 5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/trace_event/trace_event.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "content/browser/renderer_host/media/media_stream_manager.h" 14 #include "content/browser/renderer_host/media/media_stream_manager.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 using media::AudioBus; 17 using media::AudioBus;
17 using media::AudioInputBuffer; 18 using media::AudioInputBuffer;
18 using media::AudioInputBufferParameters; 19 using media::AudioInputBufferParameters;
19 20
20 namespace content { 21 namespace content {
21 22
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 "AISW: number of detected audio glitches: %" PRIuS " out of %" PRIuS, 113 "AISW: number of detected audio glitches: %" PRIuS " out of %" PRIuS,
113 write_error_count_, write_count_); 114 write_error_count_, write_count_);
114 MediaStreamManager::SendMessageToNativeLog(log_string); 115 MediaStreamManager::SendMessageToNativeLog(log_string);
115 DVLOG(1) << log_string; 116 DVLOG(1) << log_string;
116 } 117 }
117 118
118 void AudioInputSyncWriter::Write(const AudioBus* data, 119 void AudioInputSyncWriter::Write(const AudioBus* data,
119 double volume, 120 double volume,
120 bool key_pressed, 121 bool key_pressed,
121 uint32_t hardware_delay_bytes) { 122 uint32_t hardware_delay_bytes) {
123 TRACE_EVENT0("audio", "AudioInputSyncWriter::Write");
122 ++write_count_; 124 ++write_count_;
123 CheckTimeSinceLastWrite(); 125 CheckTimeSinceLastWrite();
124 126
125 // Check that the renderer side has read data so that we don't overwrite data 127 // Check that the renderer side has read data so that we don't overwrite data
126 // that hasn't been read yet. The renderer side sends a signal over the socket 128 // that hasn't been read yet. The renderer side sends a signal over the socket
127 // each time it has read data. Here, we read those verifications before 129 // each time it has read data. Here, we read those verifications before
128 // writing. We verify that each buffer index is in sequence. 130 // writing. We verify that each buffer index is in sequence.
129 size_t number_of_indices_available = socket_->Peek() / sizeof(uint32_t); 131 size_t number_of_indices_available = socket_->Peek() / sizeof(uint32_t);
130 if (number_of_indices_available > 0) { 132 if (number_of_indices_available > 0) {
131 std::unique_ptr<uint32_t[]> indices( 133 std::unique_ptr<uint32_t[]> indices(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 166
165 ++write_to_fifo_count_; 167 ++write_to_fifo_count_;
166 ++trailing_write_to_fifo_count_; 168 ++trailing_write_to_fifo_count_;
167 } 169 }
168 170
169 // Increase write error counts if error, or reset the trailing error counter 171 // Increase write error counts if error, or reset the trailing error counter
170 // if all write operations went well (no data dropped). 172 // if all write operations went well (no data dropped).
171 if (write_error) { 173 if (write_error) {
172 ++write_error_count_; 174 ++write_error_count_;
173 ++trailing_write_error_count_; 175 ++trailing_write_error_count_;
176 TRACE_EVENT_INSTANT0("audio", "AudioInputSyncWriter write error",
177 TRACE_EVENT_SCOPE_THREAD);
174 } else { 178 } else {
175 trailing_write_error_count_ = 0; 179 trailing_write_error_count_ = 0;
176 } 180 }
177 } 181 }
178 182
179 void AudioInputSyncWriter::Close() { 183 void AudioInputSyncWriter::Close() {
180 socket_->Close(); 184 socket_->Close();
181 } 185 }
182 186
183 bool AudioInputSyncWriter::Init() { 187 bool AudioInputSyncWriter::Init() {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 buffer->params.hardware_delay_bytes = hardware_delay_bytes; 327 buffer->params.hardware_delay_bytes = hardware_delay_bytes;
324 buffer->params.id = next_buffer_id_; 328 buffer->params.id = next_buffer_id_;
325 } 329 }
326 330
327 bool AudioInputSyncWriter::SignalDataWrittenAndUpdateCounters() { 331 bool AudioInputSyncWriter::SignalDataWrittenAndUpdateCounters() {
328 if (socket_->Send(&current_segment_id_, sizeof(current_segment_id_)) != 332 if (socket_->Send(&current_segment_id_, sizeof(current_segment_id_)) !=
329 sizeof(current_segment_id_)) { 333 sizeof(current_segment_id_)) {
330 const std::string error_message = "AISW: No room in socket buffer."; 334 const std::string error_message = "AISW: No room in socket buffer.";
331 LOG(WARNING) << error_message; 335 LOG(WARNING) << error_message;
332 AddToNativeLog(error_message); 336 AddToNativeLog(error_message);
337 TRACE_EVENT_INSTANT0("audio",
338 "AudioInputSyncWriter: No room in socket buffer",
339 TRACE_EVENT_SCOPE_THREAD);
333 return false; 340 return false;
334 } 341 }
335 342
336 if (++current_segment_id_ >= shared_memory_segment_count_) 343 if (++current_segment_id_ >= shared_memory_segment_count_)
337 current_segment_id_ = 0; 344 current_segment_id_ = 0;
338 ++number_of_filled_segments_; 345 ++number_of_filled_segments_;
339 CHECK_LE(number_of_filled_segments_, 346 CHECK_LE(number_of_filled_segments_,
340 static_cast<int>(shared_memory_segment_count_)); 347 static_cast<int>(shared_memory_segment_count_));
341 ++next_buffer_id_; 348 ++next_buffer_id_;
342 349
343 return true; 350 return true;
344 } 351 }
345 352
346 } // namespace content 353 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698