// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_BASE_VIDEO_RENDERER_H_ #define MEDIA_BASE_VIDEO_RENDERER_H_ #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "media/base/buffering_state.h" #include "media/base/decryptor.h" #include "media/base/media_export.h" #include "media/base/pipeline_status.h" namespace media { class DemuxerStream; class VideoDecoder; class VideoFrame; class MEDIA_EXPORT VideoRenderer { public: // Used to paint VideoFrame. typedef base::Callback&)> PaintCB; // Used to query the current time or duration of the media. typedef base::Callback TimeDeltaCB; VideoRenderer(); // Stops all operations and fires all pending callbacks. virtual ~VideoRenderer(); // Initializes a VideoRenderer with |stream|, executing |init_cb| upon // completion. If initialization fails, only |init_cb| (not |error_cb|) will // be called. // // |set_decryptor_ready_cb| is fired when a Decryptor is needed, i.e. when the // |stream| is encrypted. // // |statistics_cb| is executed periodically with video rendering stats, such // as dropped frames. // // |buffering_state_cb| is executed when video rendering has either run out of // data or has enough data to continue playback. // // |paint_cb| is executed on the video frame timing thread whenever a new // frame is available for painting. Can be called from any thread. // // |ended_cb| is executed when video rendering has reached the end of stream. // // |error_cb| is executed if an error was encountered after initialization. // // |get_time_cb| is used to query the current media playback time. // // |waiting_for_decryption_key_cb| is executed whenever the key needed to // decrypt the stream is not available. virtual void Initialize( DemuxerStream* stream, const PipelineStatusCB& init_cb, const SetDecryptorReadyCB& set_decryptor_ready_cb, const StatisticsCB& statistics_cb, const BufferingStateCB& buffering_state_cb, const PaintCB& paint_cb, const base::Closure& ended_cb, const PipelineStatusCB& error_cb, const TimeDeltaCB& get_time_cb, const base::Closure& waiting_for_decryption_key_cb) = 0; // Discards any video data and stops reading from |stream|, executing // |callback| when completed. // // Clients should expect |buffering_state_cb| to be called with // BUFFERING_HAVE_NOTHING while flushing is in progress. virtual void Flush(const base::Closure& callback) = 0; // Starts playback at |timestamp| by reading from |stream| and decoding and // rendering video. // // Only valid to call after a successful Initialize() or Flush(). virtual void StartPlayingFrom(base::TimeDelta timestamp) = 0; private: DISALLOW_COPY_AND_ASSIGN(VideoRenderer); }; } // namespace media #endif // MEDIA_BASE_VIDEO_RENDERER_H_