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

Side by Side 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 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/webaudio_capturer_source.h"
6
7 #include "base/logging.h"
8
9 using media::AudioParameters;
no longer working on chromium 2012/12/17 22:17:58 nit, move it under media::AudioFifo;
10 using media::AudioBus;
11 using media::AudioFifo;
12
13 static const int kFifoSize = 2048;
14
15 namespace content {
16
17 WebAudioCapturerSource::WebAudioCapturerSource()
18 : callback_(0),
no longer working on chromium 2012/12/17 22:17:58 NULL
19 started_(false) {
20 }
21
22 WebAudioCapturerSource::~WebAudioCapturerSource() {
23 }
24
25 void WebAudioCapturerSource::Initialize(
26 const media::AudioParameters& params,
27 media::AudioCapturerSource::CaptureCallback* callback,
28 media::AudioCapturerSource::CaptureEventHandler* event_handler) {
29 base::AutoLock auto_lock(lock_);
no longer working on chromium 2012/12/17 22:17:58 When this Initialize() needs to be called? Is it c
30 params_ = params;
31 callback_ = callback;
32 wrapper_bus_ = AudioBus::CreateWrapper(params.channels());
33 capture_bus_ = AudioBus::Create(params);
34 fifo_.reset(new AudioFifo(params.channels(), kFifoSize));
35 }
36
37 void WebAudioCapturerSource::Start() {
38 // TODO(crogers): check that our client actually is calling Start()
39 // and do something with this information.
40 started_ = true;
41 }
42
43 void WebAudioCapturerSource::Stop() {
44 started_ = false;
45 }
46
47 void WebAudioCapturerSource::consumeAudio(
48 const WebKit::WebVector<const float*>& audio_data,
49 size_t number_of_frames) {
50 base::AutoLock auto_lock(lock_);
51 if (!callback_)
52 return;
53
54 if (wrapper_bus_->channels() != static_cast<int>(audio_data.size())) {
55 LOG(ERROR) << "WebAudioCapturerSource::Consume() : Channel mismatch.";
56 return;
57 }
58
59 // TODO(crogers): Handle possible sample-rate mismatch.
60 // Currently we don't even receive this information from WebKit.
61
62 wrapper_bus_->set_frames(number_of_frames);
63 for (size_t i = 0; i < audio_data.size(); ++i)
64 wrapper_bus_->SetChannelData(i, const_cast<float*>(audio_data[i]));
65
66 // Handle mismatch between WebAudio buffer-size and WebRTC.
67 int available = fifo_->max_frames() - fifo_->frames();
68 if (available < static_cast<int>(number_of_frames)) {
69 LOG(ERROR) << "WebAudioCapturerSource::Consume() : FIFO overrun.";
70 return;
71 }
72
73 fifo_->Push(wrapper_bus_.get());
74 int capture_frames = params_.frames_per_buffer();
75 while (fifo_->frames() >= capture_frames) {
76 fifo_->Consume(capture_bus_.get(), 0, capture_frames);
77 callback_->Capture(capture_bus_.get(), 0, 1.0);
78 }
79 }
80
81 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698