-
Notifications
You must be signed in to change notification settings - Fork 4
/
v4l2-encoder.h
144 lines (110 loc) · 3.62 KB
/
v4l2-encoder.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2019-2020 Paul Kocialkowski <[email protected]>
* Copyright (C) 2020 Bootlin
*/
#ifndef _V4L2_ENCODER_H_
#define _V4L2_ENCODER_H_
#include <linux/videodev2.h>
#include <h264-rate-control.h>
#include <draw.h>
struct v4l2_encoder;
struct v4l2_encoder_buffer {
struct v4l2_encoder *encoder;
struct v4l2_buffer buffer;
struct v4l2_plane planes[4];
void *mmap_data[4];
unsigned int planes_count;
int request_fd;
};
struct v4l2_encoder_h264_src_controls {
struct v4l2_ext_controls ext_controls;
struct v4l2_ext_control controls[2];
unsigned int controls_count;
struct v4l2_ctrl_h264_encode_params encode_params;
struct v4l2_ext_control *encode_params_control;
struct v4l2_ctrl_h264_encode_rc encode_rc;
struct v4l2_ext_control *encode_rc_control;
};
struct v4l2_encoder_h264_dst_controls {
struct v4l2_ext_controls ext_controls;
struct v4l2_ext_control controls[1];
unsigned int controls_count;
struct v4l2_ext_control *encode_feedback_control;
struct v4l2_ctrl_h264_encode_feedback encode_feedback;
};
struct v4l2_encoder_setup {
/* Dimensions */
unsigned int width;
unsigned int width_mbs;
unsigned int height;
unsigned int height_mbs;
/* Format */
uint32_t format;
/* Framerate */
unsigned int fps_num;
unsigned int fps_den;
/* Bitrate */
uint64_t bitrate;
unsigned int gop_size;
/* Quality */
unsigned int qp_intra_delta;
unsigned int qp_min;
unsigned int qp_max;
};
struct v4l2_encoder {
int video_fd;
int media_fd;
char driver[32];
char card[32];
unsigned int capabilities;
unsigned int memory;
bool up;
bool started;
struct v4l2_encoder_setup setup;
unsigned int output_type;
unsigned int output_capabilities;
struct v4l2_format output_format;
struct v4l2_encoder_buffer output_buffers[3];
unsigned int output_buffers_count;
unsigned int output_buffers_index;
unsigned int capture_type;
unsigned int capture_capabilities;
struct v4l2_format capture_format;
struct v4l2_encoder_buffer capture_buffers[3];
unsigned int capture_buffers_count;
unsigned int capture_buffers_index;
struct v4l2_encoder_h264_src_controls h264_src_controls;
struct v4l2_encoder_h264_dst_controls h264_dst_controls;
struct v4l2_ctrl_h264_sps sps;
struct v4l2_ctrl_h264_pps pps;
struct h264_rate_control rc;
uint64_t reference_timestamp;
unsigned int gop_index;
struct draw_mandelbrot draw_mandelbrot;
struct draw_buffer *draw_buffer;
unsigned int x, y;
bool pattern_drawn;
bool direction;
int bitstream_fd;
};
int v4l2_encoder_prepare(struct v4l2_encoder *encoder);
int v4l2_encoder_complete(struct v4l2_encoder *encoder);
int v4l2_encoder_run(struct v4l2_encoder *encoder);
int v4l2_encoder_start(struct v4l2_encoder *encoder);
int v4l2_encoder_stop(struct v4l2_encoder *encoder);
int v4l2_encoder_intra_request(struct v4l2_encoder *encoder);
int v4l2_encoder_buffer_setup(struct v4l2_encoder_buffer *buffer,
unsigned int type, unsigned int index);
int v4l2_encoder_buffer_teardown(struct v4l2_encoder_buffer *buffer);
int v4l2_encoder_setup_defaults(struct v4l2_encoder *encoder);
int v4l2_encoder_setup_dimensions(struct v4l2_encoder *encoder,
unsigned int width, unsigned int height);
int v4l2_encoder_setup_format(struct v4l2_encoder *encoder, uint32_t format);
int v4l2_encoder_setup_fps(struct v4l2_encoder *encoder, float fps);
int v4l2_encoder_setup_bitrate(struct v4l2_encoder *encoder, uint64_t bitrate);
int v4l2_encoder_setup(struct v4l2_encoder *encoder);
int v4l2_encoder_teardown(struct v4l2_encoder *encoder);
int v4l2_encoder_probe(struct v4l2_encoder *encoder);
int v4l2_encoder_open(struct v4l2_encoder *encoder);
void v4l2_encoder_close(struct v4l2_encoder *encoder);
#endif