annotate libmpcodecs/dec_audio.c @ 7180:28677d779205

-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
author arpi
date Fri, 30 Aug 2002 21:44:20 +0000
parents b2ba67f6203e
children 1eadce15446c
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
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
29 int init_audio(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
30 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
31 unsigned i;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
32 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++)
7180
28677d779205 -afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents: 6989
diff changeset
33 // if(mpcodecs_ad_drivers[i]->info->id==sh_audio->codec->driver){
28677d779205 -afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents: 6989
diff changeset
34 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)){
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
35 mpadec=mpcodecs_ad_drivers[i]; break;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
36 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
37 if(!mpadec){
7180
28677d779205 -afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents: 6989
diff changeset
38 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr,
28677d779205 -afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents: 6989
diff changeset
39 sh_audio->codec->name, sh_audio->codec->drv);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
40 return 0; // no such driver
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
41 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
42
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
43 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
44
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
45 // reset in/out buffer size/pointer:
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
46 sh_audio->a_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
47 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
48 sh_audio->a_in_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
49 sh_audio->a_in_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
50
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
51 // Set up some common usefull defaults. ad->preinit() can override these:
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
52
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
53 sh_audio->samplesize=2;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
54 #ifdef WORDS_BIGENDIAN
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
55 sh_audio->sample_format=AFMT_S16_BE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
56 #else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
57 sh_audio->sample_format=AFMT_S16_LE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
58 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
59 sh_audio->samplerate=0;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
60 sh_audio->i_bps=0; // input rate (bytes/sec)
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
61 sh_audio->o_bps=0; // output rate (bytes/sec)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
62
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
63 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
64 sh_audio->audio_in_minsize=0;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
65
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
66 if(!mpadec->preinit(sh_audio))
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
67 {
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
68 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
69 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
70 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
71
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
72 /* allocate audio in buffer: */
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
73 if(sh_audio->audio_in_minsize>0){
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
74 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
75 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer,
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
76 sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
77 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
78 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
79 sh_audio->a_in_buffer_len=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
80 }
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
81
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
82 /* allocate audio out buffer: */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
83 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
84
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
85 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer,
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
86 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
87
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
88 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
89 if(!sh_audio->a_buffer){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
90 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
91 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
92 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
93 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
94 sh_audio->a_buffer_len=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
95
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
96 if(!mpadec->init(sh_audio)){
6989
b2ba67f6203e messages moved from dec_??d?o.c
jaf
parents: 6186
diff changeset
97 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
98 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
99 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
100 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
101
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
102 sh_audio->inited=1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
103
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
104 if(!sh_audio->channels || !sh_audio->samplerate){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
105 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
106 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
107 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
108 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
109
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
110 if(!sh_audio->o_bps)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
111 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
112
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
113 return 1;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
114 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
115
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
116 void uninit_audio(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
117 {
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
118 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
119 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
120 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
121 sh_audio->a_in_buffer=NULL;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
122 if(!sh_audio->inited) return;
7180
28677d779205 -afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents: 6989
diff changeset
123 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
124 mpadec->uninit(sh_audio);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
125 sh_audio->inited=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
126 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
127
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
128 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
129 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
130 if(sh_audio->inited)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
131 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
132 else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
133 return -1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
134 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
135
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
136 void resync_audio_stream(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
137 {
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
138 sh_audio->a_in_buffer_len=0; // clear audio input buffer
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
139 if(!sh_audio->inited) return;
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
140 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
141 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
142
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
143 void skip_audio_frame(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
144 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
145 if(!sh_audio->inited) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
146 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
147 // default skip code:
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
148 ds_fill_buffer(sh_audio->ds); // skip block
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
149 }