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_FILTERS_VPX_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ |
6 #define MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "media/base/demuxer_stream.h" | 10 #include "media/base/demuxer_stream.h" |
11 #include "media/base/video_decoder.h" | 11 #include "media/base/video_decoder.h" |
| 12 #include "media/base/video_decoder_config.h" |
12 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
13 | 14 |
14 struct vpx_codec_ctx; | 15 struct vpx_codec_ctx; |
15 struct vpx_image; | 16 struct vpx_image; |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class MessageLoopProxy; | 19 class MessageLoopProxy; |
19 } | 20 } |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 | 23 |
23 // Libvpx video decoder wrapper. | 24 // Libvpx video decoder wrapper. |
24 // Note: VpxVideoDecoder accepts only YV12A VP8 content or VP9 content. This is | 25 // Note: VpxVideoDecoder accepts only YV12A VP8 content or VP9 content. This is |
25 // done to avoid usurping FFmpeg for all vp8 decoding, because the FFmpeg VP8 | 26 // done to avoid usurping FFmpeg for all vp8 decoding, because the FFmpeg VP8 |
26 // decoder is faster than the libvpx VP8 decoder. | 27 // decoder is faster than the libvpx VP8 decoder. |
27 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { | 28 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { |
28 public: | 29 public: |
29 explicit VpxVideoDecoder( | 30 explicit VpxVideoDecoder( |
30 const scoped_refptr<base::MessageLoopProxy>& message_loop); | 31 const scoped_refptr<base::MessageLoopProxy>& message_loop); |
31 virtual ~VpxVideoDecoder(); | 32 virtual ~VpxVideoDecoder(); |
32 | 33 |
33 // VideoDecoder implementation. | 34 // VideoDecoder implementation. |
34 virtual void Initialize(DemuxerStream* stream, | 35 virtual void Initialize(const VideoDecoderConfig& config, |
35 const PipelineStatusCB& status_cb, | 36 const PipelineStatusCB& status_cb, |
36 const StatisticsCB& statistics_cb) OVERRIDE; | 37 const StatisticsCB& statistics_cb) OVERRIDE; |
37 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 38 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 39 const ReadCB& read_cb) OVERRIDE; |
38 virtual void Reset(const base::Closure& closure) OVERRIDE; | 40 virtual void Reset(const base::Closure& closure) OVERRIDE; |
39 virtual void Stop(const base::Closure& closure) OVERRIDE; | 41 virtual void Stop(const base::Closure& closure) OVERRIDE; |
40 virtual bool HasAlpha() const OVERRIDE; | 42 virtual bool HasAlpha() const OVERRIDE; |
41 | 43 |
42 private: | 44 private: |
43 enum DecoderState { | 45 enum DecoderState { |
44 kUninitialized, | 46 kUninitialized, |
45 kNormal, | 47 kNormal, |
46 kFlushCodec, | 48 kFlushCodec, |
47 kDecodeFinished, | 49 kDecodeFinished, |
48 kError | 50 kError |
49 }; | 51 }; |
50 | 52 |
51 // Handles (re-)initializing the decoder with a (new) config. | 53 // Handles (re-)initializing the decoder with a (new) config. |
52 // Returns true when initialization was successful. | 54 // Returns true when initialization was successful. |
53 bool ConfigureDecoder(); | 55 bool ConfigureDecoder(const VideoDecoderConfig& config); |
54 | 56 |
55 void CloseDecoder(); | 57 void CloseDecoder(); |
56 void ReadFromDemuxerStream(); | |
57 | |
58 // Carries out the buffer processing operation scheduled by | |
59 // DecryptOrDecodeBuffer(). | |
60 void DoDecryptOrDecodeBuffer(DemuxerStream::Status status, | |
61 const scoped_refptr<DecoderBuffer>& buffer); | |
62 | 58 |
63 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); | 59 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); |
64 bool Decode(const scoped_refptr<DecoderBuffer>& buffer, | 60 bool VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
65 scoped_refptr<VideoFrame>* video_frame); | 61 scoped_refptr<VideoFrame>* video_frame); |
66 | 62 |
67 // Reset decoder and call |reset_cb_|. | 63 // Reset decoder and call |reset_cb_|. |
68 void DoReset(); | 64 void DoReset(); |
69 | 65 |
70 void CopyVpxImageTo(const vpx_image* vpx_image, | 66 void CopyVpxImageTo(const vpx_image* vpx_image, |
71 const struct vpx_image* vpx_image_alpha, | 67 const struct vpx_image* vpx_image_alpha, |
72 scoped_refptr<VideoFrame>* video_frame); | 68 scoped_refptr<VideoFrame>* video_frame); |
73 | 69 |
74 scoped_refptr<base::MessageLoopProxy> message_loop_; | 70 scoped_refptr<base::MessageLoopProxy> message_loop_; |
75 base::WeakPtrFactory<VpxVideoDecoder> weak_factory_; | 71 base::WeakPtrFactory<VpxVideoDecoder> weak_factory_; |
76 base::WeakPtr<VpxVideoDecoder> weak_this_; | 72 base::WeakPtr<VpxVideoDecoder> weak_this_; |
77 | 73 |
78 DecoderState state_; | 74 DecoderState state_; |
79 | 75 |
80 StatisticsCB statistics_cb_; | 76 StatisticsCB statistics_cb_; |
81 ReadCB read_cb_; | 77 ReadCB read_cb_; |
82 base::Closure reset_cb_; | 78 base::Closure reset_cb_; |
83 | 79 |
84 // Pointer to the demuxer stream that will feed us compressed buffers. | 80 VideoDecoderConfig config_; |
85 DemuxerStream* demuxer_stream_; | |
86 | 81 |
87 vpx_codec_ctx* vpx_codec_; | 82 vpx_codec_ctx* vpx_codec_; |
88 vpx_codec_ctx* vpx_codec_alpha_; | 83 vpx_codec_ctx* vpx_codec_alpha_; |
89 | 84 |
90 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); | 85 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); |
91 }; | 86 }; |
92 | 87 |
93 } // namespace media | 88 } // namespace media |
94 | 89 |
95 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ | 90 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ |
OLD | NEW |