author | James Almer <jamrial@gmail.com> | 2013-05-15 22:18:25 (GMT) |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-16 15:58:56 (GMT) |
commit | b22f96b7364eeccd188c47341e7d9e9779a00001 (patch) | |
tree | 953fba2a25b6f19a7c1b6ae9f8fa901af9b5df2e | |
parent | c607a2cc97808c3213bd3b73aa076d81f5470a60 (diff) | |
download | ffmpeg-b22f96b7364eeccd188c47341e7d9e9779a00001.zip ffmpeg-b22f96b7364eeccd188c47341e7d9e9779a00001.tar.gz ffmpeg-b22f96b7364eeccd188c47341e7d9e9779a00001.tar.bz2 |
Rename ffadler to ffhash and expand it using the generic hash API
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | libavutil/Makefile | 2 | ||||
-rw-r--r-- | tools/ffadler.c | 87 | ||||
-rw-r--r-- | tools/ffhash.c | 145 |
4 files changed, 147 insertions, 88 deletions
@@ -67,6 +67,7 @@ /tools/fourcc2pixfmt /tools/ffescape /tools/ffeval +/tools/ffhash /tools/graph2dot /tools/ismindex /tools/pktdumper diff --git a/libavutil/Makefile b/libavutil/Makefile index f7852ee..5dc61e1 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -152,6 +152,6 @@ TESTPROGS = adler32 \ TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo -TOOLS = ffadler ffeval ffescape +TOOLS = ffhash ffeval ffescape $(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2 diff --git a/tools/ffadler.c b/tools/ffadler.c deleted file mode 100644 index 97e6257..0000000 --- a/tools/ffadler.c +++ b/dev/null @@ -1,87 +0,0 @@ -/* -* Copyright (c) 2002 Fabrice Bellard -* Copyright (c) 2013 Michael Niedermayer - * - * 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" -#include "libavutil/adler32.h" - -#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 - -static int check(char *file) -{ - uint8_t buffer[SIZE]; - uint32_t checksum = 1; - int fd; - int ret = 0; - - if (file) fd = open(file, O_RDONLY); - else fd = 0; - if (fd == -1) { - printf("A32=OPEN-FAILED-%d", errno); - ret = 1; - goto end; - } - - for (;;) { - ssize_t size = read(fd, buffer, SIZE); - if (size < 0) { - printf("A32=0x%08x+READ-FAILED-%d", checksum, errno); - ret = 2; - goto end; - } else if(!size) - break; - checksum = av_adler32_update(checksum, buffer, size); - } - close(fd); - - printf("A32=0x%08x", checksum); -end: - if (file) - printf(" *%s", file); - printf("\n"); - - return ret; -} - -int main(int argc, char **argv) -{ - int i; - int ret = 0; - - for (i = 1; i<argc; i++) - ret |= check(argv[i]); - - if (argc == 1) - ret |= check(NULL); - - return ret; -} diff --git a/tools/ffhash.c b/tools/ffhash.c new file mode 100644 index 0000000..99b928d --- a/dev/null +++ b/tools/ffhash.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2002 Fabrice Bellard + * Copyright (c) 2013 Michael Niedermayer + * Copyright (c) 2013 James Almer + * + * 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" +#include "libavutil/error.h" +#include "libavutil/hash.h" +#include "libavutil/mem.h" + +#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 + +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]); +} + +static int check(char *file) +{ + uint8_t buffer[SIZE]; + int fd; + int ret = 0; + + if (file) fd = open(file, O_RDONLY); + else fd = 0; + if (fd == -1) { + printf("%s=OPEN-FAILED: %s:", av_hash_get_name(hash), strerror(errno)); + ret = 1; + goto end; + } + + av_hash_init(hash); + for (;;) { + ssize_t size = read(fd, buffer, SIZE); + if (size < 0) { + finish(); + printf("+READ-FAILED: %s", strerror(errno)); + ret = 2; + goto end; + } else if(!size) + break; + av_hash_update(hash, buffer, size); + } + close(fd); + + finish(); +end: + if (file) + printf(" *%s", file); + printf("\n"); + + return ret; +} + +int main(int argc, char **argv) +{ + int i; + int ret = 0; + + 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++) + ret |= check(argv[i]); + + if (argc < 3) + ret |= check(NULL); + + av_hash_freep(&hash); + av_freep(&res); + + return ret; +} |