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
21 #include "libavutil/avstring.h"
22 #include "libavutil/common.h"
23 #include "libavutil/log.h"
26 #include "bsf_internal.h"
30 typedef struct TraceHeadersContext {
31 CodedBitstreamContext *cbc;
32 CodedBitstreamFragment fragment;
33 } TraceHeadersContext;
36 static int trace_headers_init(AVBSFContext *bsf)
38 TraceHeadersContext *ctx = bsf->priv_data;
41 err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
45 ctx->cbc->trace_enable = 1;
46 ctx->cbc->trace_level = AV_LOG_INFO;
48 if (bsf->par_in->extradata) {
49 CodedBitstreamFragment *frag = &ctx->fragment;
51 av_log(bsf, AV_LOG_INFO, "Extradata\n");
53 err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
55 ff_cbs_fragment_reset(frag);
61 static void trace_headers_close(AVBSFContext *bsf)
63 TraceHeadersContext *ctx = bsf->priv_data;
65 ff_cbs_fragment_free(&ctx->fragment);
66 ff_cbs_close(&ctx->cbc);
69 static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
71 TraceHeadersContext *ctx = bsf->priv_data;
72 CodedBitstreamFragment *frag = &ctx->fragment;
73 char tmp[256] = { 0 };
76 err = ff_bsf_get_packet_ref(bsf, pkt);
80 if (pkt->flags & AV_PKT_FLAG_KEY)
81 av_strlcat(tmp, ", key frame", sizeof(tmp));
82 if (pkt->flags & AV_PKT_FLAG_CORRUPT)
83 av_strlcat(tmp, ", corrupt", sizeof(tmp));
85 if (pkt->pts != AV_NOPTS_VALUE)
86 av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
88 av_strlcat(tmp, ", no pts", sizeof(tmp));
89 if (pkt->dts != AV_NOPTS_VALUE)
90 av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
92 av_strlcat(tmp, ", no dts", sizeof(tmp));
93 if (pkt->duration > 0)
94 av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
96 av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
98 err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
100 ff_cbs_fragment_reset(frag);
103 av_packet_unref(pkt);
107 const AVBitStreamFilter ff_trace_headers_bsf = {
108 .name = "trace_headers",
109 .priv_data_size = sizeof(TraceHeadersContext),
110 .init = &trace_headers_init,
111 .close = &trace_headers_close,
112 .filter = &trace_headers,
113 .codec_ids = ff_cbs_all_codec_ids,