# HG changeset patch # User John Tsiombikas # Date 1299437610 -7200 # Node ID b50fd6f249758c434173848a4ca8e9faa0d53fb7 # Parent 265a24704ff2d3aa7040a834b43458fc1a95526a implemented pause diff -r 265a24704ff2 -r b50fd6f24975 src/stereoplay.c --- a/src/stereoplay.c Sun Mar 06 20:31:18 2011 +0200 +++ b/src/stereoplay.c Sun Mar 06 20:53:30 2011 +0200 @@ -28,12 +28,14 @@ void keyb(unsigned char key, int x, int y); void skeyb(int key, int x, int y); void sig(int s); +void sig_decode(int s); void *shmalloc(size_t sz); struct video_file *vf; uint32_t *img; int vid_xsz, vid_ysz, win_xsz, win_ysz; unsigned int tex, sdr; +int decode_pid; int pfd[2], xsock = -1; int upd_frame; int fullscr; @@ -43,7 +45,6 @@ int main(int argc, char **argv) { - int pid; char *stereo_combiner, *sdrfile; atexit(cleanup); @@ -102,10 +103,10 @@ signal(SIGCHLD, sig); - if((pid = fork()) == -1) { + if((decode_pid = fork()) == -1) { perror("failed to fork video decoding process"); return 1; - } else if(pid) { + } else if(decode_pid) { close(pfd[1]); } else { close(pfd[0]); @@ -160,6 +161,8 @@ close(pfd[0]); } +static int paused; + /* decoding_loop() runs in a separate decoding process and communicates * with the parent process through the pfd[1] pipe. */ @@ -171,6 +174,8 @@ unsigned long frame_nsec = vid_frame_interval(vf) * 1000; printf("nanosecs per frame: %lu\n", frame_nsec); + signal(SIGUSR1, sig_decode); + gettimeofday(&tv0, 0); while(vid_get_frame(vf, img) != -1) { @@ -182,6 +187,10 @@ ts.tv_nsec = frame_nsec - (tv.tv_usec - tv0.tv_usec) * 1000; nanosleep(&ts, 0); + while(paused) { + pause(); + } + gettimeofday(&tv0, 0); } @@ -234,7 +243,7 @@ break; case ' ': - /* TODO pause/resume */ + kill(decode_pid, SIGUSR1); break; case 's': @@ -292,6 +301,15 @@ } } +void sig_decode(int s) +{ + signal(s, sig_decode); + + if(s == SIGUSR1) { + paused = !paused; + } +} + void *shmalloc(size_t sz) { int fd;