00001 #ifndef Impala_Core_VideoSet_VideoSet_h
00002 #define Impala_Core_VideoSet_VideoSet_h
00003
00004 #include <vector>
00005
00006 #include "Persistency/VideoSetsRepository.h"
00007 #include "Core/Stream/RgbDataSrcFactory.h"
00008 #include "Core/Array/Arrays.h"
00009 #include "Core/Database/RawDataSet.h"
00010 #include "Core/Array/ReadRaw.h"
00011 #include "Core/Array/WriteRaw.h"
00012 #include "Link/DiskImage/DiskImageFuncs.h"
00013
00014 namespace Impala
00015 {
00016 namespace Core
00017 {
00018 namespace VideoSet
00019 {
00020
00021
00022 class VideoSet : public Database::RawDataSet
00023 {
00024 public:
00025
00026 typedef Persistency::VideoSetsRepository VideoSetsRepository;
00027
00028 VideoSet(String setName) :
00029 Database::RawDataSet(setName),
00030 mSetId(-1)
00031 {
00032 mQuidClass = QUID_CLASS_FRAME;
00033 VideoSetsRepository::GetInstance().Register(this, GetSetName());
00034 }
00035
00036 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00037 VideoSet(Util::Database* db, String setName, bool readSet) :
00038 Database::RawDataSet
00039 (db, setName,
00040 readSet ? db->GetFilePath("VideoData", setName, false, false) : ""),
00041 mSetId(-1)
00042 {
00043 GenerateFileNames(".mpg");
00044 mQuidClass = QUID_CLASS_FRAME;
00045 VideoSetsRepository::GetInstance().Register(this, GetSetName());
00046 }
00047 #endif // REPOSITORY_USED
00048
00049 int
00050 GetSetId()
00051 {
00052 if (mSetId == -1)
00053 mSetId = VideoSetsRepository::GetInstance().GetId(GetSetName());
00054 return mSetId;
00055 }
00056
00057 Quid
00058 GetQuidVideo(int fileId, bool doIdLookup = false)
00059 {
00060 if (doIdLookup)
00061 fileId = GetFileId(fileId);
00062 return MakeQuidVideo(GetSetId(), fileId);
00063 }
00064
00065 Quid
00066 GetQuidFrame(int fileId, int frameNr, bool doIdLookup = false)
00067 {
00068 if (doIdLookup)
00069 fileId = GetFileId(fileId);
00070 return MakeQuidFrame(GetSetId(), fileId, frameNr);
00071 }
00072
00073 virtual String
00074 QuidToString(Quid quid, bool elaborate)
00075 {
00076 QuidObj qObj(quid);
00077 if (!elaborate)
00078 return qObj.ToString();
00079 String setName = "unknown";
00080 if ((qObj.Set() != 0) && (qObj.Set() == GetSetId()))
00081 setName = GetSetName();
00082 return "Q(" + QuidClassToString(qObj.Class()) + "," + setName + "," +
00083 GetFile(qObj.Object()) + "," +
00084 MakeString(qObj.Id()) + ")";
00085 }
00086
00087
00088
00089 String
00090 GetResolvedVideoPath(int fileId)
00091 {
00092 String path = FileNameConcat("VideoData", GetAsPath(fileId));
00093 typedef Persistency::RepositoryInFileSystem FS;
00094 Persistency::File file = FS::GetInstance().GetFile(GetLocator(), "",
00095 path, false, false);
00096 return file.GetPath();
00097 }
00098
00099 Stream::RgbDataSrc*
00100 GetVideoInLowResolution(int fileId, bool silent=false)
00101 {
00102 if ((fileId < 0) || (fileId >= NrFiles()))
00103 return 0;
00104
00105 String path = FileNameConcat("Frames", GetAsPath(fileId)) +
00106 "/" + "images_jpg.raw";
00107 #ifdef USE_IFILE
00108 path = "localfile:" + path;
00109 #endif
00110 CmdOptions& options = CmdOptions::GetInstance();
00111 String srcWndStr = options.GetString("srcWindow");
00112
00113 Stream::RgbDataSrcFactory& factory = Stream::RgbDataSrcFactory::Instance();
00114
00115 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00116 Stream::RgbDataSrc* src =
00117 factory.ConstructWindow(path, "raw", srcWndStr, mDb);
00118 #else // REPOSITORY_USED
00119
00120 typedef Persistency::RepositoryInFileSystem FS;
00121 Persistency::File file =
00122 FS::GetInstance().GetFile(GetLocator(), "", path, false, silent);
00123 Persistency::RgbDataSrcLocator loc(GetLocator(), file.GetPath());
00124 Stream::RgbDataSrc* src = factory.ConstructWindow(loc, "raw", srcWndStr);
00125 #endif // REPOSITORY_USED
00126
00127 if (!src || !src->Valid())
00128 {
00129 if (!silent)
00130 ILOG_ERROR("Failed at initializing low res video data source");
00131 if (src)
00132 delete src;
00133 return 0;
00134 }
00135
00136 return src;
00137 }
00138
00139 Stream::RgbDataSrc*
00140 GetVideo(int fileId)
00141 {
00142 if ((fileId < 0) || (fileId >= NrFiles()))
00143 return 0;
00144
00145 String dirOfFile = GetDirOfFile(fileId);
00146 String path;
00147
00148 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00149 if (Link::DiskImage::DiskImageUsed() &&
00150 dirOfFile.find("//#") != String::npos)
00151 {
00152 String imagePath = mDb->GetFilePath(GetSectionOfFile(fileId),
00153 false, false);
00154 if (imagePath.empty())
00155 {
00156 ILOG_ERROR("disk image file not found");
00157 return 0;
00158 }
00159 path = "diskimage:" + imagePath + ':' + GetDirOfFile(fileId) + '/'
00160 + GetFileOrDir(fileId, ".mpg");
00161 }
00162 else
00163 {
00164 path = mDb->GetFilePath("VideoData", GetSectionOfFile(fileId),
00165 dirOfFile,
00166 GetFileOrDir(fileId, ".mpg"), false,
00167 false);
00168 }
00169 #else // REPOSITORY_USED
00170 path = FileNameConcat("VideoData", GetAsPath(fileId));
00171 #endif // REPOSITORY_USED
00172
00173 CmdOptions& options = CmdOptions::GetInstance();
00174
00175 #ifdef USE_IFILE
00176 path = "localfile:" + path;
00177 #endif
00178
00179 Stream::RgbDataSrcFactory& factory =
00180 Stream::RgbDataSrcFactory::Instance();
00181 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00182 Stream::RgbDataSrc* src =
00183 factory.ConstructWindow(path, options.GetString("src"),
00184 options.GetString("srcWindow"), mDb);
00185 #else // REPOSITORY_USED
00186
00187 typedef Persistency::RepositoryInFileSystem FS;
00188 Persistency::File file = FS::GetInstance().GetFile(GetLocator(), "",
00189 path, false, false);
00190
00191 Persistency::RgbDataSrcLocator loc(GetLocator(), file.GetPath());
00192 Stream::RgbDataSrc* src =
00193 factory.ConstructWindow(loc, options.GetString("src"),
00194 options.GetString("srcWindow"));
00195 #endif // REPOSITORY_USED
00196
00197 if (!src || !src->Valid())
00198 {
00199 ILOG_ERROR("Failed at initializing data source");
00200 if (src)
00201 delete src;
00202 return 0;
00203 }
00204
00205 return src;
00206 }
00207
00208
00209
00210 void
00211 DeleteVideoInfoFile(int fileId)
00212 {
00213 if ((fileId < 0) || (fileId >= NrFiles()))
00214 return;
00215
00216 String path = FileNameConcat("VideoData", GetAsPath(fileId) + ".info");
00217 typedef Persistency::RepositoryInFileSystem FS;
00218 Persistency::File file = FS::GetInstance().GetFile(GetLocator(), "",
00219 path, true, true);
00220 file.Delete();
00221 }
00222
00223 int
00224 Diff(VideoSet* arg)
00225 {
00226 if (NrFiles() != arg->NrFiles())
00227 {
00228 ILOG_ERROR("Diff: nrFiles differs: " << NrFiles() << " vs " <<
00229 arg->NrFiles());
00230 return 1;
00231 }
00232 int nDiff = 0;
00233 for (int i=0 ; i<NrFiles() ; i++)
00234 {
00235 if (GetAsPath(i) != arg->GetAsPath(i))
00236 {
00237 ILOG_DEBUG("File " << i << " differs " << GetAsPath(i) <<
00238 " vs " << arg->GetAsPath(i));
00239 nDiff++;
00240 }
00241 else if (GetQuidVideo(i, false) != arg->GetQuidVideo(i, false))
00242 {
00243 ILOG_DEBUG("Quid " << i << " differs " << GetQuidVideo(i, false)
00244 << " vs " << arg->GetQuidVideo(i, false));
00245 nDiff++;
00246 }
00247 }
00248 if (nDiff > 0)
00249 ILOG_ERROR("Found " << nDiff << " differences");
00250 return nDiff;
00251 }
00252
00253
00254
00255 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00256 void
00257 SaveVideoSet()
00258 {
00259 Save(GetFilePathVideoData(mSetName, true, false));
00260 }
00261
00262 void
00263 UpdateVideoSet()
00264 {
00265 String fName = GetFilePathVideoData(mSetName, true, true);
00266 if (fName.empty())
00267 fName = GetFilePathVideoData(mSetName, false, false);
00268 Save(fName);
00269 }
00270 #endif // REPOSITORY_USED
00271
00272 private:
00273
00274 int mSetId;
00275
00276 ILOG_VAR_DEC;
00277 };
00278
00279 ILOG_VAR_INIT(VideoSet, Impala.Core.VideoSet);
00280
00281 }
00282 }
00283 }
00284
00285 #endif