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 */); |
} |
} |