Skip to content

Commit

Permalink
Convert NuppelVideoRecorder threads to QThreads
Browse files Browse the repository at this point in the history
Refs #5501. I have converted the three threads (Write, Audio and VBI) within
NuppelVideoRecorder to using QThreads rather than directly using pthreads.
  • Loading branch information
Beirdo committed Mar 4, 2011
1 parent eb7d2bd commit 72f13d4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 47 deletions.
68 changes: 30 additions & 38 deletions mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
Expand Up @@ -1110,7 +1110,7 @@ void NuppelVideoRecorder::StartRecording(void)
return;
}

if (SpawnChildren() < 0)
if (!SpawnChildren())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't spawn children");
errored = true;
Expand Down Expand Up @@ -1863,53 +1863,48 @@ void NuppelVideoRecorder::DoV4L2(void) {}
void NuppelVideoRecorder::DoMJPEG(void) {}
#endif // USING_V4L

int NuppelVideoRecorder::SpawnChildren(void)
bool NuppelVideoRecorder::SpawnChildren(void)
{
int result;

childrenLive = true;

result = pthread_create(&write_tid, NULL,
NuppelVideoRecorder::WriteThread, this);

if (result)
WriteThread.SetParent(this);
WriteThread.start();
if (!WriteThread.isRunning())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't spawn writer thread, exiting");
return -1;
return false;
}

result = pthread_create(&audio_tid, NULL,
NuppelVideoRecorder::AudioThread, this);

if (result)
AudioThread.SetParent(this);
AudioThread.start();
if (!AudioThread.isRunning())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't spawn audio thread, exiting");
return -1;
return false;
}

if (vbimode)
{
result = pthread_create(&vbi_tid, NULL,
NuppelVideoRecorder::VbiThread, this);

if (result)
VbiThread.SetParent(this);
VbiThread.start();
if (!VbiThread.isRunning())
{
VERBOSE(VB_IMPORTANT, LOC_ERR + "Couldn't spawn vbi thread, exiting");
return -1;
return false;
}
}

return 0;
return true;
}

void NuppelVideoRecorder::KillChildren(void)
{
childrenLive = false;

pthread_join(write_tid, NULL);
pthread_join(audio_tid, NULL);
WriteThread.wait();
AudioThread.wait();
if (vbimode)
pthread_join(vbi_tid, NULL);
VbiThread.wait();
#ifdef USING_FFMPEG_THREADS
if (useavcodec && encoding_thread_count > 1)
avcodec_thread_free(mpa_vidctx);
Expand Down Expand Up @@ -2330,31 +2325,28 @@ void NuppelVideoRecorder::Reset(void)
curRecording->ClearPositionMap(MARK_KEYFRAME);
}

void *NuppelVideoRecorder::WriteThread(void *param)
void NVRWriteThread::run(void)
{
NuppelVideoRecorder *nvr = (NuppelVideoRecorder *)param;

nvr->doWriteThread();
if (!m_parent)
return;

return NULL;
m_parent->doWriteThread();
}

void *NuppelVideoRecorder::AudioThread(void *param)
void NVRAudioThread::run(void)
{
NuppelVideoRecorder *nvr = (NuppelVideoRecorder *)param;

nvr->doAudioThread();
if (!m_parent)
return;

return NULL;
m_parent->doAudioThread();
}

void *NuppelVideoRecorder::VbiThread(void *param)
void NVRVbiThread::run(void)
{
NuppelVideoRecorder *nvr = (NuppelVideoRecorder *)param;

nvr->doVbiThread();
if (!m_parent)
return;

return NULL;
m_parent->doVbiThread();
}

void NuppelVideoRecorder::doAudioThread(void)
Expand Down
52 changes: 43 additions & 9 deletions mythtv/libs/libmythtv/NuppelVideoRecorder.h
Expand Up @@ -6,7 +6,7 @@

#include <sys/time.h>
#include <time.h>
#include <pthread.h>
#include <QThread>
#ifdef MMX
#undef MMX
#define MMXBLAH
Expand Down Expand Up @@ -47,8 +47,46 @@ class FilterManager;
class FilterChain;
class AudioInput;

class NuppelVideoRecorder;

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

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

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

class MTV_PUBLIC NuppelVideoRecorder : public RecorderBase, public CC608Input
{
friend class NVRWriteThread;
friend class NVRAudioThread;
friend class NVRVbiThread;
public:
NuppelVideoRecorder(TVRec *rec, ChannelBase *channel);
~NuppelVideoRecorder();
Expand Down Expand Up @@ -107,10 +145,6 @@ class MTV_PUBLIC NuppelVideoRecorder : public RecorderBase, public CC608Input
void SetNewVideoParams(double newaspect);

protected:
static void *WriteThread(void *param);
static void *AudioThread(void *param);
static void *VbiThread(void *param);

void doWriteThread(void);
void doAudioThread(void);
void doVbiThread(void);
Expand All @@ -126,7 +160,7 @@ class MTV_PUBLIC NuppelVideoRecorder : public RecorderBase, public CC608Input

bool MJPEGInit(void);

int SpawnChildren(void);
bool SpawnChildren(void);
void KillChildren(void);

void BufferIt(unsigned char *buf, int len = -1, bool forcekey = false);
Expand Down Expand Up @@ -210,9 +244,9 @@ class MTV_PUBLIC NuppelVideoRecorder : public RecorderBase, public CC608Input

bool childrenLive;

pthread_t write_tid;
pthread_t audio_tid;
pthread_t vbi_tid;
NVRWriteThread WriteThread;
NVRAudioThread AudioThread;
NVRVbiThread VbiThread;

bool recording;
bool errored;
Expand Down

0 comments on commit 72f13d4

Please sign in to comment.