From f1e77b74b87b516490819253c374beb1b8be9364 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 Aug 2005 15:23:27 +0000 Subject: [PATCH] Mods to get 250k on first packet for demuxer.scan --- playerradio.cc | 19 +++++++++++-------- playerradio.h | 2 +- playervideo.cc | 51 +++++++++++++++++++++++++++++++++++++------------- playervideo.h | 3 ++- tcp.cc | 4 ++-- vdr.cc | 15 ++++++--------- vdr.h | 2 +- 7 files changed, 61 insertions(+), 35 deletions(-) diff --git a/playerradio.cc b/playerradio.cc index 0c79134..666872a 100644 --- a/playerradio.cc +++ b/playerradio.cc @@ -306,14 +306,14 @@ void PlayerRadio::call() void PlayerRadio::threadMethod() { - UCHAR buf[blockSize]; - int thisRead; - int writeLength; - int thisWrite; + UCHAR* buf; + UINT thisRead; + UINT writeLength; + UINT thisWrite; VDR* vdr = VDR::getInstance(); - int askFor; + UINT askFor; while(1) { thisRead = 0; @@ -329,7 +329,8 @@ void PlayerRadio::threadMethod() { askFor = streamLength - feedPosition; } - thisRead = vdr->getBlock(buf, feedPosition, askFor); + buf = vdr->getBlock(feedPosition, askFor, &thisRead); + if (!buf) break; // temp printf("Written direct: %i\n", write(audio->getFD(), buf, thisRead)); @@ -342,9 +343,9 @@ void PlayerRadio::threadMethod() } else if (feedMode == MODE_BACKWARDS) { - if (feedPosition >= 100000) + if (feedPosition >= blockSize) { - feedPosition -= 100000; + feedPosition -= blockSize; } else { @@ -355,6 +356,8 @@ void PlayerRadio::threadMethod() threadCheckExit(); + free(buf); + /* while(writeLength < thisRead) { thisWrite = stream.put(buf + writeLength, thisRead - writeLength); diff --git a/playerradio.h b/playerradio.h index eb79b85..82a9ce0 100644 --- a/playerradio.h +++ b/playerradio.h @@ -67,7 +67,7 @@ class PlayerRadio : public Player UCHAR feedMode; const static UCHAR MODE_NORMAL = 1; const static UCHAR MODE_BACKWARDS = 2; - const static int blockSize = 2000; + const static UINT blockSize = 2000; UCHAR playing; // As in not stopped, (playing && paused) can == TRUE UCHAR paused; // Must be in playing state as well diff --git a/playervideo.cc b/playervideo.cc index 8fc632f..8b4fe5e 100644 --- a/playervideo.cc +++ b/playervideo.cc @@ -491,14 +491,14 @@ void PlayerVideo::call() void PlayerVideo::threadMethod() { - UCHAR buf[blockSize]; - int thisRead; - int writeLength; - int thisWrite; + UCHAR* buf; + UINT thisRead; + UINT writeLength; + UINT thisWrite; VDR* vdr = VDR::getInstance(); - int askFor; + UINT askFor; while(1) { thisRead = 0; @@ -515,14 +515,36 @@ void PlayerVideo::threadMethod() lastRescan = time(NULL); } - // a bit hackey. this needs to be split to live and rec players - if (streamLength && (feedPosition >= streamLength)) break; - askFor = blockSize; - if (streamLength && ((feedPosition + blockSize) > streamLength)) + if (streamLength) // is playing a recording { - askFor = streamLength - feedPosition; + if (feedPosition >= streamLength) break; // finished playback + + if (startup) + { + if (startupBlockSize > streamLength) + askFor = streamLength; // is a very small recording! + else + askFor = startupBlockSize; // normal, but a startup sized block to detect all the audio streams + } + else + { + if ((feedPosition + blockSize) > streamLength) // last block of recording + askFor = streamLength - feedPosition; + else // normal + askFor = blockSize; + } } - thisRead = vdr->getBlock(buf, feedPosition, askFor); + else // is playing live + { + if (startup) + askFor = startupBlockSize; // find audio streams sized block + else + askFor = blockSize; // normal + } + + buf = vdr->getBlock(feedPosition, askFor, &thisRead); + if (!buf) break; + if (startup) { int a_stream = demuxer.scan(buf, thisRead); @@ -537,9 +559,9 @@ void PlayerVideo::threadMethod() } else if (feedMode == MODE_BACKWARDS) { - if (feedPosition >= 100000) + if (feedPosition >= blockSize) { - feedPosition -= 100000; + feedPosition -= blockSize; demuxer.seek(); } else @@ -566,6 +588,9 @@ void PlayerVideo::threadMethod() threadCheckExit(); } + + free(buf); + } // end of recording diff --git a/playervideo.h b/playervideo.h index 08e5ae5..eb58849 100644 --- a/playervideo.h +++ b/playervideo.h @@ -74,7 +74,8 @@ class PlayerVideo : public Player time_t lastRescan; const static UCHAR MODE_NORMAL = 1; const static UCHAR MODE_BACKWARDS = 2; - const static int blockSize = 100000; + const static UINT blockSize = 100000; + const static UINT startupBlockSize = 250000; UCHAR playing; // As in not stopped, (playing && paused) can == TRUE UCHAR paused; // Must be in playing state as well diff --git a/tcp.cc b/tcp.cc index 0546d6d..f71f0e4 100644 --- a/tcp.cc +++ b/tcp.cc @@ -181,9 +181,9 @@ UCHAR* TCP::receivePacket() packetLength = ntohl(packetLength); - if (packetLength > 200000) + if (packetLength > 500000) { - Log::getInstance()->log("TCP", Log::ERR, "Received packet > 200000"); + Log::getInstance()->log("TCP", Log::ERR, "Received packet > 500000"); return NULL; } if (packetLength == 0) diff --git a/vdr.cc b/vdr.cc index e1a8999..a8bb171 100644 --- a/vdr.cc +++ b/vdr.cc @@ -475,31 +475,28 @@ int VDR::stopStreaming() return toReturn; } -int VDR::getBlock(UCHAR* buf, ULLONG position, int amount) +UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived) { UCHAR buffer[20]; *(unsigned long*)&buffer[0] = htonl(16); *(unsigned long*)&buffer[4] = htonl(VDR_GETBLOCK); *(ULLONG*)&buffer[8] = htonll(position); - *(unsigned long*)&buffer[16] = htonl(amount); + *(unsigned long*)&buffer[16] = htonl(maxAmount); pthread_mutex_lock(&mutex); int a = tcp->sendPacket(buffer, 20); if (a != 20) { pthread_mutex_unlock(&mutex); - return 0; + return NULL; } unsigned char* p = (unsigned char*)tcp->receivePacket(); pthread_mutex_unlock(&mutex); - if (!p) return 0; - int dataLength = tcp->getDataLength(); - - memcpy(buf, p, dataLength); - free(p); - return dataLength; + if (!p) return NULL; + *amountReceived = tcp->getDataLength(); + return p; } ULLONG VDR::streamRecording(Recording* rec) diff --git a/vdr.h b/vdr.h index 072adf8..bef6566 100644 --- a/vdr.h +++ b/vdr.h @@ -67,7 +67,7 @@ class VDR List* getChannelsList(ULONG type); int streamChannel(ULONG number); - int getBlock(UCHAR* buf, ULLONG position, int maxAmount); + UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived); int stopStreaming(); int getChannelSchedule(ULONG number); int configSave(char* section, char* key, char* value); -- 2.39.5