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/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
21 #include "av7110_hw.h"
22 #include "av7110_av.h"
23 #include "av7110_ipack.h"
25 /* MPEG-2 (ISO 13818 / H.222.0) stream types */
26 #define PROG_STREAM_MAP 0xBC
27 #define PRIVATE_STREAM1 0xBD
28 #define PADDING_STREAM 0xBE
29 #define PRIVATE_STREAM2 0xBF
30 #define AUDIO_STREAM_S 0xC0
31 #define AUDIO_STREAM_E 0xDF
32 #define VIDEO_STREAM_S 0xE0
33 #define VIDEO_STREAM_E 0xEF
34 #define ECM_STREAM 0xF0
35 #define EMM_STREAM 0xF1
36 #define DSM_CC_STREAM 0xF2
37 #define ISO13522_STREAM 0xF3
38 #define PROG_STREAM_DIR 0xFF
40 #define PTS_DTS_FLAGS 0xC0
46 #define TRANS_ERROR 0x80
47 #define PAY_START 0x40
48 #define TRANS_PRIO 0x20
49 #define PID_MASK_HI 0x1F
51 #define TRANS_SCRMBL1 0x80
52 #define TRANS_SCRMBL2 0x40
53 #define ADAPT_FIELD 0x20
55 #define COUNT_MASK 0x0F
58 #define DISCON_IND 0x80
59 #define RAND_ACC_IND 0x40
60 #define ES_PRI_IND 0x20
62 #define OPCR_FLAG 0x08
63 #define SPLICE_FLAG 0x04
64 #define TRANS_PRIV 0x02
65 #define ADAP_EXT_FLAG 0x01
67 // adaptation extension flags
69 #define PIECE_RATE 0x40
70 #define SEAM_SPLICE 0x20
73 static void p_to_t(u8
const *buf
, long int length
, u16 pid
,
74 u8
*counter
, struct dvb_demux_feed
*feed
);
75 static int write_ts_to_decoder(struct av7110
*av7110
, int type
, const u8
*buf
, size_t len
);
78 int av7110_record_cb(struct dvb_filter_pes2ts
*p2t
, u8
*buf
, size_t len
)
80 struct dvb_demux_feed
*dvbdmxfeed
= (struct dvb_demux_feed
*) p2t
->priv
;
82 if (!(dvbdmxfeed
->ts_type
& TS_PACKET
))
84 if (buf
[3] == 0xe0) // video PES do not have a length in TS
86 if (dvbdmxfeed
->ts_type
& TS_PAYLOAD_ONLY
)
87 return dvbdmxfeed
->cb
.ts(buf
, len
, NULL
, 0,
88 &dvbdmxfeed
->feed
.ts
, NULL
);
90 return dvb_filter_pes2ts(p2t
, buf
, len
, 1);
93 static int dvb_filter_pes2ts_cb(void *priv
, unsigned char *data
)
95 struct dvb_demux_feed
*dvbdmxfeed
= (struct dvb_demux_feed
*) priv
;
97 dvbdmxfeed
->cb
.ts(data
, 188, NULL
, 0,
98 &dvbdmxfeed
->feed
.ts
, NULL
);
102 int av7110_av_start_record(struct av7110
*av7110
, int av
,
103 struct dvb_demux_feed
*dvbdmxfeed
)
106 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
108 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110
, dvbdmxfeed
);
110 if (av7110
->playing
|| (av7110
->rec_mode
& av
))
112 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
113 dvbdmx
->recording
= 1;
114 av7110
->rec_mode
|= av
;
116 switch (av7110
->rec_mode
) {
118 dvb_filter_pes2ts_init(&av7110
->p2t
[0],
119 dvbdmx
->pesfilter
[0]->pid
,
120 dvb_filter_pes2ts_cb
,
121 (void *) dvbdmx
->pesfilter
[0]);
122 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AudioPES
, 0);
126 dvb_filter_pes2ts_init(&av7110
->p2t
[1],
127 dvbdmx
->pesfilter
[1]->pid
,
128 dvb_filter_pes2ts_cb
,
129 (void *) dvbdmx
->pesfilter
[1]);
130 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, VideoPES
, 0);
134 dvb_filter_pes2ts_init(&av7110
->p2t
[0],
135 dvbdmx
->pesfilter
[0]->pid
,
136 dvb_filter_pes2ts_cb
,
137 (void *) dvbdmx
->pesfilter
[0]);
138 dvb_filter_pes2ts_init(&av7110
->p2t
[1],
139 dvbdmx
->pesfilter
[1]->pid
,
140 dvb_filter_pes2ts_cb
,
141 (void *) dvbdmx
->pesfilter
[1]);
142 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AV_PES
, 0);
148 int av7110_av_start_play(struct av7110
*av7110
, int av
)
151 dprintk(2, "av7110:%p, \n", av7110
);
153 if (av7110
->rec_mode
)
155 if (av7110
->playing
& av
)
158 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
160 if (av7110
->playing
== RP_NONE
) {
161 av7110_ipack_reset(&av7110
->ipack
[0]);
162 av7110_ipack_reset(&av7110
->ipack
[1]);
165 av7110
->playing
|= av
;
166 switch (av7110
->playing
) {
168 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AudioPES
, 0);
171 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, VideoPES
, 0);
176 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AV_PES
, 0);
182 int av7110_av_stop(struct av7110
*av7110
, int av
)
185 dprintk(2, "av7110:%p, \n", av7110
);
187 if (!(av7110
->playing
& av
) && !(av7110
->rec_mode
& av
))
189 av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
190 if (av7110
->playing
) {
191 av7110
->playing
&= ~av
;
192 switch (av7110
->playing
) {
194 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, AudioPES
, 0);
197 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Play
, 2, VideoPES
, 0);
200 ret
= av7110_set_vidmode(av7110
, av7110
->vidmode
);
204 av7110
->rec_mode
&= ~av
;
205 switch (av7110
->rec_mode
) {
207 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, AudioPES
, 0);
210 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Record
, 2, VideoPES
, 0);
220 int av7110_pes_play(void *dest
, struct dvb_ringbuffer
*buf
, int dlen
)
227 wake_up(&buf
->queue
);
231 len
= dvb_ringbuffer_avail(buf
);
233 wake_up(&buf
->queue
);
236 sync
= DVB_RINGBUFFER_PEEK(buf
, 0) << 24;
237 sync
|= DVB_RINGBUFFER_PEEK(buf
, 1) << 16;
238 sync
|= DVB_RINGBUFFER_PEEK(buf
, 2) << 8;
239 sync
|= DVB_RINGBUFFER_PEEK(buf
, 3);
241 if (((sync
&~ 0x0f) == 0x000001e0) ||
242 ((sync
&~ 0x1f) == 0x000001c0) ||
243 (sync
== 0x000001bd))
246 DVB_RINGBUFFER_SKIP(buf
, 1);
248 blen
= DVB_RINGBUFFER_PEEK(buf
, 4) << 8;
249 blen
|= DVB_RINGBUFFER_PEEK(buf
, 5);
251 if (len
< blen
|| blen
> dlen
) {
252 //printk("buffer empty - avail %d blen %u dlen %d\n", len, blen, dlen);
253 wake_up(&buf
->queue
);
257 dvb_ringbuffer_read(buf
, dest
, (size_t) blen
);
259 dprintk(2, "pread=0x%08lx, pwrite=0x%08lx\n",
260 (unsigned long) buf
->pread
, (unsigned long) buf
->pwrite
);
261 wake_up(&buf
->queue
);
266 int av7110_set_volume(struct av7110
*av7110
, unsigned int volleft
,
267 unsigned int volright
)
269 unsigned int vol
, val
, balance
= 0;
272 dprintk(2, "av7110:%p, \n", av7110
);
274 av7110
->mixer
.volume_left
= volleft
;
275 av7110
->mixer
.volume_right
= volright
;
277 switch (av7110
->adac_type
) {
279 volleft
= (volleft
* 256) / 1036;
280 volright
= (volright
* 256) / 1036;
285 if ((err
= SendDAC(av7110
, 3, 0x80 + volleft
)))
287 return SendDAC(av7110
, 4, volright
);
289 case DVB_ADAC_CRYSTAL
:
290 volleft
= 127 - volleft
/ 2;
291 volright
= 127 - volright
/ 2;
292 i2c_writereg(av7110
, 0x20, 0x03, volleft
);
293 i2c_writereg(av7110
, 0x20, 0x04, volright
);
296 case DVB_ADAC_MSP34x0
:
297 vol
= (volleft
> volright
) ? volleft
: volright
;
298 val
= (vol
* 0x73 / 255) << 8;
300 balance
= ((volright
- volleft
) * 127) / vol
;
301 msp_writereg(av7110
, MSP_WR_DSP
, 0x0001, balance
<< 8);
302 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, val
); /* loudspeaker */
303 msp_writereg(av7110
, MSP_WR_DSP
, 0x0006, val
); /* headphonesr */
306 case DVB_ADAC_MSP34x5
:
307 vol
= (volleft
> volright
) ? volleft
: volright
;
308 val
= (vol
* 0x73 / 255) << 8;
310 balance
= ((volright
- volleft
) * 127) / vol
;
311 msp_writereg(av7110
, MSP_WR_DSP
, 0x0001, balance
<< 8);
312 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, val
); /* loudspeaker */
319 int av7110_set_vidmode(struct av7110
*av7110
, enum av7110_video_mode mode
)
322 dprintk(2, "av7110:%p, \n", av7110
);
324 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, LoadVidCode
, 1, mode
);
326 if (!ret
&& !av7110
->playing
) {
327 ret
= ChangePIDs(av7110
, av7110
->pids
[DMX_PES_VIDEO
],
328 av7110
->pids
[DMX_PES_AUDIO
],
329 av7110
->pids
[DMX_PES_TELETEXT
],
330 0, av7110
->pids
[DMX_PES_PCR
]);
332 ret
= av7110_fw_cmd(av7110
, COMTYPE_PIDFILTER
, Scan
, 0);
338 static enum av7110_video_mode sw2mode
[16] = {
339 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_NTSC
,
340 AV7110_VIDEO_MODE_NTSC
, AV7110_VIDEO_MODE_PAL
,
341 AV7110_VIDEO_MODE_NTSC
, AV7110_VIDEO_MODE_NTSC
,
342 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_NTSC
,
343 AV7110_VIDEO_MODE_PAL
, AV7110_VIDEO_MODE_PAL
,
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
,
349 static int get_video_format(struct av7110
*av7110
, u8
*buf
, int count
)
357 dprintk(2, "av7110:%p, \n", av7110
);
361 for (i
= 7; i
< count
- 10; i
++) {
363 if (p
[0] || p
[1] || p
[2] != 0x01 || p
[3] != 0xb3)
366 hsize
= ((p
[1] &0xF0) >> 4) | (p
[0] << 4);
367 vsize
= ((p
[1] &0x0F) << 8) | (p
[2]);
369 ret
= av7110_set_vidmode(av7110
, sw2mode
[sw
]);
371 dprintk(2, "playback %dx%d fr=%d\n", hsize
, vsize
, sw
);
380 /****************************************************************************
381 * I/O buffer management and control
382 ****************************************************************************/
384 static inline long aux_ring_buffer_write(struct dvb_ringbuffer
*rbuf
,
385 const u8
*buf
, unsigned long count
)
387 unsigned long todo
= count
;
391 if (dvb_ringbuffer_free(rbuf
) < 2048) {
392 if (wait_event_interruptible(rbuf
->queue
,
393 (dvb_ringbuffer_free(rbuf
) >= 2048)))
396 free
= dvb_ringbuffer_free(rbuf
);
399 dvb_ringbuffer_write(rbuf
, buf
, free
);
407 static void play_video_cb(u8
*buf
, int count
, void *priv
)
409 struct av7110
*av7110
= (struct av7110
*) priv
;
410 dprintk(2, "av7110:%p, \n", av7110
);
412 if ((buf
[3] & 0xe0) == 0xe0) {
413 get_video_format(av7110
, buf
, count
);
414 aux_ring_buffer_write(&av7110
->avout
, buf
, count
);
416 aux_ring_buffer_write(&av7110
->aout
, buf
, count
);
419 static void play_audio_cb(u8
*buf
, int count
, void *priv
)
421 struct av7110
*av7110
= (struct av7110
*) priv
;
422 dprintk(2, "av7110:%p, \n", av7110
);
424 aux_ring_buffer_write(&av7110
->aout
, buf
, count
);
428 #define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096)
430 static ssize_t
ts_play(struct av7110
*av7110
, const char __user
*buf
,
431 unsigned long count
, int nonblock
, int type
)
433 struct dvb_ringbuffer
*rb
;
435 unsigned long todo
= count
;
437 dprintk(2, "%s: type %d cnt %lu\n", __func__
, type
, count
);
439 rb
= (type
) ? &av7110
->avout
: &av7110
->aout
;
440 kb
= av7110
->kbuf
[type
];
445 if (nonblock
&& !FREE_COND_TS
)
448 while (todo
>= TS_SIZE
) {
452 if (wait_event_interruptible(rb
->queue
, FREE_COND_TS
))
455 if (copy_from_user(kb
, buf
, TS_SIZE
))
457 write_ts_to_decoder(av7110
, type
, kb
, TS_SIZE
);
466 #define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
467 dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
469 static ssize_t
dvb_play(struct av7110
*av7110
, const char __user
*buf
,
470 unsigned long count
, int nonblock
, int type
)
472 unsigned long todo
= count
, n
;
473 dprintk(2, "av7110:%p, \n", av7110
);
475 if (!av7110
->kbuf
[type
])
478 if (nonblock
&& !FREE_COND
)
485 if (wait_event_interruptible(av7110
->avout
.queue
,
492 if (copy_from_user(av7110
->kbuf
[type
], buf
, n
))
494 av7110_ipack_instant_repack(av7110
->kbuf
[type
], n
,
495 &av7110
->ipack
[type
]);
502 static ssize_t
dvb_play_kernel(struct av7110
*av7110
, const u8
*buf
,
503 unsigned long count
, int nonblock
, int type
)
505 unsigned long todo
= count
, n
;
506 dprintk(2, "av7110:%p, \n", av7110
);
508 if (!av7110
->kbuf
[type
])
511 if (nonblock
&& !FREE_COND
)
518 if (wait_event_interruptible(av7110
->avout
.queue
,
525 av7110_ipack_instant_repack(buf
, n
, &av7110
->ipack
[type
]);
532 static ssize_t
dvb_aplay(struct av7110
*av7110
, const char __user
*buf
,
533 unsigned long count
, int nonblock
, int type
)
535 unsigned long todo
= count
, n
;
536 dprintk(2, "av7110:%p, \n", av7110
);
538 if (!av7110
->kbuf
[type
])
540 if (nonblock
&& dvb_ringbuffer_free(&av7110
->aout
) < 20 * 1024)
544 if (dvb_ringbuffer_free(&av7110
->aout
) < 20 * 1024) {
547 if (wait_event_interruptible(av7110
->aout
.queue
,
548 (dvb_ringbuffer_free(&av7110
->aout
) >= 20 * 1024)))
554 if (copy_from_user(av7110
->kbuf
[type
], buf
, n
))
556 av7110_ipack_instant_repack(av7110
->kbuf
[type
], n
,
557 &av7110
->ipack
[type
]);
564 void av7110_p2t_init(struct av7110_p2t
*p
, struct dvb_demux_feed
*feed
)
566 memset(p
->pes
, 0, TS_SIZE
);
574 static void clear_p2t(struct av7110_p2t
*p
)
576 memset(p
->pes
, 0, TS_SIZE
);
583 static int find_pes_header(u8
const *buf
, long int length
, int *frags
)
590 while (c
< length
- 3 && !found
) {
591 if (buf
[c
] == 0x00 && buf
[c
+ 1] == 0x00 &&
592 buf
[c
+ 2] == 0x01) {
593 switch ( buf
[c
+ 3] ) {
594 case PROG_STREAM_MAP
:
595 case PRIVATE_STREAM2
:
596 case PROG_STREAM_DIR
:
599 case PADDING_STREAM
:
601 case ISO13522_STREAM
:
602 case PRIVATE_STREAM1
:
603 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
604 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
615 if (c
== length
- 3 && !found
) {
616 if (buf
[length
- 1] == 0x00)
618 if (buf
[length
- 2] == 0x00 &&
619 buf
[length
- 1] == 0x00)
621 if (buf
[length
- 3] == 0x00 &&
622 buf
[length
- 2] == 0x00 &&
623 buf
[length
- 1] == 0x01)
631 void av7110_p2t_write(u8
const *buf
, long int length
, u16 pid
, struct av7110_p2t
*p
)
642 if (buf
[c
] == 0x00 && buf
[c
+ 1] == 0x01) {
648 if (buf
[c
] == 0x01) {
658 case PROG_STREAM_MAP
:
659 case PRIVATE_STREAM2
:
660 case PROG_STREAM_DIR
:
663 case PADDING_STREAM
:
665 case ISO13522_STREAM
:
666 case PRIVATE_STREAM1
:
667 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
668 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
674 memcpy(p
->pes
+ p
->pos
, buf
+ c
, (TS_SIZE
- 4) - p
->pos
);
675 c
+= (TS_SIZE
- 4) - p
->pos
;
676 p_to_t(p
->pes
, (TS_SIZE
- 4), pid
, &p
->counter
, p
->feed
);
689 c2
= find_pes_header(buf
+ c
, length
- c
, &p
->frags
);
690 if (c2
>= 0 && c2
< (TS_SIZE
- 4) - p
->pos
)
693 l
= (TS_SIZE
- 4) - p
->pos
;
694 memcpy(p
->pes
+ p
->pos
, buf
, l
);
697 p_to_t(p
->pes
, p
->pos
, pid
, &p
->counter
, p
->feed
);
703 c2
= find_pes_header(buf
+ c
+ add
, length
- c
- add
, &p
->frags
);
707 p_to_t(buf
+ c
, c2
- c
, pid
, &p
->counter
, p
->feed
);
715 rest
= l
% (TS_SIZE
- 4);
717 p_to_t(buf
+ c
, l
, pid
, &p
->counter
, p
->feed
);
718 memcpy(p
->pes
, buf
+ c
+ l
, rest
);
726 static int write_ts_header2(u16 pid
, u8
*counter
, int pes_start
, u8
*buf
, u8 length
)
731 u8 tshead
[4] = { 0x47, 0x00, 0x00, 0x10 };
733 fill
= (TS_SIZE
- 4) - length
;
738 tshead
[1] |= (u8
)((pid
& 0x1F00) >> 8);
739 tshead
[2] |= (u8
)(pid
& 0x00FF);
740 tshead
[3] |= ((*counter
)++ & 0x0F);
741 memcpy(buf
, tshead
, 4);
751 for (i
= 6; i
< fill
+ 4; i
++) {
761 static void p_to_t(u8
const *buf
, long int length
, u16 pid
, u8
*counter
,
762 struct dvb_demux_feed
*feed
)
770 buf
[0] == 0x00 && buf
[1] == 0x00 && buf
[2] == 0x01)
772 case PROG_STREAM_MAP
:
773 case PRIVATE_STREAM2
:
774 case PROG_STREAM_DIR
:
777 case PADDING_STREAM
:
779 case ISO13522_STREAM
:
780 case PRIVATE_STREAM1
:
781 case AUDIO_STREAM_S
... AUDIO_STREAM_E
:
782 case VIDEO_STREAM_S
... VIDEO_STREAM_E
:
791 memset(obuf
, 0, TS_SIZE
);
792 if (length
- c
>= (TS_SIZE
- 4)){
793 l
= write_ts_header2(pid
, counter
, pes_start
,
794 obuf
, (TS_SIZE
- 4));
795 memcpy(obuf
+ l
, buf
+ c
, TS_SIZE
- l
);
798 l
= write_ts_header2(pid
, counter
, pes_start
,
800 memcpy(obuf
+ l
, buf
+ c
, TS_SIZE
- l
);
803 feed
->cb
.ts(obuf
, 188, NULL
, 0, &feed
->feed
.ts
, NULL
);
809 static int write_ts_to_decoder(struct av7110
*av7110
, int type
, const u8
*buf
, size_t len
)
811 struct ipack
*ipack
= &av7110
->ipack
[type
];
813 if (buf
[1] & TRANS_ERROR
) {
814 av7110_ipack_reset(ipack
);
818 if (!(buf
[3] & PAYLOAD
))
821 if (buf
[1] & PAY_START
)
822 av7110_ipack_flush(ipack
);
824 if (buf
[3] & ADAPT_FIELD
) {
831 av7110_ipack_instant_repack(buf
+ 4, len
- 4, ipack
);
836 int av7110_write_to_decoder(struct dvb_demux_feed
*feed
, const u8
*buf
, size_t len
)
838 struct dvb_demux
*demux
= feed
->demux
;
839 struct av7110
*av7110
= (struct av7110
*) demux
->priv
;
841 dprintk(2, "av7110:%p, \n", av7110
);
843 if (av7110
->full_ts
&& demux
->dmx
.frontend
->source
!= DMX_MEMORY_FE
)
846 switch (feed
->pes_type
) {
848 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
852 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
)
859 return write_ts_to_decoder(av7110
, feed
->pes_type
, buf
, len
);
864 /******************************************************************************
865 * Video MPEG decoder events
866 ******************************************************************************/
867 void dvb_video_add_event(struct av7110
*av7110
, struct video_event
*event
)
869 struct dvb_video_events
*events
= &av7110
->video_events
;
872 spin_lock_bh(&events
->lock
);
874 wp
= (events
->eventw
+ 1) % MAX_VIDEO_EVENT
;
875 if (wp
== events
->eventr
) {
876 events
->overflow
= 1;
877 events
->eventr
= (events
->eventr
+ 1) % MAX_VIDEO_EVENT
;
881 memcpy(&events
->events
[events
->eventw
], event
, sizeof(struct video_event
));
884 spin_unlock_bh(&events
->lock
);
886 wake_up_interruptible(&events
->wait_queue
);
890 static int dvb_video_get_event (struct av7110
*av7110
, struct video_event
*event
, int flags
)
892 struct dvb_video_events
*events
= &av7110
->video_events
;
894 if (events
->overflow
) {
895 events
->overflow
= 0;
898 if (events
->eventw
== events
->eventr
) {
901 if (flags
& O_NONBLOCK
)
904 ret
= wait_event_interruptible(events
->wait_queue
,
905 events
->eventw
!= events
->eventr
);
910 spin_lock_bh(&events
->lock
);
912 memcpy(event
, &events
->events
[events
->eventr
],
913 sizeof(struct video_event
));
914 events
->eventr
= (events
->eventr
+ 1) % MAX_VIDEO_EVENT
;
916 spin_unlock_bh(&events
->lock
);
921 /******************************************************************************
922 * DVB device file operations
923 ******************************************************************************/
925 static __poll_t
dvb_video_poll(struct file
*file
, poll_table
*wait
)
927 struct dvb_device
*dvbdev
= file
->private_data
;
928 struct av7110
*av7110
= dvbdev
->priv
;
931 dprintk(2, "av7110:%p, \n", av7110
);
933 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
)
934 poll_wait(file
, &av7110
->avout
.queue
, wait
);
936 poll_wait(file
, &av7110
->video_events
.wait_queue
, wait
);
938 if (av7110
->video_events
.eventw
!= av7110
->video_events
.eventr
)
941 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
942 if (av7110
->playing
) {
944 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
946 /* if not playing: may play if asked for */
947 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
954 static ssize_t
dvb_video_write(struct file
*file
, const char __user
*buf
,
955 size_t count
, loff_t
*ppos
)
957 struct dvb_device
*dvbdev
= file
->private_data
;
958 struct av7110
*av7110
= dvbdev
->priv
;
961 dprintk(2, "av7110:%p, \n", av7110
);
963 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
)
966 if (av7110
->videostate
.stream_source
!= VIDEO_SOURCE_MEMORY
)
969 if (get_user(c
, buf
))
971 if (c
== 0x47 && count
% TS_SIZE
== 0)
972 return ts_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 1);
974 return dvb_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 1);
977 static __poll_t
dvb_audio_poll(struct file
*file
, poll_table
*wait
)
979 struct dvb_device
*dvbdev
= file
->private_data
;
980 struct av7110
*av7110
= dvbdev
->priv
;
983 dprintk(2, "av7110:%p, \n", av7110
);
985 poll_wait(file
, &av7110
->aout
.queue
, wait
);
987 if (av7110
->playing
) {
988 if (dvb_ringbuffer_free(&av7110
->aout
) >= 20 * 1024)
989 mask
|= (EPOLLOUT
| EPOLLWRNORM
);
990 } else /* if not playing: may play if asked for */
991 mask
= (EPOLLOUT
| EPOLLWRNORM
);
996 static ssize_t
dvb_audio_write(struct file
*file
, const char __user
*buf
,
997 size_t count
, loff_t
*ppos
)
999 struct dvb_device
*dvbdev
= file
->private_data
;
1000 struct av7110
*av7110
= dvbdev
->priv
;
1003 dprintk(2, "av7110:%p, \n", av7110
);
1005 if (av7110
->audiostate
.stream_source
!= AUDIO_SOURCE_MEMORY
) {
1006 printk(KERN_ERR
"not audio source memory\n");
1010 if (get_user(c
, buf
))
1012 if (c
== 0x47 && count
% TS_SIZE
== 0)
1013 return ts_play(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 0);
1015 return dvb_aplay(av7110
, buf
, count
, file
->f_flags
& O_NONBLOCK
, 0);
1018 static u8 iframe_header
[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1020 #define MIN_IFRAME 400000
1022 static int play_iframe(struct av7110
*av7110
, char __user
*buf
, unsigned int len
, int nonblock
)
1025 int progressive
= 0;
1028 dprintk(2, "av7110:%p, \n", av7110
);
1033 if (!(av7110
->playing
& RP_VIDEO
)) {
1034 if (av7110_av_start_play(av7110
, RP_VIDEO
) < 0)
1038 /* search in buf for instances of 00 00 01 b5 1? */
1039 for (i
= 0; i
< len
; i
++) {
1041 if (get_user(c
, buf
+ i
))
1044 progressive
= c
& 0x08;
1048 match
= (match
== 1 || match
== 2) ? 2 : 1;
1052 case 2: if (c
== 0x01)
1055 case 3: if (c
== 0xb5)
1058 case 4: if ((c
& 0xf0) == 0x10)
1065 /* setting n always > 1, fixes problems when playing stillframes
1066 consisting of I- and P-Frames */
1067 n
= MIN_IFRAME
/ len
+ 1;
1069 /* FIXME: nonblock? */
1070 dvb_play_kernel(av7110
, iframe_header
, sizeof(iframe_header
), 0, 1);
1072 for (i
= 0; i
< n
; i
++)
1073 dvb_play(av7110
, buf
, len
, 0, 1);
1075 av7110_ipack_flush(&av7110
->ipack
[1]);
1078 return vidcom(av7110
, AV_VIDEO_CMD_FREEZE
, 1);
1083 #ifdef CONFIG_COMPAT
1084 struct compat_video_still_picture
{
1085 compat_uptr_t iFrame
;
1088 #define VIDEO_STILLPICTURE32 _IOW('o', 30, struct compat_video_still_picture)
1090 struct compat_video_event
{
1092 /* unused, make sure to use atomic time for y2038 if it ever gets used */
1093 compat_long_t timestamp
;
1096 unsigned int frame_rate
; /* in frames per 1000sec */
1097 unsigned char vsync_field
; /* unknown/odd/even/progressive */
1100 #define VIDEO_GET_EVENT32 _IOR('o', 28, struct compat_video_event)
1102 static int dvb_compat_video_get_event(struct av7110
*av7110
,
1103 struct compat_video_event
*event
, int flags
)
1105 struct video_event ev
;
1108 ret
= dvb_video_get_event(av7110
, &ev
, flags
);
1110 *event
= (struct compat_video_event
) {
1112 .timestamp
= ev
.timestamp
,
1113 .u
.size
= ev
.u
.size
,
1120 static int dvb_video_ioctl(struct file
*file
,
1121 unsigned int cmd
, void *parg
)
1123 struct dvb_device
*dvbdev
= file
->private_data
;
1124 struct av7110
*av7110
= dvbdev
->priv
;
1125 unsigned long arg
= (unsigned long) parg
;
1128 dprintk(1, "av7110:%p, cmd=%04x\n", av7110
,cmd
);
1130 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
1131 if ( cmd
!= VIDEO_GET_STATUS
&& cmd
!= VIDEO_GET_EVENT
&&
1132 cmd
!= VIDEO_GET_SIZE
) {
1137 if (mutex_lock_interruptible(&av7110
->ioctl_mutex
))
1138 return -ERESTARTSYS
;
1142 av7110
->videostate
.play_state
= VIDEO_STOPPED
;
1143 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
)
1144 ret
= av7110_av_stop(av7110
, RP_VIDEO
);
1146 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
,
1147 av7110
->videostate
.video_blank
? 0 : 1);
1149 av7110
->trickmode
= TRICK_NONE
;
1153 av7110
->trickmode
= TRICK_NONE
;
1154 if (av7110
->videostate
.play_state
== VIDEO_FREEZED
) {
1155 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1156 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1160 if (av7110
->videostate
.stream_source
== VIDEO_SOURCE_MEMORY
) {
1161 if (av7110
->playing
== RP_AV
) {
1162 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Stop
, 0);
1165 av7110
->playing
&= ~RP_VIDEO
;
1167 ret
= av7110_av_start_play(av7110
, RP_VIDEO
);
1170 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1172 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1176 av7110
->videostate
.play_state
= VIDEO_FREEZED
;
1177 if (av7110
->playing
& RP_VIDEO
)
1178 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Pause
, 0);
1180 ret
= vidcom(av7110
, AV_VIDEO_CMD_FREEZE
, 1);
1182 av7110
->trickmode
= TRICK_FREEZE
;
1185 case VIDEO_CONTINUE
:
1186 if (av7110
->playing
& RP_VIDEO
)
1187 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Continue
, 0);
1189 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1191 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1192 av7110
->trickmode
= TRICK_NONE
;
1196 case VIDEO_SELECT_SOURCE
:
1197 av7110
->videostate
.stream_source
= (video_stream_source_t
) arg
;
1200 case VIDEO_SET_BLANK
:
1201 av7110
->videostate
.video_blank
= (int) arg
;
1204 case VIDEO_GET_STATUS
:
1205 memcpy(parg
, &av7110
->videostate
, sizeof(struct video_status
));
1208 #ifdef CONFIG_COMPAT
1209 case VIDEO_GET_EVENT32
:
1210 ret
= dvb_compat_video_get_event(av7110
, parg
, file
->f_flags
);
1214 case VIDEO_GET_EVENT
:
1215 ret
= dvb_video_get_event(av7110
, parg
, file
->f_flags
);
1218 case VIDEO_GET_SIZE
:
1219 memcpy(parg
, &av7110
->video_size
, sizeof(video_size_t
));
1222 case VIDEO_SET_DISPLAY_FORMAT
:
1224 video_displayformat_t format
= (video_displayformat_t
) arg
;
1226 case VIDEO_PAN_SCAN
:
1227 av7110
->display_panscan
= VID_PAN_SCAN_PREF
;
1229 case VIDEO_LETTER_BOX
:
1230 av7110
->display_panscan
= VID_VC_AND_PS_PREF
;
1232 case VIDEO_CENTER_CUT_OUT
:
1233 av7110
->display_panscan
= VID_CENTRE_CUT_PREF
;
1240 av7110
->videostate
.display_format
= format
;
1241 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetPanScanType
,
1242 1, av7110
->display_panscan
);
1246 case VIDEO_SET_FORMAT
:
1251 av7110
->display_ar
= arg
;
1252 ret
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetMonitorType
,
1256 #ifdef CONFIG_COMPAT
1257 case VIDEO_STILLPICTURE32
:
1259 struct compat_video_still_picture
*pic
=
1260 (struct compat_video_still_picture
*) parg
;
1261 av7110
->videostate
.stream_source
= VIDEO_SOURCE_MEMORY
;
1262 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1263 ret
= play_iframe(av7110
, compat_ptr(pic
->iFrame
),
1264 pic
->size
, file
->f_flags
& O_NONBLOCK
);
1269 case VIDEO_STILLPICTURE
:
1271 struct video_still_picture
*pic
=
1272 (struct video_still_picture
*) parg
;
1273 av7110
->videostate
.stream_source
= VIDEO_SOURCE_MEMORY
;
1274 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1275 ret
= play_iframe(av7110
, pic
->iFrame
, pic
->size
,
1276 file
->f_flags
& O_NONBLOCK
);
1280 case VIDEO_FAST_FORWARD
:
1281 //note: arg is ignored by firmware
1282 if (av7110
->playing
& RP_VIDEO
)
1283 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1284 __Scan_I
, 2, AV_PES
, 0);
1286 ret
= vidcom(av7110
, AV_VIDEO_CMD_FFWD
, arg
);
1288 av7110
->trickmode
= TRICK_FAST
;
1289 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1293 case VIDEO_SLOWMOTION
:
1294 if (av7110
->playing
&RP_VIDEO
) {
1295 if (av7110
->trickmode
!= TRICK_SLOW
)
1296 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
, __Slow
, 2, 0, 0);
1298 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1300 ret
= vidcom(av7110
, AV_VIDEO_CMD_PLAY
, 0);
1302 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
, 0);
1304 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1307 av7110
->trickmode
= TRICK_SLOW
;
1308 av7110
->videostate
.play_state
= VIDEO_PLAYING
;
1312 case VIDEO_GET_CAPABILITIES
:
1313 *(int *)parg
= VIDEO_CAP_MPEG1
| VIDEO_CAP_MPEG2
|
1314 VIDEO_CAP_SYS
| VIDEO_CAP_PROG
;
1317 case VIDEO_CLEAR_BUFFER
:
1318 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1319 av7110_ipack_reset(&av7110
->ipack
[1]);
1320 if (av7110
->playing
== RP_AV
) {
1321 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1322 __Play
, 2, AV_PES
, 0);
1325 if (av7110
->trickmode
== TRICK_FAST
)
1326 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1327 __Scan_I
, 2, AV_PES
, 0);
1328 if (av7110
->trickmode
== TRICK_SLOW
) {
1329 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1332 ret
= vidcom(av7110
, AV_VIDEO_CMD_SLOW
, arg
);
1334 if (av7110
->trickmode
== TRICK_FREEZE
)
1335 ret
= vidcom(av7110
, AV_VIDEO_CMD_STOP
, 1);
1339 case VIDEO_SET_STREAMTYPE
:
1347 mutex_unlock(&av7110
->ioctl_mutex
);
1351 static int dvb_audio_ioctl(struct file
*file
,
1352 unsigned int cmd
, void *parg
)
1354 struct dvb_device
*dvbdev
= file
->private_data
;
1355 struct av7110
*av7110
= dvbdev
->priv
;
1356 unsigned long arg
= (unsigned long) parg
;
1359 dprintk(1, "av7110:%p, cmd=%04x\n", av7110
,cmd
);
1361 if (((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) &&
1362 (cmd
!= AUDIO_GET_STATUS
))
1365 if (mutex_lock_interruptible(&av7110
->ioctl_mutex
))
1366 return -ERESTARTSYS
;
1370 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
1371 ret
= av7110_av_stop(av7110
, RP_AUDIO
);
1373 ret
= audcom(av7110
, AUDIO_CMD_MUTE
);
1375 av7110
->audiostate
.play_state
= AUDIO_STOPPED
;
1379 if (av7110
->audiostate
.stream_source
== AUDIO_SOURCE_MEMORY
)
1380 ret
= av7110_av_start_play(av7110
, RP_AUDIO
);
1382 ret
= audcom(av7110
, AUDIO_CMD_UNMUTE
);
1384 av7110
->audiostate
.play_state
= AUDIO_PLAYING
;
1388 ret
= audcom(av7110
, AUDIO_CMD_MUTE
);
1390 av7110
->audiostate
.play_state
= AUDIO_PAUSED
;
1393 case AUDIO_CONTINUE
:
1394 if (av7110
->audiostate
.play_state
== AUDIO_PAUSED
) {
1395 av7110
->audiostate
.play_state
= AUDIO_PLAYING
;
1396 ret
= audcom(av7110
, AUDIO_CMD_UNMUTE
| AUDIO_CMD_PCM16
);
1400 case AUDIO_SELECT_SOURCE
:
1401 av7110
->audiostate
.stream_source
= (audio_stream_source_t
) arg
;
1404 case AUDIO_SET_MUTE
:
1406 ret
= audcom(av7110
, arg
? AUDIO_CMD_MUTE
: AUDIO_CMD_UNMUTE
);
1408 av7110
->audiostate
.mute_state
= (int) arg
;
1412 case AUDIO_SET_AV_SYNC
:
1413 av7110
->audiostate
.AV_sync_state
= (int) arg
;
1414 ret
= audcom(av7110
, arg
? AUDIO_CMD_SYNC_ON
: AUDIO_CMD_SYNC_OFF
);
1417 case AUDIO_SET_BYPASS_MODE
:
1418 if (FW_VERSION(av7110
->arm_app
) < 0x2621)
1420 av7110
->audiostate
.bypass_mode
= (int)arg
;
1423 case AUDIO_CHANNEL_SELECT
:
1424 av7110
->audiostate
.channel_select
= (audio_channel_select_t
) arg
;
1425 switch(av7110
->audiostate
.channel_select
) {
1427 ret
= audcom(av7110
, AUDIO_CMD_STEREO
);
1429 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1430 i2c_writereg(av7110
, 0x20, 0x02, 0x49);
1431 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1432 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220);
1435 case AUDIO_MONO_LEFT
:
1436 ret
= audcom(av7110
, AUDIO_CMD_MONO_L
);
1438 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1439 i2c_writereg(av7110
, 0x20, 0x02, 0x4a);
1440 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1441 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0200);
1444 case AUDIO_MONO_RIGHT
:
1445 ret
= audcom(av7110
, AUDIO_CMD_MONO_R
);
1447 if (av7110
->adac_type
== DVB_ADAC_CRYSTAL
)
1448 i2c_writereg(av7110
, 0x20, 0x02, 0x45);
1449 else if (av7110
->adac_type
== DVB_ADAC_MSP34x5
)
1450 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0210);
1459 case AUDIO_GET_STATUS
:
1460 memcpy(parg
, &av7110
->audiostate
, sizeof(struct audio_status
));
1463 case AUDIO_GET_CAPABILITIES
:
1464 if (FW_VERSION(av7110
->arm_app
) < 0x2621)
1465 *(unsigned int *)parg
= AUDIO_CAP_LPCM
| AUDIO_CAP_MP1
| AUDIO_CAP_MP2
;
1467 *(unsigned int *)parg
= AUDIO_CAP_LPCM
| AUDIO_CAP_DTS
| AUDIO_CAP_AC3
|
1468 AUDIO_CAP_MP1
| AUDIO_CAP_MP2
;
1471 case AUDIO_CLEAR_BUFFER
:
1472 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1473 av7110_ipack_reset(&av7110
->ipack
[0]);
1474 if (av7110
->playing
== RP_AV
)
1475 ret
= av7110_fw_cmd(av7110
, COMTYPE_REC_PLAY
,
1476 __Play
, 2, AV_PES
, 0);
1482 case AUDIO_SET_MIXER
:
1484 struct audio_mixer
*amix
= (struct audio_mixer
*)parg
;
1485 ret
= av7110_set_volume(av7110
, amix
->volume_left
, amix
->volume_right
);
1489 case AUDIO_SET_STREAMTYPE
:
1496 mutex_unlock(&av7110
->ioctl_mutex
);
1501 static int dvb_video_open(struct inode
*inode
, struct file
*file
)
1503 struct dvb_device
*dvbdev
= file
->private_data
;
1504 struct av7110
*av7110
= dvbdev
->priv
;
1507 dprintk(2, "av7110:%p, \n", av7110
);
1509 if ((err
= dvb_generic_open(inode
, file
)) < 0)
1512 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
1513 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1514 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->avout
);
1515 av7110
->video_blank
= 1;
1516 av7110
->audiostate
.AV_sync_state
= 1;
1517 av7110
->videostate
.stream_source
= VIDEO_SOURCE_DEMUX
;
1519 /* empty event queue */
1520 av7110
->video_events
.eventr
= av7110
->video_events
.eventw
= 0;
1526 static int dvb_video_release(struct inode
*inode
, struct file
*file
)
1528 struct dvb_device
*dvbdev
= file
->private_data
;
1529 struct av7110
*av7110
= dvbdev
->priv
;
1531 dprintk(2, "av7110:%p, \n", av7110
);
1533 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
1534 av7110_av_stop(av7110
, RP_VIDEO
);
1537 return dvb_generic_release(inode
, file
);
1540 static int dvb_audio_open(struct inode
*inode
, struct file
*file
)
1542 struct dvb_device
*dvbdev
= file
->private_data
;
1543 struct av7110
*av7110
= dvbdev
->priv
;
1544 int err
= dvb_generic_open(inode
, file
);
1546 dprintk(2, "av7110:%p, \n", av7110
);
1550 dvb_ringbuffer_flush_spinlock_wakeup(&av7110
->aout
);
1551 av7110
->audiostate
.stream_source
= AUDIO_SOURCE_DEMUX
;
1555 static int dvb_audio_release(struct inode
*inode
, struct file
*file
)
1557 struct dvb_device
*dvbdev
= file
->private_data
;
1558 struct av7110
*av7110
= dvbdev
->priv
;
1560 dprintk(2, "av7110:%p, \n", av7110
);
1562 av7110_av_stop(av7110
, RP_AUDIO
);
1563 return dvb_generic_release(inode
, file
);
1568 /******************************************************************************
1569 * driver registration
1570 ******************************************************************************/
1572 static const struct file_operations dvb_video_fops
= {
1573 .owner
= THIS_MODULE
,
1574 .write
= dvb_video_write
,
1575 .unlocked_ioctl
= dvb_generic_ioctl
,
1576 .compat_ioctl
= dvb_generic_ioctl
,
1577 .open
= dvb_video_open
,
1578 .release
= dvb_video_release
,
1579 .poll
= dvb_video_poll
,
1580 .llseek
= noop_llseek
,
1583 static struct dvb_device dvbdev_video
= {
1586 .readers
= 5, /* arbitrary */
1588 .fops
= &dvb_video_fops
,
1589 .kernel_ioctl
= dvb_video_ioctl
,
1592 static const struct file_operations dvb_audio_fops
= {
1593 .owner
= THIS_MODULE
,
1594 .write
= dvb_audio_write
,
1595 .unlocked_ioctl
= dvb_generic_ioctl
,
1596 .compat_ioctl
= dvb_generic_ioctl
,
1597 .open
= dvb_audio_open
,
1598 .release
= dvb_audio_release
,
1599 .poll
= dvb_audio_poll
,
1600 .llseek
= noop_llseek
,
1603 static struct dvb_device dvbdev_audio
= {
1607 .fops
= &dvb_audio_fops
,
1608 .kernel_ioctl
= dvb_audio_ioctl
,
1612 int av7110_av_register(struct av7110
*av7110
)
1614 av7110
->audiostate
.AV_sync_state
= 0;
1615 av7110
->audiostate
.mute_state
= 0;
1616 av7110
->audiostate
.play_state
= AUDIO_STOPPED
;
1617 av7110
->audiostate
.stream_source
= AUDIO_SOURCE_DEMUX
;
1618 av7110
->audiostate
.channel_select
= AUDIO_STEREO
;
1619 av7110
->audiostate
.bypass_mode
= 0;
1621 av7110
->videostate
.video_blank
= 0;
1622 av7110
->videostate
.play_state
= VIDEO_STOPPED
;
1623 av7110
->videostate
.stream_source
= VIDEO_SOURCE_DEMUX
;
1624 av7110
->videostate
.video_format
= VIDEO_FORMAT_4_3
;
1625 av7110
->videostate
.display_format
= VIDEO_LETTER_BOX
;
1626 av7110
->display_ar
= VIDEO_FORMAT_4_3
;
1627 av7110
->display_panscan
= VID_VC_AND_PS_PREF
;
1629 init_waitqueue_head(&av7110
->video_events
.wait_queue
);
1630 spin_lock_init(&av7110
->video_events
.lock
);
1631 av7110
->video_events
.eventw
= av7110
->video_events
.eventr
= 0;
1632 av7110
->video_events
.overflow
= 0;
1633 memset(&av7110
->video_size
, 0, sizeof (video_size_t
));
1635 dvb_register_device(&av7110
->dvb_adapter
, &av7110
->video_dev
,
1636 &dvbdev_video
, av7110
, DVB_DEVICE_VIDEO
, 0);
1638 dvb_register_device(&av7110
->dvb_adapter
, &av7110
->audio_dev
,
1639 &dvbdev_audio
, av7110
, DVB_DEVICE_AUDIO
, 0);
1644 void av7110_av_unregister(struct av7110
*av7110
)
1646 dvb_unregister_device(av7110
->audio_dev
);
1647 dvb_unregister_device(av7110
->video_dev
);
1650 int av7110_av_init(struct av7110
*av7110
)
1652 void (*play
[])(u8
*, int, void *) = { play_audio_cb
, play_video_cb
};
1655 for (i
= 0; i
< 2; i
++) {
1656 struct ipack
*ipack
= av7110
->ipack
+ i
;
1658 ret
= av7110_ipack_init(ipack
, IPACKS
, play
[i
]);
1661 av7110_ipack_free(--ipack
);
1664 ipack
->data
= av7110
;
1667 dvb_ringbuffer_init(&av7110
->avout
, av7110
->iobuf
, AVOUTLEN
);
1668 dvb_ringbuffer_init(&av7110
->aout
, av7110
->iobuf
+ AVOUTLEN
, AOUTLEN
);
1670 av7110
->kbuf
[0] = (u8
*)(av7110
->iobuf
+ AVOUTLEN
+ AOUTLEN
+ BMPLEN
);
1671 av7110
->kbuf
[1] = av7110
->kbuf
[0] + 2 * IPACKS
;
1676 void av7110_av_exit(struct av7110
*av7110
)
1678 av7110_ipack_free(&av7110
->ipack
[0]);
1679 av7110_ipack_free(&av7110
->ipack
[1]);