diff --git a/src/win/msdkvideodecoder.cc b/src/win/msdkvideodecoder.cc index 339a314893..018573b3fe 100644 --- a/src/win/msdkvideodecoder.cc +++ b/src/win/msdkvideodecoder.cc @@ -8,7 +8,8 @@ #include "src/win/d3d11_allocator.h" #include "src/win/msdkvideodecoder.h" #include "api/scoped_refptr.h" - +#include "api/video/i420_buffer.h" +#include "libyuv/convert.h" using namespace rtc; #define MSDK_BS_INIT_SIZE (1024*1024) @@ -20,6 +21,10 @@ namespace base { int32_t MSDKVideoDecoder::Release() { WipeMfxBitstream(&m_mfx_bs_); + if (m_pmfx_dec_ != nullptr) { + m_pmfx_dec_->Close(); + m_pmfx_dec_.reset(); + } if (m_mfx_session_) { MSDKFactory* factory = MSDKFactory::Get(); if (factory) { @@ -27,6 +32,8 @@ int32_t MSDKVideoDecoder::Release() { factory->DestroySession(m_mfx_session_); } } + if (m_pmfx_allocator_) + m_pmfx_allocator_->Close(); m_pmfx_allocator_.reset(); MSDK_SAFE_DELETE_ARRAY(m_pinput_surfaces_); inited_ = false; @@ -371,21 +378,24 @@ int32_t MSDKVideoDecoder::Decode( // Maybe we should also send the allocator as part of the frame // handle for locking/unlocking purpose. m_pmfx_allocator_->GetFrameHDL(dxMemId, (mfxHDL*)&pair); - -#if 0 - rtc::scoped_refptr cropped_buffer = - WrapI420Buffer(frame_info.Width, frame_info.Height, - av_frame_->data[kYPlaneIndex], - av_frame_->linesize[kYPlaneIndex], - av_frame_->data[kUPlaneIndex], - - av_frame_->linesize[kUPlaneIndex], - av_frame_->data[kVPlaneIndex], - av_frame_->linesize[kVPlaneIndex], - // To keep reference alive. - [frame_buffer] {}); - -#endif +#if 1 + mfxFrameData* pData = &pOutputSurface->Data; + m_pmfx_allocator_->LockFrame(dxMemId, pData); + rtc::scoped_refptr i420_buffer = + I420Buffer::Create(frame_info.Width, frame_info.Height); + libyuv::NV12ToI420(pData->Y, pData->Pitch, pData->UV, pData->Pitch, + i420_buffer->MutableDataY(), i420_buffer->StrideY(), + i420_buffer->MutableDataU(), i420_buffer->StrideU(), + i420_buffer->MutableDataV(), i420_buffer->StrideV(), + frame_info.Width, frame_info.Height); + m_pmfx_allocator_->UnlockFrame(dxMemId, pData); + if (callback_) { + webrtc::VideoFrame decoded_frame(i420_buffer, inputImage.Timestamp(), 0, webrtc::kVideoRotation_0); + decoded_frame.set_ntp_time_ms(inputImage.ntp_time_ms_); + decoded_frame.set_timestamp(inputImage.Timestamp()); + callback_->Decoded(decoded_frame); + } +#else if (callback_) { surface_handle_->d3d11_device = d3d11_device_.p; surface_handle_->texture = @@ -408,6 +418,7 @@ int32_t MSDKVideoDecoder::Decode( decoded_frame.set_timestamp(inputImage.Timestamp()); callback_->Decoded(decoded_frame); } +#endif } } else if (MFX_ERR_MORE_DATA == sts) { return WEBRTC_VIDEO_CODEC_OK;