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

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

Issue 2060833002: Implementation of 'AudioContext.getOutputTimestamp' method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added implementation for ALSA. Created 4 years, 5 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
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/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "content/browser/renderer_host/media/media_stream_manager.h" 12 #include "content/browser/renderer_host/media/media_stream_manager.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "media/audio/audio_device_thread.h"
14 15
15 using media::AudioBus; 16 using media::AudioBus;
16 using media::AudioInputBuffer; 17 using media::AudioInputBuffer;
17 using media::AudioInputBufferParameters; 18 using media::AudioInputBufferParameters;
19 using Packet = media::AudioDeviceThread::Packet;
18 20
19 namespace content { 21 namespace content {
20 22
21 namespace { 23 namespace {
22 24
23 // Used to log if any audio glitches have been detected during an audio session. 25 // Used to log if any audio glitches have been detected during an audio session.
24 // Elements in this enum should not be added, deleted or rearranged. 26 // Elements in this enum should not be added, deleted or rearranged.
25 enum AudioGlitchResult { 27 enum AudioGlitchResult {
26 AUDIO_CAPTURER_NO_AUDIO_GLITCHES = 0, 28 AUDIO_CAPTURER_NO_AUDIO_GLITCHES = 0,
27 AUDIO_CAPTURER_AUDIO_GLITCHES = 1, 29 AUDIO_CAPTURER_AUDIO_GLITCHES = 1,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 ptr += current_segment_id_ * shared_memory_segment_size_; 324 ptr += current_segment_id_ * shared_memory_segment_size_;
323 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); 325 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr);
324 buffer->params.volume = volume; 326 buffer->params.volume = volume;
325 buffer->params.size = audio_bus_memory_size_; 327 buffer->params.size = audio_bus_memory_size_;
326 buffer->params.key_pressed = key_pressed; 328 buffer->params.key_pressed = key_pressed;
327 buffer->params.hardware_delay_bytes = hardware_delay_bytes; 329 buffer->params.hardware_delay_bytes = hardware_delay_bytes;
328 buffer->params.id = next_buffer_id_; 330 buffer->params.id = next_buffer_id_;
329 } 331 }
330 332
331 bool AudioInputSyncWriter::SignalDataWrittenAndUpdateCounters() { 333 bool AudioInputSyncWriter::SignalDataWrittenAndUpdateCounters() {
332 if (socket_->Send(&current_segment_id_, sizeof(current_segment_id_)) != 334 // TODO(Mikhail) : Provide the actual device audio stream timestamp.
333 sizeof(current_segment_id_)) { 335 Packet packet = {current_segment_id_, media::AudioTimestamp()};
336 if (socket_->Send(&packet, sizeof(packet)) != sizeof(packet)) {
334 const std::string error_message = "AISW: No room in socket buffer."; 337 const std::string error_message = "AISW: No room in socket buffer.";
335 LOG(WARNING) << error_message; 338 LOG(WARNING) << error_message;
336 AddToNativeLog(error_message); 339 AddToNativeLog(error_message);
337 return false; 340 return false;
338 } 341 }
339 342
340 if (++current_segment_id_ >= shared_memory_segment_count_) 343 if (++current_segment_id_ >= shared_memory_segment_count_)
341 current_segment_id_ = 0; 344 current_segment_id_ = 0;
342 ++number_of_filled_segments_; 345 ++number_of_filled_segments_;
343 CHECK_LE(number_of_filled_segments_, 346 CHECK_LE(number_of_filled_segments_,
344 static_cast<int>(shared_memory_segment_count_)); 347 static_cast<int>(shared_memory_segment_count_));
345 ++next_buffer_id_; 348 ++next_buffer_id_;
346 349
347 return true; 350 return true;
348 } 351 }
349 352
350 } // namespace content 353 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698