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

RgbDataSrcKeyframes.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Stream_RgbDataSrcKeyframes_h
00002 #define Impala_Core_Stream_RgbDataSrcKeyframes_h
00003 
00004 #include "Persistency/ImageArchiveRepository.h"
00005 #include "Persistency/FrameRepository.h"
00006 #include "Util/ChannelPool.h"
00007 #include "Core/Stream/RgbDataSrc.h"
00008 #include "Core/VideoSet/Keyframes.h"
00009 #include "Core/Array/ImageArchiveFile.h"
00010 
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace VideoSet
00016 {
00017 
00018 
00019 class RgbDataSrcKeyframes : public Stream::RgbDataSrc
00020 {
00021 public:
00022 
00023     RgbDataSrcKeyframes(VideoSet* videoSet, Keyframes* keyframes, int videoId)
00024         : RgbDataSrc(-1, videoSet->GetFile(videoId))
00025     {
00026         mVideoSet = videoSet;
00027         mKeyframes = keyframes;
00028         mVideoId = videoId;
00029         mUseFileArchive = false;
00030         mCurIm = 0;
00031         mArchive = 0;
00032 
00033 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00034         String fName = mVideoSet->GetFilePathFrames(mVideoId, "images.raw",
00035                                                     false, true);
00036         if (!fName.empty())
00037         {
00038             mUseFileArchive = true;
00039             mArchive = new Array::ImageArchiveFile(fName, false,
00040                                                    mVideoSet->GetDatabase());
00041         }
00042 #else // REPOSITORY_USED
00043         String container = mVideoSet->GetContainerFile(mVideoId);
00044         Persistency::ImageArchiveLocator loc(mVideoSet->GetLocator(), true,
00045                                              container, "images.raw", 0);
00046         mArchive = Persistency::ImageArchiveRepository().Get(loc);
00047         if (mArchive)
00048             mUseFileArchive = true;
00049 #endif // REPOSITORY_USED
00050 
00051         int firstK = mKeyframes->GetFirstKeyframeVideo(videoId);
00052         Array::Array2dVec3UInt8* im = ReadImage(mKeyframes->GetFrameNr(firstK));
00053         if (im == 0)
00054         {
00055             ILOG_ERROR("Unable to read image");
00056             return;
00057         }
00058         // this only works in case all images have the same size
00059         mFrameWidth = im->CW();
00060         mFrameHeight = im->CH();
00061         int lastKey = firstK + mKeyframes->GetNrKeyframesVideo(videoId) - 1;
00062         mLastFrame = mKeyframes->GetFrameNr(lastKey);
00063         delete im;
00064     }
00065 
00066     virtual
00067     ~RgbDataSrcKeyframes()
00068     {
00069         if (mCurIm)
00070             delete mCurIm;
00071         if (mArchive)
00072             delete mArchive;
00073     }
00074 
00075     virtual bool
00076     Valid() const
00077     {
00078         return (mKeyframes != 0) && mArchive->Valid();
00079     }
00080 
00081     String
00082     GetKeyframeName()
00083     {
00084         int key = mKeyframes->GetFrameIdVideo(mVideoId, mFrameNr);
00085         return mKeyframes->GetName(key);
00086     }
00087 
00088 protected:
00089 
00090     bool
00091     ReadFrameData()
00092     {
00093         if (mCurIm)
00094             delete mCurIm;
00095         mCurIm = ReadImage(FrameNr());
00096         if (!mCurIm)
00097         {
00098             ILOG_ERROR("unable to read frame " << FrameNr());
00099             return false;
00100         }
00101         mData = mCurIm->CPB();
00102         return true;
00103     }
00104 
00105     Array::Array2dVec3UInt8*
00106     ReadImage(int frameNr)
00107     {
00108         Array::Array2dVec3UInt8* im = 0;
00109         if (mUseFileArchive)
00110         {
00111             int firstK = mKeyframes->GetFirstKeyframeVideo(mVideoId);
00112             int key = mKeyframes->GetFrameIdVideo(mVideoId, frameNr);
00113             im = mArchive->ReadImage(key - firstK);
00114         }
00115         else
00116         {
00117 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00118             String fName = mVideoSet->GetFilePathFrames(mVideoId, frameNr,
00119                                                         ".png", false, false);
00120             Array::ReadPng(im, fName, mVideoSet->GetDatabase());
00121 #else // REPOSITORY_USED
00122             Persistency::FrameLocator loc(mVideoSet->GetLocator(),
00123                                           mVideoSet->GetContainerFile(mVideoId),
00124                                           frameNr, ".png");
00125             im = Persistency::FrameRepository().Get(loc);
00126 #endif // REPOSITORY_USED
00127         }
00128         return im;
00129     }
00130 
00131 private:
00132 
00133     VideoSet*                mVideoSet;
00134     Keyframes*               mKeyframes;
00135     int                      mVideoId;
00136     bool                     mUseFileArchive;
00137     Array::Array2dVec3UInt8* mCurIm;
00138 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00139     Array::ImageArchiveFile* mArchive;
00140 #else // REPOSITORY_USED
00141     Array::ImageArchive*     mArchive;
00142 #endif // REPOSITORY_USED
00143 
00144     ILOG_VAR_DEC;
00145 };
00146 
00147 ILOG_VAR_INIT(RgbDataSrcKeyframes, Impala.Core.VideoSet);
00148 
00149 } // namespace VideoSet
00150 } // namespace Core
00151 } // namespace Impala
00152 
00153 #endif

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