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

Side by Side Diff: media/base/pipeline_impl.h

Issue 6686061: PipelineError is dead. Long live PipelineStatus! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: responses to CR Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Implementation of Pipeline. 5 // Implementation of Pipeline & PipelineStatusNotification (an async-to-sync
6 // callback adapter).
6 7
7 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_ 8 #ifndef MEDIA_BASE_PIPELINE_IMPL_H_
8 #define MEDIA_BASE_PIPELINE_IMPL_H_ 9 #define MEDIA_BASE_PIPELINE_IMPL_H_
9 10
10 #include <set> 11 #include <set>
11 #include <string> 12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/message_loop.h" 16 #include "base/message_loop.h"
16 #include "base/ref_counted.h" 17 #include "base/ref_counted.h"
17 #include "base/scoped_ptr.h" 18 #include "base/scoped_ptr.h"
19 #include "base/synchronization/condition_variable.h"
20 #include "base/synchronization/lock.h"
18 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
19 #include "base/time.h" 22 #include "base/time.h"
20 #include "media/base/clock.h" 23 #include "media/base/clock.h"
21 #include "media/base/composite_filter.h" 24 #include "media/base/composite_filter.h"
22 #include "media/base/filter_host.h" 25 #include "media/base/filter_host.h"
23 #include "media/base/pipeline.h" 26 #include "media/base/pipeline.h"
24 27
25 namespace media { 28 namespace media {
26 29
30 // Adapter for using asynchronous Pipeline methods in code that wants to run
31 // synchronously. To use, construct an instance of this class and pass the
32 // |Callback()| to the Pipeline method requiring a callback. Then Wait() for
33 // the callback to get fired and call status() to see what the callback's
34 // argument was.
acolwell GONE FROM CHROMIUM 2011/03/15 23:43:55 Please add a comment about Callback() being a one-
Ami GONE FROM CHROMIUM 2011/03/16 00:01:02 Done.
35 class PipelineStatusNotification {
36 public:
37 PipelineStatusNotification();
38 ~PipelineStatusNotification();
39
40 // See class-level comment for usage.
41 media::PipelineStatusCallback* Callback();
42 void Notify(media::PipelineStatus status);
43 void Wait();
44 media::PipelineStatus status();
45
46 private:
47 base::Lock lock_;
48 base::ConditionVariable cv_;
49 media::PipelineStatus status_;
50 bool notified_;
51 scoped_ptr<media::PipelineStatusCallback> callback_;
acolwell GONE FROM CHROMIUM 2011/03/15 23:43:55 DISALLOW_COPY_AND_ASSIGN
Ami GONE FROM CHROMIUM 2011/03/16 00:01:02 Done.
52 };
27 53
28 // PipelineImpl runs the media pipeline. Filters are created and called on the 54 // PipelineImpl runs the media pipeline. Filters are created and called on the
29 // message loop injected into this object. PipelineImpl works like a state 55 // message loop injected into this object. PipelineImpl works like a state
30 // machine to perform asynchronous initialization, pausing, seeking and playing. 56 // machine to perform asynchronous initialization, pausing, seeking and playing.
31 // 57 //
32 // Here's a state diagram that describes the lifetime of this object. 58 // Here's a state diagram that describes the lifetime of this object.
33 // 59 //
34 // [ *Created ] [ Stopped ] 60 // [ *Created ] [ Stopped ]
35 // | Start() ^ 61 // | Start() ^
36 // V SetError() | 62 // V SetError() |
(...skipping 23 matching lines...) Expand all
60 // playing the media. 86 // playing the media.
61 // 87 //
62 // If any error ever happens, this object will transition to the "Error" state 88 // If any error ever happens, this object will transition to the "Error" state
63 // from any state. If Stop() is ever called, this object will transition to 89 // from any state. If Stop() is ever called, this object will transition to
64 // "Stopped" state. 90 // "Stopped" state.
65 class PipelineImpl : public Pipeline, public FilterHost { 91 class PipelineImpl : public Pipeline, public FilterHost {
66 public: 92 public:
67 explicit PipelineImpl(MessageLoop* message_loop); 93 explicit PipelineImpl(MessageLoop* message_loop);
68 94
69 // Pipeline implementation. 95 // Pipeline implementation.
70 virtual void Init(PipelineCallback* ended_callback, 96 virtual void Init(PipelineStatusCallback* ended_callback,
71 PipelineCallback* error_callback, 97 PipelineStatusCallback* error_callback,
72 PipelineCallback* network_callback); 98 PipelineStatusCallback* network_callback);
73 virtual bool Start(FilterCollection* filter_collection, 99 virtual bool Start(FilterCollection* filter_collection,
74 const std::string& uri, 100 const std::string& uri,
75 PipelineCallback* start_callback); 101 PipelineStatusCallback* start_callback);
76 virtual void Stop(PipelineCallback* stop_callback); 102 virtual void Stop(PipelineStatusCallback* stop_callback);
77 virtual void Seek(base::TimeDelta time, PipelineCallback* seek_callback); 103 virtual void Seek(base::TimeDelta time,
104 PipelineStatusCallback* seek_callback);
78 virtual bool IsRunning() const; 105 virtual bool IsRunning() const;
79 virtual bool IsInitialized() const; 106 virtual bool IsInitialized() const;
80 virtual bool IsNetworkActive() const; 107 virtual bool IsNetworkActive() const;
81 virtual bool HasAudio() const; 108 virtual bool HasAudio() const;
82 virtual bool HasVideo() const; 109 virtual bool HasVideo() const;
83 virtual float GetPlaybackRate() const; 110 virtual float GetPlaybackRate() const;
84 virtual void SetPlaybackRate(float playback_rate); 111 virtual void SetPlaybackRate(float playback_rate);
85 virtual float GetVolume() const; 112 virtual float GetVolume() const;
86 virtual void SetVolume(float volume); 113 virtual void SetVolume(float volume);
87 virtual base::TimeDelta GetCurrentTime() const; 114 virtual base::TimeDelta GetCurrentTime() const;
88 virtual base::TimeDelta GetBufferedTime(); 115 virtual base::TimeDelta GetBufferedTime();
89 virtual base::TimeDelta GetMediaDuration() const; 116 virtual base::TimeDelta GetMediaDuration() const;
90 virtual int64 GetBufferedBytes() const; 117 virtual int64 GetBufferedBytes() const;
91 virtual int64 GetTotalBytes() const; 118 virtual int64 GetTotalBytes() const;
92 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; 119 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const;
93 virtual bool IsStreaming() const; 120 virtual bool IsStreaming() const;
94 virtual bool IsLoaded() const; 121 virtual bool IsLoaded() const;
95 virtual PipelineError GetError() const;
96 virtual PipelineStatistics GetStatistics() const; 122 virtual PipelineStatistics GetStatistics() const;
97 123
98 void SetClockForTesting(Clock* clock); 124 void SetClockForTesting(Clock* clock);
99 125
100 private: 126 private:
101 // Pipeline states, as described above. 127 // Pipeline states, as described above.
102 enum State { 128 enum State {
103 kCreated, 129 kCreated,
104 kInitDemuxer, 130 kInitDemuxer,
105 kInitAudioDecoder, 131 kInitAudioDecoder,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void FinishInitialization(); 174 void FinishInitialization();
149 175
150 // Returns true if the given state is one that transitions to a new state 176 // Returns true if the given state is one that transitions to a new state
151 // after iterating through each filter. 177 // after iterating through each filter.
152 static bool TransientState(State state); 178 static bool TransientState(State state);
153 179
154 // Given the current state, returns the next state. 180 // Given the current state, returns the next state.
155 State FindNextState(State current); 181 State FindNextState(State current);
156 182
157 // FilterHost implementation. 183 // FilterHost implementation.
158 virtual void SetError(PipelineError error); 184 virtual void SetError(PipelineStatus error);
159 virtual base::TimeDelta GetTime() const; 185 virtual base::TimeDelta GetTime() const;
160 virtual base::TimeDelta GetDuration() const; 186 virtual base::TimeDelta GetDuration() const;
161 virtual void SetTime(base::TimeDelta time); 187 virtual void SetTime(base::TimeDelta time);
162 virtual void SetDuration(base::TimeDelta duration); 188 virtual void SetDuration(base::TimeDelta duration);
163 virtual void SetBufferedTime(base::TimeDelta buffered_time); 189 virtual void SetBufferedTime(base::TimeDelta buffered_time);
164 virtual void SetTotalBytes(int64 total_bytes); 190 virtual void SetTotalBytes(int64 total_bytes);
165 virtual void SetBufferedBytes(int64 buffered_bytes); 191 virtual void SetBufferedBytes(int64 buffered_bytes);
166 virtual void SetVideoSize(size_t width, size_t height); 192 virtual void SetVideoSize(size_t width, size_t height);
167 virtual void SetStreaming(bool streamed); 193 virtual void SetStreaming(bool streamed);
168 virtual void SetLoaded(bool loaded); 194 virtual void SetLoaded(bool loaded);
(...skipping 14 matching lines...) Expand all
183 void OnTeardownStateTransition(); 209 void OnTeardownStateTransition();
184 210
185 // Callback executed by filters to update statistics. 211 // Callback executed by filters to update statistics.
186 void OnUpdateStatistics(const PipelineStatistics& stats); 212 void OnUpdateStatistics(const PipelineStatistics& stats);
187 213
188 // The following "task" methods correspond to the public methods, but these 214 // The following "task" methods correspond to the public methods, but these
189 // methods are run as the result of posting a task to the PipelineInternal's 215 // methods are run as the result of posting a task to the PipelineInternal's
190 // message loop. 216 // message loop.
191 void StartTask(FilterCollection* filter_collection, 217 void StartTask(FilterCollection* filter_collection,
192 const std::string& url, 218 const std::string& url,
193 PipelineCallback* start_callback); 219 PipelineStatusCallback* start_callback);
194 220
195 // InitializeTask() performs initialization in multiple passes. It is executed 221 // InitializeTask() performs initialization in multiple passes. It is executed
196 // as a result of calling Start() or InitializationComplete() that advances 222 // as a result of calling Start() or InitializationComplete() that advances
197 // initialization to the next state. It works as a hub of state transition for 223 // initialization to the next state. It works as a hub of state transition for
198 // initialization. 224 // initialization.
199 void InitializeTask(); 225 void InitializeTask();
200 226
201 // Stops and destroys all filters, placing the pipeline in the kStopped state. 227 // Stops and destroys all filters, placing the pipeline in the kStopped state.
202 void StopTask(PipelineCallback* stop_callback); 228 void StopTask(PipelineStatusCallback* stop_callback);
203 229
204 // Carries out stopping and destroying all filters, placing the pipeline in 230 // Carries out stopping and destroying all filters, placing the pipeline in
205 // the kError state. 231 // the kError state.
206 void ErrorChangedTask(PipelineError error); 232 void ErrorChangedTask(PipelineStatus error);
207 233
208 // Carries out notifying filters that the playback rate has changed. 234 // Carries out notifying filters that the playback rate has changed.
209 void PlaybackRateChangedTask(float playback_rate); 235 void PlaybackRateChangedTask(float playback_rate);
210 236
211 // Carries out notifying filters that the volume has changed. 237 // Carries out notifying filters that the volume has changed.
212 void VolumeChangedTask(float volume); 238 void VolumeChangedTask(float volume);
213 239
214 // Carries out notifying filters that we are seeking to a new timestamp. 240 // Carries out notifying filters that we are seeking to a new timestamp.
215 void SeekTask(base::TimeDelta time, PipelineCallback* seek_callback); 241 void SeekTask(base::TimeDelta time, PipelineStatusCallback* seek_callback);
216 242
217 // Carries out handling a notification from a filter that it has ended. 243 // Carries out handling a notification from a filter that it has ended.
218 void NotifyEndedTask(); 244 void NotifyEndedTask();
219 245
220 // Carries out handling a notification of network event. 246 // Carries out handling a notification of network event.
221 void NotifyNetworkEventTask(); 247 void NotifyNetworkEventTask();
222 248
223 // Carries out disabling the audio renderer. 249 // Carries out disabling the audio renderer.
224 void DisableAudioRendererTask(); 250 void DisableAudioRendererTask();
225 251
(...skipping 12 matching lines...) Expand all
238 // Internal methods used in the implementation of the pipeline thread. All 264 // Internal methods used in the implementation of the pipeline thread. All
239 // of these methods are only called on the pipeline thread. 265 // of these methods are only called on the pipeline thread.
240 266
241 // PrepareFilter() creates the filter's thread and injects a FilterHost and 267 // PrepareFilter() creates the filter's thread and injects a FilterHost and
242 // MessageLoop. 268 // MessageLoop.
243 bool PrepareFilter(scoped_refptr<Filter> filter); 269 bool PrepareFilter(scoped_refptr<Filter> filter);
244 270
245 // The following initialize methods are used to select a specific type of 271 // The following initialize methods are used to select a specific type of
246 // Filter object from FilterCollection and initialize it asynchronously. 272 // Filter object from FilterCollection and initialize it asynchronously.
247 void InitializeDemuxer(); 273 void InitializeDemuxer();
248 void OnDemuxerBuilt(PipelineError error, Demuxer* demuxer); 274 void OnDemuxerBuilt(PipelineStatus status, Demuxer* demuxer);
249 275
250 // Returns true if the asynchronous action of creating decoder has started. 276 // Returns true if the asynchronous action of creating decoder has started.
251 // Returns false if this method did nothing because the corresponding 277 // Returns false if this method did nothing because the corresponding
252 // audio/video stream does not exist. 278 // audio/video stream does not exist.
253 bool InitializeAudioDecoder(const scoped_refptr<Demuxer>& demuxer); 279 bool InitializeAudioDecoder(const scoped_refptr<Demuxer>& demuxer);
254 bool InitializeVideoDecoder(const scoped_refptr<Demuxer>& demuxer); 280 bool InitializeVideoDecoder(const scoped_refptr<Demuxer>& demuxer);
255 281
256 // Initializes a renderer and connects it with decoder. Returns true if the 282 // Initializes a renderer and connects it with decoder. Returns true if the
257 // asynchronous action of creating renderer has started. Returns 283 // asynchronous action of creating renderer has started. Returns
258 // false if this method did nothing because the corresponding audio/video 284 // false if this method did nothing because the corresponding audio/video
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 370
345 // If this value is set to true, then |clock_| is paused and we are waiting 371 // If this value is set to true, then |clock_| is paused and we are waiting
346 // for an update of the clock greater than or equal to the elapsed time to 372 // for an update of the clock greater than or equal to the elapsed time to
347 // start the clock. 373 // start the clock.
348 bool waiting_for_clock_update_; 374 bool waiting_for_clock_update_;
349 375
350 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that 376 // Status of the pipeline. Initialized to PIPELINE_OK which indicates that
351 // the pipeline is operating correctly. Any other value indicates that the 377 // the pipeline is operating correctly. Any other value indicates that the
352 // pipeline is stopped or is stopping. Clients can call the Stop() method to 378 // pipeline is stopped or is stopping. Clients can call the Stop() method to
353 // reset the pipeline state, and restore this to PIPELINE_OK. 379 // reset the pipeline state, and restore this to PIPELINE_OK.
354 PipelineError error_; 380 PipelineStatus status_;
355 381
356 // Whether the media contains rendered audio and video streams. 382 // Whether the media contains rendered audio and video streams.
357 bool has_audio_; 383 bool has_audio_;
358 bool has_video_; 384 bool has_video_;
359 385
360 // The following data members are only accessed by tasks posted to 386 // The following data members are only accessed by tasks posted to
361 // |message_loop_|. 387 // |message_loop_|.
362 388
363 // Member that tracks the current state. 389 // Member that tracks the current state.
364 State state_; 390 State state_;
(...skipping 14 matching lines...) Expand all
379 // TODO(vrk): This is a hack. 405 // TODO(vrk): This is a hack.
380 base::TimeDelta max_buffered_time_; 406 base::TimeDelta max_buffered_time_;
381 407
382 // Filter collection as passed in by Start(). 408 // Filter collection as passed in by Start().
383 scoped_ptr<FilterCollection> filter_collection_; 409 scoped_ptr<FilterCollection> filter_collection_;
384 410
385 // URL for the data source as passed in by Start(). 411 // URL for the data source as passed in by Start().
386 std::string url_; 412 std::string url_;
387 413
388 // Callbacks for various pipeline operations. 414 // Callbacks for various pipeline operations.
389 scoped_ptr<PipelineCallback> seek_callback_; 415 scoped_ptr<PipelineStatusCallback> seek_callback_;
390 scoped_ptr<PipelineCallback> stop_callback_; 416 scoped_ptr<PipelineStatusCallback> stop_callback_;
391 scoped_ptr<PipelineCallback> ended_callback_; 417 scoped_ptr<PipelineStatusCallback> ended_callback_;
392 scoped_ptr<PipelineCallback> error_callback_; 418 scoped_ptr<PipelineStatusCallback> error_callback_;
393 scoped_ptr<PipelineCallback> network_callback_; 419 scoped_ptr<PipelineStatusCallback> network_callback_;
394 420
395 // Reference to the filter(s) that constitute the pipeline. 421 // Reference to the filter(s) that constitute the pipeline.
396 scoped_refptr<Filter> pipeline_filter_; 422 scoped_refptr<Filter> pipeline_filter_;
397 423
398 // Renderer references used for setting the volume and determining 424 // Renderer references used for setting the volume and determining
399 // when playback has finished. 425 // when playback has finished.
400 scoped_refptr<AudioRenderer> audio_renderer_; 426 scoped_refptr<AudioRenderer> audio_renderer_;
401 scoped_refptr<VideoRenderer> video_renderer_; 427 scoped_refptr<VideoRenderer> video_renderer_;
402 428
403 // Helper class that stores filter references during pipeline 429 // Helper class that stores filter references during pipeline
404 // initialization. 430 // initialization.
405 class PipelineInitState; 431 class PipelineInitState;
406 scoped_ptr<PipelineInitState> pipeline_init_state_; 432 scoped_ptr<PipelineInitState> pipeline_init_state_;
407 433
408 // Statistics. 434 // Statistics.
409 PipelineStatistics statistics_; 435 PipelineStatistics statistics_;
410 436
411 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, GetBufferedTime); 437 FRIEND_TEST_ALL_PREFIXES(PipelineImplTest, GetBufferedTime);
412 438
413 DISALLOW_COPY_AND_ASSIGN(PipelineImpl); 439 DISALLOW_COPY_AND_ASSIGN(PipelineImpl);
414 }; 440 };
415 441
416 } // namespace media 442 } // namespace media
417 443
418 #endif // MEDIA_BASE_PIPELINE_IMPL_H_ 444 #endif // MEDIA_BASE_PIPELINE_IMPL_H_
OLDNEW
« no previous file with comments | « media/base/pipeline.h ('k') | media/base/pipeline_impl.cc » ('j') | media/base/pipeline_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698