stereoplay
changeset 1:b50fd6f24975
implemented pause
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 06 Mar 2011 20:53:30 +0200 |
parents | 265a24704ff2 |
children | fd671d488cfd |
files | src/stereoplay.c |
diffstat | 1 files changed, 22 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/src/stereoplay.c Sun Mar 06 20:31:18 2011 +0200 1.2 +++ b/src/stereoplay.c Sun Mar 06 20:53:30 2011 +0200 1.3 @@ -28,12 +28,14 @@ 1.4 void keyb(unsigned char key, int x, int y); 1.5 void skeyb(int key, int x, int y); 1.6 void sig(int s); 1.7 +void sig_decode(int s); 1.8 void *shmalloc(size_t sz); 1.9 1.10 struct video_file *vf; 1.11 uint32_t *img; 1.12 int vid_xsz, vid_ysz, win_xsz, win_ysz; 1.13 unsigned int tex, sdr; 1.14 +int decode_pid; 1.15 int pfd[2], xsock = -1; 1.16 int upd_frame; 1.17 int fullscr; 1.18 @@ -43,7 +45,6 @@ 1.19 1.20 int main(int argc, char **argv) 1.21 { 1.22 - int pid; 1.23 char *stereo_combiner, *sdrfile; 1.24 1.25 atexit(cleanup); 1.26 @@ -102,10 +103,10 @@ 1.27 1.28 signal(SIGCHLD, sig); 1.29 1.30 - if((pid = fork()) == -1) { 1.31 + if((decode_pid = fork()) == -1) { 1.32 perror("failed to fork video decoding process"); 1.33 return 1; 1.34 - } else if(pid) { 1.35 + } else if(decode_pid) { 1.36 close(pfd[1]); 1.37 } else { 1.38 close(pfd[0]); 1.39 @@ -160,6 +161,8 @@ 1.40 close(pfd[0]); 1.41 } 1.42 1.43 +static int paused; 1.44 + 1.45 /* decoding_loop() runs in a separate decoding process and communicates 1.46 * with the parent process through the pfd[1] pipe. 1.47 */ 1.48 @@ -171,6 +174,8 @@ 1.49 unsigned long frame_nsec = vid_frame_interval(vf) * 1000; 1.50 printf("nanosecs per frame: %lu\n", frame_nsec); 1.51 1.52 + signal(SIGUSR1, sig_decode); 1.53 + 1.54 gettimeofday(&tv0, 0); 1.55 1.56 while(vid_get_frame(vf, img) != -1) { 1.57 @@ -182,6 +187,10 @@ 1.58 ts.tv_nsec = frame_nsec - (tv.tv_usec - tv0.tv_usec) * 1000; 1.59 nanosleep(&ts, 0); 1.60 1.61 + while(paused) { 1.62 + pause(); 1.63 + } 1.64 + 1.65 gettimeofday(&tv0, 0); 1.66 } 1.67 1.68 @@ -234,7 +243,7 @@ 1.69 break; 1.70 1.71 case ' ': 1.72 - /* TODO pause/resume */ 1.73 + kill(decode_pid, SIGUSR1); 1.74 break; 1.75 1.76 case 's': 1.77 @@ -292,6 +301,15 @@ 1.78 } 1.79 } 1.80 1.81 +void sig_decode(int s) 1.82 +{ 1.83 + signal(s, sig_decode); 1.84 + 1.85 + if(s == SIGUSR1) { 1.86 + paused = !paused; 1.87 + } 1.88 +} 1.89 + 1.90 void *shmalloc(size_t sz) 1.91 { 1.92 int fd;