cx18-streams.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. * cx18 init/start/stop/exit stream functions
  3. *
  4. * Derived from ivtv-streams.c
  5. *
  6. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "cx18-driver.h"
  24. #include "cx18-fileops.h"
  25. #include "cx18-mailbox.h"
  26. #include "cx18-i2c.h"
  27. #include "cx18-queue.h"
  28. #include "cx18-ioctl.h"
  29. #include "cx18-streams.h"
  30. #include "cx18-cards.h"
  31. #include "cx18-scb.h"
  32. #include "cx18-av-core.h"
  33. #include "cx18-dvb.h"
  34. #define CX18_DSP0_INTERRUPT_MASK 0xd0004C
  35. static struct file_operations cx18_v4l2_enc_fops = {
  36. .owner = THIS_MODULE,
  37. .read = cx18_v4l2_read,
  38. .open = cx18_v4l2_open,
  39. .ioctl = cx18_v4l2_ioctl,
  40. .release = cx18_v4l2_close,
  41. .poll = cx18_v4l2_enc_poll,
  42. };
  43. /* offset from 0 to register ts v4l2 minors on */
  44. #define CX18_V4L2_ENC_TS_OFFSET 16
  45. /* offset from 0 to register pcm v4l2 minors on */
  46. #define CX18_V4L2_ENC_PCM_OFFSET 24
  47. /* offset from 0 to register yuv v4l2 minors on */
  48. #define CX18_V4L2_ENC_YUV_OFFSET 32
  49. static struct {
  50. const char *name;
  51. int vfl_type;
  52. int minor_offset;
  53. int dma;
  54. enum v4l2_buf_type buf_type;
  55. struct file_operations *fops;
  56. } cx18_stream_info[] = {
  57. { /* CX18_ENC_STREAM_TYPE_MPG */
  58. "encoder MPEG",
  59. VFL_TYPE_GRABBER, 0,
  60. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  61. &cx18_v4l2_enc_fops
  62. },
  63. { /* CX18_ENC_STREAM_TYPE_TS */
  64. "TS",
  65. VFL_TYPE_GRABBER, -1,
  66. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  67. &cx18_v4l2_enc_fops
  68. },
  69. { /* CX18_ENC_STREAM_TYPE_YUV */
  70. "encoder YUV",
  71. VFL_TYPE_GRABBER, CX18_V4L2_ENC_YUV_OFFSET,
  72. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  73. &cx18_v4l2_enc_fops
  74. },
  75. { /* CX18_ENC_STREAM_TYPE_VBI */
  76. "encoder VBI",
  77. VFL_TYPE_VBI, 0,
  78. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VBI_CAPTURE,
  79. &cx18_v4l2_enc_fops
  80. },
  81. { /* CX18_ENC_STREAM_TYPE_PCM */
  82. "encoder PCM audio",
  83. VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET,
  84. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_PRIVATE,
  85. &cx18_v4l2_enc_fops
  86. },
  87. { /* CX18_ENC_STREAM_TYPE_IDX */
  88. "encoder IDX",
  89. VFL_TYPE_GRABBER, -1,
  90. PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE,
  91. &cx18_v4l2_enc_fops
  92. },
  93. { /* CX18_ENC_STREAM_TYPE_RAD */
  94. "encoder radio",
  95. VFL_TYPE_RADIO, 0,
  96. PCI_DMA_NONE, V4L2_BUF_TYPE_PRIVATE,
  97. &cx18_v4l2_enc_fops
  98. },
  99. };
  100. static void cx18_stream_init(struct cx18 *cx, int type)
  101. {
  102. struct cx18_stream *s = &cx->streams[type];
  103. struct video_device *dev = s->v4l2dev;
  104. u32 max_size = cx->options.megabytes[type] * 1024 * 1024;
  105. /* we need to keep v4l2dev, so restore it afterwards */
  106. memset(s, 0, sizeof(*s));
  107. s->v4l2dev = dev;
  108. /* initialize cx18_stream fields */
  109. s->cx = cx;
  110. s->type = type;
  111. s->name = cx18_stream_info[type].name;
  112. s->handle = 0xffffffff;
  113. s->dma = cx18_stream_info[type].dma;
  114. s->buf_size = cx->stream_buf_size[type];
  115. if (s->buf_size)
  116. s->buffers = max_size / s->buf_size;
  117. if (s->buffers > 63) {
  118. /* Each stream has a maximum of 63 buffers,
  119. ensure we do not exceed that. */
  120. s->buffers = 63;
  121. s->buf_size = (max_size / s->buffers) & ~0xfff;
  122. }
  123. spin_lock_init(&s->qlock);
  124. init_waitqueue_head(&s->waitq);
  125. s->id = -1;
  126. cx18_queue_init(&s->q_free);
  127. cx18_queue_init(&s->q_full);
  128. cx18_queue_init(&s->q_io);
  129. }
  130. static int cx18_prep_dev(struct cx18 *cx, int type)
  131. {
  132. struct cx18_stream *s = &cx->streams[type];
  133. u32 cap = cx->v4l2_cap;
  134. int minor_offset = cx18_stream_info[type].minor_offset;
  135. int minor;
  136. /* These four fields are always initialized. If v4l2dev == NULL, then
  137. this stream is not in use. In that case no other fields but these
  138. four can be used. */
  139. s->v4l2dev = NULL;
  140. s->cx = cx;
  141. s->type = type;
  142. s->name = cx18_stream_info[type].name;
  143. /* Check whether the radio is supported */
  144. if (type == CX18_ENC_STREAM_TYPE_RAD && !(cap & V4L2_CAP_RADIO))
  145. return 0;
  146. /* Check whether VBI is supported */
  147. if (type == CX18_ENC_STREAM_TYPE_VBI &&
  148. !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)))
  149. return 0;
  150. /* card number + user defined offset + device offset */
  151. minor = cx->num + cx18_first_minor + minor_offset;
  152. /* User explicitly selected 0 buffers for these streams, so don't
  153. create them. */
  154. if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
  155. cx->options.megabytes[type] == 0) {
  156. CX18_INFO("Disabled %s device\n", cx18_stream_info[type].name);
  157. return 0;
  158. }
  159. cx18_stream_init(cx, type);
  160. if (minor_offset == -1)
  161. return 0;
  162. /* allocate and initialize the v4l2 video device structure */
  163. s->v4l2dev = video_device_alloc();
  164. if (s->v4l2dev == NULL) {
  165. CX18_ERR("Couldn't allocate v4l2 video_device for %s\n",
  166. s->name);
  167. return -ENOMEM;
  168. }
  169. s->v4l2dev->type =
  170. VID_TYPE_CAPTURE | VID_TYPE_TUNER | VID_TYPE_TELETEXT |
  171. VID_TYPE_CLIPPING | VID_TYPE_SCALES | VID_TYPE_MPEG_ENCODER;
  172. snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18%d %s",
  173. cx->num, s->name);
  174. s->v4l2dev->minor = minor;
  175. s->v4l2dev->dev = &cx->dev->dev;
  176. s->v4l2dev->fops = cx18_stream_info[type].fops;
  177. s->v4l2dev->release = video_device_release;
  178. return 0;
  179. }
  180. /* Initialize v4l2 variables and register v4l2 devices */
  181. int cx18_streams_setup(struct cx18 *cx)
  182. {
  183. int type;
  184. /* Setup V4L2 Devices */
  185. for (type = 0; type < CX18_MAX_STREAMS; type++) {
  186. /* Prepare device */
  187. if (cx18_prep_dev(cx, type))
  188. break;
  189. /* Allocate Stream */
  190. if (cx18_stream_alloc(&cx->streams[type]))
  191. break;
  192. }
  193. if (type == CX18_MAX_STREAMS)
  194. return 0;
  195. /* One or more streams could not be initialized. Clean 'em all up. */
  196. cx18_streams_cleanup(cx, 0);
  197. return -ENOMEM;
  198. }
  199. static int cx18_reg_dev(struct cx18 *cx, int type)
  200. {
  201. struct cx18_stream *s = &cx->streams[type];
  202. int vfl_type = cx18_stream_info[type].vfl_type;
  203. int minor;
  204. /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something?
  205. * We need a VFL_TYPE_TS defined.
  206. */
  207. if (strcmp("TS", s->name) == 0) {
  208. /* just return if no DVB is supported */
  209. if ((cx->card->hw_all & CX18_HW_DVB) == 0)
  210. return 0;
  211. if (cx18_dvb_register(s) < 0) {
  212. CX18_ERR("DVB failed to register\n");
  213. return -EINVAL;
  214. }
  215. }
  216. if (s->v4l2dev == NULL)
  217. return 0;
  218. minor = s->v4l2dev->minor;
  219. /* Register device. First try the desired minor, then any free one. */
  220. if (video_register_device(s->v4l2dev, vfl_type, minor) &&
  221. video_register_device(s->v4l2dev, vfl_type, -1)) {
  222. CX18_ERR("Couldn't register v4l2 device for %s minor %d\n",
  223. s->name, minor);
  224. video_device_release(s->v4l2dev);
  225. s->v4l2dev = NULL;
  226. return -ENOMEM;
  227. }
  228. minor = s->v4l2dev->minor;
  229. switch (vfl_type) {
  230. case VFL_TYPE_GRABBER:
  231. CX18_INFO("Registered device video%d for %s (%d MB)\n",
  232. minor, s->name, cx->options.megabytes[type]);
  233. break;
  234. case VFL_TYPE_RADIO:
  235. CX18_INFO("Registered device radio%d for %s\n",
  236. minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
  237. break;
  238. case VFL_TYPE_VBI:
  239. if (cx->options.megabytes[type])
  240. CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
  241. minor - MINOR_VFL_TYPE_VBI_MIN,
  242. s->name, cx->options.megabytes[type]);
  243. else
  244. CX18_INFO("Registered device vbi%d for %s\n",
  245. minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
  246. break;
  247. }
  248. return 0;
  249. }
  250. /* Register v4l2 devices */
  251. int cx18_streams_register(struct cx18 *cx)
  252. {
  253. int type;
  254. int err = 0;
  255. /* Register V4L2 devices */
  256. for (type = 0; type < CX18_MAX_STREAMS; type++)
  257. err |= cx18_reg_dev(cx, type);
  258. if (err == 0)
  259. return 0;
  260. /* One or more streams could not be initialized. Clean 'em all up. */
  261. cx18_streams_cleanup(cx, 1);
  262. return -ENOMEM;
  263. }
  264. /* Unregister v4l2 devices */
  265. void cx18_streams_cleanup(struct cx18 *cx, int unregister)
  266. {
  267. struct video_device *vdev;
  268. int type;
  269. /* Teardown all streams */
  270. for (type = 0; type < CX18_MAX_STREAMS; type++) {
  271. if (cx->streams[type].dvb.enabled)
  272. cx18_dvb_unregister(&cx->streams[type]);
  273. vdev = cx->streams[type].v4l2dev;
  274. cx->streams[type].v4l2dev = NULL;
  275. if (vdev == NULL)
  276. continue;
  277. cx18_stream_free(&cx->streams[type]);
  278. /* Unregister or release device */
  279. if (unregister)
  280. video_unregister_device(vdev);
  281. else
  282. video_device_release(vdev);
  283. }
  284. }
  285. static void cx18_vbi_setup(struct cx18_stream *s)
  286. {
  287. struct cx18 *cx = s->cx;
  288. int raw = cx->vbi.sliced_in->service_set == 0;
  289. u32 data[CX2341X_MBOX_MAX_DATA];
  290. int lines;
  291. if (cx->is_60hz) {
  292. cx->vbi.count = 12;
  293. cx->vbi.start[0] = 10;
  294. cx->vbi.start[1] = 273;
  295. } else { /* PAL/SECAM */
  296. cx->vbi.count = 18;
  297. cx->vbi.start[0] = 6;
  298. cx->vbi.start[1] = 318;
  299. }
  300. /* setup VBI registers */
  301. cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
  302. /* determine number of lines and total number of VBI bytes.
  303. A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
  304. The '- 1' byte is probably an unused U or V byte. Or something...
  305. A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
  306. header, 42 data bytes + checksum (to be confirmed) */
  307. if (raw) {
  308. lines = cx->vbi.count * 2;
  309. } else {
  310. lines = cx->is_60hz ? 24 : 38;
  311. if (cx->is_60hz)
  312. lines += 2;
  313. }
  314. cx->vbi.enc_size = lines *
  315. (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  316. data[0] = s->handle;
  317. /* Lines per field */
  318. data[1] = (lines / 2) | ((lines / 2) << 16);
  319. /* bytes per line */
  320. data[2] = (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  321. /* Every X number of frames a VBI interrupt arrives
  322. (frames as in 25 or 30 fps) */
  323. data[3] = 1;
  324. /* Setup VBI for the cx25840 digitizer */
  325. if (raw) {
  326. data[4] = 0x20602060;
  327. data[5] = 0x30703070;
  328. } else {
  329. data[4] = 0xB0F0B0F0;
  330. data[5] = 0xA0E0A0E0;
  331. }
  332. CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n",
  333. data[0], data[1], data[2], data[3], data[4], data[5]);
  334. if (s->type == CX18_ENC_STREAM_TYPE_VBI)
  335. cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
  336. }
  337. int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
  338. {
  339. u32 data[MAX_MB_ARGUMENTS];
  340. struct cx18 *cx = s->cx;
  341. struct list_head *p;
  342. int ts = 0;
  343. int captype = 0;
  344. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  345. return -EINVAL;
  346. CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
  347. switch (s->type) {
  348. case CX18_ENC_STREAM_TYPE_MPG:
  349. captype = CAPTURE_CHANNEL_TYPE_MPEG;
  350. cx->mpg_data_received = cx->vbi_data_inserted = 0;
  351. cx->dualwatch_jiffies = jiffies;
  352. cx->dualwatch_stereo_mode = cx->params.audio_properties & 0x300;
  353. cx->search_pack_header = 0;
  354. break;
  355. case CX18_ENC_STREAM_TYPE_TS:
  356. captype = CAPTURE_CHANNEL_TYPE_TS;
  357. ts = 1;
  358. break;
  359. case CX18_ENC_STREAM_TYPE_YUV:
  360. captype = CAPTURE_CHANNEL_TYPE_YUV;
  361. break;
  362. case CX18_ENC_STREAM_TYPE_PCM:
  363. captype = CAPTURE_CHANNEL_TYPE_PCM;
  364. break;
  365. case CX18_ENC_STREAM_TYPE_VBI:
  366. captype = cx->vbi.sliced_in->service_set ?
  367. CAPTURE_CHANNEL_TYPE_SLICED_VBI : CAPTURE_CHANNEL_TYPE_VBI;
  368. cx->vbi.frame = 0;
  369. cx->vbi.inserted_frame = 0;
  370. memset(cx->vbi.sliced_mpeg_size,
  371. 0, sizeof(cx->vbi.sliced_mpeg_size));
  372. break;
  373. default:
  374. return -EINVAL;
  375. }
  376. s->buffers_stolen = 0;
  377. /* mute/unmute video */
  378. cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
  379. s->handle, !!test_bit(CX18_F_I_RADIO_USER, &cx->i_flags));
  380. /* Clear Streamoff flags in case left from last capture */
  381. clear_bit(CX18_F_S_STREAMOFF, &s->s_flags);
  382. cx18_vapi_result(cx, data, CX18_CREATE_TASK, 1, CPU_CMD_MASK_CAPTURE);
  383. s->handle = data[0];
  384. cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype);
  385. if (atomic_read(&cx->capturing) == 0 && !ts) {
  386. /* Stuff from Windows, we don't know what it is */
  387. cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0);
  388. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1);
  389. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0);
  390. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1);
  391. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, s->handle, 12);
  392. cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3,
  393. s->handle, cx->digitizer, cx->digitizer);
  394. /* Setup VBI */
  395. if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE)
  396. cx18_vbi_setup(s);
  397. /* assign program index info.
  398. Mask 7: select I/P/B, Num_req: 400 max */
  399. cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0);
  400. /* Setup API for Stream */
  401. cx2341x_update(cx, cx18_api_func, NULL, &cx->params);
  402. }
  403. if (atomic_read(&cx->capturing) == 0) {
  404. clear_bit(CX18_F_I_EOS, &cx->i_flags);
  405. write_reg(7, CX18_DSP0_INTERRUPT_MASK);
  406. }
  407. cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
  408. (void *)&cx->scb->cpu_mdl_ack[s->type][0] - cx->enc_mem,
  409. (void *)&cx->scb->cpu_mdl_ack[s->type][1] - cx->enc_mem);
  410. list_for_each(p, &s->q_free.list) {
  411. struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
  412. writel(buf->dma_handle, &cx->scb->cpu_mdl[buf->id].paddr);
  413. writel(s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
  414. cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
  415. (void *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem, 1,
  416. buf->id, s->buf_size);
  417. }
  418. /* begin_capture */
  419. if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
  420. CX18_DEBUG_WARN("Error starting capture!\n");
  421. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  422. return -EINVAL;
  423. }
  424. /* you're live! sit back and await interrupts :) */
  425. atomic_inc(&cx->capturing);
  426. return 0;
  427. }
  428. void cx18_stop_all_captures(struct cx18 *cx)
  429. {
  430. int i;
  431. for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
  432. struct cx18_stream *s = &cx->streams[i];
  433. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  434. continue;
  435. if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
  436. cx18_stop_v4l2_encode_stream(s, 0);
  437. }
  438. }
  439. int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
  440. {
  441. struct cx18 *cx = s->cx;
  442. unsigned long then;
  443. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  444. return -EINVAL;
  445. /* This function assumes that you are allowed to stop the capture
  446. and that we are actually capturing */
  447. CX18_DEBUG_INFO("Stop Capture\n");
  448. if (atomic_read(&cx->capturing) == 0)
  449. return 0;
  450. if (s->type == CX18_ENC_STREAM_TYPE_MPG)
  451. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, !gop_end);
  452. else
  453. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
  454. then = jiffies;
  455. if (s->type == CX18_ENC_STREAM_TYPE_MPG && gop_end) {
  456. CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
  457. }
  458. atomic_dec(&cx->capturing);
  459. /* Clear capture and no-read bits */
  460. clear_bit(CX18_F_S_STREAMING, &s->s_flags);
  461. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  462. s->handle = 0xffffffff;
  463. if (atomic_read(&cx->capturing) > 0)
  464. return 0;
  465. write_reg(5, CX18_DSP0_INTERRUPT_MASK);
  466. wake_up(&s->waitq);
  467. return 0;
  468. }
  469. u32 cx18_find_handle(struct cx18 *cx)
  470. {
  471. int i;
  472. /* find first available handle to be used for global settings */
  473. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  474. struct cx18_stream *s = &cx->streams[i];
  475. if (s->v4l2dev && s->handle)
  476. return s->handle;
  477. }
  478. return 0;
  479. }