ivtv-fileops.c 31 KB

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