diff --git a/requirements-dev.lock b/requirements-dev.lock index c487c899..c711ac77 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -9,7 +9,6 @@ -e file:. auditwheel==5.4.0 build==0.10.0 -colorama==0.4.6 exceptiongroup==1.1.1 iniconfig==2.0.0 nanobind==1.4.0 diff --git a/src/dynamic_h264_decoder.cpp b/src/dynamic_h264_decoder.cpp index d50f3f68..e528950c 100644 --- a/src/dynamic_h264_decoder.cpp +++ b/src/dynamic_h264_decoder.cpp @@ -4,6 +4,7 @@ // WebRTC #include +#include #include // OpenH264 @@ -22,17 +23,20 @@ bool DynamicH264Decoder::Configure(const Settings& settings) { void* handle = ::dlopen(openh264_.c_str(), RTLD_LAZY); if (handle == nullptr) { + RTC_LOG(LS_ERROR) << "Failed to dlopen"; return false; } openh264_handle_ = handle; - create_decoder_ = (CreateDecoderFunc)::dlsym(handle, "WelsCreateSVCDecoder"); + create_decoder_ = (CreateDecoderFunc)::dlsym(handle, "WelsCreateDecoder"); if (create_decoder_ == nullptr) { + RTC_LOG(LS_ERROR) << "Failed to dlsym(WelsCreateDecoder)"; Release(); return false; } destroy_decoder_ = - (DestroyDecoderFunc)::dlsym(handle, "WelsDestroySVCDecoder"); + (DestroyDecoderFunc)::dlsym(handle, "WelsDestroyDecoder"); if (destroy_decoder_ == nullptr) { + RTC_LOG(LS_ERROR) << "Failed to dlsym(WelsDestroyDecoder)"; Release(); return false; } @@ -40,6 +44,7 @@ bool DynamicH264Decoder::Configure(const Settings& settings) { ISVCDecoder* decoder = nullptr; int r = create_decoder_(&decoder); if (r != 0) { + RTC_LOG(LS_ERROR) << "Failed to WelsCreateDecoder: r=" << r; Release(); return false; } @@ -47,6 +52,7 @@ bool DynamicH264Decoder::Configure(const Settings& settings) { SDecodingParam param = {}; r = decoder->Initialize(¶m); if (r != 0) { + RTC_LOG(LS_ERROR) << "Failed to ISVCDecoder::Initialize: r=" << r; Release(); return false; } @@ -82,11 +88,15 @@ int32_t DynamicH264Decoder::Decode(const EncodedImage& input_image, return WEBRTC_VIDEO_CODEC_UNINITIALIZED; } + h264_bitstream_parser_.ParseBitstream(input_image); + absl::optional qp = h264_bitstream_parser_.GetLastSliceQp(); + std::array yuv; SBufferInfo info = {}; int r = decoder_->DecodeFrameNoDelay(input_image.data(), input_image.size(), yuv.data(), &info); if (r != 0) { + RTC_LOG(LS_ERROR) << "Failed to ISVCDecoder::DecodeFrameNoDelay: r=" << r; return WEBRTC_VIDEO_CODEC_ERROR; } @@ -117,6 +127,8 @@ int32_t DynamicH264Decoder::Decode(const EncodedImage& input_image, video_frame.set_color_space(*input_image.ColorSpace()); } + callback_->Decoded(video_frame, absl::nullopt, qp); + return WEBRTC_VIDEO_CODEC_OK; } @@ -124,4 +136,4 @@ const char* DynamicH264Decoder::ImplementationName() const { return "OpenH264"; } -} // namespace webrtc \ No newline at end of file +} // namespace webrtc diff --git a/src/dynamic_h264_decoder.h b/src/dynamic_h264_decoder.h index e3be8cdc..affa6453 100644 --- a/src/dynamic_h264_decoder.h +++ b/src/dynamic_h264_decoder.h @@ -4,6 +4,7 @@ #include // WebRTC +#include #include class ISVCDecoder; @@ -33,8 +34,9 @@ class DynamicH264Decoder : public H264Decoder { const char* ImplementationName() const override; private: - DecodedImageCallback* callback_; + DecodedImageCallback* callback_ = nullptr; ISVCDecoder* decoder_ = nullptr; + webrtc::H264BitstreamParser h264_bitstream_parser_; std::string openh264_; void* openh264_handle_ = nullptr; @@ -46,4 +48,4 @@ class DynamicH264Decoder : public H264Decoder { } // namespace webrtc -#endif \ No newline at end of file +#endif