stereoplay
changeset 2:fd671d488cfd
cleanup of the hacks
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 03 Nov 2011 21:45:59 +0200 |
parents | b50fd6f24975 |
children | 0d9a1e23726c |
files | src/stereoplay.c src/vid.c |
diffstat | 2 files changed, 87 insertions(+), 10 deletions(-) [+] |
line diff
1.1 --- a/src/stereoplay.c Sun Mar 06 20:53:30 2011 +0200 1.2 +++ b/src/stereoplay.c Thu Nov 03 21:45:59 2011 +0200 1.3 @@ -30,6 +30,7 @@ 1.4 void sig(int s); 1.5 void sig_decode(int s); 1.6 void *shmalloc(size_t sz); 1.7 +int parse_args(int argc, char **argv); 1.8 1.9 struct video_file *vf; 1.10 uint32_t *img; 1.11 @@ -43,13 +44,22 @@ 1.12 1.13 Display *dpy; 1.14 1.15 +const char *vid_fname; 1.16 +int busy_loop; 1.17 + 1.18 + 1.19 int main(int argc, char **argv) 1.20 { 1.21 - char *stereo_combiner, *sdrfile; 1.22 + struct timeval *selwait = 0; 1.23 + /*char *stereo_combiner, *sdrfile;*/ 1.24 + 1.25 + if(parse_args(argc, argv) == -1) { 1.26 + return 1; 1.27 + } 1.28 1.29 atexit(cleanup); 1.30 1.31 - if(!(vf = vid_open(argv[1]))) { 1.32 + if(!(vf = vid_open(vid_fname))) { 1.33 return 1; 1.34 } 1.35 vid_xsz = win_xsz = vid_frame_width(vf); 1.36 @@ -66,7 +76,7 @@ 1.37 } 1.38 1.39 glutInit(&argc, argv); 1.40 - glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 1.41 + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_STEREO); 1.42 glutInitWindowSize(win_xsz, win_ysz); 1.43 glutCreateWindow(argv[1]); 1.44 1.45 @@ -75,6 +85,11 @@ 1.46 glutKeyboardFunc(keyb); 1.47 glutSpecialFunc(skeyb); 1.48 1.49 + if(busy_loop) { 1.50 + selwait = alloca(sizeof *selwait); 1.51 + selwait->tv_sec = selwait->tv_usec = 0; 1.52 + } 1.53 + 1.54 glewInit(); 1.55 1.56 /* create the frame texture */ 1.57 @@ -87,7 +102,7 @@ 1.58 glTexImage2D(GL_TEXTURE_2D, 0, 4, vid_xsz, vid_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 1.59 glEnable(GL_TEXTURE_2D); 1.60 1.61 - if(!(stereo_combiner = getenv("STEREO_METHOD"))) { 1.62 + /*if(!(stereo_combiner = getenv("STEREO_METHOD"))) { 1.63 stereo_combiner = "redcyan"; 1.64 } 1.65 1.66 @@ -99,7 +114,7 @@ 1.67 } 1.68 bind_program(sdr); 1.69 set_uniform_float(sdr, "left_offs", 0.5); 1.70 - set_uniform_float(sdr, "right_offs", 0.0); 1.71 + set_uniform_float(sdr, "right_offs", 0.0);*/ 1.72 1.73 signal(SIGCHLD, sig); 1.74 1.75 @@ -126,7 +141,7 @@ 1.76 FD_SET(pfd[0], &rdset); 1.77 1.78 do { 1.79 - res = select((xsock > pfd[0] ? xsock : pfd[0]) + 1, &rdset, 0, 0, 0); 1.80 + res = select((xsock > pfd[0] ? xsock : pfd[0]) + 1, &rdset, 0, 0, selwait); 1.81 } while(res == -1 && errno == EINTR); 1.82 1.83 if(FD_ISSET(pfd[0], &rdset)) { 1.84 @@ -142,6 +157,9 @@ 1.85 } 1.86 1.87 glutMainLoopEvent(); 1.88 + if(busy_loop) { 1.89 + glutPostRedisplay(); 1.90 + } 1.91 } 1.92 1.93 return 0; 1.94 @@ -161,6 +179,7 @@ 1.95 close(pfd[0]); 1.96 } 1.97 1.98 + 1.99 static int paused; 1.100 1.101 /* decoding_loop() runs in a separate decoding process and communicates 1.102 @@ -206,12 +225,24 @@ 1.103 upd_frame = 0; 1.104 } 1.105 1.106 + glDrawBuffer(swap_eyes ? GL_BACK_RIGHT : GL_BACK_LEFT); 1.107 + 1.108 glBegin(GL_QUADS); 1.109 glColor3f(1, 1, 1); 1.110 glTexCoord2f(0, 1); glVertex2f(-1, -1); 1.111 + glTexCoord2f(0.5, 1); glVertex2f(1, -1); 1.112 + glTexCoord2f(0.5, 0); glVertex2f(1, 1); 1.113 + glTexCoord2f(0, 0); glVertex2f(-1, 1); 1.114 + glEnd(); 1.115 + 1.116 + glDrawBuffer(swap_eyes ? GL_BACK_LEFT : GL_BACK_RIGHT); 1.117 + 1.118 + glBegin(GL_QUADS); 1.119 + glColor3f(1, 1, 1); 1.120 + glTexCoord2f(0.5, 1); glVertex2f(-1, -1); 1.121 glTexCoord2f(1, 1); glVertex2f(1, -1); 1.122 glTexCoord2f(1, 0); glVertex2f(1, 1); 1.123 - glTexCoord2f(0, 0); glVertex2f(-1, 1); 1.124 + glTexCoord2f(0.5, 0); glVertex2f(-1, 1); 1.125 glEnd(); 1.126 1.127 glutSwapBuffers(); 1.128 @@ -248,13 +279,13 @@ 1.129 1.130 case 's': 1.131 swap_eyes = !swap_eyes; 1.132 - if(swap_eyes) { 1.133 + /*if(swap_eyes) { 1.134 set_uniform_float(sdr, "left_offs", 0.0); 1.135 set_uniform_float(sdr, "right_offs", 0.5); 1.136 } else { 1.137 set_uniform_float(sdr, "left_offs", 0.5); 1.138 set_uniform_float(sdr, "right_offs", 0.0); 1.139 - } 1.140 + }*/ 1.141 break; 1.142 1.143 default: 1.144 @@ -326,3 +357,49 @@ 1.145 close(fd); 1.146 return shm; 1.147 } 1.148 + 1.149 +int parse_args(int argc, char **argv) 1.150 +{ 1.151 + int i; 1.152 + char *method = 0; 1.153 + 1.154 + for(i=1; i<argc; i++) { 1.155 + if(argv[i][0] == '-' && argv[i][2] == 0) { 1.156 + switch(argv[i][1]) { 1.157 + case 'b': 1.158 + busy_loop = 1; 1.159 + printf("busy looping!\n"); 1.160 + break; 1.161 + 1.162 + case 's': 1.163 + method = argv[++i]; 1.164 + break; 1.165 + 1.166 + case 'h': 1.167 + printf("Usage: %s [options]\n", argv[0]); 1.168 + printf("options:\n"); 1.169 + printf(" -b busy loop (redraw continuously)\n"); 1.170 + printf(" -s <method> stereo presentation method\n"); 1.171 + printf(" -h print usage and exit\n"); 1.172 + return 0; 1.173 + 1.174 + default: 1.175 + fprintf(stderr, "invalid option: %s\n", argv[i]); 1.176 + return -1; 1.177 + } 1.178 + } else { 1.179 + if(vid_fname) { 1.180 + fprintf(stderr, "unexpected argument: %s\n", argv[i]); 1.181 + return -1; 1.182 + } 1.183 + vid_fname = argv[i]; 1.184 + } 1.185 + } 1.186 + 1.187 + if(!vid_fname) { 1.188 + fprintf(stderr, "you must specify a video file to open\n"); 1.189 + return -1; 1.190 + } 1.191 + 1.192 + return 0; 1.193 +}
2.1 --- a/src/vid.c Sun Mar 06 20:53:30 2011 +0200 2.2 +++ b/src/vid.c Thu Nov 03 21:45:59 2011 +0200 2.3 @@ -45,7 +45,7 @@ 2.4 2.5 vf->vstream = -1; 2.6 for(i=0; i<vf->avctx->nb_streams; i++) { 2.7 - if(vf->avctx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) { 2.8 + if(vf->avctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { 2.9 vf->vstream = i; 2.10 break; 2.11 }