# HG changeset patch # User John Tsiombikas # Date 1320349559 -7200 # Node ID fd671d488cfda86ebfa1e9555c1d11f71a232ee8 # Parent b50fd6f249758c434173848a4ca8e9faa0d53fb7 cleanup of the hacks diff -r b50fd6f24975 -r fd671d488cfd src/stereoplay.c --- a/src/stereoplay.c Sun Mar 06 20:53:30 2011 +0200 +++ b/src/stereoplay.c Thu Nov 03 21:45:59 2011 +0200 @@ -30,6 +30,7 @@ void sig(int s); void sig_decode(int s); void *shmalloc(size_t sz); +int parse_args(int argc, char **argv); struct video_file *vf; uint32_t *img; @@ -43,13 +44,22 @@ Display *dpy; +const char *vid_fname; +int busy_loop; + + int main(int argc, char **argv) { - char *stereo_combiner, *sdrfile; + struct timeval *selwait = 0; + /*char *stereo_combiner, *sdrfile;*/ + + if(parse_args(argc, argv) == -1) { + return 1; + } atexit(cleanup); - if(!(vf = vid_open(argv[1]))) { + if(!(vf = vid_open(vid_fname))) { return 1; } vid_xsz = win_xsz = vid_frame_width(vf); @@ -66,7 +76,7 @@ } glutInit(&argc, argv); - glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_STEREO); glutInitWindowSize(win_xsz, win_ysz); glutCreateWindow(argv[1]); @@ -75,6 +85,11 @@ glutKeyboardFunc(keyb); glutSpecialFunc(skeyb); + if(busy_loop) { + selwait = alloca(sizeof *selwait); + selwait->tv_sec = selwait->tv_usec = 0; + } + glewInit(); /* create the frame texture */ @@ -87,7 +102,7 @@ glTexImage2D(GL_TEXTURE_2D, 0, 4, vid_xsz, vid_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glEnable(GL_TEXTURE_2D); - if(!(stereo_combiner = getenv("STEREO_METHOD"))) { + /*if(!(stereo_combiner = getenv("STEREO_METHOD"))) { stereo_combiner = "redcyan"; } @@ -99,7 +114,7 @@ } bind_program(sdr); set_uniform_float(sdr, "left_offs", 0.5); - set_uniform_float(sdr, "right_offs", 0.0); + set_uniform_float(sdr, "right_offs", 0.0);*/ signal(SIGCHLD, sig); @@ -126,7 +141,7 @@ FD_SET(pfd[0], &rdset); do { - res = select((xsock > pfd[0] ? xsock : pfd[0]) + 1, &rdset, 0, 0, 0); + res = select((xsock > pfd[0] ? xsock : pfd[0]) + 1, &rdset, 0, 0, selwait); } while(res == -1 && errno == EINTR); if(FD_ISSET(pfd[0], &rdset)) { @@ -142,6 +157,9 @@ } glutMainLoopEvent(); + if(busy_loop) { + glutPostRedisplay(); + } } return 0; @@ -161,6 +179,7 @@ close(pfd[0]); } + static int paused; /* decoding_loop() runs in a separate decoding process and communicates @@ -206,12 +225,24 @@ upd_frame = 0; } + glDrawBuffer(swap_eyes ? GL_BACK_RIGHT : GL_BACK_LEFT); + glBegin(GL_QUADS); glColor3f(1, 1, 1); glTexCoord2f(0, 1); glVertex2f(-1, -1); + glTexCoord2f(0.5, 1); glVertex2f(1, -1); + glTexCoord2f(0.5, 0); glVertex2f(1, 1); + glTexCoord2f(0, 0); glVertex2f(-1, 1); + glEnd(); + + glDrawBuffer(swap_eyes ? GL_BACK_LEFT : GL_BACK_RIGHT); + + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glTexCoord2f(0.5, 1); glVertex2f(-1, -1); glTexCoord2f(1, 1); glVertex2f(1, -1); glTexCoord2f(1, 0); glVertex2f(1, 1); - glTexCoord2f(0, 0); glVertex2f(-1, 1); + glTexCoord2f(0.5, 0); glVertex2f(-1, 1); glEnd(); glutSwapBuffers(); @@ -248,13 +279,13 @@ case 's': swap_eyes = !swap_eyes; - if(swap_eyes) { + /*if(swap_eyes) { set_uniform_float(sdr, "left_offs", 0.0); set_uniform_float(sdr, "right_offs", 0.5); } else { set_uniform_float(sdr, "left_offs", 0.5); set_uniform_float(sdr, "right_offs", 0.0); - } + }*/ break; default: @@ -326,3 +357,49 @@ close(fd); return shm; } + +int parse_args(int argc, char **argv) +{ + int i; + char *method = 0; + + for(i=1; i stereo presentation method\n"); + printf(" -h print usage and exit\n"); + return 0; + + default: + fprintf(stderr, "invalid option: %s\n", argv[i]); + return -1; + } + } else { + if(vid_fname) { + fprintf(stderr, "unexpected argument: %s\n", argv[i]); + return -1; + } + vid_fname = argv[i]; + } + } + + if(!vid_fname) { + fprintf(stderr, "you must specify a video file to open\n"); + return -1; + } + + return 0; +} diff -r b50fd6f24975 -r fd671d488cfd src/vid.c --- a/src/vid.c Sun Mar 06 20:53:30 2011 +0200 +++ b/src/vid.c Thu Nov 03 21:45:59 2011 +0200 @@ -45,7 +45,7 @@ vf->vstream = -1; for(i=0; iavctx->nb_streams; i++) { - if(vf->avctx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) { + if(vf->avctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { vf->vstream = i; break; }