Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libmpcodecs / ad_pcm.c
blob1717cdd75d42ebba81ab92b6805e353ea13f4fe0
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 #include "config.h"
6 #include "ad_internal.h"
7 #include "libaf/af_format.h"
8 #include "libaf/reorder_ch.h"
10 static ad_info_t info =
12 "Uncompressed PCM audio decoder",
13 "pcm",
14 "Nick Kurshev",
15 "A'rpi",
19 LIBAD_EXTERN(pcm)
21 static int init(sh_audio_t *sh_audio)
23 WAVEFORMATEX *h=sh_audio->wf;
24 sh_audio->i_bps=h->nAvgBytesPerSec;
25 sh_audio->channels=h->nChannels;
26 sh_audio->samplerate=h->nSamplesPerSec;
27 sh_audio->samplesize=(h->wBitsPerSample+7)/8;
28 sh_audio->sample_format=AF_FORMAT_S16_LE; // default
29 switch(sh_audio->format){ /* hardware formats: */
30 case 0x0:
31 case 0x1: // Microsoft PCM
32 case 0xfffe: // Extended
33 switch (sh_audio->samplesize) {
34 case 1: sh_audio->sample_format=AF_FORMAT_U8; break;
35 case 2: sh_audio->sample_format=AF_FORMAT_S16_LE; break;
36 case 3: sh_audio->sample_format=AF_FORMAT_S24_LE; break;
37 case 4: sh_audio->sample_format=AF_FORMAT_S32_LE; break;
39 break;
40 case 0x3: // IEEE float
41 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
42 break;
43 case 0x6: sh_audio->sample_format=AF_FORMAT_A_LAW;break;
44 case 0x7: sh_audio->sample_format=AF_FORMAT_MU_LAW;break;
45 case 0x11: sh_audio->sample_format=AF_FORMAT_IMA_ADPCM;break;
46 case 0x50: sh_audio->sample_format=AF_FORMAT_MPEG2;break;
47 /* case 0x2000: sh_audio->sample_format=AFMT_AC3; */
48 case 0x20776172: // 'raw '
49 sh_audio->sample_format=AF_FORMAT_S16_BE;
50 if(sh_audio->samplesize==1) sh_audio->sample_format=AF_FORMAT_U8;
51 break;
52 case 0x736F7774: // 'twos'
53 sh_audio->sample_format=AF_FORMAT_S16_BE;
54 // intended fall-through
55 case 0x74776F73: // 'sowt'
56 if(sh_audio->samplesize==1) sh_audio->sample_format=AF_FORMAT_S8;
57 break;
58 case 0x32336c66: // 'fl32', bigendian float32
59 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
60 sh_audio->samplesize=4;
61 break;
62 case 0x666c3332: // '23lf', little endian float32, MPlayer internal fourCC
63 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
64 sh_audio->samplesize=4;
65 break;
66 /* case 0x34366c66: // 'fl64', bigendian float64
67 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
68 sh_audio->samplesize=8;
69 break;
70 case 0x666c3634: // '46lf', little endian float64, MPlayer internal fourCC
71 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
72 sh_audio->samplesize=8;
73 break;*/
74 case 0x34326e69: // 'in24', bigendian int24
75 sh_audio->sample_format=AF_FORMAT_S24_BE;
76 sh_audio->samplesize=3;
77 break;
78 case 0x696e3234: // '42ni', little endian int24, MPlayer internal fourCC
79 sh_audio->sample_format=AF_FORMAT_S24_LE;
80 sh_audio->samplesize=3;
81 break;
82 case 0x32336e69: // 'in32', bigendian int32
83 sh_audio->sample_format=AF_FORMAT_S32_BE;
84 sh_audio->samplesize=4;
85 break;
86 case 0x696e3332: // '23ni', little endian int32, MPlayer internal fourCC
87 sh_audio->sample_format=AF_FORMAT_S32_LE;
88 sh_audio->samplesize=4;
89 break;
90 default: if(sh_audio->samplesize!=2) sh_audio->sample_format=AF_FORMAT_U8;
92 if (!sh_audio->samplesize) // this would cause MPlayer to hang later
93 sh_audio->samplesize = 2;
94 return 1;
97 static int preinit(sh_audio_t *sh)
99 sh->audio_out_minsize=2048;
100 return 1;
103 static void uninit(sh_audio_t *sh)
107 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
109 int skip;
110 switch(cmd)
112 case ADCTRL_SKIP_FRAME:
113 skip=sh->i_bps/16;
114 skip=skip&(~3);
115 demux_read_data(sh->ds,NULL,skip);
116 return CONTROL_TRUE;
118 return CONTROL_UNKNOWN;
121 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
123 unsigned len = sh_audio->channels*sh_audio->samplesize;
124 len = (minlen + len - 1) / len * len;
125 if (len > maxlen)
126 // if someone needs hundreds of channels adjust audio_out_minsize
127 // based on channels in preinit()
128 return -1;
129 len=demux_read_data(sh_audio->ds,buf,len);
130 if (len > 0 && sh_audio->channels >= 5) {
131 reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
132 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
133 sh_audio->channels,
134 len / sh_audio->samplesize, sh_audio->samplesize);
136 return len;