annotate libmpcodecs/dec_audio.c @ 7522:aa1a1249f239

-ac/-afm rewrite, now works the same way as -vc/-vfm including audio codec fallbacks if init failed
author arpi
date Sat, 28 Sep 2002 02:23:20 +0000
parents 6a2b6f3d619c
children 047212009a7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
1 #include <stdio.h>
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
2 #include <stdlib.h>
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
3 #include <unistd.h>
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
4
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
5 #include "config.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
6 #include "mp_msg.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
7 #include "help_mp.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
8
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
9 extern int verbose; // defined in mplayer.c
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
10
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
11 #include "stream.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
12 #include "demuxer.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
13
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
14 #include "codec-cfg.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
15 #include "stheader.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
16
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
17 #include "dec_audio.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
18 #include "ad.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
19 #include "../libao2/afmt.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
20
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
21 #ifdef USE_FAKE_MONO
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
22 int fakemono=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
23 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
24 /* used for ac3surround decoder - set using -channels option */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
25 int audio_output_channels = 2;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
26
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
27 static ad_functions_t* mpadec;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
28
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
29 void afm_help(){
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
30 int i;
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
31 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_AvailableAudioFm);
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
32 mp_msg(MSGT_DECAUDIO,MSGL_INFO," afm: info: (comment)\n");
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
33 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++)
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
34 if(mpcodecs_ad_drivers[i]->info->comment && mpcodecs_ad_drivers[i]->info->comment[0])
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
35 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"%9s %s (%s)\n",
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
36 mpcodecs_ad_drivers[i]->info->short_name,
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
37 mpcodecs_ad_drivers[i]->info->name,
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
38 mpcodecs_ad_drivers[i]->info->comment);
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
39 else
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
40 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"%9s %s\n",
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
41 mpcodecs_ad_drivers[i]->info->short_name,
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
42 mpcodecs_ad_drivers[i]->info->name);
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
43 }
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
44
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
45 int init_audio_codec(sh_audio_t *sh_audio)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
46 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
47 unsigned i;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
48
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
49 // reset in/out buffer size/pointer:
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
50 sh_audio->a_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
51 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
52 sh_audio->a_in_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
53 sh_audio->a_in_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
54
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
55 // Set up some common usefull defaults. ad->preinit() can override these:
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
56
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
57 sh_audio->samplesize=2;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
58 #ifdef WORDS_BIGENDIAN
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
59 sh_audio->sample_format=AFMT_S16_BE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
60 #else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
61 sh_audio->sample_format=AFMT_S16_LE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
62 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
63 sh_audio->samplerate=0;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
64 sh_audio->i_bps=0; // input rate (bytes/sec)
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
65 sh_audio->o_bps=0; // output rate (bytes/sec)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
66
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
67 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
68 sh_audio->audio_in_minsize=0;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
69
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
70 if(!mpadec->preinit(sh_audio))
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
71 {
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
72 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
73 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
74 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
75
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
76 /* allocate audio in buffer: */
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
77 if(sh_audio->audio_in_minsize>0){
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
78 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
79 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer,
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
80 sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
81 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
82 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
83 sh_audio->a_in_buffer_len=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
84 }
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
85
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
86 /* allocate audio out buffer: */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
87 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
88
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
89 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer,
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
90 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
91
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
92 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
93 if(!sh_audio->a_buffer){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
94 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
95 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
96 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
97 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
98 sh_audio->a_buffer_len=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
99
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
100 if(!mpadec->init(sh_audio)){
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
101 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
102 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
103 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
104 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
105
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
106 sh_audio->inited=1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
107
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
108 if(!sh_audio->channels || !sh_audio->samplerate){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
109 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
110 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
111 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
112 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
113
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
114 if(!sh_audio->o_bps)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
115 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
116
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
117 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, sfmt: 0x%X (%d bps), ratio: %d->%d (%3.1f kbit)\n",
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
118 sh_audio->samplerate,sh_audio->channels,
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
119 sh_audio->sample_format,sh_audio->samplesize,
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
120 sh_audio->i_bps,sh_audio->o_bps,sh_audio->i_bps*8*0.001);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
121
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
122 return 1;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
123 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
124
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
125 int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
126 unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
127 sh_audio->codec=NULL;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
128 while(1){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
129 int i;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
130 // restore original fourcc:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
131 if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
132 if(!(sh_audio->codec=find_codec(sh_audio->format,
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
133 sh_audio->wf?(&i):NULL, sh_audio->codec,1) )) break;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
134 if(sh_audio->wf) sh_audio->wf->wFormatTag=i;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
135 // ok we found one codec
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
136 if(sh_audio->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
137 if(codecname && strcmp(sh_audio->codec->name,codecname)) continue; // -ac
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
138 if(afm && strcmp(sh_audio->codec->drv,afm)) continue; // afm doesn't match
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
139 if(sh_audio->codec->status<status) continue; // too unstable
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
140 sh_audio->codec->flags|=CODECS_FLAG_SELECTED; // tagging it
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
141 // ok, it matches all rules, let's find the driver!
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
142 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
143 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)) break;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
144 mpadec=mpcodecs_ad_drivers[i];
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
145 if(!mpadec){ // driver not available (==compiled in)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
146 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr,
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
147 sh_audio->codec->name, sh_audio->codec->drv);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
148 continue;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
149 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
150 // it's available, let's try to init!
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
151 // init()
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
152 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
153 if(!init_audio_codec(sh_audio)){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
154 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ADecoderInitFailed);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
155 continue; // try next...
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
156 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
157 // Yeah! We got it!
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
158 return 1;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
159 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
160 return 0;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
161 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
162
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
163 int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
164 char* ac_l_default[2]={"",(char*)NULL};
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
165 // hack:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
166 if(!audio_codec_list) audio_codec_list=ac_l_default;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
167 // Go through the codec.conf and find the best codec...
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
168 sh_audio->inited=0;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
169 codecs_reset_selection(1);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
170 while(!sh_audio->inited && *audio_codec_list){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
171 char* audio_codec=*(audio_codec_list++);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
172 if(audio_codec[0]){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
173 if(audio_codec[0]=='-'){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
174 // disable this codec:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
175 select_codec(audio_codec+1,1);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
176 } else {
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
177 // forced codec by name:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
178 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ForcedAudioCodec,audio_codec);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
179 init_audio(sh_audio,audio_codec,NULL,-1);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
180 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
181 } else {
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
182 int status;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
183 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING.
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
184 if(audio_fm_list){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
185 char** fmlist=audio_fm_list;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
186 // try first the preferred codec families:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
187 while(!sh_audio->inited && *fmlist){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
188 char* audio_fm=*(fmlist++);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
189 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
190 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
191 if(init_audio(sh_audio,NULL,audio_fm,status)) break;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
192 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
193 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
194 if(!sh_audio->inited)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
195 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
196 if(init_audio(sh_audio,NULL,NULL,status)) break;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
197 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
198 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
199
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
200 if(!sh_audio->inited){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
201 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf"));
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
202 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
203 return 0; // failed
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
204 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
205
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
206 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Selected audio codec: [%s] afm:%s (%s)\n",
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
207 sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
208 return 1; // success
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
209 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
210
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
211
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
212 int init_best_audio_codec_old(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm){
7502
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
213 // Go through the codec.conf and find the best codec...
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
214 sh_audio->codec=NULL;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
215 if(audio_fm) mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
216 while(1){
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
217 sh_audio->codec=find_codec(sh_audio->format,NULL,sh_audio->codec,1);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
218 if(!sh_audio->codec){
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
219 if(audio_fm) {
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
220 sh_audio->codec=NULL; /* re-search */
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
221 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAfmtFallback);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
222 audio_fm=NULL;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
223 continue;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
224 }
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
225 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
226 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf"));
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
227 return 0;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
228 }
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
229 if(audio_codec && strcmp(sh_audio->codec->name,audio_codec)) continue;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
230 if(audio_fm && strcmp(sh_audio->codec->drv,audio_fm)) continue;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
231 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"%s audio codec: [%s] afm:%s (%s)\n",
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
232 audio_codec?mp_gettext("Forcing"):mp_gettext("Detected"),sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
233 break;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
234 }
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
235 // found it...
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
236 if(!init_audio_codec(sh_audio)){
7502
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
237 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CouldntInitAudioCodec);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
238 return 0;
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
239 }
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
240 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, sfmt: 0x%X (%d bps), ratio: %d->%d (%3.1f kbit)\n",
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
241 sh_audio->samplerate,sh_audio->channels,
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
242 sh_audio->sample_format,sh_audio->samplesize,
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
243 sh_audio->i_bps,sh_audio->o_bps,sh_audio->i_bps*8*0.001);
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
244 return 1; // success!
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
245 }
6a2b6f3d619c best audio/video codec selection & init moved to libmpcodecs
arpi
parents: 7240
diff changeset
246
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
247 void uninit_audio(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
248 {
7240
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
249 if(sh_audio->inited){
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
250 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv);
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
251 mpadec->uninit(sh_audio);
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
252 sh_audio->inited=0;
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
253 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
254 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
255 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
256 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
257 sh_audio->a_in_buffer=NULL;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
258 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
259
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
260 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
261 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
262 if(sh_audio->inited)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
263 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
264 else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
265 return -1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
266 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
267
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
268 void resync_audio_stream(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
269 {
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
270 sh_audio->a_in_buffer_len=0; // clear audio input buffer
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
271 if(!sh_audio->inited) return;
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
272 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
273 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
274
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
275 void skip_audio_frame(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
276 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
277 if(!sh_audio->inited) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
278 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
279 // default skip code:
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
280 ds_fill_buffer(sh_audio->ds); // skip block
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
281 }