Skip to content

Commit

Permalink
VideoPlayer: pass CFileItem to input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Nov 3, 2015
1 parent 84c1084 commit 6cb7bb4
Show file tree
Hide file tree
Showing 29 changed files with 174 additions and 166 deletions.
7 changes: 5 additions & 2 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxVobsub.cpp
Expand Up @@ -59,8 +59,11 @@ bool CDVDDemuxVobsub::Open(const std::string& filename, int source, const std::s
vobsub += ".sub";
}

m_Input.reset(CDVDFactoryInputStream::CreateInputStream(NULL, vobsub, ""));
if(!m_Input.get() || !m_Input->Open(vobsub.c_str(), "video/x-vobsub", false))
CFileItem item(vobsub, false);
item.SetMimeType("video/x-vobsub");
item.SetContentLookup(false);
m_Input.reset(CDVDFactoryInputStream::CreateInputStream(NULL, item));
if(!m_Input.get() || !m_Input->Open())
return false;

m_Demuxer.reset(new CDVDDemuxFFmpeg());
Expand Down
15 changes: 9 additions & 6 deletions xbmc/cores/VideoPlayer/DVDFileInfo.cpp
Expand Up @@ -60,11 +60,12 @@ bool CDVDFileInfo::GetFileDuration(const std::string &path, int& duration)
std::unique_ptr<CDVDInputStream> input;
std::unique_ptr<CDVDDemux> demux;

input.reset(CDVDFactoryInputStream::CreateInputStream(NULL, path, ""));
CFileItem item(path, false);
input.reset(CDVDFactoryInputStream::CreateInputStream(NULL, item));
if (!input.get())
return false;

if (!input->Open(path.c_str(), "", true))
if (!input->Open())
return false;

demux.reset(CDVDFactoryDemuxer::CreateDemuxer(input.get(), true));
Expand Down Expand Up @@ -99,7 +100,8 @@ bool CDVDFileInfo::ExtractThumb(const std::string &strPath,
{
std::string redactPath = CURL::GetRedacted(strPath);
unsigned int nTime = XbmcThreads::SystemClockMillis();
CDVDInputStream *pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, strPath, "");
CFileItem item(strPath, false);
CDVDInputStream *pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, item);
if (!pInputStream)
{
CLog::Log(LOGERROR, "InputStream: Error creating stream for %s", redactPath.c_str());
Expand All @@ -120,7 +122,7 @@ bool CDVDFileInfo::ExtractThumb(const std::string &strPath,
return false;
}

if (!pInputStream->Open(strPath.c_str(), "", true))
if (!pInputStream->Open())
{
CLog::Log(LOGERROR, "InputStream: Error opening, %s", redactPath.c_str());
if (pInputStream)
Expand Down Expand Up @@ -342,7 +344,8 @@ bool CDVDFileInfo::GetFileStreamDetails(CFileItem *pItem)
if (URIUtils::IsStack(playablePath))
playablePath = XFILE::CStackDirectory::GetFirstStackedFile(playablePath);

CDVDInputStream *pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, playablePath, "");
CFileItem item(playablePath, false);
CDVDInputStream *pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, item);
if (!pInputStream)
return false;

Expand All @@ -352,7 +355,7 @@ bool CDVDFileInfo::GetFileStreamDetails(CFileItem *pItem)
return false;
}

