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.
5 #ifndef MEDIA_BASE_VIDEO_RENDERER_H_
6 #define MEDIA_BASE_VIDEO_RENDERER_H_
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/decryptor.h"
13 #include "media/base/media_export.h"
14 #include "media/base/pipeline_status.h"
22 class MEDIA_EXPORT VideoRenderer
{
24 // Used to paint VideoFrame.
25 typedef base::Callback
<void(const scoped_refptr
<VideoFrame
>&)> PaintCB
;
27 // Used to convert a media timestamp into a wall clock timestamp.
28 typedef base::Callback
<base::TimeTicks(base::TimeDelta
)> WallClockTimeCB
;
32 // Stops all operations and fires all pending callbacks.
33 virtual ~VideoRenderer();
35 // Initializes a VideoRenderer with |stream|, executing |init_cb| upon
36 // completion. If initialization fails, only |init_cb| (not |error_cb|) will
39 // |set_decryptor_ready_cb| is fired when a Decryptor is needed, i.e. when the
40 // |stream| is encrypted.
42 // |statistics_cb| is executed periodically with video rendering stats, such
45 // |buffering_state_cb| is executed when video rendering has either run out of
46 // data or has enough data to continue playback.
48 // |ended_cb| is executed when video rendering has reached the end of stream.
50 // |error_cb| is executed if an error was encountered after initialization.
52 // |wall_clock_time_cb| is used to convert media timestamps into wallclock
55 // |waiting_for_decryption_key_cb| is executed whenever the key needed to
56 // decrypt the stream is not available.
57 virtual void Initialize(
58 DemuxerStream
* stream
,
59 const PipelineStatusCB
& init_cb
,
60 const SetDecryptorReadyCB
& set_decryptor_ready_cb
,
61 const StatisticsCB
& statistics_cb
,
62 const BufferingStateCB
& buffering_state_cb
,
63 const base::Closure
& ended_cb
,
64 const PipelineStatusCB
& error_cb
,
65 const WallClockTimeCB
& wall_clock_time_cb
,
66 const base::Closure
& waiting_for_decryption_key_cb
) = 0;
68 // Discards any video data and stops reading from |stream|, executing
69 // |callback| when completed.
71 // Clients should expect |buffering_state_cb| to be called with
72 // BUFFERING_HAVE_NOTHING while flushing is in progress.
73 virtual void Flush(const base::Closure
& callback
) = 0;
75 // Starts playback at |timestamp| by reading from |stream| and decoding and
78 // Only valid to call after a successful Initialize() or Flush().
79 virtual void StartPlayingFrom(base::TimeDelta timestamp
) = 0;
81 // Called when time starts or stops moving. Time progresses when a base time
82 // has been set and the playback rate is > 0. If either condition changes,
83 // |time_progressing| will be false.
84 virtual void OnTimeStateChanged(bool time_progressing
) = 0;
87 DISALLOW_COPY_AND_ASSIGN(VideoRenderer
);
92 #endif // MEDIA_BASE_VIDEO_RENDERER_H_