Merge pull request #4196 from arnova/sub_fallback
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDInputStreams / DVDInputStreamFFmpeg.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "DVDInputStreamFFmpeg.h"
22 #include "xbmc/playlists/PlayListM3U.h"
23 #include "settings/Settings.h"
24 #include "Util.h"
25 #include "utils/log.h"
26
27 using namespace XFILE;
28
29 CDVDInputStreamFFmpeg::CDVDInputStreamFFmpeg()
30   : CDVDInputStream(DVDSTREAM_TYPE_FFMPEG)
31   , m_can_pause(false)
32   , m_can_seek(false)
33   , m_aborted(false)
34 {
35
36 }
37
38 CDVDInputStreamFFmpeg::~CDVDInputStreamFFmpeg()
39 {
40   Close();
41 }
42
43 bool CDVDInputStreamFFmpeg::IsEOF()
44 {
45   if(m_aborted)
46     return true;
47   else
48     return false;
49 }
50
51 bool CDVDInputStreamFFmpeg::Open(const char* strFile, const std::string& content)
52 {
53   CFileItem item(strFile, false);
54   std::string selected;
55   if (item.IsInternetStream() && item.IsType(".m3u8"))
56   {
57     // get the available bandwidth and  determine the most appropriate stream
58     int bandwidth = CSettings::Get().GetInt("network.bandwidth");
59     if(bandwidth <= 0)
60       bandwidth = INT_MAX;
61     selected = PLAYLIST::CPlayListM3U::GetBestBandwidthStream(strFile, bandwidth);
62     if (selected.compare(strFile) != 0)
63     {
64       CLog::Log(LOGINFO, "CDVDInputStreamFFmpeg: Auto-selecting %s based on configured bandwidth.", selected.c_str());
65       strFile = selected.c_str();
66     }
67   }
68
69   if (!CDVDInputStream::Open(strFile, content))
70     return false;
71
72   m_can_pause = true;
73   m_can_seek  = true;
74   m_aborted   = false;
75
76   if(strnicmp(strFile, "udp://", 6) == 0
77   || strnicmp(strFile, "rtp://", 6) == 0)
78   {
79     m_can_pause = false;
80     m_can_seek  = false;
81   }
82
83   if(strnicmp(strFile, "tcp://", 6) == 0)
84   {
85     m_can_pause = true;
86     m_can_seek  = false;
87   }
88   return true;
89 }
90
91 // close file and reset everyting
92 void CDVDInputStreamFFmpeg::Close()
93 {
94   CDVDInputStream::Close();
95 }
96
97 int CDVDInputStreamFFmpeg::Read(uint8_t* buf, int buf_size)
98 {
99   return -1;
100 }
101
102 int64_t CDVDInputStreamFFmpeg::GetLength()
103 {
104   return 0;
105 }
106
107 int64_t CDVDInputStreamFFmpeg::Seek(int64_t offset, int whence)
108 {
109   return -1;
110 }
111