FFmpeg
cbs_bsf.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVCODEC_CBS_BSF_H
20 #define AVCODEC_CBS_BSF_H
21 
22 #include "libavutil/log.h"
23 #include "libavutil/opt.h"
24 
25 #include "bsf.h"
26 #include "codec_id.h"
27 #include "cbs.h"
28 #include "packet.h"
29 
30 
31 typedef struct CBSBSFType {
33 
34  // Name of a frame fragment in this codec (e.g. "access unit",
35  // "temporal unit").
36  const char *fragment_name;
37 
38  // Name of a unit for this BSF, for use in error messages (e.g.
39  // "NAL unit", "OBU").
40  const char *unit_name;
41 
42  // Update the content of a fragment with whatever metadata changes
43  // are desired. The associated AVPacket is provided so that any side
44  // data associated with the fragment can be inspected or edited. If
45  // pkt is NULL, then an extradata header fragment is being updated.
48 } CBSBSFType;
49 
50 // Common structure for all generic CBS BSF users. An instance of this
51 // structure must be the first member of the BSF private context (to be
52 // pointed to by AVBSFContext.priv_data).
53 typedef struct CBSBSFContext {
54  const AVClass *class;
55  const CBSBSFType *type;
56 
61 
62 /**
63  * Initialise generic CBS BSF setup.
64  *
65  * Creates the input and output CBS instances, and applies the filter to
66  * the extradata on the input codecpar if any is present.
67  *
68  * Since it calls the update_fragment() function immediately to deal with
69  * extradata, this should be called after any codec-specific setup is done
70  * (probably at the end of the FFBitStreamFilter.init function).
71  */
73 
74 /**
75  * Close a generic CBS BSF instance.
76  *
77  * If no other deinitialisation is required then this function can be used
78  * directly as FFBitStreamFilter.close.
79  */
81 
82 /**
83  * Filter operation for CBS BSF.
84  *
85  * Reads the input packet into a CBS fragment, calls update_fragment() on
86  * it, then writes the result to an output packet. If the input packet
87  * has AV_PKT_DATA_NEW_EXTRADATA side-data associated with it then it does
88  * the same thing to that new extradata to form the output side-data first.
89  *
90  * If the BSF does not do anything else then this function can be used
91  * directly as FFBitStreamFilter.filter.
92  */
94 
95 
96 // Options for element manipulation.
97 enum {
98  // Pass this element through unchanged.
100  // Insert this element, replacing any existing instances of it.
101  // Associated values may be provided explicitly (as additional options)
102  // or implicitly (either as side data or deduced from other parts of
103  // the stream).
105  // Remove this element if it appears in the stream.
107  // Extract this element to side data, so that further manipulation
108  // can happen elsewhere.
110 };
111 
112 #define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags) \
113  { name, help, OFFSET(field), AV_OPT_TYPE_INT, \
114  { .i64 = BSF_ELEMENT_PASS }, \
115  BSF_ELEMENT_PASS, BSF_ELEMENT_REMOVE, opt_flags, .unit = name }, \
116  { "pass", NULL, 0, AV_OPT_TYPE_CONST, \
117  { .i64 = BSF_ELEMENT_PASS }, .flags = opt_flags, .unit = name }, \
118  { "insert", NULL, 0, AV_OPT_TYPE_CONST, \
119  { .i64 = BSF_ELEMENT_INSERT }, .flags = opt_flags, .unit = name }, \
120  { "remove", NULL, 0, AV_OPT_TYPE_CONST, \
121  { .i64 = BSF_ELEMENT_REMOVE }, .flags = opt_flags, .unit = name }
122 
123 #define BSF_ELEMENT_OPTIONS_PIRE(name, help, field, opt_flags) \
124  { name, help, OFFSET(field), AV_OPT_TYPE_INT, \
125  { .i64 = BSF_ELEMENT_PASS }, \
126  BSF_ELEMENT_PASS, BSF_ELEMENT_EXTRACT, opt_flags, .unit = name }, \
127  { "pass", NULL, 0, AV_OPT_TYPE_CONST, \
128  { .i64 = BSF_ELEMENT_PASS }, .flags = opt_flags, .unit = name }, \
129  { "insert", NULL, 0, AV_OPT_TYPE_CONST, \
130  { .i64 = BSF_ELEMENT_INSERT }, .flags = opt_flags, .unit = name }, \
131  { "remove", NULL, 0, AV_OPT_TYPE_CONST, \
132  { .i64 = BSF_ELEMENT_REMOVE }, .flags = opt_flags, .unit = name }, \
133  { "extract", NULL, 0, AV_OPT_TYPE_CONST, \
134  { .i64 = BSF_ELEMENT_EXTRACT }, .flags = opt_flags, .unit = name } \
135 
136 
137 #endif /* AVCODEC_CBS_BSF_H */
opt.h
CBSBSFType::codec_id
enum AVCodecID codec_id
Definition: cbs_bsf.h:32
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
CBSBSFContext
Definition: cbs_bsf.h:53
cbs.h
ff_cbs_bsf_generic_filter
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
Definition: cbs_bsf.c:61
CBSBSFContext::input
CodedBitstreamContext * input
Definition: cbs_bsf.h:57
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
CBSBSFType::fragment_name
const char * fragment_name
Definition: cbs_bsf.h:36
BSF_ELEMENT_REMOVE
@ BSF_ELEMENT_REMOVE
Definition: cbs_bsf.h:106
bsf.h
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
CBSBSFType::update_fragment
int(* update_fragment)(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *frag)
Definition: cbs_bsf.h:46
pkt
AVPacket * pkt
Definition: movenc.c:59
codec_id.h
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
CBSBSFType::unit_name
const char * unit_name
Definition: cbs_bsf.h:40
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
BSF_ELEMENT_PASS
@ BSF_ELEMENT_PASS
Definition: cbs_bsf.h:99
CBSBSFContext::fragment
CodedBitstreamFragment fragment
Definition: cbs_bsf.h:59
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
CBSBSFType
Definition: cbs_bsf.h:31
ff_cbs_bsf_generic_init
int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition: cbs_bsf.c:110
log.h
packet.h
CBSBSFContext::type
const CBSBSFType * type
Definition: cbs_bsf.h:55
ff_cbs_bsf_generic_close
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition: cbs_bsf.c:155
AVPacket
This structure stores compressed data.
Definition: packet.h:499
BSF_ELEMENT_EXTRACT
@ BSF_ELEMENT_EXTRACT
Definition: cbs_bsf.h:109
int
int
Definition: ffmpeg_filter.c:409
CBSBSFContext::output
CodedBitstreamContext * output
Definition: cbs_bsf.h:58
BSF_ELEMENT_INSERT
@ BSF_ELEMENT_INSERT
Definition: cbs_bsf.h:104