diff options
author | Anton Khirnov <anton@khirnov.net> | 2013-11-23 11:43:13 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2016-03-20 08:15:01 +0100 |
commit | 33d18982fa03feb061c8f744a4f0a9175c1f63ab (patch) | |
tree | 194f6383561b7acf3315eb7982c13aa95ff5ef67 /libavcodec/remove_extradata_bsf.c | |
parent | a2d1922bde8db2cdac95051918fe81ae18c0376b (diff) | |
download | ffmpeg-33d18982fa03feb061c8f744a4f0a9175c1f63ab.tar.gz |
lavc: add a new bitstream filtering API
Deprecate the current bitstream filtering API.
Diffstat (limited to 'libavcodec/remove_extradata_bsf.c')
-rw-r--r-- | libavcodec/remove_extradata_bsf.c | 110 |
1 files changed, 85 insertions, 25 deletions
diff --git a/libavcodec/remove_extradata_bsf.c b/libavcodec/remove_extradata_bsf.c index b82c867f43..a89fa06e61 100644 --- a/libavcodec/remove_extradata_bsf.c +++ b/libavcodec/remove_extradata_bsf.c @@ -18,39 +18,99 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/log.h" +#include "libavutil/opt.h" + #include "avcodec.h" +#include "bsf.h" +enum RemoveFreq { + REMOVE_FREQ_KEYFRAME, + REMOVE_FREQ_ALL, +}; -static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - int cmd= args ? *args : 0; - AVCodecParserContext *s; +typedef struct RemoveExtradataContext { + const AVClass *class; + int freq; - if(!bsfc->parser){ - bsfc->parser= av_parser_init(avctx->codec_id); - } - s= bsfc->parser; - - if(s && s->parser->split){ - if( (((avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) || - (avctx->flags2 & AV_CODEC_FLAG2_LOCAL_HEADER)) && cmd == 'a') - ||(!keyframe && cmd=='k') - ||(cmd=='e' || !cmd) - ){ - int i= s->parser->split(avctx, buf, buf_size); - buf += i; - buf_size -= i; + AVCodecParserContext *parser; + AVCodecContext *avctx; +} RemoveExtradataContext; + +static int remove_extradata(AVBSFContext *ctx, AVPacket *out) +{ + RemoveExtradataContext *s = ctx->priv_data; + + AVPacket *in; + int ret; + + ret = ff_bsf_get_packet(ctx, &in); + if (ret < 0) + return ret; + + if (s->parser && s->parser->parser->split) { + if (s->freq == REMOVE_FREQ_ALL || + (s->freq == REMOVE_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) { + int i = s->parser->parser->split(s->avctx, in->data, in->size); + in->data += i; + in->size -= i; } } - *poutbuf= (uint8_t *) buf; - *poutbuf_size= buf_size; + + av_packet_move_ref(out, in); + av_packet_free(&in); return 0; } -AVBitStreamFilter ff_remove_extradata_bsf={ - "remove_extra", - 0, - remove_extradata, +static int remove_extradata_init(AVBSFContext *ctx) +{ + RemoveExtradataContext *s = ctx->priv_data; + int ret; + + s->parser = av_parser_init(ctx->par_in->codec_id); + + if (s->parser) { + s->avctx = avcodec_alloc_context3(NULL); + if (!s->avctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(s->avctx, ctx->par_in); + if (ret < 0) + return ret; + } + + return 0; +} + +static void remove_extradata_close(AVBSFContext *ctx) +{ + RemoveExtradataContext *s = ctx->priv_data; + + avcodec_free_context(&s->avctx); + av_parser_close(s->parser); +} + +#define OFFSET(x) offsetof(RemoveExtradataContext, x) +static const AVOption options[] = { + { "freq", NULL, OFFSET(freq), AV_OPT_TYPE_INT, { .i64 = REMOVE_FREQ_KEYFRAME }, REMOVE_FREQ_KEYFRAME, REMOVE_FREQ_ALL, 0, "freq" }, + { "keyframe", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = REMOVE_FREQ_KEYFRAME }, .unit = "freq" }, + { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = REMOVE_FREQ_ALL }, .unit = "freq" }, + { NULL }, +}; + +static const AVClass remove_extradata_class = { + .class_name = "remove_extradata", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +const AVBitStreamFilter ff_remove_extradata_bsf = { + .name = "remove_extra", + .priv_data_size = sizeof(RemoveExtradataContext), + .priv_class = &remove_extradata_class, + .init = remove_extradata_init, + .close = remove_extradata_close, + .filter = remove_extradata, }; |