[MD settings] moving attached() code
[chromium-blink-merge.git] / media / filters / vpx_video_decoder.h
blobbbf98950c0ac06393a244a5513caf8a49cc411b3
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_VPX_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_VPX_VIDEO_DECODER_H_
8 #include "base/callback.h"
9 #include "media/base/demuxer_stream.h"
10 #include "media/base/video_decoder.h"
11 #include "media/base/video_decoder_config.h"
12 #include "media/base/video_frame.h"
13 #include "media/base/video_frame_pool.h"
15 struct vpx_codec_ctx;
16 struct vpx_image;
18 namespace base {
19 class SingleThreadTaskRunner;
22 namespace media {
24 // Libvpx video decoder wrapper.
25 // Note: VpxVideoDecoder accepts only YV12A VP8 content or VP9 content. This is
26 // done to avoid usurping FFmpeg for all vp8 decoding, because the FFmpeg VP8
27 // decoder is faster than the libvpx VP8 decoder.
28 class MEDIA_EXPORT VpxVideoDecoder : public VideoDecoder {
29 public:
30 explicit VpxVideoDecoder(
31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
32 ~VpxVideoDecoder() override;
34 // VideoDecoder implementation.
35 std::string GetDisplayName() const override;
36 void Initialize(const VideoDecoderConfig& config,
37 bool low_delay,
38 const InitCB& init_cb,
39 const OutputCB& output_cb) override;
40 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
41 const DecodeCB& decode_cb) override;
42 void Reset(const base::Closure& closure) override;
44 private:
45 enum DecoderState {
46 kUninitialized,
47 kNormal,
48 kFlushCodec,
49 kDecodeFinished,
50 kError
53 // Handles (re-)initializing the decoder with a (new) config.
54 // Returns true when initialization was successful.
55 bool ConfigureDecoder(const VideoDecoderConfig& config);
57 void CloseDecoder();
59 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer);
60 bool VpxDecode(const scoped_refptr<DecoderBuffer>& buffer,
61 scoped_refptr<VideoFrame>* video_frame);
63 void CopyVpxImageTo(const vpx_image* vpx_image,
64 const struct vpx_image* vpx_image_alpha,
65 scoped_refptr<VideoFrame>* video_frame);
67 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
69 DecoderState state_;
71 OutputCB output_cb_;
73 // TODO(xhwang): Merge DecodeBuffer() into Decode() and remove this.
74 DecodeCB decode_cb_;
76 VideoDecoderConfig config_;
78 vpx_codec_ctx* vpx_codec_;
79 vpx_codec_ctx* vpx_codec_alpha_;
81 // Memory pool used for VP9 decoding.
82 class MemoryPool;
83 scoped_refptr<MemoryPool> memory_pool_;
85 VideoFramePool frame_pool_;
87 DISALLOW_COPY_AND_ASSIGN(VpxVideoDecoder);
90 } // namespace media
92 #endif // MEDIA_FILTERS_VPX_VIDEO_DECODER_H_