• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*!
18  * \file      exynos_v4l2.c
19  * \brief     source file for libv4l2
20  * \author    Jinsung Yang (jsgood.yang@samsung.com)
21  * \author    Sangwoo Park (sw5771.park@samsung.com)
22  * \date      2012/01/17
23  *
24  * <b>Revision History: </b>
25  * - 2012/01/17: Jinsung Yang (jsgood.yang@samsung.com) \n
26  *   Initial version
27  *
28  */
29 
30 #include <stdio.h>
31 #include <errno.h>
32 #include <stdarg.h>
33 #include <fcntl.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <sys/types.h>
37 #include <sys/ioctl.h>
38 #include <sys/stat.h>
39 
40 #include "exynos_v4l2.h"
41 
42 //#define LOG_NDEBUG 0
43 #define LOG_TAG "libexynosv4l2"
44 #include <utils/Log.h>
45 #include "Exynos_log.h"
46 
47 #define VIDEODEV_MAX 255
48 
49 //#define EXYNOS_V4L2_TRACE 0
50 #ifdef EXYNOS_V4L2_TRACE
51 #define Exynos_v4l2_In() Exynos_Log(EXYNOS_DEV_LOG_DEBUG, LOG_TAG, "%s In , Line: %d", __FUNCTION__, __LINE__)
52 #define Exynos_v4l2_Out() Exynos_Log(EXYNOS_DEV_LOG_DEBUG, LOG_TAG, "%s Out , Line: %d", __FUNCTION__, __LINE__)
53 #else
54 #define Exynos_v4l2_In() ((void *)0)
55 #define Exynos_v4l2_Out() ((void *)0)
56 #endif
57 
__v4l2_check_buf_type(enum v4l2_buf_type type)58 static bool __v4l2_check_buf_type(enum v4l2_buf_type type)
59 {
60     bool supported;
61 
62     switch (type) {
63     case V4L2_BUF_TYPE_VIDEO_CAPTURE:
64     case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
65     case V4L2_BUF_TYPE_VIDEO_OUTPUT:
66     case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
67     case V4L2_BUF_TYPE_VIDEO_OVERLAY:
68         supported = true;
69         break;
70 
71     default:
72         supported = (type >= V4L2_BUF_TYPE_PRIVATE) ? true : false;
73         break;
74     }
75 
76     return supported;
77 }
78 
__v4l2_open(const char * filename,int oflag,va_list ap)79 static int __v4l2_open(const char *filename, int oflag, va_list ap)
80 {
81     mode_t mode = 0;
82     int fd;
83 
84     if (oflag & O_CREAT)
85         mode = va_arg(ap, int);
86 
87     fd = open(filename, oflag, mode);
88 
89     return fd;
90 }
91 
exynos_v4l2_open(const char * filename,int oflag,...)92 int exynos_v4l2_open(const char *filename, int oflag, ...)
93 {
94     va_list ap;
95     int fd;
96 
97     Exynos_v4l2_In();
98 
99     va_start(ap, oflag);
100     fd = __v4l2_open(filename, oflag, ap);
101     va_end(ap);
102 
103     Exynos_v4l2_Out();
104 
105     return fd;
106 }
107 
exynos_v4l2_open_devname(const char * devname,int oflag,...)108 int exynos_v4l2_open_devname(const char *devname, int oflag, ...)
109 {
110     bool found = false;
111     int fd = -1;
112     struct stat s;
113     va_list ap;
114     FILE *stream_fd;
115     char filename[64], name[64];
116     int i = 0;
117 
118     Exynos_v4l2_In();
119 
120     do {
121         if (i > VIDEODEV_MAX)
122             break;
123 
124         /* video device node */
125         snprintf(filename, sizeof(filename), "/dev/video%d", i);
126 
127         /* if the node is video device */
128         if ((lstat(filename, &s) == 0) && S_ISCHR(s.st_mode) &&
129                 ((int)((unsigned short)(s.st_rdev) >> 8) == 81)) {
130             ALOGD("try node: %s", filename);
131             /* open sysfs entry */
132             snprintf(filename, sizeof(filename), "/sys/class/video4linux/video%d/name", i);
133             if (S_ISLNK(s.st_mode)) {
134                 ALOGE("symbolic link detected");
135                 return -1;
136             }
137             stream_fd = fopen(filename, "r");
138             if (stream_fd == NULL) {
139                 ALOGE("failed to open sysfs entry for videodev (%d - %s)", errno, strerror(errno));
140                 i++;
141                 continue;   /* try next */
142             }
143 
144             /* read sysfs entry for device name */
145             char *p = fgets(name, sizeof(name), stream_fd);
146             fclose(stream_fd);
147 
148             /* check read size */
149             if (p == NULL) {
150                 ALOGE("failed to read sysfs entry for videodev");
151             } else {
152                 /* matched */
153                 if (strncmp(name, devname, strlen(devname)) == 0) {
154                     ALOGI("node found for device %s: /dev/video%d", devname, i);
155                     found = true;
156                     break;
157                 }
158             }
159         }
160         i++;
161     } while (found == false);
162 
163     if (found) {
164         snprintf(filename, sizeof(filename), "/dev/video%d", i);
165         va_start(ap, oflag);
166         fd = __v4l2_open(filename, oflag, ap);
167         va_end(ap);
168 
169         if (fd > 0)
170             ALOGI("open video device %s", filename);
171         else
172             ALOGE("failed to open video device %s", filename);
173     } else {
174         ALOGE("no video device found");
175     }
176 
177     Exynos_v4l2_Out();
178 
179     return fd;
180 }
181 
exynos_v4l2_close(int fd)182 int exynos_v4l2_close(int fd)
183 {
184     int ret = -1;
185 
186     Exynos_v4l2_In();
187 
188     if (fd < 0)
189         ALOGE("%s: invalid fd: %d", __func__, fd);
190     else
191         ret = close(fd);
192 
193     Exynos_v4l2_Out();
194 
195     return ret;
196 }
197 
exynos_v4l2_enuminput(int fd,int index,char * input_name_buf)198 bool exynos_v4l2_enuminput(int fd, int index, char *input_name_buf)
199 {
200     int ret = -1;
201     struct v4l2_input input;
202 
203     Exynos_v4l2_In();
204 
205     if (fd < 0) {
206         ALOGE("%s: invalid fd: %d", __func__, fd);
207         return NULL;
208     }
209 
210     input.index = index;
211     ret = ioctl(fd, VIDIOC_ENUMINPUT, &input, 32);
212     if (ret) {
213         ALOGE("%s: no matching index founds", __func__);
214         return false;
215     }
216 
217     ALOGI("Name of input channel[%d] is %s", input.index, input.name);
218 
219     strncpy(input_name_buf, (const char *)input.name, 32);
220 
221     Exynos_v4l2_Out();
222 
223     return true;
224 }
225 
exynos_v4l2_s_input(int fd,int index)226 int exynos_v4l2_s_input(int fd, int index)
227 {
228     int ret = -1;
229     struct v4l2_input input;
230 
231     Exynos_v4l2_In();
232 
233     if (fd < 0) {
234         ALOGE("%s: invalid fd: %d", __func__, fd);
235         return ret;
236     }
237 
238     input.index = index;
239 
240     ret = ioctl(fd, VIDIOC_S_INPUT, &input);
241     if (ret){
242         ALOGE("failed to ioctl: VIDIOC_S_INPUT (%d - %s)", errno, strerror(errno));
243         return ret;
244     }
245 
246     Exynos_v4l2_Out();
247 
248     return ret;
249 }
250 
exynos_v4l2_querycap(int fd,unsigned int need_caps)251 bool exynos_v4l2_querycap(int fd, unsigned int need_caps)
252 {
253     struct v4l2_capability cap;
254     int ret;
255 
256     Exynos_v4l2_In();
257 
258     if (fd < 0) {
259         ALOGE("%s: invalid fd: %d", __func__, fd);
260         return false;
261     }
262 
263     if (!(need_caps & V4L2_CAP_VIDEO_CAPTURE) &&
264             !(need_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE) &&
265             !(need_caps & V4L2_CAP_VIDEO_OUTPUT) &&
266             !(need_caps & V4L2_CAP_VIDEO_OUTPUT_MPLANE) &&
267             !(need_caps & V4L2_CAP_VIDEO_OVERLAY)) {
268         ALOGE("%s: unsupported capabilities", __func__);
269         return false;
270     }
271 
272     memset(&cap, 0, sizeof(cap));
273 
274     ret = ioctl(fd, VIDIOC_QUERYCAP, &cap);
275     if (ret) {
276         ALOGE("failed to ioctl: VIDIOC_QUERYCAP (%d - %s)", errno, strerror(errno));
277         return false;
278     }
279 
280     if ((need_caps & cap.capabilities) != need_caps) {
281         ALOGE("%s: unsupported capabilities", __func__);
282         return false;
283     }
284 
285     Exynos_v4l2_Out();
286 
287     return true;
288 }
289 
exynos_v4l2_enum_fmt(int fd,enum v4l2_buf_type type,unsigned int fmt)290 bool exynos_v4l2_enum_fmt(int fd, enum v4l2_buf_type type, unsigned int fmt)
291 {
292     struct v4l2_fmtdesc fmtdesc;
293     int found = 0;
294 
295     Exynos_v4l2_In();
296 
297     fmtdesc.type = type;
298     fmtdesc.index = 0;
299 
300     while (ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
301         if (fmtdesc.pixelformat == fmt) {
302             ALOGE("Passed fmt = %#x found pixel format[%d]: %s", fmt, fmtdesc.index, fmtdesc.description);
303             found = 1;
304             break;
305         }
306 
307         fmtdesc.index++;
308     }
309 
310     if (!found) {
311         ALOGE("%s: unsupported pixel format", __func__);
312         return false;
313     }
314 
315     Exynos_v4l2_Out();
316 
317     return true;
318 }
319 
exynos_v4l2_g_fmt(int fd,struct v4l2_format * fmt)320 int exynos_v4l2_g_fmt(int fd, struct v4l2_format *fmt)
321 {
322     int ret = -1;
323 
324     Exynos_v4l2_In();
325 
326     if (fd < 0) {
327         ALOGE("%s: invalid fd: %d", __func__, fd);
328         return ret;
329     }
330 
331     if (!fmt) {
332         ALOGE("%s: fmt is NULL", __func__);
333         return ret;
334     }
335 
336     if (__v4l2_check_buf_type(fmt->type) == false) {
337         ALOGE("%s: unsupported buffer type", __func__);
338         return ret;
339     }
340 
341     ret = ioctl(fd, VIDIOC_G_FMT, fmt);
342     if (ret) {
343         ALOGE("failed to ioctl: VIDIOC_G_FMT (%d - %s)", errno, strerror(errno));
344         return ret;
345     }
346 
347     Exynos_v4l2_Out();
348 
349     return ret;
350 }
351 
__v4l2_s_fmt(int fd,unsigned int request,struct v4l2_format * fmt)352 static int __v4l2_s_fmt(int fd, unsigned int request, struct v4l2_format *fmt)
353 {
354     int ret = -1;
355 
356     Exynos_v4l2_In();
357 
358     if (fd < 0) {
359         ALOGE("%s: invalid fd: %d", __func__, fd);
360         return ret;
361     }
362 
363     if (!fmt) {
364         ALOGE("%s: fmt is NULL", __func__);
365         return ret;
366     }
367 
368     if (__v4l2_check_buf_type(fmt->type) == false) {
369         ALOGE("%s: unsupported buffer type", __func__);
370         return ret;
371     } else {
372         ret = ioctl(fd, request, fmt);
373         if (ret) {
374             if (request == VIDIOC_TRY_FMT)
375                 ALOGE("failed to ioctl: VIDIOC_TRY_FMT (%d - %s)", errno, strerror(errno));
376             else
377                 ALOGE("failed to ioctl: VIDIOC_S_FMT (%d - %s)", errno, strerror(errno));
378 
379             return ret;
380         }
381     }
382 
383     Exynos_v4l2_Out();
384 
385     return ret;
386 }
387 
exynos_v4l2_try_fmt(int fd,struct v4l2_format * fmt)388 int exynos_v4l2_try_fmt(int fd, struct v4l2_format *fmt)
389 {
390     return __v4l2_s_fmt(fd, VIDIOC_TRY_FMT, fmt);
391 }
392 
exynos_v4l2_s_fmt(int fd,struct v4l2_format * fmt)393 int exynos_v4l2_s_fmt(int fd, struct v4l2_format *fmt)
394 {
395     return __v4l2_s_fmt(fd, VIDIOC_S_FMT, fmt);
396 }
397 
exynos_v4l2_reqbufs(int fd,struct v4l2_requestbuffers * req)398 int exynos_v4l2_reqbufs(int fd, struct v4l2_requestbuffers *req)
399 {
400     int ret = -1;
401     unsigned int count;
402 
403     Exynos_v4l2_In();
404 
405     if (fd < 0) {
406         ALOGE("%s: invalid fd: %d", __func__, fd);
407         return ret;
408     }
409 
410     if (!req) {
411         ALOGE("%s: req is NULL", __func__);
412         return ret;
413     }
414 
415     if ((req->memory != V4L2_MEMORY_MMAP) &&
416 	(req->memory != V4L2_MEMORY_USERPTR) &&
417 	(req->memory != V4L2_MEMORY_DMABUF)) {
418         ALOGE("%s: unsupported memory type", __func__);
419         return ret;
420     }
421 
422     if (__v4l2_check_buf_type(req->type) == false) {
423         ALOGE("%s: unsupported buffer type", __func__);
424         return ret;
425     }
426 
427     count = req->count;
428 
429     ret = ioctl(fd, VIDIOC_REQBUFS, req);
430     if (ret) {
431         ALOGE("failed to ioctl: VIDIOC_REQBUFS (%d - %s)", ret, strerror(errno));
432         return ret;
433     }
434 
435     if (count != req->count) {
436         ALOGW("number of buffers had been changed: %d => %d", count, req->count);
437     }
438 
439     Exynos_v4l2_Out();
440 
441     return ret;
442 }
443 
exynos_v4l2_querybuf(int fd,struct v4l2_buffer * buf)444 int exynos_v4l2_querybuf(int fd, struct v4l2_buffer *buf)
445 {
446     int ret = -1;
447 
448     Exynos_v4l2_In();
449 
450     if (fd < 0) {
451         ALOGE("%s: invalid fd: %d", __func__, fd);
452         return ret;
453     }
454 
455     if (!buf) {
456         ALOGE("%s: buf is NULL", __func__);
457         return ret;
458     }
459 
460     if ((buf->memory != V4L2_MEMORY_MMAP) &&
461 	(buf->memory != V4L2_MEMORY_DMABUF)) {
462         ALOGE("%s: unsupported memory type", __func__);
463         return ret;
464     }
465 
466     if (__v4l2_check_buf_type(buf->type) == false) {
467         ALOGE("%s: unsupported buffer type", __func__);
468         return ret;
469     }
470 
471     ret = ioctl(fd, VIDIOC_QUERYBUF, buf);
472     if (ret) {
473         ALOGE("failed to ioctl: VIDIOC_QUERYBUF (%d - %s)", errno, strerror(errno));
474         return ret;
475     }
476 
477     Exynos_v4l2_Out();
478 
479     return ret;
480 }
481 
exynos_v4l2_qbuf(int fd,struct v4l2_buffer * buf)482 int exynos_v4l2_qbuf(int fd, struct v4l2_buffer *buf)
483 {
484     int ret = -1;
485 
486     Exynos_v4l2_In();
487 
488     if (fd < 0) {
489         ALOGE("%s: invalid fd: %d", __func__, fd);
490         return ret;
491     }
492 
493     if (!buf) {
494         ALOGE("%s: buf is NULL", __func__);
495         return ret;
496     }
497 
498     if ((buf->memory != V4L2_MEMORY_MMAP) &&
499 	(buf->memory != V4L2_MEMORY_USERPTR) &&
500 	(buf->memory != V4L2_MEMORY_DMABUF)) {
501         ALOGE("%s: unsupported memory type", __func__);
502         return ret;
503     }
504 
505     if (__v4l2_check_buf_type(buf->type) == false) {
506         ALOGE("%s: unsupported buffer type", __func__);
507         return ret;
508     }
509 
510     ret = ioctl(fd, VIDIOC_QBUF, buf);
511     if (ret) {
512         ALOGE("failed to ioctl: VIDIOC_QBUF (%d - %s)", errno, strerror(errno));
513         return ret;
514     }
515 
516     Exynos_v4l2_Out();
517 
518     return ret;
519 }
520 
exynos_v4l2_dqbuf(int fd,struct v4l2_buffer * buf)521 int exynos_v4l2_dqbuf(int fd, struct v4l2_buffer *buf)
522 {
523     int ret = -1;
524 
525     Exynos_v4l2_In();
526 
527     if (fd < 0) {
528         ALOGE("%s: invalid fd: %d", __func__, fd);
529         return ret;
530     }
531 
532     if (!buf) {
533         ALOGE("%s: buf is NULL", __func__);
534         return ret;
535     }
536 
537     if ((buf->memory != V4L2_MEMORY_MMAP) &&
538 	(buf->memory != V4L2_MEMORY_USERPTR) &&
539 	(buf->memory != V4L2_MEMORY_DMABUF)) {
540         ALOGE("%s: unsupported memory type", __func__);
541         return ret;
542     }
543 
544     if (__v4l2_check_buf_type(buf->type) == false) {
545         ALOGE("%s: unsupported buffer type", __func__);
546         return ret;
547     }
548 
549     ret = ioctl(fd, VIDIOC_DQBUF, buf);
550     if (ret) {
551         if (errno == EAGAIN)
552             return -errno;
553 
554         ALOGW("failed to ioctl: VIDIOC_DQBUF (%d - %s)", errno, strerror(errno));
555         return ret;
556     }
557 
558     Exynos_v4l2_Out();
559 
560     return ret;
561 }
562 
exynos_v4l2_streamon(int fd,enum v4l2_buf_type type)563 int exynos_v4l2_streamon(int fd, enum v4l2_buf_type type)
564 {
565     int ret = -1;
566 
567     Exynos_v4l2_In();
568 
569     if (fd < 0) {
570         ALOGE("%s: invalid fd: %d", __func__, fd);
571         return ret;
572     }
573 
574     if (__v4l2_check_buf_type(type) == false) {
575         ALOGE("%s: unsupported buffer type", __func__);
576         return ret;
577     }
578 
579     ret = ioctl(fd, VIDIOC_STREAMON, &type);
580     if (ret) {
581         ALOGE("failed to ioctl: VIDIOC_STREAMON (%d - %s)", errno, strerror(errno));
582         return ret;
583     }
584 
585     Exynos_v4l2_Out();
586 
587     return ret;
588 }
589 
exynos_v4l2_streamoff(int fd,enum v4l2_buf_type type)590 int exynos_v4l2_streamoff(int fd, enum v4l2_buf_type type)
591 {
592     int ret = -1;
593 
594     Exynos_v4l2_In();
595 
596     if (fd < 0) {
597         ALOGE("%s: invalid fd: %d", __func__, fd);
598         return ret;
599     }
600 
601     if (__v4l2_check_buf_type(type) == false) {
602         ALOGE("%s: unsupported buffer type", __func__);
603         return ret;
604     }
605 
606     ret = ioctl(fd, VIDIOC_STREAMOFF, &type);
607     if (ret) {
608         ALOGE("failed to ioctl: VIDIOC_STREAMOFF (%d - %s)", errno, strerror(errno));
609         return ret;
610     }
611 
612     Exynos_v4l2_Out();
613 
614     return ret;
615 }
616 
exynos_v4l2_cropcap(int fd,struct v4l2_cropcap * crop)617 int exynos_v4l2_cropcap(int fd, struct v4l2_cropcap *crop)
618 {
619     int ret = -1;
620 
621     Exynos_v4l2_In();
622 
623     if (fd < 0) {
624         ALOGE("%s: invalid fd: %d", __func__, fd);
625         return ret;
626     }
627 
628     if (!crop) {
629         ALOGE("%s: crop is NULL", __func__);
630         return ret;
631     }
632 
633     if (__v4l2_check_buf_type(crop->type) == false) {
634         ALOGE("%s: unsupported buffer type", __func__);
635         return ret;
636     }
637 
638     ret = ioctl(fd, VIDIOC_CROPCAP, crop);
639     if (ret) {
640         ALOGE("failed to ioctl: VIDIOC_CROPCAP (%d - %s)", errno, strerror(errno));
641         return ret;
642     }
643 
644     Exynos_v4l2_Out();
645 
646     return ret;
647 }
648 
exynos_v4l2_g_crop(int fd,struct v4l2_crop * crop)649 int exynos_v4l2_g_crop(int fd, struct v4l2_crop *crop)
650 {
651     int ret = -1;
652 
653     Exynos_v4l2_In();
654 
655     if (fd < 0) {
656         ALOGE("%s: invalid fd: %d", __func__, fd);
657         return ret;
658     }
659 
660     if (!crop) {
661         ALOGE("%s: crop is NULL", __func__);
662         return ret;
663     }
664 
665     if (__v4l2_check_buf_type(crop->type) == false) {
666         ALOGE("%s: unsupported buffer type", __func__);
667         return ret;
668     }
669 
670     ret = ioctl(fd, VIDIOC_G_CROP, crop);
671     if (ret) {
672         ALOGE("failed to ioctl: VIDIOC_G_CROP (%d - %s)", errno, strerror(errno));
673         return ret;
674     }
675 
676     Exynos_v4l2_Out();
677 
678     return ret;
679 }
680 
exynos_v4l2_s_crop(int fd,struct v4l2_crop * crop)681 int exynos_v4l2_s_crop(int fd, struct v4l2_crop *crop)
682 {
683     int ret = -1;
684 
685     Exynos_v4l2_In();
686 
687     if (fd < 0) {
688         ALOGE("%s: invalid fd: %d", __func__, fd);
689         return ret;
690     }
691 
692     if (!crop) {
693         ALOGE("%s: crop is NULL", __func__);
694         return ret;
695     }
696 
697     if (__v4l2_check_buf_type(crop->type) == false) {
698         ALOGE("%s: unsupported buffer type", __func__);
699         return ret;
700     }
701 
702     ret = ioctl(fd, VIDIOC_S_CROP, crop);
703     if (ret) {
704         ALOGE("failed to ioctl: VIDIOC_S_CROP (%d - %s)", errno, strerror(errno));
705         return ret;
706     }
707 
708     Exynos_v4l2_Out();
709 
710     return ret;
711 }
712 
exynos_v4l2_g_ctrl(int fd,unsigned int id,int * value)713 int exynos_v4l2_g_ctrl(int fd, unsigned int id, int *value)
714 {
715     int ret = -1;
716     struct v4l2_control ctrl;
717 
718     Exynos_v4l2_In();
719 
720     ctrl.id = id;
721 
722     if (fd < 0) {
723         ALOGE("%s: invalid fd: %d", __func__, fd);
724         return ret;
725     }
726 
727     ret = ioctl(fd, VIDIOC_G_CTRL, &ctrl);
728     if (ret) {
729         ALOGE("failed to ioctl: VIDIOC_G_CTRL (%d - %s)", errno, strerror(errno));
730         return ret;
731     }
732 
733     *value = ctrl.value;
734 
735     Exynos_v4l2_Out();
736 
737     return ret;
738 }
739 
exynos_v4l2_s_ctrl(int fd,unsigned int id,int value)740 int exynos_v4l2_s_ctrl(int fd, unsigned int id, int value)
741 {
742     int ret = -1;
743     struct v4l2_control ctrl;
744 
745     Exynos_v4l2_In();
746 
747     ctrl.id = id;
748     ctrl.value = value;
749 
750     if (fd < 0) {
751         ALOGE("%s: invalid fd: %d", __func__, fd);
752         return ret;
753     }
754 
755     ret = ioctl(fd, VIDIOC_S_CTRL, &ctrl);
756     if (ret) {
757         ALOGE("failed to ioctl: VIDIOC_S_CTRL (%d)", errno);
758         return ret;
759     }
760 
761     Exynos_v4l2_Out();
762 
763     return ret;
764 }
765 
exynos_v4l2_prepare(int fd,struct v4l2_buffer * arg)766 int exynos_v4l2_prepare(int fd, struct v4l2_buffer *arg)
767 {
768     int ret = -1;
769 
770     Exynos_v4l2_In();
771 
772     if (fd < 0) {
773         ALOGE("%s: invalid fd: %d", __func__, fd);
774         return ret;
775     }
776 
777     ret = ioctl(fd, VIDIOC_PREPARE_BUF, arg);
778     if (ret) {
779         ALOGE("failed to ioctl: VIDIOC_PREPARE_BUF (%d)", errno);
780         return ret;
781     }
782 
783     Exynos_v4l2_Out();
784 
785     return ret;
786 }
787 
exynos_v4l2_g_parm(int fd,struct v4l2_streamparm * streamparm)788 int exynos_v4l2_g_parm(int fd, struct v4l2_streamparm *streamparm)
789 {
790     int ret = -1;
791 
792     Exynos_v4l2_In();
793 
794     if (fd < 0) {
795         ALOGE("%s: invalid fd: %d", __func__, fd);
796         return ret;
797     }
798 
799     if (__v4l2_check_buf_type(streamparm->type) == false) {
800         ALOGE("%s: unsupported buffer type", __func__);
801         return ret;
802     }
803 
804     ret = ioctl(fd, VIDIOC_G_PARM, streamparm);
805     if (ret) {
806         ALOGE("failed to ioctl: VIDIOC_G_PARM (%d - %s)", errno, strerror(errno));
807         return ret;
808     }
809 
810     Exynos_v4l2_Out();
811 
812     return ret;
813 }
814 
exynos_v4l2_s_parm(int fd,struct v4l2_streamparm * streamparm)815 int exynos_v4l2_s_parm(int fd, struct v4l2_streamparm *streamparm)
816 {
817     int ret = -1;
818 
819     Exynos_v4l2_In();
820 
821     if (fd < 0) {
822         ALOGE("%s: invalid fd: %d", __func__, fd);
823         return ret;
824     }
825 
826     if (__v4l2_check_buf_type(streamparm->type) == false) {
827         ALOGE("%s: unsupported buffer type", __func__);
828         return ret;
829     }
830 
831     ret = ioctl(fd, VIDIOC_S_PARM, streamparm);
832     if (ret) {
833         ALOGE("failed to ioctl: VIDIOC_S_PARM (%d - %s)", errno, strerror(errno));
834         return ret;
835     }
836 
837     Exynos_v4l2_Out();
838 
839     return ret;
840 }
841 
exynos_v4l2_g_ext_ctrl(int fd,struct v4l2_ext_controls * ctrl)842 int exynos_v4l2_g_ext_ctrl(int fd, struct v4l2_ext_controls *ctrl)
843 {
844     int ret = -1;
845 
846     Exynos_v4l2_In();
847 
848     if (fd < 0) {
849         ALOGE("%s: invalid fd: %d", __func__, fd);
850         return ret;
851     }
852 
853     if (ctrl == NULL) {
854         ALOGE("%s: ctrl is NULL", __func__);
855         return ret;
856     }
857 
858     ret = ioctl(fd, VIDIOC_G_EXT_CTRLS, ctrl);
859     if (ret)
860         ALOGE("failed to ioctl: VIDIOC_G_EXT_CTRLS (%d - %s)", errno, strerror(errno));
861 
862     Exynos_v4l2_Out();
863 
864     return ret;
865 }
866 
exynos_v4l2_s_ext_ctrl(int fd,struct v4l2_ext_controls * ctrl)867 int exynos_v4l2_s_ext_ctrl(int fd, struct v4l2_ext_controls *ctrl)
868 {
869     int ret = -1;
870 
871     Exynos_v4l2_In();
872 
873     if (fd < 0) {
874         ALOGE("%s: invalid fd: %d", __func__, fd);
875         return ret;
876     }
877 
878     if (ctrl == NULL) {
879         ALOGE("%s: ctrl is NULL", __func__);
880         return ret;
881     }
882 
883     ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, ctrl);
884     if (ret)
885         ALOGE("failed to ioctl: VIDIOC_S_EXT_CTRLS (%d - %s)", errno, strerror(errno));
886 
887     Exynos_v4l2_Out();
888 
889     return ret;
890 }
891