Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 7186:02b1976e12e2
fix vfm and add afm support
author | pontscho |
---|---|
date | Sat, 31 Aug 2002 09:45:59 +0000 |
parents | 28677d779205 |
children | 1eadce15446c |
rev | line source |
---|---|
5342 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 | |
5 #include "config.h" | |
6 #include "mp_msg.h" | |
7 #include "help_mp.h" | |
8 | |
9 extern int verbose; // defined in mplayer.c | |
10 | |
11 #include "stream.h" | |
12 #include "demuxer.h" | |
13 | |
14 #include "codec-cfg.h" | |
15 #include "stheader.h" | |
16 | |
17 #include "dec_audio.h" | |
18 #include "ad.h" | |
19 #include "../libao2/afmt.h" | |
20 | |
21 #ifdef USE_FAKE_MONO | |
22 int fakemono=0; | |
23 #endif | |
24 /* used for ac3surround decoder - set using -channels option */ | |
25 int audio_output_channels = 2; | |
26 | |
27 static ad_functions_t* mpadec; | |
28 | |
29 int init_audio(sh_audio_t *sh_audio) | |
30 { | |
31 unsigned i; | |
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 | 35 mpadec=mpcodecs_ad_drivers[i]; break; |
36 } | |
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 | 40 return 0; // no such driver |
41 } | |
42 | |
6989 | 43 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name); |
5458 | 44 |
45 // reset in/out buffer size/pointer: | |
46 sh_audio->a_buffer_size=0; | |
47 sh_audio->a_buffer=NULL; | |
48 sh_audio->a_in_buffer_size=0; | |
49 sh_audio->a_in_buffer=NULL; | |
50 | |
51 // Set up some common usefull defaults. ad->preinit() can override these: | |
5342 | 52 |
53 sh_audio->samplesize=2; | |
54 #ifdef WORDS_BIGENDIAN | |
55 sh_audio->sample_format=AFMT_S16_BE; | |
56 #else | |
57 sh_audio->sample_format=AFMT_S16_LE; | |
58 #endif | |
59 sh_audio->samplerate=0; | |
5458 | 60 sh_audio->i_bps=0; // input rate (bytes/sec) |
61 sh_audio->o_bps=0; // output rate (bytes/sec) | |
5342 | 62 |
63 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/ | |
5458 | 64 sh_audio->audio_in_minsize=0; |
5342 | 65 |
66 if(!mpadec->preinit(sh_audio)) | |
67 { | |
6989 | 68 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 69 return 0; |
70 } | |
71 | |
5458 | 72 /* allocate audio in buffer: */ |
73 if(sh_audio->audio_in_minsize>0){ | |
74 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 75 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 76 sh_audio->a_in_buffer_size); |
77 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
78 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); | |
79 sh_audio->a_in_buffer_len=0; | |
80 } | |
81 | |
5342 | 82 /* allocate audio out buffer: */ |
83 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
84 | |
6989 | 85 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 86 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
87 | |
88 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
89 if(!sh_audio->a_buffer){ | |
90 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
91 return 0; | |
92 } | |
93 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
94 sh_audio->a_buffer_len=0; | |
95 | |
96 if(!mpadec->init(sh_audio)){ | |
6989 | 97 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 98 uninit_audio(sh_audio); // free buffers |
5342 | 99 return 0; |
100 } | |
5458 | 101 |
5342 | 102 sh_audio->inited=1; |
103 | |
104 if(!sh_audio->channels || !sh_audio->samplerate){ | |
105 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 106 uninit_audio(sh_audio); // free buffers |
5342 | 107 return 0; |
108 } | |
109 | |
110 if(!sh_audio->o_bps) | |
111 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
5458 | 112 |
113 return 1; | |
5342 | 114 } |
115 | |
116 void uninit_audio(sh_audio_t *sh_audio) | |
117 { | |
5458 | 118 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
119 sh_audio->a_buffer=NULL; | |
120 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
121 sh_audio->a_in_buffer=NULL; | |
5342 | 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 | 124 mpadec->uninit(sh_audio); |
125 sh_audio->inited=0; | |
126 } | |
127 | |
128 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) | |
129 { | |
130 if(sh_audio->inited) | |
131 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen); | |
132 else | |
133 return -1; | |
134 } | |
135 | |
136 void resync_audio_stream(sh_audio_t *sh_audio) | |
137 { | |
6049 | 138 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 139 if(!sh_audio->inited) return; |
6049 | 140 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 141 } |
142 | |
143 void skip_audio_frame(sh_audio_t *sh_audio) | |
144 { | |
145 if(!sh_audio->inited) return; | |
146 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; | |
147 // default skip code: | |
148 ds_fill_buffer(sh_audio->ds); // skip block | |
149 } |