xref: /aosp_15_r20/external/webrtc/modules/video_coding/codecs/multiplex/include/multiplex_decoder_adapter.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2017 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_MULTIPLEX_INCLUDE_MULTIPLEX_DECODER_ADAPTER_H_
12 #define MODULES_VIDEO_CODING_CODECS_MULTIPLEX_INCLUDE_MULTIPLEX_DECODER_ADAPTER_H_
13 
14 #include <map>
15 #include <memory>
16 #include <vector>
17 
18 #include "api/video_codecs/sdp_video_format.h"
19 #include "api/video_codecs/video_decoder.h"
20 #include "api/video_codecs/video_decoder_factory.h"
21 #include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h"
22 
23 namespace webrtc {
24 
25 class MultiplexDecoderAdapter : public VideoDecoder {
26  public:
27   // `factory` is not owned and expected to outlive this class.
28   MultiplexDecoderAdapter(VideoDecoderFactory* factory,
29                           const SdpVideoFormat& associated_format,
30                           bool supports_augmenting_data = false);
31   virtual ~MultiplexDecoderAdapter();
32 
33   // Implements VideoDecoder
34   bool Configure(const Settings& settings) override;
35   int32_t Decode(const EncodedImage& input_image,
36                  bool missing_frames,
37                  int64_t render_time_ms) override;
38   int32_t RegisterDecodeCompleteCallback(
39       DecodedImageCallback* callback) override;
40   int32_t Release() override;
41 
42   void Decoded(AlphaCodecStream stream_idx,
43                VideoFrame* decoded_image,
44                absl::optional<int32_t> decode_time_ms,
45                absl::optional<uint8_t> qp);
46 
47  private:
48   // Wrapper class that redirects Decoded() calls.
49   class AdapterDecodedImageCallback;
50 
51   // Holds the decoded image output of a frame.
52   struct DecodedImageData;
53 
54   // Holds the augmenting data of an image
55   struct AugmentingData;
56 
57   void MergeAlphaImages(VideoFrame* decoded_image,
58                         const absl::optional<int32_t>& decode_time_ms,
59                         const absl::optional<uint8_t>& qp,
60                         VideoFrame* multiplex_decoded_image,
61                         const absl::optional<int32_t>& multiplex_decode_time_ms,
62                         const absl::optional<uint8_t>& multiplex_qp,
63                         std::unique_ptr<uint8_t[]> augmenting_data,
64                         uint16_t augmenting_data_length);
65 
66   VideoDecoderFactory* const factory_;
67   const SdpVideoFormat associated_format_;
68   std::vector<std::unique_ptr<VideoDecoder>> decoders_;
69   std::vector<std::unique_ptr<AdapterDecodedImageCallback>> adapter_callbacks_;
70   DecodedImageCallback* decoded_complete_callback_;
71 
72   // Holds YUV or AXX decode output of a frame that is identified by timestamp.
73   std::map<uint32_t /* timestamp */, DecodedImageData> decoded_data_;
74   std::map<uint32_t /* timestamp */, AugmentingData> decoded_augmenting_data_;
75   const bool supports_augmenting_data_;
76 };
77 
78 }  // namespace webrtc
79 
80 #endif  // MODULES_VIDEO_CODING_CODECS_MULTIPLEX_INCLUDE_MULTIPLEX_DECODER_ADAPTER_H_
81