summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libffmpeg/libavutil/adler32.c53
-rw-r--r--src/libffmpeg/libavutil/adler32.h7
-rw-r--r--src/libffmpeg/libavutil/crc.c84
-rw-r--r--src/libffmpeg/libavutil/crc.h15
-rw-r--r--src/libffmpeg/libavutil/lls.c149
-rw-r--r--src/libffmpeg/libavutil/lls.h43
-rw-r--r--src/libffmpeg/libavutil/log.c80
-rw-r--r--src/libffmpeg/libavutil/log.h42
-rw-r--r--src/libffmpeg/libavutil/md5.c184
-rw-r--r--src/libffmpeg/libavutil/md5.h14
10 files changed, 671 insertions, 0 deletions
diff --git a/src/libffmpeg/libavutil/adler32.c b/src/libffmpeg/libavutil/adler32.c
new file mode 100644
index 000000000..e185a77c4
--- /dev/null
+++ b/src/libffmpeg/libavutil/adler32.c
@@ -0,0 +1,53 @@
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "common.h"
+#include "adler32.h"
+
+#define BASE 65521L /* largest prime smaller than 65536 */
+
+#define DO1(buf) {s1 += *buf++; s2 += s1;}
+#define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
+#define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
+
+unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
+{
+ unsigned long s1 = adler & 0xffff;
+ unsigned long s2 = adler >> 16;
+
+ while (len>0) {
+#ifdef CONFIG_SMALL
+ while(len>4 && s2 < (1U<<31)){
+ DO4(buf); len-=4;
+#else
+ while(len>16 && s2 < (1U<<31)){
+ DO16(buf); len-=16;
+#endif
+ }
+ DO1(buf); len--;
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ return (s2 << 16) | s1;
+}
+
+#ifdef TEST
+#include "log.h"
+#define LEN 7001
+volatile int checksum;
+int main(){
+ int i;
+ char data[LEN];
+ av_log_level = AV_LOG_DEBUG;
+ for(i=0; i<LEN; i++)
+ data[i]= ((i*i)>>3) + 123*i;
+ for(i=0; i<1000; i++){
+ START_TIMER
+ checksum= av_adler32_update(1, data, LEN);
+ STOP_TIMER("adler")
+ }
+ av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum);
+}
+#endif
diff --git a/src/libffmpeg/libavutil/adler32.h b/src/libffmpeg/libavutil/adler32.h
new file mode 100644
index 000000000..4b035dcdf
--- /dev/null
+++ b/src/libffmpeg/libavutil/adler32.h
@@ -0,0 +1,7 @@
+#ifndef ADLER32_H
+#define ADLER32_H
+
+unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
+ unsigned int len);
+
+#endif
diff --git a/src/libffmpeg/libavutil/crc.c b/src/libffmpeg/libavutil/crc.c
new file mode 100644
index 000000000..13be2020d
--- /dev/null
+++ b/src/libffmpeg/libavutil/crc.c
@@ -0,0 +1,84 @@
+#include "common.h"
+#include "crc.h"
+
+AVCRC *av_crcEDB88320;
+AVCRC *av_crc04C11DB7;
+AVCRC *av_crc8005 ;
+AVCRC *av_crc07 ;
+
+/**
+ * Inits a crc table.
+ * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
+ * @param cts_size size of ctx in bytes
+ * @return <0 on failure
+ */
+int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
+ int i, j;
+ uint32_t c;
+
+ if (bits < 8 || bits > 32 || poly >= (1LL<<bits))
+ return -1;
+ if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024)
+ return -1;
+
+ for (i = 0; i < 256; i++) {
+ if (le) {
+ for (c = i, j = 0; j < 8; j++)
+ c = (c>>1)^(poly & (-(c&1)));
+ ctx[i] = c;
+ } else {
+ for (c = i << 24, j = 0; j < 8; j++)
+ c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) );
+ ctx[i] = bswap_32(c);
+ }
+ }
+ ctx[256]=1;
+#ifndef CONFIG_SMALL
+ if(ctx_size >= sizeof(AVCRC)*1024)
+ for (i = 0; i < 256; i++)
+ for(j=0; j<3; j++)
+ ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ];
+#endif
+
+ return 0;
+}
+
+uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){
+ const uint8_t *end= buffer+length;
+
+#ifndef CONFIG_SMALL
+ if(!ctx[256])
+ while(buffer<end-3){
+ crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4;
+ crc = ctx[3*256 + ( crc &0xFF)]
+ ^ctx[2*256 + ((crc>>8 )&0xFF)]
+ ^ctx[1*256 + ((crc>>16)&0xFF)]
+ ^ctx[0*256 + ((crc>>24) )];
+ }
+#endif
+ while(buffer<end)
+ crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);
+
+ return crc;
+}
+
+#ifdef TEST
+#undef printf
+main(){
+ uint8_t buf[1999];
+ int i;
+ int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04},
+ {0, 32, 0x04c11db7L, 0xC0F5BAE0},
+ {0, 16, 0x8005 , 0x1FBB },
+ {0, 8, 0x07 , 0xE3 },};
+ AVCRC ctx[1 ? 1024:257];
+
+ for(i=0; i<sizeof(buf); i++)
+ buf[i]= i+i*i;
+
+ for(i=0; i<4; i++){
+ av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx));
+ printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf)));
+ }
+}
+#endif
diff --git a/src/libffmpeg/libavutil/crc.h b/src/libffmpeg/libavutil/crc.h
new file mode 100644
index 000000000..c5b217017
--- /dev/null
+++ b/src/libffmpeg/libavutil/crc.h
@@ -0,0 +1,15 @@
+#ifndef CRC_H
+#define CRC_H
+
+typedef uint32_t AVCRC;
+
+extern AVCRC *av_crcEDB88320;
+extern AVCRC *av_crc04C11DB7;
+extern AVCRC *av_crc8005 ;
+extern AVCRC *av_crc07 ;
+
+int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
+uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length);
+
+#endif /* CRC_H */
+
diff --git a/src/libffmpeg/libavutil/lls.c b/src/libffmpeg/libavutil/lls.c
new file mode 100644
index 000000000..6bf4d9278
--- /dev/null
+++ b/src/libffmpeg/libavutil/lls.c
@@ -0,0 +1,149 @@
+/*
+ * linear least squares model
+ *
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file lls.c
+ * linear least squares model
+ */
+
+#include <math.h>
+#include <string.h>
+
+#include "lls.h"
+
+#ifdef TEST
+#define av_log(a,b,...) printf(__VA_ARGS__)
+#endif
+
+void av_init_lls(LLSModel *m, int indep_count){
+ memset(m, 0, sizeof(LLSModel));
+
+ m->indep_count= indep_count;
+}
+
+void av_update_lls(LLSModel *m, double *var, double decay){
+ int i,j;
+
+ for(i=0; i<=m->indep_count; i++){
+ for(j=i; j<=m->indep_count; j++){
+ m->covariance[i][j] *= decay;
+ m->covariance[i][j] += var[i]*var[j];
+ }
+ }
+}
+
+void av_solve_lls(LLSModel *m, double threshold, int min_order){
+ int i,j,k;
+ double (*factor)[MAX_VARS+1]= &m->covariance[1][0];
+ double (*covar )[MAX_VARS+1]= &m->covariance[1][1];
+ double *covar_y = m->covariance[0];
+ int count= m->indep_count;
+
+ for(i=0; i<count; i++){
+ for(j=i; j<count; j++){
+ double sum= covar[i][j];
+
+ for(k=i-1; k>=0; k--)
+ sum -= factor[i][k]*factor[j][k];
+
+ if(i==j){
+ if(sum < threshold)
+ sum= 1.0;
+ factor[i][i]= sqrt(sum);
+ }else
+ factor[j][i]= sum / factor[i][i];
+ }
+ }
+ for(i=0; i<count; i++){
+ double sum= covar_y[i+1];
+ for(k=i-1; k>=0; k--)
+ sum -= factor[i][k]*m->coeff[0][k];
+ m->coeff[0][i]= sum / factor[i][i];
+ }
+
+ for(j=count-1; j>=min_order; j--){
+ for(i=j; i>=0; i--){
+ double sum= m->coeff[0][i];
+ for(k=i+1; k<=j; k++)
+ sum -= factor[k][i]*m->coeff[j][k];
+ m->coeff[j][i]= sum / factor[i][i];
+ }
+
+ m->variance[j]= covar_y[0];
+ for(i=0; i<=j; i++){
+ double sum= m->coeff[j][i]*covar[i][i] - 2*covar_y[i+1];
+ for(k=0; k<i; k++)
+ sum += 2*m->coeff[j][k]*covar[k][i];
+ m->variance[j] += m->coeff[j][i]*sum;
+ }
+ }
+}
+
+double av_evaluate_lls(LLSModel *m, double *param, int order){
+ int i;
+ double out= 0;
+
+ for(i=0; i<=order; i++)
+ out+= param[i]*m->coeff[order][i];
+
+ return out;
+}
+
+#ifdef TEST
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(){
+ LLSModel m;
+ int i, order;
+
+ av_init_lls(&m, 3);
+
+ for(i=0; i<100; i++){
+ double var[4];
+ double eval, variance;
+#if 0
+ var[1] = rand() / (double)RAND_MAX;
+ var[2] = rand() / (double)RAND_MAX;
+ var[3] = rand() / (double)RAND_MAX;
+
+ var[2]= var[1] + var[3]/2;
+
+ var[0] = var[1] + var[2] + var[3] + var[1]*var[2]/100;
+#else
+ var[0] = (rand() / (double)RAND_MAX - 0.5)*2;
+ var[1] = var[0] + rand() / (double)RAND_MAX - 0.5;
+ var[2] = var[1] + rand() / (double)RAND_MAX - 0.5;
+ var[3] = var[2] + rand() / (double)RAND_MAX - 0.5;
+#endif
+ av_update_lls(&m, var, 0.99);
+ av_solve_lls(&m, 0.001, 0);
+ for(order=0; order<3; order++){
+ eval= av_evaluate_lls(&m, var+1, order);
+ av_log(NULL, AV_LOG_DEBUG, "real:%f order:%d pred:%f var:%f coeffs:%f %f %f\n",
+ var[0], order, eval, sqrt(m.variance[order] / (i+1)),
+ m.coeff[order][0], m.coeff[order][1], m.coeff[order][2]);
+ }
+ }
+ return 0;
+}
+
+#endif
diff --git a/src/libffmpeg/libavutil/lls.h b/src/libffmpeg/libavutil/lls.h
new file mode 100644
index 000000000..944fba75d
--- /dev/null
+++ b/src/libffmpeg/libavutil/lls.h
@@ -0,0 +1,43 @@
+/*
+ * linear least squares model
+ *
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LLS_H
+#define LLS_H
+
+#define MAX_VARS 32
+
+//FIXME avoid direct access to LLSModel from outside
+
+/**
+ * Linear least squares model.
+ */
+typedef struct LLSModel{
+ double covariance[MAX_VARS+1][MAX_VARS+1];
+ double coeff[MAX_VARS][MAX_VARS];
+ double variance[MAX_VARS];
+ int indep_count;
+}LLSModel;
+
+void av_init_lls(LLSModel *m, int indep_count);
+void av_update_lls(LLSModel *m, double *param, double decay);
+void av_solve_lls(LLSModel *m, double threshold, int min_order);
+double av_evaluate_lls(LLSModel *m, double *param, int order);
+
+#endif
diff --git a/src/libffmpeg/libavutil/log.c b/src/libffmpeg/libavutil/log.c
new file mode 100644
index 000000000..f43593ad9
--- /dev/null
+++ b/src/libffmpeg/libavutil/log.c
@@ -0,0 +1,80 @@
+/*
+ * log functions
+ * Copyright (c) 2003 Michel Bardiaux
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file log.c
+ * log.
+ */
+
+#include "avutil.h"
+
+int av_log_level = AV_LOG_INFO;
+
+static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
+{
+ static int print_prefix=1;
+ AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
+ if(level>av_log_level)
+ return;
+#undef fprintf
+ if(print_prefix && avc) {
+ fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
+ }
+#define fprintf please_use_av_log
+
+ print_prefix= strstr(fmt, "\n") != NULL;
+
+ vfprintf(stderr, fmt, vl);
+}
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
+#else
+void (*av_vlog)(void*, int, const char*, va_list) = av_log_default_callback;
+#endif
+
+void av_log(void* avcl, int level, const char *fmt, ...)
+{
+ va_list vl;
+ va_start(vl, fmt);
+ av_vlog(avcl, level, fmt, vl);
+ va_end(vl);
+}
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
+{
+ av_log_callback(avcl, level, fmt, vl);
+}
+
+int av_log_get_level(void)
+{
+ return av_log_level;
+}
+
+void av_log_set_level(int level)
+{
+ av_log_level = level;
+}
+
+void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
+{
+ av_log_callback = callback;
+}
+#endif
diff --git a/src/libffmpeg/libavutil/log.h b/src/libffmpeg/libavutil/log.h
new file mode 100644
index 000000000..13366064e
--- /dev/null
+++ b/src/libffmpeg/libavutil/log.h
@@ -0,0 +1,42 @@
+#ifndef LOG_H
+#define LOG_H
+
+#include <stdarg.h>
+
+/**
+ * Used by av_log
+ */
+typedef struct AVCLASS AVClass;
+struct AVCLASS {
+ const char* class_name;
+ const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
+ or AVFormatContext, which begin with an AVClass.
+ Needed because av_log is in libavcodec and has no visibility
+ of AVIn/OutputFormat */
+ struct AVOption *option;
+};
+
+/* av_log API */
+
+#define AV_LOG_QUIET -1
+#define AV_LOG_ERROR 0
+#define AV_LOG_INFO 1
+#define AV_LOG_DEBUG 2
+extern int av_log_level;
+
+#ifdef __GNUC__
+extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
+#else
+extern void av_log(void*, int level, const char *fmt, ...);
+#endif
+
+#if LIBAVUTIL_VERSION_INT < (50<<16)
+extern void av_vlog(void*, int level, const char *fmt, va_list);
+extern int av_log_get_level(void);
+extern void av_log_set_level(int);
+extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
+#else
+extern void (*av_vlog)(void*, int, const char*, va_list);
+#endif
+
+#endif /* LOG_H */
diff --git a/src/libffmpeg/libavutil/md5.c b/src/libffmpeg/libavutil/md5.c
new file mode 100644
index 000000000..32eca3a8e
--- /dev/null
+++ b/src/libffmpeg/libavutil/md5.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at)
+ * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org)
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * References:
+ * IETF RFC 1321: The MD5 Message-Digest Algorithm
+ * Ron Rivest. IETF, April, 1992
+ *
+ * based on http://ubiqx.org/libcifs/source/Auth/MD5.c
+ * from Christopher R. Hertel (crh@ubiqx.mn.org)
+ * simplified, cleaned and IMO redundant comments removed by michael
+ *
+ * if you use gcc, then version 4.1 or later and -fomit-frame-pointer is
+ * strongly recommended
+ */
+
+#include "common.h"
+#include <string.h>
+#include "md5.h"
+
+typedef struct AVMD5{
+ uint8_t block[64];
+ uint32_t ABCD[4];
+ uint64_t len;
+ int b_used;
+} AVMD5;
+
+const int av_md5_size= sizeof(AVMD5);
+
+static const uint8_t S[4][4] = {
+ { 7, 12, 17, 22 }, /* Round 1 */
+ { 5, 9, 14, 20 }, /* Round 2 */
+ { 4, 11, 16, 23 }, /* Round 3 */
+ { 6, 10, 15, 21 } /* Round 4 */
+};
+
+static const uint32_t T[64] = {
+ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* Round 1 */
+ 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
+ 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
+ 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
+
+ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* Round 2 */
+ 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
+ 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
+ 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
+
+ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* Round 3 */
+ 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
+ 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
+ 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
+
+ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* Round 4 */
+ 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
+ 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
+ 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
+};
+
+#define CORE(i, a, b, c, d) \
+ t = S[i>>4][i&3];\
+ a += T[i];\
+\
+ switch(i>>4){\
+ case 0: a += (d ^ (b&(c^d))) + X[ i &15 ]; break;\
+ case 1: a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ]; break;\
+ case 2: a += (b^c^d) + X[ (5+3*i)&15 ]; break;\
+ case 3: a += (c^(b|~d)) + X[ ( 7*i)&15 ]; break;\
+ }\
+ a = b + (( a << t ) | ( a >> (32 - t) ));
+
+static void body(uint32_t ABCD[4], uint32_t X[16]){
+
+ int t;
+ int i attribute_unused;
+ unsigned int a= ABCD[3];
+ unsigned int b= ABCD[2];
+ unsigned int c= ABCD[1];
+ unsigned int d= ABCD[0];
+
+#ifdef WORDS_BIGENDIAN
+ for(i=0; i<16; i++)
+ X[i]= bswap_32(X[i]);
+#endif
+
+#ifdef CONFIG_SMALL
+ for( i = 0; i < 64; i++ ){
+ CORE(i,a,b,c,d)
+ t=d; d=c; c=b; b=a; a=t;
+ }
+#else
+#define CORE2(i) CORE(i,a,b,c,d) CORE((i+1),d,a,b,c) CORE((i+2),c,d,a,b) CORE((i+3),b,c,d,a)
+#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12))
+CORE4(0) CORE4(16) CORE4(32) CORE4(48)
+#endif
+
+ ABCD[0] += d;
+ ABCD[1] += c;
+ ABCD[2] += b;
+ ABCD[3] += a;
+}
+
+void av_md5_init(AVMD5 *ctx){
+ ctx->len = 0;
+ ctx->b_used = 0;
+
+ ctx->ABCD[0] = 0x10325476;
+ ctx->ABCD[1] = 0x98badcfe;
+ ctx->ABCD[2] = 0xefcdab89;
+ ctx->ABCD[3] = 0x67452301;
+}
+
+void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){
+ int i;
+
+ ctx->len += len;
+
+ for( i = 0; i < len; i++ ){
+ ctx->block[ ctx->b_used++ ] = src[i];
+ if( 64 == ctx->b_used ){
+ body(ctx->ABCD, (uint32_t*) ctx->block);
+ ctx->b_used = 0;
+ }
+ }
+}
+
+void av_md5_final(AVMD5 *ctx, uint8_t *dst){
+ int i;
+
+ ctx->block[ctx->b_used++] = 0x80;
+
+ memset(&ctx->block[ctx->b_used], 0, 64 - ctx->b_used);
+
+ if( 56 < ctx->b_used ){
+ body( ctx->ABCD, (uint32_t*) ctx->block );
+ memset(ctx->block, 0, 64);
+ }
+
+ for(i=0; i<8; i++)
+ ctx->block[56+i] = (ctx->len << 3) >> (i<<3);
+
+ body(ctx->ABCD, (uint32_t*) ctx->block);
+
+ for(i=0; i<4; i++)
+ ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]);
+}
+
+void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){
+ AVMD5 ctx[1];
+
+ av_md5_init(ctx);
+ av_md5_update(ctx, src, len);
+ av_md5_final(ctx, dst);
+}
+
+#ifdef TEST
+#include <stdio.h>
+main(){
+ uint64_t md5val;
+ int i;
+ uint8_t in[1000];
+
+ for(i=0; i<1000; i++) in[i]= i*i;
+ av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%lld\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%lld\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%lld\n", md5val);
+ av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%lld\n", md5val);
+ for(i=0; i<1000; i++) in[i]= i % 127;
+ av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%lld\n", md5val);
+}
+#endif
diff --git a/src/libffmpeg/libavutil/md5.h b/src/libffmpeg/libavutil/md5.h
new file mode 100644
index 000000000..c8144b4cc
--- /dev/null
+++ b/src/libffmpeg/libavutil/md5.h
@@ -0,0 +1,14 @@
+#ifndef MD5_H
+#define MD5_H
+
+extern const int av_md5_size;
+
+struct AVMD5;
+
+void av_md5_init(struct AVMD5 *ctx);
+void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
+void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
+void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
+
+#endif /* MD5_H */
+