1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/string.h>
7 static unsigned int bitrates[3][16] =
8 {{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0},
9 {0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,0},
10 {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0}};
13 static u32 freq[4] = {480, 441, 320, 0};
15 static unsigned int ac3_bitrates[32] =
16 {32,40,48,56,64,80,96,112,128,160,192,224,256,320,384,448,512,576,640,
17 0,0,0,0,0,0,0,0,0,0,0,0,0};
19 static u32 ac3_frames[3][32] =
20 {{64,80,96,112,128,160,192,224,256,320,384,448,512,640,768,896,1024,
21 1152,1280,0,0,0,0,0,0,0,0,0,0,0,0,0},
22 {69,87,104,121,139,174,208,243,278,348,417,487,557,696,835,975,1114,
23 1253,1393,0,0,0,0,0,0,0,0,0,0,0,0,0},
24 {96,120,144,168,192,240,288,336,384,480,576,672,768,960,1152,1344,
25 1536,1728,1920,0,0,0,0,0,0,0,0,0,0,0,0,0}};
34 dvb_filter_ipack_init(pa,
IPACKS, pes_write);
35 dvb_filter_ipack_init(pv,
IPACKS, pes_write);
49 printk(
"NULL POINTER IDIOT\n");
57 dvb_filter_ipack_reset(p);
62 if (off+4 > 187)
return;
64 dvb_filter_instant_repack(buf+4+off,
TS_SIZE-4-off, p);
74 if (pr)
printk(
"Pic header: ");
76 (headr[1] & 0x03) )& 0x03ff;
79 pct = ( headr[1] >> 2 ) & 0x07;
96 pic->
vinfo.vbv_delay = (( headr[1] >> 5 ) | ( headr[2] << 3) |
97 ( (headr[3] & 0x1F) << 11) ) & 0xffff;
99 if (pr)
printk(
" vbv delay: 0x%04x", pic->
vinfo.vbv_delay);
102 ((headr[4] & 0x80) >> 3);
107 if (pr)
printk(
" pic head param: 0x%x",
116 static int read_gop_header(
u8 *headr,
struct mpg_picture *pic,
int pr)
118 if (pr)
printk(
"GOP header: ");
120 pic->
time_code = (( headr[0] << 17 ) | ( headr[1] << 9) |
121 ( headr[2] << 1 ) | (headr[3] &0x01)) & 0x1ffffff;
123 if (pr)
printk(
" time: %d:%d.%d ", (headr[0]>>2)& 0x1F,
124 ((headr[0]<<4)& 0x30)| ((headr[1]>>4)& 0x0F),
125 ((headr[1]<<3)& 0x38)| ((headr[2]>>5)& 0x0F));
127 if ( ( headr[3] & 0x40 ) != 0 ){
134 if ( ( headr[3] & 0x20 ) != 0 ){
147 static int read_sequence_header(
u8 *headr,
struct dvb_video_info *vi,
int pr)
152 if (pr)
printk(
"Reading sequence header\n");
157 sw = (
int)((headr[3]&0xF0) >> 4) ;
162 printk(
"Videostream: ASPECT: 1:1");
167 printk(
"Videostream: ASPECT: 4:3");
172 printk(
"Videostream: ASPECT: 16:9");
177 printk(
"Videostream: ASPECT: 2.21:1");
183 printk(
"Videostream: ASPECT: reserved");
195 sw = (
int)(headr[3]&0x0F);
200 printk(
" FRate: 23.976 fps");
214 form = VIDEO_MODE_PAL;
218 printk(
" FRate: 29.97 fps");
220 form = VIDEO_MODE_NTSC;
226 form = VIDEO_MODE_NTSC;
232 form = VIDEO_MODE_PAL;
238 form = VIDEO_MODE_NTSC;
242 vi->
bit_rate = (headr[4] << 10) | (headr[5] << 2) | (headr[6] & 0x03);
245 = (( headr[6] & 0xF8) >> 3 ) | (( headr[7] & 0x1F )<< 5);
267 while (found < 4 && c+4 < count){
271 if ( b[0] == 0x00 && b[1] == 0x00 && b[2] == 0x01
272 && b[3] == 0xb3) found = 4;
278 if (! found)
return -1;
280 if (c+12 >= count)
return -1;
282 if (read_sequence_header(headr, vi, pr) < 0)
return -1;
290 static int get_ainfo(
u8 *mbuf,
int count,
struct dvb_audio_info *ai,
int pr)
297 while (found < 2 && c < count){
301 if ( b[0] == 0xff && (b[1] & 0xf8) == 0xf8)
308 if (!found)
return -1;
310 if (c+3 >= count)
return -1;
313 ai->
layer = (headr[1] & 0x06) >> 1;
319 ai->
bit_rate = bitrates[(3-ai->
layer)][(headr[2] >> 4 )]*1000;
323 printk(
" Bit rate: free");
325 printk(
" BRate: reserved");
330 fr = (headr[2] & 0x0c ) >> 2;
334 printk(
" Freq: reserved\n");
353 while ( !found && c < count){
356 if ( b[0] == 0x0b && b[1] == 0x77 )
363 if (!found)
return -1;
365 printk(
"Audiostream: AC3");
368 if (c+5 >= count)
return -1;
373 frame = (headr[2]&0x3f);
374 ai->
bit_rate = ac3_bitrates[frame >> 1]*1000;
380 fr = (headr[2] & 0xc0 ) >> 6;
385 ai->
framesize = ac3_frames[fr][frame >> 1];
386 if ((frame & 1) && (fr == 1)) ai->
framesize++;
397 static u8 *skip_pes_header(
u8 **bufp)
404 static const int mpeg1_skip_table[16] = {
405 1, 0xffff, 5, 10, 0xffff, 0xffff, 0xffff, 0xffff,
406 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
410 if ((inbuf[6] & 0xc0) == 0x80){
414 buf = inbuf + 9 + inbuf[8];
416 for (buf = inbuf + 6; *buf == 0xff; buf++)
417 if (buf == inbuf + 6 + 16) {
420 if ((*buf & 0xc0) == 0x40)
422 skip = mpeg1_skip_table [*buf >> 4];
423 if (skip == 5 || skip == 10) pts =
buf;
426 buf += mpeg1_skip_table [*buf >> 4];
435 static void initialize_quant_matrix(
u32 *matrix )
439 matrix[0] = 0x08101013;
440 matrix[1] = 0x10131616;
441 matrix[2] = 0x16161616;
442 matrix[3] = 0x1a181a1b;
443 matrix[4] = 0x1b1b1a1a;
444 matrix[5] = 0x1a1a1b1b;
445 matrix[6] = 0x1b1d1d1d;
446 matrix[7] = 0x2222221d;
447 matrix[8] = 0x1d1d1b1b;
448 matrix[9] = 0x1d1d2020;
449 matrix[10] = 0x22222526;
450 matrix[11] = 0x25232322;
451 matrix[12] = 0x23262628;
452 matrix[13] = 0x28283030;
453 matrix[14] = 0x2e2e3838;
454 matrix[15] = 0x3a454553;
456 for ( i = 16 ; i < 32 ; i++ )
457 matrix[i] = 0x10101010;
462 static void initialize_mpg_picture(
struct mpg_picture *pic)
473 for ( i = 0 ; i < 4 ; i++ ){
513 *p_h_offset = last_h_offset;
514 *(p_h_offset + 1) = last_h_offset;
515 *(p_h_offset + 2) = last_h_offset;
516 *p_v_offset = last_v_offset;
517 *(p_v_offset + 1) = last_v_offset;
518 *(p_v_offset + 2) = last_v_offset;
536 pic->
vinfo.horizontal_size
538 pic->
vinfo.vertical_size
559 unsigned char *buf=p2ts->
buf;
571 int len,
int payload_start)
573 unsigned char *buf=p2ts->
buf;
583 buf[3]=0x10|((p2ts->
cc++)&0x0f);
585 if ((ret=p2ts->
cb(p2ts->
priv, buf)))
592 buf[3]=0x30|((p2ts->
cc++)&0x0f);
601 return p2ts->
cb(p2ts->
priv, buf);