PSNR Class Reference

Adaptor class PSNR calculates psnr for each frame and provides overall statistics <short description="">. More...

#include <PSNR.hpp>

Inheritance diagram for PSNR:

VideoAdaptor Adaptor List of all members.

Public Member Functions

 PSNR (VideoESInfo *esi, YUVStreamIO *OrigYUVStream, Statistics *statistics, FILE *psnrFP=NULL)
list< Frame * > adapt (Frame *frm)
 Accepts as input a frame, and checks if it can adapt the frame, If the frame is modified, a new Frame object is created and inserted into the return list.
Adaptorclone ()
 Create a shallow copy of the Adaptor.
void initialize ()
 Initialize internal data structures.
list< Frame * > close ()
 Close and destroy an Adaptor.
u32 getTranscodingCosts () const
 returns adaptation costs (CPU only)

Protected Attributes

YUVStreamIOyuvOrig
AU lastAU
u8 * lastPayload
UncompressedVideoFramedummyFrame
Statisticsstats
double sumPSNR
int numFrames
int numFramesNotInf
FILE * psnrInfo

Detailed Description

Adaptor class PSNR calculates psnr for each frame and provides overall statistics <short description="">.

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
PSNR.hpp,v 1.11 2006/01/20 15:37:17 mkropfbe Exp

Definition at line 64 of file PSNR.hpp.


Member Function Documentation

list< Frame * > PSNR::adapt Frame frm  )  [virtual]
 

Accepts as input a frame, and checks if it can adapt the frame, If the frame is modified, a new Frame object is created and inserted into the return list.

This new frame is returned only, if the size of the payload is larger than zero. If the frame was not modified, it is also inserted into the list. For more complex adaptors, it will happen, that the adaptor caches up one complete GOP and returns the full GOP in network order. A caching adaptor has to create deep-copies for each frames. Never directly modify the payload of the input frm, always create copies!!!

Parameters:
frm object to adapt. An Adaptor is never allowed to free the input frame. This has to be done in the caller.
Returns:
List of adapted Frame objects

Reimplemented from Adaptor.

Definition at line 90 of file PSNR.cpp.

References UncompressedVideoFrame::computePSNR(), Frame::getAU(), YUVStreamIO::getFrame(), VideoFrame::getHeight(), Frame::getMediaTimeScale(), Statistics::getPlayoutSec(), Statistics::getPlayoutSecFPS(), Statistics::getPlayoutSecPSNR(), VideoFrame::getWidth(), Statistics::incPlayoutSecPSNR(), initialize(), Frame::setAU(), Frame::setMediaTimeScale(), and Frame::unsetAU().

