input: make slave command file descriptors nonblocking
[mplayer/greg.git] / libmpcodecs / ad_alaw.c
blob4a8f3849cff2d08fe6ef0ae9164f235681fefd9a
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
23 #include "config.h"
24 #include "ad_internal.h"
26 static const ad_info_t info =
28 "aLaw/uLaw audio decoder",
29 "alaw",
30 "Nick Kurshev",
31 "A'rpi",
35 LIBAD_EXTERN(alaw)
37 #include "native/alaw.h"
39 static int init(sh_audio_t *sh_audio)
41 /* aLaw audio codec:*/
42 if(!sh_audio->wf) return 0;
43 sh_audio->channels=sh_audio->wf->nChannels;
44 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
45 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
46 sh_audio->samplesize=2;
47 return 1;
50 static int preinit(sh_audio_t *sh)
52 sh->audio_out_minsize=2048;
53 sh->ds->ss_div = 1; // 1 samples/packet
54 sh->ds->ss_mul = sh->wf->nChannels; // bytes/packet
55 return 1;
58 static void uninit(sh_audio_t *sh)
62 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
64 int skip;
65 switch(cmd)
67 case ADCTRL_SKIP_FRAME:
68 skip=sh->i_bps/16;
69 skip=skip&(~3);
70 demux_read_data(sh->ds,NULL,skip);
71 return CONTROL_TRUE;
72 default:
73 return CONTROL_UNKNOWN;
75 return CONTROL_UNKNOWN;
78 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
80 int len;
81 int l=demux_read_data(sh_audio->ds,buf,minlen/2);
82 unsigned short *d=(unsigned short *) buf;
83 unsigned char *s=buf;
84 len=2*l;
85 if(sh_audio->format==6 || sh_audio->format==0x77616C61){
86 /* aLaw */
87 while(l>0){ --l; d[l]=alaw2short[s[l]]; }
88 } else {
89 /* uLaw */
90 while(l>0){ --l; d[l]=ulaw2short[s[l]]; }
92 return len;