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_DECODER_H_
6 #define MEDIA_BASE_VIDEO_DECODER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/media_export.h"
11 #include "media/base/pipeline_status.h"
12 #include "ui/gfx/size.h"
17 class VideoDecoderConfig
;
20 class MEDIA_EXPORT VideoDecoder
{
22 // Status codes for decode operations on VideoDecoder.
23 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums
24 // match, break them into a decoder_status.h.
26 kOk
, // Everything went as planned.
27 kAborted
, // Decode was aborted as a result of Reset() being called.
28 kNotEnoughData
, // Not enough data to produce a video frame.
29 kDecodeError
, // Decoding error happened.
30 kDecryptError
// Decrypting error happened.
34 virtual ~VideoDecoder();
36 // Initializes a VideoDecoder with the given |config|, executing the
37 // |status_cb| upon completion.
40 // 1) The VideoDecoder will be reinitialized if it was initialized before.
41 // Upon reinitialization, all internal buffered frames will be dropped.
42 // 2) This method should not be called during pending decode, reset or stop.
43 // 3) No VideoDecoder calls except for Stop() should be made before
44 // |status_cb| is executed.
45 virtual void Initialize(const VideoDecoderConfig
& config
,
47 const PipelineStatusCB
& status_cb
) = 0;
49 // Requests a |buffer| to be decoded. The status of the decoder and decoded
50 // frame are returned via the provided callback. Only one decode may be in
51 // flight at any given time.
53 // Implementations guarantee that the callback will not be called from within
56 // If the returned status is kOk:
57 // - Non-EOS (end of stream) frame contains decoded video data.
58 // - EOS frame indicates the end of the stream.
59 // Otherwise the returned frame must be NULL.
60 typedef base::Callback
<void(Status
,
61 const scoped_refptr
<VideoFrame
>&)> DecodeCB
;
62 virtual void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
63 const DecodeCB
& decode_cb
) = 0;
65 // Some VideoDecoders may queue up multiple VideoFrames from a single
66 // DecoderBuffer, if we have any such queued frames this will return the next
67 // one. Otherwise we return a NULL VideoFrame.
68 virtual scoped_refptr
<VideoFrame
> GetDecodeOutput();
70 // Resets decoder state, fulfilling all pending DecodeCB and dropping extra
71 // queued decoded data. After this call, the decoder is back to an initialized
73 // Note: No VideoDecoder calls should be made before |closure| is executed.
74 virtual void Reset(const base::Closure
& closure
) = 0;
76 // Stops decoder, fires any pending callbacks and sets the decoder to an
77 // uninitialized state. A VideoDecoder cannot be re-initialized after it has
79 // Note that if Initialize() is pending or has finished successfully, Stop()
80 // must be called before destructing the decoder.
81 virtual void Stop() = 0;
83 // Returns true if the decoder needs bitstream conversion before decoding.
84 virtual bool NeedsBitstreamConversion() const;
86 // Returns true if the decoder currently has the ability to decode and return
87 // a VideoFrame. Most implementations can allocate a new VideoFrame and hence
88 // this will always return true. Override and return false for decoders that
89 // use a fixed set of VideoFrames for decoding.
90 virtual bool CanReadWithoutStalling() const;
93 DISALLOW_COPY_AND_ASSIGN(VideoDecoder
);
98 #endif // MEDIA_BASE_VIDEO_DECODER_H_