Wrap InputStream in a File (for MediaPortal TVserver client in XBMC)

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
spiff Offline
Grumpy Bastard Developer
Posts: 12,181
Joined: Nov 2003
Reputation: 82
Post: #11
you need to

1) add a DVDSTREAM_TYPE_TVSERVER and assign this to your class in the factory, e.g. tvserver://
2) have a CDVDInputStreamFFMPEG as a member var
3) do the tvserver parsing to get the real rtsp url
4) open your member var on this url
5) make Read() etc in tvserver wrapper functions which calls through to your member var input stream

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
EvilDude Offline
Senior Member
Posts: 106
Joined: Feb 2006
Reputation: 0
Location: Sydney Australia
Post: #12
Hm, I have managed to get it working:
http://pastebin.com/m1bc4159b

I haven't yet tried to get channel + / - working.

The main thing that I couldn't figure out earlier, I had to do this:
Code:
+  else if (m_pInput->IsStreamType(DVDSTREAM_TYPE_TVSERVER))
+  {
+    // we have a tv server file, but it wraps rtsp, an internal ffmpeg protocol
+    
+    CTVServerFile *tvServerFile = static_cast<CTVServerFile*>(pInput);
+    const CStdString rtspUrl = tvServerFile->GetRTSPStream();
+    CLog::Log(LOGERROR, "About to open a TVSERVER stream: %s\n", rtspUrl.c_str());
+    // supposedly speeds up opening live tv
+    // m_pFormatContext->max_analyze_duration = 500000;
+    
+    if( m_dllAvFormat.av_open_input_file(&m_pFormatContext, rtspUrl.c_str(), iformat, FFMPEG_FILE_BUFFER_SIZE, NULL) < 0 )

Basically opens the actual RTSP file using internal ffmpeg libraries. Wrapping read etc doesn't work because rtsp is internal to ffmpeg. It looks like it works now - just want to make sure its the right way to do it. It takes ages to open a file at the moment - where can I disable caching?

Also, a small bug in the code I found:
Code:
cores/dvdplayer/DVDInputStreams/DVDFactoryInputStream.cpp:55:       || file.substr(0, 7) == "cmyth://"
cores/dvdplayer/DVDInputStreams/DVDFactoryInputStream.cpp:56:       || file.substr(0, 7) == "gmyth://")

I am quite sure substr's second argument should be 8.
find quote
spiff Offline
Grumpy Bastard Developer
Posts: 12,181
Joined: Nov 2003
Reputation: 82
Post: #13
thx, typos fixed in svn

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
Gamester17 Offline
Team-XBMC Forum Moderator
Posts: 10,595
Joined: Sep 2003
Reputation: 9
Location: Sweden
Thumbs Up  Great stuff! Post: #14
@EvilDude, have you looked at the MythTV client ("mythtv://") in XBMC for reference and comparison?

Confused

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
spiff Offline
Grumpy Bastard Developer
Posts: 12,181
Joined: Nov 2003
Reputation: 82
Post: #15
see DVDDemuxFFmpeg.cpp - replicate what's done for DVDSTREAM_TYPE_FFMPEG there

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
EvilDude Offline
Senior Member
Posts: 106
Joined: Feb 2006
Reputation: 0
Location: Sydney Australia
Post: #16
Gamester17: Yes that is what I initially based my design on - the myth:// code.

spiff: Yep that's what I'm doing. I tried manually loading the rtsp url (made a .strm file with the URL in it), and it turns out it's still caching. The xbox version does not seem to cache rtsp streams, yet the linux port does. I am not sure why yet.
find quote
Gamester17 Offline
Team-XBMC Forum Moderator
Posts: 10,595
Joined: Sep 2003
Reputation: 9
Location: Sweden
Thumbs Up  Please submit patch(es) for review... Post: #17
http://forum.team-mediaportal.com/genera...post277808
EvilDude Wrote:I have a patch (for xbmc linux at least, haven't tried with the xbox port but I'm hoping it works fine)
http://pastebin.com/m1bc4159b

It adds very basic native support to XBMC. The Python script is probably still better at this point Tongue However, this will hopefully eventually let me do channel+/- directly while watching. The python script is still faster, as it doesn't cache whereas this attempts to cache.

Developers: is it possible to switch channel without new graph, basically having to close the last stream etc? Or at least, is it possible to somehow get a change channel thing that will keep the stream going (with blank frames), as it would be much faster than closing and reopening the stream after changing a channel.

@EvilDude, patch would be more than welcomed, please see:
http://wiki.xbmc.org/?title=HOW-TO_submit_a_patch
http://wiki.xbmc.org/?title=Appendix_D:_...ment_Notes

Submitting the patch for review is the first step to get it accepted to the SVN

Nod

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
EvilDude Offline
Senior Member
Posts: 106
Joined: Feb 2006
Reputation: 0
Location: Sydney Australia
Post: #18
Ok thanks, posted it here
https://sourceforge.net/tracker/index.ph...tid=581840
find quote
leo2 Offline
Skilled Python Coder
Posts: 176
Joined: Jun 2008
Reputation: 0
Post: #19
Hi, I'm happy that someone is working on an integration of MP TV Server & XBMC, both software are great!
is the patch applied to the svn? if so, EvilDude, can u please describe how do I work with that?
I'm a programmer myself and I would be happy to assist improving the integration between MPTVServer & XBMC.

