FFmpeg
Loading...
Searching...
No Matches
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"
29
30#include "libavcodec/codec_id.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
54av_unused static void inline bswap(char *buf, int offset, int size)
55{
56 if (size == 8) {
57 uint64_t val = AV_RN64(buf + offset);
59 } else if (size == 4) {
60 uint32_t val = AV_RN32(buf + offset);
62 } else if (size == 2) {
63 uint16_t val = AV_RN16(buf + offset);
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, %8zu, 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};
SwsAArch64OpImplParams params
Definition ops.c:51
Public header for Adler-32 hash function implementation.
static double val(void *priv, double ch)
Definition aeval.c:77
const FFOutputFormat ff_framecrc_muxer
Main libavformat public API header.
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition avformat.h:502
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition avformat.h:501
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition avformat.h:510
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition avformat.h:507
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition avstring.c:103
static uint64_t av_const av_bswap64(uint64_t x)
Definition bswap.h:69
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static AVPacket * pkt
static int framecrc_write_header(struct AVFormatContext *s)
Definition framecrcenc.c:38
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition framecrcenc.c:68
static av_unused void bswap(char *buf, int offset, int size)
Definition framecrcenc.c:54
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
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
@ AV_CODEC_ID_PCM_S16LE
Definition codec_id.h:330
const char * av_packet_side_data_name(enum AVPacketSideDataType type)
Definition packet.c:269
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
Definition packet.h:288
@ 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_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition packet.h:296
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition packet.h:265
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition packet.h:219
@ 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
@ AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
IAMF Demixing Info Parameter Data associated with the audio frame.
Definition packet.h:312
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition packet.h:225
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition packet.h:47
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition packet.h:105
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition packet.h:142
@ 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
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition packet.h:232
@ AV_PKT_DATA_FALLBACK_TRACK
This side data contains an integer value representing the stream index of a "fallback" track.
Definition packet.h:137
@ AV_PKT_DATA_IAMF_MIX_GAIN_PARAM
IAMF Mix Gain Parameter Data associated with the audio frame.
Definition packet.h:304
@ AV_PKT_DATA_REPLAYGAIN
This side data should be associated with an audio stream and contains ReplayGain information in form ...
Definition packet.h:96
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
Calculate the Adler32 checksum of a buffer.
Definition adler32.c:44
#define AV_WN32(p, v)
#define AV_RN64(p)
#define AV_RN32(p)
#define AV_WL32(p, v)
#define AV_RB32(p)
#define AV_WN64(p, v)
#define AV_WN16(p, v)
#define AV_RN16(p)
unsigned offset
Definition libaomenc.c:763
static void bswap_buf(uint32_t *dst, const uint32_t *src, int w)
Definition bswapdsp.c:25
#define av_unused
Definition attributes.h:164
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMAX3(a, b, c)
Definition macros.h:48
const char data[16]
Definition mxf.c:149
#define av_bswap32
Definition bswap.h:47
#define av_bswap16
Definition bswap.h:28
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
This structure describes the bitrate properties of an encoded bitstream.
Definition defs.h:282
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
Format I/O context.
Definition avformat.h:1333
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:424
uint8_t * data
Definition packet.h:425
enum AVPacketSideDataType type
Definition packet.h:427
This structure stores compressed data.
Definition packet.h:580
This structure supplies correlation between a packet timestamp and a wall clock production time.
Definition defs.h:331
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int size