Skip to content

Commit 0b539d6

Browse files
committed
fix compile error of type
1 parent 305c9fc commit 0b539d6

File tree

10 files changed

+80
-38
lines changed

10 files changed

+80
-38
lines changed

build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ build_module()
152152
*)
153153
MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE}"
154154
if [[ ${ARCH} == "linux" || ${ARCH} == "pi" || ${ARCH} == "android" ]]; then
155-
${MAKE}
156-
#> /dev/null
155+
${MAKE} > /dev/null
157156
else
158157
echo "${ARCH} not support now" #make -f Makefile.${ARCH} > /dev/null
159158
fi

gear-lib/libmedia-io/libmedia-io.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern "C" {
2828

2929
#include "audio-def.h"
3030
#include "video-def.h"
31-
#include "memalign.h"
3231

3332
struct media_frame {
3433
union {

gear-lib/libmedia-io/memalign.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/******************************************************************************
2+
* Copyright (C) 2014-2020 Zhifeng Gong <[email protected]>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
******************************************************************************/
22+
#ifndef MEMALIGN_H
23+
#define MEMALIGN_H
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
30+
#define ALIGNMENT 32
31+
#define ALIGN_SIZE(size, align) (((size) + (align - 1)) & (~(align - 1)))
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
#endif

gear-lib/libmedia-io/video-def.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct video_frame *video_frame_create(enum video_format format,
130130
offsets[1] = size;
131131
size += (width / 2) * (height / 2);
132132
size = ALIGN_SIZE(size, ALIGNMENT);
133-
frame->totoal_size = size;
133+
frame->total_size = size;
134134
frame->data[0] = memalign(ALIGNMENT, size);
135135
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
136136
frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];
@@ -144,7 +144,7 @@ struct video_frame *video_frame_create(enum video_format format,
144144
offsets[0] = size;
145145
size += (width / 2) * (height / 2) * 2;
146146
size = ALIGN_SIZE(size, ALIGNMENT);
147-
frame->totoal_size = size;
147+
frame->total_size = size;
148148
frame->data[0] = memalign(ALIGNMENT, size);
149149
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
150150
frame->linesize[0] = width;
@@ -153,7 +153,7 @@ struct video_frame *video_frame_create(enum video_format format,
153153
case VIDEO_FORMAT_Y800:
154154
size = width * height;
155155
size = ALIGN_SIZE(size, ALIGNMENT);
156-
frame->totoal_size = size;
156+
frame->total_size = size;
157157
frame->data[0] = memalign(ALIGNMENT, size);
158158
frame->linesize[0] = width;
159159
break;
@@ -162,7 +162,7 @@ struct video_frame *video_frame_create(enum video_format format,
162162
case VIDEO_FORMAT_UYVY:
163163
size = width * height * 2;
164164
size = ALIGN_SIZE(size, ALIGNMENT);
165-
frame->totoal_size = size;
165+
frame->total_size = size;
166166
frame->data[0] = memalign(ALIGNMENT, size);
167167
frame->linesize[0] = width * 2;
168168
break;
@@ -172,14 +172,14 @@ struct video_frame *video_frame_create(enum video_format format,
172172
case VIDEO_FORMAT_AYUV:
173173
size = width * height * 4;
174174
size = ALIGN_SIZE(size, ALIGNMENT);
175-
frame->totoal_size = size;
175+
frame->total_size = size;
176176
frame->data[0] = memalign(ALIGNMENT, size);
177177
frame->linesize[0] = width * 4;
178178
break;
179179
case VIDEO_FORMAT_I444:
180180
size = width * height;
181181
size = ALIGN_SIZE(size, ALIGNMENT);
182-
frame->totoal_size = size;
182+
frame->total_size = size;
183183
frame->data[0] = memalign(ALIGNMENT, size * 3);
184184
frame->data[1] = (uint8_t *)frame->data[0] + size;
185185
frame->data[2] = (uint8_t *)frame->data[1] + size;
@@ -190,7 +190,7 @@ struct video_frame *video_frame_create(enum video_format format,
190190
case VIDEO_FORMAT_BGR3:
191191
size = width * height * 3;
192192
size = ALIGN_SIZE(size, ALIGNMENT);
193-
frame->totoal_size = size;
193+
frame->total_size = size;
194194
frame->data[0] = memalign(ALIGNMENT, size);
195195
frame->linesize[0] = width * 3;
196196
break;
@@ -203,7 +203,7 @@ struct video_frame *video_frame_create(enum video_format format,
203203
offsets[1] = size;
204204
size += (width / 2) * height;
205205
size = ALIGN_SIZE(size, ALIGNMENT);
206-
frame->totoal_size = size;
206+
frame->total_size = size;
207207
frame->data[0] = memalign(ALIGNMENT, size);
208208
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
209209
frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];
@@ -223,7 +223,7 @@ struct video_frame *video_frame_create(enum video_format format,
223223
offsets[2] = size;
224224
size += width * height;
225225
size = ALIGN_SIZE(size, ALIGNMENT);
226-
frame->totoal_size = size;
226+
frame->total_size = size;
227227
frame->data[0] = memalign(ALIGNMENT, size);
228228
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
229229
frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];
@@ -245,7 +245,7 @@ struct video_frame *video_frame_create(enum video_format format,
245245
offsets[2] = size;
246246
size += width * height;
247247
size = ALIGN_SIZE(size, ALIGNMENT);
248-
frame->totoal_size = size;
248+
frame->total_size = size;
249249
frame->data[0] = memalign(ALIGNMENT, size);
250250
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
251251
frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];
@@ -267,7 +267,7 @@ struct video_frame *video_frame_create(enum video_format format,
267267
offsets[2] = size;
268268
size += width * height;
269269
size = ALIGN_SIZE(size, ALIGNMENT);
270-
frame->totoal_size = size;
270+
frame->total_size = size;
271271
frame->data[0] = memalign(ALIGNMENT, size);
272272
frame->data[1] = (uint8_t *)frame->data[0] + offsets[0];
273273
frame->data[2] = (uint8_t *)frame->data[0] + offsets[1];

gear-lib/libmedia-io/video-def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct video_frame {
8888
uint32_t width;
8989
uint32_t height;
9090
uint64_t timestamp;//ns
91-
uint64_t totoal_size;
91+
uint64_t total_size;
9292
uint64_t id;
9393
uint8_t **extended_data;
9494
void *opaque;

gear-lib/libuvc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ CFLAGS += -I$(OUTPUT)/include
6767
SHARED := -shared
6868

6969
LDFLAGS := $($(ARCH)_LDFLAGS)
70-
LDFLAGS += -pthread
70+
LDFLAGS += -pthread -lmedia-io
7171
# -lv4l2
7272

7373
###############################################################################

gear-lib/libuvc/libuvc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static struct uvc_ops *uvc_ops[] = {
4343
NULL
4444
};
4545

46-
struct uvc_ctx *uvc_open(const char *dev, int width, int height)
46+
struct uvc_ctx *uvc_open(const char *dev, uint32_t width, uint32_t height)
4747
{
4848
struct uvc_ctx *uvc = (struct uvc_ctx *)calloc(1, sizeof(struct uvc_ctx));
4949
if (!uvc) {

gear-lib/libuvc/libuvc.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ typedef int (*on_stream_data)(struct uvc_ctx *c, void *data, size_t len);
4343

4444
struct uvc_ctx {
4545
int fd;
46-
int width;
47-
int height;
46+
uint32_t width;
47+
uint32_t height;
48+
enum video_format format;
4849
struct uvc_ops *ops;
4950
void *opaque;
5051
on_stream_data *on_data;
@@ -64,7 +65,7 @@ struct video_ctrl {
6465
#define UVC_SET_CTRL _IOWR('V', 1, struct video_ctrl)
6566

6667
struct uvc_ops {
67-
void *(*open)(struct uvc_ctx *uvc, const char *dev, int width, int height);
68+
void *(*open)(struct uvc_ctx *uvc, const char *dev, uint32_t width, uint32_t height);
6869
void (*close)(struct uvc_ctx *c);
6970
int (*dequeue)(struct uvc_ctx *c, struct video_frame *frame);
7071
int (*enqueue)(struct uvc_ctx *c, void *buf, size_t len);
@@ -74,7 +75,7 @@ struct uvc_ops {
7475
int (*stop_stream)(struct uvc_ctx *c);
7576
};
7677

77-
struct uvc_ctx *uvc_open(const char *dev, int width, int height);
78+
struct uvc_ctx *uvc_open(const char *dev, uint32_t width, uint32_t height);
7879
int uvc_ioctl(struct uvc_ctx *c, unsigned long int cmd, ...);
7980
void uvc_close(struct uvc_ctx *c);
8081

gear-lib/libuvc/test_libuvc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ int main(int argc, char **argv)
4040
struct file *fp;
4141
struct video_frame frm;
4242
struct uvc_ctx *uvc = uvc_open("/dev/video0", 640, 480);
43+
if (!uvc) {
44+
printf("uvc_open failed!\n");
45+
return -1;
46+
}
47+
printf("uvc %dx%d format=%s\n", uvc->width, uvc->height, video_format_name(uvc->format));
4348
uvc_ioctl(uvc, UVC_GET_CAP, NULL, 0);
4449
fp = file_open("uvc.yuv", F_CREATE);
4550
uvc_start_stream(uvc, NULL);
@@ -49,7 +54,8 @@ int main(int argc, char **argv)
4954
if (size == -1) {
5055
continue;
5156
}
52-
file_write(fp, frm.data[0], frm.size);
57+
file_write(fp, frm.data[0], frm.total_size);
58+
printf("frm.size=%zu\n", frm.total_size);
5359
}
5460
file_close(fp);
5561
uvc_stop_stream(uvc);

gear-lib/libuvc/v4l2.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ struct v4l2_ctx {
7575
int channel; /*one video node may contain several input channel */
7676
int standard;
7777
int resolution;
78-
int pixfmt;
79-
int linesize;
78+
uint32_t pixfmt;
79+
uint32_t linesize;
8080
int dv_timing;
8181
int framerate;
8282
char *name;
83-
int width;
84-
int height;
83+
uint32_t width;
84+
uint32_t height;
8585
struct iovec buf[MAX_V4L_BUF];
8686
int buf_index;
8787
int req_count;
@@ -97,16 +97,16 @@ struct v4l2_ctx {
9797

9898
static int v4l2_init(struct v4l2_ctx *vc);
9999
static int v4l2_create_mmap(struct v4l2_ctx *vc);
100-
static int v4l2_set_format(int fd, int *resolution, int *pixelformat, int *bytesperline);
100+
static int v4l2_set_format(int fd, int *resolution, uint32_t *pixelformat, uint32_t *bytesperline);
101101
static int v4l2_set_framerate(int fd, int *framerate);
102102
static int uvc_v4l2_start_stream(struct uvc_ctx *uvc);
103103

104-
static inline int v4l2_pack_tuple(int a, int b)
104+
static inline int v4l2_pack_tuple(uint32_t a, uint32_t b)
105105
{
106106
return (a << 16) | (b & 0xffff);
107107
}
108108

109-
static void v4l2_unpack_tuple(int *a, int *b, int packed)
109+
static void v4l2_unpack_tuple(uint32_t *a, uint32_t *b, int packed)
110110
{
111111
*a = packed >> 16;
112112
*b = packed & 0xffff;
@@ -115,18 +115,18 @@ static void v4l2_unpack_tuple(int *a, int *b, int packed)
115115
#define V4L2_FOURCC_STR(code) \
116116
(char[5]) \
117117
{ \
118-
(code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, \
119-
code & 0xFF, 0 \
118+
(code&0xFF), ((code>>8)&0xFF), ((code>>16)&0xFF), ((code>>24)&0xFF), \
119+
0 \
120120
}
121121

122122
#define timeval2ns(tv) \
123123
(((uint64_t)tv.tv_sec * 1000000000) + ((uint64_t)tv.tv_usec * 1000))
124124

125125

126-
static void *uvc_v4l2_open(struct uvc_ctx *uvc, const char *dev, int width, int height)
126+
static void *uvc_v4l2_open(struct uvc_ctx *uvc, const char *dev, uint32_t width, uint32_t height)
127127
{
128128
int fd = -1;
129-
int fps_num, fps_denom;
129+
uint32_t fps_num, fps_denom;
130130
struct v4l2_ctx *vc = calloc(1, sizeof(struct v4l2_ctx));
131131
if (!vc) {
132132
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
203203
goto failed;
204204
}
205205

206+
uvc->format = video_format_from_fourcc(vc->pixfmt);
206207
uvc->fd = fd;
207208
vc->parent = uvc;
208209
return vc;
@@ -449,10 +450,10 @@ static void v4l2_get_cid(struct v4l2_ctx *vc)
449450
}
450451

451452
static int v4l2_set_format(int fd, int *resolution,
452-
int *pixelformat, int *bytesperline)
453+
uint32_t *pixelformat, uint32_t *bytesperline)
453454
{
454455
bool set = false;
455-
int width, height;
456+
uint32_t width, height;
456457
struct v4l2_format fmt;
457458

458459
/* 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,
487488
static int v4l2_set_framerate(int fd, int *framerate)
488489
{
489490
bool set = false;
490-
int num, denom;
491+
uint32_t num, denom;
491492
struct v4l2_streamparm par;
492493

493494
/* 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)
700701
for (int i = 0; i < VIDEO_MAX_PLANES; ++i) {
701702
frame->data[i] = start + plane_offsets[i];
702703
}
703-
frame->size = qbuf.bytesused;
704+
frame->total_size = qbuf.bytesused;
704705

705-
return frame->size;
706+
return frame->total_size;
706707
}
707708

708709
static void uvc_v4l2_close(struct uvc_ctx *uvc)

0 commit comments

Comments
 (0)