From 2de242e96ffe6e6fbd111ef02072bbb80d57687f Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 15 May 2006 22:08:47 +0000 Subject: [PATCH] PosFromFrame, some code to move recordings between folders. Unfinished. --- mvpclient.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mvpclient.h | 2 ++ recplayer.c | 15 ++++++++++ recplayer.h | 1 + 4 files changed, 104 insertions(+) diff --git a/mvpclient.c b/mvpclient.c index d3cd9c8..f1e8a9f 100644 --- a/mvpclient.c +++ b/mvpclient.c @@ -184,6 +184,7 @@ void MVPClient::run2() break; } + log->log("Client", Log::DEBUG, "SwitchOp"); switch(opcode) { case 1: @@ -234,6 +235,12 @@ void MVPClient::run2() case 16: result = processPositionFromFrameNumber(data, packetLength); break; + case 17: + result = processFrameNumberFromPosition(data, packetLength); + break; + case 18: + result = processMoveRecording(data, packetLength); + break; } free(buffer); @@ -368,6 +375,60 @@ int MVPClient::processDeleteRecording(UCHAR* data, int length) return 1; } +int MVPClient::processMoveRecording(UCHAR* data, int length) +{ + log->log("Client", Log::DEBUG, "Process move recording"); + char* fileName = (char*)data; + char* newPath = NULL; + + for (int k = 0; k < length; k++) + { + if (data[k] == '\0') + { + newPath = (char*)&data[k+1]; + break; + } + } + log->log("Client", Log::DEBUG, "newPath=%s", newPath); + if (!newPath) return 0; + + cRecordings Recordings; + Recordings.Load(); // probably have to do this + + cRecording* recording = Recordings.GetByName((char*)fileName); + + log->log("Client", Log::DEBUG, "recording pointer %p", recording); + + if (recording) + { + log->log("Client", Log::DEBUG, "moving recording: %s", recording->Name()); + + cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName()); + if (!rc) + { + if (1) + { + + sendULONG(1); + } + else + { + sendULONG(2); + } + } + else + { + sendULONG(3); + } + } + else + { + sendULONG(4); + } + + return 1; +} + int MVPClient::processGetSummary(UCHAR* data, int length) { // data is a pointer to the fileName string @@ -680,6 +741,31 @@ int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length) return 1; } +int MVPClient::processFrameNumberFromPosition(UCHAR* data, int length) +{ + ULONG retval = 0; + + ULLONG position = ntohll(*(ULLONG*)data); + data += 8; + + if (!rp) + { + log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!"); + } + else + { + retval = rp->frameNumberFromPosition(position); + } + + UCHAR sendBuffer[8]; + *(ULONG*)&sendBuffer[0] = htonl(4); + *(ULONG*)&sendBuffer[4] = htonl(retval); + + tcp.sendPacket(sendBuffer, 8); + log->log("Client", Log::DEBUG, "Wrote frameNumFromPos reply to client"); + return 1; +} + int MVPClient::processGetChannelSchedule(UCHAR* data, int length) { ULONG channelNumber = ntohl(*(ULONG*)data); diff --git a/mvpclient.h b/mvpclient.h index f0e49bf..5d34f16 100644 --- a/mvpclient.h +++ b/mvpclient.h @@ -67,6 +67,7 @@ class MVPClient int processLogin(UCHAR* buffer, int length); int processGetRecordingsList(UCHAR* data, int length); int processDeleteRecording(UCHAR* data, int length); + int processMoveRecording(UCHAR* data, int length); int processGetSummary(UCHAR* data, int length); int processGetChannelsList(UCHAR* data, int length); int processStartStreamingChannel(UCHAR* data, int length); @@ -80,6 +81,7 @@ class MVPClient int processGetTimers(UCHAR* data, int length); int processSetTimer(UCHAR* data, int length); int processPositionFromFrameNumber(UCHAR* data, int length); + int processFrameNumberFromPosition(UCHAR* data, int length); cChannel* channelFromNumber(ULONG channelNumber); void writeResumeData(); diff --git a/recplayer.c b/recplayer.c index c2ff634..18d5c2d 100644 --- a/recplayer.c +++ b/recplayer.c @@ -197,3 +197,18 @@ ULLONG RecPlayer::positionFromFrameNumber(ULONG frameNumber) return position; } + +ULONG RecPlayer::frameNumberFromPosition(ULLONG position) +{ + if (!indexFile) return 0; + + uchar segmentNumber; + for(segmentNumber = 1; segmentNumber < 255; segmentNumber++) + { + if ((position >= segments[segmentNumber]->start) && (position < segments[segmentNumber]->end)) break; + // position is in this block + } + ULONG askposition = position - segments[segmentNumber]->start; + return indexFile->Get((int)segmentNumber, askposition); + +} diff --git a/recplayer.h b/recplayer.h index 0c75a50..ddbef0a 100644 --- a/recplayer.h +++ b/recplayer.h @@ -46,6 +46,7 @@ class RecPlayer cRecording* getCurrentRecording(); void scan(); ULLONG positionFromFrameNumber(ULONG frameNumber); + ULONG frameNumberFromPosition(ULLONG position); private: Log* log; -- 2.39.5