Skip to content

Commit

Permalink
Revert "MHEG: Fixes for InteractionChannel streaming from network URI's"
Browse files Browse the repository at this point in the history
This reverts commit ea77f42.
  • Loading branch information
stuartm committed Sep 8, 2013
1 parent cd1a5e1 commit f3600da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 68 deletions.
20 changes: 8 additions & 12 deletions mythtv/libs/libmythtv/mhi.cpp
Expand Up @@ -437,13 +437,10 @@ bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result)
// same thread this is safe. Otherwise we need to make a deep copy of
// the result.

QMutexLocker locker(&m_runLock);
bool bReported = false;
QTime t; t.start();
while (!m_stop)
{
locker.unlock();

if (isIC)
{
switch (m_ic.GetFile(objectPath, result, cert))
Expand Down Expand Up @@ -490,9 +487,7 @@ bool MHIContext::GetCarouselData(QString objectPath, QByteArray &result)
// some more packets. We should eventually find out if this item is
// present.
ProcessDSMCCQueue();

locker.relock();
m_engine_wait.wait(locker.mutex(), 300);
m_engine_wait.wait(&m_runLock, 300);
}
return false; // Stop has been set. Say the object isn't present.
}
Expand Down Expand Up @@ -607,9 +602,10 @@ bool MHIContext::OfferKey(QString key)
.arg(key).arg(action).arg(m_keyQueue.size()) );
{ QMutexLocker locker(&m_keyLock);
m_keyQueue.enqueue(action);}
QMutexLocker locker2(&m_runLock);
m_engine_wait.wakeAll();
return true;
// Accept the key except 'exit' (16) in 'always available' (3) state.
// This allows re-use of Esc as TEXTEXIT for RC's with a single backup button
return action != 16 || m_keyProfile != 3;
}

