FFmpeg
trace_headers.c
Go to the documentation of this file.
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 
29 
30 typedef struct TraceHeadersContext {
34 
35 
37 {
39  int err;
40 
41  err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
42  if (err < 0)
43  return err;
44 
45  ctx->cbc->trace_enable = 1;
46  ctx->cbc->trace_level = AV_LOG_INFO;
47  ctx->cbc->trace_context = ctx->cbc;
48  ctx->cbc->trace_read_callback = ff_cbs_trace_read_log;
49 
50  if (bsf->par_in->extradata) {
51  CodedBitstreamFragment *frag = &ctx->fragment;
52 
53  av_log(bsf, AV_LOG_INFO, "Extradata\n");
54 
55  err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
56 
58  }
59 
60  return err;
61 }
62 
64 {
66 
67  ff_cbs_fragment_free(&ctx->fragment);
68  ff_cbs_close(&ctx->cbc);
69 }
70 
72 {
74  CodedBitstreamFragment *frag = &ctx->fragment;
75  char tmp[256] = { 0 };
76  int err;
77 
78  err = ff_bsf_get_packet_ref(bsf, pkt);
79  if (err < 0)
80  return err;
81 
82  if (pkt->flags & AV_PKT_FLAG_KEY)
83  av_strlcat(tmp, ", key frame", sizeof(tmp));
85  av_strlcat(tmp, ", corrupt", sizeof(tmp));
86 
87  if (pkt->pts != AV_NOPTS_VALUE)
88  av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
89  else
90  av_strlcat(tmp, ", no pts", sizeof(tmp));
91  if (pkt->dts != AV_NOPTS_VALUE)
92  av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
93  else
94  av_strlcat(tmp, ", no dts", sizeof(tmp));
95  if (pkt->duration > 0)
96  av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
97 
98  av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
99 
101  av_log(bsf, AV_LOG_INFO, "Side data:\n");
102 
103  err = ff_cbs_read_packet_side_data(ctx->cbc, frag, pkt);
104  ff_cbs_fragment_reset(frag);
105 
106  if (err < 0) {
108  return err;
109  }
110  av_log(bsf, AV_LOG_INFO, "Payload:\n");
111  }
112 
113  err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
114 
115  ff_cbs_fragment_reset(frag);
116 
117  if (err < 0)
119  return err;
120 }
121 
123  .p.name = "trace_headers",
124  .p.codec_ids = ff_cbs_all_codec_ids,
125  .priv_data_size = sizeof(TraceHeadersContext),
127  .close = &trace_headers_close,
128  .filter = &trace_headers,
129 };
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
trace_headers_close
static void trace_headers_close(AVBSFContext *bsf)
Definition: trace_headers.c:63
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
bsf_internal.h
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:185
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
ff_cbs_read_extradata
int ff_cbs_read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecParameters *par)
Read the extradata bitstream found in codec parameters into a fragment, then split into units and dec...
Definition: cbs.c:285
TraceHeadersContext::fragment
CodedBitstreamFragment fragment
Definition: trace_headers.c:32
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
ff_cbs_read_packet_side_data
int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Definition: cbs.c:311
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:171
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
cbs.h
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:540
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:577
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:141
bsf.h
ff_cbs_trace_read_log
void ff_cbs_trace_read_log(void *trace_context, GetBitContext *gbc, int length, const char *str, const int *subscripts, int64_t value)
Helper function for read tracing which formats the syntax element and logs the result.
Definition: cbs.c:507
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:578
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
ctx
AVFormatContext * ctx
Definition: movenc.c:48
NULL
#define NULL
Definition: coverity.c:32
FFBitStreamFilter
Definition: bsf_internal.h:27
ff_cbs_all_codec_ids
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:61
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
trace_headers_init
static int trace_headers_init(AVBSFContext *bsf)
Definition: trace_headers.c:36
trace_headers
static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
Definition: trace_headers.c:71
AVPacket::size
int size
Definition: packet.h:523
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:521
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:528
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
log.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:252
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:83
av_strlcat
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
Definition: avstring.c:95
TraceHeadersContext
Definition: trace_headers.c:30
ff_cbs_read_packet
int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
Definition: cbs.c:303
avutil.h
ff_cbs_init
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:499
ff_trace_headers_bsf
const FFBitStreamFilter ff_trace_headers_bsf
Definition: trace_headers.c:122
TraceHeadersContext::cbc
CodedBitstreamContext * cbc
Definition: trace_headers.c:31
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:256
avstring.h