22 changes: 1 addition & 21 deletions mythtv/libs/libmyth/audio/spdifencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,10 @@ SPDIFEncoder::SPDIFEncoder(QString muxer, int codec_id)
QByteArray dev_ba = muxer.toAscii();
AVOutputFormat *fmt;

if (!(av_register_all && av_guess_format && avformat_alloc_context &&
av_new_stream && av_write_header && av_write_frame &&
av_write_trailer && av_set_parameters))
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavformat");
return;
}

if (!avcodec_close)
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavcodec");
return;
}

if (!(av_freep && av_alloc_put_byte))
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't find libavutil");
return;
}

avcodeclock->lock();
av_register_all();
avcodeclock->unlock();

fmt = av_guess_format(dev_ba.constData(), NULL, NULL);
if (!fmt)
{
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmyth/mythcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,7 @@ bool MythContextPrivate::PromptForDatabaseParams(const QString &error)

// Tell the user what went wrong:
if (error.length())
MythPopupBox::showOkPopup(GetMythMainWindow(), "DB connect failure",
error);
ShowOkPopup(error);

// ask user for database parameters
DatabaseSettings settings(m_DBhostCp);
Expand Down
18 changes: 9 additions & 9 deletions mythtv/libs/libmyth/mythdialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ class MPUBLIC MythPopupBox : public MythDialog
static bool showOkPopup(MythMainWindow *parent,
const QString &title,
const QString &message,
QString button_msg = QString()) MDEPRECATED;
QString button_msg = QString());

static bool showOkCancelPopup(MythMainWindow *parent, QString title,
QString message, bool focusOk) MDEPRECATED;
QString message, bool focusOk);

static DialogCode Show2ButtonPopup(
MythMainWindow *parent,
Expand All @@ -184,10 +184,10 @@ class MPUBLIC MythPopupBox : public MythDialog
MythMainWindow *parent,
const QString &title, const QString &message,
const QStringList &buttonmsgs,
DialogCode default_button) MDEPRECATED;
DialogCode default_button);

static bool showGetTextPopup(MythMainWindow *parent, QString title,
QString message, QString& text) MDEPRECATED;
QString message, QString& text);

public slots:
virtual void AcceptItem(int);
Expand Down Expand Up @@ -242,7 +242,7 @@ class MPUBLIC MythProgressDialog: public MythDialog
MythProgressDialog(const QString& message, int totalSteps = 0,
bool cancelButton = false,
const QObject * target = NULL,
const char * slot = NULL) MDEPRECATED;
const char * slot = NULL);

/* \brief Close the dialog.
Expand Down Expand Up @@ -306,7 +306,7 @@ class MPUBLIC MythBusyDialog : public MythProgressDialog
MythBusyDialog(const QString &title,
bool cancelButton = false,
const QObject * target = NULL,
const char * slot = NULL) MDEPRECATED;
const char * slot = NULL);

/** \brief Setup a timer to 'move' the spinner
Expand Down Expand Up @@ -350,10 +350,10 @@ class MPUBLIC MythThemedDialog : public MythDialog
const QString &window_name,
const QString &theme_filename = QString(),
const char *name = "MythThemedDialog",
bool setsize = true) MDEPRECATED;
bool setsize = true);
MythThemedDialog(MythMainWindow *parent,
const char *name = "MythThemedDialog",
bool setsize = true) MDEPRECATED;
bool setsize = true);

virtual bool loadThemedWindow(QString window_name, QString theme_filename);
virtual void loadWindow(QDomElement &);
Expand Down Expand Up @@ -441,7 +441,7 @@ class MPUBLIC MythSearchDialog: public MythPopupBox
public:

MythSearchDialog(MythMainWindow *parent,
const char *name = "MythSearchDialog") MDEPRECATED;
const char *name = "MythSearchDialog");

public:
void setCaption(QString text);
Expand Down
20 changes: 10 additions & 10 deletions mythtv/libs/libmythtv/darwinfirewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* Distributed as part of MythTV under GPL v2 and later.
*/

// POSIX headers
#include <pthread.h>

// OS X headers
#undef always_inline
#include <IOKit/IOMessage.h>
Expand All @@ -33,6 +30,8 @@ using namespace std;
#include <AVCVideoServices/AVSShared.h>
#include <AVCVideoServices/MPEG2Receiver.h>

#include <QThread>

