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
|
/*
* V4L2 buffer helper functions.
*
* Copyright (C) 2017 Alexis Ballier <aballier@gentoo.org>
* Copyright (C) 2017 Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_V4L2_BUFFERS_H
#define AVCODEC_V4L2_BUFFERS_H
#include <linux/videodev2.h>
#include "avcodec.h"
enum V4L2Buffer_status {
V4L2BUF_AVAILABLE,
V4L2BUF_IN_DRIVER,
V4L2BUF_RET_USER,
};
/**
* V4L2Buffer (wrapper for v4l2_buffer management)
*/
typedef struct V4L2Buffer {
/* each buffer needs to have a reference to its context */
struct V4L2Context *context;
/* keep track of the mmap address and mmap length */
struct V4L2Plane_info {
int bytesperline;
void * mm_addr;
size_t length;
} plane_info[VIDEO_MAX_PLANES];
int num_planes;
/* the v4l2_buffer buf.m.planes pointer uses the planes[] mem */
struct v4l2_buffer buf;
struct v4l2_plane planes[VIDEO_MAX_PLANES];
int flags;
enum V4L2Buffer_status status;
} V4L2Buffer;
/**
* Extracts the data from a V4L2Buffer to an AVFrame
*
* @param[in] frame The AVFRame to push the information to
* @param[in] buf The V4L2Buffer to get the information from
*
* @returns 0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect,
* AVERROR(ENOMEM) if the AVBufferRef cant be created.
*/
int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *buf);
/**
* Extracts the data from a V4L2Buffer to an AVPacket
*
* @param[in] pkt The AVPacket to push the information to
* @param[in] buf The V4L2Buffer to get the information from
*
* @returns 0 in case of success, AVERROR(EINVAL) if the number of planes is incorrect,
* AVERROR(ENOMEM) if the AVBufferRef cant be created.
*
*/
int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *buf);
/**
* Extracts the data from an AVPacket to a V4L2Buffer
*
* @param[in] frame AVPacket to get the data from
* @param[in] avbuf V4L2Bfuffer to push the information to
*
* @returns 0 in case of success, a negative AVERROR code otherwise
*/
int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, V4L2Buffer *out);
/**
* Extracts the data from an AVFrame to a V4L2Buffer
*
* @param[in] frame AVFrame to get the data from
* @param[in] avbuf V4L2Bfuffer to push the information to
*
* @returns 0 in case of success, a negative AVERROR code otherwise
*/
int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer* out);
/**
* Initializes a V4L2Buffer
*
* @param[in] avbuf V4L2Bfuffer to initialize
* @param[in] index v4l2 buffer id
*
* @returns 0 in case of success, a negative AVERROR code otherwise
*/
int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf, int index);
/**
* Enqueues a V4L2Buffer
*
* @param[in] avbuf V4L2Bfuffer to push to the driver
*
* @returns 0 in case of success, a negative AVERROR code otherwise
*/
int ff_v4l2_buffer_enqueue(V4L2Buffer* avbuf);
#endif // AVCODEC_V4L2_BUFFERS_H
|