summaryrefslogtreecommitdiff
path: root/amavutils/Amvideocaptools.c (plain)
blob: d66e1349051df6ca38a87466efb95ffdece80bc3
1/*
2 * Copyright (c) 2014 Amlogic, Inc. All rights reserved.
3 *
4 * This source code is subject to the terms and conditions defined in the
5 * file 'LICENSE' which is part of this source code package.
6 *
7 * Description:
8 */
9
10
11#define LOG_TAG "AmAvutls"
12
13#include <stdlib.h>
14#include <fcntl.h>
15#include <errno.h>
16#include <strings.h>
17#include <cutils/log.h>
18#include <sys/ioctl.h>
19
20#include "Amvideocaptools.h"
21
22
23#define VIDEOCAPDEV "/dev/amvideocap0"
24int amvideocap_capframe(char *buf, int size, int *w, int *h, int fmt_ignored, int at_end, int* ret_size, int fmt)
25{
26 int fd = open(VIDEOCAPDEV, O_RDWR);
27 int ret = 0;
28 if (fd < 0) {
29 ALOGI("amvideocap_capframe open %s failed\n", VIDEOCAPDEV);
30 return -1;
31 }
32 if (w != NULL && *w > 0) {
33 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, *w);
34 }
35 if (h != NULL && *h > 0) {
36 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, *h);
37 }
38 if (fmt) {
39 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_FORMAT, fmt);
40 }
41 if (at_end) {
42 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_AT_FLAGS, CAP_FLAG_AT_END);
43 }
44 *ret_size = read(fd, buf, size);
45 if (w != NULL) {
46 ret = ioctl(fd, AMVIDEOCAP_IOR_GET_FRAME_WIDTH, w);
47 }
48 if (h != NULL) {
49 ret = ioctl(fd, AMVIDEOCAP_IOR_GET_FRAME_HEIGHT, h);
50 }
51 close(fd);
52 return ret;
53}
54
55int amvideocap_capframe_with_rect(char *buf, int size, int src_rect_x, int src_rect_y, int *w, int *h, int fmt_ignored, int at_end, int* ret_size)
56{
57 int fd = open(VIDEOCAPDEV, O_RDWR);
58 int ret = 0;
59 if (fd < 0) {
60 ALOGI("amvideocap_capframe_with_rect open %s failed\n", VIDEOCAPDEV);
61 return -1;
62 }
63 ALOGI("amvideocap_capframe_with_rect open %d, %d\n", *w, *h);
64 if (src_rect_x > 0) {
65 ret = ioctl(fd, AMVIDEOCAP_IOR_SET_SRC_X, src_rect_x);
66 }
67 if (src_rect_y > 0) {
68 ret = ioctl(fd, AMVIDEOCAP_IOR_SET_SRC_Y, src_rect_y);
69 }
70 if (*w > 0) {
71 ret = ioctl(fd, AMVIDEOCAP_IOR_SET_SRC_WIDTH, *w);
72 }
73 if (*h > 0) {
74 ret = ioctl(fd, AMVIDEOCAP_IOR_SET_SRC_HEIGHT, *h);
75 }
76 if (*w > 0) {
77 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_WIDTH, *w);
78 }
79 if (*h > 0) {
80 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_HEIGHT, *h);
81 }
82 if (at_end) {
83 ret = ioctl(fd, AMVIDEOCAP_IOW_SET_WANTFRAME_AT_FLAGS, CAP_FLAG_AT_END);
84 }
85 *ret_size = read(fd, buf, size);
86
87 if (*w > 0) {
88 ret = ioctl(fd, AMVIDEOCAP_IOR_GET_FRAME_WIDTH, w);
89 }
90
91 if (*h > 0) {
92 ret = ioctl(fd, AMVIDEOCAP_IOR_GET_FRAME_HEIGHT, h);
93 }
94 close(fd);
95 return ret;
96}
97
98