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;
{
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));
}
else if (feedMode == MODE_BACKWARDS)
{
- if (feedPosition >= 100000)
+ if (feedPosition >= blockSize)
{
- feedPosition -= 100000;
+ feedPosition -= blockSize;
}
else
{
threadCheckExit();
+ free(buf);
+
/* while(writeLength < thisRead)
{
thisWrite = stream.put(buf + writeLength, thisRead - writeLength);
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
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;
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);
}
else if (feedMode == MODE_BACKWARDS)
{
- if (feedPosition >= 100000)
+ if (feedPosition >= blockSize)
{
- feedPosition -= 100000;
+ feedPosition -= blockSize;
demuxer.seek();
}
else
threadCheckExit();
}
+
+ free(buf);
+
}
// end of recording
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
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)
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)
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);