FFmpeg
framecrcenc.c
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
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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  */
21 
22 #include <inttypes.h>
23 
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"
31 
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  }
44 
46 }
47 
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 }
58 
60 {
61  uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
62  char buf[256];
63 
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);
71 
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;
76 
77  switch (sd->type) {
78 #if HAVE_BIGENDIAN
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 }
129 
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 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:313
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
AVOutputFormat::name
const char * name
Definition: avformat.h:491
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:465
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:62
av_unused
#define av_unused
Definition: attributes.h:131
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:368
AVPacketSideData
Definition: packet.h:306
AVPacket::data
uint8_t * data
Definition: packet.h:369
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:46
data
const char data[16]
Definition: mxf.c:142
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:387
AV_PKT_DATA_SPHERICAL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:228
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
AVPacketSideData::size
size_t size
Definition: packet.h:311
val
static double val(void *priv, double ch)
Definition: aeval.c:76
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:108
av_adler32_update
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
av_bswap32
#define av_bswap32
Definition: bswap.h:33
AV_PKT_DATA_REPLAYGAIN
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition: packet.h:99
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_PKT_DATA_AUDIO_SERVICE_TYPE
@ AV_PKT_DATA_AUDIO_SERVICE_TYPE
This side data should be associated with an audio stream and corresponds to enum AVAudioServiceType.
Definition: packet.h:120
framecrc_write_packet
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: framecrcenc.c:59
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PKT_DATA_STEREO3D
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:114
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:222
AVPacketSideData::data
uint8_t * data
Definition: packet.h:307
AV_PKT_DATA_PRFT
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:268
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:453
AVFormatContext
Format I/O context.
Definition: avformat.h:1232
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:313
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
framecrc_write_header
static int framecrc_write_header(struct AVFormatContext *s)
Definition: framecrcenc.c:32
adler32.h
bswap_buf
static void bswap_buf(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.c:25
AVProducerReferenceTime
This structure supplies correlation between a packet timestamp and a wall clock production time.
Definition: avcodec.h:503
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
ff_framecrc_muxer
AVOutputFormat ff_framecrc_muxer
Definition: framecrcenc.c:130
AVPacket::size
int size
Definition: packet.h:370
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
size
int size
Definition: twinvq_data.h:10344
AV_RB32
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:96
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:225
offset
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
Definition: writing_filters.txt:86
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:235
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
i
int i
Definition: input.c:407
AVOutputFormat
Definition: avformat.h:490
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
uint8_t
uint8_t
Definition: audio_convert.c:194
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:145
avcodec.h
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:475
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
AVStream
Stream structure.
Definition: avformat.h:873
avformat.h
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:380
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:291
avio_printf
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
AVPacket::stream_index
int stream_index
Definition: packet.h:371
AVPacket
This structure stores compressed data.
Definition: packet.h:346
ff_framehash_write_header
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
AV_PKT_DATA_FALLBACK_TRACK
@ AV_PKT_DATA_FALLBACK_TRACK
This side data contains an integer value representing the stream index of a "fallback" track.
Definition: packet.h:140
bswap
static av_unused void bswap(char *buf, int offset, int size)
Definition: framecrcenc.c:48
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_WN64
#define AV_WN64(p, v)
Definition: intreadwrite.h:380
avstring.h
av_bswap64
static uint64_t av_const av_bswap64(uint64_t x)
Definition: bswap.h:73
snprintf
#define snprintf
Definition: snprintf.h:34
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:381