summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/frame/frameQueue.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch)
tree9047cf9e6b5c43878d5bf82660adae77ceee097a /mpeglib/lib/frame/frameQueue.cpp
downloadtdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz
tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip
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
Diffstat (limited to 'mpeglib/lib/frame/frameQueue.cpp')
-rw-r--r--mpeglib/lib/frame/frameQueue.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/mpeglib/lib/frame/frameQueue.cpp b/mpeglib/lib/frame/frameQueue.cpp
new file mode 100644
index 00000000..fe524976
--- /dev/null
+++ b/mpeglib/lib/frame/frameQueue.cpp
@@ -0,0 +1,101 @@
+/*
+ queues frames
+ Copyright (C) 2001 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 "frameQueue.h"
+
+#include <iostream>
+
+using namespace std;
+
+FrameQueue::FrameQueue(int maxsize) {
+ this->size=maxsize;
+ entries = new Frame*[size];
+ int i;
+ for(i=0;i<size;i++) {
+ entries[i]=NULL;
+ }
+ fillgrade=0;
+ writepos=0;
+ readpos=0;
+}
+
+
+FrameQueue::~FrameQueue() {
+ int i;
+ for(i=0;i<size;i++) {
+ if (entries[i] != NULL) {
+ delete entries[i];
+ }
+ }
+ delete entries;
+}
+
+int FrameQueue::canRead() {
+ return (fillgrade > 0);
+}
+
+
+int FrameQueue::canWrite() {
+ return (fillgrade < size);
+}
+
+
+int FrameQueue::getFillgrade() {
+ return fillgrade;
+}
+
+
+void FrameQueue::enqueue(Frame* frame) {
+ if(canWrite() == false) {
+ cout << "FrameQueue full cannot enqueue"<<endl;
+ exit(0);
+ }
+ fillgrade++;
+ entries[writepos]=frame;
+ writepos++;
+ if (writepos == size) {
+ writepos=0;
+ }
+}
+
+
+Frame* FrameQueue::dequeue() {
+ if(canRead() == false) {
+ cout << "FrameQueue empty cannot dequeue"<<endl;
+ exit(0);
+ }
+ Frame* back=entries[readpos];
+ // invalide this frame, we do not longer own it!
+ entries[readpos]=NULL;
+ fillgrade--;
+ readpos++;
+ if (readpos == size) {
+ readpos=0;
+ }
+ return back;
+}
+
+Frame* FrameQueue::peekqueue(int pos) {
+ if(fillgrade-pos <= 0) {
+ cout << "FrameQueue : cannot peek this positon"<<endl;
+ cout << "fillgrade:"<<fillgrade<<endl;
+ cout << "pos:"<<pos<<endl;
+ exit(0);
+ }
+ int getpos=(readpos+pos) % size;
+
+
+ Frame* back=entries[getpos];
+ return back;
+}
+