annotate libmpcodecs/dec_audio.c @ 6740:913736867009

10l y422p -> y420p use uvstride in draw_slices dr2 support (disabled as mplayer doesnt like slices with width!=picture width sometimes)
author michael
date Tue, 16 Jul 2002 12:04:30 +0000
parents c16a5fe3008f
children b2ba67f6203e
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++)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
33 if(mpcodecs_ad_drivers[i]->info->id==sh_audio->codec->driver){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
34 mpadec=mpcodecs_ad_drivers[i]; break;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
35 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
36 if(!mpadec){
6186
alex
parents: 6138
diff changeset
37 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Requested audio codec family [%s] (afm=%d) not available (enable it at compile time!)\n",
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
38 sh_audio->codec->name, sh_audio->codec->driver);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
39 return 0; // no such driver
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
40 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
41
6138
523014df7d32 big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents: 6049
diff changeset
42 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Opening audio decoder: [%s] %s\n",mpadec->info->short_name,mpadec->info->name);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
43
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
44 // reset in/out buffer size/pointer:
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
45 sh_audio->a_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
46 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
47 sh_audio->a_in_buffer_size=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
48 sh_audio->a_in_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
49
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
50 // Set up some common usefull defaults. ad->preinit() can override these:
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
51
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
52 sh_audio->samplesize=2;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
53 #ifdef WORDS_BIGENDIAN
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
54 sh_audio->sample_format=AFMT_S16_BE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
55 #else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
56 sh_audio->sample_format=AFMT_S16_LE;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
57 #endif
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
58 sh_audio->samplerate=0;
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
59 sh_audio->i_bps=0; // input rate (bytes/sec)
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
60 sh_audio->o_bps=0; // output rate (bytes/sec)
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
61
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
62 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
63 sh_audio->audio_in_minsize=0;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
64
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
65 if(!mpadec->preinit(sh_audio))
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
66 {
5933
14b46420840b printf to mp_msg
albeu
parents: 5458
diff changeset
67 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ADecoder preinit failed :(\n");
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
68 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
69 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
70
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
71 /* allocate audio in buffer: */
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
72 if(sh_audio->audio_in_minsize>0){
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
73 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
74 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d bytes for input buffer\n",
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
75 sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
76 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
77 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
78 sh_audio->a_in_buffer_len=0;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
79 }
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
80
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
81 /* allocate audio out buffer: */
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
82 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
83
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
84 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n",
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
85 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
86
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
87 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
88 if(!sh_audio->a_buffer){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
89 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
90 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
91 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
92 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
93 sh_audio->a_buffer_len=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
94
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
95 if(!mpadec->init(sh_audio)){
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
96 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"ADecoder init failed :(\n");
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
97 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
98 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
99 }
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
100
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
101 sh_audio->inited=1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
102
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
103 if(!sh_audio->channels || !sh_audio->samplerate){
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
104 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio);
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
105 uninit_audio(sh_audio); // free buffers
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
106 return 0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
107 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
108
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
109 if(!sh_audio->o_bps)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
110 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
111
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
112 return 1;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
113 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
114
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
115 void uninit_audio(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
116 {
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
117 if(sh_audio->a_buffer) free(sh_audio->a_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
118 sh_audio->a_buffer=NULL;
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
119 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer);
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5342
diff changeset
120 sh_audio->a_in_buffer=NULL;
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
121 if(!sh_audio->inited) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
122 mp_msg(MSGT_DECAUDIO,MSGL_V,"uninit audio: %d \n",sh_audio->codec->driver);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
123 mpadec->uninit(sh_audio);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
124 sh_audio->inited=0;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
125 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
126
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
127 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
128 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
129 if(sh_audio->inited)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
130 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen);
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
131 else
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
132 return -1;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
133 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
134
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
135 void resync_audio_stream(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
136 {
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
137 sh_audio->a_in_buffer_len=0; // clear audio input buffer
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
138 if(!sh_audio->inited) return;
6049
4bae3caef7a9 always reser audio input buffer pointer
arpi
parents: 5933
diff changeset
139 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL);
5342
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
140 }
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
141
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
142 void skip_audio_frame(sh_audio_t *sh_audio)
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
143 {
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
144 if(!sh_audio->inited) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
145 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return;
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
146 // default skip code:
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
147 ds_fill_buffer(sh_audio->ds); // skip block
c4cf81b3af71 imporetd from MPlayerXP, with small modification
arpi
parents:
diff changeset
148 }