00001 #ifndef Impala_Core_VideoSet_IndexSegmentation_h
00002 #define Impala_Core_VideoSet_IndexSegmentation_h
00003
00004 #include "Persistency/SegmentationRepository.h"
00005 #include "Persistency/KeyframesRepository.h"
00006 #include "Persistency/Mpeg7DocRepository.h"
00007 #include "Core/VideoSet/Reporter.h"
00008 #include "Core/VideoSet/Segmentation.h"
00009 #include "Core/VideoSet/Keyframes.h"
00010 #include "Core/VideoSet/Mpeg7Doc.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace VideoSet
00017 {
00018
00019
00020 class IndexSegmentation : public Listener
00021 {
00022 public:
00023
00024 IndexSegmentation(Reporter* reporter, CmdOptions& options)
00025 {
00026 mReporter = reporter;
00027 }
00028
00029 virtual void
00030 HandleNewWalk(VideoSet* vs)
00031 {
00032 mSegmentation = new Segmentation(vs, "");
00033 mKeyframes = new Keyframes(vs, "");
00034 }
00035
00036 virtual void
00037 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00038 {
00039 if ((!src) || (src->FrameRateNum() < 0) || (src->FrameRateDen() < 0))
00040 {
00041 ILOG_ERROR("Need src with known frame rate");
00042 return;
00043 }
00044
00045 String container = vs->GetContainerFile(fileId);
00046 String name = vs->GetFileBase(fileId) + ".xml";
00047 const int MPEG7_SHOT = Persistency::Mpeg7DocLocator::MPEG7_SHOT;
00048 Persistency::Mpeg7DocLocator loc(vs->GetLocator(), MPEG7_SHOT,
00049 container, name);
00050 loc.SetFrameRateNum(src->FrameRateNum());
00051 loc.SetFrameRateDen(src->FrameRateDen());
00052 Mpeg7Doc* mp7 = Persistency::Mpeg7DocRepository().Get(loc);
00053 for (int s=0 ; s<mp7->NrShots() ; s++)
00054 {
00055 mSegmentation->Add(fileId, mp7->StartFrame(s), mp7->EndFrame(s),
00056 mp7->ShotName(s));
00057 int shotId = mSegmentation->Size() - 1;
00058 for (int k=0 ; k<mp7->NrKeyframes(s) ; k++)
00059 {
00060 String name = mp7->KeyframeName(s, k) + ".jpg";
00061 mKeyframes->Add(fileId, shotId, mp7->KeyframeFrame(s, k), name);
00062 }
00063 }
00064 delete mp7;
00065 }
00066
00067 virtual void
00068 HandleDoneWalk(VideoSet* vs)
00069 {
00070 bool binary = true;
00071 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00072 mSegmentation->Save("segmentation", binary);
00073 mKeyframes->Save("keyframes", binary);
00074 #else // REPOSITORY_USED
00075 Persistency::SegmentationLocator sLoc(vs->GetLocator(), "segmentation");
00076 Persistency::SegmentationRepository().Add(sLoc, mSegmentation);
00077 Persistency::KeyframesLocator kLoc(vs->GetLocator(), "keyframes");
00078 Persistency::KeyframesRepository().Add(kLoc, mKeyframes);
00079 #endif // REPOSITORY_USED
00080 mKeyframes->WriteImageSets();
00081 }
00082
00083 private:
00084
00085 Reporter* mReporter;
00086 Segmentation* mSegmentation;
00087 Keyframes* mKeyframes;
00088
00089 ILOG_VAR_DEC;
00090
00091 };
00092
00093 ILOG_VAR_INIT(IndexSegmentation, Impala.Core.VideoSet);
00094
00095 }
00096 }
00097 }
00098
00099 #endif