ivtv-vbi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. Vertical Blank Interval support functions
  3. Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include "ivtv-driver.h"
  17. #include "ivtv-i2c.h"
  18. #include "ivtv-ioctl.h"
  19. #include "ivtv-queue.h"
  20. #include "ivtv-vbi.h"
  21. static void ivtv_set_vps(struct ivtv *itv, int enabled, u8 vps1, u8 vps2, u8 vps3,
  22. u8 vps4, u8 vps5)
  23. {
  24. struct v4l2_sliced_vbi_data data;
  25. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  26. return;
  27. data.id = V4L2_SLICED_VPS;
  28. data.field = 0;
  29. data.line = enabled ? 16 : 0;
  30. data.data[4] = vps1;
  31. data.data[10] = vps2;
  32. data.data[11] = vps3;
  33. data.data[12] = vps4;
  34. data.data[13] = vps5;
  35. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  36. }
  37. static void ivtv_set_cc(struct ivtv *itv, int mode, u8 cc1, u8 cc2, u8 cc3, u8 cc4)
  38. {
  39. struct v4l2_sliced_vbi_data data;
  40. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  41. return;
  42. data.id = V4L2_SLICED_CAPTION_525;
  43. data.field = 0;
  44. data.line = (mode & 1) ? 21 : 0;
  45. data.data[0] = cc1;
  46. data.data[1] = cc2;
  47. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  48. data.field = 1;
  49. data.line = (mode & 2) ? 21 : 0;
  50. data.data[0] = cc3;
  51. data.data[1] = cc4;
  52. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  53. }
  54. static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
  55. {
  56. struct v4l2_sliced_vbi_data data;
  57. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  58. return;
  59. /* When using a 50 Hz system, always turn on the
  60. wide screen signal with 4x3 ratio as the default.
  61. Turning this signal on and off can confuse certain
  62. TVs. As far as I can tell there is no reason not to
  63. transmit this signal. */
  64. if ((itv->std & V4L2_STD_625_50) && !enabled) {
  65. enabled = 1;
  66. mode = 0x08; /* 4x3 full format */
  67. }
  68. data.id = V4L2_SLICED_WSS_625;
  69. data.field = 0;
  70. data.line = enabled ? 23 : 0;
  71. data.data[0] = mode & 0xff;
  72. data.data[1] = (mode >> 8) & 0xff;
  73. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  74. }
  75. static int odd_parity(u8 c)
  76. {
  77. c ^= (c >> 4);
  78. c ^= (c >> 2);
  79. c ^= (c >> 1);
  80. return c & 1;
  81. }
  82. static void passthrough_vbi_data(struct ivtv *itv, int cnt)
  83. {
  84. int wss = 0;
  85. u8 cc[4] = { 0x80, 0x80, 0x80, 0x80 };
  86. u8 vps[13];
  87. int found_cc = 0;
  88. int found_wss = 0;
  89. int found_vps = 0;
  90. int cc_pos = itv->vbi.cc_pos;
  91. int i;
  92. for (i = 0; i < cnt; i++) {
  93. struct v4l2_sliced_vbi_data *d = itv->vbi.sliced_dec_data + i;
  94. if (d->id == V4L2_SLICED_CAPTION_525 && d->line == 21) {
  95. found_cc = 1;
  96. if (d->field) {
  97. cc[2] = d->data[0];
  98. cc[3] = d->data[1];
  99. } else {
  100. cc[0] = d->data[0];
  101. cc[1] = d->data[1];
  102. }
  103. }
  104. else if (d->id == V4L2_SLICED_VPS && d->line == 16 && d->field == 0) {
  105. memcpy(vps, d->data, sizeof(vps));
  106. found_vps = 1;
  107. }
  108. else if (d->id == V4L2_SLICED_WSS_625 && d->line == 23 && d->field == 0) {
  109. wss = d->data[0] | d->data[1] << 8;
  110. found_wss = 1;
  111. }
  112. }
  113. if (itv->vbi.wss_found != found_wss || itv->vbi.wss != wss) {
  114. itv->vbi.wss = wss;
  115. itv->vbi.wss_found = found_wss;
  116. set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
  117. }
  118. if (found_vps || itv->vbi.vps_found) {
  119. itv->vbi.vps[0] = vps[2];
  120. itv->vbi.vps[1] = vps[8];
  121. itv->vbi.vps[2] = vps[9];
  122. itv->vbi.vps[3] = vps[10];
  123. itv->vbi.vps[4] = vps[11];
  124. itv->vbi.vps_found = found_vps;
  125. set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
  126. }
  127. if (found_cc && cc_pos < sizeof(itv->vbi.cc_data_even)) {
  128. itv->vbi.cc_data_odd[cc_pos] = cc[0];
  129. itv->vbi.cc_data_odd[cc_pos + 1] = cc[1];
  130. itv->vbi.cc_data_even[cc_pos] = cc[2];
  131. itv->vbi.cc_data_even[cc_pos + 1] = cc[3];
  132. itv->vbi.cc_pos = cc_pos + 2;
  133. set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
  134. }
  135. }
  136. static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp)
  137. {
  138. int line = 0;
  139. int i;
  140. u32 linemask[2] = { 0, 0 };
  141. unsigned short size;
  142. static const u8 mpeg_hdr_data[] = {
  143. 0x00, 0x00, 0x01, 0xba, 0x44, 0x00, 0x0c, 0x66,
  144. 0x24, 0x01, 0x01, 0xd1, 0xd3, 0xfa, 0xff, 0xff,
  145. 0x00, 0x00, 0x01, 0xbd, 0x00, 0x1a, 0x84, 0x80,
  146. 0x07, 0x21, 0x00, 0x5d, 0x63, 0xa7, 0xff, 0xff
  147. };
  148. const int sd = sizeof(mpeg_hdr_data); /* start of vbi data */
  149. int idx = itv->vbi.frame % IVTV_VBI_FRAMES;
  150. u8 *dst = &itv->vbi.sliced_mpeg_data[idx][0];
  151. for (i = 0; i < lines; i++) {
  152. int f, l;
  153. if (itv->vbi.sliced_data[i].id == 0)
  154. continue;
  155. l = itv->vbi.sliced_data[i].line - 6;
  156. f = itv->vbi.sliced_data[i].field;
  157. if (f)
  158. l += 18;
  159. if (l < 32)
  160. linemask[0] |= (1 << l);
  161. else
  162. linemask[1] |= (1 << (l - 32));
  163. dst[sd + 12 + line * 43] = service2vbi(itv->vbi.sliced_data[i].id);
  164. memcpy(dst + sd + 12 + line * 43 + 1, itv->vbi.sliced_data[i].data, 42);
  165. line++;
  166. }
  167. memcpy(dst, mpeg_hdr_data, sizeof(mpeg_hdr_data));
  168. if (line == 36) {
  169. /* All lines are used, so there is no space for the linemask
  170. (the max size of the VBI data is 36 * 43 + 4 bytes).
  171. So in this case we use the magic number 'ITV0'. */
  172. memcpy(dst + sd, "ITV0", 4);
  173. memcpy(dst + sd + 4, dst + sd + 12, line * 43);
  174. size = 4 + ((43 * line + 3) & ~3);
  175. } else {
  176. memcpy(dst + sd, "itv0", 4);
  177. memcpy(dst + sd + 4, &linemask[0], 8);
  178. size = 12 + ((43 * line + 3) & ~3);
  179. }
  180. dst[4+16] = (size + 10) >> 8;
  181. dst[5+16] = (size + 10) & 0xff;
  182. dst[9+16] = 0x21 | ((pts_stamp >> 29) & 0x6);
  183. dst[10+16] = (pts_stamp >> 22) & 0xff;
  184. dst[11+16] = 1 | ((pts_stamp >> 14) & 0xff);
  185. dst[12+16] = (pts_stamp >> 7) & 0xff;
  186. dst[13+16] = 1 | ((pts_stamp & 0x7f) << 1);
  187. itv->vbi.sliced_mpeg_size[idx] = sd + size;
  188. }
  189. static int ivtv_convert_ivtv_vbi(struct ivtv *itv, u8 *p)
  190. {
  191. u32 linemask[2];
  192. int i, l, id2;
  193. int line = 0;
  194. if (!memcmp(p, "itv0", 4)) {
  195. memcpy(linemask, p + 4, 8);
  196. p += 12;
  197. } else if (!memcmp(p, "ITV0", 4)) {
  198. linemask[0] = 0xffffffff;
  199. linemask[1] = 0xf;
  200. p += 4;
  201. } else {
  202. /* unknown VBI data, convert to empty VBI frame */
  203. linemask[0] = linemask[1] = 0;
  204. }
  205. for (i = 0; i < 36; i++) {
  206. int err = 0;
  207. if (i < 32 && !(linemask[0] & (1 << i)))
  208. continue;
  209. if (i >= 32 && !(linemask[1] & (1 << (i - 32))))
  210. continue;
  211. id2 = *p & 0xf;
  212. switch (id2) {
  213. case IVTV_SLICED_TYPE_TELETEXT_B:
  214. id2 = V4L2_SLICED_TELETEXT_B;
  215. break;
  216. case IVTV_SLICED_TYPE_CAPTION_525:
  217. id2 = V4L2_SLICED_CAPTION_525;
  218. err = !odd_parity(p[1]) || !odd_parity(p[2]);
  219. break;
  220. case IVTV_SLICED_TYPE_VPS:
  221. id2 = V4L2_SLICED_VPS;
  222. break;
  223. case IVTV_SLICED_TYPE_WSS_625:
  224. id2 = V4L2_SLICED_WSS_625;
  225. break;
  226. default:
  227. id2 = 0;
  228. break;
  229. }
  230. if (err == 0) {
  231. l = (i < 18) ? i + 6 : i - 18 + 6;
  232. itv->vbi.sliced_dec_data[line].line = l;
  233. itv->vbi.sliced_dec_data[line].field = i >= 18;
  234. itv->vbi.sliced_dec_data[line].id = id2;
  235. memcpy(itv->vbi.sliced_dec_data[line].data, p + 1, 42);
  236. line++;
  237. }
  238. p += 43;
  239. }
  240. while (line < 36) {
  241. itv->vbi.sliced_dec_data[line].id = 0;
  242. itv->vbi.sliced_dec_data[line].line = 0;
  243. itv->vbi.sliced_dec_data[line].field = 0;
  244. line++;
  245. }
  246. return line * sizeof(itv->vbi.sliced_dec_data[0]);
  247. }
  248. ssize_t ivtv_write_vbi(struct ivtv *itv, const char __user *ubuf, size_t count)
  249. {
  250. /* Should be a __user pointer, but sparse doesn't parse this bit correctly. */
  251. const struct v4l2_sliced_vbi_data *p = (const struct v4l2_sliced_vbi_data *)ubuf;
  252. u8 cc[4] = { 0x80, 0x80, 0x80, 0x80 };
  253. int found_cc = 0;
  254. int cc_pos = itv->vbi.cc_pos;
  255. while (count >= sizeof(struct v4l2_sliced_vbi_data)) {
  256. switch (p->id) {
  257. case V4L2_SLICED_CAPTION_525:
  258. if (p->line == 21) {
  259. found_cc = 1;
  260. if (p->field) {
  261. cc[2] = p->data[0];
  262. cc[3] = p->data[1];
  263. } else {
  264. cc[0] = p->data[0];
  265. cc[1] = p->data[1];
  266. }
  267. }
  268. break;
  269. case V4L2_SLICED_VPS:
  270. if (p->line == 16 && p->field == 0) {
  271. itv->vbi.vps[0] = p->data[2];
  272. itv->vbi.vps[1] = p->data[8];
  273. itv->vbi.vps[2] = p->data[9];
  274. itv->vbi.vps[3] = p->data[10];
  275. itv->vbi.vps[4] = p->data[11];
  276. itv->vbi.vps_found = 1;
  277. set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
  278. }
  279. break;
  280. case V4L2_SLICED_WSS_625:
  281. if (p->line == 23 && p->field == 0) {
  282. /* No lock needed for WSS */
  283. itv->vbi.wss = p->data[0] | (p->data[1] << 8);
  284. itv->vbi.wss_found = 1;
  285. set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
  286. }
  287. break;
  288. default:
  289. break;
  290. }
  291. count -= sizeof(*p);
  292. p++;
  293. }
  294. if (found_cc && cc_pos < sizeof(itv->vbi.cc_data_even)) {
  295. itv->vbi.cc_data_odd[cc_pos] = cc[0];
  296. itv->vbi.cc_data_odd[cc_pos + 1] = cc[1];
  297. itv->vbi.cc_data_even[cc_pos] = cc[2];
  298. itv->vbi.cc_data_even[cc_pos + 1] = cc[3];
  299. itv->vbi.cc_pos = cc_pos + 2;
  300. set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
  301. }
  302. return (const char __user *)p - ubuf;
  303. }
  304. /* Compress raw VBI format, removes leading SAV codes and surplus space after the
  305. field.
  306. Returns new compressed size. */
  307. static u32 compress_raw_buf(struct ivtv *itv, u8 *buf, u32 size)
  308. {
  309. u32 line_size = itv->vbi.raw_decoder_line_size;
  310. u32 lines = itv->vbi.count;
  311. u8 sav1 = itv->vbi.raw_decoder_sav_odd_field;
  312. u8 sav2 = itv->vbi.raw_decoder_sav_even_field;
  313. u8 *q = buf;
  314. u8 *p;
  315. int i;
  316. for (i = 0; i < lines; i++) {
  317. p = buf + i * line_size;
  318. /* Look for SAV code */
  319. if (p[0] != 0xff || p[1] || p[2] || (p[3] != sav1 && p[3] != sav2)) {
  320. break;
  321. }
  322. memcpy(q, p + 4, line_size - 4);
  323. q += line_size - 4;
  324. }
  325. return lines * (line_size - 4);
  326. }
  327. /* Compressed VBI format, all found sliced blocks put next to one another
  328. Returns new compressed size */
  329. static u32 compress_sliced_buf(struct ivtv *itv, u32 line, u8 *buf, u32 size, u8 sav)
  330. {
  331. u32 line_size = itv->vbi.sliced_decoder_line_size;
  332. struct v4l2_decode_vbi_line vbi;
  333. int i;
  334. /* find the first valid line */
  335. for (i = 0; i < size; i++, buf++) {
  336. if (buf[0] == 0xff && !buf[1] && !buf[2] && buf[3] == sav)
  337. break;
  338. }
  339. size -= i;
  340. if (size < line_size) {
  341. return line;
  342. }
  343. for (i = 0; i < size / line_size; i++) {
  344. u8 *p = buf + i * line_size;
  345. /* Look for SAV code */
  346. if (p[0] != 0xff || p[1] || p[2] || p[3] != sav) {
  347. continue;
  348. }
  349. vbi.p = p + 4;
  350. itv->video_dec_func(itv, VIDIOC_INT_DECODE_VBI_LINE, &vbi);
  351. if (vbi.type) {
  352. itv->vbi.sliced_data[line].id = vbi.type;
  353. itv->vbi.sliced_data[line].field = vbi.is_second_field;
  354. itv->vbi.sliced_data[line].line = vbi.line;
  355. memcpy(itv->vbi.sliced_data[line].data, vbi.p, 42);
  356. line++;
  357. }
  358. }
  359. return line;
  360. }
  361. void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
  362. u64 pts_stamp, int streamtype)
  363. {
  364. u8 *p = (u8 *) buf->buf;
  365. u32 size = buf->bytesused;
  366. int y;
  367. /* Raw VBI data */
  368. if (streamtype == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set == 0) {
  369. u8 type;
  370. ivtv_buf_swap(buf);
  371. type = p[3];
  372. size = buf->bytesused = compress_raw_buf(itv, p, size);
  373. /* second field of the frame? */
  374. if (type == itv->vbi.raw_decoder_sav_even_field) {
  375. /* Dirty hack needed for backwards
  376. compatibility of old VBI software. */
  377. p += size - 4;
  378. memcpy(p, &itv->vbi.frame, 4);
  379. itv->vbi.frame++;
  380. }
  381. return;
  382. }
  383. /* Sliced VBI data with data insertion */
  384. if (streamtype == IVTV_ENC_STREAM_TYPE_VBI) {
  385. int lines;
  386. ivtv_buf_swap(buf);
  387. /* first field */
  388. lines = compress_sliced_buf(itv, 0, p, size / 2,
  389. itv->vbi.sliced_decoder_sav_odd_field);
  390. /* second field */
  391. /* experimentation shows that the second half does not always begin
  392. at the exact address. So start a bit earlier (hence 32). */
  393. lines = compress_sliced_buf(itv, lines, p + size / 2 - 32, size / 2 + 32,
  394. itv->vbi.sliced_decoder_sav_even_field);
  395. /* always return at least one empty line */
  396. if (lines == 0) {
  397. itv->vbi.sliced_data[0].id = 0;
  398. itv->vbi.sliced_data[0].line = 0;
  399. itv->vbi.sliced_data[0].field = 0;
  400. lines = 1;
  401. }
  402. buf->bytesused = size = lines * sizeof(itv->vbi.sliced_data[0]);
  403. memcpy(p, &itv->vbi.sliced_data[0], size);
  404. if (itv->vbi.insert_mpeg) {
  405. copy_vbi_data(itv, lines, pts_stamp);
  406. }
  407. itv->vbi.frame++;
  408. return;
  409. }
  410. /* Sliced VBI re-inserted from an MPEG stream */
  411. if (streamtype == IVTV_DEC_STREAM_TYPE_VBI) {
  412. /* If the size is not 4-byte aligned, then the starting address
  413. for the swapping is also shifted. After swapping the data the
  414. real start address of the VBI data is exactly 4 bytes after the
  415. original start. It's a bit fiddly but it works like a charm.
  416. Non-4-byte alignment happens when an lseek is done on the input
  417. mpeg file to a non-4-byte aligned position. So on arrival here
  418. the VBI data is also non-4-byte aligned. */
  419. int offset = size & 3;
  420. int cnt;
  421. if (offset) {
  422. p += 4 - offset;
  423. }
  424. /* Swap Buffer */
  425. for (y = 0; y < size; y += 4) {
  426. swab32s((u32 *)(p + y));
  427. }
  428. cnt = ivtv_convert_ivtv_vbi(itv, p + offset);
  429. memcpy(buf->buf, itv->vbi.sliced_dec_data, cnt);
  430. buf->bytesused = cnt;
  431. passthrough_vbi_data(itv, cnt / sizeof(itv->vbi.sliced_dec_data[0]));
  432. return;
  433. }
  434. }
  435. void ivtv_disable_vbi(struct ivtv *itv)
  436. {
  437. clear_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
  438. clear_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
  439. clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
  440. ivtv_set_wss(itv, 0, 0);
  441. ivtv_set_cc(itv, 0, 0, 0, 0, 0);
  442. ivtv_set_vps(itv, 0, 0, 0, 0, 0, 0);
  443. itv->vbi.vps_found = itv->vbi.wss_found = 0;
  444. itv->vbi.wss = 0;
  445. itv->vbi.cc_pos = 0;
  446. }
  447. void ivtv_vbi_work_handler(struct ivtv *itv)
  448. {
  449. struct v4l2_sliced_vbi_data data;
  450. /* Lock */
  451. if (itv->output_mode == OUT_PASSTHROUGH) {
  452. /* Note: currently only the saa7115 is used in a PVR350,
  453. so these commands are for now saa7115 specific. */
  454. if (itv->is_50hz) {
  455. data.id = V4L2_SLICED_WSS_625;
  456. data.field = 0;
  457. if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
  458. ivtv_set_wss(itv, 1, data.data[0] & 0xf);
  459. itv->vbi.wss_no_update = 0;
  460. } else if (itv->vbi.wss_no_update == 4) {
  461. ivtv_set_wss(itv, 1, 0x8); /* 4x3 full format */
  462. } else {
  463. itv->vbi.wss_no_update++;
  464. }
  465. }
  466. else {
  467. u8 c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  468. int mode = 0;
  469. data.id = V4L2_SLICED_CAPTION_525;
  470. data.field = 0;
  471. if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
  472. mode |= 1;
  473. c1 = data.data[0];
  474. c2 = data.data[1];
  475. }
  476. data.field = 1;
  477. if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
  478. mode |= 2;
  479. c3 = data.data[0];
  480. c4 = data.data[1];
  481. }
  482. if (mode) {
  483. itv->vbi.cc_no_update = 0;
  484. ivtv_set_cc(itv, mode, c1, c2, c3, c4);
  485. } else if (itv->vbi.cc_no_update == 4) {
  486. ivtv_set_cc(itv, 0, 0, 0, 0, 0);
  487. } else {
  488. itv->vbi.cc_no_update++;
  489. }
  490. }
  491. return;
  492. }
  493. if (test_and_clear_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags)) {
  494. /* Lock */
  495. ivtv_set_wss(itv, itv->vbi.wss_found, itv->vbi.wss & 0xf);
  496. }
  497. if (test_and_clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags)) {
  498. if (itv->vbi.cc_pos == 0) {
  499. ivtv_set_cc(itv, 3, 0x80, 0x80, 0x80, 0x80);
  500. }
  501. while (itv->vbi.cc_pos) {
  502. u8 cc_odd0 = itv->vbi.cc_data_odd[0];
  503. u8 cc_odd1 = itv->vbi.cc_data_odd[1];
  504. u8 cc_even0 = itv->vbi.cc_data_even[0];
  505. u8 cc_even1 = itv->vbi.cc_data_even[1];
  506. memcpy(itv->vbi.cc_data_odd, itv->vbi.cc_data_odd + 2, sizeof(itv->vbi.cc_data_odd) - 2);
  507. memcpy(itv->vbi.cc_data_even, itv->vbi.cc_data_even + 2, sizeof(itv->vbi.cc_data_even) - 2);
  508. itv->vbi.cc_pos -= 2;
  509. if (itv->vbi.cc_pos && cc_odd0 == 0x80 && cc_odd1 == 0x80)
  510. continue;
  511. /* Send to Saa7127 */
  512. ivtv_set_cc(itv, 3, cc_odd0, cc_odd1, cc_even0, cc_even1);
  513. if (itv->vbi.cc_pos == 0)
  514. set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
  515. break;
  516. }
  517. }
  518. if (test_and_clear_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags)) {
  519. /* Lock */
  520. ivtv_set_vps(itv, itv->vbi.vps_found,
  521. itv->vbi.vps[0], itv->vbi.vps[1],
  522. itv->vbi.vps[2], itv->vbi.vps[3], itv->vbi.vps[4]);
  523. }
  524. }