Skip to content

Commit

Permalink
Content API: Add GetVideoLiveStream convenience API.
Browse files Browse the repository at this point in the history
Similar to the other GetLiveStream methods, accept transcode
parameters, but take the video ID as the key argument.

Usage (simplified, takes all normal live stream parameters):

http://BackendServerIP:6544/Content/GetVideoLiveStream?Id=100
  • Loading branch information
Robert McNamara committed Dec 3, 2011
1 parent a512562 commit bdc9615
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
Expand Up @@ -132,6 +132,14 @@ class SERVICE_PUBLIC ContentServices : public Service //, public QScriptable ??
const QString &AudioBitrate,
const QString &SampleRate ) = 0;

virtual DTC::LiveStreamInfo *AddVideoLiveStream ( int Id,
const QString &MaxSegments,
const QString &Width,
const QString &Height,
const QString &Bitrate,
const QString &AudioBitrate,
const QString &SampleRate ) = 0;

virtual DTC::LiveStreamInfo *GetLiveStream ( int Id ) = 0;
virtual DTC::LiveStreamInfoList *GetLiveStreamList ( void ) = 0;

Expand Down
69 changes: 66 additions & 3 deletions mythtv/programs/mythbackend/services/content.cpp
Expand Up @@ -38,6 +38,7 @@
#include "mythdownloadmanager.h"
#include "metadataimagehelper.h"
#include "httplivestream.h"
#include "videometadatalistmanager.h"

/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -450,7 +451,7 @@ QFileInfo Content::GetPreviewImage( int nChanId,
return QFileInfo();
}

if ( pginfo.GetHostname() != gCoreContext->GetHostName())
if ( pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
{
QString sMsg =
QString("GetPreviewImage: Wrong Host '%1' request from '%2'")
Expand Down Expand Up @@ -593,7 +594,7 @@ QFileInfo Content::GetRecording( int nChanId,
return QFileInfo();
}

if ( pginfo.GetHostname() != gCoreContext->GetHostName())
if ( pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
{
// We only handle requests for local resources

Expand Down Expand Up @@ -952,6 +953,7 @@ DTC::LiveStreamInfo *Content::GetLiveStream( int nId )
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

DTC::LiveStreamInfoList *Content::GetLiveStreamList( void )
{
return HTTPLiveStream::GetLiveStreamInfoList();
Expand All @@ -960,6 +962,7 @@ DTC::LiveStreamInfoList *Content::GetLiveStreamList( void )
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nChanId,
const QDateTime &dtStartTime,
const QString &sMaxSegments,
Expand All @@ -986,7 +989,7 @@ DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nChanId,
return NULL;
}

if ( pginfo.GetHostname() != gCoreContext->GetHostName())
if ( pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
{
// We only handle requests for local resources

Expand Down Expand Up @@ -1020,3 +1023,63 @@ DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nChanId,
pginfo.GetHostname(), sMaxSegments, sWidth,
sHeight, sBitrate, sAudioBitrate, sSampleRate );
}

/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////

DTC::LiveStreamInfo *Content::AddVideoLiveStream( int nId,
const QString &sMaxSegments,
const QString &sWidth,
const QString &sHeight,
const QString &sBitrate,
const QString &sAudioBitrate,
const QString &sSampleRate )
{
if (nId < 0)
throw( "Id is invalid" );

VideoMetadataListManager::VideoMetadataPtr metadata =
VideoMetadataListManager::loadOneFromDatabase(nId);

if (!metadata)
{
LOG( VB_UPNP, LOG_ERR, QString("AddVideoLiveStream - no metadata for %1")
.arg( nId ));
return NULL;
}

if ( metadata->GetHost().toLower() != gCoreContext->GetHostName().toLower())
{
// We only handle requests for local resources

QString sMsg =
QString("AddVideoLiveStream: Wrong Host '%1' request from '%2'.")
.arg( gCoreContext->GetHostName())
.arg( metadata->GetHost() );

LOG(VB_UPNP, LOG_ERR, sMsg);

throw HttpRedirectException( metadata->GetHost() );
}

StorageGroup sg("Videos", metadata->GetHost());
QString sFileName = sg.FindFile(metadata->GetFilename());

// ----------------------------------------------------------------------
// check to see if the file exists
// ----------------------------------------------------------------------

if (!QFile::exists( sFileName ))
{
LOG( VB_UPNP, LOG_ERR, QString("AddVideoLiveStream - file does not exist."));
return NULL;
}

QFileInfo fInfo( sFileName );

return AddLiveStream( "Videos", fInfo.fileName(),
metadata->GetHost(), sMaxSegments, sWidth,
sHeight, sBitrate, sAudioBitrate, sSampleRate );

}
8 changes: 8 additions & 0 deletions mythtv/programs/mythbackend/services/content.h
Expand Up @@ -101,6 +101,14 @@ class Content : public ContentServices
const QString &AudioBitrate,
const QString &SampleRate );

DTC::LiveStreamInfo *AddVideoLiveStream ( int Id,
const QString &MaxSegments,
const QString &Width,
const QString &Height,
const QString &Bitrate,
const QString &AudioBitrate,
const QString &SampleRate );

DTC::LiveStreamInfo *GetLiveStream ( int Id );
DTC::LiveStreamInfoList *GetLiveStreamList ( void );

Expand Down

0 comments on commit bdc9615

Please sign in to comment.