[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / cores / VideoPlayer / DVDMessage.cpp
blobc0665a79014b2b9dc915ba0ac6fca2b9734bb4a5
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "DVDMessage.h"
11 #include "DVDDemuxers/DVDDemuxUtils.h"
12 #include "threads/Condition.h"
13 #include "threads/CriticalSection.h"
14 #include "threads/SystemClock.h"
15 #include "utils/MathUtils.h"
16 #include "utils/log.h"
18 #include <algorithm>
19 #include <mutex>
21 using namespace std::chrono_literals;
23 class CDVDMsgGeneralSynchronizePriv
25 public:
26 CDVDMsgGeneralSynchronizePriv(std::chrono::milliseconds timeout, unsigned int sources)
27 : sources(sources), m_timer(timeout)
29 unsigned int sources;
30 unsigned int reached = 0;
31 CCriticalSection section;
32 XbmcThreads::ConditionVariable condition;
33 XbmcThreads::EndTime<> m_timer;
36 /**
37 * CDVDMsgGeneralSynchronize --- GENERAL_SYNCRONIZR
39 CDVDMsgGeneralSynchronize::CDVDMsgGeneralSynchronize(std::chrono::milliseconds timeout,
40 unsigned int sources)
41 : CDVDMsg(GENERAL_SYNCHRONIZE), m_p(new CDVDMsgGeneralSynchronizePriv(timeout, sources))
45 CDVDMsgGeneralSynchronize::~CDVDMsgGeneralSynchronize()
47 m_p->condition.notifyAll();
49 delete m_p;
52 bool CDVDMsgGeneralSynchronize::Wait(std::chrono::milliseconds timeout, unsigned int source)
54 std::unique_lock<CCriticalSection> lock(m_p->section);
56 XbmcThreads::EndTime<> timer{timeout};
58 m_p->reached |= (source & m_p->sources);
59 if ((m_p->sources & SYNCSOURCE_ANY) && source)
60 m_p->reached |= SYNCSOURCE_ANY;
62 m_p->condition.notifyAll();
64 while (m_p->reached != m_p->sources)
66 timeout = std::min(m_p->m_timer.GetTimeLeft(), timer.GetTimeLeft());
67 if (m_p->condition.wait(lock, timeout))
68 continue;
70 if (m_p->m_timer.IsTimePast())
72 CLog::Log(LOGDEBUG, "CDVDMsgGeneralSynchronize - global timeout");
73 return true; // global timeout, we are done
75 if (timer.IsTimePast())
77 return false; /* request timeout, should be retried */
80 return true;
83 void CDVDMsgGeneralSynchronize::Wait(std::atomic<bool>& abort, unsigned int source)
85 while (!Wait(100ms, source) && !abort)
89 /**
90 * CDVDMsgDemuxerPacket --- DEMUXER_PACKET
92 CDVDMsgDemuxerPacket::CDVDMsgDemuxerPacket(DemuxPacket* packet, bool drop) : CDVDMsg(DEMUXER_PACKET)
94 m_packet = packet;
95 m_drop = drop;
98 CDVDMsgDemuxerPacket::~CDVDMsgDemuxerPacket()
100 if (m_packet)
101 CDVDDemuxUtils::FreeDemuxPacket(m_packet);
104 unsigned int CDVDMsgDemuxerPacket::GetPacketSize()
106 if (m_packet)
107 return m_packet->iSize;
108 else
109 return 0;