// Called from MythPlayer::VideoStart and MythPlayer::ReinitOSD
Expand Down Expand Up @@ -1033,7 +1029,7 @@ void MHIContext::EndStream()
// Callback from MythPlayer when a stream starts or stops
bool MHIContext::StreamStarted(bool bStarted)
{
if (!m_engine || !m_notify)
if (!m_notify)
return false;

LOG(VB_MHEG, LOG_INFO, QString("[mhi] Stream 0x%1 %2")
Expand All @@ -1059,7 +1055,7 @@ bool MHIContext::BeginAudio(int tag)
return m_parent->GetNVP()->SetAudioByComponentTag(tag);
return false;
}

// Stop playing audio
void MHIContext::StopAudio()
{
Expand All @@ -1073,13 +1069,13 @@ bool MHIContext::BeginVideo(int tag)

if (tag < 0)
return true; // Leave it at the default.

m_videoTag = tag;
if (m_parent->GetNVP())
return m_parent->GetNVP()->SetVideoByComponentTag(tag);
return false;
}

// Stop displaying video
void MHIContext::StopVideo()
{
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -933,8 +933,7 @@ int MythPlayer::OpenFile(uint retries)
MythTimer peekTimer; peekTimer.start();
while (player_ctx->buffer->Peek(testbuf, testreadsize) != testreadsize)
{
// NB need to allow for streams encountering network congestion
if (peekTimer.elapsed() > 5000 || bigTimer.elapsed() > timeout)
if (peekTimer.elapsed() > 1000 || bigTimer.elapsed() > timeout)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("OpenFile(): Could not read first %1 bytes of '%2'")
Expand Down
72 changes: 24 additions & 48 deletions mythtv/libs/libmythtv/netstream.cpp
Expand Up @@ -49,7 +49,6 @@ using std::getenv;
*/
static QAtomicInt s_nRequest(1); // Unique NetStream request ID
static QMutex s_mtx; // Guard local static data e.g. NAMThread singleton
const qint64 kMaxBuffer = 4 * 1024 * 1024L; // 0= unlimited, 1MB => 4secs @ 1.5Mbps


/*
Expand Down Expand Up @@ -176,7 +175,7 @@ bool NetStream::Request(const QUrl& url)

if (m_reply)
{
// Abort the current reply
// Abort the current request
// NB the abort method appears to only work if called from NAMThread
m_reply->disconnect(this);
NAMThread::PostEvent(new NetStreamAbort(m_id, m_reply));
Expand Down Expand Up @@ -260,9 +259,8 @@ bool NetStream::Request(const QUrl& url)
}
#endif

LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Request %2 bytes=%3- from %4")
.arg(m_id).arg(m_request.url().toString())
.arg(m_pos).arg(Source(m_request)) );
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Requesting %2 from %3")
.arg(m_id).arg(m_request.url().toString()).arg(Source(m_request)) );
m_pending = new NetStreamRequest(m_id, m_request);
NAMThread::PostEvent(m_pending);
return true;
Expand All @@ -280,13 +278,12 @@ void NetStream::slotRequestStarted(int id, QNetworkReply *reply)

if (!m_reply)
{
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Started 0x%2")
.arg(m_id).arg(quintptr(reply),0,16) );
LOG(VB_FILE, LOG_DEBUG, LOC + QString("(%1) Started %2-").arg(m_id).arg(m_pos) );

m_reply = reply;
m_state = kStarted;

reply->setReadBufferSize(kMaxBuffer);
reply->setReadBufferSize(4*1024*1024L); // 0= unlimited, 1MB => 4secs @ 1.5Mbps

// NB The following signals must be Qt::DirectConnection 'cos this slot
// was connected Qt::DirectConnection so the current thread is NAMThread
Expand Down Expand Up @@ -360,28 +357,23 @@ void NetStream::slotReadyRead()

if (m_reply)
{
qint64 avail = m_reply->bytesAvailable();
LOG(VB_FILE, (avail <= 2 * kMaxBuffer) ? LOG_DEBUG :
(avail <= 4 * kMaxBuffer) ? LOG_INFO : LOG_WARNING,
LOC + QString("(%1) Ready 0x%2, %3 bytes available").arg(m_id)
.arg(quintptr(m_reply),0,16).arg(avail) );
LOG(VB_FILE, LOG_DEBUG, LOC + QString("(%1) Ready %2 bytes")
.arg(m_id).arg(m_reply->bytesAvailable()) );

if (m_size < 0 || m_state < kReady)
if (m_size < 0)
{
qlonglong first, last, len = ContentRange(m_reply, first, last);
if (len >= 0)
{
m_size = len;
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Ready 0x%2, range %3-%4/%5")
.arg(m_id).arg(quintptr(m_reply),0,16).arg(first).arg(last).arg(len) );
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) range %2-%3/%4")
.arg(m_id).arg(first).arg(last).arg(len) );
}
else
{
m_size = ContentLength(m_reply);
if (m_state < kReady || m_size >= 0)
LOG(VB_FILE, LOG_INFO, LOC +
QString("(%1) Ready 0x%2, content length %3")
.arg(m_id).arg(quintptr(m_reply),0,16).arg(m_size) );
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) content length %2")
.arg(m_id).arg(m_size) );
}
}

Expand Down Expand Up @@ -443,11 +435,8 @@ void NetStream::slotFinished()

if (m_state == kFinished)
{
if (m_size < 0)
m_size = m_pos + m_reply->size();

LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Finished 0x%2 %3/%4 bytes from %5")
.arg(m_id).arg(quintptr(m_reply),0,16).arg(m_pos).arg(m_size).arg(Source(m_reply)) );
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Finished %2/%3 bytes from %4")
.arg(m_id).arg(m_pos).arg(m_size).arg(Source(m_reply)) );

locker.unlock();
emit Finished(this);
Expand Down Expand Up @@ -528,12 +517,9 @@ void NetStream::Abort()
m_pending = 0;
}

if (m_reply)
if (m_reply && m_reply->isRunning())
{
if (m_state >= kStarted && m_state < kFinished)
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Abort 0x%2")
.arg(m_id).arg(quintptr(m_reply),0,16) );

LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) Abort").arg(m_id) );
NAMThread::PostEvent(new NetStreamAbort(m_id, m_reply));
// NAMthread will delete the reply
m_reply = 0;
Expand All @@ -558,9 +544,6 @@ int NetStream::safe_read(void *data, unsigned sz, unsigned millisecs /* = 0 */)
m_ready.wait(&m_mutex, millisecs - elapsed);
}

locker.unlock();
QMutexLocker lockNAM(NAMThread::GetMutex());
locker.relock();
if (!m_reply)
return -1;

Expand Down Expand Up @@ -729,7 +712,7 @@ NAMThread & NAMThread::manager()
return thread;
}

