FFmpeg
Loading...
Searching...
No Matches
cbs_bsf.c
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#include "bsf.h"
20#include "bsf_internal.h"
21#include "cbs_bsf.h"
22
24
26#if CONFIG_CBS_APV
28#endif
29#if CONFIG_CBS_AV1
31#endif
32#if CONFIG_CBS_H264
34#endif
35#if CONFIG_CBS_H265
37#endif
38#if CONFIG_CBS_H266
40#endif
41#if CONFIG_CBS_LCEVC
43#endif
44#if CONFIG_CBS_JPEG
46#endif
47#if CONFIG_CBS_MPEG2
49#endif
50#if CONFIG_CBS_VP8
52#endif
53#if CONFIG_CBS_VP9
55#endif
57};
58
60{
62 CodedBitstreamFragment *frag = &ctx->fragment;
63 uint8_t *side_data;
64 int err;
65
67 return 0;
68
69 err = ff_cbs_read_packet_side_data(ctx->input, frag, pkt);
70 if (err < 0) {
72 "Failed to read extradata from packet side data.\n");
73 return err;
74 }
75
76 err = ctx->type->update_fragment(bsf, NULL, frag);
77 if (err < 0)
78 return err;
79
80 err = ff_cbs_write_fragment_data(ctx->output, frag);
81 if (err < 0) {
83 "Failed to write extradata into packet side data.\n");
84 return err;
85 }
86
88 frag->data_size);
89 if (!side_data)
90 return AVERROR(ENOMEM);
91 memcpy(side_data, frag->data, frag->data_size);
92
93 ff_cbs_fragment_reset(frag);
94 return 0;
95}
96
98{
100 CodedBitstreamFragment *frag = &ctx->fragment;
101 int err;
102
103 err = ff_bsf_get_packet_ref(bsf, pkt);
104 if (err < 0)
105 return err;
106
107 err = cbs_bsf_update_side_data(bsf, pkt);
108 if (err < 0)
109 goto fail;
110
111 err = ff_cbs_read_packet(ctx->input, frag, pkt);
112 if (err < 0) {
113 av_log(bsf, AV_LOG_ERROR, "Failed to read %s from packet.\n",
114 ctx->type->fragment_name);
115 goto fail;
116 }
117
118 if (frag->nb_units == 0) {
119 av_log(bsf, AV_LOG_ERROR, "No %s found in packet.\n",
120 ctx->type->unit_name);
122 goto fail;
123 }
124
125 err = ctx->type->update_fragment(bsf, pkt, frag);
126 if (err < 0)
127 goto fail;
128
129 err = ff_cbs_write_packet(ctx->output, pkt, frag);
130 if (err < 0) {
131 av_log(bsf, AV_LOG_ERROR, "Failed to write %s into packet.\n",
132 ctx->type->fragment_name);
133 goto fail;
134 }
135
136 err = 0;
137fail:
138 ff_cbs_fragment_reset(frag);
139
140 if (err < 0)
142
143 return err;
144}
145
147{
149 CodedBitstreamFragment *frag = &ctx->fragment;
150 int err;
151
152 ctx->type = type;
153
154 err = ff_cbs_init(&ctx->input, type->codec_id, bsf);
155 if (err < 0)
156 return err;
157
158 err = ff_cbs_init(&ctx->output, type->codec_id, bsf);
159 if (err < 0)
160 return err;
161
162 ctx->output->trace_enable = 1;
163 ctx->output->trace_level = AV_LOG_TRACE;
164 ctx->output->trace_context = ctx->output;
165 ctx->output->trace_write_callback = ff_cbs_trace_write_log;
166
167 if (bsf->par_in->extradata) {
168 err = ff_cbs_read_extradata(ctx->input, frag, bsf->par_in);
169 if (err < 0) {
170 av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
171 goto fail;
172 }
173
174 err = type->update_fragment(bsf, NULL, frag);
175 if (err < 0)
176 goto fail;
177
178 err = ff_cbs_write_extradata(ctx->output, bsf->par_out, frag);
179 if (err < 0) {
180 av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
181 goto fail;
182 }
183 }
184
185 err = 0;
186fail:
187 ff_cbs_fragment_reset(frag);
188 return err;
189}
190
192{
194
195 ff_cbs_fragment_free(&ctx->fragment);
196 ff_cbs_close(&ctx->input);
197 ff_cbs_close(&ctx->output);
198}
static AVFormatContext * ctx
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition bsf.c:254
int ff_cbs_bsf_generic_filter(AVBSFContext *bsf, AVPacket *pkt)
Filter operation for CBS BSF.
Definition cbs_bsf.c:97
av_cold void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition cbs_bsf.c:191
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition cbs_bsf.c:25
av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition cbs_bsf.c:146
static int cbs_bsf_update_side_data(AVBSFContext *bsf, AVPacket *pkt)
Definition cbs_bsf.c:59
#define AV_CODEC_ID_H265
Definition codec_id.h:224
#define AV_CODEC_ID_H266
Definition codec_id.h:248
#define NULL
Definition coverity.c:32
static AVPacket * pkt
#define fail
Definition test.h:479
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_APV
Definition codec_id.h:323
@ AV_CODEC_ID_LCEVC
Definition codec_id.h:609
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition packet.h:56
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition packet.c:231
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition packet.c:252
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
cl_device_type type
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
The bitstream filter state.
Definition bsf.h:68
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:83
AVCodecParameters * par_in
Parameters of the input stream.
Definition bsf.h:90
AVCodecParameters * par_out
Parameters of the output stream.
Definition bsf.h:96
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
This structure stores compressed data.
Definition packet.h:580
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
int nb_units
Number of units in this fragment.
Definition cbs.h:160
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
#define av_log(a,...)