[Android] Add kkimlabs@ as enhanced bookmark ONWER.
[chromium-blink-merge.git] / media / base / video_decoder.h
blobc49e0dcdbd28b7e4a56b6def8c0eb0edd0cb529e
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 <string>
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"
16 namespace media {
18 class DecoderBuffer;
19 class VideoDecoderConfig;
20 class VideoFrame;
22 class MEDIA_EXPORT VideoDecoder {
23 public:
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.
27 enum Status {
28 kOk, // Everything went as planned.
29 kAborted, // Decode was aborted as a result of Reset() being called.
30 kDecodeError, // Decoding error happened.
31 kDecryptError // Decrypting error happened.
34 // Callback for VideoDecoder to return a decoded frame whenever it becomes
35 // available. Only non-EOS frames should be returned via this callback.
36 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> OutputCB;
38 // Callback type for Decode(). Called after the decoder has completed decoding
39 // corresponding DecoderBuffer, indicating that it's ready to accept another
40 // buffer to decode.
41 typedef base::Callback<void(Status status)> DecodeCB;
43 VideoDecoder();
45 // Fires any pending callbacks, stops and destroys the decoder.
46 // Note: Since this is a destructor, |this| will be destroyed after this call.
47 // Make sure the callbacks fired from this call doesn't post any task that
48 // depends on |this|.
49 virtual ~VideoDecoder();
51 // Returns the name of the decoder for logging purpose.
52 virtual std::string GetDisplayName() const = 0;
54 // Initializes a VideoDecoder with the given |config|, executing the
55 // |status_cb| upon completion. |output_cb| is called for each output frame
56 // decoded by Decode().
58 // If |low_delay| is true then the decoder is not allowed to queue frames,
59 // except for out-of-order frames, i.e. if the next frame can be returned it
60 // must be returned without waiting for Decode() to be called again.
61 // Initialization should fail if |low_delay| is true and the decoder cannot
62 // satisfy the requirements above.
64 // Note:
65 // 1) The VideoDecoder will be reinitialized if it was initialized before.
66 // Upon reinitialization, all internal buffered frames will be dropped.
67 // 2) This method should not be called during pending decode or reset.
68 // 3) No VideoDecoder calls should be made before |status_cb| is executed.
69 virtual void Initialize(const VideoDecoderConfig& config,
70 bool low_delay,
71 const PipelineStatusCB& status_cb,
72 const OutputCB& output_cb) = 0;
74 // Requests a |buffer| to be decoded. The status of the decoder and decoded
75 // frame are returned via the provided callback. Some decoders may allow
76 // decoding multiple buffers in parallel. Callers should call
77 // GetMaxDecodeRequests() to get number of buffers that may be decoded in
78 // parallel. Decoder must call |decode_cb| in the same order in which Decode()
79 // is called.
81 // Implementations guarantee that the callback will not be called from within
82 // this method and that |decode_cb| will not be blocked on the following
83 // Decode() calls (i.e. |decode_cb| will be called even if Decode() is never
84 // called again).
86 // After decoding is finished the decoder calls |output_cb| specified in
87 // Initialize() for each decoded frame. In general |output_cb| may be called
88 // before or after |decode_cb|, but software decoders normally call
89 // |output_cb| before calling |decode_cb|, i.e. while Decode() is pending.
91 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e.
92 // |output_cb| must be called for each frame pending in the queue and
93 // |decode_cb| must be called after that. Callers will not call Decode()
94 // again until after the flush completes.
95 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
96 const DecodeCB& decode_cb) = 0;
98 // Resets decoder state. All pending Decode() requests will be finished or
99 // aborted before |closure| is called.
100 // Note: No VideoDecoder calls should be made before |closure| is executed.
101 virtual void Reset(const base::Closure& closure) = 0;
103 // Returns true if the decoder needs bitstream conversion before decoding.
104 virtual bool NeedsBitstreamConversion() const;
106 // Returns true if the decoder currently has the ability to decode and return
107 // a VideoFrame. Most implementations can allocate a new VideoFrame and hence
108 // this will always return true. Override and return false for decoders that
109 // use a fixed set of VideoFrames for decoding.
110 virtual bool CanReadWithoutStalling() const;
112 // Returns maximum number of parallel decode requests.
113 virtual int GetMaxDecodeRequests() const;
115 private:
116 DISALLOW_COPY_AND_ASSIGN(VideoDecoder);
119 } // namespace media
121 #endif // MEDIA_BASE_VIDEO_DECODER_H_