if (pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) || !pInputStream->Open(playablePath.c_str(), "", true))
if (pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD) || !pInputStream->Open())
{
delete pInputStream;
return false;
Expand Down
50 changes: 24 additions & 26 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp
Expand Up @@ -39,44 +39,42 @@
#include "utils/URIUtils.h"


CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer, const std::string& file, const std::string& content, bool contentlookup)
CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem)
{
CFileItem item(file.c_str(), false);
std::string file = fileitem.GetPath();

item.SetMimeType(content);

if(item.IsDiscImage())
if (fileitem.IsDiscImage())
{
#ifdef HAVE_LIBBLURAY
CURL url("udf://");
url.SetHostName(file);
url.SetFileName("BDMV/index.bdmv");
if(XFILE::CFile::Exists(url.Get()))
return new CDVDInputStreamBluray(pPlayer);
return new CDVDInputStreamBluray(pPlayer, fileitem);
#endif

return new CDVDInputStreamNavigator(pPlayer);
return new CDVDInputStreamNavigator(pPlayer, fileitem);
}

#ifdef HAS_DVD_DRIVE
if(file.compare(g_mediaManager.TranslateDevicePath("")) == 0)
{
#ifdef HAVE_LIBBLURAY
if(XFILE::CFile::Exists(URIUtils::AddFileToFolder(file, "BDMV/index.bdmv")))
return new CDVDInputStreamBluray(pPlayer);
return new CDVDInputStreamBluray(pPlayer, fileitem);
#endif

return new CDVDInputStreamNavigator(pPlayer);
return new CDVDInputStreamNavigator(pPlayer, fileitem);
}
#endif

if (item.IsDVDFile(false, true))
return (new CDVDInputStreamNavigator(pPlayer));
if (fileitem.IsDVDFile(false, true))
return (new CDVDInputStreamNavigator(pPlayer, fileitem));
else if(file.substr(0, 6) == "pvr://")
return new CDVDInputStreamPVRManager(pPlayer);
return new CDVDInputStreamPVRManager(pPlayer, fileitem);
#ifdef HAVE_LIBBLURAY
else if (item.IsType(".bdmv") || item.IsType(".mpls") || file.substr(0, 7) == "bluray:")
return new CDVDInputStreamBluray(pPlayer);
else if (fileitem.IsType(".bdmv") || fileitem.IsType(".mpls") || file.substr(0, 7) == "bluray:")
return new CDVDInputStreamBluray(pPlayer, fileitem);
#endif
else if(file.substr(0, 6) == "rtp://"
|| file.substr(0, 7) == "rtsp://"
Expand All @@ -86,35 +84,35 @@ CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer
|| file.substr(0, 6) == "mms://"
|| file.substr(0, 7) == "mmst://"
|| file.substr(0, 7) == "mmsh://")
return new CDVDInputStreamFFmpeg();
return new CDVDInputStreamFFmpeg(fileitem);
#ifdef ENABLE_DVDINPUTSTREAM_STACK
else if(file.substr(0, 8) == "stack://")
return new CDVDInputStreamStack();
return new CDVDInputStreamStack(fileitem);
#endif
#ifdef HAS_LIBRTMP
else if(file.substr(0, 7) == "rtmp://"
|| file.substr(0, 8) == "rtmpt://"
|| file.substr(0, 8) == "rtmpe://"
|| file.substr(0, 9) == "rtmpte://"
|| file.substr(0, 8) == "rtmps://")
return new CDVDInputStreamRTMP();
return new CDVDInputStreamRTMP(fileitem);
#endif
else if (item.IsInternetStream())
else if (fileitem.IsInternetStream())
{
if (item.IsType(".m3u8"))
return new CDVDInputStreamFFmpeg();
if (fileitem.IsType(".m3u8"))
return new CDVDInputStreamFFmpeg(fileitem);

if (contentlookup)
if (fileitem.ContentLookup())
{
// request header
item.SetMimeType("");
item.FillInMimeType();
fileitem.SetMimeType("");
fileitem.FillInMimeType();
}

if (item.GetMimeType() == "application/vnd.apple.mpegurl")
return new CDVDInputStreamFFmpeg();
if (fileitem.GetMimeType() == "application/vnd.apple.mpegurl")
return new CDVDInputStreamFFmpeg(fileitem);
}

// our file interface handles all these types of streams
return (new CDVDInputStreamFile());
return (new CDVDInputStreamFile(fileitem));
}
Expand Up @@ -21,12 +21,13 @@
*/

#include <string>
#include "FileItem.h"

class CDVDInputStream;
class IVideoPlayer;

class CDVDFactoryInputStream
{
public:
static CDVDInputStream* CreateInputStream(IVideoPlayer* pPlayer, const std::string& file, const std::string& content, bool contentlookup = true);
static CDVDInputStream* CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem);
};
33 changes: 17 additions & 16 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.cpp
Expand Up @@ -21,39 +21,40 @@
#include "DVDInputStream.h"
#include "URL.h"

