FFmpeg
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 "bsf.h"
23 #include "bsf_internal.h"
24 #include "cbs.h"
25 #include "cbs_bsf.h"
26 #include "cbs_apv.h"
27 
28 typedef struct APVMetadataContext {
30 
36 
37 
39  APVRawFrameHeader *hdr)
40 {
42 
43  if (ctx->color_primaries >= 0 ||
44  ctx->transfer_characteristics >= 0 ||
45  ctx->matrix_coefficients >= 0 ||
46  ctx->full_range_flag >= 0) {
48 
49  if (ctx->color_primaries >= 0)
50  hdr->color_primaries = ctx->color_primaries;
51  if (ctx->transfer_characteristics >= 0)
52  hdr->transfer_characteristics = ctx->transfer_characteristics;
53  if (ctx->matrix_coefficients >= 0)
54  hdr->matrix_coefficients = ctx->matrix_coefficients;
55  if (ctx->full_range_flag >= 0)
56  hdr->full_range_flag = ctx->full_range_flag;
57  }
58 
59  return 0;
60 }
61 
64 {
65  int err, i;
66 
67  for (i = 0; i < frag->nb_units; i++) {
68  if (frag->units[i].type == APV_PBU_PRIMARY_FRAME) {
69  APVRawFrame *pbu = frag->units[i].content;
71  if (err < 0)
72  return err;
73  }
74  }
75 
76  return 0;
77 }
78 
79 static const CBSBSFType apv_metadata_type = {
81  .fragment_name = "access unit",
82  .unit_name = "PBU",
83  .update_fragment = &apv_metadata_update_fragment,
84 };
85 
87 {
89 }
90 
91 #define OFFSET(x) offsetof(APVMetadataContext, x)
92 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
93 static const AVOption apv_metadata_options[] = {
94  { "color_primaries", "Set color primaries (section 5.3.5)",
96  { .i64 = -1 }, -1, 255, FLAGS },
97  { "transfer_characteristics", "Set transfer characteristics (section 5.3.5)",
99  { .i64 = -1 }, -1, 255, FLAGS },
100  { "matrix_coefficients", "Set matrix coefficients (section 5.3.5)",
101  OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
102  { .i64 = -1 }, -1, 255, FLAGS },
103 
104  { "full_range_flag", "Set full range flag flag (section 5.3.5)",
105  OFFSET(full_range_flag), AV_OPT_TYPE_INT,
106  { .i64 = -1 }, -1, 1, FLAGS, .unit = "cr" },
107  { "tv", "TV (limited) range", 0, AV_OPT_TYPE_CONST,
108  { .i64 = 0 }, .flags = FLAGS, .unit = "cr" },
109  { "pc", "PC (full) range", 0, AV_OPT_TYPE_CONST,
110  { .i64 = 1 }, .flags = FLAGS, .unit = "cr" },
111 
112  { NULL }
113 };
114 
115 static const AVClass apv_metadata_class = {
116  .class_name = "apv_metadata_bsf",
117  .item_name = av_default_item_name,
118  .option = apv_metadata_options,
119  .version = LIBAVUTIL_VERSION_INT,
120 };
121 
122 static const enum AVCodecID apv_metadata_codec_ids[] = {
124 };
125 
127  .p.name = "apv_metadata",
128  .p.codec_ids = apv_metadata_codec_ids,
129  .p.priv_class = &apv_metadata_class,
130  .priv_data_size = sizeof(APVMetadataContext),
134 };
apv_metadata_class
static const AVClass apv_metadata_class
Definition: apv_metadata.c:115
APVMetadataContext
Definition: apv_metadata.c:28
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
bsf_internal.h
opt.h
CBSBSFType::codec_id
enum AVCodecID codec_id
Definition: cbs_bsf.h:32
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:114
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
APVRawFrameHeader::color_primaries
uint8_t color_primaries
Definition: cbs_apv.h:72
AVOption
AVOption.
Definition: opt.h:429
CBSBSFContext
Definition: cbs_bsf.h:53
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:81
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
bsf.h
cbs_bsf.h
OFFSET
#define OFFSET(x)
Definition: apv_metadata.c:91
APVRawFrameHeader::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_apv.h:73
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:175
pkt
AVPacket * pkt
Definition: movenc.c:60
APVRawFrame::frame_header
APVRawFrameHeader frame_header
Definition: cbs_apv.h:103
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
APVRawFrameHeader::full_range_flag
uint8_t full_range_flag
Definition: cbs_apv.h:75
ff_apv_metadata_bsf
const FFBitStreamFilter ff_apv_metadata_bsf
Definition: apv_metadata.c:126
ctx
AVFormatContext * ctx
Definition: movenc.c:49
apv_metadata_options
static const AVOption apv_metadata_options[]
Definition: apv_metadata.c:93
APVRawFrameHeader::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_apv.h:74
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
FFBitStreamFilter
Definition: bsf_internal.h:27
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:240
close
av_cold void CBS_FUNC() close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:146
FLAGS
#define FLAGS
Definition: apv_metadata.c:92
APVRawFrame
Definition: cbs_apv.h:101
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
color_primaries
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition: csp.c:76
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
apv_metadata_codec_ids
static enum AVCodecID apv_metadata_codec_ids[]
Definition: apv_metadata.c:122
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
CBSBSFType
Definition: cbs_bsf.h:31
APVRawFrameHeader
Definition: cbs_apv.h:67
APVMetadataContext::full_range_flag
int full_range_flag
Definition: apv_metadata.c:34
ff_cbs_bsf_generic_close
void ff_cbs_bsf_generic_close(AVBSFContext *bsf)
Close a generic CBS BSF instance.
Definition: cbs_bsf.c:155
transfer_characteristics
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
Definition: vf_colorspace.c:167
apv_metadata_init
static int apv_metadata_init(AVBSFContext *bsf)
Definition: apv_metadata.c:86
apv_metadata_update_fragment
static int apv_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, CodedBitstreamFragment *frag)
Definition: apv_metadata.c:62
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
APVMetadataContext::common
CBSBSFContext common
Definition: apv_metadata.c:29
common.h
APVMetadataContext::transfer_characteristics
int transfer_characteristics
Definition: apv_metadata.c:32
apv_metadata_type
static const CBSBSFType apv_metadata_type
Definition: apv_metadata.c:79
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:83
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
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:332
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
APVRawFrameHeader::color_description_present_flag
uint8_t color_description_present_flag
Definition: cbs_apv.h:71
APV_PBU_PRIMARY_FRAME
@ APV_PBU_PRIMARY_FRAME
Definition: apv.h:27
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
APVMetadataContext::matrix_coefficients
int matrix_coefficients
Definition: apv_metadata.c:33
apv_metadata_update_frame_header
static int apv_metadata_update_frame_header(AVBSFContext *bsf, APVRawFrameHeader *hdr)
Definition: apv_metadata.c:38
AVPacket
This structure stores compressed data.
Definition: packet.h:512
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
cbs_apv.h
APVMetadataContext::color_primaries
int color_primaries
Definition: apv_metadata.c:31
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:160