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

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

Issue 163343002: Reland 153623004: Remove the unified IO code on the browser (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed the cras bot Created 6 years, 10 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_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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "content/public/common/content_switches.h" 12 #include "content/public/common/content_switches.h"
13 #include "media/audio/audio_buffers_state.h" 13 #include "media/audio/audio_buffers_state.h"
14 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
15 15
16 using media::AudioBus; 16 using media::AudioBus;
17 17
18 namespace content { 18 namespace content {
19 19
20 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory, 20 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory,
21 const media::AudioParameters& params, 21 const media::AudioParameters& params)
22 int input_channels)
23 : shared_memory_(shared_memory), 22 : shared_memory_(shared_memory),
24 input_channels_(input_channels),
25 mute_audio_(CommandLine::ForCurrentProcess()->HasSwitch( 23 mute_audio_(CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kMuteAudio)), 24 switches::kMuteAudio)),
27 packet_size_(shared_memory_->requested_size()), 25 packet_size_(shared_memory_->requested_size()),
28 renderer_callback_count_(0), 26 renderer_callback_count_(0),
29 renderer_missed_callback_count_(0), 27 renderer_missed_callback_count_(0),
30 #if defined(OS_MACOSX) 28 #if defined(OS_MACOSX)
31 maximum_wait_time_(params.GetBufferDuration() / 2), 29 maximum_wait_time_(params.GetBufferDuration() / 2),
32 #else 30 #else
33 // TODO(dalecurtis): Investigate if we can reduce this on all platforms. 31 // TODO(dalecurtis): Investigate if we can reduce this on all platforms.
34 maximum_wait_time_(base::TimeDelta::FromMilliseconds(20)), 32 maximum_wait_time_(base::TimeDelta::FromMilliseconds(20)),
35 #endif 33 #endif
36 buffer_index_(0) { 34 buffer_index_(0) {
37 int input_memory_size = 0; 35 DCHECK_EQ(packet_size_, AudioBus::CalculateMemorySize(params));
38 int output_memory_size = AudioBus::CalculateMemorySize(params);
39 if (input_channels_ > 0) {
40 // The input storage is after the output storage.
41 int frames = params.frames_per_buffer();
42 input_memory_size = AudioBus::CalculateMemorySize(input_channels_, frames);
43 char* input_data =
44 static_cast<char*>(shared_memory_->memory()) + output_memory_size;
45 input_bus_ = AudioBus::WrapMemory(input_channels_, frames, input_data);
46 input_bus_->Zero();
47 }
48 DCHECK_EQ(packet_size_, output_memory_size + input_memory_size);
49 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory()); 36 output_bus_ = AudioBus::WrapMemory(params, shared_memory->memory());
50 output_bus_->Zero(); 37 output_bus_->Zero();
51 } 38 }
52 39
53 AudioSyncReader::~AudioSyncReader() { 40 AudioSyncReader::~AudioSyncReader() {
54 if (!renderer_callback_count_) 41 if (!renderer_callback_count_)
55 return; 42 return;
56 43
57 // Recording the percentage of deadline misses gives us a rough overview of 44 // Recording the percentage of deadline misses gives us a rough overview of
58 // how many users might be running into audio glitches. 45 // how many users might be running into audio glitches.
(...skipping 13 matching lines...) Expand all
72 } 59 }
73 60
74 void AudioSyncReader::Read(const AudioBus* source, AudioBus* dest) { 61 void AudioSyncReader::Read(const AudioBus* source, AudioBus* dest) {
75 ++renderer_callback_count_; 62 ++renderer_callback_count_;
76 if (!WaitUntilDataIsReady()) { 63 if (!WaitUntilDataIsReady()) {
77 ++renderer_missed_callback_count_; 64 ++renderer_missed_callback_count_;
78 dest->Zero(); 65 dest->Zero();
79 return; 66 return;
80 } 67 }
81 68
82 // Copy optional synchronized live audio input for consumption by renderer
83 // process.
84 if (input_bus_) {
85 if (source)
86 source->CopyTo(input_bus_.get());
87 else
88 input_bus_->Zero();
89 }
90
91 if (mute_audio_) 69 if (mute_audio_)
92 dest->Zero(); 70 dest->Zero();
93 else 71 else
94 output_bus_->CopyTo(dest); 72 output_bus_->CopyTo(dest);
95 } 73 }
96 74
97 void AudioSyncReader::Close() { 75 void AudioSyncReader::Close() {
98 socket_->Close(); 76 socket_->Close();
99 } 77 }
100 78
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 base::TimeDelta::FromMilliseconds(1), 147 base::TimeDelta::FromMilliseconds(1),
170 base::TimeDelta::FromMilliseconds(1000), 148 base::TimeDelta::FromMilliseconds(1000),
171 50); 149 50);
172 return false; 150 return false;
173 } 151 }
174 152
175 return true; 153 return true;
176 } 154 }
177 155
178 } // namespace content 156 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_sync_reader.h ('k') | media/audio/alsa/alsa_output_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698