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

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: addressed comments 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
« no previous file with comments | « media/renderers/audio_renderer_impl_unittest.cc ('k') | media/renderers/renderer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/cancelable_callback.h" 11 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/time/clock.h" 16 #include "base/time/clock.h"
17 #include "base/time/default_tick_clock.h" 17 #include "base/time/default_tick_clock.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "media/base/buffering_state.h" 19 #include "media/base/buffering_state.h"
20 #include "media/base/decryptor.h" 20 #include "media/base/decryptor.h"
21 #include "media/base/demuxer_stream.h"
21 #include "media/base/media_export.h" 22 #include "media/base/media_export.h"
22 #include "media/base/pipeline_status.h" 23 #include "media/base/pipeline_status.h"
23 #include "media/base/renderer.h" 24 #include "media/base/renderer.h"
24 25
25 namespace base { 26 namespace base {
26 class SingleThreadTaskRunner; 27 class SingleThreadTaskRunner;
27 } 28 }
28 29
29 namespace media { 30 namespace media {
30 31
(...skipping 10 matching lines...) Expand all
41 // GetMediaTime() runs on the render main thread because it's part of JS sync 42 // GetMediaTime() runs on the render main thread because it's part of JS sync
42 // API. 43 // API.
43 RendererImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 44 RendererImpl(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
44 std::unique_ptr<AudioRenderer> audio_renderer, 45 std::unique_ptr<AudioRenderer> audio_renderer,
45 std::unique_ptr<VideoRenderer> video_renderer); 46 std::unique_ptr<VideoRenderer> video_renderer);
46 47
47 ~RendererImpl() final; 48 ~RendererImpl() final;
48 49
49 // Renderer implementation. 50 // Renderer implementation.
50 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, 51 void Initialize(DemuxerStreamProvider* demuxer_stream_provider,
51 const PipelineStatusCB& init_cb, 52 RendererClient* client,
52 const StatisticsCB& statistics_cb, 53 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, 54 void SetCdm(CdmContext* cdm_context,
58 const CdmAttachedCB& cdm_attached_cb) final; 55 const CdmAttachedCB& cdm_attached_cb) final;
59 void Flush(const base::Closure& flush_cb) final; 56 void Flush(const base::Closure& flush_cb) final;
60 void StartPlayingFrom(base::TimeDelta time) final; 57 void StartPlayingFrom(base::TimeDelta time) final;
61 void SetPlaybackRate(double playback_rate) final; 58 void SetPlaybackRate(double playback_rate) final;
62 void SetVolume(float volume) final; 59 void SetVolume(float volume) final;
63 base::TimeDelta GetMediaTime() final; 60 base::TimeDelta GetMediaTime() final;
64 bool HasAudio() final; 61 bool HasAudio() final;
65 bool HasVideo() final; 62 bool HasVideo() final;
66 63
67 // Helper functions for testing purposes. Must be called before Initialize(). 64 // Helper functions for testing purposes. Must be called before Initialize().
68 void DisableUnderflowForTesting(); 65 void DisableUnderflowForTesting();
69 void EnableClocklessVideoPlaybackForTesting(); 66 void EnableClocklessVideoPlaybackForTesting();
70 void set_time_source_for_testing(TimeSource* time_source) { 67 void set_time_source_for_testing(TimeSource* time_source) {
71 time_source_ = time_source; 68 time_source_ = time_source;
72 } 69 }
73 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) { 70 void set_video_underflow_threshold_for_testing(base::TimeDelta threshold) {
74 video_underflow_threshold_ = threshold; 71 video_underflow_threshold_ = threshold;
75 } 72 }
76 73
77 private: 74 private:
75 class RendererClientInternal;
76
78 enum State { 77 enum State {
79 STATE_UNINITIALIZED, 78 STATE_UNINITIALIZED,
80 STATE_INIT_PENDING_CDM, // Initialization is waiting for the CDM to be set. 79 STATE_INIT_PENDING_CDM, // Initialization is waiting for the CDM to be set.
81 STATE_INITIALIZING, // Initializing audio/video renderers. 80 STATE_INITIALIZING, // Initializing audio/video renderers.
82 STATE_FLUSHING, 81 STATE_FLUSHING,
83 STATE_PLAYING, 82 STATE_PLAYING,
84 STATE_ERROR 83 STATE_ERROR
85 }; 84 };
86 85
87 bool GetWallClockTimes(const std::vector<base::TimeDelta>& media_timestamps, 86 bool GetWallClockTimes(const std::vector<base::TimeDelta>& media_timestamps,
88 std::vector<base::TimeTicks>* wall_clock_times); 87 std::vector<base::TimeTicks>* wall_clock_times);
89 88
90 bool HasEncryptedStream(); 89 bool HasEncryptedStream();
91 90
92 void FinishInitialization(PipelineStatus status); 91 void FinishInitialization(PipelineStatus status);
93 92
94 // Helper functions and callbacks for Initialize(). 93 // Helper functions and callbacks for Initialize().
95 void InitializeAudioRenderer(); 94 void InitializeAudioRenderer();
96 void OnAudioRendererInitializeDone(PipelineStatus status); 95 void OnAudioRendererInitializeDone(PipelineStatus status);
97 void InitializeVideoRenderer(); 96 void InitializeVideoRenderer();
98 void OnVideoRendererInitializeDone(PipelineStatus status); 97 void OnVideoRendererInitializeDone(PipelineStatus status);
99 98
100 // Helper functions and callbacks for Flush(). 99 // Helper functions and callbacks for Flush().
101 void FlushAudioRenderer(); 100 void FlushAudioRenderer();
102 void OnAudioRendererFlushDone(); 101 void OnAudioRendererFlushDone();
103 void FlushVideoRenderer(); 102 void FlushVideoRenderer();
104 void OnVideoRendererFlushDone(); 103 void OnVideoRendererFlushDone();
105 104
106 // Callback executed by filters to update statistics. 105 // Callback executed by filters to update statistics.
107 void OnUpdateStatistics(const PipelineStatistics& stats); 106 void OnStatisticsUpdate(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(DemuxerStream::Type type,
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(DemuxerStream::Type type);
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(PipelineStatus error);
130 void OnWaitingForDecryptionKey();
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
138 DemuxerStreamProvider* demuxer_stream_provider_; 137 DemuxerStreamProvider* demuxer_stream_provider_;
139 138 RendererClient* client_;
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 139
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<RendererClientInternal> audio_renderer_client_;
145 std::unique_ptr<RendererClientInternal> 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
« no previous file with comments | « media/renderers/audio_renderer_impl_unittest.cc ('k') | media/renderers/renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698