Skip to content

Commit

Permalink
TagLib: Implement a timeout for internet streams
Browse files Browse the repository at this point in the history
  • Loading branch information
fritsch committed Feb 27, 2017
1 parent 42ca760 commit a847221
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion xbmc/music/tags/TagLibVFSStream.cpp
Expand Up @@ -25,14 +25,21 @@
using namespace XFILE;
using namespace TagLib;
using namespace MUSIC_INFO;
#define TAGLIB_INET_STREAM_TIMEOUT 2000

/*!
* Construct a File object and opens the \a file. \a file should be a
* be an XBMC Vfile.
*/
TagLibVFSStream::TagLibVFSStream(const std::string& strFileName, bool readOnly)
TagLibVFSStream::TagLibVFSStream(const std::string& strFileName, bool readOnly, bool isInternetStream)
{
m_bIsOpen = true;

// Construct a timer for internet streams
m_isInternetStream = isInternetStream;
if (m_isInternetStream)
m_extTimer.SetInfinite();

if (readOnly)
{
if (!m_file.Open(strFileName))
Expand Down Expand Up @@ -75,6 +82,9 @@ ByteVector TagLibVFSStream::readBlock(TagLib::ulong length)
else
byteVector.clear();

if (m_isInternetStream && m_extTimer.IsTimePast())
byteVector.clear();

return byteVector;
}

Expand Down Expand Up @@ -248,6 +258,10 @@ bool TagLibVFSStream::isOpen() const
*/
void TagLibVFSStream::seek(long offset, Position p)
{
// set once
if (m_isInternetStream && m_extTimer.IsInfinite())
m_extTimer.Set(TAGLIB_INET_STREAM_TIMEOUT);

const long fileLen = length();
if (m_bIsReadOnly && fileLen > 0)
{
Expand Down
5 changes: 4 additions & 1 deletion xbmc/music/tags/TagLibVFSStream.h
Expand Up @@ -20,6 +20,7 @@
*/
#include "filesystem/File.h"
#include <taglib/tiostream.h>
#include "threads/SystemClock.h"

namespace MUSIC_INFO
{
Expand All @@ -30,7 +31,7 @@ namespace MUSIC_INFO
* Construct a File object and opens the \a file. \a file should be a
* be an XBMC Vfile.
*/
TagLibVFSStream(const std::string& strFileName, bool readOnly);
TagLibVFSStream(const std::string& strFileName, bool readOnly, bool isInternetStream = false);

/*!
* Destroys this ByteVectorStream instance.
Expand Down Expand Up @@ -126,6 +127,8 @@ namespace MUSIC_INFO
XFILE::CFile m_file;
bool m_bIsReadOnly;
bool m_bIsOpen;
XbmcThreads::EndTime m_extTimer;
bool m_isInternetStream = false;
};
}

3 changes: 2 additions & 1 deletion xbmc/music/tags/TagLoaderTagLib.cpp
Expand Up @@ -1053,7 +1053,8 @@ bool CTagLoaderTagLib::Load(const std::string& strFileName, CMusicInfoTag& tag,
}

StringUtils::ToLower(strExtension);
TagLibVFSStream* stream = new TagLibVFSStream(strFileName, true);
bool isInternetStream = URIUtils::IsInternetStream(strFileName);
TagLibVFSStream* stream = new TagLibVFSStream(strFileName, true, isInternetStream);
if (!stream)
{
CLog::Log(LOGERROR, "could not create TagLib VFS stream for: %s", strFileName.c_str());
Expand Down

0 comments on commit a847221

Please sign in to comment.