Skip to content

Commit

Permalink
Merge pull request xbmc#24940 from notspiff/add_video_fileitem_classify
Browse files Browse the repository at this point in the history
Start moving video fileitem classifiers to separate file
  • Loading branch information
notspiff committed Apr 16, 2024
2 parents eacbaed + a0aa7ba commit 497beac
Show file tree
Hide file tree
Showing 41 changed files with 353 additions and 142 deletions.
4 changes: 3 additions & 1 deletion xbmc/Autorun.cpp
Expand Up @@ -31,6 +31,7 @@
#include "settings/SettingsComponent.h"
#include "settings/lib/Setting.h"
#include "settings/lib/SettingDefinitions.h"
#include "video/VideoFileItemClassify.h"

#include <stdlib.h>
#ifndef TARGET_WINDOWS
Expand All @@ -51,6 +52,7 @@
using namespace XFILE;
using namespace MEDIA_DETECT;
using namespace KODI::MESSAGING;
using namespace KODI::VIDEO;
using namespace std::chrono_literals;

using KODI::MESSAGING::HELPERS::DialogResponse;
Expand Down Expand Up @@ -399,7 +401,7 @@ bool CAutorun::RunDisc(IDirectory* pDir, const std::string& strDrive, int& nAdde
for (int i = 0; i < tempItems.Size(); i++)
{
CFileItemPtr pItem = tempItems[i];
if (!pItem->m_bIsFolder && pItem->IsVideo())
if (!pItem->m_bIsFolder && IsVideo(*pItem))
{
bPlaying = true;
if (pItem->IsStack())
Expand Down
55 changes: 6 additions & 49 deletions xbmc/FileItem.cpp
Expand Up @@ -59,6 +59,7 @@
#include "utils/log.h"
#include "video/Bookmark.h"
#include "video/VideoDatabase.h"
#include "video/VideoFileItemClassify.h"
#include "video/VideoInfoTag.h"
#include "video/VideoUtils.h"

Expand All @@ -68,6 +69,7 @@
#include <mutex>

using namespace KODI;
using namespace KODI::VIDEO;
using namespace XFILE;
using namespace PLAYLIST;
using namespace MUSIC_INFO;
Expand Down Expand Up @@ -873,51 +875,6 @@ bool CFileItem::Exists(bool bUseCache /* = true */) const
return false;
}

bool CFileItem::IsVideo() const
{
/* check preset mime type */
if(StringUtils::StartsWithNoCase(m_mimetype, "video/"))
return true;

if (HasVideoInfoTag())
return true;

if (HasGameInfoTag())
return false;

if (HasMusicInfoTag())
return false;

if (HasPictureInfoTag())
return false;

// TV recordings are videos...
if (!m_bIsFolder && URIUtils::IsPVRTVRecordingFileOrFolder(GetPath()))
return true;

// ... all other PVR items are not.
if (IsPVR())
return false;

if (URIUtils::IsDVD(m_strPath))
return true;

std::string extension;
if(StringUtils::StartsWithNoCase(m_mimetype, "application/"))
{ /* check for some standard types */
extension = m_mimetype.substr(12);
if( StringUtils::EqualsNoCase(extension, "ogg")
|| StringUtils::EqualsNoCase(extension, "mp4")
|| StringUtils::EqualsNoCase(extension, "mxf") )
return true;
}

//! @todo If the file is a zip file, ask the game clients if any support this
// file before assuming it is video.

return URIUtils::HasExtension(m_strPath, CServiceBroker::GetFileExtensionProvider().GetVideoExtensions());
}

bool CFileItem::IsEPG() const
{
return HasEPGInfoTag();
Expand Down Expand Up @@ -1477,7 +1434,7 @@ void CFileItem::FillInDefaultIcon()
// audio
SetArt("icon", "DefaultAudio.png");
}
else if ( IsVideo() )
else if (IsVideo(*this))
{
// video
SetArt("icon", "DefaultVideo.png");
Expand Down Expand Up @@ -1866,7 +1823,7 @@ void CFileItem::MergeInfo(const CFileItem& item)
SetLabel2(item.GetLabel2());
if (!item.GetArt().empty())
{
if (item.IsVideo())
if (IsVideo(item))
AppendArt(item.GetArt());
else
SetArt(item.GetArt());
Expand Down Expand Up @@ -3809,7 +3766,7 @@ bool CFileItem::LoadDetails()
return false;
}

if (!IsPlayList() && IsVideo())
if (!IsPlayList() && IsVideo(*this))
{
if (HasVideoInfoTag())
return true;
Expand Down Expand Up @@ -3841,7 +3798,7 @@ bool CFileItem::LoadDetails()
if (playlist->Load(GetPath()) && playlist->size() == 1)
{
const auto item{(*playlist)[0]};
if (item->IsVideo())
if (IsVideo(*item))
{
CVideoDatabase db;
if (!db.Open())
Expand Down
7 changes: 0 additions & 7 deletions xbmc/FileItem.h
Expand Up @@ -156,13 +156,6 @@ class CFileItem :

bool Exists(bool bUseCache = true) const;

/*!
\brief Check whether an item is a video item. Note that this returns true for
anything with a video info tag, so that may include eg. folders.
\return true if item is video, false otherwise.
*/
bool IsVideo() const;

bool IsDiscStub() const;

/*!
Expand Down
8 changes: 5 additions & 3 deletions xbmc/PlayListPlayer.cpp
Expand Up @@ -37,9 +37,11 @@
#include "utils/Variant.h"
#include "utils/log.h"
#include "video/VideoDatabase.h"
#include "video/VideoFileItemClassify.h"

using namespace PLAYLIST;
using namespace KODI::MESSAGING;
using namespace KODI::VIDEO;

CPlayListPlayer::CPlayListPlayer(void)
{
Expand Down Expand Up @@ -266,7 +268,7 @@ bool CPlayListPlayer::PlayItemIdx(int itemIdx)
bool CPlayListPlayer::Play(const CFileItemPtr& pItem, const std::string& player)
{
Id playlistId;
bool isVideo{pItem->IsVideo()};
bool isVideo{IsVideo(*pItem)};
bool isAudio{pItem->IsAudio()};

if (isAudio && !isVideo)
Expand Down Expand Up @@ -949,7 +951,7 @@ void PLAYLIST::CPlayListPlayer::OnApplicationMessage(KODI::MESSAGING::ThreadMess
Id playlistId = TYPE_MUSIC;
for (int i = 0; i < list->Size(); i++)
{
if ((*list)[i]->IsVideo())
if (IsVideo(*list->Get(i)))
{
playlistId = TYPE_VIDEO;
break;
Expand All @@ -967,7 +969,7 @@ void PLAYLIST::CPlayListPlayer::OnApplicationMessage(KODI::MESSAGING::ThreadMess
{
return;
}
if (item->IsAudio() || item->IsVideo())
if (item->IsAudio() || IsVideo(*item))
Play(item, pMsg->strParam);
else
g_application.PlayMedia(*item, pMsg->strParam, playlistId);
Expand Down
15 changes: 6 additions & 9 deletions xbmc/Util.cpp
Expand Up @@ -7,6 +7,7 @@
*/

#include "network/Network.h"
#include "video/VideoFileItemClassify.h"
#if defined(TARGET_DARWIN)
#include <sys/param.h>
#include <mach-o/dyld.h>
Expand Down Expand Up @@ -92,6 +93,7 @@ using namespace MEDIA_DETECT;
using namespace XFILE;
using namespace PLAYLIST;
using KODI::UTILITY::CDigest;
using namespace KODI::VIDEO;

#if !defined(TARGET_WINDOWS)
unsigned int CUtil::s_randomSeed = time(NULL);
Expand Down Expand Up @@ -2054,10 +2056,8 @@ void CUtil::ScanForExternalSubtitles(const std::string& strMovie, std::vector<st
auto start = std::chrono::steady_clock::now();

CFileItem item(strMovie, false);
if ((item.IsInternetStream() && !URIUtils::IsOnLAN(item.GetDynPath()))
|| item.IsPlayList()
|| item.IsLiveTV()
|| !item.IsVideo())
if ((item.IsInternetStream() && !URIUtils::IsOnLAN(item.GetDynPath())) || item.IsPlayList() ||
item.IsLiveTV() || !IsVideo(item))
return;

CLog::Log(LOGDEBUG, "{}: Searching for subtitles...", __FUNCTION__);
Expand Down Expand Up @@ -2346,11 +2346,8 @@ std::string CUtil::GetVobSubIdxFromSub(const std::string& vobSub)
void CUtil::ScanForExternalAudio(const std::string& videoPath, std::vector<std::string>& vecAudio)
{
CFileItem item(videoPath, false);
if ( item.IsInternetStream()
|| item.IsPlayList()
|| item.IsLiveTV()
|| item.IsPVR()
|| !item.IsVideo())
if (item.IsInternetStream() || item.IsPlayList() || item.IsLiveTV() || item.IsPVR() ||
!IsVideo(item))
return;

std::string strBasePath;
Expand Down
20 changes: 10 additions & 10 deletions xbmc/application/Application.cpp
Expand Up @@ -60,6 +60,7 @@
#include "filesystem/DirectoryFactory.h"
#include "filesystem/DllLibCurl.h"
#include "filesystem/File.h"
#include "video/VideoFileItemClassify.h"
#ifdef HAS_FILESYSTEM_NFS
#include "filesystem/NFSFile.h"
#endif
Expand Down Expand Up @@ -198,6 +199,7 @@ using namespace PVR;
using namespace PERIPHERALS;
using namespace KODI;
using namespace KODI::MESSAGING;
using namespace KODI::VIDEO;
using namespace ActiveAE;

using namespace XbmcThreads;
Expand Down Expand Up @@ -2301,7 +2303,7 @@ bool CApplication::PlayFile(CFileItem item, const std::string& player, bool bRes
m_nextPlaylistItem = -1;
stackHelper->Clear();

if (item.IsVideo())
if (IsVideo(item))
CUtil::ClearSubtitles();
}

Expand Down Expand Up @@ -2346,7 +2348,7 @@ bool CApplication::PlayFile(CFileItem item, const std::string& player, bool bRes
{
// the following code block is only applicable when bRestart is false OR to ISO stacks

if (item.IsVideo())
if (IsVideo(item))
{
// open the d/b and retrieve the bookmarks for the current movie
CVideoDatabase dbs;
Expand Down Expand Up @@ -2458,7 +2460,7 @@ bool CApplication::PlayFile(CFileItem item, const std::string& player, bool bRes
CSettings::SETTING_MUSICFILES_SELECTACTION) &&
!CMediaSettings::GetInstance().DoesMediaStartWindowed();
}
else if (item.IsVideo() && playlistId == PLAYLIST::TYPE_VIDEO &&
else if (IsVideo(item) && playlistId == PLAYLIST::TYPE_VIDEO &&
CServiceBroker::GetPlaylistPlayer().GetPlaylist(playlistId).size() > 1)
{ // playing from a playlist by the looks
// don't switch to fullscreen if we are not playing the first item...
Expand Down Expand Up @@ -2783,9 +2785,9 @@ bool CApplication::OnMessage(CGUIMessage& message)
bool bNothingToQueue = false;

const auto appPlayer = GetComponent<CApplicationPlayer>();
if (!file.IsVideo() && appPlayer->IsPlayingVideo())
if (!IsVideo(file) && appPlayer->IsPlayingVideo())
bNothingToQueue = true;
else if ((!file.IsAudio() || file.IsVideo()) && appPlayer->IsPlayingAudio())
else if ((!file.IsAudio() || IsVideo(file)) && appPlayer->IsPlayingAudio())
bNothingToQueue = true;

if (bNothingToQueue)
Expand Down Expand Up @@ -3053,7 +3055,7 @@ bool CApplication::ExecuteXBMCAction(std::string actionStr,
}
else
#endif
if (item.IsAudio() || item.IsVideo() || item.IsGame())
if (item.IsAudio() || IsVideo(item) || item.IsGame())
{ // an audio or video file
PlayFile(item, "");
}
Expand Down Expand Up @@ -3174,10 +3176,8 @@ void CApplication::ProcessSlow()

// Temporarily pause pausable jobs when viewing video/picture
int currentWindow = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
if (CurrentFileItem().IsVideo() ||
CurrentFileItem().IsPicture() ||
currentWindow == WINDOW_FULLSCREEN_VIDEO ||
currentWindow == WINDOW_FULLSCREEN_GAME ||
if (IsVideo(CurrentFileItem()) || CurrentFileItem().IsPicture() ||
currentWindow == WINDOW_FULLSCREEN_VIDEO || currentWindow == WINDOW_FULLSCREEN_GAME ||
currentWindow == WINDOW_SLIDESHOW)
{
CServiceBroker::GetJobManager()->PauseJobs();
Expand Down
7 changes: 5 additions & 2 deletions xbmc/application/ApplicationPlayerCallback.cpp
Expand Up @@ -32,10 +32,13 @@
#include "utils/URIUtils.h"
#include "utils/log.h"
#include "video/VideoDatabase.h"
#include "video/VideoFileItemClassify.h"
#include "video/VideoInfoTag.h"

#include <memory>

using namespace KODI::VIDEO;

CApplicationPlayerCallback::CApplicationPlayerCallback()
{
}
Expand Down Expand Up @@ -80,7 +83,7 @@ void CApplicationPlayerCallback::OnPlayBackStarted(const CFileItem& file)
* This should speed up player startup for files on internet filesystems (eg. webdav) and
* increase performance on low powered systems (Atom/ARM).
*/
if (file.IsVideo() || file.IsGame())
if (IsVideo(file) || file.IsGame())
{
CServiceBroker::GetJobManager()->PauseJobs();
}
Expand Down Expand Up @@ -128,7 +131,7 @@ void CApplicationPlayerCallback::OnPlayerCloseFile(const CFileItem& file,

if ((fileItem.IsAudio() && advancedSettings->m_audioPlayCountMinimumPercent > 0 &&
percent >= advancedSettings->m_audioPlayCountMinimumPercent) ||
(fileItem.IsVideo() && advancedSettings->m_videoPlayCountMinimumPercent > 0 &&
(IsVideo(fileItem) && advancedSettings->m_videoPlayCountMinimumPercent > 0 &&
percent >= advancedSettings->m_videoPlayCountMinimumPercent))
{
playCountUpdate = true;
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/playercorefactory/PlayerCoreFactory.cpp
Expand Up @@ -25,12 +25,15 @@
#include "utils/StringUtils.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"
#include "video/VideoFileItemClassify.h"

#include <mutex>
#include <sstream>

#define PLAYERCOREFACTORY_XML "playercorefactory.xml"

using namespace KODI;

CPlayerCoreFactory::CPlayerCoreFactory(const CProfileManager& profileManager)
: m_settings(CServiceBroker::GetSettingsComponent()->GetSettings()),
m_profileManager(profileManager)
Expand Down Expand Up @@ -141,7 +144,7 @@ void CPlayerCoreFactory::GetPlayers(const CFileItem& item, std::vector<std::stri
// "videodefaultplayer"
if (defaultInputstreamPlayerOverride == ForcedPlayer::VIDEO_DEFAULT ||
(defaultInputstreamPlayerOverride == ForcedPlayer::NONE &&
(item.IsVideo() || (!item.IsAudio() && !item.IsGame()))))
(VIDEO::IsVideo(item) || (!item.IsAudio() && !item.IsGame()))))
{
int idx = GetPlayerIndex("videodefaultplayer");
if (idx > -1)
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/playercorefactory/PlayerSelectionRule.cpp
Expand Up @@ -19,10 +19,13 @@
#include "utils/XBMCTinyXML.h"
#include "utils/XMLUtils.h"
#include "utils/log.h"
#include "video/VideoFileItemClassify.h"
#include "video/VideoInfoTag.h"

#include <algorithm>

using namespace KODI;

CPlayerSelectionRule::CPlayerSelectionRule(TiXmlElement* pRule)
{
Initialize(pRule);
Expand Down Expand Up @@ -116,7 +119,7 @@ void CPlayerSelectionRule::GetPlayers(const CFileItem& item, std::vector<std::st
return;
if (m_tAudio >= 0 && (m_tAudio > 0) != item.IsAudio())
return;
if (m_tVideo >= 0 && (m_tVideo > 0) != item.IsVideo())
if (m_tVideo >= 0 && (m_tVideo > 0) != VIDEO::IsVideo(item))
return;
if (m_tGame >= 0 && (m_tGame > 0) != item.IsGame())
return;
Expand Down

0 comments on commit 497beac

Please sign in to comment.