// header not used because it also requires MPEG2Transmitter.h
//#include <AVCVideoServices/FireWireMPEG.h>
namespace AVS
Expand Down Expand Up @@ -65,7 +64,6 @@ static IOReturn dfd_tspacket_handler_thunk(
long unsigned int tsPacketCount, UInt32 **ppBuf, void *callback_data);
static void dfd_update_device_list(void *dfd, io_iterator_t iterator);
static void dfd_streaming_log_message(char *pString);
void *dfd_controller_thunk(void *param);
void dfd_stream_msg(long unsigned int msg, long unsigned int param1,
long unsigned int param2, void *callback_data);
int dfd_no_data_notification(void *callback_data);
Expand Down Expand Up @@ -96,7 +94,7 @@ class DFDPriv
}
}

pthread_t controller_thread;
DarwinControllerThread controllerThread;
CFRunLoopRef controller_thread_cf_ref;
bool controller_thread_running;

Expand Down Expand Up @@ -180,8 +178,8 @@ void DarwinFirewireDevice::StartController(void)
{
m_lock.unlock();

pthread_create(&m_priv->controller_thread, NULL,
dfd_controller_thunk, this);
m_priv->controllerThread.SetParent(this);
m_priv->controllerThread.start();

m_lock.lock();
while (!m_priv->controller_thread_running)
Expand Down Expand Up @@ -875,10 +873,12 @@ void DarwinFirewireDevice::HandleDeviceChange(uint messageType)

// Various message callbacks.

void *dfd_controller_thunk(void *param)
void DarwinControllerThread::run(void)
{
((DarwinFirewireDevice*)param)->RunController();
return NULL;
if (!m_parent)
return;

m_parent->RunController();
}

void dfd_update_device_list_item(
Expand Down
17 changes: 16 additions & 1 deletion mythtv/libs/libmythtv/darwinfirewiredevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@

#include "firewiredevice.h"

#include <QThread>

class DFDPriv;
class DarwinAVCInfo;

class DarwinFirewireDevice;

class DarwinControllerThread : public QThread
{
Q_OBJECT
public:
DarwinControllerThread() : m_parent(NULL) {}
void SetParent(DarwinFirewireDevice *parent) { m_parent = parent; }
void run(void);
private:
DarwinFirewireDevice *m_parent;
};

class DarwinFirewireDevice : public FirewireDevice
{
friend void *dfd_controller_thunk(void *param);
friend class DarwinControllerThread;
friend void dfd_update_device_list_item(DarwinFirewireDevice *dev,
uint64_t guid, void *item);
friend int dfd_no_data_notification(void *cb_data);
Expand Down
24 changes: 12 additions & 12 deletions mythtv/libs/libmythtv/dvbcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ using namespace std;

DVBCam::DVBCam(const QString &aDevice)
: device(aDevice), numslots(0),
ciHandler(NULL),
exitCiThread(false), ciThreadRunning(false),
ciHandlerThread(pthread_t()),
ciHandler(NULL), exitCiThread(false),
have_pmt(false), pmt_sent(false),
pmt_updated(false), pmt_added(false)
{
Expand Down Expand Up @@ -103,25 +101,26 @@ bool DVBCam::Start()
return false;
}

if (pthread_create(&ciHandlerThread, NULL, CiHandlerThreadHelper, this))
ciHandlerThread.SetParent(this);
ciHandlerThread.start();

if (!ciHandlerThread.isRunning())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to create CI handler thread");
return false;
}

ciThreadRunning = true;

VERBOSE(VB_DVBCAM, LOC + "CI handler successfully initialized!");

return true;
}

bool DVBCam::Stop()
{
if (ciThreadRunning)
if (ciHandlerThread.isRunning())
{
exitCiThread = true;
pthread_join(ciHandlerThread, NULL);
ciHandlerThread.wait();
}

if (ciHandler)
Expand All @@ -144,10 +143,12 @@ bool DVBCam::Stop()
return true;
}

void *DVBCam::CiHandlerThreadHelper(void *dvbcam)
void CiHandlerThread::run(void)
{
((DVBCam*)dvbcam)->CiHandlerLoop();
return NULL;
if (!m_parent)
return;

m_parent->CiHandlerLoop();
}

void DVBCam::HandleUserIO(void)
Expand Down Expand Up @@ -272,7 +273,6 @@ void DVBCam::CiHandlerLoop()
usleep(10 * 1000);
}

ciThreadRunning = false;
VERBOSE(VB_DVBCAM, LOC + "CiHandler thread stopped");
}

Expand Down
18 changes: 16 additions & 2 deletions mythtv/libs/libmythtv/dvbcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using namespace std;

#include <QString>
#include <QMutex>
#include <QThread>

#include "mpegtables.h"

Expand All @@ -15,8 +16,22 @@ class ChannelBase;
class cCiHandler;
typedef QMap<const ChannelBase*, ProgramMapTable*> pmt_list_t;

class DVBCam;

