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 "cbs.h"
23 
24 
25 typedef struct CBSBSFType {
27 
28  // Name of a frame fragment in this codec (e.g. "access unit",
29  // "temporal unit").
30  const char *fragment_name;
31 
32  // Name of a unit for this BSF, for use in error messages (e.g.
33  // "NAL unit", "OBU").
34  const char *unit_name;
35 
36  // Update the content of a fragment with whatever metadata changes
37  // are desired. The associated AVPacket is provided so that any side
38  // data associated with the fragment can be inspected or edited. If
39  // pkt is NULL, then an extradata header fragment is being updated.
42 } CBSBSFType;
43 
44 // Common structure for all generic CBS BSF users. An instance of this
45 // structure must be the first member of the BSF private context (to be
46 // pointed to by AVBSFContext.priv_data).
47 typedef struct CBSBSFContext {
48  const AVClass *class;
49  const CBSBSFType *type;
50 
55 
56 /**
57  * Initialise generic CBS BSF setup.
58  *
59  * Creates the input and output CBS instances, and applies the filter to
60  * the extradata on the input codecpar if any is present.
61  *
62  * Since it calls the update_fragment() function immediately to deal with
63  * extradata, this should be called after any codec-specific setup is done
64  * (probably at the end of the AVBitStreamFilter.init function).
65  */
67 
68 /**
69  * Close a generic CBS BSF instance.
70  *
71  * If no other deinitialisation is required then this function can be used
72  * directly as AVBitStreamFilter.close.
73  */
75 
76 /**
77  * Filter operation for CBS BSF.
78  *
79  * Reads the input packet into a CBS fragment, calls update_fragment() on
80  * it, then writes the result to an output packet. If the input packet
81  * has AV_PKT_DATA_NEW_EXTRADATA side-data associated with it then it does
82  * the same thing to that new extradata to form the output side-data first.
83  *
84  * If the BSF does not do anything else then this function can be used
85  * directly as AVBitStreamFilter.filter.
86  */
88 
89 
90 // Options for element manipulation.
91 enum {
92  // Pass this element through unchanged.
94  // Insert this element, replacing any existing instances of it.
95  // Associated values may be provided explicitly (as addtional options)
96  // or implicitly (either as side data or deduced from other parts of
97  // the stream).
99  // Remove this element if it appears in the stream.
101  // Extract this element to side data, so that further manipulation
102  // can happen elsewhere.
104 };
105 
106 #define BSF_ELEMENT_OPTIONS_PIR(name, help, field, opt_flags) \
107  { name, help, OFFSET(field), AV_OPT_TYPE_INT, \
108  { .i64 = BSF_ELEMENT_PASS }, \
109  BSF_ELEMENT_PASS, BSF_ELEMENT_REMOVE, opt_flags, name }, \
110  { "pass", NULL, 0, AV_OPT_TYPE_CONST, \
111  { .i64 = BSF_ELEMENT_PASS }, .flags = opt_flags, .unit = name }, \
112  { "insert", NULL, 0, AV_OPT_TYPE_CONST, \
113  { .i64 = BSF_ELEMENT_INSERT }, .flags = opt_flags, .unit = name }, \
114  { "remove", NULL, 0, AV_OPT_TYPE_CONST, \
115  { .i64 = BSF_ELEMENT_REMOVE }, .flags = opt_flags, .unit = name }
116 
117 #define BSF_ELEMENT_OPTIONS_PIRE(name, help, field, opt_flags) \
118  { name, help, OFFSET(field), AV_OPT_TYPE_INT, \
119  { .i64 = BSF_ELEMENT_PASS }, \
120  BSF_ELEMENT_PASS, BSF_ELEMENT_EXTRACT, opt_flags, name }, \
121  { "pass", NULL, 0, AV_OPT_TYPE_CONST, \
122  { .i64 = BSF_ELEMENT_PASS }, .flags = opt_flags, .unit = name }, \
123  { "insert", NULL, 0, AV_OPT_TYPE_CONST, \
124  { .i64 = BSF_ELEMENT_INSERT }, .flags = opt_flags, .unit = name }, \
125  { "remove", NULL, 0, AV_OPT_TYPE_CONST, \
126  { .i64 = BSF_ELEMENT_REMOVE }, .flags = opt_flags, .unit = name }, \
127  { "extract", NULL, 0, AV_OPT_TYPE_CONST, \
128  { .i64 = BSF_ELEMENT_EXTRACT }, .flags = opt_flags, .unit = name } \
129 
130 
131 #endif /* AVCODEC_CBS_BSF_H */
CBSBSFType::codec_id
enum AVCodecID codec_id
Definition: cbs_bsf.h:26
BSF_ELEMENT_INSERT
@ BSF_ELEMENT_INSERT
Definition: cbs_bsf.h:98
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:170
CBSBSFContext
Definition: cbs_bsf.h:47
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:63
CBSBSFContext::input
CodedBitstreamContext * input
Definition: cbs_bsf.h:51
AVBSFContext
The bitstream filter state.
Definition: bsf.h:49
CBSBSFType::fragment_name
const char * fragment_name
Definition: cbs_bsf.h:30
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:40
pkt
AVPacket * pkt
Definition: movenc.c:59
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:118
BSF_ELEMENT_REMOVE
@ BSF_ELEMENT_REMOVE
Definition: cbs_bsf.h:100
CBSBSFType::unit_name
const char * unit_name
Definition: cbs_bsf.h:34
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
BSF_ELEMENT_PASS
@ BSF_ELEMENT_PASS
Definition: cbs_bsf.h:93
CBSBSFContext::fragment
CodedBitstreamFragment fragment
Definition: cbs_bsf.h:53
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
CBSBSFType
Definition: cbs_bsf.h:25
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:112
BSF_ELEMENT_EXTRACT
@ BSF_ELEMENT_EXTRACT
Definition: cbs_bsf.h:103
CBSBSFContext::type
const CBSBSFType * type
Definition: cbs_bsf.h:49
ff_cbs_bsf_generic_close
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition: cbs_bsf.c:152
AVPacket
This structure stores compressed data.
Definition: packet.h:346
int
int
Definition: ffmpeg_filter.c:170
CBSBSFContext::output
CodedBitstreamContext * output
Definition: cbs_bsf.h:52