FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/bsf/trace_headers.c
Date: 2026-05-16 01:27:51
Exec Total Coverage
Lines: 0 53 0.0%
Functions: 0 3 0.0%
Branches: 0 22 0.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <inttypes.h>
20
21 #include "libavutil/avstring.h"
22 #include "libavutil/avutil.h"
23 #include "libavutil/log.h"
24
25 #include "bsf.h"
26 #include "bsf_internal.h"
27 #include "cbs.h"
28 #include "cbs_bsf.h"
29
30
31 typedef struct TraceHeadersContext {
32 CodedBitstreamContext *cbc;
33 CodedBitstreamFragment fragment;
34 } TraceHeadersContext;
35
36
37 static int trace_headers_init(AVBSFContext *bsf)
38 {
39 TraceHeadersContext *ctx = bsf->priv_data;
40 int err;
41
42 err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
43 if (err < 0)
44 return err;
45
46 ctx->cbc->trace_enable = 1;
47 ctx->cbc->trace_level = AV_LOG_INFO;
48 ctx->cbc->trace_context = ctx->cbc;
49 ctx->cbc->trace_read_callback = ff_cbs_trace_read_log;
50
51 if (bsf->par_in->extradata) {
52 CodedBitstreamFragment *frag = &ctx->fragment;
53
54 av_log(bsf, AV_LOG_INFO, "Extradata\n");
55
56 err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
57
58 ff_cbs_fragment_reset(frag);
59 }
60
61 return err;
62 }
63
64 static void trace_headers_close(AVBSFContext *bsf)
65 {
66 TraceHeadersContext *ctx = bsf->priv_data;
67
68 ff_cbs_fragment_free(&ctx->fragment);
69 ff_cbs_close(&ctx->cbc);
70 }
71
72 static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
73 {
74 TraceHeadersContext *ctx = bsf->priv_data;
75 CodedBitstreamFragment *frag = &ctx->fragment;
76 char tmp[256] = { 0 };
77 int err;
78
79 err = ff_bsf_get_packet_ref(bsf, pkt);
80 if (err < 0)
81 return err;
82
83 if (pkt->flags & AV_PKT_FLAG_KEY)
84 av_strlcat(tmp, ", key frame", sizeof(tmp));
85 if (pkt->flags & AV_PKT_FLAG_CORRUPT)
86 av_strlcat(tmp, ", corrupt", sizeof(tmp));
87
88 if (pkt->pts != AV_NOPTS_VALUE)
89 av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
90 else
91 av_strlcat(tmp, ", no pts", sizeof(tmp));
92 if (pkt->dts != AV_NOPTS_VALUE)
93 av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
94 else
95 av_strlcat(tmp, ", no dts", sizeof(tmp));
96 if (pkt->duration > 0)
97 av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
98
99 av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
100
101 if (av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) {
102 av_log(bsf, AV_LOG_INFO, "Side data:\n");
103
104 err = ff_cbs_read_packet_side_data(ctx->cbc, frag, pkt);
105 ff_cbs_fragment_reset(frag);
106
107 if (err < 0) {
108 av_packet_unref(pkt);
109 return err;
110 }
111 av_log(bsf, AV_LOG_INFO, "Payload:\n");
112 }
113
114 err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
115
116 ff_cbs_fragment_reset(frag);
117
118 if (err < 0)
119 av_packet_unref(pkt);
120 return err;
121 }
122
123 const FFBitStreamFilter ff_trace_headers_bsf = {
124 .p.name = "trace_headers",
125 .p.codec_ids = ff_cbs_all_codec_ids,
126 .priv_data_size = sizeof(TraceHeadersContext),
127 .init = &trace_headers_init,
128 .close = &trace_headers_close,
129 .filter = &trace_headers,
130 };
131