From 7adc02c483c09057e6b1ba7e9091a07a9d2ca1f1 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 11 Jun 2006 15:11:45 +0000 Subject: [PATCH] Update for retrieving total recording length in frames --- player.cc | 37 ++++++++++++++++++++++--------------- player.h | 6 ++++-- vdr.cc | 20 ++++++++++++-------- vdr.h | 4 ++-- vvideorec.cc | 8 +++++--- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/player.cc b/player.cc index 4475fdc..bd7585d 100644 --- a/player.cc +++ b/player.cc @@ -34,7 +34,8 @@ Player::Player(MessageQueue* messageQueue, bool tIsRecording, bool tIsRadio) playing = false; ffwd = false; fbwd = false; - streamLength = 0; + lengthBytes = 0; + lengthFrames = 0; feedPosition = 0; feedMode = MODE_NORMAL; lastRescan = 0; @@ -132,11 +133,17 @@ void Player::setPosition(ULLONG position) feedPosition = position; } -void Player::setLength(ULLONG length) +void Player::setLengthBytes(ULLONG length) { lastRescan = time(NULL); - streamLength = length; - logger->log("Player", Log::DEBUG, "Player has received length of %llu", streamLength); + lengthBytes = length; + logger->log("Player", Log::DEBUG, "Player has received length bytes of %llu", lengthBytes); +} + +void Player::setLengthFrames(ULONG length) +{ + lengthFrames = length; + logger->log("Player", Log::DEBUG, "Player has received length frames of %lu", lengthFrames); } ULLONG Player::getEndTS() // used internally (jump to percent) @@ -522,14 +529,14 @@ void Player::setEndTS() logger->log("Player", Log::DEBUG, "Setting end TS"); #ifndef NEW_DEMUXER UINT thisRead; - UCHAR* tempBuffer = VDR::getInstance()->getBlock((streamLength - 100000), 100000, &thisRead); + UCHAR* tempBuffer = VDR::getInstance()->getBlock((lengthBytes - 100000), 100000, &thisRead); if (!tempBuffer && !VDR::getInstance()->isConnected()) { doConnectionLost(); return; } if (!tempBuffer) return; if (thisRead) demuxer->findVideoPTS(tempBuffer, thisRead, &endTS); free(tempBuffer); #else //The replacement code relias completely on VDRs timecode and not the pts endTS=video->frameNumberToTimecode( - VDR::getInstance()->frameNumberFromPosition((streamLength - 100000))); + VDR::getInstance()->frameNumberFromPosition((lengthBytes - 100000))); #endif logger->log("Player", Log::DEBUG, "Set end TS"); } @@ -615,28 +622,28 @@ void Player::threadMethod() // If we havn't rescanned for a while.. if (isRecording && ((lastRescan + 60) < time(NULL))) { - streamLength = vdr->rescanRecording(); + lengthBytes = vdr->rescanRecording(&lengthFrames); if (!vdr->isConnected()) { doConnectionLost(); return; } - logger->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", streamLength); + logger->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", lengthBytes); lastRescan = time(NULL); setEndTS(); } - if (streamLength) // is playing a recording + if (lengthBytes) // is playing a recording { - if (feedPosition >= streamLength) break; // finished playback + if (feedPosition >= lengthBytes) break; // finished playback if (startup) { - if (startupBlockSize > streamLength) - askFor = streamLength; // is a very small recording! + if (startupBlockSize > lengthBytes) + askFor = lengthBytes; // 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; + if ((feedPosition + blockSize) > lengthBytes) // last block of recording + askFor = lengthBytes - feedPosition; else // normal askFor = blockSize; } @@ -750,7 +757,7 @@ void Player::threadMethod() threadCheckExit(); Message* m = new Message(); // Must be done after this thread finishes, and must break into master mutex - if (streamLength) m->message = Message::STOP_PLAYBACK; // recording + if (lengthBytes) m->message = Message::STOP_PLAYBACK; // recording else m->message = Message::STREAM_END; // live logger->log("Player", Log::DEBUG, "Posting message to %p...", commandMessageQueue); commandMessageQueue->postMessage(m); diff --git a/player.h b/player.h index 09af40c..915b0db 100644 --- a/player.h +++ b/player.h @@ -49,7 +49,8 @@ class Player : public Thread_TYPE, public Callback int init(); int shutdown(); void setPosition(ULLONG position); - void setLength(ULLONG length); + void setLengthBytes(ULLONG length); + void setLengthFrames(ULONG length); int play(); void stop(); @@ -117,7 +118,8 @@ class Player : public Thread_TYPE, public Callback ULLONG startTS; ULLONG endTS; - ULLONG streamLength; + ULLONG lengthBytes; + ULONG lengthFrames; ULLONG feedPosition; UCHAR feedMode; time_t lastRescan; diff --git a/vdr.cc b/vdr.cc index 179e807..36dd7da 100644 --- a/vdr.cc +++ b/vdr.cc @@ -652,7 +652,7 @@ UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived) return toReturn; } -ULLONG VDR::streamRecording(char* fileName) +ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames) { unsigned long totalLength = 8 + strlen(fileName) + 1; UCHAR* buffer = new UCHAR[totalLength]; @@ -680,16 +680,18 @@ ULLONG VDR::streamRecording(char* fileName) return 0; } - ULLONG recordingLength = extractULLONG(); + ULLONG lengthBytes = extractULLONG(); + ULONG lengthFrames = extractULONG(); freePacket(); MUTEX_UNLOCK(&mutex); - Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu", recordingLength); + Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames); - return recordingLength; + *totalFrames = lengthFrames; + return lengthBytes; } -ULLONG VDR::rescanRecording() +ULLONG VDR::rescanRecording(ULONG* totalFrames) { unsigned long totalLength = 8; UCHAR* buffer = new UCHAR[totalLength]; @@ -716,13 +718,15 @@ ULLONG VDR::rescanRecording() return 0; } - ULLONG recordingLength = extractULLONG(); + ULLONG lengthBytes = extractULLONG(); + ULONG lengthFrames = extractULONG(); freePacket(); MUTEX_UNLOCK(&mutex); - Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu", recordingLength); + Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames); - return recordingLength; + *totalFrames = lengthFrames; + return lengthBytes; } ULLONG VDR::positionFromFrameNumber(ULONG frameNumber) diff --git a/vdr.h b/vdr.h index 5f63793..f80b6e6 100644 --- a/vdr.h +++ b/vdr.h @@ -117,8 +117,8 @@ class VDR char* getRecordingSummary(char* fileName); int deleteRecording(char* fileName); char* moveRecording(char* fileName, char* newPath); - ULLONG streamRecording(char* fileName); - ULLONG rescanRecording(); + ULLONG streamRecording(char* fileName, ULONG* lengthFrames); + ULLONG rescanRecording(ULONG* lengthFrames); ULLONG positionFromFrameNumber(ULONG frameNumber); ULONG frameNumberFromPosition(ULLONG position); diff --git a/vvideorec.cc b/vvideorec.cc index 819aec9..5f3eb47 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -96,11 +96,13 @@ void VVideoRec::draw() void VVideoRec::go(ULLONG startPosition) { Log::getInstance()->log("VVideoRec", Log::DEBUG, "Starting stream: %s", myRec->getFileName()); - ULLONG recLength = vdr->streamRecording(myRec->getFileName()); - if (recLength) + ULONG lengthFrames = 0; + ULLONG lengthBytes = vdr->streamRecording(myRec->getFileName(), &lengthFrames); + if (lengthBytes) { doBar(0); - player->setLength(recLength); + player->setLengthBytes(lengthBytes); + player->setLengthFrames(lengthFrames); player->setPosition(startPosition); player->play(); playing = true; -- 2.39.5