From 0b539d628066212bcd428fad56976c77647b646f Mon Sep 17 00:00:00 2001 From: gozfree Date: Sat, 21 Dec 2019 15:50:29 +0800 Subject: [PATCH] fix compile error of type --- build.sh | 3 +-- gear-lib/libmedia-io/libmedia-io.h | 1 - gear-lib/libmedia-io/memalign.h | 36 ++++++++++++++++++++++++++++++ gear-lib/libmedia-io/video-def.c | 22 +++++++++--------- gear-lib/libmedia-io/video-def.h | 2 +- gear-lib/libuvc/Makefile | 2 +- gear-lib/libuvc/libuvc.c | 2 +- gear-lib/libuvc/libuvc.h | 9 ++++---- gear-lib/libuvc/test_libuvc.c | 8 ++++++- gear-lib/libuvc/v4l2.c | 33 ++++++++++++++------------- 10 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 gear-lib/libmedia-io/memalign.h diff --git a/build.sh b/build.sh index cd3e5909..c503d7a5 100755 --- a/build.sh +++ b/build.sh @@ -152,8 +152,7 @@ build_module() *) MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE}" if [[ ${ARCH} == "linux" || ${ARCH} == "pi" || ${ARCH} == "android" ]]; then - ${MAKE} -#> /dev/null + ${MAKE} > /dev/null else echo "${ARCH} not support now" #make -f Makefile.${ARCH} > /dev/null fi diff --git a/gear-lib/libmedia-io/libmedia-io.h b/gear-lib/libmedia-io/libmedia-io.h index 042d284d..235890dd 100644 --- a/gear-lib/libmedia-io/libmedia-io.h +++ b/gear-lib/libmedia-io/libmedia-io.h @@ -28,7 +28,6 @@ extern "C" { #include "audio-def.h" #include "video-def.h" -#include "memalign.h" struct media_frame { union { diff --git a/gear-lib/libmedia-io/memalign.h b/gear-lib/libmedia-io/memalign.h new file mode 100644 index 00000000..545b2625 --- /dev/null +++ b/gear-lib/libmedia-io/memalign.h @@ -0,0 +1,36 @@ +/****************************************************************************** + * Copyright (C) 2014-2020 Zhifeng Gong + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + ******************************************************************************/ +#ifndef MEMALIGN_H +#define MEMALIGN_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#define ALIGNMENT 32 +#define ALIGN_SIZE(size, align) (((size) + (align - 1)) & (~(align - 1))) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/gear-lib/libmedia-io/video-def.c b/gear-lib/libmedia-io/video-def.c index 5357cada..dbc14033 100644 --- a/gear-lib/libmedia-io/video-def.c +++ b/gear-lib/libmedia-io/video-def.c @@ -130,7 +130,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[1] = size; size += (width / 2) * (height / 2); size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->data[2] = (uint8_t *)frame->data[0] + offsets[1]; @@ -144,7 +144,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[0] = size; size += (width / 2) * (height / 2) * 2; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->linesize[0] = width; @@ -153,7 +153,7 @@ struct video_frame *video_frame_create(enum video_format format, case VIDEO_FORMAT_Y800: size = width * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->linesize[0] = width; break; @@ -162,7 +162,7 @@ struct video_frame *video_frame_create(enum video_format format, case VIDEO_FORMAT_UYVY: size = width * height * 2; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->linesize[0] = width * 2; break; @@ -172,14 +172,14 @@ struct video_frame *video_frame_create(enum video_format format, case VIDEO_FORMAT_AYUV: size = width * height * 4; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->linesize[0] = width * 4; break; case VIDEO_FORMAT_I444: size = width * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size * 3); frame->data[1] = (uint8_t *)frame->data[0] + size; frame->data[2] = (uint8_t *)frame->data[1] + size; @@ -190,7 +190,7 @@ struct video_frame *video_frame_create(enum video_format format, case VIDEO_FORMAT_BGR3: size = width * height * 3; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->linesize[0] = width * 3; break; @@ -203,7 +203,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[1] = size; size += (width / 2) * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->data[2] = (uint8_t *)frame->data[0] + offsets[1]; @@ -223,7 +223,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[2] = size; size += width * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->data[2] = (uint8_t *)frame->data[0] + offsets[1]; @@ -245,7 +245,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[2] = size; size += width * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->data[2] = (uint8_t *)frame->data[0] + offsets[1]; @@ -267,7 +267,7 @@ struct video_frame *video_frame_create(enum video_format format, offsets[2] = size; size += width * height; size = ALIGN_SIZE(size, ALIGNMENT); - frame->totoal_size = size; + frame->total_size = size; frame->data[0] = memalign(ALIGNMENT, size); frame->data[1] = (uint8_t *)frame->data[0] + offsets[0]; frame->data[2] = (uint8_t *)frame->data[0] + offsets[1]; diff --git a/gear-lib/libmedia-io/video-def.h b/gear-lib/libmedia-io/video-def.h index e666d1e9..1283c8b6 100644 --- a/gear-lib/libmedia-io/video-def.h +++ b/gear-lib/libmedia-io/video-def.h @@ -88,7 +88,7 @@ struct video_frame { uint32_t width; uint32_t height; uint64_t timestamp;//ns - uint64_t totoal_size; + uint64_t total_size; uint64_t id; uint8_t **extended_data; void *opaque; diff --git a/gear-lib/libuvc/Makefile b/gear-lib/libuvc/Makefile index 554468a5..24a9a634 100644 --- a/gear-lib/libuvc/Makefile +++ b/gear-lib/libuvc/Makefile @@ -67,7 +67,7 @@ CFLAGS += -I$(OUTPUT)/include SHARED := -shared LDFLAGS := $($(ARCH)_LDFLAGS) -LDFLAGS += -pthread +LDFLAGS += -pthread -lmedia-io # -lv4l2 ############################################################################### diff --git a/gear-lib/libuvc/libuvc.c b/gear-lib/libuvc/libuvc.c index 00780088..34ac7c78 100644 --- a/gear-lib/libuvc/libuvc.c +++ b/gear-lib/libuvc/libuvc.c @@ -43,7 +43,7 @@ static struct uvc_ops *uvc_ops[] = { NULL }; -struct uvc_ctx *uvc_open(const char *dev, int width, int height) +struct uvc_ctx *uvc_open(const char *dev, uint32_t width, uint32_t height) { struct uvc_ctx *uvc = (struct uvc_ctx *)calloc(1, sizeof(struct uvc_ctx)); if (!uvc) { diff --git a/gear-lib/libuvc/libuvc.h b/gear-lib/libuvc/libuvc.h index ed3b567f..f790cb66 100644 --- a/gear-lib/libuvc/libuvc.h +++ b/gear-lib/libuvc/libuvc.h @@ -43,8 +43,9 @@ typedef int (*on_stream_data)(struct uvc_ctx *c, void *data, size_t len); struct uvc_ctx { int fd; - int width; - int height; + uint32_t width; + uint32_t height; + enum video_format format; struct uvc_ops *ops; void *opaque; on_stream_data *on_data; @@ -64,7 +65,7 @@ struct video_ctrl { #define UVC_SET_CTRL _IOWR('V', 1, struct video_ctrl) struct uvc_ops { - void *(*open)(struct uvc_ctx *uvc, const char *dev, int width, int height); + void *(*open)(struct uvc_ctx *uvc, const char *dev, uint32_t width, uint32_t height); void (*close)(struct uvc_ctx *c); int (*dequeue)(struct uvc_ctx *c, struct video_frame *frame); int (*enqueue)(struct uvc_ctx *c, void *buf, size_t len); @@ -74,7 +75,7 @@ struct uvc_ops { int (*stop_stream)(struct uvc_ctx *c); }; -struct uvc_ctx *uvc_open(const char *dev, int width, int height); +struct uvc_ctx *uvc_open(const char *dev, uint32_t width, uint32_t height); int uvc_ioctl(struct uvc_ctx *c, unsigned long int cmd, ...); void uvc_close(struct uvc_ctx *c); diff --git a/gear-lib/libuvc/test_libuvc.c b/gear-lib/libuvc/test_libuvc.c index 5b153afe..8afbac11 100644 --- a/gear-lib/libuvc/test_libuvc.c +++ b/gear-lib/libuvc/test_libuvc.c @@ -40,6 +40,11 @@ int main(int argc, char **argv) struct file *fp; struct video_frame frm; struct uvc_ctx *uvc = uvc_open("/dev/video0", 640, 480); + if (!uvc) { + printf("uvc_open failed!\n"); + return -1; + } + printf("uvc %dx%d format=%s\n", uvc->width, uvc->height, video_format_name(uvc->format)); uvc_ioctl(uvc, UVC_GET_CAP, NULL, 0); fp = file_open("uvc.yuv", F_CREATE); uvc_start_stream(uvc, NULL); @@ -49,7 +54,8 @@ int main(int argc, char **argv) if (size == -1) { continue; } - file_write(fp, frm.data[0], frm.size); + file_write(fp, frm.data[0], frm.total_size); + printf("frm.size=%zu\n", frm.total_size); } file_close(fp); uvc_stop_stream(uvc); diff --git a/gear-lib/libuvc/v4l2.c b/gear-lib/libuvc/v4l2.c index 451387fc..3fcb7d1f 100644 --- a/gear-lib/libuvc/v4l2.c +++ b/gear-lib/libuvc/v4l2.c @@ -75,13 +75,13 @@ struct v4l2_ctx { int channel; /*one video node may contain several input channel */ int standard; int resolution; - int pixfmt; - int linesize; + uint32_t pixfmt; + uint32_t linesize; int dv_timing; int framerate; char *name; - int width; - int height; + uint32_t width; + uint32_t height; struct iovec buf[MAX_V4L_BUF]; int buf_index; int req_count; @@ -97,16 +97,16 @@ struct v4l2_ctx { static int v4l2_init(struct v4l2_ctx *vc); static int v4l2_create_mmap(struct v4l2_ctx *vc); -static int v4l2_set_format(int fd, int *resolution, int *pixelformat, int *bytesperline); +static int v4l2_set_format(int fd, int *resolution, uint32_t *pixelformat, uint32_t *bytesperline); static int v4l2_set_framerate(int fd, int *framerate); static int uvc_v4l2_start_stream(struct uvc_ctx *uvc); -static inline int v4l2_pack_tuple(int a, int b) +static inline int v4l2_pack_tuple(uint32_t a, uint32_t b) { return (a << 16) | (b & 0xffff); } -static void v4l2_unpack_tuple(int *a, int *b, int packed) +static void v4l2_unpack_tuple(uint32_t *a, uint32_t *b, int packed) { *a = packed >> 16; *b = packed & 0xffff; @@ -115,18 +115,18 @@ static void v4l2_unpack_tuple(int *a, int *b, int packed) #define V4L2_FOURCC_STR(code) \ (char[5]) \ { \ - (code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, \ - code & 0xFF, 0 \ + (code&0xFF), ((code>>8)&0xFF), ((code>>16)&0xFF), ((code>>24)&0xFF), \ + 0 \ } #define timeval2ns(tv) \ (((uint64_t)tv.tv_sec * 1000000000) + ((uint64_t)tv.tv_usec * 1000)) -static void *uvc_v4l2_open(struct uvc_ctx *uvc, const char *dev, int width, int height) +static void *uvc_v4l2_open(struct uvc_ctx *uvc, const char *dev, uint32_t width, uint32_t height) { int fd = -1; - int fps_num, fps_denom; + uint32_t fps_num, fps_denom; struct v4l2_ctx *vc = calloc(1, sizeof(struct v4l2_ctx)); if (!vc) { printf("malloc v4l2_ctx failed!\n"); @@ -203,6 +203,7 @@ static void *uvc_v4l2_open(struct uvc_ctx *uvc, const char *dev, int width, int goto failed; } + uvc->format = video_format_from_fourcc(vc->pixfmt); uvc->fd = fd; vc->parent = uvc; return vc; @@ -449,10 +450,10 @@ static void v4l2_get_cid(struct v4l2_ctx *vc) } static int v4l2_set_format(int fd, int *resolution, - int *pixelformat, int *bytesperline) + uint32_t *pixelformat, uint32_t *bytesperline) { bool set = false; - int width, height; + uint32_t width, height; struct v4l2_format fmt; /* We need to set the type in order to query the settings */ @@ -487,7 +488,7 @@ static int v4l2_set_format(int fd, int *resolution, static int v4l2_set_framerate(int fd, int *framerate) { bool set = false; - int num, denom; + uint32_t num, denom; struct v4l2_streamparm par; /* We need to set the type in order to query the stream settings */ @@ -700,9 +701,9 @@ static int uvc_v4l2_dequeue(struct uvc_ctx *uvc, struct video_frame *frame) for (int i = 0; i < VIDEO_MAX_PLANES; ++i) { frame->data[i] = start + plane_offsets[i]; } - frame->size = qbuf.bytesused; + frame->total_size = qbuf.bytesused; - return frame->size; + return frame->total_size; } static void uvc_v4l2_close(struct uvc_ctx *uvc)