typo fixes
[mplayer/greg.git] / libmpcodecs / ad_hwmpa.c
bloba3fcb0277b8d00613079253836eee153e217f761
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
6 #include "config.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
11 #include "libaf/af_format.h"
12 #include "ad_internal.h"
14 #include "libmpdemux/mp3_hdr.h"
16 //based on ad_hwac3.c and ad_libmad.c
17 static int isdts = -1;
19 static ad_info_t info =
21 "MPEG audio pass-through (fake decoder)",
22 "hwmpa",
23 "NicoDVB",
24 "NicoDVB",
25 "For hardware decoders"
28 LIBAD_EXTERN(hwmpa)
30 static int mpa_sync(sh_audio_t *sh, int no_frames, int *n, int *chans, int *srate, int *spf, int *mpa_layer, int *br)
32 int cnt = 0, x = 0, len, frames_count;
34 frames_count = 0;
37 while(cnt + 4 < sh->a_in_buffer_len)
39 if(((sh->a_in_buffer[cnt] << 8) | sh->a_in_buffer[cnt+1]) & 0xffe0 != 0xffe0)
40 continue;
41 x = mp_get_mp3_header(&(sh->a_in_buffer[cnt]), chans, srate, spf, mpa_layer, br);
42 if(x > 0)
44 frames_count++;
45 if(frames_count == no_frames)
47 *n = x;
48 return cnt;
51 cnt++;
53 len = demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],sh->a_in_buffer_size-sh->a_in_buffer_len);
54 if(len > 0)
55 sh->a_in_buffer_len += len;
56 } while(len > 0);
57 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Cannot sync MPA frame: %d\r\n", len);
58 return -1;
61 static int preinit(sh_audio_t *sh)
63 sh->audio_out_minsize = 48;//check
64 sh->audio_in_minsize = 4608;//check
65 sh->sample_format = AF_FORMAT_MPEG2;
66 return 1;
69 static int init(sh_audio_t *sh)
71 int cnt, chans, srate, spf, mpa_layer, br, len;
73 if((cnt = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br)) < 0)
74 return 0;
76 sh->channels = chans;
77 sh->samplerate = srate;
78 sh->i_bps = br * 125;
79 sh->samplesize = 2;
81 mp_msg(MSGT_DECAUDIO,MSGL_V,"AC_HWMPA initialized, bitrate: %d kb/s\r\n", len);
82 return 1;
85 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen)
87 int len, start, cnt2, tot;
88 int chans, srate, spf, mpa_layer, br;
90 tot = cnt2 = 0;
91 while(tot < minlen && tot+4608<=maxlen)
93 start = mpa_sync(sh, 1, &len, &chans, &srate, &spf, &mpa_layer, &br);
94 if(start < 0)
95 break;
97 if(start + len < sh->a_in_buffer_len && start + len >= maxlen)
98 break;
99 memcpy(&buf[cnt2], &(sh->a_in_buffer[start]), len);
100 cnt2 += len;
101 sh->a_in_buffer_len -= start + len;
102 memmove(sh->a_in_buffer, &(sh->a_in_buffer[start + len]), sh->a_in_buffer_len);
103 tot += start + len;
106 return tot;
110 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
112 int start, len, n;
114 switch(cmd)
116 case ADCTRL_RESYNC_STREAM:
117 if(mpa_sync(sh, 1, &len, NULL, NULL, NULL, NULL, NULL) >= 0)
118 return CONTROL_TRUE;
119 else
120 return CONTROL_FALSE;
121 case ADCTRL_SKIP_FRAME:
122 start = mpa_sync(sh, 2, &len, NULL, NULL, NULL, NULL, NULL);
123 if(len < 0)
124 return CONTROL_FALSE;
126 sh->a_in_buffer_len -= start;
127 memmove(sh->a_in_buffer, &(sh->a_in_buffer[start]), sh->a_in_buffer_len);
128 return CONTROL_TRUE;
130 return CONTROL_UNKNOWN;
134 static void uninit(sh_audio_t *sh)