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

Side by Side Diff: trunk/src/media/audio/alsa/alsa_input.cc

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/audio/alsa/alsa_input.h" 5 #include "media/audio/alsa/alsa_input.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 25 matching lines...) Expand all
36 8), 36 8),
37 wrapper_(wrapper), 37 wrapper_(wrapper),
38 buffer_duration_(base::TimeDelta::FromMicroseconds( 38 buffer_duration_(base::TimeDelta::FromMicroseconds(
39 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / 39 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
40 static_cast<float>(params.sample_rate()))), 40 static_cast<float>(params.sample_rate()))),
41 callback_(NULL), 41 callback_(NULL),
42 device_handle_(NULL), 42 device_handle_(NULL),
43 mixer_handle_(NULL), 43 mixer_handle_(NULL),
44 mixer_element_handle_(NULL), 44 mixer_element_handle_(NULL),
45 read_callback_behind_schedule_(false), 45 read_callback_behind_schedule_(false),
46 audio_bus_(AudioBus::Create(params)), 46 weak_factory_(this) {}
47 weak_factory_(this) {
48 }
49 47
50 AlsaPcmInputStream::~AlsaPcmInputStream() {} 48 AlsaPcmInputStream::~AlsaPcmInputStream() {}
51 49
52 bool AlsaPcmInputStream::Open() { 50 bool AlsaPcmInputStream::Open() {
53 if (device_handle_) 51 if (device_handle_)
54 return false; // Already open. 52 return false; // Already open.
55 53
56 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat( 54 snd_pcm_format_t pcm_format = alsa_util::BitsToFormat(
57 params_.bits_per_sample()); 55 params_.bits_per_sample());
58 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { 56 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 201
204 // Update the AGC volume level once every second. Note that, |volume| is 202 // Update the AGC volume level once every second. Note that, |volume| is
205 // also updated each time SetVolume() is called through IPC by the 203 // also updated each time SetVolume() is called through IPC by the
206 // render-side AGC. 204 // render-side AGC.
207 GetAgcVolume(&normalized_volume); 205 GetAgcVolume(&normalized_volume);
208 206
209 while (num_buffers--) { 207 while (num_buffers--) {
210 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(), 208 int frames_read = wrapper_->PcmReadi(device_handle_, audio_buffer_.get(),
211 params_.frames_per_buffer()); 209 params_.frames_per_buffer());
212 if (frames_read == params_.frames_per_buffer()) { 210 if (frames_read == params_.frames_per_buffer()) {
213 audio_bus_->FromInterleaved(audio_buffer_.get(), 211 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_,
214 audio_bus_->frames(), 212 hardware_delay_bytes, normalized_volume);
215 params_.bits_per_sample() / 8);
216 callback_->OnData(
217 this, audio_bus_.get(), hardware_delay_bytes, normalized_volume);
218 } else { 213 } else {
219 LOG(WARNING) << "PcmReadi returning less than expected frames: " 214 LOG(WARNING) << "PcmReadi returning less than expected frames: "
220 << frames_read << " vs. " << params_.frames_per_buffer() 215 << frames_read << " vs. " << params_.frames_per_buffer()
221 << ". Dropping this buffer."; 216 << ". Dropping this buffer.";
222 } 217 }
223 } 218 }
224 219
225 next_read_time_ += buffer_duration_; 220 next_read_time_ += buffer_duration_;
226 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now(); 221 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now();
227 if (delay < base::TimeDelta()) { 222 if (delay < base::TimeDelta()) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 330
336 return static_cast<double>(current_volume); 331 return static_cast<double>(current_volume);
337 } 332 }
338 333
339 void AlsaPcmInputStream::HandleError(const char* method, int error) { 334 void AlsaPcmInputStream::HandleError(const char* method, int error) {
340 LOG(WARNING) << method << ": " << wrapper_->StrError(error); 335 LOG(WARNING) << method << ": " << wrapper_->StrError(error);
341 callback_->OnError(this); 336 callback_->OnError(this);
342 } 337 }
343 338
344 } // namespace media 339 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/media/audio/alsa/alsa_input.h ('k') | trunk/src/media/audio/android/audio_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698