From c0f445ddca6eb745c3e680b297d7d48158ec51a8 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 1 Oct 2006 23:35:24 +0000 Subject: [PATCH] New getRecInfo system --- mvpclient.c | 298 +++++++++++++++++++++++++++++++++++++--------------- mvpclient.h | 5 +- 2 files changed, 218 insertions(+), 85 deletions(-) diff --git a/mvpclient.c b/mvpclient.c index e66207b..184ed30 100644 --- a/mvpclient.c +++ b/mvpclient.c @@ -198,9 +198,6 @@ void MVPClient::run2() case 3: result = processDeleteRecording(data, packetLength); break; - case 4: - result = processGetSummary(data, packetLength); - break; case 5: result = processGetChannelsList(data, packetLength); break; @@ -226,7 +223,7 @@ void MVPClient::run2() result = processConfigLoad(data, packetLength); break; case 13: - result = processReScanRecording(data, packetLength); + result = processReScanRecording(data, packetLength); // FIXME obselete break; case 14: result = processGetTimers(data, packetLength); @@ -246,6 +243,9 @@ void MVPClient::run2() case 19: result = processGetIFrame(data, packetLength); break; + case 20: + result = processGetRecInfo(data, packetLength); + break; } free(buffer); @@ -537,65 +537,6 @@ int MVPClient::processMoveRecording(UCHAR* data, int length) return 1; } -int MVPClient::processGetSummary(UCHAR* data, int length) -{ - // data is a pointer to the fileName string - - cRecordings Recordings; - Recordings.Load(); // probably have to do this - - cRecording *recording = Recordings.GetByName((char*)data); - - log->log("Client", Log::DEBUG, "recording pointer %p", recording); - - if (recording) - { - UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough - int count = 4; // leave space for the packet length - char* point; - -#if VDRVERSNUM < 10300 - point = (char*)recording->Summary(); -#else - const cRecordingInfo *Info = recording->Info(); - point = (char*)Info->ShortText(); - log->log("Client", Log::DEBUG, "info pointer %p summary pointer %p", Info, point); - if (isempty(point)) - { - point = (char*)Info->Description(); - log->log("Client", Log::DEBUG, "description pointer %p", point); - } -#endif - - if (point) - { - strcpy((char*)&sendBuffer[count], point); - count += strlen(point) + 1; - } - else - { - strcpy((char*)&sendBuffer[count], ""); - count += 1; - } - - *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field - - log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0])); - - tcp.sendPacket(sendBuffer, count); - delete[] sendBuffer; - log->log("Client", Log::DEBUG, "Written summary"); - - - } - else - { - sendULONG(0); - } - - return 1; -} - int MVPClient::processGetChannelsList(UCHAR* data, int length) { UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough @@ -802,26 +743,6 @@ int MVPClient::processStartStreamingRecording(UCHAR* data, int length) return 1; } -int MVPClient::processReScanRecording(UCHAR* data, int length) -{ - if (!rp) - { - log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!"); - return 0; - } - - rp->scan(); - - UCHAR sendBuffer[16]; - *(ULONG*)&sendBuffer[0] = htonl(12); - *(ULLONG*)&sendBuffer[4] = htonll(rp->getLengthBytes()); - *(ULONG*)&sendBuffer[12] = htonl(rp->getLengthFrames()); - - tcp.sendPacket(sendBuffer, 16); - log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client"); - return 1; -} - int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length) { ULLONG retval = 0; @@ -1615,3 +1536,214 @@ int MVPClient::processSetTimer(UCHAR* buffer, int length) delete timer; return 1; } + +int MVPClient::processGetRecInfo(UCHAR* data, int length) +{ + // data is a pointer to the fileName string + + cRecordings Recordings; + Recordings.Load(); // probably have to do this + + cRecording *recording = Recordings.GetByName((char*)data); + + time_t timerStart = 0; + time_t timerStop = 0; + char* summary = NULL; + ULONG resumePoint = 0; + + if (!recording) + { + log->log("Client", Log::ERR, "GetRecInfo found no recording"); + sendULONG(0); + return 1; + } + + ULONG sendBufferSize = 10000; + UCHAR* sendBuffer = (UCHAR*)malloc(sendBufferSize); + ULONG pos = 4; // leave first 4 bytes for size field + + + /* Return packet: + 4 bytes: start time for timer + 4 bytes: end time for timer + 4 bytes: resume point + string: summary + 4 bytes: num components + { + 1 byte: stream + 1 byte: type + string: language + string: description + } + + */ + + // Get current timer + + cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName()); + if (rc) + { + timerStart = rc->Timer()->StartTime(); + timerStop = rc->Timer()->StopTime(); + log->log("Client", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop); + } + + *(time_t*)&sendBuffer[pos] = htonl(timerStart); pos += 4; + *(time_t*)&sendBuffer[pos] = htonl(timerStop); pos += 4; + + // Get resume point + + char* value = config.getValueString("ResumeData", (char*)data); + if (value) + { + resumePoint = strtoul(value, NULL, 10); + delete[] value; + } + log->log("Client", Log::DEBUG, "GRI: RP: %lu", resumePoint); + + *(ULONG*)&sendBuffer[pos] = htonl(resumePoint); pos += 4; + + + // Get summary + +#if VDRVERSNUM < 10300 + summary = (char*)recording->Summary(); +#else + const cRecordingInfo *Info = recording->Info(); + summary = (char*)Info->ShortText(); + if (isempty(summary)) summary = (char*)Info->Description(); +#endif + log->log("Client", Log::DEBUG, "GRI: S: %s", summary); + if (summary) + { + // memory insanity... + if ((sendBufferSize - pos) < (strlen(summary) + 500)) // random + { + UCHAR* newBuffer = (UCHAR*)realloc(sendBuffer, sendBufferSize + strlen(summary) + 10000); + if (newBuffer) + { + sendBuffer = newBuffer; + sendBufferSize += strlen(summary) + 10000; + } + else + { + free(sendBuffer); + sendULONG(0); + return 1; + } + } + + strcpy((char*)&sendBuffer[pos], summary); + pos += strlen(summary) + 1; + } + else + { + strcpy((char*)&sendBuffer[pos], ""); + pos += 1; + } + + + // Get channels + +#if VDRVERSNUM < 10300 + + // Send 0 for numchannels - this signals the client this info is not available + *(ULONG*)&sendBuffer[pos] = 0; pos += 4; + +#else + const cComponents* components = Info->Components(); + + *(ULONG*)&sendBuffer[pos] = htonl(components->NumComponents()); pos += 4; + + tComponent* component; + for (int i = 0; i < components->NumComponents(); i++) + { + component = components->Component(i); + + // memory insanity... + ULONG extraNeeded = 2 + (component->language ? strlen(component->language) : 0) + + (component->description ? strlen(component->description) : 0) + 2; + + if ((sendBufferSize - pos) < extraNeeded) + { + UCHAR* newBuffer = (UCHAR*)realloc(sendBuffer, sendBufferSize + extraNeeded + 10000); + if (newBuffer) + { + sendBuffer = newBuffer; + sendBufferSize += extraNeeded + 10000; + } + else + { + free(sendBuffer); + sendULONG(0); + return 1; + } + } + + log->log("Client", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description); + sendBuffer[pos] = component->stream; pos += 1; + sendBuffer[pos] = component->type; pos += 1; + if (component->language) + { + strcpy((char*)&sendBuffer[pos], component->language); + pos += strlen(component->language) + 1; + } + else + { + strcpy((char*)&sendBuffer[pos], ""); + pos += 1; + } + if (component->description) + { + strcpy((char*)&sendBuffer[pos], component->description); + pos += strlen(component->description) + 1; + } + else + { + strcpy((char*)&sendBuffer[pos], ""); + pos += 1; + } + + } + +#endif + + // Done. send it + + *(ULONG*)&sendBuffer[0] = htonl(pos - 4); // -4 : take off the size field + + log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0])); + + tcp.sendPacket(sendBuffer, pos); + delete[] sendBuffer; + log->log("Client", Log::DEBUG, "Written getrecinfo"); + + return 1; +} + + + + +// FIXME obselete + +int MVPClient::processReScanRecording(UCHAR* data, int length) +{ + if (!rp) + { + log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!"); + return 0; + } + + rp->scan(); + + UCHAR sendBuffer[16]; + *(ULONG*)&sendBuffer[0] = htonl(12); + *(ULLONG*)&sendBuffer[4] = htonll(rp->getLengthBytes()); + *(ULONG*)&sendBuffer[12] = htonl(rp->getLengthFrames()); + + tcp.sendPacket(sendBuffer, 16); + log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client"); + return 1; +} + +// FIXME without client calling rescan, getblock wont work even tho more data is avail diff --git a/mvpclient.h b/mvpclient.h index 5358d09..27d0d9e 100644 --- a/mvpclient.h +++ b/mvpclient.h @@ -68,13 +68,11 @@ class MVPClient 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); int processGetBlock(UCHAR* data, int length); int processStopStreaming(UCHAR* data, int length); int processStartStreamingRecording(UCHAR* data, int length); - int processReScanRecording(UCHAR* data, int length); int processGetChannelSchedule(UCHAR* data, int length); int processConfigSave(UCHAR* data, int length); int processConfigLoad(UCHAR* data, int length); @@ -83,6 +81,9 @@ class MVPClient int processPositionFromFrameNumber(UCHAR* data, int length); int processFrameNumberFromPosition(UCHAR* data, int length); int processGetIFrame(UCHAR* data, int length); + int processGetRecInfo(UCHAR* data, int length); + + int processReScanRecording(UCHAR* data, int length); // FIXME obselete cChannel* channelFromNumber(ULONG channelNumber); void writeResumeData(); -- 2.39.5