CDVDInputStream::CDVDInputStream(DVDStreamType streamType)
CDVDInputStream::CDVDInputStream(DVDStreamType streamType, CFileItem& fileitem)
{
m_streamType = streamType;
m_contentLookup = true;
m_realtime = false;
m_item = fileitem;
}

CDVDInputStream::~CDVDInputStream()
{

}

bool CDVDInputStream::Open(const char* strFile, const std::string &content, bool contentLookup)
bool CDVDInputStream::Open()
{
CURL url(strFile);

m_url = url;
// get rid of any protocol options which might have sneaked in here
// but keep them in m_url.
url.SetProtocolOptions("");
m_strFileName = url.Get();

m_content = content;
m_contentLookup = contentLookup;
m_content = m_item.GetMimeType();
m_contentLookup = m_item.ContentLookup();
return true;
}

void CDVDInputStream::Close()
{
m_strFileName = "";
m_item.Reset();

}

std::string CDVDInputStream::GetFileName()
{
CURL url(m_item.GetPath());

url.SetProtocolOptions("");
return url.Get();
}

void CDVDInputStream::SetFileItem(const CFileItem& item)
CURL CDVDInputStream::GetURL()
{
m_item = item;
return m_item.GetURL();
}
14 changes: 5 additions & 9 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.h
Expand Up @@ -147,17 +147,17 @@ class CDVDInputStream
NEXTSTREAM_RETRY,
};

CDVDInputStream(DVDStreamType m_streamType);
CDVDInputStream(DVDStreamType m_streamType, CFileItem& fileitem);
virtual ~CDVDInputStream();
virtual bool Open(const char* strFileName, const std::string& content, bool contentLookup);
virtual void Close() = 0;
virtual bool Open();
virtual void Close();
virtual int Read(uint8_t* buf, int buf_size) = 0;
virtual int64_t Seek(int64_t offset, int whence) = 0;
virtual bool Pause(double dTime) = 0;
virtual int64_t GetLength() = 0;
virtual std::string& GetContent() { return m_content; };
virtual std::string& GetFileName() { return m_strFileName; }
virtual CURL &GetURL() { return m_url; }
virtual std::string GetFileName();
virtual CURL GetURL();
virtual ENextStream NextStream() { return NEXTSTREAM_NONE; }
virtual void Abort() {}
virtual int GetBlockSize() { return 0; }
Expand All @@ -178,8 +178,6 @@ class CDVDInputStream
virtual bool IsEOF() = 0;
virtual BitstreamStats GetBitstreamStats() const { return m_stats; }

void SetFileItem(const CFileItem& item);

bool ContentLookup() { return m_contentLookup; }

bool IsRealtime() { return m_realtime; }
Expand All @@ -188,8 +186,6 @@ class CDVDInputStream

protected:
DVDStreamType m_streamType;
std::string m_strFileName;
CURL m_url;
BitstreamStats m_stats;
std::string m_content;
CFileItem m_item;
Expand Down
12 changes: 6 additions & 6 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStreamBluray.cpp
Expand Up @@ -183,8 +183,8 @@ void bluray_overlay_argb_cb(void *this_gen, const struct bd_argb_overlay_s * co
}
#endif

