cx18-streams.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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);
  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);
  262. return -ENOMEM;
  263. }
  264. /* Unregister v4l2 devices */
  265. void cx18_streams_cleanup(struct cx18 *cx)
  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 device */
  279. video_unregister_device(vdev);
  280. }
  281. }
  282. static void cx18_vbi_setup(struct cx18_stream *s)
  283. {
  284. struct cx18 *cx = s->cx;
  285. int raw = cx->vbi.sliced_in->service_set == 0;
  286. u32 data[CX2341X_MBOX_MAX_DATA];
  287. int lines;
  288. if (cx->is_60hz) {
  289. cx->vbi.count = 12;
  290. cx->vbi.start[0] = 10;
  291. cx->vbi.start[1] = 273;
  292. } else { /* PAL/SECAM */
  293. cx->vbi.count = 18;
  294. cx->vbi.start[0] = 6;
  295. cx->vbi.start[1] = 318;
  296. }
  297. /* setup VBI registers */
  298. cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in);
  299. /* determine number of lines and total number of VBI bytes.
  300. A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
  301. The '- 1' byte is probably an unused U or V byte. Or something...
  302. A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal
  303. header, 42 data bytes + checksum (to be confirmed) */
  304. if (raw) {
  305. lines = cx->vbi.count * 2;
  306. } else {
  307. lines = cx->is_60hz ? 24 : 38;
  308. if (cx->is_60hz)
  309. lines += 2;
  310. }
  311. cx->vbi.enc_size = lines *
  312. (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  313. data[0] = s->handle;
  314. /* Lines per field */
  315. data[1] = (lines / 2) | ((lines / 2) << 16);
  316. /* bytes per line */
  317. data[2] = (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
  318. /* Every X number of frames a VBI interrupt arrives
  319. (frames as in 25 or 30 fps) */
  320. data[3] = 1;
  321. /* Setup VBI for the cx25840 digitizer */
  322. if (raw) {
  323. data[4] = 0x20602060;
  324. data[5] = 0x30703070;
  325. } else {
  326. data[4] = 0xB0F0B0F0;
  327. data[5] = 0xA0E0A0E0;
  328. }
  329. CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n",
  330. data[0], data[1], data[2], data[3], data[4], data[5]);
  331. if (s->type == CX18_ENC_STREAM_TYPE_VBI)
  332. cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
  333. }
  334. int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
  335. {
  336. u32 data[MAX_MB_ARGUMENTS];
  337. struct cx18 *cx = s->cx;
  338. struct list_head *p;
  339. int ts = 0;
  340. int captype = 0;
  341. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  342. return -EINVAL;
  343. CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
  344. switch (s->type) {
  345. case CX18_ENC_STREAM_TYPE_MPG:
  346. captype = CAPTURE_CHANNEL_TYPE_MPEG;
  347. cx->mpg_data_received = cx->vbi_data_inserted = 0;
  348. cx->dualwatch_jiffies = jiffies;
  349. cx->dualwatch_stereo_mode = cx->params.audio_properties & 0x300;
  350. cx->search_pack_header = 0;
  351. break;
  352. case CX18_ENC_STREAM_TYPE_TS:
  353. captype = CAPTURE_CHANNEL_TYPE_TS;
  354. ts = 1;
  355. break;
  356. case CX18_ENC_STREAM_TYPE_YUV:
  357. captype = CAPTURE_CHANNEL_TYPE_YUV;
  358. break;
  359. case CX18_ENC_STREAM_TYPE_PCM:
  360. captype = CAPTURE_CHANNEL_TYPE_PCM;
  361. break;
  362. case CX18_ENC_STREAM_TYPE_VBI:
  363. captype = cx->vbi.sliced_in->service_set ?
  364. CAPTURE_CHANNEL_TYPE_SLICED_VBI : CAPTURE_CHANNEL_TYPE_VBI;
  365. cx->vbi.frame = 0;
  366. cx->vbi.inserted_frame = 0;
  367. memset(cx->vbi.sliced_mpeg_size,
  368. 0, sizeof(cx->vbi.sliced_mpeg_size));
  369. break;
  370. default:
  371. return -EINVAL;
  372. }
  373. s->buffers_stolen = 0;
  374. /* mute/unmute video */
  375. cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
  376. s->handle, !!test_bit(CX18_F_I_RADIO_USER, &cx->i_flags));
  377. /* Clear Streamoff flags in case left from last capture */
  378. clear_bit(CX18_F_S_STREAMOFF, &s->s_flags);
  379. cx18_vapi_result(cx, data, CX18_CREATE_TASK, 1, CPU_CMD_MASK_CAPTURE);
  380. s->handle = data[0];
  381. cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype);
  382. if (atomic_read(&cx->capturing) == 0 && !ts) {
  383. /* Stuff from Windows, we don't know what it is */
  384. cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0);
  385. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1);
  386. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0);
  387. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1);
  388. cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, s->handle, 12);
  389. cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3,
  390. s->handle, cx->digitizer, cx->digitizer);
  391. /* Setup VBI */
  392. if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE)
  393. cx18_vbi_setup(s);
  394. /* assign program index info.
  395. Mask 7: select I/P/B, Num_req: 400 max */
  396. cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0);
  397. /* Setup API for Stream */
  398. cx2341x_update(cx, cx18_api_func, NULL, &cx->params);
  399. }
  400. if (atomic_read(&cx->capturing) == 0) {
  401. clear_bit(CX18_F_I_EOS, &cx->i_flags);
  402. write_reg(7, CX18_DSP0_INTERRUPT_MASK);
  403. }
  404. cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
  405. (void *)&cx->scb->cpu_mdl_ack[s->type][0] - cx->enc_mem,
  406. (void *)&cx->scb->cpu_mdl_ack[s->type][1] - cx->enc_mem);
  407. list_for_each(p, &s->q_free.list) {
  408. struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
  409. writel(buf->dma_handle, &cx->scb->cpu_mdl[buf->id].paddr);
  410. writel(s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
  411. cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
  412. (void *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem, 1,
  413. buf->id, s->buf_size);
  414. }
  415. /* begin_capture */
  416. if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
  417. CX18_DEBUG_WARN("Error starting capture!\n");
  418. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  419. return -EINVAL;
  420. }
  421. /* you're live! sit back and await interrupts :) */
  422. atomic_inc(&cx->capturing);
  423. return 0;
  424. }
  425. void cx18_stop_all_captures(struct cx18 *cx)
  426. {
  427. int i;
  428. for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
  429. struct cx18_stream *s = &cx->streams[i];
  430. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  431. continue;
  432. if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
  433. cx18_stop_v4l2_encode_stream(s, 0);
  434. }
  435. }
  436. int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
  437. {
  438. struct cx18 *cx = s->cx;
  439. unsigned long then;
  440. if (s->v4l2dev == NULL && s->dvb.enabled == 0)
  441. return -EINVAL;
  442. /* This function assumes that you are allowed to stop the capture
  443. and that we are actually capturing */
  444. CX18_DEBUG_INFO("Stop Capture\n");
  445. if (atomic_read(&cx->capturing) == 0)
  446. return 0;
  447. if (s->type == CX18_ENC_STREAM_TYPE_MPG)
  448. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, !gop_end);
  449. else
  450. cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
  451. then = jiffies;
  452. if (s->type == CX18_ENC_STREAM_TYPE_MPG && gop_end) {
  453. CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
  454. }
  455. atomic_dec(&cx->capturing);
  456. /* Clear capture and no-read bits */
  457. clear_bit(CX18_F_S_STREAMING, &s->s_flags);
  458. cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
  459. s->handle = 0xffffffff;
  460. if (atomic_read(&cx->capturing) > 0)
  461. return 0;
  462. write_reg(5, CX18_DSP0_INTERRUPT_MASK);
  463. wake_up(&s->waitq);
  464. return 0;
  465. }
  466. u32 cx18_find_handle(struct cx18 *cx)
  467. {
  468. int i;
  469. /* find first available handle to be used for global settings */
  470. for (i = 0; i < CX18_MAX_STREAMS; i++) {
  471. struct cx18_stream *s = &cx->streams[i];
  472. if (s->v4l2dev && s->handle)
  473. return s->handle;
  474. }
  475. return 0;
  476. }