Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gpu decode #38

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/win/msdkvideodecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,13 +21,19 @@ 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) {
factory->UnloadMSDKPlugin(m_mfx_session_, &m_plugin_id_);
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;
Expand Down Expand Up @@ -365,27 +372,29 @@ int32_t MSDKVideoDecoder::Decode(
if (sts == MFX_ERR_NONE && syncp != nullptr) {
sts = m_mfx_session_->SyncOperation(syncp, MSDK_DEC_WAIT_INTERVAL);
if (sts >= MFX_ERR_NONE) {
mfxFrameData* pData = &pOutputSurface->Data;
mfxMemId dxMemId = pOutputSurface->Data.MemId;
mfxFrameInfo frame_info = pOutputSurface->Info;
mfxHDLPair pair = {nullptr};
// Maybe we should also send the allocator as part of the frame
// handle for locking/unlocking purpose.
m_pmfx_allocator_->GetFrameHDL(dxMemId, (mfxHDL*)&pair);

m_pmfx_allocator_->LockFrame(dxMemId, pData);
rtc::scoped_refptr<I420Buffer> i420_buffer =
I420Buffer::Create(frame_info.Width, frame_info.Height);
libyuv::NV12ToI420(pData->Y, pData->Pitch, pData->UV, pData->Pitch/2,
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);
}
#if 0
rtc::scoped_refptr<webrtc::VideoFrameBuffer> 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 (callback_) {
surface_handle_->d3d11_device = d3d11_device_.p;
surface_handle_->texture =
Expand All @@ -408,6 +417,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;
Expand Down