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

Set Game metadata #21286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Set Game metadata #21286

wants to merge 2 commits into from

Conversation

NikosSiak
Copy link
Member

Description

This PR extends the Python API to support game metadata, like title, developer, publisher and captions (from #20913)

Motivation and context

How has this been tested?

I have wrote a small addon that uses the API to update the discord rich presence status displaying what game you are playing and what you are doing in the game at this moment https://github.com/NikosSiak/service.games.discord.richpresence

image

What is the effect on users?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

: IPlayer(callback), m_gameServices(CServiceBroker::GetGameServices())
: IPlayer(callback),
m_gameServices(CServiceBroker::GetGameServices()),
m_fileItem(new CFileItem())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m_fileItem(new CFileItem())
m_fileItem(std::make_shared<CFileItem>())

@@ -136,6 +144,9 @@ class CRetroPlayer : public IPlayer,

// Synchronization parameters
CCriticalSection m_mutex;

// File metadata
std::shared_ptr<CFileItem> m_fileItem;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this actually needs to be a shared_ptr when looking at its usage.

{
XBMC_TRACE;
if (!g_application.GetAppPlayer().IsPlayingGame())
throw PlayerException("XBMC is not playing any game file");
Copy link
Member

Choose a reason for hiding this comment

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

Should probably change XBMC -> KODI

Copy link
Member

@a1rwulf a1rwulf Apr 20, 2022

Choose a reason for hiding this comment

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

If you want it 100% correct, you want it to be CCompileInfo::GetAppName().
The question though: Is it really needed to specifiy our application name in such an exception.

@@ -128,6 +133,12 @@ void InfoTagGame::setGameClient(const String& gameClient)
setGameClientRaw(infoTag, gameClient);
}

void InfoTagGame::setCaption(const String& gameClient)
Copy link
Member

Choose a reason for hiding this comment

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

Should this parameter be caption instead of gameClient?

@@ -2252,6 +2252,19 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
}
break;

case TMSG_SET_PLAYER_ITEM:
Copy link
Member

@enen92 enen92 Apr 20, 2022

Choose a reason for hiding this comment

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

it seems really odd that some component (in this case retroplayer) sends some thread message to the application so that it resets its internal state. Can't this be done in some other way, for example by extending the IPlayerCallback interface? This has been the cause for a lot of bugs regarding state inconsistency between the app and the player (in json-rpc for example).

I took a look into the python addon and you seem to follow some polling approach in the service. If callbacks are used instead you could just react to the OnSomething event on the xbmc.Player() object

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is needed at all.
Retroplayer calls OnPlaybackStarted just as VideoPlayer or any other player.
CApplications OnPlayBackStarted handler sets m_itemCurrentFile already.

Copy link
Member

Choose a reason for hiding this comment

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

Also CServiceBroker::GetGUI()->GetInfoManager().SetCurrentItem(*m_itemCurrentFile); is done in in
GUI_MSG_PLAYBACK_STARTED of CApplication (and this message is sent at the end of the OnPlaybackStarted callback handler, so this code ultimately runs already as well).

My take: If it does not work without this new message, you should probably find out the root cause and find a better solution to your problem.

Copy link
Member

@enen92 enen92 Apr 20, 2022

Choose a reason for hiding this comment

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

My guess is that maybe during playback the item changes without restarting the player (some video game level or something similar? Probably just the game infotag with some level caption judging by the discord screenshot) and you get to a point where there is state inconsistency between the item the app holds and the item the player holds. That's why my suggestion was to extend the player callback intertface with some other event that represents what happens here if this is really needed. Basically following the same approach that already takes place OnPlaybackStarted

Copy link
Member

Choose a reason for hiding this comment

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

Not sure how the item would change without a call to OpenFile.

Copy link
Member Author

Choose a reason for hiding this comment

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

The item tags change without opening an other file, every time the game saves a caption is generated and it might change depending your progress

Copy link
Member

@garbear garbear May 1, 2022

Choose a reason for hiding this comment

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

It's worth thinking that maybe we took the wrong approach. The need is to pass the caption to Python. We use the player API and pass game info tags of the currently-playing item. The advantage of going through the player is that we don't need to worry about modifying the Python API. But maybe, to avoid the loop mentioned in the comment added to CRetroPlayer, we extend the player API?

It's worth noting that an item not changing without OpenFile isn't necessarily a current assumption - recall all the dyn stuff. This change just solidifies that items can change, and exposes a mechanism to keep changes in sync throughout the system.

/// @brief \python_func{ isPlayingGame() }
/// Check for playing game.
///
/// @return True if kodi is playing a game
Copy link
Member

Choose a reason for hiding this comment

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

missing doxygen python revision tags

/// @return Game info tag
/// @throws Exception If player is not playing a file or current
/// file is not a game file.
///
Copy link
Member

Choose a reason for hiding this comment

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

same on this one

constexpr auto RICH_PRESENCE = "RichPresencePatch";
constexpr auto GAME_TITLE = "Title";
Copy link
Member

Choose a reason for hiding this comment

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

would be nice to avoid the auto keyword here. What is the type of those vars? I assume they are cstrings / char*
There seems to be a recent "preference" for std::string_view instead

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Sep 22, 2022
@jenkins4kodi jenkins4kodi removed the Rebase needed PR that does not apply/merge cleanly to current base branch label Oct 2, 2022
@jenkins4kodi
Copy link
Contributor

I've made some formatting changes to meet the current code style. The diffs are available in the following links:

For more information please see our current code style guidelines.

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Oct 15, 2022
@jenkins4kodi
Copy link
Contributor

@NikosSiak this needs a rebase

@garbear
Copy link
Member

garbear commented Mar 25, 2023

I've split this PR in two and submitted the first half upstream: #23054

@garbear
Copy link
Member

garbear commented Apr 3, 2023

@NikosSiak Thanks to the work here, I was able to extract and upstream most of the code: #23054

On top of that, I rebased on that had another go at this PR. Check out: https://github.com/garbear/xbmc/commits/update-discord

As you can see, we're down to the bare minimum needed to get caption in the game metadata. At least this should let the discord plugin work in my test builds.

However, I don't think game infotags are the right way to get the caption to Python. It should probably be in a player-related API. I'll leave it up to you if you want to pursue the Discord feature (I'd certainly like to use it).

@garbear garbear self-assigned this Apr 3, 2023
@fuzzard fuzzard removed the v21 Omega label Sep 1, 2023
@fuzzard fuzzard removed this from the Omega 21.0 Alpha 3 milestone Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change: Python Rebase needed PR that does not apply/merge cleanly to current base branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants