FFmpeg: libavformat/uncodedframecrcenc.c Source File

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 "avformat.h"
27 #include "internal.h"
28 
29 /* Identical to Adler32 when the type is uint8_t. */
30  #define DEFINE_CKSUM_LINE(name, type, conv) \
31 static void cksum_line_ ## name(unsigned *cksum, void *data, unsigned size) \
32 { \
33  type *p = data; \
34  unsigned a = *cksum & 0xFFFF, b = *cksum >> 16; \
35  for (; size > 0; size--, p++) { \
36  a = (a + (unsigned)(conv)) % 65521; \
37  b = (b + a) % 65521; \
38  } \
39  *cksum = a | (b << 16); \
40 }
41 
42 DEFINE_CKSUM_LINE(u8, uint8_t, *p)
43 DEFINE_CKSUM_LINE(s16, int16_t, *p + 0x8000)
44 DEFINE_CKSUM_LINE(s32, int32_t, *p + 0x80000000)
45 DEFINE_CKSUM_LINE(flt, float, *p * 0x80000000 + 0x80000000)
46 DEFINE_CKSUM_LINE(dbl, double, *p * 0x80000000 + 0x80000000)
47 
48  static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
49 {
50  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
51  int i, y;
52  uint8_t *data;
53  int linesize[5] = { 0 };
54 
55  av_bprintf(bp, ", %d x %d", frame->width, frame->height);
56  if (!desc) {
57  av_bprintf(bp, ", unknown");
58  return;
59  }
60  if (av_image_fill_linesizes(linesize, frame->format, frame->width) < 0)
61  return;
62  av_bprintf(bp, ", %s", desc->name);
63  for (i = 0; linesize[i]; i++) {
64  unsigned cksum = 0;
65  int h = frame->height;
66  if ((i == 1 || i == 2) && desc->nb_components >= 3)
67  h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
68  data = frame->data[i];
69  for (y = 0; y < h; y++) {
70  cksum = av_adler32_update(cksum, data, linesize[i]);
71  data += frame->linesize[i];
72  }
73  av_bprintf(bp, ", 0x%08x", cksum);
74  }
75 }
76 
77  static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
78 {
79  int nb_planes, nb_samples, p;
80  const char *name;
81 
82  nb_planes = frame->channels;
83  nb_samples = frame->nb_samples;
84  if (!av_sample_fmt_is_planar(frame->format)) {
85  nb_samples *= nb_planes;
86  nb_planes = 1;
87  }
88  name = av_get_sample_fmt_name(frame->format);
89  av_bprintf(bp, ", %d samples", frame->nb_samples);
90  av_bprintf(bp, ", %s", name ? name : "unknown");
91  for (p = 0; p < nb_planes; p++) {
92  uint32_t cksum = 0;
93  void *d = frame->extended_data[p];
94  switch (frame->format) {
95  case AV_SAMPLE_FMT_U8:
96  case AV_SAMPLE_FMT_U8P:
97  cksum_line_u8(&cksum, d, nb_samples);
98  break;
99  case AV_SAMPLE_FMT_S16:
100  case AV_SAMPLE_FMT_S16P:
101  cksum_line_s16(&cksum, d, nb_samples);
102  break;
103  case AV_SAMPLE_FMT_S32:
104  case AV_SAMPLE_FMT_S32P:
105  cksum_line_s32(&cksum, d, nb_samples);
106  break;
107  case AV_SAMPLE_FMT_FLT:
108  case AV_SAMPLE_FMT_FLTP:
109  cksum_line_flt(&cksum, d, nb_samples);
110  break;
111  case AV_SAMPLE_FMT_DBL:
112  case AV_SAMPLE_FMT_DBLP:
113  cksum_line_dbl(&cksum, d, nb_samples);
114  break;
115  default:
116  av_assert0(!"reached");
117  }
118  av_bprintf(bp, ", 0x%08"PRIx32, cksum);
119  }
120 }
121 
122  static int write_header(struct AVFormatContext *s)
123 {
124  return ff_framehash_write_header(s);
125 }
126 
127  static int write_frame(struct AVFormatContext *s, int stream_index,
128  AVFrame **frame, unsigned flags)
129 {
130  AVBPrint bp;
131  int ret = 0;
132  enum AVMediaType type;
133  const char *type_name;
134 
135  if ((flags & AV_WRITE_UNCODED_FRAME_QUERY))
136  return 0;
137 
138  av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
139  av_bprintf(&bp, "%d, %10"PRId64"",
140  stream_index, (*frame)->pts);
141  type = s->streams[stream_index]->codecpar->codec_type;
142  type_name = av_get_media_type_string(type);
143  av_bprintf(&bp, ", %s", type_name ? type_name : "unknown");
144  switch (type) {
145  case AVMEDIA_TYPE_VIDEO:
146  video_frame_cksum(&bp, *frame);
147  break;
148  case AVMEDIA_TYPE_AUDIO:
149  audio_frame_cksum(&bp, *frame);
150  break;
151  }
152 
153  av_bprint_chars(&bp, '\n', 1);
154  if (av_bprint_is_complete(&bp))
155  avio_write(s->pb, bp.str, bp.len);
156  else
157  ret = AVERROR(ENOMEM);
158  av_bprint_finalize(&bp, NULL);
159  return ret;
160 }
161 
162  static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
163 {
164  return AVERROR(ENOSYS);
165 }
166 
167  AVOutputFormat ff_uncodedframecrc_muxer = {
168  .name = "uncodedframecrc",
169  .long_name = NULL_IF_CONFIG_SMALL("uncoded framecrc testing"),
170  .audio_codec = AV_CODEC_ID_PCM_S16LE,
171  .video_codec = AV_CODEC_ID_RAWVIDEO,
172  .write_header = write_header,
173  .write_packet = write_packet,
174  .write_uncoded_frame = write_frame,
175  .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
176  AVFMT_TS_NEGATIVE,
177 };
AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
NULL
#define NULL
Definition: coverity.c:32
s
const char * s
Definition: avisynth_c.h:768
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2363
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
data
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
imgutils.h
misc image utilities
desc
const char * desc
Definition: nvenc.c:65
audio_frame_cksum
static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
Definition: uncodedframecrcenc.c:77
AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:479
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t
uint8_t
Definition: audio_convert.c:194
AV_SAMPLE_FMT_U8
AV_SAMPLE_FMT_U8
Definition: audio_convert.c:194
AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition: internal.h:628
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:44
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1410
write_packet
static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: uncodedframecrcenc.c:162
frame
static AVFrame * frame
Definition: demuxing_decoding.c:53
flags
static int flags
Definition: log.c:55
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:82
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:112
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
AVERROR
#define AVERROR(e)
Definition: error.h:43
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:186
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
write_header
static int write_header(struct AVFormatContext *s)
Definition: uncodedframecrcenc.c:122
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3880
avassert.h
simple assert() macros that are a bit more flexible than ISO C assert().
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:49
ff_uncodedframecrc_muxer
AVOutputFormat ff_uncodedframecrc_muxer
Definition: uncodedframecrcenc.c:167
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
AVFrame::channels
int channels
number of audio channels, only used for audio.
Definition: frame.h:523
AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:68
DEFINE_CKSUM_LINE
#define DEFINE_CKSUM_LINE(name, type, conv)
Definition: uncodedframecrcenc.c:30
AVOutputFormat::name
const char * name
Definition: avformat.h:507
int32_t
int32_t
Definition: audio_convert.c:194
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
AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
Definition: samplefmt.h:66
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
adler32.h
Public header for Adler-32 hash function implementation.
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:291
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1384
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
type
GLint GLenum type
Definition: opengl_enc.c:105
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
write_frame
static int write_frame(struct AVFormatContext *s, int stream_index, AVFrame **frame, unsigned flags)
Definition: uncodedframecrcenc.c:127
AVMediaType
AVMediaType
Definition: avutil.h:199
video_frame_cksum
static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
Definition: uncodedframecrcenc.c:48
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:76
avformat.h
Main libavformat public API header.
AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:472
AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1020
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:265
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:484
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1407
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:284
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
name
const char * name
Definition: opengl_enc.c:103
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

Generated on Sun May 13 2018 02:04:07 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /