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

Unified Diff: content/renderer/media/webaudio_capturer_source.cc

Issue 11369171: Add chromium support for MediaStreamAudioDestinationNode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webaudio_capturer_source.cc
===================================================================
--- content/renderer/media/webaudio_capturer_source.cc (revision 0)
+++ content/renderer/media/webaudio_capturer_source.cc (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/media/webaudio_capturer_source.h"
+
+#include "base/logging.h"
+
+using media::AudioParameters;
+using media::AudioBus;
+using media::AudioFifo;
+
+static const int kFifoSize = 2048;
+
+namespace content {
+
+WebAudioCapturerSource::WebAudioCapturerSource()
+ : callback_(0),
+ started_(false) {
+}
+
+WebAudioCapturerSource::~WebAudioCapturerSource() {
+}
+
+void WebAudioCapturerSource::Initialize(
+ const media::AudioParameters& params,
+ media::AudioCapturerSource::CaptureCallback* callback,
+ media::AudioCapturerSource::CaptureEventHandler* event_handler) {
+ base::AutoLock auto_lock(lock_);
+ params_ = params;
+ callback_ = callback;
+ wrapper_bus_ = AudioBus::CreateWrapper(params.channels());
+ capture_bus_ = AudioBus::Create(params);
+ fifo_.reset(new AudioFifo(params.channels(), kFifoSize));
+}
+
+void WebAudioCapturerSource::Start() {
+ // TODO(crogers): check that our client actually is calling Start()
+ // and do something with this information.
+ started_ = true;
+}
+
+void WebAudioCapturerSource::Stop() {
+ started_ = false;
+}
+
+void WebAudioCapturerSource::HandleCapture(
+ const WebKit::WebVector<const float*>& audio_data,
+ size_t number_of_frames) {
+ base::AutoLock auto_lock(lock_);
+ if (!callback_)
+ return;
+
+ if (wrapper_bus_->channels() != static_cast<int>(audio_data.size())) {
+ LOG(ERROR) << "WebAudioCapturerSource::Consume() : Channel mismatch.";
+ return;
+ }
+
+ // TODO(crogers): Handle possibly sample-rate mismatch.
+ // Currently we don't even receive this information from WebKit.
+
+ // Wrap.
tommi (sloooow) - chröme 2012/11/12 09:46:18 comment doesn't add much :)
+ wrapper_bus_->set_frames(number_of_frames);
+ for (unsigned i = 0; i < audio_data.size(); ++i)
tommi (sloooow) - chröme 2012/11/12 09:46:18 s/unsigned/size_t or int?
+ wrapper_bus_->SetChannelData(i, const_cast<float*>(audio_data[i]));
+
+ // Handle mismatch between WebAudio buffer-size and WebRTC.
+ int available = fifo_->max_frames() - fifo_->frames();
+ if (available < static_cast<int>(number_of_frames)) {
+ LOG(ERROR) << "WebAudioCapturerSource::Consume() : FIFO overrun.";
+ return;
+ }
+
+ fifo_->Push(wrapper_bus_.get());
+ int capture_frames = params_.frames_per_buffer();
+ while (fifo_->frames() >= capture_frames) {
+ fifo_->Consume(capture_bus_.get(), 0, capture_frames);
+ callback_->Capture(capture_bus_.get(), 0, 1.0);
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698