comparison mplayer.c @ 92:92776006958f

ACM code cleanup, nosound at ACM error
author arpi_esp
date Mon, 12 Mar 2001 01:09:35 +0000
parents 74064c2929a1
children 506d7560279c
comparison
equal deleted inserted replaced
91:315979891f2d 92:92776006958f
993 //================== MAIN: ========================== 993 //================== MAIN: ==========================
994 { 994 {
995 char* a_buffer=NULL; 995 char* a_buffer=NULL;
996 int a_buffer_len=0; 996 int a_buffer_len=0;
997 int a_buffer_size=0; 997 int a_buffer_size=0;
998 char* a_in_buffer=NULL;
999 int a_in_buffer_len=0;
1000 int a_in_buffer_size=0;
1001 int audio_fd=-1; 998 int audio_fd=-1;
1002 int pcm_bswap=0; 999 int pcm_bswap=0;
1003 float buffer_delay=0; 1000 float buffer_delay=0;
1004 float frame_correction=0; // A-V timestamp kulonbseg atlagolas 1001 float frame_correction=0; // A-V timestamp kulonbseg atlagolas
1005 int frame_corr_num=0; // 1002 int frame_corr_num=0; //
1056 if(has_audio==4){ 1053 if(has_audio==4){
1057 // Win32 ACM audio codec: 1054 // Win32 ACM audio codec:
1058 if(init_audio_codec()){ 1055 if(init_audio_codec()){
1059 MP3_channels=avi_header.wf.nChannels; 1056 MP3_channels=avi_header.wf.nChannels;
1060 MP3_samplerate=avi_header.wf.nSamplesPerSec; 1057 MP3_samplerate=avi_header.wf.nSamplesPerSec;
1061 a_in_buffer_size=avi_header.audio_in_minsize;
1062 a_in_buffer=malloc(a_in_buffer_size);
1063 a_in_buffer_len=0;
1064 if(a_buffer_size<avi_header.audio_out_minsize+OUTBURST) 1058 if(a_buffer_size<avi_header.audio_out_minsize+OUTBURST)
1065 a_buffer_size=avi_header.audio_out_minsize+OUTBURST; 1059 a_buffer_size=avi_header.audio_out_minsize+OUTBURST;
1066 } else { 1060 } else {
1067 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); 1061 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
1068 if((((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag)==0x55){ 1062 if((((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag)==0x55){
1075 1069
1076 // allocate audio out buffer: 1070 // allocate audio out buffer:
1077 a_buffer=malloc(a_buffer_size); 1071 a_buffer=malloc(a_buffer_size);
1078 memset(a_buffer,0,a_buffer_size); 1072 memset(a_buffer,0,a_buffer_size);
1079 a_buffer_len=0; 1073 a_buffer_len=0;
1074
1075 if(has_audio==4){
1076 int ret=acm_decode_audio(a_buffer,a_buffer_size);
1077 if(ret<0){
1078 printf("ACM error %d -> switching to nosound...\n",ret);
1079 has_audio=0;
1080 } else {
1081 a_buffer_len=ret;
1082 printf("ACM decoding test: %d bytes\n",ret);
1083 }
1084 }
1080 1085
1081 if(has_audio==2){ 1086 if(has_audio==2){
1082 if(file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_AVI_NI){ 1087 if(file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_AVI_NI){
1083 // AVI PCM Audio: 1088 // AVI PCM Audio:
1084 WAVEFORMATEX *h=(WAVEFORMATEX*)&avi_header.wf_ext; 1089 WAVEFORMATEX *h=(WAVEFORMATEX*)&avi_header.wf_ext;
1234 } 1239 }
1235 if(force_fps) default_fps=force_fps; 1240 if(force_fps) default_fps=force_fps;
1236 1241
1237 printf("Start playing...\n");fflush(stdout); 1242 printf("Start playing...\n");fflush(stdout);
1238 1243
1239 if(0) // ACM debug code 1244 #if 0
1245 // ACM debug code
1240 { DWORD srcsize=0; 1246 { DWORD srcsize=0;
1241 DWORD dstsize=16384*8; 1247 DWORD dstsize=16384*8;
1242 int ret=acmStreamSize(avi_header.srcstream,dstsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); 1248 int ret=acmStreamSize(avi_header.srcstream,dstsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
1243 printf("acmStreamSize %d -> %d (err=%d)\n",dstsize,srcsize,ret); 1249 printf("acmStreamSize %d -> %d (err=%d)\n",dstsize,srcsize,ret);
1244 } 1250 }
1251 #endif
1245 1252
1246 InitTimer(); 1253 InitTimer();
1247 1254
1248 while(!eof){ 1255 while(!eof){
1249 1256
1284 } 1291 }
1285 break; 1292 break;
1286 } 1293 }
1287 case 6: // MS-GSM decoder 1294 case 6: // MS-GSM decoder
1288 { unsigned char buf[65]; // 65 bytes / frame 1295 { unsigned char buf[65]; // 65 bytes / frame
1289 while(a_buffer_len<OUTBURST){ 1296 while(a_buffer_len<OUTBURST){
1290 if(demux_read_data(d_audio,buf,65)!=65) break; // EOF 1297 if(demux_read_data(d_audio,buf,65)!=65) break; // EOF
1291 XA_MSGSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 65 byte -> 320 short 1298 XA_MSGSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 65 byte -> 320 short
1292 // XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short 1299 // XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short
1293 a_buffer_len+=2*320; 1300 a_buffer_len+=2*320;
1294 } 1301 }
1295 break; 1302 break;
1296 } 1303 }
1297 case 3: // AC3 decoder 1304 case 3: // AC3 decoder
1298 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); 1305 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
1299 if(!ac3_frame) ac3_frame=ac3_decode_frame(); 1306 if(!ac3_frame) ac3_frame=ac3_decode_frame();
1304 ac3_frame=NULL; 1311 ac3_frame=NULL;
1305 } 1312 }
1306 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); 1313 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
1307 break; 1314 break;
1308 case 4: 1315 case 4:
1309 { ACMSTREAMHEADER ash; 1316 { int ret=acm_decode_audio(&a_buffer[a_buffer_len],a_buffer_size-a_buffer_len);
1310 HRESULT hr; 1317 if(ret>0) a_buffer_len+=ret;
1311 DWORD srcsize=0;
1312 acmStreamSize(avi_header.srcstream,a_buffer_size-a_buffer_len , &srcsize, ACM_STREAMSIZEF_DESTINATION);
1313 if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,a_in_buffer_size,a_buffer_size-a_buffer_len);
1314 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&avi_header.wf_ext)->nBlockAlign;
1315 if(srcsize>a_in_buffer_size) srcsize=a_in_buffer_size; // !!!!!!
1316 if(a_in_buffer_len<srcsize){
1317 a_in_buffer_len+=
1318 demux_read_data(d_audio,&a_in_buffer[a_in_buffer_len],
1319 srcsize-a_in_buffer_len);
1320 }
1321 memset(&ash, 0, sizeof(ash));
1322 ash.cbStruct=sizeof(ash);
1323 ash.fdwStatus=0;
1324 ash.dwUser=0;
1325 ash.pbSrc=a_in_buffer;
1326 ash.cbSrcLength=a_in_buffer_len;
1327 ash.pbDst=&a_buffer[a_buffer_len];
1328 ash.cbDstLength=a_buffer_size-a_buffer_len;
1329 hr=acmStreamPrepareHeader(avi_header.srcstream,&ash,0);
1330 if(hr){
1331 printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr);break;
1332 }
1333 hr=acmStreamConvert(avi_header.srcstream,&ash,0);
1334 if(hr){
1335 printf("ACM_Decoder: acmStreamConvert error %d\n",hr);break;
1336 }
1337 //printf("ACM convert %d -> %d (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len);
1338 if(ash.cbSrcLengthUsed>=a_in_buffer_len){
1339 a_in_buffer_len=0;
1340 } else {
1341 a_in_buffer_len-=ash.cbSrcLengthUsed;
1342 memcpy(a_in_buffer,&a_in_buffer[ash.cbSrcLengthUsed],a_in_buffer_len);
1343 }
1344 a_buffer_len+=ash.cbDstLengthUsed;
1345 hr=acmStreamUnprepareHeader(avi_header.srcstream,&ash,0);
1346 if(hr){
1347 printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr);
1348 }
1349 break; 1318 break;
1350 } 1319 }
1351 } 1320 }
1352 } 1321 }
1353 current_module=NULL; // Leave AUDIO decoder module 1322 current_module=NULL; // Leave AUDIO decoder module