Skip to content

Commit

Permalink
デコーダが正しく動いてなかったのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Jul 2, 2023
1 parent adf328b commit 71aff90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions src/dynamic_h264_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// WebRTC
#include <api/video/i420_buffer.h>
#include <rtc_base/logging.h>
#include <third_party/libyuv/include/libyuv.h>

// OpenH264
Expand All @@ -22,31 +23,36 @@ 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;
}

ISVCDecoder* decoder = nullptr;
int r = create_decoder_(&decoder);
if (r != 0) {
RTC_LOG(LS_ERROR) << "Failed to WelsCreateDecoder: r=" << r;
Release();
return false;
}

SDecodingParam param = {};
r = decoder->Initialize(&param);
if (r != 0) {
RTC_LOG(LS_ERROR) << "Failed to ISVCDecoder::Initialize: r=" << r;
Release();
return false;
}
Expand Down Expand Up @@ -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<int> qp = h264_bitstream_parser_.GetLastSliceQp();

std::array<std::uint8_t*, 3> 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;
}

Expand Down Expand Up @@ -117,11 +127,13 @@ 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;
}

const char* DynamicH264Decoder::ImplementationName() const {
return "OpenH264";
}

} // namespace webrtc
} // namespace webrtc
6 changes: 4 additions & 2 deletions src/dynamic_h264_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <memory>

// WebRTC
#include <common_video/h264/h264_bitstream_parser.h>
#include <modules/video_coding/codecs/h264/include/h264.h>

class ISVCDecoder;
Expand Down Expand Up @@ -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;
Expand All @@ -46,4 +48,4 @@ class DynamicH264Decoder : public H264Decoder {

} // namespace webrtc

#endif
#endif

0 comments on commit 71aff90

Please sign in to comment.