From 50e07d6a994b1bf8f1a9c8b7192d33668581b144 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 11 Mar 2006 23:27:03 +0000 Subject: [PATCH] Frame number stuff --- player.cc | 38 ++++++++++++++++++++++++-------------- vdr.cc | 34 ++++++++++++++++++++++++++++++++++ vdr.h | 2 ++ video.cc | 6 ++++++ video.h | 1 + 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/player.cc b/player.cc index 81cc055..e70eca7 100644 --- a/player.cc +++ b/player.cc @@ -518,7 +518,7 @@ void Player::threadMethod() if (isRecording && ((lastRescan + 60) < time(NULL))) { streamLength = vdr->rescanRecording(); - Log::getInstance()->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", streamLength); + logger->log("Player", Log::DEBUG, "Rescanned and reset length: %llu", streamLength); lastRescan = time(NULL); setEndTS(); } @@ -557,7 +557,7 @@ void Player::threadMethod() { int a_stream = demuxer.scan(threadBuffer, thisRead); demuxer.setAudioStream(a_stream); - Log::getInstance()->log("Player", Log::DEBUG, "Startup Audio stream chosen %x", a_stream); + logger->log("Player", Log::DEBUG, "Startup Audio stream chosen %x", a_stream); setStartTS(thisRead); @@ -593,12 +593,12 @@ void Player::threadMethod() if (!thisWrite) { -// Log::getInstance()->log("Player", Log::DEBUG, "DEMUXER FULL!!!"); +// logger->log("Player", Log::DEBUG, "DEMUXER FULL!!!"); // demuxer is full and cant take anymore threadLock(); threadWaitForSignal(); threadUnlock(); -// Log::getInstance()->log("Player", Log::DEBUG, "BACK FROM WAIT"); +// logger->log("Player", Log::DEBUG, "BACK FROM WAIT"); } threadCheckExit(); @@ -610,25 +610,25 @@ void Player::threadMethod() } // end of recording - Log::getInstance()->log("Player", Log::DEBUG, "Recording playback ends"); + logger->log("Player", Log::DEBUG, "Recording playback ends"); 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 else m->message = Message::STREAM_END; // live - Log::getInstance()->log("Player", Log::DEBUG, "Posting message to %p...", commandMessageQueue); + logger->log("Player", Log::DEBUG, "Posting message to %p...", commandMessageQueue); commandMessageQueue->postMessage(m); - Log::getInstance()->log("Player", Log::DEBUG, "Message posted..."); + logger->log("Player", Log::DEBUG, "Message posted..."); } void Player::threadPostStopCleanup() { - Log::getInstance()->log("Player", Log::DEBUG, "Post stop cleanup 1"); + logger->log("Player", Log::DEBUG, "Post stop cleanup 1"); if (threadBuffer) { - Log::getInstance()->log("Player", Log::DEBUG, "Post stop cleanup 2"); + logger->log("Player", Log::DEBUG, "Post stop cleanup 2"); free(threadBuffer); threadBuffer = NULL; } - Log::getInstance()->log("Player", Log::DEBUG, "Post stop cleanup 3"); + logger->log("Player", Log::DEBUG, "Post stop cleanup 3"); } void Player::setStartTS(UINT dataInBuffer) @@ -652,24 +652,34 @@ void Player::setStartTS(UINT dataInBuffer) void Player::setEndTS() { - Log::getInstance()->log("Player", Log::DEBUG, "Setting end TS"); + logger->log("Player", Log::DEBUG, "Setting end TS"); UINT thisRead; UCHAR* tempBuffer = VDR::getInstance()->getBlock((streamLength - 100000), 100000, &thisRead); if (!tempBuffer) return; if (thisRead) demuxer.findVideoPTS(tempBuffer, thisRead, &endTS); free(tempBuffer); - Log::getInstance()->log("Player", Log::DEBUG, "Set end TS"); + logger->log("Player", Log::DEBUG, "Set end TS"); } #ifdef DEV void Player::test1() { - Log::getInstance()->log("Player", Log::DEBUG, "PLAYER TEST 1"); + logger->log("Player", Log::DEBUG, "PLAYER TEST 1"); } void Player::test2() { - Log::getInstance()->log("Player", Log::DEBUG, "PLAYER TEST 2"); + logger->log("Player", Log::DEBUG, "PLAYER TEST 2"); + + ULLONG currentTS = getPositionTS(); + ULONG currentFrameNumber = video->timecodeToFrameNumber(currentTS); + logger->log("Player", Log::DEBUG, "Current frame number: %lu", currentFrameNumber); + + ULONG wantedFrameNumber = video->timecodeToFrameNumber(currentTS + (10 * 90000)); + logger->log("Player", Log::DEBUG, "Wanted frame number: %lu", wantedFrameNumber); + + ULLONG newPosition = VDR::getInstance()->positionFromFrameNumber(wantedFrameNumber); + logger->log("Player", Log::DEBUG, "feedpos %llu goto %llu", feedPosition, newPosition); } #endif diff --git a/vdr.cc b/vdr.cc index 3b12f9d..92d5055 100644 --- a/vdr.cc +++ b/vdr.cc @@ -663,6 +663,40 @@ ULLONG VDR::rescanRecording() return recordingLength; } +ULLONG VDR::positionFromFrameNumber(ULONG frameNumber) +{ + if (!connected) return 0; + + unsigned long totalLength = 12; + UCHAR buffer[totalLength]; + + *(unsigned long*)&buffer[0] = htonl(totalLength - 4); + *(unsigned long*)&buffer[4] = htonl(VDR_POSFROMFRAME); + *(unsigned long*)&buffer[8] = htonl(frameNumber); + + pthread_mutex_lock(&mutex); + unsigned int a = tcp->sendPacket(buffer, totalLength); + if (a != totalLength) + { + pthread_mutex_unlock(&mutex); + return 0; + } + + if (!getPacket()) + { + pthread_mutex_unlock(&mutex); + return 0; + } + + ULLONG position = extractULLONG(); + freePacket(); + pthread_mutex_unlock(&mutex); + + Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position); + + return position; +} + EventList* VDR::getChannelSchedule(ULONG number) { time_t now; diff --git a/vdr.h b/vdr.h index 7809054..0c4dd7f 100644 --- a/vdr.h +++ b/vdr.h @@ -119,6 +119,7 @@ class VDR int deleteRecording(char* fileName); ULLONG streamRecording(Recording* rec); ULLONG rescanRecording(); + ULLONG positionFromFrameNumber(ULONG frameNumber); ChannelList* getChannelsList(ULONG type); int streamChannel(ULONG number); @@ -168,6 +169,7 @@ class VDR const static ULONG VDR_RESCANRECORDING = 13; const static ULONG VDR_GETTIMERS = 14; const static ULONG VDR_SETTIMER = 15; + const static ULONG VDR_POSFROMFRAME = 16; int getPacket(); void freePacket(); diff --git a/video.cc b/video.cc index f129df1..008e11a 100644 --- a/video.cc +++ b/video.cc @@ -388,6 +388,12 @@ ULLONG Video::getCurrentTimestamp() } } +ULONG Video::timecodeToFrameNumber(ULLONG timecode) +{ + if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25); + else return (ULONG)(((double)timecode / (double)90000) * (double)30); +} + #ifdef DEV int Video::test() { diff --git a/video.h b/video.h index 11497f9..88267b3 100644 --- a/video.h +++ b/video.h @@ -108,6 +108,7 @@ class Video int signalOn(); int signalOff(); int attachFrameBuffer(); // What does this do? + ULONG timecodeToFrameNumber(ULLONG timecode); #ifdef DEV int test(); -- 2.39.5