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

NfiSixView.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #ifndef Impala_Application_IDash_NfiSixView_h
00003 #define Impala_Application_IDash_NfiSixView_h
00004 
00005 #include "Visualization/VideoPlayer.h"
00006 #include "Core/VideoSet/VideoSet.h"
00007 
00008 namespace Impala {
00009 namespace Application {
00010 namespace IDash {
00011 
00012 class NfiSixView : public OglGui::Window,
00013                    public Visualization::VideoPlayerListener
00014 {
00015     typedef Impala::Visualization::VideoPlayer          VideoPlayer;
00016     typedef Impala::Visualization::VideoPlayerListener  VideoPlayerListener;
00017     typedef Impala::Core::Stream::RgbDataSrc            RgbDataSrc;
00018 
00019 public:
00020     NfiSixView(OglGui::Window *parent, int x, int y, int w, int h) :
00021       OglGui::Window(parent, x, y, w, h)
00022     {
00023         Init(w,h);
00024     }
00025 
00026     void SetVideo(Core::VideoSet::VideoSet *vset, int id) 
00027     {
00028         mVideoSet = vset;
00029         mVideoID = id;
00030     }
00031 
00032     void ClearVideos()
00033     {
00034         for (int p=0; p<6; p++)
00035             mPlayers[p]->OpenVideo(0);
00036     }
00037 
00038     bool OpenVideo()
00039     {
00040         int lastFrameNr = -1;
00041 
00042         ClearVideos();
00043 
00044         for (int i = 0; i < 6; i++)
00045         {
00046             int playerIndex = i + ((i>2) ? -3 : 3);
00047             VideoPlayer* player = mPlayers[playerIndex];
00048             RgbDataSrc* rgbDataSrc = mVideoSet->GetVideo(mVideoID);
00049             if (!CheckRgbValidity(rgbDataSrc))
00050                 return false;
00051             //SK
00052             try
00053             {
00054                 player->OpenVideo(rgbDataSrc,lastFrameNr,6,i);
00055             }
00056             catch (std::exception e)
00057             {
00058                 ILOG_WARNING("Reading from RgbDataSrc faltered: Can't play");
00059                 ClearVideos();
00060                 return false;
00061             }
00062             //SK
00063             if (lastFrameNr < 0)
00064                 lastFrameNr = player->LastFrameNr();
00065         }
00066         return true;
00067     }
00068 
00069     VideoPlayer* GetVideoPlayer(int n)
00070     {
00071         if (n<0 || n>5) return 0;
00072         return mPlayers[n];
00073     }
00074 
00075     void SetLoopVideo(bool value)
00076     {
00077         for (int i = 0; i < 6; i++)
00078             mPlayers[i]->SetLoopVideo(value);
00079     }
00080 
00081     bool GetLoopVideo()
00082     {
00083         return mPlayers[0]->GetLoopVideo();
00084     }
00085 
00086     void TogglePause()
00087     {
00088         if (mPlayers[0]->Playing())
00089             Stop();
00090         else
00091             Play();
00092     }
00093 
00094     void DoNormalSpeed(bool val)
00095     {
00096         for (int i = 0; i < 6; i++)
00097             mPlayers[i]->NormalSpeed(val);
00098     }
00099 
00100     void Play()
00101     {
00102         for (int i = 0; i < 6; i++)
00103             mPlayers[i]->Play();
00104     }
00105 
00106     void Stop()
00107     {
00108         for (int i = 0; i < 6; i++)
00109             mPlayers[i]->Stop();
00110     }
00111 
00112     void Rewind()
00113     {
00114         for (int i = 0; i < 6; i++)
00115             mPlayers[i]->Rewind();
00116     }
00117 
00118     void FFwd()
00119     {
00120         for (int i = 0; i < 6; i++)
00121             mPlayers[i]->FFwd();
00122     }
00123 
00124     void FBwd()
00125     {
00126         for (int i = 0; i < 6; i++)
00127             mPlayers[i]->FBwd();
00128     }
00129 
00130     void NextFrame(int inc=1)
00131     {
00132         for (int i = 0; i < 6; i++)
00133             mPlayers[i]->NextFrame(inc);
00134     }
00135 
00136     virtual void OnKey(VideoPlayer *src, int c, int state, void* userData)
00137     {
00138         if (c == ' ')
00139             TogglePause();
00140         if (c == oglDOWN) // normal speed
00141             DoNormalSpeed(true);
00142         else if (c == oglUP) // fast
00143             DoNormalSpeed(false);
00144         else if (c == 'p') // play
00145             Play();
00146         else if (c == 's') // stop
00147             Stop();
00148     }
00149 
00150     virtual void ReshapeFunc(int w, int h)
00151     {
00152        for (int i=0; i<6; i++)
00153         mPlayers[i]->SetDimensions(i%3 * w/3, i/3 * h/2, w/3, h/2);
00154     }
00155 
00156 protected:
00157     bool CheckRgbValidity(RgbDataSrc* rgb)
00158     {
00159         if (!rgb || !rgb->Valid() || !rgb->HasIndex())
00160         {
00161             ILOG_WARNING("RgbDataSrc invalid or no Index: Can't play");
00162             if (rgb) delete rgb;
00163             return false;
00164         }
00165         return true;
00166     }
00167 
00168 private:
00169     void Init(int w, int h)
00170     {
00171         for (int i=0; i<6; i++)
00172         {
00173             mPlayers[i] = new VideoPlayer(this,i%3*w/3,i/3*h/2,w/3,h/2,"","");
00174             mPlayers[i]->NormalSpeed(true);
00175             mPlayers[i]->Play();
00176             mPlayers[i]->SetVideoPlayerListener(this,i);
00177             mPlayers[i]->ShowFrameNr(true);
00178         }
00179         mVideoID = 0;
00180     }
00181 
00182     Core::VideoSet::VideoSet*   mVideoSet;
00183     VideoPlayer*                mPlayers[6];
00184     int                         mVideoID;
00185 
00186     ILOG_VAR_DEC;
00187 };
00188 
00189 ILOG_VAR_INIT(NfiSixView, Application.IDash);
00190 
00191 
00192 }
00193 }
00194 }
00195 
00196 #endif

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