1 #include "dvb_filter.h"
2 #include "av7110_ipack.h"
3 #include <linux/string.h> /* for memcpy() */
4 #include <linux/vmalloc.h>
7 void av7110_ipack_reset(struct ipack *p)
23 int av7110_ipack_init(struct ipack *p, int size,
24 void (*func)(u8 *buf, int size, void *priv))
26 if ( !(p->buf = vmalloc(size*sizeof(u8))) ){
27 printk ("Couldn't allocate memory for ipack\n");
33 av7110_ipack_reset(p);
38 void av7110_ipack_free(struct ipack * p)
45 static void send_ipack(struct ipack *p)
48 struct dvb_audio_info ai;
59 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
60 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
61 if (p->repack_subids && p->cid == PRIVATE_STREAM1){
63 streamid = p->buf[off];
64 if ((streamid & 0xf8) == 0x80) {
66 ac3_off = ((p->buf[off+2] << 8)|
68 if (ac3_off < p->count)
69 f=dvb_filter_get_ac3info(p->buf+off+3+ac3_off,
70 p->count-ac3_off, &ai,0);
72 nframes = (p->count-off-3-ac3_off)/
74 p->buf[off + 2] = (ac3_off >> 8) & 0xff;
75 p->buf[off + 3] = (ac3_off) & 0xff;
76 p->buf[off+1] = nframes;
77 ac3_off += nframes * ai.framesize - p->count;
81 p->func(p->buf, p->count, p->data);
87 if (p->repack_subids && p->cid == PRIVATE_STREAM1
88 && (streamid & 0xf8) == 0x80) {
91 p->buf[10] = (ac3_off >> 8) & 0xff;
92 p->buf[11] = (ac3_off) & 0xff;
101 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
102 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
103 p->func(p->buf, p->count, p->data);
112 void av7110_ipack_flush(struct ipack *p)
114 if (p->plength != MMAX_PLENGTH-6 || p->found<=6)
116 p->plength = p->found-6;
119 av7110_ipack_reset(p);
123 static void write_ipack(struct ipack *p, const u8 *data, int count)
125 u8 headr[3] = { 0x00, 0x00, 0x01} ;
128 memcpy(p->buf, headr, 3);
132 if (p->count + count < p->size){
133 memcpy(p->buf+p->count, data, count);
136 int rest = p->size - p->count;
137 memcpy(p->buf+p->count, data, rest);
140 if (count - rest > 0)
141 write_ipack(p, data+rest, count-rest);
146 int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
151 while (c < count && (p->mpeg == 0 ||
152 (p->mpeg == 1 && p->found < 7) ||
153 (p->mpeg == 2 && p->found < 9))
154 && (p->found < 5 || !p->done)){
167 else if (buf[c] == 0)
176 case PROG_STREAM_MAP:
177 case PRIVATE_STREAM2:
178 case PROG_STREAM_DIR:
181 case PADDING_STREAM :
183 case ISO13522_STREAM:
186 case PRIVATE_STREAM1:
187 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
188 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
206 p->plength=(p->plen[0]<<8)|p->plen[1];
217 p->plength=(p->plen[0]<<8)|p->plen[1];
224 if ((p->flag1 & 0xc0) == 0x80)
236 if ( !p->done && p->mpeg == 2) {
244 if ( !p->done && p->mpeg == 2) {
257 p->plength = MMAX_PLENGTH - 6;
259 if ( p->done || ((p->mpeg == 2 && p->found >= 9) ||
260 (p->mpeg == 1 && p->found >= 7)) ){
263 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
264 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
265 case PRIVATE_STREAM1:
267 if (p->mpeg == 2 && p->found == 9) {
268 write_ipack(p, &p->flag1, 1);
269 write_ipack(p, &p->flag2, 1);
270 write_ipack(p, &p->hlength, 1);
273 if (p->mpeg == 1 && p->found == 7)
274 write_ipack(p, &p->flag1, 1);
276 if (p->mpeg == 2 && (p->flag2 & PTS_ONLY) &&
278 while (c < count && p->found < 14) {
279 p->pts[p->found-9] = buf[c];
280 write_ipack(p, buf+c, 1);
288 if (p->mpeg == 1 && p->which < 2000) {
295 while (!p->which && c < count &&
298 write_ipack(p, buf+c, 1);
307 if ((p->check & 0xc0) == 0x40 && !p->which) {
309 write_ipack(p, buf+c, 1);
318 write_ipack(p, buf+c, 1);
329 write_ipack(p, buf+c, 1);
338 if ((p->check & 0x30) && p->check != 0xff) {
339 p->flag2 = (p->check & 0xf0) << 2;
340 p->pts[0] = p->check;
347 if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
348 while (c < count && p->which < 7) {
349 p->pts[p->which - 2] = buf[c];
350 write_ipack(p,buf+c,1);
358 } else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
359 while (c < count && p->which < 12) {
361 p->pts[p->which - 2] = buf[c];
362 write_ipack(p,buf+c,1);
376 while (c < count && p->found < p->plength+6){
378 if (l+p->found > p->plength+6)
379 l = p->plength+6-p->found;
380 write_ipack(p, buf+c, l);
390 if( p->found + count - c < p->plength+6){
394 c += p->plength+6 - p->found;
395 p->found = p->plength+6;
399 if (p->plength && p->found == p->plength+6) {
401 av7110_ipack_reset(p);
403 av7110_ipack_instant_repack(buf+c, count-c, p);