FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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"
28 #include "libavutil/intreadwrite.h"
29 
30 #include "libavcodec/codec_id.h"
31 #include "libavcodec/codec_par.h"
32 #include "libavcodec/packet.h"
33 
34 #include "avformat.h"
35 #include "internal.h"
36 #include "mux.h"
37 
39 {
40  int i;
41  for (i = 0; i < s->nb_streams; i++) {
42  AVStream *st = s->streams[i];
43  AVCodecParameters *par = st->codecpar;
44  if (par->extradata) {
45  uint32_t crc = av_adler32_update(0, par->extradata, par->extradata_size);
46  avio_printf(s->pb, "#extradata %d: %8d, 0x%08"PRIx32"\n",
47  i, par->extradata_size, crc);
48  }
49  }
50 
52 }
53 
54 static av_unused void inline bswap(char *buf, int offset, int size)
55 {
56  if (size == 8) {
57  uint64_t val = AV_RN64(buf + offset);
58  AV_WN64(buf + offset, av_bswap64(val));
59  } else if (size == 4) {
60  uint32_t val = AV_RN32(buf + offset);
61  AV_WN32(buf + offset, av_bswap32(val));
62  } else if (size == 2) {
63  uint16_t val = AV_RN16(buf + offset);
64  AV_WN16(buf + offset, av_bswap16(val));
65  }
66 }
67 
69 {
70  uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
71  char buf[256];
72 
73  snprintf(buf, sizeof(buf), "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, 0x%08"PRIx32,
74  pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size, crc);
75  if (pkt->flags != AV_PKT_FLAG_KEY)
76  av_strlcatf(buf, sizeof(buf), ", F=0x%0X", pkt->flags);
77  if (pkt->side_data_elems) {
78  av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);
79 
80  for (int i = 0; i < pkt->side_data_elems; i++) {
81  const AVPacketSideData *const sd = &pkt->side_data[i];
82  const uint8_t *data = sd->data;
83  uint32_t side_data_crc = 0;
84 
85  switch (sd->type) {
86 #if HAVE_BIGENDIAN
87  uint8_t bswap_buf[FFMAX3(sizeof(AVCPBProperties),
89  sizeof(AVDynamicHDRPlus))];
100  for (size_t j = 0; j < sd->size / 4; j++) {
101  uint8_t buf[4];
102  AV_WL32(buf, AV_RB32(sd->data + 4 * j));
103  side_data_crc = av_adler32_update(side_data_crc, buf, 4);
104  }
105  break;
107 #define BSWAP(struct, field) bswap(bswap_buf, offsetof(struct, field), sizeof(((struct){0}).field))
108 #define BSWAP_RAT(struct, field) do {BSWAP(struct, field.num); BSWAP(struct, field.den);} while(0)
109  if (sd->size == sizeof(AVCPBProperties)) {
110  memcpy(bswap_buf, sd->data, sizeof(AVCPBProperties));
111  data = bswap_buf;
112  BSWAP(AVCPBProperties, max_bitrate);
113  BSWAP(AVCPBProperties, min_bitrate);
114  BSWAP(AVCPBProperties, avg_bitrate);
115  BSWAP(AVCPBProperties, buffer_size);
116  BSWAP(AVCPBProperties, vbv_delay);
117  }
118  goto pod;
119  case AV_PKT_DATA_PRFT:
120  if (sd->size == sizeof(AVProducerReferenceTime)) {
121  memcpy(bswap_buf, sd->data, sizeof(AVProducerReferenceTime));
122  data = bswap_buf;
123  BSWAP(AVProducerReferenceTime, wallclock);
125  }
126  goto pod;
128  if (sd->size == sizeof(AVDynamicHDRPlus)) {
129  memcpy(bswap_buf, sd->data, sizeof(AVDynamicHDRPlus));
130  data = bswap_buf;
131  for (int i = 0; i < FF_ARRAY_ELEMS(((AVDynamicHDRPlus*)0)->params); i++) {
132  BSWAP_RAT(AVDynamicHDRPlus, params[i].window_upper_left_corner_x);
133  BSWAP_RAT(AVDynamicHDRPlus, params[i].window_upper_left_corner_y);
134  BSWAP_RAT(AVDynamicHDRPlus, params[i].window_lower_right_corner_x);
135  BSWAP_RAT(AVDynamicHDRPlus, params[i].window_lower_right_corner_y);
136  BSWAP(AVDynamicHDRPlus, params[i].center_of_ellipse_x);
137  BSWAP(AVDynamicHDRPlus, params[i].center_of_ellipse_y);
138  BSWAP(AVDynamicHDRPlus, params[i].semimajor_axis_internal_ellipse);
139  BSWAP(AVDynamicHDRPlus, params[i].semimajor_axis_external_ellipse);
140  BSWAP(AVDynamicHDRPlus, params[i].semiminor_axis_external_ellipse);
141  //!!! overlap_process_option
142  for(int j = 0; j < FF_ARRAY_ELEMS(((AVDynamicHDRPlus*)0)->params->maxscl); j++)
143  BSWAP_RAT(AVDynamicHDRPlus, params[i].maxscl[j]);
144  BSWAP_RAT(AVDynamicHDRPlus, params[i].average_maxrgb);
145  BSWAP_RAT(AVDynamicHDRPlus, params[i].fraction_bright_pixels);
146  BSWAP_RAT(AVDynamicHDRPlus, params[i].knee_point_x);
147  BSWAP_RAT(AVDynamicHDRPlus, params[i].knee_point_y);
148  for(int j = 0; j < FF_ARRAY_ELEMS(((AVDynamicHDRPlus*)0)->params->distribution_maxrgb); j++) {
149  BSWAP_RAT(AVDynamicHDRPlus, params[i].distribution_maxrgb[j].percentile);
150  BSWAP_RAT(AVDynamicHDRPlus, params[i].bezier_curve_anchors[j]);
151  }
152  BSWAP_RAT(AVDynamicHDRPlus, params[i].color_saturation_weight);
153  }
154  BSWAP_RAT(AVDynamicHDRPlus, targeted_system_display_maximum_luminance);
155  for(int i = 0; i<FF_ARRAY_ELEMS(((AVDynamicHDRPlus*)0)->targeted_system_display_actual_peak_luminance); i++)
156  for(int j = 0; j<FF_ARRAY_ELEMS(((AVDynamicHDRPlus*)0)->targeted_system_display_actual_peak_luminance[0]); j++) {
157  BSWAP_RAT(AVDynamicHDRPlus, targeted_system_display_actual_peak_luminance[i][j]);
158  BSWAP_RAT(AVDynamicHDRPlus, mastering_display_actual_peak_luminance[i][j]);
159  }
160  }
161  pod:
162 #endif
163 
164  default:
165  side_data_crc = av_adler32_update(0, data, sd->size);
166  break;
170  side_data_crc = 0;
171  }
172 
173  av_strlcatf(buf, sizeof(buf), ", %s, %8"SIZE_SPECIFIER", 0x%08"PRIx32,
174  av_packet_side_data_name(sd->type), sd->size, side_data_crc);
175  }
176  }
177  av_strlcatf(buf, sizeof(buf), "\n");
178  avio_write(s->pb, buf, strlen(buf));
179  return 0;
180 }
181 
183  .p.name = "framecrc",
184  .p.long_name = NULL_IF_CONFIG_SMALL("framecrc testing"),
185  .p.audio_codec = AV_CODEC_ID_PCM_S16LE,
186  .p.video_codec = AV_CODEC_ID_RAWVIDEO,
187  .write_header = framecrc_write_header,
188  .write_packet = framecrc_write_packet,
191 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:336
flags
const SwsFlags flags[]
Definition: swscale.c:61
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:105
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
AVOutputFormat::name
const char * name
Definition: avformat.h:506
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
AVFMT_NODIMENSIONS
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition: avformat.h:482
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:481
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:219
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
av_unused
#define av_unused
Definition: attributes.h:131
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:356
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:364
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:386
AVPacket::data
uint8_t * data
Definition: packet.h:535
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:137
data
const char data[16]
Definition: mxf.c:149
AV_PKT_DATA_S12M_TIMECODE
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition: packet.h:288
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:553
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:590
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
AVPacketSideData::size
size_t size
Definition: packet.h:388
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:96
AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
@ AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM
IAMF Recon Gain Info Parameter Data associated with the audio frame.
Definition: packet.h:320
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:47
val
static double val(void *priv, double ch)
Definition: aeval.c:77
pkt
AVPacket * pkt
Definition: movenc.c:60
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
codec_id.h
framecrc_write_packet
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: framecrcenc.c:68
av_packet_side_data_name
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition: packet.c:270
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVPacketSideData::data
uint8_t * data
Definition: packet.h:387
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:111
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:279
AVFormatContext
Format I/O context.
Definition: avformat.h:1264
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:767
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:389
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
framecrc_write_header
static int framecrc_write_header(struct AVFormatContext *s)
Definition: framecrcenc.c:38
FFOutputFormat
Definition: mux.h:61
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: defs.h:328
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:232
av_adler32_update
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:44
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:225
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVPacket::size
int size
Definition: packet.h:536
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:94
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:372
AV_PKT_DATA_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:296
av_bswap32
#define av_bswap32
Definition: bswap.h:47
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:534
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
AV_PKT_DATA_PRFT
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:265
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
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:541
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:142
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:528
packet.h
AVDynamicHDRPlus
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
Definition: hdr_dynamic_metadata.h:243
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:490
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:487
AVStream
Stream structure.
Definition: avformat.h:744
ff_framecrc_muxer
const FFOutputFormat ff_framecrc_muxer
Definition: framecrcenc.c:182
avformat.h
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:546
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:129
avio_printf
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
hdr_dynamic_metadata.h
AVPacket::stream_index
int stream_index
Definition: packet.h:537
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:117
codec_par.h
AVPacket
This structure stores compressed data.
Definition: packet.h:512
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:25
bswap
static av_unused void bswap(char *buf, int offset, int size)
Definition: framecrcenc.c:54
FFMAX3
#define FFMAX3(a, b, c)
Definition: macros.h:48
AV_WN64
#define AV_WN64(p, v)
Definition: intreadwrite.h:376
avstring.h
av_bswap16
#define av_bswap16
Definition: bswap.h:28
av_bswap64
static uint64_t av_const av_bswap64(uint64_t x)
Definition: bswap.h:69
snprintf
#define snprintf
Definition: snprintf.h:34
AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition: packet.h:304
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:547
mux.h
AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition: packet.h:312
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:368