| 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/ref_counted.h" | 9 #include "base/memory/ref_counted.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_frame.h" |
| 13 |
| 14 // Include libvpx header files. |
| 15 // VPX_CODEC_DISABLE_COMPAT excludes parts of the libvpx API that provide |
| 16 // backwards compatibility for legacy applications using the library. |
| 17 #define VPX_CODEC_DISABLE_COMPAT 1 |
| 18 extern "C" { |
| 19 #include "third_party/libvpx/source/libvpx/vpx/vpx_decoder.h" |
| 20 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" |
| 21 } |
| 12 | 22 |
| 13 struct vpx_codec_ctx; | 23 struct vpx_codec_ctx; |
| 14 struct vpx_image; | 24 struct vpx_image; |
| 15 | 25 |
| 16 namespace base { | 26 namespace base { |
| 17 class MessageLoopProxy; | 27 class MessageLoopProxy; |
| 18 } | 28 } |
| 19 | 29 |
| 20 namespace media { | 30 namespace media { |
| 21 | 31 |
| 32 struct VpxDeleter { |
| 33 inline void operator()(vpx_codec_ctx* ptr) const { |
| 34 if (ptr) { |
| 35 vpx_codec_destroy(ptr); |
| 36 delete ptr; |
| 37 } |
| 38 } |
| 39 }; |
| 40 |
| 22 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { | 41 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { |
| 23 public: | 42 public: |
| 24 explicit VpxVideoDecoder( | 43 explicit VpxVideoDecoder( |
| 25 const scoped_refptr<base::MessageLoopProxy>& message_loop); | 44 const scoped_refptr<base::MessageLoopProxy>& message_loop); |
| 26 | 45 |
| 27 // VideoDecoder implementation. | 46 // VideoDecoder implementation. |
| 28 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, | 47 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 29 const PipelineStatusCB& status_cb, | 48 const PipelineStatusCB& status_cb, |
| 30 const StatisticsCB& statistics_cb) OVERRIDE; | 49 const StatisticsCB& statistics_cb) OVERRIDE; |
| 31 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 50 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 32 virtual void Reset(const base::Closure& closure) OVERRIDE; | 51 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 33 virtual void Stop(const base::Closure& closure) OVERRIDE; | 52 virtual void Stop(const base::Closure& closure) OVERRIDE; |
| 34 | 53 |
| 35 protected: | 54 protected: |
| 36 virtual ~VpxVideoDecoder(); | 55 virtual ~VpxVideoDecoder(); |
| 37 | 56 |
| 38 private: | 57 private: |
| 39 enum DecoderState { | 58 enum DecoderState { |
| 40 kUninitialized, | 59 kUninitialized, |
| 41 kNormal, | 60 kNormal, |
| 42 kFlushCodec, | 61 kFlushCodec, |
| 43 kDecodeFinished | 62 kDecodeFinished |
| 44 }; | 63 }; |
| 45 | 64 |
| 46 // Handles (re-)initializing the decoder with a (new) config. | 65 // Handles (re-)initializing the decoder with a (new) config. |
| 47 // Returns true when initialization was successful. | 66 // Returns true when initialization was successful. |
| 48 bool ConfigureDecoder(); | 67 bool ConfigureDecoder(); |
| 49 | 68 |
| 50 void CloseDecoder(); | |
| 51 void ReadFromDemuxerStream(); | 69 void ReadFromDemuxerStream(); |
| 52 | 70 |
| 53 // Carries out the buffer processing operation scheduled by | 71 // Carries out the buffer processing operation scheduled by |
| 54 // DecryptOrDecodeBuffer(). | 72 // DecryptOrDecodeBuffer(). |
| 55 void DoDecryptOrDecodeBuffer(DemuxerStream::Status status, | 73 void DoDecryptOrDecodeBuffer(DemuxerStream::Status status, |
| 56 const scoped_refptr<DecoderBuffer>& buffer); | 74 const scoped_refptr<DecoderBuffer>& buffer); |
| 57 | 75 |
| 58 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); | 76 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); |
| 59 bool Decode(const scoped_refptr<DecoderBuffer>& buffer, | 77 bool Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 60 scoped_refptr<VideoFrame>* video_frame); | 78 scoped_refptr<VideoFrame>* video_frame); |
| 61 | 79 |
| 62 // Reset decoder and call |reset_cb_|. | 80 // Reset decoder and call |reset_cb_|. |
| 63 void DoReset(); | 81 void DoReset(); |
| 64 | 82 |
| 65 void CopyVpxImageTo(const vpx_image* vpx_image, | 83 void CopyVpxImageTo(const struct vpx_image* vpx_image, |
| 84 const struct vpx_image* vpx_image_alpha, |
| 66 scoped_refptr<VideoFrame>* video_frame); | 85 scoped_refptr<VideoFrame>* video_frame); |
| 67 | 86 |
| 68 scoped_refptr<base::MessageLoopProxy> message_loop_; | 87 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 69 | 88 |
| 70 DecoderState state_; | 89 DecoderState state_; |
| 71 | 90 |
| 72 StatisticsCB statistics_cb_; | 91 StatisticsCB statistics_cb_; |
| 73 ReadCB read_cb_; | 92 ReadCB read_cb_; |
| 74 base::Closure reset_cb_; | 93 base::Closure reset_cb_; |
| 75 | 94 |
| 76 // Pointer to the demuxer stream that will feed us compressed buffers. | 95 // Pointer to the demuxer stream that will feed us compressed buffers. |
| 77 scoped_refptr<DemuxerStream> demuxer_stream_; | 96 scoped_refptr<DemuxerStream> demuxer_stream_; |
| 78 | 97 |
| 79 vpx_codec_ctx* vpx_codec_; | 98 scoped_ptr<vpx_codec_ctx, VpxDeleter> vpx_codec_; |
| 99 scoped_ptr<vpx_codec_ctx, VpxDeleter> vpx_codec_alpha_; |
| 80 | 100 |
| 81 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); | 101 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); |
| 82 }; | 102 }; |
| 83 | 103 |
| 84 } // namespace media | 104 } // namespace media |
| 85 | 105 |
| 86 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ | 106 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ |
| OLD | NEW |