class CiHandlerThread : public QThread
{
Q_OBJECT
public:
CiHandlerThread() : m_parent(NULL) {}
void SetParent(DVBCam *parent) { m_parent = parent; }
void run(void);
private:
DVBCam *m_parent;
};

class DVBCam
{
friend class CiHandlerThread;
public:
DVBCam(const QString &device);
~DVBCam();
Expand All @@ -28,7 +43,6 @@ class DVBCam
void SetTimeOffset(double offset_in_seconds);

private:
static void *CiHandlerThreadHelper(void*);
void CiHandlerLoop(void);
void HandleUserIO(void);
void HandlePMT(void);
Expand All @@ -42,7 +56,7 @@ class DVBCam
bool exitCiThread;
bool ciThreadRunning;

pthread_t ciHandlerThread;
CiHandlerThread ciHandlerThread;

pmt_list_t PMTList;
pmt_list_t PMTAddList;
Expand Down
83 changes: 32 additions & 51 deletions mythtv/libs/libmythtv/fifowriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@ FIFOWriter::FIFOWriter(int count, bool sync)
{
num_fifos = count;
usesync = sync;
cur_id = -1;
maxblksize = new long[count];
killwr = new int[count];
fbcount = new int[count];
fifo_buf = new struct fifo_buf *[count];
fb_inptr = new struct fifo_buf *[count];
fb_outptr = new struct fifo_buf *[count];
fifothrds = new pthread_t[count];
fifo_lock = new pthread_mutex_t [count];
empty_cond = new pthread_cond_t[count];
full_cond = new pthread_cond_t[count];
for (int i = 0; i < count; i++)
{
pthread_cond_init(&empty_cond[i], NULL);
pthread_cond_init(&full_cond[i], NULL);
pthread_mutex_init(&fifo_lock[i], NULL);
}
fifothrds = new FIFOThread[count];
fifo_lock = new QMutex[count];
empty_cond = new QWaitCondition[count];
full_cond = new QWaitCondition[count];
filename = new QString [count];
fbdesc = new QString [count];
}
Expand All @@ -53,15 +46,11 @@ FIFOWriter::~FIFOWriter()
{
killwr[i] = 1;

pthread_mutex_lock(&fifo_lock[i]);
pthread_cond_signal(&empty_cond[i]);
pthread_mutex_unlock(&fifo_lock[i]);

pthread_join(fifothrds[i], NULL);
fifo_lock[i].lock();
empty_cond[i].wakeAll();
fifo_lock[i].unlock();

pthread_cond_destroy(&empty_cond[i]);
pthread_cond_destroy(&full_cond[i]);
pthread_mutex_destroy(&fifo_lock[i]);
fifothrds[i].wait();
}
delete [] maxblksize;
delete [] fifo_buf;
Expand Down Expand Up @@ -111,36 +100,33 @@ int FIFOWriter::FIFOInit(int id, QString desc, QString name, long size,
fb_inptr[id] = fifo_buf[id];
fb_outptr[id] = fifo_buf[id];

cur_id = id;
fifothrds[id].SetParent(this);
fifothrds[id].SetId(id);
fifothrds[id].start();

pthread_create(&fifothrds[id], NULL, FIFOStartThread, this);
while (cur_id >= 0)
usleep(50);
if (cur_id == -1)
return true;
else
return false;
usleep(50);

return (fifothrds[id].isRunning());
}

void *FIFOWriter::FIFOStartThread(void *param)
void FIFOThread::run(void)
{
FIFOWriter *fifo = (FIFOWriter *)param;
fifo->FIFOWriteThread();
if (!m_parent || m_id == -1)
return;

return NULL;
m_parent->FIFOWriteThread(m_id);
}

void FIFOWriter::FIFOWriteThread(void)
void FIFOWriter::FIFOWriteThread(int id)
{
int id = cur_id;
int fd = -1;
pthread_mutex_lock(&fifo_lock[id]);
cur_id = -1;

fifo_lock[id].lock();
while (1)
{
if (fb_inptr[id] == fb_outptr[id])
pthread_cond_wait(&empty_cond[id],&fifo_lock[id]);
pthread_mutex_unlock(&fifo_lock[id]);
empty_cond[id].wait(&fifo_lock[id]);
fifo_lock[id].unlock();
if (killwr[id])
break;
if (fd < 0)
Expand Down Expand Up @@ -168,9 +154,9 @@ void FIFOWriter::FIFOWriteThread(void)
}
}
}
pthread_mutex_lock(&fifo_lock[id]);
fifo_lock[id].lock();
fb_outptr[id] = fb_outptr[id]->next;
pthread_cond_signal(&full_cond[id]);
full_cond[id].wakeAll();
}

