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++)
|
|
33 if(mpcodecs_ad_drivers[i]->info->id==sh_audio->codec->driver){
|
|
34 mpadec=mpcodecs_ad_drivers[i]; break;
|
|
35 }
|
|
36 if(!mpadec){
|
|
37 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Requested audio codec family [%s] (vfm=%d) not available (enable it at compile time!)\n",
|
|
38 sh_audio->codec->name, sh_audio->codec->driver);
|
|
39 return 0; // no such driver
|
|
40 }
|
|
41
|
|
42 printf("Selecting Audio Decoder: [%s] %s\n",mpadec->info->short_name,mpadec->info->name);
|
|
43
|
|
44 sh_audio->samplesize=2;
|
|
45 #ifdef WORDS_BIGENDIAN
|
|
46 sh_audio->sample_format=AFMT_S16_BE;
|
|
47 #else
|
|
48 sh_audio->sample_format=AFMT_S16_LE;
|
|
49 #endif
|
|
50 sh_audio->samplerate=0;
|
|
51 sh_audio->o_bps=0;
|
|
52
|
|
53 sh_audio->a_buffer_size=0;
|
|
54 sh_audio->a_buffer=NULL;
|
|
55
|
|
56 sh_audio->a_in_buffer_len=0;
|
|
57
|
|
58 /* setup required min. in/out buffer size:*/
|
|
59 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/
|
|
60
|
|
61 if(!mpadec->preinit(sh_audio))
|
|
62 {
|
|
63 printf("ADecoder preinit failed :(\n");
|
|
64 return 0;
|
|
65 }
|
|
66
|
|
67 /* allocate audio out buffer: */
|
|
68 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/
|
|
69
|
|
70 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n",
|
|
71 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
|
|
72
|
|
73 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
|
|
74 if(!sh_audio->a_buffer){
|
|
75 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
|
|
76 return 0;
|
|
77 }
|
|
78 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
|
|
79 sh_audio->a_buffer_len=0;
|
|
80
|
|
81 if(!mpadec->init(sh_audio)){
|
|
82 printf("ADecoder init failed :(\n");
|
|
83 return 0;
|
|
84 }
|
|
85 sh_audio->inited=1;
|
|
86
|
|
87 if(!sh_audio->channels || !sh_audio->samplerate){
|
|
88 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
|
|
89 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
|
|
90 sh_audio->a_buffer=NULL;
|
|
91 return 0;
|
|
92 }
|
|
93
|
|
94 if(!sh_audio->o_bps)
|
|
95 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
|
|
96 return sh_audio->codec->driver;
|
|
97 }
|
|
98
|
|
99 void uninit_audio(sh_audio_t *sh_audio)
|
|
100 {
|
|
101 if(!sh_audio->inited) return;
|
|
102 mp_msg(MSGT_DECAUDIO,MSGL_V,"uninit audio: %d \n",sh_audio->codec->driver);
|
|
103 mpadec->uninit(sh_audio);
|
|
104 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
|
|
105 sh_audio->a_buffer=NULL;
|
|
106 sh_audio->inited=0;
|
|
107 }
|
|
108
|
|
109 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
|
|
110 {
|
|
111 if(sh_audio->inited)
|
|
112 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen);
|
|
113 else
|
|
114 return -1;
|
|
115 }
|
|
116
|
|
117 void resync_audio_stream(sh_audio_t *sh_audio)
|
|
118 {
|
|
119 if(!sh_audio->inited) return;
|
|
120 if(mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL)==CONTROL_TRUE) return;
|
|
121 // default resync code:
|
|
122 sh_audio->a_in_buffer_len=0; // clear audio input buffer
|
|
123 }
|
|
124
|
|
125 void skip_audio_frame(sh_audio_t *sh_audio)
|
|
126 {
|
|
127 if(!sh_audio->inited) return;
|
|
128 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return;
|
|
129 // default skip code:
|
|
130 ds_fill_buffer(sh_audio->ds); // skip block
|
|
131 }
|