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/buffering_state.h"
     12 #include "media/base/media_export.h"
     13 #include "media/base/pipeline_status.h"
     14 
     15 namespace media {
     16 
     17 class DemuxerStream;
     18 class VideoDecoder;
     19 
     20 class MEDIA_EXPORT VideoRenderer {
     21  public:
     22   // Used to query the current time or duration of the media.
     23   typedef base::Callback<base::TimeDelta()> TimeDeltaCB;
     24 
     25   VideoRenderer();
     26 
     27   // Stops all operations and fires all pending callbacks.
     28   virtual ~VideoRenderer();
     29 
     30   // Initializes a VideoRenderer with |stream|, executing |init_cb| upon
     31   // completion.
     32   //
     33   // |statistics_cb| is executed periodically with video rendering stats, such
     34   // as dropped frames.
     35   //
     36   // |buffering_state_cb| is executed when video rendering has either run out of
     37   // data or has enough data to continue playback.
     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   virtual void Initialize(DemuxerStream* stream,
     45                           bool low_delay,
     46                           const PipelineStatusCB& init_cb,
     47                           const StatisticsCB& statistics_cb,
     48                           const BufferingStateCB& buffering_state_cb,
     49                           const base::Closure& ended_cb,
     50                           const PipelineStatusCB& error_cb,
     51                           const TimeDeltaCB& get_time_cb) = 0;
     52 
     53   // Discards any video data and stops reading from |stream|, executing
     54   // |callback| when completed.
     55   //
     56   // Clients should expect |buffering_state_cb| to be called with
     57   // BUFFERING_HAVE_NOTHING while flushing is in progress.
     58   virtual void Flush(const base::Closure& callback) = 0;
     59 
     60   // Starts playback at |timestamp| by reading from |stream| and decoding and
     61   // rendering video.
     62   //
     63   // Only valid to call after a successful Initialize() or Flush().
     64   virtual void StartPlayingFrom(base::TimeDelta timestamp) = 0;
     65 
     66  private:
     67   DISALLOW_COPY_AND_ASSIGN(VideoRenderer);
     68 };
     69 
     70 }  // namespace media
     71 
     72 #endif  // MEDIA_BASE_VIDEO_RENDERER_H_
     73