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

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 unittest compile breakage caused by recent method rename. 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
« no previous file with comments | « chrome/renderer/media/cast_receiver_audio_valve.h ('k') | chrome/renderer/media/cast_receiver_session.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6efb23db0b73d7cebd2be8e54b7a3cd246c9414d 100644
--- a/chrome/renderer/media/cast_receiver_audio_valve.cc
+++ b/chrome/renderer/media/cast_receiver_audio_valve.cc
@@ -4,26 +4,55 @@
#include "chrome/renderer/media/cast_receiver_audio_valve.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "media/audio/audio_parameters.h"
+
CastReceiverAudioValve::CastReceiverAudioValve(
+ const media::AudioParameters& params,
media::AudioCapturerSource::CaptureCallback* cb)
- : cb_(cb) {
+ : cb_(cb),
+ fifo_(base::Bind(&CastReceiverAudioValve::DeliverRebufferedAudio,
+ base::Unretained(this))),
+ sample_rate_(params.sample_rate()) {
+ fifo_.Reset(params.frames_per_buffer());
}
+
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) {
+ current_playout_time_ = playout_time;
+ // The following will result in zero, one, or multiple synchronous calls to
+ // DeliverRebufferedAudio().
+ fifo_.Push(*audio_bus);
}
-void CastReceiverAudioValve::OnCaptureError(const std::string& message) {
+void CastReceiverAudioValve::DeliverRebufferedAudio(
+ const media::AudioBus& audio_bus,
+ int frame_delay) {
+ const base::TimeTicks playout_time =
+ current_playout_time_ +
+ base::TimeDelta::FromMicroseconds(
+ frame_delay * base::Time::kMicrosecondsPerSecond / sample_rate_);
+
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 int audio_delay_milliseconds =
+ (base::TimeTicks::Now() - playout_time).InMilliseconds();
+
+ cb_->Capture(&audio_bus, audio_delay_milliseconds, 1.0 /* volume */,
+ false /* key_pressed */);
}
}
« no previous file with comments | « chrome/renderer/media/cast_receiver_audio_valve.h ('k') | chrome/renderer/media/cast_receiver_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698