00001
00002
00003
00004 #ifndef Impala_Visualization_VideoTimeLine_h
00005 #define Impala_Visualization_VideoTimeLine_h
00006
00007 #include "Core/Stream/RgbDataSrcFactory.h"
00008
00009 #include "OglGui/TitledWindow.h"
00010 #include "OglGui/WindowDocScroller.h"
00011
00012 #include "Visualization/VideoPlayerWithButtons.h"
00013 #include "Visualization/TimeLineViewStrip.h"
00014
00015
00016 namespace Impala {
00017 namespace Visualization {
00018
00019
00020
00021 class VideoTimeLine : public OglGui::Window,
00022 public OglGui::WindowTimeLineListener,
00023 public VideoPlayerListener
00024 {
00025 public:
00026 typedef OglGui::Window Window;
00027 typedef OglGui::StaticText StaticText;
00028 typedef OglGui::TitledWindow TitledWindow;
00029 typedef OglGui::WindowDocScroller WindowDocScroller;
00030 typedef OglGui::WindowTimeLine WindowTimeLine;
00031 typedef OglGui::WindowTimeLineListener WindowTimeLineListener;
00032 typedef Impala::Core::Stream::RgbDataSrcFactory RgbDataSrcFactory;
00033 typedef Impala::Core::Stream::RgbDataSrc RgbDataSrc;
00034
00035 VideoTimeLine(int x, int y, int w, int h) :
00036 Window(x, y, w, h)
00037 {
00038 Init(w,h);
00039 }
00040
00041 VideoTimeLine(Window* parent, int w, int h) :
00042 Window(parent, w, h)
00043 {
00044 Init(w,h);
00045 }
00046
00047 VideoTimeLine(Window* parent,int x,int y,int w,int h):
00048 Window(parent, x, y, w, h)
00049 {
00050 Init(w,h);
00051 }
00052
00053 void OpenVideo(String videoName, strconst videoType)
00054 {
00055 RgbDataSrc* videoRgb = VideoPlayer::Construct(videoName, videoType);
00056 RgbDataSrc* stripRgb = VideoPlayer::Construct(videoName, videoType);
00057 OpenVideo(videoName, videoRgb, stripRgb);
00058 }
00059
00060 void
00061 OpenVideo(String videoName, RgbDataSrc* vidRgb, RgbDataSrc* stripRgb)
00062 {
00063 ShowTitle(videoName);
00064 mVideoPlayer->OpenVideo(vidRgb);
00065 mTLineViewStrip->ViewStripRgbDataSrc(stripRgb);
00066 if (vidRgb && stripRgb)
00067 HandleNewVideo();
00068 }
00069
00070 virtual void HandleNewVideo()
00071 {
00072 mVideoPlayer->Reset();
00073 HandleFrameSettings();
00074 }
00075
00076 virtual void HandleFrameSettings()
00077 {
00078 int nFrames = mVideoPlayer->LastFrame();
00079 int imW = mVideoPlayer->DataSrc()->FrameWidth();
00080 if (mTLineViewStrip->ViewStripRgbSrc())
00081 imW = mTLineViewStrip->ViewStripRgbSrc()->FrameWidth();
00082 mTLineViewStrip->Current(0);
00083 mTLineViewStrip->SetSpan(40*nFrames);
00084 mTLineViewStrip->SetMinMaxDocWidth(160, nFrames*imW);
00085 mTLineViewStrip->DocW(nFrames*4);
00086
00087 mTimeLineRuler->SetSpan(40*nFrames);
00088 }
00089
00090 void ShowTitle(strconst videoName)
00091 {
00092 if (!videoName.empty())
00093 {
00094 std::string name = FileNameTail(videoName);
00095 mTitledVideoPlayer->TitleText()->SetText(name);
00096 }
00097 }
00098
00099
00100 virtual void CurrentChanged(WindowTimeLine *src, long nVal, void* userData)
00101 {
00102 VideoPlayer* vP = (VideoPlayer*) userData;
00103 int nFrame = (int) floor((nVal / 40.)+0.5);
00104 if (nFrame != vP->FrameNr())
00105 vP->GotoFrame(nFrame);
00106 else
00107 {
00108 mTLineViewStrip->Current(nFrame*40);
00109 mTimeLineRuler->Current(nFrame*40);
00110 }
00111 }
00112
00113 virtual void
00114 OnNewFrame(VideoPlayer *src, int frameNr, void* userData)
00115 {
00116 mTimeLineRuler->Current(frameNr*40);
00117 mTLineViewStrip->Current(frameNr*40);
00118 HandleVisibility(mTLineViewStrip);
00119 }
00120
00121 void HandleVisibility(TimeLineViewStrip* tLineViewStrip)
00122 {
00123 if (!tLineViewStrip->IsDragging() &&
00124 (mCenterNeedle || (mVideoPlayer->Playing() && mCenterNeedleOnPlay)))
00125 tLineViewStrip->ShowCurrentAt(tLineViewStrip->W()/2);
00126 else
00127 tLineViewStrip->MakeCurrentVisible();
00128 }
00129
00130
00132
00133 void CenterNeedleOnPlay(bool mode) { mCenterNeedleOnPlay = mode; }
00134 bool CenterNeedleOnPlay() { return mCenterNeedleOnPlay; }
00135
00136 void CenterNeedle(bool mode) { mCenterNeedle = mode; }
00137 bool CenterNeedle() { return mCenterNeedle; }
00138
00139
00141
00142 TitledWindow* TitledVideoPlayer() {return mTitledVideoPlayer;}
00143 TitledWindow* TitledTimeLine() {return mTitledTimeLine;}
00144 TimeLineViewStrip* TLineViewStrip() {return mTLineViewStrip;}
00145 VideoPlayer* VidPlayer() {return mVideoPlayer;}
00146 WindowTimeLine* TimeLineRuler() {return mTimeLineRuler;}
00147 WindowDocScroller* ViewStripScroller() {return mViewStripScroller;}
00148 StaticText* FrameNrTxt() {return mFrameNrTxt;}
00149
00150 VideoPlayerWithButtons* VideoPlayerWithBtns() {return mVideoPlayerWithBtns;}
00151
00153
00154 virtual void DisplayFunc()
00155 {
00156 mTimeLineRuler->DocX(5);
00157 mTimeLineRuler->DocW(mTimeLineRuler->W()-10);
00158 if (mCenterNeedle)
00159 HandleVisibility(mTLineViewStrip);
00160 Window::DisplayFunc();
00161 }
00162
00163 private:
00164 void Init(int w, int h)
00165 {
00166 int vpH = 288 + 32 + 8;
00167
00168 mTitledVideoPlayer = new TitledWindow(this,4,4,352+8,vpH+32,"");
00169 Window* pane = mTitledVideoPlayer->ContentPane();
00170 int paneW = pane->W();
00171 int paneH = pane->H();
00172
00173 mVideoPlayerWithBtns = new VideoPlayerWithButtons(pane,0,0,paneW,paneH);
00174 mVideoPlayerWithBtns->ConnectTo(pane);
00175 mVideoPlayer = mVideoPlayerWithBtns->Player();
00176 mVideoPlayer->NormalSpeed(true);
00177
00178 Window* videoTitle = mTitledVideoPlayer->TitleText();
00179 mFrameNrTxt = new StaticText(videoTitle,paneW-90,2,60,20, "");
00180 mFrameNrTxt->SetAlign(oglLeftAlign,oglCenterAlign);
00181 mFrameNrTxt->ConnectTo(videoTitle,OglGui::TORIGHT);
00182
00183 mTitledTimeLine = new TitledWindow(this,368,4,w-372,vpH+32,"TimeLine");
00184 pane = mTitledTimeLine->ContentPane();
00185 paneW = pane->W();
00186 paneH = pane->H();
00187
00188 mTimeLineRuler = new WindowTimeLine(pane,0,paneH-32,paneW,30);
00189 mTimeLineRuler->ConnectTo(pane,OglGui::TOLEFTRIGHT | OglGui::TOTOP);
00190 mTimeLineRuler->SetListener(this, (void*) mVideoPlayer);
00191 mTimeLineRuler->SetBorderType(BEV_ETCHED);
00192 mTimeLineRuler->SetBorderFillShaded(2);
00193 mTimeLineRuler->ShowNeedle(true);
00194 mTimeLineRuler->SetNeedleUpDownHeight(100,100);
00195 mTimeLineRuler->SetNeedleColor(oglRED);
00196
00197 mViewStripScroller = new WindowDocScroller(pane,0,0,paneW,paneH-34,1);
00198 mViewStripScroller->ConnectTo(pane);
00199 mTLineViewStrip =
00200 new TimeLineViewStrip(mViewStripScroller,0,16,paneW,paneH-50,600);
00201 mViewStripScroller->SetDocWindow(mTLineViewStrip,mTLineViewStrip,true);
00202
00203 mTLineViewStrip->SetBorderType(-1);
00204 mTLineViewStrip->SetListener(this, (void *) mVideoPlayer);
00205 mTLineViewStrip->CurrentViewOnTop(2);
00206 mVideoPlayer->SetVideoPlayerListener(this,0);
00207
00208 mCenterNeedle = true;
00209 mCenterNeedleOnPlay = true;
00210 }
00211
00212 TitledWindow* mTitledVideoPlayer;
00213 TitledWindow* mTitledTimeLine;
00214 TimeLineViewStrip* mTLineViewStrip;
00215 VideoPlayer* mVideoPlayer;
00216 VideoPlayerWithButtons* mVideoPlayerWithBtns;
00217 WindowTimeLine* mTimeLineRuler;
00218 WindowDocScroller* mViewStripScroller;
00219 StaticText* mFrameNrTxt;
00220
00221 bool mCenterNeedleOnPlay;
00222 bool mCenterNeedle;
00223
00224 ILOG_VAR_DEC;
00225 };
00226
00227 ILOG_VAR_INIT(VideoTimeLine, Visualization);
00228
00229 }
00230 }
00231 #endif
00232