From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/cores/VideoPlayer/DVDMessage.cpp | 110 ++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 xbmc/cores/VideoPlayer/DVDMessage.cpp (limited to 'xbmc/cores/VideoPlayer/DVDMessage.cpp') diff --git a/xbmc/cores/VideoPlayer/DVDMessage.cpp b/xbmc/cores/VideoPlayer/DVDMessage.cpp new file mode 100644 index 0000000..34e8076 --- /dev/null +++ b/xbmc/cores/VideoPlayer/DVDMessage.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "DVDMessage.h" + +#include "DVDDemuxers/DVDDemuxUtils.h" +#include "threads/Condition.h" +#include "threads/CriticalSection.h" +#include "threads/SystemClock.h" +#include "utils/MathUtils.h" +#include "utils/log.h" + +#include +#include + +using namespace std::chrono_literals; + +class CDVDMsgGeneralSynchronizePriv +{ +public: + CDVDMsgGeneralSynchronizePriv(std::chrono::milliseconds timeout, unsigned int sources) + : sources(sources), reached(0), m_timer(timeout) + {} + unsigned int sources; + unsigned int reached; + CCriticalSection section; + XbmcThreads::ConditionVariable condition; + XbmcThreads::EndTime<> m_timer; +}; + +/** + * CDVDMsgGeneralSynchronize --- GENERAL_SYNCRONIZR + */ +CDVDMsgGeneralSynchronize::CDVDMsgGeneralSynchronize(std::chrono::milliseconds timeout, + unsigned int sources) + : CDVDMsg(GENERAL_SYNCHRONIZE), m_p(new CDVDMsgGeneralSynchronizePriv(timeout, sources)) +{ +} + +CDVDMsgGeneralSynchronize::~CDVDMsgGeneralSynchronize() +{ + m_p->condition.notifyAll(); + + delete m_p; +} + +bool CDVDMsgGeneralSynchronize::Wait(std::chrono::milliseconds timeout, unsigned int source) +{ + std::unique_lock lock(m_p->section); + + XbmcThreads::EndTime<> timer{timeout}; + + m_p->reached |= (source & m_p->sources); + if ((m_p->sources & SYNCSOURCE_ANY) && source) + m_p->reached |= SYNCSOURCE_ANY; + + m_p->condition.notifyAll(); + + while (m_p->reached != m_p->sources) + { + timeout = std::min(m_p->m_timer.GetTimeLeft(), timer.GetTimeLeft()); + if (m_p->condition.wait(lock, timeout)) + continue; + + if (m_p->m_timer.IsTimePast()) + { + CLog::Log(LOGDEBUG, "CDVDMsgGeneralSynchronize - global timeout"); + return true; // global timeout, we are done + } + if (timer.IsTimePast()) + { + return false; /* request timeout, should be retried */ + } + } + return true; +} + +void CDVDMsgGeneralSynchronize::Wait(std::atomic& abort, unsigned int source) +{ + while (!Wait(100ms, source) && !abort) + ; +} + +/** + * CDVDMsgDemuxerPacket --- DEMUXER_PACKET + */ +CDVDMsgDemuxerPacket::CDVDMsgDemuxerPacket(DemuxPacket* packet, bool drop) : CDVDMsg(DEMUXER_PACKET) +{ + m_packet = packet; + m_drop = drop; +} + +CDVDMsgDemuxerPacket::~CDVDMsgDemuxerPacket() +{ + if (m_packet) + CDVDDemuxUtils::FreeDemuxPacket(m_packet); +} + +unsigned int CDVDMsgDemuxerPacket::GetPacketSize() +{ + if (m_packet) + return m_packet->iSize; + else + return 0; +} -- cgit v1.2.3