Update avcodec to 20080825
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27536 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
7052b75ea5
commit
ed4a799c2c
35
src/add-ons/media/plugins/avcodec/libavutil/Jamfile
Normal file
35
src/add-ons/media/plugins/avcodec/libavutil/Jamfile
Normal file
@ -0,0 +1,35 @@
|
||||
SubDir HAIKU_TOP src add-ons media plugins avcodec libavutil ;
|
||||
|
||||
# filter warnings we don't want here
|
||||
TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS)
|
||||
: -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith ] ;
|
||||
|
||||
SubDirCcFlags -fomit-frame-pointer -DPIC ;
|
||||
SubDirCcFlags -DHAVE_AV_CONFIG_H=1 ;
|
||||
|
||||
StaticLibrary libavutil.a :
|
||||
adler32.c
|
||||
aes.c
|
||||
base64.c
|
||||
crc.c
|
||||
des.c
|
||||
fifo.c
|
||||
integer.c
|
||||
intfloat_readwrite.c
|
||||
lfg.c
|
||||
lls.c
|
||||
log.c
|
||||
lzo.c
|
||||
mathematics.c
|
||||
md5.c
|
||||
mem.c
|
||||
pca.c
|
||||
random.c
|
||||
rational.c
|
||||
rc4.c
|
||||
sha1.c
|
||||
softfloat.c
|
||||
string.c
|
||||
tree.c
|
||||
utils.c
|
||||
;
|
71
src/add-ons/media/plugins/avcodec/libavutil/adler32.c
Normal file
71
src/add-ons/media/plugins/avcodec/libavutil/adler32.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* This is a modified version based on adler32.c from the zlib library.
|
||||
*
|
||||
* Copyright (C) 1995 Mark Adler
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#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(void){
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
30
src/add-ons/media/plugins/avcodec/libavutil/adler32.h
Normal file
30
src/add-ons/media/plugins/avcodec/libavutil/adler32.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* copyright (c) 2006 Mans Rullgard
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_ADLER32_H
|
||||
#define FFMPEG_ADLER32_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
|
||||
unsigned int len) av_pure;
|
||||
|
||||
#endif /* FFMPEG_ADLER32_H */
|
243
src/add-ons/media/plugins/avcodec/libavutil/aes.c
Normal file
243
src/add-ons/media/plugins/avcodec/libavutil/aes.c
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* some optimization ideas from aes128.c by Reimar Doeffinger
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "aes.h"
|
||||
|
||||
typedef struct AVAES{
|
||||
// Note: round_key[16] is accessed in the init code, but this only
|
||||
// overwrites state, which does not matter (see also r7471).
|
||||
uint8_t round_key[15][4][4];
|
||||
uint8_t state[2][4][4];
|
||||
int rounds;
|
||||
}AVAES;
|
||||
|
||||
const int av_aes_size= sizeof(AVAES);
|
||||
|
||||
static const uint8_t rcon[10] = {
|
||||
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
|
||||
};
|
||||
|
||||
static uint8_t sbox[256];
|
||||
static uint8_t inv_sbox[256];
|
||||
#ifdef CONFIG_SMALL
|
||||
static uint32_t enc_multbl[1][256];
|
||||
static uint32_t dec_multbl[1][256];
|
||||
#else
|
||||
static uint32_t enc_multbl[4][256];
|
||||
static uint32_t dec_multbl[4][256];
|
||||
#endif
|
||||
|
||||
static inline void addkey(uint64_t dst[2], uint64_t src[2], uint64_t round_key[2]){
|
||||
dst[0] = src[0] ^ round_key[0];
|
||||
dst[1] = src[1] ^ round_key[1];
|
||||
}
|
||||
|
||||
static void subshift(uint8_t s0[2][16], int s, uint8_t *box){
|
||||
uint8_t (*s1)[16]= s0[0] - s;
|
||||
uint8_t (*s3)[16]= s0[0] + s;
|
||||
s0[0][0]=box[s0[1][ 0]]; s0[0][ 4]=box[s0[1][ 4]]; s0[0][ 8]=box[s0[1][ 8]]; s0[0][12]=box[s0[1][12]];
|
||||
s1[0][3]=box[s1[1][ 7]]; s1[0][ 7]=box[s1[1][11]]; s1[0][11]=box[s1[1][15]]; s1[0][15]=box[s1[1][ 3]];
|
||||
s0[0][2]=box[s0[1][10]]; s0[0][10]=box[s0[1][ 2]]; s0[0][ 6]=box[s0[1][14]]; s0[0][14]=box[s0[1][ 6]];
|
||||
s3[0][1]=box[s3[1][13]]; s3[0][13]=box[s3[1][ 9]]; s3[0][ 9]=box[s3[1][ 5]]; s3[0][ 5]=box[s3[1][ 1]];
|
||||
}
|
||||
|
||||
static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){
|
||||
#ifdef CONFIG_SMALL
|
||||
#define ROT(x,s) ((x<<s)|(x>>(32-s)))
|
||||
return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
|
||||
#else
|
||||
return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d];
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void mix(uint8_t state[2][4][4], uint32_t multbl[4][256], int s1, int s3){
|
||||
((uint32_t *)(state))[0] = mix_core(multbl, state[1][0][0], state[1][s1 ][1], state[1][2][2], state[1][s3 ][3]);
|
||||
((uint32_t *)(state))[1] = mix_core(multbl, state[1][1][0], state[1][s3-1][1], state[1][3][2], state[1][s1-1][3]);
|
||||
((uint32_t *)(state))[2] = mix_core(multbl, state[1][2][0], state[1][s3 ][1], state[1][0][2], state[1][s1 ][3]);
|
||||
((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]);
|
||||
}
|
||||
|
||||
static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
|
||||
int r;
|
||||
|
||||
for(r=a->rounds-1; r>0; r--){
|
||||
mix(a->state, multbl, 3-s, 1+s);
|
||||
addkey(a->state[1], a->state[0], a->round_key[r]);
|
||||
}
|
||||
subshift(a->state[0][0], s, sbox);
|
||||
}
|
||||
|
||||
void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){
|
||||
while(count--){
|
||||
addkey(a->state[1], src, a->round_key[a->rounds]);
|
||||
if(decrypt) {
|
||||
crypt(a, 0, inv_sbox, dec_multbl);
|
||||
if(iv){
|
||||
addkey(a->state[0], a->state[0], iv);
|
||||
memcpy(iv, src, 16);
|
||||
}
|
||||
addkey(dst, a->state[0], a->round_key[0]);
|
||||
}else{
|
||||
if(iv) addkey(a->state[1], a->state[1], iv);
|
||||
crypt(a, 2, sbox, enc_multbl);
|
||||
addkey(dst, a->state[0], a->round_key[0]);
|
||||
if(iv) memcpy(iv, dst, 16);
|
||||
}
|
||||
src+=16;
|
||||
dst+=16;
|
||||
}
|
||||
}
|
||||
|
||||
static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *alog8, uint8_t *sbox){
|
||||
int i, j;
|
||||
for(i=0; i<1024; i++){
|
||||
int x= sbox[i>>2];
|
||||
if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ];
|
||||
}
|
||||
#ifndef CONFIG_SMALL
|
||||
for(j=256; j<1024; j++)
|
||||
for(i=0; i<4; i++)
|
||||
tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024];
|
||||
#endif
|
||||
}
|
||||
|
||||
// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
|
||||
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
|
||||
int i, j, t, rconpointer = 0;
|
||||
uint8_t tk[8][4];
|
||||
int KC= key_bits>>5;
|
||||
int rounds= KC + 6;
|
||||
uint8_t log8[256];
|
||||
uint8_t alog8[512];
|
||||
|
||||
if(!enc_multbl[0][sizeof(enc_multbl)/sizeof(enc_multbl[0][0])-1]){
|
||||
j=1;
|
||||
for(i=0; i<255; i++){
|
||||
alog8[i]=
|
||||
alog8[i+255]= j;
|
||||
log8[j]= i;
|
||||
j^= j+j;
|
||||
if(j>255) j^= 0x11B;
|
||||
}
|
||||
for(i=0; i<256; i++){
|
||||
j= i ? alog8[255-log8[i]] : 0;
|
||||
j ^= (j<<1) ^ (j<<2) ^ (j<<3) ^ (j<<4);
|
||||
j = (j ^ (j>>8) ^ 99) & 255;
|
||||
inv_sbox[j]= i;
|
||||
sbox [i]= j;
|
||||
}
|
||||
init_multbl2(dec_multbl[0], (int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox);
|
||||
init_multbl2(enc_multbl[0], (int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox);
|
||||
}
|
||||
|
||||
if(key_bits!=128 && key_bits!=192 && key_bits!=256)
|
||||
return -1;
|
||||
|
||||
a->rounds= rounds;
|
||||
|
||||
memcpy(tk, key, KC*4);
|
||||
|
||||
for(t= 0; t < (rounds+1)*16;) {
|
||||
memcpy(a->round_key[0][0]+t, tk, KC*4);
|
||||
t+= KC*4;
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]];
|
||||
tk[0][0] ^= rcon[rconpointer++];
|
||||
|
||||
for(j = 1; j < KC; j++){
|
||||
if(KC != 8 || j != KC>>1)
|
||||
for(i = 0; i < 4; i++) tk[j][i] ^= tk[j-1][i];
|
||||
else
|
||||
for(i = 0; i < 4; i++) tk[j][i] ^= sbox[tk[j-1][i]];
|
||||
}
|
||||
}
|
||||
|
||||
if(decrypt){
|
||||
for(i=1; i<rounds; i++){
|
||||
uint8_t tmp[3][16];
|
||||
memcpy(tmp[2], a->round_key[i][0], 16);
|
||||
subshift(tmp[1], 0, sbox);
|
||||
mix(tmp, dec_multbl, 1, 3);
|
||||
memcpy(a->round_key[i][0], tmp[0], 16);
|
||||
}
|
||||
}else{
|
||||
for(i=0; i<(rounds+1)>>1; i++){
|
||||
for(j=0; j<16; j++)
|
||||
FFSWAP(int, a->round_key[i][0][j], a->round_key[rounds-i][0][j]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "log.h"
|
||||
|
||||
#undef random
|
||||
|
||||
int main(void){
|
||||
int i,j;
|
||||
AVAES ae, ad, b;
|
||||
uint8_t rkey[2][16]= {
|
||||
{0},
|
||||
{0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59}};
|
||||
uint8_t pt[16], rpt[2][16]= {
|
||||
{0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3},
|
||||
{0}};
|
||||
uint8_t rct[2][16]= {
|
||||
{0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf},
|
||||
{0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}};
|
||||
uint8_t temp[16];
|
||||
|
||||
av_aes_init(&ae, "PI=3.141592654..", 128, 0);
|
||||
av_aes_init(&ad, "PI=3.141592654..", 128, 1);
|
||||
av_log_level= AV_LOG_DEBUG;
|
||||
|
||||
for(i=0; i<2; i++){
|
||||
av_aes_init(&b, rkey[i], 128, 1);
|
||||
av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
|
||||
for(j=0; j<16; j++)
|
||||
if(rpt[i][j] != temp[j])
|
||||
av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]);
|
||||
}
|
||||
|
||||
for(i=0; i<10000; i++){
|
||||
for(j=0; j<16; j++){
|
||||
pt[j]= random();
|
||||
}
|
||||
{START_TIMER
|
||||
av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
|
||||
if(!(i&(i-1)))
|
||||
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]);
|
||||
av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
|
||||
STOP_TIMER("aes")}
|
||||
for(j=0; j<16; j++){
|
||||
if(pt[j] != temp[j]){
|
||||
av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
47
src/add-ons/media/plugins/avcodec/libavutil/aes.h
Normal file
47
src/add-ons/media/plugins/avcodec/libavutil/aes.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AES_H
|
||||
#define FFMPEG_AES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern const int av_aes_size;
|
||||
|
||||
struct AVAES;
|
||||
|
||||
/**
|
||||
* Initializes an AVAES context.
|
||||
* @param key_bits 128, 192 or 256
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
|
||||
|
||||
/**
|
||||
* Encrypts / decrypts.
|
||||
* @param count number of 16 byte blocks
|
||||
* @param dst destination array, can be equal to src
|
||||
* @param src source array, can be equal to dst
|
||||
* @param iv initialization vector for CBC mode, if NULL then ECB will be used
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
|
||||
#endif /* FFMPEG_AES_H */
|
90
src/add-ons/media/plugins/avcodec/libavutil/avstring.h
Normal file
90
src/add-ons/media/plugins/avcodec/libavutil/avstring.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Mans Rullgard
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AVSTRING_H
|
||||
#define FFMPEG_AVSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
|
||||
* the address of the first character in str after the prefix.
|
||||
*
|
||||
* @param str input string
|
||||
* @param pfx prefix to test
|
||||
* @param ptr updated after the prefix in str in there is a match
|
||||
* @return non-zero if the prefix matches, zero otherwise
|
||||
*/
|
||||
int av_strstart(const char *str, const char *pfx, const char **ptr);
|
||||
|
||||
/**
|
||||
* Return non-zero if pfx is a prefix of str independent of case. If
|
||||
* it is, *ptr is set to the address of the first character in str
|
||||
* after the prefix.
|
||||
*
|
||||
* @param str input string
|
||||
* @param pfx prefix to test
|
||||
* @param ptr updated after the prefix in str in there is a match
|
||||
* @return non-zero if the prefix matches, zero otherwise
|
||||
*/
|
||||
int av_stristart(const char *str, const char *pfx, const char **ptr);
|
||||
|
||||
/**
|
||||
* Copy the string src to dst, but no more than size - 1 bytes, and
|
||||
* null terminate dst.
|
||||
*
|
||||
* This function is the same as BSD strlcpy().
|
||||
*
|
||||
* @param dst destination buffer
|
||||
* @param src source string
|
||||
* @param size size of destination buffer
|
||||
* @return the length of src
|
||||
*/
|
||||
size_t av_strlcpy(char *dst, const char *src, size_t size);
|
||||
|
||||
/**
|
||||
* Append the string src to the string dst, but to a total length of
|
||||
* no more than size - 1 bytes, and null terminate dst.
|
||||
*
|
||||
* This function is similar to BSD strlcat(), but differs when
|
||||
* size <= strlen(dst).
|
||||
*
|
||||
* @param dst destination buffer
|
||||
* @param src source string
|
||||
* @param size size of destination buffer
|
||||
* @return the total length of src and dst
|
||||
*/
|
||||
size_t av_strlcat(char *dst, const char *src, size_t size);
|
||||
|
||||
/**
|
||||
* Append output to a string, according to a format. Never write out of
|
||||
* the destination buffer, and and always put a terminating 0 within
|
||||
* the buffer.
|
||||
* @param dst destination buffer (string to which the output is
|
||||
* appended)
|
||||
* @param size total size of the destination buffer
|
||||
* @param fmt printf-compatible format string, specifying how the
|
||||
* following parameters are used
|
||||
* @return the length of the string that would have been generated
|
||||
* if enough space had been available
|
||||
*/
|
||||
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
|
||||
|
||||
#endif /* FFMPEG_AVSTRING_H */
|
147
src/add-ons/media/plugins/avcodec/libavutil/avutil.h
Normal file
147
src/add-ons/media/plugins/avcodec/libavutil/avutil.h
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AVUTIL_H
|
||||
#define FFMPEG_AVUTIL_H
|
||||
|
||||
/**
|
||||
* @file avutil.h
|
||||
* external API header
|
||||
*/
|
||||
|
||||
|
||||
#define AV_STRINGIFY(s) AV_TOSTRING(s)
|
||||
#define AV_TOSTRING(s) #s
|
||||
|
||||
#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
|
||||
#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
|
||||
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
|
||||
|
||||
#define LIBAVUTIL_VERSION_MAJOR 49
|
||||
#define LIBAVUTIL_VERSION_MINOR 10
|
||||
#define LIBAVUTIL_VERSION_MICRO 0
|
||||
|
||||
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
|
||||
LIBAVUTIL_VERSION_MINOR, \
|
||||
LIBAVUTIL_VERSION_MICRO)
|
||||
#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
|
||||
LIBAVUTIL_VERSION_MINOR, \
|
||||
LIBAVUTIL_VERSION_MICRO)
|
||||
#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
|
||||
|
||||
#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
|
||||
|
||||
/**
|
||||
* Returns the LIBAVUTIL_VERSION_INT constant.
|
||||
*/
|
||||
unsigned avutil_version(void);
|
||||
|
||||
#include "common.h"
|
||||
#include "mathematics.h"
|
||||
#include "rational.h"
|
||||
#include "intfloat_readwrite.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* Pixel format. Notes:
|
||||
*
|
||||
* PIX_FMT_RGB32 is handled in an endian-specific manner. A RGBA
|
||||
* color is put together as:
|
||||
* (A << 24) | (R << 16) | (G << 8) | B
|
||||
* This is stored as BGRA on little endian CPU architectures and ARGB on
|
||||
* big endian CPUs.
|
||||
*
|
||||
* When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
|
||||
* image data is stored in AVFrame.data[0]. The palette is transported in
|
||||
* AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
|
||||
* formatted the same as in PIX_FMT_RGB32 described above (i.e., it is
|
||||
* also endian-specific). Note also that the individual RGB palette
|
||||
* components stored in AVFrame.data[1] should be in the range 0..255.
|
||||
* This is important as many custom PAL8 video codecs that were designed
|
||||
* to run on the IBM VGA graphics adapter use 6-bit palette components.
|
||||
*/
|
||||
enum PixelFormat {
|
||||
PIX_FMT_NONE= -1,
|
||||
PIX_FMT_YUV420P, ///< Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
|
||||
PIX_FMT_YUYV422, ///< Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
|
||||
PIX_FMT_RGB24, ///< Packed RGB 8:8:8, 24bpp, RGBRGB...
|
||||
PIX_FMT_BGR24, ///< Packed RGB 8:8:8, 24bpp, BGRBGR...
|
||||
PIX_FMT_YUV422P, ///< Planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
|
||||
PIX_FMT_YUV444P, ///< Planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
|
||||
PIX_FMT_RGB32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness
|
||||
PIX_FMT_YUV410P, ///< Planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
|
||||
PIX_FMT_YUV411P, ///< Planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
|
||||
PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness
|
||||
PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0
|
||||
PIX_FMT_GRAY8, ///< Y , 8bpp
|
||||
PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black
|
||||
PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white
|
||||
PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
|
||||
PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg)
|
||||
PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg)
|
||||
PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg)
|
||||
PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
|
||||
PIX_FMT_XVMC_MPEG2_IDCT,
|
||||
PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
|
||||
PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
|
||||
PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness
|
||||
PIX_FMT_BGR565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in cpu endianness
|
||||
PIX_FMT_BGR555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in cpu endianness most significant bit to 1
|
||||
PIX_FMT_BGR8, ///< Packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
|
||||
PIX_FMT_BGR4, ///< Packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_BGR4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_RGB8, ///< Packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_RGB4, ///< Packed RGB 1:2:1, 4bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_RGB4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_NV12, ///< Planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 for UV
|
||||
PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
|
||||
|
||||
PIX_FMT_RGB32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in cpu endianness
|
||||
PIX_FMT_BGR32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in cpu endianness
|
||||
|
||||
PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian
|
||||
PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian
|
||||
PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
|
||||
PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg)
|
||||
PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
|
||||
PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
|
||||
};
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PIX_FMT_RGBA PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_BGRA PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ARGB PIX_FMT_RGB32
|
||||
#define PIX_FMT_ABGR PIX_FMT_BGR32
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE
|
||||
#else
|
||||
#define PIX_FMT_RGBA PIX_FMT_BGR32
|
||||
#define PIX_FMT_BGRA PIX_FMT_RGB32
|
||||
#define PIX_FMT_ARGB PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ABGR PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE
|
||||
#endif
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT < (50<<16)
|
||||
#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411
|
||||
#define PIX_FMT_RGBA32 PIX_FMT_RGB32
|
||||
#define PIX_FMT_YUV422 PIX_FMT_YUYV422
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_AVUTIL_H */
|
228
src/add-ons/media/plugins/avcodec/libavutil/base64.c
Normal file
228
src/add-ons/media/plugins/avcodec/libavutil/base64.c
Normal file
@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Base64.c
|
||||
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file base64.c
|
||||
* @brief Base64 Encode/Decode
|
||||
* @author Ryan Martell <rdm4@martellventures.com> (with lots of Michael)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "base64.h"
|
||||
|
||||
/* ---------------- private code */
|
||||
static const uint8_t map2[] =
|
||||
{
|
||||
0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36,
|
||||
0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01,
|
||||
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
|
||||
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b,
|
||||
0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
|
||||
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
|
||||
0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
|
||||
};
|
||||
|
||||
int av_base64_decode(uint8_t * out, const char *in, int out_length)
|
||||
{
|
||||
int i, v;
|
||||
uint8_t *dst = out;
|
||||
|
||||
v = 0;
|
||||
for (i = 0; in[i] && in[i] != '='; i++) {
|
||||
unsigned int index= in[i]-43;
|
||||
if (index>=(sizeof(map2)/sizeof(map2[0])) || map2[index] == 0xff)
|
||||
return -1;
|
||||
v = (v << 6) + map2[index];
|
||||
if (i & 3) {
|
||||
if (dst - out < out_length) {
|
||||
*dst++ = v >> (6 - 2 * (i & 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dst - out;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* b64_encode: stolen from VLC's http.c
|
||||
* simplified by michael
|
||||
* fixed edge cases and made it work from data (vs. strings) by ryan.
|
||||
*****************************************************************************/
|
||||
|
||||
char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len)
|
||||
{
|
||||
static const char b64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
char *ret, *dst;
|
||||
unsigned i_bits = 0;
|
||||
int i_shift = 0;
|
||||
int bytes_remaining = len;
|
||||
|
||||
if (len >= UINT_MAX / 4 ||
|
||||
buf_len < len * 4 / 3 + 12)
|
||||
return NULL;
|
||||
ret = dst = buf;
|
||||
while (bytes_remaining) {
|
||||
i_bits = (i_bits << 8) + *src++;
|
||||
bytes_remaining--;
|
||||
i_shift += 8;
|
||||
|
||||
do {
|
||||
*dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
|
||||
i_shift -= 6;
|
||||
} while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0));
|
||||
}
|
||||
while ((dst - ret) & 3)
|
||||
*dst++ = '=';
|
||||
*dst = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// #define TEST_BASE64
|
||||
|
||||
#ifdef TEST_BASE64
|
||||
#include "avutil.h"
|
||||
|
||||
int b64test()
|
||||
{
|
||||
int numerr = 0;
|
||||
int len;
|
||||
int numtest = 1;
|
||||
uint8_t decode[1000];
|
||||
struct test {
|
||||
void *data;
|
||||
int len;
|
||||
const char *result;
|
||||
} *t, tests[] = {
|
||||
{
|
||||
"", 0, ""}, {
|
||||
"1", 1, "MQ=="}, {
|
||||
"22", 2, "MjI="}, {
|
||||
"333", 3, "MzMz"}, {
|
||||
"4444", 4, "NDQ0NA=="}, {
|
||||
"55555", 5, "NTU1NTU="}, {
|
||||
"abc:def", 7, "YWJjOmRlZg=="}, {
|
||||
NULL}
|
||||
};
|
||||
for (t = tests; t->data; t++) {
|
||||
char *str;
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data);
|
||||
str = av_base64_encode(t->data, t->len);
|
||||
if (str) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str);
|
||||
if (strcmp(str, t->result) != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n",
|
||||
numtest, str, t->result);
|
||||
numerr++;
|
||||
}
|
||||
av_free(str);
|
||||
}
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Done encoding, about to decode...\n");
|
||||
len = av_base64_decode(decode, t->result, sizeof(decode));
|
||||
if (len != t->len) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: len %d != %d\n",
|
||||
numtest, len, t->len);
|
||||
numerr++;
|
||||
} else if (memcmp(decode, t->data, t->len) != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: data\n", numtest);
|
||||
numerr++;
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR, "Decoded to %s\n",
|
||||
(char *) t->data);
|
||||
}
|
||||
numtest++;
|
||||
}
|
||||
|
||||
#undef srand
|
||||
#undef rand
|
||||
|
||||
{
|
||||
int test_count;
|
||||
srand(123141); // time(NULL));
|
||||
for (test_count = 0; test_count < 100; test_count++) {
|
||||
int size = rand() % 1024;
|
||||
int ii;
|
||||
uint8_t *data;
|
||||
char *encoded_result;
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...",
|
||||
test_count, size);
|
||||
data = (uint8_t *) av_malloc(size);
|
||||
for (ii = 0; ii < size; ii++) {
|
||||
data[ii] = rand() % 255;
|
||||
}
|
||||
|
||||
encoded_result = av_base64_encode(data, size);
|
||||
if (encoded_result) {
|
||||
int decode_buffer_size = size + 10; // try without 10 as well
|
||||
uint8_t *decode_buffer = av_malloc(decode_buffer_size);
|
||||
if (decode_buffer) {
|
||||
int decoded_size =
|
||||
av_base64_decode(decode_buffer, encoded_result,
|
||||
decode_buffer_size);
|
||||
|
||||
if (decoded_size != size) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Decoded/Encoded size mismatch (%d != %d)\n",
|
||||
decoded_size, size);
|
||||
} else {
|
||||
if (memcmp(decode_buffer, data, decoded_size) == 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Passed!\n");
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Failed (Data differs)!\n");
|
||||
}
|
||||
}
|
||||
av_free(decode_buffer);
|
||||
}
|
||||
|
||||
av_free(encoded_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// these are invalid strings, that it currently decodes (which it probably shouldn't?)
|
||||
{
|
||||
uint8_t str[32];
|
||||
if (av_base64_decode(str, "M=M=", sizeof(str)) != -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"failed test %d: successful decode of `M=M='\n",
|
||||
numtest++);
|
||||
numerr++;
|
||||
}
|
||||
if (av_base64_decode(str, "MQ===", sizeof(str)) != -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"failed test %d: successful decode of `MQ==='\n",
|
||||
numtest++);
|
||||
numerr++;
|
||||
}
|
||||
}
|
||||
|
||||
return numerr;
|
||||
}
|
||||
#endif
|
||||
|
40
src/add-ons/media/plugins/avcodec/libavutil/base64.h
Normal file
40
src/add-ons/media/plugins/avcodec/libavutil/base64.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Base64.c
|
||||
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_BASE64_H
|
||||
#define FFMPEG_BASE64_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* decodes base64
|
||||
* param order as strncpy()
|
||||
*/
|
||||
int av_base64_decode(uint8_t * out, const char *in, int out_length);
|
||||
|
||||
/**
|
||||
* encodes base64
|
||||
* @param src data, not a string
|
||||
* @param buf output string
|
||||
*/
|
||||
char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len);
|
||||
|
||||
#endif /* FFMPEG_BASE64_H */
|
132
src/add-ons/media/plugins/avcodec/libavutil/bswap.h
Normal file
132
src/add-ons/media/plugins/avcodec/libavutil/bswap.h
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file bswap.h
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_BSWAP_H
|
||||
#define FFMPEG_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#ifdef HAVE_BYTESWAP_H
|
||||
#include <byteswap.h>
|
||||
#else
|
||||
|
||||
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
#if defined(ARCH_X86)
|
||||
asm("rorw $8, %0" : "+r"(x));
|
||||
#elif defined(ARCH_SH4)
|
||||
asm("swap.b %0,%0" : "=r"(x) : "0"(x));
|
||||
#elif defined(HAVE_ARMV6)
|
||||
asm("rev16 %0, %0" : "+r"(x));
|
||||
#else
|
||||
x= (x>>8) | (x<<8);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
#if defined(ARCH_X86)
|
||||
#ifdef HAVE_BSWAP
|
||||
asm("bswap %0" : "+r" (x));
|
||||
#else
|
||||
asm("rorw $8, %w0 \n\t"
|
||||
"rorl $16, %0 \n\t"
|
||||
"rorw $8, %w0"
|
||||
: "+r"(x));
|
||||
#endif
|
||||
#elif defined(ARCH_SH4)
|
||||
asm("swap.b %0,%0\n"
|
||||
"swap.w %0,%0\n"
|
||||
"swap.b %0,%0\n"
|
||||
: "=r"(x) : "0"(x));
|
||||
#elif defined(HAVE_ARMV6)
|
||||
asm("rev %0, %0" : "+r"(x));
|
||||
#elif defined(ARCH_ARMV4L)
|
||||
uint32_t t;
|
||||
asm ("eor %1, %0, %0, ror #16 \n\t"
|
||||
"bic %1, %1, #0xFF0000 \n\t"
|
||||
"mov %0, %0, ror #8 \n\t"
|
||||
"eor %0, %0, %1, lsr #8 \n\t"
|
||||
: "+r"(x), "+r"(t));
|
||||
#elif defined(ARCH_BFIN)
|
||||
unsigned tmp;
|
||||
asm("%1 = %0 >> 8 (V); \n\t"
|
||||
"%0 = %0 << 8 (V); \n\t"
|
||||
"%0 = %0 | %1; \n\t"
|
||||
"%0 = PACK(%0.L, %0.H); \n\t"
|
||||
: "+d"(x), "=&d"(tmp));
|
||||
#else
|
||||
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
||||
x= (x>>16) | (x<<16);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline uint64_t av_const bswap_64(uint64_t x)
|
||||
{
|
||||
#if 0
|
||||
x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
|
||||
x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
|
||||
return (x>>32) | (x<<32);
|
||||
#elif defined(ARCH_X86_64)
|
||||
asm("bswap %0": "=r" (x) : "0" (x));
|
||||
return x;
|
||||
#else
|
||||
union {
|
||||
uint64_t ll;
|
||||
uint32_t l[2];
|
||||
} w, r;
|
||||
w.ll = x;
|
||||
r.l[0] = bswap_32 (w.l[1]);
|
||||
r.l[1] = bswap_32 (w.l[0]);
|
||||
return r.ll;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !HAVE_BYTESWAP_H */
|
||||
|
||||
// be2me ... BigEndian to MachineEndian
|
||||
// le2me ... LittleEndian to MachineEndian
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define be2me_16(x) (x)
|
||||
#define be2me_32(x) (x)
|
||||
#define be2me_64(x) (x)
|
||||
#define le2me_16(x) bswap_16(x)
|
||||
#define le2me_32(x) bswap_32(x)
|
||||
#define le2me_64(x) bswap_64(x)
|
||||
#else
|
||||
#define be2me_16(x) bswap_16(x)
|
||||
#define be2me_32(x) bswap_32(x)
|
||||
#define be2me_64(x) bswap_64(x)
|
||||
#define le2me_16(x) (x)
|
||||
#define le2me_32(x) (x)
|
||||
#define le2me_64(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_BSWAP_H */
|
415
src/add-ons/media/plugins/avcodec/libavutil/common.h
Normal file
415
src/add-ons/media/plugins/avcodec/libavutil/common.h
Normal file
@ -0,0 +1,415 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file common.h
|
||||
* common internal and external API header
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_COMMON_H
|
||||
#define FFMPEG_COMMON_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
/* only include the following when compiling package */
|
||||
# include "config.h"
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <ctype.h>
|
||||
# include <limits.h>
|
||||
# include <errno.h>
|
||||
# include <math.h>
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
#ifndef av_always_inline
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
# define av_always_inline __attribute__((always_inline)) inline
|
||||
#else
|
||||
# define av_always_inline inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_noinline
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
# define av_noinline __attribute__((noinline))
|
||||
#else
|
||||
# define av_noinline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_pure
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
# define av_pure __attribute__((pure))
|
||||
#else
|
||||
# define av_pure
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_const
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
|
||||
# define av_const __attribute__((const))
|
||||
#else
|
||||
# define av_const
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_cold
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
|
||||
# define av_cold __attribute__((cold))
|
||||
#else
|
||||
# define av_cold
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "internal.h"
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
#ifndef attribute_deprecated
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
# define attribute_deprecated __attribute__((deprecated))
|
||||
#else
|
||||
# define attribute_deprecated
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_unused
|
||||
#if defined(__GNUC__)
|
||||
# define av_unused __attribute__((unused))
|
||||
#else
|
||||
# define av_unused
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
//rounded divison & shift
|
||||
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
|
||||
/* assume b>0 */
|
||||
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
|
||||
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
|
||||
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
|
||||
|
||||
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
|
||||
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
|
||||
|
||||
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
|
||||
|
||||
/* misc math functions */
|
||||
extern const uint8_t ff_log2_tab[256];
|
||||
|
||||
static inline av_const int av_log2(unsigned int v)
|
||||
{
|
||||
int n = 0;
|
||||
if (v & 0xffff0000) {
|
||||
v >>= 16;
|
||||
n += 16;
|
||||
}
|
||||
if (v & 0xff00) {
|
||||
v >>= 8;
|
||||
n += 8;
|
||||
}
|
||||
n += ff_log2_tab[v];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline av_const int av_log2_16bit(unsigned int v)
|
||||
{
|
||||
int n = 0;
|
||||
if (v & 0xff00) {
|
||||
v >>= 8;
|
||||
n += 8;
|
||||
}
|
||||
n += ff_log2_tab[v];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/* median of 3 */
|
||||
static inline av_const int mid_pred(int a, int b, int c)
|
||||
{
|
||||
#ifdef HAVE_CMOV
|
||||
int i=b;
|
||||
asm volatile(
|
||||
"cmp %2, %1 \n\t"
|
||||
"cmovg %1, %0 \n\t"
|
||||
"cmovg %2, %1 \n\t"
|
||||
"cmp %3, %1 \n\t"
|
||||
"cmovl %3, %1 \n\t"
|
||||
"cmp %1, %0 \n\t"
|
||||
"cmovg %1, %0 \n\t"
|
||||
:"+&r"(i), "+&r"(a)
|
||||
:"r"(b), "r"(c)
|
||||
);
|
||||
return i;
|
||||
#elif 0
|
||||
int t= (a-b)&((a-b)>>31);
|
||||
a-=t;
|
||||
b+=t;
|
||||
b-= (b-c)&((b-c)>>31);
|
||||
b+= (a-b)&((a-b)>>31);
|
||||
|
||||
return b;
|
||||
#else
|
||||
if(a>b){
|
||||
if(c>b){
|
||||
if(c>a) b=a;
|
||||
else b=c;
|
||||
}
|
||||
}else{
|
||||
if(b>c){
|
||||
if(c>a) b=c;
|
||||
else b=a;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the amin-amax range
|
||||
* @param a value to clip
|
||||
* @param amin minimum value of the clip range
|
||||
* @param amax maximum value of the clip range
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const int av_clip(int a, int amin, int amax)
|
||||
{
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the 0-255 range
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const uint8_t av_clip_uint8(int a)
|
||||
{
|
||||
if (a&(~255)) return (-a)>>31;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the -32768,32767 range
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const int16_t av_clip_int16(int a)
|
||||
{
|
||||
if ((a+32768) & ~65535) return (a>>31) ^ 32767;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* clip a float value into the amin-amax range
|
||||
* @param a value to clip
|
||||
* @param amin minimum value of the clip range
|
||||
* @param amax maximum value of the clip range
|
||||
* @return clipped value
|
||||
*/
|
||||
static inline av_const float av_clipf(float a, float amin, float amax)
|
||||
{
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/* math */
|
||||
int64_t av_const ff_gcd(int64_t a, int64_t b);
|
||||
|
||||
/**
|
||||
* converts fourcc string to int
|
||||
*/
|
||||
static inline av_pure int ff_get_fourcc(const char *s){
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
assert( strlen(s)==4 );
|
||||
#endif
|
||||
|
||||
return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
|
||||
}
|
||||
|
||||
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
|
||||
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
|
||||
|
||||
/*!
|
||||
* \def GET_UTF8(val, GET_BYTE, ERROR)
|
||||
* converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
|
||||
* \param val is the output and should be of type uint32_t. It holds the converted
|
||||
* UCS-4 character and should be a left value.
|
||||
* \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
|
||||
* a function or a statement whose return value or evaluated value is of type
|
||||
* uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
|
||||
* and up to 7 times in the general case.
|
||||
* \param ERROR action that should be taken when an invalid UTF-8 byte is returned
|
||||
* from GET_BYTE. It should be a statement that jumps out of the macro,
|
||||
* like exit(), goto, return, break, or continue.
|
||||
*/
|
||||
#define GET_UTF8(val, GET_BYTE, ERROR)\
|
||||
val= GET_BYTE;\
|
||||
{\
|
||||
int ones= 7 - av_log2(val ^ 255);\
|
||||
if(ones==1)\
|
||||
ERROR\
|
||||
val&= 127>>ones;\
|
||||
while(--ones > 0){\
|
||||
int tmp= GET_BYTE - 128;\
|
||||
if(tmp>>6)\
|
||||
ERROR\
|
||||
val= (val<<6) + tmp;\
|
||||
}\
|
||||
}
|
||||
|
||||
/*!
|
||||
* \def PUT_UTF8(val, tmp, PUT_BYTE)
|
||||
* converts a 32-bit unicode character to its UTF-8 encoded form (up to 4 bytes long).
|
||||
* \param val is an input only argument and should be of type uint32_t. It holds
|
||||
* a ucs4 encoded unicode character that is to be converted to UTF-8. If
|
||||
* val is given as a function it's executed only once.
|
||||
* \param tmp is a temporary variable and should be of type uint8_t. It
|
||||
* represents an intermediate value during conversion that is to be
|
||||
* outputted by PUT_BYTE.
|
||||
* \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
|
||||
* It could be a function or a statement, and uses tmp as the input byte.
|
||||
* For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
|
||||
* executed up to 4 times for values in the valid UTF-8 range and up to
|
||||
* 7 times in the general case, depending on the length of the converted
|
||||
* unicode character.
|
||||
*/
|
||||
#define PUT_UTF8(val, tmp, PUT_BYTE)\
|
||||
{\
|
||||
int bytes, shift;\
|
||||
uint32_t in = val;\
|
||||
if (in < 0x80) {\
|
||||
tmp = in;\
|
||||
PUT_BYTE\
|
||||
} else {\
|
||||
bytes = (av_log2(in) + 4) / 5;\
|
||||
shift = (bytes - 1) * 6;\
|
||||
tmp = (256 - (256 >> bytes)) | (in >> shift);\
|
||||
PUT_BYTE\
|
||||
while (shift >= 6) {\
|
||||
shift -= 6;\
|
||||
tmp = 0x80 | ((in >> shift) & 0x3f);\
|
||||
PUT_BYTE\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN)
|
||||
#define AV_READ_TIME read_time
|
||||
#if defined(ARCH_X86_64)
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint64_t a, d;
|
||||
asm volatile("rdtsc\n\t"
|
||||
: "=a" (a), "=d" (d));
|
||||
return (d << 32) | (a & 0xffffffff);
|
||||
}
|
||||
#elif defined(ARCH_X86_32)
|
||||
static inline long long read_time(void)
|
||||
{
|
||||
long long l;
|
||||
asm volatile("rdtsc\n\t"
|
||||
: "=A" (l));
|
||||
return l;
|
||||
}
|
||||
#elif ARCH_BFIN
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned lo;
|
||||
unsigned hi;
|
||||
} p;
|
||||
unsigned long long c;
|
||||
} t;
|
||||
asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
|
||||
return t.c;
|
||||
}
|
||||
#else //FIXME check ppc64
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint32_t tbu, tbl, temp;
|
||||
|
||||
/* from section 2.2.1 of the 32-bit PowerPC PEM */
|
||||
asm volatile(
|
||||
"1:\n"
|
||||
"mftbu %2\n"
|
||||
"mftb %0\n"
|
||||
"mftbu %1\n"
|
||||
"cmpw %2,%1\n"
|
||||
"bne 1b\n"
|
||||
: "=r"(tbl), "=r"(tbu), "=r"(temp)
|
||||
:
|
||||
: "cc");
|
||||
|
||||
return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
|
||||
}
|
||||
#endif
|
||||
#elif defined(HAVE_GETHRTIME)
|
||||
#define AV_READ_TIME gethrtime
|
||||
#endif
|
||||
|
||||
#ifdef AV_READ_TIME
|
||||
#define START_TIMER \
|
||||
uint64_t tend;\
|
||||
uint64_t tstart= AV_READ_TIME();\
|
||||
|
||||
#define STOP_TIMER(id) \
|
||||
tend= AV_READ_TIME();\
|
||||
{\
|
||||
static uint64_t tsum=0;\
|
||||
static int tcount=0;\
|
||||
static int tskip_count=0;\
|
||||
if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
|
||||
tsum+= tend - tstart;\
|
||||
tcount++;\
|
||||
}else\
|
||||
tskip_count++;\
|
||||
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
|
||||
av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
|
||||
tsum*10/tcount, id, tcount, tskip_count);\
|
||||
}\
|
||||
}
|
||||
#else
|
||||
#define START_TIMER
|
||||
#define STOP_TIMER(id) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns NULL if CONFIG_SMALL is defined otherwise the argument
|
||||
* without modifications, used to disable the definition of strings
|
||||
* (for example AVCodec long_names).
|
||||
*/
|
||||
#ifdef CONFIG_SMALL
|
||||
# define NULL_IF_CONFIG_SMALL(x) NULL
|
||||
#else
|
||||
# define NULL_IF_CONFIG_SMALL(x) x
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_COMMON_H */
|
151
src/add-ons/media/plugins/avcodec/libavutil/crc.c
Normal file
151
src/add-ons/media/plugins/avcodec/libavutil/crc.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "crc.h"
|
||||
|
||||
#ifdef CONFIG_HARDCODED_TABLES
|
||||
#include "crc_data.h"
|
||||
#else
|
||||
static struct {
|
||||
uint8_t le;
|
||||
uint8_t bits;
|
||||
uint32_t poly;
|
||||
} av_crc_table_params[AV_CRC_MAX] = {
|
||||
[AV_CRC_8_ATM] = { 0, 8, 0x07 },
|
||||
[AV_CRC_16_ANSI] = { 0, 16, 0x8005 },
|
||||
[AV_CRC_16_CCITT] = { 0, 16, 0x1021 },
|
||||
[AV_CRC_32_IEEE] = { 0, 32, 0x04C11DB7 },
|
||||
[AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 },
|
||||
};
|
||||
static AVCRC av_crc_table[AV_CRC_MAX][257];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param le if 1, lowest bit represents coefficient for highest exponent
|
||||
* of corresponding polynomial (both for poly and actual CRC).
|
||||
* If 0, you must swap the crc parameter and the result of av_crc
|
||||
* if you need the standard representation (can be simplified in
|
||||
* most cases to e.g. bswap16):
|
||||
* bswap_32(crc << (32-bits))
|
||||
* @param bits number of bits for the CRC
|
||||
* @param poly generator polynomial without the x**bits coefficient, in the
|
||||
* representation as specified by le
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an initialized standard CRC table.
|
||||
* @param crc_id ID of a standard CRC
|
||||
* @return a pointer to the CRC table or NULL on failure
|
||||
*/
|
||||
const AVCRC *av_crc_get_table(AVCRCId crc_id){
|
||||
#ifndef CONFIG_HARDCODED_TABLES
|
||||
if (!av_crc_table[crc_id][sizeof(av_crc_table[crc_id])/sizeof(av_crc_table[crc_id][0])-1])
|
||||
if (av_crc_init(av_crc_table[crc_id],
|
||||
av_crc_table_params[crc_id].le,
|
||||
av_crc_table_params[crc_id].bits,
|
||||
av_crc_table_params[crc_id].poly,
|
||||
sizeof(av_crc_table[crc_id])) < 0)
|
||||
return NULL;
|
||||
#endif
|
||||
return av_crc_table[crc_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the CRC of a block
|
||||
* @param crc CRC of previous blocks if any or initial value for CRC.
|
||||
* @return CRC updated with the data from the given block
|
||||
*
|
||||
* @see av_crc_init() "le" parameter
|
||||
*/
|
||||
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(*(const 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
|
||||
int main(void){
|
||||
uint8_t buf[1999];
|
||||
int i;
|
||||
int p[4][3]={{AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04},
|
||||
{AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0},
|
||||
{AV_CRC_16_ANSI , 0x8005, 0x1FBB },
|
||||
{AV_CRC_8_ATM , 0x07, 0xE3 },};
|
||||
const AVCRC *ctx;
|
||||
|
||||
for(i=0; i<sizeof(buf); i++)
|
||||
buf[i]= i+i*i;
|
||||
|
||||
for(i=0; i<4; i++){
|
||||
ctx = av_crc_get_table(p[i][0]);
|
||||
printf("crc %08X =%X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
44
src/add-ons/media/plugins/avcodec/libavutil/crc.h
Normal file
44
src/add-ons/media/plugins/avcodec/libavutil/crc.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_CRC_H
|
||||
#define FFMPEG_CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "common.h"
|
||||
|
||||
typedef uint32_t AVCRC;
|
||||
|
||||
typedef enum {
|
||||
AV_CRC_8_ATM,
|
||||
AV_CRC_16_ANSI,
|
||||
AV_CRC_16_CCITT,
|
||||
AV_CRC_32_IEEE,
|
||||
AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */
|
||||
AV_CRC_MAX, /*< not part of public API! don't use outside lavu */
|
||||
}AVCRCId;
|
||||
|
||||
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
|
||||
const AVCRC *av_crc_get_table(AVCRCId crc_id);
|
||||
uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length) av_pure;
|
||||
|
||||
#endif /* FFMPEG_CRC_H */
|
||||
|
213
src/add-ons/media/plugins/avcodec/libavutil/crc_data.h
Normal file
213
src/add-ons/media/plugins/avcodec/libavutil/crc_data.h
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* copyright (c) 2008 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_CRC_DATA_H
|
||||
#define FFMPEG_CRC_DATA_H
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
|
||||
[AV_CRC_8_ATM] = {
|
||||
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31,
|
||||
0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
|
||||
0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9,
|
||||
0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
|
||||
0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1,
|
||||
0xB4, 0xB3, 0xBA, 0xBD, 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
|
||||
0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 0xB7, 0xB0, 0xB9, 0xBE,
|
||||
0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
|
||||
0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16,
|
||||
0x03, 0x04, 0x0D, 0x0A, 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
|
||||
0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 0x89, 0x8E, 0x87, 0x80,
|
||||
0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
|
||||
0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8,
|
||||
0xDD, 0xDA, 0xD3, 0xD4, 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
|
||||
0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, 0x19, 0x1E, 0x17, 0x10,
|
||||
0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
|
||||
0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F,
|
||||
0x6A, 0x6D, 0x64, 0x63, 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
|
||||
0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 0xAE, 0xA9, 0xA0, 0xA7,
|
||||
0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
|
||||
0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
|
||||
0xFA, 0xFD, 0xF4, 0xF3, 0x01
|
||||
},
|
||||
[AV_CRC_16_ANSI] = {
|
||||
0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
|
||||
0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
|
||||
0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200,
|
||||
0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180,
|
||||
0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200,
|
||||
0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180,
|
||||
0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180,
|
||||
0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200,
|
||||
0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201,
|
||||
0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181,
|
||||
0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181,
|
||||
0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201,
|
||||
0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181,
|
||||
0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201,
|
||||
0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201,
|
||||
0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181,
|
||||
0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203,
|
||||
0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183,
|
||||
0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183,
|
||||
0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203,
|
||||
0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183,
|
||||
0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203,
|
||||
0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203,
|
||||
0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183,
|
||||
0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182,
|
||||
0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202,
|
||||
0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202,
|
||||
0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182,
|
||||
0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202,
|
||||
0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182,
|
||||
0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182,
|
||||
0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202,
|
||||
0x0001
|
||||
},
|
||||
[AV_CRC_16_CCITT] = {
|
||||
0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770,
|
||||
0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1,
|
||||
0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662,
|
||||
0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3,
|
||||
0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554,
|
||||
0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5,
|
||||
0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446,
|
||||
0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7,
|
||||
0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338,
|
||||
0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9,
|
||||
0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A,
|
||||
0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB,
|
||||
0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C,
|
||||
0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D,
|
||||
0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E,
|
||||
0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F,
|
||||
0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1,
|
||||
0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760,
|
||||
0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3,
|
||||
0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672,
|
||||
0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5,
|
||||
0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544,
|
||||
0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7,
|
||||
0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456,
|
||||
0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9,
|
||||
0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328,
|
||||
0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB,
|
||||
0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A,
|
||||
0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D,
|
||||
0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C,
|
||||
0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F,
|
||||
0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E,
|
||||
0x0001
|
||||
},
|
||||
[AV_CRC_32_IEEE] = {
|
||||
0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D, 0xDC760413, 0x6B6BC517,
|
||||
0xB24D861A, 0x0550471E, 0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B,
|
||||
0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38, 0x70DB114C, 0xC7C6D048,
|
||||
0x1EE09345, 0xA9FD5241, 0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652,
|
||||
0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67, 0x14401D79, 0xA35DDC7D,
|
||||
0x7A7B9F70, 0xCD665E74, 0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095,
|
||||
0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486, 0x585B2BBE, 0xEF46EABA,
|
||||
0x3660A9B7, 0x817D68B3, 0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0,
|
||||
0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9, 0x4C1B36C7, 0xFB06F7C3,
|
||||
0x2220B4CE, 0x953D75CA, 0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF,
|
||||
0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC, 0x77708634, 0xC06D4730,
|
||||
0x194B043D, 0xAE56C539, 0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A,
|
||||
0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F, 0x13EB8A01, 0xA4F64B05,
|
||||
0x7DD00808, 0xCACDC90C, 0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475,
|
||||
0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066, 0xBF469F5E, 0x085B5E5A,
|
||||
0xD17D1D57, 0x6660DC53, 0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840,
|
||||
0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1, 0x4BB0A1BF, 0xFCAD60BB,
|
||||
0x258B23B6, 0x9296E2B2, 0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87,
|
||||
0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94, 0xE71DB4E0, 0x500075E4,
|
||||
0x892636E9, 0x3E3BF7ED, 0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE,
|
||||
0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB, 0x8386B8D5, 0x349B79D1,
|
||||
0xEDBD3ADC, 0x5AA0FBD8, 0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64,
|
||||
0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77, 0x560D044F, 0xE110C54B,
|
||||
0x38368646, 0x8F2B4742, 0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351,
|
||||
0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28, 0x424D1936, 0xF550D832,
|
||||
0x2C769B3F, 0x9B6B5A3B, 0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E,
|
||||
0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D, 0x0E562FF1, 0xB94BEEF5,
|
||||
0x606DADF8, 0xD7706CFC, 0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF,
|
||||
0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA, 0x6ACD23C4, 0xDDD0E2C0,
|
||||
0x04F6A1CD, 0xB3EB60C9, 0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0,
|
||||
0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3, 0xC660369B, 0x717DF79F,
|
||||
0xA85BB492, 0x1F467596, 0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185,
|
||||
0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950, 0x45E68E4E, 0xF2FB4F4A,
|
||||
0x2BDD0C47, 0x9CC0CD43, 0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176,
|
||||
0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565, 0xE94B9B11, 0x5E565A15,
|
||||
0x87701918, 0x306DD81C, 0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F,
|
||||
0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A, 0x8DD09724, 0x3ACD5620,
|
||||
0xE3EB152D, 0x54F6D429, 0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8,
|
||||
0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB, 0xC1CBA1E3, 0x76D660E7,
|
||||
0xAFF023EA, 0x18EDE2EE, 0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD,
|
||||
0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84, 0xD58BBC9A, 0x62967D9E,
|
||||
0xBBB03E93, 0x0CADFF97, 0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2,
|
||||
0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1, 0x00000001
|
||||
},
|
||||
[AV_CRC_32_IEEE_LE] = {
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
|
||||
0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
|
||||
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
|
||||
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
||||
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
|
||||
0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
|
||||
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
|
||||
0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
||||
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
|
||||
0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
|
||||
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,
|
||||
0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
||||
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
|
||||
0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
|
||||
0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
||||
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
|
||||
0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
|
||||
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,
|
||||
0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
||||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
|
||||
0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
|
||||
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,
|
||||
0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
||||
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
|
||||
0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
|
||||
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
|
||||
0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
|
||||
0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
|
||||
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,
|
||||
0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
||||
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
|
||||
0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
|
||||
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
|
||||
0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
|
||||
0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
|
||||
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
|
||||
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
|
||||
0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0x00000001
|
||||
},
|
||||
};
|
||||
|
||||
#endif /* FFMPEG_CRC_DATA_H */
|
334
src/add-ons/media/plugins/avcodec/libavutil/des.c
Normal file
334
src/add-ons/media/plugins/avcodec/libavutil/des.c
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
* DES encryption/decryption
|
||||
* Copyright (c) 2007 Reimar Doeffinger
|
||||
*
|
||||
* 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 <inttypes.h>
|
||||
#include "common.h"
|
||||
#include "des.h"
|
||||
|
||||
#define T(a, b, c, d, e, f, g, h) 64-a,64-b,64-c,64-d,64-e,64-f,64-g,64-h
|
||||
static const uint8_t IP_shuffle[] = {
|
||||
T(58, 50, 42, 34, 26, 18, 10, 2),
|
||||
T(60, 52, 44, 36, 28, 20, 12, 4),
|
||||
T(62, 54, 46, 38, 30, 22, 14, 6),
|
||||
T(64, 56, 48, 40, 32, 24, 16, 8),
|
||||
T(57, 49, 41, 33, 25, 17, 9, 1),
|
||||
T(59, 51, 43, 35, 27, 19, 11, 3),
|
||||
T(61, 53, 45, 37, 29, 21, 13, 5),
|
||||
T(63, 55, 47, 39, 31, 23, 15, 7)
|
||||
};
|
||||
#undef T
|
||||
|
||||
#define T(a, b, c, d) 32-a,32-b,32-c,32-d
|
||||
static const uint8_t P_shuffle[] = {
|
||||
T(16, 7, 20, 21),
|
||||
T(29, 12, 28, 17),
|
||||
T( 1, 15, 23, 26),
|
||||
T( 5, 18, 31, 10),
|
||||
T( 2, 8, 24, 14),
|
||||
T(32, 27, 3, 9),
|
||||
T(19, 13, 30, 6),
|
||||
T(22, 11, 4, 25)
|
||||
};
|
||||
#undef T
|
||||
|
||||
#define T(a, b, c, d, e, f, g) 64-a,64-b,64-c,64-d,64-e,64-f,64-g
|
||||
static const uint8_t PC1_shuffle[] = {
|
||||
T(57, 49, 41, 33, 25, 17, 9),
|
||||
T( 1, 58, 50, 42, 34, 26, 18),
|
||||
T(10, 2, 59, 51, 43, 35, 27),
|
||||
T(19, 11, 3, 60, 52, 44, 36),
|
||||
T(63, 55, 47, 39, 31, 23, 15),
|
||||
T( 7, 62, 54, 46, 38, 30, 22),
|
||||
T(14, 6, 61, 53, 45, 37, 29),
|
||||
T(21, 13, 5, 28, 20, 12, 4)
|
||||
};
|
||||
#undef T
|
||||
|
||||
#define T(a, b, c, d, e, f) 56-a,56-b,56-c,56-d,56-e,56-f
|
||||
static const uint8_t PC2_shuffle[] = {
|
||||
T(14, 17, 11, 24, 1, 5),
|
||||
T( 3, 28, 15, 6, 21, 10),
|
||||
T(23, 19, 12, 4, 26, 8),
|
||||
T(16, 7, 27, 20, 13, 2),
|
||||
T(41, 52, 31, 37, 47, 55),
|
||||
T(30, 40, 51, 45, 33, 48),
|
||||
T(44, 49, 39, 56, 34, 53),
|
||||
T(46, 42, 50, 36, 29, 32)
|
||||
};
|
||||
#undef T
|
||||
|
||||
#ifdef CONFIG_SMALL
|
||||
static const uint8_t S_boxes[8][32] = {
|
||||
{
|
||||
0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87,
|
||||
0xf4, 0xc1, 0x8e, 0x28, 0x4d, 0x96, 0x12, 0x7b, 0x5f, 0xbc, 0x39, 0xe7, 0xa3, 0x0a, 0x65, 0xd0,
|
||||
}, {
|
||||
0x3f, 0xd1, 0x48, 0x7e, 0xf6, 0x2b, 0x83, 0xe4, 0xc9, 0x07, 0x12, 0xad, 0x6c, 0x90, 0xb5, 0x5a,
|
||||
0xd0, 0x8e, 0xa7, 0x1b, 0x3a, 0xf4, 0x4d, 0x21, 0xb5, 0x68, 0x7c, 0xc6, 0x09, 0x53, 0xe2, 0x9f,
|
||||
}, {
|
||||
0xda, 0x70, 0x09, 0x9e, 0x36, 0x43, 0x6f, 0xa5, 0x21, 0x8d, 0x5c, 0xe7, 0xcb, 0xb4, 0xf2, 0x18,
|
||||
0x1d, 0xa6, 0xd4, 0x09, 0x68, 0x9f, 0x83, 0x70, 0x4b, 0xf1, 0xe2, 0x3c, 0xb5, 0x5a, 0x2e, 0xc7,
|
||||
}, {
|
||||
0xd7, 0x8d, 0xbe, 0x53, 0x60, 0xf6, 0x09, 0x3a, 0x41, 0x72, 0x28, 0xc5, 0x1b, 0xac, 0xe4, 0x9f,
|
||||
0x3a, 0xf6, 0x09, 0x60, 0xac, 0x1b, 0xd7, 0x8d, 0x9f, 0x41, 0x53, 0xbe, 0xc5, 0x72, 0x28, 0xe4,
|
||||
}, {
|
||||
0xe2, 0xbc, 0x24, 0xc1, 0x47, 0x7a, 0xdb, 0x16, 0x58, 0x05, 0xf3, 0xaf, 0x3d, 0x90, 0x8e, 0x69,
|
||||
0xb4, 0x82, 0xc1, 0x7b, 0x1a, 0xed, 0x27, 0xd8, 0x6f, 0xf9, 0x0c, 0x95, 0xa6, 0x43, 0x50, 0x3e,
|
||||
}, {
|
||||
0xac, 0xf1, 0x4a, 0x2f, 0x79, 0xc2, 0x96, 0x58, 0x60, 0x1d, 0xd3, 0xe4, 0x0e, 0xb7, 0x35, 0x8b,
|
||||
0x49, 0x3e, 0x2f, 0xc5, 0x92, 0x58, 0xfc, 0xa3, 0xb7, 0xe0, 0x14, 0x7a, 0x61, 0x0d, 0x8b, 0xd6,
|
||||
}, {
|
||||
0xd4, 0x0b, 0xb2, 0x7e, 0x4f, 0x90, 0x18, 0xad, 0xe3, 0x3c, 0x59, 0xc7, 0x25, 0xfa, 0x86, 0x61,
|
||||
0x61, 0xb4, 0xdb, 0x8d, 0x1c, 0x43, 0xa7, 0x7e, 0x9a, 0x5f, 0x06, 0xf8, 0xe0, 0x25, 0x39, 0xc2,
|
||||
}, {
|
||||
0x1d, 0xf2, 0xd8, 0x84, 0xa6, 0x3f, 0x7b, 0x41, 0xca, 0x59, 0x63, 0xbe, 0x05, 0xe0, 0x9c, 0x27,
|
||||
0x27, 0x1b, 0xe4, 0x71, 0x49, 0xac, 0x8e, 0xd2, 0xf0, 0xc6, 0x9a, 0x0d, 0x3f, 0x53, 0x65, 0xb8,
|
||||
}
|
||||
};
|
||||
#else
|
||||
/**
|
||||
* This table contains the results of applying both the S-box and P-shuffle.
|
||||
* It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
|
||||
*/
|
||||
static const uint32_t S_boxes_P_shuffle[8][64] = {
|
||||
{
|
||||
0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
|
||||
0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
|
||||
0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
|
||||
0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
|
||||
0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
|
||||
0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
|
||||
0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
|
||||
0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002,
|
||||
},
|
||||
{
|
||||
0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
|
||||
0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
|
||||
0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
|
||||
0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
|
||||
0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
|
||||
0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
|
||||
0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
|
||||
0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000,
|
||||
},
|
||||
{
|
||||
0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
|
||||
0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
|
||||
0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
|
||||
0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
|
||||
0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
|
||||
0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
|
||||
0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
|
||||
0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100,
|
||||
},
|
||||
{
|
||||
0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
|
||||
0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
|
||||
0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
|
||||
0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
|
||||
0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
|
||||
0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
|
||||
0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
|
||||
0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040,
|
||||
},
|
||||
{
|
||||
0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
|
||||
0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
|
||||
0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
|
||||
0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
|
||||
0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
|
||||
0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
|
||||
0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
|
||||
0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080,
|
||||
},
|
||||
{
|
||||
0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
|
||||
0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
|
||||
0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
|
||||
0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
|
||||
0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
|
||||
0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
|
||||
0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
|
||||
0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008,
|
||||
},
|
||||
{
|
||||
0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
|
||||
0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
|
||||
0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
|
||||
0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
|
||||
0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
|
||||
0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
|
||||
0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
|
||||
0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001,
|
||||
},
|
||||
{
|
||||
0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
|
||||
0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
|
||||
0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
|
||||
0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
|
||||
0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
|
||||
0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
|
||||
0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
|
||||
0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
|
||||
int i;
|
||||
uint64_t res = 0;
|
||||
for (i = 0; i < shuffle_len; i++)
|
||||
res += res + ((in >> *shuffle++) & 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len) {
|
||||
int i;
|
||||
uint64_t res = 0;
|
||||
shuffle += shuffle_len - 1;
|
||||
for (i = 0; i < shuffle_len; i++) {
|
||||
res |= (in & 1) << *shuffle--;
|
||||
in >>= 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint32_t f_func(uint32_t r, uint64_t k) {
|
||||
int i;
|
||||
uint32_t out = 0;
|
||||
// rotate to get first part of E-shuffle in the lowest 6 bits
|
||||
r = (r << 1) | (r >> 31);
|
||||
// apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits
|
||||
for (i = 7; i >= 0; i--) {
|
||||
uint8_t tmp = (r ^ k) & 0x3f;
|
||||
#ifdef CONFIG_SMALL
|
||||
uint8_t v = S_boxes[i][tmp >> 1];
|
||||
if (tmp & 1) v >>= 4;
|
||||
out = (out >> 4) | (v << 28);
|
||||
#else
|
||||
out |= S_boxes_P_shuffle[i][tmp];
|
||||
#endif
|
||||
// get next 6 bits of E-shuffle and round key k into the lowest bits
|
||||
r = (r >> 4) | (r << 28);
|
||||
k >>= 6;
|
||||
}
|
||||
#ifdef CONFIG_SMALL
|
||||
out = shuffle(out, P_shuffle, sizeof(P_shuffle));
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief rotate the two halves of the expanded 56 bit key each 1 bit left
|
||||
*
|
||||
* Note: the specification calls this "shift", so I kept it although
|
||||
* it is confusing.
|
||||
*/
|
||||
static uint64_t key_shift_left(uint64_t CDn) {
|
||||
uint64_t carries = (CDn >> 27) & 0x10000001;
|
||||
CDn <<= 1;
|
||||
CDn &= ~0x10000001;
|
||||
CDn |= carries;
|
||||
return CDn;
|
||||
}
|
||||
|
||||
uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) {
|
||||
int i;
|
||||
uint64_t K[16];
|
||||
// discard parity bits from key and shuffle it into C and D parts
|
||||
uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle));
|
||||
// generate round keys
|
||||
for (i = 0; i < 16; i++) {
|
||||
CDn = key_shift_left(CDn);
|
||||
if (i > 1 && i != 8 && i != 15)
|
||||
CDn = key_shift_left(CDn);
|
||||
K[i] = shuffle(CDn, PC2_shuffle, sizeof(PC2_shuffle));
|
||||
}
|
||||
// used to apply round keys in reverse order for decryption
|
||||
decrypt = decrypt ? 15 : 0;
|
||||
// shuffle irrelevant to security but to ease hardware implementations
|
||||
in = shuffle(in, IP_shuffle, sizeof(IP_shuffle));
|
||||
for (i = 0; i < 16; i++) {
|
||||
uint32_t f_res;
|
||||
f_res = f_func(in, K[decrypt ^ i]);
|
||||
in = (in << 32) | (in >> 32);
|
||||
in ^= f_res;
|
||||
}
|
||||
in = (in << 32) | (in >> 32);
|
||||
// reverse shuffle used to ease hardware implementations
|
||||
in = shuffle_inv(in, IP_shuffle, sizeof(IP_shuffle));
|
||||
return in;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#undef printf
|
||||
#undef rand
|
||||
#undef srand
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
static uint64_t rand64(void) {
|
||||
uint64_t r = rand();
|
||||
r = (r << 32) | rand();
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int i, j;
|
||||
struct timeval tv;
|
||||
uint64_t key;
|
||||
uint64_t data;
|
||||
uint64_t ct;
|
||||
gettimeofday(&tv, NULL);
|
||||
srand(tv.tv_sec * 1000 * 1000 + tv.tv_usec);
|
||||
key = 0x123456789abcdef0ULL;
|
||||
data = 0xfedcba9876543210ULL;
|
||||
if (ff_des_encdec(data, key, 0) != 0x4ab65b3d4b061518ULL) {
|
||||
printf("Test 1 failed\n");
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < 1000000; i++) {
|
||||
key = rand64();
|
||||
data = rand64();
|
||||
ct = ff_des_encdec(data, key, 0);
|
||||
if (ff_des_encdec(ct, key, 1) != data) {
|
||||
printf("Test 2 failed\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#ifdef GENTABLES
|
||||
printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf(" {");
|
||||
for (j = 0; j < 64; j++) {
|
||||
uint32_t v = S_boxes[i][j >> 1];
|
||||
v = j & 1 ? v >> 4 : v & 0xf;
|
||||
v <<= 28 - 4 * i;
|
||||
v = shuffle(v, P_shuffle, sizeof(P_shuffle));
|
||||
printf((j & 7) == 0 ? "\n " : " ");
|
||||
printf("0x%08X,", v);
|
||||
}
|
||||
printf("\n },\n");
|
||||
}
|
||||
printf("};\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
40
src/add-ons/media/plugins/avcodec/libavutil/des.h
Normal file
40
src/add-ons/media/plugins/avcodec/libavutil/des.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* DES encryption/decryption
|
||||
* Copyright (c) 2007 Reimar Doeffinger
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_DES_H
|
||||
#define FFMPEG_DES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* \brief en- or decrypt an 64-bit block of data with DES
|
||||
* \param in data to process.
|
||||
* \param key key to use for en-/decryption.
|
||||
* \param decrypt if 0 encrypt, else decrypt.
|
||||
* \return processed data
|
||||
*
|
||||
* If your input data is in 8-bit blocks treat it as big-endian
|
||||
* (use e.g. AV_RB64 and AV_WB64).
|
||||
*/
|
||||
uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) av_const;
|
||||
|
||||
#endif /* FFMPEG_DES_H */
|
124
src/add-ons/media/plugins/avcodec/libavutil/fifo.c
Normal file
124
src/add-ons/media/plugins/avcodec/libavutil/fifo.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* A very simple circular buffer FIFO implementation
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2006 Roman Shaposhnik
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "fifo.h"
|
||||
|
||||
int av_fifo_init(AVFifoBuffer *f, unsigned int size)
|
||||
{
|
||||
size= FFMAX(size, size+1);
|
||||
f->wptr = f->rptr =
|
||||
f->buffer = av_malloc(size);
|
||||
f->end = f->buffer + size;
|
||||
if (!f->buffer)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_fifo_free(AVFifoBuffer *f)
|
||||
{
|
||||
av_free(f->buffer);
|
||||
}
|
||||
|
||||
int av_fifo_size(AVFifoBuffer *f)
|
||||
{
|
||||
int size = f->wptr - f->rptr;
|
||||
if (size < 0)
|
||||
size += f->end - f->buffer;
|
||||
return size;
|
||||
}
|
||||
|
||||
int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
|
||||
{
|
||||
return av_fifo_generic_read(f, buf_size, NULL, buf);
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
|
||||
av_fifo_realloc2(f, new_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
|
||||
unsigned int old_size= f->end - f->buffer;
|
||||
|
||||
if(old_size <= new_size){
|
||||
int len= av_fifo_size(f);
|
||||
AVFifoBuffer f2;
|
||||
|
||||
if (av_fifo_init(&f2, new_size) < 0)
|
||||
return -1;
|
||||
av_fifo_read(f, f2.buffer, len);
|
||||
f2.wptr += len;
|
||||
av_free(f->buffer);
|
||||
*f= f2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
|
||||
{
|
||||
av_fifo_generic_write(f, (void *)buf, size, NULL);
|
||||
}
|
||||
|
||||
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
|
||||
{
|
||||
int total = size;
|
||||
do {
|
||||
int len = FFMIN(f->end - f->wptr, size);
|
||||
if(func) {
|
||||
if(func(src, f->wptr, len) <= 0)
|
||||
break;
|
||||
} else {
|
||||
memcpy(f->wptr, src, len);
|
||||
src = (uint8_t*)src + len;
|
||||
}
|
||||
f->wptr += len;
|
||||
if (f->wptr >= f->end)
|
||||
f->wptr = f->buffer;
|
||||
size -= len;
|
||||
} while (size > 0);
|
||||
return total - size;
|
||||
}
|
||||
|
||||
|
||||
int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest)
|
||||
{
|
||||
do {
|
||||
int len = FFMIN(f->end - f->rptr, buf_size);
|
||||
if(func) func(dest, f->rptr, len);
|
||||
else{
|
||||
memcpy(dest, f->rptr, len);
|
||||
dest = (uint8_t*)dest + len;
|
||||
}
|
||||
av_fifo_drain(f, len);
|
||||
buf_size -= len;
|
||||
} while (buf_size > 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** discard data from the fifo */
|
||||
void av_fifo_drain(AVFifoBuffer *f, int size)
|
||||
{
|
||||
f->rptr += size;
|
||||
if (f->rptr >= f->end)
|
||||
f->rptr -= f->end - f->buffer;
|
||||
}
|
128
src/add-ons/media/plugins/avcodec/libavutil/fifo.h
Normal file
128
src/add-ons/media/plugins/avcodec/libavutil/fifo.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file fifo.h
|
||||
* A very simple circular buffer FIFO implementation.
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_FIFO_H
|
||||
#define FFMPEG_FIFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
typedef struct AVFifoBuffer {
|
||||
uint8_t *buffer;
|
||||
uint8_t *rptr, *wptr, *end;
|
||||
} AVFifoBuffer;
|
||||
|
||||
/**
|
||||
* Initializes an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to initialize
|
||||
* @param size of FIFO
|
||||
* @return <0 for failure >=0 otherwise
|
||||
*/
|
||||
int av_fifo_init(AVFifoBuffer *f, unsigned int size);
|
||||
|
||||
/**
|
||||
* Frees an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to free
|
||||
*/
|
||||
void av_fifo_free(AVFifoBuffer *f);
|
||||
|
||||
/**
|
||||
* Returns the amount of data in bytes in the AVFifoBuffer, that is the
|
||||
* amount of data you can read from it.
|
||||
* @param *f AVFifoBuffer to read from
|
||||
* @return size
|
||||
*/
|
||||
int av_fifo_size(AVFifoBuffer *f);
|
||||
|
||||
/**
|
||||
* Reads data from an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to read from
|
||||
* @param *buf data destination
|
||||
* @param buf_size number of bytes to read
|
||||
*/
|
||||
int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
|
||||
|
||||
/**
|
||||
* Feeds data from an AVFifoBuffer to a user supplied callback.
|
||||
* @param *f AVFifoBuffer to read from
|
||||
* @param buf_size number of bytes to read
|
||||
* @param *func generic read function
|
||||
* @param *dest data destination
|
||||
*/
|
||||
int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
|
||||
|
||||
/**
|
||||
* Writes data into an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to write to
|
||||
* @param *buf data source
|
||||
* @param size data size
|
||||
*/
|
||||
attribute_deprecated void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
|
||||
|
||||
/**
|
||||
* Feeds data from a user supplied callback to an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to write to
|
||||
* @param *src data source
|
||||
* @param size number of bytes to write
|
||||
* @param *func generic write function. First parameter is src,
|
||||
* second is dest_buf, third is dest_buf_size.
|
||||
* func must return the number of bytes written to dest_buf, or <= 0 to
|
||||
* indicate no more data available to write.
|
||||
* If func is NULL, src is interpreted as a simple byte array for source data.
|
||||
* @return the number of bytes written to the fifo.
|
||||
*/
|
||||
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int));
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
/**
|
||||
* Resizes an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to resize
|
||||
* @param size new AVFifoBuffer size in bytes
|
||||
* @see av_fifo_realloc2()
|
||||
*/
|
||||
attribute_deprecated void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Resizes an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to resize
|
||||
* @param size new AVFifoBuffer size in bytes
|
||||
* @return <0 for failure >=0 otherwise
|
||||
*/
|
||||
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
|
||||
|
||||
/**
|
||||
* Reads and discards the specified amount of data from an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to read from
|
||||
* @param size amount of data to read in bytes
|
||||
*/
|
||||
void av_fifo_drain(AVFifoBuffer *f, int size);
|
||||
|
||||
static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
|
||||
{
|
||||
uint8_t *ptr = f->rptr + offs;
|
||||
if (ptr >= f->end)
|
||||
ptr -= f->end - f->buffer;
|
||||
return *ptr;
|
||||
}
|
||||
#endif /* FFMPEG_FIFO_H */
|
197
src/add-ons/media/plugins/avcodec/libavutil/integer.c
Normal file
197
src/add-ons/media/plugins/avcodec/libavutil/integer.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* arbitrary precision integers
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file integer.c
|
||||
* arbitrary precision integers.
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "integer.h"
|
||||
|
||||
AVInteger av_add_i(AVInteger a, AVInteger b){
|
||||
int i, carry=0;
|
||||
|
||||
for(i=0; i<AV_INTEGER_SIZE; i++){
|
||||
carry= (carry>>16) + a.v[i] + b.v[i];
|
||||
a.v[i]= carry;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
AVInteger av_sub_i(AVInteger a, AVInteger b){
|
||||
int i, carry=0;
|
||||
|
||||
for(i=0; i<AV_INTEGER_SIZE; i++){
|
||||
carry= (carry>>16) + a.v[i] - b.v[i];
|
||||
a.v[i]= carry;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int av_log2_i(AVInteger a){
|
||||
int i;
|
||||
|
||||
for(i=AV_INTEGER_SIZE-1; i>=0; i--){
|
||||
if(a.v[i])
|
||||
return av_log2_16bit(a.v[i]) + 16*i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
AVInteger av_mul_i(AVInteger a, AVInteger b){
|
||||
AVInteger out;
|
||||
int i, j;
|
||||
int na= (av_log2_i(a)+16) >> 4;
|
||||
int nb= (av_log2_i(b)+16) >> 4;
|
||||
|
||||
memset(&out, 0, sizeof(out));
|
||||
|
||||
for(i=0; i<na; i++){
|
||||
unsigned int carry=0;
|
||||
|
||||
if(a.v[i])
|
||||
for(j=i; j<AV_INTEGER_SIZE && j-i<=nb; j++){
|
||||
carry= (carry>>16) + out.v[j] + a.v[i]*b.v[j-i];
|
||||
out.v[j]= carry;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int av_cmp_i(AVInteger a, AVInteger b){
|
||||
int i;
|
||||
int v= (int16_t)a.v[AV_INTEGER_SIZE-1] - (int16_t)b.v[AV_INTEGER_SIZE-1];
|
||||
if(v) return (v>>16)|1;
|
||||
|
||||
for(i=AV_INTEGER_SIZE-2; i>=0; i--){
|
||||
int v= a.v[i] - b.v[i];
|
||||
if(v) return (v>>16)|1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
AVInteger av_shr_i(AVInteger a, int s){
|
||||
AVInteger out;
|
||||
int i;
|
||||
|
||||
for(i=0; i<AV_INTEGER_SIZE; i++){
|
||||
unsigned int index= i + (s>>4);
|
||||
unsigned int v=0;
|
||||
if(index+1<AV_INTEGER_SIZE) v = a.v[index+1]<<16;
|
||||
if(index <AV_INTEGER_SIZE) v+= a.v[index ];
|
||||
out.v[i]= v >> (s&15);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
|
||||
int i= av_log2_i(a) - av_log2_i(b);
|
||||
AVInteger quot_temp;
|
||||
if(!quot) quot = "_temp;
|
||||
|
||||
assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
|
||||
assert(av_log2(b)>=0);
|
||||
|
||||
if(i > 0)
|
||||
b= av_shr_i(b, -i);
|
||||
|
||||
memset(quot, 0, sizeof(AVInteger));
|
||||
|
||||
while(i-- >= 0){
|
||||
*quot= av_shr_i(*quot, -1);
|
||||
if(av_cmp_i(a, b) >= 0){
|
||||
a= av_sub_i(a, b);
|
||||
quot->v[0] += 1;
|
||||
}
|
||||
b= av_shr_i(b, 1);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
AVInteger av_div_i(AVInteger a, AVInteger b){
|
||||
AVInteger quot;
|
||||
av_mod_i(", a, b);
|
||||
return quot;
|
||||
}
|
||||
|
||||
AVInteger av_int2i(int64_t a){
|
||||
AVInteger out;
|
||||
int i;
|
||||
|
||||
for(i=0; i<AV_INTEGER_SIZE; i++){
|
||||
out.v[i]= a;
|
||||
a>>=16;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int64_t av_i2int(AVInteger a){
|
||||
int i;
|
||||
int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
|
||||
|
||||
for(i= AV_INTEGER_SIZE-2; i>=0; i--){
|
||||
out = (out<<16) + a.v[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
|
||||
const uint8_t ff_log2_tab[256]={
|
||||
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
int main(void){
|
||||
int64_t a,b;
|
||||
|
||||
for(a=7; a<256*256*256; a+=13215){
|
||||
for(b=3; b<256*256*256; b+=27118){
|
||||
AVInteger ai= av_int2i(a);
|
||||
AVInteger bi= av_int2i(b);
|
||||
|
||||
assert(av_i2int(ai) == a);
|
||||
assert(av_i2int(bi) == b);
|
||||
assert(av_i2int(av_add_i(ai,bi)) == a+b);
|
||||
assert(av_i2int(av_sub_i(ai,bi)) == a-b);
|
||||
assert(av_i2int(av_mul_i(ai,bi)) == a*b);
|
||||
assert(av_i2int(av_shr_i(ai, 9)) == a>>9);
|
||||
assert(av_i2int(av_shr_i(ai,-9)) == a<<9);
|
||||
assert(av_i2int(av_shr_i(ai, 17)) == a>>17);
|
||||
assert(av_i2int(av_shr_i(ai,-17)) == a<<17);
|
||||
assert(av_log2_i(ai) == av_log2(a));
|
||||
assert(av_i2int(av_div_i(ai,bi)) == a/b);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
84
src/add-ons/media/plugins/avcodec/libavutil/integer.h
Normal file
84
src/add-ons/media/plugins/avcodec/libavutil/integer.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* arbitrary precision integers
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file integer.h
|
||||
* arbitrary precision integers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTEGER_H
|
||||
#define FFMPEG_INTEGER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#define AV_INTEGER_SIZE 8
|
||||
|
||||
typedef struct AVInteger{
|
||||
uint16_t v[AV_INTEGER_SIZE];
|
||||
} AVInteger;
|
||||
|
||||
AVInteger av_add_i(AVInteger a, AVInteger b) av_const;
|
||||
AVInteger av_sub_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* returns the rounded down value of the logarithm of base 2 of the given AVInteger.
|
||||
* this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0
|
||||
*/
|
||||
int av_log2_i(AVInteger a) av_const;
|
||||
AVInteger av_mul_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* returns 0 if a==b, 1 if a>b and -1 if a<b.
|
||||
*/
|
||||
int av_cmp_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* bitwise shift.
|
||||
* @param s the number of bits by which the value should be shifted right, may be negative for shifting left
|
||||
*/
|
||||
AVInteger av_shr_i(AVInteger a, int s) av_const;
|
||||
|
||||
/**
|
||||
* returns a % b.
|
||||
* @param quot a/b will be stored here
|
||||
*/
|
||||
AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
|
||||
|
||||
/**
|
||||
* returns a/b.
|
||||
*/
|
||||
AVInteger av_div_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* converts the given int64_t to an AVInteger.
|
||||
*/
|
||||
AVInteger av_int2i(int64_t a) av_const;
|
||||
|
||||
/**
|
||||
* converts the given AVInteger to an int64_t.
|
||||
* if the AVInteger is too large to fit into an int64_t,
|
||||
* then only the least significant 64bit will be used
|
||||
*/
|
||||
int64_t av_i2int(AVInteger a) av_const;
|
||||
|
||||
#endif /* FFMPEG_INTEGER_H */
|
300
src/add-ons/media/plugins/avcodec/libavutil/internal.h
Normal file
300
src/add-ons/media/plugins/avcodec/libavutil/internal.h
Normal file
@ -0,0 +1,300 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file internal.h
|
||||
* common internal api header.
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTERNAL_H
|
||||
#define FFMPEG_INTERNAL_H
|
||||
|
||||
#if !defined(DEBUG) && !defined(NDEBUG)
|
||||
# define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef attribute_align_arg
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
|
||||
# define attribute_align_arg __attribute__((force_align_arg_pointer))
|
||||
#else
|
||||
# define attribute_align_arg
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef attribute_used
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
# define attribute_used __attribute__((used))
|
||||
#else
|
||||
# define attribute_used
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-0x7fff-1)
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX 0x7fff
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-0x7fffffff-1)
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX 0x7fffffff
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX 0xffffffff
|
||||
#endif
|
||||
|
||||
#ifndef INT64_MIN
|
||||
#define INT64_MIN (-0x7fffffffffffffffLL-1)
|
||||
#endif
|
||||
|
||||
#ifndef INT64_MAX
|
||||
#define INT64_MAX INT64_C(9223372036854775807)
|
||||
#endif
|
||||
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef INT_BIT
|
||||
# if INT_MAX != 2147483647
|
||||
# define INT_BIT 64
|
||||
# else
|
||||
# define INT_BIT 32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
|
||||
# define PIC
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "bswap.h"
|
||||
|
||||
#ifndef offsetof
|
||||
# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
|
||||
#endif
|
||||
|
||||
// Use rip-relative addressing if compiling PIC code on x86-64.
|
||||
#if defined(ARCH_X86_64) && defined(PIC)
|
||||
# define LOCAL_MANGLE(a) #a "(%%rip)"
|
||||
#else
|
||||
# define LOCAL_MANGLE(a) #a
|
||||
#endif
|
||||
|
||||
#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
|
||||
|
||||
/* debug stuff */
|
||||
|
||||
/* dprintf macros */
|
||||
#ifdef DEBUG
|
||||
# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
# define dprintf(pctx, ...)
|
||||
#endif
|
||||
|
||||
#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
|
||||
|
||||
/* math */
|
||||
|
||||
extern const uint32_t ff_inverse[256];
|
||||
|
||||
#if defined(ARCH_X86)
|
||||
# define FASTDIV(a,b) \
|
||||
({\
|
||||
int ret,dmy;\
|
||||
asm volatile(\
|
||||
"mull %3"\
|
||||
:"=d"(ret),"=a"(dmy)\
|
||||
:"1"(a),"g"(ff_inverse[b])\
|
||||
);\
|
||||
ret;\
|
||||
})
|
||||
#elif defined(HAVE_ARMV6)
|
||||
static inline av_const int FASTDIV(int a, int b)
|
||||
{
|
||||
int r;
|
||||
asm volatile("cmp %2, #0 \n\t"
|
||||
"smmul %0, %1, %2 \n\t"
|
||||
"rsblt %0, %0, #0 \n\t"
|
||||
: "=r"(r) : "r"(a), "r"(ff_inverse[b]));
|
||||
return r;
|
||||
}
|
||||
#elif defined(ARCH_ARMV4L)
|
||||
# define FASTDIV(a,b) \
|
||||
({\
|
||||
int ret,dmy;\
|
||||
asm volatile(\
|
||||
"umull %1, %0, %2, %3"\
|
||||
:"=&r"(ret),"=&r"(dmy)\
|
||||
:"r"(a),"r"(ff_inverse[b])\
|
||||
);\
|
||||
ret;\
|
||||
})
|
||||
#elif defined(CONFIG_FASTDIV)
|
||||
# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
|
||||
#else
|
||||
# define FASTDIV(a,b) ((a)/(b))
|
||||
#endif
|
||||
|
||||
extern const uint8_t ff_sqrt_tab[256];
|
||||
|
||||
static inline int av_log2_16bit(unsigned int v);
|
||||
|
||||
static inline av_const unsigned int ff_sqrt(unsigned int a)
|
||||
{
|
||||
unsigned int b;
|
||||
|
||||
if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
|
||||
else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
|
||||
#ifndef CONFIG_SMALL
|
||||
else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
|
||||
else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ;
|
||||
#endif
|
||||
else{
|
||||
int s= av_log2_16bit(a>>16)>>1;
|
||||
unsigned int c= a>>(s+2);
|
||||
b= ff_sqrt_tab[c>>(s+8)];
|
||||
b= FASTDIV(c,b) + (b<<s);
|
||||
}
|
||||
|
||||
return b - (a<b*b);
|
||||
}
|
||||
|
||||
#if defined(ARCH_X86)
|
||||
#define MASK_ABS(mask, level)\
|
||||
asm volatile(\
|
||||
"cltd \n\t"\
|
||||
"xorl %1, %0 \n\t"\
|
||||
"subl %1, %0 \n\t"\
|
||||
: "+a" (level), "=&d" (mask)\
|
||||
);
|
||||
#else
|
||||
#define MASK_ABS(mask, level)\
|
||||
mask= level>>31;\
|
||||
level= (level^mask)-mask;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CMOV
|
||||
#define COPY3_IF_LT(x,y,a,b,c,d)\
|
||||
asm volatile (\
|
||||
"cmpl %0, %3 \n\t"\
|
||||
"cmovl %3, %0 \n\t"\
|
||||
"cmovl %4, %1 \n\t"\
|
||||
"cmovl %5, %2 \n\t"\
|
||||
: "+&r" (x), "+&r" (a), "+r" (c)\
|
||||
: "r" (y), "r" (b), "r" (d)\
|
||||
);
|
||||
#else
|
||||
#define COPY3_IF_LT(x,y,a,b,c,d)\
|
||||
if((y)<(x)){\
|
||||
(x)=(y);\
|
||||
(a)=(b);\
|
||||
(c)=(d);\
|
||||
}
|
||||
#endif
|
||||
|
||||
/* avoid usage of various functions */
|
||||
#undef malloc
|
||||
#define malloc please_use_av_malloc
|
||||
#undef free
|
||||
#define free please_use_av_free
|
||||
#undef realloc
|
||||
#define realloc please_use_av_realloc
|
||||
#undef time
|
||||
#define time time_is_forbidden_due_to_security_issues
|
||||
#undef rand
|
||||
#define rand rand_is_forbidden_due_to_state_trashing_use_av_random
|
||||
#undef srand
|
||||
#define srand srand_is_forbidden_due_to_state_trashing_use_av_init_random
|
||||
#undef random
|
||||
#define random random_is_forbidden_due_to_state_trashing_use_av_random
|
||||
#undef sprintf
|
||||
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
|
||||
#undef strcat
|
||||
#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
|
||||
#undef exit
|
||||
#define exit exit_is_forbidden
|
||||
#if !(defined(LIBAVFORMAT_BUILD) || defined(FFMPEG_FRAMEHOOK_H))
|
||||
#undef printf
|
||||
#define printf please_use_av_log
|
||||
#undef fprintf
|
||||
#define fprintf please_use_av_log
|
||||
#undef puts
|
||||
#define puts please_use_av_log
|
||||
#undef perror
|
||||
#define perror please_use_av_log_instead_of_perror
|
||||
#endif
|
||||
|
||||
#define CHECKED_ALLOCZ(p, size)\
|
||||
{\
|
||||
p= av_mallocz(size);\
|
||||
if(p==NULL && (size)!=0){\
|
||||
av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\
|
||||
goto fail;\
|
||||
}\
|
||||
}
|
||||
|
||||
#ifndef HAVE_LLRINT
|
||||
static av_always_inline av_const long long llrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif /* HAVE_LLRINT */
|
||||
|
||||
#ifndef HAVE_LRINT
|
||||
static av_always_inline av_const long int lrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif /* HAVE_LRINT */
|
||||
|
||||
#ifndef HAVE_LRINTF
|
||||
static av_always_inline av_const long int lrintf(float x)
|
||||
{
|
||||
return (int)(rint(x));
|
||||
}
|
||||
#endif /* HAVE_LRINTF */
|
||||
|
||||
#ifndef HAVE_ROUND
|
||||
static av_always_inline av_const double round(double x)
|
||||
{
|
||||
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
|
||||
}
|
||||
#endif /* HAVE_ROUND */
|
||||
|
||||
#ifndef HAVE_ROUNDF
|
||||
static av_always_inline av_const float roundf(float x)
|
||||
{
|
||||
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
|
||||
}
|
||||
#endif /* HAVE_ROUNDF */
|
||||
|
||||
#endif /* FFMPEG_INTERNAL_H */
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* portable IEEE float/double read/write functions
|
||||
*
|
||||
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file intfloat_readwrite.c
|
||||
* Portable IEEE float/double read/write functions.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "intfloat_readwrite.h"
|
||||
|
||||
double av_int2dbl(int64_t v){
|
||||
if(v+v > 0xFFEULL<<52)
|
||||
return 0.0/0.0;
|
||||
return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
|
||||
}
|
||||
|
||||
float av_int2flt(int32_t v){
|
||||
if(v+v > 0xFF000000U)
|
||||
return 0.0/0.0;
|
||||
return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
|
||||
}
|
||||
|
||||
double av_ext2dbl(const AVExtFloat ext){
|
||||
uint64_t m = 0;
|
||||
int e, i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
m = (m<<8) + ext.mantissa[i];
|
||||
e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1];
|
||||
if (e == 0x7fff && m)
|
||||
return 0.0/0.0;
|
||||
e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
|
||||
* mantissa bit is written as opposed to the
|
||||
* single and double precision formats */
|
||||
if (ext.exponent[0]&0x80)
|
||||
m= -m;
|
||||
return ldexp(m, e);
|
||||
}
|
||||
|
||||
int64_t av_dbl2int(double d){
|
||||
int e;
|
||||
if ( !d) return 0;
|
||||
else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d);
|
||||
d= frexp(d, &e);
|
||||
return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53));
|
||||
}
|
||||
|
||||
int32_t av_flt2int(float d){
|
||||
int e;
|
||||
if ( !d) return 0;
|
||||
else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
|
||||
d= frexp(d, &e);
|
||||
return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
|
||||
}
|
||||
|
||||
AVExtFloat av_dbl2ext(double d){
|
||||
struct AVExtFloat ext= {{0}};
|
||||
int e, i; double f; uint64_t m;
|
||||
|
||||
f = fabs(frexp(d, &e));
|
||||
if (f >= 0.5 && f < 1) {
|
||||
e += 16382;
|
||||
ext.exponent[0] = e>>8;
|
||||
ext.exponent[1] = e;
|
||||
m = (uint64_t)ldexp(f, 64);
|
||||
for (i=0; i < 8; i++)
|
||||
ext.mantissa[i] = m>>(56-(i<<3));
|
||||
} else if (f != 0.0) {
|
||||
ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
|
||||
if (f != 1/0.0)
|
||||
ext.mantissa[0] = ~0;
|
||||
}
|
||||
if (d < 0)
|
||||
ext.exponent[0] |= 0x80;
|
||||
return ext;
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTFLOAT_READWRITE_H
|
||||
#define FFMPEG_INTFLOAT_READWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
/* IEEE 80 bits extended float */
|
||||
typedef struct AVExtFloat {
|
||||
uint8_t exponent[2];
|
||||
uint8_t mantissa[8];
|
||||
} AVExtFloat;
|
||||
|
||||
double av_int2dbl(int64_t v) av_const;
|
||||
float av_int2flt(int32_t v) av_const;
|
||||
double av_ext2dbl(const AVExtFloat ext) av_const;
|
||||
int64_t av_dbl2int(double d) av_const;
|
||||
int32_t av_flt2int(float d) av_const;
|
||||
AVExtFloat av_dbl2ext(double d) av_const;
|
||||
|
||||
#endif /* FFMPEG_INTFLOAT_READWRITE_H */
|
192
src/add-ons/media/plugins/avcodec/libavutil/intreadwrite.h
Normal file
192
src/add-ons/media/plugins/avcodec/libavutil/intreadwrite.h
Normal file
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTREADWRITE_H
|
||||
#define FFMPEG_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "bswap.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
struct unaligned_64 { uint64_t l; } __attribute__((packed));
|
||||
struct unaligned_32 { uint32_t l; } __attribute__((packed));
|
||||
struct unaligned_16 { uint16_t l; } __attribute__((packed));
|
||||
|
||||
#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
|
||||
#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
|
||||
#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
|
||||
|
||||
#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
|
||||
#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
|
||||
#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
|
||||
|
||||
#elif defined(__DECC)
|
||||
|
||||
#define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
|
||||
#define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
|
||||
#define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
|
||||
|
||||
#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
|
||||
#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
|
||||
#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
|
||||
|
||||
#else
|
||||
|
||||
#define AV_RN16(a) (*((const uint16_t*)(a)))
|
||||
#define AV_RN32(a) (*((const uint32_t*)(a)))
|
||||
#define AV_RN64(a) (*((const uint64_t*)(a)))
|
||||
|
||||
#define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
|
||||
#define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
|
||||
#define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
|
||||
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
/* endian macros */
|
||||
#define AV_RB8(x) (((const uint8_t*)(x))[0])
|
||||
#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
|
||||
|
||||
#define AV_RL8(x) AV_RB8(x)
|
||||
#define AV_WL8(p, d) AV_WB8(p, d)
|
||||
|
||||
#ifdef HAVE_FAST_UNALIGNED
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define AV_RB16(x) AV_RN16(x)
|
||||
# define AV_WB16(p, d) AV_WN16(p, d)
|
||||
|
||||
# define AV_RL16(x) bswap_16(AV_RN16(x))
|
||||
# define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
|
||||
|
||||
# define AV_RB32(x) AV_RN32(x)
|
||||
# define AV_WB32(p, d) AV_WN32(p, d)
|
||||
|
||||
# define AV_RL32(x) bswap_32(AV_RN32(x))
|
||||
# define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
|
||||
|
||||
# define AV_RB64(x) AV_RN64(x)
|
||||
# define AV_WB64(p, d) AV_WN64(p, d)
|
||||
|
||||
# define AV_RL64(x) bswap_64(AV_RN64(x))
|
||||
# define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
|
||||
# else /* WORDS_BIGENDIAN */
|
||||
# define AV_RB16(x) bswap_16(AV_RN16(x))
|
||||
# define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
|
||||
|
||||
# define AV_RL16(x) AV_RN16(x)
|
||||
# define AV_WL16(p, d) AV_WN16(p, d)
|
||||
|
||||
# define AV_RB32(x) bswap_32(AV_RN32(x))
|
||||
# define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
|
||||
|
||||
# define AV_RL32(x) AV_RN32(x)
|
||||
# define AV_WL32(p, d) AV_WN32(p, d)
|
||||
|
||||
# define AV_RB64(x) bswap_64(AV_RN64(x))
|
||||
# define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
|
||||
|
||||
# define AV_RL64(x) AV_RN64(x)
|
||||
# define AV_WL64(p, d) AV_WN64(p, d)
|
||||
# endif
|
||||
#else /* HAVE_FAST_UNALIGNED */
|
||||
#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
|
||||
#define AV_WB16(p, d) do { \
|
||||
((uint8_t*)(p))[1] = (d); \
|
||||
((uint8_t*)(p))[0] = (d)>>8; } while(0)
|
||||
|
||||
#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL16(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; } while(0)
|
||||
|
||||
#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
|
||||
(((const uint8_t*)(x))[1] << 16) | \
|
||||
(((const uint8_t*)(x))[2] << 8) | \
|
||||
((const uint8_t*)(x))[3])
|
||||
#define AV_WB32(p, d) do { \
|
||||
((uint8_t*)(p))[3] = (d); \
|
||||
((uint8_t*)(p))[2] = (d)>>8; \
|
||||
((uint8_t*)(p))[1] = (d)>>16; \
|
||||
((uint8_t*)(p))[0] = (d)>>24; } while(0)
|
||||
|
||||
#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
|
||||
(((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL32(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; \
|
||||
((uint8_t*)(p))[3] = (d)>>24; } while(0)
|
||||
|
||||
#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
|
||||
((uint64_t)((const uint8_t*)(x))[1] << 48) | \
|
||||
((uint64_t)((const uint8_t*)(x))[2] << 40) | \
|
||||
((uint64_t)((const uint8_t*)(x))[3] << 32) | \
|
||||
((uint64_t)((const uint8_t*)(x))[4] << 24) | \
|
||||
((uint64_t)((const uint8_t*)(x))[5] << 16) | \
|
||||
((uint64_t)((const uint8_t*)(x))[6] << 8) | \
|
||||
(uint64_t)((const uint8_t*)(x))[7])
|
||||
#define AV_WB64(p, d) do { \
|
||||
((uint8_t*)(p))[7] = (d); \
|
||||
((uint8_t*)(p))[6] = (d)>>8; \
|
||||
((uint8_t*)(p))[5] = (d)>>16; \
|
||||
((uint8_t*)(p))[4] = (d)>>24; \
|
||||
((uint8_t*)(p))[3] = (d)>>32; \
|
||||
((uint8_t*)(p))[2] = (d)>>40; \
|
||||
((uint8_t*)(p))[1] = (d)>>48; \
|
||||
((uint8_t*)(p))[0] = (d)>>56; } while(0)
|
||||
|
||||
#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
|
||||
((uint64_t)((const uint8_t*)(x))[6] << 48) | \
|
||||
((uint64_t)((const uint8_t*)(x))[5] << 40) | \
|
||||
((uint64_t)((const uint8_t*)(x))[4] << 32) | \
|
||||
((uint64_t)((const uint8_t*)(x))[3] << 24) | \
|
||||
((uint64_t)((const uint8_t*)(x))[2] << 16) | \
|
||||
((uint64_t)((const uint8_t*)(x))[1] << 8) | \
|
||||
(uint64_t)((const uint8_t*)(x))[0])
|
||||
#define AV_WL64(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; \
|
||||
((uint8_t*)(p))[3] = (d)>>24; \
|
||||
((uint8_t*)(p))[4] = (d)>>32; \
|
||||
((uint8_t*)(p))[5] = (d)>>40; \
|
||||
((uint8_t*)(p))[6] = (d)>>48; \
|
||||
((uint8_t*)(p))[7] = (d)>>56; } while(0)
|
||||
#endif /* HAVE_FAST_UNALIGNED */
|
||||
|
||||
#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[2])
|
||||
#define AV_WB24(p, d) do { \
|
||||
((uint8_t*)(p))[2] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[0] = (d)>>16; } while(0)
|
||||
|
||||
#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#define AV_WL24(p, d) do { \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; } while(0)
|
||||
|
||||
#endif /* FFMPEG_INTREADWRITE_H */
|
64
src/add-ons/media/plugins/avcodec/libavutil/lfg.c
Normal file
64
src/add-ons/media/plugins/avcodec/libavutil/lfg.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Lagged Fibonacci PRNG
|
||||
* Copyright (c) 2008 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 <inttypes.h>
|
||||
#include "lfg.h"
|
||||
#include "md5.h"
|
||||
#include "intreadwrite.h"
|
||||
|
||||
void av_cold av_lfg_init(AVLFG *c, unsigned int seed){
|
||||
uint8_t tmp[16]={0};
|
||||
int i;
|
||||
|
||||
for(i=8; i<64; i+=4){
|
||||
AV_WL32(tmp, seed); tmp[4]=i;
|
||||
av_md5_sum(tmp, tmp, 16);
|
||||
c->state[i ]= AV_RL32(tmp);
|
||||
c->state[i+1]= AV_RL32(tmp+4);
|
||||
c->state[i+2]= AV_RL32(tmp+8);
|
||||
c->state[i+3]= AV_RL32(tmp+12);
|
||||
}
|
||||
c->index=0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x=0;
|
||||
int i, j;
|
||||
AVLFG state;
|
||||
|
||||
av_lfg_init(&state, 0xdeadbeef);
|
||||
for (j = 0; j < 10000; j++) {
|
||||
START_TIMER
|
||||
for (i = 0; i < 624; i++) {
|
||||
// av_log(NULL,AV_LOG_ERROR, "%X\n", av_lfg_get(&state));
|
||||
x+=av_lfg_get(&state);
|
||||
}
|
||||
STOP_TIMER("624 calls of av_random");
|
||||
}
|
||||
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
54
src/add-ons/media/plugins/avcodec/libavutil/lfg.h
Normal file
54
src/add-ons/media/plugins/avcodec/libavutil/lfg.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Lagged Fibonacci PRNG
|
||||
* Copyright (c) 2008 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LFG_H
|
||||
#define FFMPEG_LFG_H
|
||||
|
||||
typedef struct {
|
||||
unsigned int state[64];
|
||||
int index;
|
||||
} AVLFG;
|
||||
|
||||
void av_lfg_init(AVLFG *c, unsigned int seed);
|
||||
|
||||
/**
|
||||
* Gets the next random unsigned 32bit number using a ALFG.
|
||||
*
|
||||
* Please also consider a simple LCG like state= state*1664525+1013904223,
|
||||
* it may be good enough and faster for your specific use case.
|
||||
*/
|
||||
static inline unsigned int av_lfg_get(AVLFG *c){
|
||||
c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
|
||||
return c->state[c->index++ & 63];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next random unsigned 32bit number using a MLFG.
|
||||
*
|
||||
* Please also consider the av_lfg_get() above, it is faster.
|
||||
*/
|
||||
static inline unsigned int av_mlfg_get(AVLFG *c){
|
||||
unsigned int a= c->state[(c->index-55) & 63];
|
||||
unsigned int b= c->state[(c->index-24) & 63];
|
||||
return c->state[c->index++ & 63] = 2*a*b+a+b;
|
||||
}
|
||||
|
||||
#endif //FFMPEG_LFG_H
|
147
src/add-ons/media/plugins/avcodec/libavutil/lls.c
Normal file
147
src/add-ons/media/plugins/avcodec/libavutil/lls.c
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* linear least squares model
|
||||
*
|
||||
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lls.c
|
||||
* linear least squares model
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lls.h"
|
||||
|
||||
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]= (void*)&m->covariance[1][0];
|
||||
double (*covar )[MAX_VARS+1]= (void*)&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(void){
|
||||
LLSModel m;
|
||||
int i, order;
|
||||
|
||||
av_init_lls(&m, 3);
|
||||
|
||||
for(i=0; i<100; i++){
|
||||
double var[4];
|
||||
double eval;
|
||||
#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);
|
||||
printf("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
|
45
src/add-ons/media/plugins/avcodec/libavutil/lls.h
Normal file
45
src/add-ons/media/plugins/avcodec/libavutil/lls.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* linear least squares model
|
||||
*
|
||||
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LLS_H
|
||||
#define FFMPEG_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 /* FFMPEG_LLS_H */
|
75
src/add-ons/media/plugins/avcodec/libavutil/log.c
Normal file
75
src/add-ons/media/plugins/avcodec/libavutil/log.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* log functions
|
||||
* Copyright (c) 2003 Michel Bardiaux
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file log.c
|
||||
* log.
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
|
||||
int av_log_level = AV_LOG_INFO;
|
||||
|
||||
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), ptr);
|
||||
}
|
||||
|
||||
print_prefix= strstr(fmt, "\n") != NULL;
|
||||
|
||||
vfprintf(stderr, fmt, vl);
|
||||
}
|
||||
|
||||
static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
129
src/add-ons/media/plugins/avcodec/libavutil/log.h
Normal file
129
src/add-ons/media/plugins/avcodec/libavutil/log.h
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LOG_H
|
||||
#define FFMPEG_LOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
* Describes the class of an AVClass context structure, that is an
|
||||
* arbitrary struct of which the first field is a pointer to an
|
||||
* AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
|
||||
*/
|
||||
typedef struct AVCLASS AVClass;
|
||||
struct AVCLASS {
|
||||
/**
|
||||
* The name of the class; usually it is the same name as the
|
||||
* context structure type to which the AVClass is associated.
|
||||
*/
|
||||
const char* class_name;
|
||||
|
||||
/**
|
||||
* a pointer to a function which returns the name of a context
|
||||
* instance \p ctx associated with the class
|
||||
*/
|
||||
const char* (*item_name)(void* ctx);
|
||||
|
||||
/**
|
||||
* a pointer to the first option specified in the class if any or NULL
|
||||
*
|
||||
* @see av_set_default_options()
|
||||
*/
|
||||
const struct AVOption *option;
|
||||
};
|
||||
|
||||
/* av_log API */
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT < (50<<16)
|
||||
#define AV_LOG_QUIET -1
|
||||
#define AV_LOG_FATAL 0
|
||||
#define AV_LOG_ERROR 0
|
||||
#define AV_LOG_WARNING 1
|
||||
#define AV_LOG_INFO 1
|
||||
#define AV_LOG_VERBOSE 1
|
||||
#define AV_LOG_DEBUG 2
|
||||
#else
|
||||
#define AV_LOG_QUIET -8
|
||||
|
||||
/**
|
||||
* something went really wrong and we will crash now
|
||||
*/
|
||||
#define AV_LOG_PANIC 0
|
||||
|
||||
/**
|
||||
* something went wrong and recovery is not possible
|
||||
* like no header in a format which depends on it or a combination
|
||||
* of parameters which are not allowed
|
||||
*/
|
||||
#define AV_LOG_FATAL 8
|
||||
|
||||
/**
|
||||
* something went wrong and cannot losslessly be recovered
|
||||
* but not all future data is affected
|
||||
*/
|
||||
#define AV_LOG_ERROR 16
|
||||
|
||||
/**
|
||||
* something somehow does not look correct / something which may or may not
|
||||
* lead to some problems like use of -vstrict -2
|
||||
*/
|
||||
#define AV_LOG_WARNING 24
|
||||
|
||||
#define AV_LOG_INFO 32
|
||||
#define AV_LOG_VERBOSE 40
|
||||
|
||||
/**
|
||||
* stuff which is only useful for libav* developers
|
||||
*/
|
||||
#define AV_LOG_DEBUG 48
|
||||
#endif
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT < (50<<16)
|
||||
extern int av_log_level;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Send the specified message to the log if the level is less than or equal to
|
||||
* the current av_log_level. By default, all logging messages are sent to
|
||||
* stderr. This behavior can be altered by setting a different av_vlog callback
|
||||
* function.
|
||||
*
|
||||
* @param avcl A pointer to an arbitrary struct of which the first field is a
|
||||
* pointer to an AVClass struct.
|
||||
* @param level The importance level of the message, lower values signifying
|
||||
* higher importance.
|
||||
* @param fmt The format string (printf-compatible) that specifies how
|
||||
* subsequent arguments are converted to output.
|
||||
* @see av_vlog
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
#else
|
||||
void av_log(void*, int level, const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
void av_vlog(void*, int level, const char *fmt, va_list);
|
||||
int av_log_get_level(void);
|
||||
void av_log_set_level(int);
|
||||
void av_log_set_callback(void (*)(void*, int, const char*, va_list));
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
|
||||
|
||||
#endif /* FFMPEG_LOG_H */
|
291
src/add-ons/media/plugins/avcodec/libavutil/lzo.c
Normal file
291
src/add-ons/media/plugins/avcodec/libavutil/lzo.c
Normal file
@ -0,0 +1,291 @@
|
||||
/*
|
||||
* LZO 1x decompression
|
||||
* Copyright (c) 2006 Reimar Doeffinger
|
||||
*
|
||||
* 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 "common.h"
|
||||
//! avoid e.g. MPlayers fast_memcpy, it slows things down here
|
||||
#undef memcpy
|
||||
#include <string.h>
|
||||
#include "lzo.h"
|
||||
|
||||
//! define if we may write up to 12 bytes beyond the output buffer
|
||||
#define OUTBUF_PADDED 1
|
||||
//! define if we may read up to 8 bytes beyond the input buffer
|
||||
#define INBUF_PADDED 1
|
||||
typedef struct LZOContext {
|
||||
const uint8_t *in, *in_end;
|
||||
uint8_t *out_start, *out, *out_end;
|
||||
int error;
|
||||
} LZOContext;
|
||||
|
||||
/**
|
||||
* \brief read one byte from input buffer, avoiding overrun
|
||||
* \return byte read
|
||||
*/
|
||||
static inline int get_byte(LZOContext *c) {
|
||||
if (c->in < c->in_end)
|
||||
return *c->in++;
|
||||
c->error |= LZO_INPUT_DEPLETED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef INBUF_PADDED
|
||||
#define GETB(c) (*(c).in++)
|
||||
#else
|
||||
#define GETB(c) get_byte(&(c))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief decode a length value in the coding used by lzo
|
||||
* \param x previous byte value
|
||||
* \param mask bits used from x
|
||||
* \return decoded length value
|
||||
*/
|
||||
static inline int get_len(LZOContext *c, int x, int mask) {
|
||||
int cnt = x & mask;
|
||||
if (!cnt) {
|
||||
while (!(x = get_byte(c))) cnt += 255;
|
||||
cnt += mask + x;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
//#define UNALIGNED_LOADSTORE
|
||||
#define BUILTIN_MEMCPY
|
||||
#ifdef UNALIGNED_LOADSTORE
|
||||
#define COPY2(d, s) *(uint16_t *)(d) = *(uint16_t *)(s);
|
||||
#define COPY4(d, s) *(uint32_t *)(d) = *(uint32_t *)(s);
|
||||
#elif defined(BUILTIN_MEMCPY)
|
||||
#define COPY2(d, s) memcpy(d, s, 2);
|
||||
#define COPY4(d, s) memcpy(d, s, 4);
|
||||
#else
|
||||
#define COPY2(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1];
|
||||
#define COPY4(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief copy bytes from input to output buffer with checking
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*/
|
||||
static inline void copy(LZOContext *c, int cnt) {
|
||||
register const uint8_t *src = c->in;
|
||||
register uint8_t *dst = c->out;
|
||||
if (cnt > c->in_end - src) {
|
||||
cnt = FFMAX(c->in_end - src, 0);
|
||||
c->error |= LZO_INPUT_DEPLETED;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
}
|
||||
#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
|
||||
COPY4(dst, src);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
if (cnt > 0)
|
||||
#endif
|
||||
memcpy(dst, src, cnt);
|
||||
c->in = src + cnt;
|
||||
c->out = dst + cnt;
|
||||
}
|
||||
|
||||
static inline void memcpy_backptr(uint8_t *dst, int back, int cnt);
|
||||
|
||||
/**
|
||||
* \brief copy previously decoded bytes to current position
|
||||
* \param back how many bytes back we start
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*
|
||||
* cnt > back is valid, this will copy the bytes we just copied,
|
||||
* thus creating a repeating pattern with a period length of back.
|
||||
*/
|
||||
static inline void copy_backptr(LZOContext *c, int back, int cnt) {
|
||||
register const uint8_t *src = &c->out[-back];
|
||||
register uint8_t *dst = c->out;
|
||||
if (src < c->out_start || src > dst) {
|
||||
c->error |= LZO_INVALID_BACKPTR;
|
||||
return;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
}
|
||||
memcpy_backptr(dst, back, cnt);
|
||||
c->out = dst + cnt;
|
||||
}
|
||||
|
||||
static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) {
|
||||
const uint8_t *src = &dst[-back];
|
||||
if (back == 1) {
|
||||
memset(dst, *src, cnt);
|
||||
} else {
|
||||
#ifdef OUTBUF_PADDED
|
||||
COPY2(dst, src);
|
||||
COPY2(dst + 2, src + 2);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
if (cnt > 0) {
|
||||
COPY2(dst, src);
|
||||
COPY2(dst + 2, src + 2);
|
||||
COPY2(dst + 4, src + 4);
|
||||
COPY2(dst + 6, src + 6);
|
||||
src += 8;
|
||||
dst += 8;
|
||||
cnt -= 8;
|
||||
}
|
||||
#endif
|
||||
if (cnt > 0) {
|
||||
int blocklen = back;
|
||||
while (cnt > blocklen) {
|
||||
memcpy(dst, src, blocklen);
|
||||
dst += blocklen;
|
||||
cnt -= blocklen;
|
||||
blocklen <<= 1;
|
||||
}
|
||||
memcpy(dst, src, cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief deliberately overlapping memcpy implementation
|
||||
* \param dst destination buffer; must be padded with 12 additional bytes
|
||||
* \param back how many bytes back we start (the initial size of the overlapping window)
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*
|
||||
* cnt > back is valid, this will copy the bytes we just copied,
|
||||
* thus creating a repeating pattern with a period length of back.
|
||||
*/
|
||||
void av_memcpy_backptr(uint8_t *dst, int back, int cnt) {
|
||||
memcpy_backptr(dst, back, cnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief decode LZO 1x compressed data
|
||||
* \param out output buffer
|
||||
* \param outlen size of output buffer, number of bytes left are returned here
|
||||
* \param in input buffer
|
||||
* \param inlen size of input buffer, number of bytes left are returned here
|
||||
* \return 0 on success, otherwise error flags, see lzo.h
|
||||
*
|
||||
* make sure all buffers are appropriately padded, in must provide
|
||||
* LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
|
||||
*/
|
||||
int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
||||
int state= 0;
|
||||
int x;
|
||||
LZOContext c;
|
||||
c.in = in;
|
||||
c.in_end = (const uint8_t *)in + *inlen;
|
||||
c.out = c.out_start = out;
|
||||
c.out_end = (uint8_t *)out + * outlen;
|
||||
c.error = 0;
|
||||
x = GETB(c);
|
||||
if (x > 17) {
|
||||
copy(&c, x - 17);
|
||||
x = GETB(c);
|
||||
if (x < 16) c.error |= LZO_ERROR;
|
||||
}
|
||||
if (c.in > c.in_end)
|
||||
c.error |= LZO_INPUT_DEPLETED;
|
||||
while (!c.error) {
|
||||
int cnt, back;
|
||||
if (x > 15) {
|
||||
if (x > 63) {
|
||||
cnt = (x >> 5) - 1;
|
||||
back = (GETB(c) << 3) + ((x >> 2) & 7) + 1;
|
||||
} else if (x > 31) {
|
||||
cnt = get_len(&c, x, 31);
|
||||
x = GETB(c);
|
||||
back = (GETB(c) << 6) + (x >> 2) + 1;
|
||||
} else {
|
||||
cnt = get_len(&c, x, 7);
|
||||
back = (1 << 14) + ((x & 8) << 11);
|
||||
x = GETB(c);
|
||||
back += (GETB(c) << 6) + (x >> 2);
|
||||
if (back == (1 << 14)) {
|
||||
if (cnt != 1)
|
||||
c.error |= LZO_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if(!state){
|
||||
cnt = get_len(&c, x, 15);
|
||||
copy(&c, cnt + 3);
|
||||
x = GETB(c);
|
||||
if (x > 15)
|
||||
continue;
|
||||
cnt = 1;
|
||||
back = (1 << 11) + (GETB(c) << 2) + (x >> 2) + 1;
|
||||
} else {
|
||||
cnt = 0;
|
||||
back = (GETB(c) << 2) + (x >> 2) + 1;
|
||||
}
|
||||
copy_backptr(&c, back, cnt + 2);
|
||||
state=
|
||||
cnt = x & 3;
|
||||
copy(&c, cnt);
|
||||
x = GETB(c);
|
||||
}
|
||||
*inlen = c.in_end - c.in;
|
||||
if (c.in > c.in_end)
|
||||
*inlen = 0;
|
||||
*outlen = c.out_end - c.out;
|
||||
return c.error;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
#include <lzo/lzo1x.h>
|
||||
#include "log.h"
|
||||
#define MAXSZ (10*1024*1024)
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *in = fopen(argv[1], "rb");
|
||||
uint8_t *orig = av_malloc(MAXSZ + 16);
|
||||
uint8_t *comp = av_malloc(2*MAXSZ + 16);
|
||||
uint8_t *decomp = av_malloc(MAXSZ + 16);
|
||||
size_t s = fread(orig, 1, MAXSZ, in);
|
||||
lzo_uint clen = 0;
|
||||
long tmp[LZO1X_MEM_COMPRESS];
|
||||
int inlen, outlen;
|
||||
int i;
|
||||
av_log_level = AV_LOG_DEBUG;
|
||||
lzo1x_999_compress(orig, s, comp, &clen, tmp);
|
||||
for (i = 0; i < 300; i++) {
|
||||
START_TIMER
|
||||
inlen = clen; outlen = MAXSZ;
|
||||
#ifdef LIBLZO
|
||||
if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL))
|
||||
#elif defined(LIBLZO_UNSAFE)
|
||||
if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
|
||||
#else
|
||||
if (lzo1x_decode(decomp, &outlen, comp, &inlen))
|
||||
#endif
|
||||
av_log(NULL, AV_LOG_ERROR, "decompression error\n");
|
||||
STOP_TIMER("lzod")
|
||||
}
|
||||
if (memcmp(orig, decomp, s))
|
||||
av_log(NULL, AV_LOG_ERROR, "decompression incorrect\n");
|
||||
else
|
||||
av_log(NULL, AV_LOG_ERROR, "decompression ok\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
39
src/add-ons/media/plugins/avcodec/libavutil/lzo.h
Normal file
39
src/add-ons/media/plugins/avcodec/libavutil/lzo.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* LZO 1x decompression
|
||||
* copyright (c) 2006 Reimar Doeffinger
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LZO_H
|
||||
#define FFMPEG_LZO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define LZO_INPUT_DEPLETED 1
|
||||
#define LZO_OUTPUT_FULL 2
|
||||
#define LZO_INVALID_BACKPTR 4
|
||||
#define LZO_ERROR 8
|
||||
|
||||
#define LZO_INPUT_PADDING 8
|
||||
#define LZO_OUTPUT_PADDING 12
|
||||
|
||||
int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
|
||||
|
||||
void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
|
||||
|
||||
#endif /* FFMPEG_LZO_H */
|
145
src/add-ons/media/plugins/avcodec/libavutil/mathematics.c
Normal file
145
src/add-ons/media/plugins/avcodec/libavutil/mathematics.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mathematics.c
|
||||
* Miscellaneous math routines and tables.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "mathematics.h"
|
||||
|
||||
const uint8_t ff_sqrt_tab[256]={
|
||||
0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90,
|
||||
91, 92, 94, 95, 96, 98, 99,100,102,103,104,105,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,151,152,153,154,155,156,156,
|
||||
157,158,159,160,160,161,162,163,164,164,165,166,167,168,168,169,170,171,171,172,173,174,174,175,176,176,177,178,179,179,180,181,
|
||||
182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202,202,
|
||||
203,204,204,205,205,206,207,207,208,208,209,210,210,211,212,212,213,213,214,215,215,216,216,217,218,218,219,219,220,220,221,222,
|
||||
222,223,223,224,224,225,226,226,227,227,228,228,229,230,230,231,231,232,232,233,233,234,235,235,236,236,237,237,238,238,239,239,
|
||||
240,240,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,255
|
||||
};
|
||||
|
||||
const uint8_t ff_log2_tab[256]={
|
||||
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
int64_t ff_gcd(int64_t a, int64_t b){
|
||||
if(b) return ff_gcd(b, a%b);
|
||||
else return a;
|
||||
}
|
||||
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
|
||||
int64_t r=0;
|
||||
assert(c > 0);
|
||||
assert(b >=0);
|
||||
assert(rnd >=0 && rnd<=5 && rnd!=4);
|
||||
|
||||
if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
|
||||
|
||||
if(rnd==AV_ROUND_NEAR_INF) r= c/2;
|
||||
else if(rnd&1) r= c-1;
|
||||
|
||||
if(b<=INT_MAX && c<=INT_MAX){
|
||||
if(a<=INT_MAX)
|
||||
return (a * b + r)/c;
|
||||
else
|
||||
return a/c*b + (a%c*b + r)/c;
|
||||
}else{
|
||||
#if 1
|
||||
uint64_t a0= a&0xFFFFFFFF;
|
||||
uint64_t a1= a>>32;
|
||||
uint64_t b0= b&0xFFFFFFFF;
|
||||
uint64_t b1= b>>32;
|
||||
uint64_t t1= a0*b1 + a1*b0;
|
||||
uint64_t t1a= t1<<32;
|
||||
int i;
|
||||
|
||||
a0 = a0*b0 + t1a;
|
||||
a1 = a1*b1 + (t1>>32) + (a0<t1a);
|
||||
a0 += r;
|
||||
a1 += a0<r;
|
||||
|
||||
for(i=63; i>=0; i--){
|
||||
// int o= a1 & 0x8000000000000000ULL;
|
||||
a1+= a1 + ((a0>>i)&1);
|
||||
t1+=t1;
|
||||
if(/*o || */c <= a1){
|
||||
a1 -= c;
|
||||
t1++;
|
||||
}
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
#else
|
||||
AVInteger ai;
|
||||
ai= av_mul_i(av_int2i(a), av_int2i(b));
|
||||
ai= av_add_i(ai, av_int2i(r));
|
||||
|
||||
return av_i2int(av_div_i(ai, av_int2i(c)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
||||
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
|
||||
}
|
||||
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
|
||||
int64_t b= bq.num * (int64_t)cq.den;
|
||||
int64_t c= cq.num * (int64_t)bq.den;
|
||||
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "integer.h"
|
||||
#undef printf
|
||||
int main(void){
|
||||
int64_t a,b,c,d,e;
|
||||
|
||||
for(a=7; a<(1LL<<62); a+=a/3+1){
|
||||
for(b=3; b<(1LL<<62); b+=b/4+1){
|
||||
for(c=9; c<(1LL<<62); c+=(c*2)/5+3){
|
||||
int64_t r= c/2;
|
||||
AVInteger ai;
|
||||
ai= av_mul_i(av_int2i(a), av_int2i(b));
|
||||
ai= av_add_i(ai, av_int2i(r));
|
||||
|
||||
d= av_i2int(av_div_i(ai, av_int2i(c)));
|
||||
|
||||
e= av_rescale(a,b,c);
|
||||
|
||||
if((double)a * (double)b / (double)c > (1LL<<63))
|
||||
continue;
|
||||
|
||||
if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId64"\n", a, b, c, d, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
69
src/add-ons/media/plugins/avcodec/libavutil/mathematics.h
Normal file
69
src/add-ons/media/plugins/avcodec/libavutil/mathematics.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MATHEMATICS_H
|
||||
#define FFMPEG_MATHEMATICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "rational.h"
|
||||
|
||||
#ifndef M_E
|
||||
#define M_E 2.7182818284590452354 /* e */
|
||||
#endif
|
||||
#ifndef M_LN2
|
||||
#define M_LN2 0.69314718055994530942 /* log_e 2 */
|
||||
#endif
|
||||
#ifndef M_LN10
|
||||
#define M_LN10 2.30258509299404568402 /* log_e 10 */
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#endif
|
||||
#ifndef M_SQRT1_2
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
#endif
|
||||
|
||||
enum AVRounding {
|
||||
AV_ROUND_ZERO = 0, ///< round toward zero
|
||||
AV_ROUND_INF = 1, ///< round away from zero
|
||||
AV_ROUND_DOWN = 2, ///< round toward -infinity
|
||||
AV_ROUND_UP = 3, ///< round toward +infinity
|
||||
AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero
|
||||
};
|
||||
|
||||
/**
|
||||
* rescale a 64bit integer with rounding to nearest.
|
||||
* a simple a*b/c isn't possible as it can overflow
|
||||
*/
|
||||
int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const;
|
||||
|
||||
/**
|
||||
* rescale a 64bit integer with specified rounding.
|
||||
* a simple a*b/c isn't possible as it can overflow
|
||||
*/
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
|
||||
|
||||
/**
|
||||
* rescale a 64bit integer by 2 rational numbers.
|
||||
*/
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
|
||||
|
||||
#endif /* FFMPEG_MATHEMATICS_H */
|
182
src/add-ons/media/plugins/avcodec/libavutil/md5.c
Normal file
182
src/add-ons/media/plugins/avcodec/libavutil/md5.c
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at)
|
||||
* Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org)
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include <string.h>
|
||||
#include "md5.h"
|
||||
|
||||
typedef struct AVMD5{
|
||||
uint64_t len;
|
||||
uint8_t block[64];
|
||||
uint32_t ABCD[4];
|
||||
} 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] = { // T[i]= fabs(sin(i+1)<<32)
|
||||
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];\
|
||||
\
|
||||
if(i<32){\
|
||||
if(i<16) a += (d ^ (b&(c^d))) + X[ i &15 ];\
|
||||
else a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ];\
|
||||
}else{\
|
||||
if(i<48) a += (b^c^d) + X[ (5+3*i)&15 ];\
|
||||
else a += (c^(b|~d)) + X[ ( 7*i)&15 ];\
|
||||
}\
|
||||
a = b + (( a << t ) | ( a >> (32 - t) ));
|
||||
|
||||
static void body(uint32_t ABCD[4], uint32_t X[16]){
|
||||
|
||||
int t;
|
||||
int i av_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->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, j;
|
||||
|
||||
j= ctx->len & 63;
|
||||
ctx->len += len;
|
||||
|
||||
for( i = 0; i < len; i++ ){
|
||||
ctx->block[j++] = src[i];
|
||||
if( 64 == j ){
|
||||
body(ctx->ABCD, (uint32_t*) ctx->block);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void av_md5_final(AVMD5 *ctx, uint8_t *dst){
|
||||
int i;
|
||||
uint64_t finalcount= le2me_64(ctx->len<<3);
|
||||
|
||||
av_md5_update(ctx, "\200", 1);
|
||||
while((ctx->len & 63)<56)
|
||||
av_md5_update(ctx, "", 1);
|
||||
|
||||
av_md5_update(ctx, (uint8_t*)&finalcount, 8);
|
||||
|
||||
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>
|
||||
#undef printf
|
||||
int main(void){
|
||||
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("%"PRId64"\n", md5val);
|
||||
av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val);
|
||||
av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val);
|
||||
av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val);
|
||||
for(i=0; i<1000; i++) in[i]= i % 127;
|
||||
av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
36
src/add-ons/media/plugins/avcodec/libavutil/md5.h
Normal file
36
src/add-ons/media/plugins/avcodec/libavutil/md5.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MD5_H
|
||||
#define FFMPEG_MD5_H
|
||||
|
||||
#include <stdint.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 /* FFMPEG_MD5_H */
|
||||
|
151
src/add-ons/media/plugins/avcodec/libavutil/mem.c
Normal file
151
src/add-ons/media/plugins/avcodec/libavutil/mem.c
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* default memory allocator for libavutil
|
||||
* Copyright (c) 2002 Fabrice Bellard.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mem.c
|
||||
* default memory allocator for libavutil.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/* here we can use OS dependent allocation functions */
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
/* you can redefine av_malloc and av_free in your project to use your
|
||||
memory allocator. You do not need to suppress this file because the
|
||||
linker will do it automatically */
|
||||
|
||||
void *av_malloc(unsigned int size)
|
||||
{
|
||||
void *ptr;
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
long diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
ptr = malloc(size+16);
|
||||
if(!ptr)
|
||||
return ptr;
|
||||
diff= ((-(long)ptr - 1)&15) + 1;
|
||||
ptr = (char*)ptr + diff;
|
||||
((char*)ptr)[-1]= diff;
|
||||
#elif defined (HAVE_MEMALIGN)
|
||||
ptr = memalign(16,size);
|
||||
/* Why 64?
|
||||
Indeed, we should align it:
|
||||
on 4 for 386
|
||||
on 16 for 486
|
||||
on 32 for 586, PPro - k6-III
|
||||
on 64 for K7 (maybe for P3 too).
|
||||
Because L1 and L2 caches are aligned on those values.
|
||||
But I don't want to code such logic here!
|
||||
*/
|
||||
/* Why 16?
|
||||
Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
|
||||
it will just trigger an exception and the unaligned load will be done in the
|
||||
exception handler or it will just segfault (SSE2 on P4)
|
||||
Why not larger? Because I did not see a difference in benchmarks ...
|
||||
*/
|
||||
/* benchmarks with p3
|
||||
memalign(64)+1 3071,3051,3032
|
||||
memalign(64)+2 3051,3032,3041
|
||||
memalign(64)+4 2911,2896,2915
|
||||
memalign(64)+8 2545,2554,2550
|
||||
memalign(64)+16 2543,2572,2563
|
||||
memalign(64)+32 2546,2545,2571
|
||||
memalign(64)+64 2570,2533,2558
|
||||
|
||||
btw, malloc seems to do 8 byte alignment by default here
|
||||
*/
|
||||
#else
|
||||
ptr = malloc(size);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *av_realloc(void *ptr, unsigned int size)
|
||||
{
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
int diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
//FIXME this isn't aligned correctly, though it probably isn't needed
|
||||
if(!ptr) return av_malloc(size);
|
||||
diff= ((char*)ptr)[-1];
|
||||
return (char*)realloc((char*)ptr - diff, size + diff) + diff;
|
||||
#else
|
||||
return realloc(ptr, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_free(void *ptr)
|
||||
{
|
||||
/* XXX: this test should not be needed on most libcs */
|
||||
if (ptr)
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
free((char*)ptr - ((char*)ptr)[-1]);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_freep(void *arg)
|
||||
{
|
||||
void **ptr= (void**)arg;
|
||||
av_free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
|
||||
void *av_mallocz(unsigned int size)
|
||||
{
|
||||
void *ptr = av_malloc(size);
|
||||
if (ptr)
|
||||
memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *av_strdup(const char *s)
|
||||
{
|
||||
char *ptr= NULL;
|
||||
if(s){
|
||||
int len = strlen(s) + 1;
|
||||
ptr = av_malloc(len);
|
||||
if (ptr)
|
||||
memcpy(ptr, s, len);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
119
src/add-ons/media/plugins/avcodec/libavutil/mem.h
Normal file
119
src/add-ons/media/plugins/avcodec/libavutil/mem.h
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mem.h
|
||||
* Memory handling functions.
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MEM_H
|
||||
#define FFMPEG_MEM_H
|
||||
|
||||
#ifdef __ICC
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
|
||||
#elif defined(__GNUC__)
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
|
||||
#elif defined(HAVE_INLINE_ASM)
|
||||
#error The asm code needs alignment, but we do not know how to do it for this compiler.
|
||||
#else
|
||||
#define DECLARE_ALIGNED(n,t,v) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#define av_malloc_attrib __attribute__((__malloc__))
|
||||
#else
|
||||
#define av_malloc_attrib
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
|
||||
#define av_alloc_size(n) __attribute__((alloc_size(n)))
|
||||
#else
|
||||
#define av_alloc_size(n)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocate a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU).
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if it cannot allocate
|
||||
* it.
|
||||
* @see av_mallocz()
|
||||
*/
|
||||
void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Allocate or reallocate a block of memory.
|
||||
* If \p ptr is NULL and \p size > 0, allocate a new block. If \p
|
||||
* size is zero, free the memory block pointed by \p ptr.
|
||||
* @param size Size in bytes for the memory block to be allocated or
|
||||
* reallocated.
|
||||
* @param ptr Pointer to a memory block already allocated with
|
||||
* av_malloc(z)() or av_realloc() or NULL.
|
||||
* @return Pointer to a newly reallocated block or NULL if it cannot
|
||||
* reallocate or the function is used to free the memory block.
|
||||
* @see av_fast_realloc()
|
||||
*/
|
||||
void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
|
||||
|
||||
/**
|
||||
* Free a memory block which has been allocated with av_malloc(z)() or
|
||||
* av_realloc().
|
||||
* @param ptr Pointer to the memory block which should be freed.
|
||||
* @note ptr = NULL is explicitly allowed.
|
||||
* @note It is recommended that you use av_freep() instead.
|
||||
* @see av_freep()
|
||||
*/
|
||||
void av_free(void *ptr);
|
||||
|
||||
/**
|
||||
* Allocate a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU) and
|
||||
* set to zeroes all the bytes of the block.
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if it cannot allocate
|
||||
* it.
|
||||
* @see av_malloc()
|
||||
*/
|
||||
void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Duplicate the string \p s.
|
||||
* @param s String to be duplicated.
|
||||
* @return Pointer to a newly allocated string containing a
|
||||
* copy of \p s or NULL if it cannot be allocated.
|
||||
*/
|
||||
char *av_strdup(const char *s) av_malloc_attrib;
|
||||
|
||||
/**
|
||||
* Free a memory block which has been allocated with av_malloc(z)() or
|
||||
* av_realloc() and set to NULL the pointer to it.
|
||||
* @param ptr Pointer to the pointer to the memory block which should
|
||||
* be freed.
|
||||
* @see av_free()
|
||||
*/
|
||||
void av_freep(void *ptr);
|
||||
|
||||
#endif /* FFMPEG_MEM_H */
|
242
src/add-ons/media/plugins/avcodec/libavutil/pca.c
Normal file
242
src/add-ons/media/plugins/avcodec/libavutil/pca.c
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Principal component analysis
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pca.c
|
||||
* Principal component analysis
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "pca.h"
|
||||
|
||||
typedef struct PCA{
|
||||
int count;
|
||||
int n;
|
||||
double *covariance;
|
||||
double *mean;
|
||||
}PCA;
|
||||
|
||||
PCA *ff_pca_init(int n){
|
||||
PCA *pca;
|
||||
if(n<=0)
|
||||
return NULL;
|
||||
|
||||
pca= av_mallocz(sizeof(PCA));
|
||||
pca->n= n;
|
||||
pca->count=0;
|
||||
pca->covariance= av_mallocz(sizeof(double)*n*n);
|
||||
pca->mean= av_mallocz(sizeof(double)*n);
|
||||
|
||||
return pca;
|
||||
}
|
||||
|
||||
void ff_pca_free(PCA *pca){
|
||||
av_freep(&pca->covariance);
|
||||
av_freep(&pca->mean);
|
||||
av_free(pca);
|
||||
}
|
||||
|
||||
void ff_pca_add(PCA *pca, double *v){
|
||||
int i, j;
|
||||
const int n= pca->n;
|
||||
|
||||
for(i=0; i<n; i++){
|
||||
pca->mean[i] += v[i];
|
||||
for(j=i; j<n; j++)
|
||||
pca->covariance[j + i*n] += v[i]*v[j];
|
||||
}
|
||||
pca->count++;
|
||||
}
|
||||
|
||||
int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
|
||||
int i, j, k, pass;
|
||||
const int n= pca->n;
|
||||
double z[n];
|
||||
|
||||
memset(eigenvector, 0, sizeof(double)*n*n);
|
||||
|
||||
for(j=0; j<n; j++){
|
||||
pca->mean[j] /= pca->count;
|
||||
eigenvector[j + j*n] = 1.0;
|
||||
for(i=0; i<=j; i++){
|
||||
pca->covariance[j + i*n] /= pca->count;
|
||||
pca->covariance[j + i*n] -= pca->mean[i] * pca->mean[j];
|
||||
pca->covariance[i + j*n] = pca->covariance[j + i*n];
|
||||
}
|
||||
eigenvalue[j]= pca->covariance[j + j*n];
|
||||
z[j]= 0;
|
||||
}
|
||||
|
||||
for(pass=0; pass < 50; pass++){
|
||||
double sum=0;
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
for(j=i+1; j<n; j++)
|
||||
sum += fabs(pca->covariance[j + i*n]);
|
||||
|
||||
if(sum == 0){
|
||||
for(i=0; i<n; i++){
|
||||
double maxvalue= -1;
|
||||
for(j=i; j<n; j++){
|
||||
if(eigenvalue[j] > maxvalue){
|
||||
maxvalue= eigenvalue[j];
|
||||
k= j;
|
||||
}
|
||||
}
|
||||
eigenvalue[k]= eigenvalue[i];
|
||||
eigenvalue[i]= maxvalue;
|
||||
for(j=0; j<n; j++){
|
||||
double tmp= eigenvector[k + j*n];
|
||||
eigenvector[k + j*n]= eigenvector[i + j*n];
|
||||
eigenvector[i + j*n]= tmp;
|
||||
}
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
|
||||
for(i=0; i<n; i++){
|
||||
for(j=i+1; j<n; j++){
|
||||
double covar= pca->covariance[j + i*n];
|
||||
double t,c,s,tau,theta, h;
|
||||
|
||||
if(pass < 3 && fabs(covar) < sum / (5*n*n)) //FIXME why pass < 3
|
||||
continue;
|
||||
if(fabs(covar) == 0.0) //FIXME shouldnt be needed
|
||||
continue;
|
||||
if(pass >=3 && fabs((eigenvalue[j]+z[j])/covar) > (1LL<<32) && fabs((eigenvalue[i]+z[i])/covar) > (1LL<<32)){
|
||||
pca->covariance[j + i*n]=0.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
h= (eigenvalue[j]+z[j]) - (eigenvalue[i]+z[i]);
|
||||
theta=0.5*h/covar;
|
||||
t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
|
||||
if(theta < 0.0) t = -t;
|
||||
|
||||
c=1.0/sqrt(1+t*t);
|
||||
s=t*c;
|
||||
tau=s/(1.0+c);
|
||||
z[i] -= t*covar;
|
||||
z[j] += t*covar;
|
||||
|
||||
#define ROTATE(a,i,j,k,l) {\
|
||||
double g=a[j + i*n];\
|
||||
double h=a[l + k*n];\
|
||||
a[j + i*n]=g-s*(h+g*tau);\
|
||||
a[l + k*n]=h+s*(g-h*tau); }
|
||||
for(k=0; k<n; k++) {
|
||||
if(k!=i && k!=j){
|
||||
ROTATE(pca->covariance,FFMIN(k,i),FFMAX(k,i),FFMIN(k,j),FFMAX(k,j))
|
||||
}
|
||||
ROTATE(eigenvector,k,i,k,j)
|
||||
}
|
||||
pca->covariance[j + i*n]=0.0;
|
||||
}
|
||||
}
|
||||
for (i=0; i<n; i++) {
|
||||
eigenvalue[i] += z[i];
|
||||
z[i]=0.0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#undef printf
|
||||
#undef random
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(){
|
||||
PCA *pca;
|
||||
int i, j, k;
|
||||
#define LEN 8
|
||||
double eigenvector[LEN*LEN];
|
||||
double eigenvalue[LEN];
|
||||
|
||||
pca= ff_pca_init(LEN);
|
||||
|
||||
for(i=0; i<9000000; i++){
|
||||
double v[2*LEN+100];
|
||||
double sum=0;
|
||||
int pos= random()%LEN;
|
||||
int v2= (random()%101) - 50;
|
||||
v[0]= (random()%101) - 50;
|
||||
for(j=1; j<8; j++){
|
||||
if(j<=pos) v[j]= v[0];
|
||||
else v[j]= v2;
|
||||
sum += v[j];
|
||||
}
|
||||
/* for(j=0; j<LEN; j++){
|
||||
v[j] -= v[pos];
|
||||
}*/
|
||||
// sum += random()%10;
|
||||
/* for(j=0; j<LEN; j++){
|
||||
v[j] -= sum/LEN;
|
||||
}*/
|
||||
// lbt1(v+100,v+100,LEN);
|
||||
ff_pca_add(pca, v);
|
||||
}
|
||||
|
||||
|
||||
ff_pca(pca, eigenvector, eigenvalue);
|
||||
for(i=0; i<LEN; i++){
|
||||
pca->count= 1;
|
||||
pca->mean[i]= 0;
|
||||
|
||||
// (0.5^|x|)^2 = 0.5^2|x| = 0.25^|x|
|
||||
|
||||
|
||||
// pca.covariance[i + i*LEN]= pow(0.5, fabs
|
||||
for(j=i; j<LEN; j++){
|
||||
printf("%f ", pca->covariance[i + j*LEN]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#if 1
|
||||
for(i=0; i<LEN; i++){
|
||||
double v[LEN];
|
||||
double error=0;
|
||||
memset(v, 0, sizeof(v));
|
||||
for(j=0; j<LEN; j++){
|
||||
for(k=0; k<LEN; k++){
|
||||
v[j] += pca->covariance[FFMIN(k,j) + FFMAX(k,j)*LEN] * eigenvector[i + k*LEN];
|
||||
}
|
||||
v[j] /= eigenvalue[i];
|
||||
error += fabs(v[j] - eigenvector[i + j*LEN]);
|
||||
}
|
||||
printf("%f ", error);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
for(i=0; i<LEN; i++){
|
||||
for(j=0; j<LEN; j++){
|
||||
printf("%9.6f ", eigenvector[i + j*LEN]);
|
||||
}
|
||||
printf(" %9.1f %f\n", eigenvalue[i], eigenvalue[i]/eigenvalue[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
35
src/add-ons/media/plugins/avcodec/libavutil/pca.h
Normal file
35
src/add-ons/media/plugins/avcodec/libavutil/pca.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Principal component analysis
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file pca.h
|
||||
* Principal component analysis
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_PCA_H
|
||||
#define FFMPEG_PCA_H
|
||||
|
||||
struct PCA *ff_pca_init(int n);
|
||||
void ff_pca_free(struct PCA *pca);
|
||||
void ff_pca_add(struct PCA *pca, double *v);
|
||||
int ff_pca(struct PCA *pca, double *eigenvector, double *eigenvalue);
|
||||
|
||||
#endif /* FFMPEG_PCA_H */
|
97
src/add-ons/media/plugins/avcodec/libavutil/random.c
Normal file
97
src/add-ons/media/plugins/avcodec/libavutil/random.c
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Mersenne Twister Random Algorithm
|
||||
* Copyright (c) 2006 Ryan Martell.
|
||||
* Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
|
||||
* Takuji Nishimura and Makoto Matsumoto.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
see http://en.wikipedia.org/wiki/Mersenne_twister for an explanation of this algorithm.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "random.h"
|
||||
|
||||
|
||||
/* Period parameters */
|
||||
#define M 397
|
||||
#define A 0x9908b0df /* constant vector a */
|
||||
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffff /* least significant r bits */
|
||||
|
||||
/** initializes mt[AV_RANDOM_N] with a seed */
|
||||
void av_init_random(unsigned int seed, AVRandomState *state)
|
||||
{
|
||||
int index;
|
||||
|
||||
/*
|
||||
This differs from the wikipedia article. Source is from the
|
||||
Makoto Matsumoto and Takuji Nishimura code, with the following comment:
|
||||
*/
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array mt[]. */
|
||||
state->mt[0] = seed & 0xffffffff;
|
||||
for (index = 1; index < AV_RANDOM_N; index++) {
|
||||
unsigned int prev= state->mt[index - 1];
|
||||
state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff;
|
||||
}
|
||||
state->index= index; // will cause it to generate untempered numbers the first iteration
|
||||
}
|
||||
|
||||
/** generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't) */
|
||||
void av_random_generate_untempered_numbers(AVRandomState *state)
|
||||
{
|
||||
int kk;
|
||||
unsigned int y;
|
||||
|
||||
for (kk = 0; kk < AV_RANDOM_N - M; kk++) {
|
||||
y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
|
||||
state->mt[kk] = state->mt[kk + M] ^ (y >> 1) ^ ((y&1)*A);
|
||||
}
|
||||
for (; kk < AV_RANDOM_N - 1; kk++) {
|
||||
y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
|
||||
state->mt[kk] = state->mt[kk + (M - AV_RANDOM_N)] ^ (y >> 1) ^ ((y&1)*A);
|
||||
}
|
||||
y = (state->mt[AV_RANDOM_N - 1] & UPPER_MASK) | (state->mt[0] & LOWER_MASK);
|
||||
state->mt[AV_RANDOM_N - 1] = state->mt[M - 1] ^ (y >> 1) ^ ((y&1)*A);
|
||||
state->index = 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
int main(void)
|
||||
{
|
||||
int x=0;
|
||||
int i, j;
|
||||
AVRandomState state;
|
||||
|
||||
av_init_random(0xdeadbeef, &state);
|
||||
for (j = 0; j < 10000; j++) {
|
||||
START_TIMER
|
||||
for (i = 0; i < 624; i++) {
|
||||
x+= av_random(&state);
|
||||
}
|
||||
STOP_TIMER("624 calls of av_random");
|
||||
}
|
||||
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
73
src/add-ons/media/plugins/avcodec/libavutil/random.h
Normal file
73
src/add-ons/media/plugins/avcodec/libavutil/random.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Mersenne Twister Random Algorithm
|
||||
* Copyright (c) 2006 Ryan Martell.
|
||||
* Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
|
||||
* Takuji Nishimura and Makoto Matsumoto.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RANDOM_H
|
||||
#define FFMPEG_RANDOM_H
|
||||
|
||||
#define AV_RANDOM_N 624
|
||||
|
||||
typedef struct {
|
||||
unsigned int mt[AV_RANDOM_N]; ///< the array for the state vector
|
||||
int index; ///< Current untempered value we use as the base.
|
||||
} AVRandomState;
|
||||
|
||||
|
||||
void av_init_random(unsigned int seed, AVRandomState *state); ///< To be inlined, the struct must be visible. So it does not make sense to try and keep it opaque with malloc/free-like calls.
|
||||
void av_random_generate_untempered_numbers(AVRandomState *state); ///< Regenerate the untempered numbers (must be done every 624 iterations, or it will loop).
|
||||
|
||||
/**
|
||||
* Generates a random number from the interval [0,0xffffffff].
|
||||
*
|
||||
* Please do NOT use the Mersenne Twister, it is slow. Use the random generator
|
||||
* from lfg.c/h or a simple LCG like state= state*1664525+1013904223.
|
||||
* If you still choose to use MT, expect that you will have to provide
|
||||
* some evidence that it makes a difference for the case where you use it.
|
||||
*/
|
||||
static inline unsigned int av_random(AVRandomState *state)
|
||||
{
|
||||
unsigned int y;
|
||||
|
||||
// Regenerate the untempered numbers if we should...
|
||||
if (state->index >= AV_RANDOM_N)
|
||||
av_random_generate_untempered_numbers(state);
|
||||
|
||||
// Grab one...
|
||||
y = state->mt[state->index++];
|
||||
|
||||
/* Now temper (Mersenne Twister coefficients). The coefficients for MT19937 are.. */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680;
|
||||
y ^= (y << 15) & 0xefc60000;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
/** Return random in range [0-1] as double. */
|
||||
static inline double av_random_real1(AVRandomState *state)
|
||||
{
|
||||
/* divided by 2^32-1 */
|
||||
return av_random(state) * (1.0 / 4294967296.0);
|
||||
}
|
||||
|
||||
#endif /* FFMPEG_RANDOM_H */
|
103
src/add-ons/media/plugins/avcodec/libavutil/rational.c
Normal file
103
src/add-ons/media/plugins/avcodec/libavutil/rational.c
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Rational numbers
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file rational.c
|
||||
* Rational numbers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
//#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "mathematics.h"
|
||||
#include "rational.h"
|
||||
|
||||
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
||||
AVRational a0={0,1}, a1={1,0};
|
||||
int sign= (nom<0) ^ (den<0);
|
||||
int64_t gcd= ff_gcd(FFABS(nom), FFABS(den));
|
||||
|
||||
if(gcd){
|
||||
nom = FFABS(nom)/gcd;
|
||||
den = FFABS(den)/gcd;
|
||||
}
|
||||
if(nom<=max && den<=max){
|
||||
a1= (AVRational){nom, den};
|
||||
den=0;
|
||||
}
|
||||
|
||||
while(den){
|
||||
uint64_t x = nom / den;
|
||||
int64_t next_den= nom - den*x;
|
||||
int64_t a2n= x*a1.num + a0.num;
|
||||
int64_t a2d= x*a1.den + a0.den;
|
||||
|
||||
if(a2n > max || a2d > max){
|
||||
if(a1.num) x= (max - a0.num) / a1.num;
|
||||
if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den);
|
||||
|
||||
if (den*(2*x*a1.den + a0.den) > nom*a1.den)
|
||||
a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den};
|
||||
break;
|
||||
}
|
||||
|
||||
a0= a1;
|
||||
a1= (AVRational){a2n, a2d};
|
||||
nom= den;
|
||||
den= next_den;
|
||||
}
|
||||
assert(ff_gcd(a1.num, a1.den) <= 1U);
|
||||
|
||||
*dst_nom = sign ? -a1.num : a1.num;
|
||||
*dst_den = a1.den;
|
||||
|
||||
return den==0;
|
||||
}
|
||||
|
||||
AVRational av_mul_q(AVRational b, AVRational c){
|
||||
av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX);
|
||||
return b;
|
||||
}
|
||||
|
||||
AVRational av_div_q(AVRational b, AVRational c){
|
||||
return av_mul_q(b, (AVRational){c.den, c.num});
|
||||
}
|
||||
|
||||
AVRational av_add_q(AVRational b, AVRational c){
|
||||
av_reduce(&b.num, &b.den, b.num * (int64_t)c.den + c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX);
|
||||
return b;
|
||||
}
|
||||
|
||||
AVRational av_sub_q(AVRational b, AVRational c){
|
||||
return av_add_q(b, (AVRational){-c.num, c.den});
|
||||
}
|
||||
|
||||
AVRational av_d2q(double d, int max){
|
||||
AVRational a;
|
||||
#define LOG2 0.69314718055994530941723212145817656807550013436025
|
||||
int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
|
||||
int64_t den= 1LL << (61 - exponent);
|
||||
av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
|
||||
|
||||
return a;
|
||||
}
|
116
src/add-ons/media/plugins/avcodec/libavutil/rational.h
Normal file
116
src/add-ons/media/plugins/avcodec/libavutil/rational.h
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Rational numbers
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file rational.h
|
||||
* Rational numbers.
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RATIONAL_H
|
||||
#define FFMPEG_RATIONAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Rational number num/den.
|
||||
*/
|
||||
typedef struct AVRational{
|
||||
int num; ///< numerator
|
||||
int den; ///< denominator
|
||||
} AVRational;
|
||||
|
||||
/**
|
||||
* Compare two rationals.
|
||||
* @param a first rational
|
||||
* @param b second rational
|
||||
* @return 0 if a==b, 1 if a>b and -1 if a<b.
|
||||
*/
|
||||
static inline int av_cmp_q(AVRational a, AVRational b){
|
||||
const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
|
||||
|
||||
if(tmp) return (tmp>>63)|1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rational to double conversion.
|
||||
* @param a rational to convert
|
||||
* @return (double) a
|
||||
*/
|
||||
static inline double av_q2d(AVRational a){
|
||||
return a.num / (double) a.den;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce a fraction.
|
||||
* This is useful for framerate calculations.
|
||||
* @param dst_nom destination numerator
|
||||
* @param dst_den destination denominator
|
||||
* @param nom source numerator
|
||||
* @param den source denominator
|
||||
* @param max the maximum allowed for dst_nom & dst_den
|
||||
* @return 1 if exact, 0 otherwise
|
||||
*/
|
||||
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
|
||||
|
||||
/**
|
||||
* Multiplies two rationals.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b*c.
|
||||
*/
|
||||
AVRational av_mul_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Divides one rational by another.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b/c.
|
||||
*/
|
||||
AVRational av_div_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Adds two rationals.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b+c.
|
||||
*/
|
||||
AVRational av_add_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Subtracts one rational from another.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b-c.
|
||||
*/
|
||||
AVRational av_sub_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Converts a double precision floating point number to a rational.
|
||||
* @param d double to convert
|
||||
* @param max the maximum allowed numerator and denominator
|
||||
* @return (AVRational) d.
|
||||
*/
|
||||
AVRational av_d2q(double d, int max) av_const;
|
||||
|
||||
#endif /* FFMPEG_RATIONAL_H */
|
48
src/add-ons/media/plugins/avcodec/libavutil/rc4.c
Normal file
48
src/add-ons/media/plugins/avcodec/libavutil/rc4.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* RC4 encryption/decryption/pseudo-random number generator
|
||||
* Copyright (c) 2007 Reimar Doeffinger
|
||||
*
|
||||
* loosely based on LibTomCrypt by Tom St Denis
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "rc4.h"
|
||||
|
||||
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) {
|
||||
int i, j;
|
||||
uint8_t x, y;
|
||||
uint8_t state[256];
|
||||
for (i = 0; i < 256; i++)
|
||||
state[i] = i;
|
||||
y = 0;
|
||||
// j is i % keylen
|
||||
for (j = 0, i = 0; i < 256; i++, j++) {
|
||||
if (j == keylen) j = 0;
|
||||
y += state[i] + key[j];
|
||||
FFSWAP(uint8_t, state[i], state[y]);
|
||||
}
|
||||
// state initialized, now do the real encryption
|
||||
x = 1; y = state[1];
|
||||
while (datalen-- > 0) {
|
||||
uint8_t sum = state[x] + state[y];
|
||||
FFSWAP(uint8_t, state[x], state[y]);
|
||||
*data++ ^= state[sum];
|
||||
x++;
|
||||
y += state[x];
|
||||
}
|
||||
}
|
28
src/add-ons/media/plugins/avcodec/libavutil/rc4.h
Normal file
28
src/add-ons/media/plugins/avcodec/libavutil/rc4.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* RC4 encryption/decryption/pseudo-random number generator
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RC4_H
|
||||
#define FFMPEG_RC4_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen);
|
||||
|
||||
#endif /* FFMPEG_RC4_H */
|
180
src/add-ons/media/plugins/avcodec/libavutil/sha1.c
Normal file
180
src/add-ons/media/plugins/avcodec/libavutil/sha1.c
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
|
||||
* based on public domain SHA-1 code by Steve Reid <steve@edmweb.com>
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "bswap.h"
|
||||
#include "sha1.h"
|
||||
|
||||
typedef struct AVSHA1 {
|
||||
uint64_t count;
|
||||
uint8_t buffer[64];
|
||||
uint32_t state[5];
|
||||
} AVSHA1;
|
||||
|
||||
const int av_sha1_size = sizeof(AVSHA1);
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||
#define blk0(i) (block[i] = be2me_32(((const uint32_t*)buffer)[i]))
|
||||
#define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1))
|
||||
|
||||
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk (i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R2(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
||||
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk (i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
||||
#define R4(v,w,x,y,z,i) z+=( w^x ^y) +blk (i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
|
||||
static void transform(uint32_t state[5], const uint8_t buffer[64]){
|
||||
uint32_t block[80];
|
||||
unsigned int i, a, b, c, d, e;
|
||||
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
#ifdef CONFIG_SMALL
|
||||
for(i=0; i<80; i++){
|
||||
int t;
|
||||
if(i<16) t= be2me_32(((uint32_t*)buffer)[i]);
|
||||
else t= rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1);
|
||||
block[i]= t;
|
||||
t+= e+rol(a,5);
|
||||
if(i<40){
|
||||
if(i<20) t+= ((b&(c^d))^d) +0x5A827999;
|
||||
else t+= ( b^c ^d) +0x6ED9EBA1;
|
||||
}else{
|
||||
if(i<60) t+= (((b|c)&d)|(b&c))+0x8F1BBCDC;
|
||||
else t+= ( b^c ^d) +0xCA62C1D6;
|
||||
}
|
||||
e= d;
|
||||
d= c;
|
||||
c= rol(b,30);
|
||||
b= a;
|
||||
a= t;
|
||||
}
|
||||
#else
|
||||
for(i=0; i<15; i+=5){
|
||||
R0(a,b,c,d,e,0+i); R0(e,a,b,c,d,1+i); R0(d,e,a,b,c,2+i); R0(c,d,e,a,b,3+i); R0(b,c,d,e,a,4+i);
|
||||
}
|
||||
R0(a,b,c,d,e,15); R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
for(i=20; i<40; i+=5){
|
||||
R2(a,b,c,d,e,0+i); R2(e,a,b,c,d,1+i); R2(d,e,a,b,c,2+i); R2(c,d,e,a,b,3+i); R2(b,c,d,e,a,4+i);
|
||||
}
|
||||
for(; i<60; i+=5){
|
||||
R3(a,b,c,d,e,0+i); R3(e,a,b,c,d,1+i); R3(d,e,a,b,c,2+i); R3(c,d,e,a,b,3+i); R3(b,c,d,e,a,4+i);
|
||||
}
|
||||
for(; i<80; i+=5){
|
||||
R4(a,b,c,d,e,0+i); R4(e,a,b,c,d,1+i); R4(d,e,a,b,c,2+i); R4(c,d,e,a,b,3+i); R4(b,c,d,e,a,4+i);
|
||||
}
|
||||
#endif
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
}
|
||||
|
||||
void av_sha1_init(AVSHA1* ctx){
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
ctx->count = 0;
|
||||
}
|
||||
|
||||
void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len){
|
||||
unsigned int i, j;
|
||||
|
||||
j = ctx->count & 63;
|
||||
ctx->count += len;
|
||||
#ifdef CONFIG_SMALL
|
||||
for( i = 0; i < len; i++ ){
|
||||
ctx->buffer[ j++ ] = data[i];
|
||||
if( 64 == j ){
|
||||
transform(ctx->state, ctx->buffer);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((j + len) > 63) {
|
||||
memcpy(&ctx->buffer[j], data, (i = 64-j));
|
||||
transform(ctx->state, ctx->buffer);
|
||||
for ( ; i + 63 < len; i += 64) {
|
||||
transform(ctx->state, &data[i]);
|
||||
}
|
||||
j=0;
|
||||
}
|
||||
else i = 0;
|
||||
memcpy(&ctx->buffer[j], &data[i], len - i);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){
|
||||
int i;
|
||||
uint64_t finalcount= be2me_64(ctx->count<<3);
|
||||
|
||||
av_sha1_update(ctx, "\200", 1);
|
||||
while ((ctx->count & 63) != 56) {
|
||||
av_sha1_update(ctx, "", 1);
|
||||
}
|
||||
av_sha1_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */
|
||||
for(i=0; i<5; i++)
|
||||
((uint32_t*)digest)[i]= be2me_32(ctx->state[i]);
|
||||
}
|
||||
|
||||
// use the following to test
|
||||
// gcc -DTEST -DHAVE_AV_CONFIG_H -I.. sha1.c -O2 -W -Wall -o sha1 && time ./sha1
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
#undef printf
|
||||
|
||||
int main(void){
|
||||
int i, k;
|
||||
AVSHA1 ctx;
|
||||
unsigned char digest[20];
|
||||
|
||||
for(k=0; k<3; k++){
|
||||
av_sha1_init(&ctx);
|
||||
if(k==0)
|
||||
av_sha1_update(&ctx, "abc", 3);
|
||||
else if(k==1)
|
||||
av_sha1_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
|
||||
else
|
||||
for(i=0; i<1000*1000; i++)
|
||||
av_sha1_update(&ctx, "a", 1);
|
||||
av_sha1_final(&ctx, digest);
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%02X", digest[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
//Test Vectors (from FIPS PUB 180-1)
|
||||
printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
|
||||
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
|
||||
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
34
src/add-ons/media/plugins/avcodec/libavutil/sha1.h
Normal file
34
src/add-ons/media/plugins/avcodec/libavutil/sha1.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_SHA1_H
|
||||
#define FFMPEG_SHA1_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern const int av_sha1_size;
|
||||
|
||||
struct AVSHA1;
|
||||
|
||||
void av_sha1_init(struct AVSHA1* context);
|
||||
void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len);
|
||||
void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]);
|
||||
|
||||
#endif /* FFMPEG_SHA1_H */
|
72
src/add-ons/media/plugins/avcodec/libavutil/softfloat.c
Normal file
72
src/add-ons/media/plugins/avcodec/libavutil/softfloat.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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 <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "softfloat.h"
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef printf
|
||||
|
||||
int main(void){
|
||||
SoftFloat one= av_int2sf(1, 0);
|
||||
SoftFloat sf1, sf2;
|
||||
double d1, d2;
|
||||
int i, j;
|
||||
av_log_level = AV_LOG_DEBUG;
|
||||
|
||||
d1= 1;
|
||||
for(i= 0; i<10; i++){
|
||||
d1= 1/(d1+1);
|
||||
}
|
||||
printf("test1 double=%d\n", (int)(d1 * (1<<24)));
|
||||
|
||||
sf1= one;
|
||||
for(i= 0; i<10; i++){
|
||||
sf1= av_div_sf(one, av_normalize_sf(av_add_sf(one, sf1)));
|
||||
}
|
||||
printf("test1 sf =%d\n", av_sf2int(sf1, 24));
|
||||
|
||||
|
||||
for(i= 0; i<100; i++){
|
||||
START_TIMER
|
||||
d1= i;
|
||||
d2= i/100.0;
|
||||
for(j= 0; j<1000; j++){
|
||||
d1= (d1+1)*d2;
|
||||
}
|
||||
STOP_TIMER("float add mul")
|
||||
}
|
||||
printf("test2 double=%d\n", (int)(d1 * (1<<24)));
|
||||
|
||||
for(i= 0; i<100; i++){
|
||||
START_TIMER
|
||||
sf1= av_int2sf(i, 0);
|
||||
sf2= av_div_sf(av_int2sf(i, 2), av_int2sf(200, 3));
|
||||
for(j= 0; j<1000; j++){
|
||||
sf1= av_mul_sf(av_add_sf(sf1, one),sf2);
|
||||
}
|
||||
STOP_TIMER("softfloat add mul")
|
||||
}
|
||||
printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant);
|
||||
return 0;
|
||||
}
|
129
src/add-ons/media/plugins/avcodec/libavutil/softfloat.h
Normal file
129
src/add-ons/media/plugins/avcodec/libavutil/softfloat.h
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_SOFTFLOAT_H
|
||||
#define FFMPEG_SOFTFLOAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#define MIN_EXP -126
|
||||
#define MAX_EXP 126
|
||||
#define ONE_BITS 29
|
||||
|
||||
typedef struct SoftFloat{
|
||||
int32_t exp;
|
||||
int32_t mant;
|
||||
}SoftFloat;
|
||||
|
||||
static av_const SoftFloat av_normalize_sf(SoftFloat a){
|
||||
if(a.mant){
|
||||
#if 1
|
||||
while((a.mant + 0x20000000U)<0x40000000U){
|
||||
a.mant += a.mant;
|
||||
a.exp -= 1;
|
||||
}
|
||||
#else
|
||||
int s=ONE_BITS + 1 - av_log2(a.mant ^ (a.mant<<1));
|
||||
a.exp -= s;
|
||||
a.mant <<= s;
|
||||
#endif
|
||||
if(a.exp < MIN_EXP){
|
||||
a.exp = MIN_EXP;
|
||||
a.mant= 0;
|
||||
}
|
||||
}else{
|
||||
a.exp= MIN_EXP;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
|
||||
#if 1
|
||||
if(a.mant + 0x40000000 < 0){
|
||||
a.exp++;
|
||||
a.mant>>=1;
|
||||
}
|
||||
return a;
|
||||
#elif 1
|
||||
int t= a.mant + 0x40000000 < 0;
|
||||
return (SoftFloat){a.exp+t, a.mant>>t};
|
||||
#else
|
||||
int t= (a.mant + 0x40000000U)>>31;
|
||||
return (SoftFloat){a.exp+t, a.mant>>t};
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return will not be more denormalized then a+b, so if either input is
|
||||
* normalized then the output will not be worse then the other input
|
||||
* if both are normalized then the output will be normalized
|
||||
*/
|
||||
static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
|
||||
a.exp += b.exp;
|
||||
a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
|
||||
return av_normalize1_sf(a);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* b has to be normalized and not zero
|
||||
* @return will not be more denormalized then a
|
||||
*/
|
||||
static av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
|
||||
a.exp -= b.exp+1;
|
||||
a.mant = ((int64_t)a.mant<<(ONE_BITS+1)) / b.mant;
|
||||
return av_normalize1_sf(a);
|
||||
}
|
||||
|
||||
static inline av_const int av_cmp_sf(SoftFloat a, SoftFloat b){
|
||||
int t= a.exp - b.exp;
|
||||
if(t<0) return (a.mant >> (-t)) - b.mant ;
|
||||
else return a.mant - (b.mant >> t);
|
||||
}
|
||||
|
||||
static inline av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
|
||||
int t= a.exp - b.exp;
|
||||
if(t<0) return av_normalize1_sf((SoftFloat){b.exp, b.mant + (a.mant >> (-t))});
|
||||
else return av_normalize1_sf((SoftFloat){a.exp, a.mant + (b.mant >> t )});
|
||||
}
|
||||
|
||||
static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
|
||||
return av_add_sf(a, (SoftFloat){b.exp, -b.mant});
|
||||
}
|
||||
|
||||
//FIXME sqrt, log, exp, pow, sin, cos
|
||||
|
||||
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
|
||||
return av_normalize_sf((SoftFloat){ONE_BITS-frac_bits, v});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rounding is to -inf
|
||||
*/
|
||||
static inline av_const int av_sf2int(SoftFloat v, int frac_bits){
|
||||
v.exp += frac_bits - ONE_BITS;
|
||||
if(v.exp >= 0) return v.mant << v.exp ;
|
||||
else return v.mant >>(-v.exp);
|
||||
}
|
||||
|
||||
#endif /* FFMPEG_SOFTFLOAT_H */
|
78
src/add-ons/media/plugins/avcodec/libavutil/string.c
Normal file
78
src/add-ons/media/plugins/avcodec/libavutil/string.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2007 Mans Rullgard
|
||||
*
|
||||
* 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 <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "avstring.h"
|
||||
|
||||
int av_strstart(const char *str, const char *pfx, const char **ptr)
|
||||
{
|
||||
while (*pfx && *pfx == *str) {
|
||||
pfx++;
|
||||
str++;
|
||||
}
|
||||
if (!*pfx && ptr)
|
||||
*ptr = str;
|
||||
return !*pfx;
|
||||
}
|
||||
|
||||
int av_stristart(const char *str, const char *pfx, const char **ptr)
|
||||
{
|
||||
while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) {
|
||||
pfx++;
|
||||
str++;
|
||||
}
|
||||
if (!*pfx && ptr)
|
||||
*ptr = str;
|
||||
return !*pfx;
|
||||
}
|
||||
|
||||
size_t av_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (++len < size && *src)
|
||||
*dst++ = *src++;
|
||||
if (len <= size)
|
||||
*dst = 0;
|
||||
return len + strlen(src) - 1;
|
||||
}
|
||||
|
||||
size_t av_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t len = strlen(dst);
|
||||
if (size <= len + 1)
|
||||
return len + strlen(src);
|
||||
return len + av_strlcpy(dst + len, src, size - len);
|
||||
}
|
||||
|
||||
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
|
||||
{
|
||||
int len = strlen(dst);
|
||||
va_list vl;
|
||||
|
||||
va_start(vl, fmt);
|
||||
len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);
|
||||
va_end(vl);
|
||||
|
||||
return len;
|
||||
}
|
203
src/add-ons/media/plugins/avcodec/libavutil/tree.c
Normal file
203
src/add-ons/media/plugins/avcodec/libavutil/tree.c
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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 "common.h"
|
||||
#include "log.h"
|
||||
#include "tree.h"
|
||||
|
||||
typedef struct AVTreeNode{
|
||||
struct AVTreeNode *child[2];
|
||||
void *elem;
|
||||
int state;
|
||||
}AVTreeNode;
|
||||
|
||||
const int av_tree_node_size = sizeof(AVTreeNode);
|
||||
|
||||
void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const void *b), void *next[2]){
|
||||
if(t){
|
||||
unsigned int v= cmp(key, t->elem);
|
||||
if(v){
|
||||
if(next) next[v>>31]= t->elem;
|
||||
return av_tree_find(t->child[(v>>31)^1], key, cmp, next);
|
||||
}else{
|
||||
if(next){
|
||||
av_tree_find(t->child[0], key, cmp, next);
|
||||
av_tree_find(t->child[1], key, cmp, next);
|
||||
}
|
||||
return t->elem;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){
|
||||
AVTreeNode *t= *tp;
|
||||
if(t){
|
||||
unsigned int v= cmp(t->elem, key);
|
||||
void *ret;
|
||||
if(!v){
|
||||
if(*next)
|
||||
return t->elem;
|
||||
else if(t->child[0]||t->child[1]){
|
||||
int i= !t->child[0];
|
||||
void *next_elem[2];
|
||||
av_tree_find(t->child[i], key, cmp, next_elem);
|
||||
key= t->elem= next_elem[i];
|
||||
v= -i;
|
||||
}else{
|
||||
*next= t;
|
||||
*tp=NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
ret= av_tree_insert(&t->child[v>>31], key, cmp, next);
|
||||
if(!ret){
|
||||
int i= (v>>31) ^ !!*next;
|
||||
AVTreeNode **child= &t->child[i];
|
||||
t->state += 2*i - 1;
|
||||
|
||||
if(!(t->state&1)){
|
||||
if(t->state){
|
||||
/* The following code is equivalent to
|
||||
if((*child)->state*2 == -t->state)
|
||||
rotate(child, i^1);
|
||||
rotate(tp, i);
|
||||
|
||||
with rotate():
|
||||
static void rotate(AVTreeNode **tp, int i){
|
||||
AVTreeNode *t= *tp;
|
||||
|
||||
*tp= t->child[i];
|
||||
t->child[i]= t->child[i]->child[i^1];
|
||||
(*tp)->child[i^1]= t;
|
||||
i= 4*t->state + 2*(*tp)->state + 12;
|
||||
t ->state= ((0x614586 >> i) & 3)-1;
|
||||
(*tp)->state= ((*tp)->state>>1) + ((0x400EEA >> i) & 3)-1;
|
||||
}
|
||||
but such a rotate function is both bigger and slower
|
||||
*/
|
||||
if((*child)->state*2 == -t->state){
|
||||
*tp= (*child)->child[i^1];
|
||||
(*child)->child[i^1]= (*tp)->child[i];
|
||||
(*tp)->child[i]= *child;
|
||||
*child= (*tp)->child[i^1];
|
||||
(*tp)->child[i^1]= t;
|
||||
|
||||
(*tp)->child[0]->state= -((*tp)->state>0);
|
||||
(*tp)->child[1]->state= (*tp)->state<0 ;
|
||||
(*tp)->state=0;
|
||||
}else{
|
||||
*tp= *child;
|
||||
*child= (*child)->child[i^1];
|
||||
(*tp)->child[i^1]= t;
|
||||
if((*tp)->state) t->state = 0;
|
||||
else t->state>>= 1;
|
||||
(*tp)->state= -t->state;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!(*tp)->state ^ !!*next)
|
||||
return key;
|
||||
}
|
||||
return ret;
|
||||
}else{
|
||||
*tp= *next; *next= NULL;
|
||||
(*tp)->elem= key;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void av_tree_destroy(AVTreeNode *t){
|
||||
av_tree_destroy(t->child[0]);
|
||||
av_tree_destroy(t->child[1]);
|
||||
av_free(t);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void *elem)){
|
||||
int v= f(opaque, t->elem);
|
||||
if(v>=0) av_tree_enumerate(t->child[0], opaque, f);
|
||||
if(v<=0) av_tree_enumerate(t->child[1], opaque, f);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
#undef random
|
||||
static int check(AVTreeNode *t){
|
||||
if(t){
|
||||
int left= check(t->child[0]);
|
||||
int right= check(t->child[1]);
|
||||
|
||||
if(left>999 || right>999)
|
||||
return 1000;
|
||||
if(right - left != t->state)
|
||||
return 1000;
|
||||
if(t->state>1 || t->state<-1)
|
||||
return 1000;
|
||||
return FFMAX(left, right)+1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print(AVTreeNode *t, int depth){
|
||||
int i;
|
||||
for(i=0; i<depth*4; i++) av_log(NULL, AV_LOG_ERROR, " ");
|
||||
if(t){
|
||||
av_log(NULL, AV_LOG_ERROR, "Node %p %2d %4d\n", t, t->state, t->elem);
|
||||
print(t->child[0], depth+1);
|
||||
print(t->child[1], depth+1);
|
||||
}else
|
||||
av_log(NULL, AV_LOG_ERROR, "NULL\n");
|
||||
}
|
||||
|
||||
int cmp(const void *a, const void *b){
|
||||
return a-b;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int i,k;
|
||||
AVTreeNode *root= NULL, *node=NULL;
|
||||
|
||||
for(i=0; i<10000; i++){
|
||||
int j= (random()%86294);
|
||||
if(check(root) > 999){
|
||||
av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
|
||||
print(root, 0);
|
||||
return -1;
|
||||
}
|
||||
av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j);
|
||||
if(!node)
|
||||
node= av_mallocz(av_tree_node_size);
|
||||
av_tree_insert(&root, (void*)(j+1), cmp, &node);
|
||||
|
||||
j= (random()%86294);
|
||||
k= av_tree_find(root, (void*)(j+1), cmp, NULL);
|
||||
if(k){
|
||||
AVTreeNode *node2=NULL;
|
||||
av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j);
|
||||
av_tree_insert(&root, (void*)(j+1), cmp, &node2);
|
||||
k= av_tree_find(root, (void*)(j+1), cmp, NULL);
|
||||
if(k)
|
||||
av_log(NULL, AV_LOG_ERROR, "removial failure %d\n", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
82
src/add-ons/media/plugins/avcodec/libavutil/tree.h
Normal file
82
src/add-ons/media/plugins/avcodec/libavutil/tree.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tree.h
|
||||
* A tree container.
|
||||
* Insertion, Removial, Finding equal, largest which is smaller than and
|
||||
* smallest which is larger than all have O(log n) worst case time.
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_TREE_H
|
||||
#define FFMPEG_TREE_H
|
||||
|
||||
struct AVTreeNode;
|
||||
extern const int av_tree_node_size;
|
||||
|
||||
/**
|
||||
* Finds an element.
|
||||
* @param root a pointer to the root node of the tree
|
||||
* @param next If next is not NULL then next[0] will contain the previous
|
||||
* element and next[1] the next element if either does not exist
|
||||
* then the corresponding entry in next is unchanged.
|
||||
* @return An element with cmp(key, elem)==0 or NULL if no such element exists in
|
||||
* the tree.
|
||||
*/
|
||||
void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *key, const void *b), void *next[2]);
|
||||
|
||||
/**
|
||||
* Inserts or removes an element.
|
||||
* If *next is NULL then the element supplied will be removed, if no such
|
||||
* element exists behavior is undefined.
|
||||
* If *next is not NULL then the element supplied will be inserted, unless
|
||||
* it already exists in the tree.
|
||||
* @param rootp A pointer to a pointer to the root node of the tree. Note that
|
||||
* the root node can change during insertions, this is required
|
||||
* to keep the tree balanced.
|
||||
* @param next Used to allocate and free AVTreeNodes. For insertion the user
|
||||
* must set it to an allocated and zeroed object of at least
|
||||
* av_tree_node_size bytes size. av_tree_insert() will set it to
|
||||
* NULL if it has been consumed.
|
||||
* For deleting elements *next is set to NULL by the user and
|
||||
* av_tree_node_size() will set it to the AVTreeNode which was
|
||||
* used for the removed element.
|
||||
* This allows the use of flat arrays, which have
|
||||
* lower overhead compared to many malloced elements.
|
||||
* You might want to define a function like:
|
||||
* void *tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){
|
||||
* if(!*next) *next= av_mallocz(av_tree_node_size);
|
||||
* return av_tree_insert(rootp, key, cmp, next);
|
||||
* }
|
||||
* void *tree_remove(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b, AVTreeNode **next)){
|
||||
* if(*next) av_freep(next);
|
||||
* return av_tree_insert(rootp, key, cmp, next);
|
||||
* }
|
||||
*
|
||||
* @return If no insertion happened, the found element.
|
||||
* If an insertion or removial happened, then either key or NULL will be returned.
|
||||
* Which one it is depends on the tree state and the implementation. You
|
||||
* should make no assumptions that it's one or the other in the code.
|
||||
*/
|
||||
void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next);
|
||||
void av_tree_destroy(struct AVTreeNode *t);
|
||||
|
||||
#endif /* FFMPEG_TREE_H */
|
29
src/add-ons/media/plugins/avcodec/libavutil/utils.c
Normal file
29
src/add-ons/media/plugins/avcodec/libavutil/utils.c
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 "avutil.h"
|
||||
|
||||
/**
|
||||
* @file libavutil/utils.c
|
||||
* various utility functions
|
||||
*/
|
||||
|
||||
unsigned avutil_version(void)
|
||||
{
|
||||
return LIBAVUTIL_VERSION_INT;
|
||||
}
|
79
src/add-ons/media/plugins/avcodec/libavutil/x86_cpu.h
Normal file
79
src/add-ons/media/plugins/avcodec/libavutil/x86_cpu.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_X86CPU_H
|
||||
#define FFMPEG_X86CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ARCH_X86_64
|
||||
# define REG_a "rax"
|
||||
# define REG_b "rbx"
|
||||
# define REG_c "rcx"
|
||||
# define REG_d "rdx"
|
||||
# define REG_D "rdi"
|
||||
# define REG_S "rsi"
|
||||
# define PTR_SIZE "8"
|
||||
typedef int64_t x86_reg;
|
||||
|
||||
# define REG_SP "rsp"
|
||||
# define REG_BP "rbp"
|
||||
# define REGBP rbp
|
||||
# define REGa rax
|
||||
# define REGb rbx
|
||||
# define REGc rcx
|
||||
# define REGd rdx
|
||||
# define REGSP rsp
|
||||
|
||||
#else
|
||||
|
||||
# define REG_a "eax"
|
||||
# define REG_b "ebx"
|
||||
# define REG_c "ecx"
|
||||
# define REG_d "edx"
|
||||
# define REG_D "edi"
|
||||
# define REG_S "esi"
|
||||
# define PTR_SIZE "4"
|
||||
typedef int32_t x86_reg;
|
||||
|
||||
# define REG_SP "esp"
|
||||
# define REG_BP "ebp"
|
||||
# define REGBP ebp
|
||||
# define REGa eax
|
||||
# define REGb ebx
|
||||
# define REGc ecx
|
||||
# define REGd edx
|
||||
# define REGSP esp
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(HAVE_EBX_AVAILABLE) && defined(HAVE_EBP_AVAILABLE))
|
||||
# define HAVE_7REGS 1
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && (defined(HAVE_EBX_AVAILABLE) || defined(HAVE_EBP_AVAILABLE)))
|
||||
# define HAVE_6REGS 1
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_X86_64) && defined(PIC)
|
||||
# define BROKEN_RELOCATIONS 1
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_X86CPU_H */
|
Loading…
Reference in New Issue
Block a user