if (fd != -1)
Expand All @@ -191,7 +177,7 @@ void FIFOWriter::FIFOWriteThread(void)

void FIFOWriter::FIFOWrite(int id, void *buffer, long blksize)
{
pthread_mutex_lock(&fifo_lock[id]);
fifo_lock[id].lock();
while (fb_inptr[id]->next == fb_outptr[id])
{
bool blocking = false;
Expand Down Expand Up @@ -219,12 +205,7 @@ void FIFOWriter::FIFOWrite(int id, void *buffer, long blksize)
}
else
{
struct timespec timeout;
struct timeval now;
gettimeofday(&now, NULL);
timeout.tv_sec = now.tv_sec + 1;
timeout.tv_nsec = now.tv_usec * 1000;
pthread_cond_timedwait(&full_cond[id], &fifo_lock[id], &timeout);
full_cond[id].wait(&fifo_lock[id], 1000);
}
}
if (blksize > maxblksize[id])
Expand All @@ -235,8 +216,8 @@ void FIFOWriter::FIFOWrite(int id, void *buffer, long blksize)
memcpy(fb_inptr[id]->data,buffer,blksize);
fb_inptr[id]->blksize = blksize;
fb_inptr[id] = fb_inptr[id]->next;
pthread_cond_signal(&empty_cond[id]);
pthread_mutex_unlock(&fifo_lock[id]);
empty_cond[id].wakeAll();
fifo_lock[id].unlock();
}

void FIFOWriter::FIFODrain(void)
Expand All @@ -250,9 +231,9 @@ void FIFOWriter::FIFODrain(void)
if (fb_inptr[i] == fb_outptr[i])
{
killwr[i] = 1;
pthread_mutex_lock(&fifo_lock[i]);
pthread_cond_signal(&empty_cond[i]);
pthread_mutex_unlock(&fifo_lock[i]);
fifo_lock[i].lock();
empty_cond[i].wakeAll();
fifo_lock[i].unlock();
count++;
}
}
Expand Down
31 changes: 22 additions & 9 deletions mythtv/libs/libmythtv/fifowriter.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
#ifndef FIFOWRITER
#define FIFOWRITER

// POSIX headers
#include <pthread.h>

// Qt headers
#include <QString>
#include <QMutex>
#include <QWaitCondition>
#include <QThread>

// MythTV headers
#include "mythtvexp.h"

using namespace std;

class FIFOWriter;

class FIFOThread : public QThread
{
Q_OBJECT
public:
FIFOThread() : m_parent(NULL), m_id(-1) {}
void SetId(int id) { m_id = id; }
void SetParent(FIFOWriter *parent) { m_parent = parent; }
void run(void);
private:
FIFOWriter *m_parent;
int m_id;
};

class MTV_PUBLIC FIFOWriter
{
friend class FIFOThread;
public:
FIFOWriter(int count, bool sync);
~FIFOWriter();
Expand All @@ -24,8 +39,7 @@ class MTV_PUBLIC FIFOWriter
void FIFODrain(void);

private:
void FIFOWriteThread(void);
static void *FIFOStartThread(void *param);
void FIFOWriteThread(int id);

struct fifo_buf
{
Expand All @@ -34,17 +48,16 @@ class MTV_PUBLIC FIFOWriter
long blksize;
} **fifo_buf, **fb_inptr, **fb_outptr;

pthread_t *fifothrds;
pthread_mutex_t *fifo_lock;
pthread_cond_t *full_cond, *empty_cond;
FIFOThread *fifothrds;
QMutex *fifo_lock;
QWaitCondition *full_cond, *empty_cond;

QString *filename, *fbdesc;

long *maxblksize;
int *killwr, *fbcount;
int num_fifos;
bool usesync;
int cur_id;
};

#endif
Expand Down
34 changes: 15 additions & 19 deletions mythtv/libs/libmythtv/firewiresignalmonitor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// -*- Mode: c++ -*-
// Copyright (c) 2006, Daniel Thor Kristjansson

#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
Expand Down Expand Up @@ -43,7 +42,6 @@ FirewireSignalMonitor::FirewireSignalMonitor(
FirewireChannel *_channel,
uint64_t _flags) :
DTVSignalMonitor(db_cardnum, _channel, _flags),
dtvMonitorRunning(false),
stb_needs_retune(true),
stb_needs_to_wait_for_pat(false),
stb_needs_to_wait_for_power(false)
Expand Down Expand Up @@ -74,10 +72,10 @@ void FirewireSignalMonitor::Stop(void)
{
VERBOSE(VB_CHANNEL, LOC + "Stop() -- begin");
SignalMonitor::Stop();
if (dtvMonitorRunning)
if (table_monitor_thread.isRunning())
{
dtvMonitorRunning = false;
pthread_join(table_monitor_thread, NULL);
dtvMonitorRun = false;
table_monitor_thread.wait();
}
VERBOSE(VB_CHANNEL, LOC + "Stop() -- end");
}
Expand Down Expand Up @@ -125,26 +123,25 @@ void FirewireSignalMonitor::HandlePMT(uint pnum, const ProgramMapTable *pmt)
DTVSignalMonitor::HandlePMT(pnum, pmt);
}

