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

Unified Diff: media/audio/clockless_audio_sink.cc

Issue 1260193005: Fix incorrect opus seek preroll and flaky pre-skip removal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test cases. Created 5 years, 5 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: media/audio/clockless_audio_sink.cc
diff --git a/media/audio/clockless_audio_sink.cc b/media/audio/clockless_audio_sink.cc
index 60c839c124b210c682f9cf5fd724881075ff12bb..718e35d2de80a53cbe0c69ff20873517659f36c4 100644
--- a/media/audio/clockless_audio_sink.cc
+++ b/media/audio/clockless_audio_sink.cc
@@ -8,6 +8,7 @@
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/simple_thread.h"
+#include "media/base/audio_hash.h"
namespace media {
@@ -15,11 +16,15 @@ namespace media {
// thread, running as fast as it can read the data.
class ClocklessAudioSinkThread : public base::DelegateSimpleThread::Delegate {
public:
- explicit ClocklessAudioSinkThread(const AudioParameters& params,
- AudioRendererSink::RenderCallback* callback)
+ ClocklessAudioSinkThread(const AudioParameters& params,
+ AudioRendererSink::RenderCallback* callback,
+ bool hashing)
: callback_(callback),
audio_bus_(AudioBus::Create(params)),
- stop_event_(new base::WaitableEvent(false, false)) {}
+ stop_event_(new base::WaitableEvent(false, false)) {
+ if (hashing)
+ audio_hash_.reset(new AudioHash());
+ }
void Start() {
stop_event_->Reset();
@@ -34,12 +39,18 @@ class ClocklessAudioSinkThread : public base::DelegateSimpleThread::Delegate {
return playback_time_;
}
+ std::string GetAudioHash() {
+ return audio_hash_->ToString();
wolenetz 2015/07/29 21:57:27 nit: Is this for test only (I think so)? If not, t
DaleCurtis 2015/07/30 01:28:14 It is only for testing, but I can't add ForTesting
wolenetz 2015/08/06 22:21:27 Acknowledged.
+ }
+
private:
// Call Render() repeatedly, keeping track of the rendering time.
void Run() override {
base::TimeTicks start;
while (!stop_event_->IsSignaled()) {
int frames_received = callback_->Render(audio_bus_.get(), 0);
+ if (audio_hash_)
+ audio_hash_->Update(audio_bus_.get(), frames_received);
wolenetz 2015/07/29 21:57:27 hmm. Could frames_received indeed be negative (see
DaleCurtis 2015/07/30 01:28:14 No, it's always >= 0. I've added a DCHECK and fixe
wolenetz 2015/08/06 22:21:27 Acknowledged.
if (frames_received <= 0) {
// No data received, so let other threads run to provide data.
base::PlatformThread::YieldCurrentThread();
@@ -58,18 +69,18 @@ class ClocklessAudioSinkThread : public base::DelegateSimpleThread::Delegate {
scoped_ptr<base::WaitableEvent> stop_event_;
scoped_ptr<base::DelegateSimpleThread> thread_;
base::TimeDelta playback_time_;
+ scoped_ptr<AudioHash> audio_hash_;
};
ClocklessAudioSink::ClocklessAudioSink()
- : initialized_(false),
- playing_(false) {}
+ : initialized_(false), playing_(false), hashing_(false) {}
ClocklessAudioSink::~ClocklessAudioSink() {}
void ClocklessAudioSink::Initialize(const AudioParameters& params,
RenderCallback* callback) {
DCHECK(!initialized_);
- thread_.reset(new ClocklessAudioSinkThread(params, callback));
+ thread_.reset(new ClocklessAudioSinkThread(params, callback, hashing_));
initialized_ = true;
}
@@ -115,4 +126,13 @@ void ClocklessAudioSink::SwitchOutputDevice(
callback.Run(SWITCH_OUTPUT_DEVICE_RESULT_ERROR_NOT_SUPPORTED);
}
+void ClocklessAudioSink::StartAudioHashForTesting() {
+ DCHECK(!initialized_);
+ hashing_ = true;
+}
+
+std::string ClocklessAudioSink::GetAudioHashForTesting() {
+ return thread_ && hashing_ ? thread_->GetAudioHash() : std::string();
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698