2014-01-08 03:15:25 +04:00
|
|
|
/*
|
2016-09-02 00:32:49 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2014-01-08 03:15:25 +04:00
|
|
|
*
|
2016-09-02 00:32:49 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2014-01-08 03:15:25 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Frame-by-frame MD5 Checksum
|
|
|
|
// ===========================
|
|
|
|
//
|
|
|
|
// This example builds upon the simple decoder loop to show how checksums
|
|
|
|
// of the decoded output can be generated. These are used for validating
|
|
|
|
// decoder implementations against the reference implementation, for example.
|
|
|
|
//
|
|
|
|
// MD5 algorithm
|
|
|
|
// -------------
|
|
|
|
// The Message-Digest 5 (MD5) is a well known hash function. We have provided
|
|
|
|
// an implementation derived from the RSA Data Security, Inc. MD5 Message-Digest
|
|
|
|
// Algorithm for your use. Our implmentation only changes the interface of this
|
|
|
|
// reference code. You must include the `md5_utils.h` header for access to these
|
|
|
|
// functions.
|
|
|
|
//
|
|
|
|
// Processing The Decoded Data
|
|
|
|
// ---------------------------
|
|
|
|
// Each row of the image is passed to the MD5 accumulator. First the Y plane
|
|
|
|
// is processed, then U, then V. It is important to honor the image's `stride`
|
|
|
|
// values.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-01-24 23:20:09 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom/aomdx.h"
|
|
|
|
#include "aom/aom_decoder.h"
|
2014-01-24 23:20:09 +04:00
|
|
|
|
2015-02-05 03:11:57 +03:00
|
|
|
#include "../md5_utils.h"
|
|
|
|
#include "../tools_common.h"
|
|
|
|
#include "../video_reader.h"
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "./aom_config.h"
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static void get_image_md5(const aom_image_t *img, unsigned char digest[16]) {
|
2014-01-11 02:50:58 +04:00
|
|
|
int plane, y;
|
|
|
|
MD5Context md5;
|
|
|
|
|
|
|
|
MD5Init(&md5);
|
|
|
|
|
|
|
|
for (plane = 0; plane < 3; ++plane) {
|
|
|
|
const unsigned char *buf = img->planes[plane];
|
|
|
|
const int stride = img->stride[plane];
|
|
|
|
const int w = plane ? (img->d_w + 1) >> 1 : img->d_w;
|
|
|
|
const int h = plane ? (img->d_h + 1) >> 1 : img->d_h;
|
|
|
|
|
|
|
|
for (y = 0; y < h; ++y) {
|
|
|
|
MD5Update(&md5, buf, w);
|
|
|
|
buf += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 02:38:27 +04:00
|
|
|
MD5Final(digest, &md5);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_md5(FILE *stream, unsigned char digest[16]) {
|
|
|
|
int i;
|
|
|
|
|
2016-08-09 04:51:16 +03:00
|
|
|
for (i = 0; i < 16; ++i) fprintf(stream, "%02x", digest[i]);
|
2014-01-11 02:50:58 +04:00
|
|
|
}
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2014-01-24 23:20:09 +04:00
|
|
|
static const char *exec_name;
|
|
|
|
|
2015-05-09 20:33:26 +03:00
|
|
|
void usage_exit(void) {
|
2014-01-24 23:20:09 +04:00
|
|
|
fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-01-08 03:15:25 +04:00
|
|
|
int main(int argc, char **argv) {
|
2014-02-06 06:34:46 +04:00
|
|
|
int frame_cnt = 0;
|
|
|
|
FILE *outfile = NULL;
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_codec_ctx_t codec;
|
|
|
|
AvxVideoReader *reader = NULL;
|
|
|
|
const AvxVideoInfo *info = NULL;
|
|
|
|
const AvxInterface *decoder = NULL;
|
2014-01-24 23:20:09 +04:00
|
|
|
|
|
|
|
exec_name = argv[0];
|
2014-01-11 02:50:58 +04:00
|
|
|
|
2016-08-09 04:51:16 +03:00
|
|
|
if (argc != 3) die("Invalid number of arguments.");
|
2014-01-11 02:50:58 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
reader = aom_video_reader_open(argv[1]);
|
2016-08-09 04:51:16 +03:00
|
|
|
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
2014-01-11 02:50:58 +04:00
|
|
|
|
|
|
|
if (!(outfile = fopen(argv[2], "wb")))
|
2014-02-06 06:34:46 +04:00
|
|
|
die("Failed to open %s for writing.", argv[2]);
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
info = aom_video_reader_get_info(reader);
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
|
2016-08-09 04:51:16 +03:00
|
|
|
if (!decoder) die("Unknown input codec.");
|
2014-01-16 02:38:27 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
printf("Using %s\n", aom_codec_iface_name(decoder->codec_interface()));
|
2014-01-16 02:38:27 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
if (aom_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0))
|
2014-01-08 03:15:25 +04:00
|
|
|
die_codec(&codec, "Failed to initialize decoder");
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
while (aom_video_reader_read_frame(reader)) {
|
|
|
|
aom_codec_iter_t iter = NULL;
|
|
|
|
aom_image_t *img = NULL;
|
2014-01-24 23:20:09 +04:00
|
|
|
size_t frame_size = 0;
|
2016-08-09 04:51:16 +03:00
|
|
|
const unsigned char *frame =
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_video_reader_get_frame(reader, &frame_size);
|
|
|
|
if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
2014-01-08 03:15:25 +04:00
|
|
|
die_codec(&codec, "Failed to decode frame");
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
while ((img = aom_codec_get_frame(&codec, &iter)) != NULL) {
|
2014-01-16 02:38:27 +04:00
|
|
|
unsigned char digest[16];
|
|
|
|
|
|
|
|
get_image_md5(img, digest);
|
|
|
|
print_md5(outfile, digest);
|
2016-08-09 04:51:16 +03:00
|
|
|
fprintf(outfile, " img-%dx%d-%04d.i420\n", img->d_w, img->d_h,
|
|
|
|
++frame_cnt);
|
2014-01-08 03:15:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-11 02:50:58 +04:00
|
|
|
printf("Processed %d frames.\n", frame_cnt);
|
2016-08-31 00:01:10 +03:00
|
|
|
if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_video_reader_close(reader);
|
2014-01-24 23:20:09 +04:00
|
|
|
|
2014-01-08 03:15:25 +04:00
|
|
|
fclose(outfile);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|