00090 { 00091 list < Frame * >tmp; 00092 u32 thisCTS; 00093 double psnr; 00094 int thisSec; 00095 int done=0; 00096 if(!this->initialized) 00097 initialize(); 00098 00099 UncompressedVideoFrame *thisFrame = (UncompressedVideoFrame*)frm; 00100 thisCTS = frm->getAU()->cts; 00101 thisSec = (int)floor((double)thisCTS / es->getMediaTimeScale()); 00102 UncompressedVideoFrame *origFrame; 00103 dprintf_full("PSNR::adapt frame CTS %i, VOP increment %i, playoutSec: %6.3f\n", 00104 thisCTS,es->getVOPTimeIncrement(),stats->getPlayoutSec()); 00105 00106 //first frame, malloc payload, size is always the same for YUV frames! 00107 if (!lastAU.payload) { 00108 dprintf_full("PSNR::adapt creating initial buffers\n"); 00109 lastPayload = (u8*)malloc(thisFrame->getAU()->size); 00110 lastAU.payload = lastPayload; 00111 lastAU.size = thisFrame->getAU()->size; 00112 dummyFrame = new UncompressedVideoFrame(Frame::NN_VOP, thisFrame->getWidth(), thisFrame->getHeight()); 00113 dummyFrame->setMediaTimeScale(thisFrame->getMediaTimeScale()); 00114 dummyFrame->setAU(&lastAU,false); //disable detectFrameType() for efficiency! 00115 } 00116 00117 while(!done) { 00118 numFrames++; 00119 origFrame = (UncompressedVideoFrame *)yuvOrig->getFrame(); 00120 assert(origFrame); 00121 assert(origFrame->getAU()->cts <= thisCTS); 00122 psnr=0; 00123 00124 if (origFrame->getAU()->cts == thisCTS) { //NO FRAME LOSS 00125 psnr = thisFrame->computePSNR(origFrame); 00126 done=1; 00127 } else { //catch up BECAUSE OF FRAME LOSS 00128 psnr = dummyFrame->computePSNR(origFrame); 00129 dprintf_full("PSNR::adapt dummyADAPT!\n"); 00130 } 00131 if (psnr < DBL_MAX) { 00132 numFramesNotInf++; 00133 sumPSNR+=psnr; 00134 stats->incPlayoutSecPSNR(thisSec, psnr); 00135 } 00136 00137 if (done) { 00138 dprintf_full("PSNR::adapt: (sec %i), origFrame CTS %8i thisFrame CTS %8i: thisPSNR %3.3f thisSecAvgPSNR %3.3f thisSecFPS %i overallPSNR %3.3f\n", 00139 thisSec, origFrame->getAU()->cts, thisCTS, psnr, 00140 stats->getPlayoutSecPSNR(thisSec), stats->getPlayoutSecFPS(thisSec), 00141 sumPSNR/numFramesNotInf); 00142 } else { 00143 dprintf_full("PSNR::adapt: (sec %i), origFrame CTS %8i dummyFrame CTS %8i: thisPSNR %3.3f thisSecAvgPSNR %3.3f thisSecFPS %i overallPSNR %3.3f\n", 00144 thisSec, origFrame->getAU()->cts, dummyFrame->getAU()->cts, psnr, 00145 stats->getPlayoutSecPSNR(thisSec), stats->getPlayoutSecFPS(thisSec), 00146 sumPSNR/numFramesNotInf); 00147 } 00148 00149 if(psnrInfo) { 00150 fprintf(psnrInfo,"%8i %s %8i %8i %6.3f %6.3f %6.3f %8i %8i %8i\n", 00151 thisSec, done?"OK ":"DROP", origFrame->getAU()->cts, done?thisCTS:dummyFrame->getAU()->cts, psnr, 00152 stats->getPlayoutSecPSNR(thisSec), sumPSNR/numFramesNotInf, 00153 stats->getPlayoutSecFPS(thisSec), numFrames, numFramesNotInf); 00154 } 00155 delete origFrame; 00156 } 00157 00158 00159 assert(lastAU.size == thisFrame->getAU()->size); 00160 dummyFrame->unsetAU(); 00161 lastAU = thisFrame->getAU(); 00162 lastAU.payload = lastPayload; 00163 lastAU.size = thisFrame->getAU()->size; 00164 memcpy(lastAU.payload, thisFrame->getAU()->payload, thisFrame->getAU()->size); 00165 dummyFrame->setAU(&lastAU,false); //disable detectFrameType() for efficiency! 00166 00167 //standard forwarding adaptor behaviour 00168 tmp.push_front(frm); 00169 return tmp; 00170 }

Adaptor* PSNR::clone  )  [inline, virtual]
 

Create a shallow copy of the Adaptor.

Creates an Adaptor with the same setup (without copying the current status).

Returns:
An Adaptor object.

Implements Adaptor.

Definition at line 78 of file PSNR.hpp.

00078 { return new PSNR(es, yuvOrig,stats,NULL); };

list< Frame * > PSNR::close  )  [inline, virtual]
 

Close and destroy an Adaptor.

Releases all internally buffered frame objects, and deallocate all allocated memory. The Adaptor must not be used after calling the close method!!!

Returns:
List of adapted Frame objects.

Reimplemented from Adaptor.

Definition at line 82 of file PSNR.hpp.

00082 { 00083 list < Frame * >tmp; 00084 if(psnrInfo) { 00085 fclose(psnrInfo); 00086 psnrInfo=NULL; 00087 } 00088 return tmp; 00089 };

void PSNR::initialize  )  [virtual]
 

Initialize internal data structures.

Implements Adaptor.

Definition at line 79 of file PSNR.cpp.

Referenced by adapt().

00079 { 00080 if(!initialized) { 00081 if(psnrInfo) { 00082 fprintf(psnrInfo,"Second status Orig_CTS Compr_CTS framePSNR thisSecAvgPSNR totalAvgPSNR numFramesPerSec SumNumFrames SumNumFramesNotInfinite\n"); 00083 } 00084 initialized=true; 00085 } 00086 }


The documentation for this class was generated from the following files: