2017-05-05 00:06:20 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
#include "libavutil/common.h"
|
|
|
|
#include "libavutil/log.h"
|
|
|
|
|
2020-04-07 16:41:48 +02:00
|
|
|
#include "bsf.h"
|
2020-04-07 16:49:28 +02:00
|
|
|
#include "bsf_internal.h"
|
2017-05-05 00:06:20 +02:00
|
|
|
#include "cbs.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct TraceHeadersContext {
|
|
|
|
CodedBitstreamContext *cbc;
|
2019-02-12 00:47:42 +02:00
|
|
|
CodedBitstreamFragment fragment;
|
2017-05-05 00:06:20 +02:00
|
|
|
} TraceHeadersContext;
|
|
|
|
|
|
|
|
|
|
|
|
static int trace_headers_init(AVBSFContext *bsf)
|
|
|
|
{
|
|
|
|
TraceHeadersContext *ctx = bsf->priv_data;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
ctx->cbc->trace_enable = 1;
|
|
|
|
ctx->cbc->trace_level = AV_LOG_INFO;
|
|
|
|
|
|
|
|
if (bsf->par_in->extradata) {
|
2019-02-12 00:47:42 +02:00
|
|
|
CodedBitstreamFragment *frag = &ctx->fragment;
|
2017-05-05 00:06:20 +02:00
|
|
|
|
|
|
|
av_log(bsf, AV_LOG_INFO, "Extradata\n");
|
|
|
|
|
2019-02-12 00:47:42 +02:00
|
|
|
err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
|
2017-05-05 00:06:20 +02:00
|
|
|
|
2019-02-12 00:47:43 +02:00
|
|
|
ff_cbs_fragment_reset(ctx->cbc, frag);
|
2017-05-05 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 01:09:45 +02:00
|
|
|
return err;
|
2017-05-05 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void trace_headers_close(AVBSFContext *bsf)
|
|
|
|
{
|
|
|
|
TraceHeadersContext *ctx = bsf->priv_data;
|
|
|
|
|
2019-02-12 00:47:43 +02:00
|
|
|
ff_cbs_fragment_free(ctx->cbc, &ctx->fragment);
|
2017-05-05 00:06:20 +02:00
|
|
|
ff_cbs_close(&ctx->cbc);
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:50:28 +02:00
|
|
|
static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
|
2017-05-05 00:06:20 +02:00
|
|
|
{
|
|
|
|
TraceHeadersContext *ctx = bsf->priv_data;
|
2019-02-12 00:47:42 +02:00
|
|
|
CodedBitstreamFragment *frag = &ctx->fragment;
|
2017-05-05 00:06:20 +02:00
|
|
|
char tmp[256] = { 0 };
|
|
|
|
int err;
|
|
|
|
|
2018-03-11 18:50:28 +02:00
|
|
|
err = ff_bsf_get_packet_ref(bsf, pkt);
|
2017-05-05 00:06:20 +02:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2018-03-11 18:50:28 +02:00
|
|
|
if (pkt->flags & AV_PKT_FLAG_KEY)
|
2017-05-05 00:06:20 +02:00
|
|
|
av_strlcat(tmp, ", key frame", sizeof(tmp));
|
2018-03-11 18:50:28 +02:00
|
|
|
if (pkt->flags & AV_PKT_FLAG_CORRUPT)
|
2017-05-05 00:06:20 +02:00
|
|
|
av_strlcat(tmp, ", corrupt", sizeof(tmp));
|
|
|
|
|
2018-03-11 18:50:28 +02:00
|
|
|
if (pkt->pts != AV_NOPTS_VALUE)
|
|
|
|
av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
|
2017-05-05 00:06:20 +02:00
|
|
|
else
|
|
|
|
av_strlcat(tmp, ", no pts", sizeof(tmp));
|
2018-03-11 18:50:28 +02:00
|
|
|
if (pkt->dts != AV_NOPTS_VALUE)
|
|
|
|
av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
|
2017-05-05 00:06:20 +02:00
|
|
|
else
|
|
|
|
av_strlcat(tmp, ", no dts", sizeof(tmp));
|
2018-03-11 18:50:28 +02:00
|
|
|
if (pkt->duration > 0)
|
|
|
|
av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
|
2017-05-05 00:06:20 +02:00
|
|
|
|
2018-03-11 18:50:28 +02:00
|
|
|
av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
|
2017-05-05 00:06:20 +02:00
|
|
|
|
2019-02-12 00:47:42 +02:00
|
|
|
err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
|
2017-05-05 00:06:20 +02:00
|
|
|
|
2019-02-12 00:47:43 +02:00
|
|
|
ff_cbs_fragment_reset(ctx->cbc, frag);
|
2017-05-05 00:06:20 +02:00
|
|
|
|
2018-10-05 01:09:45 +02:00
|
|
|
if (err < 0)
|
|
|
|
av_packet_unref(pkt);
|
|
|
|
return err;
|
2017-05-05 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const AVBitStreamFilter ff_trace_headers_bsf = {
|
|
|
|
.name = "trace_headers",
|
|
|
|
.priv_data_size = sizeof(TraceHeadersContext),
|
|
|
|
.init = &trace_headers_init,
|
|
|
|
.close = &trace_headers_close,
|
|
|
|
.filter = &trace_headers,
|
2018-03-11 19:27:15 +02:00
|
|
|
.codec_ids = ff_cbs_all_codec_ids,
|
2017-05-05 00:06:20 +02:00
|
|
|
};
|