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
base: master
Are you sure you want to change the base?
Set Game metadata #21286
Conversation
: IPlayer(callback), m_gameServices(CServiceBroker::GetGameServices()) | ||
: IPlayer(callback), | ||
m_gameServices(CServiceBroker::GetGameServices()), | ||
m_fileItem(new CFileItem()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_fileItem(new CFileItem()) | |
m_fileItem(std::make_shared<CFileItem>()) |
xbmc/cores/RetroPlayer/RetroPlayer.h
Outdated
@@ -136,6 +144,9 @@ class CRetroPlayer : public IPlayer, | |||
|
|||
// Synchronization parameters | |||
CCriticalSection m_mutex; | |||
|
|||
// File metadata | |||
std::shared_ptr<CFileItem> m_fileItem; |
There was a problem hiding this comment.
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/interfaces/legacy/Player.cpp
Outdated
{ | ||
XBMC_TRACE; | ||
if (!g_application.GetAppPlayer().IsPlayingGame()) | ||
throw PlayerException("XBMC is not playing any game file"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
xbmc/Application.cpp
Outdated
@@ -2252,6 +2252,19 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg) | |||
} | |||
break; | |||
|
|||
case TMSG_SET_PLAYER_ITEM: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. | ||
/// |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
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. |
@NikosSiak this needs a rebase |
I've split this PR in two and submitted the first half upstream: #23054 |
@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). |
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
What is the effect on users?
Screenshots (if appropriate):
Types of change
Checklist: