Mercurial > mplayer.hg
comparison mplayer.c @ 440:d19a3da6ac13
Pontscho's mixer, select, and hell-a-lot-of-stuff patch ;)
author | gabucino |
---|---|
date | Sun, 15 Apr 2001 18:35:17 +0000 |
parents | 50955d1a56c1 |
children | 0828c5d13418 |
comparison
equal
deleted
inserted
replaced
439:fc760523e55a | 440:d19a3da6ac13 |
---|---|
86 int verbose=0; | 86 int verbose=0; |
87 | 87 |
88 #define ABS(x) (((x)>=0)?(x):(-(x))) | 88 #define ABS(x) (((x)>=0)?(x):(-(x))) |
89 | 89 |
90 //**************************************************************************// | 90 //**************************************************************************// |
91 // .SUB | 91 // .SUB |
92 //**************************************************************************// | 92 //**************************************************************************// |
93 | 93 |
94 static current_sub=0; | 94 static current_sub=0; |
95 | 95 |
96 static subtitle* subtitles=NULL; | 96 static subtitle* subtitles=NULL; |
125 ++verbose; | 125 ++verbose; |
126 return 0; | 126 return 0; |
127 } | 127 } |
128 | 128 |
129 static int cfg_include(struct config *conf, char *filename){ | 129 static int cfg_include(struct config *conf, char *filename){ |
130 return parse_config_file(conf, filename); | 130 return parse_config_file(conf, filename); |
131 } | 131 } |
132 | 132 |
133 char *get_path(char *filename){ | 133 char *get_path(char *filename){ |
134 char *homedir; | 134 char *homedir; |
135 char *buff; | 135 char *buff; |
136 static char *config_dir = "/.mplayer"; | 136 static char *config_dir = "/.mplayer"; |
137 int len; | 137 int len; |
138 | 138 |
139 if ((homedir = getenv("HOME")) == NULL) | 139 if ((homedir = getenv("HOME")) == NULL) |
140 return NULL; | 140 return NULL; |
141 len = strlen(homedir) + strlen(config_dir) + 1; | 141 len = strlen(homedir) + strlen(config_dir) + 1; |
142 if (filename == NULL) { | 142 if (filename == NULL) { |
143 if ((buff = (char *) malloc(len)) == NULL) | 143 if ((buff = (char *) malloc(len)) == NULL) |
144 return NULL; | 144 return NULL; |
145 sprintf(buff, "%s%s", homedir, config_dir); | 145 sprintf(buff, "%s%s", homedir, config_dir); |
146 } else { | 146 } else { |
147 len += strlen(filename) + 1; | 147 len += strlen(filename) + 1; |
148 if ((buff = (char *) malloc(len)) == NULL) | 148 if ((buff = (char *) malloc(len)) == NULL) |
149 return NULL; | 149 return NULL; |
150 sprintf(buff, "%s%s/%s", homedir, config_dir, filename); | 150 sprintf(buff, "%s%s/%s", homedir, config_dir, filename); |
151 } | 151 } |
152 return buff; | 152 return buff; |
153 } | 153 } |
154 | 154 |
155 static int max_framesize=0; | 155 static int max_framesize=0; |
156 | 156 |
157 //static int dbg_es_sent=0; | 157 static int dbg_es_sent=0; |
158 //static int dbg_es_rcvd=0; | 158 static int dbg_es_rcvd=0; |
159 | 159 |
160 //static int show_packets=0; | 160 //static int show_packets=0; |
161 | 161 |
162 //**************************************************************************// | 162 //**************************************************************************// |
163 //**************************************************************************// | |
164 // Input media streaming & demultiplexer: | |
165 //**************************************************************************// | |
166 | |
167 #include "stream.c" | |
168 #include "demuxer.c" | |
169 | |
170 #include "stheader.h" | |
171 | 163 |
172 typedef struct { | 164 typedef struct { |
173 // file: | 165 // file: |
174 MainAVIHeader avih; | 166 MainAVIHeader avih; |
175 unsigned int movi_start; | 167 unsigned int movi_start; |
179 int idx_size; | 171 int idx_size; |
180 int idx_pos; | 172 int idx_pos; |
181 int idx_pos_a; | 173 int idx_pos_a; |
182 int idx_pos_v; | 174 int idx_pos_v; |
183 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez | 175 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez |
184 // streams: | |
185 sh_audio_t* a_streams[256]; | |
186 sh_video_t* v_streams[256]; | |
187 // video: | 176 // video: |
188 unsigned int bitrate; | 177 unsigned int bitrate; |
189 } avi_header_t; | 178 } avi_header_t; |
190 | 179 |
191 avi_header_t avi_header; | 180 avi_header_t avi_header; |
192 | 181 |
193 #include "aviprint.c" | 182 #include "aviprint.c" |
194 | 183 |
195 sh_audio_t* new_sh_audio(int id){ | 184 extern picture_t *picture; |
196 if(avi_header.a_streams[id]){ | 185 |
197 printf("Warning! Audio stream header %d redefined!\n",id); | 186 char* encode_name=NULL; |
198 } else { | 187 char* encode_index_name=NULL; |
199 if(verbose) printf("Found audio stream: %d\n",id); | 188 int encode_bitrate=0; |
200 avi_header.a_streams[id]=malloc(sizeof(sh_audio_t)); | 189 |
201 memset(avi_header.a_streams[id],0,sizeof(sh_audio_t)); | 190 //**************************************************************************// |
202 } | 191 // Input media streaming & demultiplexer: |
203 return avi_header.a_streams[id]; | 192 //**************************************************************************// |
204 } | 193 |
205 | 194 #include "stream.c" |
206 sh_video_t* new_sh_video(int id){ | 195 #include "demuxer.c" |
207 if(avi_header.v_streams[id]){ | 196 |
208 printf("Warning! video stream header %d redefined!\n",id); | 197 #include "stheader.h" |
209 } else { | |
210 if(verbose) printf("Found video stream: %d\n",id); | |
211 avi_header.v_streams[id]=malloc(sizeof(sh_video_t)); | |
212 memset(avi_header.v_streams[id],0,sizeof(sh_video_t)); | |
213 } | |
214 return avi_header.v_streams[id]; | |
215 } | |
216 | |
217 | 198 |
218 #include "demux_avi.c" | 199 #include "demux_avi.c" |
219 #include "demux_mpg.c" | 200 #include "demux_mpg.c" |
220 | 201 |
221 demuxer_t *demuxer=NULL; | 202 demuxer_t *demuxer=NULL; |
222 demux_stream_t *d_audio=NULL; | 203 demux_stream_t *d_audio=NULL; |
223 demux_stream_t *d_video=NULL; | 204 demux_stream_t *d_video=NULL; |
224 | 205 |
225 sh_audio_t *sh_audio=NULL;//&sh_audio_i; | 206 sh_audio_t sh_audio_i; // FIXME later! |
226 sh_video_t *sh_video=NULL;//&sh_video_i; | 207 sh_video_t sh_video_i; |
227 | 208 sh_audio_t *sh_audio=&sh_audio_i; |
228 char* encode_name=NULL; | 209 sh_video_t *sh_video=&sh_video_i; |
229 char* encode_index_name=NULL; | |
230 int encode_bitrate=0; | |
231 | 210 |
232 // MPEG video stream parser: | 211 // MPEG video stream parser: |
233 #include "parse_es.c" | 212 #include "parse_es.c" |
234 | |
235 extern picture_t *picture; | |
236 | 213 |
237 static const int frameratecode2framerate[16] = { | 214 static const int frameratecode2framerate[16] = { |
238 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, | 215 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, |
239 60*10000, 0,0,0,0,0,0,0 | 216 60*10000, 0,0,0,0,0,0,0 |
240 }; | 217 }; |
272 unsigned char *opendivx_src[3]; | 249 unsigned char *opendivx_src[3]; |
273 int opendivx_stride[3]; | 250 int opendivx_stride[3]; |
274 | 251 |
275 // callback, the opendivx decoder calls this for each frame: | 252 // callback, the opendivx decoder calls this for each frame: |
276 void convert_linux(unsigned char *puc_y, int stride_y, | 253 void convert_linux(unsigned char *puc_y, int stride_y, |
277 unsigned char *puc_u, unsigned char *puc_v, int stride_uv, | 254 unsigned char *puc_u, unsigned char *puc_v, int stride_uv, |
278 unsigned char *bmp, int width_y, int height_y){ | 255 unsigned char *bmp, int width_y, int height_y){ |
279 | 256 |
280 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); | 257 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); |
281 | 258 |
282 opendivx_src[0]=puc_y; | 259 opendivx_src[0]=puc_y; |
283 opendivx_src[1]=puc_u; | 260 opendivx_src[1]=puc_u; |
284 opendivx_src[2]=puc_v; | 261 opendivx_src[2]=puc_v; |
285 | 262 |
286 opendivx_stride[0]=stride_y; | 263 opendivx_stride[0]=stride_y; |
287 opendivx_stride[1]=stride_uv; | 264 opendivx_stride[1]=stride_uv; |
288 opendivx_stride[2]=stride_uv; | 265 opendivx_stride[2]=stride_uv; |
289 } | 266 } |
290 | 267 |
370 ); | 347 ); |
371 exit_player(NULL); | 348 exit_player(NULL); |
372 } | 349 } |
373 | 350 |
374 int divx_quality=0; | 351 int divx_quality=0; |
375 extern int vo_dbpp; | |
376 | 352 |
377 int main(int argc,char* argv[], char *envp[]){ | 353 int main(int argc,char* argv[], char *envp[]){ |
378 char* filename=NULL; //"MI2-Trailer.avi"; | 354 char* filename=NULL; //"MI2-Trailer.avi"; |
379 int i; | 355 int i; |
380 int seek_to_sec=0; | 356 int seek_to_sec=0; |
381 int seek_to_byte=0; | 357 int seek_to_byte=0; |
382 int f; // filedes | 358 int f; // filedes |
383 int stream_type; | 359 int stream_type; |
384 stream_t* stream=NULL; | 360 stream_t* stream=NULL; |
385 int file_format=DEMUXER_TYPE_UNKNOWN; | 361 int file_format=DEMUXER_TYPE_UNKNOWN; |
386 int has_audio=1; | 362 int has_audio=1; // audio 0=no 1=mpeg 2=pcm 3=ac3 4=ACM 5=alaw 6=msgsm 7=DShow |
387 //int has_video=1; | 363 int has_video=1; // video 0=no 1=mpeg 2=win32/VfW 3=OpenDivX 4=w32/DShow |
388 // | 364 // |
389 int audio_format=0; // override | 365 int audio_format=0; // override |
390 #ifdef ALSA_TIMER | 366 #ifdef ALSA_TIMER |
391 int alsa=1; | 367 int alsa=1; |
392 #else | 368 #else |
428 float font_factor=0.75; | 404 float font_factor=0.75; |
429 char *sub_name=NULL; | 405 char *sub_name=NULL; |
430 float sub_delay=0; | 406 float sub_delay=0; |
431 float sub_fps=0; | 407 float sub_fps=0; |
432 //int user_bpp=0; | 408 //int user_bpp=0; |
433 | 409 extern int vo_dbpp; |
410 // --- NEW | |
411 #include "mixer.h" | |
412 // --- | |
434 #include "cfg-mplayer.h" | 413 #include "cfg-mplayer.h" |
435 | 414 |
436 printf("%s",banner_text); | 415 printf("%s",banner_text); |
437 | 416 |
438 if (parse_config_file(conf, "/etc/mplayer.conf") < 0) | 417 if (parse_config_file(conf, "/etc/mplayer.conf") < 0) |
468 if(video_driver && strcmp(video_driver,"help")==0){ | 447 if(video_driver && strcmp(video_driver,"help")==0){ |
469 printf("Available video output drivers:\n"); | 448 printf("Available video output drivers:\n"); |
470 i=0; | 449 i=0; |
471 while (video_out_drivers[i]) { | 450 while (video_out_drivers[i]) { |
472 const vo_info_t *info = video_out_drivers[i++]->get_info (); | 451 const vo_info_t *info = video_out_drivers[i++]->get_info (); |
473 printf("\t%s\t%s\n", info->short_name, info->name); | 452 printf("\t%s\t%s\n", info->short_name, info->name); |
474 } | 453 } |
475 printf("\n"); | 454 printf("\n"); |
476 exit(0); | 455 exit(0); |
477 } | 456 } |
478 | 457 |
479 if(!filename){ | 458 // check font |
480 if(vcd_track) filename="/dev/cdrom"; | 459 if(font_name){ |
481 else { | 460 vo_font=read_font_desc(font_name,font_factor,verbose>1); |
482 printf("%s",help_text); exit(0); | 461 if(!vo_font) printf("Can't load font: %s\n",font_name); |
483 } | 462 } else { |
484 } | 463 // try default: |
464 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1); | |
465 } | |
466 | |
467 // check .sub | |
468 if(sub_name){ | |
469 subtitles=sub_read_file(sub_name); | |
470 if(!subtitles) printf("Can't load subtitles: %s\n",font_name); | |
471 } else { | |
472 // try default: | |
473 subtitles=sub_read_file(get_path("default.sub")); | |
474 } | |
475 | |
485 | 476 |
486 // check video_out driver name: | 477 // check video_out driver name: |
487 if(!video_driver) | 478 if(!video_driver) |
488 video_out=video_out_drivers[0]; | 479 video_out=video_out_drivers[0]; |
489 else | 480 else |
496 if(!video_out){ | 487 if(!video_out){ |
497 printf("Invalid video output driver name: %s\n",video_driver); | 488 printf("Invalid video output driver name: %s\n",video_driver); |
498 return 0; | 489 return 0; |
499 } | 490 } |
500 | 491 |
492 if(!filename){ | |
493 if(vcd_track) filename="/dev/cdrom"; | |
494 else { | |
495 printf("%s",help_text); exit(0); | |
496 } | |
497 } | |
498 | |
501 // check codec.conf | 499 // check codec.conf |
502 if(!parse_codec_cfg(get_path("codecs.conf"))){ | 500 if(!parse_codec_cfg(get_path("codecs.conf"))){ |
503 printf("(copy/link DOCS/codecs.conf to ~/.mplayer/codecs.conf)\n"); | 501 printf("(copy/link DOCS/codecs.conf to ~/.mplayer/codecs.conf)\n"); |
504 exit(1); | 502 exit(1); |
505 } | 503 } |
506 | |
507 // check font | |
508 if(font_name){ | |
509 vo_font=read_font_desc(font_name,font_factor,verbose>1); | |
510 if(!vo_font) printf("Can't load font: %s\n",font_name); | |
511 } else { | |
512 // try default: | |
513 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1); | |
514 } | |
515 | |
516 // check .sub | |
517 if(sub_name){ | |
518 subtitles=sub_read_file(sub_name); | |
519 if(!subtitles) printf("Can't load subtitles: %s\n",font_name); | |
520 } else { | |
521 // try default: | |
522 subtitles=sub_read_file(get_path("default.sub")); | |
523 } | |
524 | 504 |
525 | 505 |
526 if(vcd_track){ | 506 if(vcd_track){ |
527 //============ Open VideoCD track ============== | 507 //============ Open VideoCD track ============== |
528 f=open(filename,O_RDONLY); | 508 f=open(filename,O_RDONLY); |
544 | 524 |
545 stream=new_stream(f,stream_type); | 525 stream=new_stream(f,stream_type); |
546 | 526 |
547 //============ Open & Sync stream and detect file format =============== | 527 //============ Open & Sync stream and detect file format =============== |
548 | 528 |
549 if(!has_audio) audio_id=-2; // do NOT read audio packets... | 529 if(has_audio==0) audio_id=-2; // do NOT read audio packets... |
550 | 530 |
551 //=============== Try to open as AVI file: ================= | 531 //=============== Try to open as AVI file: ================= |
552 stream_reset(stream); | 532 stream_reset(stream); |
553 demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id); | 533 demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id); |
554 stream_seek(demuxer->stream,seek_to_byte); | 534 stream_seek(demuxer->stream,seek_to_byte); |
555 { //---- RIFF header: | 535 { //---- RIFF header: |
556 int id=stream_read_dword_le(demuxer->stream); // "RIFF" | 536 int id=stream_read_dword_le(demuxer->stream); // "RIFF" |
557 if(id==mmioFOURCC('R','I','F','F')){ | 537 if(id==mmioFOURCC('R','I','F','F')){ |
558 stream_read_dword_le(demuxer->stream); //filesize | 538 stream_read_dword_le(demuxer->stream); //filesize |
559 id=stream_read_dword_le(demuxer->stream); // "AVI " | 539 id=stream_read_dword_le(demuxer->stream); // "AVI " |
560 if(id==formtypeAVI){ | 540 if(id==formtypeAVI){ |
561 printf("Detected AVI file format!\n"); | 541 printf("Detected AVI file format!\n"); |
562 file_format=DEMUXER_TYPE_AVI; | 542 file_format=DEMUXER_TYPE_AVI; |
563 } | 543 } |
564 } | 544 } |
565 } | 545 } |
616 exit(1); | 596 exit(1); |
617 } | 597 } |
618 //====== File format recognized, set up these for compatibility: ========= | 598 //====== File format recognized, set up these for compatibility: ========= |
619 d_audio=demuxer->audio; | 599 d_audio=demuxer->audio; |
620 d_video=demuxer->video; | 600 d_video=demuxer->video; |
621 //d_audio->sh=sh_audio; | 601 d_audio->sh=sh_audio; sh_audio->ds=d_audio; |
622 //d_video->sh=sh_video; | 602 d_video->sh=sh_video; sh_video->ds=d_video; |
623 //sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
624 //sh_video=d_video->sh;sh_video->ds=d_video; | |
625 | 603 |
626 switch(file_format){ | 604 switch(file_format){ |
627 case DEMUXER_TYPE_AVI: { | 605 case DEMUXER_TYPE_AVI: { |
628 //---- AVI header: | 606 //---- AVI header: |
629 read_avi_header(no_index); | 607 read_avi_header(no_index); |
639 else | 617 else |
640 avi_header.idx_offset=0; | 618 avi_header.idx_offset=0; |
641 if(verbose) printf("AVI index offset: %d\n",avi_header.idx_offset); | 619 if(verbose) printf("AVI index offset: %d\n",avi_header.idx_offset); |
642 } | 620 } |
643 demuxer->endpos=avi_header.movi_end; | 621 demuxer->endpos=avi_header.movi_end; |
644 | 622 |
645 if(avi_header.idx_size>0){ | 623 if(avi_header.idx_size>0){ |
646 // check that file is non-interleaved: | 624 // check that file is non-interleaved: |
647 int i; | 625 int i; |
648 int a_pos=-1; | 626 int a_pos=-1; |
649 int v_pos=-1; | 627 int v_pos=-1; |
669 has_audio=0; | 647 has_audio=0; |
670 } else { | 648 } else { |
671 if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB | 649 if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB |
672 printf("Detected NON-INTERLEAVED AVI file-format!\n"); | 650 printf("Detected NON-INTERLEAVED AVI file-format!\n"); |
673 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!! | 651 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!! |
674 pts_from_bps=1; // force BPS sync! | 652 pts_from_bps=1; // force BPS sync! |
675 } | 653 } |
676 } | 654 } |
677 } else { | 655 } else { |
678 // no index | 656 // no index |
679 if(force_ni){ | 657 if(force_ni){ |
680 printf("Using NON-INTERLEAVED Broken AVI file-format!\n"); | 658 printf("Using NON-INTERLEAVED Broken AVI file-format!\n"); |
681 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!! | 659 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!! |
682 avi_header.idx_pos_a= | 660 avi_header.idx_pos_a= |
683 avi_header.idx_pos_v=avi_header.movi_start; | 661 avi_header.idx_pos_v=avi_header.movi_start; |
684 pts_from_bps=1; // force BPS sync! | 662 pts_from_bps=1; // force BPS sync! |
685 } | 663 } |
686 } | 664 } |
687 if(!ds_fill_buffer(d_video)){ | 665 if(!ds_fill_buffer(d_video)){ |
688 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); | 666 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); |
689 exit(1); | 667 exit(1); |
690 } | 668 } |
691 sh_video=d_video->sh;sh_video->ds=d_video; | |
692 if(has_audio){ | 669 if(has_audio){ |
693 if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id); | 670 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); |
694 if(!ds_fill_buffer(d_audio)){ | 671 if(!ds_fill_buffer(d_audio)){ |
695 printf("AVI: No Audio stream found... ->nosound\n"); | 672 printf("ASF: No Audio stream found... ->nosound\n"); |
696 has_audio=0; | 673 has_audio=0; |
697 sh_audio=NULL; | 674 } else sh_audio->format=sh_audio->wf.wFormatTag; |
698 } else { | |
699 sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
700 sh_audio->format=sh_audio->wf->wFormatTag; | |
701 } | |
702 } | 675 } |
703 // calc. FPS: | 676 // calc. FPS: |
704 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; | 677 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; |
705 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; | 678 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
706 // calculating video bitrate: | 679 // calculating video bitrate: |
707 avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; | 680 avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; |
708 if(sh_audio) avi_header.bitrate-=sh_audio->audio.dwLength; | 681 if(sh_audio) avi_header.bitrate-=sh_audio->audio.dwLength; |
709 if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); | 682 if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); |
710 avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength)*sh_video->fps; | 683 avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength)*sh_video->fps; |
711 printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", | 684 printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", |
712 &sh_video->bih->biCompression, | 685 &sh_video->bih.biCompression, |
713 sh_video->bih->biWidth, | 686 sh_video->bih.biWidth, |
714 sh_video->bih->biHeight, | 687 sh_video->bih.biHeight, |
715 sh_video->bih->biBitCount, | 688 sh_video->bih.biBitCount, |
716 sh_video->fps, | 689 sh_video->fps, |
717 avi_header.bitrate*0.008f, | 690 avi_header.bitrate*0.008f, |
718 avi_header.bitrate/1024.0f ); | 691 avi_header.bitrate/1024.0f ); |
719 break; | 692 break; |
720 } | 693 } |
727 demuxer->endpos=avi_header.movi_end; | 700 demuxer->endpos=avi_header.movi_end; |
728 if(!ds_fill_buffer(d_video)){ | 701 if(!ds_fill_buffer(d_video)){ |
729 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); | 702 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); |
730 exit(1); | 703 exit(1); |
731 } | 704 } |
732 sh_video=d_video->sh;sh_video->ds=d_video; | |
733 if(has_audio){ | 705 if(has_audio){ |
734 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); | 706 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); |
735 if(!ds_fill_buffer(d_audio)){ | 707 if(!ds_fill_buffer(d_audio)){ |
736 printf("ASF: No Audio stream found... ->nosound\n"); | 708 printf("ASF: No Audio stream found... ->nosound\n"); |
737 has_audio=0; | 709 has_audio=0; |
738 sh_audio=NULL; | 710 } else sh_audio->format=sh_audio->wf.wFormatTag; |
739 } else { | |
740 sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
741 sh_audio->format=sh_audio->wf->wFormatTag; | |
742 } | |
743 } | 711 } |
744 sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms | 712 sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms |
745 printf("VIDEO: [%.4s] %dx%d %dbpp\n", | 713 printf("VIDEO: [%.4s] %dx%d %dbpp\n", |
746 &sh_video->bih->biCompression, | 714 &sh_video->bih.biCompression, |
747 sh_video->bih->biWidth, | 715 sh_video->bih.biWidth, |
748 sh_video->bih->biHeight, | 716 sh_video->bih.biHeight, |
749 sh_video->bih->biBitCount); | 717 sh_video->bih.biBitCount); |
750 break; | 718 break; |
751 } | 719 } |
752 case DEMUXER_TYPE_MPEG_ES: { | 720 case DEMUXER_TYPE_MPEG_ES: { |
753 d_audio->type=0; | 721 demuxer->audio->type=0; |
754 has_audio=0;sh_audio=NULL; // ES streams has no audio channel | 722 has_audio=0; // ES streams has no audio channel |
755 break; | 723 break; |
756 } | 724 } |
757 case DEMUXER_TYPE_MPEG_PS: { | 725 case DEMUXER_TYPE_MPEG_PS: { |
758 if(has_audio) | 726 if(has_audio) |
759 if(!ds_fill_buffer(d_audio)){ | 727 if(!ds_fill_buffer(d_audio)){ |
760 printf("MPEG: No Audio stream found... ->nosound\n"); | 728 printf("MPEG: No Audio stream found... ->nosound\n"); |
761 has_audio=0;sh_audio=NULL; | 729 has_audio=0; |
762 } else { | 730 } else { |
763 sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
764 if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type); | 731 if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type); |
765 switch(d_audio->type){ | 732 switch(d_audio->type){ |
766 case 1: sh_audio->format=0x50;break; // mpeg | 733 case 1: sh_audio->format=0x50;break; // mpeg |
767 case 2: sh_audio->format=0x10001;break; // dvd pcm | 734 case 2: sh_audio->format=0x2;break; // pcm |
768 case 3: sh_audio->format=0x2000;break; // ac3 | 735 case 3: sh_audio->format=0x2000;break; // ac3 |
769 default: has_audio=0; // unknown type | 736 default: has_audio=0; // unknown type |
770 } | 737 } |
771 } | 738 } |
772 break; | 739 break; |
776 // Determine image properties: | 743 // Determine image properties: |
777 switch(file_format){ | 744 switch(file_format){ |
778 case DEMUXER_TYPE_AVI: | 745 case DEMUXER_TYPE_AVI: |
779 case DEMUXER_TYPE_ASF: { | 746 case DEMUXER_TYPE_ASF: { |
780 // display info: | 747 // display info: |
781 sh_video->format=sh_video->bih->biCompression; | 748 sh_video->format=sh_video->bih.biCompression; |
782 sh_video->disp_w=sh_video->bih->biWidth; | 749 sh_video->disp_w=sh_video->bih.biWidth; |
783 sh_video->disp_h=abs(sh_video->bih->biHeight); | 750 sh_video->disp_h=abs(sh_video->bih.biHeight); |
784 break; | 751 break; |
785 } | 752 } |
786 case DEMUXER_TYPE_MPEG_ES: | 753 case DEMUXER_TYPE_MPEG_ES: |
787 case DEMUXER_TYPE_MPEG_PS: { | 754 case DEMUXER_TYPE_MPEG_PS: { |
788 // Find sequence_header first: | 755 // Find sequence_header first: |
795 printf("MPEG: FATAL: EOF while searching for sequence header\n"); | 762 printf("MPEG: FATAL: EOF while searching for sequence header\n"); |
796 exit(1); | 763 exit(1); |
797 } | 764 } |
798 } | 765 } |
799 if(verbose) printf("OK!\n"); | 766 if(verbose) printf("OK!\n"); |
800 sh_video=d_video->sh;sh_video->ds=d_video; | |
801 sh_video->format=1; // mpeg video | 767 sh_video->format=1; // mpeg video |
802 mpeg2_init(); | 768 mpeg2_init(); |
803 // ========= Read & process sequence header & extension ============ | 769 // ========= Read & process sequence header & extension ============ |
804 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); | 770 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); |
805 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);} | 771 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);} |
831 picture->bitrate/16.0f ); | 797 picture->bitrate/16.0f ); |
832 break; | 798 break; |
833 } | 799 } |
834 } // switch(file_format) | 800 } // switch(file_format) |
835 | 801 |
836 //if(verbose) printf("file successfully opened (has_audio=%d)\n",has_audio); | 802 if(verbose) printf("file successfully opened (has_audio=%d)\n",has_audio); |
837 | 803 |
838 printf("[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", | 804 printf("[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
839 file_format,sh_video->format,sh_video->disp_w,sh_video->disp_h, | 805 file_format,sh_video->format,sh_video->disp_w,sh_video->disp_h, |
840 sh_video->fps,sh_video->frametime | 806 sh_video->fps,sh_video->frametime |
841 ); | 807 ); |
849 if(!sh_audio->codec){ | 815 if(!sh_audio->codec){ |
850 printf("Can't find codec for audio format 0x%X !\n",sh_audio->format); | 816 printf("Can't find codec for audio format 0x%X !\n",sh_audio->format); |
851 has_audio=0; | 817 has_audio=0; |
852 } else { | 818 } else { |
853 printf("Found audio codec: [%s] drv:%d (%s)\n",sh_audio->codec->name,sh_audio->codec->driver,sh_audio->codec->info); | 819 printf("Found audio codec: [%s] drv:%d (%s)\n",sh_audio->codec->name,sh_audio->codec->driver,sh_audio->codec->info); |
854 //has_audio=sh_audio->codec->driver; | 820 has_audio=sh_audio->codec->driver; |
855 } | 821 } |
856 } | 822 } |
857 | 823 |
858 if(has_audio){ | 824 if(has_audio){ |
859 if(verbose) printf("Initializing audio codec...\n"); | 825 if(verbose) printf("Initializing audio codec...\n"); |
860 if(!init_audio(sh_audio)){ | 826 has_audio=init_audio(sh_audio); |
827 if(!has_audio){ | |
861 printf("Couldn't initialize audio codec! -> nosound\n"); | 828 printf("Couldn't initialize audio codec! -> nosound\n"); |
862 has_audio=0; | |
863 } else { | 829 } else { |
864 printf("AUDIO: samplerate=%d channels=%d bps=%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); | 830 printf("AUDIO: samplerate=%d channels=%d bps=%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); |
865 } | 831 } |
866 } | 832 } |
867 | 833 |
868 //================== Init VIDEO (codec & libvo) ========================== | 834 //================== Init VIDEO (codec & libvo) ========================== |
869 | 835 |
870 // Go through the codec.conf and find the best codec... | 836 // Go through the codec.conf and find the best codec... |
871 sh_video->codec=find_codec(sh_video->format, | 837 sh_video->codec=find_codec(sh_video->format,(unsigned int*) &sh_video->bih.biCompression,NULL,0); |
872 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,NULL,0); | |
873 if(!sh_video->codec){ | 838 if(!sh_video->codec){ |
874 printf("Can't find codec for video format 0x%X !\n",sh_video->format); | 839 printf("Can't find codec for video format 0x%X !\n",sh_video->format); |
875 exit(1); | 840 exit(1); |
876 } | 841 } |
877 //has_video=sh_video->codec->driver; | 842 has_video=sh_video->codec->driver; |
878 | 843 |
879 printf("Found video codec: [%s] drv:%d (%s)\n",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->info); | 844 printf("Found video codec: [%s] drv:%d (%s)\n",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->info); |
845 | |
846 //if(user_bpp)printf("Trying user defined depth of %dbpp\n", user_bpp); | |
880 | 847 |
881 for(i=0;i<CODECS_MAX_OUTFMT;i++){ | 848 for(i=0;i<CODECS_MAX_OUTFMT;i++){ |
882 out_fmt=sh_video->codec->outfmt[i]; | 849 out_fmt=sh_video->codec->outfmt[i]; |
883 if(video_out->query_format(out_fmt)) break; | 850 // if(vo_dbpp){ |
851 // if( ((out_fmt & IMGFMT_BGR_MASK) == IMGFMT_BGR) && ((out_fmt & 0xff) == vo_dbpp) || (out_fmt & IMGFMT_BGR_MASK) != IMGFMT_BGR){ | |
852 // if(video_out->query_format(out_fmt)) break; | |
853 // } | |
854 // }else{ | |
855 if(video_out->query_format(out_fmt)) break; | |
856 // } | |
884 } | 857 } |
885 if(i>=CODECS_MAX_OUTFMT){ | 858 if(i>=CODECS_MAX_OUTFMT){ |
886 printf("Sorry, selected video_out device is incompatible with this codec.\n"); | 859 printf("Sorry, selected video_out device is incompatible with this codec.\n"); |
887 exit(1); | 860 exit(1); |
888 } | 861 } |
889 sh_video->outfmtidx=i; | 862 sh_video->outfmtidx=i; |
890 | 863 |
891 switch(sh_video->codec->driver){ | 864 switch(has_video){ |
892 case 2: { | 865 case 2: { |
893 if(!init_video_codec(out_fmt)) exit(1); | 866 if(!init_video_codec(out_fmt)) exit(1); |
894 if(verbose) printf("INFO: Win32 video codec init OK!\n"); | 867 if(verbose) printf("INFO: Win32 video codec init OK!\n"); |
895 break; | 868 break; |
896 } | 869 } |
898 #ifndef USE_DIRECTSHOW | 871 #ifndef USE_DIRECTSHOW |
899 printf("MPlayer was compiled WITHOUT directshow support!\n"); | 872 printf("MPlayer was compiled WITHOUT directshow support!\n"); |
900 exit(1); | 873 exit(1); |
901 #else | 874 #else |
902 sh_video->our_out_buffer=NULL; | 875 sh_video->our_out_buffer=NULL; |
903 if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){ | 876 if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, &sh_video->bih, 0, &sh_video->our_out_buffer)){ |
904 printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); | 877 printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); |
905 printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); | 878 printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); |
906 printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); | 879 printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); |
907 printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); | 880 printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); |
908 exit(1); | 881 exit(1); |
909 } | 882 } |
910 | 883 |
911 if(out_fmt==IMGFMT_YUY2) | 884 if(out_fmt==IMGFMT_YUY2) |
912 DS_VideoDecoder_SetDestFmt(16,mmioFOURCC('Y', 'U', 'Y', '2')); | 885 DS_VideoDecoder_SetDestFmt(16,mmioFOURCC('Y', 'U', 'Y', '2')); |
913 // DS_VideoDecoder_SetDestFmt(16,mmioFOURCC('Y', 'V', '1', '2')); | 886 // DS_VideoDecoder_SetDestFmt(16,mmioFOURCC('Y', 'V', '1', '2')); |
914 else | 887 else |
915 DS_VideoDecoder_SetDestFmt(out_fmt&255,0); | 888 DS_VideoDecoder_SetDestFmt(out_fmt&255,0); |
916 | 889 |
917 DS_VideoDecoder_Start(); | 890 DS_VideoDecoder_Start(); |
918 | 891 |
919 printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); | 892 printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); |
920 // printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); | 893 // printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); |
921 | 894 |
922 if(verbose) printf("INFO: Win32/DShow video codec init OK!\n"); | 895 if(verbose) printf("INFO: Win32/DShow video codec init OK!\n"); |
923 break; | 896 break; |
924 #endif | 897 #endif |
925 } | 898 } |
926 case 3: { // OpenDivX | 899 case 3: { // OpenDivX |
927 if(verbose) printf("OpenDivX video codec\n"); | 900 if(verbose) printf("OpenDivX video codec\n"); |
928 { DEC_PARAM dec_param; | 901 { DEC_PARAM dec_param; |
929 DEC_SET dec_set; | 902 DEC_SET dec_set; |
930 dec_param.x_dim = sh_video->bih->biWidth; | 903 dec_param.x_dim = sh_video->bih.biWidth; |
931 dec_param.y_dim = sh_video->bih->biHeight; | 904 dec_param.y_dim = sh_video->bih.biHeight; |
932 dec_param.color_depth = 32; | 905 dec_param.color_depth = 32; |
933 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); | 906 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); |
934 dec_set.postproc_level = divx_quality; | 907 dec_set.postproc_level = divx_quality; |
935 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); | 908 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); |
936 } | 909 } |
937 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); | 910 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); |
938 break; | 911 break; |
939 } | 912 } |
940 case 1: { | 913 case 1: { |
1041 printf("FATAL: Cannot initialize video driver!\n");exit(1); | 1014 printf("FATAL: Cannot initialize video driver!\n");exit(1); |
1042 } | 1015 } |
1043 if(verbose) printf("INFO: Video OUT driver init OK!\n"); | 1016 if(verbose) printf("INFO: Video OUT driver init OK!\n"); |
1044 | 1017 |
1045 fflush(stdout); | 1018 fflush(stdout); |
1046 | 1019 |
1047 //================== MAIN: ========================== | 1020 //================== MAIN: ========================== |
1048 { | 1021 { |
1049 int audio_fd=-1; | 1022 int audio_fd=-1; |
1050 float buffer_delay=0; | 1023 float buffer_delay=0; |
1051 float frame_correction=0; // A-V timestamp kulonbseg atlagolas | 1024 float frame_correction=0; // A-V timestamp kulonbseg atlagolas |
1169 if(!has_audio){ | 1142 if(!has_audio){ |
1170 printf("Audio: no sound\n"); | 1143 printf("Audio: no sound\n"); |
1171 if(verbose) printf("Freeing %d unused audio chunks\n",d_audio->packs); | 1144 if(verbose) printf("Freeing %d unused audio chunks\n",d_audio->packs); |
1172 ds_free_packs(d_audio); // free buffered chunks | 1145 ds_free_packs(d_audio); // free buffered chunks |
1173 d_audio->id=-2; // do not read audio chunks | 1146 d_audio->id=-2; // do not read audio chunks |
1174 if(sh_audio) if(sh_audio->a_buffer) free(sh_audio->a_buffer); | 1147 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
1175 alsa=1; | 1148 alsa=1; |
1176 // fake, required for timer: | 1149 // fake, required for timer: |
1177 sh_audio=new_sh_audio(255); // FIXME!!!!!!!!!! | |
1178 sh_audio->samplerate=76800; | 1150 sh_audio->samplerate=76800; |
1179 sh_audio->samplesize=sh_audio->channels=2; | 1151 sh_audio->samplesize=sh_audio->channels=2; |
1180 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | 1152 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
1181 } | 1153 } |
1182 | 1154 |
1213 while(has_audio){ | 1185 while(has_audio){ |
1214 | 1186 |
1215 // Update buffer if needed | 1187 // Update buffer if needed |
1216 unsigned int t=GetTimer(); | 1188 unsigned int t=GetTimer(); |
1217 current_module="decode_audio"; // Enter AUDIO decoder module | 1189 current_module="decode_audio"; // Enter AUDIO decoder module |
1218 //sh_audio->codec->driver=has_audio; // FIXME! | 1190 sh_audio->codec->driver=has_audio; // FIXME! |
1219 while(sh_audio->a_buffer_len<OUTBURST && !d_audio->eof){ | 1191 while(sh_audio->a_buffer_len<OUTBURST && !d_audio->eof){ |
1220 int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],sh_audio->a_buffer_size-sh_audio->a_buffer_len); | 1192 int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],sh_audio->a_buffer_size-sh_audio->a_buffer_len); |
1221 if(ret>0) sh_audio->a_buffer_len+=ret; else break; | 1193 if(ret>0) sh_audio->a_buffer_len+=ret; else break; |
1222 } | 1194 } |
1223 current_module=NULL; // Leave AUDIO decoder module | 1195 current_module=NULL; // Leave AUDIO decoder module |
1290 | 1262 |
1291 /*========================== PLAY VIDEO ============================*/ | 1263 /*========================== PLAY VIDEO ============================*/ |
1292 | 1264 |
1293 if(1) | 1265 if(1) |
1294 while(v_frame<a_frame || force_redraw){ | 1266 while(v_frame<a_frame || force_redraw){ |
1295 | 1267 |
1296 float frame_time=1; | 1268 float frame_time=1; |
1297 float pts1=d_video->pts; | 1269 float pts1=d_video->pts; |
1298 | 1270 |
1299 current_module="decode_video"; | 1271 current_module="decode_video"; |
1300 | 1272 |
1301 //-------------------- Decode a frame: ----------------------- | 1273 //-------------------- Decode a frame: ----------------------- |
1302 switch(sh_video->codec->driver){ | 1274 switch(has_video){ |
1303 case 3: { | 1275 case 3: { |
1304 // OpenDivX | 1276 // OpenDivX |
1305 unsigned int t=GetTimer(); | 1277 unsigned int t=GetTimer(); |
1306 unsigned int t2; | 1278 unsigned int t2; |
1307 DEC_FRAME dec_frame; | 1279 DEC_FRAME dec_frame; |
1309 int in_size=ds_get_packet(d_video,&start); | 1281 int in_size=ds_get_packet(d_video,&start); |
1310 if(in_size<0){ eof=1;break;} | 1282 if(in_size<0){ eof=1;break;} |
1311 if(in_size>max_framesize) max_framesize=in_size; | 1283 if(in_size>max_framesize) max_framesize=in_size; |
1312 // let's decode | 1284 // let's decode |
1313 dec_frame.length = in_size; | 1285 dec_frame.length = in_size; |
1314 dec_frame.bitstream = start; | 1286 dec_frame.bitstream = start; |
1315 dec_frame.render_flag = 1; | 1287 dec_frame.render_flag = 1; |
1316 decore(0x123, 0, &dec_frame, NULL); | 1288 decore(0x123, 0, &dec_frame, NULL); |
1317 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | 1289 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
1318 | 1290 |
1319 if(opendivx_src[0]){ | 1291 if(opendivx_src[0]){ |
1320 video_out->draw_slice(opendivx_src,opendivx_stride, | 1292 video_out->draw_slice(opendivx_src,opendivx_stride, |
1321 sh_video->disp_w,sh_video->disp_h,0,0); | 1293 sh_video->disp_w,sh_video->disp_h,0,0); |
1347 unsigned int t=GetTimer(); | 1319 unsigned int t=GetTimer(); |
1348 unsigned int t2; | 1320 unsigned int t2; |
1349 int in_size=ds_get_packet(d_video,&start); | 1321 int in_size=ds_get_packet(d_video,&start); |
1350 if(in_size<0){ eof=1;break;} | 1322 if(in_size<0){ eof=1;break;} |
1351 if(in_size>max_framesize) max_framesize=in_size; | 1323 if(in_size>max_framesize) max_framesize=in_size; |
1352 | 1324 |
1353 if(in_size){ | 1325 sh_video->bih.biSizeImage = in_size; |
1354 sh_video->bih->biSizeImage = in_size; | 1326 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), |
1355 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), | 1327 ret = ICDecompress(sh_video->hic, ICDECOMPRESS_NOTKEYFRAME, |
1356 ret = ICDecompress(sh_video->hic, ICDECOMPRESS_NOTKEYFRAME, | 1328 &sh_video->bih, start, |
1357 sh_video->bih, start, | |
1358 &sh_video->o_bih, sh_video->our_out_buffer); | 1329 &sh_video->o_bih, sh_video->our_out_buffer); |
1359 if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; } | 1330 if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; } |
1360 } | 1331 |
1361 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; | 1332 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
1362 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); | 1333 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); |
1363 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | 1334 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; |
1364 | 1335 |
1365 break; | 1336 break; |
1387 } else { | 1358 } else { |
1388 //if(i==0x100) in_frame=1; // picture startcode | 1359 //if(i==0x100) in_frame=1; // picture startcode |
1389 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode | 1360 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode |
1390 else if(!i){ eof=1; break;} // EOF | 1361 else if(!i){ eof=1; break;} // EOF |
1391 } | 1362 } |
1392 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; | 1363 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; |
1393 if(!read_video_packet(d_video)){ eof=1; break;} // EOF | 1364 if(!read_video_packet(d_video)){ eof=1; break;} // EOF |
1394 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); | 1365 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); |
1395 } | 1366 } |
1396 | 1367 |
1397 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug | 1368 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug |
1398 //printf("--- SEND %d bytes\n",videobuf_len); | 1369 //printf("--- SEND %d bytes\n",videobuf_len); |
1399 if(grab_frames==1){ | 1370 if(grab_frames==1){ |
1400 FILE *f=fopen("grab.mpg","ab"); | 1371 FILE *f=fopen("grab.mpg","ab"); |
1401 fwrite(videobuffer,videobuf_len-4,1,f); | 1372 fwrite(videobuffer,videobuf_len-4,1,f); |
1402 fclose(f); | 1373 fclose(f); |
1403 } | 1374 } |
1404 | 1375 |
1405 t-=GetTimer(); | 1376 t-=GetTimer(); |
1406 mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len); | 1377 mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len); |
1407 t+=GetTimer(); video_time_usage+=t*0.000001; | 1378 t+=GetTimer(); video_time_usage+=t*0.000001; |
1408 | 1379 |
1409 newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; | 1380 newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; |
1410 if(ABS(sh_video->fps-newfps)>0.01f) if(!force_fps){ | 1381 if(ABS(sh_video->fps-newfps)>0.01f){ |
1411 printf("Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code); | 1382 printf("Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code); |
1412 sh_video->fps=newfps; | 1383 sh_video->fps=newfps; |
1413 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; | 1384 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; |
1414 } | 1385 } |
1415 | 1386 |
1416 frame_time=(100+picture->repeat_count)*0.01f; | 1387 frame_time=(100+picture->repeat_count)*0.01f; |
1417 picture->repeat_count=0; | 1388 picture->repeat_count=0; |
1418 | 1389 |
1419 break; | 1390 break; |
1420 } | 1391 } |
1422 //------------------------ frame decoded. -------------------- | 1393 //------------------------ frame decoded. -------------------- |
1423 | 1394 |
1424 // Increase video timers: | 1395 // Increase video timers: |
1425 num_frames+=frame_time; | 1396 num_frames+=frame_time; |
1426 frame_time*=sh_video->frametime; | 1397 frame_time*=sh_video->frametime; |
1427 if(file_format==DEMUXER_TYPE_ASF && !force_fps){ | 1398 if(file_format==DEMUXER_TYPE_ASF){ |
1428 // .ASF files has no fixed FPS - just frame durations! | 1399 // .ASF files has no fixed FPS - just frame durations! |
1429 float d=d_video->pts-pts1; | 1400 float d=d_video->pts-pts1; |
1430 if(d>=0 && d<5) frame_time=d; | 1401 if(d>=0 && d<5) frame_time=d; |
1431 } | 1402 } |
1432 v_frame+=frame_time; | 1403 v_frame+=frame_time; |
1448 #if 1 | 1419 #if 1 |
1449 /*================ A-V TIMESTAMP CORRECTION: =========================*/ | 1420 /*================ A-V TIMESTAMP CORRECTION: =========================*/ |
1450 if(has_audio){ | 1421 if(has_audio){ |
1451 if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){ | 1422 if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){ |
1452 // a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay+audio_delay); | 1423 // a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay+audio_delay); |
1453 a_pts=(float)ds_tell(d_audio)/sh_audio->wf->nAvgBytesPerSec-(buffer_delay); | 1424 a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay); |
1454 delay_corrected=1; // hack | 1425 delay_corrected=1; // hack |
1455 } else | 1426 } else |
1456 if(d_audio->pts){ | 1427 if(d_audio->pts){ |
1457 // printf("\n=== APTS a_pts=%5.3f v_pts=%5.3f === \n",d_audio->pts,d_video->pts); | 1428 // printf("\n=== APTS a_pts=%5.3f v_pts=%5.3f === \n",d_audio->pts,d_video->pts); |
1458 #if 1 | 1429 #if 1 |
1479 x*=0.5f; | 1450 x*=0.5f; |
1480 if(x<-max_pts_correction) x=-max_pts_correction; else | 1451 if(x<-max_pts_correction) x=-max_pts_correction; else |
1481 if(x> max_pts_correction) x= max_pts_correction; | 1452 if(x> max_pts_correction) x= max_pts_correction; |
1482 max_pts_correction=default_max_pts_correction; | 1453 max_pts_correction=default_max_pts_correction; |
1483 a_frame+=x; c_total+=x; | 1454 a_frame+=x; c_total+=x; |
1484 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% \r",c_total, | 1455 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% %d \r",c_total, |
1485 (int)num_frames, | 1456 (int)num_frames, |
1486 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, | 1457 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, |
1487 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, | 1458 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, |
1488 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 | 1459 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, |
1489 // dbg_es_sent-dbg_es_rcvd | 1460 dbg_es_sent-dbg_es_rcvd |
1490 ); | 1461 ); |
1491 fflush(stdout); | 1462 fflush(stdout); |
1492 } | 1463 } |
1493 frame_corr_num=0; frame_correction=0; | 1464 frame_corr_num=0; frame_correction=0; |
1494 } | 1465 } |
1496 } else { | 1467 } else { |
1497 // No audio: | 1468 // No audio: |
1498 if(d_video->pts) v_pts=d_video->pts; | 1469 if(d_video->pts) v_pts=d_video->pts; |
1499 if(frame_corr_num==5){ | 1470 if(frame_corr_num==5){ |
1500 // printf("A: --- V:%6.1f \r",v_pts); | 1471 // printf("A: --- V:%6.1f \r",v_pts); |
1501 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts, | 1472 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% %d \r",v_pts, |
1502 (int)num_frames, | 1473 (int)num_frames, |
1503 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, | 1474 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, |
1504 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, | 1475 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, |
1505 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 | 1476 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, |
1506 // dbg_es_sent-dbg_es_rcvd | 1477 dbg_es_sent-dbg_es_rcvd); |
1507 ); | |
1508 | 1478 |
1509 fflush(stdout); | 1479 fflush(stdout); |
1510 frame_corr_num=0; | 1480 frame_corr_num=0; |
1511 } | 1481 } |
1512 } | 1482 } |
1523 while( | 1493 while( |
1524 #ifdef HAVE_LIRC | 1494 #ifdef HAVE_LIRC |
1525 lirc_mp_getinput()<=0 && | 1495 lirc_mp_getinput()<=0 && |
1526 #endif | 1496 #endif |
1527 getch2(20)<=0 && mplayer_get_key()<=0){ | 1497 getch2(20)<=0 && mplayer_get_key()<=0){ |
1528 video_out->check_events(); | 1498 video_out->check_events(); |
1529 } | 1499 } |
1530 osd_function=OSD_PLAY; | 1500 osd_function=OSD_PLAY; |
1531 } | 1501 } |
1532 | 1502 |
1533 } // while(v_frame<a_frame || force_redraw) | 1503 } // while(v_frame<a_frame || force_redraw) |
1576 osd_function=OSD_PAUSE; | 1546 osd_function=OSD_PAUSE; |
1577 break; | 1547 break; |
1578 case 'o': // toggle OSD | 1548 case 'o': // toggle OSD |
1579 osd_level=(osd_level+1)%3; | 1549 osd_level=(osd_level+1)%3; |
1580 break; | 1550 break; |
1551 // --- NEW | |
1552 case '*': | |
1553 mixer_incvolume(); | |
1554 break; | |
1555 case '/': | |
1556 mixer_decvolume(); | |
1557 break; | |
1558 case 'm': | |
1559 mixer_usemaster=1; | |
1560 break;; | |
1561 case 'c': | |
1562 mixer_usemaster=0; | |
1563 break; | |
1564 // --- | |
1581 } | 1565 } |
1582 if(rel_seek_secs) | 1566 if(rel_seek_secs) |
1583 if(file_format==DEMUXER_TYPE_AVI && avi_header.idx_size<=0){ | 1567 if(file_format==DEMUXER_TYPE_AVI && avi_header.idx_size<=0){ |
1584 printf("Can't seek in raw .AVI streams! (index required) \n"); | 1568 printf("Can't seek in raw .AVI streams! (index required) \n"); |
1585 } else { | 1569 } else { |
1587 float skip_audio_secs=0; | 1571 float skip_audio_secs=0; |
1588 | 1572 |
1589 // clear demux buffers: | 1573 // clear demux buffers: |
1590 if(has_audio) ds_free_packs(d_audio); | 1574 if(has_audio) ds_free_packs(d_audio); |
1591 ds_free_packs(d_video); | 1575 ds_free_packs(d_video); |
1592 | 1576 |
1593 // printf("sh_audio->a_buffer_len=%d \n",sh_audio->a_buffer_len); | 1577 // printf("sh_audio->a_buffer_len=%d \n",sh_audio->a_buffer_len); |
1594 sh_audio->a_buffer_len=0; | 1578 sh_audio->a_buffer_len=0; |
1595 | 1579 |
1596 switch(file_format){ | 1580 switch(file_format){ |
1597 | 1581 |
1599 //================= seek in AVI ========================== | 1583 //================= seek in AVI ========================== |
1600 int rel_seek_frames=rel_seek_secs*sh_video->fps; | 1584 int rel_seek_frames=rel_seek_secs*sh_video->fps; |
1601 int curr_audio_pos=0; | 1585 int curr_audio_pos=0; |
1602 int audio_chunk_pos=-1; | 1586 int audio_chunk_pos=-1; |
1603 int video_chunk_pos=d_video->pos; | 1587 int video_chunk_pos=d_video->pos; |
1604 | 1588 |
1605 skip_video_frames=0; | 1589 skip_video_frames=0; |
1606 | 1590 |
1607 // SEEK streams | 1591 // SEEK streams |
1608 // if(d_video->pts) avi_video_pts=d_video->pts; | 1592 // if(d_video->pts) avi_video_pts=d_video->pts; |
1609 avi_audio_pts=0; | 1593 avi_audio_pts=0; |
1663 int apos=0; | 1647 int apos=0; |
1664 int last=0; | 1648 int last=0; |
1665 int len=0; | 1649 int len=0; |
1666 | 1650 |
1667 // calc new audio position in audio stream: (using avg.bps value) | 1651 // calc new audio position in audio stream: (using avg.bps value) |
1668 curr_audio_pos=(avi_video_pts) * sh_audio->wf->nAvgBytesPerSec; | 1652 curr_audio_pos=(avi_video_pts) * sh_audio->wf.nAvgBytesPerSec; |
1669 if(curr_audio_pos<0)curr_audio_pos=0; | 1653 if(curr_audio_pos<0)curr_audio_pos=0; |
1670 #if 1 | 1654 #if 1 |
1671 curr_audio_pos&=~15; // requires for PCM formats!!! | 1655 curr_audio_pos&=~15; // requires for PCM formats!!! |
1672 #else | 1656 #else |
1673 curr_audio_pos/=sh_audio->wf->nBlockAlign; | 1657 curr_audio_pos/=sh_audio->wf.nBlockAlign; |
1674 curr_audio_pos*=sh_audio->wf->nBlockAlign; | 1658 curr_audio_pos*=sh_audio->wf.nBlockAlign; |
1675 avi_header.audio_seekable=1; | 1659 avi_header.audio_seekable=1; |
1676 #endif | 1660 #endif |
1677 | 1661 |
1678 // find audio chunk pos: | 1662 // find audio chunk pos: |
1679 for(i=0;i<video_chunk_pos;i++){ | 1663 for(i=0;i<video_chunk_pos;i++){ |
1705 avi_header.idx_pos=audio_chunk_pos; | 1689 avi_header.idx_pos=audio_chunk_pos; |
1706 | 1690 |
1707 if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){ | 1691 if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){ |
1708 #if 0 | 1692 #if 0 |
1709 // curr_audio_pos=apos; // selected audio codec can't seek in chunk | 1693 // curr_audio_pos=apos; // selected audio codec can't seek in chunk |
1710 skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf->nAvgBytesPerSec; | 1694 skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf.nAvgBytesPerSec; |
1711 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs); | 1695 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs); |
1712 skip_audio_bytes=0; | 1696 skip_audio_bytes=0; |
1713 #else | 1697 #else |
1714 int d=skip_audio_bytes % sh_audio->wf->nBlockAlign; | 1698 int d=skip_audio_bytes % sh_audio->wf.nBlockAlign; |
1715 skip_audio_bytes-=d; | 1699 skip_audio_bytes-=d; |
1716 // curr_audio_pos-=d; | 1700 // curr_audio_pos-=d; |
1717 skip_audio_secs=(float)d/(float)sh_audio->wf->nAvgBytesPerSec; | 1701 skip_audio_secs=(float)d/(float)sh_audio->wf.nAvgBytesPerSec; |
1718 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs); | 1702 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs); |
1719 #endif | 1703 #endif |
1720 } | 1704 } |
1721 // now: audio_chunk_pos=pos in index | 1705 // now: audio_chunk_pos=pos in index |
1722 // skip_audio_bytes=bytes to skip from that chunk | 1706 // skip_audio_bytes=bytes to skip from that chunk |
1723 // skip_audio_secs=time to play audio before video (if can't skip) | 1707 // skip_audio_secs=time to play audio before video (if can't skip) |
1724 | 1708 |
1725 // calc skip_video_frames & adjust video pts counter: | 1709 // calc skip_video_frames & adjust video pts counter: |
1726 // i=last; | 1710 // i=last; |
1727 i=avi_header.idx_pos; | 1711 i=avi_header.idx_pos; |
1728 while(i<video_chunk_pos){ | 1712 while(i<video_chunk_pos){ |
1729 int id=avi_header.idx[i].ckid; | 1713 int id=avi_header.idx[i].ckid; |
1733 // requires for correct audio pts calculation (demuxer): | 1717 // requires for correct audio pts calculation (demuxer): |
1734 avi_video_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; | 1718 avi_video_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1735 } | 1719 } |
1736 ++i; | 1720 ++i; |
1737 } | 1721 } |
1738 | 1722 |
1739 } | 1723 } |
1740 | 1724 |
1741 if(verbose) printf("SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n", | 1725 if(verbose) printf("SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n", |
1742 avi_header.idx_pos,audio_chunk_pos,video_chunk_pos, | 1726 avi_header.idx_pos,audio_chunk_pos,video_chunk_pos, |
1743 skip_video_frames,skip_audio_bytes,skip_audio_secs); | 1727 skip_video_frames,skip_audio_bytes,skip_audio_secs); |
1766 newpos=demuxer->filepos+rel_seek_bytes; | 1750 newpos=demuxer->filepos+rel_seek_bytes; |
1767 if(newpos<0) newpos=0; | 1751 if(newpos<0) newpos=0; |
1768 stream_seek(demuxer->stream,newpos); | 1752 stream_seek(demuxer->stream,newpos); |
1769 } | 1753 } |
1770 break; | 1754 break; |
1771 | 1755 |
1772 case DEMUXER_TYPE_MPEG_ES: | 1756 case DEMUXER_TYPE_MPEG_ES: |
1773 case DEMUXER_TYPE_MPEG_PS: { | 1757 case DEMUXER_TYPE_MPEG_PS: { |
1774 //================= seek in MPEG ========================== | 1758 //================= seek in MPEG ========================== |
1775 int newpos; | 1759 int newpos; |
1776 if(picture->bitrate==0x3FFFF) // unspecified? | 1760 if(picture->bitrate==0x3FFFF) // unspecified? |
1800 | 1784 |
1801 if(skip_audio_bytes){ | 1785 if(skip_audio_bytes){ |
1802 demux_read_data(d_audio,NULL,skip_audio_bytes); | 1786 demux_read_data(d_audio,NULL,skip_audio_bytes); |
1803 d_audio->pts=0; // PTS is outdated because of the raw data skipping | 1787 d_audio->pts=0; // PTS is outdated because of the raw data skipping |
1804 } | 1788 } |
1805 | 1789 |
1806 current_module="resync_audio"; | 1790 current_module="resync_audio"; |
1807 | 1791 |
1808 switch(sh_audio->codec->driver){ | 1792 switch(has_audio){ |
1809 case 1: | 1793 case 1: |
1810 MP3_DecodeFrame(NULL,-2); // resync | 1794 MP3_DecodeFrame(NULL,-2); // resync |
1811 MP3_DecodeFrame(NULL,-2); // resync | 1795 MP3_DecodeFrame(NULL,-2); // resync |
1812 MP3_DecodeFrame(NULL,-2); // resync | 1796 MP3_DecodeFrame(NULL,-2); // resync |
1813 break; | 1797 break; |
1825 | 1809 |
1826 // re-sync PTS (MPEG-PS only!!!) | 1810 // re-sync PTS (MPEG-PS only!!!) |
1827 if(file_format==DEMUXER_TYPE_MPEG_PS) | 1811 if(file_format==DEMUXER_TYPE_MPEG_PS) |
1828 if(d_video->pts && d_audio->pts){ | 1812 if(d_video->pts && d_audio->pts){ |
1829 if (d_video->pts < d_audio->pts){ | 1813 if (d_video->pts < d_audio->pts){ |
1830 | 1814 |
1831 } else { | 1815 } else { |
1832 while(d_video->pts > d_audio->pts){ | 1816 while(d_video->pts > d_audio->pts){ |
1833 switch(sh_audio->codec->driver){ | 1817 switch(has_audio){ |
1834 case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame | 1818 case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame |
1835 case 3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame | 1819 case 3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
1836 default: ds_fill_buffer(d_audio); // skip PCM frame | 1820 default: ds_fill_buffer(d_audio); // skip PCM frame |
1837 } | 1821 } |
1838 } | 1822 } |
1867 } else { | 1851 } else { |
1868 vo_osd_text=NULL; | 1852 vo_osd_text=NULL; |
1869 } | 1853 } |
1870 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0; | 1854 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0; |
1871 // vo_osd_text=osd_text_buffer; | 1855 // vo_osd_text=osd_text_buffer; |
1872 | 1856 |
1873 // find sub | 1857 // find sub |
1874 if(subtitles){ | 1858 if(subtitles){ |
1875 if(sub_fps==0) sub_fps=sh_video->fps; | 1859 if(sub_fps==0) sub_fps=sh_video->fps; |
1876 find_sub(sub_uses_time?(100*(v_pts+sub_delay)):((v_pts+sub_delay)*sub_fps)); // FIXME! frame counter... | 1860 find_sub(sub_uses_time?(100*(v_pts+sub_delay)):((v_pts+sub_delay)*sub_fps)); // FIXME! frame counter... |
1877 } | 1861 } |