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(KERN_WARNING "Couldn't allocate memory for ipack\n");
33 av7110_ipack_reset(p);
38 void av7110_ipack_free(struct ipack *p)
44 static void send_ipack(struct ipack *p)
47 struct dvb_audio_info ai;
58 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
59 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
60 if (p->repack_subids && p->cid == PRIVATE_STREAM1) {
62 streamid = p->buf[off];
63 if ((streamid & 0xf8) == 0x80) {
65 ac3_off = ((p->buf[off + 2] << 8)|
67 if (ac3_off < p->count)
68 f = dvb_filter_get_ac3info(p->buf + off + 3 + ac3_off,
69 p->count - ac3_off, &ai, 0);
71 nframes = (p->count - off - 3 - ac3_off) /
73 p->buf[off + 2] = (ac3_off >> 8) & 0xff;
74 p->buf[off + 3] = (ac3_off) & 0xff;
75 p->buf[off + 1] = nframes;
76 ac3_off += nframes * ai.framesize - p->count;
80 p->func(p->buf, p->count, p->data);
86 if (p->repack_subids && p->cid == PRIVATE_STREAM1
87 && (streamid & 0xf8) == 0x80) {
90 p->buf[10] = (ac3_off >> 8) & 0xff;
91 p->buf[11] = (ac3_off) & 0xff;
100 p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
101 p->buf[5] = (u8)((p->count - 6) & 0x00ff);
102 p->func(p->buf, p->count, p->data);
111 void av7110_ipack_flush(struct ipack *p)
113 if (p->plength != MMAX_PLENGTH - 6 || p->found <= 6)
115 p->plength = p->found - 6;
118 av7110_ipack_reset(p);
122 static void write_ipack(struct ipack *p, const u8 *data, int count)
124 u8 headr[3] = { 0x00, 0x00, 0x01 };
127 memcpy(p->buf, headr, 3);
131 if (p->count + count < p->size){
132 memcpy(p->buf+p->count, data, count);
135 int rest = p->size - p->count;
136 memcpy(p->buf+p->count, data, rest);
139 if (count - rest > 0)
140 write_ipack(p, data + rest, count - rest);
145 int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
150 while (c < count && (p->mpeg == 0 ||
151 (p->mpeg == 1 && p->found < 7) ||
152 (p->mpeg == 2 && p->found < 9))
153 && (p->found < 5 || !p->done)) {
166 else if (buf[c] == 0)
175 case PROG_STREAM_MAP:
176 case PRIVATE_STREAM2:
177 case PROG_STREAM_DIR:
180 case PADDING_STREAM :
182 case ISO13522_STREAM:
185 case PRIVATE_STREAM1:
186 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
187 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
205 p->plength = (p->plen[0] << 8) | p->plen[1];
216 p->plength = (p->plen[0] << 8) | p->plen[1];
223 if ((p->flag1 & 0xc0) == 0x80)
235 if (!p->done && p->mpeg == 2) {
243 if (!p->done && p->mpeg == 2) {
256 p->plength = MMAX_PLENGTH - 6;
258 if (p->done || ((p->mpeg == 2 && p->found >= 9) ||
259 (p->mpeg == 1 && p->found >= 7))) {
261 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
262 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
263 case PRIVATE_STREAM1:
264 if (p->mpeg == 2 && p->found == 9) {
265 write_ipack(p, &p->flag1, 1);
266 write_ipack(p, &p->flag2, 1);
267 write_ipack(p, &p->hlength, 1);
270 if (p->mpeg == 1 && p->found == 7)
271 write_ipack(p, &p->flag1, 1);
273 if (p->mpeg == 2 && (p->flag2 & PTS_ONLY) &&
275 while (c < count && p->found < 14) {
276 p->pts[p->found - 9] = buf[c];
277 write_ipack(p, buf + c, 1);
285 if (p->mpeg == 1 && p->which < 2000) {
292 while (!p->which && c < count &&
295 write_ipack(p, buf + c, 1);
304 if ((p->check & 0xc0) == 0x40 && !p->which) {
306 write_ipack(p, buf + c, 1);
315 write_ipack(p, buf + c, 1);
326 write_ipack(p, buf + c, 1);
335 if ((p->check & 0x30) && p->check != 0xff) {
336 p->flag2 = (p->check & 0xf0) << 2;
337 p->pts[0] = p->check;
344 if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
345 while (c < count && p->which < 7) {
346 p->pts[p->which - 2] = buf[c];
347 write_ipack(p, buf + c, 1);
355 } else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
356 while (c < count && p->which < 12) {
358 p->pts[p->which - 2] = buf[c];
359 write_ipack(p, buf + c, 1);
373 while (c < count && p->found < p->plength + 6) {
375 if (l + p->found > p->plength + 6)
376 l = p->plength + 6 - p->found;
377 write_ipack(p, buf + c, l);
386 if (p->found + count - c < p->plength + 6) {
387 p->found += count - c;
390 c += p->plength + 6 - p->found;
391 p->found = p->plength + 6;
395 if (p->plength && p->found == p->plength + 6) {
397 av7110_ipack_reset(p);
399 av7110_ipack_instant_repack(buf + c, count - c, p);