enum Status {
kOk, // Everything went as planned.
kAborted, // Decode was aborted as a result of Reset() being called.
- kNotEnoughData, // Not enough data to produce a video frame.
kDecodeError, // Decoding error happened.
kDecryptError // Decrypting error happened.
};
+ // Callback for VideoDecoder to return a decoded frame whenever it becomes
+ // available. Only non-EOS frames should be returned via this callback.
+ typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> OutputCB;
+
+ // Callback type for Decode(). Called after the decoder has completed decoding
+ // corresponding DecoderBuffer, indicating that it's ready to accept another
+ // buffer to decode.
+ typedef base::Callback<void(Status status)> DecodeCB;
+
VideoDecoder();
+
+ // Fires any pending callbacks, stops and destroys the decoder.
+ // Note: Since this is a destructor, |this| will be destroyed after this call.
+ // Make sure the callbacks fired from this call doesn't post any task that
+ // depends on |this|.
virtual ~VideoDecoder();
// Initializes a VideoDecoder with the given |config|, executing the
- // |status_cb| upon completion.
+ // |status_cb| upon completion. |output_cb| is called for each output frame
+ // decoded by Decode().
//
// Note:
// 1) The VideoDecoder will be reinitialized if it was initialized before.
// Upon reinitialization, all internal buffered frames will be dropped.
- // 2) This method should not be called during pending decode, reset or stop.
- // 3) No VideoDecoder calls except for Stop() should be made before
- // |status_cb| is executed.
+ // 2) This method should not be called during pending decode or reset.
+ // 3) No VideoDecoder calls should be made before |status_cb| is executed.
virtual void Initialize(const VideoDecoderConfig& config,
- const PipelineStatusCB& status_cb) = 0;
+ bool low_delay,
+ const PipelineStatusCB& status_cb,
+ const OutputCB& output_cb) = 0;
// Requests a |buffer| to be decoded. The status of the decoder and decoded
- // frame are returned via the provided callback. Only one decode may be in
- // flight at any given time.
+ // frame are returned via the provided callback. Some decoders may allow
+ // decoding multiple buffers in parallel. Callers should call
+ // GetMaxDecodeRequests() to get number of buffers that may be decoded in
+ // parallel. Decoder must call |decode_cb| in the same order in which Decode()
+ // is called.
//
// Implementations guarantee that the callback will not be called from within
- // this method.
+ // this method and that |decode_cb| will not be blocked on the following
+ // Decode() calls (i.e. |decode_cb| will be called even Decode() is never
+ // called again).
+ //
+ // After decoding is finished the decoder calls |output_cb| specified in
+ // Initialize() for each decoded frame. |output_cb| may be called before or
+ // after |decode_cb|.
//
- // If the returned status is kOk:
- // - Non-EOS (end of stream) frame contains decoded video data.
- // - EOS frame indicates the end of the stream.
- // Otherwise the returned frame must be NULL.
- typedef base::Callback<void(Status,
- const scoped_refptr<VideoFrame>&)> DecodeCB;
+ // If |buffer| is an EOS buffer then the decoder must be flushed, i.e.
+ // |output_cb| must be called for each frame pending in the queue and
+ // |decode_cb| must be called after that.
virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
const DecodeCB& decode_cb) = 0;
- // Some VideoDecoders may queue up multiple VideoFrames from a single
- // DecoderBuffer, if we have any such queued frames this will return the next
- // one. Otherwise we return a NULL VideoFrame.
- virtual scoped_refptr<VideoFrame> GetDecodeOutput();
-
- // Resets decoder state, fulfilling all pending DecodeCB and dropping extra
- // queued decoded data. After this call, the decoder is back to an initialized
- // clean state.
+ // Resets decoder state. All pending Decode() requests will be finished or
+ // aborted before |closure| is called.
// Note: No VideoDecoder calls should be made before |closure| is executed.
virtual void Reset(const base::Closure& closure) = 0;
- // Stops decoder, fires any pending callbacks and sets the decoder to an
- // uninitialized state. A VideoDecoder cannot be re-initialized after it has
- // been stopped.
- // Note that if Initialize() has been called, Stop() must be called and
- // complete before deleting the decoder.
- virtual void Stop(const base::Closure& closure) = 0;
-
- // Returns true if the output format has an alpha channel. Most formats do not
- // have alpha so the default is false. Override and return true for decoders
- // that return formats with an alpha channel.
- virtual bool HasAlpha() const;
-
// Returns true if the decoder needs bitstream conversion before decoding.
virtual bool NeedsBitstreamConversion() const;
// use a fixed set of VideoFrames for decoding.
virtual bool CanReadWithoutStalling() const;
+ // Returns maximum number of parallel decode requests.
+ virtual int GetMaxDecodeRequests() const;
+
private:
DISALLOW_COPY_AND_ASSIGN(VideoDecoder);
};