-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathv4l2-hantro-h264-encoder.c
87 lines (67 loc) · 1.33 KB
/
v4l2-hantro-h264-encoder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (C) 2020 Bootlin
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/videodev2.h>
#include <linux/media.h>
#include <v4l2.h>
#include <v4l2-encoder.h>
int main(int argc, char *argv[])
{
struct v4l2_encoder *encoder = NULL;
unsigned int width = 640;
unsigned int height = 480;
unsigned int frames = 10;
int ret;
encoder = calloc(1, sizeof(*encoder));
if (!encoder)
goto error;
ret = v4l2_encoder_open(encoder);
if (ret)
goto error;
ret = v4l2_encoder_probe(encoder);
if (ret)
goto error;
ret = v4l2_encoder_setup_defaults(encoder);
if (ret)
goto error;
ret = v4l2_encoder_setup_dimensions(encoder, width, height);
if (ret)
return ret;
ret = v4l2_encoder_setup(encoder);
if (ret)
goto error;
ret = v4l2_encoder_start(encoder);
if (ret)
goto error;
while (frames--) {
ret = v4l2_encoder_prepare(encoder);
if (ret)
goto error;
ret = v4l2_encoder_run(encoder);
if (ret)
goto error;
ret = v4l2_encoder_complete(encoder);
if (ret)
goto error;
}
ret = 0;
goto complete;
error:
ret = 1;
complete:
if (encoder) {
v4l2_encoder_stop(encoder);
v4l2_encoder_teardown(encoder);
v4l2_encoder_close(encoder);
free(encoder);
}
return ret;
}