This is jamesr@ code I am landing.
[chromium-blink-merge.git] / media / base / video_decoder.h
blobedca238e784a03c04233db1e0f66c89a0d445b16
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"
14 namespace media {
16 class DecoderBuffer;
17 class VideoDecoderConfig;
18 class VideoFrame;
20 class MEDIA_EXPORT VideoDecoder {
21 public:
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.
25 enum Status {
26 kOk, // Everything went as planned.
27 kAborted, // Decode was aborted as a result of Reset() being called.
28 kDecodeError, // Decoding error happened.
29 kDecryptError // Decrypting error happened.
32 // Callback for VideoDecoder to return a decoded frame whenever it becomes
33 // available. Only non-EOS frames should be returned via this callback.
34 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> OutputCB;
36 // Callback type for Decode(). Called after the decoder has completed decoding
37 // corresponding DecoderBuffer, indicating that it's ready to accept another
38 // buffer to decode.
39 typedef base::Callback<void(Status status)> DecodeCB;
41 VideoDecoder();
43 // Fires any pending callbacks, stops and destroys the decoder.
44 // Note: Since this is a destructor, |this| will be destroyed after this call.
45 // Make sure the callbacks fired from this call doesn't post any task that
46 // depends on |this|.
47 virtual ~VideoDecoder();
49 // Initializes a VideoDecoder with the given |config|, executing the
50 // |status_cb| upon completion. |output_cb| is called for each output frame
51 // decoded by Decode().
53 // Note:
54 // 1) The VideoDecoder will be reinitialized if it was initialized before.
55 // Upon reinitialization, all internal buffered frames will be dropped.
56 // 2) This method should not be called during pending decode or reset.
57 // 3) No VideoDecoder calls should be made before |status_cb| is executed.
58 virtual void Initialize(const VideoDecoderConfig& config,
59 bool low_delay,
60 const PipelineStatusCB& status_cb,
61 const OutputCB& output_cb) = 0;
63 // Requests a |buffer| to be decoded. The status of the decoder and decoded
64 // frame are returned via the provided callback. Some decoders may allow
65 // decoding multiple buffers in parallel. Callers should call
66 // GetMaxDecodeRequests() to get number of buffers that may be decoded in
67 // parallel. Decoder must call |decode_cb| in the same order in which Decode()
68 // is called.
70 // Implementations guarantee that the callback will not be called from within
71 // this method and that |decode_cb| will not be blocked on the following
72 // Decode() calls (i.e. |decode_cb| will be called even Decode() is never
73 // called again).
75 // After decoding is finished the decoder calls |output_cb| specified in
76 // Initialize() for each decoded frame. |output_cb| may be called before or
77 // after |decode_cb|.
79 // If |buffer| is an EOS buffer then the decoder must be flushed, i.e.
80 // |output_cb| must be called for each frame pending in the queue and
81 // |decode_cb| must be called after that.
82 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
83 const DecodeCB& decode_cb) = 0;
85 // Resets decoder state. All pending Decode() requests will be finished or
86 // aborted before |closure| is called.
87 // Note: No VideoDecoder calls should be made before |closure| is executed.
88 virtual void Reset(const base::Closure& closure) = 0;
90 // Returns true if the decoder needs bitstream conversion before decoding.
91 virtual bool NeedsBitstreamConversion() const;
93 // Returns true if the decoder currently has the ability to decode and return
94 // a VideoFrame. Most implementations can allocate a new VideoFrame and hence
95 // this will always return true. Override and return false for decoders that
96 // use a fixed set of VideoFrames for decoding.
97 virtual bool CanReadWithoutStalling() const;
99 // Returns maximum number of parallel decode requests.
100 virtual int GetMaxDecodeRequests() const;
102 private:
103 DISALLOW_COPY_AND_ASSIGN(VideoDecoder);
106 } // namespace media
108 #endif // MEDIA_BASE_VIDEO_DECODER_H_