From fe94a4ecd4aadba921429366d46b8855e273ebb2 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 11 Aug 2005 23:09:33 +0000 Subject: [PATCH] Fix for chasing playback by allowing the client to rescan the length --- mvpclient.c | 25 +++++++++++++++++++++++++ mvpclient.h | 1 + recplayer.c | 48 +++++++++++++++++++++++++++--------------------- recplayer.h | 3 ++- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/mvpclient.c b/mvpclient.c index 1fe4cd2..eb52477 100644 --- a/mvpclient.c +++ b/mvpclient.c @@ -220,6 +220,9 @@ void MVPClient::run2() case 12: processConfigLoad(data, packetLength); break; + case 13: + processReScanRecording(data, packetLength); + break; } free(buffer); @@ -525,6 +528,28 @@ void MVPClient::processStartStreamingRecording(unsigned char* data, int length) } } +void MVPClient::processReScanRecording(unsigned char* data, int length) +{ + ULLONG retval = 0; + + if (!rp) + { + log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!"); + } + else + { + rp->scan(); + retval = rp->getTotalLength(); + } + + unsigned char sendBuffer[12]; + *(unsigned long*)&sendBuffer[0] = htonl(8); + *(ULLONG*)&sendBuffer[4] = htonll(retval); + + tcp.sendPacket(sendBuffer, 12); + log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client"); +} + void MVPClient::processGetChannelSchedule(unsigned char* data, int length) { ULONG channelNumber = ntohl(*(ULLONG*)data); diff --git a/mvpclient.h b/mvpclient.h index 3658d00..0049d56 100644 --- a/mvpclient.h +++ b/mvpclient.h @@ -69,6 +69,7 @@ class MVPClient void processGetBlock(unsigned char* data, int length); void processStopStreaming(unsigned char* data, int length); void processStartStreamingRecording(unsigned char* data, int length); + void processReScanRecording(unsigned char* data, int length); void processGetChannelSchedule(unsigned char* data, int length); void processConfigSave(unsigned char* data, int length); void processConfigLoad(unsigned char* data, int length); diff --git a/recplayer.c b/recplayer.c index 8e688ca..a13a64e 100644 --- a/recplayer.c +++ b/recplayer.c @@ -22,39 +22,45 @@ RecPlayer::RecPlayer(cRecording* rec) { + log = Log::getInstance(); file = NULL; - totalLength = 0; + fileOpen = 0; lastPosition = 0; - log = Log::getInstance(); recording = rec; + for(int i = 1; i < 1000; i++) segments[i] = NULL; // FIXME find out max file path / name lengths + scan(); +} + +void RecPlayer::scan() +{ + if (file) fclose(file); + totalLength = 0; + fileOpen = 0; + + int i = 1; + while(segments[i++]) delete segments[i]; char fileName[2048]; - for(int i = 1; i < 1001; i++) + for(i = 1; i < 1000; i++) { - snprintf(fileName, 2047, "%s/%03i.vdr", rec->FileName(), i); + snprintf(fileName, 2047, "%s/%03i.vdr", recording->FileName(), i); log->log("RecPlayer", Log::DEBUG, "FILENAME: %s", fileName); file = fopen(fileName, "r"); - if (file) - { - segments[i] = new Segment(); - segments[i]->start = totalLength; - - fseek(file, 0, SEEK_END); - totalLength += ftell(file); - log->log("RecPlayer", Log::DEBUG, "File %i found, totalLength now %llu", i, totalLength); - segments[i]->end = totalLength; - fclose(file); - } - else - { - segments[i] = NULL; - break; - } + if (!file) break; + + segments[i] = new Segment(); + segments[i]->start = totalLength; + fseek(file, 0, SEEK_END); + totalLength += ftell(file); + log->log("RecPlayer", Log::DEBUG, "File %i found, totalLength now %llu", i, totalLength); + segments[i]->end = totalLength; + fclose(file); } - openFile(1); + + file = NULL; } RecPlayer::~RecPlayer() diff --git a/recplayer.h b/recplayer.h index d2ad4ec..5ab84d2 100644 --- a/recplayer.h +++ b/recplayer.h @@ -44,13 +44,14 @@ class RecPlayer int openFile(int index); ULLONG getLastPosition(); cRecording* getCurrentRecording(); + void scan(); private: Log* log; cRecording* recording; FILE* file; int fileOpen; - Segment* segments[1001]; + Segment* segments[1000]; ULLONG totalLength; ULLONG lastPosition; }; -- 2.39.5