void *FirewireSignalMonitor::TableMonitorThread(void *param)
void FWSignalThread::run(void)
{
FirewireSignalMonitor *mon = (FirewireSignalMonitor*) param;
mon->RunTableMonitor();
return NULL;
if (!m_parent)
return;

m_parent->RunTableMonitor();
}

void FirewireSignalMonitor::RunTableMonitor(void)
{
stb_needs_to_wait_for_pat = true;
stb_wait_for_pat_timer.start();
dtvMonitorRunning = true;

VERBOSE(VB_CHANNEL, LOC + "RunTableMonitor(): -- begin");

FirewireChannel *lchan = dynamic_cast<FirewireChannel*>(channel);
if (!lchan)
{
VERBOSE(VB_CHANNEL, LOC + "RunTableMonitor(): -- err end");
dtvMonitorRunning = false;
return;
}

Expand All @@ -153,22 +150,20 @@ void FirewireSignalMonitor::RunTableMonitor(void)
dev->OpenPort();
dev->AddListener(this);

while (dtvMonitorRunning && GetStreamData())
while (dtvMonitorRun && GetStreamData())
usleep(100000);

VERBOSE(VB_CHANNEL, LOC + "RunTableMonitor(): -- shutdown ");

dev->RemoveListener(this);
dev->ClosePort();

dtvMonitorRunning = false;

VERBOSE(VB_CHANNEL, LOC + "RunTableMonitor(): -- end");
}

