Home | History | Annotate | Download | only in base
      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 media {
     15 
     16 class DemuxerStream;
     17 class VideoDecoder;
     18 
     19 class MEDIA_EXPORT VideoRenderer {
     20  public:
     21   // Used to update the pipeline's clock time. The parameter is the time that
     22   // the clock should not exceed.
     23   typedef base::Callback<void(base::TimeDelta)> TimeCB;
     24 
     25   // Used to query the current time or duration of the media.
     26   typedef base::Callback<base::TimeDelta()> TimeDeltaCB;
     27 
     28   VideoRenderer();
     29   virtual ~VideoRenderer();
     30 
     31   // Initialize a VideoRenderer with |stream|, executing |init_cb| upon
     32   // completion.
     33   //
     34   // |statistics_cb| is executed periodically with video rendering stats, such
     35   // as dropped frames.
     36   //
     37   // |time_cb| is executed whenever time has advanced by way of video rendering.
     38   //
     39   // |ended_cb| is executed when video rendering has reached the end of stream.
     40   //
     41   // |error_cb| is executed if an error was encountered.
     42   //
     43   // |get_time_cb| is used to query the current media playback time.
     44   //
     45   // |get_duration_cb| is used to query the media duration.
     46   virtual void Initialize(DemuxerStream* stream,
     47                           bool low_delay,
     48                           const PipelineStatusCB& init_cb,
     49                           const StatisticsCB& statistics_cb,
     50                           const TimeCB& time_cb,
     51                           const base::Closure& ended_cb,
     52                           const PipelineStatusCB& error_cb,
     53                           const TimeDeltaCB& get_time_cb,
     54                           const TimeDeltaCB& get_duration_cb) = 0;
     55 
     56   // Start audio decoding and rendering at the current playback rate, executing
     57   // |callback| when playback is underway.
     58   virtual void Play(const base::Closure& callback) = 0;
     59 
     60   // Discard any video data and stop reading from |stream|, executing |callback|
     61   // when completed.
     62   virtual void Flush(const base::Closure& callback) = 0;
     63 
     64   // Start prerolling video data. If |time| equals kNoTimestamp() then all
     65   // samples delivered to the renderer are used to complete preroll. If |time|
     66   // does not equal kNoTimestamp(), then any samples delivered to the renderer
     67   // with timestamps less than |time| are silently dropped and not used to
     68   // satisfy preroll. |callback| is executed when preroll has completed.
     69   //
     70   // Only valid to call after a successful Initialize(), Pause(), or Flush().
     71   virtual void Preroll(base::TimeDelta time,
     72                        const PipelineStatusCB& callback) = 0;
     73 
     74   // Stop all operations in preparation for being deleted, executing |callback|
     75   // when complete.
     76   virtual void Stop(const base::Closure& callback) = 0;
     77 
     78   // Updates the current playback rate.
     79   virtual void SetPlaybackRate(float playback_rate) = 0;
     80 
     81  private:
     82   DISALLOW_COPY_AND_ASSIGN(VideoRenderer);
     83 };
     84 
     85 }  // namespace media
     86 
     87 #endif  // MEDIA_BASE_VIDEO_RENDERER_H_
     88