| 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/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
| 11 #include "media/base/demuxer_stream.h" | 11 #include "media/base/demuxer_stream.h" |
| 12 #include "media/base/video_decoder.h" | 12 #include "media/base/video_decoder.h" |
| 13 #include "media/base/video_decoder_config.h" | 13 #include "media/base/video_decoder_config.h" |
| 14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 15 #include "media/base/video_frame_pool.h" | 15 #include "media/base/video_frame_pool.h" |
| 16 | 16 |
| 17 struct vpx_codec_ctx; | 17 struct vpx_codec_ctx; |
| 18 struct vpx_image; | 18 struct vpx_image; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 class GpuMemoryBufferVideoFramePool; |
| 25 | 26 |
| 26 // Libvpx video decoder wrapper. | 27 // Libvpx video decoder wrapper. |
| 27 // Note: VpxVideoDecoder accepts only YV12A VP8 content or VP9 content. This is | 28 // Note: VpxVideoDecoder accepts only YV12A VP8 content or VP9 content. This is |
| 28 // done to avoid usurping FFmpeg for all VP8 decoding, because the FFmpeg VP8 | 29 // done to avoid usurping FFmpeg for all VP8 decoding, because the FFmpeg VP8 |
| 29 // decoder is faster than the libvpx VP8 decoder. | 30 // decoder is faster than the libvpx VP8 decoder. |
| 30 // Alpha channel, if any, is sent in the DecoderBuffer's side_data() as a frame | 31 // Alpha channel, if any, is sent in the DecoderBuffer's side_data() as a frame |
| 31 // on its own of which the Y channel is taken [1]. | 32 // on its own of which the Y channel is taken [1]. |
| 32 // [1] http://wiki.webmproject.org/alpha-channel | 33 // [1] http://wiki.webmproject.org/alpha-channel |
| 33 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { | 34 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder { |
| 34 public: | 35 public: |
| 35 VpxVideoDecoder(); | 36 VpxVideoDecoder(); |
| 37 explicit VpxVideoDecoder( |
| 38 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool); |
| 36 ~VpxVideoDecoder() override; | 39 ~VpxVideoDecoder() override; |
| 37 | 40 |
| 38 // VideoDecoder implementation. | 41 // VideoDecoder implementation. |
| 39 std::string GetDisplayName() const override; | 42 std::string GetDisplayName() const override; |
| 40 void Initialize(const VideoDecoderConfig& config, | 43 void Initialize(const VideoDecoderConfig& config, |
| 41 bool low_delay, | 44 bool low_delay, |
| 42 CdmContext* cdm_context, | 45 CdmContext* cdm_context, |
| 43 const InitCB& init_cb, | 46 const InitCB& init_cb, |
| 44 const OutputCB& output_cb) override; | 47 const OutputCB& output_cb) override; |
| 45 void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 48 void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, | 70 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, |
| 68 const DecodeCB& bound_decode_cb); | 71 const DecodeCB& bound_decode_cb); |
| 69 | 72 |
| 70 // Try to decode |buffer| into |video_frame|. Return true if all decoding | 73 // Try to decode |buffer| into |video_frame|. Return true if all decoding |
| 71 // succeeded. Note that decoding can succeed and still |video_frame| be | 74 // succeeded. Note that decoding can succeed and still |video_frame| be |
| 72 // nullptr if there has been a partial decoding. | 75 // nullptr if there has been a partial decoding. |
| 73 bool VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, | 76 bool VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
| 74 scoped_refptr<VideoFrame>* video_frame); | 77 scoped_refptr<VideoFrame>* video_frame); |
| 75 | 78 |
| 76 bool CopyVpxImageToVideoFrame(const struct vpx_image* vpx_image, | 79 bool CopyVpxImageToVideoFrame(const struct vpx_image* vpx_image, |
| 80 const scoped_refptr<DecoderBuffer>& buffer, |
| 77 scoped_refptr<VideoFrame>* video_frame); | 81 scoped_refptr<VideoFrame>* video_frame); |
| 78 | 82 |
| 79 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
| 80 | 84 |
| 81 // |state_| must only be read and written to on |offload_task_runner_| if it | 85 // |state_| must only be read and written to on |offload_task_runner_| if it |
| 82 // is non-null and there are outstanding tasks on the offload thread. | 86 // is non-null and there are outstanding tasks on the offload thread. |
| 83 DecoderState state_; | 87 DecoderState state_; |
| 84 | 88 |
| 85 OutputCB output_cb_; | 89 OutputCB output_cb_; |
| 86 | 90 |
| 87 VideoDecoderConfig config_; | 91 VideoDecoderConfig config_; |
| 88 | 92 |
| 89 vpx_codec_ctx* vpx_codec_; | 93 vpx_codec_ctx* vpx_codec_; |
| 90 vpx_codec_ctx* vpx_codec_alpha_; | 94 vpx_codec_ctx* vpx_codec_alpha_; |
| 91 | 95 |
| 92 // |memory_pool_| is a single-threaded memory pool used for VP9 decoding | 96 // |memory_pool_| is a single-threaded memory pool used for VP9 decoding |
| 93 // with no alpha. |frame_pool_| is used for all other cases. | 97 // with no alpha. |frame_pool_| is used for all other cases. |
| 94 class MemoryPool; | 98 class MemoryPool; |
| 95 scoped_refptr<MemoryPool> memory_pool_; | 99 scoped_refptr<MemoryPool> memory_pool_; |
| 96 | 100 |
| 97 // High resolution vp9 may block the media thread for too long, in such cases | 101 // High resolution vp9 may block the media thread for too long, in such cases |
| 98 // we share a per-process thread to avoid overly long blocks. | 102 // we share a per-process thread to avoid overly long blocks. |
| 99 scoped_refptr<base::SingleThreadTaskRunner> offload_task_runner_; | 103 scoped_refptr<base::SingleThreadTaskRunner> offload_task_runner_; |
| 100 | 104 |
| 101 VideoFramePool frame_pool_; | 105 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_video_frame_pool_; |
| 102 | 106 |
| 103 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); | 107 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder); |
| 104 }; | 108 }; |
| 105 | 109 |
| 106 } // namespace media | 110 } // namespace media |
| 107 | 111 |
| 108 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ | 112 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_ |
| OLD | NEW |