Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 7483:44198b2f42db
removed unused old keyboard fifo hack
removed unused allow_dshow hack
author | arpi |
---|---|
date | Sun, 22 Sep 2002 15:37:51 +0000 |
parents | a1ae7d811e35 |
children | 6a2b6f3d619c |
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 | |
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 |
5342 | 45 int init_audio(sh_audio_t *sh_audio) |
46 { | |
47 unsigned i; | |
48 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
|
49 // 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
|
50 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)){ |
5342 | 51 mpadec=mpcodecs_ad_drivers[i]; break; |
52 } | |
53 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
|
54 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
|
55 sh_audio->codec->name, sh_audio->codec->drv); |
5342 | 56 return 0; // no such driver |
57 } | |
58 | |
6989 | 59 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name); |
5458 | 60 |
61 // reset in/out buffer size/pointer: | |
62 sh_audio->a_buffer_size=0; | |
63 sh_audio->a_buffer=NULL; | |
64 sh_audio->a_in_buffer_size=0; | |
65 sh_audio->a_in_buffer=NULL; | |
66 | |
67 // Set up some common usefull defaults. ad->preinit() can override these: | |
5342 | 68 |
69 sh_audio->samplesize=2; | |
70 #ifdef WORDS_BIGENDIAN | |
71 sh_audio->sample_format=AFMT_S16_BE; | |
72 #else | |
73 sh_audio->sample_format=AFMT_S16_LE; | |
74 #endif | |
75 sh_audio->samplerate=0; | |
5458 | 76 sh_audio->i_bps=0; // input rate (bytes/sec) |
77 sh_audio->o_bps=0; // output rate (bytes/sec) | |
5342 | 78 |
79 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/ | |
5458 | 80 sh_audio->audio_in_minsize=0; |
5342 | 81 |
82 if(!mpadec->preinit(sh_audio)) | |
83 { | |
6989 | 84 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 85 return 0; |
86 } | |
87 | |
5458 | 88 /* allocate audio in buffer: */ |
89 if(sh_audio->audio_in_minsize>0){ | |
90 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 91 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 92 sh_audio->a_in_buffer_size); |
93 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
94 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); | |
95 sh_audio->a_in_buffer_len=0; | |
96 } | |
97 | |
5342 | 98 /* allocate audio out buffer: */ |
99 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
100 | |
6989 | 101 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 102 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
103 | |
104 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
105 if(!sh_audio->a_buffer){ | |
106 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
107 return 0; | |
108 } | |
109 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
110 sh_audio->a_buffer_len=0; | |
111 | |
112 if(!mpadec->init(sh_audio)){ | |
6989 | 113 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 114 uninit_audio(sh_audio); // free buffers |
5342 | 115 return 0; |
116 } | |
5458 | 117 |
5342 | 118 sh_audio->inited=1; |
119 | |
120 if(!sh_audio->channels || !sh_audio->samplerate){ | |
121 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 122 uninit_audio(sh_audio); // free buffers |
5342 | 123 return 0; |
124 } | |
125 | |
126 if(!sh_audio->o_bps) | |
127 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
5458 | 128 |
129 return 1; | |
5342 | 130 } |
131 | |
132 void uninit_audio(sh_audio_t *sh_audio) | |
133 { | |
7240 | 134 if(sh_audio->inited){ |
135 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv); | |
136 mpadec->uninit(sh_audio); | |
137 sh_audio->inited=0; | |
138 } | |
5458 | 139 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
140 sh_audio->a_buffer=NULL; | |
141 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
142 sh_audio->a_in_buffer=NULL; | |
5342 | 143 } |
144 | |
145 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) | |
146 { | |
147 if(sh_audio->inited) | |
148 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen); | |
149 else | |
150 return -1; | |
151 } | |
152 | |
153 void resync_audio_stream(sh_audio_t *sh_audio) | |
154 { | |
6049 | 155 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 156 if(!sh_audio->inited) return; |
6049 | 157 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 158 } |
159 | |
160 void skip_audio_frame(sh_audio_t *sh_audio) | |
161 { | |
162 if(!sh_audio->inited) return; | |
163 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; | |
164 // default skip code: | |
165 ds_fill_buffer(sh_audio->ds); // skip block | |
166 } |