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