友善之臂视频监控方案源码学习(5) - 输入控制(9)
时间:2026-01-26
时间:2026-01-26
2. {
3. if (vd == NULL || device == NULL)
4. return -1;
5. if (width == 0 || height == 0)
6. return -1;
7. if (grabmethod < 0 || grabmethod > 1)
8. grabmethod = 1; //mmap by default;
9. vd->videodevice = NULL;
10. vd->status = NULL;
11. vd->pictName = NULL;
12. vd->videodevice = (char *) calloc (1, 16 * sizeof (char)); 13. vd->status = (char *) calloc (1, 100 * sizeof (char));
14. vd->pictName = (char *) calloc (1, 80 * sizeof (char));
15. snprintf (vd->videodevice, 12, "%s", device);
16. vd->toggleAvi = 0;
17. vd->getPict = 0;
18. vd->signalquit = 1;
19. vd->width = width;
20. vd->height = height;
21. vd->fps = fps;
22. vd->formatIn = format;
23. vd->grabmethod = grabmethod;
24. if (init_v4l2 (vd) < 0) {
25. fprintf (stderr, " Init v4L2 failed !! exit fatal \n"); 26. goto error;;
27. }
28. /* alloc a temp buffer to reconstruct the pict */
29. vd->framesizeIn = (vd->width * vd->height << 1);
30. switch (vd->formatIn) {
31. case V4L2_PIX_FMT_MJPEG:
32. vd->tmpbuffer = (unsigned char *) calloc(1, (size_t) vd->framesizeIn); 33. if (!vd->tmpbuffer)
34. goto error;
35. vd->framebuffer =
36. (unsigned char *) calloc(1, (size_t) vd->width * (vd->height + 8) *
2);
37. break;
38. case V4L2_PIX_FMT_YUYV:
39. default:
40. vd->framebuffer =
41. (unsigned char *) calloc(1, (size_t) vd->framesizeIn); 42. break;
43. //fprintf(stderr, " should never arrive exit fatal !!\n"); 44. //goto error;