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 DemuxerStream; | 16 class DecoderBuffer; |
| 17 class VideoDecoderConfig; |
17 class VideoFrame; | 18 class VideoFrame; |
18 | 19 |
19 class MEDIA_EXPORT VideoDecoder { | 20 class MEDIA_EXPORT VideoDecoder { |
20 public: | 21 public: |
21 // Status codes for read operations on VideoDecoder. | 22 // Status codes for decode operations on VideoDecoder. |
22 enum Status { | 23 enum Status { |
23 kOk, // Everything went as planned. | 24 kOk, // Everything went as planned. |
| 25 kNotEnoughData, // Not enough data to produce a video frame. |
24 kDecodeError, // Decoding error happened. | 26 kDecodeError, // Decoding error happened. |
25 kDecryptError // Decrypting error happened. | 27 kDecryptError // Decrypting error happened. |
26 }; | 28 }; |
27 | 29 |
28 VideoDecoder(); | 30 VideoDecoder(); |
29 virtual ~VideoDecoder(); | 31 virtual ~VideoDecoder(); |
30 | 32 |
31 // Initializes a VideoDecoder with the given DemuxerStream, executing the | 33 // Initializes a VideoDecoder with the given |config|, executing the |
32 // |status_cb| upon completion. | 34 // |status_cb| upon completion. |
33 // |statistics_cb| is used to update the global pipeline statistics. | 35 // |statistics_cb| is used to update the global pipeline statistics. |
34 // | 36 // |
35 // Note: | 37 // Note: |
36 // 1) The VideoDecoder will be reinitialized if it was initialized before. | 38 // 1) The VideoDecoder will be reinitialized if it was initialized before. |
37 // Upon reinitialization, all internal buffered frames will be dropped. | 39 // Upon reinitialization, all internal buffered frames will be dropped. |
38 // 2) This method should not be called during any pending read, reset or stop. | 40 // 2) This method should not be called during pending decode, reset or stop. |
39 // 3) No VideoDecoder calls except for Stop() should be made before | 41 // 3) No VideoDecoder calls except for Stop() should be made before |
40 // |status_cb| is executed. | 42 // |status_cb| is executed. |
41 // 4) DemuxerStream should not be accessed after the VideoDecoder is stopped. | 43 virtual void Initialize(const VideoDecoderConfig& config, |
42 // | |
43 // TODO(xhwang): Make all VideoDecoder implementations reinitializable. | |
44 // See http://crbug.com/233608 | |
45 virtual void Initialize(DemuxerStream* stream, | |
46 const PipelineStatusCB& status_cb, | 44 const PipelineStatusCB& status_cb, |
47 const StatisticsCB& statistics_cb) = 0; | 45 const StatisticsCB& statistics_cb) = 0; |
48 | 46 |
49 // Requests a frame to be decoded. The status of the decoder and decoded frame | 47 // Requests a |buffer| to be decoded. The status of the decoder and decoded |
50 // are returned via the provided callback. Only one read may be in flight at | 48 // frame are returned via the provided callback. Only one decode may be in |
51 // any given time. | 49 // flight at any given time. |
52 // | 50 // |
53 // Implementations guarantee that the callback will not be called from within | 51 // Implementations guarantee that the callback will not be called from within |
54 // this method. | 52 // this method. |
55 // | 53 // |
56 // If the returned status is not kOk, some error has occurred in the video | 54 // If the returned status is kOk: |
57 // decoder. In this case, the returned frame should always be NULL. | 55 // - Non-EOS (end of stream) frame contains decoded video data. |
| 56 // - EOS frame indicates the end of the stream. |
| 57 // - NULL frame indicates an aborted decode. This can happen if Reset() or |
| 58 // Stop() is called during the decoding process. |
| 59 // Otherwise the returned frame must be NULL. |
58 // | 60 // |
59 // Otherwise, the video decoder is in good shape. In this case, Non-NULL | 61 // TODO(xhwang): Rename this to DecodeCB. |
60 // frames contain decoded video data or may indicate the end of the stream. | |
61 // NULL video frames indicate an aborted read. This can happen if the | |
62 // DemuxerStream gets flushed and doesn't have any more data to return. | |
63 typedef base::Callback<void(Status, const scoped_refptr<VideoFrame>&)> ReadCB; | 62 typedef base::Callback<void(Status, const scoped_refptr<VideoFrame>&)> ReadCB; |
64 virtual void Read(const ReadCB& read_cb) = 0; | 63 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 64 const ReadCB& read_cb) = 0; |
65 | 65 |
66 // Resets decoder state, fulfilling all pending ReadCB and dropping extra | 66 // Resets decoder state, fulfilling all pending ReadCB and dropping extra |
67 // queued decoded data. After this call, the decoder is back to an initialized | 67 // queued decoded data. After this call, the decoder is back to an initialized |
68 // clean state. | 68 // clean state. |
69 // Note: No VideoDecoder calls should be made before |closure| is executed. | 69 // Note: No VideoDecoder calls should be made before |closure| is executed. |
70 virtual void Reset(const base::Closure& closure) = 0; | 70 virtual void Reset(const base::Closure& closure) = 0; |
71 | 71 |
72 // Stops decoder, fires any pending callbacks and sets the decoder to an | 72 // Stops decoder, fires any pending callbacks and sets the decoder to an |
73 // uninitialized state. A VideoDecoder cannot be re-initialized after it has | 73 // uninitialized state. A VideoDecoder cannot be re-initialized after it has |
74 // been stopped. | 74 // been stopped. |
(...skipping 15 matching lines...) Expand all Loading... |
90 // use a fixed set of VideoFrames for decoding. | 90 // use a fixed set of VideoFrames for decoding. |
91 virtual bool CanReadWithoutStalling() const; | 91 virtual bool CanReadWithoutStalling() const; |
92 | 92 |
93 private: | 93 private: |
94 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); | 94 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); |
95 }; | 95 }; |
96 | 96 |
97 } // namespace media | 97 } // namespace media |
98 | 98 |
99 #endif // MEDIA_BASE_VIDEO_DECODER_H_ | 99 #endif // MEDIA_BASE_VIDEO_DECODER_H_ |
OLD | NEW |