Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #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 | |
| 90 | static void p_to_t(u8 const *buf, long int length, u16 pid, |
| 91 | u8 *counter, struct dvb_demux_feed *feed); |
Oliver Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 92 | static int write_ts_to_decoder(struct av7110 *av7110, int type, const u8 *buf, size_t len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | |
| 95 | int 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 | |
| 110 | static 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 | |
| 119 | int av7110_av_start_record(struct av7110 *av7110, int av, |
| 120 | struct dvb_demux_feed *dvbdmxfeed) |
| 121 | { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 122 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 139 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 147 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 159 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | break; |
| 161 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 162 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | int av7110_av_start_play(struct av7110 *av7110, int av) |
| 166 | { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 167 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 185 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | break; |
| 187 | case RP_VIDEO: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 188 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | av7110->sinfo = 0; |
| 190 | break; |
| 191 | case RP_AV: |
| 192 | av7110->sinfo = 0; |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 193 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | break; |
| 195 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 196 | if (!ret) |
| 197 | ret = av7110->playing; |
| 198 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 201 | int av7110_av_stop(struct av7110 *av7110, int av) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 203 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | dprintk(2, "av7110:%p, \n", av7110); |
| 205 | |
| 206 | if (!(av7110->playing & av) && !(av7110->rec_mode & av)) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 207 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 213 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | break; |
| 215 | case RP_VIDEO: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 216 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | break; |
| 218 | case RP_NONE: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 219 | ret = av7110_set_vidmode(av7110, av7110->vidmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | } else { |
| 223 | av7110->rec_mode &= ~av; |
| 224 | switch (av7110->rec_mode) { |
| 225 | case RP_AUDIO: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 226 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | break; |
| 228 | case RP_VIDEO: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 229 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | break; |
| 231 | case RP_NONE: |
| 232 | break; |
| 233 | } |
| 234 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 235 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
| 239 | int 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 Viro | b0ba0e3 | 2008-06-22 14:20:29 -0300 | [diff] [blame] | 273 | dvb_ringbuffer_read(buf, dest, (size_t) blen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 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 | |
| 282 | int 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 Schluessler | 1c13b95 | 2006-01-09 15:25:06 -0200 | [diff] [blame] | 310 | case DVB_ADAC_MSP34x0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 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 Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 319 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Marco Schluessler | 58a4404 | 2007-10-31 01:20:42 -0300 | [diff] [blame] | 333 | int av7110_set_vidmode(struct av7110 *av7110, enum av7110_video_mode mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 335 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | dprintk(2, "av7110:%p, \n", av7110); |
| 337 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 338 | ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 340 | if (!ret && !av7110->playing) { |
| 341 | ret = ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | av7110->pids[DMX_PES_AUDIO], |
| 343 | av7110->pids[DMX_PES_TELETEXT], |
| 344 | 0, av7110->pids[DMX_PES_PCR]); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 345 | if (!ret) |
| 346 | ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 348 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
Marco Schluessler | 58a4404 | 2007-10-31 01:20:42 -0300 | [diff] [blame] | 352 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 363 | static int get_video_format(struct av7110 *av7110, u8 *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
| 365 | int i; |
| 366 | int hsize, vsize; |
| 367 | int sw; |
| 368 | u8 *p; |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 369 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | dprintk(2, "av7110:%p, \n", av7110); |
| 372 | |
| 373 | if (av7110->sinfo) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 374 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 383 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | break; |
| 389 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 390 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
| 394 | /**************************************************************************** |
| 395 | * I/O buffer management and control |
| 396 | ****************************************************************************/ |
| 397 | |
| 398 | static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf, |
Oliver Endriss | 804b445 | 2007-07-12 20:37:50 -0300 | [diff] [blame] | 399 | const u8 *buf, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
| 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 | |
| 421 | static 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 | |
| 433 | static 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 Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 441 | |
| 442 | #define FREE_COND_TS (dvb_ringbuffer_free(rb) >= 4096) |
| 443 | |
| 444 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | #define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \ |
| 481 | dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024) |
| 482 | |
Oliver Endriss | 804b445 | 2007-07-12 20:37:50 -0300 | [diff] [blame] | 483 | static ssize_t dvb_play(struct av7110 *av7110, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 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 | |
| 516 | static 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 Endriss | 804b445 | 2007-07-12 20:37:50 -0300 | [diff] [blame] | 546 | static ssize_t dvb_aplay(struct av7110 *av7110, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | 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 | |
| 578 | void 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 | |
| 588 | static 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 | |
| 597 | static 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 | |
| 645 | void 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 | |
| 740 | static 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 | |
| 775 | static 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 Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 823 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | dprintk(2, "av7110:%p, \n", av7110); |
| 851 | |
Oliver Endriss | 9e615ea | 2008-09-03 19:15:27 -0300 | [diff] [blame] | 852 | if (av7110->full_ts && demux->dmx.frontend->source != DMX_MEMORY_FE) |
| 853 | return 0; |
| 854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | 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 Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 868 | return write_ts_to_decoder(av7110, feed->pes_type, buf, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | |
| 873 | /****************************************************************************** |
| 874 | * Video MPEG decoder events |
| 875 | ******************************************************************************/ |
| 876 | void 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 | |
| 899 | static 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 | |
| 935 | static unsigned int dvb_video_poll(struct file *file, poll_table *wait) |
| 936 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 937 | struct dvb_device *dvbdev = file->private_data; |
| 938 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | 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 | |
| 962 | static ssize_t dvb_video_write(struct file *file, const char __user *buf, |
| 963 | size_t count, loff_t *ppos) |
| 964 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 965 | struct dvb_device *dvbdev = file->private_data; |
| 966 | struct av7110 *av7110 = dvbdev->priv; |
Oliver Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 967 | unsigned char c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
| 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 Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 977 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static unsigned int dvb_audio_poll(struct file *file, poll_table *wait) |
| 986 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 987 | struct dvb_device *dvbdev = file->private_data; |
| 988 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | 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 | |
| 1004 | static ssize_t dvb_audio_write(struct file *file, const char __user *buf, |
| 1005 | size_t count, loff_t *ppos) |
| 1006 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1007 | struct dvb_device *dvbdev = file->private_data; |
| 1008 | struct av7110 *av7110 = dvbdev->priv; |
Oliver Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 1009 | unsigned char c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
| 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 Endriss | fd46d16 | 2009-04-10 10:20:00 -0300 | [diff] [blame^] | 1017 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 }; |
| 1027 | |
| 1028 | #define MIN_IFRAME 400000 |
| 1029 | |
Oliver Endriss | 804b445 | 2007-07-12 20:37:50 -0300 | [diff] [blame] | 1030 | static int play_iframe(struct av7110 *av7110, char __user *buf, unsigned int len, int nonblock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | { |
Al Viro | a230e55 | 2008-05-21 00:30:41 -0300 | [diff] [blame] | 1032 | unsigned i, n; |
Oliver Endriss | 0ed4a6e | 2008-01-30 01:07:20 -0300 | [diff] [blame] | 1033 | int progressive = 0; |
Al Viro | a230e55 | 2008-05-21 00:30:41 -0300 | [diff] [blame] | 1034 | int match = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
| 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 Viro | a230e55 | 2008-05-21 00:30:41 -0300 | [diff] [blame] | 1043 | /* 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 Endriss | 0ed4a6e | 2008-01-30 01:07:20 -0300 | [diff] [blame] | 1068 | } |
| 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | /* 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 Endriss | 0ed4a6e | 2008-01-30 01:07:20 -0300 | [diff] [blame] | 1081 | |
| 1082 | if (progressive) |
| 1083 | return vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1); |
| 1084 | else |
| 1085 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | static int dvb_video_ioctl(struct inode *inode, struct file *file, |
| 1090 | unsigned int cmd, void *parg) |
| 1091 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1092 | struct dvb_device *dvbdev = file->private_data; |
| 1093 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | unsigned long arg = (unsigned long) parg; |
| 1095 | int ret = 0; |
| 1096 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1097 | dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1110 | ret = av7110_av_stop(av7110, RP_VIDEO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | else |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1112 | ret = vidcom(av7110, AV_VIDEO_CMD_STOP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | av7110->videostate.video_blank ? 0 : 1); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1114 | if (!ret) |
| 1115 | av7110->trickmode = TRICK_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | 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 Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1122 | ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1123 | if (ret) |
| 1124 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) { |
| 1128 | if (av7110->playing == RP_AV) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1129 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0); |
| 1130 | if (ret) |
| 1131 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | av7110->playing &= ~RP_VIDEO; |
| 1133 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1134 | ret = av7110_av_start_play(av7110, RP_VIDEO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1136 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1137 | ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1138 | if (!ret) |
| 1139 | av7110->videostate.play_state = VIDEO_PLAYING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | break; |
| 1141 | |
| 1142 | case VIDEO_FREEZE: |
| 1143 | av7110->videostate.play_state = VIDEO_FREEZED; |
| 1144 | if (av7110->playing & RP_VIDEO) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1145 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | else |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1147 | ret = vidcom(av7110, AV_VIDEO_CMD_FREEZE, 1); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1148 | if (!ret) |
| 1149 | av7110->trickmode = TRICK_FREEZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | break; |
| 1151 | |
| 1152 | case VIDEO_CONTINUE: |
| 1153 | if (av7110->playing & RP_VIDEO) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1154 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0); |
| 1155 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1156 | ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1157 | if (!ret) { |
| 1158 | av7110->videostate.play_state = VIDEO_PLAYING; |
| 1159 | av7110->trickmode = TRICK_NONE; |
| 1160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1176 | ret = dvb_video_get_event(av7110, parg, file->f_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | switch (format) { |
| 1188 | case VIDEO_PAN_SCAN: |
Oliver Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1189 | av7110->display_panscan = VID_PAN_SCAN_PREF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | case VIDEO_LETTER_BOX: |
Oliver Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1193 | av7110->display_panscan = VID_VC_AND_PS_PREF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | |
| 1196 | case VIDEO_CENTER_CUT_OUT: |
Oliver Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1197 | av7110->display_panscan = VID_CENTRE_CUT_PREF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | |
| 1200 | default: |
| 1201 | ret = -EINVAL; |
| 1202 | } |
| 1203 | if (ret < 0) |
| 1204 | break; |
Johannes Stezenbach | a65d3bb | 2005-05-16 21:54:26 -0700 | [diff] [blame] | 1205 | av7110->videostate.display_format = format; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType, |
Oliver Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1207 | 1, av7110->display_panscan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1235 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, |
Johannes Stezenbach | 7a2fa90 | 2005-07-07 17:58:01 -0700 | [diff] [blame] | 1236 | __Scan_I, 2, AV_PES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | else |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1238 | ret = vidcom(av7110, AV_VIDEO_CMD_FFWD, arg); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1239 | if (!ret) { |
| 1240 | av7110->trickmode = TRICK_FAST; |
| 1241 | av7110->videostate.play_state = VIDEO_PLAYING; |
| 1242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | break; |
| 1244 | |
| 1245 | case VIDEO_SLOWMOTION: |
| 1246 | if (av7110->playing&RP_VIDEO) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1247 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0); |
| 1248 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1249 | ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } else { |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1251 | ret = vidcom(av7110, AV_VIDEO_CMD_PLAY, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1252 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1253 | ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1254 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1255 | ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | } |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1257 | if (!ret) { |
| 1258 | av7110->trickmode = TRICK_SLOW; |
| 1259 | av7110->videostate.play_state = VIDEO_PLAYING; |
| 1260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1273 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, |
Johannes Stezenbach | 7a2fa90 | 2005-07-07 17:58:01 -0700 | [diff] [blame] | 1274 | __Play, 2, AV_PES, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1275 | if (ret) |
| 1276 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | if (av7110->trickmode == TRICK_FAST) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1278 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, |
Johannes Stezenbach | 7a2fa90 | 2005-07-07 17:58:01 -0700 | [diff] [blame] | 1279 | __Scan_I, 2, AV_PES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | if (av7110->trickmode == TRICK_SLOW) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1281 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, |
Johannes Stezenbach | 7a2fa90 | 2005-07-07 17:58:01 -0700 | [diff] [blame] | 1282 | __Slow, 2, 0, 0); |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1283 | if (!ret) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1284 | ret = vidcom(av7110, AV_VIDEO_CMD_SLOW, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | if (av7110->trickmode == TRICK_FREEZE) |
Hans Verkuil | 2435be1 | 2007-04-27 12:31:09 -0300 | [diff] [blame] | 1287 | ret = vidcom(av7110, AV_VIDEO_CMD_STOP, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 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 | |
| 1302 | static int dvb_audio_ioctl(struct inode *inode, struct file *file, |
| 1303 | unsigned int cmd, void *parg) |
| 1304 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1305 | struct dvb_device *dvbdev = file->private_data; |
| 1306 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | unsigned long arg = (unsigned long) parg; |
| 1308 | int ret = 0; |
| 1309 | |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1310 | dprintk(1, "av7110:%p, cmd=%04x\n", av7110,cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1319 | ret = av7110_av_stop(av7110, RP_AUDIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | else |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1321 | ret = audcom(av7110, AUDIO_CMD_MUTE); |
| 1322 | if (!ret) |
| 1323 | av7110->audiostate.play_state = AUDIO_STOPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | break; |
| 1325 | |
| 1326 | case AUDIO_PLAY: |
| 1327 | if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY) |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1328 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | break; |
| 1334 | |
| 1335 | case AUDIO_PAUSE: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1336 | ret = audcom(av7110, AUDIO_CMD_MUTE); |
| 1337 | if (!ret) |
| 1338 | av7110->audiostate.play_state = AUDIO_PAUSED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | break; |
| 1340 | |
| 1341 | case AUDIO_CONTINUE: |
| 1342 | if (av7110->audiostate.play_state == AUDIO_PAUSED) { |
| 1343 | av7110->audiostate.play_state = AUDIO_PLAYING; |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1344 | ret = audcom(av7110, AUDIO_CMD_UNMUTE | AUDIO_CMD_PCM16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1354 | ret = audcom(av7110, arg ? AUDIO_CMD_MUTE : AUDIO_CMD_UNMUTE); |
| 1355 | if (!ret) |
| 1356 | av7110->audiostate.mute_state = (int) arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | break; |
| 1358 | } |
| 1359 | |
| 1360 | case AUDIO_SET_AV_SYNC: |
| 1361 | av7110->audiostate.AV_sync_state = (int) arg; |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1362 | ret = audcom(av7110, arg ? AUDIO_CMD_SYNC_ON : AUDIO_CMD_SYNC_OFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | case AUDIO_SET_BYPASS_MODE: |
Dr. Werner Fink | 47f3692 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1366 | if (FW_VERSION(av7110->arm_app) < 0x2621) |
| 1367 | ret = -EINVAL; |
| 1368 | av7110->audiostate.bypass_mode = (int)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1376 | ret = audcom(av7110, AUDIO_CMD_STEREO); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1377 | if (!ret) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1378 | if (av7110->adac_type == DVB_ADAC_CRYSTAL) |
| 1379 | i2c_writereg(av7110, 0x20, 0x02, 0x49); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1380 | else if (av7110->adac_type == DVB_ADAC_MSP34x5) |
| 1381 | msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); |
| 1382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | break; |
| 1384 | |
| 1385 | case AUDIO_MONO_LEFT: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1386 | ret = audcom(av7110, AUDIO_CMD_MONO_L); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1387 | if (!ret) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1388 | if (av7110->adac_type == DVB_ADAC_CRYSTAL) |
| 1389 | i2c_writereg(av7110, 0x20, 0x02, 0x4a); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1390 | else if (av7110->adac_type == DVB_ADAC_MSP34x5) |
| 1391 | msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0200); |
| 1392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | |
| 1395 | case AUDIO_MONO_RIGHT: |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1396 | ret = audcom(av7110, AUDIO_CMD_MONO_R); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1397 | if (!ret) { |
Wolfgang Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1398 | if (av7110->adac_type == DVB_ADAC_CRYSTAL) |
| 1399 | i2c_writereg(av7110, 0x20, 0x02, 0x45); |
Tim Kaiser | 61391e0 | 2006-06-25 09:14:07 -0300 | [diff] [blame] | 1400 | else if (av7110->adac_type == DVB_ADAC_MSP34x5) |
| 1401 | msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0210); |
| 1402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | 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 Fink | 47f3692 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1416 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1427 | ret = av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, |
Johannes Stezenbach | 7a2fa90 | 2005-07-07 17:58:01 -0700 | [diff] [blame] | 1428 | __Play, 2, AV_PES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | 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 Rohdewald | ce18a22 | 2005-07-07 17:57:59 -0700 | [diff] [blame] | 1437 | ret = av7110_set_volume(av7110, amix->volume_left, amix->volume_right); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | } |
| 1440 | case AUDIO_SET_STREAMTYPE: |
| 1441 | break; |
| 1442 | default: |
| 1443 | ret = -ENOIOCTLCMD; |
| 1444 | } |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | static int dvb_video_open(struct inode *inode, struct file *file) |
| 1450 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1451 | struct dvb_device *dvbdev = file->private_data; |
| 1452 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | 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 | |
| 1474 | static int dvb_video_release(struct inode *inode, struct file *file) |
| 1475 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1476 | struct dvb_device *dvbdev = file->private_data; |
| 1477 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
| 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 | |
| 1488 | static int dvb_audio_open(struct inode *inode, struct file *file) |
| 1489 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1490 | struct dvb_device *dvbdev = file->private_data; |
| 1491 | struct av7110 *av7110 = dvbdev->priv; |
| 1492 | int err = dvb_generic_open(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
| 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 | |
| 1503 | static int dvb_audio_release(struct inode *inode, struct file *file) |
| 1504 | { |
Tobias Klauser | d9bdf77 | 2006-12-26 07:33:48 -0300 | [diff] [blame] | 1505 | struct dvb_device *dvbdev = file->private_data; |
| 1506 | struct av7110 *av7110 = dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
| 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 Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 1520 | static const struct file_operations dvb_video_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | .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 | |
| 1529 | static 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 Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 1538 | static const struct file_operations dvb_audio_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | .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 | |
| 1547 | static 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 | |
| 1556 | int 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 Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1569 | av7110->videostate.display_format = VIDEO_LETTER_BOX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | av7110->display_ar = VIDEO_FORMAT_4_3; |
Oliver Endriss | defd574e | 2007-07-12 23:08:07 -0300 | [diff] [blame] | 1571 | av7110->display_panscan = VID_VC_AND_PS_PREF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
| 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 Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1579 | dvb_register_device(&av7110->dvb_adapter, &av7110->video_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | &dvbdev_video, av7110, DVB_DEVICE_VIDEO); |
| 1581 | |
Johannes Stezenbach | fdc53a6 | 2005-05-16 21:54:39 -0700 | [diff] [blame] | 1582 | dvb_register_device(&av7110->dvb_adapter, &av7110->audio_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | &dvbdev_audio, av7110, DVB_DEVICE_AUDIO); |
| 1584 | |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
| 1588 | void av7110_av_unregister(struct av7110 *av7110) |
| 1589 | { |
| 1590 | dvb_unregister_device(av7110->audio_dev); |
| 1591 | dvb_unregister_device(av7110->video_dev); |
| 1592 | } |
| 1593 | |
| 1594 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | 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; |
| 1616 | out: |
| 1617 | return ret; |
| 1618 | } |
| 1619 | |
| 1620 | void av7110_av_exit(struct av7110 *av7110) |
| 1621 | { |
| 1622 | av7110_ipack_free(&av7110->ipack[0]); |
| 1623 | av7110_ipack_free(&av7110->ipack[1]); |
| 1624 | } |