FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "cbs.h"
27 
28 
29 typedef struct TraceHeadersContext {
32 
33 
35 {
37  int err;
38 
39  err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
40  if (err < 0)
41  return err;
42 
43  ctx->cbc->trace_enable = 1;
44  ctx->cbc->trace_level = AV_LOG_INFO;
45 
46  if (bsf->par_in->extradata) {
48 
49  av_log(bsf, AV_LOG_INFO, "Extradata\n");
50 
51  err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
52 
53  ff_cbs_fragment_uninit(ctx->cbc, &ps);
54  }
55 
56  return err;
57 }
58 
60 {
62 
63  ff_cbs_close(&ctx->cbc);
64 }
65 
67 {
70  char tmp[256] = { 0 };
71  int err;
72 
73  err = ff_bsf_get_packet_ref(bsf, pkt);
74  if (err < 0)
75  return err;
76 
77  if (pkt->flags & AV_PKT_FLAG_KEY)
78  av_strlcat(tmp, ", key frame", sizeof(tmp));
79  if (pkt->flags & AV_PKT_FLAG_CORRUPT)
80  av_strlcat(tmp, ", corrupt", sizeof(tmp));
81 
82  if (pkt->pts != AV_NOPTS_VALUE)
83  av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, pkt->pts);
84  else
85  av_strlcat(tmp, ", no pts", sizeof(tmp));
86  if (pkt->dts != AV_NOPTS_VALUE)
87  av_strlcatf(tmp, sizeof(tmp), ", dts %"PRId64, pkt->dts);
88  else
89  av_strlcat(tmp, ", no dts", sizeof(tmp));
90  if (pkt->duration > 0)
91  av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, pkt->duration);
92 
93  av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
94 
95  err = ff_cbs_read_packet(ctx->cbc, &au, pkt);
96 
97  ff_cbs_fragment_uninit(ctx->cbc, &au);
98 
99  if (err < 0)
100  av_packet_unref(pkt);
101  return err;
102 }
103 
105  .name = "trace_headers",
106  .priv_data_size = sizeof(TraceHeadersContext),
108  .close = &trace_headers_close,
109  .filter = &trace_headers,
111 };
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:74
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3899
The bitstream filter state.
Definition: avcodec.h:5702
int size
Definition: avcodec.h:1445
static int trace_headers_init(AVBSFContext *bsf)
const AVBitStreamFilter ff_trace_headers_bsf
static AVPacket pkt
void * priv_data
Opaque filter-specific private data.
Definition: avcodec.h:5723
CodedBitstreamContext * cbc
int trace_enable
Enable trace output during read/write operations.
Definition: cbs.h:197
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:153
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1462
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:233
const char * name
Definition: avcodec.h:5752
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1476
static void trace_headers_close(AVBSFContext *bsf)
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:139
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1450
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:598
int trace_level
Log level to use for trace output.
Definition: cbs.h:203
Context structure for coded bitstream operations.
Definition: cbs.h:159
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:113
static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
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:213
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
common internal and external API header
static enum AVCodecID codec_ids[]
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: avcodec.h:1477
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:52
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3913
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1443
This structure stores compressed data.
Definition: avcodec.h:1421
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5730
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:238
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1437
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
static uint8_t tmp[11]
Definition: aes_ctr.c:26