2007-05-19 03:35:27 +03:00
|
|
|
/*
|
|
|
|
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-05-19 03:35:27 +03:00
|
|
|
#include "avcodec.h"
|
2013-11-23 13:43:13 +03:00
|
|
|
#include "bsf.h"
|
|
|
|
|
|
|
|
#include "libavutil/log.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
|
|
|
enum DumpFreq {
|
|
|
|
DUMP_FREQ_KEYFRAME,
|
|
|
|
DUMP_FREQ_ALL,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct DumpExtradataContext {
|
|
|
|
const AVClass *class;
|
2018-07-24 00:16:30 +02:00
|
|
|
AVPacket pkt;
|
2013-11-23 13:43:13 +03:00
|
|
|
int freq;
|
|
|
|
} DumpExtradataContext;
|
|
|
|
|
|
|
|
static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
|
|
|
|
{
|
|
|
|
DumpExtradataContext *s = ctx->priv_data;
|
2018-07-24 00:16:30 +02:00
|
|
|
AVPacket *in = &s->pkt;
|
2013-11-23 13:43:13 +03:00
|
|
|
int ret = 0;
|
|
|
|
|
2018-07-24 00:16:30 +02:00
|
|
|
ret = ff_bsf_get_packet_ref(ctx, in);
|
2013-11-23 13:43:13 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ctx->par_in->extradata &&
|
|
|
|
(s->freq == DUMP_FREQ_ALL ||
|
2019-07-13 04:55:50 +02:00
|
|
|
(s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
|
2019-12-15 00:19:26 +02:00
|
|
|
(in->size < ctx->par_in->extradata_size ||
|
|
|
|
memcmp(in->data, ctx->par_in->extradata, ctx->par_in->extradata_size))) {
|
2013-11-23 13:43:13 +03:00
|
|
|
if (in->size >= INT_MAX - ctx->par_in->extradata_size) {
|
|
|
|
ret = AVERROR(ERANGE);
|
|
|
|
goto fail;
|
|
|
|
}
|
2007-05-19 03:35:27 +03:00
|
|
|
|
2013-11-23 13:43:13 +03:00
|
|
|
ret = av_new_packet(out, in->size + ctx->par_in->extradata_size);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2007-05-19 03:35:27 +03:00
|
|
|
|
2013-11-23 13:43:13 +03:00
|
|
|
ret = av_packet_copy_props(out, in);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_packet_unref(out);
|
|
|
|
goto fail;
|
2007-05-19 03:35:27 +03:00
|
|
|
}
|
2013-11-23 13:43:13 +03:00
|
|
|
|
|
|
|
memcpy(out->data, ctx->par_in->extradata, ctx->par_in->extradata_size);
|
|
|
|
memcpy(out->data + ctx->par_in->extradata_size, in->data, in->size);
|
|
|
|
} else {
|
|
|
|
av_packet_move_ref(out, in);
|
2007-05-19 03:35:27 +03:00
|
|
|
}
|
2013-11-23 13:43:13 +03:00
|
|
|
|
|
|
|
fail:
|
2018-07-24 00:16:30 +02:00
|
|
|
av_packet_unref(in);
|
2013-11-23 13:43:13 +03:00
|
|
|
|
|
|
|
return ret;
|
2007-05-19 03:35:27 +03:00
|
|
|
}
|
|
|
|
|
2013-11-23 13:43:13 +03:00
|
|
|
#define OFFSET(x) offsetof(DumpExtradataContext, x)
|
2018-03-08 08:01:48 +02:00
|
|
|
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
|
2013-11-23 13:43:13 +03:00
|
|
|
static const AVOption options[] = {
|
2019-06-04 15:41:05 +02:00
|
|
|
{ "freq", "When to dump extradata", OFFSET(freq), AV_OPT_TYPE_INT,
|
2018-03-08 08:01:48 +02:00
|
|
|
{ .i64 = DUMP_FREQ_KEYFRAME }, DUMP_FREQ_KEYFRAME, DUMP_FREQ_ALL, FLAGS, "freq" },
|
|
|
|
{ "k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_KEYFRAME }, .flags = FLAGS, .unit = "freq" },
|
|
|
|
{ "keyframe", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_KEYFRAME }, .flags = FLAGS, .unit = "freq" },
|
|
|
|
{ "e", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_ALL }, .flags = FLAGS, .unit = "freq" },
|
|
|
|
{ "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = DUMP_FREQ_ALL }, .flags = FLAGS, .unit = "freq" },
|
2013-11-23 13:43:13 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass dump_extradata_class = {
|
|
|
|
.class_name = "dump_extradata bsf",
|
|
|
|
.item_name = av_default_item_name,
|
|
|
|
.option = options,
|
2018-04-19 23:44:13 +02:00
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
2013-11-23 13:43:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const AVBitStreamFilter ff_dump_extradata_bsf = {
|
|
|
|
.name = "dump_extra",
|
|
|
|
.priv_data_size = sizeof(DumpExtradataContext),
|
|
|
|
.priv_class = &dump_extradata_class,
|
|
|
|
.filter = dump_extradata,
|
2007-05-19 03:35:27 +03:00
|
|
|
};
|