From 1ed2055ec1789bca26bd9c8c5953405ab25d86c3 Mon Sep 17 00:00:00 2001 From: eladash Date: Wed, 13 Mar 2019 09:14:27 +0200 Subject: [PATCH] Fix cellVdecGetPicItem element popping behaviour --- rpcs3/Emu/Cell/Modules/cellVdec.cpp | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellVdec.cpp b/rpcs3/Emu/Cell/Modules/cellVdec.cpp index 93ae3cff51..7b6eaef86b 100644 --- a/rpcs3/Emu/Cell/Modules/cellVdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellVdec.cpp @@ -53,6 +53,7 @@ struct vdec_frame u64 pts; u64 userdata; u32 frc; + bool PicItemRecieved = false; AVFrame* operator ->() const { @@ -84,7 +85,7 @@ struct vdec_context final u64 next_dts{}; u64 ppu_tid{}; - std::queue out; + std::deque out; atomic_t out_max = 60; atomic_t au_count{0}; @@ -353,7 +354,7 @@ struct vdec_context final cellVdec.trace("Got picture (pts=0x%llx[0x%llx], dts=0x%llx[0x%llx])", frame.pts, frame->pkt_pts, frame.dts, frame->pkt_dts); - std::lock_guard{mutex}, out.push(std::move(frame)); + std::lock_guard{mutex}, out.push_back(std::move(frame)); cb_func(ppu, vid, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, cb_arg); lv2_obj::sleep(ppu); @@ -586,7 +587,7 @@ s32 cellVdecGetPicture(u32 handle, vm::cptr format, vm::ptrout.front()); - vdec->out.pop(); + vdec->out.pop_front(); if (vdec->out.size() + 1 == vdec->out_max) notify = true; } @@ -706,16 +707,25 @@ s32 cellVdecGetPicItem(u32 handle, vm::pptr picItem) { std::lock_guard lock(vdec->mutex); - if (vdec->out.empty()) + for (auto& picture : vdec->out) { - return CELL_VDEC_ERROR_EMPTY; + if (!picture.PicItemRecieved) + { + picture.PicItemRecieved = true; + frame = picture.avf.get(); + pts = picture.pts; + dts = picture.dts; + usrd = picture.userdata; + frc = picture.frc; + break; + } } + } - frame = vdec->out.front().avf.get(); - pts = vdec->out.front().pts; - dts = vdec->out.front().dts; - usrd = vdec->out.front().userdata; - frc = vdec->out.front().frc; + if (!frame) + { + // If frame is empty info was not found + return CELL_VDEC_ERROR_EMPTY; } const vm::ptr info = vm::cast(vdec->mem_addr + vdec->mem_bias);