FFmpeg  4.4.5
trace_headers_bsf.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 <stdio.h>
20 
21 #include "libavutil/avstring.h"
22 #include "libavutil/common.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 
48  if (bsf->par_in->extradata) {
49  CodedBitstreamFragment *frag = &ctx->fragment;
50 
51  av_log(bsf, AV_LOG_INFO, "Extradata\n");
52 
53  err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
54 
56  }
57 
58  return err;
59 }
60 
62 {
64 
65  ff_cbs_fragment_free(&ctx->fragment);
66  ff_cbs_close(&ctx->cbc);
67 }
68 
70 {
72  CodedBitstreamFragment *frag = &ctx->fragment;
73  char tmp[256] = { 0 };
74  int err;
75 
76  err = ff_bsf_get_packet_ref(bsf, pkt);
77  if (err < 0)
78  return err;
79 
80  if (pkt->flags & AV_PKT_FLAG_KEY)
81  av_strlcat(tmp, ", key frame", sizeof(tmp));
83  av_strlcat(tmp, ", corrupt", sizeof(tmp));
84 
85  if (pkt->pts != AV_NOPTS_VALUE)
86  av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
87  else
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);
91  else
92  av_strlcat(tmp, ", no dts", sizeof(tmp));
93  if (pkt->duration > 0)
94  av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
95 
96  av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
97 
98  err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
99 
100  ff_cbs_fragment_reset(frag);
101 
102  if (err < 0)
104  return err;
105 }
106 
108  .name = "trace_headers",
109  .priv_data_size = sizeof(TraceHeadersContext),
111  .close = &trace_headers_close,
112  .filter = &trace_headers,
114 };
static enum AVCodecID codec_ids[]
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:253
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:53
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:126
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:156
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:288
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:270
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:75
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:170
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhddsp.c:27
common internal and external API header
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:411
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
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:93
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
The bitstream filter state.
Definition: bsf.h:49
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:70
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:77
const char * name
Definition: bsf.h:99
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
This structure stores compressed data.
Definition: packet.h:346
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int size
Definition: packet.h:370
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
Context structure for coded bitstream operations.
Definition: cbs.h:170
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:118
CodedBitstreamContext * cbc
CodedBitstreamFragment fragment
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
AVPacket * pkt
Definition: movenc.c:59
AVFormatContext * ctx
Definition: movenc.c:48
const AVBitStreamFilter ff_trace_headers_bsf
static int trace_headers_init(AVBSFContext *bsf)
static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
static void trace_headers_close(AVBSFContext *bsf)