Go to the documentation of this file.
1 /*
2  * frame CRC encoder (for codec/format testing)
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
22 #include <inttypes.h>
24 #include "config.h"
25 #include "libavutil/adler32.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavcodec/avcodec.h"
29 #include "avformat.h"
30 #include "internal.h"
33 {
34  int i;
35  for (i = 0; i < s->nb_streams; i++) {
36  AVStream *st = s->streams[i];
37  AVCodecParameters *par = st->codecpar;
38  if (par->extradata) {
39  uint32_t crc = av_adler32_update(0, par->extradata, par->extradata_size);
40  avio_printf(s->pb, "#extradata %d: %8d, 0x%08"PRIx32"\n",
41  i, par->extradata_size, crc);
42  }
43  }
45  return ff_framehash_write_header(s);
46 }
48 static av_unused void inline bswap(char *buf, int offset, int size)
49 {
50  if (size == 8) {
51  uint64_t val = AV_RN64(buf + offset);
52  AV_WN64(buf + offset, av_bswap64(val));
53  } else if (size == 4) {
54  uint32_t val = AV_RN32(buf + offset);
55  AV_WN32(buf + offset, av_bswap32(val));
56  }
57 }
60 {
61  uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
62  char buf[256];
64  snprintf(buf, sizeof(buf), "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, 0x%08"PRIx32,
65  pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size, crc);
66  if (pkt->flags != AV_PKT_FLAG_KEY)
67  av_strlcatf(buf, sizeof(buf), ", F=0x%0X", pkt->flags);
68  if (pkt->side_data_elems) {
69  int i;
70  av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);
72  for (i=0; i<pkt->side_data_elems; i++) {
73  const AVPacketSideData *const sd = &pkt->side_data[i];
74  const uint8_t *data = sd->data;
75  uint32_t side_data_crc = 0;
77  switch (sd->type) {
80  sizeof(AVProducerReferenceTime))];
91  for (int j = 0; j < sd->size / 4; j++) {
92  uint8_t buf[4];
93  AV_WL32(buf, AV_RB32(sd->data + 4 * j));
94  side_data_crc = av_adler32_update(side_data_crc, buf, 4);
95  }
96  break;
98 #define BSWAP(struct, field) bswap(bswap_buf, offsetof(struct, field), sizeof(((struct){0}).field))
99  if (sd->size == sizeof(AVCPBProperties)) {
100  memcpy(bswap_buf, sd->data, sizeof(AVCPBProperties));
101  data = bswap_buf;
102  BSWAP(AVCPBProperties, max_bitrate);
103  BSWAP(AVCPBProperties, min_bitrate);
104  BSWAP(AVCPBProperties, avg_bitrate);
105  BSWAP(AVCPBProperties, buffer_size);
106  BSWAP(AVCPBProperties, vbv_delay);
107  }
108  goto pod;
109  case AV_PKT_DATA_PRFT:
110  if (sd->size == sizeof(AVProducerReferenceTime)) {
111  memcpy(bswap_buf, sd->data, sizeof(AVProducerReferenceTime));
112  data = bswap_buf;
113  BSWAP(AVProducerReferenceTime, wallclock);
115  }
116  goto pod;
117  pod:
118 #endif
119  default:
120  side_data_crc = av_adler32_update(0, data, sd->size);
121  }
122  av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc);
123  }
124  }
125  av_strlcatf(buf, sizeof(buf), "\n");
126  avio_write(s->pb, buf, strlen(buf));
127  return 0;
128 }
131  .name = "framecrc",
132  .long_name = NULL_IF_CONFIG_SMALL("framecrc testing"),
133  .audio_codec = AV_CODEC_ID_PCM_S16LE,
134  .video_codec = AV_CODEC_ID_RAWVIDEO,
135  .write_header = framecrc_write_header,
136  .write_packet = framecrc_write_packet,
139 };
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:268
static int framecrc_write_header(struct AVFormatContext *s)
Definition: framecrcenc.c:32
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:114
int size
Definition: packet.h:370
This side data contains an integer value representing the stream index of a "fallback" track...
Definition: packet.h:140
AVPacket * pkt
Definition: movenc.c:59
size_t size
Definition: packet.h:311
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:222
Format I/O context.
Definition: avformat.h:1247
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: framecrcenc.c:59
static av_unused void bswap(char *buf, int offset, int size)
Definition: framecrcenc.c:48
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:108
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:91
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1315
uint8_t * data
Definition: packet.h:369
uint8_t * data
Definition: packet.h:307
ptrdiff_t size
Definition: opengl_enc.c:100
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:225
The packet contains a keyframe.
Definition: packet.h:410
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette...
Definition: packet.h:46
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
enum AVPacketSideDataType type
Definition: packet.h:313
int side_data_elems
Definition: packet.h:381
#define FFMAX(a, b)
Definition: common.h:103
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:45
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1303
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:228
const char * name
Definition: avformat.h:500
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_framehash_write_header(AVFormatContext *s)
Set the timebase for each stream from the corresponding codec timebase and print it.
Definition: framehash.c:23
Stream structure.
Definition: avformat.h:884
Public header for Adler-32 hash function implementation.
Content light level (based on CTA-861.3).
Definition: packet.h:235
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:453
#define av_bswap32
Definition: bswap.h:33
static uint64_t av_const av_bswap64(uint64_t x)
Definition: bswap.h:73
Libavcodec external API header.
AVIOContext * pb
I/O context.
Definition: avformat.h:1289
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
#define snprintf
Definition: snprintf.h:34
#define AV_RN32(p)
Definition: intreadwrite.h:364
#define flags(name, subs,...)
Definition: cbs_av1.c:561
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: packet.h:99
static void bswap_buf(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.c:25
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:291
Main libavformat public API header.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:380
AVOutputFormat ff_framecrc_muxer
Definition: framecrcenc.c:130
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
This structure supplies correlation between a packet timestamp and a wall clock production time...
Definition: avcodec.h:503
Format allows variable fps.
Definition: avformat.h:465
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:145
#define AV_RN64(p)
Definition: intreadwrite.h:368
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:368
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1049
int stream_index
Definition: packet.h:371
Format allows muxing negative timestamps.
Definition: avformat.h:477
static double val(void *priv, double ch)
Definition: aeval.c:76
This structure stores compressed data.
Definition: packet.h:346
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int i
Definition: input.c:407
#define av_unused
Definition: attributes.h:131
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: packet.h:120
#define AV_WN64(p, v)
Definition: intreadwrite.h:380