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

Unified Diff: chrome/renderer/media/cast_receiver_audio_valve.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: chrome/renderer/media/cast_receiver_audio_valve.cc
diff --git a/chrome/renderer/media/cast_receiver_audio_valve.cc b/chrome/renderer/media/cast_receiver_audio_valve.cc
index 785d90df7e85c5f5acbbdb6afff9c06c16cc1759..5e47116fb602183ac4301068a3800de1a49cff18 100644
--- a/chrome/renderer/media/cast_receiver_audio_valve.cc
+++ b/chrome/renderer/media/cast_receiver_audio_valve.cc
@@ -4,26 +4,57 @@
#include "chrome/renderer/media/cast_receiver_audio_valve.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/time/time.h"
+#include "media/audio/audio_parameters.h"
+
CastReceiverAudioValve::CastReceiverAudioValve(
+ const media::AudioParameters& params,
media::AudioCapturerSource::CaptureCallback* cb)
- : cb_(cb) {
+ : cb_(cb),
+ rechunker_(
+ base::TimeDelta::FromMicroseconds(params.frames_per_buffer() *
+ base::Time::kMicrosecondsPerSecond /
+ params.sample_rate()),
+ base::Bind(&CastReceiverAudioValve::DeliverRechunkedAudio,
+ base::Unretained(this))) {
+ rechunker_.SetSampleRate(params.sample_rate());
xjz 2016/02/20 01:53:04 Need to check returning true?
miu 2016/02/23 04:27:41 No longer applicable.
}
+
CastReceiverAudioValve::~CastReceiverAudioValve() {}
-void CastReceiverAudioValve::Capture(const media::AudioBus* audio_source,
- int audio_delay_milliseconds,
- double volume,
- bool key_pressed) {
- base::AutoLock lock(lock_);
- if (cb_) {
- cb_->Capture(audio_source, audio_delay_milliseconds, volume, key_pressed);
- }
+void CastReceiverAudioValve::DeliverDecodedAudio(
+ const media::AudioBus* audio_bus,
+ base::TimeTicks playout_time) {
+ const base::TimeDelta timestamp_relative_to_origin =
+ playout_time - base::TimeTicks();
+ // The following will result in zero, one, or multiple synchronous calls to
+ // DeliverRechunkedAudio().
+ rechunker_.Push(*audio_bus, timestamp_relative_to_origin);
}
-void CastReceiverAudioValve::OnCaptureError(const std::string& message) {
+void CastReceiverAudioValve::DeliverRechunkedAudio(
+ const media::AudioBus& audio_bus,
+ base::TimeDelta timestamp_relative_to_origin) {
base::AutoLock lock(lock_);
if (cb_) {
- cb_->OnCaptureError(message);
+ // The AudioCapturerSource::Callback interface provides timing information
+ // only as a relative delay value that means "captured N milliseconds ago."
+ // Therefore, translate the playout time to these semantics. Since playout
+ // time is generally in the future, because audio should be decoded well
+ // ahead of when it should be played out, the audio delay value will
+ // generally be negative.
+ //
+ // TimeTicks::Now() is being called after the |lock_| was acquired in order
+ // to provide the most accurate delay value.
+ const base::TimeTicks playout_time =
+ base::TimeTicks() + timestamp_relative_to_origin;
+ const int audio_delay_milliseconds =
+ (base::TimeTicks::Now() - playout_time).InMilliseconds();
+
+ cb_->Capture(&audio_bus, audio_delay_milliseconds, 1.0 /* volume */,
+ false /* key_pressed */);
}
}

Powered by Google App Engine
This is Rietveld 408576698