CDVDInputStreamBluray::CDVDInputStreamBluray(IVideoPlayer* player) :
CDVDInputStream(DVDSTREAM_TYPE_BLURAY)
CDVDInputStreamBluray::CDVDInputStreamBluray(IVideoPlayer* player, CFileItem& fileitem) :
CDVDInputStream(DVDSTREAM_TYPE_BLURAY, fileitem)
{
m_title = NULL;
m_clip = (uint32_t)-1;
Expand Down Expand Up @@ -260,12 +260,12 @@ BLURAY_TITLE_INFO* CDVDInputStreamBluray::GetTitleFile(const std::string& filena
}


bool CDVDInputStreamBluray::Open(const char* strFile, const std::string& content, bool contentLookup)
bool CDVDInputStreamBluray::Open()
{
if(m_player == NULL)
return false;

std::string strPath(strFile);
std::string strPath(m_item.GetPath());
std::string filename;
std::string root;

Expand Down Expand Up @@ -298,8 +298,8 @@ bool CDVDInputStreamBluray::Open(const char* strFile, const std::string& content
strPath = URIUtils::GetDirectory(strPath);
URIUtils::RemoveSlashAtEnd(strPath);
}
root = strPath;
filename = URIUtils::GetFileName(strFile);
root = strPath;
filename = URIUtils::GetFileName(m_item.GetPath());
}

// root should not have trailing slash
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStreamBluray.h
Expand Up @@ -47,9 +47,9 @@ class CDVDInputStreamBluray
, public CDVDInputStream::IMenus
{
public:
CDVDInputStreamBluray(IVideoPlayer* player);
CDVDInputStreamBluray(IVideoPlayer* player, CFileItem& fileitem);
virtual ~CDVDInputStreamBluray();
virtual bool Open(const char* strFile, const std::string &content, bool contentLookup);
virtual bool Open();
virtual void Close();
virtual int Read(uint8_t* buf, int buf_size);
virtual int64_t Seek(int64_t offset, int whence);
Expand Down
23 changes: 11 additions & 12 deletions xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStreamFFmpeg.cpp
Expand Up @@ -26,8 +26,8 @@

using namespace XFILE;

CDVDInputStreamFFmpeg::CDVDInputStreamFFmpeg()
: CDVDInputStream(DVDSTREAM_TYPE_FFMPEG)
CDVDInputStreamFFmpeg::CDVDInputStreamFFmpeg(CFileItem& fileitem)
: CDVDInputStream(DVDSTREAM_TYPE_FFMPEG, fileitem)
, m_can_pause(false)
, m_can_seek(false)
, m_aborted(false)
Expand All @@ -48,40 +48,39 @@ bool CDVDInputStreamFFmpeg::IsEOF()
return false;
}

bool CDVDInputStreamFFmpeg::Open(const char* strFile, const std::string& content, bool contentLookup)
bool CDVDInputStreamFFmpeg::Open()
{
CFileItem item(strFile, false);
std::string selected;
if (item.IsInternetStream() && (item.IsType(".m3u8") || content == "application/vnd.apple.mpegurl"))
if (m_item.IsInternetStream() && (m_item.IsType(".m3u8") || m_item.GetMimeType() == "application/vnd.apple.mpegurl"))
{
// get the available bandwidth and determine the most appropriate stream
int bandwidth = CSettings::GetInstance().GetInt(CSettings::SETTING_NETWORK_BANDWIDTH);
if(bandwidth <= 0)
bandwidth = INT_MAX;
selected = PLAYLIST::CPlayListM3U::GetBestBandwidthStream(strFile, bandwidth);
if (selected.compare(strFile) != 0)
selected = PLAYLIST::CPlayListM3U::GetBestBandwidthStream(m_item.GetPath(), bandwidth);
if (selected.compare(m_item.GetPath()) != 0)
{
CLog::Log(LOGINFO, "CDVDInputStreamFFmpeg: Auto-selecting %s based on configured bandwidth.", selected.c_str());
strFile = selected.c_str();
m_item.SetPath(selected.c_str());
}
}

if (!CDVDInputStream::Open(strFile, content, contentLookup))
if (!CDVDInputStream::Open())
return false;

m_can_pause = true;
m_can_seek = true;
m_aborted = false;

if(strnicmp(strFile, "udp://", 6) == 0 ||
strnicmp(strFile, "rtp://", 6) == 0)
if(strnicmp(m_item.GetPath().c_str(), "udp://", 6) == 0 ||
strnicmp(m_item.GetPath().c_str(), "rtp://", 6) == 0)
{
m_can_pause = false;
m_can_seek = false;
m_realtime = true;
}

if(strnicmp(strFile, "tcp://", 6) == 0)
if(strnicmp(m_item.GetPath().c_str(), "tcp://", 6) == 0)
{
m_can_pause = true;
m_can_seek = false;
Expand Down

0 comments on commit 6cb7bb4

Please sign in to comment.