change to fixed rate refresh stratigy for vicons
authorGood Guy <[email protected]>
Sat, 19 Dec 2015 03:06:36 +0000 (20:06 -0700)
committerGood Guy <[email protected]>
Sat, 19 Dec 2015 03:06:36 +0000 (20:06 -0700)
cinelerra-5.0/cinelerra/awindowgui.C
cinelerra-5.0/cinelerra/ffmpeg.C
cinelerra-5.0/guicast/vicon.C

index 3e351957ae83b13d87fe3fd29feb8c72b8d8a3f1..d2a87597e9ea8a0b260aed35212b6a353c65a20b 100644 (file)
@@ -90,12 +90,12 @@ VFrame *AssetVIcon::frame()
                }
                if( !temp )
                        temp = new VFrame(asset->width, asset->height, BC_RGB888);
-               file->set_layer(0);
-               int64_t pos = seq_no / picon->gui->vicon_thread->refresh_rate * frame_rate;
-               file->set_video_position(pos,0);
                int ww = picon->gui->vicon_thread->view_w;
                int hh = picon->gui->vicon_thread->view_h;
                while( seq_no >= images.size() ) {
+                       file->set_layer(0);
+                       int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
+                       file->set_video_position(pos,0);
                        file->read_frame(temp);
                        add_image(temp, ww, hh, BC_RGB8);
                }
@@ -262,10 +262,11 @@ void AssetPicon::create_objects()
                                        icon_vframe->transfer_from(gui->temp_picon);
 // vicon images
                                        double framerate = asset->get_frame_rate();
-                                       if( !framerate ) framerate = 24;
-                                       int64_t length = framerate * 5;
-                                       int64_t vframes = asset->get_video_frames();
-                                       if( length > vframes ) length = vframes;
+                                       if( !framerate ) framerate = VICON_RATE;
+                                       int64_t frames = asset->get_video_frames();
+                                       double secs = frames / framerate;
+                                       if( secs > 5 ) secs = 5;
+                                       int64_t length = secs * gui->vicon_thread->refresh_rate;
                                        vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
                                        gui->vicon_thread->add_vicon(vicon);
                                        if(debug) printf("AssetPicon::create_objects %d\n", __LINE__);
index 4b585eaa531faed284d8740b781273ae28d0751e..120a75d61368ba62d63a6111879078e05e999be1 100644 (file)
@@ -746,7 +746,7 @@ int FFVideoStream::load(VFrame *vframe, int64_t pos)
                ret = read_frame(frame);
                if( ret > 0 ) ++curr_pos;
        }
-       if( ret > 0 ) {
+       if( ret >= 0 ) {
                AVCodecContext *ctx = st->codec;
                ret = convert_cmodel(vframe, (AVPicture *)frame,
                        ctx->pix_fmt, ctx->width, ctx->height);
index 428ed4c70ccfcf3b0abaccaeb94f016cb4388b6e..906fb6e938556377af762768e82dd8cd9428a823 100644 (file)
@@ -262,49 +262,51 @@ run()
                draw_lock->lock("VIconThread::run 0");
                if( done ) break;;
                wdw->lock_window("BC_WindowBase::run 1");
-               reset_images();
                interrupted = 0;
                drawing_started();
-               int64_t draw_flash = 0;
-               VIcon *first = 0;
+               reset_images();
+               int64_t seq_no = 0, now = 0;
+               int64_t draw_flash = 1000 / refresh_rate;
                while( !interrupted ) {
                        if( viewing != vicon )
                                update_view();
                        VIcon *next = low_vicon();
-                       if( !next ) break;
-                       int64_t now = timer->get_difference();
-                       if( next == first || (draw_flash && now >= draw_flash) ) {
+                       while( next && next->age < draw_flash ) {
+                               now = timer->get_difference();
+                               if( now >= draw_flash ) break;
+                               draw(next);
+                               if( !next->seq_no ) next->cycle_start = now;
+                               int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate;
+                               int count = ref_no - next->seq_no;
+                               if( count < 1 ) count = 1;
+                               ref_no = next->seq_no + count;
+                               next->age =  next->cycle_start + 1000. * ref_no / refresh_rate;
+                               if( !next->set_seq_no(ref_no) )
+                                       next->age = now + 1000.;
                                add_vicon(next);
-                               if( !draw_flash ) draw_flash = now + 100;
-                               else if( now >= draw_flash ) draw_flash = now + 1; 
-                               wdw->unlock_window();
-                               while( !interrupted ) {
-                                       now = timer->get_difference();
-                                       int64_t ms = draw_flash - now;
-                                       if( ms <= 0 ) break;
-                                       if( ms > 100 ) ms = 100;
-                                       Timer::delay(ms);
-                               }
-                               wdw->lock_window("BC_WindowBase::run 2");
+                               next = low_vicon();
+                       }
+                       if( !next ) break;
+                       add_vicon(next);
+                       if( draw_flash < now+1 )
+                               draw_flash = now+1;
+                       wdw->unlock_window();
+                       while( !interrupted ) {
                                now = timer->get_difference();
-                               int64_t late = now - draw_flash;
-                               if( late < 1000 ) flash();
-                               draw_flash = 0;
-                               first = 0;
-                               continue;
+                               int64_t ms = draw_flash - now;
+                               if( ms <= 0 ) break;
+                               if( ms > 100 ) ms = 100;
+                               Timer::delay(ms);
                        }
-                       if( !first ) first = next;
-                       if( draw(next) && !draw_flash )
-                               draw_flash = next->age;
+                       wdw->lock_window("BC_WindowBase::run 2");
                        now = timer->get_difference();
-                       if( !next->seq_no ) next->cycle_start = now;
-                       int64_t ref_no = (now - next->cycle_start) / 1000 * refresh_rate;
-                       int count = ref_no - next->seq_no;
+                       int64_t late = now - draw_flash;
+                       if( late < 1000 ) flash();
+                       int64_t ref_no = now / 1000. * refresh_rate;
+                       int64_t count = ref_no - seq_no;
                        if( count < 1 ) count = 1;
-                       next->age += count * 1000 / refresh_rate;
-                       if( !next->set_seq_no(next->seq_no + count) )
-                               next->age = now + 1000;
-                       add_vicon(next);
+                       seq_no += count;
+                       draw_flash = seq_no * 1000. / refresh_rate;
                }
                if( viewing != vicon )
                        update_view();