2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 // Frame-by-frame MD5 Checksum
13 // ===========================
15 // This example builds upon the simple decoder loop to show how checksums
16 // of the decoded output can be generated. These are used for validating
17 // decoder implementations against the reference implementation, for example.
21 // The Message-Digest 5 (MD5) is a well known hash function. We have provided
22 // an implementation derived from the RSA Data Security, Inc. MD5 Message-Digest
23 // Algorithm for your use. Our implmentation only changes the interface of this
24 // reference code. You must include the `md5_utils.h` header for access to these
27 // Processing The Decoded Data
28 // ---------------------------
29 // Each row of the image is passed to the MD5 accumulator. First the Y plane
30 // is processed, then U, then V. It is important to honor the image's `stride`
37 #include "aom/aom_decoder.h"
38 #include "aom/aomdx.h"
39 #include "common/md5_utils.h"
40 #include "common/tools_common.h"
41 #include "common/video_reader.h"
43 static void get_image_md5(const aom_image_t
*img
, unsigned char digest
[16]) {
49 for (plane
= 0; plane
< 3; ++plane
) {
50 const unsigned char *buf
= img
->planes
[plane
];
51 const int stride
= img
->stride
[plane
];
52 const int w
= plane
? (img
->d_w
+ 1) >> 1 : img
->d_w
;
53 const int h
= plane
? (img
->d_h
+ 1) >> 1 : img
->d_h
;
55 for (y
= 0; y
< h
; ++y
) {
56 MD5Update(&md5
, buf
, w
);
61 MD5Final(digest
, &md5
);
64 static void print_md5(FILE *stream
, unsigned char digest
[16]) {
67 for (i
= 0; i
< 16; ++i
) fprintf(stream
, "%02x", digest
[i
]);
70 static const char *exec_name
;
72 void usage_exit(void) {
73 fprintf(stderr
, "Usage: %s <infile> <outfile>\n", exec_name
);
77 int main(int argc
, char **argv
) {
80 aom_codec_ctx_t codec
;
81 AvxVideoReader
*reader
= NULL
;
82 const AvxVideoInfo
*info
= NULL
;
83 const AvxInterface
*decoder
= NULL
;
87 if (argc
!= 3) die("Invalid number of arguments.");
89 reader
= aom_video_reader_open(argv
[1]);
90 if (!reader
) die("Failed to open %s for reading.", argv
[1]);
92 if (!(outfile
= fopen(argv
[2], "wb")))
93 die("Failed to open %s for writing.", argv
[2]);
95 info
= aom_video_reader_get_info(reader
);
97 decoder
= get_aom_decoder_by_fourcc(info
->codec_fourcc
);
98 if (!decoder
) die("Unknown input codec.");
100 printf("Using %s\n", aom_codec_iface_name(decoder
->codec_interface()));
102 if (aom_codec_dec_init(&codec
, decoder
->codec_interface(), NULL
, 0))
103 die_codec(&codec
, "Failed to initialize decoder");
105 while (aom_video_reader_read_frame(reader
)) {
106 aom_codec_iter_t iter
= NULL
;
107 aom_image_t
*img
= NULL
;
108 size_t frame_size
= 0;
109 const unsigned char *frame
=
110 aom_video_reader_get_frame(reader
, &frame_size
);
111 if (aom_codec_decode(&codec
, frame
, frame_size
, NULL
))
112 die_codec(&codec
, "Failed to decode frame");
114 while ((img
= aom_codec_get_frame(&codec
, &iter
)) != NULL
) {
115 unsigned char digest
[16];
117 get_image_md5(img
, digest
);
118 print_md5(outfile
, digest
);
119 fprintf(outfile
, " img-%dx%d-%04d.i420\n", img
->d_w
, img
->d_h
,
124 printf("Processed %d frames.\n", frame_cnt
);
125 if (aom_codec_destroy(&codec
)) die_codec(&codec
, "Failed to destroy codec.");
127 aom_video_reader_close(reader
);