31 #include <linux/types.h>
32 #include <linux/kernel.h>
33 #include <linux/string.h>
43 #define PROG_STREAM_MAP 0xBC
44 #define PRIVATE_STREAM1 0xBD
45 #define PADDING_STREAM 0xBE
46 #define PRIVATE_STREAM2 0xBF
47 #define AUDIO_STREAM_S 0xC0
48 #define AUDIO_STREAM_E 0xDF
49 #define VIDEO_STREAM_S 0xE0
50 #define VIDEO_STREAM_E 0xEF
51 #define ECM_STREAM 0xF0
52 #define EMM_STREAM 0xF1
53 #define DSM_CC_STREAM 0xF2
54 #define ISO13522_STREAM 0xF3
55 #define PROG_STREAM_DIR 0xFF
57 #define PTS_DTS_FLAGS 0xC0
63 #define TRANS_ERROR 0x80
64 #define PAY_START 0x40
65 #define TRANS_PRIO 0x20
66 #define PID_MASK_HI 0x1F
68 #define TRANS_SCRMBL1 0x80
69 #define TRANS_SCRMBL2 0x40
70 #define ADAPT_FIELD 0x20
72 #define COUNT_MASK 0x0F
75 #define DISCON_IND 0x80
76 #define RAND_ACC_IND 0x40
77 #define ES_PRI_IND 0x20
79 #define OPCR_FLAG 0x08
80 #define SPLICE_FLAG 0x04
81 #define TRANS_PRIV 0x02
82 #define ADAP_EXT_FLAG 0x01
86 #define PIECE_RATE 0x40
87 #define SEAM_SPLICE 0x20
104 return dvbdmxfeed->
cb.
ts(buf, len,
NULL, 0,
110 static int dvb_filter_pes2ts_cb(
void *
priv,
unsigned char *
data)
114 dvbdmxfeed->
cb.
ts(data, 188,
NULL, 0,
125 dprintk(2,
"av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed);
137 dvb_filter_pes2ts_cb,
145 dvb_filter_pes2ts_cb,
153 dvb_filter_pes2ts_cb,
157 dvb_filter_pes2ts_cb,
168 dprintk(2,
"av7110:%p, \n", av7110);
202 dprintk(2,
"av7110:%p, \n", av7110);
258 if (((sync &~ 0x0f) == 0x000001e0) ||
259 ((sync &~ 0x1f) == 0x000001c0) ||
260 (sync == 0x000001bd))
268 if (len < blen || blen > dlen) {
276 dprintk(2,
"pread=0x%08lx, pwrite=0x%08lx\n",
277 (
unsigned long) buf->
pread, (
unsigned long) buf->
pwrite);
287 dprintk(2,
"av7110:%p, \n", av7110);
289 av7110->
mixer.volume_left = volleft;
290 av7110->
mixer.volume_right = volright;
294 volleft = (volleft * 256) / 1036;
295 volright = (volright * 256) / 1036;
300 if ((err = SendDAC(av7110, 3, 0x80 + volleft)))
302 return SendDAC(av7110, 4, volright);
305 volleft = 127 - volleft / 2;
306 volright = 127 - volright / 2;
312 vol = (volleft > volright) ? volleft : volright;
313 val = (vol * 0x73 / 255) << 8;
315 balance = ((volright - volleft) * 127) /
vol;
322 vol = (volleft > volright) ? volleft : volright;
323 val = (vol * 0x73 / 255) << 8;
325 balance = ((volright - volleft) * 127) /
vol;
337 dprintk(2,
"av7110:%p, \n", av7110);
341 if (!ret && !av7110->
playing) {
372 dprintk(2,
"av7110:%p, \n", av7110);
376 for (i = 7; i < count - 10; i++) {
378 if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3)
381 hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4);
382 vsize = ((p[1] &0x0F) << 8) | (p[2]);
386 dprintk(2,
"playback %dx%d fr=%d\n", hsize, vsize, sw);
399 static inline long aux_ring_buffer_write(
struct dvb_ringbuffer *rbuf,
400 const u8 *buf,
unsigned long count)
422 static void play_video_cb(
u8 *buf,
int count,
void *priv)
424 struct av7110 *av7110 = (
struct av7110 *) priv;
425 dprintk(2,
"av7110:%p, \n", av7110);
427 if ((buf[3] & 0xe0) == 0xe0) {
428 get_video_format(av7110, buf, count);
429 aux_ring_buffer_write(&av7110->
avout, buf, count);
431 aux_ring_buffer_write(&av7110->
aout, buf, count);
434 static void play_audio_cb(
u8 *buf,
int count,
void *priv)
436 struct av7110 *av7110 = (
struct av7110 *) priv;
437 dprintk(2,
"av7110:%p, \n", av7110);
439 aux_ring_buffer_write(&av7110->
aout, buf, count);
443 #define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096)
445 static ssize_t ts_play(
struct av7110 *av7110,
const char __user *buf,
446 unsigned long count,
int nonblock,
int type)
450 unsigned long todo =
count;
452 dprintk(2,
"%s: type %d cnt %lu\n", __func__, type, count);
455 kb = av7110->
kbuf[type];
472 write_ts_to_decoder(av7110, type, kb,
TS_SIZE);
481 #define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
482 dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
484 static ssize_t dvb_play(
struct av7110 *av7110,
const char __user *buf,
485 unsigned long count,
int nonblock,
int type)
487 unsigned long todo =
count,
n;
488 dprintk(2,
"av7110:%p, \n", av7110);
490 if (!av7110->
kbuf[type])
510 &av7110->
ipack[type]);
517 static ssize_t dvb_play_kernel(
struct av7110 *av7110,
const u8 *buf,
518 unsigned long count,
int nonblock,
int type)
520 unsigned long todo =
count,
n;
521 dprintk(2,
"av7110:%p, \n", av7110);
523 if (!av7110->
kbuf[type])
547 static ssize_t dvb_aplay(
struct av7110 *av7110,
const char __user *buf,
548 unsigned long count,
int nonblock,
int type)
550 unsigned long todo =
count,
n;
551 dprintk(2,
"av7110:%p, \n", av7110);
553 if (!av7110->
kbuf[type])
572 &av7110->
ipack[type]);
598 static int find_pes_header(
u8 const *buf,
long int length,
int *frags)
605 while (c < length - 3 && !found) {
606 if (buf[c] == 0x00 && buf[c + 1] == 0x00 &&
607 buf[c + 2] == 0x01) {
608 switch ( buf[c + 3] ) {
630 if (c == length - 3 && !found) {
631 if (buf[length - 1] == 0x00)
633 if (buf[length - 2] == 0x00 &&
634 buf[length - 1] == 0x00)
636 if (buf[length - 3] == 0x00 &&
637 buf[length - 2] == 0x00 &&
638 buf[length - 1] == 0x01)
657 if (buf[c] == 0x00 && buf[c + 1] == 0x01) {
663 if (buf[c] == 0x01) {
704 c2 = find_pes_header(buf + c, length - c, &p->
frags);
718 c2 = find_pes_header(buf + c + add, length - c - add, &p->
frags);
722 p_to_t(buf + c, c2 - c, pid, &p->
counter, p->
feed);
746 u8 tshead[4] = { 0x47, 0x00, 0x00, 0x10 };
753 tshead[1] |= (
u8)((pid & 0x1F00) >> 8);
754 tshead[2] |= (
u8)(pid & 0x00FF);
755 tshead[3] |= ((*counter)++ & 0x0F);
766 for (i = 6; i < fill + 4; i++) {
776 static void p_to_t(
u8 const *buf,
long int length,
u16 pid,
u8 *counter,
785 buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x01)
807 if (length - c >= (
TS_SIZE - 4)){
808 l = write_ts_header2(pid, counter, pes_start,
813 l = write_ts_header2(pid, counter, pes_start,
824 static int write_ts_to_decoder(
struct av7110 *av7110,
int type,
const u8 *buf,
size_t len)
854 struct av7110 *av7110 = (
struct av7110 *) demux->
priv;
856 dprintk(2,
"av7110:%p, \n", av7110);
874 return write_ts_to_decoder(av7110, feed->
pes_type, buf, len);
887 spin_lock_bh(&events->
lock);
890 if (wp == events->
eventr) {
899 spin_unlock_bh(&events->
lock);
925 spin_lock_bh(&events->
lock);
931 spin_unlock_bh(&events->
lock);
944 struct av7110 *av7110 = dvbdev->
priv;
945 unsigned int mask = 0;
947 dprintk(2,
"av7110:%p, \n", av7110);
950 poll_wait(file, &av7110->
avout.queue, wait);
952 poll_wait(file, &av7110->
video_events.wait_queue, wait);
968 static ssize_t dvb_video_write(
struct file *file,
const char __user *buf,
969 size_t count, loff_t *ppos)
972 struct av7110 *av7110 = dvbdev->
priv;
975 dprintk(2,
"av7110:%p, \n", av7110);
985 if (c == 0x47 && count %
TS_SIZE == 0)
991 static unsigned int dvb_audio_poll(
struct file *file,
poll_table *wait)
994 struct av7110 *av7110 = dvbdev->
priv;
995 unsigned int mask = 0;
997 dprintk(2,
"av7110:%p, \n", av7110);
999 poll_wait(file, &av7110->
aout.queue, wait);
1010 static ssize_t dvb_audio_write(
struct file *file,
const char __user *buf,
1011 size_t count, loff_t *ppos)
1014 struct av7110 *av7110 = dvbdev->
priv;
1017 dprintk(2,
"av7110:%p, \n", av7110);
1026 if (c == 0x47 && count %
TS_SIZE == 0)
1032 static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1034 #define MIN_IFRAME 400000
1036 static int play_iframe(
struct av7110 *av7110,
char __user *buf,
unsigned int len,
int nonblock)
1039 int progressive = 0;
1042 dprintk(2,
"av7110:%p, \n", av7110);
1050 for (i = 0; i < len; i++) {
1055 progressive = c & 0x08;
1059 match = (match == 1 || match == 2) ? 2 : 1;
1063 case 2:
if (c == 0x01)
1066 case 3:
if (c == 0xb5)
1069 case 4:
if ((c & 0xf0) == 0x10)
1081 dvb_play_kernel(av7110, iframe_header,
sizeof(iframe_header), 0, 1);
1083 for (i = 0; i <
n; i++)
1084 dvb_play(av7110, buf, len, 0, 1);
1095 static int dvb_video_ioctl(
struct file *file,
1096 unsigned int cmd,
void *parg)
1099 struct av7110 *av7110 = dvbdev->
priv;
1100 unsigned long arg = (
unsigned long) parg;
1103 dprintk(1,
"av7110:%p, cmd=%04x\n", av7110,cmd);
1181 ret = dvb_video_get_event(av7110, parg, file->
f_flags);
1228 ret = play_iframe(av7110, pic->
iFrame, pic->
size,
1303 static int dvb_audio_ioctl(
struct file *file,
1304 unsigned int cmd,
void *parg)
1307 struct av7110 *av7110 = dvbdev->
priv;
1308 unsigned long arg = (
unsigned long) parg;
1311 dprintk(1,
"av7110:%p, cmd=%04x\n", av7110,cmd);
1449 static int dvb_video_open(
struct inode *
inode,
struct file *file)
1452 struct av7110 *av7110 = dvbdev->
priv;
1455 dprintk(2,
"av7110:%p, \n", av7110);
1474 static int dvb_video_release(
struct inode *inode,
struct file *file)
1477 struct av7110 *av7110 = dvbdev->
priv;
1479 dprintk(2,
"av7110:%p, \n", av7110);
1488 static int dvb_audio_open(
struct inode *inode,
struct file *file)
1491 struct av7110 *av7110 = dvbdev->
priv;
1494 dprintk(2,
"av7110:%p, \n", av7110);
1503 static int dvb_audio_release(
struct inode *inode,
struct file *file)
1506 struct av7110 *av7110 = dvbdev->
priv;
1508 dprintk(2,
"av7110:%p, \n", av7110);
1522 .write = dvb_video_write,
1524 .open = dvb_video_open,
1525 .release = dvb_video_release,
1526 .poll = dvb_video_poll,
1535 .fops = &dvb_video_fops,
1536 .kernel_ioctl = dvb_video_ioctl,
1541 .write = dvb_audio_write,
1543 .open = dvb_audio_open,
1544 .release = dvb_audio_release,
1545 .poll = dvb_audio_poll,
1553 .fops = &dvb_audio_fops,
1554 .kernel_ioctl = dvb_audio_ioctl,
1598 void (*play[])(
u8 *,
int,
void *) = { play_audio_cb, play_video_cb };
1601 for (i = 0; i < 2; i++) {
1602 struct ipack *ipack = av7110->
ipack +
i;
1610 ipack->
data = av7110;