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

Side by Side Diff: media/renderers/renderer_impl.h

Issue 1955843002: Move Renderer permanent callbacks into RendererClient interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_RENDERERS_RENDERER_IMPL_H_ 5 #ifndef MEDIA_RENDERERS_RENDERER_IMPL_H_
6 #define MEDIA_RENDERERS_RENDERER_IMPL_H_ 6 #define MEDIA_RENDERERS_RENDERER_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 29 matching lines...) Expand all
40 // provided. All methods except for GetMediaTime() run on the |task_runner|. 40 // provided. All methods except for GetMediaTime() run on the |task_runner|.
41 // GetMediaTime() runs on the render main thread because it's part of JS sync 41 // GetMediaTime() runs on the render main thread because it's part of JS sync
42 // API. 42 // API.
43 RendererImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 43 RendererImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
44 std::unique_ptr<AudioRenderer> audio_renderer, 44 std::unique_ptr<AudioRenderer> audio_renderer,
45 std::unique_ptr<VideoRenderer> video_renderer); 45 std::unique_ptr<VideoRenderer> video_renderer);
46 46
47 ~RendererImpl() final; 47 ~RendererImpl() final;
48 48
49 // Renderer implementation. 49 // Renderer implementation.
50 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, 50 void Initialize(RendererClient* client,
51 const PipelineStatusCB& init_cb, 51 DemuxerStreamProvider* demuxer_stream_provider,
52 const StatisticsCB& statistics_cb, 52 const PipelineStatusCB& init_cb) final;
53 const BufferingStateCB& buffering_state_cb,
54 const base::Closure& ended_cb,
55 const PipelineStatusCB& error_cb,
56 const base::Closure& waiting_for_decryption_key_cb) final;
57 void SetCdm(CdmContext* cdm_context, 53 void SetCdm(CdmContext* cdm_context,
58 const CdmAttachedCB& cdm_attached_cb) final; 54 const CdmAttachedCB& cdm_attached_cb) final;
59 void Flush(const base::Closure& flush_cb) final; 55 void Flush(const base::Closure& flush_cb) final;
60 void StartPlayingFrom(base::TimeDelta time) final; 56 void StartPlayingFrom(base::TimeDelta time) final;
61 void SetPlaybackRate(double playback_rate) final; 57 void SetPlaybackRate(double playback_rate) final;
62 void SetVolume(float volume) final; 58 void SetVolume(float volume) final;
63 base::TimeDelta GetMediaTime() final; 59 base::TimeDelta GetMediaTime() final;
64 bool HasAudio() final; 60 bool HasAudio() final;
65 bool HasVideo() final; 61 bool HasVideo() final;
66 62
67 // Helper functions for testing purposes. Must be called before Initialize(). 63 // Helper functions for testing purposes. Must be called before Initialize().
68 void DisableUnderflowForTesting(); 64 void DisableUnderflowForTesting();
69 void EnableClocklessVideoPlaybackForTesting(); 65 void EnableClocklessVideoPlaybackForTesting();
70 void set_time_source_for_testing(TimeSource* time_source) { 66 void set_time_source_for_testing(TimeSource* time_source) {
71 time_source_ = time_source; 67 time_source_ = time_source;
72 } 68 }
73 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) { 69 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) {
74 video_underflow_threshold_ = threshold; 70 video_underflow_threshold_ = threshold;
75 } 71 }
76 72
77 private: 73 private:
74 class AudioVideoRendererClient;
xhwang 2016/05/09 18:13:23 This can only be the client for audio OR video. So
alokp 2016/05/09 21:31:44 Done.
75
78 enum State { 76 enum State {
79 STATE_UNINITIALIZED, 77 STATE_UNINITIALIZED,
80 STATE_INIT_PENDING_CDM, // Initialization is waiting for the CDM to be set. 78 STATE_INIT_PENDING_CDM, // Initialization is waiting for the CDM to be set.
81 STATE_INITIALIZING, // Initializing audio/video renderers. 79 STATE_INITIALIZING, // Initializing audio/video renderers.
82 STATE_FLUSHING, 80 STATE_FLUSHING,
83 STATE_PLAYING, 81 STATE_PLAYING,
84 STATE_ERROR 82 STATE_ERROR
85 }; 83 };
86 84
87 bool GetWallClockTimes(const std::vector<base::TimeDelta>& media_timestamps, 85 bool GetWallClockTimes(const std::vector<base::TimeDelta>& media_timestamps,
88 std::vector<base::TimeTicks>* wall_clock_times); 86 std::vector<base::TimeTicks>* wall_clock_times);
89 87
90 bool HasEncryptedStream(); 88 bool HasEncryptedStream();
91 89
92 void FinishInitialization(PipelineStatus status); 90 void FinishInitialization(PipelineStatus status);
93 91
94 // Helper functions and callbacks for Initialize(). 92 // Helper functions and callbacks for Initialize().
95 void InitializeAudioRenderer(); 93 void InitializeAudioRenderer();
96 void OnAudioRendererInitializeDone(PipelineStatus status); 94 void OnAudioRendererInitializeDone(PipelineStatus status);
97 void InitializeVideoRenderer(); 95 void InitializeVideoRenderer();
98 void OnVideoRendererInitializeDone(PipelineStatus status); 96 void OnVideoRendererInitializeDone(PipelineStatus status);
99 97
100 // Helper functions and callbacks for Flush(). 98 // Helper functions and callbacks for Flush().
101 void FlushAudioRenderer(); 99 void FlushAudioRenderer();
102 void OnAudioRendererFlushDone(); 100 void OnAudioRendererFlushDone();
103 void FlushVideoRenderer(); 101 void FlushVideoRenderer();
104 void OnVideoRendererFlushDone(); 102 void OnVideoRendererFlushDone();
105 103
106 // Callback executed by filters to update statistics. 104 // Callback executed by filters to update statistics.
107 void OnUpdateStatistics(const PipelineStatistics& stats); 105 void OnStatisticsUpdate(AudioVideoRendererClient* client,
106 const PipelineStatistics& stats);
108 107
109 // Collection of callback methods and helpers for tracking changes in 108 // Collection of callback methods and helpers for tracking changes in
110 // buffering state and transition from paused/underflow states and playing 109 // buffering state and transition from paused/underflow states and playing
111 // states. 110 // states.
112 // 111 //
113 // While in the kPlaying state: 112 // While in the kPlaying state:
114 // - A waiting to non-waiting transition indicates preroll has completed 113 // - A waiting to non-waiting transition indicates preroll has completed
115 // and StartPlayback() should be called 114 // and StartPlayback() should be called
116 // - A non-waiting to waiting transition indicates underflow has occurred 115 // - A non-waiting to waiting transition indicates underflow has occurred
117 // and PausePlayback() should be called 116 // and PausePlayback() should be called
118 void OnBufferingStateChanged(BufferingState* buffering_state, 117 void OnBufferingStateChange(AudioVideoRendererClient* client,
119 BufferingState new_buffering_state); 118 BufferingState new_buffering_state);
120 bool WaitingForEnoughData() const; 119 bool WaitingForEnoughData() const;
121 void PausePlayback(); 120 void PausePlayback();
122 void StartPlayback(); 121 void StartPlayback();
123 122
124 // Callbacks executed when a renderer has ended. 123 // Callbacks executed when a renderer has ended.
125 void OnAudioRendererEnded(); 124 void OnRendererEnded(AudioVideoRendererClient* client);
126 void OnVideoRendererEnded();
127 bool PlaybackHasEnded() const; 125 bool PlaybackHasEnded() const;
128 void RunEndedCallbackIfNeeded(); 126 void RunEndedCallbackIfNeeded();
129 127
130 // Callback executed when a runtime error happens. 128 // Callback executed when a runtime error happens.
131 void OnError(PipelineStatus error); 129 void OnError(AudioVideoRendererClient* client, PipelineStatus error);
130 void OnWaitingForDecryptionKey(AudioVideoRendererClient* client);
132 131
133 State state_; 132 State state_;
134 133
135 // Task runner used to execute pipeline tasks. 134 // Task runner used to execute pipeline tasks.
136 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
137 136
137 RendererClient* client_;
138 DemuxerStreamProvider* demuxer_stream_provider_; 138 DemuxerStreamProvider* demuxer_stream_provider_;
139 139
140 // Permanent callbacks to notify various renderer states/stats.
141 StatisticsCB statistics_cb_;
142 base::Closure ended_cb_;
143 PipelineStatusCB error_cb_;
144 BufferingStateCB buffering_state_cb_;
145 base::Closure waiting_for_decryption_key_cb_;
146
147 // Temporary callback used for Initialize() and Flush(). 140 // Temporary callback used for Initialize() and Flush().
148 PipelineStatusCB init_cb_; 141 PipelineStatusCB init_cb_;
149 base::Closure flush_cb_; 142 base::Closure flush_cb_;
150 143
144 std::unique_ptr<AudioVideoRendererClient> audio_renderer_client_;
145 std::unique_ptr<AudioVideoRendererClient> video_renderer_client_;
151 std::unique_ptr<AudioRenderer> audio_renderer_; 146 std::unique_ptr<AudioRenderer> audio_renderer_;
152 std::unique_ptr<VideoRenderer> video_renderer_; 147 std::unique_ptr<VideoRenderer> video_renderer_;
153 148
154 // Renderer-provided time source used to control playback. 149 // Renderer-provided time source used to control playback.
155 TimeSource* time_source_; 150 TimeSource* time_source_;
156 std::unique_ptr<WallClockTimeSource> wall_clock_time_source_; 151 std::unique_ptr<WallClockTimeSource> wall_clock_time_source_;
157 bool time_ticking_; 152 bool time_ticking_;
158 double playback_rate_; 153 double playback_rate_;
159 154
160 // The time to start playback from after starting/seeking has completed. 155 // The time to start playback from after starting/seeking has completed.
(...skipping 21 matching lines...) Expand all
182 177
183 base::WeakPtr<RendererImpl> weak_this_; 178 base::WeakPtr<RendererImpl> weak_this_;
184 base::WeakPtrFactory<RendererImpl> weak_factory_; 179 base::WeakPtrFactory<RendererImpl> weak_factory_;
185 180
186 DISALLOW_COPY_AND_ASSIGN(RendererImpl); 181 DISALLOW_COPY_AND_ASSIGN(RendererImpl);
187 }; 182 };
188 183
189 } // namespace media 184 } // namespace media
190 185
191 #endif // MEDIA_RENDERERS_RENDERER_IMPL_H_ 186 #endif // MEDIA_RENDERERS_RENDERER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698