xref: /aosp_15_r20/external/webrtc/modules/video_coding/codecs/vp8/libvpx_vp8_decoder.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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   bool Configure(const Settings& settings) override;
33   int Decode(const EncodedImage& input_image,
34              bool missing_frames,
35              int64_t /*render_time_ms*/) override;
36 
37   int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override;
38   int Release() override;
39 
40   DecoderInfo GetDecoderInfo() const override;
41   const char* ImplementationName() const override;
42 
43   struct DeblockParams {
DeblockParamsDeblockParams44     DeblockParams() : max_level(6), degrade_qp(1), min_qp(0) {}
DeblockParamsDeblockParams45     DeblockParams(int max_level, int degrade_qp, int min_qp)
46         : max_level(max_level), degrade_qp(degrade_qp), min_qp(min_qp) {}
47     int max_level;   // Deblocking strength: [0, 16].
48     int degrade_qp;  // If QP value is below, start lowering `max_level`.
49     int min_qp;      // If QP value is below, turn off deblocking.
50   };
51 
52  private:
53   class QpSmoother;
54   int ReturnFrame(const vpx_image_t* img,
55                   uint32_t timeStamp,
56                   int qp,
57                   const webrtc::ColorSpace* explicit_color_space);
58   const bool use_postproc_;
59 
60   VideoFrameBufferPool buffer_pool_;
61   DecodedImageCallback* decode_complete_callback_;
62   bool inited_;
63   vpx_codec_ctx_t* decoder_;
64   int propagation_cnt_;
65   int last_frame_width_;
66   int last_frame_height_;
67   bool key_frame_required_;
68   const absl::optional<DeblockParams> deblock_params_;
69   const std::unique_ptr<QpSmoother> qp_smoother_;
70 };
71 
72 }  // namespace webrtc
73 
74 #endif  // MODULES_VIDEO_CODING_CODECS_VP8_LIBVPX_VP8_DECODER_H_
75