home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek 6
/
Geek-006.iso
/
linux
/
video
/
xmovie-1.5.3.tar.gz
/
xmovie-1.5.3.tar
/
xmovie-1.5.3
/
xmovie
/
vrender.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-11-29
|
4KB
|
167 lines
#include "file.h"
#include "settings.h"
#include "mainmenu.h"
#include "mainwindow.h"
#include "mwindowgui.h"
#include "playbackengine.h"
#include "settings.h"
#include "units.h"
#include "vrender.h"
VRender::VRender(MainWindow *mwindow)
{
this->mwindow = mwindow;
}
VRender::~VRender()
{
}
int VRender::arm_playback()
{
startup_lock.lock();
synchronous = 1;
mwindow->video_file->set_position(mwindow->current_percentage);
interrupt = 0;
mwindow->gui->start_playback();
return 0;
}
int VRender::stop_playback()
{
interrupt = 1;
return 0;
}
int VRender::close_playback()
{
double percentage, time;
mwindow->gui->stop_playback();
mwindow->video_file->get_position(percentage, time);
mwindow->flash_frame(percentage);
mwindow->gui->canvas->flash();
return 0;
}
int VRender::wait_for_startup()
{
startup_lock.lock();
startup_lock.unlock();
return 0;
}
int VRender::wait_for_completion()
{
join();
return 0;
}
void VRender::run()
{
long current_sample = 0; // Time the frame was finished being decompressed.
long current_frame = 0; // Current frame being flashed
int last_frame = 0;
long start_sample, end_sample; // Absolute counts.
int done = 0, skip;
long delay;
long skip_countdown = VRENDER_THRESHOLD;
long delay_countdown = VRENDER_THRESHOLD;
framerate_counter = 0;
startup_lock.unlock();
while(!interrupt && !done)
{
// Update the framerate counter
if(!framerate_counter)
{
mwindow->actual_framerate = (float)((int)mwindow->frame_rate) / ((float)framerate_timer.get_difference() / 1000);
if(mwindow->settingsmenu->thread->thread_running)
{
mwindow->settingsmenu->thread->update_framerate();
}
framerate_counter = (int)mwindow->frame_rate;
framerate_timer.update();
}
framerate_counter--;
// Skip frames now
mwindow->video_file->drop_frames(current_frame - last_frame - 1);
last_frame = current_frame;
// Perform the most time consuming part of frame decompression now.
mwindow->arm_frame();
// Determine the delay until the frame needs to be shown.
current_sample = (long)(mwindow->engine->current_sample());
// latest sample at which the frame can be shown.
end_sample = Units::tosamples(current_frame, mwindow->samplerate, mwindow->frame_rate);
// earliest sample by which the frame needs to be shown.
start_sample = Units::tosamples(current_frame - 1, mwindow->samplerate, mwindow->frame_rate);
if(end_sample < current_sample)
{
// Frame rendered late. Flash it now.
mwindow->gui->lock_window();
mwindow->flash_armed_frame();
mwindow->gui->unlock_window();
if(mwindow->every_frame)
{
// User wants every frame.
current_frame++;
}
else
if(skip_countdown > 0)
{
// Maybe just a freak.
current_frame++;
skip_countdown--;
}
else
{
// Get the frames to skip.
delay_countdown = VRENDER_THRESHOLD;
skip = 1 + (long)Units::toframes(current_sample, mwindow->samplerate, mwindow->frame_rate) -
(long)Units::toframes(end_sample, mwindow->samplerate, mwindow->frame_rate);
current_frame += skip;
}
}
else
{
// Frame rendered early or just in time.
current_frame++;
if(delay_countdown > 0)
{
// Maybe just a freak
delay_countdown--;
}
else
{
skip_countdown = VRENDER_THRESHOLD;
if(start_sample > current_sample)
{
// Came before the earliest sample so delay
delay = (long)((float)(start_sample - current_sample) * 1000 / mwindow->samplerate);
timer.delay(delay);
}
else
{
// Came after the earliest sample so keep going
}
}
// Flash frame now.
mwindow->gui->lock_window();
mwindow->flash_armed_frame();
mwindow->gui->unlock_window();
}
if(mwindow->video_file->end_of_video()) done = 1;
}
close_playback();
}