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

VideoPlayer: inputstream changes, bump to 1.0.2 #9410

Merged
merged 2 commits into from Mar 21, 2016
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
4 changes: 2 additions & 2 deletions addons/kodi.inputstream/addon.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="kodi.inputstream" version="1.0.1" provider-name="Team Kodi">
<backwards-compatibility abi="1.0.1"/>
<addon id="kodi.inputstream" version="1.0.2" provider-name="Team Kodi">
<backwards-compatibility abi="1.0.2"/>
<requires>
<import addon="xbmc.core" version="0.1.0"/>
</requires>
Expand Down
69 changes: 45 additions & 24 deletions xbmc/addons/InputStream.cpp
Expand Up @@ -20,12 +20,17 @@
#include "utils/StringUtils.h"
#include "utils/log.h"
#include "cores/VideoPlayer/DVDDemuxers/DVDDemux.h"
#include "threads/SingleLock.h"
#include "utils/RegExp.h"
#include "utils/URIUtils.h"

namespace ADDON
{

bool CInputStream::m_hasConfig = false;
std::vector<std::string> CInputStream::m_pathList;
CCriticalSection CInputStream::m_parentSection;

std::unique_ptr<CInputStream> CInputStream::FromExtension(AddonProps props, const cp_extension_t* ext)
{
std::string listitemprops = CAddonMgr::GetInstance().GetExtValue(ext->configuration, "@listitemprops");
Expand All @@ -52,51 +57,62 @@ CInputStream::CInputStream(AddonProps props, std::string name, std::string listi
{
StringUtils::Trim(ext);
}

if (!m_bIsChild && !m_hasConfig)
UpdateConfig();
}

bool CInputStream::Supports(CFileItem &fileitem)
void CInputStream::SaveSettings()
{
std::string extension = URIUtils::GetExtension(fileitem.GetPath());
bool match = false;
for (auto &ext : m_extensionsList)
{
if (ext == extension)
{
match = true;
break;
}
}
if (!match)
return false;

if (!m_pStruct)
return true;
CAddon::SaveSettings();
if (!m_bIsChild)
UpdateConfig();
}

void CInputStream::UpdateConfig()
{
std::string pathList;
Create();
try
{
pathList = m_pStruct->GetPathList();
}
catch (std::exception &e)
{
CLog::Log(LOGERROR, "CInputStream::Supports - could not get a list of paths. Reason: %s", e.what());
return false;
}
Destroy();

CSingleLock lock(m_parentSection);
m_pathList = StringUtils::Tokenize(pathList, "|");
for (auto &path : m_pathList)
{
StringUtils::Trim(path);
}
m_hasConfig = true;
}

bool CInputStream::Supports(CFileItem &fileitem)
{
// check if a specific inputstream addon is requested
CVariant addon = fileitem.GetProperty("inputstreamaddon");
if (!addon.isNull())
{
if (addon.asString() != Name())
return false;
}

// check paths
CSingleLock lock(m_parentSection);

match = false;
bool match = false;
for (auto &path : m_pathList)
{
if (path.empty())
continue;

CRegExp r(true, CRegExp::asciiOnly, path.c_str());
if (r.RegFind(path.c_str()) == 0 && r.GetFindLen() > 5)
if (r.RegFind(fileitem.GetPath().c_str()) == 0 && r.GetFindLen() > 5)
{
match = true;
break;
Expand All @@ -108,17 +124,22 @@ bool CInputStream::Supports(CFileItem &fileitem)
bool CInputStream::Open(CFileItem &fileitem)
{
INPUTSTREAM props;
props.m_nCountInfoValues = 0;
std::vector<std::string> values;
std::map<std::string, std::string> propsMap;
for (auto &key : m_fileItemProps)
{
if (fileitem.GetProperty(key).isNull())
continue;
props.m_ListItemProperties[props.m_nCountInfoValues].m_strKey = key.c_str();
values.push_back(fileitem.GetProperty(key).asString());
props.m_ListItemProperties[props.m_nCountInfoValues].m_strValue = values.back().c_str();
propsMap[key] = fileitem.GetProperty(key).asString();
}

props.m_nCountInfoValues = 0;
for (auto &pair : propsMap)
{
props.m_ListItemProperties[props.m_nCountInfoValues].m_strKey = pair.first.c_str();
props.m_ListItemProperties[props.m_nCountInfoValues].m_strValue = pair.second.c_str();
props.m_nCountInfoValues++;
}

props.m_strURL = fileitem.GetPath().c_str();

std::string libFolder = URIUtils::GetDirectory(m_parentLib);
Expand Down
9 changes: 8 additions & 1 deletion xbmc/addons/InputStream.h
Expand Up @@ -21,6 +21,7 @@
#include "AddonDll.h"
#include "addons/kodi-addon-dev-kit/include/kodi/kodi_inputstream_types.h"
#include "FileItem.h"
#include "threads/CriticalSection.h"
#include <vector>
#include <map>

Expand All @@ -44,6 +45,8 @@ namespace ADDON
CInputStream(AddonProps props, std::string name, std::string listitemprops, std::string extensions);
virtual ~CInputStream() {}

virtual void SaveSettings() override;

bool Supports(CFileItem &fileitem);
bool Open(CFileItem &fileitem);
void Close();
Expand Down Expand Up @@ -85,12 +88,16 @@ namespace ADDON
protected:
void UpdateStreams();
void DisposeStreams();
void UpdateConfig();

std::vector<std::string> m_fileItemProps;
std::vector<std::string> m_pathList;
std::vector<std::string> m_extensionsList;
INPUTSTREAM_CAPABILITIES m_caps;
std::map<int, CDemuxStream*> m_streams;

static CCriticalSection m_parentSection;
static bool m_hasConfig;
static std::vector<std::string> m_pathList;
};

} /*namespace ADDON*/