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_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "media/base/media_export.h"
13 #include "media/base/pipeline_status.h"
14 #include "ui/gfx/geometry/size.h"
19 class VideoDecoderConfig
;
22 class MEDIA_EXPORT VideoDecoder
{
24 // Status codes for decode operations on VideoDecoder.
25 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums
26 // match, break them into a decoder_status.h.
28 kOk
, // Everything went as planned.
29 kAborted
, // Decode was aborted as a result of Reset() being called.
30 kDecodeError
// Decoding error happened.
33 // Callback for VideoDecoder initialization.
34 typedef base::Callback
<void(bool success
)> InitCB
;
36 // Callback for VideoDecoder to return a decoded frame whenever it becomes
37 // available. Only non-EOS frames should be returned via this callback.
38 typedef base::Callback
<void(const scoped_refptr
<VideoFrame
>&)> OutputCB
;
40 // Callback type for Decode(). Called after the decoder has completed decoding
41 // corresponding DecoderBuffer, indicating that it's ready to accept another
43 typedef base::Callback
<void(Status status
)> DecodeCB
;
47 // Fires any pending callbacks, stops and destroys the decoder.
48 // Note: Since this is a destructor, |this| will be destroyed after this call.
49 // Make sure the callbacks fired from this call doesn't post any task that
51 virtual ~VideoDecoder();
53 // Returns the name of the decoder for logging purpose.
54 virtual std::string
GetDisplayName() const = 0;
56 // Initializes a VideoDecoder with the given |config|, executing the
57 // |init_cb| upon completion. |output_cb| is called for each output frame
58 // decoded by Decode().
60 // If |low_delay| is true then the decoder is not allowed to queue frames,
61 // except for out-of-order frames, i.e. if the next frame can be returned it
62 // must be returned without waiting for Decode() to be called again.
63 // Initialization should fail if |low_delay| is true and the decoder cannot
64 // satisfy the requirements above.
67 // 1) The VideoDecoder will be reinitialized if it was initialized before.
68 // Upon reinitialization, all internal buffered frames will be dropped.
69 // 2) This method should not be called during pending decode or reset.
70 // 3) No VideoDecoder calls should be made before |init_cb| is executed.
71 virtual void Initialize(const VideoDecoderConfig
& config
,
73 const InitCB
& init_cb
,
74 const OutputCB
& output_cb
) = 0;
76 // Requests a |buffer| to be decoded. The status of the decoder and decoded
77 // frame are returned via the provided callback. Some decoders may allow
78 // decoding multiple buffers in parallel. Callers should call
79 // GetMaxDecodeRequests() to get number of buffers that may be decoded in
80 // parallel. Decoder must call |decode_cb| in the same order in which Decode()
83 // Implementations guarantee that the callback will not be called from within
84 // this method and that |decode_cb| will not be blocked on the following
85 // Decode() calls (i.e. |decode_cb| will be called even if Decode() is never
88 // After decoding is finished the decoder calls |output_cb| specified in
89 // Initialize() for each decoded frame. In general |output_cb| may be called
90 // before or after |decode_cb|, but software decoders normally call
91 // |output_cb| before calling |decode_cb|, i.e. while Decode() is pending.
93 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e.
94 // |output_cb| must be called for each frame pending in the queue and
95 // |decode_cb| must be called after that. Callers will not call Decode()
96 // again until after the flush completes.
97 virtual void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
98 const DecodeCB
& decode_cb
) = 0;
100 // Resets decoder state. All pending Decode() requests will be finished or
101 // aborted before |closure| is called.
102 // Note: No VideoDecoder calls should be made before |closure| is executed.
103 virtual void Reset(const base::Closure
& closure
) = 0;
105 // Returns true if the decoder needs bitstream conversion before decoding.
106 virtual bool NeedsBitstreamConversion() const;
108 // Returns true if the decoder currently has the ability to decode and return
109 // a VideoFrame. Most implementations can allocate a new VideoFrame and hence
110 // this will always return true. Override and return false for decoders that
111 // use a fixed set of VideoFrames for decoding.
112 virtual bool CanReadWithoutStalling() const;
114 // Returns maximum number of parallel decode requests.
115 virtual int GetMaxDecodeRequests() const;
118 DISALLOW_COPY_AND_ASSIGN(VideoDecoder
);
123 #endif // MEDIA_BASE_VIDEO_DECODER_H_