From 95774edd0317a39d6a2dc635a33797ee0b00c9b3 Mon Sep 17 00:00:00 2001 From: enm10k Date: Thu, 11 Apr 2024 17:58:00 +0900 Subject: [PATCH] =?UTF-8?q?mfxBitstream=20=E3=82=92=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=A7=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E6=88=BB=E3=81=97=E3=81=A6=E3=81=BF=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hwenc_vpl/vpl_video_decoder.cpp | 38 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/hwenc_vpl/vpl_video_decoder.cpp b/src/hwenc_vpl/vpl_video_decoder.cpp index c5a73e01..10a26c8f 100644 --- a/src/hwenc_vpl/vpl_video_decoder.cpp +++ b/src/hwenc_vpl/vpl_video_decoder.cpp @@ -69,6 +69,9 @@ class VplVideoDecoderImpl : public VplVideoDecoder { std::unique_ptr decoder_; std::vector surface_buffer_; std::vector surfaces_; + + std::vector bitstream_buffer_; + mfxBitstream bitstream_; }; VplVideoDecoderImpl::VplVideoDecoderImpl(std::shared_ptr session, @@ -192,13 +195,11 @@ int32_t VplVideoDecoderImpl::Decode(const webrtc::EncodedImage& input_image, return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; } - mfxBitstream bs; - memset(&bs, 0, sizeof(mfxBitstream)); - std::vector buf; - buf.assign(input_image.data(), input_image.data() + input_image.size()); - bs.Data = buf.data(); - bs.DataLength = input_image.size(); - bs.MaxLength = input_image.size(); + if (bitstream_.MaxLength < bitstream_.DataLength + input_image.size()) { + bitstream_buffer_.resize(bitstream_.DataLength + input_image.size()); + bitstream_.MaxLength = bitstream_.DataLength + bitstream_buffer_.size(); + bitstream_.Data = bitstream_buffer_.data(); + } //printf("size=%zu\n", input_image.size()); //for (size_t i = 0; i < input_image.size(); i++) { // const uint8_t* p = input_image.data(); @@ -210,6 +211,13 @@ int32_t VplVideoDecoderImpl::Decode(const webrtc::EncodedImage& input_image, // } //} + memmove(bitstream_.Data, bitstream_.Data + bitstream_.DataOffset, + bitstream_.DataLength); + bitstream_.DataOffset = 0; + memcpy(bitstream_.Data + bitstream_.DataLength, input_image.data(), + input_image.size()); + bitstream_.DataLength += input_image.size(); + // 使ってない入力サーフェスを取り出す auto surface = std::find_if(surfaces_.begin(), surfaces_.end(), @@ -226,7 +234,12 @@ int32_t VplVideoDecoderImpl::Decode(const webrtc::EncodedImage& input_image, mfxFrameSurface1* out_surface = nullptr; while (true) { - sts = decoder_->DecodeFrameAsync(&bs, &*surface, &out_surface, &syncp); + int before = bitstream_.DataLength; + sts = decoder_->DecodeFrameAsync(&bitstream_, &*surface, &out_surface, + &syncp); + + RTC_LOG(LS_INFO) << "DecodeFrameAsync sts=" << sts << " " << before + << " -> " << bitstream_.DataLength; if (sts == MFX_WRN_DEVICE_BUSY) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); continue; @@ -243,7 +256,8 @@ int32_t VplVideoDecoderImpl::Decode(const webrtc::EncodedImage& input_image, } auto width = param.mfx.FrameInfo.CropW; auto height = param.mfx.FrameInfo.CropH; - if (width_ != width || height_ != height) { + if (sts == MFX_WRN_VIDEO_PARAM_CHANGED || + (width_ != width || height_ != height)) { RTC_LOG(LS_INFO) << "Change Frame Size: " << width_ << "x" << height_ << " to " << width << "x" << height; width_ = width; @@ -323,6 +337,12 @@ bool VplVideoDecoderImpl::InitVpl() { RTC_LOG(LS_INFO) << "Decoder NumFrameSuggested=" << alloc_request_.NumFrameSuggested; + // 入力ビットストリーム + bitstream_buffer_.resize(1024 * 1024); + memset(&bitstream_, 0, sizeof(bitstream_)); + bitstream_.MaxLength = bitstream_buffer_.size(); + bitstream_.Data = bitstream_buffer_.data(); + // 必要な枚数分の出力サーフェスを作る { int width = (alloc_request_.Info.Width + 31) / 32 * 32;