1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * av7110_av.c: audio and video MPEG decoder stuff
5 * Copyright (C) 1999-2002 Ralph Metzler
6 * & Marcus Metzler for convergence integrated media GmbH
8 * originally based on code by:
9 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
11 * the project's page is at https://linuxtv.org
14 #include <linux/ethtool.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/delay.h>
22 #include "av7110_hw.h"
23 #include "av7110_av.h"
24 #include "av7110_ipack.h"
26 /* MPEG-2 (ISO 13818 / H.222.0) stream types */
27 #define PROG_STREAM_MAP 0xBC
28 #define PRIVATE_STREAM1 0xBD
29 #define PADDING_STREAM 0xBE
30 #define PRIVATE_STREAM2 0xBF
31 #define AUDIO_STREAM_S 0xC0
32 #define AUDIO_STREAM_E 0xDF
33 #define VIDEO_STREAM_S 0xE0
34 #define VIDEO_STREAM_E 0xEF
35 #define ECM_STREAM 0xF0
36 #define EMM_STREAM 0xF1
37 #define DSM_CC_STREAM 0xF2
38 #define ISO13522_STREAM 0xF3
39 #define PROG_STREAM_DIR 0xFF
41 #define PTS_DTS_FLAGS 0xC0
47 #define TRANS_ERROR 0x80
48 #define PAY_START 0x40
49 #define TRANS_PRIO 0x20
50 #define PID_MASK_HI 0x1F
52 #define TRANS_SCRMBL1 0x80
53 #define TRANS_SCRMBL2 0x40
54 #define ADAPT_FIELD 0x20
56 #define COUNT_MASK 0x0F
59 #define DISCON_IND 0x80
60 #define RAND_ACC_IND 0x40
61 #define ES_PRI_IND 0x20
63 #define OPCR_FLAG 0x08
64 #define SPLICE_FLAG 0x04
65 #define TRANS_PRIV 0x02
66 #define ADAP_EXT_FLAG 0x01
68 // adaptation extension flags
70 #define PIECE_RATE 0x40
71 #define SEAM_SPLICE 0x20
74 static void p_to_t(u8
const *buf
, long int length
, u16 pid
,
75 u8
*counter
, struct dvb_demux_feed
*feed
);
76 static int write_ts_to_decoder(struct av7110
*av7110
, int type
, const u8
*buf
, size_t len
);
79 int av7110_record_cb(struct dvb_filter_pes2ts
*p2t
, u8
*buf
, size_t len
)
81 struct dvb_demux_feed
*dvbdmxfeed
= (struct dvb_demux_feed
*) p2t
->priv
;
83 if (!(dvbdmxfeed
->ts_type
& TS_PACKET
))
85 if (buf
[3] == 0xe0) // video PES do not have a length in TS
87 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
88 return dvbdmxfeed
->cb
.ts(buf
, len
, NULL
, 0,
89 &dvbdmxfeed
->feed
.ts
, NULL
);
91 return dvb_filter_pes2ts(p2t
, buf
, len
, 1);
94 static int dvb_filter_pes2ts_cb(void *priv
, unsigned char *data
)
96 struct dvb_demux_feed
*dvbdmxfeed
= (struct dvb_demux_feed
*) priv
;
98 dvbdmxfeed
->cb
.ts(data
, 188, NULL
, 0,
99 &dvbdmxfeed
->feed
.ts
, NULL
);
103 int av7110_av_start_record(struct av7110
*av7110
, int av
,
104 struct dvb_demux_feed
*dvbdmxfeed
)
107 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
109 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110
, dvbdmxfeed
);
111 if (av7110
->playing
|| (av7110
->rec_mode
& av
))
113 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
114 dvbdmx
->recording
= 1;
115 av7110
->rec_mode
|= av
;
117 switch (av7110
->rec_mode
) {
119 dvb_filter_pes2ts_init(&av7110
->p2t
[0],
120 dvbdmx
->pesfilter
[0]->pid
,
121 dvb_filter_pes2ts_cb
,
122 (void *) dvbdmx
->pesfilter
[0]);
123 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AudioPES
, 0);
127 dvb_filter_pes2ts_init(&av7110
->p2t
[1],
128 dvbdmx
->pesfilter
[1]->pid
,
129 dvb_filter_pes2ts_cb
,
130 (void *) dvbdmx
->pesfilter
[1]);
131 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, VideoPES
, 0);
135 dvb_filter_pes2ts_init(&av7110
->p2t
[0],
136 dvbdmx
->pesfilter
[0]->pid
,
137 dvb_filter_pes2ts_cb
,
138 (void *) dvbdmx
->pesfilter
[0]);
139 dvb_filter_pes2ts_init(&av7110
->p2t
[1],
140 dvbdmx
->pesfilter
[1]->pid
,
141 dvb_filter_pes2ts_cb
,
142 (void *) dvbdmx
->pesfilter
[1]);
143 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AV_PES
, 0);
149 int av7110_av_start_play(struct av7110
*av7110
, int av
)
152 dprintk(2, "av7110:%p, \n", av7110
);
154 if (av7110
->rec_mode
)
156 if (av7110
->playing
& av
)
159 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
161 if (av7110
->playing
== RP_NONE
) {
162 av7110_ipack_reset(&av7110
->ipack
[0]);
163 av7110_ipack_reset(&av7110
->ipack
[1]);
166 av7110
->playing
|= av
;
167 switch (av7110
->playing
) {
169 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AudioPES
, 0);
172 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, VideoPES
, 0);
177 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AV_PES
, 0);
183 int av7110_av_stop(struct av7110
*av7110
, int av
)
186 dprintk(2, "av7110:%p, \n", av7110
);
188 if (!(av7110
->playing
& av
) && !(av7110
->rec_mode
& av
))
190 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
191 if (av7110
->playing
) {
192 av7110
->playing
&= ~av
;
193 switch (av7110
->playing
) {
195 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AudioPES
, 0);
198 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, VideoPES
, 0);
201 ret
= av7110_set_vidmode(av7110
, av7110
->vidmode
);
205 av7110
->rec_mode
&= ~av
;
206 switch (av7110
->rec_mode
) {
208 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AudioPES
, 0);
211 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, VideoPES
, 0);
221 int av7110_pes_play(void *dest
, struct dvb_ringbuffer
*buf
, int dlen
)
228 wake_up(&buf
->queue
);
232 len
= dvb_ringbuffer_avail(buf
);
234 wake_up(&buf
->queue
);
237 sync
= DVB_RINGBUFFER_PEEK(buf
, 0) << 24;
238 sync
|= DVB_RINGBUFFER_PEEK(buf
, 1) << 16;
239 sync
|= DVB_RINGBUFFER_PEEK(buf
, 2) << 8;
240 sync
|= DVB_RINGBUFFER_PEEK(buf
, 3);
242 if (((sync
&~ 0x0f) == 0x000001e0) ||
243 ((sync
&~ 0x1f) == 0x000001c0) ||
244 (sync
== 0x000001bd))
247 DVB_RINGBUFFER_SKIP(buf
, 1);
249 blen
= DVB_RINGBUFFER_PEEK(buf
, 4) << 8;
250 blen
|= DVB_RINGBUFFER_PEEK(buf
, 5);
252 if (len
< blen
|| blen
> dlen
) {
253 //printk("buffer empty - avail %d blen %u dlen %d\n", len, blen, dlen);
254 wake_up(&buf
->queue
);
258 dvb_ringbuffer_read(buf
, dest
, (size_t) blen
);
260 dprintk(2, "pread=0x%08lx, pwrite=0x%08lx\n",
261 (unsigned long) buf
->pread
, (unsigned long) buf
->pwrite
);
262 wake_up(&buf
->queue
);
267 int av7110_set_volume(struct av7110
*av7110
, unsigned int volleft
,
268 unsigned int volright
)
270 unsigned int vol
, val
, balance
= 0;
273 dprintk(2, "av7110:%p, \n", av7110
);
275 av7110
->mixer
.volume_left
= volleft
;
276 av7110
->mixer
.volume_right
= volright
;
278 switch (av7110
->adac_type
) {
280 volleft
= (volleft
* 256) / 1036;
281 volright
= (volright
* 256) / 1036;
286 if ((err
= SendDAC(av7110
, 3, 0x80 + volleft
)))
288 return SendDAC(av7110
, 4, volright
);
290 case DVB_ADAC_CRYSTAL
:
291 volleft
= 127 - volleft
/ 2;
292 volright
= 127 - volright
/ 2;
293 i2c_writereg(av7110
, 0x20, 0x03, volleft
);
294 i2c_writereg(av7110
, 0x20, 0x04, volright
);
297 case DVB_ADAC_MSP34x0
:
298 vol
= (volleft
> volright
) ? volleft
: volright
;
299 val
= (vol
* 0x73 / 255) << 8;
301 balance
= ((volright
- volleft
) * 127) / vol
;
302 msp_writereg(av7110
, MSP_WR_DSP
, 0x0001, balance
<< 8);
303 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, val
); /* loudspeaker */
304 msp_writereg(av7110
, MSP_WR_DSP
, 0x0006, val
); /* headphonesr */
307 case DVB_ADAC_MSP34x5
:
308 vol
= (volleft
> volright
) ? volleft
: volright
;
309 val
= (vol
* 0x73 / 255) << 8;
311 balance
= ((volright
- volleft
) * 127) / vol
;
312 msp_writereg(av7110
, MSP_WR_DSP
, 0x0001, balance
<< 8);
313 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, val
); /* loudspeaker */
320 int av7110_set_vidmode(struct av7110
*av7110
, enum av7110_video_mode mode
)
323 dprintk(2, "av7110:%p, \n", av7110
);
325 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, LoadVidCode
, 1, mode
);
327 if (!ret
&& !av7110
->playing
) {
328 ret
= ChangePIDs(av7110
, av7110
->pids
[DMX_PES_VIDEO
],
329 av7110
->pids
[DMX_PES_AUDIO
],
330 av7110
->pids
[DMX_PES_TELETEXT
],
331 0, av7110
->pids
[DMX_PES_PCR
]);
333 ret
= av7110_fw_cmd(av7110
, COMTYPE_PIDFILTER
, Scan
, 0);
339 static enum av7110_video_mode sw2mode
[16] = {
340 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_NTSC
,
341 AV7110_VIDEO_MODE_NTSC
, AV7110_VIDEO_MODE_PAL
,
342 AV7110_VIDEO_MODE_NTSC
, AV7110_VIDEO_MODE_NTSC
,
343 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_NTSC
,
344 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_PAL
,
345 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_PAL
,
346 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_PAL
,
347 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_PAL
,
350 static int get_video_format(struct av7110
*av7110
, u8
*buf
, int count
)
358 dprintk(2, "av7110:%p, \n", av7110
);
362 for (i
= 7; i
< count
- 10; i
++) {
364 if (p
[0] || p
[1] || p
[2] != 0x01 || p
[3] != 0xb3)
367 hsize
= ((p
[1] &0xF0) >> 4) | (p
[0] << 4);
368 vsize
= ((p
[1] &0x0F) << 8) | (p
[2]);
370 ret
= av7110_set_vidmode(av7110
, sw2mode
[sw
]);
372 dprintk(2, "playback %dx%d fr=%d\n", hsize
, vsize
, sw
);
381 /****************************************************************************
382 * I/O buffer management and control
383 ****************************************************************************/
385 static inline long aux_ring_buffer_write(struct dvb_ringbuffer
*rbuf
,
386 const u8
*buf
, unsigned long count
)
388 unsigned long todo
= count
;
392 if (dvb_ringbuffer_free(rbuf
) < 2048) {
393 if (wait_event_interruptible(rbuf
->queue
,
394 (dvb_ringbuffer_free(rbuf
) >= 2048)))
397 free
= dvb_ringbuffer_free(rbuf
);
400 dvb_ringbuffer_write(rbuf
, buf
, free
);
408 static void play_video_cb(u8
*buf
, int count
, void *priv
)
410 struct av7110
*av7110
= (struct av7110
*) priv
;
411 dprintk(2, "av7110:%p, \n", av7110
);
413 if ((buf
[3] & 0xe0) == 0xe0) {
414 get_video_format(av7110
, buf
, count
);
415 aux_ring_buffer_write(&av7110
->avout
, buf
, count
);
417 aux_ring_buffer_write(&av7110
->aout
, buf
, count
);
420 static void play_audio_cb(u8
*buf
, int count
, void *priv
)
422 struct av7110
*av7110
= (struct av7110
*) priv
;
423 dprintk(2, "av7110:%p, \n", av7110
);
425 aux_ring_buffer_write(&av7110
->aout
, buf
, count
);
429 #define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096)
431 static ssize_t
ts_play(struct av7110
*av7110
, const char __user
*buf
,
432 unsigned long count
, int nonblock
, int type
)
434 struct dvb_ringbuffer
*rb
;
436 unsigned long todo
= count
;
438 dprintk(2, "%s: type %d cnt %lu\n", __func__
, type
, count
);
440 rb
= (type
) ? &av7110
->avout
: &av7110
->aout
;
441 kb
= av7110
->kbuf
[type
];
446 if (nonblock
&& !FREE_COND_TS
)
449 while (todo
>= TS_SIZE
) {
453 if (wait_event_interruptible(rb
->queue
, FREE_COND_TS
))
456 if (copy_from_user(kb
, buf
, TS_SIZE
))
458 write_ts_to_decoder(av7110
, type
, kb
, TS_SIZE
);
467 #define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
468 dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
470 static ssize_t
dvb_play(struct av7110
*av7110
, const char __user
*buf
,
471 unsigned long count
, int nonblock
, int type
)
473 unsigned long todo
= count
, n
;
474 dprintk(2, "av7110:%p, \n", av7110
);
476 if (!av7110
->kbuf
[type
])
479 if (nonblock
&& !FREE_COND
)
486 if (wait_event_interruptible(av7110
->avout
.queue
,
493 if (copy_from_user(av7110
->kbuf
[type
], buf
, n
))
495 av7110_ipack_instant_repack(av7110
->kbuf
[type
], n
,
496 &av7110
->ipack
[type
]);
503 static ssize_t
dvb_play_kernel(struct av7110
*av7110
, const u8
*buf
,
504 unsigned long count
, int nonblock
, int type
)
506 unsigned long todo
= count
, n
;
507 dprintk(2, "av7110:%p, \n", av7110
);
509 if (!av7110
->kbuf
[type
])
512 if (nonblock
&& !FREE_COND
)
519 if (wait_event_interruptible(av7110
->avout
.queue
,
526 av7110_ipack_instant_repack(buf
, n
, &av7110
->ipack
[type
]);
533 static ssize_t
dvb_aplay(struct av7110
*av7110
, const char __user
*buf
,
534 unsigned long count
, int nonblock
, int type
)
536 unsigned long todo
= count
, n
;
537 dprintk(2, "av7110:%p, \n", av7110
);
539 if (!av7110
->kbuf
[type
])
541 if (nonblock
&& dvb_ringbuffer_free(&av7110
->aout
) < 20 * 1024)
545 if (dvb_ringbuffer_free(&av7110
->aout
) < 20 * 1024) {
548 if (wait_event_interruptible(av7110
->aout
.queue
,
549 (dvb_ringbuffer_free(&av7110
->aout
) >= 20 * 1024)))
555 if (copy_from_user(av7110
->kbuf
[type
], buf
, n
))
557 av7110_ipack_instant_repack(av7110
->kbuf
[type
], n
,
558 &av7110
->ipack
[type
]);
565 void av7110_p2t_init(struct av7110_p2t
*p
, struct dvb_demux_feed
*feed
)
567 memset(p
->pes
, 0, TS_SIZE
);
575 static void clear_p2t(struct av7110_p2t
*p
)
577 memset(p
->pes
, 0, TS_SIZE
);
584 static int find_pes_header(u8
const *buf
, long int length
, int *frags
)
591 while (c
< length
- 3 && !found
) {
592 if (buf
[c
] == 0x00 && buf
[c
+ 1] == 0x00 &&
593 buf
[c
+ 2] == 0x01) {
594 switch ( buf
[c
+ 3] ) {
595 case PROG_STREAM_MAP
:
596 case PRIVATE_STREAM2
:
597 case PROG_STREAM_DIR
:
600 case PADDING_STREAM
:
602 case ISO13522_STREAM
:
603 case PRIVATE_STREAM1
:
604 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
605 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
616 if (c
== length
- 3 && !found
) {
617 if (buf
[length
- 1] == 0x00)
619 if (buf
[length
- 2] == 0x00 &&
620 buf
[length
- 1] == 0x00)
622 if (buf
[length
- 3] == 0x00 &&
623 buf
[length
- 2] == 0x00 &&
624 buf
[length
- 1] == 0x01)
632 void av7110_p2t_write(u8
const *buf
, long int length
, u16 pid
, struct av7110_p2t
*p
)
643 if (buf
[c
] == 0x00 && buf
[c
+ 1] == 0x01) {
649 if (buf
[c
] == 0x01) {
659 case PROG_STREAM_MAP
:
660 case PRIVATE_STREAM2
:
661 case PROG_STREAM_DIR
:
664 case PADDING_STREAM
:
666 case ISO13522_STREAM
:
667 case PRIVATE_STREAM1
:
668 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
669 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
675 memcpy(p
->pes
+ p
->pos
, buf
+ c
, (TS_SIZE
- 4) - p
->pos
);
676 c
+= (TS_SIZE
- 4) - p
->pos
;
677 p_to_t(p
->pes
, (TS_SIZE
- 4), pid
, &p
->counter
, p
->feed
);
690 c2
= find_pes_header(buf
+ c
, length
- c
, &p
->frags
);
691 if (c2
>= 0 && c2
< (TS_SIZE
- 4) - p
->pos
)
694 l
= (TS_SIZE
- 4) - p
->pos
;
695 memcpy(p
->pes
+ p
->pos
, buf
, l
);
698 p_to_t(p
->pes
, p
->pos
, pid
, &p
->counter
, p
->feed
);
704 c2
= find_pes_header(buf
+ c
+ add
, length
- c
- add
, &p
->frags
);
708 p_to_t(buf
+ c
, c2
- c
, pid
, &p
->counter
, p
->feed
);
716 rest
= l
% (TS_SIZE
- 4);
718 p_to_t(buf
+ c
, l
, pid
, &p
->counter
, p
->feed
);
719 memcpy(p
->pes
, buf
+ c
+ l
, rest
);
727 static int write_ts_header2(u16 pid
, u8
*counter
, int pes_start
, u8
*buf
, u8 length
)
732 u8 tshead
[4] = { 0x47, 0x00, 0x00, 0x10 };
734 fill
= (TS_SIZE
- 4) - length
;
739 tshead
[1] |= (u8
)((pid
& 0x1F00) >> 8);
740 tshead
[2] |= (u8
)(pid
& 0x00FF);
741 tshead
[3] |= ((*counter
)++ & 0x0F);
742 memcpy(buf
, tshead
, 4);
752 for (i
= 6; i
< fill
+ 4; i
++) {
762 static void p_to_t(u8
const *buf
, long int length
, u16 pid
, u8
*counter
,
763 struct dvb_demux_feed
*feed
)
771 buf
[0] == 0x00 && buf
[1] == 0x00 && buf
[2] == 0x01)
773 case PROG_STREAM_MAP
:
774 case PRIVATE_STREAM2
:
775 case PROG_STREAM_DIR
:
778 case PADDING_STREAM
:
780 case ISO13522_STREAM
:
781 case PRIVATE_STREAM1
:
782 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
783 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
792 memset(obuf
, 0, TS_SIZE
);
793 if (length
- c
>= (TS_SIZE
- 4)){
794 l
= write_ts_header2(pid
, counter
, pes_start
,
795 obuf
, (TS_SIZE
- 4));
796 memcpy(obuf
+ l
, buf
+ c
, TS_SIZE
- l
);
799 l
= write_ts_header2(pid
, counter
, pes_start
,
801 memcpy(obuf
+ l
, buf
+ c
, TS_SIZE
- l
);
804 feed
->cb
.ts(obuf
, 188, NULL
, 0, &feed
->feed
.ts
, NULL
);
810 static int write_ts_to_decoder(struct av7110
*av7110
, int type
, const u8
*buf
, size_t len
)
812 struct ipack
*ipack
= &av7110
->ipack
[type
];
814 if (buf
[1] & TRANS_ERROR
) {
815 av7110_ipack_reset(ipack
);
819 if (!(buf
[3] & PAYLOAD
))
822 if (buf
[1] & PAY_START
)
823 av7110_ipack_flush(ipack
);
825 if (buf
[3] & ADAPT_FIELD
) {
832 av7110_ipack_instant_repack(buf
+ 4, len
- 4, ipack
);
837 int av7110_write_to_decoder(struct dvb_demux_feed
*feed
, const u8
*buf
, size_t len
)
839 struct dvb_demux
*demux
= feed
->demux
;
840 struct av7110
*av7110
= (struct av7110
*) demux
->priv
;
842 dprintk(2, "av7110:%p, \n", av7110
);
844 if (av7110
->full_ts
&& demux
->dmx
.frontend
->source
!= DMX_MEMORY_FE
)
847 switch (feed
->pes_type
) {
849 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
853 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
)
860 return write_ts_to_decoder(av7110
, feed
->pes_type
, buf
, len
);
865 /******************************************************************************
866 * Video MPEG decoder events
867 ******************************************************************************/
868 void dvb_video_add_event(struct av7110
*av7110
, struct video_event
*event
)
870 struct dvb_video_events
*events
= &av7110
->video_events
;
873 spin_lock_bh(&events
->lock
);
875 wp
= (events
->eventw
+ 1) % MAX_VIDEO_EVENT
;
876 if (wp
== events
->eventr
) {
877 events
->overflow
= 1;
878 events
->eventr
= (events
->eventr
+ 1) % MAX_VIDEO_EVENT
;
882 memcpy(&events
->events
[events
->eventw
], event
, sizeof(struct video_event
));
885 spin_unlock_bh(&events
->lock
);
887 wake_up_interruptible(&events
->wait_queue
);
891 static int dvb_video_get_event (struct av7110
*av7110
, struct video_event
*event
, int flags
)
893 struct dvb_video_events
*events
= &av7110
->video_events
;
895 if (events
->overflow
) {
896 events
->overflow
= 0;
899 if (events
->eventw
== events
->eventr
) {
902 if (flags
& O_NONBLOCK
)
905 ret
= wait_event_interruptible(events
->wait_queue
,
906 events
->eventw
!= events
->eventr
);
911 spin_lock_bh(&events
->lock
);
913 memcpy(event
, &events
->events
[events
->eventr
],
914 sizeof(struct video_event
));
915 events
->eventr
= (events
->eventr
+ 1) % MAX_VIDEO_EVENT
;
917 spin_unlock_bh(&events
->lock
);
922 /******************************************************************************
923 * DVB device file operations
924 ******************************************************************************/
926 static __poll_t
dvb_video_poll(struct file
*file
, poll_table
*wait
)
928 struct dvb_device
*dvbdev
= file
->private_data
;
929 struct av7110
*av7110
= dvbdev
->priv
;
932 dprintk(2, "av7110:%p, \n", av7110
);
934 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
)
935 poll_wait(file
, &av7110
->avout
.queue
, wait
);
937 poll_wait(file
, &av7110
->video_events
.wait_queue
, wait
);
939 if (av7110
->video_events
.eventw
!= av7110
->video_events
.eventr
)
942 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
943 if (av7110
->playing
) {
945 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
947 /* if not playing: may play if asked for */
948 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
955 static ssize_t
dvb_video_write(struct file
*file
, const char __user
*buf
,
956 size_t count
, loff_t
*ppos
)
958 struct dvb_device
*dvbdev
= file
->private_data
;
959 struct av7110
*av7110
= dvbdev
->priv
;
962 dprintk(2, "av7110:%p, \n", av7110
);
964 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
)
967 if (av7110
->videostate
.stream_source
!= VIDEO_SOURCE_MEMORY
)
970 if (get_user(c
, buf
))
972 if (c
== 0x47 && count
% TS_SIZE
== 0)
973 return ts_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 1);
975 return dvb_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 1);
978 static __poll_t
dvb_audio_poll(struct file
*file
, poll_table
*wait
)
980 struct dvb_device
*dvbdev
= file
->private_data
;
981 struct av7110
*av7110
= dvbdev
->priv
;
984 dprintk(2, "av7110:%p, \n", av7110
);
986 poll_wait(file
, &av7110
->aout
.queue
, wait
);
988 if (av7110
->playing
) {
989 if (dvb_ringbuffer_free(&av7110
->aout
) >= 20 * 1024)
990 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
991 } else /* if not playing: may play if asked for */
992 mask
= (EPOLLOUT
| EPOLLWRNORM
);
997 static ssize_t
dvb_audio_write(struct file
*file
, const char __user
*buf
,
998 size_t count
, loff_t
*ppos
)
1000 struct dvb_device
*dvbdev
= file
->private_data
;
1001 struct av7110
*av7110
= dvbdev
->priv
;
1004 dprintk(2, "av7110:%p, \n", av7110
);
1006 if (av7110
->audiostate
.stream_source
!= AUDIO_SOURCE_MEMORY
) {
1007 printk(KERN_ERR
"not audio source memory\n");
1011 if (get_user(c
, buf
))
1013 if (c
== 0x47 && count
% TS_SIZE
== 0)
1014 return ts_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 0);
1016 return dvb_aplay(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 0);
1019 static u8 iframe_header
[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1021 #define MIN_IFRAME 400000
1023 static int play_iframe(struct av7110
*av7110
, char __user
*buf
, unsigned int len
, int nonblock
)
1026 int progressive
= 0;
1029 dprintk(2, "av7110:%p, \n", av7110
);
1034 if (!(av7110
->playing
& RP_VIDEO
)) {
1035 if (av7110_av_start_play(av7110
, RP_VIDEO
) < 0)
1039 /* search in buf for instances of 00 00 01 b5 1? */
1040 for (i
= 0; i
< len
; i
++) {
1042 if (get_user(c
, buf
+ i
))
1045 progressive
= c
& 0x08;
1049 match
= (match
== 1 || match
== 2) ? 2 : 1;
1053 case 2: if (c
== 0x01)
1056 case 3: if (c
== 0xb5)
1059 case 4: if ((c
& 0xf0) == 0x10)
1066 /* setting n always > 1, fixes problems when playing stillframes
1067 consisting of I- and P-Frames */
1068 n
= MIN_IFRAME
/ len
+ 1;
1070 /* FIXME: nonblock? */
1071 dvb_play_kernel(av7110
, iframe_header
, sizeof(iframe_header
), 0, 1);
1073 for (i
= 0; i
< n
; i
++)
1074 dvb_play(av7110
, buf
, len
, 0, 1);
1076 av7110_ipack_flush(&av7110
->ipack
[1]);
1079 return vidcom(av7110
, AV_VIDEO_CMD_FREEZE
, 1);
1084 #ifdef CONFIG_COMPAT
1085 struct compat_video_still_picture
{
1086 compat_uptr_t iFrame
;
1089 #define VIDEO_STILLPICTURE32 _IOW('o', 30, struct compat_video_still_picture)
1091 struct compat_video_event
{
1093 /* unused, make sure to use atomic time for y2038 if it ever gets used */
1094 compat_long_t timestamp
;
1097 unsigned int frame_rate
; /* in frames per 1000sec */
1098 unsigned char vsync_field
; /* unknown/odd/even/progressive */
1101 #define VIDEO_GET_EVENT32 _IOR('o', 28, struct compat_video_event)
1103 static int dvb_compat_video_get_event(struct av7110
*av7110
,
1104 struct compat_video_event
*event
, int flags
)
1106 struct video_event ev
;
1109 ret
= dvb_video_get_event(av7110
, &ev
, flags
);
1111 *event
= (struct compat_video_event
) {
1113 .timestamp
= ev
.timestamp
,
1114 .u
.size
= ev
.u
.size
,
1121 static int dvb_video_ioctl(struct file
*file
,
1122 unsigned int cmd
, void *parg
)
1124 struct dvb_device
*dvbdev
= file
->private_data
;
1125 struct av7110
*av7110
= dvbdev
->priv
;
1126 unsigned long arg
= (unsigned long) parg
;
1129 dprintk(1, "av7110:%p, cmd=%04x\n", av7110
,cmd
);
1131 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
1132 if ( cmd
!= VIDEO_GET_STATUS
&& cmd
!= VIDEO_GET_EVENT
&&
1133 cmd
!= VIDEO_GET_SIZE
) {
1138 if (mutex_lock_interruptible(&av7110
->ioctl_mutex
))
1139 return -ERESTARTSYS
;
1143 av7110
->videostate
.play_state
= VIDEO_STOPPED
;
1144 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
)
1145 ret
= av7110_av_stop(av7110
, RP_VIDEO
);
1147 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
,
1148 av7110
->videostate
.video_blank
? 0 : 1);
1150 av7110
->trickmode
= TRICK_NONE
;
1154 av7110
->trickmode
= TRICK_NONE
;
1155 if (av7110
->videostate
.play_state
== VIDEO_FREEZED
) {
1156 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1157 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1161 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
) {
1162 if (av7110
->playing
== RP_AV
) {
1163 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
1166 av7110
->playing
&= ~RP_VIDEO
;
1168 ret
= av7110_av_start_play(av7110
, RP_VIDEO
);
1171 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1173 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1177 av7110
->videostate
.play_state
= VIDEO_FREEZED
;
1178 if (av7110
->playing
& RP_VIDEO
)
1179 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Pause
, 0);
1181 ret
= vidcom(av7110
, AV_VIDEO_CMD_FREEZE
, 1);
1183 av7110
->trickmode
= TRICK_FREEZE
;
1186 case VIDEO_CONTINUE
:
1187 if (av7110
->playing
& RP_VIDEO
)
1188 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Continue
, 0);
1190 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1192 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1193 av7110
->trickmode
= TRICK_NONE
;
1197 case VIDEO_SELECT_SOURCE
:
1198 av7110
->videostate
.stream_source
= (video_stream_source_t
) arg
;
1201 case VIDEO_SET_BLANK
:
1202 av7110
->videostate
.video_blank
= (int) arg
;
1205 case VIDEO_GET_STATUS
:
1206 memcpy(parg
, &av7110
->videostate
, sizeof(struct video_status
));
1209 #ifdef CONFIG_COMPAT
1210 case VIDEO_GET_EVENT32
:
1211 ret
= dvb_compat_video_get_event(av7110
, parg
, file
->f_flags
);
1215 case VIDEO_GET_EVENT
:
1216 ret
= dvb_video_get_event(av7110
, parg
, file
->f_flags
);
1219 case VIDEO_GET_SIZE
:
1220 memcpy(parg
, &av7110
->video_size
, sizeof(video_size_t
));
1223 case VIDEO_SET_DISPLAY_FORMAT
:
1225 video_displayformat_t format
= (video_displayformat_t
) arg
;
1227 case VIDEO_PAN_SCAN
:
1228 av7110
->display_panscan
= VID_PAN_SCAN_PREF
;
1230 case VIDEO_LETTER_BOX
:
1231 av7110
->display_panscan
= VID_VC_AND_PS_PREF
;
1233 case VIDEO_CENTER_CUT_OUT
:
1234 av7110
->display_panscan
= VID_CENTRE_CUT_PREF
;
1241 av7110
->videostate
.display_format
= format
;
1242 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetPanScanType
,
1243 1, av7110
->display_panscan
);
1247 case VIDEO_SET_FORMAT
:
1252 av7110
->display_ar
= arg
;
1253 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetMonitorType
,
1257 #ifdef CONFIG_COMPAT
1258 case VIDEO_STILLPICTURE32
:
1260 struct compat_video_still_picture
*pic
=
1261 (struct compat_video_still_picture
*) parg
;
1262 av7110
->videostate
.stream_source
= VIDEO_SOURCE_MEMORY
;
1263 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1264 ret
= play_iframe(av7110
, compat_ptr(pic
->iFrame
),
1265 pic
->size
, file
->f_flags
& O_NONBLOCK
);
1270 case VIDEO_STILLPICTURE
:
1272 struct video_still_picture
*pic
=
1273 (struct video_still_picture
*) parg
;
1274 av7110
->videostate
.stream_source
= VIDEO_SOURCE_MEMORY
;
1275 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1276 ret
= play_iframe(av7110
, pic
->iFrame
, pic
->size
,
1277 file
->f_flags
& O_NONBLOCK
);
1281 case VIDEO_FAST_FORWARD
:
1282 //note: arg is ignored by firmware
1283 if (av7110
->playing
& RP_VIDEO
)
1284 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1285 __Scan_I
, 2, AV_PES
, 0);
1287 ret
= vidcom(av7110
, AV_VIDEO_CMD_FFWD
, arg
);
1289 av7110
->trickmode
= TRICK_FAST
;
1290 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1294 case VIDEO_SLOWMOTION
:
1295 if (av7110
->playing
&RP_VIDEO
) {
1296 if (av7110
->trickmode
!= TRICK_SLOW
)
1297 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Slow
, 2, 0, 0);
1299 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1301 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1303 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
, 0);
1305 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1308 av7110
->trickmode
= TRICK_SLOW
;
1309 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1313 case VIDEO_GET_CAPABILITIES
:
1314 *(int *)parg
= VIDEO_CAP_MPEG1
| VIDEO_CAP_MPEG2
|
1315 VIDEO_CAP_SYS
| VIDEO_CAP_PROG
;
1318 case VIDEO_CLEAR_BUFFER
:
1319 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1320 av7110_ipack_reset(&av7110
->ipack
[1]);
1321 if (av7110
->playing
== RP_AV
) {
1322 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1323 __Play
, 2, AV_PES
, 0);
1326 if (av7110
->trickmode
== TRICK_FAST
)
1327 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1328 __Scan_I
, 2, AV_PES
, 0);
1329 if (av7110
->trickmode
== TRICK_SLOW
) {
1330 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1333 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1335 if (av7110
->trickmode
== TRICK_FREEZE
)
1336 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
, 1);
1340 case VIDEO_SET_STREAMTYPE
:
1348 mutex_unlock(&av7110
->ioctl_mutex
);
1352 static int dvb_audio_ioctl(struct file
*file
,
1353 unsigned int cmd
, void *parg
)
1355 struct dvb_device
*dvbdev
= file
->private_data
;
1356 struct av7110
*av7110
= dvbdev
->priv
;
1357 unsigned long arg
= (unsigned long) parg
;
1360 dprintk(1, "av7110:%p, cmd=%04x\n", av7110
,cmd
);
1362 if (((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) &&
1363 (cmd
!= AUDIO_GET_STATUS
))
1366 if (mutex_lock_interruptible(&av7110
->ioctl_mutex
))
1367 return -ERESTARTSYS
;
1371 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
1372 ret
= av7110_av_stop(av7110
, RP_AUDIO
);
1374 ret
= audcom(av7110
, AUDIO_CMD_MUTE
);
1376 av7110
->audiostate
.play_state
= AUDIO_STOPPED
;
1380 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
1381 ret
= av7110_av_start_play(av7110
, RP_AUDIO
);
1383 ret
= audcom(av7110
, AUDIO_CMD_UNMUTE
);
1385 av7110
->audiostate
.play_state
= AUDIO_PLAYING
;
1389 ret
= audcom(av7110
, AUDIO_CMD_MUTE
);
1391 av7110
->audiostate
.play_state
= AUDIO_PAUSED
;
1394 case AUDIO_CONTINUE
:
1395 if (av7110
->audiostate
.play_state
== AUDIO_PAUSED
) {
1396 av7110
->audiostate
.play_state
= AUDIO_PLAYING
;
1397 ret
= audcom(av7110
, AUDIO_CMD_UNMUTE
| AUDIO_CMD_PCM16
);
1401 case AUDIO_SELECT_SOURCE
:
1402 av7110
->audiostate
.stream_source
= (audio_stream_source_t
) arg
;
1405 case AUDIO_SET_MUTE
:
1407 ret
= audcom(av7110
, arg
? AUDIO_CMD_MUTE
: AUDIO_CMD_UNMUTE
);
1409 av7110
->audiostate
.mute_state
= (int) arg
;
1413 case AUDIO_SET_AV_SYNC
:
1414 av7110
->audiostate
.AV_sync_state
= (int) arg
;
1415 ret
= audcom(av7110
, arg
? AUDIO_CMD_SYNC_ON
: AUDIO_CMD_SYNC_OFF
);
1418 case AUDIO_SET_BYPASS_MODE
:
1419 if (FW_VERSION(av7110
->arm_app
) < 0x2621)
1421 av7110
->audiostate
.bypass_mode
= (int)arg
;
1424 case AUDIO_CHANNEL_SELECT
:
1425 av7110
->audiostate
.channel_select
= (audio_channel_select_t
) arg
;
1426 switch(av7110
->audiostate
.channel_select
) {
1428 ret
= audcom(av7110
, AUDIO_CMD_STEREO
);
1430 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1431 i2c_writereg(av7110
, 0x20, 0x02, 0x49);
1432 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1433 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220);
1436 case AUDIO_MONO_LEFT
:
1437 ret
= audcom(av7110
, AUDIO_CMD_MONO_L
);
1439 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1440 i2c_writereg(av7110
, 0x20, 0x02, 0x4a);
1441 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1442 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0200);
1445 case AUDIO_MONO_RIGHT
:
1446 ret
= audcom(av7110
, AUDIO_CMD_MONO_R
);
1448 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1449 i2c_writereg(av7110
, 0x20, 0x02, 0x45);
1450 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1451 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0210);
1460 case AUDIO_GET_STATUS
:
1461 memcpy(parg
, &av7110
->audiostate
, sizeof(struct audio_status
));
1464 case AUDIO_GET_CAPABILITIES
:
1465 if (FW_VERSION(av7110
->arm_app
) < 0x2621)
1466 *(unsigned int *)parg
= AUDIO_CAP_LPCM
| AUDIO_CAP_MP1
| AUDIO_CAP_MP2
;
1468 *(unsigned int *)parg
= AUDIO_CAP_LPCM
| AUDIO_CAP_DTS
| AUDIO_CAP_AC3
|
1469 AUDIO_CAP_MP1
| AUDIO_CAP_MP2
;
1472 case AUDIO_CLEAR_BUFFER
:
1473 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1474 av7110_ipack_reset(&av7110
->ipack
[0]);
1475 if (av7110
->playing
== RP_AV
)
1476 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1477 __Play
, 2, AV_PES
, 0);
1483 case AUDIO_SET_MIXER
:
1485 struct audio_mixer
*amix
= (struct audio_mixer
*)parg
;
1486 ret
= av7110_set_volume(av7110
, amix
->volume_left
, amix
->volume_right
);
1490 case AUDIO_SET_STREAMTYPE
:
1497 mutex_unlock(&av7110
->ioctl_mutex
);
1502 static int dvb_video_open(struct inode
*inode
, struct file
*file
)
1504 struct dvb_device
*dvbdev
= file
->private_data
;
1505 struct av7110
*av7110
= dvbdev
->priv
;
1508 dprintk(2, "av7110:%p, \n", av7110
);
1510 if ((err
= dvb_generic_open(inode
, file
)) < 0)
1513 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
1514 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1515 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1516 av7110
->video_blank
= 1;
1517 av7110
->audiostate
.AV_sync_state
= 1;
1518 av7110
->videostate
.stream_source
= VIDEO_SOURCE_DEMUX
;
1520 /* empty event queue */
1521 av7110
->video_events
.eventr
= av7110
->video_events
.eventw
= 0;
1527 static int dvb_video_release(struct inode
*inode
, struct file
*file
)
1529 struct dvb_device
*dvbdev
= file
->private_data
;
1530 struct av7110
*av7110
= dvbdev
->priv
;
1532 dprintk(2, "av7110:%p, \n", av7110
);
1534 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
1535 av7110_av_stop(av7110
, RP_VIDEO
);
1538 return dvb_generic_release(inode
, file
);
1541 static int dvb_audio_open(struct inode
*inode
, struct file
*file
)
1543 struct dvb_device
*dvbdev
= file
->private_data
;
1544 struct av7110
*av7110
= dvbdev
->priv
;
1545 int err
= dvb_generic_open(inode
, file
);
1547 dprintk(2, "av7110:%p, \n", av7110
);
1551 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1552 av7110
->audiostate
.stream_source
= AUDIO_SOURCE_DEMUX
;
1556 static int dvb_audio_release(struct inode
*inode
, struct file
*file
)
1558 struct dvb_device
*dvbdev
= file
->private_data
;
1559 struct av7110
*av7110
= dvbdev
->priv
;
1561 dprintk(2, "av7110:%p, \n", av7110
);
1563 av7110_av_stop(av7110
, RP_AUDIO
);
1564 return dvb_generic_release(inode
, file
);
1569 /******************************************************************************
1570 * driver registration
1571 ******************************************************************************/
1573 static const struct file_operations dvb_video_fops
= {
1574 .owner
= THIS_MODULE
,
1575 .write
= dvb_video_write
,
1576 .unlocked_ioctl
= dvb_generic_ioctl
,
1577 .compat_ioctl
= dvb_generic_ioctl
,
1578 .open
= dvb_video_open
,
1579 .release
= dvb_video_release
,
1580 .poll
= dvb_video_poll
,
1581 .llseek
= noop_llseek
,
1584 static struct dvb_device dvbdev_video
= {
1587 .readers
= 5, /* arbitrary */
1589 .fops
= &dvb_video_fops
,
1590 .kernel_ioctl
= dvb_video_ioctl
,
1593 static const struct file_operations dvb_audio_fops
= {
1594 .owner
= THIS_MODULE
,
1595 .write
= dvb_audio_write
,
1596 .unlocked_ioctl
= dvb_generic_ioctl
,
1597 .compat_ioctl
= dvb_generic_ioctl
,
1598 .open
= dvb_audio_open
,
1599 .release
= dvb_audio_release
,
1600 .poll
= dvb_audio_poll
,
1601 .llseek
= noop_llseek
,
1604 static struct dvb_device dvbdev_audio
= {
1608 .fops
= &dvb_audio_fops
,
1609 .kernel_ioctl
= dvb_audio_ioctl
,
1613 int av7110_av_register(struct av7110
*av7110
)
1615 av7110
->audiostate
.AV_sync_state
= 0;
1616 av7110
->audiostate
.mute_state
= 0;
1617 av7110
->audiostate
.play_state
= AUDIO_STOPPED
;
1618 av7110
->audiostate
.stream_source
= AUDIO_SOURCE_DEMUX
;
1619 av7110
->audiostate
.channel_select
= AUDIO_STEREO
;
1620 av7110
->audiostate
.bypass_mode
= 0;
1622 av7110
->videostate
.video_blank
= 0;
1623 av7110
->videostate
.play_state
= VIDEO_STOPPED
;
1624 av7110
->videostate
.stream_source
= VIDEO_SOURCE_DEMUX
;
1625 av7110
->videostate
.video_format
= VIDEO_FORMAT_4_3
;
1626 av7110
->videostate
.display_format
= VIDEO_LETTER_BOX
;
1627 av7110
->display_ar
= VIDEO_FORMAT_4_3
;
1628 av7110
->display_panscan
= VID_VC_AND_PS_PREF
;
1630 init_waitqueue_head(&av7110
->video_events
.wait_queue
);
1631 spin_lock_init(&av7110
->video_events
.lock
);
1632 av7110
->video_events
.eventw
= av7110
->video_events
.eventr
= 0;
1633 av7110
->video_events
.overflow
= 0;
1634 memset(&av7110
->video_size
, 0, sizeof (video_size_t
));
1636 dvb_register_device(&av7110
->dvb_adapter
, &av7110
->video_dev
,
1637 &dvbdev_video
, av7110
, DVB_DEVICE_VIDEO
, 0);
1639 dvb_register_device(&av7110
->dvb_adapter
, &av7110
->audio_dev
,
1640 &dvbdev_audio
, av7110
, DVB_DEVICE_AUDIO
, 0);
1645 void av7110_av_unregister(struct av7110
*av7110
)
1647 dvb_unregister_device(av7110
->audio_dev
);
1648 dvb_unregister_device(av7110
->video_dev
);
1651 int av7110_av_init(struct av7110
*av7110
)
1653 void (*play
[])(u8
*, int, void *) = { play_audio_cb
, play_video_cb
};
1656 for (i
= 0; i
< 2; i
++) {
1657 struct ipack
*ipack
= av7110
->ipack
+ i
;
1659 ret
= av7110_ipack_init(ipack
, IPACKS
, play
[i
]);
1662 av7110_ipack_free(--ipack
);
1665 ipack
->data
= av7110
;
1668 dvb_ringbuffer_init(&av7110
->avout
, av7110
->iobuf
, AVOUTLEN
);
1669 dvb_ringbuffer_init(&av7110
->aout
, av7110
->iobuf
+ AVOUTLEN
, AOUTLEN
);
1671 av7110
->kbuf
[0] = (u8
*)(av7110
->iobuf
+ AVOUTLEN
+ AOUTLEN
+ BMPLEN
);
1672 av7110
->kbuf
[1] = av7110
->kbuf
[0] + 2 * IPACKS
;
1677 void av7110_av_exit(struct av7110
*av7110
)
1679 av7110_ipack_free(&av7110
->ipack
[0]);
1680 av7110_ipack_free(&av7110
->ipack
[1]);