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
|
|
|
|
*/
|
|
|
|
|
2021-08-01 08:36:09 +02:00
|
|
|
#include <inttypes.h>
|
2017-05-05 00:06:20 +02:00
|
|
|
|
|
|
|
#include "libavutil/avstring.h"
|
2021-08-01 08:36:09 +02:00
|
|
|
#include "libavutil/avutil.h"
|
2017-05-05 00:06:20 +02:00
|
|
|
#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;
|
2023-09-11 09:52:26 +02:00
|
|
|
ctx->cbc->trace_context = ctx->cbc;
|
|
|
|
ctx->cbc->trace_read_callback = ff_cbs_trace_read_log;
|
2017-05-05 00:06:20 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(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;
|
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_free(&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
|
|
|
|
2021-08-05 17:04:14 +02:00
|
|
|
if (av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
|
|
|
|
av_log(bsf, AV_LOG_INFO, "Side data:\n");
|
|
|
|
|
|
|
|
err = ff_cbs_read_packet_side_data(ctx->cbc, frag, pkt);
|
|
|
|
ff_cbs_fragment_reset(frag);
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
av_packet_unref(pkt);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
av_log(bsf, AV_LOG_INFO, "Payload:\n");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-06 00:34:25 +02:00
|
|
|
ff_cbs_fragment_reset(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
|
|
|
}
|
|
|
|
|
2022-03-21 23:25:27 +02:00
|
|
|
const FFBitStreamFilter ff_trace_headers_bsf = {
|
|
|
|
.p.name = "trace_headers",
|
|
|
|
.p.codec_ids = ff_cbs_all_codec_ids,
|
2017-05-05 00:06:20 +02:00
|
|
|
.priv_data_size = sizeof(TraceHeadersContext),
|
|
|
|
.init = &trace_headers_init,
|
|
|
|
.close = &trace_headers_close,
|
|
|
|
.filter = &trace_headers,
|
|
|
|
};
|