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"
29 typedef struct TraceHeadersContext {
30 CodedBitstreamContext *cbc;
31 } TraceHeadersContext;
34 static int trace_headers_init(AVBSFContext *bsf)
36 TraceHeadersContext *ctx = bsf->priv_data;
39 err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
43 ctx->cbc->trace_enable = 1;
44 ctx->cbc->trace_level = AV_LOG_INFO;
46 if (bsf->par_in->extradata) {
47 CodedBitstreamFragment ps;
49 av_log(bsf, AV_LOG_INFO, "Extradata\n");
51 err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
53 av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
57 ff_cbs_fragment_uninit(ctx->cbc, &ps);
63 static void trace_headers_close(AVBSFContext *bsf)
65 TraceHeadersContext *ctx = bsf->priv_data;
67 ff_cbs_close(&ctx->cbc);
70 static int trace_headers(AVBSFContext *bsf, AVPacket *out)
72 TraceHeadersContext *ctx = bsf->priv_data;
73 CodedBitstreamFragment au;
75 char tmp[256] = { 0 };
78 err = ff_bsf_get_packet(bsf, &in);
82 if (in->flags & AV_PKT_FLAG_KEY)
83 av_strlcat(tmp, ", key frame", sizeof(tmp));
84 if (in->flags & AV_PKT_FLAG_CORRUPT)
85 av_strlcat(tmp, ", corrupt", sizeof(tmp));
87 if (in->pts != AV_NOPTS_VALUE)
88 av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, in->pts);
90 av_strlcat(tmp, ", no pts", sizeof(tmp));
91 if (in->dts != AV_NOPTS_VALUE)
92 av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, in->dts);
94 av_strlcat(tmp, ", no dts", sizeof(tmp));
96 av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, in->duration);
98 av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", in->size, tmp);
100 err = ff_cbs_read_packet(ctx->cbc, &au, in);
104 ff_cbs_fragment_uninit(ctx->cbc, &au);
106 av_packet_move_ref(out, in);
112 static const enum AVCodecID trace_headers_codec_ids[] = {
115 AV_CODEC_ID_MPEG2VIDEO,
119 const AVBitStreamFilter ff_trace_headers_bsf = {
120 .name = "trace_headers",
121 .priv_data_size = sizeof(TraceHeadersContext),
122 .init = &trace_headers_init,
123 .close = &trace_headers_close,
124 .filter = &trace_headers,
125 .codec_ids = trace_headers_codec_ids,