leo
find quote
Gamester17 Offline
Team-XBMC Forum Moderator
Posts: 10,595
Joined: Sep 2003
Reputation: 9
Location: Sweden
Post: #20
leo2 Wrote:is the patch applied to the svn?
No, elupus will need to review it but he is currently away on holiday, and spiff already asked for some changes:
Quote:not a real review, just some stuff i noticed right away..

Index: xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
===================================================================
--- xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp (revision 13756)
+++ xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp (working copy)
@@ -259,6 +260,25 @@
[...]
+ if( m_dllAvFormat.av_open_input_file(&m_pFormatContext,
rtspUrl.c_str(), iformat, FFMPEG_FILE_BUFFER_SIZE, NULL) < 0 )
+ {
+ CLog::Log(LOGDEBUG, "Error, could not open tv server file %s",
strFile.c_str());
+ Dispose();
+ return false;
+ }
+ CLog::Log(LOGERROR, "SUCCESS??!?\n");
+
+ }
this block is shared with the stream_type_ffmpeg one

else
{
g_urltimeout = 0;
@@ -318,6 +338,7 @@

// read data using avformat's buffers
pd.buf_size = m_dllAvFormat.get_buffer(m_ioContext, pd.buf,
sizeof(probe_buffer));
+
unrelated cosmetics

if (pd.buf_size == 0)
{
CLog::Log(LOGERROR, "%s - error reading from input stream, %s",
__FUNCTION__, strFile.c_str());
Index: xbmc/cores/dvdplayer/DVDInputStreams/DVDFactoryInputStream.cpp
===================================================================
---
xbmc/cores/dvdplayer/DVDInputStreams/DVDFactoryInputStream.cpp (revision
13756)
+++
xbmc/cores/dvdplayer/DVDInputStreams/DVDFactoryInputStream.cpp (working
copy)
@@ -52,7 +54,10 @@
else if(file.substr(0, 7) == "myth://"
|| file.substr(0, 8) == "cmyth://"
|| file.substr(0, 8) == "gmyth://")
+ //|| file.substr(0, 10) == "tvserver://")
?

Index: xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamFile.cpp
===================================================================
--- xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamFile.cpp (revision
13756)
+++ xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamFile.cpp (working
copy)
@@ -54,6 +54,7 @@
if( CFileItem(strFile, false).IsInternetStream() )
flags |= READ_CACHED;

+ CLog::Log(LOGERROR, "ABOUT TO OPEN A FILE!! file is %s", strFile);
please remove

#define DVDSTREAM_BLOCK_SIZE_FILE (2048 * 16)
Index: xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.cpp
===================================================================
--- xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.cpp (revision 0)
+++ xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.cpp (revision 0)
@@ -0,0 +1,256 @@
[..]
+ if(nret) return false;
separate line please

+ CStdString result = c.StartTimeshift(channelId);
+ CLog::Log(LOGERROR, "Start timeshift returned %s", result.c_str());
+ c.Disconnect();
+
+ if(result.substr(0, 7) == "[ERROR]") return false;
ditto
+ rtspFile = new CDVDInputStreamFFmpeg();
+ if(!rtspFile) return false;
ditto

+ rtspFileUrl = result;
+ CLog::Log(LOGERROR, "WE HAVE SUCCESSFULLY MADE AN INPUT STREAM!!\n");
+
+
+ bool openFile = rtspFile->Open(result,"application/rtsl");
+ CLog::Log(LOGERROR, "Open file result %d\n", openFile);
+
+
+ return openFile;
+}
+


+
+
+bool CTVServerFile::Open(const char* strFile, const std::string
&content){
braces on separate lines please. everywhere

+const CStdString CTVServerFile::GetRTSPStream()
+{
+ return this->rtspFileUrl;
+}
+
+
+void CTVServerFile::Close()
+{
+ if(rtspFile) rtspFile->Close();

separate

+ /*
+ if(!m_dll)
+ return;
+
+ if(m_program)
+ {
+ m_dll->ref_release(m_program);
+ m_program = NULL;
+ }
+ if(m_recorder)
+ {
+ m_dll->recorder_stop_livetv(m_recorder);
+ m_dll->ref_release(m_recorder);
+ m_recorder = NULL;
+ }
+ if(m_file)
+ {
+ m_dll->ref_release(m_file);
+ m_file = NULL;
+ }
+ if(m_session)
+ {
+ m_session->SetListener(NULL);
+ CCMythSession::ReleaseSession(m_session);
+ m_session = NULL;
+ }
+ */

remove. no new commented code
+}
+
+CTVServerFile::CTVServerFile() :
CDVDInputStream(DVDSTREAM_TYPE_TVSERVER)
+{
+
+ rtspFile = NULL;
+
+ CLog::Log(LOGERROR, "CTVServerFILE!!!!!");
remove. in general get rid of these or atleast put them at debug level
+}
+
+CTVServerFile::~CTVServerFile()
+{
+ if (rtspFile) rtspFile->Close();
ndex: xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.h
===================================================================
--- xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.h (revision 0)
+++ xbmc/cores/dvdplayer/DVDInputStreams/TVServerFile.h (revision 0)
@@ -0,0 +1,58 @@
[...]
+using namespace XFILE;

big no. no using of namespaces in headers, it means all code after the
inclusion of this header is using it.

Index: xbmc/FileSystem/ILiveTV.h
===================================================================
--- xbmc/FileSystem/ILiveTV.h (revision 13756)
+++ xbmc/FileSystem/ILiveTV.h (working copy)
@@ -1,3 +1,6 @@
+#ifndef __I_LIVETV__H__
+#define __I_LIVETV__H__
+

identifiers starting with _ is reserved for the compiler

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote