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

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

Issue 1714593003: Introduce media::AudioPushFifo and a couple of use cases (and clean-ups). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win compile issue. Created 4 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webaudio_capturer_source.cc
diff --git a/content/renderer/media/webaudio_capturer_source.cc b/content/renderer/media/webaudio_capturer_source.cc
index bcebcbb3e24e523288827db01d6b740a019a29fd..6a4966070870b38b1e0627cb6aeca2e93da426c2 100644
--- a/content/renderer/media/webaudio_capturer_source.cc
+++ b/content/renderer/media/webaudio_capturer_source.cc
@@ -4,27 +4,28 @@
#include "content/renderer/media/webaudio_capturer_source.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "content/renderer/media/webrtc_local_audio_track.h"
using media::AudioBus;
-using media::AudioFifo;
using media::AudioParameters;
using media::ChannelLayout;
using media::CHANNEL_LAYOUT_MONO;
using media::CHANNEL_LAYOUT_STEREO;
-static const int kMaxNumberOfBuffersInFifo = 5;
-
namespace content {
WebAudioCapturerSource::WebAudioCapturerSource(
const blink::WebMediaStreamSource& blink_source)
: track_(NULL),
audio_format_changed_(false),
- blink_source_(blink_source) {
-}
+ rechunker_(base::TimeDelta::FromMilliseconds(10),
+ base::Bind(&WebAudioCapturerSource::DeliverRechunkedAudio,
+ base::Unretained(this))),
+ blink_source_(blink_source) {}
WebAudioCapturerSource::~WebAudioCapturerSource() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -48,20 +49,19 @@ void WebAudioCapturerSource::setFormat(
// Set the format used by this WebAudioCapturerSource. We are using 10ms data
// as buffer size since that is the native buffer size of WebRtc packet
// running on.
+ rechunker_.SetSampleRate(sample_rate);
params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, 16, sample_rate / 100);
+ sample_rate, 16, rechunker_.output_frames());
// Take care of the discrete channel layout case.
params_.set_channels_for_discrete(number_of_channels);
audio_format_changed_ = true;
- wrapper_bus_ = AudioBus::CreateWrapper(params_.channels());
- capture_bus_ = AudioBus::Create(params_);
-
- fifo_.reset(new AudioFifo(
- params_.channels(),
- kMaxNumberOfBuffersInFifo * params_.frames_per_buffer()));
+ if (!wrapper_bus_ ||
+ wrapper_bus_->channels() != static_cast<int>(number_of_channels)) {
+ wrapper_bus_ = AudioBus::CreateWrapper(params_.channels());
+ }
}
void WebAudioCapturerSource::Start(WebRtcLocalAudioTrack* track) {
@@ -85,6 +85,11 @@ void WebAudioCapturerSource::Stop() {
void WebAudioCapturerSource::consumeAudio(
const blink::WebVector<const float*>& audio_data,
size_t number_of_frames) {
+ // TODO(miu): Plumbing is needed to determine the actual capture timestamp
+ // of the audio, instead of just snapshotting TimeTicks::Now(), for proper
+ // audio/video sync. http://crbug.com/335335
+ base::TimeTicks reference_time = base::TimeTicks::Now();
+
base::AutoLock auto_lock(lock_);
if (!track_)
return;
@@ -96,36 +101,20 @@ void WebAudioCapturerSource::consumeAudio(
}
wrapper_bus_->set_frames(number_of_frames);
-
- // Make sure WebKit is honoring what it told us up front
- // about the channels.
DCHECK_EQ(params_.channels(), static_cast<int>(audio_data.size()));
-
for (size_t i = 0; i < audio_data.size(); ++i)
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)) {
- NOTREACHED() << "WebAudioCapturerSource::Consume() : FIFO overrun.";
- return;
- }
-
- // Compute the estimated capture time of the first sample frame of audio that
- // will be consumed from the FIFO in the loop below.
- base::TimeTicks estimated_capture_time = base::TimeTicks::Now() -
- fifo_->frames() * base::TimeDelta::FromSeconds(1) / params_.sample_rate();
-
- fifo_->Push(wrapper_bus_.get());
- while (fifo_->frames() >= capture_bus_->frames()) {
- fifo_->Consume(capture_bus_.get(), 0, capture_bus_->frames());
- track_->Capture(*capture_bus_, estimated_capture_time, false);
+ // The following will result in zero, one, or multiple synchronous calls to
+ // DeliverRechunkedAudio().
+ rechunker_.Push(*wrapper_bus_, reference_time - base::TimeTicks());
o1ka 2016/02/22 13:04:47 I like how neat it becomes!
miu 2016/02/23 04:27:41 Acknowledged.
+}
- // Advance the estimated capture time for the next FIFO consume operation.
- estimated_capture_time +=
- capture_bus_->frames() * base::TimeDelta::FromSeconds(1) /
- params_.sample_rate();
- }
+void WebAudioCapturerSource::DeliverRechunkedAudio(
+ const media::AudioBus& audio_bus,
+ base::TimeDelta reference_timestamp) {
+ lock_.AssertAcquired();
+ track_->Capture(audio_bus, base::TimeTicks() + reference_timestamp, false);
}
// If registered as audio consumer in |blink_source_|, deregister from

Powered by Google App Engine
This is Rietveld 408576698