From 2ba092874905669f0f8e8fda1b043c73e50db716 Mon Sep 17 00:00:00 2001 From: arpi_esp Date: Sun, 15 Apr 2001 03:40:37 +0000 Subject: [PATCH] new stream selection code git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@427 b3059339-0415-0410-9bf9-f77b7e298cf2 --- asfheader.c | 12 +++--- aviheader.c | 21 +++++++---- demux_asf.c | 24 +++++++----- demux_avi.c | 28 +++++++++++++- demux_mpg.c | 28 +++++++------- mplayer.c | 107 +++++++++++++++++++++++++++++++++++----------------- stheader.h | 1 + version.h | 2 +- 8 files changed, 149 insertions(+), 74 deletions(-) diff --git a/asfheader.c b/asfheader.c index f9ef236129..e1c4ef1e83 100644 --- a/asfheader.c +++ b/asfheader.c @@ -128,7 +128,7 @@ if(verbose){ stream_read(demuxer->stream,(char*) buffer,streamh.type_size); switch(*((unsigned int*)&streamh.type)){ case 0xF8699E40: { // guid_audio_stream - sh_audio_t *sh_audio=&sh_audio_i; // FIXME! + sh_audio_t* sh_audio=new_sh_audio(streamh.stream_no & 0x7F); memcpy(&sh_audio->wf,buffer,streamh.type_size<64?streamh.type_size:64); if(verbose>=1) print_wave_header((WAVEFORMATEX*)buffer); if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){ @@ -141,17 +141,17 @@ if(verbose){ asf_scrambling_b=asf_scrambling_h=asf_scrambling_w=1; } printf("ASF: audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b); - if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F; + //if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F; break; } case 0xBC19EFC0: { // guid_video_stream - sh_video_t *sh_video=&sh_video_i; // FIXME! + sh_video_t* sh_video=new_sh_video(streamh.stream_no & 0x7F); memcpy(&sh_video->bih,&buffer[4+4+1+2],sizeof(BITMAPINFOHEADER)); - sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; - sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; + //sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; + //sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; if(verbose>=1) print_video_header((BITMAPINFOHEADER*)&buffer[4+4+1+2]); //asf_video_id=streamh.stream_no & 0x7F; - if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; + //if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; break; } } diff --git a/aviheader.c b/aviheader.c index 215fbc1bce..f3c1f69776 100644 --- a/aviheader.c +++ b/aviheader.c @@ -2,7 +2,8 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) void read_avi_header(int no_index){ - +sh_audio_t *sh_audio=NULL; +sh_video_t *sh_video=NULL; int stream_id=-1; //---- AVI header: @@ -41,29 +42,33 @@ while(1){ AVIStreamHeader h; stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h))); chunksize-=MIN(size2,sizeof(h)); - if(h.fccType==streamtypeVIDEO) memcpy(&sh_video_i.video,&h,sizeof(h));else - if(h.fccType==streamtypeAUDIO) memcpy(&sh_audio_i.audio,&h,sizeof(h)); + ++stream_id; + if(h.fccType==streamtypeVIDEO){ + sh_video=new_sh_video(stream_id); + memcpy(&sh_video->video,&h,sizeof(h)); + } else + if(h.fccType==streamtypeAUDIO){ + sh_audio=new_sh_audio(stream_id); + memcpy(&sh_audio->audio,&h,sizeof(h)); + } last_fccType=h.fccType; if(verbose>=1) print_strh(&h); - ++stream_id; break; } case ckidSTREAMFORMAT: { // read 'strf' if(last_fccType==streamtypeVIDEO){ - sh_video_t *sh_video=&sh_video_i; // FIXME! stream_read(demuxer->stream,(char*) &sh_video->bih,MIN(size2,sizeof(sh_video->bih))); chunksize-=MIN(size2,sizeof(sh_video->bih)); sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; - if(demuxer->video->id==-1) demuxer->video->id=stream_id; +// if(demuxer->video->id==-1) demuxer->video->id=stream_id; } else if(last_fccType==streamtypeAUDIO){ - sh_audio_t *sh_audio=&sh_audio_i; // FIXME! int z=(chunksize<64)?chunksize:64; if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX)); stream_read(demuxer->stream,(char*) &sh_audio->wf,z); chunksize-=z; if(verbose>=1) print_wave_header(&sh_audio->wf); - if(demuxer->audio->id==-1) demuxer->audio->id=stream_id; +// if(demuxer->audio->id==-1) demuxer->audio->id=stream_id; } break; } diff --git a/demux_asf.c b/demux_asf.c index 5f30496eab..9d9fed7c8c 100644 --- a/demux_asf.c +++ b/demux_asf.c @@ -21,25 +21,29 @@ static int demux_asf_read_packet(demuxer_t *demux,unsigned char *data,int len,in if(verbose>=4) printf("demux_asf.read_packet: id=%d seq=%d len=%d\n",id,seq,len); -#if 0 - if(demux->video->id==-1) { - demux->video->id=asf_video_id; - if(verbose) printf("ASF video ID = %d\n",demux->video->id); - } + if(demux->video->id==-1) + if(avi_header.v_streams[id]) + demux->video->id=id; + if(demux->audio->id==-1) - if(id!=asf_video_id && id!=demux->video->id){ - demux->audio->id=id; - if(verbose) printf("ASF audio ID = %d\n",demux->audio->id); - } -#endif + if(avi_header.a_streams[id]) + demux->audio->id=id; if(id==demux->audio->id){ // audio ds=demux->audio; + if(!ds->sh){ + ds->sh=avi_header.a_streams[id]; + if(verbose) printf("Auto-selected ASF audio ID = %d\n",ds->id); + } } else if(id==demux->video->id){ // video ds=demux->video; + if(!ds->sh){ + ds->sh=avi_header.v_streams[id]; + if(verbose) printf("Auto-selected ASF video ID = %d\n",ds->id); + } } if(ds){ diff --git a/demux_avi.c b/demux_avi.c index 9a847fec23..3a1b564f4c 100644 --- a/demux_avi.c +++ b/demux_avi.c @@ -17,8 +17,32 @@ static inline int avi_stream_id(unsigned int id){ // Select ds from ID static inline demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){ int stream_id=avi_stream_id(id); - if(stream_id==demux->audio->id) return demux->audio; - if(stream_id==demux->video->id) return demux->video; + +// printf("demux_avi_select_stream(%d) {a:%d/v:%d}\n",stream_id, +// demux->audio->id,demux->video->id); + + if(demux->video->id==-1) + if(avi_header.v_streams[stream_id]) + demux->video->id=stream_id; + + if(demux->audio->id==-1) + if(avi_header.a_streams[stream_id]) + demux->audio->id=stream_id; + + if(stream_id==demux->audio->id){ + if(!demux->audio->sh){ + demux->audio->sh=avi_header.a_streams[stream_id]; + if(verbose) printf("Auto-selected AVI audio ID = %d\n",demux->audio->id); + } + return demux->audio; + } + if(stream_id==demux->video->id){ + if(!demux->video->sh){ + demux->video->sh=avi_header.v_streams[stream_id]; + if(verbose) printf("Auto-selected AVI video ID = %d\n",demux->video->id); + } + return demux->video; + } if(id!=mmioFOURCC('J','U','N','K')){ // unknown if(verbose>=2) printf("Unknown chunk: %.4s (%X)\n",&id,id); diff --git a/demux_mpg.c b/demux_mpg.c index ba7dd9f304..3b3e5fc804 100644 --- a/demux_mpg.c +++ b/demux_mpg.c @@ -83,19 +83,15 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ //============== DVD Audio sub-stream ====================== if(id==0x1BD){ - int aid=stream_read_char(demux->stream)&0x7F;--len; - ds=demux->audio; - if(ds->id==-1) ds->id=aid; - if(!dvdaudio_table[aid]){ - dvdaudio_table[aid]=1; - printf("DVD Audio format: %s ID=%d%s\n", - ((aid&0x70)==0x20)?"PCM":"AC3",aid,(ds->id==aid)?" CURRENT":""); - } + int aid=128+(stream_read_char(demux->stream)&0x7F);--len; if(len<3) return -1; // invalid audio packet - if(ds->id!=aid){ - // drop packet (not selected channel) - ds=NULL; - } else { + + if(!avi_header.a_streams[aid]) new_sh_audio(aid); + if(demux->audio->id==-1) demux->audio->id=aid; + + if(demux->audio->id==aid){ + ds=demux->audio; + if(!ds->sh) ds->sh=avi_header.a_streams[aid]; // READ Packet: Skip additional audio header data: c=stream_read_char(demux->stream); c=stream_read_char(demux->stream); @@ -130,17 +126,23 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ if(id>=0x1C0 && id<=0x1DF){ // mpeg audio int aid=id-0x1C0; + if(!avi_header.a_streams[aid]) new_sh_audio(aid); if(demux->audio->id==-1) demux->audio->id=aid; if(demux->audio->id==aid){ ds=demux->audio; + if(!ds->sh) ds->sh=avi_header.a_streams[aid]; if(ds->type==-1) ds->type=1; } } else if(id>=0x1E0 && id<=0x1EF){ // mpeg video int aid=id-0x1E0; + if(!avi_header.v_streams[aid]) new_sh_video(aid); if(demux->video->id==-1) demux->video->id=aid; - if(demux->video->id==aid) ds=demux->video; + if(demux->video->id==aid){ + ds=demux->video; + if(!ds->sh) ds->sh=avi_header.v_streams[aid]; + } } if(ds){ diff --git a/mplayer.c b/mplayer.c index 3e7fca5366..f0fd453349 100644 --- a/mplayer.c +++ b/mplayer.c @@ -154,12 +154,20 @@ char *get_path(char *filename){ static int max_framesize=0; -static int dbg_es_sent=0; -static int dbg_es_rcvd=0; +//static int dbg_es_sent=0; +//static int dbg_es_rcvd=0; //static int show_packets=0; //**************************************************************************// +//**************************************************************************// +// Input media streaming & demultiplexer: +//**************************************************************************// + +#include "stream.c" +#include "demuxer.c" + +#include "stheader.h" typedef struct { // file: @@ -173,6 +181,9 @@ typedef struct { int idx_pos_a; int idx_pos_v; int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez + // streams: + sh_audio_t* a_streams[256]; + sh_video_t* v_streams[256]; // video: unsigned int bitrate; } avi_header_t; @@ -181,20 +192,28 @@ avi_header_t avi_header; #include "aviprint.c" -extern picture_t *picture; +sh_audio_t* new_sh_audio(int id){ + if(avi_header.a_streams[id]){ + printf("Warning! Audio stream header %d redefined!\n",id); + } else { + if(verbose) printf("Found audio stream: %d\n",id); + avi_header.a_streams[id]=malloc(sizeof(sh_audio_t)); + memset(avi_header.a_streams[id],0,sizeof(sh_audio_t)); + } + return avi_header.a_streams[id]; +} -char* encode_name=NULL; -char* encode_index_name=NULL; -int encode_bitrate=0; +sh_video_t* new_sh_video(int id){ + if(avi_header.v_streams[id]){ + printf("Warning! video stream header %d redefined!\n",id); + } else { + if(verbose) printf("Found video stream: %d\n",id); + avi_header.v_streams[id]=malloc(sizeof(sh_video_t)); + memset(avi_header.v_streams[id],0,sizeof(sh_video_t)); + } + return avi_header.v_streams[id]; +} -//**************************************************************************// -// Input media streaming & demultiplexer: -//**************************************************************************// - -#include "stream.c" -#include "demuxer.c" - -#include "stheader.h" #include "demux_avi.c" #include "demux_mpg.c" @@ -203,14 +222,18 @@ demuxer_t *demuxer=NULL; demux_stream_t *d_audio=NULL; demux_stream_t *d_video=NULL; -sh_audio_t sh_audio_i; // FIXME later! -sh_video_t sh_video_i; -sh_audio_t *sh_audio=&sh_audio_i; -sh_video_t *sh_video=&sh_video_i; +sh_audio_t *sh_audio=NULL;//&sh_audio_i; +sh_video_t *sh_video=NULL;//&sh_video_i; + +char* encode_name=NULL; +char* encode_index_name=NULL; +int encode_bitrate=0; // MPEG video stream parser: #include "parse_es.c" +extern picture_t *picture; + static const int frameratecode2framerate[16] = { 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000, 0,0,0,0,0,0,0 @@ -349,6 +372,7 @@ void exit_sighandler(int x){ } int divx_quality=0; +extern int vo_dbpp; int main(int argc,char* argv[], char *envp[]){ char* filename=NULL; //"MI2-Trailer.avi"; @@ -406,7 +430,7 @@ char *sub_name=NULL; float sub_delay=0; float sub_fps=0; //int user_bpp=0; -extern int vo_dbpp; + #include "cfg-mplayer.h" printf("%s",banner_text); @@ -594,8 +618,10 @@ if(file_format==DEMUXER_TYPE_UNKNOWN){ //====== File format recognized, set up these for compatibility: ========= d_audio=demuxer->audio; d_video=demuxer->video; -d_audio->sh=sh_audio; sh_audio->ds=d_audio; -d_video->sh=sh_video; sh_video->ds=d_video; +//d_audio->sh=sh_audio; +//d_video->sh=sh_video; +//sh_audio=d_audio->sh;sh_audio->ds=d_audio; +//sh_video=d_video->sh;sh_video->ds=d_video; switch(file_format){ case DEMUXER_TYPE_AVI: { @@ -662,12 +688,17 @@ switch(file_format){ printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); exit(1); } + sh_video=d_video->sh;sh_video->ds=d_video; if(has_audio){ - if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); + if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id); if(!ds_fill_buffer(d_audio)){ - printf("ASF: No Audio stream found... ->nosound\n"); + printf("AVI: No Audio stream found... ->nosound\n"); has_audio=0; - } else sh_audio->format=sh_audio->wf.wFormatTag; + sh_audio=NULL; + } else { + sh_audio=d_audio->sh;sh_audio->ds=d_audio; + sh_audio->format=sh_audio->wf.wFormatTag; + } } // calc. FPS: sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; @@ -698,12 +729,17 @@ switch(file_format){ printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); exit(1); } + sh_video=d_video->sh;sh_video->ds=d_video; if(has_audio){ if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); if(!ds_fill_buffer(d_audio)){ printf("ASF: No Audio stream found... ->nosound\n"); has_audio=0; - } else sh_audio->format=sh_audio->wf.wFormatTag; + sh_audio=NULL; + } else { + sh_audio=d_audio->sh;sh_audio->ds=d_audio; + sh_audio->format=sh_audio->wf.wFormatTag; + } } sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms printf("VIDEO: [%.4s] %dx%d %dbpp\n", @@ -714,16 +750,17 @@ switch(file_format){ break; } case DEMUXER_TYPE_MPEG_ES: { - demuxer->audio->type=0; - has_audio=0; // ES streams has no audio channel + d_audio->type=0; + has_audio=0;sh_audio=NULL; // ES streams has no audio channel break; } case DEMUXER_TYPE_MPEG_PS: { if(has_audio) if(!ds_fill_buffer(d_audio)){ printf("MPEG: No Audio stream found... ->nosound\n"); - has_audio=0; + has_audio=0;sh_audio=NULL; } else { + sh_audio=d_audio->sh;sh_audio->ds=d_audio; if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type); switch(d_audio->type){ case 1: sh_audio->format=0x50;break; // mpeg @@ -760,6 +797,7 @@ switch(file_format){ } } if(verbose) printf("OK!\n"); + sh_video=d_video->sh;sh_video->ds=d_video; sh_video->format=1; // mpeg video mpeg2_init(); // ========= Read & process sequence header & extension ============ @@ -1440,12 +1478,12 @@ switch(sh_video->codec->driver){ if(x> max_pts_correction) x= max_pts_correction; max_pts_correction=default_max_pts_correction; a_frame+=x; c_total+=x; - printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% %d \r",c_total, + printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% \r",c_total, (int)num_frames, (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, - (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, - dbg_es_sent-dbg_es_rcvd + (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 +// dbg_es_sent-dbg_es_rcvd ); fflush(stdout); } @@ -1457,12 +1495,13 @@ switch(sh_video->codec->driver){ if(d_video->pts) v_pts=d_video->pts; if(frame_corr_num==5){ // printf("A: --- V:%6.1f \r",v_pts); - printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% %d \r",v_pts, + printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts, (int)num_frames, (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, - (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0, - dbg_es_sent-dbg_es_rcvd); + (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 +// dbg_es_sent-dbg_es_rcvd + ); fflush(stdout); frame_corr_num=0; diff --git a/stheader.h b/stheader.h index ae81709a9b..68b059953b 100644 --- a/stheader.h +++ b/stheader.h @@ -57,3 +57,4 @@ typedef struct { HIC hic; // handle } sh_video_t; + diff --git a/version.h b/version.h index a1155d66d4..d11d7aef43 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "0.11pre-cvs" +#define VERSION "0.11cvs-010415-00:56"