Skip to content

Commit

Permalink
Sync with Master on recent live TV program transition fixes. Refs #10490
Browse files Browse the repository at this point in the history
  • Loading branch information
stichnot committed Apr 23, 2012
1 parent 9ac4b79 commit 0ecb1d9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/fileringbuffer.cpp
Expand Up @@ -453,8 +453,8 @@ int FileRingBuffer::safe_read(int fd, void *data, uint sz)
tot += ret;
}

//if (oldfile)
//break;
if (oldfile)
break;

if (ret == 0) // EOF returns 0
{
Expand All @@ -465,7 +465,7 @@ int FileRingBuffer::safe_read(int fd, void *data, uint sz)

// 0.36 second timeout for livetvchain with usleep(60000),
// or 2.4 seconds if it's a new file less than 30 minutes old.
if (zerocnt >= (oldfile ? 4 : (livetvchain ? 6 : 40)))
if (zerocnt >= (livetvchain ? 6 : 40))
{
break;
}
Expand Down
25 changes: 24 additions & 1 deletion mythtv/libs/libmythtv/livetvchain.cpp
Expand Up @@ -37,23 +37,31 @@ LiveTVChain::~LiveTVChain()

QString LiveTVChain::InitializeNewChain(const QString &seed)
{
QMutexLocker lock(&m_lock);

QDateTime curdt = QDateTime::currentDateTime();
m_id = QString("live-%1-%2").arg(seed).arg(curdt.toString(Qt::ISODate));
return m_id;
}

void LiveTVChain::SetHostPrefix(const QString &prefix)
{
QMutexLocker lock(&m_lock);

m_hostprefix = prefix;
}

void LiveTVChain::SetCardType(const QString &type)
{
QMutexLocker lock(&m_lock);

m_cardtype = type;
}

void LiveTVChain::LoadFromExistingChain(const QString &id)
{
QMutexLocker lock(&m_lock);

m_id = id;
ReloadAll();
}
Expand Down Expand Up @@ -188,6 +196,8 @@ void LiveTVChain::DeleteProgram(ProgramInfo *pginfo)

void LiveTVChain::BroadcastUpdate(void)
{
QMutexLocker lock(&m_lock);

QString message = QString("LIVETV_CHAIN UPDATE %1").arg(m_id);
MythEvent me(message);
gCoreContext->dispatch(me);
Expand Down Expand Up @@ -357,6 +367,8 @@ int LiveTVChain::GetLengthAtCurPos(void)

int LiveTVChain::TotalSize(void) const
{
QMutexLocker lock(&m_lock);

return m_chain.count();
}

Expand All @@ -373,6 +385,8 @@ void LiveTVChain::SetProgram(const ProgramInfo &pginfo)

bool LiveTVChain::HasNext(void) const
{
QMutexLocker lock(&m_lock);

return ((int)m_chain.count() - 1 > m_curpos);
}

Expand All @@ -397,9 +411,10 @@ void LiveTVChain::ClearSwitch(void)
ProgramInfo *LiveTVChain::GetSwitchProgram(bool &discont, bool &newtype,
int &newid)
{
ReloadAll();
QMutexLocker lock(&m_lock);

ReloadAll();

if (m_switchid < 0 || m_curpos == m_switchid)
{
ClearSwitch();
Expand Down Expand Up @@ -506,6 +521,8 @@ void LiveTVChain::SwitchTo(int num)
*/
void LiveTVChain::SwitchToNext(bool up)
{
QMutexLocker lock(&m_lock);

#if 0
LOG(VB_PLAYBACK, LOG_DEBUG, LOC + "SwitchToNext("<<(up?"up":"down")<<")");
#endif
Expand All @@ -517,12 +534,16 @@ void LiveTVChain::SwitchToNext(bool up)

void LiveTVChain::JumpTo(int num, int pos)
{
QMutexLocker lock(&m_lock);

m_jumppos = pos;
SwitchTo(num);
}

void LiveTVChain::JumpToNext(bool up, int pos)
{
QMutexLocker lock(&m_lock);

m_jumppos = pos;
SwitchToNext(up);
}
Expand All @@ -532,6 +553,8 @@ void LiveTVChain::JumpToNext(bool up, int pos)
*/
int LiveTVChain::GetJumpPos(void)
{
QMutexLocker lock(&m_lock);

int ret = m_jumppos;
m_jumppos = 0;
return ret;
Expand Down
14 changes: 5 additions & 9 deletions mythtv/libs/libmythtv/ringbuffer.cpp
Expand Up @@ -553,6 +553,7 @@ void RingBuffer::KillReadAheadThread(void)
*/
void RingBuffer::StopReads(void)
{
LOG(VB_FILE, LOG_INFO, LOC + "StopReads()");
stopreads = true;
generalWait.wakeAll();
}
Expand All @@ -563,6 +564,7 @@ void RingBuffer::StopReads(void)
*/
void RingBuffer::StartReads(void)
{
LOG(VB_FILE, LOG_INFO, LOC + "StartReads()");
stopreads = false;
generalWait.wakeAll();
}
Expand All @@ -573,6 +575,7 @@ void RingBuffer::StartReads(void)
*/
void RingBuffer::Pause(void)
{
LOG(VB_FILE, LOG_INFO, LOC + "Pause()");
StopReads();

rwlock.lockForWrite();
Expand All @@ -586,6 +589,7 @@ void RingBuffer::Pause(void)
*/
void RingBuffer::Unpause(void)
{
LOG(VB_FILE, LOG_INFO, LOC + "Unpause()");
StartReads();

rwlock.lockForWrite();
Expand Down Expand Up @@ -724,7 +728,6 @@ void RingBuffer::run(void)
struct timeval lastread, now;
int readtimeavg = 300;
bool ignore_for_read_timing = true;
bool did_set_oldfile = false;

gettimeofday(&lastread, NULL); // this is just to keep gcc happy

Expand Down Expand Up @@ -843,13 +846,6 @@ void RingBuffer::run(void)
"Reading enough data to start playback");
}

if (!did_set_oldfile && remotefile && livetvchain &&
livetvchain->HasNext())
{
remotefile->SetTimeout(true);
did_set_oldfile = true;
}

LOG(VB_FILE, LOG_DEBUG, LOC +
QString("safe_read(...@%1, %2) -- begin")
.arg(rbwpos).arg(totfree));
Expand Down Expand Up @@ -922,7 +918,6 @@ void RingBuffer::run(void)
{
livetvchain->SwitchToNext(true);
setswitchtonext = true;
did_set_oldfile = false;
}
}
else
Expand Down Expand Up @@ -1557,6 +1552,7 @@ void RingBuffer::SetWriteBufferMinWriteSize(int newMinSize)
*/
void RingBuffer::SetOldFile(bool is_old)
{
LOG(VB_FILE, LOG_INFO, LOC + QString("SetOldFile(%1)").arg(is_old));
rwlock.lockForWrite();
oldfile = is_old;
rwlock.unlock();
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythtv/tv_rec.cpp
Expand Up @@ -1080,7 +1080,10 @@ void TVRec::TeardownRecorder(uint request_flags)
}

if (ringBuffer)
{
LOG(VB_FILE, LOG_INFO, LOC + "calling StopReads()");
ringBuffer->StopReads();
}

if (curRecording)
{
Expand Down
4 changes: 4 additions & 0 deletions mythtv/programs/mythbackend/filetransfer.cpp
Expand Up @@ -7,6 +7,7 @@
#include "mythmiscutil.h"
#include "mythsocket.h"
#include "programinfo.h"
#include "mythlogging.h"

FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, int timeout_ms) :
Expand Down Expand Up @@ -94,6 +95,7 @@ void FileTransfer::Stop(void)
if (readthreadlive)
{
readthreadlive = false;
LOG(VB_FILE, LOG_INFO, "calling StopReads()");
rbuffer->StopReads();
QMutexLocker locker(&lock);
readsLocked = true;
Expand All @@ -108,6 +110,7 @@ void FileTransfer::Stop(void)

void FileTransfer::Pause(void)
{
LOG(VB_FILE, LOG_INFO, "calling StopReads()");
rbuffer->StopReads();
QMutexLocker locker(&lock);
readsLocked = true;
Expand All @@ -118,6 +121,7 @@ void FileTransfer::Pause(void)

void FileTransfer::Unpause(void)
{
LOG(VB_FILE, LOG_INFO, "calling StartReads()");
rbuffer->StartReads();
{
QMutexLocker locker(&lock);
Expand Down

0 comments on commit 0ecb1d9

Please sign in to comment.