00001 #include "YUVStream.hpp"
00002
00003 #ifdef WIN32
00004
00005 #else
00006 #include <unistd.h>
00007
00008 #endif
00009 #include <qtimer.h>
00010
00011
00012 YUVStream::~YUVStream() {}
00013
00014 YUVStream::YUVStream(const QString &fname, int x, int y,
00015 bool preRead, uint fpp)
00016 : Stream(fname,preRead) {
00017
00018
00019 file.setName(fname);
00020 if (!file.open(IO_ReadOnly)) {
00021 #if MYDEBUG >= 1
00022 cout << "Can't open " << fname.ascii() << "!\n\n";
00023 #endif
00024
00025 }
00026
00027 width = x;
00028 height = y;
00029 ySize = width * height;
00030 uvSize = ySize / 4;
00031 noFrames = 0;
00032 minCompPatSize = 0;
00033 maxCompPatSize = 0;
00034
00035 bufOffsetY = 0;
00036 bufOffsetU = bufOffsetY + ySize;
00037 bufOffsetV = bufOffsetU + uvSize;
00038
00039
00040 file.at(0);
00041
00042 gopList.setAutoDelete(TRUE);
00043 fileSize = file.size();
00044 maxPSNR = 0;
00045
00046 #if MYDEBUG >= 4
00047 cout << "estimated maxPSNR: " << maxPSNR << nl;
00048 #endif
00049
00050 if (preRead)
00051 while (addNextGOP(fpp) != NULL)
00052 ;
00053
00054 }
00055
00056 long YUVStream::getFrameSize() { return ySize + 2 * uvSize; }
00057
00058 long YUVStream::getYSize() { return ySize; }
00059
00060 long YUVStream::getUSize() { return uvSize; }
00061
00062 long YUVStream::getVSize() { return uvSize; }
00063
00064 uint YUVStream::getMinCompressedPatSize() { return minCompPatSize; }
00065
00066 void YUVStream::setMinCompressedPatSize(uint s) { minCompPatSize = s; }
00067
00068 uint YUVStream::getMaxCompressedPatSize() { return maxCompPatSize; }
00069
00070 void YUVStream::setMaxCompressedPatSize(uint s) { maxCompPatSize = s; }
00071
00072 uint YUVStream::getMinCompressedBaselayerSize() { return minCompBLSize; }
00073
00074 void YUVStream::setMinCompressedBaselayerSize(uint s) { minCompBLSize = s; }
00075
00076 uint YUVStream::getMaxCompressedBaselayerSize() { return maxCompBLSize; }
00077
00078 void YUVStream::setMaxCompressedBaselayerSize(uint s) { maxCompBLSize = s; }
00079
00080 long YUVStream::getBufOffsetY() {return bufOffsetY; }
00081
00082 long YUVStream::getBufOffsetU() {return bufOffsetU; }
00083
00084 long YUVStream::getBufOffsetV() {return bufOffsetV; }
00085
00086 double YUVStream::getMaxPSNR() {return maxPSNR; }
00087
00088 long YUVStream::getFileSize() { return fileSize; }
00089
00090
00091
00092 GOP* YUVStream::addNextGOP(uint numFrames) {
00093 uint fppCount = 0;
00094 YUVGOP *p;
00095 YUVFrame *frame;
00096 long filePos = file.at();
00097
00098 if (filePos >= fileSize)
00099 return NULL;
00100
00101
00102 p = new YUVGOP(this, gopList.count());
00103 gopList.append(p);
00104 p->setPSNRmp(maxPSNR);
00105
00106
00107 while ( (filePos < fileSize) && (fppCount < numFrames) ) {
00108
00109 #ifdef MENS_HEKK
00110 if (fppCount == 0)
00111 frame = new YUVFrame(noFrames, fppCount, filePos, p, I_VOP);
00112 else
00113 frame = new YUVFrame(noFrames, fppCount, filePos, p, B_VOP);
00114 frame->setNoInDisplay(noFrames);
00115 frame->setByteSize(this->getFrameSize());
00116 p->addFrame(frame);
00117 filePos += this->getFrameSize();
00118 file.at(filePos);
00119 fppCount++;
00120 noFrames++;
00121 continue;
00122 #endif
00123 frame = new YUVFrame(noFrames, fppCount, filePos, p);
00124 frame->setNoInDisplay(noFrames);
00125 frame->setByteSize(this->getFrameSize());
00126 p->addFrame(frame);
00127 filePos += this->getFrameSize();
00128 file.at(filePos);
00129 fppCount++;
00130 noFrames++;
00131 }
00132
00133 p->calcByteSize();
00134
00135 #if MYDEBUG >= 4
00136 printf("YUVaddNextGOP (%i frames@%ld) from file pos %li (From %li)\n",
00137 p->getFrameCount(),getFrameSize(),filePos,fileSize);
00138 #endif
00139
00140 return p;
00141 }