2 * This file is part of FFmpeg.
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.
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.
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
20 #include "libavutil/intreadwrite.h"
21 #include "libavutil/opt.h"
23 typedef struct OpusBSFContext {
28 static int opus_metadata_filter(AVBSFContext *bsfc, AVPacket *pkt)
30 return ff_bsf_get_packet_ref(bsfc, pkt);
33 static int opus_metadata_init(AVBSFContext *bsfc)
35 OpusBSFContext *s = bsfc->priv_data;
37 if (bsfc->par_out->extradata_size < 19)
38 return AVERROR_INVALIDDATA;
40 AV_WL16(bsfc->par_out->extradata + 16, s->gain);
45 #define OFFSET(x) offsetof(OpusBSFContext, x)
46 #define FLAGS (AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_BSF_PARAM)
47 static const AVOption opus_metadata_options[] = {
48 { "gain", "Gain, actual amplification is pow(10, gain/(20.0*256))", OFFSET(gain),
49 AV_OPT_TYPE_INT, { .i64 = 0 }, -(INT16_MAX + 1), INT16_MAX, .flags = FLAGS },
54 static const AVClass opus_metadata_class = {
55 .class_name = "opus_metadata_bsf",
56 .item_name = av_default_item_name,
57 .option = opus_metadata_options,
58 .version = LIBAVUTIL_VERSION_INT,
61 static const enum AVCodecID codec_ids[] = {
62 AV_CODEC_ID_OPUS, AV_CODEC_ID_NONE,
65 const AVBitStreamFilter ff_opus_metadata_bsf = {
66 .name = "opus_metadata",
67 .priv_data_size = sizeof(OpusBSFContext),
68 .priv_class = &opus_metadata_class,
69 .init = &opus_metadata_init,
70 .filter = &opus_metadata_filter,
71 .codec_ids = codec_ids,