1#include <linux/kernel.h> 2#include <linux/module.h> 3#include <linux/string.h> 4#include "dvb_filter.h" 5 6 7static u32 freq[4] = {480, 441, 320, 0}; 8 9static unsigned int ac3_bitrates[32] = 10 {32,40,48,56,64,80,96,112,128,160,192,224,256,320,384,448,512,576,640, 11 0,0,0,0,0,0,0,0,0,0,0,0,0}; 12 13static u32 ac3_frames[3][32] = 14 {{64,80,96,112,128,160,192,224,256,320,384,448,512,640,768,896,1024, 15 1152,1280,0,0,0,0,0,0,0,0,0,0,0,0,0}, 16 {69,87,104,121,139,174,208,243,278,348,417,487,557,696,835,975,1114, 17 1253,1393,0,0,0,0,0,0,0,0,0,0,0,0,0}, 18 {96,120,144,168,192,240,288,336,384,480,576,672,768,960,1152,1344, 19 1536,1728,1920,0,0,0,0,0,0,0,0,0,0,0,0,0}}; 20 21 22 23 24 25 26 27 28 29 30 31 32 33int dvb_filter_get_ac3info(u8 *mbuf, int count, struct dvb_audio_info *ai, int pr) 34{ 35 u8 *headr; 36 int found = 0; 37 int c = 0; 38 u8 frame = 0; 39 int fr = 0; 40 41 while ( !found && c < count){ 42 u8 *b = mbuf+c; 43 44 if ( b[0] == 0x0b && b[1] == 0x77 ) 45 found = 1; 46 else { 47 c++; 48 } 49 } 50 51 if (!found) return -1; 52 if (pr) 53 printk("Audiostream: AC3"); 54 55 ai->off = c; 56 if (c+5 >= count) return -1; 57 58 ai->layer = 0; // 0 for AC3 59 headr = mbuf+c+2; 60 61 frame = (headr[2]&0x3f); 62 ai->bit_rate = ac3_bitrates[frame >> 1]*1000; 63 64 if (pr) 65 printk(" BRate: %d kb/s", (int) ai->bit_rate/1000); 66 67 ai->frequency = (headr[2] & 0xc0 ) >> 6; 68 fr = (headr[2] & 0xc0 ) >> 6; 69 ai->frequency = freq[fr]*100; 70 if (pr) printk (" Freq: %d Hz\n", (int) ai->frequency); 71 72 73 ai->framesize = ac3_frames[fr][frame >> 1]; 74 if ((frame & 1) && (fr == 1)) ai->framesize++; 75 ai->framesize = ai->framesize << 1; 76 if (pr) printk (" Framesize %d\n",(int) ai->framesize); 77 78 79 return 0; 80} 81EXPORT_SYMBOL(dvb_filter_get_ac3info); 82 83 84 85 86 87 88 89void dvb_filter_pes2ts_init(struct dvb_filter_pes2ts *p2ts, unsigned short pid, 90 dvb_filter_pes2ts_cb_t *cb, void *priv) 91{ 92 unsigned char *buf=p2ts->buf; 93 94 buf[0]=0x47; 95 buf[1]=(pid>>8); 96 buf[2]=pid&0xff; 97 p2ts->cc=0; 98 p2ts->cb=cb; 99 p2ts->priv=priv; 100} 101EXPORT_SYMBOL(dvb_filter_pes2ts_init); 102 103int dvb_filter_pes2ts(struct dvb_filter_pes2ts *p2ts, unsigned char *pes, 104 int len, int payload_start) 105{ 106 unsigned char *buf=p2ts->buf; 107 int ret=0, rest; 108 109 //len=6+((pes[4]<<8)|pes[5]); 110 111 if (payload_start) 112 buf[1]|=0x40; 113 else 114 buf[1]&=~0x40; 115 while (len>=184) { 116 buf[3]=0x10|((p2ts->cc++)&0x0f); 117 memcpy(buf+4, pes, 184); 118 if ((ret=p2ts->cb(p2ts->priv, buf))) 119 return ret; 120 len-=184; pes+=184; 121 buf[1]&=~0x40; 122 } 123 if (!len) 124 return 0; 125 buf[3]=0x30|((p2ts->cc++)&0x0f); 126 rest=183-len; 127 if (rest) { 128 buf[5]=0x00; 129 if (rest-1) 130 memset(buf+6, 0xff, rest-1); 131 } 132 buf[4]=rest; 133 memcpy(buf+5+rest, pes, len); 134 return p2ts->cb(p2ts->priv, buf); 135} 136EXPORT_SYMBOL(dvb_filter_pes2ts); 137