FFmpeg
uncodedframecrcenc.c
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2013 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #include "libavutil/adler32.h"
22 #include "libavutil/avassert.h"
23 #include "libavutil/bprint.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavformat/mux.h"
27 #include "avformat.h"
28 #include "internal.h"
29 
30 /* Identical to Adler32 when the type is uint8_t. */
31 #define DEFINE_CKSUM_LINE(name, type, conv) \
32 static void cksum_line_ ## name(unsigned *cksum, void *data, unsigned size) \
33 { \
34  type *p = data; \
35  unsigned a = *cksum & 0xFFFF, b = *cksum >> 16; \
36  for (; size > 0; size--, p++) { \
37  a = (a + (unsigned)(conv)) % 65521; \
38  b = (b + a) % 65521; \
39  } \
40  *cksum = a | (b << 16); \
41 }
42 
43 DEFINE_CKSUM_LINE(u8, uint8_t, *p)
44 DEFINE_CKSUM_LINE(s16, int16_t, *p + 0x8000)
45 DEFINE_CKSUM_LINE(s32, int32_t, *p + 0x80000000)
46 DEFINE_CKSUM_LINE(flt, float, *p * 0x80000000 + 0x80000000)
47 DEFINE_CKSUM_LINE(dbl, double, *p * 0x80000000 + 0x80000000)
48 
49 static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
50 {
52  int i, y;
53  uint8_t *data;
54  int linesize[5] = { 0 };
55 
56  av_bprintf(bp, ", %d x %d", frame->width, frame->height);
57  if (!desc) {
58  av_bprintf(bp, ", unknown");
59  return;
60  }
61  if (av_image_fill_linesizes(linesize, frame->format, frame->width) < 0)
62  return;
63  av_bprintf(bp, ", %s", desc->name);
64  for (i = 0; linesize[i]; i++) {
65  unsigned cksum = 0;
66  int h = frame->height;
67  if ((i == 1 || i == 2) && desc->nb_components >= 3)
68  h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
69  data = frame->data[i];
70  for (y = 0; y < h; y++) {
71  cksum = av_adler32_update(cksum, data, linesize[i]);
72  data += frame->linesize[i];
73  }
74  av_bprintf(bp, ", 0x%08x", cksum);
75  }
76 }
77 
78 static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
79 {
80  int nb_planes, nb_samples, p;
81  const char *name;
82 
83  nb_planes = frame->ch_layout.nb_channels;
84  nb_samples = frame->nb_samples;
85  if (!av_sample_fmt_is_planar(frame->format)) {
86  nb_samples *= nb_planes;
87  nb_planes = 1;
88  }
90  av_bprintf(bp, ", %d samples", frame->nb_samples);
91  av_bprintf(bp, ", %s", name ? name : "unknown");
92  for (p = 0; p < nb_planes; p++) {
93  uint32_t cksum = 0;
94  void *d = frame->extended_data[p];
95  switch (frame->format) {
96  case AV_SAMPLE_FMT_U8:
97  case AV_SAMPLE_FMT_U8P:
98  cksum_line_u8(&cksum, d, nb_samples);
99  break;
100  case AV_SAMPLE_FMT_S16:
101  case AV_SAMPLE_FMT_S16P:
102  cksum_line_s16(&cksum, d, nb_samples);
103  break;
104  case AV_SAMPLE_FMT_S32:
105  case AV_SAMPLE_FMT_S32P:
106  cksum_line_s32(&cksum, d, nb_samples);
107  break;
108  case AV_SAMPLE_FMT_FLT:
109  case AV_SAMPLE_FMT_FLTP:
110  cksum_line_flt(&cksum, d, nb_samples);
111  break;
112  case AV_SAMPLE_FMT_DBL:
113  case AV_SAMPLE_FMT_DBLP:
114  cksum_line_dbl(&cksum, d, nb_samples);
115  break;
116  default:
117  av_assert0(!"reached");
118  }
119  av_bprintf(bp, ", 0x%08"PRIx32, cksum);
120  }
121 }
122 
123 static int write_header(struct AVFormatContext *s)
124 {
126 }
127 
128 static int write_frame(struct AVFormatContext *s, int stream_index,
129  AVFrame **frame, unsigned flags)
130 {
131  AVBPrint bp;
132  int ret = 0;
133  enum AVMediaType type;
134  const char *type_name;
135 
137  return 0;
138 
140  av_bprintf(&bp, "%d, %10"PRId64"",
141  stream_index, (*frame)->pts);
142  type = s->streams[stream_index]->codecpar->codec_type;
143  type_name = av_get_media_type_string(type);
144  av_bprintf(&bp, ", %s", type_name ? type_name : "unknown");
145  switch (type) {
146  case AVMEDIA_TYPE_VIDEO:
147  video_frame_cksum(&bp, *frame);
148  break;
149  case AVMEDIA_TYPE_AUDIO:
150  audio_frame_cksum(&bp, *frame);
151  break;
152  }
153 
154  av_bprint_chars(&bp, '\n', 1);
155  if (av_bprint_is_complete(&bp))
156  avio_write(s->pb, bp.str, bp.len);
157  else
158  ret = AVERROR(ENOMEM);
159  av_bprint_finalize(&bp, NULL);
160  return ret;
161 }
162 
164 {
165  return AVERROR(ENOSYS);
166 }
167 
169  .name = "uncodedframecrc",
170  .long_name = NULL_IF_CONFIG_SMALL("uncoded framecrc testing"),
171  .audio_codec = AV_CODEC_ID_PCM_S16LE,
172  .video_codec = AV_CODEC_ID_RAWVIDEO,
173  .write_header = write_header,
174  .write_packet = write_packet,
175  .write_uncoded_frame = write_frame,
178 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:318
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2662
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:484
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
pixdesc.h
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
data
const char data[16]
Definition: mxf.c:143
type
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 type
Definition: writing_filters.txt:86
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:59
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
s
#define s(width, name)
Definition: cbs_vp9.c:256
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:114
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
internal.h
write_frame
static int write_frame(struct AVFormatContext *s, int stream_index, AVFrame **frame, unsigned flags)
Definition: uncodedframecrcenc.c:128
NULL
#define NULL
Definition: coverity.c:32
adler32.h
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_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
write_packet
static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: uncodedframecrcenc.c:163
AVMediaType
AVMediaType
Definition: avutil.h:199
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_SAMPLE_FMT_U8P
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
Definition: samplefmt.h:63
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:232
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
bprint.h
write_header
static int write_header(struct AVFormatContext *s)
Definition: uncodedframecrcenc.c:123
AVOutputFormat
Definition: avformat.h:509
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AV_SAMPLE_FMT_U8
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
Definition: samplefmt.h:57
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:494
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:491
ff_uncodedframecrc_muxer
const AVOutputFormat ff_uncodedframecrc_muxer
Definition: uncodedframecrcenc.c:168
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
avformat.h
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
AV_WRITE_UNCODED_FRAME_QUERY
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition: mux.h:95
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
audio_frame_cksum
static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
Definition: uncodedframecrcenc.c:78
DEFINE_CKSUM_LINE
#define DEFINE_CKSUM_LINE(name, type, conv)
Definition: uncodedframecrcenc.c:31
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVPacket
This structure stores compressed data.
Definition: packet.h:351
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
d
d
Definition: ffmpeg_filter.c:153
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
video_frame_cksum
static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
Definition: uncodedframecrcenc.c:49
h
h
Definition: vp9dsp_template.c:2038
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140
mux.h