comparison mplayer.c @ 426:26e513f392b2

new stream selection code
author arpi_esp
date Sun, 15 Apr 2001 03:40:37 +0000
parents ca9c8ca4fe67
children c106cb97db06
comparison
equal deleted inserted replaced
425:ca9c8ca4fe67 426:26e513f392b2
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"
163 171
164 typedef struct { 172 typedef struct {
165 // file: 173 // file:
166 MainAVIHeader avih; 174 MainAVIHeader avih;
167 unsigned int movi_start; 175 unsigned int movi_start;
171 int idx_size; 179 int idx_size;
172 int idx_pos; 180 int idx_pos;
173 int idx_pos_a; 181 int idx_pos_a;
174 int idx_pos_v; 182 int idx_pos_v;
175 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez 183 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];
176 // video: 187 // video:
177 unsigned int bitrate; 188 unsigned int bitrate;
178 } avi_header_t; 189 } avi_header_t;
179 190
180 avi_header_t avi_header; 191 avi_header_t avi_header;
181 192
182 #include "aviprint.c" 193 #include "aviprint.c"
183 194
184 extern picture_t *picture; 195 sh_audio_t* new_sh_audio(int id){
196 if(avi_header.a_streams[id]){
197 printf("Warning! Audio stream header %d redefined!\n",id);
198 } else {
199 if(verbose) printf("Found audio stream: %d\n",id);
200 avi_header.a_streams[id]=malloc(sizeof(sh_audio_t));
201 memset(avi_header.a_streams[id],0,sizeof(sh_audio_t));
202 }
203 return avi_header.a_streams[id];
204 }
205
206 sh_video_t* new_sh_video(int id){
207 if(avi_header.v_streams[id]){
208 printf("Warning! video stream header %d redefined!\n",id);
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
218 #include "demux_avi.c"
219 #include "demux_mpg.c"
220
221 demuxer_t *demuxer=NULL;
222 demux_stream_t *d_audio=NULL;
223 demux_stream_t *d_video=NULL;
224
225 sh_audio_t *sh_audio=NULL;//&sh_audio_i;
226 sh_video_t *sh_video=NULL;//&sh_video_i;
185 227
186 char* encode_name=NULL; 228 char* encode_name=NULL;
187 char* encode_index_name=NULL; 229 char* encode_index_name=NULL;
188 int encode_bitrate=0; 230 int encode_bitrate=0;
189 231
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: 232 // MPEG video stream parser:
212 #include "parse_es.c" 233 #include "parse_es.c"
234
235 extern picture_t *picture;
213 236
214 static const int frameratecode2framerate[16] = { 237 static const int frameratecode2framerate[16] = {
215 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 238 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 239 60*10000, 0,0,0,0,0,0,0
217 }; 240 };
347 ); 370 );
348 exit_player(NULL); 371 exit_player(NULL);
349 } 372 }
350 373
351 int divx_quality=0; 374 int divx_quality=0;
375 extern int vo_dbpp;
352 376
353 int main(int argc,char* argv[], char *envp[]){ 377 int main(int argc,char* argv[], char *envp[]){
354 char* filename=NULL; //"MI2-Trailer.avi"; 378 char* filename=NULL; //"MI2-Trailer.avi";
355 int i; 379 int i;
356 int seek_to_sec=0; 380 int seek_to_sec=0;
404 float font_factor=0.75; 428 float font_factor=0.75;
405 char *sub_name=NULL; 429 char *sub_name=NULL;
406 float sub_delay=0; 430 float sub_delay=0;
407 float sub_fps=0; 431 float sub_fps=0;
408 //int user_bpp=0; 432 //int user_bpp=0;
409 extern int vo_dbpp; 433
410 #include "cfg-mplayer.h" 434 #include "cfg-mplayer.h"
411 435
412 printf("%s",banner_text); 436 printf("%s",banner_text);
413 437
414 if (parse_config_file(conf, "/etc/mplayer.conf") < 0) 438 if (parse_config_file(conf, "/etc/mplayer.conf") < 0)
592 exit(1); 616 exit(1);
593 } 617 }
594 //====== File format recognized, set up these for compatibility: ========= 618 //====== File format recognized, set up these for compatibility: =========
595 d_audio=demuxer->audio; 619 d_audio=demuxer->audio;
596 d_video=demuxer->video; 620 d_video=demuxer->video;
597 d_audio->sh=sh_audio; sh_audio->ds=d_audio; 621 //d_audio->sh=sh_audio;
598 d_video->sh=sh_video; sh_video->ds=d_video; 622 //d_video->sh=sh_video;
623 //sh_audio=d_audio->sh;sh_audio->ds=d_audio;
624 //sh_video=d_video->sh;sh_video->ds=d_video;
599 625
600 switch(file_format){ 626 switch(file_format){
601 case DEMUXER_TYPE_AVI: { 627 case DEMUXER_TYPE_AVI: {
602 //---- AVI header: 628 //---- AVI header:
603 read_avi_header(no_index); 629 read_avi_header(no_index);
660 } 686 }
661 if(!ds_fill_buffer(d_video)){ 687 if(!ds_fill_buffer(d_video)){
662 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); 688 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n");
663 exit(1); 689 exit(1);
664 } 690 }
691 sh_video=d_video->sh;sh_video->ds=d_video;
665 if(has_audio){ 692 if(has_audio){
666 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); 693 if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id);
667 if(!ds_fill_buffer(d_audio)){ 694 if(!ds_fill_buffer(d_audio)){
668 printf("ASF: No Audio stream found... ->nosound\n"); 695 printf("AVI: No Audio stream found... ->nosound\n");
669 has_audio=0; 696 has_audio=0;
670 } else sh_audio->format=sh_audio->wf.wFormatTag; 697 sh_audio=NULL;
698 } else {
699 sh_audio=d_audio->sh;sh_audio->ds=d_audio;
700 sh_audio->format=sh_audio->wf.wFormatTag;
701 }
671 } 702 }
672 // calc. FPS: 703 // calc. FPS:
673 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; 704 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
674 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; 705 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
675 // calculating video bitrate: 706 // calculating video bitrate:
696 demuxer->endpos=avi_header.movi_end; 727 demuxer->endpos=avi_header.movi_end;
697 if(!ds_fill_buffer(d_video)){ 728 if(!ds_fill_buffer(d_video)){
698 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); 729 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
699 exit(1); 730 exit(1);
700 } 731 }
732 sh_video=d_video->sh;sh_video->ds=d_video;
701 if(has_audio){ 733 if(has_audio){
702 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); 734 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id);
703 if(!ds_fill_buffer(d_audio)){ 735 if(!ds_fill_buffer(d_audio)){
704 printf("ASF: No Audio stream found... ->nosound\n"); 736 printf("ASF: No Audio stream found... ->nosound\n");
705 has_audio=0; 737 has_audio=0;
706 } else sh_audio->format=sh_audio->wf.wFormatTag; 738 sh_audio=NULL;
739 } else {
740 sh_audio=d_audio->sh;sh_audio->ds=d_audio;
741 sh_audio->format=sh_audio->wf.wFormatTag;
742 }
707 } 743 }
708 sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms 744 sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms
709 printf("VIDEO: [%.4s] %dx%d %dbpp\n", 745 printf("VIDEO: [%.4s] %dx%d %dbpp\n",
710 &sh_video->bih.biCompression, 746 &sh_video->bih.biCompression,
711 sh_video->bih.biWidth, 747 sh_video->bih.biWidth,
712 sh_video->bih.biHeight, 748 sh_video->bih.biHeight,
713 sh_video->bih.biBitCount); 749 sh_video->bih.biBitCount);
714 break; 750 break;
715 } 751 }
716 case DEMUXER_TYPE_MPEG_ES: { 752 case DEMUXER_TYPE_MPEG_ES: {
717 demuxer->audio->type=0; 753 d_audio->type=0;
718 has_audio=0; // ES streams has no audio channel 754 has_audio=0;sh_audio=NULL; // ES streams has no audio channel
719 break; 755 break;
720 } 756 }
721 case DEMUXER_TYPE_MPEG_PS: { 757 case DEMUXER_TYPE_MPEG_PS: {
722 if(has_audio) 758 if(has_audio)
723 if(!ds_fill_buffer(d_audio)){ 759 if(!ds_fill_buffer(d_audio)){
724 printf("MPEG: No Audio stream found... ->nosound\n"); 760 printf("MPEG: No Audio stream found... ->nosound\n");
725 has_audio=0; 761 has_audio=0;sh_audio=NULL;
726 } else { 762 } else {
763 sh_audio=d_audio->sh;sh_audio->ds=d_audio;
727 if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type); 764 if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type);
728 switch(d_audio->type){ 765 switch(d_audio->type){
729 case 1: sh_audio->format=0x50;break; // mpeg 766 case 1: sh_audio->format=0x50;break; // mpeg
730 case 2: sh_audio->format=0x10001;break; // dvd pcm 767 case 2: sh_audio->format=0x10001;break; // dvd pcm
731 case 3: sh_audio->format=0x2000;break; // ac3 768 case 3: sh_audio->format=0x2000;break; // ac3
758 printf("MPEG: FATAL: EOF while searching for sequence header\n"); 795 printf("MPEG: FATAL: EOF while searching for sequence header\n");
759 exit(1); 796 exit(1);
760 } 797 }
761 } 798 }
762 if(verbose) printf("OK!\n"); 799 if(verbose) printf("OK!\n");
800 sh_video=d_video->sh;sh_video->ds=d_video;
763 sh_video->format=1; // mpeg video 801 sh_video->format=1; // mpeg video
764 mpeg2_init(); 802 mpeg2_init();
765 // ========= Read & process sequence header & extension ============ 803 // ========= Read & process sequence header & extension ============
766 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); 804 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE);
767 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);} 805 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);}
1438 x*=0.5f; 1476 x*=0.5f;
1439 if(x<-max_pts_correction) x=-max_pts_correction; else 1477 if(x<-max_pts_correction) x=-max_pts_correction; else
1440 if(x> max_pts_correction) x= max_pts_correction; 1478 if(x> max_pts_correction) x= max_pts_correction;
1441 max_pts_correction=default_max_pts_correction; 1479 max_pts_correction=default_max_pts_correction;
1442 a_frame+=x; c_total+=x; 1480 a_frame+=x; c_total+=x;
1443 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% %d \r",c_total, 1481 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% \r",c_total,
1444 (int)num_frames, 1482 (int)num_frames,
1445 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, 1483 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
1446 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, 1484 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
1447 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, 1485 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0
1448 dbg_es_sent-dbg_es_rcvd 1486 // dbg_es_sent-dbg_es_rcvd
1449 ); 1487 );
1450 fflush(stdout); 1488 fflush(stdout);
1451 } 1489 }
1452 frame_corr_num=0; frame_correction=0; 1490 frame_corr_num=0; frame_correction=0;
1453 } 1491 }
1455 } else { 1493 } else {
1456 // No audio: 1494 // No audio:
1457 if(d_video->pts) v_pts=d_video->pts; 1495 if(d_video->pts) v_pts=d_video->pts;
1458 if(frame_corr_num==5){ 1496 if(frame_corr_num==5){
1459 // printf("A: --- V:%6.1f \r",v_pts); 1497 // printf("A: --- V:%6.1f \r",v_pts);
1460 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% %d \r",v_pts, 1498 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts,
1461 (int)num_frames, 1499 (int)num_frames,
1462 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, 1500 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
1463 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, 1501 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
1464 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, 1502 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0
1465 dbg_es_sent-dbg_es_rcvd); 1503 // dbg_es_sent-dbg_es_rcvd
1504 );
1466 1505
1467 fflush(stdout); 1506 fflush(stdout);
1468 frame_corr_num=0; 1507 frame_corr_num=0;
1469 } 1508 }
1470 } 1509 }