FFmpeg
Loading...
Searching...
No Matches
apv_metadata.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 "libavutil/common.h"
20#include "libavutil/opt.h"
21
22#include "libavcodec/bsf.h"
24#include "libavcodec/cbs.h"
25#include "libavcodec/cbs_bsf.h"
26#include "libavcodec/cbs_apv.h"
27
38
39
42{
44
45 if (ctx->color_primaries >= 0 ||
46 ctx->transfer_characteristics >= 0 ||
47 ctx->matrix_coefficients >= 0 ||
48 ctx->full_range_flag >= 0) {
50
51 if (ctx->color_primaries >= 0)
52 hdr->color_primaries = ctx->color_primaries;
53 if (ctx->transfer_characteristics >= 0)
54 hdr->transfer_characteristics = ctx->transfer_characteristics;
55 if (ctx->matrix_coefficients >= 0)
56 hdr->matrix_coefficients = ctx->matrix_coefficients;
57 if (ctx->full_range_flag >= 0)
58 hdr->full_range_flag = ctx->full_range_flag;
59 }
60
61 return 0;
62}
63
66{
68 const CodedBitstreamAPVContext *priv = ctx->common.input->priv_data;
69 int err, i;
70
71 for (i = 0; i < frag->nb_units; i++) {
72 if (frag->units[i].type == APV_PBU_PRIMARY_FRAME) {
73 APVRawFrame *pbu = frag->units[i].content;
75 if (err < 0)
76 return err;
77 }
78 }
79
80 if (ctx->delete_filler) {
81 // Types of filler to delete:
82 // - Filler PBUs.
83 // - Filler at end of frame PBUs.
84 // - Dummy bytes trailing in tile data.
85 // - Filler at end of AU info PBUs.
86 // - Filler at end of metadata PBUs.
87 // - Filler metadata payloads.
88
89 for (i = frag->nb_units - 1; i >= 0; i--) {
90 switch (frag->units[i].type) {
91 case APV_PBU_FILLER:
92 ff_cbs_delete_unit(frag, i);
93 break;
99 {
100 APVRawFrame *frame = frag->units[i].content;
101 frame->filler.filler_size = 0;
102 for (int t = 0; t < priv->num_tiles; t++)
103 frame->tile[t].tile_dummy_byte_size = 0;
104 // tile_size[t] may be wrong here, but are
105 // recalculated during CBS write.
106 }
107 break;
109 {
111 au_info->filler.filler_size = 0;
112 }
113 break;
114 case APV_PBU_METADATA:
115 {
116 APVRawMetadata *md = frag->units[i].content;
117 int k = 0;
118 md->filler.filler_size = 0;
119 for (int j = 0; j < md->metadata_count; j++) {
120 APVRawMetadataPayload *pl = &md->payloads[j];
122 // Drop this payload.
123 } else {
124 if (k < j)
125 md->payloads[k] = md->payloads[j];
126 ++k;
127 }
128 }
129 if (k == 0) {
130 // This metadata PBU contained only a filler
131 // payload, so now we have to delete the whole
132 // thing because a metadata PBU must contain at
133 // least one payload.
134 ff_cbs_delete_unit(frag, i);
135 } else {
136 md->metadata_count = k;
137 // metadata_size may be wrong here, but is
138 // recalculated during CBS write.
139 }
140 }
141 break;
142 }
143 }
144 }
145
146 return 0;
147}
148
150 .codec_id = AV_CODEC_ID_APV,
151 .fragment_name = "access unit",
152 .unit_name = "PBU",
153 .update_fragment = &apv_metadata_update_fragment,
154};
155
157{
159}
160
161#define OFFSET(x) offsetof(APVMetadataContext, x)
162#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
164 { "color_primaries", "Set color primaries (section 5.3.5)",
166 { .i64 = -1 }, -1, 255, FLAGS },
167 { "transfer_characteristics", "Set transfer characteristics (section 5.3.5)",
169 { .i64 = -1 }, -1, 255, FLAGS },
170 { "matrix_coefficients", "Set matrix coefficients (section 5.3.5)",
171 OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
172 { .i64 = -1 }, -1, 255, FLAGS },
173
174 { "full_range_flag", "Set full range flag flag (section 5.3.5)",
175 OFFSET(full_range_flag), AV_OPT_TYPE_INT,
176 { .i64 = -1 }, -1, 1, FLAGS, .unit = "cr" },
177 { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST,
178 { .i64 = 0 }, .flags = FLAGS, .unit = "cr" },
179 { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST,
180 { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
181
182 { "delete_filler", "Delete all filler in the stream",
183 OFFSET(delete_filler), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
184
185 { NULL }
186};
187
189 .class_name = "apv_metadata_bsf",
190 .item_name = av_default_item_name,
191 .option = apv_metadata_options,
192 .version = LIBAVUTIL_VERSION_INT,
193};
194
198
200 .p.name = "apv_metadata",
201 .p.codec_ids = apv_metadata_codec_ids,
202 .p.priv_class = &apv_metadata_class,
203 .priv_data_size = sizeof(APVMetadataContext),
207};
static AVFormatContext * ctx
static const CBSBSFType apv_metadata_type
static int apv_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *frag)
static int apv_metadata_init(AVBSFContext *bsf)
static const AVClass apv_metadata_class
static const AVOption apv_metadata_options[]
#define OFFSET(x)
static int apv_metadata_update_frame_header(AVBSFContext *bsf, APVRawFrameHeader *hdr)
static enum AVCodecID apv_metadata_codec_ids[]
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
const FFBitStreamFilter ff_apv_metadata_bsf
static int FUNC au_info(CodedBitstreamContext *ctx, RWContext *rw, APVRawAUInfo *current)
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
av_cold int ff_cbs_bsf_generic_init(AVBSFContext *bsf, const CBSBSFType *type)
Initialise generic CBS BSF setup.
Definition cbs_bsf.c:146
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:596
common internal and external API header
#define NULL
Definition coverity.c:32
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition csp.c:76
static AVPacket * pkt
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
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_NONE
Definition codec_id.h:48
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
@ APV_PBU_ALPHA_FRAME
Definition apv.h:31
@ APV_PBU_PRIMARY_FRAME
Definition apv.h:27
@ APV_PBU_PREVIEW_FRAME
Definition apv.h:29
@ APV_PBU_NON_PRIMARY_FRAME
Definition apv.h:28
@ APV_PBU_FILLER
Definition apv.h:34
@ APV_PBU_ACCESS_UNIT_INFORMATION
Definition apv.h:32
@ APV_PBU_DEPTH_FRAME
Definition apv.h:30
@ APV_PBU_METADATA
Definition apv.h:33
@ APV_METADATA_FILLER
Definition apv.h:85
static const struct TransferCharacteristics transfer_characteristics[]
AVOptions.
CBSBSFContext common
uint8_t color_primaries
Definition cbs_apv.h:72
uint8_t color_description_present_flag
Definition cbs_apv.h:71
uint8_t full_range_flag
Definition cbs_apv.h:75
uint8_t matrix_coefficients
Definition cbs_apv.h:74
uint8_t transfer_characteristics
Definition cbs_apv.h:73
APVRawFrameHeader frame_header
Definition cbs_apv.h:103
uint32_t payload_type
Definition cbs_apv.h:166
The bitstream filter state.
Definition bsf.h:68
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:83
Describe the class of an AVClass context structure.
Definition log.h:76
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition cbs.h:175
int nb_units
Number of units in this fragment.
Definition cbs.h:160
void * content
Pointer to the decomposed form of this unit.
Definition cbs.h:114
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define md