Switch to using media::TimeSource inside media::RendererImpl.
This finally replaces the time-updating-callback inside of AudioRenderer
and VideoRenderer with a model where clients can query the time. As a
result, many other bits of cleanup are now possible:
- Renderers no longer need to be aware of the media duration
- TimeDeltaInterpolator can be replaced with WallClockTimeSource
- We can separate time values used for syncing video vs. informational
BUG=370634
Review URL: https://codereview.chromium.org/534073002
Cr-Commit-Position: refs/heads/master@{#294029}
diff --git a/media/filters/renderer_impl.h b/media/filters/renderer_impl.h
index bc2c0e8..baef465 100644
--- a/media/filters/renderer_impl.h
+++ b/media/filters/renderer_impl.h
@@ -25,17 +25,16 @@
class AudioRenderer;
class Demuxer;
-class TimeDeltaInterpolator;
class TimeSource;
class VideoRenderer;
+class WallClockTimeSource;
class MEDIA_EXPORT RendererImpl : public Renderer {
public:
// Renders audio/video streams in |demuxer| using |audio_renderer| and
// |video_renderer| provided. All methods except for GetMediaTime() run on the
// |task_runner|. GetMediaTime() runs on the render main thread because it's
- // part of JS sync API. |get_duration_cb| is used to get the duration of the
- // stream.
+ // part of JS sync API.
RendererImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
Demuxer* demuxer,
scoped_ptr<AudioRenderer> audio_renderer,
@@ -48,8 +47,7 @@
const StatisticsCB& statistics_cb,
const base::Closure& ended_cb,
const PipelineStatusCB& error_cb,
- const BufferingStateCB& buffering_state_cb,
- const TimeDeltaCB& get_duration_cb) OVERRIDE;
+ const BufferingStateCB& buffering_state_cb) OVERRIDE;
virtual void Flush(const base::Closure& flush_cb) OVERRIDE;
virtual void StartPlayingFrom(base::TimeDelta time) OVERRIDE;
virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
@@ -61,7 +59,7 @@
// Helper functions for testing purposes. Must be called before Initialize().
void DisableUnderflowForTesting();
- void SetTimeDeltaInterpolatorForTesting(TimeDeltaInterpolator* interpolator);
+ void EnableClocklessVideoPlaybackForTesting();
private:
enum State {
@@ -72,7 +70,7 @@
STATE_ERROR
};
- base::TimeDelta GetMediaDuration();
+ base::TimeDelta GetMediaTimeForSyncingVideo();
// Helper functions and callbacks for Initialize().
void InitializeAudioRenderer();
@@ -86,12 +84,6 @@
void FlushVideoRenderer();
void OnVideoRendererFlushDone();
- // Callback executed by audio renderer to update clock time.
- void OnAudioTimeUpdate(base::TimeDelta time, base::TimeDelta max_time);
-
- // Callback executed by video renderer to update clock time.
- void OnVideoTimeUpdate(base::TimeDelta max_time);
-
// Callback executed by filters to update statistics.
void OnUpdateStatistics(const PipelineStatistics& stats);
@@ -110,12 +102,10 @@
void PausePlayback();
void StartPlayback();
- void PauseClockAndStopTicking_Locked();
- void StartClockIfWaitingForTimeUpdate_Locked();
-
// Callbacks executed when a renderer has ended.
void OnAudioRendererEnded();
void OnVideoRendererEnded();
+ bool PlaybackHasEnded() const;
void RunEndedCallbackIfNeeded();
// Callback executed when a runtime error happens.
@@ -130,9 +120,6 @@
Demuxer* demuxer_;
- // Permanent callback to get the media duration.
- TimeDeltaCB get_duration_cb_;
-
// Permanent callbacks to notify various renderer states/stats.
StatisticsCB statistics_cb_;
base::Closure ended_cb_;
@@ -148,6 +135,8 @@
// Renderer-provided time source used to control playback.
TimeSource* time_source_;
+ scoped_ptr<WallClockTimeSource> wall_clock_time_source_;
+ bool time_ticking_;
// The time to start playback from after starting/seeking has completed.
base::TimeDelta start_time_;
@@ -160,32 +149,7 @@
bool video_ended_;
bool underflow_disabled_for_testing_;
-
- // Protects time interpolation related member variables, i.e. |interpolator_|,
- // |default_tick_clock_| and |interpolation_state_|. This is because
- // |interpolator_| can be used on different threads (see GetMediaTime()).
- mutable base::Lock interpolator_lock_;
-
- // Tracks the most recent media time update and provides interpolated values
- // as playback progresses.
- scoped_ptr<TimeDeltaInterpolator> interpolator_;
-
- // base::TickClock used by |interpolator_|.
- // TODO(xhwang): This can be TimeDeltaInterpolator's implementation detail.
- base::DefaultTickClock default_tick_clock_;
-
- enum InterpolationState {
- // Audio (if present) is not rendering. Time isn't being interpolated.
- INTERPOLATION_STOPPED,
-
- // Audio (if present) is rendering. Time isn't being interpolated.
- INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE,
-
- // Audio (if present) is rendering. Time is being interpolated.
- INTERPOLATION_STARTED,
- };
-
- InterpolationState interpolation_state_;
+ bool clockless_video_playback_enabled_for_testing_;
// NOTE: Weak pointers must be invalidated before all other member variables.
base::WeakPtrFactory<RendererImpl> weak_factory_;