void FirewireSignalMonitor::AddData(const unsigned char *data, uint len)
{
if (!dtvMonitorRunning)
if (!table_monitor_thread.isRunning())
return;

if (GetStreamData())
Expand All @@ -193,7 +188,7 @@ void FirewireSignalMonitor::UpdateValues(void)
if (!IsChannelTuned())
return;

if (dtvMonitorRunning)
if (table_monitor_thread.isRunning())
{
EmitStatus();
if (IsAllGood())
Expand Down Expand Up @@ -276,13 +271,14 @@ void FirewireSignalMonitor::UpdateValues(void)
kDTVSigMon_WaitForMGT | kDTVSigMon_WaitForVCT |
kDTVSigMon_WaitForNIT | kDTVSigMon_WaitForSDT))
{
pthread_create(&table_monitor_thread, NULL,
TableMonitorThread, this);
dtvMonitorRun = true;
table_monitor_thread.SetParent(this);
table_monitor_thread.start();

VERBOSE(VB_CHANNEL, LOC + "UpdateValues() -- "
"Waiting for table monitor to start");

while (!dtvMonitorRunning)
while (!table_monitor_thread.isRunning())
usleep(50);

VERBOSE(VB_CHANNEL, LOC + "UpdateValues() -- "
Expand Down
20 changes: 17 additions & 3 deletions mythtv/libs/libmythtv/firewiresignalmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace std;
// Qt headers
#include <QMutex>
#include <QMap>
#include <QThread>

// MythTV headers
#include "dtvsignalmonitor.h"
Expand All @@ -18,8 +19,22 @@ using namespace std;

class FirewireChannel;

class FirewireSignalMonitor;

class FWSignalThread : public QThread
{
Q_OBJECT
public:
FWSignalThread() : m_parent(NULL) {}
void SetParent(FirewireSignalMonitor *parent) { m_parent = parent; }
void run(void);
private:
FirewireSignalMonitor *m_parent;
};

class FirewireSignalMonitor : public DTVSignalMonitor, public TSDataListener
{
friend class FWSignalThread;
public:
FirewireSignalMonitor(int db_cardnum, FirewireChannel *_channel,
uint64_t _flags = kFWSigMon_WaitForPower);
Expand All @@ -36,7 +51,6 @@ class FirewireSignalMonitor : public DTVSignalMonitor, public TSDataListener

virtual void UpdateValues(void);

static void *TableMonitorThread(void *param);
void RunTableMonitor(void);

bool SupportsTSMonitoring(void);
Expand All @@ -48,8 +62,8 @@ class FirewireSignalMonitor : public DTVSignalMonitor, public TSDataListener
static const uint kBufferTimeout;

protected:
bool dtvMonitorRunning;
pthread_t table_monitor_thread;
bool dtvMonitorRun;
FWSignalThread table_monitor_thread;
bool stb_needs_retune;
bool stb_needs_to_wait_for_pat;
bool stb_needs_to_wait_for_power;
Expand Down
28 changes: 13 additions & 15 deletions mythtv/libs/libmythtv/iptvsignalmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
IPTVSignalMonitor::IPTVSignalMonitor(int db_cardnum,
IPTVChannel *_channel,
uint64_t _flags) :
DTVSignalMonitor(db_cardnum, _channel, _flags),
dtvMonitorRunning(false), table_monitor_thread(pthread_t())
DTVSignalMonitor(db_cardnum, _channel, _flags)
{
bool isLocked = false;
IPTVChannelInfo chaninfo = GetChannel()->GetCurrentChanInfo();
Expand Down Expand Up @@ -69,36 +68,34 @@ void IPTVSignalMonitor::Stop(void)
DBG_SM("Stop", "begin");
GetChannel()->GetFeeder()->RemoveListener(this);
SignalMonitor::Stop();
if (dtvMonitorRunning)
if (table_monitor_thread.isRunning())
{
GetChannel()->GetFeeder()->Stop();
dtvMonitorRunning = false;
pthread_join(table_monitor_thread, NULL);
table_monitor_thread.wait();
}
DBG_SM("Stop", "end");
}

void *IPTVSignalMonitor::TableMonitorThread(void *param)
void IPTVMonitorThread::run(void)
{
IPTVSignalMonitor *mon = (IPTVSignalMonitor*) param;
mon->RunTableMonitor();
return NULL;
if (!m_parent)
return;

m_parent->RunTableMonitor();
}

/** \fn IPTVSignalMonitor::RunTableMonitor(void)
*/
void IPTVSignalMonitor::RunTableMonitor(void)
{
DBG_SM("Run", "begin");
dtvMonitorRunning = true;

GetStreamData()->AddListeningPID(0);

GetChannel()->GetFeeder()->AddListener(this);
GetChannel()->GetFeeder()->Run();
GetChannel()->GetFeeder()->RemoveListener(this);

dtvMonitorRunning = false;
DBG_SM("Run", "end");
}

Expand All @@ -122,7 +119,7 @@ void IPTVSignalMonitor::UpdateValues(void)
if (!IsChannelTuned())
return;

if (dtvMonitorRunning)
if (table_monitor_thread.isRunning())
{
EmitStatus();
if (IsAllGood())
Expand Down Expand Up @@ -150,10 +147,11 @@ void IPTVSignalMonitor::UpdateValues(void)
kDTVSigMon_WaitForMGT | kDTVSigMon_WaitForVCT |
kDTVSigMon_WaitForNIT | kDTVSigMon_WaitForSDT))
{
pthread_create(&table_monitor_thread, NULL,
TableMonitorThread, this);
table_monitor_thread.SetParent(this);
table_monitor_thread.start();

DBG_SM("UpdateValues", "Waiting for table monitor to start");
while (!dtvMonitorRunning)
while (!table_monitor_thread.isRunning())
usleep(50);
DBG_SM("UpdateValues", "Table monitor started");
}
Expand Down
27 changes: 20 additions & 7 deletions mythtv/libs/libmythtv/iptvsignalmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@

#include "dtvsignalmonitor.h"

#include <QThread>
#include <QObject>

class IPTVChannel;
class IPTVSignalMonitor;

class IPTVSignalMonitor : public DTVSignalMonitor, public TSDataListener
class IPTVMonitorThread : public QThread
{
Q_OBJECT
public:
IPTVMonitorThread() : m_parent(NULL) {}
void SetParent(IPTVSignalMonitor *parent) { m_parent = parent; }
void run(void);
private:
IPTVSignalMonitor *m_parent;
};

class IPTVSignalMonitor : public QObject, public DTVSignalMonitor, public TSDataListener
{
Q_OBJECT

friend class IPTVMonitorThread;
public:
IPTVSignalMonitor(int db_cardnum, IPTVChannel *_channel,
uint64_t _flags = 0);
Expand All @@ -19,23 +37,18 @@ class IPTVSignalMonitor : public DTVSignalMonitor, public TSDataListener
// implements TSDataListener
void AddData(const unsigned char *data, unsigned int dataSize);

public slots:
void deleteLater(void);

protected:
IPTVSignalMonitor(void);
IPTVSignalMonitor(const IPTVSignalMonitor&);

virtual void UpdateValues(void);

static void *TableMonitorThread(void *param);
void RunTableMonitor(void);

IPTVChannel *GetChannel(void);

protected:
bool dtvMonitorRunning;
pthread_t table_monitor_thread;
IPTVMonitorThread table_monitor_thread;
};

#endif // _IPTVSIGNALMONITOR_H_
48 changes: 15 additions & 33 deletions mythtv/libs/libmythtv/linuxfirewiredevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

// POSIX headers
#include <pthread.h>
#include <sys/select.h>
#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -50,7 +49,7 @@ class LFDPriv
public:
LFDPriv() :
generation(0), reset_timer_on(false),
run_port_handler(false), is_port_handler_running(false),
run_port_handler(false),
avstream(NULL), channel(-1),
output_plug(-1), input_plug(-1), bandwidth(0), no_data_cnt(0),
is_p2p_node_open(false), is_bcast_node_open(false),
Expand All @@ -71,7 +70,6 @@ class LFDPriv
MythTimer reset_timer;

bool run_port_handler;
bool is_port_handler_running;
QMutex start_stop_port_handler_lock;

iec61883_mpeg2_t avstream;
Expand All @@ -85,8 +83,8 @@ class LFDPriv
bool is_bcast_node_open;
bool is_streaming;

QDateTime stop_streaming_timer;
pthread_t port_handler_thread;
QDateTime stop_streaming_timer;
LinuxControllerThread port_handler_thread;

avcinfo_list_t devices;

Expand Down Expand Up @@ -275,10 +273,13 @@ bool LinuxFirewireDevice::OpenPort(void)
return false;
}

m_priv->run_port_handler = true;

VERBOSE(VB_RECORD, LOC + "Starting port handler thread");
int rval = pthread_create(&m_priv->port_handler_thread, NULL,
linux_firewire_device_port_handler_thunk, this);
if (rval != 0)
m_priv->port_handler_thread.SetParent(this);
m_priv->port_handler_thread.start();

if (!m_priv->port_handler_thread.isRunning())
{
VERBOSE(VB_IMPORTANT, LOC_ERR +
QString("Failed to create port handler thread.") + ENO);
Expand All @@ -290,16 +291,6 @@ bool LinuxFirewireDevice::OpenPort(void)
return false;
}

m_priv->run_port_handler = true;

VERBOSE(VB_RECORD, LOC + "Waiting for port handler thread to start");
while (!m_priv->is_port_handler_running)
{
m_lock.unlock();
usleep(5000);
m_lock.lock();
}

VERBOSE(VB_RECORD, LOC + "Port handler thread started");

m_open_port_cnt++;
Expand Down Expand Up @@ -335,15 +326,7 @@ bool LinuxFirewireDevice::ClosePort(void)

VERBOSE(VB_RECORD, LOC + "Waiting for port handler thread to stop");
m_priv->run_port_handler = false;
while (m_priv->is_port_handler_running)
{
m_lock.unlock();
usleep(5000);
m_lock.lock();
}

VERBOSE(VB_RECORD, LOC + "Joining port handler thread");
pthread_join(m_priv->port_handler_thread, NULL);
m_priv->port_handler_thread.wait();

remove_handle(GetInfoPtr()->fw_handle);

Expand Down Expand Up @@ -597,19 +580,19 @@ bool LinuxFirewireDevice::CloseAVStream(void)
return true;
}

