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.
24 kOk
, // Everything went as planned.
25 kNotEnoughData
, // Not enough data to produce a video frame.
26 kDecodeError
, // Decoding error happened.
27 kDecryptError
// Decrypting error happened.
31 virtual ~VideoDecoder();
33 // Initializes a VideoDecoder with the given |config|, executing the
34 // |status_cb| upon completion.
37 // 1) The VideoDecoder will be reinitialized if it was initialized before.
38 // Upon reinitialization, all internal buffered frames will be dropped.
39 // 2) This method should not be called during pending decode, reset or stop.
40 // 3) No VideoDecoder calls except for Stop() should be made before
41 // |status_cb| is executed.
42 virtual void Initialize(const VideoDecoderConfig
& config
,
43 const PipelineStatusCB
& status_cb
) = 0;
45 // Requests a |buffer| to be decoded. The status of the decoder and decoded
46 // frame are returned via the provided callback. Only one decode may be in
47 // flight at any given time.
49 // Implementations guarantee that the callback will not be called from within
52 // If the returned status is kOk:
53 // - Non-EOS (end of stream) frame contains decoded video data.
54 // - EOS frame indicates the end of the stream.
55 // - NULL frame indicates an aborted decode. This can happen if Reset() or
56 // Stop() is called during the decoding process.
57 // Otherwise the returned frame must be NULL.
58 typedef base::Callback
<void(Status
,
59 const scoped_refptr
<VideoFrame
>&)> DecodeCB
;
60 virtual void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
61 const DecodeCB
& decode_cb
) = 0;
63 // Resets decoder state, fulfilling all pending DecodeCB and dropping extra
64 // queued decoded data. After this call, the decoder is back to an initialized
66 // Note: No VideoDecoder calls should be made before |closure| is executed.
67 virtual void Reset(const base::Closure
& closure
) = 0;
69 // Stops decoder, fires any pending callbacks and sets the decoder to an
70 // uninitialized state. A VideoDecoder cannot be re-initialized after it has
72 // Note that if Initialize() has been called, Stop() must be called and
73 // complete before deleting the decoder.
74 virtual void Stop(const base::Closure
& closure
) = 0;
76 // Returns true if the output format has an alpha channel. Most formats do not
77 // have alpha so the default is false. Override and return true for decoders
78 // that return formats with an alpha channel.
79 virtual bool HasAlpha() const;
81 // Returns true if the decoder needs bitstream conversion before decoding.
82 virtual bool NeedsBitstreamConversion() const;
84 // Returns true if the decoder currently has the ability to decode and return
85 // a VideoFrame. Most implementations can allocate a new VideoFrame and hence
86 // this will always return true. Override and return false for decoders that
87 // use a fixed set of VideoFrames for decoding.
88 virtual bool CanReadWithoutStalling() const;
91 DISALLOW_COPY_AND_ASSIGN(VideoDecoder
);
96 #endif // MEDIA_BASE_VIDEO_DECODER_H_