FFmpeg
libavcodec
v4l2_m2m.h
Go to the documentation of this file.
1
/*
2
* V4L2 mem2mem helper functions
3
*
4
* Copyright (C) 2017 Alexis Ballier <aballier@gentoo.org>
5
* Copyright (C) 2017 Jorge Ramirez <jorge.ramirez-ortiz@linaro.org>
6
*
7
* This file is part of FFmpeg.
8
*
9
* FFmpeg is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
13
*
14
* FFmpeg is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
18
*
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with FFmpeg; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
*/
23
24
#ifndef AVCODEC_V4L2_M2M_H
25
#define AVCODEC_V4L2_M2M_H
26
27
#include <
semaphore.h
>
28
#include <unistd.h>
29
#include <dirent.h>
30
#include <linux/videodev2.h>
31
32
#include "
libavcodec/avcodec.h
"
33
#include "
v4l2_context.h
"
34
35
#define container_of(ptr, type, member) ({ \
36
const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
37
(type *)((char *)__mptr - offsetof(type,member) );})
38
39
#define V4L_M2M_DEFAULT_OPTS \
40
{ "num_output_buffers", "Number of buffers in the output context",\
41
OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 2, INT_MAX, FLAGS }
42
43
typedef
struct
V4L2m2mContext
{
44
char
devname
[
PATH_MAX
];
45
int
fd
;
46
47
/* the codec context queues */
48
V4L2Context
capture
;
49
V4L2Context
output
;
50
51
/* dynamic stream reconfig */
52
AVCodecContext
*
avctx
;
53
sem_t
refsync
;
54
atomic_uint
refcount
;
55
int
reinit
;
56
57
/* null frame/packet received */
58
int
draining
;
59
AVPacket
buf_pkt
;
60
61
/* Reference to a frame. Only used during encoding */
62
AVFrame
*
frame
;
63
64
/* Reference to self; only valid while codec is active. */
65
struct
V4L2m2mContext
*
self_ref
;
66
67
/* reference back to V4L2m2mPriv */
68
void
*
priv
;
69
}
V4L2m2mContext
;
70
71
typedef
struct
V4L2m2mPriv
{
72
AVClass
*
class
;
73
74
V4L2m2mContext
*
context
;
///< RefStruct reference
75
76
int
num_output_buffers
;
77
int
num_capture_buffers
;
78
}
V4L2m2mPriv
;
79
80
/**
81
* Allocate a new context and references for a V4L2 M2M instance.
82
*
83
* @param[in] ctx The V4L2m2mPriv instantiated by the encoder/decoder.
84
* @param[out] ctx The V4L2m2mContext.
85
*
86
* @returns 0 in success, a negative error code otherwise.
87
*/
88
int
ff_v4l2_m2m_create_context
(
V4L2m2mPriv
*priv,
V4L2m2mContext
**
s
);
89
90
91
/**
92
* Probes the video nodes looking for the required codec capabilities.
93
*
94
* @param[in] ctx The V4L2m2mPriv instantiated by the encoder/decoder.
95
*
96
* @returns 0 if a driver is found, a negative number otherwise.
97
*/
98
int
ff_v4l2_m2m_codec_init
(
V4L2m2mPriv
*priv);
99
100
/**
101
* Releases all the codec resources if all AVBufferRefs have been returned to the
102
* ctx. Otherwise keep the driver open.
103
*
104
* @param[in] The V4L2m2mPriv instantiated by the encoder/decoder.
105
*
106
* @returns 0
107
*
108
*/
109
int
ff_v4l2_m2m_codec_end
(
V4L2m2mPriv
*priv);
110
111
/**
112
* Reinitializes the V4L2m2mContext when the driver cannot continue processing
113
* with the capture parameters.
114
*
115
* @param[in] ctx The V4L2m2mContext instantiated by the encoder/decoder.
116
*
117
* @returns 0 in case of success, negative number otherwise
118
*/
119
int
ff_v4l2_m2m_codec_reinit
(
V4L2m2mContext
*
ctx
);
120
121
/**
122
* Reinitializes the V4L2m2mContext when the driver cannot continue processing
123
* with the any of the current V4L2Contexts (ie, changes in output and capture).
124
*
125
* @param[in] ctx The V4L2m2mContext instantiated by the encoder/decoder.
126
*
127
* @returns 0 in case of success, negative number otherwise
128
*/
129
int
ff_v4l2_m2m_codec_full_reinit
(
V4L2m2mContext
*
ctx
);
130
131
#endif
/* AVCODEC_V4L2_M2M_H */
V4L2m2mContext::refsync
sem_t refsync
Definition:
v4l2_m2m.h:53
V4L2m2mContext::reinit
int reinit
Definition:
v4l2_m2m.h:55
sem_t
#define sem_t
Definition:
semaphore.h:25
V4L2m2mContext
Definition:
v4l2_m2m.h:43
AVFrame
This structure describes decoded (raw) audio or video data.
Definition:
frame.h:389
V4L2m2mPriv::context
V4L2m2mContext * context
RefStruct reference.
Definition:
v4l2_m2m.h:74
ff_v4l2_m2m_create_context
int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s)
Allocate a new context and references for a V4L2 M2M instance.
Definition:
v4l2_m2m.c:328
V4L2m2mContext::self_ref
struct V4L2m2mContext * self_ref
Definition:
v4l2_m2m.h:65
semaphore.h
s
#define s(width, name)
Definition:
cbs_vp9.c:198
V4L2m2mContext::capture
V4L2Context capture
Definition:
v4l2_m2m.h:48
ctx
AVFormatContext * ctx
Definition:
movenc.c:49
V4L2m2mContext::devname
char devname[PATH_MAX]
Definition:
v4l2_m2m.h:44
AVClass
Describe the class of an AVClass context structure.
Definition:
log.h:75
V4L2Context
Definition:
v4l2_context.h:37
PATH_MAX
#define PATH_MAX
Definition:
ipfsgateway.c:34
ff_v4l2_m2m_codec_full_reinit
int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *ctx)
Reinitializes the V4L2m2mContext when the driver cannot continue processing with the any of the curre...
V4L2m2mContext::draining
int draining
Definition:
v4l2_m2m.h:58
V4L2m2mPriv::num_output_buffers
int num_output_buffers
Definition:
v4l2_m2m.h:76
V4L2m2mContext::output
V4L2Context output
Definition:
v4l2_m2m.h:49
V4L2m2mContext::priv
void * priv
Definition:
v4l2_m2m.h:68
ff_v4l2_m2m_codec_init
int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv)
Probes the video nodes looking for the required codec capabilities.
Definition:
v4l2_m2m.c:290
V4L2m2mContext::buf_pkt
AVPacket buf_pkt
Definition:
v4l2_m2m.h:59
V4L2m2mContext::avctx
AVCodecContext * avctx
Definition:
v4l2_m2m.h:52
V4L2m2mContext::refcount
atomic_uint refcount
Definition:
v4l2_m2m.h:54
v4l2_context.h
avcodec.h
ff_v4l2_m2m_codec_reinit
int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *ctx)
Reinitializes the V4L2m2mContext when the driver cannot continue processing with the capture paramete...
Definition:
v4l2_m2m.c:208
ff_v4l2_m2m_codec_end
int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv)
Releases all the codec resources if all AVBufferRefs have been returned to the ctx.
Definition:
v4l2_m2m.c:264
AVCodecContext
main external API structure.
Definition:
avcodec.h:451
V4L2m2mPriv::num_capture_buffers
int num_capture_buffers
Definition:
v4l2_m2m.h:77
V4L2m2mPriv
Definition:
v4l2_m2m.h:71
atomic_uint
intptr_t atomic_uint
Definition:
stdatomic.h:56
V4L2m2mContext::fd
int fd
Definition:
v4l2_m2m.h:45
AVPacket
This structure stores compressed data.
Definition:
packet.h:516
V4L2m2mContext::frame
AVFrame * frame
Definition:
v4l2_m2m.h:62
Generated on Sat Nov 2 2024 19:22:02 for FFmpeg by
1.8.17