From 945240d136e6986bc0f7c1061d422acfbdf8a569 Mon Sep 17 00:00:00 2001 From: Mark Calderbank Date: Fri, 23 Jun 2006 23:23:38 +0000 Subject: [PATCH] MVP/Windows convergence --- defines.h | 1 + demuxer.cc | 13 +------------ demuxer.h | 8 -------- demuxervdr.cc | 46 +++++++++------------------------------------- demuxervdr.h | 8 ++------ objects.mk | 26 ++++++++++++++------------ player.cc | 12 +----------- stream.cc | 3 +-- stream.h | 5 ----- videowin.cc | 11 ++++++----- videowin.h | 2 +- 11 files changed, 36 insertions(+), 99 deletions(-) diff --git a/defines.h b/defines.h index e6e4003..d3c1f0d 100644 --- a/defines.h +++ b/defines.h @@ -48,6 +48,7 @@ void MILLISLEEP(ULONG a); #define STRCASECMP _stricmp #define STRCASESTR StrStrI /* #define STRTOULL _strtoui64 */ + #define STRTOUL strtoul #define CLOSESOCKET closesocket #else diff --git a/demuxer.cc b/demuxer.cc index 0b6f2cd..8e97ec6 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -185,11 +185,8 @@ 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(); @@ -201,11 +198,7 @@ int Demuxer::PESPacket::submit(ULLONG cur_pos) { 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; } @@ -213,11 +206,7 @@ int Demuxer::PESPacket::submit(ULLONG cur_pos) { if (dx->audio_current == -1) dx->audio_current = packetType; 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 6447f0c..7e0f88d 100644 --- a/demuxer.h +++ b/demuxer.h @@ -46,11 +46,7 @@ protected: PESPacket(); void init(UCHAR type); int write(UCHAR* buf, int len); -#ifndef NEW_DEMUXER int submit(); -#else - int submit(ULLONG cur_pos); -#endif protected: UCHAR data[0x10000]; UINT length, size; @@ -82,11 +78,7 @@ protected: 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 virtual void setFrameNum(ULONG frame) {} virtual ULONG getFrameNumFromPTS(ULLONG pts) {return 0;} diff --git a/demuxervdr.cc b/demuxervdr.cc index cb0a4fd..9444b5b 100644 --- a/demuxervdr.cc +++ b/demuxervdr.cc @@ -141,25 +141,12 @@ void DemuxerVDR::setFrameNum(ULONG frame) Log::getInstance()->log("Demuxer", Log::DEBUG, "setFrameNum %d", frame); } -#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; @@ -172,11 +159,7 @@ int DemuxerVDR::put(UCHAR* buf, int len, ULLONG cur_pos) packet.write(buf, state); buf += state; len -= state; ret += state; state = 0; -#ifndef NEW_DEMUXER - if (packet.submit() == 0) // Stream is full -#else - if (packet.submit(current_position) == 0) // Stream is full -#endif + if (packet.submit() == 0) // Stream is full { submitting = true; return ret; @@ -229,25 +212,14 @@ int DemuxerVDR::put(UCHAR* buf, int len, ULLONG cur_pos) break; } -#ifdef NEW_DEMUXER - current_position++; -#endif - if (state == -6) // Packet header complete { if (len >= packetLength) // The entire packet is available. { packet.write(buf, packetLength); buf += packetLength; len -= packetLength; ret += packetLength; -#ifdef NEW_DEMUXER - current_position+=(ULLONG)packetLength; -#endif state = 0; -#ifndef NEW_DEMUXER if (packet.submit() == 0) // Stream is full -#else - if (packet.submit(current_position) == 0) // Stream is full -#endif { submitting = true; return ret; @@ -270,7 +242,7 @@ ULONG DemuxerVDR::getFrameNumFromPTS(ULLONG pts) ULLONG difference = (1LL<<33); ULONG ref_frame = 0; int total = 0, actual = 0; - pthread_mutex_lock(&pts_map_mutex); + pts_map_mutex.Lock(); PTSMap::iterator iter = pts_map.begin(); while (iter != pts_map.end()) { @@ -296,7 +268,7 @@ ULONG DemuxerVDR::getFrameNumFromPTS(ULLONG pts) iter = pts_map.begin(); iter++; pts_map.erase(iter, pts_map.end()); } - pthread_mutex_unlock(&pts_map_mutex); + pts_map_mutex.Unlock(); if (total > 1 && actual == 1) Log::getInstance()->log("Demuxer", Log::DEBUG, "DELETED REFERENCES"); if (actual > 1) @@ -323,18 +295,18 @@ void DemuxerVDR::PESPacketVDR::parseDetails() if (seq_header && pts != PTS_INVALID) { PTSMapEntry me; - pthread_mutex_lock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Lock(); if (dx->pts_map.empty()) { me.pts = pts; me.frame = frame_num; - pthread_mutex_unlock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Unlock(); Log::getInstance()->log("Demuxer", Log::DEBUG, "+* PTS INIT *+ %llu %u", me.pts, me.frame); - pthread_mutex_lock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Lock(); dx->pts_map.push_front(me); } me = dx->pts_map.front(); - pthread_mutex_unlock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Unlock(); UINT fps = Video::getInstance()->getFPS(); ULLONG pts_expected = me.pts + 90000*(frame_num - me.frame) / fps; @@ -345,9 +317,9 @@ Log::getInstance()->log("Demuxer", Log::DEBUG, "+* PTS INIT *+ %llu %u", me.pts, Log::getInstance()->log("Demuxer", Log::DEBUG, "+* PTS JUMP *+ %llu %u", pts, frame_num); me.pts = pts; me.frame = frame_num; - pthread_mutex_lock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Lock(); dx->pts_map.push_front(me); - pthread_mutex_unlock(&(dx->pts_map_mutex)); + dx->pts_map_mutex.Unlock(); } } } diff --git a/demuxervdr.h b/demuxervdr.h index d1412e0..65b0e8e 100644 --- a/demuxervdr.h +++ b/demuxervdr.h @@ -21,7 +21,7 @@ #ifndef DEMUXERVDR_H #define DEMUXERVDR_H -#include "pthread.h" +#include "mutex.h" #include #include "demuxer.h" #include "defines.h" @@ -40,11 +40,7 @@ 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 void setFrameNum(ULONG frame); ULONG getFrameNumFromPTS(ULLONG pts); @@ -59,7 +55,7 @@ class DemuxerVDR : public Demuxer typedef struct { ULLONG pts; ULONG frame; } PTSMapEntry; typedef std::deque PTSMap; PTSMap pts_map; - pthread_mutex_t pts_map_mutex; + Mutex pts_map_mutex; }; #endif diff --git a/objects.mk b/objects.mk index b51cde8..1fd2051 100644 --- a/objects.mk +++ b/objects.mk @@ -1,13 +1,15 @@ -OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o \ - message.o messagequeue.o \ - vdr.o recman.o recording.o channel.o rectimer.o event.o directory.o \ - player.o vfeed.o afeed.o \ - demuxer.o demuxervdr.o stream.o draintarget.o \ - viewman.o box.o region.o colour.o view.o \ - vinfo.o vwallpaper.o vvolume.o vrecordinglist.o vlivebanner.o vmute.o \ - vtimerlist.o vtimeredit.o voptionsmenu.o vrecordingmenu.o vquestion.o \ - vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ - vchannelselect.o vserverselect.o vconnect.o voptions.o vepg.o vrecmove.o \ - widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o woptionbox.o wtextbox.o \ - fonts/helvB24.o fonts/helvB18.o \ +OBJECTS1 = command.o log.o tcp.o dsock.o thread.o timers.o i18n.o mutex.o \ + message.o messagequeue.o \ + vdr.o recman.o recording.o channel.o rectimer.o event.o directory.o\ + player.o vfeed.o afeed.o \ + demuxer.o demuxervdr.o stream.o draintarget.o \ + viewman.o box.o region.o colour.o view.o \ + vinfo.o vquestion.o vwallpaper.o vrecordinglist.o vlivebanner.o \ + vmute.o vvolume.o voptions.o \ + vtimerlist.o vtimeredit.o voptionsmenu.o vrecordingmenu.o \ + vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o \ + vchannelselect.o vserverselect.o vconnect.o vepg.o vrecmove.o \ + widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o \ + woptionbox.o wtextbox.o \ + fonts/helvB24.o fonts/helvB18.o \ remote.o led.o mtd.o video.o audio.o osd.o surface.o diff --git a/player.cc b/player.cc index 13b7576..bdacba5 100644 --- a/player.cc +++ b/player.cc @@ -573,9 +573,6 @@ void Player::threadMethod() UINT writeLength; UINT thisWrite; UINT preBufferTotal = 0; -#ifdef NEW_DEMUXER - ULLONG currentposition; -#endif VDR* vdr = VDR::getInstance(); @@ -626,9 +623,7 @@ void Player::threadMethod() } threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead); -#ifdef NEW_DEMUXER - currentposition=feedPosition; -#endif + if (!vdr->isConnected()) { doConnectionLost(); @@ -693,12 +688,7 @@ 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); diff --git a/stream.cc b/stream.cc index 68232ab..6a4531e 100644 --- a/stream.cc +++ b/stream.cc @@ -119,7 +119,7 @@ int Stream::put(UCHAR* inbuf, int len) return ret; } #else -int Stream::put(UCHAR* inbuf, int len,ULLONG curpos) +int Stream::put(UCHAR* inbuf, int len) { int ret = 0; int tail = bufferTail; @@ -130,7 +130,6 @@ int Stream::put(UCHAR* inbuf, int len,ULLONG curpos) MediaPacket newPacket; newPacket.length=len; newPacket.pos_buffer=0; - newPacket.recording_byte_pos=curpos; newPacket.synched=false; newPacket.disconti=false; newPacket.pts=0; diff --git a/stream.h b/stream.h index 6d33cf0..507855b 100644 --- a/stream.h +++ b/stream.h @@ -42,12 +42,7 @@ class Stream int init(DrainTarget* tdt, 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 - int drain(); private: diff --git a/videowin.cc b/videowin.cc index 487c019..d029886 100644 --- a/videowin.cc +++ b/videowin.cc @@ -48,8 +48,8 @@ VideoWin::VideoWin() startoffset=0; lastrefaudiotime=0; lastrefvideotime=0; - lastreftimeBYTE=0; lastreftimeRT=0; + lastreftimePTS=0; firstsynched=false; cur_audio_media_sample=NULL; cur_video_media_sample=NULL; @@ -377,8 +377,9 @@ ULLONG VideoWin::getCurrentTimestamp() startoffset=sourcefilter->getStartOffset(); ncr_time-=startoffset; ncr_time-=lastreftimeRT; - ULLONG result=frameNumberToTimecode( - VDR::getInstance()->frameNumberFromPosition(lastreftimeBYTE)); + /* ULLONG result=frameNumberToTimecode( + VDR::getInstance()->frameNumberFromPosition(lastreftimeBYTE));*/ + ULLONG result=lastreftimePTS; result+=(ULLONG)(ncr_time/10000LL*90LL); return result; @@ -536,7 +537,7 @@ UINT VideoWin::DeliverMediaSample(MediaPacket packet, else ms->SetPreroll(FALSE); /*Timecode handling*/ lastreftimeRT=reftime1; - lastreftimeBYTE=packet.recording_byte_pos; + lastreftimePTS=packet.pts; }else { ms->SetSyncPoint(FALSE); @@ -689,8 +690,8 @@ void VideoWin::ResetTimeOffsets() { startoffset=0; lastrefaudiotime=0; lastrefvideotime=0; - lastreftimeBYTE=0; lastreftimeRT=0; + lastreftimePTS=0; } diff --git a/videowin.h b/videowin.h index c6b6db8..5176d6a 100644 --- a/videowin.h +++ b/videowin.h @@ -128,7 +128,7 @@ private: bool videoon; UCHAR pseudotvsize; REFERENCE_TIME lastreftimeRT; - ULLONG lastreftimeBYTE; + ULLONG lastreftimePTS; unsigned int videoposx; unsigned int videoposy; #ifdef DS_DEBUG -- 2.39.5