/*
- Copyright 2007 Chris Tallon
+ Copyright 2007-2020 Chris Tallon
This file is part of VOMP.
videoStartup = false;
pendingAudioPlay = false;
- stopNow = false;
state = S_STOP;
video->turnVideoOn();
{
if (!initted) return 0;
logger->log("PlayerVideoLive", Log::DEBUG, "Shutdown");
- stop();
+ if (state != S_STOP)
+ {
+ logger->log("PlayerVideoLive", Log::DEBUG, "state is not stop, calling");
+ stop();
+ }
+
initted = false;
delete demuxer;
void PlayerVideoLive::go(ULONG index)
{
+ playerThreadMutex.lock();
+
struct PLInstruction i;
i.instruction = I_SETCHANNEL;
i.channelIndex = index;
instructions.push(i);
- threadStart();
+
+ playerThread = std::thread([this]
+ {
+ playerThreadMutex.lock();
+ playerThreadMutex.unlock();
+ threadMethod();
+ });
+ playerThreadMutex.unlock();
}
void PlayerVideoLive::setChannel(ULONG index)
i.instruction = I_SETCHANNEL;
i.channelIndex = index;
instructions.push(i);
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
void PlayerVideoLive::stop()
{
logger->log("PlayerVideoLive", Log::DEBUG, "stop");
+
+ playerThreadMutex.lock();
+
struct PLInstruction i;
i.instruction = I_STOP;
instructions.push(i);
- threadSignal();
- threadStop();
+
+ playerThreadCond.notify_one();
+ playerThreadMutex.unlock();
+ playerThread.join();
+
logger->log("PlayerVideoLive", Log::DEBUG, "stop succesfull");
}
{
logger->log("PlayerVideoLive", Log::DEBUG, "afeed video startup");
videoStartup = true;
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
}
}
s.data = data;
s.len = len;
streamChunks.push(s);
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
else
{
if (!video->independentAVStartUp())
{
videoStartup = true;
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
return;
}
if (!video->independentAVStartUp())
{
videoStartup = true;
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
return;
}
if (!video->independentAVStartUp())
{
videoStartup = true;
- threadSignalNoLock();
+ playerThreadCond.notify_one();
}
return;
}
void PlayerVideoLive::threadMethod()
{
+ std::unique_lock<std::mutex> ul(playerThreadMutex, std::defer_lock);
+
while(1)
{
//logger->log("PlayerVideoLive", Log::DEBUG, "VS: %d pA %d",videoStartup,pendingAudioPlay);
checkError();
}
- while(!instructions.empty())
+ while (!instructions.empty())
{
if (instructions.size() > 1) optimizeInstructionQueue();
}
else if (i.instruction == I_STOP)
{
- logger->log("PlayerVideoLive", Log::DEBUG, "Stopping");
+ logger->log("PlayerVideoLive", Log::DEBUG, "Stopping by instruction");
switchState(S_STOP);
checkError();
-
- stopNow = true;
- break;
+ return;
}
}
- threadCheckExit();
-
- if (stopNow) break;
-
while(streamChunks.size())
{
//logger->log("PlayerVideoLive", Log::DEBUG, "chunk mark1 %d", streamChunks.size());
}
}
//logger->log("PlayerVideoLive", Log::DEBUG, "wait for signal %d", streamChunks.size());
- threadLock();
- threadWaitForSignal(); // unlocks and waits for signal
- threadUnlock();
+
+ playerThreadMutex.lock();
+ if (!instructions.empty()) { playerThreadMutex.unlock(); continue; }
+ playerThreadCond.wait(ul);
+ playerThreadMutex.unlock();
+
//logger->log("PlayerVideoLive", Log::DEBUG, "wait for signal2 %d",streamChunks.size());
}
#endif
#include <time.h>
+#include <mutex>
+#include <thread>
+#include <condition_variable>
+
#include <queue>
#include "playerlive.h"
-#ifdef WIN32
-#include "threadwin.h"
-#else
-#include "threadp.h"
-#endif
-
#include "callback.h"
#include "defines.h"
#include "vfeed.h"
class OSDReceiver;
class DVBSubtitles;
-class PlayerVideoLive : public PlayerLive, public Thread_TYPE, public Callback, public StreamReceiver
+class PlayerVideoLive : public PlayerLive, public Callback, public StreamReceiver
{
public:
PlayerVideoLive(MessageQueue* messageQueue, void* messageReceiver, OSDReceiver* tosdReceiver, ChannelList* chanList);
bool initted;
+ std::thread playerThread;
+ std::mutex playerThreadMutex;
+ std::condition_variable playerThreadCond;
+
UCHAR state;
const static UCHAR S_STOP = 1;
const static UCHAR S_VIDEOSTARTUP = 2;
bool videoStartup;
bool pendingAudioPlay;
- bool stopNow;
bool h264;
int preBufferCount;
const static int preBufferAmount = 3;