Skip to content

Commit

Permalink
Live TV: Delay opening a new ringbuffer until the TVChain is updated.
Browse files Browse the repository at this point in the history
Refs #10490.  The problem is that at a program transition, the new
ringbuffer was opened before the TVChain was advanced, so the new
ringbuffer readahead thread was immediately setting the oldfile flag
on the remote ringbuffer, leading to premature EOF.

Additional logging is added to track setting of oldfile and stopreads,
for easier future debugging.
  • Loading branch information
stichnot committed Apr 21, 2012
1 parent f4d7bff commit 7c7852f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -2446,6 +2446,7 @@ void MythPlayer::SwitchToProgram(void)
return;
}

#if 0
player_ctx->buffer->OpenFile(
pginfo->GetPlaybackURL(), RingBuffer::kLiveTVOpenTimeout);

Expand All @@ -2460,6 +2461,7 @@ void MythPlayer::SwitchToProgram(void)
delete pginfo;
return;
}
#endif

if (GetEof())
{
Expand All @@ -2476,6 +2478,30 @@ void MythPlayer::SwitchToProgram(void)
player_ctx->tvchain->SetProgram(*pginfo);
if (decoder)
decoder->SetProgramInfo(*pginfo);
}

player_ctx->buffer->OpenFile(
pginfo->GetPlaybackURL(), RingBuffer::kLiveTVOpenTimeout);

if (!player_ctx->buffer->IsOpen())
{
LOG(VB_GENERAL, LOG_ERR, LOC + "SwitchToProgram's OpenFile failed " +
QString("(card type: %1).")
.arg(player_ctx->tvchain->GetCardType(newid)));
LOG(VB_GENERAL, LOG_ERR, player_ctx->tvchain->toString());
SetEof(true);
SetErrored(QObject::tr("Error opening switch program buffer"));
delete pginfo;
return;
}

if (discontinuity || newtype)
{
#if 0
player_ctx->tvchain->SetProgram(*pginfo);
if (decoder)
decoder->SetProgramInfo(*pginfo);
#endif

player_ctx->buffer->Reset(true);
if (newtype)
Expand Down
5 changes: 5 additions & 0 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 @@ -1557,6 +1561,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 7c7852f

Please sign in to comment.