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

cellMusic: Implement some error checking #12625

Merged
merged 2 commits into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 40 additions & 6 deletions rpcs3/Emu/Cell/Modules/cellMusic.cpp
Expand Up @@ -248,6 +248,11 @@ error_code cellMusicGetSelectionContext(vm::ptr<CellMusicSelectionContext> conte
auto& music = g_fxo->get<music_state>();
std::lock_guard lock(music.mtx);

if (!music.current_selection_context)
{
return CELL_MUSIC2_ERROR_NO_ACTIVE_CONTENT;
}

*context = music.current_selection_context.get();
cellMusic.success("cellMusicGetSelectionContext: selection context = %s", music.current_selection_context.to_string());

Expand Down Expand Up @@ -317,6 +322,12 @@ error_code cellMusicGetContentsId(vm::ptr<CellSearchContentId> contents_id)
// HACKY
auto& music = g_fxo->get<music_state>();
std::lock_guard lock(music.mtx);

if (!music.current_selection_context)
{
return CELL_MUSIC2_ERROR_NO_ACTIVE_CONTENT;
}

return music.current_selection_context.find_content_id(contents_id);
}

Expand Down Expand Up @@ -363,6 +374,7 @@ error_code cellMusicInitialize2SystemWorkload(s32 mode, vm::ptr<CellMusic2Callba
auto& music = g_fxo->get<music_state>();
music.func = func;
music.userData = userData;
music.current_selection_context = {};

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
{
Expand Down Expand Up @@ -429,6 +441,7 @@ error_code cellMusicInitializeSystemWorkload(s32 mode, u32 container, vm::ptr<Ce
auto& music = g_fxo->get<music_state>();
music.func = func;
music.userData = userData;
music.current_selection_context = {};

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
{
Expand All @@ -451,6 +464,7 @@ error_code cellMusicInitialize(s32 mode, u32 container, s32 spuPriority, vm::ptr
auto& music = g_fxo->get<music_state>();
music.func = func;
music.userData = userData;
music.current_selection_context = {};

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
{
Expand Down Expand Up @@ -489,6 +503,11 @@ error_code cellMusicGetSelectionContext2(vm::ptr<CellMusicSelectionContext> cont
auto& music = g_fxo->get<music_state>();
std::lock_guard lock(music.mtx);

if (!music.current_selection_context)
{
return CELL_MUSIC2_ERROR_NO_ACTIVE_CONTENT;
}

*context = music.current_selection_context.get();
cellMusic.success("cellMusicGetSelectionContext2: selection context = %s", music.current_selection_context.to_string());

Expand Down Expand Up @@ -533,14 +552,21 @@ error_code cellMusicSetPlaybackCommand2(s32 command, vm::ptr<void> param)
if (!music.func)
return CELL_MUSIC2_ERROR_GENERIC;

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
error_code result = CELL_OK;

if (!music.current_selection_context)
{
result = CELL_MUSIC_ERROR_GENERIC;
}

sysutil_register_cb([=, &music, prev_res = result](ppu_thread& ppu) -> s32
{
const error_code result = music.set_playback_command(command);
const error_code result = prev_res ? prev_res : music.set_playback_command(command);
music.func(ppu, CELL_MUSIC2_EVENT_SET_PLAYBACK_COMMAND_RESULT, vm::addr_t(+result), music.userData);
return CELL_OK;
});

return CELL_OK;
return result;
}

error_code cellMusicSetPlaybackCommand(s32 command, vm::ptr<void> param)
Expand All @@ -555,14 +581,21 @@ error_code cellMusicSetPlaybackCommand(s32 command, vm::ptr<void> param)
if (!music.func)
return CELL_MUSIC_ERROR_GENERIC;

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
error_code result = CELL_OK;

if (!music.current_selection_context)
{
const error_code result = music.set_playback_command(command);
result = CELL_MUSIC2_ERROR_GENERIC;
}

sysutil_register_cb([=, &music, prev_res = result](ppu_thread& ppu) -> s32
{
const error_code result = prev_res ? prev_res : music.set_playback_command(command);
music.func(ppu, CELL_MUSIC_EVENT_SET_PLAYBACK_COMMAND_RESULT, vm::addr_t(+result), music.userData);
return CELL_OK;
});

return CELL_OK;
return result;
}

error_code cellMusicSelectContents2()
Expand Down Expand Up @@ -591,6 +624,7 @@ error_code cellMusicInitialize2(s32 mode, s32 spuPriority, vm::ptr<CellMusic2Cal
auto& music = g_fxo->get<music_state>();
music.func = func;
music.userData = userData;
music.current_selection_context = {};

sysutil_register_cb([=, &music](ppu_thread& ppu) -> s32
{
Expand Down
6 changes: 6 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellMusic.h
Expand Up @@ -141,6 +141,7 @@ struct CellMusicSelectionContext

struct music_selection_context
{
bool valid = false;
char magic[4] = "SUS";
std::string hash;
CellSearchContentType content_type = CELL_SEARCH_CONTENTTYPE_MUSIC;
Expand All @@ -167,6 +168,11 @@ struct music_selection_context
bool load_playlist();
u32 step_track(bool next);

operator bool() const
{
return atomic_storage<bool>::load(valid);
}

// Helper
error_code find_content_id(vm::ptr<CellSearchContentId> contents_id);
};
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/Modules/cellMusicSelectionContext.cpp
Expand Up @@ -242,6 +242,7 @@ bool music_selection_context::load_playlist()
playlist.push_back(track_node[i].Scalar());
}

valid = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when is it set to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUModule.cpp
Expand Up @@ -680,7 +680,7 @@ static auto ppu_load_exports(ppu_linkage_info* link, u32 exports_start, u32 expo
{
const u32 fnid = fnids[i];
const u32 faddr = faddrs[i];
ppu_loader.notice("**** %s export: [%s] (0x%08x) at 0x%x", module_name, ppu_get_function_name(module_name, fnid), fnid, faddr);
ppu_loader.notice("**** %s export: [%s] (0x%08x) at 0x%x [at:0x%x]", module_name, ppu_get_function_name(module_name, fnid), fnid, faddr, vm::read32(faddr));

// Function linkage info
auto& flink = mlink.functions[fnid];
Expand Down