Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_BASE_VIDEO_DECODER_H_ |
| 6 #define MEDIA_BASE_VIDEO_DECODER_H_ | 6 #define MEDIA_BASE_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
| 11 #include "media/base/pipeline_status.h" | 11 #include "media/base/pipeline_status.h" |
| 12 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 class DecoderBuffer; | 16 class DecoderBuffer; |
| 17 class VideoDecoderConfig; | 17 class VideoDecoderConfig; |
| 18 class VideoFrame; | 18 class VideoFrame; |
| 19 | 19 |
| 20 class MEDIA_EXPORT VideoDecoder { | 20 class MEDIA_EXPORT VideoDecoder { |
| 21 public: | 21 public: |
| 22 // Status codes for decode operations on VideoDecoder. | 22 // Status codes for decode operations on VideoDecoder. |
| 23 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums | 23 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums |
| 24 // match, break them into a decoder_status.h. | 24 // match, break them into a decoder_status.h. |
| 25 enum Status { | 25 enum Status { |
| 26 kOk, // Everything went as planned. | 26 kOk, // Everything went as planned. |
| 27 kAborted, // Decode was aborted as a result of Reset() being called. | 27 kAborted, // Decode was aborted as a result of Reset() being called. |
| 28 kNotEnoughData, // Not enough data to produce a video frame. | |
| 29 kDecodeError, // Decoding error happened. | 28 kDecodeError, // Decoding error happened. |
| 30 kDecryptError // Decrypting error happened. | 29 kDecryptError // Decrypting error happened. |
| 31 }; | 30 }; |
| 32 | 31 |
| 32 // Callback to return decode frames. | |
| 33 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> OutputCB; | |
| 34 | |
| 35 // Callback type for Decode(). | |
| 36 typedef base::Callback<void(Status status)> DecodeCB; | |
| 37 | |
| 33 VideoDecoder(); | 38 VideoDecoder(); |
| 34 virtual ~VideoDecoder(); | 39 virtual ~VideoDecoder(); |
| 35 | 40 |
| 36 // Initializes a VideoDecoder with the given |config|, executing the | 41 // Initializes a VideoDecoder with the given |config|, executing the |
| 37 // |status_cb| upon completion. | 42 // |status_cb| upon completion. |
| 38 // | 43 // |
| 39 // Note: | 44 // Note: |
| 40 // 1) The VideoDecoder will be reinitialized if it was initialized before. | 45 // 1) The VideoDecoder will be reinitialized if it was initialized before. |
| 41 // Upon reinitialization, all internal buffered frames will be dropped. | 46 // Upon reinitialization, all internal buffered frames will be dropped. |
| 42 // 2) This method should not be called during pending decode, reset or stop. | 47 // 2) This method should not be called during pending decode, reset or stop. |
| 43 // 3) No VideoDecoder calls except for Stop() should be made before | 48 // 3) No VideoDecoder calls except for Stop() should be made before |
| 44 // |status_cb| is executed. | 49 // |status_cb| is executed. |
| 45 virtual void Initialize(const VideoDecoderConfig& config, | 50 virtual void Initialize(const VideoDecoderConfig& config, |
| 46 bool low_delay, | 51 bool low_delay, |
| 47 const PipelineStatusCB& status_cb) = 0; | 52 const PipelineStatusCB& status_cb, |
| 53 const OutputCB& output_cb) = 0; | |
| 48 | 54 |
| 49 // Requests a |buffer| to be decoded. The status of the decoder and decoded | 55 // Requests a |buffer| to be decoded. The status of the decoder and decoded |
| 50 // frame are returned via the provided callback. Some decoders may allow | 56 // frame are returned via the provided callback. Some decoders may allow |
| 51 // decoding multiple buffers in parallel. Callers should call | 57 // decoding multiple buffers in parallel. Callers should call |
| 52 // GetMaxDecodeRequests() to get number of buffers that may be decoded in | 58 // GetMaxDecodeRequests() to get number of buffers that may be decoded in |
| 53 // parallel. Decoder must call |decode_cb| in the same order in which Decode() | 59 // parallel. Decoder must call |decode_cb| in the same order in which Decode() |
| 54 // is called. | 60 // is called. |
| 55 // | 61 // |
| 56 // Implementations guarantee that the callback will not be called from within | 62 // Implementations guarantee that the callback will not be called from within |
| 57 // this method and that |decode_cb| will not be blocked on the following | 63 // this method and that |decode_cb| will not be blocked on the following |
| 58 // Decode() calls (i.e. |decode_cb| will be called even Decode() is never | 64 // Decode() calls (i.e. |decode_cb| will be called even Decode() is never |
| 59 // called again). | 65 // called again). |
| 60 // | 66 // |
| 61 // If the returned status is kOk: | 67 // If the returned status is kOk: |
| 62 // - Non-EOS (end of stream) frame contains decoded video data. | 68 // - Non-EOS (end of stream) frame contains decoded video data. |
| 63 // - EOS frame indicates the end of the stream. | 69 // - EOS frame indicates the end of the stream. |
| 64 // Otherwise the returned frame must be NULL. | 70 // Otherwise the returned frame must be NULL. |
|
xhwang
2014/05/29 22:15:14
This whole comment block needs to be updated.
Sergey Ulanov
2014/06/03 00:08:11
Done.
| |
| 65 typedef base::Callback<void(Status, | |
| 66 const scoped_refptr<VideoFrame>&)> DecodeCB; | |
| 67 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 71 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 68 const DecodeCB& decode_cb) = 0; | 72 const DecodeCB& decode_cb) = 0; |
| 69 | 73 |
| 70 // Some VideoDecoders may queue up multiple VideoFrames from a single | |
| 71 // DecoderBuffer, if we have any such queued frames this will return the next | |
| 72 // one. Otherwise we return a NULL VideoFrame. | |
| 73 // | |
| 74 // TODO(xhwang): Revisit this method. | |
| 75 virtual scoped_refptr<VideoFrame> GetDecodeOutput(); | |
| 76 | |
| 77 // Resets decoder state, fulfilling all pending DecodeCB and dropping extra | 74 // Resets decoder state, fulfilling all pending DecodeCB and dropping extra |
| 78 // queued decoded data. After this call, the decoder is back to an initialized | 75 // queued decoded data. After this call, the decoder is back to an initialized |
| 79 // clean state. | 76 // clean state. |
| 80 // Note: No VideoDecoder calls should be made before |closure| is executed. | 77 // Note: No VideoDecoder calls should be made before |closure| is executed. |
| 81 virtual void Reset(const base::Closure& closure) = 0; | 78 virtual void Reset(const base::Closure& closure) = 0; |
| 82 | 79 |
| 83 // Stops decoder, fires any pending callbacks and sets the decoder to an | 80 // Stops decoder, fires any pending callbacks and sets the decoder to an |
| 84 // uninitialized state. A VideoDecoder cannot be re-initialized after it has | 81 // uninitialized state. A VideoDecoder cannot be re-initialized after it has |
| 85 // been stopped. | 82 // been stopped. |
| 86 // Note that if Initialize() is pending or has finished successfully, Stop() | 83 // Note that if Initialize() is pending or has finished successfully, Stop() |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 99 // Returns maximum number of parallel decode requests. | 96 // Returns maximum number of parallel decode requests. |
| 100 virtual int GetMaxDecodeRequests() const; | 97 virtual int GetMaxDecodeRequests() const; |
| 101 | 98 |
| 102 private: | 99 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); | 100 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 } // namespace media | 103 } // namespace media |
| 107 | 104 |
| 108 #endif // MEDIA_BASE_VIDEO_DECODER_H_ | 105 #endif // MEDIA_BASE_VIDEO_DECODER_H_ |
| OLD | NEW |