NAMThread::NAMThread() : m_bQuit(false), m_mutexNAM(QMutex::Recursive), m_nam(0)
NAMThread::NAMThread() : m_bQuit(false), m_nam(0)
{
setObjectName("NAMThread");

Expand Down Expand Up @@ -792,25 +775,18 @@ void NAMThread::run()

m_running.release();

QMutexLocker lockNAM(&m_mutexNAM);
while(!m_bQuit)
{
// Process NAM events
QCoreApplication::processEvents();

lockNAM.unlock();

QMutexLocker locker(&m_mutex);
m_work.wait(&m_mutex, 100);

lockNAM.relock();

while (!m_workQ.isEmpty())
{
QScopedPointer< QEvent > ev(m_workQ.dequeue());
locker.unlock();
NewRequest(ev.data());
locker.relock();
}
}

Expand All @@ -829,10 +805,12 @@ void NAMThread::quit()
QThread::quit();
}

void NAMThread::Post(QEvent *event)
// static
void NAMThread::PostEvent(QEvent *event)
{
QMutexLocker locker(&m_mutex);
m_workQ.enqueue(event);
NAMThread &m = manager();
QMutexLocker locker(&m.m_mutex);
m.m_workQ.enqueue(event);
}

bool NAMThread::NewRequest(QEvent *event)
Expand All @@ -859,9 +837,8 @@ bool NAMThread::StartRequest(NetStreamRequest *p)

if (!p->m_bCancelled)
{
LOG(VB_FILE, LOG_DEBUG, LOC + QString("(%1) StartRequest").arg(p->m_id) );
QNetworkReply *reply = m_nam->get(p->m_req);
LOG(VB_FILE, LOG_DEBUG, LOC + QString("(%1) StartRequest 0x%2")
.arg(p->m_id).arg(quintptr(reply),0,16) );
emit requestStarted(p->m_id, reply);
}
else
Expand All @@ -877,8 +854,7 @@ bool NAMThread::AbortRequest(NetStreamAbort *p)
return false;
}

LOG(VB_FILE, LOG_DEBUG, LOC + QString("(%1) AbortRequest 0x%2").arg(p->m_id)
.arg(quintptr(p->m_reply),0,16) );
LOG(VB_FILE, LOG_INFO, LOC + QString("(%1) AbortRequest").arg(p->m_id) );
p->m_reply->abort();
p->m_reply->disconnect();
delete p->m_reply;
Expand Down
8 changes: 2 additions & 6 deletions mythtv/libs/libmythtv/netstream.h
Expand Up @@ -120,10 +120,7 @@ class NAMThread : public QThread
static NAMThread & manager(); // Singleton
virtual ~NAMThread();

static inline void PostEvent(QEvent *e) { manager().Post(e); }
void Post(QEvent *event);

static inline QMutex* GetMutex() { return &manager().m_mutexNAM; }
static void PostEvent(QEvent *);

static bool isAvailable(); // is network usable
static QDateTime GetLastModified(const QString &url);
Expand All @@ -146,9 +143,8 @@ private slots:

volatile bool m_bQuit;
QSemaphore m_running;
mutable QMutex m_mutexNAM; // Provides recursive access to m_nam
QNetworkAccessManager *m_nam;
mutable QMutex m_mutex; // Protects r/w access to the following data
QNetworkAccessManager *m_nam;
QQueue< QEvent * > m_workQ;
QWaitCondition m_work;
};
Expand Down

0 comments on commit f3600da

Please sign in to comment.