ivtv-fileops.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. static 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 (time_after(jiffies,
  197. itv->dualwatch_jiffies +
  198. msecs_to_jiffies(1000))) {
  199. itv->dualwatch_jiffies = jiffies;
  200. ivtv_dualwatch(itv);
  201. }
  202. if (test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) &&
  203. !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) {
  204. while ((buf = ivtv_dequeue(s_vbi, &s_vbi->q_full))) {
  205. /* byteswap and process VBI data */
  206. ivtv_process_vbi_data(itv, buf, s_vbi->dma_pts, s_vbi->type);
  207. ivtv_enqueue(s_vbi, buf, &s_vbi->q_free);
  208. }
  209. }
  210. buf = &itv->vbi.sliced_mpeg_buf;
  211. if (buf->readpos != buf->bytesused) {
  212. return buf;
  213. }
  214. }
  215. /* do we have leftover data? */
  216. buf = ivtv_dequeue(s, &s->q_io);
  217. if (buf)
  218. return buf;
  219. /* do we have new data? */
  220. buf = ivtv_dequeue(s, &s->q_full);
  221. if (buf) {
  222. if ((buf->b_flags & IVTV_F_B_NEED_BUF_SWAP) == 0)
  223. return buf;
  224. buf->b_flags &= ~IVTV_F_B_NEED_BUF_SWAP;
  225. if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
  226. /* byteswap MPG data */
  227. ivtv_buf_swap(buf);
  228. else if (s->type != IVTV_DEC_STREAM_TYPE_VBI) {
  229. /* byteswap and process VBI data */
  230. ivtv_process_vbi_data(itv, buf, s->dma_pts, s->type);
  231. }
  232. return buf;
  233. }
  234. /* return if end of stream */
  235. if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  236. IVTV_DEBUG_INFO("EOS %s\n", s->name);
  237. return NULL;
  238. }
  239. /* return if file was opened with O_NONBLOCK */
  240. if (non_block) {
  241. *err = -EAGAIN;
  242. return NULL;
  243. }
  244. /* wait for more data to arrive */
  245. prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
  246. /* New buffers might have become available before we were added to the waitqueue */
  247. if (!s->q_full.buffers)
  248. schedule();
  249. finish_wait(&s->waitq, &wait);
  250. if (signal_pending(current)) {
  251. /* return if a signal was received */
  252. IVTV_DEBUG_INFO("User stopped %s\n", s->name);
  253. *err = -EINTR;
  254. return NULL;
  255. }
  256. }
  257. }
  258. static void ivtv_setup_sliced_vbi_buf(struct ivtv *itv)
  259. {
  260. int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES;
  261. itv->vbi.sliced_mpeg_buf.buf = itv->vbi.sliced_mpeg_data[idx];
  262. itv->vbi.sliced_mpeg_buf.bytesused = itv->vbi.sliced_mpeg_size[idx];
  263. itv->vbi.sliced_mpeg_buf.readpos = 0;
  264. }
  265. static size_t ivtv_copy_buf_to_user(struct ivtv_stream *s, struct ivtv_buffer *buf,
  266. char __user *ubuf, size_t ucount)
  267. {
  268. struct ivtv *itv = s->itv;
  269. size_t len = buf->bytesused - buf->readpos;
  270. if (len > ucount) len = ucount;
  271. if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  272. itv->vbi.sliced_in->service_set && buf != &itv->vbi.sliced_mpeg_buf) {
  273. const char *start = buf->buf + buf->readpos;
  274. const char *p = start + 1;
  275. const u8 *q;
  276. u8 ch = itv->search_pack_header ? 0xba : 0xe0;
  277. int stuffing, i;
  278. while (start + len > p && (q = memchr(p, 0, start + len - p))) {
  279. p = q + 1;
  280. if ((char *)q + 15 >= buf->buf + buf->bytesused ||
  281. q[1] != 0 || q[2] != 1 || q[3] != ch) {
  282. continue;
  283. }
  284. if (!itv->search_pack_header) {
  285. if ((q[6] & 0xc0) != 0x80)
  286. continue;
  287. if (((q[7] & 0xc0) == 0x80 && (q[9] & 0xf0) == 0x20) ||
  288. ((q[7] & 0xc0) == 0xc0 && (q[9] & 0xf0) == 0x30)) {
  289. ch = 0xba;
  290. itv->search_pack_header = 1;
  291. p = q + 9;
  292. }
  293. continue;
  294. }
  295. stuffing = q[13] & 7;
  296. /* all stuffing bytes must be 0xff */
  297. for (i = 0; i < stuffing; i++)
  298. if (q[14 + i] != 0xff)
  299. break;
  300. if (i == stuffing && (q[4] & 0xc4) == 0x44 && (q[12] & 3) == 3 &&
  301. q[14 + stuffing] == 0 && q[15 + stuffing] == 0 &&
  302. q[16 + stuffing] == 1) {
  303. itv->search_pack_header = 0;
  304. len = (char *)q - start;
  305. ivtv_setup_sliced_vbi_buf(itv);
  306. break;
  307. }
  308. }
  309. }
  310. if (copy_to_user(ubuf, (u8 *)buf->buf + buf->readpos, len)) {
  311. IVTV_DEBUG_WARN("copy %zd bytes to user failed for %s\n", len, s->name);
  312. return -EFAULT;
  313. }
  314. /*IVTV_INFO("copied %lld %d %d %d %d %d vbi %d\n", itv->mpg_data_received, len, ucount,
  315. buf->readpos, buf->bytesused, buf->bytesused - buf->readpos - len,
  316. buf == &itv->vbi.sliced_mpeg_buf); */
  317. buf->readpos += len;
  318. if (s->type == IVTV_ENC_STREAM_TYPE_MPG && buf != &itv->vbi.sliced_mpeg_buf)
  319. itv->mpg_data_received += len;
  320. return len;
  321. }
  322. static ssize_t ivtv_read(struct ivtv_stream *s, char __user *ubuf, size_t tot_count, int non_block)
  323. {
  324. struct ivtv *itv = s->itv;
  325. size_t tot_written = 0;
  326. int single_frame = 0;
  327. if (atomic_read(&itv->capturing) == 0 && s->id == -1) {
  328. /* shouldn't happen */
  329. IVTV_DEBUG_WARN("Stream %s not initialized before read\n", s->name);
  330. return -EIO;
  331. }
  332. /* Each VBI buffer is one frame, the v4l2 API says that for VBI the frames should
  333. arrive one-by-one, so make sure we never output more than one VBI frame at a time */
  334. if (s->type == IVTV_DEC_STREAM_TYPE_VBI ||
  335. (s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set))
  336. single_frame = 1;
  337. for (;;) {
  338. struct ivtv_buffer *buf;
  339. int rc;
  340. buf = ivtv_get_buffer(s, non_block, &rc);
  341. /* if there is no data available... */
  342. if (buf == NULL) {
  343. /* if we got data, then return that regardless */
  344. if (tot_written)
  345. break;
  346. /* EOS condition */
  347. if (rc == 0) {
  348. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  349. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  350. ivtv_release_stream(s);
  351. }
  352. /* set errno */
  353. return rc;
  354. }
  355. rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written);
  356. if (buf != &itv->vbi.sliced_mpeg_buf) {
  357. ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io);
  358. }
  359. else if (buf->readpos == buf->bytesused) {
  360. int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES;
  361. itv->vbi.sliced_mpeg_size[idx] = 0;
  362. itv->vbi.inserted_frame++;
  363. itv->vbi_data_inserted += buf->bytesused;
  364. }
  365. if (rc < 0)
  366. return rc;
  367. tot_written += rc;
  368. if (tot_written == tot_count || single_frame)
  369. break;
  370. }
  371. return tot_written;
  372. }
  373. static ssize_t ivtv_read_pos(struct ivtv_stream *s, char __user *ubuf, size_t count,
  374. loff_t *pos, int non_block)
  375. {
  376. ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0;
  377. struct ivtv *itv = s->itv;
  378. IVTV_DEBUG_HI_FILE("read %zd from %s, got %zd\n", count, s->name, rc);
  379. if (rc > 0)
  380. pos += rc;
  381. return rc;
  382. }
  383. int ivtv_start_capture(struct ivtv_open_id *id)
  384. {
  385. struct ivtv *itv = id->itv;
  386. struct ivtv_stream *s = &itv->streams[id->type];
  387. struct ivtv_stream *s_vbi;
  388. if (s->type == IVTV_ENC_STREAM_TYPE_RAD ||
  389. s->type == IVTV_DEC_STREAM_TYPE_MPG ||
  390. s->type == IVTV_DEC_STREAM_TYPE_YUV ||
  391. s->type == IVTV_DEC_STREAM_TYPE_VOUT) {
  392. /* you cannot read from these stream types. */
  393. return -EPERM;
  394. }
  395. /* Try to claim this stream. */
  396. if (ivtv_claim_stream(id, s->type))
  397. return -EBUSY;
  398. /* This stream does not need to start capturing */
  399. if (s->type == IVTV_DEC_STREAM_TYPE_VBI) {
  400. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  401. return 0;
  402. }
  403. /* If capture is already in progress, then we also have to
  404. do nothing extra. */
  405. if (test_bit(IVTV_F_S_STREAMOFF, &s->s_flags) || test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  406. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  407. return 0;
  408. }
  409. /* Start VBI capture if required */
  410. s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  411. if (s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  412. test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) &&
  413. !test_and_set_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) {
  414. /* Note: the IVTV_ENC_STREAM_TYPE_VBI is claimed
  415. automatically when the MPG stream is claimed.
  416. We only need to start the VBI capturing. */
  417. if (ivtv_start_v4l2_encode_stream(s_vbi)) {
  418. IVTV_DEBUG_WARN("VBI capture start failed\n");
  419. /* Failure, clean up and return an error */
  420. clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags);
  421. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  422. /* also releases the associated VBI stream */
  423. ivtv_release_stream(s);
  424. return -EIO;
  425. }
  426. IVTV_DEBUG_INFO("VBI insertion started\n");
  427. }
  428. /* Tell the card to start capturing */
  429. if (!ivtv_start_v4l2_encode_stream(s)) {
  430. /* We're done */
  431. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  432. /* Resume a possibly paused encoder */
  433. if (test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
  434. ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1);
  435. return 0;
  436. }
  437. /* failure, clean up */
  438. IVTV_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name);
  439. /* Note: the IVTV_ENC_STREAM_TYPE_VBI is released
  440. automatically when the MPG stream is released.
  441. We only need to stop the VBI capturing. */
  442. if (s->type == IVTV_ENC_STREAM_TYPE_MPG &&
  443. test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) {
  444. ivtv_stop_v4l2_encode_stream(s_vbi, 0);
  445. clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags);
  446. }
  447. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  448. ivtv_release_stream(s);
  449. return -EIO;
  450. }
  451. ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos)
  452. {
  453. struct ivtv_open_id *id = filp->private_data;
  454. struct ivtv *itv = id->itv;
  455. struct ivtv_stream *s = &itv->streams[id->type];
  456. int rc;
  457. IVTV_DEBUG_HI_FILE("read %zd bytes from %s\n", count, s->name);
  458. mutex_lock(&itv->serialize_lock);
  459. rc = ivtv_start_capture(id);
  460. mutex_unlock(&itv->serialize_lock);
  461. if (rc)
  462. return rc;
  463. return ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK);
  464. }
  465. int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
  466. {
  467. struct ivtv *itv = id->itv;
  468. struct ivtv_stream *s = &itv->streams[id->type];
  469. if (atomic_read(&itv->decoding) == 0) {
  470. if (ivtv_claim_stream(id, s->type)) {
  471. /* someone else is using this stream already */
  472. IVTV_DEBUG_WARN("start decode, stream already claimed\n");
  473. return -EBUSY;
  474. }
  475. ivtv_start_v4l2_decode_stream(s, 0);
  476. }
  477. if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
  478. return ivtv_set_speed(itv, speed);
  479. return 0;
  480. }
  481. ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos)
  482. {
  483. struct ivtv_open_id *id = filp->private_data;
  484. struct ivtv *itv = id->itv;
  485. struct ivtv_stream *s = &itv->streams[id->type];
  486. struct yuv_playback_info *yi = &itv->yuv_info;
  487. struct ivtv_buffer *buf;
  488. struct ivtv_queue q;
  489. int bytes_written = 0;
  490. int mode;
  491. int rc;
  492. DEFINE_WAIT(wait);
  493. IVTV_DEBUG_HI_FILE("write %zd bytes to %s\n", count, s->name);
  494. if (s->type != IVTV_DEC_STREAM_TYPE_MPG &&
  495. s->type != IVTV_DEC_STREAM_TYPE_YUV &&
  496. s->type != IVTV_DEC_STREAM_TYPE_VOUT)
  497. /* not decoder streams */
  498. return -EPERM;
  499. /* Try to claim this stream */
  500. if (ivtv_claim_stream(id, s->type))
  501. return -EBUSY;
  502. /* This stream does not need to start any decoding */
  503. if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) {
  504. int elems = count / sizeof(struct v4l2_sliced_vbi_data);
  505. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  506. ivtv_write_vbi(itv, (const struct v4l2_sliced_vbi_data *)user_buf, elems);
  507. return elems * sizeof(struct v4l2_sliced_vbi_data);
  508. }
  509. mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV;
  510. if (ivtv_set_output_mode(itv, mode) != mode) {
  511. ivtv_release_stream(s);
  512. return -EBUSY;
  513. }
  514. ivtv_queue_init(&q);
  515. set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  516. /* Start decoder (returns 0 if already started) */
  517. mutex_lock(&itv->serialize_lock);
  518. rc = ivtv_start_decoding(id, itv->speed);
  519. mutex_unlock(&itv->serialize_lock);
  520. if (rc) {
  521. IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name);
  522. /* failure, clean up */
  523. clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
  524. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  525. return rc;
  526. }
  527. retry:
  528. /* If possible, just DMA the entire frame - Check the data transfer size
  529. since we may get here before the stream has been fully set-up */
  530. if (mode == OUT_YUV && s->q_full.length == 0 && itv->dma_data_req_size) {
  531. while (count >= itv->dma_data_req_size) {
  532. if (!ivtv_yuv_udma_stream_frame (itv, (void __user *)user_buf)) {
  533. bytes_written += itv->dma_data_req_size;
  534. user_buf += itv->dma_data_req_size;
  535. count -= itv->dma_data_req_size;
  536. } else {
  537. break;
  538. }
  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 = 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. poll_wait(filp, &s->waitq, wait);
  639. set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
  640. if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) ||
  641. test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
  642. res = POLLPRI;
  643. /* Allow write if buffers are available for writing */
  644. if (s->q_free.buffers)
  645. res |= POLLOUT | POLLWRNORM;
  646. return res;
  647. }
  648. unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
  649. {
  650. struct ivtv_open_id *id = filp->private_data;
  651. struct ivtv *itv = id->itv;
  652. struct ivtv_stream *s = &itv->streams[id->type];
  653. int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  654. /* Start a capture if there is none */
  655. if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  656. int rc;
  657. mutex_lock(&itv->serialize_lock);
  658. rc = ivtv_start_capture(id);
  659. mutex_unlock(&itv->serialize_lock);
  660. if (rc) {
  661. IVTV_DEBUG_INFO("Could not start capture for %s (%d)\n",
  662. s->name, rc);
  663. return POLLERR;
  664. }
  665. IVTV_DEBUG_FILE("Encoder poll started capture\n");
  666. }
  667. /* add stream's waitq to the poll list */
  668. IVTV_DEBUG_HI_FILE("Encoder poll\n");
  669. poll_wait(filp, &s->waitq, wait);
  670. if (s->q_full.length || s->q_io.length)
  671. return POLLIN | POLLRDNORM;
  672. if (eof)
  673. return POLLHUP;
  674. return 0;
  675. }
  676. void ivtv_stop_capture(struct ivtv_open_id *id, int gop_end)
  677. {
  678. struct ivtv *itv = id->itv;
  679. struct ivtv_stream *s = &itv->streams[id->type];
  680. IVTV_DEBUG_FILE("close() of %s\n", s->name);
  681. /* 'Unclaim' this stream */
  682. /* Stop capturing */
  683. if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  684. struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
  685. IVTV_DEBUG_INFO("close stopping capture\n");
  686. /* Special case: a running VBI capture for VBI insertion
  687. in the mpeg stream. Need to stop that too. */
  688. if (id->type == IVTV_ENC_STREAM_TYPE_MPG &&
  689. test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags) &&
  690. !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) {
  691. IVTV_DEBUG_INFO("close stopping embedded VBI capture\n");
  692. ivtv_stop_v4l2_encode_stream(s_vbi, 0);
  693. }
  694. if ((id->type == IVTV_DEC_STREAM_TYPE_VBI ||
  695. id->type == IVTV_ENC_STREAM_TYPE_VBI) &&
  696. test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) {
  697. /* Also used internally, don't stop capturing */
  698. s->id = -1;
  699. }
  700. else {
  701. ivtv_stop_v4l2_encode_stream(s, gop_end);
  702. }
  703. }
  704. if (!gop_end) {
  705. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  706. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  707. ivtv_release_stream(s);
  708. }
  709. }
  710. static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
  711. {
  712. struct ivtv *itv = id->itv;
  713. struct ivtv_stream *s = &itv->streams[id->type];
  714. IVTV_DEBUG_FILE("close() of %s\n", s->name);
  715. /* Stop decoding */
  716. if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
  717. IVTV_DEBUG_INFO("close stopping decode\n");
  718. ivtv_stop_v4l2_decode_stream(s, flags, pts);
  719. itv->output_mode = OUT_NONE;
  720. }
  721. clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
  722. clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
  723. if (id->type == IVTV_DEC_STREAM_TYPE_YUV && test_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags)) {
  724. /* Restore registers we've changed & clean up any mess we've made */
  725. ivtv_yuv_close(itv);
  726. }
  727. if (itv->output_mode == OUT_UDMA_YUV && id->yuv_frames)
  728. itv->output_mode = OUT_NONE;
  729. itv->speed = 0;
  730. clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags);
  731. ivtv_release_stream(s);
  732. }
  733. int ivtv_v4l2_close(struct inode *inode, struct file *filp)
  734. {
  735. struct ivtv_open_id *id = filp->private_data;
  736. struct ivtv *itv = id->itv;
  737. struct ivtv_stream *s = &itv->streams[id->type];
  738. IVTV_DEBUG_FILE("close %s\n", s->name);
  739. v4l2_prio_close(&itv->prio, &id->prio);
  740. /* Easy case first: this stream was never claimed by us */
  741. if (s->id != id->open_id) {
  742. kfree(id);
  743. return 0;
  744. }
  745. /* 'Unclaim' this stream */
  746. /* Stop radio */
  747. mutex_lock(&itv->serialize_lock);
  748. if (id->type == IVTV_ENC_STREAM_TYPE_RAD) {
  749. /* Closing radio device, return to TV mode */
  750. ivtv_mute(itv);
  751. /* Mark that the radio is no longer in use */
  752. clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
  753. /* Switch tuner to TV */
  754. ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std);
  755. /* Select correct audio input (i.e. TV tuner or Line in) */
  756. ivtv_audio_set_io(itv);
  757. if (itv->hw_flags & IVTV_HW_SAA711X)
  758. {
  759. struct v4l2_crystal_freq crystal_freq;
  760. crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
  761. crystal_freq.flags = 0;
  762. ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq);
  763. }
  764. if (atomic_read(&itv->capturing) > 0) {
  765. /* Undo video mute */
  766. ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
  767. itv->params.video_mute | (itv->params.video_mute_yuv << 8));
  768. }
  769. /* Done! Unmute and continue. */
  770. ivtv_unmute(itv);
  771. ivtv_release_stream(s);
  772. } else if (s->type >= IVTV_DEC_STREAM_TYPE_MPG) {
  773. struct ivtv_stream *s_vout = &itv->streams[IVTV_DEC_STREAM_TYPE_VOUT];
  774. ivtv_stop_decoding(id, VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0);
  775. /* If all output streams are closed, and if the user doesn't have
  776. IVTV_DEC_STREAM_TYPE_VOUT open, then disable CC on TV-out. */
  777. if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) {
  778. /* disable CC on TV-out */
  779. ivtv_disable_cc(itv);
  780. }
  781. } else {
  782. ivtv_stop_capture(id, 0);
  783. }
  784. kfree(id);
  785. mutex_unlock(&itv->serialize_lock);
  786. return 0;
  787. }
  788. static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
  789. {
  790. struct ivtv *itv = s->itv;
  791. struct ivtv_open_id *item;
  792. IVTV_DEBUG_FILE("open %s\n", s->name);
  793. if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
  794. test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
  795. return -EBUSY;
  796. if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
  797. test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags))
  798. return -EBUSY;
  799. if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
  800. if (read_reg(0x82c) == 0) {
  801. IVTV_ERR("Tried to open YUV output device but need to send data to mpeg decoder before it can be used\n");
  802. /* return -ENODEV; */
  803. }
  804. ivtv_udma_alloc(itv);
  805. }
  806. /* Allocate memory */
  807. item = kmalloc(sizeof(struct ivtv_open_id), GFP_KERNEL);
  808. if (NULL == item) {
  809. IVTV_DEBUG_WARN("nomem on v4l2 open\n");
  810. return -ENOMEM;
  811. }
  812. item->itv = itv;
  813. item->type = s->type;
  814. v4l2_prio_open(&itv->prio, &item->prio);
  815. item->open_id = itv->open_id++;
  816. filp->private_data = item;
  817. if (item->type == IVTV_ENC_STREAM_TYPE_RAD) {
  818. /* Try to claim this stream */
  819. if (ivtv_claim_stream(item, item->type)) {
  820. /* No, it's already in use */
  821. kfree(item);
  822. return -EBUSY;
  823. }
  824. if (!test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
  825. if (atomic_read(&itv->capturing) > 0) {
  826. /* switching to radio while capture is
  827. in progress is not polite */
  828. ivtv_release_stream(s);
  829. kfree(item);
  830. return -EBUSY;
  831. }
  832. }
  833. /* Mark that the radio is being used. */
  834. set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
  835. /* We have the radio */
  836. ivtv_mute(itv);
  837. /* Switch tuner to radio */
  838. ivtv_call_i2c_clients(itv, AUDC_SET_RADIO, NULL);
  839. /* Select the correct audio input (i.e. radio tuner) */
  840. ivtv_audio_set_io(itv);
  841. if (itv->hw_flags & IVTV_HW_SAA711X)
  842. {
  843. struct v4l2_crystal_freq crystal_freq;
  844. crystal_freq.freq = SAA7115_FREQ_32_11_MHZ;
  845. crystal_freq.flags = SAA7115_FREQ_FL_APLL;
  846. ivtv_saa7115(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq);
  847. }
  848. /* Done! Unmute and continue. */
  849. ivtv_unmute(itv);
  850. }
  851. /* YUV or MPG Decoding Mode? */
  852. if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
  853. clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
  854. } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
  855. set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
  856. /* For yuv, we need to know the dma size before we start */
  857. itv->dma_data_req_size =
  858. 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
  859. itv->yuv_info.stream_size = 0;
  860. }
  861. return 0;
  862. }
  863. int ivtv_v4l2_open(struct inode *inode, struct file *filp)
  864. {
  865. int res, x, y = 0;
  866. struct ivtv *itv = NULL;
  867. struct ivtv_stream *s = NULL;
  868. int minor = iminor(inode);
  869. /* Find which card this open was on */
  870. spin_lock(&ivtv_cards_lock);
  871. for (x = 0; itv == NULL && x < ivtv_cards_active; x++) {
  872. if (ivtv_cards[x] == NULL)
  873. continue;
  874. /* find out which stream this open was on */
  875. for (y = 0; y < IVTV_MAX_STREAMS; y++) {
  876. s = &ivtv_cards[x]->streams[y];
  877. if (s->v4l2dev && s->v4l2dev->minor == minor) {
  878. itv = ivtv_cards[x];
  879. break;
  880. }
  881. }
  882. }
  883. spin_unlock(&ivtv_cards_lock);
  884. if (itv == NULL) {
  885. /* Couldn't find a device registered
  886. on that minor, shouldn't happen! */
  887. printk(KERN_WARNING "No ivtv device found on minor %d\n", minor);
  888. return -ENXIO;
  889. }
  890. mutex_lock(&itv->serialize_lock);
  891. if (ivtv_init_on_first_open(itv)) {
  892. IVTV_ERR("Failed to initialize on minor %d\n", minor);
  893. mutex_unlock(&itv->serialize_lock);
  894. return -ENXIO;
  895. }
  896. res = ivtv_serialized_open(s, filp);
  897. mutex_unlock(&itv->serialize_lock);
  898. return res;
  899. }
  900. void ivtv_mute(struct ivtv *itv)
  901. {
  902. if (atomic_read(&itv->capturing))
  903. ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 1);
  904. IVTV_DEBUG_INFO("Mute\n");
  905. }
  906. void ivtv_unmute(struct ivtv *itv)
  907. {
  908. if (atomic_read(&itv->capturing)) {
  909. ivtv_msleep_timeout(100, 0);
  910. ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12);
  911. ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 0);
  912. }
  913. IVTV_DEBUG_INFO("Unmute\n");
  914. }