SubtitleTimeout(0),
timeout_clear(false)
{
-#ifndef WIN32
- pthread_mutex_init(&input_mutex, NULL);
- pthread_mutex_init(&output_mutex, NULL);
-#else
- input_mutex=CreateMutex(NULL,FALSE,NULL);
- output_mutex=CreateMutex(NULL,FALSE,NULL);
-#endif
}
void DVBSubtitles::put(const PESPacket& packet)
{
- lockInput();
+ input_mutex.lock();
if (running)
{
if (packet.getPTS() != PESPacket::PTS_INVALID)
nudge();
}
}
- unlockInput();
+ input_mutex.unlock();
}
bool DVBSubtitles::decodePacket(const PESPacket& packet)
Log::getInstance()->log("SUBTITLES", Log::DEBUG, "SubtitleTimeout %d", page.timeout);
}
-void DVBSubtitles::lockInput()
-{
-#ifndef WIN32
- pthread_mutex_lock(&input_mutex);
-#else
- WaitForSingleObject(input_mutex, INFINITE);
-#endif
-}
-
-void DVBSubtitles::unlockInput()
-{
-#ifndef WIN32
- pthread_mutex_unlock(&input_mutex);
-#else
- ReleaseMutex(input_mutex);
-#endif
-}
-
-void DVBSubtitles::lockOutput()
-{
-#ifndef WIN32
- pthread_mutex_lock(&output_mutex);
-#else
- WaitForSingleObject(output_mutex, INFINITE);
-#endif
-}
-
-void DVBSubtitles::unlockOutput()
-{
-#ifndef WIN32
- pthread_mutex_unlock(&output_mutex);
-#else
- ReleaseMutex(output_mutex);
-#endif
-}
-
int DVBSubtitles::start()
{
- lockInput();
+ input_mutex.lock();
dds=DVBSubtitleDisplayDefinition();
running = true;
- unlockInput();
+ input_mutex.unlock();
return threadStart();
}
void DVBSubtitles::stop()
{
threadStop();
- lockInput();
+ input_mutex.lock();
running = false;
worklist.clear();
- unlockInput();
- lockOutput();
+ input_mutex.unlock();
+ output_mutex.lock();
PageMap::const_iterator pageEntry = pages.find(pageOnDisplay);
if (pageEntry != pages.end())
{
}
pages.clear();
pageOnDisplay = 65536;
- unlockOutput();
+ output_mutex.unlock();
threadNudged = false;
}
void DVBSubtitles::show()
{
- lockOutput();
+ output_mutex.lock();
showing = true;
- unlockOutput();
+ output_mutex.unlock();
}
void DVBSubtitles::hide()
{
- lockOutput();
+ output_mutex.lock();
showing = false;
PageMap::const_iterator pageEntry = pages.find(pageOnDisplay);
if (pageEntry != pages.end())
}
pages.clear();
pageOnDisplay = 65536;
- unlockOutput();
+ output_mutex.unlock();
}
void DVBSubtitles::nudge()
{
if (SubtitleTimeout.TimedOut()) // do we have a subtitle timeout
{
- lockOutput();
+ output_mutex.lock();
if (showing && !osdMenuShowing) {
if (!timeout_clear) {
osd->clearOSD(); // if we have the timeout, lets clear the OSD
timeout_clear=true;
}
}
- unlockOutput();
+ output_mutex.unlock();
}
else if (showing) // if not lets check when will we have it
{
threadCheckExit();
finished = true;
pktPTS = PESPacket::PTS_INVALID;
- lockInput();
+ input_mutex.lock();
if (!worklist.empty())
pktPTS = worklist.front().getPTS();
- unlockInput();
+ input_mutex.unlock();
if (pktPTS != PESPacket::PTS_INVALID)
{ // An entry exists in the work list
nowPTS = Video::getInstance()->getCurrentTimestamp();
PTSDifference(pktPTS, nowPTS) < 4000)
{ // It is due for processing or discarding.
finished = false;
- lockInput();
+ input_mutex.lock();
if (!worklist.empty())
{
PESPacket packet = worklist.front();
worklist.pop_front();
- unlockInput();
- lockOutput();
+ input_mutex.unlock();
+ output_mutex.lock();
if (showing) decodePacket(packet);
- unlockOutput();
+ output_mutex.unlock();
}
- else unlockInput();
+ else input_mutex.unlock();
}
else if (PTSDifference(pktPTS, nowPTS) >= 60*90000)
{ // Seems like a bad or very old entry. Get rid of it.
finished = false;
- lockInput();
+ input_mutex.lock();
if (!worklist.empty()) worklist.pop_front();
- unlockInput();
+ input_mutex.unlock();
}
}
}
void DVBSubtitles::setOSDMenuVisibility(bool visible)
{
- lockOutput();
+ output_mutex.lock();
osdMenuShowing = visible;
- unlockOutput();
+ output_mutex.unlock();
}
#include <vector>
#include <deque>
#include <map>
+#include <mutex>
class cTimeMs {
private:
void lockOutput();
void unlockOutput();
void threadMethod();
-#ifndef WIN32
- pthread_mutex_t input_mutex;
- pthread_mutex_t output_mutex;
-#else
- HANDLE input_mutex;
- HANDLE output_mutex;
-#endif
+
+ std::mutex input_mutex;
+ std::mutex output_mutex;
};
#endif
along with VOMP. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "playerradio.h"
-
#include "log.h"
#include "audio.h"
#include "video.h"
#include "message.h"
#include "messagequeue.h"
+#include "playerradio.h"
+
// ----------------------------------- Called from outside, one offs or info funcs
PlayerRadio::PlayerRadio(MessageQueue* tmessageQueue, void* tmessageReceiver)
-: afeed(this)
+: messageQueue(tmessageQueue), messageReceiver(tmessageReceiver), afeed(this)
{
- messageQueue = tmessageQueue;
- messageReceiver = tmessageReceiver;
audio = Audio::getInstance();
logger = Log::getInstance();
vdr = VDR::getInstance();
- initted = false;
- lengthBytes = 0;
- lengthFrames = 0;
- currentFrameNumber = 0;
- state = S_STOP;
-
- startPTS = 0;
- lengthSeconds = 0;
-
- threadBuffer = NULL;
-
- blockSize = 10000;
- startupBlockSize = 20000;
-
Video::getInstance()->turnVideoOff();
}
if (initted) shutdown();
}
-int PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthFrames, bool isPesRecording)
+bool PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthFrames, bool isPesRecording)
{
- if (initted) return 0;
-#ifndef WIN32
- pthread_mutex_init(&mutex, NULL);
-#else
- mutex=CreateMutex(NULL,FALSE,NULL);
-#endif
+ if (initted) return false;
if (isPesRecording)
demuxer = new DemuxerVDR();
else
demuxer = new DemuxerTS();
- if (!demuxer) return 0;
+ if (!demuxer) return false;
if (!demuxer->init(this, audio, NULL, NULL, 0, 40000, 0))
{
logger->log("PlayerRadio", Log::ERR, "Demuxer failed to init");
shutdown();
- return 0;
+ return false;
}
afeed.init();
logger->log("PlayerRadio", Log::ERR, "Failed to get start block");
shutdown();
if (!vdr->isConnected()) doConnectionLost();
- return 0;
+ return false;
}
success = demuxer->findPTS(buffer, thisRead, &startPTS);
logger->log("PlayerRadio", Log::ERR, "Failed to get start PTS");
free(buffer);
shutdown();
- return 0;
+ return false;
}
free(buffer);
{
logger->log("PlayerRadio", Log::ERR, "Failed to setLengthSeconds");
shutdown();
- return 0;
+ return false;
}
initted = true;
- return 1;
+ return true;
}
bool PlayerRadio::setLengthSeconds()
if (startPTS < endPTS)
{
- lengthSeconds = (endPTS - startPTS) / 90000;
+ lengthSeconds = static_cast<ULONG>((endPTS - startPTS) / 90000);
}
else
{
- lengthSeconds = (startPTS - endPTS) / 90000;
+ lengthSeconds = static_cast<ULONG>((startPTS - endPTS) / 90000);
}
return true;
delete demuxer;
demuxer = NULL;
-#ifdef WIN32
- CloseHandle(mutex);
-#endif
-
return 1;
}
long long currentPTS = demuxer->getAudioPTS();
currentPTS -= startPTS;
if (currentPTS < 0) currentPTS += 8589934592ULL;
- ULONG ret = currentPTS / 90000;
+ ULONG ret = static_cast<ULONG>(currentPTS / 90000);
return ret;
}
{
if (!initted) return;
if (state == S_PLAY) return;
- lock();
+ stateLock.lock();
switchState(S_PLAY);
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::playpause()
{
if (!initted) return;
- lock();
+ stateLock.lock();
if (state==S_PLAY) {
switchState(S_PAUSE_P);
} else {
switchState(S_PLAY);
}
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::stop()
{
if (!initted) return;
if (state == S_STOP) return;
- lock();
+ stateLock.lock();
logger->log("PlayerRadio", Log::DEBUG, "Stop called lock");
switchState(S_STOP);
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::pause()
{
if (!initted) return;
- lock();
+ stateLock.lock();
if (state == S_PAUSE_P)
{
switchState(S_PAUSE_P);
}
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::jumpToPercent(double percent)
{
- lock();
+ stateLock.lock();
logger->log("PlayerRadio", Log::DEBUG, "JUMP TO %i%%", percent);
- ULONG newFrame = (ULONG)(percent * lengthFrames / 100);
+ ULONG newFrame = static_cast<ULONG>(percent * lengthFrames / 100);
switchState(S_JUMP, newFrame);
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::skipForward(UINT seconds)
{
- lock();
+ stateLock.lock();
logger->log("PlayerRadio", Log::DEBUG, "SKIP FORWARD %i SECONDS", seconds);
ULONG currentSeconds = getCurrentSeconds();
ULONG currentFrame = demuxer->getPacketNum();
- if (currentSeconds == 0) { unLock(); return; } // div by zero
- if (currentFrame == 0) { unLock(); return; } // Current pos from demuxer is not valid
+ if (currentSeconds == 0) { stateLock.unlock(); return; } // div by zero
+ if (currentFrame == 0) { stateLock.unlock(); return; } // Current pos from demuxer is not valid
ULONG newFrame = currentFrame + (currentFrame * seconds / currentSeconds);
- if (newFrame > lengthFrames) { switchState(S_PLAY); unLock(); }
+ if (newFrame > lengthFrames) { switchState(S_PLAY); stateLock.unlock(); }
else switchState(S_JUMP, newFrame);
- unLock();
+ stateLock.unlock();
}
void PlayerRadio::skipBackward(UINT seconds)
{
- lock();
+ stateLock.lock();
logger->log("PlayerRadio", Log::DEBUG, "SKIP BACKWARD %i SECONDS", seconds);
ULONG currentSeconds = getCurrentSeconds();
ULONG currentFrame = demuxer->getPacketNum();
- if (currentSeconds == 0) { unLock(); return; } // div by zero
- if (currentFrame == 0) { unLock(); return; } // Current pos from demuxer is not valid
+ if (currentSeconds == 0) { stateLock.unlock(); return; } // div by zero
+ if (currentFrame == 0) { stateLock.unlock(); return; } // Current pos from demuxer is not valid
ULONG newFrame;
- if ((UINT)seconds > currentSeconds)
+ if (seconds > currentSeconds)
newFrame = 0;
else
newFrame = currentFrame - (currentFrame * seconds / currentSeconds);
switchState(S_JUMP, newFrame);
- unLock();
+ stateLock.unlock();
}
// ----------------------------------- Implementations called events
// ----------------------------------- Internal functions
-void PlayerRadio::lock()
-{
-#ifndef WIN32
- pthread_mutex_lock(&mutex);
- logger->log("PlayerRadio", Log::DEBUG, "LOCKED");
-
-#else
- WaitForSingleObject(mutex, INFINITE);
-#endif
-}
-
-void PlayerRadio::unLock()
-{
-#ifndef WIN32
- logger->log("PlayerRadio", Log::DEBUG, "UNLOCKING");
- pthread_mutex_unlock(&mutex);
-#else
- ReleaseMutex(mutex);
-#endif
-}
-
void PlayerRadio::restartAtFrame(ULONG newFrame)
{
afeed.stop();
if (startup)
{
if (startupBlockSize > lengthBytes)
- askFor = lengthBytes; // is a very small recording!
+ askFor = static_cast<UINT>(lengthBytes); // is a very small recording!
else
askFor = startupBlockSize; // normal, but a startup sized block to detect all the audio streams
}
else
{
if ((feedPosition + blockSize) > lengthBytes) // last block of recording
- askFor = lengthBytes - feedPosition;
+ askFor = static_cast<UINT>(lengthBytes - feedPosition);
else // normal
askFor = blockSize;
}
#endif
#include <time.h>
+#include <mutex>
+
#include "threadsystem.h"
#include "callback.h"
PlayerRadio(MessageQueue* messageQueue, void* messageReceiver);
virtual ~PlayerRadio();
- int init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
+ bool init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
int shutdown();
void setCurrentFrameNumber(ULONG num);
VDR* vdr;
AFeed afeed;
- bool initted;
+ bool initted{};
bool startup;
- ULLONG startPTS;
- ULONG lengthSeconds;
+ ULLONG startPTS{};
+ ULONG lengthSeconds{};
-#ifndef WIN32
- pthread_mutex_t mutex;
-#else
- HANDLE mutex;
-#endif
- void lock();
- void unLock();
-
- ULLONG lengthBytes;
- ULONG lengthFrames;
- ULONG currentFrameNumber;
- UINT blockSize;
- UINT startupBlockSize;
- UCHAR* threadBuffer;
- UCHAR state;
+ std::mutex stateLock;
+
+ ULLONG lengthBytes{};
+ ULONG lengthFrames{};
+ ULONG currentFrameNumber{};
+ static const UINT blockSize{10000};
+ static const UINT startupBlockSize{20000};
+ UCHAR* threadBuffer{};
+ UCHAR state{S_STOP};
};
#endif
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "stream.h"
-#include "log.h"
+#include <stdlib.h>
+#include <string.h>
-Stream::Stream()
-{
- initted = 0;
- draintarget = NULL;
- cur_packet_pos = 0;
-}
+#include "log.h"
+#include "stream.h"
Stream::~Stream()
{
void Stream::shutdown()
{
- if (initted)
- {
- free(outbuf);
-#ifdef WIN32
- CloseHandle(mutex);
-#endif
-
- }
+ if (initted) free(outbuf);
initted = 0;
}
int Stream::init(DrainTarget* tdt, int bufsize)
{
- outbuf = (UCHAR*) malloc(bufsize);
+ outbuf = (UCHAR*)malloc(bufsize);
if (!outbuf) return 0;
draintarget = tdt;
bufferSize = bufsize;
initted = 1;
-#ifndef WIN32
- pthread_mutex_init(&mutex, NULL);
-#else
- mutex=CreateMutex(NULL,FALSE,NULL);
-#endif
return 1;
}
void Stream::flush()
{
- lock();
-
+ mutex.lock();
mediapackets.clear();
cur_packet_pos = 0;
- unLock();
+ mutex.unlock();
+
if (draintarget) draintarget->ResetTimeOffsets();
}
}
}
- lock();
+ mutex.lock();
int front, back;
if (mediapackets.empty())
{
back = mediapackets.back().pos_buffer + mediapackets.back().length;
if (back == bufferSize) back = 0;
}
- unLock();
+ mutex.unlock();
if (back <= front)
{
{
memcpy(outbuf + back, inbuf, len);
newPacket.pos_buffer = back;
- lock();
+ mutex.lock();
mediapackets.push_back(newPacket);
- unLock();
+ mutex.unlock();
} else {
// Log::getInstance()->log("Stream", Log::DEBUG, "We are full %d!",bufferSize);
}
bool Stream::drain(bool * dataavail)
{
bool ret = false;
- if (dataavail) *dataavail=false;
+ if (dataavail) *dataavail = false;
if (draintarget->DrainTargetBufferFull()) return false; //We are full, no need to do something else
- lock();
+ mutex.lock();
UINT listlength = mediapackets.size();
if (listlength != 0)
{
draintarget->PrepareMediaSample(mediapackets, cur_packet_pos);
- unLock();
- if (dataavail && draintarget->DrainTargetReady()) *dataavail=true;
+ mutex.unlock();
+ if (dataavail && draintarget->DrainTargetReady()) *dataavail = true;
UINT consumed = draintarget->DeliverMediaSample(outbuf, &cur_packet_pos);
- lock();
+ mutex.lock();
if (consumed != 0) ret = true;
if (consumed > listlength) consumed = listlength;
while (consumed--)
mediapackets.pop_front();
}
}
- unLock();
+ mutex.unlock();
return ret;
}
-
-void Stream::lock()
-{
-#ifndef WIN32
- pthread_mutex_lock(&mutex);
- //logger->log("Player", Log::DEBUG, "LOCKED");
-
-#else
- WaitForSingleObject(mutex, INFINITE );
-#endif
-}
-
-void Stream::unLock()
-{
-#ifndef WIN32
- //logger->log("Player", Log::DEBUG, "UNLOCKING");
- pthread_mutex_unlock(&mutex);
-#else
- ReleaseMutex(mutex);
-#endif
-}
#ifndef STREAM_H
#define STREAM_H
-#ifndef WIN32
-#include <pthread.h>
-#endif
+#include <mutex>
-#include <stdlib.h>
-#ifndef WIN32
-#include <unistd.h>
-#else
-#include <winsock2.h>
-#include <windows.h>
-#endif
-#include <memory.h>
#include "defines.h"
-
#include "draintarget.h"
class Stream
{
public:
- Stream();
~Stream();
int init(DrainTarget* tdt, int bufsize);
void shutdown();
void flush();
- int put(const UCHAR* inbuf, int len, UCHAR type,unsigned int index);
- bool drain(bool * dataavail=NULL);
+ int put(const UCHAR* inbuf, int len, UCHAR type, UINT index);
+ bool drain(bool* dataavail = NULL);
private:
MediaPacketList mediapackets;
- UINT cur_packet_pos;
-#ifndef WIN32
- pthread_mutex_t mutex;
-#else
- HANDLE mutex;
-#endif
- void lock();
- void unLock();
-
- DrainTarget* draintarget;
- int initted;
+ UINT cur_packet_pos{};
+ std::mutex mutex;
+ DrainTarget* draintarget{};
+ int initted{};
UCHAR* outbuf;
int bufferSize;
};
#include "tcp.h"
-#ifndef WIN32
-#define MUTEX_LOCK(mutex) pthread_mutex_lock(mutex)
-#define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(mutex)
-#else
-#define MUTEX_LOCK(mutex) WaitForSingleObject(*(mutex), INFINITE )
-#define MUTEX_UNLOCK(mutex) ReleaseMutex(*(mutex))
-#endif
-
TCP::TCP()
{
sock = 0;
connected = 0;
timeoutEnabled = 1;
-
-#ifndef WIN32
- pthread_mutex_init(&mutex, NULL);
-#else
- mutex=CreateMutex(NULL,FALSE,NULL);
-#endif
}
TCP::~TCP()
CLOSESOCKET(sock);
Log::getInstance()->log("TCP", Log::DEBUG, "Have closed");
}
-
-#ifdef WIN32
- CloseHandle(mutex);
-#endif
}
void TCP::disableTimeout()
unsigned char* buf = static_cast<unsigned char*>(bufR);
- MUTEX_LOCK(&mutex);
+ mutex.lock();
while (bytes_sent < count)
{
#endif
if (this_write <= 0)
{
- MUTEX_UNLOCK(&mutex);
+ mutex.unlock();
return(this_write);
}
bytes_sent += this_write;
buf += this_write;
}
- MUTEX_UNLOCK(&mutex);
+ mutex.unlock();
return(count);
}
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
+#include <mutex>
#ifndef WIN32
#include <sys/socket.h>
int connected;
int timeoutEnabled;
int dataLength;
-
-#ifndef WIN32
- pthread_mutex_t mutex;
-#else
- HANDLE mutex;
-#endif
+ std::mutex mutex;
static UCHAR dcc(UCHAR c);
};
lastaudiomode=MPTYPE_MPEG_AUDIO;
//lastaudiomode=MPTYPE_AC3;
dsvmrsurfnotify=NULL;
- filtermutex=CreateMutex(NULL,FALSE,NULL);
offsetnotset=true;
offsetvideonotset=true;
offsetaudionotset=true;
VideoWin::~VideoWin()
{
CleanupDS();
- CloseHandle(filtermutex);
unsigned int i;
for (i=0;i<videofilterlist.size();i++)
{
CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsrenderer)!=S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
}
/*VMR 9 stuff**/
if (hres=dsgraphbuilder->AddFilter(dsrenderer,L"VMR9")!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!");
return 0;
IVMRFilterConfig9* vmrfilconfig;
if (dsrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!");
return 0;
if (dsrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,
(void**)& dsvmrsurfnotify) != S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!");
return 0;
IVMRDeinterlaceControl9* deintctrl;
if (dsrenderer->QueryInterface(IID_IVMRDeinterlaceControl9,(void**)&deintctrl)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Deinterlace control!");
return 0;
CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsrenderer)!=S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating EVR renderer!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
}
/*EVR stuff**/
if (hres=dsgraphbuilder->AddFilter(dsrenderer,L"EVR")!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding EVR renderer!");
return 0;
IMFGetService *evr_services;
if (dsrenderer->QueryInterface(IID_IMFGetService,(void**)&evr_services)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting EVR IMFGetServices interface!");
return 0;
IMFVideoDisplayControl* mfvideodisplaycontrol;
if (evr_services->GetService(MR_VIDEO_RENDER_SERVICE,IID_IMFVideoDisplayControl,(void**)&mfvideodisplaycontrol)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting EVR IMFVideoDisplayControl interface!");
return 0;
IMFVideoRenderer *mfvideorenderer;
if (dsrenderer->QueryInterface(IID_IMFVideoRenderer,(void**)&mfvideorenderer)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting EVR IMFVideoRenderer interface!");
return 0;
/* IVMRDeinterlaceControl9* deintctrl;
if (dsrenderer->QueryInterface(IID_IVMRDeinterlaceControl9,(void**)&deintctrl)!=S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Deinterlace control!");
return 0;
if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!= S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!");
fg2->Release();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
if (hres=dsgraphbuilder->AddFilter(videofilter,NULL) != S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Video Filter!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
{
Log::getInstance()->log("VideoWin", Log::WARN , "Video Filter has no suitable input!");
videofilter->Release();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
{
Log::getInstance()->log("VideoWin", Log::WARN , "Video Filter has no suitable output!");
videofilter->Release();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
//Build filter graph
HRESULT hres;
//So this is the real code, this prevents the feeder from calling noexisting objects!
- WaitForSingleObject(filtermutex,INFINITE);
+ filtermutex.lock();
if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,(void**)&dsgraphbuilder) != S_OK)
{
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 0;
}
#ifdef DS_DEBUG
if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter") != S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
/*if (hres=dsgraphbuilder->Render((IPin*)sourcefilter->GetAudioPin()/*audio*)!=S_OK)
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering audio!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}*/
if (((AudioWin*)Audio::getInstance())->dsInitAudioFilter(dsgraphbuilder)==0)
{
Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering audio!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
hresdeb=dsmediacontrol->Run();
iframemode=false;//exit iframe mode
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 1;
}
if (!initted) return 0;
CleanupDS();
//So this is the real code, this prevents the feeder from calling noexisting objects!
- WaitForSingleObject(filtermutex,INFINITE);
+ filtermutex.lock();
iframemode=true;//enter iframe mode
//Build filter graph
HRESULT hres;
if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) {
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 0;
}
#ifdef DS_DEBUG
// to DirectShow
if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {
Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
CleanupDS();
return 0;
}
dsmediacontrol->Run();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 1;
}
int VideoWin::dspause()
{
if (!initted) return 0;
- WaitForSingleObject(filtermutex,INFINITE);
+ filtermutex.lock();
if (dsmediacontrol) dsmediacontrol->Pause();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 1;
}
int VideoWin::dsunPause() // FIXME get rid - same as play!!
{//No on windows this is not the same, I don't get rid of!
if (!initted) return 0;
- WaitForSingleObject(filtermutex,INFINITE);
+ filtermutex.lock();
if (dsmediacontrol) dsmediacontrol->Run();
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
return 1;
}
*/
void VideoWin::CleanupDS()
{
- WaitForSingleObject(filtermutex,INFINITE);
+ filtermutex.lock();
dsinited=false;
if (dsmediacontrol)dsmediacontrol->Stop();
if (cur_audio_media_sample) {
sourcefilter=NULL; //The Graph Builder destroys our SourceFilter
}
- ReleaseMutex(filtermutex);
+ filtermutex.unlock();
}
int VideoWin::getCurrentAudioMediaSample(IMediaSample** ms)
{
- //WaitForSingleObject(filtermutex,INFINITE);
+ //filtermutex.lock();
if (!sourcefilter){
- // ReleaseMutex(filtermutex);
+ // filtermutex.unlock();
return 0;
}
if (cur_audio_media_sample) {
return 1;
}
if (!sourcefilter->getCurrentAudioMediaSample(ms)) {
- // ReleaseMutex(filtermutex);
+ // filtermutex.unlock();
}
if (*ms) (*ms)->SetActualDataLength(0);
cur_audio_media_sample=*ms;
int VideoWin::getCurrentVideoMediaSample(IMediaSample** ms)
{
- //WaitForSingleObject(filtermutex,INFINITE);
+ //filtermutex.lock();
if (!sourcefilter){
- // ReleaseMutex(filtermutex);
+ // filtermutex.unlock();
return 0;
}
if (cur_video_media_sample) {
return 1;
}
if (!sourcefilter->getCurrentVideoMediaSample(ms)) {
- // ReleaseMutex(filtermutex);
+ // filtermutex.unlock();
}
if (*ms) (*ms)->SetActualDataLength(0);
sourcefilter->DeliverAudioMediaSample(cur_audio_media_sample);
cur_audio_media_sample=NULL;
}
- //ReleaseMutex(filtermutex);
+ //filtermutex.unlock();
return 1;
}
sourcefilter->DeliverVideoMediaSample(cur_video_media_sample);
cur_video_media_sample=NULL;
}
- //ReleaseMutex(filtermutex);
+ //filtermutex.unlock();
return 1;
}
#include <d3d9.h>
#include <vmr9.h>
#include <vector>
+#include <mutex>
#include "defines.h"
#include "video.h"
DsSourceFilter* sourcefilter;
DsAllocator* allocatorvmr;
- HANDLE filtermutex;
+ std::mutex filtermutex;
void CleanupDS();
bool offsetnotset;
bool offsetvideonotset;
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
#include "windowsosd.h"
#include "dsallocator.h"
#include "video.h"
#include "log.h"
#include "colour.h"
-
typedef HRESULT(__stdcall *FCT_DXVA2CreateDirect3DDeviceManager9)(UINT* pResetToken, IDirect3DDeviceManager9** ppDeviceManager);
typedef HRESULT(__stdcall *FCT_MFCreateVideoSampleFromSurface)(IUnknown* pUnkSurface, IMFSample** ppSample);
FCT_DXVA2CreateDirect3DDeviceManager9 ptrDXVA2CreateDirect3DDeviceManager9 = NULL;
FCT_MFCreateVideoSampleFromSurface ptrMFCreateVideoSampleFromSurface = NULL;
-
WindowsOsd::WindowsOsd()
{
d3d = NULL;
lastrendertime = timeGetTime();
event = CreateEvent(NULL,/*FALSE*/TRUE, FALSE, NULL);
- d3dmutex = CreateMutex(NULL, FALSE, NULL);
/*EVR stuff*/
dxvadevicehandle = NULL;
WindowsOsd::~WindowsOsd()
{
CloseHandle(event);
- CloseHandle(d3dmutex);
}
void WindowsOsd::BeginPainting() {//We synchronize calls to d3d between different threads
- WaitForSingleObject(d3dmutex, INFINITE);
+ d3dmutex.lock();
LockDevice();
}
void WindowsOsd::EndPainting() {
UnlockDevice();
- ReleaseMutex(d3dmutex);
+ d3dmutex.unlock();
}
DWORD WindowsOsd::getFilterCaps()
#ifndef WINDOWSOSD_H
#define WINDOWSOSD_H
+#include <mutex>
#include <winsock2.h>
#include <d3d9.h>
#include <Dxva2api.h>
void BeginPainting();
void EndPainting();
- virtual int isInitialized()=0;
+ virtual bool isInitialized()=0;
void threadMethod();
DsAllocator* dsallocator;
bool external_driving;
- HANDLE d3dmutex;
+ std::mutex d3dmutex;
HANDLE event;
DWORD lastrendertime;
DWORD lastosdrendertime;