ivtv-fileops.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. /*
  2. file operation functions
  3. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  4. Copyright (C) 2004 Chris Kennedy <c@groovy.org>
  5. Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include "ivtv-driver.h"
  19. #include "ivtv-fileops.h"
  20. #include "ivtv-i2c.h"
  21. #include "ivtv-queue.h"
  22. #include "ivtv-udma.h"
  23. #include "ivtv-irq.h"
  24. #include "ivtv-vbi.h"
  25. #include "ivtv-mailbox.h"
  26. #include "ivtv-routing.h"
  27. #include "ivtv-streams.h"
  28. #include "ivtv-yuv.h"
  29. #include "ivtv-ioctl.h"
  30. #include "ivtv-cards.h"
  31. #include <media/saa7115.h>
  32. /* This function tries to claim the stream for a specific file descriptor.
  33. If no one else is using this stream then the stream is claimed and
  34. associated VBI streams are also automatically claimed.
  35. Possible error returns: -EBUSY if someone else has claimed
  36. the stream or 0 on success. */
  37. int ivtv_claim_stream(struct ivtv_open_id *id, int type)
  38. {
  39. struct ivtv *itv = id->itv;
  40. struct ivtv_stream *s = &itv->streams[type];
  41. struct ivtv_stream *s_vbi;
  42. int vbi_type;
  43. if (test_and_set_bit(IVTV_F_S_CLAIMED, &s->s_flags)) {
  44. /* someone already claimed this stream */
  45. if (s->id == id->open_id) {
  46. /* yes, this file descriptor did. So that's OK. */
  47. return 0;
  48. }
  49. if (s->id == -1 && (type == IVTV_DEC_STREAM_TYPE_VBI ||
  50. type == IVTV_ENC_STREAM_TYPE_VBI)) {
  51. /* VBI is handled already internally, now also assign
  52. the file descriptor to this stream for external
  53. reading of the stream. */
  54. s->id = id->open_id;
  55. IVTV_DEBUG_INFO("Start Read VBI\n");
  56. return 0;
  57. }
  58. /* someone else is using this stream already */
  59. IVTV_DEBUG_INFO("Stream %d is busy\n", type);
  60. return -EBUSY;
  61. }
  62. s->id = id->open_id;
  63. if (type == IVTV_DEC_STREAM_TYPE_VBI) {
  64. /* Enable reinsertion interrupt */
  65. ivtv_clear_irq_mask(itv, IVTV_IRQ_DEC_VBI_RE_INSERT);
  66. }
  67. /* IVTV_DEC_STREAM_TYPE_MPG needs to claim IVTV_DEC_STREAM_TYPE_VBI,
  68. IVTV_ENC_STREAM_TYPE_MPG needs to claim IVTV_ENC_STREAM_TYPE_VBI
  69. (provided VBI insertion is on and sliced VBI is selected), for all
  70. other streams we're done */
  71. if (type == IVTV_DEC_STREAM_TYPE_MPG) {
  72. vbi_type = IVTV_DEC_STREAM_TYPE_VBI;
  73. } else if (type == IVTV_ENC_STREAM_TYPE_MPG &&
  74. itv->vbi.insert_mpeg && itv->vbi.sliced_in->service_set) {
  75. vbi_type = IVTV_ENC_STREAM_TYPE_VBI;
  76. } else {
  77. return 0;
  78. }
  79. s_vbi = &itv->streams[vbi_type];
  80. if (!test_and_set_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags)) {
  81. /* Enable reinsertion interrupt */
  82. if (vbi_type == IVTV_DEC_STREAM_TYPE_VBI)
  83. ivtv_clear_irq_mask(itv, IVTV_IRQ_DEC_VBI_RE_INSERT);
  84. }
  85. /* mark that it is used internally */
  86. set_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags);
  87. return 0;
  88. }
  89. /* This function releases a previously claimed stream. It will take into
  90. account associated VBI streams. */
  91. void ivtv_release_stream(struct ivtv_stream *s)
  92. {
  93. struct ivtv *itv = s->itv;
  94. struct ivtv_stream *s_vbi;
  95. s->id = -1;
  96. if ((s->type == IVTV_DEC_STREAM_TYPE_VBI || s->type == IVTV_ENC_STREAM_TYPE_VBI) &&
  97. test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) {
  98. /* this stream is still in use internally */
  99. return;
  100. }
  101. if (!test_and_clear_bit(IVTV_F_S_CLAIMED, &s->s_flags)) {
  102. IVTV_DEBUG_WARN("Release stream %s not in use!\n", s->name);
  103. return;
  104. }
  105. ivtv_flush_queues(s);
  106. /* disable reinsertion interrupt */
  107. if (s->type == IVTV_DEC_STREAM_TYPE_VBI)
  108. ivtv_set_irq_mask(itv, IVTV_IRQ_DEC_VBI_RE_INSERT);
  109. /* IVTV_DEC_STREAM_TYPE_MPG needs to release IVTV_DEC_STREAM_TYPE_VBI,
  110. IVTV_ENC_STREAM_TYPE_MPG needs to release IVTV_ENC_STREAM_TYPE_VBI,
  111. for all other streams we're done */
  112. if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
  113. s_vbi = &itv->streams[IVTV_DEC_STREAM_TYPE_VBI];
  114. else if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
  115. s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  116. else
  117. return;
  118. /* clear internal use flag */
  119. if (!test_and_clear_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags)) {
  120. /* was already cleared */
  121. return;
  122. }
  123. if (s_vbi->id != -1) {
  124. /* VBI stream still claimed by a file descriptor */
  125. return;
  126. }
  127. /* disable reinsertion interrupt */
  128. if (s_vbi->type == IVTV_DEC_STREAM_TYPE_VBI)
  129. ivtv_set_irq_mask(itv, IVTV_IRQ_DEC_VBI_RE_INSERT);
  130. clear_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags);
  131. ivtv_flush_queues(s_vbi);
  132. }
  133. static void ivtv_dualwatch(struct ivtv *itv)
  134. {
  135. struct v4l2_tuner vt;
  136. u16 new_bitmap;
  137. u16 new_stereo_mode;
  138. const u16 stereo_mask = 0x0300;
  139. const u16 dual = 0x0200;
  140. new_stereo_mode = itv->params.audio_properties & stereo_mask;
  141. memset(&vt, 0, sizeof(vt));
  142. ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, &vt);
  143. if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2))
  144. new_stereo_mode = dual;
  145. if (new_stereo_mode == itv->dualwatch_stereo_mode)
  146. return;
  147. new_bitmap = new_stereo_mode | (itv->params.audio_properties & ~stereo_mask);
  148. IVTV_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. new audio_bitmask=0x%ux\n",
  149. itv->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
  150. if (ivtv_vapi(itv, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new_bitmap) == 0) {
  151. itv->dualwatch_stereo_mode = new_stereo_mode;
  152. return;
  153. }
  154. IVTV_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
  155. }
  156. static void ivtv_update_pgm_info(struct ivtv *itv)
  157. {
  158. u32 wr_idx = (read_enc(itv->pgm_info_offset) - itv->pgm_info_offset - 4) / 24;
  159. int cnt;
  160. int i = 0;
  161. if (wr_idx >= itv->pgm_info_num) {
  162. IVTV_DEBUG_WARN("Invalid PGM index %d (>= %d)\n", wr_idx, itv->pgm_info_num);
  163. return;
  164. }
  165. cnt = (wr_idx + itv->pgm_info_num - itv->pgm_info_write_idx) % itv->pgm_info_num;
  166. while (i < cnt) {
  167. int idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num;
  168. struct v4l2_enc_idx_entry *e = itv->pgm_info + idx;
  169. u32 addr = itv->pgm_info_offset + 4 + idx * 24;
  170. const int mapping[8] = { -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P, -1,
  171. V4L2_ENC_IDX_FRAME_B, -1, -1, -1 };
  172. // 1=I, 2=P, 4=B
  173. e->offset = read_enc(addr + 4) + ((u64)read_enc(addr + 8) << 32);
  174. if (e->offset > itv->mpg_data_received) {
  175. break;
  176. }
  177. e->offset += itv->vbi_data_inserted;
  178. e->length = read_enc(addr);
  179. e->pts = read_enc(addr + 16) + ((u64)(read_enc(addr + 20) & 1) << 32);
  180. e->flags = mapping[read_enc(addr + 12) & 7];
  181. i++;
  182. }
  183. itv->pgm_info_write_idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num;
  184. }
  185. static struct ivtv_buffer *ivtv_get_buffer(struct ivtv_stream *s, int non_block, int *err)
  186. {
  187. struct ivtv *itv = s->itv;
  188. struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  189. struct ivtv_buffer *buf;
  190. DEFINE_WAIT(wait);
  191. *err = 0;
  192. while (1) {
  193. if (s->type == IVTV_ENC_STREAM_TYPE_MPG) {
  194. /* Process pending program info updates and pending VBI data */
  195. ivtv_update_pgm_info(itv);
  196. if (jiffies - itv->dualwatch_jiffies > msecs_to_jiffies(1000)) {
  197. itv->dualwatch_jiffies = jiffies;
  198. ivtv_dualwatch(itv);
  199. }
  200. if (test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) &&
  201. !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) {
  202. while ((buf = ivtv_dequeue(s_vbi, &s_vbi->q_full))) {
  203. /* byteswap and process VBI data */
  204. ivtv_process_vbi_data(itv, buf, s_vbi->dma_pts, s_vbi->type);
  205. ivtv_enqueue(s_vbi, buf, &s_vbi->q_free);
  206. }
  207. }
  208. buf = &itv->vbi.sliced_mpeg_buf;
  209. if (buf->readpos != buf->bytesused) {
  210. return buf;
  211. }
  212. }
  213. /* do we have leftover data? */
  214. buf = ivtv_dequeue(s, &s->q_io);
  215. if (buf)
  216. return buf;
  217. /* do we have new data? */
  218. buf = ivtv_dequeue(s, &s->q_full);
  219. if (buf) {
  220. if ((buf->b_flags & IVTV_F_B_NEED_BUF_SWAP) == 0)
  221. return buf;
  222. buf->b_flags &= ~IVTV_F_B_NEED_BUF_SWAP;
  223. if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
  224. /* byteswap MPG data */
  225. ivtv_buf_swap(buf);
  226. else if (s->type != IVTV_DEC_STREAM_TYPE_VBI) {
  227. /* byteswap and process VBI data */
  228. ivtv_process_vbi_data(itv, buf, s->dma_pts, s->type);
  229. }
  230. return buf;
  231. }
  232. /* return if end of stream */
  233. if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  234. IVTV_DEBUG_INFO("EOS %s\n", s->name);
  235. return NULL;
  236. }
  237. /* return if file was opened with O_NONBLOCK */
  238. if (non_block) {
  239. *err = -EAGAIN;
  240. return NULL;
  241. }
  242. /* wait for more data to arrive */
  243. prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
  244. /* New buffers might have become available before we were added to the waitqueue */
  245. if (!s->q_full.buffers)
  246. schedule();
  247. finish_wait(&s->waitq, &wait);
  248. if (signal_pending(current)) {
  249. /* return if a signal was received */
  250. IVTV_DEBUG_INFO("User stopped %s\n", s->name);
  251. *err = -EINTR;
  252. return NULL;
  253. }
  254. }
  255. }
  256. static void ivtv_setup_sliced_vbi_buf(struct ivtv *itv)
  257. {
  258. int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES;
  259. itv->vbi.sliced_mpeg_buf.buf = itv->vbi.sliced_mpeg_data[idx];
  260. itv->vbi.sliced_mpeg_buf.bytesused = itv->vbi.sliced_mpeg_size[idx];
  261. itv->vbi.sliced_mpeg_buf.readpos = 0;
  262. }
  263. static size_t ivtv_copy_buf_to_user(struct ivtv_stream *s, struct ivtv_buffer *buf,
  264. char __user *ubuf, size_t ucount)
  265. {
  266. struct ivtv *itv = s->itv;
  267. size_t len = buf->bytesused - buf->readpos;
  268. if (len > ucount) len = ucount;
  269. if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  270. itv->vbi.sliced_in->service_set && buf != &itv->vbi.sliced_mpeg_buf) {
  271. const char *start = buf->buf + buf->readpos;
  272. const char *p = start + 1;
  273. const u8 *q;
  274. u8 ch = itv->search_pack_header ? 0xba : 0xe0;
  275. int stuffing, i;
  276. while (start + len > p && (q = memchr(p, 0, start + len - p))) {
  277. p = q + 1;
  278. if ((char *)q + 15 >= buf->buf + buf->bytesused ||
  279. q[1] != 0 || q[2] != 1 || q[3] != ch) {
  280. continue;
  281. }
  282. if (!itv->search_pack_header) {
  283. if ((q[6] & 0xc0) != 0x80)
  284. continue;
  285. if (((q[7] & 0xc0) == 0x80 && (q[9] & 0xf0) == 0x20) ||
  286. ((q[7] & 0xc0) == 0xc0 && (q[9] & 0xf0) == 0x30)) {
  287. ch = 0xba;
  288. itv->search_pack_header = 1;
  289. p = q + 9;
  290. }
  291. continue;
  292. }
  293. stuffing = q[13] & 7;
  294. /* all stuffing bytes must be 0xff */
  295. for (i = 0; i < stuffing; i++)
  296. if (q[14 + i] != 0xff)
  297. break;
  298. if (i == stuffing && (q[4] & 0xc4) == 0x44 && (q[12] & 3) == 3 &&
  299. q[14 + stuffing] == 0 && q[15 + stuffing] == 0 &&
  300. q[16 + stuffing] == 1) {
  301. itv->search_pack_header = 0;
  302. len = (char *)q - start;
  303. ivtv_setup_sliced_vbi_buf(itv);
  304. break;
  305. }
  306. }
  307. }
  308. if (copy_to_user(ubuf, (u8 *)buf->buf + buf->readpos, len)) {
  309. IVTV_DEBUG_WARN("copy %zd bytes to user failed for %s\n", len, s->name);
  310. return -EFAULT;
  311. }
  312. /*IVTV_INFO("copied %lld %d %d %d %d %d vbi %d\n", itv->mpg_data_received, len, ucount,
  313. buf->readpos, buf->bytesused, buf->bytesused - buf->readpos - len,
  314. buf == &itv->vbi.sliced_mpeg_buf); */
  315. buf->readpos += len;
  316. if (s->type == IVTV_ENC_STREAM_TYPE_MPG && buf != &itv->vbi.sliced_mpeg_buf)
  317. itv->mpg_data_received += len;
  318. return len;
  319. }
  320. static ssize_t ivtv_read(struct ivtv_stream *s, char __user *ubuf, size_t tot_count, int non_block)
  321. {
  322. struct ivtv *itv = s->itv;
  323. size_t tot_written = 0;
  324. int single_frame = 0;
  325. if (atomic_read(&itv->capturing) == 0 && s->id == -1) {
  326. /* shouldn't happen */
  327. IVTV_DEBUG_WARN("Stream %s not initialized before read\n", s->name);
  328. return -EIO;
  329. }
  330. /* Each VBI buffer is one frame, the v4l2 API says that for VBI the frames should
  331. arrive one-by-one, so make sure we never output more than one VBI frame at a time */
  332. if (s->type == IVTV_DEC_STREAM_TYPE_VBI ||
  333. (s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set))
  334. single_frame = 1;
  335. for (;;) {
  336. struct ivtv_buffer *buf;
  337. int rc;
  338. buf = ivtv_get_buffer(s, non_block, &rc);
  339. /* if there is no data available... */
  340. if (buf == NULL) {
  341. /* if we got data, then return that regardless */
  342. if (tot_written)
  343. break;
  344. /* EOS condition */
  345. if (rc == 0) {
  346. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  347. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  348. ivtv_release_stream(s);
  349. }
  350. /* set errno */
  351. return rc;
  352. }
  353. rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written);
  354. if (buf != &itv->vbi.sliced_mpeg_buf) {
  355. ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io);
  356. }
  357. else if (buf->readpos == buf->bytesused) {
  358. int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES;
  359. itv->vbi.sliced_mpeg_size[idx] = 0;
  360. itv->vbi.inserted_frame++;
  361. itv->vbi_data_inserted += buf->bytesused;
  362. }
  363. if (rc < 0)
  364. return rc;
  365. tot_written += rc;
  366. if (tot_written == tot_count || single_frame)
  367. break;
  368. }
  369. return tot_written;
  370. }
  371. static ssize_t ivtv_read_pos(struct ivtv_stream *s, char __user *ubuf, size_t count,
  372. loff_t *pos, int non_block)
  373. {
  374. ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0;
  375. struct ivtv *itv = s->itv;
  376. IVTV_DEBUG_HI_FILE("read %zd from %s, got %zd\n", count, s->name, rc);
  377. if (rc > 0)
  378. pos += rc;
  379. return rc;
  380. }
  381. int ivtv_start_capture(struct ivtv_open_id *id)
  382. {
  383. struct ivtv *itv = id->itv;
  384. struct ivtv_stream *s = &itv->streams[id->type];
  385. struct ivtv_stream *s_vbi;
  386. if (s->type == IVTV_ENC_STREAM_TYPE_RAD ||
  387. s->type == IVTV_DEC_STREAM_TYPE_MPG ||
  388. s->type == IVTV_DEC_STREAM_TYPE_YUV ||
  389. s->type == IVTV_DEC_STREAM_TYPE_VOUT) {
  390. /* you cannot read from these stream types. */
  391. return -EPERM;
  392. }
  393. /* Try to claim this stream. */
  394. if (ivtv_claim_stream(id, s->type))
  395. return -EBUSY;
  396. /* This stream does not need to start capturing */
  397. if (s->type == IVTV_DEC_STREAM_TYPE_VBI) {
  398. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  399. return 0;
  400. }
  401. /* If capture is already in progress, then we also have to
  402. do nothing extra. */
  403. if (test_bit(IVTV_F_S_STREAMOFF, &s->s_flags) || test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  404. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  405. return 0;
  406. }
  407. /* Start VBI capture if required */
  408. s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  409. if (s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  410. test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) &&
  411. !test_and_set_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) {
  412. /* Note: the IVTV_ENC_STREAM_TYPE_VBI is claimed
  413. automatically when the MPG stream is claimed.
  414. We only need to start the VBI capturing. */
  415. if (ivtv_start_v4l2_encode_stream(s_vbi)) {
  416. IVTV_DEBUG_WARN("VBI capture start failed\n");
  417. /* Failure, clean up and return an error */
  418. clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags);
  419. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  420. /* also releases the associated VBI stream */
  421. ivtv_release_stream(s);
  422. return -EIO;
  423. }
  424. IVTV_DEBUG_INFO("VBI insertion started\n");
  425. }
  426. /* Tell the card to start capturing */
  427. if (!ivtv_start_v4l2_encode_stream(s)) {
  428. /* We're done */
  429. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  430. /* Resume a possibly paused encoder */
  431. if (test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
  432. ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1);
  433. return 0;
  434. }
  435. /* failure, clean up */
  436. IVTV_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name);
  437. /* Note: the IVTV_ENC_STREAM_TYPE_VBI is released
  438. automatically when the MPG stream is released.
  439. We only need to stop the VBI capturing. */
  440. if (s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  441. test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) {
  442. ivtv_stop_v4l2_encode_stream(s_vbi, 0);
  443. clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags);
  444. }
  445. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  446. ivtv_release_stream(s);
  447. return -EIO;
  448. }
  449. ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos)
  450. {
  451. struct ivtv_open_id *id = filp->private_data;
  452. struct ivtv *itv = id->itv;
  453. struct ivtv_stream *s = &itv->streams[id->type];
  454. int rc;
  455. IVTV_DEBUG_HI_FILE("read %zd bytes from %s\n", count, s->name);
  456. mutex_lock(&itv->serialize_lock);
  457. rc = ivtv_start_capture(id);
  458. mutex_unlock(&itv->serialize_lock);
  459. if (rc)
  460. return rc;
  461. return ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK);
  462. }
  463. int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
  464. {
  465. struct ivtv *itv = id->itv;
  466. struct ivtv_stream *s = &itv->streams[id->type];
  467. if (atomic_read(&itv->decoding) == 0) {
  468. if (ivtv_claim_stream(id, s->type)) {
  469. /* someone else is using this stream already */
  470. IVTV_DEBUG_WARN("start decode, stream already claimed\n");
  471. return -EBUSY;
  472. }
  473. ivtv_start_v4l2_decode_stream(s, 0);
  474. }
  475. if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
  476. return ivtv_set_speed(itv, speed);
  477. return 0;
  478. }
  479. ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos)
  480. {
  481. struct ivtv_open_id *id = filp->private_data;
  482. struct ivtv *itv = id->itv;
  483. struct ivtv_stream *s = &itv->streams[id->type];
  484. struct yuv_playback_info *yi = &itv->yuv_info;
  485. struct ivtv_buffer *buf;
  486. struct ivtv_queue q;
  487. int bytes_written = 0;
  488. int mode;
  489. int rc;
  490. DEFINE_WAIT(wait);
  491. IVTV_DEBUG_HI_FILE("write %zd bytes to %s\n", count, s->name);
  492. if (s->type != IVTV_DEC_STREAM_TYPE_MPG &&
  493. s->type != IVTV_DEC_STREAM_TYPE_YUV &&
  494. s->type != IVTV_DEC_STREAM_TYPE_VOUT)
  495. /* not decoder streams */
  496. return -EPERM;
  497. /* Try to claim this stream */
  498. if (ivtv_claim_stream(id, s->type))
  499. return -EBUSY;
  500. /* This stream does not need to start any decoding */
  501. if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) {
  502. int elems = count / sizeof(struct v4l2_sliced_vbi_data);
  503. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  504. ivtv_write_vbi(itv, (const struct v4l2_sliced_vbi_data *)user_buf, elems);
  505. return elems * sizeof(struct v4l2_sliced_vbi_data);
  506. }
  507. mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV;
  508. if (ivtv_set_output_mode(itv, mode) != mode) {
  509. ivtv_release_stream(s);
  510. return -EBUSY;
  511. }
  512. ivtv_queue_init(&q);
  513. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  514. retry:
  515. /* If possible, just DMA the entire frame - Check the data transfer size
  516. since we may get here before the stream has been fully set-up */
  517. if (mode == OUT_YUV && s->q_full.length == 0 && itv->dma_data_req_size) {
  518. while (count >= itv->dma_data_req_size) {
  519. if (!ivtv_yuv_udma_stream_frame (itv, (void *)user_buf)) {
  520. bytes_written += itv->dma_data_req_size;
  521. user_buf += itv->dma_data_req_size;
  522. count -= itv->dma_data_req_size;
  523. } else {
  524. break;
  525. }
  526. }
  527. if (count == 0) {
  528. IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused);
  529. return bytes_written;
  530. }
  531. }
  532. for (;;) {
  533. /* Gather buffers */
  534. while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_io)))
  535. ivtv_enqueue(s, buf, &q);
  536. while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_free))) {
  537. ivtv_enqueue(s, buf, &q);
  538. }
  539. if (q.buffers)
  540. break;
  541. if (filp->f_flags & O_NONBLOCK)
  542. return -EAGAIN;
  543. prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
  544. /* New buffers might have become free before we were added to the waitqueue */
  545. if (!s->q_free.buffers)
  546. schedule();
  547. finish_wait(&s->waitq, &wait);
  548. if (signal_pending(current)) {
  549. IVTV_DEBUG_INFO("User stopped %s\n", s->name);
  550. return -EINTR;
  551. }
  552. }
  553. /* copy user data into buffers */
  554. while ((buf = ivtv_dequeue(s, &q))) {
  555. /* yuv is a pain. Don't copy more data than needed for a single
  556. frame, otherwise we lose sync with the incoming stream */
  557. if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
  558. yi->stream_size + count > itv->dma_data_req_size)
  559. rc = ivtv_buf_copy_from_user(s, buf, user_buf,
  560. itv->dma_data_req_size - yi->stream_size);
  561. else
  562. rc = ivtv_buf_copy_from_user(s, buf, user_buf, count);
  563. /* Make sure we really got all the user data */
  564. if (rc < 0) {
  565. ivtv_queue_move(s, &q, NULL, &s->q_free, 0);
  566. return rc;
  567. }
  568. user_buf += rc;
  569. count -= rc;
  570. bytes_written += rc;
  571. if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
  572. yi->stream_size += rc;
  573. /* If we have a complete yuv frame, break loop now */
  574. if (yi->stream_size == itv->dma_data_req_size) {
  575. ivtv_enqueue(s, buf, &s->q_full);
  576. yi->stream_size = 0;
  577. break;
  578. }
  579. }
  580. if (buf->bytesused != s->buf_size) {
  581. /* incomplete, leave in q_io for next time */
  582. ivtv_enqueue(s, buf, &s->q_io);
  583. break;
  584. }
  585. /* Byteswap MPEG buffer */
  586. if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
  587. ivtv_buf_swap(buf);
  588. ivtv_enqueue(s, buf, &s->q_full);
  589. }
  590. /* Start decoder (returns 0 if already started) */
  591. mutex_lock(&itv->serialize_lock);
  592. rc = ivtv_start_decoding(id, itv->speed);
  593. mutex_unlock(&itv->serialize_lock);
  594. if (rc) {
  595. IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name);
  596. /* failure, clean up */
  597. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  598. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  599. return rc;
  600. }
  601. if (test_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags)) {
  602. if (s->q_full.length >= itv->dma_data_req_size) {
  603. int got_sig;
  604. if (mode == OUT_YUV)
  605. ivtv_yuv_setup_stream_frame(itv);
  606. prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
  607. while (!(got_sig = signal_pending(current)) &&
  608. test_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) {
  609. schedule();
  610. }
  611. finish_wait(&itv->dma_waitq, &wait);
  612. if (got_sig) {
  613. IVTV_DEBUG_INFO("User interrupted %s\n", s->name);
  614. return -EINTR;
  615. }
  616. clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
  617. ivtv_queue_move(s, &s->q_full, NULL, &s->q_predma, itv->dma_data_req_size);
  618. ivtv_dma_stream_dec_prepare(s, itv->dma_data_req_offset + IVTV_DECODER_OFFSET, 1);
  619. }
  620. }
  621. /* more user data is available, wait until buffers become free
  622. to transfer the rest. */
  623. if (count && !(filp->f_flags & O_NONBLOCK))
  624. goto retry;
  625. IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused);
  626. return bytes_written;
  627. }
  628. unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
  629. {
  630. struct ivtv_open_id *id = filp->private_data;
  631. struct ivtv *itv = id->itv;
  632. struct ivtv_stream *s = &itv->streams[id->type];
  633. int res = 0;
  634. /* add stream's waitq to the poll list */
  635. IVTV_DEBUG_HI_FILE("Decoder poll\n");
  636. poll_wait(filp, &s->waitq, wait);
  637. set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
  638. if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) ||
  639. test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
  640. res = POLLPRI;
  641. /* Allow write if buffers are available for writing */
  642. if (s->q_free.buffers)
  643. res |= POLLOUT | POLLWRNORM;
  644. return res;
  645. }
  646. unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
  647. {
  648. struct ivtv_open_id *id = filp->private_data;
  649. struct ivtv *itv = id->itv;
  650. struct ivtv_stream *s = &itv->streams[id->type];
  651. int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  652. /* Start a capture if there is none */
  653. if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  654. int rc;
  655. mutex_lock(&itv->serialize_lock);
  656. rc = ivtv_start_capture(id);
  657. mutex_unlock(&itv->serialize_lock);
  658. if (rc) {
  659. IVTV_DEBUG_INFO("Could not start capture for %s (%d)\n",
  660. s->name, rc);
  661. return POLLERR;
  662. }
  663. IVTV_DEBUG_FILE("Encoder poll started capture\n");
  664. }
  665. /* add stream's waitq to the poll list */
  666. IVTV_DEBUG_HI_FILE("Encoder poll\n");
  667. poll_wait(filp, &s->waitq, wait);
  668. if (eof || s->q_full.length || s->q_io.length)
  669. return POLLIN | POLLRDNORM;
  670. return 0;
  671. }
  672. void ivtv_stop_capture(struct ivtv_open_id *id, int gop_end)
  673. {
  674. struct ivtv *itv = id->itv;
  675. struct ivtv_stream *s = &itv->streams[id->type];
  676. IVTV_DEBUG_FILE("close() of %s\n", s->name);
  677. /* 'Unclaim' this stream */
  678. /* Stop capturing */
  679. if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  680. struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  681. IVTV_DEBUG_INFO("close stopping capture\n");
  682. /* Special case: a running VBI capture for VBI insertion
  683. in the mpeg stream. Need to stop that too. */
  684. if (id->type == IVTV_ENC_STREAM_TYPE_MPG &&
  685. test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags) &&
  686. !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) {
  687. IVTV_DEBUG_INFO("close stopping embedded VBI capture\n");
  688. ivtv_stop_v4l2_encode_stream(s_vbi, 0);
  689. }
  690. if ((id->type == IVTV_DEC_STREAM_TYPE_VBI ||
  691. id->type == IVTV_ENC_STREAM_TYPE_VBI) &&
  692. test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) {
  693. /* Also used internally, don't stop capturing */
  694. s->id = -1;
  695. }
  696. else {
  697. ivtv_stop_v4l2_encode_stream(s, gop_end);
  698. }
  699. }
  700. if (!gop_end) {
  701. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  702. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  703. ivtv_release_stream(s);
  704. }
  705. }
  706. static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
  707. {
  708. struct ivtv *itv = id->itv;
  709. struct ivtv_stream *s = &itv->streams[id->type];
  710. IVTV_DEBUG_FILE("close() of %s\n", s->name);
  711. /* Stop decoding */
  712. if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  713. IVTV_DEBUG_INFO("close stopping decode\n");
  714. ivtv_stop_v4l2_decode_stream(s, flags, pts);
  715. itv->output_mode = OUT_NONE;
  716. }
  717. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  718. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  719. if (id->type == IVTV_DEC_STREAM_TYPE_YUV && test_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags)) {
  720. /* Restore registers we've changed & clean up any mess we've made */
  721. ivtv_yuv_close(itv);
  722. }
  723. if (itv->output_mode == OUT_UDMA_YUV && id->yuv_frames)
  724. itv->output_mode = OUT_NONE;
  725. itv->speed = 0;
  726. clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags);
  727. ivtv_release_stream(s);
  728. }
  729. int ivtv_v4l2_close(struct inode *inode, struct file *filp)
  730. {
  731. struct ivtv_open_id *id = filp->private_data;
  732. struct ivtv *itv = id->itv;
  733. struct ivtv_stream *s = &itv->streams[id->type];
  734. IVTV_DEBUG_FILE("close %s\n", s->name);
  735. v4l2_prio_close(&itv->prio, &id->prio);
  736. /* Easy case first: this stream was never claimed by us */
  737. if (s->id != id->open_id) {
  738. kfree(id);
  739. return 0;
  740. }
  741. /* 'Unclaim' this stream */
  742. /* Stop radio */
  743. mutex_lock(&itv->serialize_lock);
  744. if (id->type == IVTV_ENC_STREAM_TYPE_RAD) {
  745. /* Closing radio device, return to TV mode */
  746. ivtv_mute(itv);
  747. /* Mark that the radio is no longer in use */
  748. clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
  749. /* Switch tuner to TV */
  750. ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std);
  751. /* Select correct audio input (i.e. TV tuner or Line in) */
  752. ivtv_audio_set_io(itv);
  753. if (itv->hw_flags & IVTV_HW_SAA711X)
  754. {
  755. struct v4l2_crystal_freq crystal_freq;
  756. crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
  757. crystal_freq.flags = 0;
  758. ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq);
  759. }
  760. if (atomic_read(&itv->capturing) > 0) {
  761. /* Undo video mute */
  762. ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
  763. itv->params.video_mute | (itv->params.video_mute_yuv << 8));
  764. }
  765. /* Done! Unmute and continue. */
  766. ivtv_unmute(itv);
  767. ivtv_release_stream(s);
  768. } else if (s->type >= IVTV_DEC_STREAM_TYPE_MPG) {
  769. struct ivtv_stream *s_vout = &itv->streams[IVTV_DEC_STREAM_TYPE_VOUT];
  770. ivtv_stop_decoding(id, VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0);
  771. /* If all output streams are closed, and if the user doesn't have
  772. IVTV_DEC_STREAM_TYPE_VOUT open, then disable CC on TV-out. */
  773. if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) {
  774. /* disable CC on TV-out */
  775. ivtv_disable_cc(itv);
  776. }
  777. } else {
  778. ivtv_stop_capture(id, 0);
  779. }
  780. kfree(id);
  781. mutex_unlock(&itv->serialize_lock);
  782. return 0;
  783. }
  784. static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
  785. {
  786. struct ivtv *itv = s->itv;
  787. struct ivtv_open_id *item;
  788. IVTV_DEBUG_FILE("open %s\n", s->name);
  789. if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
  790. test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
  791. return -EBUSY;
  792. if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
  793. test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags))
  794. return -EBUSY;
  795. if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
  796. if (read_reg(0x82c) == 0) {
  797. IVTV_ERR("Tried to open YUV output device but need to send data to mpeg decoder before it can be used\n");
  798. /* return -ENODEV; */
  799. }
  800. ivtv_udma_alloc(itv);
  801. }
  802. /* Allocate memory */
  803. item = kmalloc(sizeof(struct ivtv_open_id), GFP_KERNEL);
  804. if (NULL == item) {
  805. IVTV_DEBUG_WARN("nomem on v4l2 open\n");
  806. return -ENOMEM;
  807. }
  808. item->itv = itv;
  809. item->type = s->type;
  810. v4l2_prio_open(&itv->prio, &item->prio);
  811. item->open_id = itv->open_id++;
  812. filp->private_data = item;
  813. if (item->type == IVTV_ENC_STREAM_TYPE_RAD) {
  814. /* Try to claim this stream */
  815. if (ivtv_claim_stream(item, item->type)) {
  816. /* No, it's already in use */
  817. kfree(item);
  818. return -EBUSY;
  819. }
  820. if (!test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
  821. if (atomic_read(&itv->capturing) > 0) {
  822. /* switching to radio while capture is
  823. in progress is not polite */
  824. ivtv_release_stream(s);
  825. kfree(item);
  826. return -EBUSY;
  827. }
  828. }
  829. /* Mark that the radio is being used. */
  830. set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
  831. /* We have the radio */
  832. ivtv_mute(itv);
  833. /* Switch tuner to radio */
  834. ivtv_call_i2c_clients(itv, AUDC_SET_RADIO, NULL);
  835. /* Select the correct audio input (i.e. radio tuner) */
  836. ivtv_audio_set_io(itv);
  837. if (itv->hw_flags & IVTV_HW_SAA711X)
  838. {
  839. struct v4l2_crystal_freq crystal_freq;
  840. crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
  841. crystal_freq.flags = SAA7115_FREQ_FL_APLL;
  842. ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq);
  843. }
  844. /* Done! Unmute and continue. */
  845. ivtv_unmute(itv);
  846. }
  847. /* YUV or MPG Decoding Mode? */
  848. if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
  849. clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
  850. } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
  851. set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
  852. /* For yuv, we need to know the dma size before we start */
  853. itv->dma_data_req_size =
  854. 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
  855. itv->yuv_info.stream_size = 0;
  856. }
  857. return 0;
  858. }
  859. int ivtv_v4l2_open(struct inode *inode, struct file *filp)
  860. {
  861. int res, x, y = 0;
  862. struct ivtv *itv = NULL;
  863. struct ivtv_stream *s = NULL;
  864. int minor = iminor(inode);
  865. /* Find which card this open was on */
  866. spin_lock(&ivtv_cards_lock);
  867. for (x = 0; itv == NULL && x < ivtv_cards_active; x++) {
  868. /* find out which stream this open was on */
  869. for (y = 0; y < IVTV_MAX_STREAMS; y++) {
  870. s = &ivtv_cards[x]->streams[y];
  871. if (s->v4l2dev && s->v4l2dev->minor == minor) {
  872. itv = ivtv_cards[x];
  873. break;
  874. }
  875. }
  876. }
  877. spin_unlock(&ivtv_cards_lock);
  878. if (itv == NULL) {
  879. /* Couldn't find a device registered
  880. on that minor, shouldn't happen! */
  881. printk(KERN_WARNING "No ivtv device found on minor %d\n", minor);
  882. return -ENXIO;
  883. }
  884. mutex_lock(&itv->serialize_lock);
  885. if (ivtv_init_on_first_open(itv)) {
  886. IVTV_ERR("Failed to initialize on minor %d\n", minor);
  887. mutex_unlock(&itv->serialize_lock);
  888. return -ENXIO;
  889. }
  890. res = ivtv_serialized_open(s, filp);
  891. mutex_unlock(&itv->serialize_lock);
  892. return res;
  893. }
  894. void ivtv_mute(struct ivtv *itv)
  895. {
  896. if (atomic_read(&itv->capturing))
  897. ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 1);
  898. IVTV_DEBUG_INFO("Mute\n");
  899. }
  900. void ivtv_unmute(struct ivtv *itv)
  901. {
  902. if (atomic_read(&itv->capturing)) {
  903. ivtv_msleep_timeout(100, 0);
  904. ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12);
  905. ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 0);
  906. }
  907. IVTV_DEBUG_INFO("Unmute\n");
  908. }