| Line | Branch | Exec | Source |
|---|---|---|---|
| 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_lcevc.h" | ||
| 27 | #include "lcevc.h" | ||
| 28 | |||
| 29 | typedef struct LCEVCMetadataContext { | ||
| 30 | CBSBSFContext common; | ||
| 31 | |||
| 32 | int overscan_appropriate_flag; | ||
| 33 | |||
| 34 | int video_format; | ||
| 35 | int video_full_range_flag; | ||
| 36 | int colour_primaries; | ||
| 37 | int transfer_characteristics; | ||
| 38 | int matrix_coefficients; | ||
| 39 | |||
| 40 | int chroma_sample_loc_type; | ||
| 41 | |||
| 42 | LCEVCRawAdditionalInfo ai; | ||
| 43 | |||
| 44 | int delete_filler; | ||
| 45 | } LCEVCMetadataContext; | ||
| 46 | |||
| 47 | ✗ | static int lcevc_metadata_handle_vui(AVBSFContext *bsf, | |
| 48 | CodedBitstreamFragment *au) | ||
| 49 | { | ||
| 50 | ✗ | LCEVCMetadataContext *ctx = bsf->priv_data; | |
| 51 | ✗ | LCEVCRawProcessBlock *block = NULL; | |
| 52 | ✗ | LCEVCRawAdditionalInfo *ai = &ctx->ai; | |
| 53 | ✗ | LCEVCRawVUI *vui = &ai->vui; | |
| 54 | int position, err; | ||
| 55 | |||
| 56 | ✗ | position = ff_cbs_lcevc_find_process_block(ctx->common.output, au, | |
| 57 | LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG, | ||
| 58 | &block); | ||
| 59 | ✗ | if (position < 0) | |
| 60 | ✗ | return 0; | |
| 61 | |||
| 62 | ✗ | memset(ai, 0, sizeof(*ai)); | |
| 63 | ✗ | ai->additional_info_type = LCEVC_ADDITIONAL_INFO_TYPE_VUI; | |
| 64 | |||
| 65 | ✗ | if (ctx->overscan_appropriate_flag >= 0) { | |
| 66 | ✗ | vui->overscan_info_present_flag = 1; | |
| 67 | ✗ | vui->overscan_appropriate_flag = ctx->overscan_appropriate_flag; | |
| 68 | } | ||
| 69 | |||
| 70 | ✗ | if (ctx->video_format >= 0) { | |
| 71 | ✗ | vui->video_signal_type_present_flag = 1; | |
| 72 | ✗ | vui->video_format = ctx->video_format; | |
| 73 | } else | ||
| 74 | ✗ | vui->video_format = 5; | |
| 75 | |||
| 76 | ✗ | if (ctx->video_full_range_flag >= 0) { | |
| 77 | ✗ | vui->video_signal_type_present_flag = 1; | |
| 78 | ✗ | vui->video_full_range_flag = ctx->video_full_range_flag; | |
| 79 | } | ||
| 80 | |||
| 81 | ✗ | if (ctx->colour_primaries >= 0) { | |
| 82 | ✗ | vui->video_signal_type_present_flag = vui->colour_description_present_flag = 1; | |
| 83 | ✗ | vui->colour_primaries = ctx->colour_primaries; | |
| 84 | } else | ||
| 85 | ✗ | vui->colour_primaries = 2; | |
| 86 | ✗ | if (ctx->transfer_characteristics >= 0) { | |
| 87 | ✗ | vui->video_signal_type_present_flag = vui->colour_description_present_flag = 1; | |
| 88 | ✗ | vui->transfer_characteristics = ctx->transfer_characteristics; | |
| 89 | } else | ||
| 90 | ✗ | vui->transfer_characteristics = 2; | |
| 91 | ✗ | if (ctx->matrix_coefficients >= 0) { | |
| 92 | ✗ | vui->video_signal_type_present_flag = vui->colour_description_present_flag = 1; | |
| 93 | ✗ | vui->matrix_coefficients = ctx->matrix_coefficients; | |
| 94 | } else | ||
| 95 | ✗ | vui->matrix_coefficients = 2; | |
| 96 | |||
| 97 | ✗ | if (ctx->chroma_sample_loc_type >= 0) { | |
| 98 | ✗ | vui->chroma_loc_info_present_flag = 1; | |
| 99 | ✗ | vui->chroma_sample_loc_type_top_field = ctx->chroma_sample_loc_type; | |
| 100 | ✗ | vui->chroma_sample_loc_type_top_field = ctx->chroma_sample_loc_type; | |
| 101 | } | ||
| 102 | |||
| 103 | ✗ | err = ff_cbs_lcevc_add_process_block(ctx->common.output, au, position, | |
| 104 | LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO, | ||
| 105 | ai, NULL); | ||
| 106 | ✗ | if (err < 0) | |
| 107 | ✗ | return err; | |
| 108 | |||
| 109 | ✗ | return 0; | |
| 110 | } | ||
| 111 | |||
| 112 | ✗ | static int lcevc_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, | |
| 113 | CodedBitstreamFragment *au) | ||
| 114 | { | ||
| 115 | ✗ | LCEVCMetadataContext *ctx = bsf->priv_data; | |
| 116 | int err; | ||
| 117 | |||
| 118 | ✗ | if (ctx->overscan_appropriate_flag >= 0 || ctx->video_format >= 0 || | |
| 119 | ✗ | ctx->video_full_range_flag >= 0 || ctx->colour_primaries >= 0 || | |
| 120 | ✗ | ctx->transfer_characteristics >= 0 || ctx->matrix_coefficients >= 0 || | |
| 121 | ✗ | ctx->chroma_sample_loc_type >= 0) { | |
| 122 | ✗ | err = lcevc_metadata_handle_vui(bsf, au); | |
| 123 | ✗ | if (err < 0) | |
| 124 | ✗ | return err; | |
| 125 | } | ||
| 126 | |||
| 127 | ✗ | if (ctx->delete_filler) { | |
| 128 | ✗ | for (int i = 0; i < au->nb_units; i++) { | |
| 129 | ✗ | if (au->units[i].type == LCEVC_NON_IDR_NUT || | |
| 130 | ✗ | au->units[i].type == LCEVC_IDR_NUT) { | |
| 131 | ✗ | ff_cbs_lcevc_delete_process_block_type(ctx->common.output, au, | |
| 132 | LCEVC_PAYLOAD_TYPE_FILLER); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | ✗ | return 0; | |
| 138 | } | ||
| 139 | |||
| 140 | static const CBSBSFType lcevc_metadata_type = { | ||
| 141 | .codec_id = AV_CODEC_ID_LCEVC, | ||
| 142 | .fragment_name = "access unit", | ||
| 143 | .unit_name = "NAL unit", | ||
| 144 | .update_fragment = &lcevc_metadata_update_fragment, | ||
| 145 | }; | ||
| 146 | |||
| 147 | ✗ | static int lcevc_metadata_init(AVBSFContext *bsf) | |
| 148 | { | ||
| 149 | ✗ | return ff_cbs_bsf_generic_init(bsf, &lcevc_metadata_type); | |
| 150 | } | ||
| 151 | |||
| 152 | #define OFFSET(x) offsetof(LCEVCMetadataContext, x) | ||
| 153 | #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM) | ||
| 154 | static const AVOption lcevc_metadata_options[] = { | ||
| 155 | { "overscan_appropriate_flag", "Set VUI overscan appropriate flag", | ||
| 156 | OFFSET(overscan_appropriate_flag), AV_OPT_TYPE_BOOL, | ||
| 157 | { .i64 = -1 }, -1, 1, FLAGS }, | ||
| 158 | |||
| 159 | { "video_format", "Set video format (table E-2)", | ||
| 160 | OFFSET(video_format), AV_OPT_TYPE_INT, | ||
| 161 | { .i64 = -1 }, -1, 5, FLAGS}, | ||
| 162 | { "video_full_range_flag", "Set video full range flag", | ||
| 163 | OFFSET(video_full_range_flag), AV_OPT_TYPE_BOOL, | ||
| 164 | { .i64 = -1 }, -1, 1, FLAGS }, | ||
| 165 | { "colour_primaries", "Set colour primaries (table E-3)", | ||
| 166 | OFFSET(colour_primaries), AV_OPT_TYPE_INT, | ||
| 167 | { .i64 = -1 }, -1, 255, FLAGS }, | ||
| 168 | { "transfer_characteristics", "Set transfer characteristics (table E-4)", | ||
| 169 | OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, | ||
| 170 | { .i64 = -1 }, -1, 255, FLAGS }, | ||
| 171 | { "matrix_coefficients", "Set matrix coefficients (table E-5)", | ||
| 172 | OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, | ||
| 173 | { .i64 = -1 }, -1, 255, FLAGS }, | ||
| 174 | |||
| 175 | { "chroma_sample_loc_type", "Set chroma sample location type (figure E-1)", | ||
| 176 | OFFSET(chroma_sample_loc_type), AV_OPT_TYPE_INT, | ||
| 177 | { .i64 = -1 }, -1, 5, FLAGS }, | ||
| 178 | |||
| 179 | { "delete_filler", "Delete all filler", | ||
| 180 | OFFSET(delete_filler), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS}, | ||
| 181 | |||
| 182 | { NULL } | ||
| 183 | }; | ||
| 184 | |||
| 185 | static const AVClass lcevc_metadata_class = { | ||
| 186 | .class_name = "lcevc_metadata_bsf", | ||
| 187 | .item_name = av_default_item_name, | ||
| 188 | .option = lcevc_metadata_options, | ||
| 189 | .version = LIBAVUTIL_VERSION_INT, | ||
| 190 | }; | ||
| 191 | |||
| 192 | static const enum AVCodecID lcevc_metadata_codec_ids[] = { | ||
| 193 | AV_CODEC_ID_LCEVC, AV_CODEC_ID_NONE, | ||
| 194 | }; | ||
| 195 | |||
| 196 | const FFBitStreamFilter ff_lcevc_metadata_bsf = { | ||
| 197 | .p.name = "lcevc_metadata", | ||
| 198 | .p.codec_ids = lcevc_metadata_codec_ids, | ||
| 199 | .p.priv_class = &lcevc_metadata_class, | ||
| 200 | .priv_data_size = sizeof(LCEVCMetadataContext), | ||
| 201 | .init = &lcevc_metadata_init, | ||
| 202 | .close = &ff_cbs_bsf_generic_close, | ||
| 203 | .filter = &ff_cbs_bsf_generic_filter, | ||
| 204 | }; | ||
| 205 |