From 8c80d89c47439076f66ef5996085e336545f7a7a Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 13 May 2006 23:04:58 +0000 Subject: [PATCH] Windows port changes --- demuxer.cc | 25 +++++++++++++++++++++++-- demuxer.h | 9 +++++++++ demuxervdr.cc | 46 ++++++++++++++++++++++++++++++++++++++++++---- demuxervdr.h | 7 ++++++- player.cc | 37 +++++++++++++++++++++++++++++++------ player.h | 2 +- stream.cc | 10 +++++----- stream.h | 7 ++++++- winmain.cc | 21 --------------------- 9 files changed, 123 insertions(+), 41 deletions(-) diff --git a/demuxer.cc b/demuxer.cc index e251e83..d8be631 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -19,7 +19,13 @@ */ #include "demuxer.h" +#ifndef WIN32 #include +#else +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif #if __BYTE_ORDER == __BIG_ENDIAN #define DEMUXER_SEQ_HEAD 0x000001B3 @@ -27,6 +33,8 @@ #define DEMUXER_SEQ_HEAD 0xB3010000 #endif + + const int Demuxer::FrameRates[9] = { 0, 23, 24, 25, 29, 30, 50, 59, 60 }; Demuxer* Demuxer::instance = NULL; @@ -38,6 +46,8 @@ Demuxer::Demuxer() initted = false; callback = NULL; arcnt = 0; + vid_seeking = aud_seeking = false; + video_pts = audio_pts = 0; } Demuxer::~Demuxer() @@ -183,8 +193,11 @@ int Demuxer::PESPacket::write(UCHAR *buf, int len) data[5] = (length & 0xFF); return 1; } - +#ifndef NEW_DEMUXER int Demuxer::PESPacket::submit() +#else +int Demuxer::PESPacket::submit(ULLONG cur_pos) +#endif { if (submitted >= size) return 0; if (!closed) parseDetails(); @@ -196,15 +209,23 @@ int Demuxer::PESPacket::submit() { if (dx->video_current == -1) dx->video_current = packetType; if (dx->video_current == packetType && !dx->vid_seeking) +#ifndef NEW_DEMUXER sent = dx->videostream.put(data+submitted, size-submitted); +#else + sent = dx->videostream.put(data+submitted, size-submitted,cur_pos); +#endif else sent = size-submitted; } else if (packetType >= PESTYPE_AUD0 && packetType <= PESTYPE_AUDMAX) { if (dx->audio_current == -1) dx->audio_current = packetType; - if (dx->audio_current == packetType & !dx->aud_seeking) + if (dx->audio_current == packetType && !dx->aud_seeking) +#ifndef NEW_DEMUXER sent = dx->audiostream.put(data+submitted, size-submitted); +#else + sent = dx->audiostream.put(data+submitted, size-submitted,cur_pos); +#endif else sent = size-submitted; } diff --git a/demuxer.h b/demuxer.h index e02c989..b28f273 100644 --- a/demuxer.h +++ b/demuxer.h @@ -43,13 +43,18 @@ however, no code was copied verbatim. class Demuxer { +public: //MS Visual C++ need this, private does not work for DemuxerVDR, Marten class PESPacket { public: PESPacket(); void init(UCHAR type); int write(UCHAR* buf, int len); +#ifndef NEW_DEMUXER int submit(); +#else + int submit(ULLONG cur_pos); +#endif private: UCHAR data[0x10000]; UINT length, size; @@ -81,7 +86,11 @@ class Demuxer virtual int scan(UCHAR* buf, int len) = 0; virtual int findVideoPTS(UCHAR* buf, int len, ULLONG* dest) = 0; +#ifndef NEW_DEMUXER virtual int put(UCHAR* buf, int len) = 0; +#else + virtual int put(UCHAR* buf, int len,ULLONG cur_pos) = 0; +#endif int getHorizontalSize() { return horizontal_size; } int getVerticalSize() { return vertical_size; } diff --git a/demuxervdr.cc b/demuxervdr.cc index 2c3fd03..c65c06d 100644 --- a/demuxervdr.cc +++ b/demuxervdr.cc @@ -19,9 +19,22 @@ */ #include "demuxervdr.h" +#ifndef WIN32 #include +#else +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#if __BYTE_ORDER == __BIG_ENDIAN +#define DEMUXER_SEQ_HEAD 0x000001B3 +#else +#define DEMUXER_SEQ_HEAD 0xB3010000 +#endif -DemuxerVDR::DemuxerVDR() {} +DemuxerVDR::DemuxerVDR() { +} //MS Visual C++ needs the Bracket after the first line other it ignores the line void DemuxerVDR::flush() { @@ -95,14 +108,25 @@ int DemuxerVDR::findVideoPTS(UCHAR* buf, int len, ULLONG* dest) // No PTS found. return 0; } - +#ifndef NEW_DEMUXER int DemuxerVDR::put(UCHAR* buf, int len) +#else +int DemuxerVDR::put(UCHAR* buf, int len, ULLONG cur_pos) +#endif { int ret = 0; // return number of bytes consumed +#ifdef NEW_DEMUXER + ULLONG current_position = cur_pos; +#endif + if (submitting) { +#ifndef NEW_DEMUXER if (packet.submit() == 0) // Still full! +#else + if (packet.submit(current_position) == 0) // Still full! +#endif return ret; else submitting = false; @@ -115,7 +139,11 @@ int DemuxerVDR::put(UCHAR* buf, int len) packet.write(buf, state); buf += state; len -= state; ret += state; state = 0; - if (packet.submit() == 0) // Stream is full. +#ifndef NEW_DEMUXER + if (packet.submit() == 0) // Still full! +#else + if (packet.submit(current_position) == 0) // Still full! +#endif { submitting = true; return ret; @@ -165,6 +193,9 @@ int DemuxerVDR::put(UCHAR* buf, int len) } buf++; len--; ret++; +#ifdef NEW_DEMUXER + current_position++; +#endif if (state == -6) // Packet header complete { @@ -172,8 +203,15 @@ int DemuxerVDR::put(UCHAR* buf, int len) { packet.write(buf, packetLength); buf += packetLength; len -= packetLength; ret += packetLength; +#ifdef NEW_DEMUXER + current_position+=(ULLONG)packetLength; +#endif state = 0; - if (packet.submit() == 0) // Stream is full. +#ifndef NEW_DEMUXER + if (packet.submit() == 0) // Still full! +#else + if (packet.submit(current_position) == 0) // Still full! +#endif { submitting = true; return ret; diff --git a/demuxervdr.h b/demuxervdr.h index 1f2d90e..410a23a 100644 --- a/demuxervdr.h +++ b/demuxervdr.h @@ -31,13 +31,18 @@ class DemuxerVDR : public Demuxer void flush(); int scan(UCHAR* buf, int len); int findVideoPTS(UCHAR* buf, int len, ULLONG* dest); +#ifndef NEW_DEMUXER int put(UCHAR* buf, int len); +#else + int put(UCHAR* buf, int len,ULLONG cur_pos); +#endif + private: int state; bool submitting; int packetLength; - PESPacket packet; + PESPacket packet; }; #endif diff --git a/player.cc b/player.cc index a07d8ce..997dcff 100644 --- a/player.cc +++ b/player.cc @@ -70,8 +70,11 @@ Player::~Player() int Player::init() { if (initted) return 0; - +#ifndef WIN32 pthread_mutex_init(&mutex, NULL); +#else + mutex=CreateMutex(NULL,FALSE,NULL); +#endif demuxer = new DemuxerVDR(); if (!demuxer) return 0; @@ -121,6 +124,9 @@ int Player::shutdown() delete demuxer; demuxer = NULL; +#ifdef WIN32 + CloseHandle(mutex); +#endif return 1; } @@ -442,7 +448,7 @@ void Player::lock() logger->log("Player", Log::DEBUG, "LOCKED"); #else - // FIXME Marten + WaitForSingleObject(mutex, INFINITE ); #endif } @@ -452,7 +458,7 @@ void Player::unLock() logger->log("Player", Log::DEBUG, "UNLOCKING"); pthread_mutex_unlock(&mutex); #else - // FIXME Marten + ReleaseMutex(mutex); #endif } @@ -489,6 +495,7 @@ void Player::restartAt(ULLONG timecode) void Player::setStartTS(UINT dataInBuffer) { +#ifndef NEW_DEMUXER if (isRecording && feedPosition) // (feedPosition != 0) { // FIXME find out how much data need to get to find a TS @@ -505,18 +512,25 @@ void Player::setStartTS(UINT dataInBuffer) { demuxer->findVideoPTS(threadBuffer, dataInBuffer, &startTS); } +#else + startTS=0; +#endif } 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); 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))); + #endif logger->log("Player", Log::DEBUG, "Set end TS"); } @@ -582,7 +596,10 @@ void Player::threadMethod() UINT thisRead; UINT writeLength; UINT thisWrite; - UINT preBufferTotal; + UINT preBufferTotal = 0; +#ifdef NEW_DEMUXER + ULLONG currentposition; +#endif VDR* vdr = VDR::getInstance(); @@ -633,6 +650,9 @@ void Player::threadMethod() } threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead); +#ifdef NEW_DEMUXER + currentposition=feedPosition; + #endif if (!vdr->isConnected()) { doConnectionLost(); @@ -697,7 +717,12 @@ void Player::threadMethod() while(writeLength < thisRead) { +#ifndef NEW_DEMUXER thisWrite = demuxer->put(threadBuffer + writeLength, thisRead - writeLength); +#else + thisWrite = demuxer->put(threadBuffer + writeLength, thisRead - writeLength, + currentposition+(ULLONG)writeLength); +#endif writeLength += thisWrite; // logger->log("Player", Log::DEBUG, "Put %i to demuxer", thisWrite); @@ -747,7 +772,7 @@ void Player::threadPostStopCleanup() void Player::test1() { logger->log("Player", Log::DEBUG, "PLAYER TEST 1"); - video->play(); + video->play(); // video->setAspectRatio(Video::ASPECT4X3); } diff --git a/player.h b/player.h index 1496dce..09af40c 100644 --- a/player.h +++ b/player.h @@ -110,7 +110,7 @@ class Player : public Thread_TYPE, public Callback #ifndef WIN32 pthread_mutex_t mutex; #else - // FIXME Marten + HANDLE mutex; #endif void lock(); void unLock(); diff --git a/stream.cc b/stream.cc index f61ecfb..f226d8f 100644 --- a/stream.cc +++ b/stream.cc @@ -38,6 +38,7 @@ void Stream::shutdown() { if (initted) free(outbuf); initted = 0; + } int Stream::init(int bufsize) @@ -56,6 +57,7 @@ void Stream::flush() { #ifdef NEW_DEMUXER mediapackets.clear(); + if (draintarget) draintarget->ResetTimeOffsets(); #endif bufferHead = 0; bufferTail = 0; @@ -100,7 +102,7 @@ int Stream::put(UCHAR* inbuf, int len) return ret; } #else -int Stream::put(UCHAR* inbuf, int len) +int Stream::put(UCHAR* inbuf, int len,ULLONG curpos) { int ret = 0; int tail = bufferTail; @@ -111,7 +113,7 @@ int Stream::put(UCHAR* inbuf, int len) MediaPacket newPacket; newPacket.length=len; newPacket.pos_buffer=0; - newPacket.recording_byte_pos=0; + newPacket.recording_byte_pos=curpos; newPacket.synched=false; newPacket.disconti=false; newPacket.pts=0; @@ -243,9 +245,7 @@ int Stream::drain(DrainTarget* dt) if (cur_packet_pos==cur_mp.length) { cur_packet_pos=0; mediapackets.pop_back(); -// if ((int)(tail+cur_mp.length) < mark) { - if ((((ULONG)tail)+cur_mp.length) < ((ULONG)mark)) - { + if ((((ULONG)tail)+cur_mp.length) < ((ULONG)mark)) { bufferTail=tail+cur_mp.length; } else { bufferTail=0; diff --git a/stream.h b/stream.h index 0b48840..c3abce6 100644 --- a/stream.h +++ b/stream.h @@ -39,12 +39,17 @@ class Stream int init(int bufsize); void shutdown(); void flush(); +#ifndef NEW_DEMUXER int put(UCHAR* inbuf, int len); +#else + int put(UCHAR* inbuf, int len,ULLONG curpos); +#endif + #ifndef NEW_DEMUXER int drain(int fd); #else int drain(DrainTarget* fd); - void setDrainTarget(DrainTarget *dt) {draintarget=dt;}; + void setDrainTarget(DrainTarget *dt) {if (dt) draintarget=dt;}; #endif private: diff --git a/winmain.cc b/winmain.cc index d1efe84..f6053fa 100644 --- a/winmain.cc +++ b/winmain.cc @@ -560,27 +560,6 @@ ULLONG ntohll(ULLONG a) ULLONG htonll(ULLONG a) { -/* - #if BYTE_ORDER == BIG_ENDIAN - return a; - #else - ULLONG b = 0; - - b = ((a << 56) & 0xFF00000000000000ULL) - | ((a << 40) & 0x00FF000000000000ULL) - | ((a << 24) & 0x0000FF0000000000ULL) - | ((a << 8) & 0x000000FF00000000ULL) - | ((a >> 8) & 0x00000000FF000000ULL) - | ((a >> 24) & 0x0000000000FF0000ULL) - | ((a >> 40) & 0x000000000000FF00ULL) - | ((a >> 56) & 0x00000000000000FFULL) ; - - return b; - #endif*///This macro switching does not work for windows, here is a implementation without - // using BYTE_ORDER - //#define ntohll(x) (((_int64)(ntohl((int)((x << 32) >> 32))) << 32) | - // (unsigned int)ntohl(((int)(x >> 32)))) //By Runner - return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) |(ULONG)htonl(((ULONG) (a >> 32)))); } -- 2.39.5