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

Generated on Thu Jan 13 09:04:36 2011 for ImpalaSrc by  doxygen 1.5.1