libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd/progs video_play_source.cc


From: Edward Rosten
Subject: [libcvd-members] libcvd/progs video_play_source.cc
Date: Mon, 03 Oct 2011 15:12:34 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        11/10/03 15:12:34

Modified files:
        progs          : video_play_source.cc 

Log message:
        Pausing and frame-by frame stepping for video_play_source. Also 
rectangular
        texture fixes from Robert Castle.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/progs/video_play_source.cc?cvsroot=libcvd&r1=1.7&r2=1.8

Patches:
Index: video_play_source.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/progs/video_play_source.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- video_play_source.cc        6 Dec 2010 16:31:35 -0000       1.7
+++ video_play_source.cc        3 Oct 2011 15:12:33 -0000       1.8
@@ -44,6 +44,63 @@
 using namespace std;
 using namespace CVD;
 
+
+class Actions: public GLWindow::EventHandler
+{      
+       public:
+               int paused;
+               int advance_one;
+               int back_one;
+               int expose;
+               int quit;
+
+               Actions()
+               :paused(0),advance_one(0),expose(0),quit(0)
+               {}
+
+               void clear()
+               {
+                       advance_one=0;
+                       expose=0;
+                       back_one=0;
+               }
+
+               virtual void on_key_down(GLWindow&, int key)
+               {
+                       if(key == ' ' || key == 'p')
+                               paused = !paused;
+                       else if(key == '.')
+                       {
+                               advance_one=1;
+                               paused=1;
+                       }
+                       else if(key == ',')
+                       {
+                               back_one=1;
+                               paused=1;
+                       }
+               }
+
+               virtual void on_event(GLWindow&, int e)
+               {
+                       if(e == GLWindow::EVENT_EXPOSE)
+                               expose=1;
+                       else if(e == GLWindow::EVENT_CLOSE)
+                               quit=1;
+               }
+
+               virtual void on_resize(GLWindow&, ImageRef size)
+               {
+                       glViewport(0, 0, size.x, size.y);
+                       glMatrixMode(GL_PROJECTION);
+                       glLoadIdentity();
+                       glRasterPos2f(-1, 1);
+                       glOrtho(-0.375, size.x-0.375, size.y-0.375, -0.375, -1 
, 1); //offsets to make (0,0) the top left pixel (rather than off the display)
+               }
+
+};
+
+
 template<class C> void play(string s)
 {
        VideoBuffer<C> *buffer = open_video_source<C>(s);
@@ -51,9 +108,9 @@
        GLWindow display(buffer->size());
        glDrawBuffer(GL_BACK);
        
-       //while(buffer->frame_pending())
+       double dt = 1.001/buffer->frame_rate();
        
-       cout << "FPS: " << buffer->frame_rate() << endl;
+       cout << "FPS: " << buffer->frame_rate() << " " << dt << endl;
        cout << "Size: " << buffer->size() << endl;
 
        RawVideoBuffer* root = buffer->root_buffer();
@@ -67,29 +124,58 @@
                }
        #endif
 
+       GLenum texTarget;
+       #ifdef GL_TEXTURE_RECTANGLE_ARB
+       texTarget=GL_TEXTURE_RECTANGLE_ARB;
+       #else
+       #ifdef GL_TEXTURE_RECTANGLE_NV
+       texTarget=GL_TEXTURE_RECTANGLE_NV;
+       #else
+       texTarget=GL_TEXTURE_RECTANGLE_EXT;
+       #endif
+       #endif
+
+
+
+       VideoFrame<C>* frame=0;
        bool f=1;
        GLWindow::EventSummary e;
        glDisable(GL_BLEND);
-       glEnable(GL_TEXTURE_RECTANGLE_ARB);
+       glEnable(texTarget);
+       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+       glTexParameterf( texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+       glTexParameterf( texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+       glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+       bool new_frame=0;
+
+       Actions a;
+
        for(;;)
        {
-               display.get_events(e);
-               if(e.should_quit())
-                       break;
+               a.clear();
+               display.handle_events(a);
 
-               VideoFrame<C>* frame = buffer->get_frame();
+               if(a.quit)
+                       break;
 
-               glViewport(0, 0, display.size().x, display.size().y);
-               glMatrixMode(GL_PROJECTION);
-               glLoadIdentity();
-               glRasterPos2f(-1, 1);
-               glOrtho(-0.375, display.size().x-0.375, display.size().y-0.375, 
-0.375, -1 , 1); //offsets to make (0,0) the top left pixel (rather than off 
the display)
+               new_frame=0;
+               if(!a.paused || a.advance_one || a.back_one)
+               {
+                       if(a.back_one)
+                       {
+                               buffer->seek_to(frame->timestamp() - dt);
+                       }
 
-               glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-               glTexParameterf( GL_TEXTURE_RECTANGLE_NV, 
GL_TEXTURE_MIN_FILTER, GL_NEAREST );
-               glTexParameterf( GL_TEXTURE_RECTANGLE_NV, 
GL_TEXTURE_MAG_FILTER, GL_NEAREST );
-               glPixelStorei(GL_UNPACK_ALIGNMENT,1);
+                       if(frame)
+                               buffer->put_frame(frame);
+                       frame = buffer->get_frame();
+                       new_frame=1;
                glTexImage2D(*frame, 0, GL_TEXTURE_RECTANGLE_NV);
+               }
+               
+               if(a.expose || new_frame)
+               {
+                       cerr << a.expose << endl;
                glBegin(GL_QUADS);
                glTexCoord2i(0, 0);
                glVertex2i(0,0);
@@ -100,19 +186,23 @@
                glTexCoord2i(0, frame->size().y);
                glVertex2i(0, display.size().y);
                glEnd ();
-
+                       glFlush();
+                       display.swap_buffers();
+               }
 
                if(f)
                {
                        cout << "frame size: " << frame->size() << endl;
                        f=0;
                }
-               buffer->put_frame(frame);
-               glFlush();
 
-               display.swap_buffers();
+               if(a.paused)
+                       usleep(100000);
        }
 
+       if(frame)
+               buffer->put_frame(frame);
+
        cout << "Exiting\n";
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]