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 int32_t InitDecode(const VideoCodec* codec_settings, 35 int32_t number_of_cores) override; 36 int32_t Decode(const EncodedImage& input_image, 37 bool missing_frames, 38 int64_t render_time_ms) override; 39 int32_t RegisterDecodeCompleteCallback( 40 DecodedImageCallback* callback) override; 41 int32_t Release() override; 42 43 void Decoded(AlphaCodecStream stream_idx, 44 VideoFrame* decoded_image, 45 absl::optional<int32_t> decode_time_ms, 46 absl::optional<uint8_t> qp); 47 48 private: 49 // Wrapper class that redirects Decoded() calls. 50 class AdapterDecodedImageCallback; 51 52 // Holds the decoded image output of a frame. 53 struct DecodedImageData; 54 55 // Holds the augmenting data of an image 56 struct AugmentingData; 57 58 void MergeAlphaImages(VideoFrame* decoded_image, 59 const absl::optional<int32_t>& decode_time_ms, 60 const absl::optional<uint8_t>& qp, 61 VideoFrame* multiplex_decoded_image, 62 const absl::optional<int32_t>& multiplex_decode_time_ms, 63 const absl::optional<uint8_t>& multiplex_qp, 64 std::unique_ptr<uint8_t[]> augmenting_data, 65 uint16_t augmenting_data_length); 66 67 VideoDecoderFactory* const factory_; 68 const SdpVideoFormat associated_format_; 69 std::vector<std::unique_ptr<VideoDecoder>> decoders_; 70 std::vector<std::unique_ptr<AdapterDecodedImageCallback>> adapter_callbacks_; 71 DecodedImageCallback* decoded_complete_callback_; 72 73 // Holds YUV or AXX decode output of a frame that is identified by timestamp. 74 std::map<uint32_t /* timestamp */, DecodedImageData> decoded_data_; 75 std::map<uint32_t /* timestamp */, AugmentingData> decoded_augmenting_data_; 76 const bool supports_augmenting_data_; 77 }; 78 79 } // namespace webrtc 80 81 #endif // MODULES_VIDEO_CODING_CODECS_MULTIPLEX_INCLUDE_MULTIPLEX_DECODER_ADAPTER_H_ 82