annotate libmpcodecs/dec_audio.c @ 8169:7c9253521f9c

A struct setter. It allow you to setup struct from some user settings.
author albeu
date Tue, 12 Nov 2002 14:16:30 +0000
parents e8832e66babd
children a892e5f051e1
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 #include "stream.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
10 #include "demuxer.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
11
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
12 #include "codec-cfg.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
13 #include "stheader.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
14
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
15 #include "dec_audio.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
16 #include "ad.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
17 #include "../libao2/afmt.h"
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
18
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
19 #include "../libaf/af.h"
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
20
8152
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
21 #ifdef DYNAMIC_PLUGINS
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
22 #include <dlfcn.h>
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
23 #endif
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
24
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
25 #ifdef USE_FAKE_MONO
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
26 int fakemono=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
27 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
28 /* used for ac3surround decoder - set using -channels option */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
29 int audio_output_channels = 2;
7614
ce6a938aa6d3 Adding -format and -af switches
anders
parents: 7604
diff changeset
30 af_cfg_t af_cfg; // Configuration for audio filters
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
31
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
32 static ad_functions_t* mpadec;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
33
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
34 void afm_help(){
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
35 int i;
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
36 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
37 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
38 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
39 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
40 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
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 mpcodecs_ad_drivers[i]->info->comment);
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
44 else
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
45 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
46 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
47 mpcodecs_ad_drivers[i]->info->name);
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
48 }
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
49
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
50 int init_audio_codec(sh_audio_t *sh_audio)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
51 {
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
52
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
53 // reset in/out buffer size/pointer:
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
54 sh_audio->a_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
55 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
56 sh_audio->a_in_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
57 sh_audio->a_in_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
58
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
59 // Set up some common usefull defaults. ad->preinit() can override these:
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
60
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
61 sh_audio->samplesize=2;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
62 #ifdef WORDS_BIGENDIAN
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
63 sh_audio->sample_format=AFMT_S16_BE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
64 #else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
65 sh_audio->sample_format=AFMT_S16_LE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
66 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
67 sh_audio->samplerate=0;
7669
0b3b1cbebd99 reset channels too
arpi
parents: 7614
diff changeset
68 sh_audio->channels=0;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
69 sh_audio->i_bps=0; // input rate (bytes/sec)
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
70 sh_audio->o_bps=0; // output rate (bytes/sec)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
71
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
72 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
73 sh_audio->audio_in_minsize=0;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
74
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
75 if(!mpadec->preinit(sh_audio))
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
76 {
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
77 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
78 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
79 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
80
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
81 /* allocate audio in buffer: */
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
82 if(sh_audio->audio_in_minsize>0){
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
83 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
84 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer,
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
85 sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
86 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
87 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
88 sh_audio->a_in_buffer_len=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
89 }
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
90
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
91 /* allocate audio out buffer: */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
92 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
93
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
94 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer,
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
95 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
96
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
97 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
98 if(!sh_audio->a_buffer){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
99 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
100 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
101 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
102 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
103 sh_audio->a_buffer_len=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
104
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
105 if(!mpadec->init(sh_audio)){
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
106 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
107 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
108 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
109 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
110
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
111 sh_audio->inited=1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
112
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
113 if(!sh_audio->channels || !sh_audio->samplerate){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
114 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
115 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
116 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
117 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
118
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
119 if(!sh_audio->o_bps)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
120 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
121
7561
047212009a7f removed obsolote func, some cosmetics of AUDIO: msg
arpi
parents: 7522
diff changeset
122 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, %d bit (0x%X), ratio: %d->%d (%3.1f kbit)\n",
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
123 sh_audio->samplerate,sh_audio->channels,
7561
047212009a7f removed obsolote func, some cosmetics of AUDIO: msg
arpi
parents: 7522
diff changeset
124 sh_audio->samplesize*8,sh_audio->sample_format,
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
125 sh_audio->i_bps,sh_audio->o_bps,sh_audio->i_bps*8*0.001);
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
126
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
127 sh_audio->a_out_buffer_size=sh_audio->a_buffer_size;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
128 sh_audio->a_out_buffer=sh_audio->a_buffer;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
129 sh_audio->a_out_buffer_len=sh_audio->a_buffer_len;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
130
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
131 return 1;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
132 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
133
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
134 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
135 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
136 sh_audio->codec=NULL;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
137 while(1){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
138 int i;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
139 // restore original fourcc:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
140 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
141 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
142 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
143 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
144 // ok we found one codec
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
145 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
146 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
147 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
148 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
149 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
150 // 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
151 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
152 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
153 mpadec=mpcodecs_ad_drivers[i];
8152
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
154 #ifdef DYNAMIC_PLUGINS
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
155 if (!mpadec)
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
156 {
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
157 /* try to open shared decoder plugin */
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
158 int buf_len;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
159 char *buf;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
160 ad_functions_t *funcs_sym;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
161 ad_info_t *info_sym;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
162
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
163 buf_len = strlen(LIBDIR)+strlen(sh_audio->codec->drv)+16;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
164 buf = malloc(buf_len);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
165 if (!buf)
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
166 break;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
167 snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", LIBDIR, sh_audio->codec->drv);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
168 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
169 sh_audio->dec_handle = dlopen(buf, RTLD_LAZY);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
170 if (!sh_audio->dec_handle)
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
171 break;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
172 snprintf(buf, buf_len, "mpcodecs_ad_%s", sh_audio->codec->drv);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
173 funcs_sym = dlsym(sh_audio->dec_handle, buf);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
174 if (!funcs_sym || !funcs_sym->info || !funcs_sym->preinit ||
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
175 !funcs_sym->init || !funcs_sym->uninit || !funcs_sym->control ||
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
176 !funcs_sym->decode_audio)
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
177 break;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
178 info_sym = funcs_sym->info;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
179 if (strcmp(info_sym->short_name, sh_audio->codec->drv))
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
180 break;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
181 free(buf);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
182 mpadec = funcs_sym;
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
183 mp_msg(MSGT_DECAUDIO, MSGL_V, "Using external decoder plugin (%s/mplayer/ad_%s.so)!\n",
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
184 LIBDIR, sh_audio->codec->drv);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
185 }
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
186 #endif
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
187 if(!mpadec){ // driver not available (==compiled in)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
188 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
189 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
190 continue;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
191 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
192 // 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
193 // init()
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
194 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
195 if(!init_audio_codec(sh_audio)){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
196 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
197 continue; // try next...
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 // Yeah! We got it!
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
200 return 1;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
201 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
202 return 0;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
203 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
204
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 8027
diff changeset
205 extern char *get_path(char *filename);
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 8027
diff changeset
206
7522
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
207 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
208 char* ac_l_default[2]={"",(char*)NULL};
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
209 // hack:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
210 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
211 // 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
212 sh_audio->inited=0;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
213 codecs_reset_selection(1);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
214 while(!sh_audio->inited && *audio_codec_list){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
215 char* audio_codec=*(audio_codec_list++);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
216 if(audio_codec[0]){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
217 if(audio_codec[0]=='-'){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
218 // disable this codec:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
219 select_codec(audio_codec+1,1);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
220 } else {
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
221 // forced codec by name:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
222 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
223 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
224 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
225 } else {
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
226 int status;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
227 // 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
228 if(audio_fm_list){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
229 char** fmlist=audio_fm_list;
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
230 // try first the preferred codec families:
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
231 while(!sh_audio->inited && *fmlist){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
232 char* audio_fm=*(fmlist++);
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
233 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
234 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
235 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
236 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
237 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
238 if(!sh_audio->inited)
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
239 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
240 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
241 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
242 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
243
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
244 if(!sh_audio->inited){
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
245 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
246 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
247 return 0; // failed
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
248 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
249
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
250 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
251 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
252 return 1; // success
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
253 }
aa1a1249f239 -ac/-afm rewrite, now works the same way as -vc/-vfm
arpi
parents: 7502
diff changeset
254
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
255 void uninit_audio(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
256 {
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
257 if(sh_audio->afilter){
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
258 mp_msg(MSGT_DECAUDIO,MSGL_V,"Uninit audio filters...\n");
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
259 af_uninit(sh_audio->afilter);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
260 sh_audio->afilter=NULL;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
261 }
7240
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
262 if(sh_audio->inited){
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
263 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv);
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
264 mpadec->uninit(sh_audio);
8152
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
265 #ifdef DYNAMIC_PLUGINS
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
266 if (sh_audio->dec_handle)
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
267 dlclose(sh_audio->dec_handle);
4b02f73cb4b9 dlopen() support for ad and vd
alex
parents: 8123
diff changeset
268 #endif
7240
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
269 sh_audio->inited=0;
a1ae7d811e35 fixed uninit order
arpi
parents: 7191
diff changeset
270 }
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
271 if(sh_audio->a_out_buffer!=sh_audio->a_buffer) free(sh_audio->a_out_buffer);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
272 sh_audio->a_out_buffer=NULL;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
273 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
274 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
275 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
276 sh_audio->a_in_buffer=NULL;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
277 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
278
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
279 /* Init audio filters */
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
280 int init_audio_filters(sh_audio_t *sh_audio,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
281 int in_samplerate, int in_channels, int in_format, int in_bps,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
282 int out_samplerate, int out_channels, int out_format, int out_bps,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
283 int out_minsize, int out_maxsize){
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
284 af_stream_t* afs=malloc(sizeof(af_stream_t));
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
285 memset(afs,0,sizeof(af_stream_t));
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
286
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
287 // input format: same as codec's output format:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
288 afs->input.rate = in_samplerate;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
289 afs->input.nch = in_channels;
8167
e8832e66babd New features:
anders
parents: 8152
diff changeset
290 afs->input.format = af_format_decode(in_format);
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
291 afs->input.bps = in_bps;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
292
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
293 // output format: same as ao driver's input format (if missing, fallback to input)
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
294 afs->output.rate = out_samplerate ? out_samplerate : afs->input.rate;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
295 afs->output.nch = out_channels ? out_channels : afs->input.nch;
8167
e8832e66babd New features:
anders
parents: 8152
diff changeset
296 afs->output.format = af_format_decode(out_format ? out_format : afs->input.format);
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
297 afs->output.bps = out_bps ? out_bps : afs->input.bps;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
298
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
299 // filter config:
7614
ce6a938aa6d3 Adding -format and -af switches
anders
parents: 7604
diff changeset
300 memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t));
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
301
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
302 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Building audio filter chain for %dHz/%dch/%dbit -> %dHz/%dch/%dbit...\n",
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
303 afs->input.rate,afs->input.nch,afs->input.bps*8,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
304 afs->output.rate,afs->output.nch,afs->output.bps*8);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
305
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
306 // let's autoprobe it!
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
307 if(0 != af_init(afs)){
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
308 free(afs);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
309 return 0; // failed :(
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
310 }
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
311
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
312 // allocate the a_out_* buffers:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
313 if(out_maxsize<out_minsize) out_maxsize=out_minsize;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
314 if(out_maxsize<8192) out_maxsize=MAX_OUTBURST; // not sure this is ok
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
315
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
316 sh_audio->a_out_buffer_size=out_maxsize;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
317 sh_audio->a_out_buffer=malloc(sh_audio->a_out_buffer_size);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
318 memset(sh_audio->a_out_buffer,0,sh_audio->a_out_buffer_size);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
319 sh_audio->a_out_buffer_len=0;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
320
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
321 // ok!
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
322 sh_audio->afilter=(void*)afs;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
323 return 1;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
324 }
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
325
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
326 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
327 {
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
328 int declen;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
329 af_data_t afd; // filter input
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
330 af_data_t* pafd; // filter output
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
331
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
332 if(!sh_audio->inited) return -1; // no codec
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
333 if(!sh_audio->afilter){
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
334 // no filter, just decode:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
335 // FIXME: don't drop initial decoded data in a_buffer!
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
336 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
337 }
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
338
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
339 // declen=af_inputlen(sh_audio->afilter,minlen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
340 declen=af_calc_insize_constrained(sh_audio->afilter,minlen,maxlen,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
341 sh_audio->a_buffer_size-sh_audio->audio_out_minsize);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
342
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
343 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\ndecaudio: minlen=%d maxlen=%d declen=%d (max=%d)\n",
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
344 minlen, maxlen, declen, sh_audio->a_buffer_size);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
345
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
346 if(declen<=0) return -1; // error!
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
347
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
348 // limit declen to buffer size: - DONE by af_calc_insize_constrained
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
349 // if(declen>sh_audio->a_buffer_size) declen=sh_audio->a_buffer_size;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
350
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
351 // decode if needed:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
352 while(declen>sh_audio->a_buffer_len){
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
353 int len=declen-sh_audio->a_buffer_len;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
354 int maxlen=sh_audio->a_buffer_size-sh_audio->a_buffer_len;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
355
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
356 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"decaudio: decoding %d bytes, max: %d (%d)\n",
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
357 len, maxlen, sh_audio->audio_out_minsize);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
358
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
359 if(maxlen<sh_audio->audio_out_minsize) break; // don't overflow buffer!
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
360 // not enough decoded data waiting, decode 'len' bytes more:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
361 len=mpadec->decode_audio(sh_audio,
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
362 sh_audio->a_buffer+sh_audio->a_buffer_len, len, maxlen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
363 if(len<=0) break; // EOF?
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
364 sh_audio->a_buffer_len+=len;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
365 }
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
366 if(declen>sh_audio->a_buffer_len)
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
367 declen=sh_audio->a_buffer_len; // still no enough data (EOF) :(
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
368
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
369 // round to whole samples:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
370 // declen/=sh_audio->samplesize*sh_audio->channels;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
371 // declen*=sh_audio->samplesize*sh_audio->channels;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
372
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
373 // run the filters:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
374 afd.audio=sh_audio->a_buffer;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
375 afd.len=declen;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
376 afd.rate=sh_audio->samplerate;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
377 afd.nch=sh_audio->channels;
8167
e8832e66babd New features:
anders
parents: 8152
diff changeset
378 afd.format=af_format_decode(sh_audio->sample_format);
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
379 afd.bps=sh_audio->samplesize;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
380 //pafd=&afd;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
381 // printf("\nAF: %d --> ",declen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
382 pafd=af_play(sh_audio->afilter,&afd);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
383 // printf("%d \n",pafd->len);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
384
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
385 if(!pafd) return -1; // error
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
386
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
387 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"decaudio: declen=%d out=%d (max %d)\n",
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
388 declen, pafd->len, maxlen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
389
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
390 // copy filter==>out:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
391 if(maxlen < pafd->len)
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
392 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"%i bytes of audio data lost due to buffer overflow, len = %i", pafd->len - maxlen,pafd->len);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
393 else
7604
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
394 maxlen=pafd->len;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
395 memmove(buf, pafd->audio, maxlen);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
396
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
397 // remove processed data from decoder buffer:
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
398 sh_audio->a_buffer_len-=declen;
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
399 if(sh_audio->a_buffer_len>0)
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
400 memmove(sh_audio->a_buffer, sh_audio->a_buffer+declen, sh_audio->a_buffer_len);
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
401
32efb806436e aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents: 7561
diff changeset
402 return maxlen;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
403 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
404
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
405 void resync_audio_stream(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
406 {
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
407 sh_audio->a_in_buffer_len=0; // clear audio input buffer
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
408 if(!sh_audio->inited) return;
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
409 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
410 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
411
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
412 void skip_audio_frame(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
413 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
414 if(!sh_audio->inited) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
415 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
416 // default skip code:
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
417 ds_fill_buffer(sh_audio->ds); // skip block
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
418 }