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  if (err < 0) {
53  av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
54  return err;
55  }
56 
57  ff_cbs_fragment_uninit(ctx->cbc, &ps);
58  }
59 
60  return 0;
61 }
62 
64 {
66 
67  ff_cbs_close(&ctx->cbc);
68 }
69 
71 {
74  AVPacket *in;
75  char tmp[256] = { 0 };
76  int err;
77 
78  err = ff_bsf_get_packet(bsf, &in);
79  if (err < 0)
80  return err;
81 
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));
86 
87  if (in->pts != AV_NOPTS_VALUE)
88  av_strlcatf(tmp, sizeof(tmp), ", pts %"PRId64, in->pts);
89  else
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);
93  else
94  av_strlcat(tmp, ", no dts", sizeof(tmp));
95  if (in->duration > 0)
96  av_strlcatf(tmp, sizeof(tmp), ", duration %"PRId64, in->duration);
97 
98  av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", in->size, tmp);
99 
100  err = ff_cbs_read_packet(ctx->cbc, &au, in);
101  if (err < 0)
102  return err;
103 
104  ff_cbs_fragment_uninit(ctx->cbc, &au);
105 
106  av_packet_move_ref(out, in);
107  av_packet_free(&in);
108 
109  return 0;
110 }
111 
112 static const enum AVCodecID trace_headers_codec_ids[] = {
117 };
118 
120  .name = "trace_headers",
121  .priv_data_size = sizeof(TraceHeadersContext),
123  .close = &trace_headers_close,
124  .filter = &trace_headers,
126 };
static enum AVCodecID trace_headers_codec_ids[]
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:42
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3812
The bitstream filter state.
Definition: avcodec.h:5557
int size
Definition: avcodec.h:1401
static int trace_headers_init(AVBSFContext *bsf)
const AVBitStreamFilter ff_trace_headers_bsf
void * priv_data
Opaque filter-specific private data.
Definition: avcodec.h:5578
static int trace_headers(AVBSFContext *bsf, AVPacket *out)
CodedBitstreamContext * cbc
int trace_enable
Enable trace output during read/write operations.
Definition: cbs.h:183
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:97
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:62
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1418
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:172
const char * name
Definition: avcodec.h:5607
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:645
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1432
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
static void trace_headers_close(AVBSFContext *bsf)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:106
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1406
AVFormatContext * ctx
Definition: movenc.c:48
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:108
int trace_level
Log level to use for trace output.
Definition: cbs.h:189
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Context structure for coded bitstream operations.
Definition: cbs.h:145
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:81
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:151
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[]
int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
Called by the bitstream filters to get the next packet for filtering.
Definition: bsf.c:201
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: avcodec.h:1433
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3826
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1399
FILE * out
Definition: movenc.c:54
This structure stores compressed data.
Definition: avcodec.h:1377
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5585
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1393
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
static uint8_t tmp[11]
Definition: aes_ctr.c:26