blob: 2fc90e9a8b77abe799a507ff822945bcac744a5b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * av7110_av.c: audio and video MPEG decoder stuff
3 *
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
6 *
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 *
27 *
28 * the project's page is at http://www.linuxtv.org/dvb/
29 */
30
31#include <linux/types.h>
32#include <linux/kernel.h>
33#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/fs.h>
36
37#include "av7110.h"
38#include "av7110_hw.h"
39#include "av7110_av.h"
40#include "av7110_ipack.h"
41
42/* MPEG-2 (ISO 13818 / H.222.0) stream types */
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
56
57#define PTS_DTS_FLAGS 0xC0
58
59//pts_dts flags
60#define PTS_ONLY 0x80
61#define PTS_DTS 0xC0
62#define TS_SIZE 188
63#define TRANS_ERROR 0x80
64#define PAY_START 0x40
65#define TRANS_PRIO 0x20
66#define PID_MASK_HI 0x1F
67//flags
68#define TRANS_SCRMBL1 0x80
69#define TRANS_SCRMBL2 0x40
70#define ADAPT_FIELD 0x20
71#define PAYLOAD 0x10
72#define COUNT_MASK 0x0F
73
74// adaptation flags
75#define DISCON_IND 0x80
76#define RAND_ACC_IND 0x40
77#define ES_PRI_IND 0x20
78#define PCR_FLAG 0x10
79#define OPCR_FLAG 0x08
80#define SPLICE_FLAG 0x04
81#define TRANS_PRIV 0x02
82#define ADAP_EXT_FLAG 0x01
83
84// adaptation extension flags
85#define LTW_FLAG 0x80
86#define PIECE_RATE 0x40
87#define SEAM_SPLICE 0x20
88
89
90static void p_to_t(u8 const *buf, long int length, u16 pid,
91 u8 *counter, struct dvb_demux_feed *feed);
Oliver Endrissfd46d162009-04-10 10:20:00 -030092static int write_ts_to_decoder(struct av7110 *av7110, int type, const u8 *buf, size_t len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94
95int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len)
96{
97 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) p2t->priv;
98
99 if (!(dvbdmxfeed->ts_type & TS_PACKET))
100 return 0;
101 if (buf[3] == 0xe0) // video PES do not have a length in TS
102 buf[4] = buf[5] = 0;
103 if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
104 return dvbdmxfeed->cb.ts(buf, len, NULL, 0,
105 &dvbdmxfeed->feed.ts, DMX_OK);
106 else
107 return dvb_filter_pes2ts(p2t, buf, len, 1);
108}
109
110static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
111{
112 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv;
113
114 dvbdmxfeed->cb.ts(data, 188, NULL, 0,
115 &dvbdmxfeed->feed.ts, DMX_OK);
116 return 0;
117}
118
119int av7110_av_start_record(struct av7110 *av7110, int av,
120 struct dvb_demux_feed *dvbdmxfeed)
121{
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700122 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
124
125 dprintk(2, "av7110:%p, , dvb_demux_feed:%p\n", av7110, dvbdmxfeed);
126
127 if (av7110->playing || (av7110->rec_mode & av))
128 return -EBUSY;
129 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
130 dvbdmx->recording = 1;
131 av7110->rec_mode |= av;
132
133 switch (av7110->rec_mode) {
134 case RP_AUDIO:
135 dvb_filter_pes2ts_init(&av7110->p2t[0],
136 dvbdmx->pesfilter[0]->pid,
137 dvb_filter_pes2ts_cb,
138 (void *) dvbdmx->pesfilter[0]);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700139 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 break;
141
142 case RP_VIDEO:
143 dvb_filter_pes2ts_init(&av7110->p2t[1],
144 dvbdmx->pesfilter[1]->pid,
145 dvb_filter_pes2ts_cb,
146 (void *) dvbdmx->pesfilter[1]);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700147 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 break;
149
150 case RP_AV:
151 dvb_filter_pes2ts_init(&av7110->p2t[0],
152 dvbdmx->pesfilter[0]->pid,
153 dvb_filter_pes2ts_cb,
154 (void *) dvbdmx->pesfilter[0]);
155 dvb_filter_pes2ts_init(&av7110->p2t[1],
156 dvbdmx->pesfilter[1]->pid,
157 dvb_filter_pes2ts_cb,
158 (void *) dvbdmx->pesfilter[1]);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700159 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 break;
161 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700162 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165int av7110_av_start_play(struct av7110 *av7110, int av)
166{
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700167 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 dprintk(2, "av7110:%p, \n", av7110);
169
170 if (av7110->rec_mode)
171 return -EBUSY;
172 if (av7110->playing & av)
173 return -EBUSY;
174
175 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
176
177 if (av7110->playing == RP_NONE) {
178 av7110_ipack_reset(&av7110->ipack[0]);
179 av7110_ipack_reset(&av7110->ipack[1]);
180 }
181
182 av7110->playing |= av;
183 switch (av7110->playing) {
184 case RP_AUDIO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700185 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 break;
187 case RP_VIDEO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700188 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 av7110->sinfo = 0;
190 break;
191 case RP_AV:
192 av7110->sinfo = 0;
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700193 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 break;
195 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700196 if (!ret)
197 ret = av7110->playing;
198 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700201int av7110_av_stop(struct av7110 *av7110, int av)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700203 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 dprintk(2, "av7110:%p, \n", av7110);
205
206 if (!(av7110->playing & av) && !(av7110->rec_mode & av))
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700207 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
209 if (av7110->playing) {
210 av7110->playing &= ~av;
211 switch (av7110->playing) {
212 case RP_AUDIO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700213 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 break;
215 case RP_VIDEO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700216 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
218 case RP_NONE:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700219 ret = av7110_set_vidmode(av7110, av7110->vidmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 break;
221 }
222 } else {
223 av7110->rec_mode &= ~av;
224 switch (av7110->rec_mode) {
225 case RP_AUDIO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700226 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228 case RP_VIDEO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700229 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 break;
231 case RP_NONE:
232 break;
233 }
234 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700235 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238
239int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
240{
241 int len;
242 u32 sync;
243 u16 blen;
244
245 if (!dlen) {
246 wake_up(&buf->queue);
247 return -1;
248 }
249 while (1) {
250 if ((len = dvb_ringbuffer_avail(buf)) < 6)
251 return -1;
252 sync = DVB_RINGBUFFER_PEEK(buf, 0) << 24;
253 sync |= DVB_RINGBUFFER_PEEK(buf, 1) << 16;
254 sync |= DVB_RINGBUFFER_PEEK(buf, 2) << 8;
255 sync |= DVB_RINGBUFFER_PEEK(buf, 3);
256
257 if (((sync &~ 0x0f) == 0x000001e0) ||
258 ((sync &~ 0x1f) == 0x000001c0) ||
259 (sync == 0x000001bd))
260 break;
261 printk("resync\n");
262 DVB_RINGBUFFER_SKIP(buf, 1);
263 }
264 blen = DVB_RINGBUFFER_PEEK(buf, 4) << 8;
265 blen |= DVB_RINGBUFFER_PEEK(buf, 5);
266 blen += 6;
267 if (len < blen || blen > dlen) {
268 //printk("buffer empty - avail %d blen %u dlen %d\n", len, blen, dlen);
269 wake_up(&buf->queue);
270 return -1;
271 }
272
Al Virob0ba0e32008-06-22 14:20:29 -0300273 dvb_ringbuffer_read(buf, dest, (size_t) blen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 dprintk(2, "pread=0x%08lx, pwrite=0x%08lx\n",
276 (unsigned long) buf->pread, (unsigned long) buf->pwrite);
277 wake_up(&buf->queue);
278 return blen;
279}
280
281
282int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
283{
284 int err, vol, val, balance = 0;
285
286 dprintk(2, "av7110:%p, \n", av7110);
287
288 av7110->mixer.volume_left = volleft;
289 av7110->mixer.volume_right = volright;
290
291 switch (av7110->adac_type) {
292 case DVB_ADAC_TI:
293 volleft = (volleft * 256) / 1036;
294 volright = (volright * 256) / 1036;
295 if (volleft > 0x3f)
296 volleft = 0x3f;
297 if (volright > 0x3f)
298 volright = 0x3f;
299 if ((err = SendDAC(av7110, 3, 0x80 + volleft)))
300 return err;
301 return SendDAC(av7110, 4, volright);
302
303 case DVB_ADAC_CRYSTAL:
304 volleft = 127 - volleft / 2;
305 volright = 127 - volright / 2;
306 i2c_writereg(av7110, 0x20, 0x03, volleft);
307 i2c_writereg(av7110, 0x20, 0x04, volright);
308 return 0;
309
Marco Schluessler1c13b952006-01-09 15:25:06 -0200310 case DVB_ADAC_MSP34x0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 vol = (volleft > volright) ? volleft : volright;
312 val = (vol * 0x73 / 255) << 8;
313 if (vol > 0)
314 balance = ((volright - volleft) * 127) / vol;
315 msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
316 msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
317 msp_writereg(av7110, MSP_WR_DSP, 0x0006, val); /* headphonesr */
318 return 0;
Tim Kaiser61391e02006-06-25 09:14:07 -0300319
320 case DVB_ADAC_MSP34x5:
321 vol = (volleft > volright) ? volleft : volright;
322 val = (vol * 0x73 / 255) << 8;
323 if (vol > 0)
324 balance = ((volright - volleft) * 127) / vol;
325 msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
326 msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
327 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Tim Kaiser61391e02006-06-25 09:14:07 -0300329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return 0;
331}
332
Marco Schluessler58a44042007-10-31 01:20:42 -0300333int av7110_set_vidmode(struct av7110 *av7110, enum av7110_video_mode mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700335 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 dprintk(2, "av7110:%p, \n", av7110);
337
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700338 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700340 if (!ret && !av7110->playing) {
341 ret = ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 av7110->pids[DMX_PES_AUDIO],
343 av7110->pids[DMX_PES_TELETEXT],
344 0, av7110->pids[DMX_PES_PCR]);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700345 if (!ret)
346 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700348 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
351
Marco Schluessler58a44042007-10-31 01:20:42 -0300352static enum av7110_video_mode sw2mode[16] = {
353 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
354 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_PAL,
355 AV7110_VIDEO_MODE_NTSC, AV7110_VIDEO_MODE_NTSC,
356 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_NTSC,
357 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
358 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
359 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
360 AV7110_VIDEO_MODE_PAL, AV7110_VIDEO_MODE_PAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361};
362
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700363static int get_video_format(struct av7110 *av7110, u8 *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 int i;
366 int hsize, vsize;
367 int sw;
368 u8 *p;
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700369 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 dprintk(2, "av7110:%p, \n", av7110);
372
373 if (av7110->sinfo)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700374 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 for (i = 7; i < count - 10; i++) {
376 p = buf + i;
377 if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3)
378 continue;
379 p += 4;
380 hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4);
381 vsize = ((p[1] &0x0F) << 8) | (p[2]);
382 sw = (p[3] & 0x0F);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700383 ret = av7110_set_vidmode(av7110, sw2mode[sw]);
384 if (!ret) {
385 dprintk(2, "playback %dx%d fr=%d\n", hsize, vsize, sw);
386 av7110->sinfo = 1;
387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 break;
389 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -0700390 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
393
394/****************************************************************************
395 * I/O buffer management and control
396 ****************************************************************************/
397
398static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
Oliver Endriss804b4452007-07-12 20:37:50 -0300399 const u8 *buf, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
401 unsigned long todo = count;
402 int free;
403
404 while (todo > 0) {
405 if (dvb_ringbuffer_free(rbuf) < 2048) {
406 if (wait_event_interruptible(rbuf->queue,
407 (dvb_ringbuffer_free(rbuf) >= 2048)))
408 return count - todo;
409 }
410 free = dvb_ringbuffer_free(rbuf);
411 if (free > todo)
412 free = todo;
413 dvb_ringbuffer_write(rbuf, buf, free);
414 todo -= free;
415 buf += free;
416 }
417
418 return count - todo;
419}
420
421static void play_video_cb(u8 *buf, int count, void *priv)
422{
423 struct av7110 *av7110 = (struct av7110 *) priv;
424 dprintk(2, "av7110:%p, \n", av7110);
425
426 if ((buf[3] & 0xe0) == 0xe0) {
427 get_video_format(av7110, buf, count);
428 aux_ring_buffer_write(&av7110->avout, buf, count);
429 } else
430 aux_ring_buffer_write(&av7110->aout, buf, count);
431}
432
433static void play_audio_cb(u8 *buf, int count, void *priv)
434{
435 struct av7110 *av7110 = (struct av7110 *) priv;
436 dprintk(2, "av7110:%p, \n", av7110);
437
438 aux_ring_buffer_write(&av7110->aout, buf, count);
439}
440
Oliver Endrissfd46d162009-04-10 10:20:00 -0300441
442#define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096)
443
444static ssize_t ts_play(struct av7110 *av7110, const char __user *buf,
445 unsigned long count, int nonblock, int type)
446{
447 struct dvb_ringbuffer *rb;
448 u8 *kb;
449 unsigned long todo = count;
450
451 dprintk(2, "%s: type %d cnt %lu\n", __func__, type, count);
452
453 rb = (type) ? &av7110->avout : &av7110->aout;
454 kb = av7110->kbuf[type];
455
456 if (!kb)
457 return -ENOBUFS;
458
459 if (nonblock && !FREE_COND_TS)
460 return -EWOULDBLOCK;
461
462 while (todo >= TS_SIZE) {
463 if (!FREE_COND_TS) {
464 if (nonblock)
465 return count - todo;
466 if (wait_event_interruptible(rb->queue, FREE_COND_TS))
467 return count - todo;
468 }
469 if (copy_from_user(kb, buf, TS_SIZE))
470 return -EFAULT;
471 write_ts_to_decoder(av7110, type, kb, TS_SIZE);
472 todo -= TS_SIZE;
473 buf += TS_SIZE;
474 }
475
476 return count - todo;
477}
478
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
481 dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
482
Oliver Endriss804b4452007-07-12 20:37:50 -0300483static ssize_t dvb_play(struct av7110 *av7110, const char __user *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 unsigned long count, int nonblock, int type)
485{
486 unsigned long todo = count, n;
487 dprintk(2, "av7110:%p, \n", av7110);
488
489 if (!av7110->kbuf[type])
490 return -ENOBUFS;
491
492 if (nonblock && !FREE_COND)
493 return -EWOULDBLOCK;
494
495 while (todo > 0) {
496 if (!FREE_COND) {
497 if (nonblock)
498 return count - todo;
499 if (wait_event_interruptible(av7110->avout.queue,
500 FREE_COND))
501 return count - todo;
502 }
503 n = todo;
504 if (n > IPACKS * 2)
505 n = IPACKS * 2;
506 if (copy_from_user(av7110->kbuf[type], buf, n))
507 return -EFAULT;
508 av7110_ipack_instant_repack(av7110->kbuf[type], n,
509 &av7110->ipack[type]);
510 todo -= n;
511 buf += n;
512 }
513 return count - todo;
514}
515
516static ssize_t dvb_play_kernel(struct av7110 *av7110, const u8 *buf,
517 unsigned long count, int nonblock, int type)
518{
519 unsigned long todo = count, n;
520 dprintk(2, "av7110:%p, \n", av7110);
521
522 if (!av7110->kbuf[type])
523 return -ENOBUFS;
524
525 if (nonblock && !FREE_COND)
526 return -EWOULDBLOCK;
527
528 while (todo > 0) {
529 if (!FREE_COND) {
530 if (nonblock)
531 return count - todo;
532 if (wait_event_interruptible(av7110->avout.queue,
533 FREE_COND))
534 return count - todo;
535 }
536 n = todo;
537 if (n > IPACKS * 2)
538 n = IPACKS * 2;
539 av7110_ipack_instant_repack(buf, n, &av7110->ipack[type]);
540 todo -= n;
541 buf += n;
542 }
543 return count - todo;
544}
545
Oliver Endriss804b4452007-07-12 20:37:50 -0300546static ssize_t dvb_aplay(struct av7110 *av7110, const char __user *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 unsigned long count, int nonblock, int type)
548{
549 unsigned long todo = count, n;
550 dprintk(2, "av7110:%p, \n", av7110);
551
552 if (!av7110->kbuf[type])
553 return -ENOBUFS;
554 if (nonblock && dvb_ringbuffer_free(&av7110->aout) < 20 * 1024)
555 return -EWOULDBLOCK;
556
557 while (todo > 0) {
558 if (dvb_ringbuffer_free(&av7110->aout) < 20 * 1024) {
559 if (nonblock)
560 return count - todo;
561 if (wait_event_interruptible(av7110->aout.queue,
562 (dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)))
563 return count-todo;
564 }
565 n = todo;
566 if (n > IPACKS * 2)
567 n = IPACKS * 2;
568 if (copy_from_user(av7110->kbuf[type], buf, n))
569 return -EFAULT;
570 av7110_ipack_instant_repack(av7110->kbuf[type], n,
571 &av7110->ipack[type]);
572 todo -= n;
573 buf += n;
574 }
575 return count - todo;
576}
577
578void av7110_p2t_init(struct av7110_p2t *p, struct dvb_demux_feed *feed)
579{
580 memset(p->pes, 0, TS_SIZE);
581 p->counter = 0;
582 p->pos = 0;
583 p->frags = 0;
584 if (feed)
585 p->feed = feed;
586}
587
588static void clear_p2t(struct av7110_p2t *p)
589{
590 memset(p->pes, 0, TS_SIZE);
591// p->counter = 0;
592 p->pos = 0;
593 p->frags = 0;
594}
595
596
597static int find_pes_header(u8 const *buf, long int length, int *frags)
598{
599 int c = 0;
600 int found = 0;
601
602 *frags = 0;
603
604 while (c < length - 3 && !found) {
605 if (buf[c] == 0x00 && buf[c + 1] == 0x00 &&
606 buf[c + 2] == 0x01) {
607 switch ( buf[c + 3] ) {
608 case PROG_STREAM_MAP:
609 case PRIVATE_STREAM2:
610 case PROG_STREAM_DIR:
611 case ECM_STREAM :
612 case EMM_STREAM :
613 case PADDING_STREAM :
614 case DSM_CC_STREAM :
615 case ISO13522_STREAM:
616 case PRIVATE_STREAM1:
617 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
618 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
619 found = 1;
620 break;
621
622 default:
623 c++;
624 break;
625 }
626 } else
627 c++;
628 }
629 if (c == length - 3 && !found) {
630 if (buf[length - 1] == 0x00)
631 *frags = 1;
632 if (buf[length - 2] == 0x00 &&
633 buf[length - 1] == 0x00)
634 *frags = 2;
635 if (buf[length - 3] == 0x00 &&
636 buf[length - 2] == 0x00 &&
637 buf[length - 1] == 0x01)
638 *frags = 3;
639 return -1;
640 }
641
642 return c;
643}
644
645void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t *p)
646{
647 int c, c2, l, add;
648 int check, rest;
649
650 c = 0;
651 c2 = 0;
652 if (p->frags){
653 check = 0;
654 switch(p->frags) {
655 case 1:
656 if (buf[c] == 0x00 && buf[c + 1] == 0x01) {
657 check = 1;
658 c += 2;
659 }
660 break;
661 case 2:
662 if (buf[c] == 0x01) {
663 check = 1;
664 c++;
665 }
666 break;
667 case 3:
668 check = 1;
669 }
670 if (check) {
671 switch (buf[c]) {
672 case PROG_STREAM_MAP:
673 case PRIVATE_STREAM2:
674 case PROG_STREAM_DIR:
675 case ECM_STREAM :
676 case EMM_STREAM :
677 case PADDING_STREAM :
678 case DSM_CC_STREAM :
679 case ISO13522_STREAM:
680 case PRIVATE_STREAM1:
681 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
682 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
683 p->pes[0] = 0x00;
684 p->pes[1] = 0x00;
685 p->pes[2] = 0x01;
686 p->pes[3] = buf[c];
687 p->pos = 4;
688 memcpy(p->pes + p->pos, buf + c, (TS_SIZE - 4) - p->pos);
689 c += (TS_SIZE - 4) - p->pos;
690 p_to_t(p->pes, (TS_SIZE - 4), pid, &p->counter, p->feed);
691 clear_p2t(p);
692 break;
693
694 default:
695 c = 0;
696 break;
697 }
698 }
699 p->frags = 0;
700 }
701
702 if (p->pos) {
703 c2 = find_pes_header(buf + c, length - c, &p->frags);
704 if (c2 >= 0 && c2 < (TS_SIZE - 4) - p->pos)
705 l = c2+c;
706 else
707 l = (TS_SIZE - 4) - p->pos;
708 memcpy(p->pes + p->pos, buf, l);
709 c += l;
710 p->pos += l;
711 p_to_t(p->pes, p->pos, pid, &p->counter, p->feed);
712 clear_p2t(p);
713 }
714
715 add = 0;
716 while (c < length) {
717 c2 = find_pes_header(buf + c + add, length - c - add, &p->frags);
718 if (c2 >= 0) {
719 c2 += c + add;
720 if (c2 > c){
721 p_to_t(buf + c, c2 - c, pid, &p->counter, p->feed);
722 c = c2;
723 clear_p2t(p);
724 add = 0;
725 } else
726 add = 1;
727 } else {
728 l = length - c;
729 rest = l % (TS_SIZE - 4);
730 l -= rest;
731 p_to_t(buf + c, l, pid, &p->counter, p->feed);
732 memcpy(p->pes, buf + c + l, rest);
733 p->pos = rest;
734 c = length;
735 }
736 }
737}
738
739
740static int write_ts_header2(u16 pid, u8 *counter, int pes_start, u8 *buf, u8 length)
741{
742 int i;
743 int c = 0;
744 int fill;
745 u8 tshead[4] = { 0x47, 0x00, 0x00, 0x10 };
746
747 fill = (TS_SIZE - 4) - length;
748 if (pes_start)
749 tshead[1] = 0x40;
750 if (fill)
751 tshead[3] = 0x30;
752 tshead[1] |= (u8)((pid & 0x1F00) >> 8);
753 tshead[2] |= (u8)(pid & 0x00FF);
754 tshead[3] |= ((*counter)++ & 0x0F);
755 memcpy(buf, tshead, 4);
756 c += 4;
757
758 if (fill) {
759 buf[4] = fill - 1;
760 c++;
761 if (fill > 1) {
762 buf[5] = 0x00;
763 c++;
764 }
765 for (i = 6; i < fill + 4; i++) {
766 buf[i] = 0xFF;
767 c++;
768 }
769 }
770
771 return c;
772}
773
774
775static void p_to_t(u8 const *buf, long int length, u16 pid, u8 *counter,
776 struct dvb_demux_feed *feed)
777{
778 int l, pes_start;
779 u8 obuf[TS_SIZE];
780 long c = 0;
781
782 pes_start = 0;
783 if (length > 3 &&
784 buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x01)
785 switch (buf[3]) {
786 case PROG_STREAM_MAP:
787 case PRIVATE_STREAM2:
788 case PROG_STREAM_DIR:
789 case ECM_STREAM :
790 case EMM_STREAM :
791 case PADDING_STREAM :
792 case DSM_CC_STREAM :
793 case ISO13522_STREAM:
794 case PRIVATE_STREAM1:
795 case AUDIO_STREAM_S ... AUDIO_STREAM_E:
796 case VIDEO_STREAM_S ... VIDEO_STREAM_E:
797 pes_start = 1;
798 break;
799
800 default:
801 break;
802 }
803
804 while (c < length) {
805 memset(obuf, 0, TS_SIZE);
806 if (length - c >= (TS_SIZE - 4)){
807 l = write_ts_header2(pid, counter, pes_start,
808 obuf, (TS_SIZE - 4));
809 memcpy(obuf + l, buf + c, TS_SIZE - l);
810 c += TS_SIZE - l;
811 } else {
812 l = write_ts_header2(pid, counter, pes_start,
813 obuf, length - c);
814 memcpy(obuf + l, buf + c, TS_SIZE - l);
815 c = length;
816 }
817 feed->cb.ts(obuf, 188, NULL, 0, &feed->feed.ts, DMX_OK);
818 pes_start = 0;
819 }
820}
821
822
Oliver Endrissfd46d162009-04-10 10:20:00 -0300823static int write_ts_to_decoder(struct av7110 *av7110, int type, const u8 *buf, size_t len)
824{
825 struct ipack *ipack = &av7110->ipack[type];
826
827 if (!(buf[3] & PAYLOAD))
828 return -1;
829
830 if (buf[1] & PAY_START)
831 av7110_ipack_flush(ipack);
832
833 if (buf[3] & ADAPT_FIELD) {
834 len -= buf[4] + 1;
835 buf += buf[4] + 1;
836 if (!len)
837 return 0;
838 }
839
840 av7110_ipack_instant_repack(buf + 4, len - 4, ipack);
841 return 0;
842}
843
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len)
846{
847 struct dvb_demux *demux = feed->demux;
848 struct av7110 *av7110 = (struct av7110 *) demux->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 dprintk(2, "av7110:%p, \n", av7110);
851
Oliver Endriss9e615ea2008-09-03 19:15:27 -0300852 if (av7110->full_ts && demux->dmx.frontend->source != DMX_MEMORY_FE)
853 return 0;
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 switch (feed->pes_type) {
856 case 0:
857 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
858 return -EINVAL;
859 break;
860 case 1:
861 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
862 return -EINVAL;
863 break;
864 default:
865 return -1;
866 }
867
Oliver Endrissfd46d162009-04-10 10:20:00 -0300868 return write_ts_to_decoder(av7110, feed->pes_type, buf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
870
871
872
873/******************************************************************************
874 * Video MPEG decoder events
875 ******************************************************************************/
876void dvb_video_add_event(struct av7110 *av7110, struct video_event *event)
877{
878 struct dvb_video_events *events = &av7110->video_events;
879 int wp;
880
881 spin_lock_bh(&events->lock);
882
883 wp = (events->eventw + 1) % MAX_VIDEO_EVENT;
884 if (wp == events->eventr) {
885 events->overflow = 1;
886 events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
887 }
888
889 //FIXME: timestamp?
890 memcpy(&events->events[events->eventw], event, sizeof(struct video_event));
891 events->eventw = wp;
892
893 spin_unlock_bh(&events->lock);
894
895 wake_up_interruptible(&events->wait_queue);
896}
897
898
899static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event, int flags)
900{
901 struct dvb_video_events *events = &av7110->video_events;
902
903 if (events->overflow) {
904 events->overflow = 0;
905 return -EOVERFLOW;
906 }
907 if (events->eventw == events->eventr) {
908 int ret;
909
910 if (flags & O_NONBLOCK)
911 return -EWOULDBLOCK;
912
913 ret = wait_event_interruptible(events->wait_queue,
914 events->eventw != events->eventr);
915 if (ret < 0)
916 return ret;
917 }
918
919 spin_lock_bh(&events->lock);
920
921 memcpy(event, &events->events[events->eventr],
922 sizeof(struct video_event));
923 events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
924
925 spin_unlock_bh(&events->lock);
926
927 return 0;
928}
929
930
931/******************************************************************************
932 * DVB device file operations
933 ******************************************************************************/
934
935static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
936{
Tobias Klauserd9bdf772006-12-26 07:33:48 -0300937 struct dvb_device *dvbdev = file->private_data;
938 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 unsigned int mask = 0;
940
941 dprintk(2, "av7110:%p, \n", av7110);
942
943 if ((file->f_flags & O_ACCMODE) != O_RDONLY)
944 poll_wait(file, &av7110->avout.queue, wait);
945
946 poll_wait(file, &av7110->video_events.wait_queue, wait);
947
948 if (av7110->video_events.eventw != av7110->video_events.eventr)
949 mask = POLLPRI;
950
951 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
952 if (av7110->playing) {
953 if (FREE_COND)
954 mask |= (POLLOUT | POLLWRNORM);
955 } else /* if not playing: may play if asked for */
956 mask |= (POLLOUT | POLLWRNORM);
957 }
958
959 return mask;
960}
961
962static ssize_t dvb_video_write(struct file *file, const char __user *buf,
963 size_t count, loff_t *ppos)
964{
Tobias Klauserd9bdf772006-12-26 07:33:48 -0300965 struct dvb_device *dvbdev = file->private_data;
966 struct av7110 *av7110 = dvbdev->priv;
Oliver Endrissfd46d162009-04-10 10:20:00 -0300967 unsigned char c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 dprintk(2, "av7110:%p, \n", av7110);
970
971 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
972 return -EPERM;
973
974 if (av7110->videostate.stream_source != VIDEO_SOURCE_MEMORY)
975 return -EPERM;
976
Oliver Endrissfd46d162009-04-10 10:20:00 -0300977 if (get_user(c, buf))
978 return -EFAULT;
979 if (c == 0x47 && count % TS_SIZE == 0)
980 return ts_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1);
981 else
982 return dvb_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
985static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
986{
Tobias Klauserd9bdf772006-12-26 07:33:48 -0300987 struct dvb_device *dvbdev = file->private_data;
988 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 unsigned int mask = 0;
990
991 dprintk(2, "av7110:%p, \n", av7110);
992
993 poll_wait(file, &av7110->aout.queue, wait);
994
995 if (av7110->playing) {
996 if (dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
997 mask |= (POLLOUT | POLLWRNORM);
998 } else /* if not playing: may play if asked for */
999 mask = (POLLOUT | POLLWRNORM);
1000
1001 return mask;
1002}
1003
1004static ssize_t dvb_audio_write(struct file *file, const char __user *buf,
1005 size_t count, loff_t *ppos)
1006{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001007 struct dvb_device *dvbdev = file->private_data;
1008 struct av7110 *av7110 = dvbdev->priv;
Oliver Endrissfd46d162009-04-10 10:20:00 -03001009 unsigned char c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 dprintk(2, "av7110:%p, \n", av7110);
1012
1013 if (av7110->audiostate.stream_source != AUDIO_SOURCE_MEMORY) {
1014 printk(KERN_ERR "not audio source memory\n");
1015 return -EPERM;
1016 }
Oliver Endrissfd46d162009-04-10 10:20:00 -03001017
1018 if (get_user(c, buf))
1019 return -EFAULT;
1020 if (c == 0x47 && count % TS_SIZE == 0)
1021 return ts_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
1022 else
1023 return dvb_aplay(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
1025
1026static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1027
1028#define MIN_IFRAME 400000
1029
Oliver Endriss804b4452007-07-12 20:37:50 -03001030static int play_iframe(struct av7110 *av7110, char __user *buf, unsigned int len, int nonblock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Al Viroa230e552008-05-21 00:30:41 -03001032 unsigned i, n;
Oliver Endriss0ed4a6e2008-01-30 01:07:20 -03001033 int progressive = 0;
Al Viroa230e552008-05-21 00:30:41 -03001034 int match = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 dprintk(2, "av7110:%p, \n", av7110);
1037
1038 if (!(av7110->playing & RP_VIDEO)) {
1039 if (av7110_av_start_play(av7110, RP_VIDEO) < 0)
1040 return -EBUSY;
1041 }
1042
Al Viroa230e552008-05-21 00:30:41 -03001043 /* search in buf for instances of 00 00 01 b5 1? */
1044 for (i = 0; i < len; i++) {
1045 unsigned char c;
1046 if (get_user(c, buf + i))
1047 return -EFAULT;
1048 if (match == 5) {
1049 progressive = c & 0x08;
1050 match = 0;
1051 }
1052 if (c == 0x00) {
1053 match = (match == 1 || match == 2) ? 2 : 1;
1054 continue;
1055 }
1056 switch (match++) {
1057 case 2: if (c == 0x01)
1058 continue;
1059 break;
1060 case 3: if (c == 0xb5)
1061 continue;
1062 break;
1063 case 4: if ((c & 0xf0) == 0x10)
1064 continue;
1065 break;
1066 }
1067 match = 0;
Oliver Endriss0ed4a6e2008-01-30 01:07:20 -03001068 }
1069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 /* setting n always > 1, fixes problems when playing stillframes
1071 consisting of I- and P-Frames */
1072 n = MIN_IFRAME / len + 1;
1073
1074 /* FIXME: nonblock? */
1075 dvb_play_kernel(av7110, iframe_header, sizeof(iframe_header), 0, 1);
1076
1077 for (i = 0; i < n; i++)
1078 dvb_play(av7110, buf, len, 0, 1);
1079
1080 av7110_ipack_flush(&av7110->ipack[1]);
Oliver Endriss0ed4a6e2008-01-30 01:07:20 -03001081
1082 if (progressive)
1083 return vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
1084 else
1085 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
1088
1089static int dvb_video_ioctl(struct inode *inode, struct file *file,
1090 unsigned int cmd, void *parg)
1091{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001092 struct dvb_device *dvbdev = file->private_data;
1093 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 unsigned long arg = (unsigned long) parg;
1095 int ret = 0;
1096
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001097 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
1100 if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT &&
1101 cmd != VIDEO_GET_SIZE ) {
1102 return -EPERM;
1103 }
1104 }
1105
1106 switch (cmd) {
1107 case VIDEO_STOP:
1108 av7110->videostate.play_state = VIDEO_STOPPED;
1109 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001110 ret = av7110_av_stop(av7110, RP_VIDEO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 else
Hans Verkuil2435be12007-04-27 12:31:09 -03001112 ret = vidcom(av7110, AV_VIDEO_CMD_STOP,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 av7110->videostate.video_blank ? 0 : 1);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001114 if (!ret)
1115 av7110->trickmode = TRICK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 case VIDEO_PLAY:
1119 av7110->trickmode = TRICK_NONE;
1120 if (av7110->videostate.play_state == VIDEO_FREEZED) {
1121 av7110->videostate.play_state = VIDEO_PLAYING;
Hans Verkuil2435be12007-04-27 12:31:09 -03001122 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001123 if (ret)
1124 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
1126
1127 if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) {
1128 if (av7110->playing == RP_AV) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001129 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
1130 if (ret)
1131 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 av7110->playing &= ~RP_VIDEO;
1133 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001134 ret = av7110_av_start_play(av7110, RP_VIDEO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001136 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001137 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001138 if (!ret)
1139 av7110->videostate.play_state = VIDEO_PLAYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 break;
1141
1142 case VIDEO_FREEZE:
1143 av7110->videostate.play_state = VIDEO_FREEZED;
1144 if (av7110->playing & RP_VIDEO)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001145 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 else
Hans Verkuil2435be12007-04-27 12:31:09 -03001147 ret = vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001148 if (!ret)
1149 av7110->trickmode = TRICK_FREEZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 break;
1151
1152 case VIDEO_CONTINUE:
1153 if (av7110->playing & RP_VIDEO)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001154 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0);
1155 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001156 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001157 if (!ret) {
1158 av7110->videostate.play_state = VIDEO_PLAYING;
1159 av7110->trickmode = TRICK_NONE;
1160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 break;
1162
1163 case VIDEO_SELECT_SOURCE:
1164 av7110->videostate.stream_source = (video_stream_source_t) arg;
1165 break;
1166
1167 case VIDEO_SET_BLANK:
1168 av7110->videostate.video_blank = (int) arg;
1169 break;
1170
1171 case VIDEO_GET_STATUS:
1172 memcpy(parg, &av7110->videostate, sizeof(struct video_status));
1173 break;
1174
1175 case VIDEO_GET_EVENT:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001176 ret = dvb_video_get_event(av7110, parg, file->f_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 break;
1178
1179 case VIDEO_GET_SIZE:
1180 memcpy(parg, &av7110->video_size, sizeof(video_size_t));
1181 break;
1182
1183 case VIDEO_SET_DISPLAY_FORMAT:
1184 {
1185 video_displayformat_t format = (video_displayformat_t) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 switch (format) {
1188 case VIDEO_PAN_SCAN:
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001189 av7110->display_panscan = VID_PAN_SCAN_PREF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
1191
1192 case VIDEO_LETTER_BOX:
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001193 av7110->display_panscan = VID_VC_AND_PS_PREF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 break;
1195
1196 case VIDEO_CENTER_CUT_OUT:
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001197 av7110->display_panscan = VID_CENTRE_CUT_PREF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 break;
1199
1200 default:
1201 ret = -EINVAL;
1202 }
1203 if (ret < 0)
1204 break;
Johannes Stezenbacha65d3bb2005-05-16 21:54:26 -07001205 av7110->videostate.display_format = format;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001207 1, av7110->display_panscan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 break;
1209 }
1210
1211 case VIDEO_SET_FORMAT:
1212 if (arg > 1) {
1213 ret = -EINVAL;
1214 break;
1215 }
1216 av7110->display_ar = arg;
1217 ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetMonitorType,
1218 1, (u16) arg);
1219 break;
1220
1221 case VIDEO_STILLPICTURE:
1222 {
1223 struct video_still_picture *pic =
1224 (struct video_still_picture *) parg;
1225 av7110->videostate.stream_source = VIDEO_SOURCE_MEMORY;
1226 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1227 ret = play_iframe(av7110, pic->iFrame, pic->size,
1228 file->f_flags & O_NONBLOCK);
1229 break;
1230 }
1231
1232 case VIDEO_FAST_FORWARD:
1233 //note: arg is ignored by firmware
1234 if (av7110->playing & RP_VIDEO)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001235 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
Johannes Stezenbach7a2fa902005-07-07 17:58:01 -07001236 __Scan_I, 2, AV_PES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 else
Hans Verkuil2435be12007-04-27 12:31:09 -03001238 ret = vidcom(av7110, AV_VIDEO_CMD_FFWD, arg);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001239 if (!ret) {
1240 av7110->trickmode = TRICK_FAST;
1241 av7110->videostate.play_state = VIDEO_PLAYING;
1242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 break;
1244
1245 case VIDEO_SLOWMOTION:
1246 if (av7110->playing&RP_VIDEO) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001247 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0);
1248 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001249 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 } else {
Hans Verkuil2435be12007-04-27 12:31:09 -03001251 ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001252 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001253 ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001254 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001255 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001257 if (!ret) {
1258 av7110->trickmode = TRICK_SLOW;
1259 av7110->videostate.play_state = VIDEO_PLAYING;
1260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 break;
1262
1263 case VIDEO_GET_CAPABILITIES:
1264 *(int *)parg = VIDEO_CAP_MPEG1 | VIDEO_CAP_MPEG2 |
1265 VIDEO_CAP_SYS | VIDEO_CAP_PROG;
1266 break;
1267
1268 case VIDEO_CLEAR_BUFFER:
1269 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1270 av7110_ipack_reset(&av7110->ipack[1]);
1271
1272 if (av7110->playing == RP_AV) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001273 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
Johannes Stezenbach7a2fa902005-07-07 17:58:01 -07001274 __Play, 2, AV_PES, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001275 if (ret)
1276 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 if (av7110->trickmode == TRICK_FAST)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001278 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
Johannes Stezenbach7a2fa902005-07-07 17:58:01 -07001279 __Scan_I, 2, AV_PES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (av7110->trickmode == TRICK_SLOW) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001281 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
Johannes Stezenbach7a2fa902005-07-07 17:58:01 -07001282 __Slow, 2, 0, 0);
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001283 if (!ret)
Hans Verkuil2435be12007-04-27 12:31:09 -03001284 ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286 if (av7110->trickmode == TRICK_FREEZE)
Hans Verkuil2435be12007-04-27 12:31:09 -03001287 ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
1289 break;
1290
1291 case VIDEO_SET_STREAMTYPE:
1292
1293 break;
1294
1295 default:
1296 ret = -ENOIOCTLCMD;
1297 break;
1298 }
1299 return ret;
1300}
1301
1302static int dvb_audio_ioctl(struct inode *inode, struct file *file,
1303 unsigned int cmd, void *parg)
1304{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001305 struct dvb_device *dvbdev = file->private_data;
1306 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 unsigned long arg = (unsigned long) parg;
1308 int ret = 0;
1309
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001310 dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 if (((file->f_flags & O_ACCMODE) == O_RDONLY) &&
1313 (cmd != AUDIO_GET_STATUS))
1314 return -EPERM;
1315
1316 switch (cmd) {
1317 case AUDIO_STOP:
1318 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001319 ret = av7110_av_stop(av7110, RP_AUDIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 else
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001321 ret = audcom(av7110, AUDIO_CMD_MUTE);
1322 if (!ret)
1323 av7110->audiostate.play_state = AUDIO_STOPPED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 break;
1325
1326 case AUDIO_PLAY:
1327 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001328 ret = av7110_av_start_play(av7110, RP_AUDIO);
1329 if (!ret)
1330 ret = audcom(av7110, AUDIO_CMD_UNMUTE);
1331 if (!ret)
1332 av7110->audiostate.play_state = AUDIO_PLAYING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 break;
1334
1335 case AUDIO_PAUSE:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001336 ret = audcom(av7110, AUDIO_CMD_MUTE);
1337 if (!ret)
1338 av7110->audiostate.play_state = AUDIO_PAUSED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 break;
1340
1341 case AUDIO_CONTINUE:
1342 if (av7110->audiostate.play_state == AUDIO_PAUSED) {
1343 av7110->audiostate.play_state = AUDIO_PLAYING;
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001344 ret = audcom(av7110, AUDIO_CMD_UNMUTE | AUDIO_CMD_PCM16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
1346 break;
1347
1348 case AUDIO_SELECT_SOURCE:
1349 av7110->audiostate.stream_source = (audio_stream_source_t) arg;
1350 break;
1351
1352 case AUDIO_SET_MUTE:
1353 {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001354 ret = audcom(av7110, arg ? AUDIO_CMD_MUTE : AUDIO_CMD_UNMUTE);
1355 if (!ret)
1356 av7110->audiostate.mute_state = (int) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 break;
1358 }
1359
1360 case AUDIO_SET_AV_SYNC:
1361 av7110->audiostate.AV_sync_state = (int) arg;
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001362 ret = audcom(av7110, arg ? AUDIO_CMD_SYNC_ON : AUDIO_CMD_SYNC_OFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 break;
1364
1365 case AUDIO_SET_BYPASS_MODE:
Dr. Werner Fink47f36922006-01-09 15:25:07 -02001366 if (FW_VERSION(av7110->arm_app) < 0x2621)
1367 ret = -EINVAL;
1368 av7110->audiostate.bypass_mode = (int)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 break;
1370
1371 case AUDIO_CHANNEL_SELECT:
1372 av7110->audiostate.channel_select = (audio_channel_select_t) arg;
1373
1374 switch(av7110->audiostate.channel_select) {
1375 case AUDIO_STEREO:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001376 ret = audcom(av7110, AUDIO_CMD_STEREO);
Tim Kaiser61391e02006-06-25 09:14:07 -03001377 if (!ret) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001378 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1379 i2c_writereg(av7110, 0x20, 0x02, 0x49);
Tim Kaiser61391e02006-06-25 09:14:07 -03001380 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1381 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220);
1382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 break;
1384
1385 case AUDIO_MONO_LEFT:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001386 ret = audcom(av7110, AUDIO_CMD_MONO_L);
Tim Kaiser61391e02006-06-25 09:14:07 -03001387 if (!ret) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001388 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1389 i2c_writereg(av7110, 0x20, 0x02, 0x4a);
Tim Kaiser61391e02006-06-25 09:14:07 -03001390 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1391 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0200);
1392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 break;
1394
1395 case AUDIO_MONO_RIGHT:
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001396 ret = audcom(av7110, AUDIO_CMD_MONO_R);
Tim Kaiser61391e02006-06-25 09:14:07 -03001397 if (!ret) {
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001398 if (av7110->adac_type == DVB_ADAC_CRYSTAL)
1399 i2c_writereg(av7110, 0x20, 0x02, 0x45);
Tim Kaiser61391e02006-06-25 09:14:07 -03001400 else if (av7110->adac_type == DVB_ADAC_MSP34x5)
1401 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0210);
1402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 break;
1404
1405 default:
1406 ret = -EINVAL;
1407 break;
1408 }
1409 break;
1410
1411 case AUDIO_GET_STATUS:
1412 memcpy(parg, &av7110->audiostate, sizeof(struct audio_status));
1413 break;
1414
1415 case AUDIO_GET_CAPABILITIES:
Dr. Werner Fink47f36922006-01-09 15:25:07 -02001416 if (FW_VERSION(av7110->arm_app) < 0x2621)
1417 *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
1418 else
1419 *(unsigned int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_DTS | AUDIO_CAP_AC3 |
1420 AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 break;
1422
1423 case AUDIO_CLEAR_BUFFER:
1424 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1425 av7110_ipack_reset(&av7110->ipack[0]);
1426 if (av7110->playing == RP_AV)
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001427 ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
Johannes Stezenbach7a2fa902005-07-07 17:58:01 -07001428 __Play, 2, AV_PES, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 break;
1430 case AUDIO_SET_ID:
1431
1432 break;
1433 case AUDIO_SET_MIXER:
1434 {
1435 struct audio_mixer *amix = (struct audio_mixer *)parg;
1436
Wolfgang Rohdewaldce18a222005-07-07 17:57:59 -07001437 ret = av7110_set_volume(av7110, amix->volume_left, amix->volume_right);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 break;
1439 }
1440 case AUDIO_SET_STREAMTYPE:
1441 break;
1442 default:
1443 ret = -ENOIOCTLCMD;
1444 }
1445 return ret;
1446}
1447
1448
1449static int dvb_video_open(struct inode *inode, struct file *file)
1450{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001451 struct dvb_device *dvbdev = file->private_data;
1452 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 int err;
1454
1455 dprintk(2, "av7110:%p, \n", av7110);
1456
1457 if ((err = dvb_generic_open(inode, file)) < 0)
1458 return err;
1459
1460 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1461 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1462 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
1463 av7110->video_blank = 1;
1464 av7110->audiostate.AV_sync_state = 1;
1465 av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
1466
1467 /* empty event queue */
1468 av7110->video_events.eventr = av7110->video_events.eventw = 0;
1469 }
1470
1471 return 0;
1472}
1473
1474static int dvb_video_release(struct inode *inode, struct file *file)
1475{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001476 struct dvb_device *dvbdev = file->private_data;
1477 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
1479 dprintk(2, "av7110:%p, \n", av7110);
1480
1481 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1482 av7110_av_stop(av7110, RP_VIDEO);
1483 }
1484
1485 return dvb_generic_release(inode, file);
1486}
1487
1488static int dvb_audio_open(struct inode *inode, struct file *file)
1489{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001490 struct dvb_device *dvbdev = file->private_data;
1491 struct av7110 *av7110 = dvbdev->priv;
1492 int err = dvb_generic_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 dprintk(2, "av7110:%p, \n", av7110);
1495
1496 if (err < 0)
1497 return err;
1498 dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
1499 av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
1500 return 0;
1501}
1502
1503static int dvb_audio_release(struct inode *inode, struct file *file)
1504{
Tobias Klauserd9bdf772006-12-26 07:33:48 -03001505 struct dvb_device *dvbdev = file->private_data;
1506 struct av7110 *av7110 = dvbdev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 dprintk(2, "av7110:%p, \n", av7110);
1509
1510 av7110_av_stop(av7110, RP_AUDIO);
1511 return dvb_generic_release(inode, file);
1512}
1513
1514
1515
1516/******************************************************************************
1517 * driver registration
1518 ******************************************************************************/
1519
Jan Engelhardt784e29d2009-01-11 06:12:43 -03001520static const struct file_operations dvb_video_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 .owner = THIS_MODULE,
1522 .write = dvb_video_write,
1523 .ioctl = dvb_generic_ioctl,
1524 .open = dvb_video_open,
1525 .release = dvb_video_release,
1526 .poll = dvb_video_poll,
1527};
1528
1529static struct dvb_device dvbdev_video = {
1530 .priv = NULL,
1531 .users = 6,
1532 .readers = 5, /* arbitrary */
1533 .writers = 1,
1534 .fops = &dvb_video_fops,
1535 .kernel_ioctl = dvb_video_ioctl,
1536};
1537
Jan Engelhardt784e29d2009-01-11 06:12:43 -03001538static const struct file_operations dvb_audio_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 .owner = THIS_MODULE,
1540 .write = dvb_audio_write,
1541 .ioctl = dvb_generic_ioctl,
1542 .open = dvb_audio_open,
1543 .release = dvb_audio_release,
1544 .poll = dvb_audio_poll,
1545};
1546
1547static struct dvb_device dvbdev_audio = {
1548 .priv = NULL,
1549 .users = 1,
1550 .writers = 1,
1551 .fops = &dvb_audio_fops,
1552 .kernel_ioctl = dvb_audio_ioctl,
1553};
1554
1555
1556int av7110_av_register(struct av7110 *av7110)
1557{
1558 av7110->audiostate.AV_sync_state = 0;
1559 av7110->audiostate.mute_state = 0;
1560 av7110->audiostate.play_state = AUDIO_STOPPED;
1561 av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
1562 av7110->audiostate.channel_select = AUDIO_STEREO;
1563 av7110->audiostate.bypass_mode = 0;
1564
1565 av7110->videostate.video_blank = 0;
1566 av7110->videostate.play_state = VIDEO_STOPPED;
1567 av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
1568 av7110->videostate.video_format = VIDEO_FORMAT_4_3;
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001569 av7110->videostate.display_format = VIDEO_LETTER_BOX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 av7110->display_ar = VIDEO_FORMAT_4_3;
Oliver Endrissdefd574e2007-07-12 23:08:07 -03001571 av7110->display_panscan = VID_VC_AND_PS_PREF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 init_waitqueue_head(&av7110->video_events.wait_queue);
1574 spin_lock_init(&av7110->video_events.lock);
1575 av7110->video_events.eventw = av7110->video_events.eventr = 0;
1576 av7110->video_events.overflow = 0;
1577 memset(&av7110->video_size, 0, sizeof (video_size_t));
1578
Johannes Stezenbachfdc53a62005-05-16 21:54:39 -07001579 dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 &dvbdev_video, av7110, DVB_DEVICE_VIDEO);
1581
Johannes Stezenbachfdc53a62005-05-16 21:54:39 -07001582 dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 &dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
1584
1585 return 0;
1586}
1587
1588void av7110_av_unregister(struct av7110 *av7110)
1589{
1590 dvb_unregister_device(av7110->audio_dev);
1591 dvb_unregister_device(av7110->video_dev);
1592}
1593
1594int av7110_av_init(struct av7110 *av7110)
1595{
1596 void (*play[])(u8 *, int, void *) = { play_audio_cb, play_video_cb };
1597 int i, ret;
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 for (i = 0; i < 2; i++) {
1600 struct ipack *ipack = av7110->ipack + i;
1601
1602 ret = av7110_ipack_init(ipack, IPACKS, play[i]);
1603 if (ret < 0) {
1604 if (i)
1605 av7110_ipack_free(--ipack);
1606 goto out;
1607 }
1608 ipack->data = av7110;
1609 }
1610
1611 dvb_ringbuffer_init(&av7110->avout, av7110->iobuf, AVOUTLEN);
1612 dvb_ringbuffer_init(&av7110->aout, av7110->iobuf + AVOUTLEN, AOUTLEN);
1613
1614 av7110->kbuf[0] = (u8 *)(av7110->iobuf + AVOUTLEN + AOUTLEN + BMPLEN);
1615 av7110->kbuf[1] = av7110->kbuf[0] + 2 * IPACKS;
1616out:
1617 return ret;
1618}
1619
1620void av7110_av_exit(struct av7110 *av7110)
1621{
1622 av7110_ipack_free(&av7110->ipack[0]);
1623 av7110_ipack_free(&av7110->ipack[1]);
1624}