void *linux_firewire_device_port_handler_thunk(void *param)
void LinuxControllerThread::run(void)
{
LinuxFirewireDevice *mon = (LinuxFirewireDevice*) param;
mon->RunPortHandler();
return NULL;
if (!m_parent)
return;

m_parent->RunPortHandler();
}

void LinuxFirewireDevice::RunPortHandler(void)
{
VERBOSE(VB_RECORD, LOC + "RunPortHandler -- start");
m_lock.lock();
VERBOSE(VB_RECORD, LOC + "RunPortHandler -- got first lock");
m_priv->is_port_handler_running = true;

m_priv->no_data_cnt = 0;
while (m_priv->run_port_handler)
Expand Down Expand Up @@ -677,7 +660,6 @@ void LinuxFirewireDevice::RunPortHandler(void)
}
}

m_priv->is_port_handler_running = false;
m_lock.unlock();
VERBOSE(VB_RECORD, LOC + "RunPortHandler -- end");
}
Expand Down
15 changes: 14 additions & 1 deletion mythtv/libs/libmythtv/linuxfirewiredevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
#define _LINUX_FIREWIRE_DEVICE_H_

#include "firewiredevice.h"
#include <QThread>

class LFDPriv;
class LinuxAVCInfo;
class LinuxFirewireDevice;

class LinuxControllerThread : public QThread
{
Q_OBJECT
public:
LinuxControllerThread() : m_parent(NULL) {}
void SetParent(LinuxFirewireDevice *parent) { m_parent = parent; }
void run(void);
private:
LinuxFirewireDevice *m_parent;
};

