Skip to content

Commit

Permalink
fix compile error of type
Browse files Browse the repository at this point in the history
  • Loading branch information
gozfree committed Dec 21, 2019
1 parent 305c9fc commit 0b539d6
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 38 deletions.
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion gear-lib/libmedia-io/libmedia-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern "C" {

#include "audio-def.h"
#include "video-def.h"
#include "memalign.h"

struct media_frame {
union {
Expand Down
36 changes: 36 additions & 0 deletions gear-lib/libmedia-io/memalign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/******************************************************************************
* Copyright (C) 2014-2020 Zhifeng Gong <gozfree@163.com>
*
* 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
22 changes: 11 additions & 11 deletions gear-lib/libmedia-io/video-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libmedia-io/video-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libuvc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CFLAGS += -I$(OUTPUT)/include
SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -pthread
LDFLAGS += -pthread -lmedia-io
# -lv4l2

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion gear-lib/libuvc/libuvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions gear-lib/libuvc/libuvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion gear-lib/libuvc/test_libuvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
33 changes: 17 additions & 16 deletions gear-lib/libuvc/v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0b539d6

Please sign in to comment.