]> git.vomp.tv Git - vompclient.git/commitdiff
New void* wrapper class. Remove one use of Thread::postStopCleanup
authorChris Tallon <chris@vomp.tv>
Tue, 3 Mar 2020 18:48:14 +0000 (18:48 +0000)
committerChris Tallon <chris@vomp.tv>
Tue, 3 Mar 2020 18:48:14 +0000 (18:48 +0000)
buffer.cc [new file with mode: 0644]
buffer.h [new file with mode: 0644]
objects.mk
playervideorec.cc
playervideorec.h

diff --git a/buffer.cc b/buffer.cc
new file mode 100644 (file)
index 0000000..dbb33f7
--- /dev/null
+++ b/buffer.cc
@@ -0,0 +1,44 @@
+/*
+    Copyright 2020 Chris Tallon
+
+    This file is part of VOMP.
+
+    VOMP is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    VOMP is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+
+#include "buffer.h"
+
+Buffer::~Buffer()
+{
+  if (memory) free(memory);
+}
+
+void Buffer::set(void* newptr)
+{
+  if (memory) abort();
+  memory = newptr;
+}
+
+void Buffer::release()
+{
+  if (memory) free(memory);
+  memory = nullptr;
+}
+
+unsigned char* Buffer::ucharp()
+{
+  return reinterpret_cast<unsigned char*>(memory);
+}
diff --git a/buffer.h b/buffer.h
new file mode 100644 (file)
index 0000000..e5aee0b
--- /dev/null
+++ b/buffer.h
@@ -0,0 +1,44 @@
+/*
+    Copyright 2020 Chris Tallon
+
+    This file is part of VOMP.
+
+    VOMP is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    VOMP is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#ifndef BUFFER_H
+#define BUFFER_H
+
+class Buffer
+{
+  public:
+    Buffer() {};
+    Buffer(const Buffer&) = delete;            // copy
+    Buffer& operator=(const Buffer&) = delete; // assign
+    Buffer(Buffer&&) = delete;                 // move
+    Buffer& operator=(Buffer&&) = delete;      // move-assign
+
+    ~Buffer();
+
+    void set(void* mem);
+    bool isNull() { return (memory == nullptr); }
+    void release();
+
+    unsigned char* ucharp();
+
+  private:
+    void* memory{};
+};
+
+#endif
index 62d908908b4718295dc79771a26808c950e06fd0..1e8187365e0cfc28746a6a301d657c4ba98f26d8 100644 (file)
@@ -18,7 +18,7 @@ OBJ_COMMON = command.o tcp.o dsock.o thread.o timers.o i18n.o vdp6.o
              wprogressbar.o bitmap.o dvbsubtitles.o tfeed.o vteletextview.o        \
              teletextdecodervbiebu.o teletxt/txtfont.o movieinfo.o seriesinfo.o    \
              wmovieview.o wseriesview.o tvmedia.o wtvmedia.o wpictureview.o        \
-             osdvector.o surfacevector.o
+             osdvector.o surfacevector.o buffer.o
 
 OBJ_RASPBERRY = main.o threadp.o osdopenvg.o                                       \
                 ledraspberry.o videoomx.o audioomx.o imageomx.o                    \
index 2f682478c34092f64f577d7a69374f77d53613de..b5ffa0409b30c4b13be1c6daac95302a1d1b0042 100644 (file)
@@ -28,6 +28,7 @@
 #include "message.h"
 #include "dvbsubtitles.h"
 #include "osdreceiver.h"
+#include "buffer.h"
 
 #include "playervideorec.h"
 
@@ -1068,6 +1069,7 @@ void PlayerVideoRec::threadFeedPlay()
   if (!vdr->isConnected()) { doConnectionLost(); return; }
   logger->log("Player", Log::DEBUG, "startFeedPlay: wantedframe %i goto %llu", currentFrameNumber, feedPosition);
 
+  Buffer threadBuffer;
 
   while(1)
   {
@@ -1104,7 +1106,7 @@ void PlayerVideoRec::threadFeedPlay()
     }
     //logger->log("Player", Log::DEBUG, "Get Block in");
 
-    threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead);
+    threadBuffer.set(vdr->getBlock(feedPosition, askFor, &thisRead));
     //logger->log("Player", Log::DEBUG, "Get Block out");
 
     feedPosition += thisRead;
@@ -1115,11 +1117,11 @@ void PlayerVideoRec::threadFeedPlay()
       return;
     }
 
-    if (!threadBuffer) break;
+    if (threadBuffer.isNull()) break;
 
     if (startup)
     {
-      int a_stream = demuxer->scan(threadBuffer, thisRead);
+      int a_stream = demuxer->scan(threadBuffer.ucharp(), thisRead);
       demuxer->setAudioStream(a_stream);
       logger->log("Player", Log::DEBUG, "Startup Audio stream chosen %x", a_stream);
       startup = false;
@@ -1130,7 +1132,7 @@ void PlayerVideoRec::threadFeedPlay()
     while(writeLength < thisRead)
     {
       //logger->log("Player", Log::DEBUG, "Put in");
-      thisWrite = demuxer->put(threadBuffer + writeLength, thisRead - writeLength);
+      thisWrite = demuxer->put(threadBuffer.ucharp() + writeLength, thisRead - writeLength);
       //logger->log("Player", Log::DEBUG, "Put out");
       writeLength += thisWrite;
 
@@ -1146,9 +1148,7 @@ void PlayerVideoRec::threadFeedPlay()
       threadCheckExit();
     }
 
-    free(threadBuffer);
-    threadBuffer = NULL;
-
+    threadBuffer.release();
   }
 
   // end of recording
@@ -1193,6 +1193,8 @@ void PlayerVideoRec::threadPTSFeedScan()
 
   int frameTimeOffset = 0; // Time in msec between frames
 
+  Buffer threadBuffer;
+
   if (state == S_FFWD)
   {
     direction = 1; // and 0 for backward
@@ -1217,23 +1219,20 @@ void PlayerVideoRec::threadPTSFeedScan()
 
     logger->log("Player", Log::DEBUG, "XXX Got frame");
 
-    threadBuffer = vdr->getBlock(filePos, iframeLength, &amountReceived);
+    threadBuffer.set(vdr->getBlock(filePos, iframeLength, &amountReceived));
 
     if (!vdr->isConnected())
     {
-      if (threadBuffer) free(threadBuffer);
       doConnectionLost();
       break;
     }
 
-
     threadCheckExit();
 
-
-    videoLength = demuxer->stripAudio(threadBuffer, amountReceived);
-    demuxer->changeTimes(threadBuffer,videoLength,playtime);
+    videoLength = demuxer->stripAudio(threadBuffer.ucharp(), amountReceived);
+    demuxer->changeTimes(threadBuffer.ucharp(), videoLength, playtime);
     int count=0;
-    while (!video->displayIFrame(threadBuffer, videoLength)) // the device might block
+    while (!video->displayIFrame(threadBuffer.ucharp(), videoLength)) // the device might block
     {
        MILLISLEEP(20);
        threadCheckExit();
@@ -1259,8 +1258,7 @@ void PlayerVideoRec::threadPTSFeedScan()
                }
        }
 
-    free(threadBuffer);
-    threadBuffer = NULL;
+    threadBuffer.release();
   }
 }
 
@@ -1295,6 +1293,8 @@ void PlayerVideoRec::threadFeedScan()
 
   if (state == S_FFWD) direction = 1; // and 0 for backward
 
+  Buffer threadBuffer;
+
   while(1)
   {
     // Fetch I-frames until we get one that can be displayed in good time
@@ -1330,11 +1330,10 @@ void PlayerVideoRec::threadFeedScan()
 #endif
     logger->log("Player", Log::DEBUG, "XXX Got frame");
 
-    threadBuffer = vdr->getBlock(filePos, iframeLength, &amountReceived);
+    threadBuffer.set(vdr->getBlock(filePos, iframeLength, &amountReceived));
 
     if (!vdr->isConnected() || !amountReceived)
     {
-      if (threadBuffer) free(threadBuffer);
       doConnectionLost();
       break;
     }
@@ -1355,11 +1354,10 @@ void PlayerVideoRec::threadFeedScan()
     MILLISLEEP(sleepTime);
    logger->log("Player", Log::DEBUG, "XXX Slept for %d", sleepTime);
 
-    videoLength = demuxer->stripAudio(threadBuffer, amountReceived);
-    video->displayIFrame(threadBuffer, videoLength);
+    videoLength = demuxer->stripAudio(threadBuffer.ucharp(), amountReceived);
+    video->displayIFrame(threadBuffer.ucharp(), videoLength);
     currentFrameNumber = iframeNumber;
-    free(threadBuffer);
-    threadBuffer = NULL;
+    threadBuffer.release();
 
 #ifndef WIN32
     gettimeofday(&clock2, NULL);
@@ -1378,15 +1376,6 @@ void PlayerVideoRec::threadFeedScan()
   }
 }
 
-void PlayerVideoRec::threadPostStopCleanup()
-{
-  if (threadBuffer)
-  {
-    free(threadBuffer);
-    threadBuffer = NULL;
-  }
-}
-
 // ----------------------------------- Dev
 
 #ifdef DEV
index 8d44911e2fd5065dbbfb9b6726defa526b1f7b18..0ea99c0189c2b7332e2e4d246164d6201b2f02f4 100644 (file)
@@ -122,7 +122,6 @@ class PlayerVideoRec : public Thread_TYPE, public Callback
 
   protected:
     void threadMethod();
-    void threadPostStopCleanup();
 
   private:
     void switchState(UCHAR newState, ULONG jumpFrame=0);
@@ -165,7 +164,6 @@ class PlayerVideoRec : public Thread_TYPE, public Callback
     ULONG currentFrameNumber{};
     UINT blockSize{100000};
     UINT startupBlockSize{250000};
-    UCHAR* threadBuffer{};
     UCHAR state{S_STOP};
     UCHAR ifactor{4}; // 4, 8, 16, 32
 };