1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/module.h>
4 #include <linux/string.h>
5 #include "dvb_filter.h"
7 static u32 freq[4] = {480, 441, 320, 0};
9 static 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};
13 static 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}};
21 int dvb_filter_get_ac3info(u8 *mbuf, int count, struct dvb_audio_info *ai, int pr)
29 while ( !found && c < count){
32 if ( b[0] == 0x0b && b[1] == 0x77 )
39 if (!found) return -1;
41 printk(KERN_DEBUG "Audiostream: AC3");
44 if (c+5 >= count) return -1;
46 ai->layer = 0; // 0 for AC3
49 frame = (headr[2]&0x3f);
50 ai->bit_rate = ac3_bitrates[frame >> 1]*1000;
53 printk(KERN_CONT " BRate: %d kb/s", (int) ai->bit_rate/1000);
55 ai->frequency = (headr[2] & 0xc0 ) >> 6;
56 fr = (headr[2] & 0xc0 ) >> 6;
57 ai->frequency = freq[fr]*100;
59 printk(KERN_CONT " Freq: %d Hz\n", (int) ai->frequency);
61 ai->framesize = ac3_frames[fr][frame >> 1];
62 if ((frame & 1) && (fr == 1)) ai->framesize++;
63 ai->framesize = ai->framesize << 1;
65 printk(KERN_DEBUG " Framesize %d\n", (int) ai->framesize);
70 void dvb_filter_pes2ts_init(struct dvb_filter_pes2ts *p2ts, unsigned short pid,
71 dvb_filter_pes2ts_cb_t *cb, void *priv)
73 unsigned char *buf=p2ts->buf;
83 int dvb_filter_pes2ts(struct dvb_filter_pes2ts *p2ts, unsigned char *pes,
84 int len, int payload_start)
86 unsigned char *buf=p2ts->buf;
89 //len=6+((pes[4]<<8)|pes[5]);
96 buf[3]=0x10|((p2ts->cc++)&0x0f);
97 memcpy(buf+4, pes, 184);
98 if ((ret=p2ts->cb(p2ts->priv, buf)))
105 buf[3]=0x30|((p2ts->cc++)&0x0f);
110 memset(buf+6, 0xff, rest-1);
113 memcpy(buf+5+rest, pes, len);
114 return p2ts->cb(p2ts->priv, buf);