class LinuxFirewireDevice : public FirewireDevice
{
friend void *linux_firewire_device_port_handler_thunk(void *param);
friend class LinuxControllerThread;
friend int linux_firewire_device_tspacket_handler(
unsigned char *tspacket, int len, uint dropped, void *callback_data);

Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/tv_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,10 @@ void TVRec::FinishedRecording(RecordingInfo *curRec)
VERBOSE(VB_RECORD, LOC + QString("FinishedRecording(%1) in recgroup: %2")
.arg(curRec->GetTitle()).arg(recgrp));

if (curRec->GetRecordingStatus() != rsFailed)
if (curRec->GetRecordingStatus() == rsRecording)
curRec->SetRecordingStatus(rsRecorded);
else if (curRec->GetRecordingStatus() != rsRecorded)
curRec->SetRecordingStatus(rsFailed);
curRec->SetRecordingEndTime(mythCurrentDateTime());

if (tvchain)
Expand Down
18 changes: 12 additions & 6 deletions mythtv/programs/mythbackend/mainserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,11 @@ void MainServer::DoHandleStopRecording(
if (pbs)
pbssock = pbs->getSocket();

if (recinfo.GetRecordingStatus() == rsRecording)
recinfo.SetRecordingStatus(rsRecorded);
else if (recinfo.GetRecordingStatus() != rsRecorded)
recinfo.SetRecordingStatus(rsFailed);

if (ismaster && recinfo.GetHostname() != gCoreContext->GetHostName())
{
PlaybackSock *slave = GetSlaveByHostname(recinfo.GetHostname());
Expand All @@ -2278,7 +2283,6 @@ void MainServer::DoHandleStopRecording(
if (num > 0)
{
(*encoderList)[num]->StopRecording();
recinfo.SetRecordingStatus(rsRecorded);
if (m_sched)
m_sched->UpdateRecStatus(&recinfo);
}
Expand All @@ -2297,7 +2301,6 @@ void MainServer::DoHandleStopRecording(
// recording has stopped and the status should be updated.
// Continue so that the master can try to update the endtime
// of the file is in a shared directory.
recinfo.SetRecordingStatus(rsRecorded);
if (m_sched)
m_sched->UpdateRecStatus(&recinfo);
}
Expand Down Expand Up @@ -2325,7 +2328,6 @@ void MainServer::DoHandleStopRecording(

if (ismaster)
{
recinfo.SetRecordingStatus(rsRecorded);
if (m_sched)
m_sched->UpdateRecStatus(&recinfo);
}
Expand Down Expand Up @@ -2408,7 +2410,8 @@ void MainServer::DoHandleDeleteRecording(
{
recinfo.ApplyRecordRecGroupChange("Deleted");
recinfo.SaveAutoExpire(kDeletedAutoExpire, true);
if (recinfo.GetRecordingStatus() == rsRecording)
if (recinfo.GetRecordingStatus() == rsRecording ||
recinfo.GetRecordingStatus() == rsTuning)
DoHandleStopRecording(recinfo, NULL);
if (forgetHistory)
recinfo.ForgetHistory();
Expand All @@ -2417,6 +2420,11 @@ void MainServer::DoHandleDeleteRecording(
return;
}

if (recinfo.GetRecordingStatus() == rsRecording)
recinfo.SetRecordingStatus(rsRecorded);
else if (recinfo.GetRecordingStatus() != rsRecorded)
recinfo.SetRecordingStatus(rsFailed);

// If this recording was made by a another recorder, and that
// recorder is available, tell it to do the deletion.
if (ismaster && recinfo.GetHostname() != gCoreContext->GetHostName())
Expand All @@ -2430,7 +2438,6 @@ void MainServer::DoHandleDeleteRecording(
if (num > 0)
{
(*encoderList)[num]->StopRecording();
recinfo.SetRecordingStatus(rsRecorded);
if (m_sched)
m_sched->UpdateRecStatus(&recinfo);
}
Expand Down Expand Up @@ -2471,7 +2478,6 @@ void MainServer::DoHandleDeleteRecording(

if (ismaster)
{
recinfo.SetRecordingStatus(rsRecorded);
if (m_sched)
m_sched->UpdateRecStatus(&recinfo);
}
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythtranscode/transcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AudioReencodeBuffer : public AudioOutput
// timecode is in milliseconds.
virtual bool AddFrames(void *buffer, int frames, int64_t timecode)
{
AddData(buffer, frames * bytes_per_frame, timecode);
return AddData(buffer, frames * bytes_per_frame, timecode);
}

// timecode is in milliseconds.
Expand Down