1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_DECODER_H_
12 #define MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_DECODER_H_
13 
14 #include <memory>
15 
16 #include "absl/types/optional.h"
17 #include "api/video/encoded_image.h"
18 #include "api/video_codecs/video_decoder.h"
19 #include "common_video/include/video_frame_buffer_pool.h"
20 #include "modules/video_coding/codecs/vp8/include/vp8.h"
21 #include "modules/video_coding/include/video_codec_interface.h"
22 #include "vpx/vp8dx.h"
23 #include "vpx/vpx_decoder.h"
24 
25 namespace webrtc {
26 
27 class LibvpxVp8Decoder : public VideoDecoder {
28  public:
29   LibvpxVp8Decoder();
30   ~LibvpxVp8Decoder() override;
31 
32   int InitDecode(const VideoCodec* inst, int number_of_cores) override;
33 
34   int Decode(const EncodedImage& input_image,
35              bool missing_frames,
36              int64_t /*render_time_ms*/) override;
37 
38   int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
39   int Release() override;
40 
41   DecoderInfo GetDecoderInfo() const override;
42   const char* ImplementationName() const override;
43 
44   struct DeblockParams {
45     int max_level = 6;   // Deblocking strength: [0, 16].
46     int degrade_qp = 1;  // If QP value is below, start lowering |max_level|.
47     int min_qp = 0;      // If QP value is below, turn off deblocking.
48   };
49 
50  private:
51   class QpSmoother;
52   int ReturnFrame(const vpx_image_t* img,
53                   uint32_t timeStamp,
54                   int qp,
55                   const webrtc::ColorSpace* explicit_color_space);
56   const bool use_postproc_;
57 
58   VideoFrameBufferPool buffer_pool_;
59   DecodedImageCallback* decode_complete_callback_;
60   bool inited_;
61   vpx_codec_ctx_t* decoder_;
62   int propagation_cnt_;
63   int last_frame_width_;
64   int last_frame_height_;
65   bool key_frame_required_;
66   const absl::optional<DeblockParams> deblock_params_;
67   const std::unique_ptr<QpSmoother> qp_smoother_;
68 
69   // Decoder should produce this format if possible.
70   const VideoFrameBuffer::Type preferred_output_format_;
71 };
72 
73 }  // namespace webrtc
74 
75 #endif  // MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_DECODER_H_
76