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/timeStampArray.cpp | 178 ++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 mpeglib/lib/util/timeStampArray.cpp (limited to 'mpeglib/lib/util/timeStampArray.cpp') diff --git a/mpeglib/lib/util/timeStampArray.cpp b/mpeglib/lib/util/timeStampArray.cpp new file mode 100644 index 00000000..730dc280 --- /dev/null +++ b/mpeglib/lib/util/timeStampArray.cpp @@ -0,0 +1,178 @@ +/* + class for managing byte positions and associated time positions + Copyright (C) 1999 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 + +#include "timeStampArray.h" + +using namespace std; + + +TimeStampArray::TimeStampArray(char* aName,int entries) { + + writePos=0; + readPos=0; + fillgrade=0; + lastWritePos=0; + this->entries=entries; + if (entries < 1) { + cout << "TimeStampArray entries must be >= 1"; + exit(0); + } + + + abs_thread_mutex_init(&writeInMut); + abs_thread_mutex_init(&changeMut); + + + + name=strdup(aName); + int i; + tStampArray=new TimeStamp*[entries]; + + for(i=0;icopyTo(tStampArray[writePos]); + tStampArray[writePos]->setKey(key,len); + /* + if (fillgrade > 0) { + if (tStampArray[lastWritePos]->getKey() == key) { + unlockStampArray(); + return; + } + } + */ + + lastWritePos=writePos; + writePos++; + fillgrade++; + if (writePos == entries) { + writePos=0; + } + if (fillgrade == entries) { + cout << name<<" TimeStampArray::array overfull forward"<getKey()-key; + unlockStampArray(); + return back; +} + +TimeStamp* TimeStampArray::getTimeStamp(long key) { + lockStampArray(); + TimeStamp* back=tStampArray[readPos]; + if (key > back->getKey()+back->getKeyLen()) { + if (fillgrade > 1) { + internalForward(); + unlockStampArray(); + return getTimeStamp(key); + } + } + + /* + if (back->getKey() > key) { + cout << "key "<getKey()-key<print("key access"); + } + */ + unlockStampArray(); + /* maybe we should return NULL here to indicate + that there is no valid timestamp */ + /* This would need a check for every getTimeStamp call + I think returning the last available stamp is ok + */ + return back; +} + + +void TimeStampArray::forward() { + lockStampArray(); + internalForward(); + unlockStampArray(); +} + + + +void TimeStampArray::clear() { + lockStampArray(); + writePos=0; + readPos=0; + fillgrade=0; + unlockStampArray(); +} + + +void TimeStampArray::lockStampArray() { + + abs_thread_mutex_lock(&changeMut); + abs_thread_mutex_lock(&writeInMut); + abs_thread_mutex_unlock(&changeMut); + +} + + +void TimeStampArray::unlockStampArray() { + abs_thread_mutex_unlock(&writeInMut); +} + + +void TimeStampArray::internalForward() { + readPos++; + fillgrade--; + if (readPos == entries) { + readPos=0; + } +} -- cgit v1.2.3