Skip to content

Commit

Permalink
Convert QDateTime in various services to UTC ASAP. Also fixes three m…
Browse files Browse the repository at this point in the history
…emory leaks in Dvr service.
  • Loading branch information
daniel-kristjansson committed May 31, 2012
1 parent 064ae79 commit b9f7eb1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 69 deletions.
73 changes: 40 additions & 33 deletions mythtv/programs/mythbackend/services/content.cpp
Expand Up @@ -258,13 +258,13 @@ QFileInfo Content::GetRecordingArtwork ( const QString &sType,
//
/////////////////////////////////////////////////////////////////////////////

DTC::ArtworkInfoList* Content::GetRecordingArtworkList( int nChanId,
const QDateTime &dStartTime )
DTC::ArtworkInfoList* Content::GetRecordingArtworkList(
int chanid, const QDateTime &recstarttsRaw)
{
if (nChanId <= 0 || !dStartTime.isValid())
if (chanid <= 0 || !recstarttsRaw.isValid())
throw( QString("Channel ID or StartTime appears invalid."));

ProgramInfo pInfo = ProgramInfo(nChanId, dStartTime);
ProgramInfo pInfo(chanid, recstarttsRaw.toUTC());

return GetProgramArtworkList(pInfo.GetInetRef(), pInfo.GetSeason());
}
Expand Down Expand Up @@ -422,36 +422,38 @@ QFileInfo Content::GetAlbumArt( int nId, int nWidth, int nHeight )
/////////////////////////////////////////////////////////////////////////////

QFileInfo Content::GetPreviewImage( int nChanId,
const QDateTime &dtStartTime,
const QDateTime &recstarttsRaw,
int nWidth,
int nHeight,
int nSecsIn )
{
if (!dtStartTime.isValid())
if (!recstarttsRaw.isValid())
{
QString sMsg = QString("GetPreviewImage: bad start time '%1'")
.arg( dtStartTime.toString(Qt::ISODate) );
.arg(MythDate::toString(recstarttsRaw, MythDate::ISODate));

LOG(VB_GENERAL, LOG_ERR, sMsg);

throw sMsg;
}

QDateTime recstartts = recstarttsRaw.toUTC();

// ----------------------------------------------------------------------
// Read Recording From Database
// ----------------------------------------------------------------------

ProgramInfo pginfo( (uint)nChanId, dtStartTime);
ProgramInfo pginfo( (uint)nChanId, recstartts);

if (!pginfo.GetChanID())
{
LOG(VB_GENERAL, LOG_ERR,
QString( "GetPreviewImage: no recording for start time '%1'" )
.arg( dtStartTime.toString(Qt::ISODate) ));
QString("GetPreviewImage: No recording for '%1'")
.arg(ProgramInfo::MakeUniqueKey(nChanId, recstartts)));
return QFileInfo();
}

if ( pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
if (pginfo.GetHostname().toLower() != gCoreContext->GetHostName().toLower())
{
QString sMsg =
QString("GetPreviewImage: Wrong Host '%1' request from '%2'")
Expand Down Expand Up @@ -575,26 +577,28 @@ QFileInfo Content::GetPreviewImage( int nChanId,
/////////////////////////////////////////////////////////////////////////////

QFileInfo Content::GetRecording( int nChanId,
const QDateTime &dtStartTime )
const QDateTime &recstarttsRaw )
{
if (!dtStartTime.isValid())
if (!recstarttsRaw.isValid())
throw( "StartTime is invalid" );

// ------------------------------------------------------------------
// Read Recording From Database
// ------------------------------------------------------------------

ProgramInfo pginfo( (uint)nChanId, dtStartTime );
QDateTime recstartts = recstarttsRaw.toUTC();

ProgramInfo pginfo((uint)nChanId, recstartts);

if (!pginfo.GetChanID())
{
LOG( VB_UPNP, LOG_ERR, QString("GetRecording - for %1, %2 failed")
.arg( nChanId )
.arg( dtStartTime.toString(Qt::ISODate) ));
LOG(VB_UPNP, LOG_ERR, QString("GetRecording - for '%1' failed")
.arg(ProgramInfo::MakeUniqueKey(nChanId, recstartts)));

return QFileInfo();
}

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

Expand Down Expand Up @@ -920,33 +924,36 @@ DTC::LiveStreamInfoList *Content::GetFilteredLiveStreamList( const QString &Fi
//
/////////////////////////////////////////////////////////////////////////////

DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nChanId,
const QDateTime &dtStartTime,
int nMaxSegments,
int nWidth,
int nHeight,
int nBitrate,
int nAudioBitrate,
int nSampleRate )
DTC::LiveStreamInfo *Content::AddRecordingLiveStream(
int nChanId,
const QDateTime &recstarttsRaw,
int nMaxSegments,
int nWidth,
int nHeight,
int nBitrate,
int nAudioBitrate,
int nSampleRate )
{
if (!dtStartTime.isValid())
if (!recstarttsRaw.isValid())
throw( "StartTime is invalid" );

// ------------------------------------------------------------------
// Read Recording From Database
// ------------------------------------------------------------------

ProgramInfo pginfo( (uint)nChanId, dtStartTime );
QDateTime recstartts = recstarttsRaw.toUTC();

ProgramInfo pginfo((uint)nChanId, recstartts);

if (!pginfo.GetChanID())
{
LOG( VB_UPNP, LOG_ERR, QString("AddRecordingLiveStream - for %1, %2 failed")
.arg( nChanId )
.arg( dtStartTime.toString() ));
LOG(VB_UPNP, LOG_ERR,
QString("AddRecordingLiveStream - for %1, %2 failed")
.arg(ProgramInfo::MakeUniqueKey(nChanId, recstartts)));
return NULL;
}

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

Expand All @@ -970,7 +977,7 @@ DTC::LiveStreamInfo *Content::AddRecordingLiveStream( int nChanId,
{
LOG( VB_UPNP, LOG_ERR, QString("AddRecordingLiveStream - for %1, %2 failed")
.arg( nChanId )
.arg( dtStartTime.toString() ));
.arg( recstartts.toString() ));
return NULL;
}

Expand Down
53 changes: 24 additions & 29 deletions mythtv/programs/mythbackend/services/dvr.cpp
Expand Up @@ -156,16 +156,15 @@ DTC::ProgramList* Dvr::GetFilteredRecordedList( bool bDescending,
//
/////////////////////////////////////////////////////////////////////////////

DTC::Program* Dvr::GetRecorded( int nChanId,
const QDateTime &dStartTime )
DTC::Program* Dvr::GetRecorded(int chanid, const QDateTime &recstarttsRaw)
{
if (nChanId <= 0 || !dStartTime.isValid())
throw( QString("Channel ID or StartTime appears invalid."));
if (chanid <= 0 || !recstarttsRaw.isValid())
throw QString("Channel ID or StartTime appears invalid.");

ProgramInfo *pInfo = new ProgramInfo(nChanId, dStartTime);
ProgramInfo pi(chanid, recstarttsRaw.toUTC());

DTC::Program *pProgram = new DTC::Program();
FillProgramInfo( pProgram, pInfo, true );
FillProgramInfo( pProgram, &pi, true );

return pProgram;
}
Expand All @@ -174,28 +173,25 @@ DTC::Program* Dvr::GetRecorded( int nChanId,
//
/////////////////////////////////////////////////////////////////////////////

bool Dvr::RemoveRecorded( int nChanId,
const QDateTime &dStartTime )
bool Dvr::RemoveRecorded(int chanid, const QDateTime &recstarttsRaw)
{
if (nChanId <= 0 || !dStartTime.isValid())
throw( QString("Channel ID or StartTime appears invalid."));
if (chanid <= 0 || !recstarttsRaw.isValid())
throw QString("Channel ID or StartTime appears invalid.");

bool bResult = false;

ProgramInfo *pInfo = new ProgramInfo(nChanId, dStartTime);
ProgramInfo pi(chanid, recstarttsRaw.toUTC());

QString cmd = QString("DELETE_RECORDING %1 %2")
.arg(nChanId)
.arg(dStartTime.toString(Qt::ISODate));
MythEvent me(cmd);

if (pInfo->HasPathname())
if (pi.GetChanID() && pi.HasPathname())
{
QString cmd = QString("DELETE_RECORDING %1 %2")
.arg(pi.GetChanID())
.arg(pi.GetRecordingStartTime(MythDate::ISODate));
MythEvent me(cmd);

gCoreContext->dispatch(me);
bResult = true;
return true;
}

return bResult;
return false;
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -420,8 +416,8 @@ DTC::ProgramList* Dvr::GetConflictList( int nStartIndex,
return pPrograms;
}

int Dvr::AddRecordSchedule ( int nChanId,
QDateTime dStartTime,
int Dvr::AddRecordSchedule ( int chanid,
QDateTime recstarttsRaw,
int nParentId,
bool bInactive,
uint nSeason,
Expand Down Expand Up @@ -453,8 +449,10 @@ int Dvr::AddRecordSchedule ( int nChanId,
bool bAutoUserJob4,
int nTranscoder)
{
RecordingInfo *info = new RecordingInfo(nChanId, dStartTime, false);
RecordingRule *rule = info->GetRecordingRule();
QDateTime recstartts = recstarttsRaw.toUTC();
RecordingInfo info(chanid, recstartts, false);
RecordingRule *rule = info.GetRecordingRule();
// ^ rule is owned by info and deleted when it leaves scope

if (sType.isEmpty())
sType = "single";
Expand All @@ -468,7 +466,7 @@ int Dvr::AddRecordSchedule ( int nChanId,
if (sDupIn.isEmpty())
sDupIn = "all";

rule->m_title = info->GetTitle();
rule->m_title = info.GetTitle();
rule->m_type = recTypeFromString(sType);
rule->m_searchType = searchTypeFromString(sSearchType);
rule->m_dupMethod = dupMethodFromString(sDupMethod);
Expand Down Expand Up @@ -524,9 +522,6 @@ int Dvr::AddRecordSchedule ( int nChanId,

int recid = rule->m_recordID;

delete rule;
rule = NULL;

return recid;
}

Expand Down
18 changes: 11 additions & 7 deletions mythtv/programs/mythbackend/services/guide.cpp
Expand Up @@ -37,19 +37,21 @@ extern Scheduler *sched;
//
/////////////////////////////////////////////////////////////////////////////

DTC::ProgramGuide *Guide::GetProgramGuide( const QDateTime &dtStartTime ,
const QDateTime &dtEndTime ,
DTC::ProgramGuide *Guide::GetProgramGuide( const QDateTime &rawStartTime ,
const QDateTime &rawEndTime ,
int nStartChanId,
int nNumChannels,
bool bDetails )
{

if (!dtStartTime.isValid())
if (!rawStartTime.isValid())
throw( "StartTime is invalid" );

if (!dtEndTime.isValid())
if (!rawEndTime.isValid())
throw( "EndTime is invalid" );

QDateTime dtStartTime = rawStartTime.toUTC();
QDateTime dtEndTime = rawEndTime.toUTC();

if (dtEndTime < dtStartTime)
throw( "EndTime is before StartTime");

Expand Down Expand Up @@ -162,12 +164,14 @@ DTC::ProgramGuide *Guide::GetProgramGuide( const QDateTime &dtStartTime ,
/////////////////////////////////////////////////////////////////////////////

DTC::Program* Guide::GetProgramDetails( int nChanId,
const QDateTime &dtStartTime )
const QDateTime &rawStartTime )

{
if (!dtStartTime.isValid())
if (!rawStartTime.isValid())
throw( "StartTime is invalid" );

QDateTime dtStartTime = rawStartTime.toUTC();

// ----------------------------------------------------------------------
// -=>TODO: Add support for getting Recorded Program Info
// ----------------------------------------------------------------------
Expand Down

0 comments on commit b9f7eb1

Please sign in to comment.