From 624f34ae138bdd79210faaec79e96e0caba3c684 Mon Sep 17 00:00:00 2001 From: capriots <29807355+capriots@users.noreply.github.com> Date: Tue, 7 May 2024 20:16:26 +0200 Subject: [PATCH] cellAtracXdec: review fixes --- rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp | 55 +++++++++++++++--------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp b/rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp index ac94007770..3b3915380f 100644 --- a/rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp @@ -273,18 +273,24 @@ void AtracXdecContext::exec(ppu_thread& ppu) lv2_obj::sleep(ppu); std::lock_guard lock{queue_mutex}; - while (cmd_queue.empty() && thread_ctrl::state() != thread_state::aborting) + while (cmd_queue.empty() && !ppu.is_stopped()) { lv2_obj::sleep(ppu); queue_not_empty.wait(queue_mutex, 20000); } - if (!run_thread || thread_ctrl::state() == thread_state::aborting) + if (ppu.is_stopped()) { + ppu.state += cpu_flag::again; return; } cmd_queue.pop(cmd); + + if (!run_thread) + { + return; + } } cellAtracXdec.trace("Command type: %d", static_cast(cmd.type.get())); @@ -321,6 +327,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (!savestate_lock.owns_lock()) { + ppu.state += cpu_flag::again; return; } @@ -330,7 +337,6 @@ void AtracXdecContext::exec(ppu_thread& ppu) notify_seq_done.cbFunc(ppu, notify_seq_done.cbArg); break; } - case AtracXdecCmdType::decode_au: { skip_getting_command = true; @@ -342,13 +348,19 @@ void AtracXdecContext::exec(ppu_thread& ppu) lv2_obj::sleep(ppu); std::unique_lock output_mutex_lock{output_mutex}; - while (output_locked && thread_ctrl::state() != thread_state::aborting) + while (output_locked && !ppu.is_stopped()) { lv2_obj::sleep(ppu); output_consumed.wait(output_mutex, 20000); } - if (!run_thread || thread_ctrl::state() == thread_state::aborting) + if (ppu.is_stopped()) + { + ppu.state += cpu_flag::again; + return; + } + + if (!run_thread) { return; } @@ -365,6 +377,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (!savestate_lock.owns_lock()) { + ppu.state += cpu_flag::again; return; } @@ -402,7 +415,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (int err = avcodec_receive_frame(decoder.ctx, decoder.frame); err) { cellAtracXdec.error("avcodec_receive_frame() failed (err=0x%x='%s')", err, utils::av_error_to_string(err)); - error = CELL_ADEC_ERROR_ATX_NON_FATAL; // Not accurate, LLE uses an error code dependant on which part of the access unit is invalid + error = CELL_ADEC_ERROR_ATX_NON_FATAL; // Not accurate, FFmpeg doesn't provide detailed errors like LLE } decoded_samples_num = decoder.frame->nb_samples; @@ -432,7 +445,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (sample >= std::bit_cast(std::bit_cast(1.f) - 1)) { - output_f32[sample_idx * decoder.nch_in + ATXDEC_AVCODEC_CH_MAP[decoder.ch_config_idx - 1][channel_idx]] = std::bit_cast>(std::array{ 0x3f, 0x7f, 0xff, 0xff }); // Prevents an unnecessary endian swap + output_f32[sample_idx * decoder.nch_in + ATXDEC_AVCODEC_CH_MAP[decoder.ch_config_idx - 1][channel_idx]] = std::bit_cast>("\x3f\x7f\xff\xff"_u32); // Prevents an unnecessary endian swap } else if (sample <= -1.f) { @@ -524,6 +537,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (!savestate_lock.owns_lock()) { + ppu.state += cpu_flag::again; return; } @@ -537,6 +551,7 @@ void AtracXdecContext::exec(ppu_thread& ppu) if (!savestate_lock.owns_lock()) { + ppu.state += cpu_flag::again; return; } @@ -608,15 +623,11 @@ void atracXdecEntry(ppu_thread& ppu, vm::ptr atxdec) atxdec->decoder.free_avcodec(); - if (thread_ctrl::state() == thread_state::aborting) + if (ppu.state & cpu_flag::again) { - // For savestates, restore argument - idm::get>(static_cast(atxdec->thread_id))->cmd_list - ({ - { ppu_cmd::set_args, 1 }, static_cast(atxdec.addr()), - }); + // For savestates, save argument + ppu.syscall_args[0] = atxdec.addr(); - ppu.state += cpu_flag::again; return; } @@ -656,11 +667,11 @@ error_code _CellAdecCoreOpOpenExt_atracx(ppu_thread& ppu, vm::ptr::make(handle.addr() + utils::align(static_cast(sizeof(AtracXdecContext)), 0x80) + ATXDEC_SPURS_STRUCTS_SIZE)); + write_to_ptr(handle.get_ptr(), AtracXdecContext(notifyAuDone, notifyAuDoneArg, notifyPcmOut, notifyPcmOutArg, notifyError, notifyErrorArg, notifySeqDone, notifySeqDoneArg, + vm::bptr::make(handle.addr() + utils::align(static_cast(sizeof(AtracXdecContext)), 0x80) + ATXDEC_SPURS_STRUCTS_SIZE))); const vm::var _name = vm::make_str("HLE ATRAC3plus decoder"); const auto entry = g_fxo->get().func_addr(FIND_FUNC(atracXdecEntry)); @@ -745,13 +756,16 @@ error_code _CellAdecCoreOpDecodeAu_atracx(ppu_thread& ppu, vm::ptrsend_command(ppu, pcmHandle, *auInfo); } -void _CellAdecCoreOpGetVersion_atracx(vm::ptr> version) +void _CellAdecCoreOpGetVersion_atracx(vm::ptr version) { cellAtracXdec.notice("_CellAdecCoreOpGetVersion_atracx(version=*0x%x)", version); ensure(!!version); // Not checked on LLE - *version = { 0x01, 0x02, 0x00, 0x00 }; + version[0] = 0x01; + version[1] = 0x02; + version[2] = 0x00; + version[3] = 0x00; } error_code _CellAdecCoreOpRealign_atracx(vm::ptr handle, vm::ptr outBuffer, vm::cptr pcmStartAddr) @@ -761,6 +775,7 @@ error_code _CellAdecCoreOpRealign_atracx(vm::ptr handle, vm::p if (outBuffer) { ensure(!!handle && !!pcmStartAddr); // Not checked on LLE + ensure(vm::check_addr(outBuffer.addr(), vm::page_info_t::page_writable, handle->decoder.pcm_output_size)); std::memcpy(outBuffer.get_ptr(), pcmStartAddr.get_ptr(), handle->decoder.pcm_output_size); }