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

Unified Diff: content/renderer/media/audio_renderer_impl.h

Issue 9347029: Decouple 'give me more data' and 'rendered end of stream' audio callbacks. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 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 | « no previous file | content/renderer/media/audio_renderer_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/audio_renderer_impl.h
===================================================================
--- content/renderer/media/audio_renderer_impl.h (revision 121128)
+++ content/renderer/media/audio_renderer_impl.h (working copy)
@@ -19,9 +19,12 @@
#include <vector>
+#include "base/atomicops.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop_proxy.h"
#include "base/synchronization/lock.h"
+#include "base/time.h"
#include "content/renderer/media/audio_device.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_parameters.h"
@@ -77,18 +80,27 @@
void DoPause();
void DoSeek();
+ // Methods called on IO thread ----------------------------------------------
+ void DoSignalEndOfStream(base::subtle::Atomic32 stream_id);
+
// media::AudioRendererSink::RenderCallback implementation.
virtual size_t Render(const std::vector<float*>& audio_data,
size_t number_of_frames,
size_t audio_delay_milliseconds) OVERRIDE;
virtual void OnError() OVERRIDE;
+ // Returns delay in ms before call to OnRenderEndOfStream().
+ // Made virtual so test can override.
+ virtual int64 OnRenderEndOfStreamDelay();
+
// Accessors used by tests.
- base::Time earliest_end_time() const {
+ base::Time earliest_end_time() {
+ base::AutoLock auto_lock(earliest_end_time_lock_);
return earliest_end_time_;
}
void set_earliest_end_time(const base::Time& earliest_end_time) {
+ base::AutoLock auto_lock(earliest_end_time_lock_);
earliest_end_time_ = earliest_end_time;
}
@@ -113,6 +125,11 @@
// Set to true when OnInitialize() is called.
bool is_initialized_;
+ // Set to true when we post delayed task to signal 'ended' event.
+ // Made Atomic, not bool, because it can be accessed simultaneously
+ // by pipeline and audio threads.
+ base::subtle::Atomic32 ended_event_scheduled_;
+
// We're supposed to know amount of audio data OS or hardware buffered, but
// that is not always so -- on my Linux box
// AudioBuffersState::hardware_delay_bytes never reaches 0.
@@ -127,10 +144,26 @@
// empty till that time. Workaround is not bulletproof, as we don't exactly
// know when that particular data would start playing, but it is much better
// than nothing.
+ // Access protected by lock as it can be accessed by pipeline and audio
+ // threads, and there is no Atomic64 on 32-bit systems.
base::Time earliest_end_time_;
+ base::Lock earliest_end_time_lock_;
AudioParameters audio_parameters_;
+ // Use message loop proxy, not message loop itself, to avoid crash
+ // because of message loop that ended while we are still playing.
+ // We don't need complex shutdown operations, just not posting tasks
+ // is enough, so we can use message loop proxy.
+ scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
+
+ // Stream id -- necessary because there is no way to cancel scheduled task.
+ // We want be sure we are still playing the same stream when delayed task is
+ // called. If seek or pause happened after scheduling but before task was
+ // called, there would be mismatch between expected and actual ids and delayed
+ // task would not do anything.
+ base::subtle::Atomic32 stream_id_;
Ami GONE FROM CHROMIUM 2012/02/23 20:18:25 I might be missing something, but ISTM this member
enal1 2012/02/23 20:28:04 ++stream_id_ happens only on the pipeline thread,
+
DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl);
};
« no previous file with comments | « no previous file | content/renderer/media/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698