From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mpeglib/lib/util/syncClockMPEG.cpp | 221 +++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 mpeglib/lib/util/syncClockMPEG.cpp (limited to 'mpeglib/lib/util/syncClockMPEG.cpp') diff --git a/mpeglib/lib/util/syncClockMPEG.cpp b/mpeglib/lib/util/syncClockMPEG.cpp new file mode 100644 index 00000000..53ae7e2d --- /dev/null +++ b/mpeglib/lib/util/syncClockMPEG.cpp @@ -0,0 +1,221 @@ +/* + synchronisation of audio/video (PTS) against system clock stamps (SCR) + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#include "syncClockMPEG.h" + + +#include + +using namespace std; + + +SyncClockMPEG::SyncClockMPEG() { + syncMode=__SYNC_NONE; + abs_thread_mutex_init(&scrMut); + abs_thread_mutex_init(&changeMut); + lastSCR=0.0; + lastPTS=0.0; + jitter=0.0; + oldjitter=0.0; + + TimeWrapper::gettimeofday(&lastPTS_time); + + +} + + +SyncClockMPEG::~SyncClockMPEG() { + abs_thread_mutex_destroy(&changeMut); + abs_thread_mutex_destroy(&scrMut); +} + + + +int SyncClockMPEG::getSyncMode() { + return syncMode; +} + + +void SyncClockMPEG::setSyncMode(int syncMode) { + this->syncMode=syncMode; +} + + + +int SyncClockMPEG::syncAudio(double pts,double scr) { + switch(syncMode) { + case __SYNC_AUDIO: + markLastPTSTime(scr,pts); + break; + default: + cout << "syncMode not implemented:"<tv_usec=a->tv_usec; + c->tv_sec=a->tv_sec; + + c->tv_usec-=b->tv_usec; + c->tv_sec-=b->tv_sec; + + if (c->tv_usec <= 0) { + c->tv_usec=c->tv_usec+1000000; + c->tv_sec--; + } + if (c->tv_usec >= 1000000) { + c->tv_usec=c->tv_usec-1000000; + c->tv_sec++; + } + return true; +} + + +double SyncClockMPEG::timeval2Double(timeval_t* a) { + return (double)a->tv_sec+(double)(a->tv_usec)/1000000.0; +} + + +void SyncClockMPEG::double2Timeval(double a,timeval_t* dest) { + dest->tv_sec=(int)a; + dest->tv_usec=(int)(1000000.0*(double)(a-(double)dest->tv_sec)); +} + + +int SyncClockMPEG::gowait(double ,double pts, + TimeStamp* earlyTime,TimeStamp* ) { + double window; + double currentPTS=getPTSTime(&window); + double diff_time; + + // in window we have the jitter + // diff_time is positive when we are in the future + diff_time=pts-(currentPTS+window); + + + + // tolerate one frame (for 25 frames/s) in the future + // but wait a bit + if (diff_time > 0.0) { + diff_time=diff_time/4.0; + + double2Timeval(diff_time,earlyTime->getTime()); + if (diff_time > 1) { + // cannot be, we assume stange clock error + earlyTime->set(1,0); + } + + return true; + } + + earlyTime->set(0,0); + // one frame late, display it, without waiting + // and hope we catch up + if (diff_time > -0.04) { + return true; + } + /* + cout << "(video) pts stream:"<tv_sec + << "time(usec)"<tv_usec<