Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RgbDataSrc.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Stream_RgbDataSrc_h
00002 #define Impala_Core_Stream_RgbDataSrc_h
00003 
00004 #include <iostream>
00005 
00006 #include "Basis/String.h"
00007 #include "Basis/NativeTypes.h"
00008 #include "Core/Array/Arrays.h"
00009 #include "Core/Array/MD5Hash.h"
00010 
00011 #include "Core/Stream/DummyFrameProvider.h" 
00012 
00013 
00014 namespace Impala
00015 {
00016 namespace Core
00017 {
00018 namespace Stream
00019 {
00020 
00021 
00022 class RgbDataSrc
00023 {
00024 
00025 public:
00026 
00027     static const int     LASTFRAME_UNKNOWN = 10000000; // not known (yet)
00028     static const int     LASTFRAME_INFINITY = -1;      // src is endless :camera
00029     static const int     UNKNOWN_INT   = -2;
00030     static const Int64   UNKNOWN_INT64 = -2;
00031     static const long    UNKNOWN_LONG  = -2;
00032     // MSVC cannot handle these :-(
00033     //static const float   UNKNOWN_FLOAT = -2;
00034     //static const double  UNKNOWN_DOUBLE= -2;
00035 
00036     RgbDataSrc(int src, CString srcName)
00037     :   mSrc            (src),
00038         mSrcName        (srcName),
00039         mFrameNr        (-1),             // SK: deprecated
00040         mTargetFrameNr        (-1),
00041         mCurrentFrameNr        (-1),
00042         mFrameWidth     (0),
00043         mFrameHeight    (0),
00044         mLastFrame      (LASTFRAME_UNKNOWN),
00045         mData           (0),
00046         mDataOrig       (0),
00047 
00048         mNewImpl        (false),
00049 
00050         mFormatName     ("Unknown Format"),
00051         mFormatLName    (""),
00052         mCodecName      ("Unknown Codec"),
00053 
00054         mGopSize        (UNKNOWN_INT),
00055         mBitRate        (UNKNOWN_INT),
00056         mFrameRateNum   (UNKNOWN_INT),
00057         mFrameRateDen   (UNKNOWN_INT),
00058         mTimeBaseNum    (UNKNOWN_INT),
00059         mTimeBaseDen    (UNKNOWN_INT),
00060         mAspectRatioNum (UNKNOWN_INT),
00061         mAspectRatioDen (UNKNOWN_INT),
00062         mStreamCount    (UNKNOWN_INT),
00063         mBlankFrames    (0),
00064 
00065         mIndexExists(false),
00066         mIsFrameAccurate(true),
00067 
00068         mStartTime      (UNKNOWN_INT64), // deprecated
00069         mEndTime        (UNKNOWN_INT64), // deprecated
00070         mDuration       (UNKNOWN_INT64),
00071         mDurationSec    (UNKNOWN_INT64),
00072         mDurationMin    (UNKNOWN_INT64),
00073         mDurationHour   (UNKNOWN_INT64),
00074         mVideoDuration  (UNKNOWN_INT64),
00075         mVideoShiftSec  (UNKNOWN_INT64) // deprecated
00076     {
00077     }
00078 
00079     virtual
00080     ~RgbDataSrc()
00081     {
00082     }
00083 
00084     int
00085     FrameWidth() const
00086     {
00087         return mFrameWidth;
00088     }
00089 
00090     int
00091     FrameHeight() const
00092     {
00093         return mFrameHeight;
00094     }
00095 
00096     int
00097     FrameNr() const
00098     {
00099         if (mNewImpl)
00100             return mCurrentFrameNr;
00101         else
00102             return mFrameNr;
00103     }
00104 
00105     String
00106     CodecName() const
00107     {
00108         return mCodecName;
00109     }
00110 
00111     String 
00112     FormatName() const
00113     {
00114         return mFormatName + " : " + mFormatLName;
00115     }
00116 
00117     int 
00118     TimeBaseNum() const
00119     {
00120         return mTimeBaseNum;
00121     }
00122 
00123     int 
00124     TimeBaseDen() const
00125     {
00126         return mTimeBaseDen;
00127     }
00128 
00129     int 
00130     GopSize() const
00131     {
00132         return mGopSize;
00133     }
00134 
00135     int 
00136     AspectRatioNum() const
00137     {
00138         return mAspectRatioNum;
00139     }
00140 
00141     int 
00142     AspectRatioDen() const
00143     {
00144         return mAspectRatioDen;
00145     }
00146 
00147     float 
00148     BitRate() const
00149     {
00150         return mBitRate;
00151     }
00152 
00153     //* deprecated; use LeadingBadFrames instead;
00154     const int 
00155     BlankFrames() const
00156     {
00157         ILOG_WARN("BlankFrames() is deprecated; use LeadingBadFrames() instead");
00158         return LeadingBadFrames();
00159     }
00160 
00161     // number of bad frames before the first valid frame
00162     //(used to be called "blank frames")
00163     const int
00164     LeadingBadFrames() const
00165     {
00166         return mBlankFrames;
00167     }
00168 
00169     // total number of bad frames (including leading bad frames)
00170     virtual const int 
00171     BadFrames() const
00172     {
00173         return LeadingBadFrames();
00174     }
00175 
00176     int 
00177     StreamCnt() const
00178     {
00179         return mStreamCount;
00180     }
00181 
00182     virtual bool
00183     IsFrameAccurate() const
00184     {
00185         return mIsFrameAccurate;
00186     }
00187 
00188     Int64
00189     GetDurationSec() const
00190     {
00191         return mDuration;
00192     }
00193 
00194     void 
00195     GetDuration(long& hour,long& minute,long& second,long& fraction) const
00196     {
00197         hour     = mDurationHour;
00198         minute   = mDurationMin;
00199         second   = mDurationSec;
00200         fraction = 0;
00201         return;
00202     }
00203 
00204     void
00205     GetTime(long& hour, long& minute, long& second, long& fraction) const
00206     {
00207         Frame2Time(FrameNr(), hour, minute, second, fraction);
00208     }
00209 
00210     int
00211     GetHour() const
00212     {
00213         long hour, minute, second, fraction;
00214         GetTime(hour, minute, second, fraction);
00215         return hour;
00216     }
00217 
00218     int
00219     GetMinute() const
00220     {
00221         long hour, minute, second, fraction;
00222         GetTime(hour, minute, second, fraction);
00223         return minute;
00224     }
00225 
00226     int
00227     GetSecond() const
00228     {
00229         long hour, minute, second, fraction;
00230         GetTime(hour, minute, second, fraction);
00231         return second;
00232     }
00233 
00234     int
00235     GetFraction() const
00236     {
00237         long hour, minute, second, fraction;
00238         GetTime(hour, minute, second, fraction);
00239         return fraction;
00240     }
00241 
00242     int
00243     LastFrame() const
00244     {
00245         return mLastFrame;
00246     }
00247 
00248     String
00249     LastFrameAsTime() const
00250     {
00251         return FrameAsTimeString(mLastFrame);
00252     }
00253 
00254     UInt8*
00255     DataPtr() const
00256     {
00257         if (!mNewImpl || FrameValid(FrameNr()))
00258             return mData;
00259         else
00260             return DummyFrameProvider::DataPtr(FrameWidth(), FrameHeight());
00261     }
00262 
00263     virtual char
00264     FrameType() const
00265     {
00266         return '?';
00267     }
00268 
00269     virtual bool
00270     CurIsIFrame() const
00271     {
00272         return false;
00273     }
00274 
00275     virtual bool
00276     Valid() const = 0;
00277 
00278     virtual bool
00279     HasIndex() const
00280     {
00281         return mIndexExists;
00282     }
00283 
00284     virtual void
00285     SetInterval(int /*interval*/)
00286     {
00287     }
00288 
00289     bool
00290     NextFrame(int inc = 1)
00291     {
00292         return GotoFrame(FrameNr() + inc);
00293     }
00294 
00295     bool
00296     GotoFrame(int target)
00297     {
00298         if (target < 0)
00299             target = 0;
00300         if (target >= mLastFrame)
00301             target = mLastFrame;
00302 
00303         if (!mNewImpl)
00304         {
00305             mFrameNr = target;          //SK: deprecated
00306         }
00307         else
00308             mTargetFrameNr = target;
00309 
00310          return ReadFrameData();
00311     }
00312 
00313     virtual bool
00314     TheEnd() const
00315     {
00316         return FrameNr() >= mLastFrame;
00317     }
00318 
00319     virtual void
00320     Reset()
00321     {
00322         if (!mNewImpl)
00323         {
00324             ILOG_INFO("Using deprecated code within Reset()");
00325             mFrameNr = -1; // for backw.compat.
00326         }
00327 
00328         mCurrentFrameNr = -1;
00329     }
00330 
00331     String
00332     GetName() const
00333     {
00334         return mSrcName;
00335     }
00336 
00337     int
00338     GetType() const
00339     {
00340         return mSrc;
00341     }
00342 
00343     virtual int
00344     GetTimeBaseNumerator() const
00345     {
00346         return 1;
00347     }
00348 
00349     virtual int
00350     GetTimeBaseDenominator() const
00351     {
00352         return 25;
00353     }
00354 
00355     virtual void
00356     DumpInfo() const
00357     {
00358     }
00359 
00360     virtual String 
00361     GetHash() const
00362     {
00363         return CalcHash_protected();
00364     }
00365 
00369     virtual String
00370     CalcHash() const
00371     {
00372         // SK: next line should be enabled after the new lavc impl is in normal used
00373         //ILOG_WARN("CalcHash() is deprecated (will become protected; use GetHash() instead!");
00374 
00375         return GetHash();
00376     }
00377 
00378 
00379 protected:
00380 
00381     // debug; caller assumes ownership
00382     UInt8*
00383     CopyData(UInt8* dP, int numBytes)
00384     {
00385         UInt8* theCopy = new UInt8[numBytes];
00386         for (int i = 0; i < numBytes; i++)
00387             theCopy[i] = dP[i];
00388         return theCopy;
00389     }
00390 
00391     // debug; caller assumes ownership
00392     void
00393     MatchData(UInt8* dP, UInt8* dataCopy, int numBytes) const
00394     {
00395         for (int i = 0; i < numBytes; i++)
00396             if (dP[i] != dataCopy[i])
00397             {
00398                 ILOG_DEBUG("mismatch for i=" << i << " ; stored value=" << (int) dataCopy[i] << " and current value=" << (int) dP[i]);
00399                 break;
00400             }
00401     }
00402 
00407     virtual String
00408     CalcHash_protected() const
00409     {
00410         Array::Array2dVec3UInt8* arr =
00411             new Array::Array2dVec3UInt8(FrameWidth(), FrameHeight(), 0, 0,
00412                                  DataPtr(), true, false);
00413         String hash = Array::MD5Hash(arr);
00414         delete arr;
00415         return hash;
00416     }
00417 
00418     // Read data for frame mCurrentFrameNr
00419     virtual bool
00420     ReadFrameData() = 0;
00421 
00422     void
00423     Frame2Time(int frameNr, long& hour, long& minute, long& second,
00424                long& fraction) const
00425     {
00426         long numerator = GetTimeBaseNumerator();
00427         long denominator = GetTimeBaseDenominator();
00428         long totalFractions = frameNr * numerator;
00429         fraction = totalFractions % denominator;
00430         long totalSeconds = (totalFractions - fraction) / denominator;
00431         hour = totalSeconds / 3600;
00432         totalSeconds %= 3600;
00433         minute = totalSeconds / 60;
00434         second = totalSeconds % 60;
00435     }
00436 
00437     String
00438     FrameAsTimeString(int frameNr) const
00439     {
00440         if ((frameNr < 0) || (frameNr >= LASTFRAME_UNKNOWN))
00441             return "unknown";
00442         long hour, minute, second, fraction;
00443         Frame2Time(frameNr, hour, minute, second, fraction);
00444         return MakeString(hour) + ":" + MakeString(minute, 2, '0')
00445             + ":" + MakeString(second, 2, '0') + "."
00446             + MakeString(fraction);
00447     }
00448 
00449     virtual bool
00450     FrameValid(int frameNr) const
00451     {
00452         if (frameNr < mBlankFrames)
00453             return false;
00454 
00455         if (frameNr > mLastFrame)
00456             return false;
00457 
00458         return true;
00459     }
00460 
00461     void
00462     SetLeadingBadFrames(const int numberOfFrames)
00463     {
00464         mBlankFrames = numberOfFrames;
00465     }
00466 
00467 
00468     bool           mNewImpl; // for distinction between old and new impl
00469 
00470     int            mSrc;
00471     String         mSrcName;
00472     int            mFrameNr; //SK: deprecated
00473     int            mTargetFrameNr;
00474     int            mCurrentFrameNr;
00475     int            mFrameWidth;
00476     int            mFrameHeight;
00477     int            mLastFrame;
00478     UInt8*         mData;
00479     UInt8*         mDataOrig;
00480 
00482     //VideoInfo
00483     bool   mIndexExists;
00484     mutable bool mIsFrameAccurate;
00485     String mFormatName;
00486     String mFormatLName;
00487     String mCodecName;
00488     String mCodecTag;
00489     int    mFrameRateNum;
00490     int    mFrameRateDen;
00491     int    mTimeBaseNum;
00492     int    mTimeBaseDen;
00493     int    mAspectRatioNum;
00494     int    mAspectRatioDen;
00495     int    mGopSize;
00496     int    mBitRate;
00497     int    mStreamCount;
00498     UInt32 mBlankFrames; // i.e. number of leading bad frames; to be renamed mLeadingBadFrames
00499     Int64  mStartTime; // deprecated
00500     Int64  mEndTime;   // deprecated
00501     Int64  mDuration;
00502     Int64  mDurationSec;
00503     Int64  mDurationMin;
00504     Int64  mDurationHour;
00505     Int64  mVideoDuration; // duration of video stream in number of fractions
00506     double mVideoShiftSec; // deprecated
00508 
00509     ILOG_VAR_DECL;
00510 
00511 };
00512 
00513 ILOG_VAR_INIT(RgbDataSrc, Impala.Core.Stream);
00514 
00515 } // namespace Stream
00516 } // namespace Core
00517 } // namespace Impala
00518 
00519 #endif

Generated on Fri Mar 19 09:31:18 2010 for ImpalaSrc by  doxygen 1.5.1