FFmpeg
murmur3.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
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
8  * License 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <inttypes.h>
22 #include <stdio.h>
23 
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/murmur3.h"
27 
28 int main(void)
29 {
30  int i;
31  uint8_t hash_result[16] = {0};
32  struct AVMurMur3 *ctx = av_murmur3_alloc();
33 #if 1
34  uint8_t in[256] = {0};
35  uint8_t *hashes = av_mallocz(256 * 16);
36  for (i = 0; i < 256; i++)
37  {
38  in[i] = i;
40  // Note: this actually tests hashing 0 bytes
41  av_murmur3_update(ctx, in, i);
42  av_murmur3_final(ctx, hashes + 16 * i);
43  }
45  av_murmur3_update(ctx, hashes, 256 * 16);
46  av_murmur3_final(ctx, hash_result);
47  av_free(hashes);
48  av_freep(&ctx);
49  printf("result: 0x%"PRIx64" 0x%"PRIx64"\n", AV_RL64(hash_result), AV_RL64(hash_result + 8));
50  // official reference value is 32 bit
51  return AV_RL32(hash_result) != 0x6384ba69;
52 #else
53  uint8_t *in = av_mallocz(512*1024);
55  for (i = 0; i < 40*1024; i++)
56  av_murmur3_update(ctx, in, 512*1024);
57  av_murmur3_final(ctx, hash_result);
58  av_free(in);
59  return hash_result[0];
60 #endif
61 }
AV_RL64
uint64_t_TMPL AV_RL64
Definition: bytestream.h:91
intreadwrite.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_murmur3_alloc
AVMurMur3 * av_murmur3_alloc(void)
Allocate an AVMurMur3 hash context.
Definition: murmur3.c:35
main
int main(void)
Definition: murmur3.c:28
av_murmur3_final
void av_murmur3_final(AVMurMur3 *c, uint8_t dst[16])
Finish hashing and output digest value.
Definition: murmur3.c:144
printf
printf("static const uint8_t my_array[100] = {\n")
AVMurMur3
Definition: murmur3.c:28
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
av_murmur3_init_seeded
void av_murmur3_init_seeded(AVMurMur3 *c, uint64_t seed)
Initialize or reinitialize an AVMurMur3 hash context with a seed.
Definition: murmur3.c:40
av_murmur3_init
void av_murmur3_init(AVMurMur3 *c)
Initialize or reinitialize an AVMurMur3 hash context.
Definition: murmur3.c:46
mem.h
av_murmur3_update
void av_murmur3_update(AVMurMur3 *c, const uint8_t *src, size_t len)
Update hash context with new data.
Definition: murmur3.c:95
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
murmur3.h