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 GetVideo(int fileId)
00101 {
00102 if ((fileId < 0) || (fileId >= NrFiles()))
00103 return 0;
00104
00105 String dirOfFile = GetDirOfFile(fileId);
00106 String path;
00107
00108 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00109 if (Link::DiskImage::DiskImageUsed() &&
00110 dirOfFile.find("//#") != String::npos)
00111 {
00112 String imagePath = mDb->GetFilePath(GetSectionOfFile(fileId),
00113 false, false);
00114 if (imagePath.empty())
00115 {
00116 ILOG_ERROR("disk image file not found");
00117 return 0;
00118 }
00119 path = "diskimage:" + imagePath + ':' + GetDirOfFile(fileId) + '/'
00120 + GetFileOrDir(fileId, ".mpg");
00121 }
00122 else
00123 {
00124 path = mDb->GetFilePath("VideoData", GetSectionOfFile(fileId),
00125 dirOfFile,
00126 GetFileOrDir(fileId, ".mpg"), false,
00127 false);
00128 }
00129 #else // REPOSITORY_USED
00130 path = FileNameConcat("VideoData", GetAsPath(fileId));
00131 #endif // REPOSITORY_USED
00132
00133 CmdOptions& options = CmdOptions::GetInstance();
00134
00135 #ifdef USE_IFILE
00136 path = "localfile:" + path;
00137 #endif
00138
00139 Stream::RgbDataSrcFactory& factory =
00140 Stream::RgbDataSrcFactory::Instance();
00141 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00142 Stream::RgbDataSrc* src =
00143 factory.ConstructWindow(path, options.GetString("src"),
00144 options.GetString("srcWindow"), mDb);
00145 #else // REPOSITORY_USED
00146
00147 typedef Persistency::RepositoryInFileSystem FS;
00148 Persistency::File file = FS::GetInstance().GetFile(GetLocator(), "",
00149 path, false, false);
00150
00151 Persistency::RgbDataSrcLocator loc(GetLocator(), file.GetPath());
00152 Stream::RgbDataSrc* src =
00153 factory.ConstructWindow(loc, options.GetString("src"),
00154 options.GetString("srcWindow"));
00155 #endif // REPOSITORY_USED
00156
00157 if (!src || !src->Valid())
00158 {
00159 ILOG_ERROR("Failed at initializing data source");
00160 if (src)
00161 delete src;
00162 return 0;
00163 }
00164
00165 return src;
00166 }
00167
00168 int
00169 Diff(VideoSet* arg)
00170 {
00171 if (NrFiles() != arg->NrFiles())
00172 {
00173 ILOG_ERROR("Diff: nrFiles differs: " << NrFiles() << " vs " <<
00174 arg->NrFiles());
00175 return 1;
00176 }
00177 int nDiff = 0;
00178 for (int i=0 ; i<NrFiles() ; i++)
00179 {
00180 if (GetAsPath(i) != arg->GetAsPath(i))
00181 {
00182 ILOG_DEBUG("File " << i << " differs " << GetAsPath(i) <<
00183 " vs " << arg->GetAsPath(i));
00184 nDiff++;
00185 }
00186 else if (GetQuidVideo(i, false) != arg->GetQuidVideo(i, false))
00187 {
00188 ILOG_DEBUG("Quid " << i << " differs " << GetQuidVideo(i, false)
00189 << " vs " << arg->GetQuidVideo(i, false));
00190 nDiff++;
00191 }
00192 }
00193 if (nDiff > 0)
00194 ILOG_ERROR("Found " << nDiff << " differences");
00195 return nDiff;
00196 }
00197
00198
00199
00200 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00201 void
00202 SaveVideoSet()
00203 {
00204 Save(GetFilePathVideoData(mSetName, true, false));
00205 }
00206
00207 void
00208 UpdateVideoSet()
00209 {
00210 String fName = GetFilePathVideoData(mSetName, true, true);
00211 if (fName.empty())
00212 fName = GetFilePathVideoData(mSetName, false, false);
00213 Save(fName);
00214 }
00215 #endif // REPOSITORY_USED
00216
00217 private:
00218
00219 int mSetId;
00220
00221 ILOG_VAR_DEC;
00222 };
00223
00224 ILOG_VAR_INIT(VideoSet, Impala.Core.VideoSet);
00225
00226 }
00227 }
00228 }
00229
00230 #endif