--- /dev/null
+/*
+ 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);
+}
--- /dev/null
+/*
+ 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
#include "message.h"
#include "dvbsubtitles.h"
#include "osdreceiver.h"
+#include "buffer.h"
#include "playervideorec.h"
if (!vdr->isConnected()) { doConnectionLost(); return; }
logger->log("Player", Log::DEBUG, "startFeedPlay: wantedframe %i goto %llu", currentFrameNumber, feedPosition);
+ Buffer threadBuffer;
while(1)
{
}
//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;
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;
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;
threadCheckExit();
}
- free(threadBuffer);
- threadBuffer = NULL;
-
+ threadBuffer.release();
}
// end of recording
int frameTimeOffset = 0; // Time in msec between frames
+ Buffer threadBuffer;
+
if (state == S_FFWD)
{
direction = 1; // and 0 for backward
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();
}
}
- free(threadBuffer);
- threadBuffer = NULL;
+ threadBuffer.release();
}
}
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
#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;
}
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);
}
}
-void PlayerVideoRec::threadPostStopCleanup()
-{
- if (threadBuffer)
- {
- free(threadBuffer);
- threadBuffer = NULL;
- }
-}
-
// ----------------------------------- Dev
#ifdef DEV