1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MEDIA_BASE_VIDEO_RENDERER_H_ 6 #define MEDIA_BASE_VIDEO_RENDERER_H_ 7 8 #include "base/callback.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/time/time.h" 11 #include "media/base/media_export.h" 12 #include "media/base/pipeline_status.h" 13 14 namespace gfx { 15 class Size; 16 } 17 18 namespace media { 19 20 class DemuxerStream; 21 class VideoDecoder; 22 23 class MEDIA_EXPORT VideoRenderer { 24 public: 25 // Used to update the pipeline's clock time. The parameter is the time that 26 // the clock should not exceed. 27 typedef base::Callback<void(base::TimeDelta)> TimeCB; 28 29 // Executed when the natural size of the video has changed. 30 typedef base::Callback<void(const gfx::Size& size)> NaturalSizeChangedCB; 31 32 // Used to query the current time or duration of the media. 33 typedef base::Callback<base::TimeDelta()> TimeDeltaCB; 34 35 VideoRenderer(); 36 virtual ~VideoRenderer(); 37 38 // Initialize a VideoRenderer with |stream|, executing |init_cb| upon 39 // completion. 40 // 41 // |statistics_cb| is executed periodically with video rendering stats, such 42 // as dropped frames. 43 // 44 // |time_cb| is executed whenever time has advanced by way of video rendering. 45 // 46 // |size_changed_cb| is executed whenever the dimensions of the video has 47 // changed. 48 // 49 // |ended_cb| is executed when video rendering has reached the end of stream. 50 // 51 // |error_cb| is executed if an error was encountered. 52 // 53 // |get_time_cb| is used to query the current media playback time. 54 // 55 // |get_duration_cb| is used to query the media duration. 56 virtual void Initialize(DemuxerStream* stream, 57 const PipelineStatusCB& init_cb, 58 const StatisticsCB& statistics_cb, 59 const TimeCB& time_cb, 60 const NaturalSizeChangedCB& size_changed_cb, 61 const base::Closure& ended_cb, 62 const PipelineStatusCB& error_cb, 63 const TimeDeltaCB& get_time_cb, 64 const TimeDeltaCB& get_duration_cb) = 0; 65 66 // Start audio decoding and rendering at the current playback rate, executing 67 // |callback| when playback is underway. 68 virtual void Play(const base::Closure& callback) = 0; 69 70 // Temporarily suspend decoding and rendering video, executing |callback| when 71 // playback has been suspended. 72 virtual void Pause(const base::Closure& callback) = 0; 73 74 // Discard any video data, executing |callback| when completed. 75 virtual void Flush(const base::Closure& callback) = 0; 76 77 // Start prerolling video data. If |time| equals kNoTimestamp() then all 78 // samples delivered to the renderer are used to complete preroll. If |time| 79 // does not equal kNoTimestamp(), then any samples delivered to the renderer 80 // with timestamps less than |time| are silently dropped and not used to 81 // satisfy preroll. |callback| is executed when preroll has completed. 82 // 83 // Only valid to call after a successful Initialize(), Pause(), or Flush(). 84 virtual void Preroll(base::TimeDelta time, 85 const PipelineStatusCB& callback) = 0; 86 87 // Stop all operations in preparation for being deleted, executing |callback| 88 // when complete. 89 virtual void Stop(const base::Closure& callback) = 0; 90 91 // Updates the current playback rate. 92 virtual void SetPlaybackRate(float playback_rate) = 0; 93 94 private: 95 DISALLOW_COPY_AND_ASSIGN(VideoRenderer); 96 }; 97 98 } // namespace media 99 100 #endif // MEDIA_BASE_VIDEO_RENDERER_H_ 101