Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Stream.cpp

Go to the documentation of this file.
00001 
00007 #include "Stream.hpp"
00008 #include "GOP.hpp"
00009 #include "Frame.hpp"
00010 
00011 
00012 Stream::Stream(const QString & fName, bool preRead) {
00013         file.setName(fName);
00014         width = -1;
00015         height = -1;
00016         gopList.setAutoDelete(true);
00017 }
00018 
00019 
00020 Stream::~Stream(){};
00021 
00022 
00023 GOP *Stream::getMasterGOP(unsigned int i) {
00024     return gopList.at(i);
00025 }
00026 
00027 
00028 Frame *Stream::getFrame(uint no) {
00029 
00030     uint fpp = 0;               // frames per pattern
00031     uint currNo = 0;
00032     GOP *p;
00033 
00034     for (uint i = 0; i < getMasterGOPCount(); i++) {
00035         p = getMasterGOP(i);
00036         ASSERT(p != NULL);
00037         fpp = p->getFrameCount();
00038         currNo += fpp;
00039         if (currNo >= no) {
00040             if (currNo == no) {
00041                 // we start with 0 -> it's the first frame in the next pattern
00042                 p = getMasterGOP(i + 1);
00043                 return p->getFrame(0);
00044             } else {
00045                 uint offset = currNo - no;
00046                 return p->getFrame(fpp - offset);       // p->getFrameCount()
00047             }
00048         }
00049     }
00050     return NULL;
00051 
00052 }
00053 
00054 
00055 int Stream::fillBuffer(Frame * f) {
00056 
00057     // buffer seems to be full
00058     if (f->inMem())
00059         return ERR_OK;
00060 
00061     if (!file.at(f->getFileOffset())) {
00062 #if MYDEBUG >= 1
00063         cout << "Frame's fileOffset (" << f->
00064             getFileOffset() << ") is wrong!\n";
00065 #endif
00066         return (ERR_FILE);
00067     }
00068     // resize the buffer now!
00069     if (!f->resizeBuffer(f->getByteSize())) {
00070 #if MYDEBUG >= 1
00071         cout << "Can't resize the buffer to " << f->
00072             getByteSize() << " bytes!\n";
00073 #endif
00074         return ERR;
00075     }
00076     // fill it now!
00077     if (!file.readBlock(f->getBuffer(), f->getByteSize())) {
00078 #if MYDEBUG >= 1
00079         cout << "Can't read " << f->
00080             getByteSize() << " bytes from stream!\n";
00081 #endif
00082 
00083     }
00084     return ERR_OK;
00085 }
00086 
00087 
00088 
00089 int Stream::fillBuffer(GOP * p) {
00090     unsigned int frameCount = p->getFrameCount();
00091     Frame *fr;
00092     int err;
00093 
00094     for (unsigned int i = 0; i < frameCount; i++) {
00095                 fr = p->getFrame(i);
00096                 if (!fr->inMem()) {
00097                         err = fillBuffer(fr);
00098                         if (err != ERR_OK)
00099                                 return err;
00100                 }
00101     }
00102     return ERR_OK;
00103 }
00104 
00105 
00106 int Stream::freeBuffer(GOP *p) {
00107     uint frameCount = p->getFrameCount();
00108     Frame *f;
00109     int err;
00110 
00111         for (uint i = 0; i < frameCount; i++) {
00112                 f = p->getFrame(i);
00113                 if (f->inMem()) {
00114                         err = f->resizeBuffer(0);
00115                         if (err != ERR_OK)
00116                                 return err;
00117                 }
00118         }
00119         
00120         return ERR_OK;
00121 }
00122 
00123 int Stream::freeBuffer(Frame *f) {
00124 
00125     // buffer seems to be empty
00126     if (!f->inMem())
00127                 return ERR_OK;
00128 
00129     if (!f->resizeBuffer(0))
00130                 return ERR;
00131 
00132     return ERR_OK;
00133 }
00134 
00135 
00136 int Stream::getWidth() {
00137         return width;
00138 }
00139 
00140 int Stream::getHeight() {
00141         return height;
00142 }
00143 
00144 unsigned int Stream::getMasterGOPCount() {
00145         return gopList.count();
00146 };
00147 
00148 unsigned int Stream::getFrameCount() {
00149         return noFrames;
00150 }
00151 
00152 
00153 QString Stream::getFileName() {
00154         return file.name();
00155 }

Generated on Wed Mar 19 11:57:43 2003 for qctva4lv by doxygen1.2.17