mirror of https://github.com/FFmpeg/FFmpeg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
3.1 KiB
146 lines
3.1 KiB
12 years ago
|
/*
|
||
12 years ago
|
* Copyright (c) 2002 Fabrice Bellard
|
||
|
* Copyright (c) 2013 Michael Niedermayer
|
||
|
* Copyright (c) 2013 James Almer
|
||
12 years ago
|
*
|
||
|
* This file is part of FFmpeg.
|
||
|
*
|
||
|
* FFmpeg is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* FFmpeg is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with FFmpeg; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
*/
|
||
|
|
||
|
#include "config.h"
|
||
12 years ago
|
#include "libavutil/error.h"
|
||
|
#include "libavutil/hash.h"
|
||
|
#include "libavutil/mem.h"
|
||
12 years ago
|
|
||
|
#include <errno.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <stdio.h>
|
||
|
#include <sys/stat.h>
|
||
|
|
||
|
#if HAVE_IO_H
|
||
|
#include <io.h>
|
||
|
#endif
|
||
|
#if HAVE_UNISTD_H
|
||
|
#include <unistd.h>
|
||
|
#endif
|
||
|
|
||
|
#define SIZE 65536
|
||
|
|
||
12 years ago
|
static struct AVHashContext *hash;
|
||
|
static uint8_t *res;
|
||
|
|
||
|
static void usage(void)
|
||
|
{
|
||
|
int i = 0;
|
||
|
const char *name;
|
||
|
|
||
|
printf("usage: ffhash [algorithm] [input]...\n");
|
||
|
printf("Supported hash algorithms:");
|
||
|
do {
|
||
|
name = av_hash_names(i);
|
||
|
if (name)
|
||
|
printf(" %s", name);
|
||
|
i++;
|
||
|
} while(name);
|
||
|
printf("\n");
|
||
|
}
|
||
|
|
||
|
static void finish(void)
|
||
|
{
|
||
|
int i, len = av_hash_get_size(hash);
|
||
|
|
||
|
printf("%s=0x", av_hash_get_name(hash));
|
||
|
av_hash_final(hash, res);
|
||
|
for (i = 0; i < len; i++)
|
||
|
printf("%02x", res[i]);
|
||
|
}
|
||
|
|
||
12 years ago
|
static int check(char *file)
|
||
12 years ago
|
{
|
||
|
uint8_t buffer[SIZE];
|
||
|
int fd;
|
||
|
int ret = 0;
|
||
|
|
||
12 years ago
|
if (file) fd = open(file, O_RDONLY);
|
||
|
else fd = 0;
|
||
12 years ago
|
if (fd == -1) {
|
||
12 years ago
|
printf("%s=OPEN-FAILED: %s:", av_hash_get_name(hash), strerror(errno));
|
||
12 years ago
|
ret = 1;
|
||
|
goto end;
|
||
|
}
|
||
|
|
||
12 years ago
|
av_hash_init(hash);
|
||
12 years ago
|
for (;;) {
|
||
|
ssize_t size = read(fd, buffer, SIZE);
|
||
|
if (size < 0) {
|
||
12 years ago
|
finish();
|
||
|
printf("+READ-FAILED: %s", strerror(errno));
|
||
12 years ago
|
ret = 2;
|
||
|
goto end;
|
||
|
} else if(!size)
|
||
|
break;
|
||
12 years ago
|
av_hash_update(hash, buffer, size);
|
||
12 years ago
|
}
|
||
|
close(fd);
|
||
|
|
||
12 years ago
|
finish();
|
||
12 years ago
|
end:
|
||
12 years ago
|
if (file)
|
||
|
printf(" *%s", file);
|
||
12 years ago
|
printf("\n");
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
12 years ago
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
int i;
|
||
|
int ret = 0;
|
||
|
|
||
12 years ago
|
if (argc == 1) {
|
||
|
usage();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if ((ret = av_hash_alloc(&hash, argv[1])) < 0) {
|
||
|
switch(ret) {
|
||
|
case AVERROR(EINVAL):
|
||
|
printf("Invalid hash type: %s\n", argv[1]);
|
||
|
break;
|
||
|
case AVERROR(ENOMEM):
|
||
|
printf("%s\n", strerror(errno));
|
||
|
break;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
res = av_malloc(av_hash_get_size(hash));
|
||
|
if (!res) {
|
||
|
printf("%s\n", strerror(errno));
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
for (i = 2; i < argc; i++)
|
||
12 years ago
|
ret |= check(argv[i]);
|
||
|
|
||
12 years ago
|
if (argc < 3)
|
||
12 years ago
|
ret |= check(NULL);
|
||
|
|
||
12 years ago
|
av_hash_freep(&hash);
|
||
|
av_freep(&res);
|
||
|
|
||
12 years ago
|
return ret;
|
||
|
}
|