7d6e14115f8df143fa8f1d50074514ce3c41f24b
[buildroot.git] /
1 From 482d898333facf53bd3208cf5e44a0cf3e1f4f3b Mon Sep 17 00:00:00 2001
2 From: phunkyfish <phunkyfish@gmail.com>
3 Date: Thu, 8 Oct 2020 14:59:55 +0100
4 Subject: [PATCH] Use std::thread, std::mutex, condition_variable instead of
5 event
6
7 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
8 ---
9 src/lib/tsreader/DeMultiplexer.cpp | 2 +-
10 src/lib/tsreader/DeMultiplexer.h | 4 +-
11 src/lib/tsreader/FileReader.cpp | 2 +-
12 src/lib/tsreader/MemoryBuffer.cpp | 15 +++--
13 src/lib/tsreader/MemoryBuffer.h | 7 +-
14 src/lib/tsreader/MemoryReader.h | 1 +
15 src/lib/tsreader/MemorySink.cpp | 2 +-
16 src/lib/tsreader/MemorySink.h | 4 +-
17 src/lib/tsreader/MepoRTSPClient.cpp | 28 ++++----
18 src/lib/tsreader/MepoRTSPClient.h | 10 ++-
19 src/lib/tsreader/MultiFileReader.cpp | 9 ++-
20 src/os-dependent.h | 95 ++++++++++++++++++++++++++++
21 src/pvrclient-mediaportal.cpp | 29 ++++-----
22 src/pvrclient-mediaportal.h | 21 +++---
23 14 files changed, 168 insertions(+), 61 deletions(-)
24
25 diff --git a/src/lib/tsreader/DeMultiplexer.cpp b/src/lib/tsreader/DeMultiplexer.cpp
26 index 436e452..3d0d9a2 100644
27 --- a/src/lib/tsreader/DeMultiplexer.cpp
28 +++ b/src/lib/tsreader/DeMultiplexer.cpp
29 @@ -104,7 +104,7 @@ namespace MPTV
30 if (m_filter.IsSeeking())
31 return 0; // Ambass : to check
32
33 - P8PLATFORM::CLockObject lock(m_sectionRead);
34 + std::lock_guard<std::mutex> lock(m_sectionRead);
35 if (NULL == m_reader)
36 return 0;
37
38 diff --git a/src/lib/tsreader/DeMultiplexer.h b/src/lib/tsreader/DeMultiplexer.h
39 index c7cd577..72ed87d 100644
40 --- a/src/lib/tsreader/DeMultiplexer.h
41 +++ b/src/lib/tsreader/DeMultiplexer.h
42 @@ -37,7 +37,7 @@
43 #include "PacketSync.h"
44 #include "TSHeader.h"
45 #include "PatParser.h"
46 -#include "p8-platform/threads/mutex.h"
47 +#include <mutex>
48
49 namespace MPTV
50 {
51 @@ -60,7 +60,7 @@ namespace MPTV
52 private:
53 unsigned long long m_LastDataFromRtsp;
54 bool m_bEndOfFile;
55 - P8PLATFORM::CMutex m_sectionRead;
56 + std::mutex m_sectionRead;
57 FileReader* m_reader;
58 CPatParser m_patParser;
59 CTsReader& m_filter;
60 diff --git a/src/lib/tsreader/FileReader.cpp b/src/lib/tsreader/FileReader.cpp
61 index 73b23af..358b05f 100644
62 --- a/src/lib/tsreader/FileReader.cpp
63 +++ b/src/lib/tsreader/FileReader.cpp
64 @@ -35,7 +35,7 @@
65 #include "FileReader.h"
66 #include <kodi/General.h> //for kodi::Log
67 #include "TSDebug.h"
68 -#include "p8-platform/threads/threads.h"
69 +#include "os-dependent.h"
70 #include <algorithm> //std::min, std::max
71 #include "utils.h"
72 #include <errno.h>
73 diff --git a/src/lib/tsreader/MemoryBuffer.cpp b/src/lib/tsreader/MemoryBuffer.cpp
74 index 0e736f2..b5400da 100644
75 --- a/src/lib/tsreader/MemoryBuffer.cpp
76 +++ b/src/lib/tsreader/MemoryBuffer.cpp
77 @@ -29,7 +29,7 @@
78
79 #ifdef LIVE555
80
81 -#include "p8-platform/threads/mutex.h"
82 +#include "os-dependent.h"
83 #include "MemoryBuffer.h"
84 #include <kodi/General.h> //for kodi::Log
85 #include "TSDebug.h"
86 @@ -56,7 +56,7 @@ bool CMemoryBuffer::IsRunning()
87
88 void CMemoryBuffer::Clear()
89 {
90 - P8PLATFORM::CLockObject BufferLock(m_BufferLock);
91 + std::lock_guard<std::mutex> BufferLock(m_BufferLock);
92 std::vector<BufferItem *>::iterator it = m_Array.begin();
93
94 for (auto& item : m_Array)
95 @@ -104,14 +104,17 @@ size_t CMemoryBuffer::ReadFromBuffer(unsigned char *pbData, size_t lDataLength)
96 {
97 if (!m_bRunning)
98 return 0;
99 - m_event.Wait(5000);
100 +
101 + std::unique_lock<std::mutex> lock(m_BufferLock);
102 + m_condition.wait_for(lock, std::chrono::milliseconds(5000));
103 +
104 if (!m_bRunning)
105 return 0;
106 }
107
108 // kodi::Log(ADDON_LOG_DEBUG, "get..%d/%d", lDataLength, m_BytesInBuffer);
109 size_t bytesWritten = 0;
110 - P8PLATFORM::CLockObject BufferLock(m_BufferLock);
111 + std::lock_guard<std::mutex> BufferLock(m_BufferLock);
112
113 while (bytesWritten < lDataLength)
114 {
115 @@ -172,7 +175,7 @@ long CMemoryBuffer::PutBuffer(unsigned char *pbData, size_t lDataLength)
116 memcpy(item->data, pbData, lDataLength);
117 bool sleep = false;
118 {
119 - P8PLATFORM::CLockObject BufferLock(m_BufferLock);
120 + std::lock_guard<std::mutex> BufferLock(m_BufferLock);
121 m_Array.push_back(item);
122 m_BytesInBuffer += lDataLength;
123
124 @@ -192,7 +195,7 @@ long CMemoryBuffer::PutBuffer(unsigned char *pbData, size_t lDataLength)
125 }
126 if (m_BytesInBuffer > 0)
127 {
128 - m_event.Broadcast();
129 + m_condition.notify_one();
130 }
131 }
132
133 diff --git a/src/lib/tsreader/MemoryBuffer.h b/src/lib/tsreader/MemoryBuffer.h
134 index 080553b..4f8708f 100644
135 --- a/src/lib/tsreader/MemoryBuffer.h
136 +++ b/src/lib/tsreader/MemoryBuffer.h
137 @@ -30,7 +30,8 @@
138
139 #ifdef LIVE555
140
141 -#include "p8-platform/threads/mutex.h"
142 +#include <condition_variable>
143 +#include <mutex>
144 #include <vector>
145
146 class CMemoryBuffer
147 @@ -55,9 +56,9 @@ class CMemoryBuffer
148
149 protected:
150 std::vector<BufferItem *> m_Array;
151 - P8PLATFORM::CMutex m_BufferLock;
152 + std::mutex m_BufferLock;
153 size_t m_BytesInBuffer;
154 - P8PLATFORM::CEvent m_event;
155 + std::condition_variable m_condition;
156 bool m_bRunning;
157 };
158 #endif //LIVE555
159 diff --git a/src/lib/tsreader/MemoryReader.h b/src/lib/tsreader/MemoryReader.h
160 index fef4f98..288984b 100644
161 --- a/src/lib/tsreader/MemoryReader.h
162 +++ b/src/lib/tsreader/MemoryReader.h
163 @@ -32,6 +32,7 @@
164
165 #include "FileReader.h"
166 #include "MemoryBuffer.h"
167 +#include "os-dependent.h"
168
169 namespace MPTV
170 {
171 diff --git a/src/lib/tsreader/MemorySink.cpp b/src/lib/tsreader/MemorySink.cpp
172 index dafef56..af8b74c 100644
173 --- a/src/lib/tsreader/MemorySink.cpp
174 +++ b/src/lib/tsreader/MemorySink.cpp
175 @@ -84,7 +84,7 @@ void CMemorySink::addData(unsigned char* data, size_t dataSize, struct timeval U
176 return;
177 }
178
179 - P8PLATFORM::CLockObject BufferLock(m_BufferLock);
180 + std::lock_guard<std::mutex> BufferLock(m_BufferLock);
181
182 m_bReEntrant = true;
183 m_buffer.PutBuffer(data, dataSize);
184 diff --git a/src/lib/tsreader/MemorySink.h b/src/lib/tsreader/MemorySink.h
185 index cc0f3c8..22d91c6 100644
186 --- a/src/lib/tsreader/MemorySink.h
187 +++ b/src/lib/tsreader/MemorySink.h
188 @@ -35,7 +35,7 @@
189 #endif
190
191 #include "MemoryBuffer.h"
192 -#include "p8-platform/threads/mutex.h"
193 +#include <mutex>
194
195 class CMemorySink: public MediaSink
196 {
197 @@ -57,7 +57,7 @@ class CMemorySink: public MediaSink
198 private: // redefined virtual functions:
199 virtual Boolean continuePlaying();
200
201 - P8PLATFORM::CMutex m_BufferLock;
202 + std::mutex m_BufferLock;
203 unsigned char* m_pSubmitBuffer;
204 int m_iSubmitBufferPos;
205 bool m_bReEntrant;
206 diff --git a/src/lib/tsreader/MepoRTSPClient.cpp b/src/lib/tsreader/MepoRTSPClient.cpp
207 index ccd6761..688ae84 100644
208 --- a/src/lib/tsreader/MepoRTSPClient.cpp
209 +++ b/src/lib/tsreader/MepoRTSPClient.cpp
210 @@ -54,7 +54,7 @@ CRTSPClient::CRTSPClient()
211 m_env = NULL;
212 m_fDuration = 0.0f;
213 m_url[0] = '\0';
214 - m_bRunning = false;
215 + m_running = false;
216 }
217
218 CRTSPClient::~CRTSPClient()
219 @@ -496,7 +496,9 @@ void CRTSPClient::StartBufferThread()
220
221 if (!m_BufferThreadActive)
222 {
223 - CreateThread();
224 + m_running = true;
225 + m_thread = std::thread([&] { Process(); });
226 +
227 m_BufferThreadActive = true;
228 }
229 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::StartBufferThread done");
230 @@ -505,11 +507,12 @@ void CRTSPClient::StartBufferThread()
231 void CRTSPClient::StopBufferThread()
232 {
233 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::StopBufferThread");
234 - m_bRunning = false;
235 + m_running = false;
236 if (!m_BufferThreadActive)
237 return;
238
239 - StopThread();
240 + if (m_thread.joinable())
241 + m_thread.join();
242
243 m_BufferThreadActive = false;
244 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::StopBufferThread done");
245 @@ -539,25 +542,22 @@ void CRTSPClient::FillBuffer(unsigned long byteCount)
246 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::Fillbuffer...%d/%d\n", byteCount, m_buffer->Size() );
247 }
248
249 -void *CRTSPClient::Process()
250 +void CRTSPClient::Process()
251 {
252 m_BufferThreadActive = true;
253 - m_bRunning = true;
254
255 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient:: thread started");
256
257 - while (m_env != NULL && !IsStopped())
258 + while (m_env != NULL && m_running)
259 {
260 m_env->taskScheduler().doEventLoop();
261 - if (m_bRunning == false)
262 + if (m_running == false)
263 break;
264 }
265
266 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient:: thread stopped");
267
268 m_BufferThreadActive = false;
269 -
270 - return NULL;
271 }
272
273 void CRTSPClient::Continue()
274 @@ -582,8 +582,12 @@ bool CRTSPClient::Pause()
275 if (m_ourClient != NULL && m_session != NULL)
276 {
277 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::Pause() stopthread");
278 - StopThread(10000); // Ambass : sometimes 100mS ( prev value ) is not enough and thread is not stopped.
279 - // now stopping takes around 5 secs ?!?! why ????
280 + // Ambass : sometimes 100mS ( prev value ) is not enough and thread is not stopped.
281 + // now stopping takes around 5 secs ?!?! why ????
282 + m_running = false;
283 + if (m_thread.joinable())
284 + m_thread.join();
285 +
286 kodi::Log(ADDON_LOG_DEBUG, "CRTSPClient::Pause() thread stopped");
287 RTSPClient* rtspClient=(RTSPClient*)m_ourClient;
288 rtspClient->pauseMediaSession(*m_session);
289 diff --git a/src/lib/tsreader/MepoRTSPClient.h b/src/lib/tsreader/MepoRTSPClient.h
290 index bd6e578..9bb0421 100644
291 --- a/src/lib/tsreader/MepoRTSPClient.h
292 +++ b/src/lib/tsreader/MepoRTSPClient.h
293 @@ -31,7 +31,8 @@
294
295 #ifdef LIVE555
296
297 -#include "p8-platform/threads/threads.h"
298 +#include <atomic>
299 +#include <thread>
300 #include "lib/tsreader/MemoryBuffer.h"
301
302 #include "liveMedia.hh"
303 @@ -41,7 +42,7 @@
304
305 #define RTSP_URL_BUFFERSIZE 2048
306
307 -class CRTSPClient: public P8PLATFORM::CThread
308 +class CRTSPClient
309 {
310 public:
311 CRTSPClient();
312 @@ -101,7 +102,7 @@ class CRTSPClient: public P8PLATFORM::CThread
313
314 // Thread
315 private:
316 - virtual void *Process(void);
317 + void Process();
318 void StartBufferThread();
319 void StopBufferThread();
320 bool m_BufferThreadActive;
321 @@ -113,5 +114,8 @@ class CRTSPClient: public P8PLATFORM::CThread
322 bool m_bRunning;
323 bool m_bPaused;
324 char m_outFileName[1000];
325 +
326 + std::atomic<bool> m_running = {false};
327 + std::thread m_thread;
328 };
329 #endif //LIVE555
330 diff --git a/src/lib/tsreader/MultiFileReader.cpp b/src/lib/tsreader/MultiFileReader.cpp
331 index 21fd7b2..5106418 100644
332 --- a/src/lib/tsreader/MultiFileReader.cpp
333 +++ b/src/lib/tsreader/MultiFileReader.cpp
334 @@ -35,17 +35,16 @@
335 #include "MultiFileReader.h"
336 #include <kodi/General.h> //for kodi::Log
337 #include <kodi/Filesystem.h>
338 +#include <kodi/tools/EndTime.h>
339 #include "TSDebug.h"
340 #include <string>
341 #include "utils.h"
342 #include <algorithm>
343 -#include "p8-platform/threads/threads.h"
344 #include <inttypes.h>
345 +#include "os-dependent.h"
346
347 #include <thread>
348
349 -using namespace P8PLATFORM;
350 -
351 //Maximum time in msec to wait for the buffer file to become available - Needed for DVB radio (this sometimes takes some time)
352 #define MAX_BUFFER_TIMEOUT 1500
353
354 @@ -121,12 +120,12 @@ namespace MPTV
355 if (RefreshTSBufferFile() == S_FALSE)
356 {
357 // For radio the buffer sometimes needs some time to become available, so wait and try it more than once
358 - P8PLATFORM::CTimeout timeout(MAX_BUFFER_TIMEOUT);
359 + kodi::tools::CEndTime timeout(MAX_BUFFER_TIMEOUT);
360
361 do
362 {
363 std::this_thread::sleep_for(std::chrono::milliseconds(100));
364 - if (timeout.TimeLeft() == 0)
365 + if (timeout.MillisLeft() == 0)
366 {
367 kodi::Log(ADDON_LOG_ERROR, "MultiFileReader: timed out while waiting for buffer file to become available");
368 kodi::QueueNotification(QUEUE_ERROR, "", "Time out while waiting for buffer file");
369 diff --git a/src/os-dependent.h b/src/os-dependent.h
370 index cdc6980..28c162c 100644
371 --- a/src/os-dependent.h
372 +++ b/src/os-dependent.h
373 @@ -11,6 +11,13 @@
374
375 #if (defined(_WIN32) || defined(_WIN64))
376
377 +#include <wchar.h>
378 +
379 +/* Handling of 2-byte Windows wchar strings */
380 +#define WcsLen wcslen
381 +#define WcsToMbs wcstombs
382 +typedef wchar_t Wchar_t; /* sizeof(wchar_t) = 2 bytes on Windows */
383 +
384 #ifndef _SSIZE_T_DEFINED
385 #ifdef _WIN64
386 typedef __int64 ssize_t;
387 @@ -20,20 +27,108 @@ typedef _W64 int ssize_t;
388 #define _SSIZE_T_DEFINED
389 #endif
390
391 +/* Prevent deprecation warnings */
392 +#define strnicmp _strnicmp
393 +
394 +#define PATH_SEPARATOR_CHAR '\\'
395 +
396 #else
397
398 #if (defined(TARGET_LINUX) || defined(TARGET_DARWIN))
399 #include <sys/types.h>
400 #include <chrono>
401 #include <cstring>
402 +
403 +#define strnicmp(X,Y,N) strncasecmp(X,Y,N)
404 +
405 inline unsigned long long GetTickCount64(void)
406 {
407 auto now = std::chrono::steady_clock::now();
408 return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
409 };
410 +
411 +#define PATH_SEPARATOR_CHAR '/'
412 +
413 +#if defined(__APPLE__)
414 +// for HRESULT
415 +#include <CoreFoundation/CFPlugInCOM.h>
416 +#endif
417 +
418 +/* Handling of 2-byte Windows wchar strings on non-Windows targets
419 + * Used by The MediaPortal and ForTheRecord pvr addons
420 + */
421 +typedef uint16_t Wchar_t; /* sizeof(wchar_t) = 4 bytes on Linux, but the MediaPortal buffer files have 2-byte wchars */
422 +
423 +/* This is a replacement of the Windows wcslen() function which assumes that
424 + * wchar_t is a 2-byte character.
425 + * It is used for processing Windows wchar strings
426 + */
427 +inline size_t WcsLen(const Wchar_t *str)
428 +{
429 + const unsigned short *eos = (const unsigned short*)str;
430 + while( *eos++ ) ;
431 + return( (size_t)(eos - (const unsigned short*)str) -1);
432 +};
433 +
434 +/* This is a replacement of the Windows wcstombs() function which assumes that
435 + * wchar_t is a 2-byte character.
436 + * It is used for processing Windows wchar strings
437 + */
438 +inline size_t WcsToMbs(char *s, const Wchar_t *w, size_t n)
439 +{
440 + size_t i = 0;
441 + const unsigned short *wc = (const unsigned short*) w;
442 + while(wc[i] && (i < n))
443 + {
444 + s[i] = wc[i];
445 + ++i;
446 + }
447 + if (i < n) s[i] = '\0';
448 +
449 + return (i);
450 +};
451 +
452 #endif /* TARGET_LINUX || TARGET_DARWIN */
453
454 #endif
455
456 +typedef long LONG;
457 +#if !defined(__APPLE__)
458 +typedef LONG HRESULT;
459 +#endif
460 +
461 +#ifndef FAILED
462 +#define FAILED(Status) ((HRESULT)(Status)<0)
463 +#endif
464 +
465 +#ifndef SUCCEEDED
466 +#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
467 +#endif
468 +
469 +#define _FILE_OFFSET_BITS 64
470 +#define FILE_BEGIN 0
471 +#define FILE_CURRENT 1
472 +#define FILE_END 2
473 +
474 +#ifndef S_OK
475 +#define S_OK 0L
476 +#endif
477 +
478 +#ifndef S_FALSE
479 +#define S_FALSE 1L
480 +#endif
481 +
482 +// Error codes
483 +#define ERROR_FILENAME_EXCED_RANGE 206L
484 +#define ERROR_INVALID_NAME 123L
485 +
486 +#ifndef E_OUTOFMEMORY
487 +#define E_OUTOFMEMORY 0x8007000EL
488 +#endif
489 +
490 +#ifndef E_FAIL
491 +#define E_FAIL 0x8004005EL
492 +#endif
493 +
494 // Additional typedefs
495 typedef uint8_t byte;
496 diff --git a/src/pvrclient-mediaportal.cpp b/src/pvrclient-mediaportal.cpp
497 index 851b940..c1052e3 100644
498 --- a/src/pvrclient-mediaportal.cpp
499 +++ b/src/pvrclient-mediaportal.cpp
500 @@ -28,8 +28,6 @@
501 #include <kodi/General.h>
502 #include <kodi/Filesystem.h>
503
504 -#include <thread>
505 -
506 using namespace kodi::tools;
507 using namespace std;
508 using namespace MPTV;
509 @@ -70,7 +68,6 @@ cPVRClientMediaPortal::cPVRClientMediaPortal(KODI_HANDLE instance, const std::st
510 m_BackendTime = 0;
511 m_tsreader = NULL;
512 m_genretable = NULL;
513 - m_iLastRecordingUpdate = 0;
514 m_signalStateCounter = 0;
515 m_iSignal = 0;
516 m_iSNR = 0;
517 @@ -99,7 +96,7 @@ string cPVRClientMediaPortal::SendCommand(const char* command)
518
519 string cPVRClientMediaPortal::SendCommand(const string& command)
520 {
521 - P8PLATFORM::CLockObject critsec(m_mutex);
522 + std::lock_guard<std::mutex> critsec(m_mutex);
523
524 if ( !m_tcpclient->send(command) )
525 {
526 @@ -174,10 +171,10 @@ ADDON_STATUS cPVRClientMediaPortal::TryConnect()
527 case PVR_CONNECTION_STATE_SERVER_UNREACHABLE:
528 kodi::Log(ADDON_LOG_ERROR, "Could not connect to MediaPortal TV Server backend.");
529 // Start background thread for connecting to the backend
530 - if (!IsRunning())
531 + if (!m_running)
532 {
533 - kodi::Log(ADDON_LOG_INFO, "Waiting for a connection in the background.");
534 - CreateThread();
535 + m_running = true;
536 + m_thread = std::thread([&] { Process(); });
537 }
538 return ADDON_STATUS_LOST_CONNECTION;
539 case PVR_CONNECTION_STATE_CONNECTING:
540 @@ -190,7 +187,7 @@ ADDON_STATUS cPVRClientMediaPortal::TryConnect()
541
542 PVR_CONNECTION_STATE cPVRClientMediaPortal::Connect(bool updateConnectionState)
543 {
544 - P8PLATFORM::CLockObject critsec(m_connectionMutex);
545 + std::lock_guard<std::mutex> critsec(m_connectionMutex);
546
547 string result;
548
549 @@ -317,9 +314,11 @@ void cPVRClientMediaPortal::Disconnect()
550
551 kodi::Log(ADDON_LOG_INFO, "Disconnect");
552
553 - if (IsRunning())
554 + if (m_running)
555 {
556 - StopThread(1000);
557 + m_running = false;
558 + if (m_thread.joinable())
559 + m_thread.join();
560 }
561
562 if (m_tcpclient->is_valid() && m_bTimeShiftStarted)
563 @@ -361,14 +360,14 @@ bool cPVRClientMediaPortal::IsUp()
564 }
565 }
566
567 -void* cPVRClientMediaPortal::Process(void)
568 +void cPVRClientMediaPortal::Process()
569 {
570 kodi::Log(ADDON_LOG_DEBUG, "Background thread started.");
571
572 bool keepWaiting = true;
573 PVR_CONNECTION_STATE state;
574
575 - while (!IsStopped() && keepWaiting)
576 + while (m_running && keepWaiting)
577 {
578 state = Connect(false);
579
580 @@ -396,8 +395,6 @@ void* cPVRClientMediaPortal::Process(void)
581 SetConnectionState(state);
582
583 kodi::Log(ADDON_LOG_DEBUG, "Background thread finished.");
584 -
585 - return NULL;
586 }
587
588
589 @@ -1188,7 +1185,7 @@ PVR_ERROR cPVRClientMediaPortal::GetRecordings(bool deleted, kodi::addon::PVRRec
590 }
591 }
592
593 - m_iLastRecordingUpdate = P8PLATFORM::GetTimeMs();
594 + m_iLastRecordingUpdate = std::chrono::system_clock::now();
595
596 return PVR_ERROR_NO_ERROR;
597 }
598 @@ -1383,7 +1380,7 @@ PVR_ERROR cPVRClientMediaPortal::GetTimers(kodi::addon::PVRTimersResultSet& resu
599 }
600 }
601
602 - if ( P8PLATFORM::GetTimeMs() > m_iLastRecordingUpdate + 15000)
603 + if ( std::chrono::system_clock::now() > m_iLastRecordingUpdate + std::chrono::milliseconds(15000))
604 {
605 kodi::addon::CInstancePVRClient::TriggerRecordingUpdate();
606 }
607 diff --git a/src/pvrclient-mediaportal.h b/src/pvrclient-mediaportal.h
608 index 3087634..e5da832 100644
609 --- a/src/pvrclient-mediaportal.h
610 +++ b/src/pvrclient-mediaportal.h
611 @@ -7,6 +7,10 @@
612
613 #pragma once
614
615 +#include <atomic>
616 +#include <chrono>
617 +#include <mutex>
618 +#include <thread>
619 #include <vector>
620
621 /* Master defines for client control */
622 @@ -17,8 +21,6 @@
623 #include "Cards.h"
624 #include "epg.h"
625 #include "channels.h"
626 -#include "p8-platform/threads/mutex.h"
627 -#include "p8-platform/threads/threads.h"
628
629 /* Use a forward declaration here. Including RTSPClient.h via TSReader.h at this point gives compile errors */
630 namespace MPTV
631 @@ -28,9 +30,7 @@ namespace MPTV
632 class cRecording;
633
634 class ATTRIBUTE_HIDDEN cPVRClientMediaPortal
635 - : public kodi::addon::CInstancePVRClient,
636 - public P8PLATFORM::PreventCopy,
637 - public P8PLATFORM::CThread
638 + : public kodi::addon::CInstancePVRClient
639 {
640 public:
641 /* Class interface */
642 @@ -110,7 +110,7 @@ class ATTRIBUTE_HIDDEN cPVRClientMediaPortal
643
644 private:
645 /* TVServerKodi Listening Thread */
646 - void* Process(void);
647 + void Process();
648 PVR_CONNECTION_STATE Connect(bool updateConnectionState = true);
649
650 void LoadGenreTable(void);
651 @@ -134,9 +134,9 @@ class ATTRIBUTE_HIDDEN cPVRClientMediaPortal
652 time_t m_BackendTime;
653 CCards m_cCards;
654 CGenreTable* m_genretable;
655 - P8PLATFORM::CMutex m_mutex;
656 - P8PLATFORM::CMutex m_connectionMutex;
657 - int64_t m_iLastRecordingUpdate;
658 + std::mutex m_mutex;
659 + std::mutex m_connectionMutex;
660 + std::chrono::system_clock::time_point m_iLastRecordingUpdate;
661 MPTV::CTsReader* m_tsreader;
662 std::map<int,cChannel> m_channels;
663 int m_signalStateCounter;
664 @@ -145,6 +145,9 @@ class ATTRIBUTE_HIDDEN cPVRClientMediaPortal
665
666 cRecording* m_lastSelectedRecording;
667
668 + std::atomic<bool> m_running = {false};
669 + std::thread m_thread;
670 +
671 //Used for TV Server communication:
672 std::string SendCommand(const char* command);
673 std::string SendCommand(const std::string& command);