Updated FFMPEG to version 1.1.2, using this project: http://sourceforge.net/projects/ffmpeg4android/
This commit is contained in:
136
project/jni/ffmpeg/libavutil/Makefile
Normal file
136
project/jni/ffmpeg/libavutil/Makefile
Normal file
@@ -0,0 +1,136 @@
|
||||
include $(SUBDIR)../config.mak
|
||||
|
||||
NAME = avutil
|
||||
|
||||
HEADERS = adler32.h \
|
||||
aes.h \
|
||||
attributes.h \
|
||||
audio_fifo.h \
|
||||
audioconvert.h \
|
||||
avassert.h \
|
||||
avstring.h \
|
||||
avutil.h \
|
||||
base64.h \
|
||||
blowfish.h \
|
||||
bprint.h \
|
||||
bswap.h \
|
||||
channel_layout.h \
|
||||
common.h \
|
||||
cpu.h \
|
||||
crc.h \
|
||||
error.h \
|
||||
eval.h \
|
||||
fifo.h \
|
||||
file.h \
|
||||
imgutils.h \
|
||||
intfloat.h \
|
||||
intfloat_readwrite.h \
|
||||
intreadwrite.h \
|
||||
lfg.h \
|
||||
log.h \
|
||||
mathematics.h \
|
||||
md5.h \
|
||||
mem.h \
|
||||
dict.h \
|
||||
old_pix_fmts.h \
|
||||
opt.h \
|
||||
parseutils.h \
|
||||
pixdesc.h \
|
||||
pixfmt.h \
|
||||
random_seed.h \
|
||||
rational.h \
|
||||
samplefmt.h \
|
||||
sha.h \
|
||||
time.h \
|
||||
timecode.h \
|
||||
timestamp.h \
|
||||
version.h \
|
||||
xtea.h \
|
||||
|
||||
HEADERS-$(CONFIG_LZO) += lzo.h
|
||||
|
||||
ARCH_HEADERS = bswap.h \
|
||||
intmath.h \
|
||||
intreadwrite.h \
|
||||
timer.h \
|
||||
|
||||
BUILT_HEADERS = avconfig.h
|
||||
|
||||
OBJS = adler32.o \
|
||||
aes.o \
|
||||
audio_fifo.o \
|
||||
avstring.o \
|
||||
base64.o \
|
||||
blowfish.o \
|
||||
bprint.o \
|
||||
channel_layout.o \
|
||||
cpu.o \
|
||||
crc.o \
|
||||
des.o \
|
||||
error.o \
|
||||
eval.o \
|
||||
fifo.o \
|
||||
file.o \
|
||||
float_dsp.o \
|
||||
imgutils.o \
|
||||
intfloat_readwrite.o \
|
||||
intmath.o \
|
||||
lfg.o \
|
||||
lls.o \
|
||||
log.o \
|
||||
log2_tab.o \
|
||||
mathematics.o \
|
||||
md5.o \
|
||||
mem.o \
|
||||
dict.o \
|
||||
opt.o \
|
||||
parseutils.o \
|
||||
pixdesc.o \
|
||||
random_seed.o \
|
||||
rational.o \
|
||||
rc4.o \
|
||||
samplefmt.o \
|
||||
sha.o \
|
||||
time.o \
|
||||
timecode.o \
|
||||
tree.o \
|
||||
utils.o \
|
||||
xga_font_data.o \
|
||||
xtea.o \
|
||||
|
||||
OBJS-$(CONFIG_LZO) += lzo.o
|
||||
|
||||
OBJS += $(COMPAT_OBJS:%=../compat/%)
|
||||
|
||||
SKIPHEADERS = old_pix_fmts.h
|
||||
|
||||
TESTPROGS = adler32 \
|
||||
aes \
|
||||
avstring \
|
||||
base64 \
|
||||
blowfish \
|
||||
bprint \
|
||||
cpu \
|
||||
crc \
|
||||
des \
|
||||
error \
|
||||
eval \
|
||||
file \
|
||||
fifo \
|
||||
lfg \
|
||||
lls \
|
||||
md5 \
|
||||
opt \
|
||||
pca \
|
||||
parseutils \
|
||||
random_seed \
|
||||
rational \
|
||||
sha \
|
||||
tree \
|
||||
xtea \
|
||||
|
||||
TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
|
||||
|
||||
TOOLS = ffeval ffescape
|
||||
|
||||
$(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2
|
||||
136
project/jni/ffmpeg/libavutil/Makefile.android
Normal file
136
project/jni/ffmpeg/libavutil/Makefile.android
Normal file
@@ -0,0 +1,136 @@
|
||||
#include $(SUBDIR)../config.mak
|
||||
|
||||
NAME = avutil
|
||||
|
||||
HEADERS = adler32.h \
|
||||
aes.h \
|
||||
attributes.h \
|
||||
audio_fifo.h \
|
||||
audioconvert.h \
|
||||
avassert.h \
|
||||
avstring.h \
|
||||
avutil.h \
|
||||
base64.h \
|
||||
blowfish.h \
|
||||
bprint.h \
|
||||
bswap.h \
|
||||
channel_layout.h \
|
||||
common.h \
|
||||
cpu.h \
|
||||
crc.h \
|
||||
error.h \
|
||||
eval.h \
|
||||
fifo.h \
|
||||
file.h \
|
||||
imgutils.h \
|
||||
intfloat.h \
|
||||
intfloat_readwrite.h \
|
||||
intreadwrite.h \
|
||||
lfg.h \
|
||||
log.h \
|
||||
mathematics.h \
|
||||
md5.h \
|
||||
mem.h \
|
||||
dict.h \
|
||||
old_pix_fmts.h \
|
||||
opt.h \
|
||||
parseutils.h \
|
||||
pixdesc.h \
|
||||
pixfmt.h \
|
||||
random_seed.h \
|
||||
rational.h \
|
||||
samplefmt.h \
|
||||
sha.h \
|
||||
time.h \
|
||||
timecode.h \
|
||||
timestamp.h \
|
||||
version.h \
|
||||
xtea.h \
|
||||
|
||||
HEADERS-$(CONFIG_LZO) += lzo.h
|
||||
|
||||
ARCH_HEADERS = bswap.h \
|
||||
intmath.h \
|
||||
intreadwrite.h \
|
||||
timer.h \
|
||||
|
||||
BUILT_HEADERS = avconfig.h
|
||||
|
||||
OBJS = adler32.o \
|
||||
aes.o \
|
||||
audio_fifo.o \
|
||||
avstring.o \
|
||||
base64.o \
|
||||
blowfish.o \
|
||||
bprint.o \
|
||||
channel_layout.o \
|
||||
cpu.o \
|
||||
crc.o \
|
||||
des.o \
|
||||
error.o \
|
||||
eval.o \
|
||||
fifo.o \
|
||||
file.o \
|
||||
float_dsp.o \
|
||||
imgutils.o \
|
||||
intfloat_readwrite.o \
|
||||
intmath.o \
|
||||
lfg.o \
|
||||
lls.o \
|
||||
log.o \
|
||||
log2_tab.o \
|
||||
mathematics.o \
|
||||
md5.o \
|
||||
mem.o \
|
||||
dict.o \
|
||||
opt.o \
|
||||
parseutils.o \
|
||||
pixdesc.o \
|
||||
random_seed.o \
|
||||
rational.o \
|
||||
rc4.o \
|
||||
samplefmt.o \
|
||||
sha.o \
|
||||
time.o \
|
||||
timecode.o \
|
||||
tree.o \
|
||||
utils.o \
|
||||
xga_font_data.o \
|
||||
xtea.o \
|
||||
|
||||
OBJS-$(CONFIG_LZO) += lzo.o
|
||||
|
||||
OBJS += $(COMPAT_OBJS:%=../compat/%)
|
||||
|
||||
SKIPHEADERS = old_pix_fmts.h
|
||||
|
||||
TESTPROGS = adler32 \
|
||||
aes \
|
||||
avstring \
|
||||
base64 \
|
||||
blowfish \
|
||||
bprint \
|
||||
cpu \
|
||||
crc \
|
||||
des \
|
||||
error \
|
||||
eval \
|
||||
file \
|
||||
fifo \
|
||||
lfg \
|
||||
lls \
|
||||
md5 \
|
||||
opt \
|
||||
pca \
|
||||
parseutils \
|
||||
random_seed \
|
||||
rational \
|
||||
sha \
|
||||
tree \
|
||||
xtea \
|
||||
|
||||
TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
|
||||
|
||||
TOOLS = ffeval ffescape
|
||||
|
||||
$(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2
|
||||
123
project/jni/ffmpeg/libavutil/adler32.c
Normal file
123
project/jni/ffmpeg/libavutil/adler32.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
#include "adler32.h"
|
||||
#include "common.h"
|
||||
#include "intreadwrite.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) {
|
||||
#if HAVE_FAST_64BIT && HAVE_FAST_UNALIGNED && !CONFIG_SMALL
|
||||
unsigned len2 = FFMIN((len-1) & ~7, 23*8);
|
||||
if (len2) {
|
||||
uint64_t a1= 0;
|
||||
uint64_t a2= 0;
|
||||
uint64_t b1= 0;
|
||||
uint64_t b2= 0;
|
||||
len -= len2;
|
||||
s2 += s1*len2;
|
||||
while (len2 >= 8) {
|
||||
uint64_t v = AV_RN64(buf);
|
||||
a2 += a1;
|
||||
b2 += b1;
|
||||
a1 += v &0x00FF00FF00FF00FF;
|
||||
b1 += (v>>8)&0x00FF00FF00FF00FF;
|
||||
len2 -= 8;
|
||||
buf+=8;
|
||||
}
|
||||
|
||||
//We combine the 8 interleaved adler32 checksums without overflows
|
||||
//Decreasing the number of iterations would allow below code to be
|
||||
//simplified but would likely be slower due to the fewer iterations
|
||||
//of the inner loop
|
||||
s1 += ((a1+b1)*0x1000100010001)>>48;
|
||||
s2 += ((((a2&0xFFFF0000FFFF)+(b2&0xFFFF0000FFFF)+((a2>>16)&0xFFFF0000FFFF)+((b2>>16)&0xFFFF0000FFFF))*0x800000008)>>32)
|
||||
#if HAVE_BIGENDIAN
|
||||
+ 2*((b1*0x1000200030004)>>48)
|
||||
+ ((a1*0x1000100010001)>>48)
|
||||
+ 2*((a1*0x0000100020003)>>48);
|
||||
#else
|
||||
+ 2*((a1*0x4000300020001)>>48)
|
||||
+ ((b1*0x1000100010001)>>48)
|
||||
+ 2*((b1*0x3000200010000)>>48);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
while (len > 4 && s2 < (1U << 31)) {
|
||||
DO4(buf);
|
||||
len -= 4;
|
||||
}
|
||||
#endif
|
||||
DO1(buf); len--;
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
return (s2 << 16) | s1;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
// LCOV_EXCL_START
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "timer.h"
|
||||
#define LEN 7001
|
||||
|
||||
static volatile int checksum;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char data[LEN];
|
||||
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
|
||||
for (i = 0; i < LEN; i++)
|
||||
data[i] = ((i * i) >> 3) + 123 * i;
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-t")) {
|
||||
for (i = 0; i < 1000; i++) {
|
||||
START_TIMER;
|
||||
checksum = av_adler32_update(1, data, LEN);
|
||||
STOP_TIMER("adler");
|
||||
}
|
||||
} else {
|
||||
checksum = av_adler32_update(1, data, LEN);
|
||||
}
|
||||
|
||||
av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum);
|
||||
return checksum == 0x50e6e508 ? 0 : 1;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
#endif
|
||||
43
project/jni/ffmpeg/libavutil/adler32.h
Normal file
43
project/jni/ffmpeg/libavutil/adler32.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 AVUTIL_ADLER32_H
|
||||
#define AVUTIL_ADLER32_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "attributes.h"
|
||||
|
||||
/**
|
||||
* @ingroup lavu_crypto
|
||||
* Calculate the Adler32 checksum of a buffer.
|
||||
*
|
||||
* Passing the return value to a subsequent av_adler32_update() call
|
||||
* allows the checksum of multiple buffers to be calculated as though
|
||||
* they were concatenated.
|
||||
*
|
||||
* @param adler initial checksum value
|
||||
* @param buf pointer to input buffer
|
||||
* @param len size of input buffer
|
||||
* @return updated checksum
|
||||
*/
|
||||
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
|
||||
unsigned int len) av_pure;
|
||||
|
||||
#endif /* AVUTIL_ADLER32_H */
|
||||
341
project/jni/ffmpeg/libavutil/aes.c
Normal file
341
project/jni/ffmpeg/libavutil/aes.c
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "intreadwrite.h"
|
||||
|
||||
typedef union {
|
||||
uint64_t u64[2];
|
||||
uint32_t u32[4];
|
||||
uint8_t u8x4[4][4];
|
||||
uint8_t u8[16];
|
||||
} av_aes_block;
|
||||
|
||||
typedef struct AVAES {
|
||||
// Note: round_key[16] is accessed in the init code, but this only
|
||||
// overwrites state, which does not matter (see also commit ba554c0).
|
||||
av_aes_block round_key[15];
|
||||
av_aes_block state[2];
|
||||
int rounds;
|
||||
} AVAES;
|
||||
|
||||
const int av_aes_size= sizeof(AVAES);
|
||||
|
||||
struct AVAES *av_aes_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct 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];
|
||||
#if 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
|
||||
|
||||
#if HAVE_BIGENDIAN
|
||||
# define ROT(x, s) ((x >> s) | (x << (32-s)))
|
||||
#else
|
||||
# define ROT(x, s) ((x << s) | (x >> (32-s)))
|
||||
#endif
|
||||
|
||||
static inline void addkey(av_aes_block *dst, const av_aes_block *src,
|
||||
const av_aes_block *round_key)
|
||||
{
|
||||
dst->u64[0] = src->u64[0] ^ round_key->u64[0];
|
||||
dst->u64[1] = src->u64[1] ^ round_key->u64[1];
|
||||
}
|
||||
|
||||
static inline void addkey_s(av_aes_block *dst, const uint8_t *src,
|
||||
const av_aes_block *round_key)
|
||||
{
|
||||
dst->u64[0] = AV_RN64(src) ^ round_key->u64[0];
|
||||
dst->u64[1] = AV_RN64(src + 8) ^ round_key->u64[1];
|
||||
}
|
||||
|
||||
static inline void addkey_d(uint8_t *dst, const av_aes_block *src,
|
||||
const av_aes_block *round_key)
|
||||
{
|
||||
AV_WN64(dst, src->u64[0] ^ round_key->u64[0]);
|
||||
AV_WN64(dst + 8, src->u64[1] ^ round_key->u64[1]);
|
||||
}
|
||||
|
||||
static void subshift(av_aes_block s0[2], int s, const uint8_t *box)
|
||||
{
|
||||
av_aes_block *s1 = (av_aes_block *) (s0[0].u8 - s);
|
||||
av_aes_block *s3 = (av_aes_block *) (s0[0].u8 + s);
|
||||
|
||||
s0[0].u8[ 0] = box[s0[1].u8[ 0]];
|
||||
s0[0].u8[ 4] = box[s0[1].u8[ 4]];
|
||||
s0[0].u8[ 8] = box[s0[1].u8[ 8]];
|
||||
s0[0].u8[12] = box[s0[1].u8[12]];
|
||||
s1[0].u8[ 3] = box[s1[1].u8[ 7]];
|
||||
s1[0].u8[ 7] = box[s1[1].u8[11]];
|
||||
s1[0].u8[11] = box[s1[1].u8[15]];
|
||||
s1[0].u8[15] = box[s1[1].u8[ 3]];
|
||||
s0[0].u8[ 2] = box[s0[1].u8[10]];
|
||||
s0[0].u8[10] = box[s0[1].u8[ 2]];
|
||||
s0[0].u8[ 6] = box[s0[1].u8[14]];
|
||||
s0[0].u8[14] = box[s0[1].u8[ 6]];
|
||||
s3[0].u8[ 1] = box[s3[1].u8[13]];
|
||||
s3[0].u8[13] = box[s3[1].u8[ 9]];
|
||||
s3[0].u8[ 9] = box[s3[1].u8[ 5]];
|
||||
s3[0].u8[ 5] = box[s3[1].u8[ 1]];
|
||||
}
|
||||
|
||||
static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
|
||||
#if CONFIG_SMALL
|
||||
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(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
|
||||
uint8_t (*src)[4] = state[1].u8x4;
|
||||
state[0].u32[0] = mix_core(multbl, src[0][0], src[s1 ][1], src[2][2], src[s3 ][3]);
|
||||
state[0].u32[1] = mix_core(multbl, src[1][0], src[s3-1][1], src[3][2], src[s1-1][3]);
|
||||
state[0].u32[2] = mix_core(multbl, src[2][0], src[s3 ][1], src[0][2], src[s1 ][3]);
|
||||
state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
|
||||
}
|
||||
|
||||
static inline void crypt(AVAES *a, int s, const uint8_t *sbox,
|
||||
uint32_t multbl[][256])
|
||||
{
|
||||
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], s, sbox);
|
||||
}
|
||||
|
||||
void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src,
|
||||
int count, uint8_t *iv, int decrypt)
|
||||
{
|
||||
while (count--) {
|
||||
addkey_s(&a->state[1], src, &a->round_key[a->rounds]);
|
||||
if (decrypt) {
|
||||
crypt(a, 0, inv_sbox, dec_multbl);
|
||||
if (iv) {
|
||||
addkey_s(&a->state[0], iv, &a->state[0]);
|
||||
memcpy(iv, src, 16);
|
||||
}
|
||||
addkey_d(dst, &a->state[0], &a->round_key[0]);
|
||||
} else {
|
||||
if (iv)
|
||||
addkey_s(&a->state[1], iv, &a->state[1]);
|
||||
crypt(a, 2, sbox, enc_multbl);
|
||||
addkey_d(dst, &a->state[0], &a->round_key[0]);
|
||||
if (iv)
|
||||
memcpy(iv, dst, 16);
|
||||
}
|
||||
src += 16;
|
||||
dst += 16;
|
||||
}
|
||||
}
|
||||
|
||||
static void init_multbl2(uint32_t tbl[][256], const int c[4],
|
||||
const uint8_t *log8, const uint8_t *alog8,
|
||||
const uint8_t *sbox)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
int x = sbox[i];
|
||||
if (x) {
|
||||
int k, l, m, n;
|
||||
x = log8[x];
|
||||
k = alog8[x + log8[c[0]]];
|
||||
l = alog8[x + log8[c[1]]];
|
||||
m = alog8[x + log8[c[2]]];
|
||||
n = alog8[x + log8[c[3]]];
|
||||
tbl[0][i] = AV_NE(MKBETAG(k,l,m,n), MKTAG(k,l,m,n));
|
||||
#if !CONFIG_SMALL
|
||||
tbl[1][i] = ROT(tbl[0][i], 8);
|
||||
tbl[2][i] = ROT(tbl[0][i], 16);
|
||||
tbl[3][i] = ROT(tbl[0][i], 24);
|
||||
#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[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[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, (const int[4]) { 0xe, 0x9, 0xd, 0xb },
|
||||
log8, alog8, inv_sbox);
|
||||
init_multbl2(enc_multbl, (const 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);
|
||||
memcpy(a->round_key[0].u8, key, KC * 4);
|
||||
|
||||
for (t = KC * 4; t < (rounds + 1) * 16; 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]];
|
||||
}
|
||||
|
||||
memcpy(a->round_key[0].u8 + t, tk, KC * 4);
|
||||
}
|
||||
|
||||
if (decrypt) {
|
||||
for (i = 1; i < rounds; i++) {
|
||||
av_aes_block tmp[3];
|
||||
tmp[2] = a->round_key[i];
|
||||
subshift(&tmp[1], 0, sbox);
|
||||
mix(tmp, dec_multbl, 1, 3);
|
||||
a->round_key[i] = tmp[0];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < (rounds + 1) >> 1; i++) {
|
||||
FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
// LCOV_EXCL_START
|
||||
#include <string.h>
|
||||
#include "lfg.h"
|
||||
#include "log.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
AVAES 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];
|
||||
int err = 0;
|
||||
|
||||
av_log_set_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]);
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-t")) {
|
||||
AVAES ae, ad;
|
||||
AVLFG prng;
|
||||
|
||||
av_aes_init(&ae, "PI=3.141592654..", 128, 0);
|
||||
av_aes_init(&ad, "PI=3.141592654..", 128, 1);
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
for (i = 0; i < 10000; i++) {
|
||||
for (j = 0; j < 16; j++) {
|
||||
pt[j] = av_lfg_get(&prng);
|
||||
}
|
||||
{
|
||||
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 err;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
#endif
|
||||
65
project/jni/ffmpeg/libavutil/aes.h
Normal file
65
project/jni/ffmpeg/libavutil/aes.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 AVUTIL_AES_H
|
||||
#define AVUTIL_AES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @defgroup lavu_aes AES
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const int av_aes_size;
|
||||
|
||||
struct AVAES;
|
||||
|
||||
/**
|
||||
* Allocate an AVAES context.
|
||||
*/
|
||||
struct AVAES *av_aes_alloc(void);
|
||||
|
||||
/**
|
||||
* Initialize 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);
|
||||
|
||||
/**
|
||||
* Encrypt or decrypt a buffer using a previously initialized context.
|
||||
* @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, const uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_AES_H */
|
||||
8
project/jni/ffmpeg/libavutil/arm/Makefile
Normal file
8
project/jni/ffmpeg/libavutil/arm/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
OBJS += arm/cpu.o \
|
||||
arm/float_dsp_init_arm.o \
|
||||
|
||||
VFP-OBJS += arm/float_dsp_init_vfp.o \
|
||||
arm/float_dsp_vfp.o \
|
||||
|
||||
NEON-OBJS += arm/float_dsp_init_neon.o \
|
||||
arm/float_dsp_neon.o \
|
||||
304
project/jni/ffmpeg/libavutil/arm/asm.S
Normal file
304
project/jni/ffmpeg/libavutil/arm/asm.S
Normal file
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Mans Rullgard <mans@mansr.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 "config.h"
|
||||
|
||||
#ifdef __ELF__
|
||||
# define ELF
|
||||
#else
|
||||
# define ELF @
|
||||
#endif
|
||||
|
||||
#if CONFIG_THUMB
|
||||
# define A @
|
||||
# define T
|
||||
#else
|
||||
# define A
|
||||
# define T @
|
||||
#endif
|
||||
|
||||
#if HAVE_NEON
|
||||
.arch armv7-a
|
||||
#elif HAVE_ARMV6T2
|
||||
.arch armv6t2
|
||||
#elif HAVE_ARMV6
|
||||
.arch armv6
|
||||
#elif HAVE_ARMV5TE
|
||||
.arch armv5te
|
||||
#endif
|
||||
|
||||
#if HAVE_NEON
|
||||
.fpu neon
|
||||
#elif HAVE_VFP
|
||||
.fpu vfp
|
||||
#endif
|
||||
|
||||
.syntax unified
|
||||
T .thumb
|
||||
ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
|
||||
|
||||
.macro function name, export=0
|
||||
.set .Lpic_idx, 0
|
||||
.set .Lpic_gp, 0
|
||||
.macro endfunc
|
||||
.if .Lpic_idx
|
||||
.align 2
|
||||
.altmacro
|
||||
put_pic %(.Lpic_idx - 1)
|
||||
.noaltmacro
|
||||
.endif
|
||||
ELF .size \name, . - \name
|
||||
.endfunc
|
||||
.purgem endfunc
|
||||
.endm
|
||||
.text
|
||||
.align 2
|
||||
.if \export
|
||||
.global EXTERN_ASM\name
|
||||
EXTERN_ASM\name:
|
||||
.endif
|
||||
ELF .type \name, %function
|
||||
.func \name
|
||||
\name:
|
||||
.endm
|
||||
|
||||
.macro const name, align=2
|
||||
.macro endconst
|
||||
ELF .size \name, . - \name
|
||||
.purgem endconst
|
||||
.endm
|
||||
.section .rodata
|
||||
.align \align
|
||||
\name:
|
||||
.endm
|
||||
|
||||
#if !HAVE_ARMV6T2_EXTERNAL
|
||||
.macro movw rd, val
|
||||
mov \rd, \val & 255
|
||||
orr \rd, \val & ~255
|
||||
.endm
|
||||
#endif
|
||||
|
||||
.macro mov32 rd, val
|
||||
#if HAVE_ARMV6T2_EXTERNAL
|
||||
movw \rd, #(\val) & 0xffff
|
||||
.if (\val) >> 16
|
||||
movt \rd, #(\val) >> 16
|
||||
.endif
|
||||
#else
|
||||
ldr \rd, =\val
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro put_pic num
|
||||
put_pic_\num
|
||||
.endm
|
||||
|
||||
.macro do_def_pic num, val, label
|
||||
.macro put_pic_\num
|
||||
.if \num
|
||||
.altmacro
|
||||
put_pic %(\num - 1)
|
||||
.noaltmacro
|
||||
.endif
|
||||
\label: .word \val
|
||||
.purgem put_pic_\num
|
||||
.endm
|
||||
.endm
|
||||
|
||||
.macro def_pic val, label
|
||||
.altmacro
|
||||
do_def_pic %.Lpic_idx, \val, \label
|
||||
.noaltmacro
|
||||
.set .Lpic_idx, .Lpic_idx + 1
|
||||
.endm
|
||||
|
||||
.macro ldpic rd, val, indir=0
|
||||
ldr \rd, .Lpicoff\@
|
||||
.Lpic\@:
|
||||
.if \indir
|
||||
A ldr \rd, [pc, \rd]
|
||||
T add \rd, pc
|
||||
T ldr \rd, [\rd]
|
||||
.else
|
||||
add \rd, pc
|
||||
.endif
|
||||
def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
|
||||
.endm
|
||||
|
||||
.macro movrel rd, val
|
||||
#if CONFIG_PIC
|
||||
ldpic \rd, \val
|
||||
#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
|
||||
movw \rd, #:lower16:\val
|
||||
movt \rd, #:upper16:\val
|
||||
#else
|
||||
ldr \rd, =\val
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro movrelx rd, val, gp
|
||||
#if CONFIG_PIC && defined(__ELF__)
|
||||
.ifnb \gp
|
||||
.if .Lpic_gp
|
||||
.unreq gp
|
||||
.endif
|
||||
gp .req \gp
|
||||
ldpic gp, _GLOBAL_OFFSET_TABLE_
|
||||
.elseif !.Lpic_gp
|
||||
gp .req r12
|
||||
ldpic gp, _GLOBAL_OFFSET_TABLE_
|
||||
.endif
|
||||
.set .Lpic_gp, 1
|
||||
ldr \rd, .Lpicoff\@
|
||||
ldr \rd, [gp, \rd]
|
||||
def_pic \val(GOT), .Lpicoff\@
|
||||
#elif CONFIG_PIC && defined(__APPLE__)
|
||||
ldpic \rd, .Lpic\@, indir=1
|
||||
.non_lazy_symbol_pointer
|
||||
.Lpic\@:
|
||||
.indirect_symbol \val
|
||||
.word 0
|
||||
.text
|
||||
#else
|
||||
movrel \rd, \val
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro add_sh rd, rn, rm, sh:vararg
|
||||
A add \rd, \rn, \rm, \sh
|
||||
T mov \rm, \rm, \sh
|
||||
T add \rd, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro ldr_pre rt, rn, rm:vararg
|
||||
A ldr \rt, [\rn, \rm]!
|
||||
T add \rn, \rn, \rm
|
||||
T ldr \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro ldr_dpre rt, rn, rm:vararg
|
||||
A ldr \rt, [\rn, -\rm]!
|
||||
T sub \rn, \rn, \rm
|
||||
T ldr \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro ldr_nreg rt, rn, rm:vararg
|
||||
A ldr \rt, [\rn, -\rm]
|
||||
T sub \rt, \rn, \rm
|
||||
T ldr \rt, [\rt]
|
||||
.endm
|
||||
|
||||
.macro ldr_post rt, rn, rm:vararg
|
||||
A ldr \rt, [\rn], \rm
|
||||
T ldr \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro ldrd_reg rt, rt2, rn, rm
|
||||
A ldrd \rt, \rt2, [\rn, \rm]
|
||||
T add \rt, \rn, \rm
|
||||
T ldrd \rt, \rt2, [\rt]
|
||||
.endm
|
||||
|
||||
.macro ldrd_post rt, rt2, rn, rm
|
||||
A ldrd \rt, \rt2, [\rn], \rm
|
||||
T ldrd \rt, \rt2, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro ldrh_pre rt, rn, rm
|
||||
A ldrh \rt, [\rn, \rm]!
|
||||
T add \rn, \rn, \rm
|
||||
T ldrh \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro ldrh_dpre rt, rn, rm
|
||||
A ldrh \rt, [\rn, -\rm]!
|
||||
T sub \rn, \rn, \rm
|
||||
T ldrh \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro ldrh_post rt, rn, rm
|
||||
A ldrh \rt, [\rn], \rm
|
||||
T ldrh \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro ldrb_post rt, rn, rm
|
||||
A ldrb \rt, [\rn], \rm
|
||||
T ldrb \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro str_post rt, rn, rm:vararg
|
||||
A str \rt, [\rn], \rm
|
||||
T str \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro strb_post rt, rn, rm:vararg
|
||||
A strb \rt, [\rn], \rm
|
||||
T strb \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro strd_post rt, rt2, rn, rm
|
||||
A strd \rt, \rt2, [\rn], \rm
|
||||
T strd \rt, \rt2, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro strh_pre rt, rn, rm
|
||||
A strh \rt, [\rn, \rm]!
|
||||
T add \rn, \rn, \rm
|
||||
T strh \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro strh_dpre rt, rn, rm
|
||||
A strh \rt, [\rn, -\rm]!
|
||||
T sub \rn, \rn, \rm
|
||||
T strh \rt, [\rn]
|
||||
.endm
|
||||
|
||||
.macro strh_post rt, rn, rm
|
||||
A strh \rt, [\rn], \rm
|
||||
T strh \rt, [\rn]
|
||||
T add \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
.macro strh_dpost rt, rn, rm
|
||||
A strh \rt, [\rn], -\rm
|
||||
T strh \rt, [\rn]
|
||||
T sub \rn, \rn, \rm
|
||||
.endm
|
||||
|
||||
#if HAVE_VFP_ARGS
|
||||
.eabi_attribute 28, 1
|
||||
# define VFP
|
||||
# define NOVFP @
|
||||
#else
|
||||
# define VFP @
|
||||
# define NOVFP
|
||||
#endif
|
||||
|
||||
#define GLUE(a, b) a ## b
|
||||
#define JOIN(a, b) GLUE(a, b)
|
||||
#define X(s) JOIN(EXTERN_ASM, s)
|
||||
67
project/jni/ffmpeg/libavutil/arm/bswap.h
Normal file
67
project/jni/ffmpeg/libavutil/arm/bswap.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 AVUTIL_ARM_BSWAP_H
|
||||
#define AVUTIL_ARM_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
|
||||
#ifdef __ARMCC_VERSION
|
||||
|
||||
#if HAVE_ARMV6
|
||||
#define av_bswap32 av_bswap32
|
||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||
{
|
||||
return __rev(x);
|
||||
}
|
||||
#endif /* HAVE_ARMV6 */
|
||||
|
||||
#elif HAVE_INLINE_ASM
|
||||
|
||||
#if HAVE_ARMV6_INLINE
|
||||
#define av_bswap16 av_bswap16
|
||||
static av_always_inline av_const unsigned av_bswap16(unsigned x)
|
||||
{
|
||||
__asm__("rev16 %0, %0" : "+r"(x));
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !AV_GCC_VERSION_AT_LEAST(4,5)
|
||||
#define av_bswap32 av_bswap32
|
||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||
{
|
||||
#if HAVE_ARMV6_INLINE
|
||||
__asm__("rev %0, %0" : "+r"(x));
|
||||
#else
|
||||
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));
|
||||
#endif /* HAVE_ARMV6_INLINE */
|
||||
return x;
|
||||
}
|
||||
#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */
|
||||
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
#endif /* AVUTIL_ARM_BSWAP_H */
|
||||
113
project/jni/ffmpeg/libavutil/arm/cpu.c
Normal file
113
project/jni/ffmpeg/libavutil/arm/cpu.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libavutil/cpu.h"
|
||||
#include "config.h"
|
||||
|
||||
#define CORE_FLAG(f) \
|
||||
(AV_CPU_FLAG_ ## f * (HAVE_ ## f ## _EXTERNAL || HAVE_ ## f ## _INLINE))
|
||||
|
||||
#define CORE_CPU_FLAGS \
|
||||
(CORE_FLAG(ARMV5TE) | \
|
||||
CORE_FLAG(ARMV6) | \
|
||||
CORE_FLAG(ARMV6T2) | \
|
||||
CORE_FLAG(VFP) | \
|
||||
CORE_FLAG(VFPV3) | \
|
||||
CORE_FLAG(NEON))
|
||||
|
||||
#if defined __linux__ || defined __ANDROID__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define AT_HWCAP 16
|
||||
|
||||
/* Relevant HWCAP values from kernel headers */
|
||||
#define HWCAP_VFP (1 << 6)
|
||||
#define HWCAP_EDSP (1 << 7)
|
||||
#define HWCAP_THUMBEE (1 << 11)
|
||||
#define HWCAP_NEON (1 << 12)
|
||||
#define HWCAP_VFPv3 (1 << 13)
|
||||
#define HWCAP_TLS (1 << 15)
|
||||
|
||||
static int get_hwcap(uint32_t *hwcap)
|
||||
{
|
||||
struct { uint32_t a_type; uint32_t a_val; } auxv;
|
||||
FILE *f = fopen("/proc/self/auxv", "r");
|
||||
int err = -1;
|
||||
|
||||
if (!f)
|
||||
return -1;
|
||||
|
||||
while (fread(&auxv, sizeof(auxv), 1, f) > 0) {
|
||||
if (auxv.a_type == AT_HWCAP) {
|
||||
*hwcap = auxv.a_val;
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return err;
|
||||
}
|
||||
|
||||
int ff_get_cpu_flags_arm(void)
|
||||
{
|
||||
int flags = CORE_CPU_FLAGS;
|
||||
uint32_t hwcap;
|
||||
|
||||
if (get_hwcap(&hwcap) < 0)
|
||||
return flags;
|
||||
|
||||
#define check_cap(cap, flag) do { \
|
||||
if (hwcap & HWCAP_ ## cap) \
|
||||
flags |= AV_CPU_FLAG_ ## flag; \
|
||||
} while (0)
|
||||
|
||||
/* No flags explicitly indicate v6 or v6T2 so check others which
|
||||
imply support. */
|
||||
check_cap(EDSP, ARMV5TE);
|
||||
check_cap(TLS, ARMV6);
|
||||
check_cap(THUMBEE, ARMV6T2);
|
||||
check_cap(VFP, VFP);
|
||||
check_cap(VFPv3, VFPV3);
|
||||
check_cap(NEON, NEON);
|
||||
|
||||
/* The v6 checks above are not reliable so let higher flags
|
||||
trickle down. */
|
||||
if (flags & (AV_CPU_FLAG_VFPV3 | AV_CPU_FLAG_NEON))
|
||||
flags |= AV_CPU_FLAG_ARMV6T2;
|
||||
if (flags & AV_CPU_FLAG_ARMV6T2)
|
||||
flags |= AV_CPU_FLAG_ARMV6;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int ff_get_cpu_flags_arm(void)
|
||||
{
|
||||
return AV_CPU_FLAG_ARMV5TE * HAVE_ARMV5TE |
|
||||
AV_CPU_FLAG_ARMV6 * HAVE_ARMV6 |
|
||||
AV_CPU_FLAG_ARMV6T2 * HAVE_ARMV6T2 |
|
||||
AV_CPU_FLAG_VFP * HAVE_VFP |
|
||||
AV_CPU_FLAG_VFPV3 * HAVE_VFPV3 |
|
||||
AV_CPU_FLAG_NEON * HAVE_NEON;
|
||||
}
|
||||
|
||||
#endif
|
||||
32
project/jni/ffmpeg/libavutil/arm/cpu.h
Normal file
32
project/jni/ffmpeg/libavutil/arm/cpu.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_ARM_CPU_H
|
||||
#define AVUTIL_ARM_CPU_H
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/cpu.h"
|
||||
|
||||
#define have_armv5te(flags) (HAVE_ARMV5TE && ((flags) & AV_CPU_FLAG_ARMV5TE))
|
||||
#define have_armv6(flags) (HAVE_ARMV6 && ((flags) & AV_CPU_FLAG_ARMV6))
|
||||
#define have_armv6t2(flags) (HAVE_ARMV6T2 && ((flags) & AV_CPU_FLAG_ARMV6T2))
|
||||
#define have_vfp(flags) (HAVE_VFP && ((flags) & AV_CPU_FLAG_VFP))
|
||||
#define have_vfpv3(flags) (HAVE_VFPV3 && ((flags) & AV_CPU_FLAG_VFPV3))
|
||||
#define have_neon(flags) (HAVE_NEON && ((flags) & AV_CPU_FLAG_NEON))
|
||||
|
||||
#endif
|
||||
29
project/jni/ffmpeg/libavutil/arm/float_dsp_arm.h
Normal file
29
project/jni/ffmpeg/libavutil/arm/float_dsp_arm.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Mans Rullgard <mans@mansr.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 AVUTIL_ARM_FLOAT_DSP_ARM_H
|
||||
#define AVUTIL_ARM_FLOAT_DSP_ARM_H
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
|
||||
void ff_float_dsp_init_vfp (AVFloatDSPContext *fdsp);
|
||||
void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp);
|
||||
|
||||
#endif /* AVUTIL_ARM_FLOAT_DSP_ARM_H */
|
||||
33
project/jni/ffmpeg/libavutil/arm/float_dsp_init_arm.c
Normal file
33
project/jni/ffmpeg/libavutil/arm/float_dsp_init_arm.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ARM optimized DSP utils
|
||||
*
|
||||
* 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 "libavutil/float_dsp.h"
|
||||
#include "cpu.h"
|
||||
#include "float_dsp_arm.h"
|
||||
|
||||
void ff_float_dsp_init_arm(AVFloatDSPContext *fdsp)
|
||||
{
|
||||
int cpu_flags = av_get_cpu_flags();
|
||||
|
||||
if (have_vfp(cpu_flags))
|
||||
ff_float_dsp_init_vfp(fdsp);
|
||||
if (have_neon(cpu_flags))
|
||||
ff_float_dsp_init_neon(fdsp);
|
||||
}
|
||||
40
project/jni/ffmpeg/libavutil/arm/float_dsp_init_neon.c
Normal file
40
project/jni/ffmpeg/libavutil/arm/float_dsp_init_neon.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* ARM NEON optimised Float DSP functions
|
||||
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
|
||||
*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libavutil/float_dsp.h"
|
||||
#include "float_dsp_arm.h"
|
||||
|
||||
void ff_vector_fmul_neon(float *dst, const float *src0, const float *src1, int len);
|
||||
|
||||
void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul,
|
||||
int len);
|
||||
|
||||
void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul,
|
||||
int len);
|
||||
|
||||
void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp)
|
||||
{
|
||||
fdsp->vector_fmul = ff_vector_fmul_neon;
|
||||
fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_neon;
|
||||
fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_neon;
|
||||
}
|
||||
34
project/jni/ffmpeg/libavutil/arm/float_dsp_init_vfp.c
Normal file
34
project/jni/ffmpeg/libavutil/arm/float_dsp_init_vfp.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
|
||||
*
|
||||
* 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 "libavutil/float_dsp.h"
|
||||
#include "cpu.h"
|
||||
#include "float_dsp_arm.h"
|
||||
|
||||
void ff_vector_fmul_vfp(float *dst, const float *src0, const float *src1,
|
||||
int len);
|
||||
|
||||
void ff_float_dsp_init_vfp(AVFloatDSPContext *fdsp)
|
||||
{
|
||||
int cpu_flags = av_get_cpu_flags();
|
||||
|
||||
if (!have_vfpv3(cpu_flags))
|
||||
fdsp->vector_fmul = ff_vector_fmul_vfp;
|
||||
}
|
||||
148
project/jni/ffmpeg/libavutil/arm/float_dsp_neon.S
Normal file
148
project/jni/ffmpeg/libavutil/arm/float_dsp_neon.S
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* ARM NEON optimised Float DSP functions
|
||||
* Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
|
||||
*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "asm.S"
|
||||
|
||||
function ff_vector_fmul_neon, export=1
|
||||
subs r3, r3, #8
|
||||
vld1.32 {d0-d3}, [r1,:128]!
|
||||
vld1.32 {d4-d7}, [r2,:128]!
|
||||
vmul.f32 q8, q0, q2
|
||||
vmul.f32 q9, q1, q3
|
||||
beq 3f
|
||||
bics ip, r3, #15
|
||||
beq 2f
|
||||
1: subs ip, ip, #16
|
||||
vld1.32 {d0-d1}, [r1,:128]!
|
||||
vld1.32 {d4-d5}, [r2,:128]!
|
||||
vmul.f32 q10, q0, q2
|
||||
vld1.32 {d2-d3}, [r1,:128]!
|
||||
vld1.32 {d6-d7}, [r2,:128]!
|
||||
vmul.f32 q11, q1, q3
|
||||
vst1.32 {d16-d19},[r0,:128]!
|
||||
vld1.32 {d0-d1}, [r1,:128]!
|
||||
vld1.32 {d4-d5}, [r2,:128]!
|
||||
vmul.f32 q8, q0, q2
|
||||
vld1.32 {d2-d3}, [r1,:128]!
|
||||
vld1.32 {d6-d7}, [r2,:128]!
|
||||
vmul.f32 q9, q1, q3
|
||||
vst1.32 {d20-d23},[r0,:128]!
|
||||
bne 1b
|
||||
ands r3, r3, #15
|
||||
beq 3f
|
||||
2: vld1.32 {d0-d1}, [r1,:128]!
|
||||
vld1.32 {d4-d5}, [r2,:128]!
|
||||
vst1.32 {d16-d17},[r0,:128]!
|
||||
vmul.f32 q8, q0, q2
|
||||
vld1.32 {d2-d3}, [r1,:128]!
|
||||
vld1.32 {d6-d7}, [r2,:128]!
|
||||
vst1.32 {d18-d19},[r0,:128]!
|
||||
vmul.f32 q9, q1, q3
|
||||
3: vst1.32 {d16-d19},[r0,:128]!
|
||||
bx lr
|
||||
endfunc
|
||||
|
||||
function ff_vector_fmac_scalar_neon, export=1
|
||||
VFP len .req r2
|
||||
VFP acc .req r3
|
||||
NOVFP len .req r3
|
||||
NOVFP acc .req r2
|
||||
VFP vdup.32 q15, d0[0]
|
||||
NOVFP vdup.32 q15, r2
|
||||
bics r12, len, #15
|
||||
mov acc, r0
|
||||
beq 3f
|
||||
vld1.32 {q0}, [r1,:128]!
|
||||
vld1.32 {q8}, [acc,:128]!
|
||||
vld1.32 {q1}, [r1,:128]!
|
||||
vld1.32 {q9}, [acc,:128]!
|
||||
1: vmla.f32 q8, q0, q15
|
||||
vld1.32 {q2}, [r1,:128]!
|
||||
vld1.32 {q10}, [acc,:128]!
|
||||
vmla.f32 q9, q1, q15
|
||||
vld1.32 {q3}, [r1,:128]!
|
||||
vld1.32 {q11}, [acc,:128]!
|
||||
vmla.f32 q10, q2, q15
|
||||
vst1.32 {q8}, [r0,:128]!
|
||||
vmla.f32 q11, q3, q15
|
||||
vst1.32 {q9}, [r0,:128]!
|
||||
subs r12, r12, #16
|
||||
beq 2f
|
||||
vld1.32 {q0}, [r1,:128]!
|
||||
vld1.32 {q8}, [acc,:128]!
|
||||
vst1.32 {q10}, [r0,:128]!
|
||||
vld1.32 {q1}, [r1,:128]!
|
||||
vld1.32 {q9}, [acc,:128]!
|
||||
vst1.32 {q11}, [r0,:128]!
|
||||
b 1b
|
||||
2: vst1.32 {q10}, [r0,:128]!
|
||||
vst1.32 {q11}, [r0,:128]!
|
||||
ands len, len, #15
|
||||
it eq
|
||||
bxeq lr
|
||||
3: vld1.32 {q0}, [r1,:128]!
|
||||
vld1.32 {q8}, [acc,:128]!
|
||||
vmla.f32 q8, q0, q15
|
||||
vst1.32 {q8}, [r0,:128]!
|
||||
subs len, len, #4
|
||||
bgt 3b
|
||||
bx lr
|
||||
.unreq len
|
||||
endfunc
|
||||
|
||||
function ff_vector_fmul_scalar_neon, export=1
|
||||
VFP len .req r2
|
||||
NOVFP len .req r3
|
||||
VFP vdup.32 q8, d0[0]
|
||||
NOVFP vdup.32 q8, r2
|
||||
bics r12, len, #15
|
||||
beq 3f
|
||||
vld1.32 {q0},[r1,:128]!
|
||||
vld1.32 {q1},[r1,:128]!
|
||||
1: vmul.f32 q0, q0, q8
|
||||
vld1.32 {q2},[r1,:128]!
|
||||
vmul.f32 q1, q1, q8
|
||||
vld1.32 {q3},[r1,:128]!
|
||||
vmul.f32 q2, q2, q8
|
||||
vst1.32 {q0},[r0,:128]!
|
||||
vmul.f32 q3, q3, q8
|
||||
vst1.32 {q1},[r0,:128]!
|
||||
subs r12, r12, #16
|
||||
beq 2f
|
||||
vld1.32 {q0},[r1,:128]!
|
||||
vst1.32 {q2},[r0,:128]!
|
||||
vld1.32 {q1},[r1,:128]!
|
||||
vst1.32 {q3},[r0,:128]!
|
||||
b 1b
|
||||
2: vst1.32 {q2},[r0,:128]!
|
||||
vst1.32 {q3},[r0,:128]!
|
||||
ands len, len, #15
|
||||
it eq
|
||||
bxeq lr
|
||||
3: vld1.32 {q0},[r1,:128]!
|
||||
vmul.f32 q0, q0, q8
|
||||
vst1.32 {q0},[r0,:128]!
|
||||
subs len, len, #4
|
||||
bgt 3b
|
||||
bx lr
|
||||
.unreq len
|
||||
endfunc
|
||||
68
project/jni/ffmpeg/libavutil/arm/float_dsp_vfp.S
Normal file
68
project/jni/ffmpeg/libavutil/arm/float_dsp_vfp.S
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of FFmpeg
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "asm.S"
|
||||
|
||||
/**
|
||||
* Assume that len is a positive number and is multiple of 8
|
||||
*/
|
||||
@ void ff_vector_fmul_vfp(float *dst, const float *src0, const float *src1, int len)
|
||||
function ff_vector_fmul_vfp, export=1
|
||||
vpush {d8-d15}
|
||||
fmrx r12, fpscr
|
||||
orr r12, r12, #(3 << 16) /* set vector size to 4 */
|
||||
fmxr fpscr, r12
|
||||
|
||||
vldmia r1!, {s0-s3}
|
||||
vldmia r2!, {s8-s11}
|
||||
vldmia r1!, {s4-s7}
|
||||
vldmia r2!, {s12-s15}
|
||||
vmul.f32 s8, s0, s8
|
||||
1:
|
||||
subs r3, r3, #16
|
||||
vmul.f32 s12, s4, s12
|
||||
itttt ge
|
||||
vldmiage r1!, {s16-s19}
|
||||
vldmiage r2!, {s24-s27}
|
||||
vldmiage r1!, {s20-s23}
|
||||
vldmiage r2!, {s28-s31}
|
||||
it ge
|
||||
vmulge.f32 s24, s16, s24
|
||||
vstmia r0!, {s8-s11}
|
||||
vstmia r0!, {s12-s15}
|
||||
it ge
|
||||
vmulge.f32 s28, s20, s28
|
||||
itttt gt
|
||||
vldmiagt r1!, {s0-s3}
|
||||
vldmiagt r2!, {s8-s11}
|
||||
vldmiagt r1!, {s4-s7}
|
||||
vldmiagt r2!, {s12-s15}
|
||||
ittt ge
|
||||
vmulge.f32 s8, s0, s8
|
||||
vstmiage r0!, {s24-s27}
|
||||
vstmiage r0!, {s28-s31}
|
||||
bgt 1b
|
||||
|
||||
bic r12, r12, #(7 << 16) /* set vector size back to 1 */
|
||||
fmxr fpscr, r12
|
||||
vpop {d8-d15}
|
||||
bx lr
|
||||
endfunc
|
||||
110
project/jni/ffmpeg/libavutil/arm/intmath.h
Normal file
110
project/jni/ffmpeg/libavutil/arm/intmath.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Mans Rullgard <mans@mansr.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 AVUTIL_ARM_INTMATH_H
|
||||
#define AVUTIL_ARM_INTMATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
|
||||
#if HAVE_INLINE_ASM
|
||||
|
||||
#if HAVE_ARMV6_INLINE
|
||||
|
||||
#define av_clip_uint8 av_clip_uint8_arm
|
||||
static av_always_inline av_const unsigned av_clip_uint8_arm(int a)
|
||||
{
|
||||
unsigned x;
|
||||
__asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_clip_int8 av_clip_int8_arm
|
||||
static av_always_inline av_const int av_clip_int8_arm(int a)
|
||||
{
|
||||
int x;
|
||||
__asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_clip_uint16 av_clip_uint16_arm
|
||||
static av_always_inline av_const unsigned av_clip_uint16_arm(int a)
|
||||
{
|
||||
unsigned x;
|
||||
__asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_clip_int16 av_clip_int16_arm
|
||||
static av_always_inline av_const int av_clip_int16_arm(int a)
|
||||
{
|
||||
int x;
|
||||
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_clip_uintp2 av_clip_uintp2_arm
|
||||
static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
|
||||
{
|
||||
unsigned x;
|
||||
__asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_sat_add32 av_sat_add32_arm
|
||||
static av_always_inline int av_sat_add32_arm(int a, int b)
|
||||
{
|
||||
int r;
|
||||
__asm__ ("qadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
||||
return r;
|
||||
}
|
||||
|
||||
#define av_sat_dadd32 av_sat_dadd32_arm
|
||||
static av_always_inline int av_sat_dadd32_arm(int a, int b)
|
||||
{
|
||||
int r;
|
||||
__asm__ ("qdadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* HAVE_ARMV6_INLINE */
|
||||
|
||||
#if HAVE_ASM_MOD_Q
|
||||
|
||||
#define av_clipl_int32 av_clipl_int32_arm
|
||||
static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
|
||||
{
|
||||
int x, y;
|
||||
__asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t"
|
||||
"itet ne \n\t"
|
||||
"mvnne %1, #1<<31 \n\t"
|
||||
"moveq %0, %Q2 \n\t"
|
||||
"eorne %0, %1, %R2, asr #31 \n\t"
|
||||
: "=r"(x), "=&r"(y) : "r"(a) : "cc");
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif /* HAVE_ASM_MOD_Q */
|
||||
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
|
||||
#endif /* AVUTIL_ARM_INTMATH_H */
|
||||
91
project/jni/ffmpeg/libavutil/arm/intreadwrite.h
Normal file
91
project/jni/ffmpeg/libavutil/arm/intreadwrite.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 AVUTIL_ARM_INTREADWRITE_H
|
||||
#define AVUTIL_ARM_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
|
||||
#if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM && !AV_GCC_VERSION_AT_LEAST(4,7)
|
||||
|
||||
#define AV_RN16 AV_RN16
|
||||
static av_always_inline unsigned AV_RN16(const void *p)
|
||||
{
|
||||
const uint8_t *q = p;
|
||||
unsigned v;
|
||||
#if !AV_GCC_VERSION_AT_LEAST(4,6)
|
||||
__asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)q));
|
||||
#elif defined __thumb__
|
||||
__asm__ ("ldrh %0, %1" : "=r"(v) : "m"(q[0]), "m"(q[1]));
|
||||
#else
|
||||
__asm__ ("ldrh %0, %1" : "=r"(v) : "Uq"(q[0]), "m"(q[1]));
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_WN16 AV_WN16
|
||||
static av_always_inline void AV_WN16(void *p, uint16_t v)
|
||||
{
|
||||
__asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
|
||||
}
|
||||
|
||||
#define AV_RN32 AV_RN32
|
||||
static av_always_inline uint32_t AV_RN32(const void *p)
|
||||
{
|
||||
const struct __attribute__((packed)) { uint32_t v; } *q = p;
|
||||
uint32_t v;
|
||||
__asm__ ("ldr %0, %1" : "=r"(v) : "m"(*q));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_WN32 AV_WN32
|
||||
static av_always_inline void AV_WN32(void *p, uint32_t v)
|
||||
{
|
||||
__asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
|
||||
}
|
||||
|
||||
#if HAVE_ASM_MOD_Q
|
||||
|
||||
#define AV_RN64 AV_RN64
|
||||
static av_always_inline uint64_t AV_RN64(const void *p)
|
||||
{
|
||||
const struct __attribute__((packed)) { uint32_t v; } *q = p;
|
||||
uint64_t v;
|
||||
__asm__ ("ldr %Q0, %1 \n\t"
|
||||
"ldr %R0, %2 \n\t"
|
||||
: "=&r"(v)
|
||||
: "m"(q[0]), "m"(q[1]));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_WN64 AV_WN64
|
||||
static av_always_inline void AV_WN64(void *p, uint64_t v)
|
||||
{
|
||||
__asm__ ("str %Q2, %0 \n\t"
|
||||
"str %R2, %1 \n\t"
|
||||
: "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
|
||||
: "r"(v));
|
||||
}
|
||||
|
||||
#endif /* HAVE_ASM_MOD_Q */
|
||||
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
|
||||
#endif /* AVUTIL_ARM_INTREADWRITE_H */
|
||||
40
project/jni/ffmpeg/libavutil/arm/timer.h
Normal file
40
project/jni/ffmpeg/libavutil/arm/timer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Mans Rullgard <mans@mansr.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 AVUTIL_ARM_TIMER_H
|
||||
#define AVUTIL_ARM_TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#if HAVE_INLINE_ASM && defined(__ARM_ARCH_7A__)
|
||||
|
||||
#define AV_READ_TIME read_time
|
||||
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
unsigned cc;
|
||||
__asm__ volatile ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc));
|
||||
return cc;
|
||||
}
|
||||
|
||||
#endif /* HAVE_INLINE_ASM && __ARM_ARCH_7A__ */
|
||||
|
||||
#endif /* AVUTIL_ARM_TIMER_H */
|
||||
154
project/jni/ffmpeg/libavutil/attributes.h
Normal file
154
project/jni/ffmpeg/libavutil/attributes.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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
|
||||
* Macro definitions for various function/variable attributes
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_ATTRIBUTES_H
|
||||
#define AVUTIL_ATTRIBUTES_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
|
||||
#else
|
||||
# define AV_GCC_VERSION_AT_LEAST(x,y) 0
|
||||
#endif
|
||||
|
||||
#ifndef av_always_inline
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_always_inline __attribute__((always_inline)) inline
|
||||
#elif defined(_MSC_VER)
|
||||
# define av_always_inline __forceinline
|
||||
#else
|
||||
# define av_always_inline inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef av_extern_inline
|
||||
#if defined(__ICL) && __ICL >= 1210 || defined(__GNUC_STDC_INLINE__)
|
||||
# define av_extern_inline extern inline
|
||||
#else
|
||||
# define av_extern_inline inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_noinline __attribute__((noinline))
|
||||
#else
|
||||
# define av_noinline
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_pure __attribute__((pure))
|
||||
#else
|
||||
# define av_pure
|
||||
#endif
|
||||
|
||||
#ifndef av_restrict
|
||||
#define av_restrict restrict
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(2,6)
|
||||
# define av_const __attribute__((const))
|
||||
#else
|
||||
# define av_const
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
# define av_cold __attribute__((cold))
|
||||
#else
|
||||
# define av_cold
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(4,1)
|
||||
# define av_flatten __attribute__((flatten))
|
||||
#else
|
||||
# define av_flatten
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define attribute_deprecated __attribute__((deprecated))
|
||||
#else
|
||||
# define attribute_deprecated
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Disable warnings about deprecated features
|
||||
* This is useful for sections of code kept for backward compatibility and
|
||||
* scheduled for removal.
|
||||
*/
|
||||
#ifndef AV_NOWARN_DEPRECATED
|
||||
#if AV_GCC_VERSION_AT_LEAST(4,6)
|
||||
# define AV_NOWARN_DEPRECATED(code) \
|
||||
_Pragma("GCC diagnostic push") \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
|
||||
code \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#else
|
||||
# define AV_NOWARN_DEPRECATED(code) code
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define av_unused __attribute__((unused))
|
||||
#else
|
||||
# define av_unused
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Mark a variable as used and prevent the compiler from optimizing it
|
||||
* away. This is useful for variables accessed only from inline
|
||||
* assembler without the compiler being aware.
|
||||
*/
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_used __attribute__((used))
|
||||
#else
|
||||
# define av_used
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,3)
|
||||
# define av_alias __attribute__((may_alias))
|
||||
#else
|
||||
# define av_alias
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
|
||||
# define av_uninit(x) x=x
|
||||
#else
|
||||
# define av_uninit(x) x
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define av_builtin_constant_p __builtin_constant_p
|
||||
# define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
|
||||
#else
|
||||
# define av_builtin_constant_p(x) 0
|
||||
# define av_printf_format(fmtpos, attrpos)
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(2,5)
|
||||
# define av_noreturn __attribute__((noreturn))
|
||||
#else
|
||||
# define av_noreturn
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_ATTRIBUTES_H */
|
||||
194
project/jni/ffmpeg/libavutil/audio_fifo.c
Normal file
194
project/jni/ffmpeg/libavutil/audio_fifo.c
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Audio FIFO
|
||||
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
|
||||
*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Audio FIFO
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
#include "audio_fifo.h"
|
||||
#include "common.h"
|
||||
#include "fifo.h"
|
||||
#include "mem.h"
|
||||
#include "samplefmt.h"
|
||||
|
||||
struct AVAudioFifo {
|
||||
AVFifoBuffer **buf; /**< single buffer for interleaved, per-channel buffers for planar */
|
||||
int nb_buffers; /**< number of buffers */
|
||||
int nb_samples; /**< number of samples currently in the FIFO */
|
||||
int allocated_samples; /**< current allocated size, in samples */
|
||||
|
||||
int channels; /**< number of channels */
|
||||
enum AVSampleFormat sample_fmt; /**< sample format */
|
||||
int sample_size; /**< size, in bytes, of one sample in a buffer */
|
||||
};
|
||||
|
||||
void av_audio_fifo_free(AVAudioFifo *af)
|
||||
{
|
||||
if (af) {
|
||||
if (af->buf) {
|
||||
int i;
|
||||
for (i = 0; i < af->nb_buffers; i++) {
|
||||
if (af->buf[i])
|
||||
av_fifo_free(af->buf[i]);
|
||||
}
|
||||
av_free(af->buf);
|
||||
}
|
||||
av_free(af);
|
||||
}
|
||||
}
|
||||
|
||||
AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
|
||||
int nb_samples)
|
||||
{
|
||||
AVAudioFifo *af;
|
||||
int buf_size, i;
|
||||
|
||||
/* get channel buffer size (also validates parameters) */
|
||||
if (av_samples_get_buffer_size(&buf_size, channels, nb_samples, sample_fmt, 1) < 0)
|
||||
return NULL;
|
||||
|
||||
af = av_mallocz(sizeof(*af));
|
||||
if (!af)
|
||||
return NULL;
|
||||
|
||||
af->channels = channels;
|
||||
af->sample_fmt = sample_fmt;
|
||||
af->sample_size = buf_size / nb_samples;
|
||||
af->nb_buffers = av_sample_fmt_is_planar(sample_fmt) ? channels : 1;
|
||||
|
||||
af->buf = av_mallocz(af->nb_buffers * sizeof(*af->buf));
|
||||
if (!af->buf)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < af->nb_buffers; i++) {
|
||||
af->buf[i] = av_fifo_alloc(buf_size);
|
||||
if (!af->buf[i])
|
||||
goto error;
|
||||
}
|
||||
af->allocated_samples = nb_samples;
|
||||
|
||||
return af;
|
||||
|
||||
error:
|
||||
av_audio_fifo_free(af);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
|
||||
{
|
||||
int i, ret, buf_size;
|
||||
|
||||
if ((ret = av_samples_get_buffer_size(&buf_size, af->channels, nb_samples,
|
||||
af->sample_fmt, 1)) < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < af->nb_buffers; i++) {
|
||||
if ((ret = av_fifo_realloc2(af->buf[i], buf_size)) < 0)
|
||||
return ret;
|
||||
}
|
||||
af->allocated_samples = nb_samples;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
|
||||
{
|
||||
int i, ret, size;
|
||||
|
||||
/* automatically reallocate buffers if needed */
|
||||
if (av_audio_fifo_space(af) < nb_samples) {
|
||||
int current_size = av_audio_fifo_size(af);
|
||||
/* check for integer overflow in new size calculation */
|
||||
if (INT_MAX / 2 - current_size < nb_samples)
|
||||
return AVERROR(EINVAL);
|
||||
/* reallocate buffers */
|
||||
if ((ret = av_audio_fifo_realloc(af, 2 * (current_size + nb_samples))) < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
size = nb_samples * af->sample_size;
|
||||
for (i = 0; i < af->nb_buffers; i++) {
|
||||
ret = av_fifo_generic_write(af->buf[i], data[i], size, NULL);
|
||||
if (ret != size)
|
||||
return AVERROR_BUG;
|
||||
}
|
||||
af->nb_samples += nb_samples;
|
||||
|
||||
return nb_samples;
|
||||
}
|
||||
|
||||
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
|
||||
{
|
||||
int i, ret, size;
|
||||
|
||||
if (nb_samples < 0)
|
||||
return AVERROR(EINVAL);
|
||||
nb_samples = FFMIN(nb_samples, af->nb_samples);
|
||||
if (!nb_samples)
|
||||
return 0;
|
||||
|
||||
size = nb_samples * af->sample_size;
|
||||
for (i = 0; i < af->nb_buffers; i++) {
|
||||
if ((ret = av_fifo_generic_read(af->buf[i], data[i], size, NULL)) < 0)
|
||||
return AVERROR_BUG;
|
||||
}
|
||||
af->nb_samples -= nb_samples;
|
||||
|
||||
return nb_samples;
|
||||
}
|
||||
|
||||
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
|
||||
{
|
||||
int i, size;
|
||||
|
||||
if (nb_samples < 0)
|
||||
return AVERROR(EINVAL);
|
||||
nb_samples = FFMIN(nb_samples, af->nb_samples);
|
||||
|
||||
if (nb_samples) {
|
||||
size = nb_samples * af->sample_size;
|
||||
for (i = 0; i < af->nb_buffers; i++)
|
||||
av_fifo_drain(af->buf[i], size);
|
||||
af->nb_samples -= nb_samples;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_audio_fifo_reset(AVAudioFifo *af)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < af->nb_buffers; i++)
|
||||
av_fifo_reset(af->buf[i]);
|
||||
|
||||
af->nb_samples = 0;
|
||||
}
|
||||
|
||||
int av_audio_fifo_size(AVAudioFifo *af)
|
||||
{
|
||||
return af->nb_samples;
|
||||
}
|
||||
|
||||
int av_audio_fifo_space(AVAudioFifo *af)
|
||||
{
|
||||
return af->allocated_samples - af->nb_samples;
|
||||
}
|
||||
146
project/jni/ffmpeg/libavutil/audio_fifo.h
Normal file
146
project/jni/ffmpeg/libavutil/audio_fifo.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Audio FIFO
|
||||
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
|
||||
*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Audio FIFO Buffer
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_AUDIO_FIFO_H
|
||||
#define AVUTIL_AUDIO_FIFO_H
|
||||
|
||||
#include "avutil.h"
|
||||
#include "fifo.h"
|
||||
#include "samplefmt.h"
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_audio
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Context for an Audio FIFO Buffer.
|
||||
*
|
||||
* - Operates at the sample level rather than the byte level.
|
||||
* - Supports multiple channels with either planar or packed sample format.
|
||||
* - Automatic reallocation when writing to a full buffer.
|
||||
*/
|
||||
typedef struct AVAudioFifo AVAudioFifo;
|
||||
|
||||
/**
|
||||
* Free an AVAudioFifo.
|
||||
*
|
||||
* @param af AVAudioFifo to free
|
||||
*/
|
||||
void av_audio_fifo_free(AVAudioFifo *af);
|
||||
|
||||
/**
|
||||
* Allocate an AVAudioFifo.
|
||||
*
|
||||
* @param sample_fmt sample format
|
||||
* @param channels number of channels
|
||||
* @param nb_samples initial allocation size, in samples
|
||||
* @return newly allocated AVAudioFifo, or NULL on error
|
||||
*/
|
||||
AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
|
||||
int nb_samples);
|
||||
|
||||
/**
|
||||
* Reallocate an AVAudioFifo.
|
||||
*
|
||||
* @param af AVAudioFifo to reallocate
|
||||
* @param nb_samples new allocation size, in samples
|
||||
* @return 0 if OK, or negative AVERROR code on failure
|
||||
*/
|
||||
int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
|
||||
|
||||
/**
|
||||
* Write data to an AVAudioFifo.
|
||||
*
|
||||
* The AVAudioFifo will be reallocated automatically if the available space
|
||||
* is less than nb_samples.
|
||||
*
|
||||
* @see enum AVSampleFormat
|
||||
* The documentation for AVSampleFormat describes the data layout.
|
||||
*
|
||||
* @param af AVAudioFifo to write to
|
||||
* @param data audio data plane pointers
|
||||
* @param nb_samples number of samples to write
|
||||
* @return number of samples actually written, or negative AVERROR
|
||||
* code on failure.
|
||||
*/
|
||||
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
|
||||
|
||||
/**
|
||||
* Read data from an AVAudioFifo.
|
||||
*
|
||||
* @see enum AVSampleFormat
|
||||
* The documentation for AVSampleFormat describes the data layout.
|
||||
*
|
||||
* @param af AVAudioFifo to read from
|
||||
* @param data audio data plane pointers
|
||||
* @param nb_samples number of samples to read
|
||||
* @return number of samples actually read, or negative AVERROR code
|
||||
* on failure.
|
||||
*/
|
||||
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
|
||||
|
||||
/**
|
||||
* Drain data from an AVAudioFifo.
|
||||
*
|
||||
* Removes the data without reading it.
|
||||
*
|
||||
* @param af AVAudioFifo to drain
|
||||
* @param nb_samples number of samples to drain
|
||||
* @return 0 if OK, or negative AVERROR code on failure
|
||||
*/
|
||||
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
|
||||
|
||||
/**
|
||||
* Reset the AVAudioFifo buffer.
|
||||
*
|
||||
* This empties all data in the buffer.
|
||||
*
|
||||
* @param af AVAudioFifo to reset
|
||||
*/
|
||||
void av_audio_fifo_reset(AVAudioFifo *af);
|
||||
|
||||
/**
|
||||
* Get the current number of samples in the AVAudioFifo available for reading.
|
||||
*
|
||||
* @param af the AVAudioFifo to query
|
||||
* @return number of samples available for reading
|
||||
*/
|
||||
int av_audio_fifo_size(AVAudioFifo *af);
|
||||
|
||||
/**
|
||||
* Get the current number of samples in the AVAudioFifo available for writing.
|
||||
*
|
||||
* @param af the AVAudioFifo to query
|
||||
* @return number of samples available for writing
|
||||
*/
|
||||
int av_audio_fifo_space(AVAudioFifo *af);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_AUDIO_FIFO_H */
|
||||
6
project/jni/ffmpeg/libavutil/audioconvert.h
Normal file
6
project/jni/ffmpeg/libavutil/audioconvert.h
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#if FF_API_AUDIOCONVERT
|
||||
#include "channel_layout.h"
|
||||
#endif
|
||||
66
project/jni/ffmpeg/libavutil/avassert.h
Normal file
66
project/jni/ffmpeg/libavutil/avassert.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* copyright (c) 2010 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
|
||||
* simple assert() macros that are a bit more flexible than ISO C assert().
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_AVASSERT_H
|
||||
#define AVUTIL_AVASSERT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "avutil.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* assert() equivalent, that is always enabled.
|
||||
*/
|
||||
#define av_assert0(cond) do { \
|
||||
if (!(cond)) { \
|
||||
av_log(NULL, AV_LOG_PANIC, "Assertion %s failed at %s:%d\n", \
|
||||
AV_STRINGIFY(cond), __FILE__, __LINE__); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**
|
||||
* assert() equivalent, that does not lie in speed critical code.
|
||||
* These asserts() thus can be enabled without fearing speedloss.
|
||||
*/
|
||||
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0
|
||||
#define av_assert1(cond) av_assert0(cond)
|
||||
#else
|
||||
#define av_assert1(cond) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* assert() equivalent, that does lie in speed critical code.
|
||||
*/
|
||||
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
|
||||
#define av_assert2(cond) av_assert0(cond)
|
||||
#else
|
||||
#define av_assert2(cond) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_AVASSERT_H */
|
||||
44
project/jni/ffmpeg/libavutil/avr32/bswap.h
Normal file
44
project/jni/ffmpeg/libavutil/avr32/bswap.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 AVUTIL_AVR32_BSWAP_H
|
||||
#define AVUTIL_AVR32_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
|
||||
#if HAVE_INLINE_ASM
|
||||
|
||||
#define av_bswap16 av_bswap16
|
||||
static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
|
||||
{
|
||||
__asm__ ("swap.bh %0" : "+r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define av_bswap32 av_bswap32
|
||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||
{
|
||||
__asm__ ("swap.b %0" : "+r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif /* HAVE_INLINE_ASM */
|
||||
|
||||
#endif /* AVUTIL_AVR32_BSWAP_H */
|
||||
182
project/jni/ffmpeg/libavutil/avr32/intreadwrite.h
Normal file
182
project/jni/ffmpeg/libavutil/avr32/intreadwrite.h
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Mans Rullgard <mans@mansr.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 AVUTIL_AVR32_INTREADWRITE_H
|
||||
#define AVUTIL_AVR32_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/bswap.h"
|
||||
|
||||
/*
|
||||
* AVR32 does not support unaligned memory accesses, except for the AP
|
||||
* series which suppports unaligned 32-bit loads and stores. 16-bit
|
||||
* and 64-bit accesses must be aligned to 16 and 32 bits, respectively.
|
||||
* This means we cannot use the byte-swapping load/store instructions
|
||||
* here.
|
||||
*
|
||||
* For 16-bit, 24-bit, and (on UC series) 32-bit loads, we instead use
|
||||
* the LDINS.B instruction, which gcc fails to utilise with the
|
||||
* generic code. GCC also fails to use plain LD.W and ST.W even for
|
||||
* AP processors, so we override the generic code. The 64-bit
|
||||
* versions are improved by using our optimised 32-bit functions.
|
||||
*/
|
||||
|
||||
#define AV_RL16 AV_RL16
|
||||
static av_always_inline uint16_t AV_RL16(const void *p)
|
||||
{
|
||||
uint16_t v;
|
||||
__asm__ ("ld.ub %0, %1 \n\t"
|
||||
"ldins.b %0:l, %2 \n\t"
|
||||
: "=&r"(v)
|
||||
: "m"(*(const uint8_t*)p), "RKs12"(*((const uint8_t*)p+1)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_RB16 AV_RB16
|
||||
static av_always_inline uint16_t AV_RB16(const void *p)
|
||||
{
|
||||
uint16_t v;
|
||||
__asm__ ("ld.ub %0, %2 \n\t"
|
||||
"ldins.b %0:l, %1 \n\t"
|
||||
: "=&r"(v)
|
||||
: "RKs12"(*(const uint8_t*)p), "m"(*((const uint8_t*)p+1)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_RB24 AV_RB24
|
||||
static av_always_inline uint32_t AV_RB24(const void *p)
|
||||
{
|
||||
uint32_t v;
|
||||
__asm__ ("ld.ub %0, %3 \n\t"
|
||||
"ldins.b %0:l, %2 \n\t"
|
||||
"ldins.b %0:u, %1 \n\t"
|
||||
: "=&r"(v)
|
||||
: "RKs12"(* (const uint8_t*)p),
|
||||
"RKs12"(*((const uint8_t*)p+1)),
|
||||
"m" (*((const uint8_t*)p+2)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_RL24 AV_RL24
|
||||
static av_always_inline uint32_t AV_RL24(const void *p)
|
||||
{
|
||||
uint32_t v;
|
||||
__asm__ ("ld.ub %0, %1 \n\t"
|
||||
"ldins.b %0:l, %2 \n\t"
|
||||
"ldins.b %0:u, %3 \n\t"
|
||||
: "=&r"(v)
|
||||
: "m" (* (const uint8_t*)p),
|
||||
"RKs12"(*((const uint8_t*)p+1)),
|
||||
"RKs12"(*((const uint8_t*)p+2)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#if ARCH_AVR32_AP
|
||||
|
||||
#define AV_RB32 AV_RB32
|
||||
static av_always_inline uint32_t AV_RB32(const void *p)
|
||||
{
|
||||
uint32_t v;
|
||||
__asm__ ("ld.w %0, %1" : "=r"(v) : "m"(*(const uint32_t*)p));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_WB32 AV_WB32
|
||||
static av_always_inline void AV_WB32(void *p, uint32_t v)
|
||||
{
|
||||
__asm__ ("st.w %0, %1" : "=m"(*(uint32_t*)p) : "r"(v));
|
||||
}
|
||||
|
||||
/* These two would be defined by generic code, but we need them sooner. */
|
||||
#define AV_RL32(p) av_bswap32(AV_RB32(p))
|
||||
#define AV_WL32(p, v) AV_WB32(p, av_bswap32(v))
|
||||
|
||||
#define AV_WB64 AV_WB64
|
||||
static av_always_inline void AV_WB64(void *p, uint64_t v)
|
||||
{
|
||||
union { uint64_t v; uint32_t hl[2]; } vv = { v };
|
||||
AV_WB32(p, vv.hl[0]);
|
||||
AV_WB32((uint32_t*)p+1, vv.hl[1]);
|
||||
}
|
||||
|
||||
#define AV_WL64 AV_WL64
|
||||
static av_always_inline void AV_WL64(void *p, uint64_t v)
|
||||
{
|
||||
union { uint64_t v; uint32_t hl[2]; } vv = { v };
|
||||
AV_WL32(p, vv.hl[1]);
|
||||
AV_WL32((uint32_t*)p+1, vv.hl[0]);
|
||||
}
|
||||
|
||||
#else /* ARCH_AVR32_AP */
|
||||
|
||||
#define AV_RB32 AV_RB32
|
||||
static av_always_inline uint32_t AV_RB32(const void *p)
|
||||
{
|
||||
uint32_t v;
|
||||
__asm__ ("ld.ub %0, %4 \n\t"
|
||||
"ldins.b %0:l, %3 \n\t"
|
||||
"ldins.b %0:u, %2 \n\t"
|
||||
"ldins.b %0:t, %1 \n\t"
|
||||
: "=&r"(v)
|
||||
: "RKs12"(* (const uint8_t*)p),
|
||||
"RKs12"(*((const uint8_t*)p+1)),
|
||||
"RKs12"(*((const uint8_t*)p+2)),
|
||||
"m" (*((const uint8_t*)p+3)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#define AV_RL32 AV_RL32
|
||||
static av_always_inline uint32_t AV_RL32(const void *p)
|
||||
{
|
||||
uint32_t v;
|
||||
__asm__ ("ld.ub %0, %1 \n\t"
|
||||
"ldins.b %0:l, %2 \n\t"
|
||||
"ldins.b %0:u, %3 \n\t"
|
||||
"ldins.b %0:t, %4 \n\t"
|
||||
: "=&r"(v)
|
||||
: "m" (* (const uint8_t*)p),
|
||||
"RKs12"(*((const uint8_t*)p+1)),
|
||||
"RKs12"(*((const uint8_t*)p+2)),
|
||||
"RKs12"(*((const uint8_t*)p+3)));
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* ARCH_AVR32_AP */
|
||||
|
||||
#define AV_RB64 AV_RB64
|
||||
static av_always_inline uint64_t AV_RB64(const void *p)
|
||||
{
|
||||
union { uint64_t v; uint32_t hl[2]; } v;
|
||||
v.hl[0] = AV_RB32(p);
|
||||
v.hl[1] = AV_RB32((const uint32_t*)p+1);
|
||||
return v.v;
|
||||
}
|
||||
|
||||
#define AV_RL64 AV_RL64
|
||||
static av_always_inline uint64_t AV_RL64(const void *p)
|
||||
{
|
||||
union { uint64_t v; uint32_t hl[2]; } v;
|
||||
v.hl[1] = AV_RL32(p);
|
||||
v.hl[0] = AV_RL32((const uint32_t*)p+1);
|
||||
return v.v;
|
||||
}
|
||||
|
||||
#endif /* AVUTIL_AVR32_INTREADWRITE_H */
|
||||
308
project/jni/ffmpeg/libavutil/avstring.c
Normal file
308
project/jni/ffmpeg/libavutil/avstring.c
Normal file
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* 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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "avstring.h"
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "mem.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;
|
||||
}
|
||||
|
||||
char *av_stristr(const char *s1, const char *s2)
|
||||
{
|
||||
if (!*s2)
|
||||
return (char*)(intptr_t)s1;
|
||||
|
||||
do {
|
||||
if (av_stristart(s1, s2, NULL))
|
||||
return (char*)(intptr_t)s1;
|
||||
} while (*s1++);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char *av_asprintf(const char *fmt, ...)
|
||||
{
|
||||
char *p = NULL;
|
||||
va_list va;
|
||||
int len;
|
||||
|
||||
va_start(va, fmt);
|
||||
len = vsnprintf(NULL, 0, fmt, va);
|
||||
va_end(va);
|
||||
if (len < 0)
|
||||
goto end;
|
||||
|
||||
p = av_malloc(len + 1);
|
||||
if (!p)
|
||||
goto end;
|
||||
|
||||
va_start(va, fmt);
|
||||
len = vsnprintf(p, len + 1, fmt, va);
|
||||
va_end(va);
|
||||
if (len < 0)
|
||||
av_freep(&p);
|
||||
|
||||
end:
|
||||
return p;
|
||||
}
|
||||
|
||||
char *av_d2str(double d)
|
||||
{
|
||||
char *str= av_malloc(16);
|
||||
if(str) snprintf(str, 16, "%f", d);
|
||||
return str;
|
||||
}
|
||||
|
||||
#define WHITESPACES " \n\t"
|
||||
|
||||
char *av_get_token(const char **buf, const char *term)
|
||||
{
|
||||
char *out = av_malloc(strlen(*buf) + 1);
|
||||
char *ret= out, *end= out;
|
||||
const char *p = *buf;
|
||||
if (!out) return NULL;
|
||||
p += strspn(p, WHITESPACES);
|
||||
|
||||
while(*p && !strspn(p, term)) {
|
||||
char c = *p++;
|
||||
if(c == '\\' && *p){
|
||||
*out++ = *p++;
|
||||
end= out;
|
||||
}else if(c == '\''){
|
||||
while(*p && *p != '\'')
|
||||
*out++ = *p++;
|
||||
if(*p){
|
||||
p++;
|
||||
end= out;
|
||||
}
|
||||
}else{
|
||||
*out++ = c;
|
||||
}
|
||||
}
|
||||
|
||||
do{
|
||||
*out-- = 0;
|
||||
}while(out >= end && strspn(out, WHITESPACES));
|
||||
|
||||
*buf = p;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *av_strtok(char *s, const char *delim, char **saveptr)
|
||||
{
|
||||
char *tok;
|
||||
|
||||
if (!s && !(s = *saveptr))
|
||||
return NULL;
|
||||
|
||||
/* skip leading delimiters */
|
||||
s += strspn(s, delim);
|
||||
|
||||
/* s now points to the first non delimiter char, or to the end of the string */
|
||||
if (!*s) {
|
||||
*saveptr = NULL;
|
||||
return NULL;
|
||||
}
|
||||
tok = s++;
|
||||
|
||||
/* skip non delimiters */
|
||||
s += strcspn(s, delim);
|
||||
if (*s) {
|
||||
*s = 0;
|
||||
*saveptr = s+1;
|
||||
} else {
|
||||
*saveptr = NULL;
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
int av_strcasecmp(const char *a, const char *b)
|
||||
{
|
||||
uint8_t c1, c2;
|
||||
do {
|
||||
c1 = av_tolower(*a++);
|
||||
c2 = av_tolower(*b++);
|
||||
} while (c1 && c1 == c2);
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
int av_strncasecmp(const char *a, const char *b, size_t n)
|
||||
{
|
||||
const char *end = a + n;
|
||||
uint8_t c1, c2;
|
||||
do {
|
||||
c1 = av_tolower(*a++);
|
||||
c2 = av_tolower(*b++);
|
||||
} while (a < end && c1 && c1 == c2);
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
const char *av_basename(const char *path)
|
||||
{
|
||||
char *p = strrchr(path, '/');
|
||||
|
||||
#if HAVE_DOS_PATHS
|
||||
char *q = strrchr(path, '\\');
|
||||
char *d = strchr(path, ':');
|
||||
|
||||
p = FFMAX3(p, q, d);
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
return path;
|
||||
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
const char *av_dirname(char *path)
|
||||
{
|
||||
char *p = strrchr(path, '/');
|
||||
|
||||
#if HAVE_DOS_PATHS
|
||||
char *q = strrchr(path, '\\');
|
||||
char *d = strchr(path, ':');
|
||||
|
||||
d = d ? d + 1 : d;
|
||||
|
||||
p = FFMAX3(p, q, d);
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
return ".";
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Testing av_get_token()\n");
|
||||
{
|
||||
const char *strings[] = {
|
||||
"''",
|
||||
"",
|
||||
":",
|
||||
"\\",
|
||||
"'",
|
||||
" '' :",
|
||||
" '' '' :",
|
||||
"foo '' :",
|
||||
"'foo'",
|
||||
"foo ",
|
||||
" ' foo ' ",
|
||||
"foo\\",
|
||||
"foo': blah:blah",
|
||||
"foo\\: blah:blah",
|
||||
"foo\'",
|
||||
"'foo : ' :blahblah",
|
||||
"\\ :blah",
|
||||
" foo",
|
||||
" foo ",
|
||||
" foo \\ ",
|
||||
"foo ':blah",
|
||||
" foo bar : blahblah",
|
||||
"\\f\\o\\o",
|
||||
"'foo : \\ \\ ' : blahblah",
|
||||
"'\\fo\\o:': blahblah",
|
||||
"\\'fo\\o\\:': foo ' :blahblah"
|
||||
};
|
||||
|
||||
for (i=0; i < FF_ARRAY_ELEMS(strings); i++) {
|
||||
const char *p = strings[i];
|
||||
char *q;
|
||||
printf("|%s|", p);
|
||||
q = av_get_token(&p, ":");
|
||||
printf(" -> |%s|", q);
|
||||
printf(" + |%s|\n", p);
|
||||
av_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
225
project/jni/ffmpeg/libavutil/avstring.h
Normal file
225
project/jni/ffmpeg/libavutil/avstring.h
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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 AVUTIL_AVSTRING_H
|
||||
#define AVUTIL_AVSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "attributes.h"
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_string
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 if the prefix is matched inside str
|
||||
* @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 if the prefix is matched inside str
|
||||
* @return non-zero if the prefix matches, zero otherwise
|
||||
*/
|
||||
int av_stristart(const char *str, const char *pfx, const char **ptr);
|
||||
|
||||
/**
|
||||
* Locate the first case-independent occurrence in the string haystack
|
||||
* of the string needle. A zero-length string needle is considered to
|
||||
* match at the start of haystack.
|
||||
*
|
||||
* This function is a case-insensitive version of the standard strstr().
|
||||
*
|
||||
* @param haystack string to search in
|
||||
* @param needle string to search for
|
||||
* @return pointer to the located match within haystack
|
||||
* or a null pointer if no match
|
||||
*/
|
||||
char *av_stristr(const char *haystack, const char *needle);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @warning since the return value is the length of src, src absolutely
|
||||
* _must_ be a properly 0-terminated string, otherwise this will read beyond
|
||||
* the end of the buffer and possibly crash.
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @warning since the return value use the length of src and dst, these
|
||||
* absolutely _must_ be a properly 0-terminated strings, otherwise this
|
||||
* will read beyond the end of the buffer and possibly crash.
|
||||
*/
|
||||
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 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, ...) av_printf_format(3, 4);
|
||||
|
||||
/**
|
||||
* Print arguments following specified format into a large enough auto
|
||||
* allocated buffer. It is similar to GNU asprintf().
|
||||
* @param fmt printf-compatible format string, specifying how the
|
||||
* following parameters are used.
|
||||
* @return the allocated string
|
||||
* @note You have to free the string yourself with av_free().
|
||||
*/
|
||||
char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2);
|
||||
|
||||
/**
|
||||
* Convert a number to a av_malloced string.
|
||||
*/
|
||||
char *av_d2str(double d);
|
||||
|
||||
/**
|
||||
* Unescape the given string until a non escaped terminating char,
|
||||
* and return the token corresponding to the unescaped string.
|
||||
*
|
||||
* The normal \ and ' escaping is supported. Leading and trailing
|
||||
* whitespaces are removed, unless they are escaped with '\' or are
|
||||
* enclosed between ''.
|
||||
*
|
||||
* @param buf the buffer to parse, buf will be updated to point to the
|
||||
* terminating char
|
||||
* @param term a 0-terminated list of terminating chars
|
||||
* @return the malloced unescaped string, which must be av_freed by
|
||||
* the user, NULL in case of allocation failure
|
||||
*/
|
||||
char *av_get_token(const char **buf, const char *term);
|
||||
|
||||
/**
|
||||
* Split the string into several tokens which can be accessed by
|
||||
* successive calls to av_strtok().
|
||||
*
|
||||
* A token is defined as a sequence of characters not belonging to the
|
||||
* set specified in delim.
|
||||
*
|
||||
* On the first call to av_strtok(), s should point to the string to
|
||||
* parse, and the value of saveptr is ignored. In subsequent calls, s
|
||||
* should be NULL, and saveptr should be unchanged since the previous
|
||||
* call.
|
||||
*
|
||||
* This function is similar to strtok_r() defined in POSIX.1.
|
||||
*
|
||||
* @param s the string to parse, may be NULL
|
||||
* @param delim 0-terminated list of token delimiters, must be non-NULL
|
||||
* @param saveptr user-provided pointer which points to stored
|
||||
* information necessary for av_strtok() to continue scanning the same
|
||||
* string. saveptr is updated to point to the next character after the
|
||||
* first delimiter found, or to NULL if the string was terminated
|
||||
* @return the found token, or NULL when no token is found
|
||||
*/
|
||||
char *av_strtok(char *s, const char *delim, char **saveptr);
|
||||
|
||||
/**
|
||||
* Locale-independent conversion of ASCII characters to uppercase.
|
||||
*/
|
||||
static inline int av_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
c ^= 0x20;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale-independent conversion of ASCII characters to lowercase.
|
||||
*/
|
||||
static inline int av_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c ^= 0x20;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale-independent case-insensitive compare.
|
||||
* @note This means only ASCII-range characters are case-insensitive
|
||||
*/
|
||||
int av_strcasecmp(const char *a, const char *b);
|
||||
|
||||
/**
|
||||
* Locale-independent case-insensitive compare.
|
||||
* @note This means only ASCII-range characters are case-insensitive
|
||||
*/
|
||||
int av_strncasecmp(const char *a, const char *b, size_t n);
|
||||
|
||||
|
||||
/**
|
||||
* Thread safe basename.
|
||||
* @param path the path, on DOS both \ and / are considered separators.
|
||||
* @return pointer to the basename substring.
|
||||
*/
|
||||
const char *av_basename(const char *path);
|
||||
|
||||
/**
|
||||
* Thread safe dirname.
|
||||
* @param path the path, on DOS both \ and / are considered separators.
|
||||
* @return the path with the separator replaced by the string terminator or ".".
|
||||
* @note the function may change the input string.
|
||||
*/
|
||||
const char *av_dirname(char *path);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_AVSTRING_H */
|
||||
260
project/jni/ffmpeg/libavutil/avutil.h
Normal file
260
project/jni/ffmpeg/libavutil/avutil.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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 AVUTIL_AVUTIL_H
|
||||
#define AVUTIL_AVUTIL_H
|
||||
|
||||
/**
|
||||
* @file
|
||||
* external API header
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage
|
||||
*
|
||||
* @section ffmpeg_intro Introduction
|
||||
*
|
||||
* This document describes the usage of the different libraries
|
||||
* provided by FFmpeg.
|
||||
*
|
||||
* @li @ref libavc "libavcodec" encoding/decoding library
|
||||
* @li @ref lavfi "libavfilter" graph based frame editing library
|
||||
* @li @ref libavf "libavformat" I/O and muxing/demuxing library
|
||||
* @li @ref lavd "libavdevice" special devices muxing/demuxing library
|
||||
* @li @ref lavu "libavutil" common utility library
|
||||
* @li @ref lswr "libswresample" audio resampling, format conversion and mixing
|
||||
* @li @ref lpp "libpostproc" post processing library
|
||||
* @li @ref lsws "libswscale" color conversion and scaling library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup lavu Common utility functions
|
||||
*
|
||||
* @brief
|
||||
* libavutil contains the code shared across all the other FFmpeg
|
||||
* libraries
|
||||
*
|
||||
* @note In order to use the functions provided by avutil you must include
|
||||
* the specific header.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @defgroup lavu_crypto Crypto and Hashing
|
||||
*
|
||||
* @{
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_math Maths
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_string String Manipulation
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_mem Memory Management
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_data Data Structures
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_audio Audio related
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_error Error Codes
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*
|
||||
* @defgroup lavu_misc Other
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @defgroup lavu_internal Internal
|
||||
*
|
||||
* Not exported functions, for internal usage only
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_ver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the LIBAVUTIL_VERSION_INT constant.
|
||||
*/
|
||||
unsigned avutil_version(void);
|
||||
|
||||
/**
|
||||
* Return the libavutil build-time configuration.
|
||||
*/
|
||||
const char *avutil_configuration(void);
|
||||
|
||||
/**
|
||||
* Return the libavutil license.
|
||||
*/
|
||||
const char *avutil_license(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_media Media Type
|
||||
* @brief Media Type
|
||||
*/
|
||||
|
||||
enum AVMediaType {
|
||||
AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA
|
||||
AVMEDIA_TYPE_VIDEO,
|
||||
AVMEDIA_TYPE_AUDIO,
|
||||
AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous
|
||||
AVMEDIA_TYPE_SUBTITLE,
|
||||
AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse
|
||||
AVMEDIA_TYPE_NB
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a string describing the media_type enum, NULL if media_type
|
||||
* is unknown.
|
||||
*/
|
||||
const char *av_get_media_type_string(enum AVMediaType media_type);
|
||||
|
||||
/**
|
||||
* @defgroup lavu_const Constants
|
||||
* @{
|
||||
*
|
||||
* @defgroup lavu_enc Encoding specific
|
||||
*
|
||||
* @note those definition should move to avcodec
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define FF_LAMBDA_SHIFT 7
|
||||
#define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
|
||||
#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
|
||||
#define FF_LAMBDA_MAX (256*128-1)
|
||||
|
||||
#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @defgroup lavu_time Timestamp specific
|
||||
*
|
||||
* FFmpeg internal timebase and timestamp definitions
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Undefined timestamp value
|
||||
*
|
||||
* Usually reported by demuxer that work on containers that do not provide
|
||||
* either pts or dts.
|
||||
*/
|
||||
|
||||
#define AV_NOPTS_VALUE ((int64_t)UINT64_C(0x8000000000000000))
|
||||
|
||||
/**
|
||||
* Internal time base represented as integer
|
||||
*/
|
||||
|
||||
#define AV_TIME_BASE 1000000
|
||||
|
||||
/**
|
||||
* Internal time base represented as fractional value
|
||||
*/
|
||||
|
||||
#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @defgroup lavu_picture Image related
|
||||
*
|
||||
* AVPicture types, pixel formats and basic image planes manipulation.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
enum AVPictureType {
|
||||
AV_PICTURE_TYPE_NONE = 0, ///< Undefined
|
||||
AV_PICTURE_TYPE_I, ///< Intra
|
||||
AV_PICTURE_TYPE_P, ///< Predicted
|
||||
AV_PICTURE_TYPE_B, ///< Bi-dir predicted
|
||||
AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG4
|
||||
AV_PICTURE_TYPE_SI, ///< Switching Intra
|
||||
AV_PICTURE_TYPE_SP, ///< Switching Predicted
|
||||
AV_PICTURE_TYPE_BI, ///< BI type
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a single letter to describe the given picture type
|
||||
* pict_type.
|
||||
*
|
||||
* @param[in] pict_type the picture type @return a single character
|
||||
* representing the picture type, '?' if pict_type is unknown
|
||||
*/
|
||||
char av_get_picture_type_char(enum AVPictureType pict_type);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "error.h"
|
||||
#include "version.h"
|
||||
#include "mathematics.h"
|
||||
#include "rational.h"
|
||||
#include "intfloat_readwrite.h"
|
||||
#include "log.h"
|
||||
#include "pixfmt.h"
|
||||
|
||||
/**
|
||||
* Return x default pointer in case p is NULL.
|
||||
*/
|
||||
static inline void *av_x_if_null(const void *p, const void *x)
|
||||
{
|
||||
return (void *)(intptr_t)(p ? p : x);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_AVUTIL_H */
|
||||
277
project/jni/ffmpeg/libavutil/base64.c
Normal file
277
project/jni/ffmpeg/libavutil/base64.c
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* 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
|
||||
* @brief Base64 encode/decode
|
||||
* @author Ryan Martell <rdm4@martellventures.com> (with lots of Michael)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "base64.h"
|
||||
#include "intreadwrite.h"
|
||||
|
||||
/* ---------------- private code */
|
||||
static const uint8_t map2[256] =
|
||||
{
|
||||
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff,
|
||||
|
||||
0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36,
|
||||
0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff,
|
||||
0xff, 0xff, 0xfe, 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,
|
||||
|
||||
0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
};
|
||||
|
||||
#define BASE64_DEC_STEP(i) do { \
|
||||
bits = map2[in[i]]; \
|
||||
if (bits & 0x80) \
|
||||
goto out ## i; \
|
||||
v = i ? (v << 6) + bits : bits; \
|
||||
} while(0)
|
||||
|
||||
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
|
||||
{
|
||||
uint8_t *dst = out;
|
||||
uint8_t *end = out + out_size;
|
||||
// no sign extension
|
||||
const uint8_t *in = in_str;
|
||||
unsigned bits = 0xff;
|
||||
unsigned v;
|
||||
|
||||
while (end - dst > 3) {
|
||||
BASE64_DEC_STEP(0);
|
||||
BASE64_DEC_STEP(1);
|
||||
BASE64_DEC_STEP(2);
|
||||
BASE64_DEC_STEP(3);
|
||||
// Using AV_WB32 directly confuses compiler
|
||||
v = av_be2ne32(v << 8);
|
||||
AV_WN32(dst, v);
|
||||
dst += 3;
|
||||
in += 4;
|
||||
}
|
||||
if (end - dst) {
|
||||
BASE64_DEC_STEP(0);
|
||||
BASE64_DEC_STEP(1);
|
||||
BASE64_DEC_STEP(2);
|
||||
BASE64_DEC_STEP(3);
|
||||
*dst++ = v >> 16;
|
||||
if (end - dst)
|
||||
*dst++ = v >> 8;
|
||||
if (end - dst)
|
||||
*dst++ = v;
|
||||
in += 4;
|
||||
}
|
||||
while (1) {
|
||||
BASE64_DEC_STEP(0);
|
||||
in++;
|
||||
BASE64_DEC_STEP(0);
|
||||
in++;
|
||||
BASE64_DEC_STEP(0);
|
||||
in++;
|
||||
BASE64_DEC_STEP(0);
|
||||
in++;
|
||||
}
|
||||
|
||||
out3:
|
||||
*dst++ = v >> 10;
|
||||
v <<= 2;
|
||||
out2:
|
||||
*dst++ = v >> 4;
|
||||
out1:
|
||||
out0:
|
||||
return bits & 1 ? AVERROR_INVALIDDATA : 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 *out, int out_size, const uint8_t *in, int in_size)
|
||||
{
|
||||
static const char b64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
char *ret, *dst;
|
||||
unsigned i_bits = 0;
|
||||
int i_shift = 0;
|
||||
int bytes_remaining = in_size;
|
||||
|
||||
if (in_size >= UINT_MAX / 4 ||
|
||||
out_size < AV_BASE64_SIZE(in_size))
|
||||
return NULL;
|
||||
ret = dst = out;
|
||||
while (bytes_remaining > 3) {
|
||||
i_bits = AV_RB32(in);
|
||||
in += 3; bytes_remaining -= 3;
|
||||
*dst++ = b64[ i_bits>>26 ];
|
||||
*dst++ = b64[(i_bits>>20) & 0x3F];
|
||||
*dst++ = b64[(i_bits>>14) & 0x3F];
|
||||
*dst++ = b64[(i_bits>>8 ) & 0x3F];
|
||||
}
|
||||
i_bits = 0;
|
||||
while (bytes_remaining) {
|
||||
i_bits = (i_bits << 8) + *in++;
|
||||
bytes_remaining--;
|
||||
i_shift += 8;
|
||||
}
|
||||
while (i_shift > 0) {
|
||||
*dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
|
||||
i_shift -= 6;
|
||||
}
|
||||
while ((dst - ret) & 3)
|
||||
*dst++ = '=';
|
||||
*dst = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
// LCOV_EXCL_START
|
||||
|
||||
#define MAX_DATA_SIZE 1024
|
||||
#define MAX_ENCODED_SIZE 2048
|
||||
|
||||
static int test_encode_decode(const uint8_t *data, unsigned int data_size,
|
||||
const char *encoded_ref)
|
||||
{
|
||||
char encoded[MAX_ENCODED_SIZE];
|
||||
uint8_t data2[MAX_DATA_SIZE];
|
||||
int data2_size, max_data2_size = MAX_DATA_SIZE;
|
||||
|
||||
if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
|
||||
printf("Failed: cannot encode the input data\n");
|
||||
return 1;
|
||||
}
|
||||
if (encoded_ref && strcmp(encoded, encoded_ref)) {
|
||||
printf("Failed: encoded string differs from reference\n"
|
||||
"Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) {
|
||||
printf("Failed: cannot decode the encoded string\n"
|
||||
"Encoded:\n%s\n", encoded);
|
||||
return 1;
|
||||
}
|
||||
if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) {
|
||||
printf("Failed: cannot decode with minimal buffer\n"
|
||||
"Encoded:\n%s\n", encoded);
|
||||
return 1;
|
||||
}
|
||||
if (memcmp(data2, data, data_size)) {
|
||||
printf("Failed: encoded/decoded data differs from original data\n");
|
||||
return 1;
|
||||
}
|
||||
if (av_base64_decode(NULL, encoded, 0) != 0) {
|
||||
printf("Failed: decode to NULL buffer\n");
|
||||
return 1;
|
||||
}
|
||||
if (strlen(encoded)) {
|
||||
char *end = strchr(encoded, '=');
|
||||
if (!end)
|
||||
end = encoded + strlen(encoded) - 1;
|
||||
*end = '%';
|
||||
if (av_base64_decode(NULL, encoded, 0) >= 0) {
|
||||
printf("Failed: error detection\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Passed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int i, error_count = 0;
|
||||
struct test {
|
||||
const uint8_t *data;
|
||||
const char *encoded_ref;
|
||||
} tests[] = {
|
||||
{ "", ""},
|
||||
{ "1", "MQ=="},
|
||||
{ "22", "MjI="},
|
||||
{ "333", "MzMz"},
|
||||
{ "4444", "NDQ0NA=="},
|
||||
{ "55555", "NTU1NTU="},
|
||||
{ "666666", "NjY2NjY2"},
|
||||
{ "abc:def", "YWJjOmRlZg=="},
|
||||
};
|
||||
char in[1024], out[2048];
|
||||
|
||||
printf("Encoding/decoding tests\n");
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
|
||||
error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
|
||||
|
||||
if (argc>1 && !strcmp(argv[1], "-t")) {
|
||||
memset(in, 123, sizeof(in));
|
||||
for(i=0; i<10000; i++){
|
||||
START_TIMER
|
||||
av_base64_encode(out, sizeof(out), in, sizeof(in));
|
||||
STOP_TIMER("encode")
|
||||
}
|
||||
for(i=0; i<10000; i++){
|
||||
START_TIMER
|
||||
av_base64_decode(in, out, sizeof(in));
|
||||
STOP_TIMER("decode")
|
||||
}
|
||||
|
||||
for(i=0; i<10000; i++){
|
||||
START_TIMER
|
||||
av_base64_decode(NULL, out, 0);
|
||||
STOP_TIMER("syntax check")
|
||||
}
|
||||
}
|
||||
|
||||
return error_count;
|
||||
}
|
||||
|
||||
// LCOV_EXCL_STOP
|
||||
#endif
|
||||
67
project/jni/ffmpeg/libavutil/base64.h
Normal file
67
project/jni/ffmpeg/libavutil/base64.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 AVUTIL_BASE64_H
|
||||
#define AVUTIL_BASE64_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @defgroup lavu_base64 Base64
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Decode a base64-encoded string.
|
||||
*
|
||||
* @param out buffer for decoded data
|
||||
* @param in null-terminated input string
|
||||
* @param out_size size in bytes of the out buffer, must be at
|
||||
* least 3/4 of the length of in
|
||||
* @return number of bytes written, or a negative value in case of
|
||||
* invalid input
|
||||
*/
|
||||
int av_base64_decode(uint8_t *out, const char *in, int out_size);
|
||||
|
||||
/**
|
||||
* Encode data to base64 and null-terminate.
|
||||
*
|
||||
* @param out buffer for encoded data
|
||||
* @param out_size size in bytes of the out buffer (including the
|
||||
* null terminator), must be at least AV_BASE64_SIZE(in_size)
|
||||
* @param in input buffer containing the data to encode
|
||||
* @param in_size size in bytes of the in buffer
|
||||
* @return out or NULL in case of error
|
||||
*/
|
||||
char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
|
||||
|
||||
/**
|
||||
* Calculate the output size needed to base64-encode x bytes to a
|
||||
* null-terminated string.
|
||||
*/
|
||||
#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_BASE64_H */
|
||||
45
project/jni/ffmpeg/libavutil/bfin/bswap.h
Normal file
45
project/jni/ffmpeg/libavutil/bfin/bswap.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Marc Hoffman
|
||||
*
|
||||
* 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
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_BFIN_BSWAP_H
|
||||
#define AVUTIL_BFIN_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/attributes.h"
|
||||
|
||||
#define av_bswap32 av_bswap32
|
||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||
{
|
||||
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));
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif /* AVUTIL_BFIN_BSWAP_H */
|
||||
41
project/jni/ffmpeg/libavutil/bfin/timer.h
Normal file
41
project/jni/ffmpeg/libavutil/bfin/timer.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Marc Hoffman
|
||||
*
|
||||
* 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 AVUTIL_BFIN_TIMER_H
|
||||
#define AVUTIL_BFIN_TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define AV_READ_TIME read_time
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#endif /* AVUTIL_BFIN_TIMER_H */
|
||||
589
project/jni/ffmpeg/libavutil/blowfish.c
Normal file
589
project/jni/ffmpeg/libavutil/blowfish.c
Normal file
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* Blowfish algorithm
|
||||
* Copyright (c) 2012 Samuel Pitoiset
|
||||
*
|
||||
* loosely based on Paul Kocher's implementation
|
||||
*
|
||||
* 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 "libavutil/intreadwrite.h"
|
||||
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "blowfish.h"
|
||||
|
||||
static const uint32_t orig_p[AV_BF_ROUNDS + 2] = {
|
||||
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
||||
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
||||
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
||||
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
|
||||
0x9216D5D9, 0x8979FB1B
|
||||
};
|
||||
|
||||
static const uint32_t orig_s[4][256] = {
|
||||
{ 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
|
||||
0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
|
||||
0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
|
||||
0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
|
||||
0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
|
||||
0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
|
||||
0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
|
||||
0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
|
||||
0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
|
||||
0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
|
||||
0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
|
||||
0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
|
||||
0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
|
||||
0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
|
||||
0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
|
||||
0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
|
||||
0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
|
||||
0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
|
||||
0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
|
||||
0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
|
||||
0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
|
||||
0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
|
||||
0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
|
||||
0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
|
||||
0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
|
||||
0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
|
||||
0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
|
||||
0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
|
||||
0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
|
||||
0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
|
||||
0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
|
||||
0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
|
||||
0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
|
||||
0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
|
||||
0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
|
||||
0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
|
||||
0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
|
||||
0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
|
||||
0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
|
||||
0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
|
||||
0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
|
||||
0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
|
||||
0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
|
||||
0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
|
||||
0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
|
||||
0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
|
||||
0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
|
||||
0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
|
||||
0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
|
||||
0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
|
||||
0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
|
||||
0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
|
||||
0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
|
||||
0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
|
||||
0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
|
||||
0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
|
||||
0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
|
||||
0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
|
||||
0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
|
||||
0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
|
||||
0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
|
||||
0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
|
||||
0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
|
||||
0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A },
|
||||
{ 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
|
||||
0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
|
||||
0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
|
||||
0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
|
||||
0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
|
||||
0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
|
||||
0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
|
||||
0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
|
||||
0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
|
||||
0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
|
||||
0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
|
||||
0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
|
||||
0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
|
||||
0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
|
||||
0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
|
||||
0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
|
||||
0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
|
||||
0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
|
||||
0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
|
||||
0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
|
||||
0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
|
||||
0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
|
||||
0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
|
||||
0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
|
||||
0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
|
||||
0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
|
||||
0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
|
||||
0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
|
||||
0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
|
||||
0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
|
||||
0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
|
||||
0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
|
||||
0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
|
||||
0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
|
||||
0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
|
||||
0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
|
||||
0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
|
||||
0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
|
||||
0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
|
||||
0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
|
||||
0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
|
||||
0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
|
||||
0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
|
||||
0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
|
||||
0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
|
||||
0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
|
||||
0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
|
||||
0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
|
||||
0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
|
||||
0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
|
||||
0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
|
||||
0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
|
||||
0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
|
||||
0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
|
||||
0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
|
||||
0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
|
||||
0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
|
||||
0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
|
||||
0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
|
||||
0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
|
||||
0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
|
||||
0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
|
||||
0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
|
||||
0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7 },
|
||||
{ 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
|
||||
0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
|
||||
0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
|
||||
0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
|
||||
0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
|
||||
0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
|
||||
0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
|
||||
0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
|
||||
0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
|
||||
0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
|
||||
0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
|
||||
0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
|
||||
0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
|
||||
0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
|
||||
0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
|
||||
0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
|
||||
0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
|
||||
0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
|
||||
0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
|
||||
0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
|
||||
0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
|
||||
0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
|
||||
0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
|
||||
0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
|
||||
0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
|
||||
0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
|
||||
0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
|
||||
0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
|
||||
0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
|
||||
0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
|
||||
0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
|
||||
0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
|
||||
0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
|
||||
0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
|
||||
0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
|
||||
0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
|
||||
0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
|
||||
0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
|
||||
0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
|
||||
0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
|
||||
0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
|
||||
0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
|
||||
0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
|
||||
0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
|
||||
0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
|
||||
0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
|
||||
0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
|
||||
0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
|
||||
0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
|
||||
0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
|
||||
0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
|
||||
0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
|
||||
0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
|
||||
0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
|
||||
0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
|
||||
0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
|
||||
0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
|
||||
0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
|
||||
0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
|
||||
0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
|
||||
0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
|
||||
0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
|
||||
0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
|
||||
0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0 },
|
||||
{ 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
|
||||
0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
|
||||
0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
|
||||
0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
|
||||
0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
|
||||
0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
|
||||
0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
|
||||
0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
|
||||
0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
|
||||
0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
|
||||
0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
|
||||
0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
|
||||
0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
|
||||
0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
|
||||
0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
|
||||
0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
|
||||
0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
|
||||
0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
|
||||
0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
|
||||
0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
|
||||
0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
|
||||
0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
|
||||
0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
|
||||
0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
|
||||
0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
|
||||
0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
|
||||
0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
|
||||
0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
|
||||
0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
|
||||
0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
|
||||
0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
|
||||
0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
|
||||
0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
|
||||
0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
|
||||
0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
|
||||
0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
|
||||
0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
|
||||
0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
|
||||
0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
|
||||
0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
|
||||
0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
|
||||
0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
|
||||
0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
|
||||
0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
|
||||
0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
|
||||
0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
|
||||
0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
|
||||
0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
|
||||
0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
|
||||
0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
|
||||
0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
|
||||
0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
|
||||
0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
|
||||
0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
|
||||
0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
|
||||
0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
|
||||
0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
|
||||
0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
|
||||
0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
|
||||
0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
|
||||
0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
|
||||
0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
|
||||
0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
|
||||
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 }
|
||||
};
|
||||
|
||||
#define F(Xl, Xr, P) \
|
||||
Xr ^=((( ctx->s[0][ Xl >> 24 ] \
|
||||
+ ctx->s[1][(Xl >> 16) & 0xFF])\
|
||||
^ ctx->s[2][(Xl >> 8) & 0xFF])\
|
||||
+ ctx->s[3][ Xl & 0xFF])\
|
||||
^ P;
|
||||
|
||||
av_cold void av_blowfish_init(AVBlowfish *ctx, const uint8_t *key, int key_len)
|
||||
{
|
||||
uint32_t data, data_l, data_r;
|
||||
int i, j, k;
|
||||
|
||||
memcpy(ctx->s, orig_s, sizeof(orig_s));
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < AV_BF_ROUNDS + 2; ++i) {
|
||||
data = 0;
|
||||
for (k = 0; k < 4; k++) {
|
||||
data = (data << 8) | key[j];
|
||||
if (++j >= key_len)
|
||||
j = 0;
|
||||
}
|
||||
ctx->p[i] = orig_p[i] ^ data;
|
||||
}
|
||||
|
||||
data_l = data_r = 0;
|
||||
|
||||
for (i = 0; i < AV_BF_ROUNDS + 2; i += 2) {
|
||||
av_blowfish_crypt_ecb(ctx, &data_l, &data_r, 0);
|
||||
ctx->p[i] = data_l;
|
||||
ctx->p[i + 1] = data_r;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
for (j = 0; j < 256; j += 2) {
|
||||
av_blowfish_crypt_ecb(ctx, &data_l, &data_r, 0);
|
||||
ctx->s[i][j] = data_l;
|
||||
ctx->s[i][j + 1] = data_r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void av_blowfish_crypt_ecb(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr,
|
||||
int decrypt)
|
||||
{
|
||||
uint32_t Xl, Xr;
|
||||
int i;
|
||||
|
||||
Xl = *xl;
|
||||
Xr = *xr;
|
||||
|
||||
if (decrypt) {
|
||||
Xl ^= ctx->p[AV_BF_ROUNDS + 1];
|
||||
for (i = AV_BF_ROUNDS; i > 0; i-=2) {
|
||||
F(Xl, Xr, ctx->p[i ]);
|
||||
F(Xr, Xl, ctx->p[i-1]);
|
||||
}
|
||||
|
||||
Xr ^= ctx->p[0];
|
||||
} else {
|
||||
Xl ^= ctx->p[0];
|
||||
for (i = 1; i < AV_BF_ROUNDS+1; i+=2){
|
||||
F(Xl, Xr, ctx->p[i ]);
|
||||
F(Xr, Xl, ctx->p[i+1]);
|
||||
}
|
||||
|
||||
Xr ^= ctx->p[AV_BF_ROUNDS + 1];
|
||||
}
|
||||
|
||||
*xl = Xr;
|
||||
*xr = Xl;
|
||||
}
|
||||
|
||||
void av_blowfish_crypt(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
|
||||
int count, uint8_t *iv, int decrypt)
|
||||
{
|
||||
uint32_t v0, v1;
|
||||
int i;
|
||||
|
||||
if (decrypt) {
|
||||
while (count--) {
|
||||
v0 = AV_RB32(src);
|
||||
v1 = AV_RB32(src + 4);
|
||||
|
||||
av_blowfish_crypt_ecb(ctx, &v0, &v1, decrypt);
|
||||
|
||||
if (iv) {
|
||||
v0 ^= AV_RB32(iv);
|
||||
v1 ^= AV_RB32(iv + 4);
|
||||
memcpy(iv, src, 8);
|
||||
}
|
||||
|
||||
AV_WB32(dst, v0);
|
||||
AV_WB32(dst + 4, v1);
|
||||
|
||||
src += 8;
|
||||
dst += 8;
|
||||
}
|
||||
} else {
|
||||
while (count--) {
|
||||
if (iv) {
|
||||
for (i = 0; i < 8; i++)
|
||||
dst[i] = src[i] ^ iv[i];
|
||||
v0 = AV_RB32(dst);
|
||||
v1 = AV_RB32(dst + 4);
|
||||
} else {
|
||||
v0 = AV_RB32(src);
|
||||
v1 = AV_RB32(src + 4);
|
||||
}
|
||||
|
||||
av_blowfish_crypt_ecb(ctx, &v0, &v1, decrypt);
|
||||
|
||||
AV_WB32(dst, v0);
|
||||
AV_WB32(dst + 4, v1);
|
||||
|
||||
if (iv)
|
||||
memcpy(iv, dst, 8);
|
||||
|
||||
src += 8;
|
||||
dst += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
|
||||
#define NUM_VARIABLE_KEY_TESTS 34
|
||||
|
||||
/* plaintext bytes -- left halves */
|
||||
static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = {
|
||||
0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111,
|
||||
0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8,
|
||||
0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0,
|
||||
0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18,
|
||||
0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577,
|
||||
0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567,
|
||||
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
|
||||
};
|
||||
|
||||
/* plaintext bytes -- right halves */
|
||||
static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = {
|
||||
0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111,
|
||||
0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA,
|
||||
0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2,
|
||||
0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA,
|
||||
0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A,
|
||||
0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF,
|
||||
0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
|
||||
};
|
||||
|
||||
/* key bytes for variable key tests */
|
||||
static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
|
||||
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
|
||||
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
|
||||
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
|
||||
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
|
||||
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
|
||||
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
|
||||
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
|
||||
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
|
||||
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
|
||||
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
|
||||
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
|
||||
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
|
||||
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
|
||||
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
|
||||
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
|
||||
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
|
||||
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
|
||||
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
|
||||
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
|
||||
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
|
||||
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
|
||||
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
|
||||
};
|
||||
|
||||
/* ciphertext bytes -- left halves */
|
||||
static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = {
|
||||
0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380,
|
||||
0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B,
|
||||
0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7,
|
||||
0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B,
|
||||
0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A,
|
||||
0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D,
|
||||
0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C
|
||||
};
|
||||
|
||||
/* ciphertext bytes -- right halves */
|
||||
static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = {
|
||||
0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096,
|
||||
0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0,
|
||||
0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98,
|
||||
0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B,
|
||||
0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5,
|
||||
0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D,
|
||||
0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A
|
||||
};
|
||||
|
||||
/* plaintext bytes */
|
||||
static const uint8_t plaintext[8] = "BLOWFISH";
|
||||
|
||||
static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH";
|
||||
|
||||
/* ciphertext bytes */
|
||||
static const uint8_t ciphertext[8] = {
|
||||
0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03
|
||||
};
|
||||
|
||||
static const uint8_t ciphertext2[16] = {
|
||||
0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99,
|
||||
0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1,
|
||||
};
|
||||
|
||||
#define IV "blowfish"
|
||||
|
||||
static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
|
||||
const uint8_t *ref, int len, uint8_t *iv, int dir,
|
||||
const char *test)
|
||||
{
|
||||
av_blowfish_crypt(ctx, dst, src, len, iv, dir);
|
||||
if (memcmp(dst, ref, 8*len)) {
|
||||
int i;
|
||||
printf("%s failed\ngot ", test);
|
||||
for (i = 0; i < 8*len; i++)
|
||||
printf("%02x ", dst[i]);
|
||||
printf("\nexpected ");
|
||||
for (i = 0; i < 8*len; i++)
|
||||
printf("%02x ", ref[i]);
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVBlowfish ctx;
|
||||
uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
|
||||
uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
|
||||
uint8_t tmp[16], iv[8];
|
||||
int i;
|
||||
|
||||
av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
|
||||
|
||||
test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption");
|
||||
test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption");
|
||||
test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption");
|
||||
test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption");
|
||||
memcpy(iv, IV, 8);
|
||||
test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption");
|
||||
memcpy(iv, IV, 8);
|
||||
test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption");
|
||||
memcpy(iv, IV, 8);
|
||||
test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption");
|
||||
memcpy(iv, IV, 8);
|
||||
test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption");
|
||||
|
||||
memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS);
|
||||
memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS);
|
||||
|
||||
for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
|
||||
av_blowfish_init(&ctx, variable_key[i], 8);
|
||||
|
||||
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0);
|
||||
if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) {
|
||||
printf("Test encryption failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1);
|
||||
if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) {
|
||||
printf("Test decryption failed.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("Test encryption/decryption success.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
77
project/jni/ffmpeg/libavutil/blowfish.h
Normal file
77
project/jni/ffmpeg/libavutil/blowfish.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Blowfish algorithm
|
||||
* Copyright (c) 2012 Samuel Pitoiset
|
||||
*
|
||||
* 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 AVUTIL_BLOWFISH_H
|
||||
#define AVUTIL_BLOWFISH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @defgroup lavu_blowfish Blowfish
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define AV_BF_ROUNDS 16
|
||||
|
||||
typedef struct AVBlowfish {
|
||||
uint32_t p[AV_BF_ROUNDS + 2];
|
||||
uint32_t s[4][256];
|
||||
} AVBlowfish;
|
||||
|
||||
/**
|
||||
* Initialize an AVBlowfish context.
|
||||
*
|
||||
* @param ctx an AVBlowfish context
|
||||
* @param key a key
|
||||
* @param key_len length of the key
|
||||
*/
|
||||
void av_blowfish_init(struct AVBlowfish *ctx, const uint8_t *key, int key_len);
|
||||
|
||||
/**
|
||||
* Encrypt or decrypt a buffer using a previously initialized context.
|
||||
*
|
||||
* @param ctx an AVBlowfish context
|
||||
* @param xl left four bytes halves of input to be encrypted
|
||||
* @param xr right four bytes halves of input to be encrypted
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
void av_blowfish_crypt_ecb(struct AVBlowfish *ctx, uint32_t *xl, uint32_t *xr,
|
||||
int decrypt);
|
||||
|
||||
/**
|
||||
* Encrypt or decrypt a buffer using a previously initialized context.
|
||||
*
|
||||
* @param ctx an AVBlowfish context
|
||||
* @param dst destination array, can be equal to src
|
||||
* @param src source array, can be equal to dst
|
||||
* @param count number of 8 byte blocks
|
||||
* @param iv initialization vector for CBC mode, if NULL ECB will be used
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
void av_blowfish_crypt(struct AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
|
||||
int count, uint8_t *iv, int decrypt);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_BLOWFISH_H */
|
||||
294
project/jni/ffmpeg/libavutil/bprint.c
Normal file
294
project/jni/ffmpeg/libavutil/bprint.c
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Nicolas George
|
||||
*
|
||||
* 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 <time.h>
|
||||
#include "avassert.h"
|
||||
#include "bprint.h"
|
||||
#include "common.h"
|
||||
#include "error.h"
|
||||
#include "mem.h"
|
||||
|
||||
#define av_bprint_room(buf) ((buf)->size - FFMIN((buf)->len, (buf)->size))
|
||||
#define av_bprint_is_allocated(buf) ((buf)->str != (buf)->reserved_internal_buffer)
|
||||
|
||||
static int av_bprint_alloc(AVBPrint *buf, unsigned room)
|
||||
{
|
||||
char *old_str, *new_str;
|
||||
unsigned min_size, new_size;
|
||||
|
||||
if (buf->size == buf->size_max)
|
||||
return AVERROR(EIO);
|
||||
if (!av_bprint_is_complete(buf))
|
||||
return AVERROR_INVALIDDATA; /* it is already truncated anyway */
|
||||
min_size = buf->len + 1 + FFMIN(UINT_MAX - buf->len - 1, room);
|
||||
new_size = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
|
||||
if (new_size < min_size)
|
||||
new_size = FFMIN(buf->size_max, min_size);
|
||||
old_str = av_bprint_is_allocated(buf) ? buf->str : NULL;
|
||||
new_str = av_realloc(old_str, new_size);
|
||||
if (!new_str)
|
||||
return AVERROR(ENOMEM);
|
||||
if (!old_str)
|
||||
memcpy(new_str, buf->str, buf->len + 1);
|
||||
buf->str = new_str;
|
||||
buf->size = new_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void av_bprint_grow(AVBPrint *buf, unsigned extra_len)
|
||||
{
|
||||
/* arbitrary margin to avoid small overflows */
|
||||
extra_len = FFMIN(extra_len, UINT_MAX - 5 - buf->len);
|
||||
buf->len += extra_len;
|
||||
if (buf->size)
|
||||
buf->str[FFMIN(buf->len, buf->size - 1)] = 0;
|
||||
}
|
||||
|
||||
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
|
||||
{
|
||||
unsigned size_auto = (char *)buf + sizeof(*buf) -
|
||||
buf->reserved_internal_buffer;
|
||||
|
||||
if (size_max == 1)
|
||||
size_max = size_auto;
|
||||
buf->str = buf->reserved_internal_buffer;
|
||||
buf->len = 0;
|
||||
buf->size = FFMIN(size_auto, size_max);
|
||||
buf->size_max = size_max;
|
||||
*buf->str = 0;
|
||||
if (size_init > buf->size)
|
||||
av_bprint_alloc(buf, size_init - 1);
|
||||
}
|
||||
|
||||
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
|
||||
{
|
||||
buf->str = buffer;
|
||||
buf->len = 0;
|
||||
buf->size = size;
|
||||
buf->size_max = size;
|
||||
*buf->str = 0;
|
||||
}
|
||||
|
||||
void av_bprintf(AVBPrint *buf, const char *fmt, ...)
|
||||
{
|
||||
unsigned room;
|
||||
char *dst;
|
||||
va_list vl;
|
||||
int extra_len;
|
||||
|
||||
while (1) {
|
||||
room = av_bprint_room(buf);
|
||||
dst = room ? buf->str + buf->len : NULL;
|
||||
va_start(vl, fmt);
|
||||
extra_len = vsnprintf(dst, room, fmt, vl);
|
||||
va_end(vl);
|
||||
if (extra_len <= 0)
|
||||
return;
|
||||
if (extra_len < room)
|
||||
break;
|
||||
if (av_bprint_alloc(buf, extra_len))
|
||||
break;
|
||||
}
|
||||
av_bprint_grow(buf, extra_len);
|
||||
}
|
||||
|
||||
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
|
||||
{
|
||||
unsigned room, real_n;
|
||||
|
||||
while (1) {
|
||||
room = av_bprint_room(buf);
|
||||
if (n < room)
|
||||
break;
|
||||
if (av_bprint_alloc(buf, n))
|
||||
break;
|
||||
}
|
||||
if (room) {
|
||||
real_n = FFMIN(n, room - 1);
|
||||
memset(buf->str + buf->len, c, real_n);
|
||||
}
|
||||
av_bprint_grow(buf, n);
|
||||
}
|
||||
|
||||
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm)
|
||||
{
|
||||
unsigned room;
|
||||
size_t l;
|
||||
|
||||
if (!*fmt)
|
||||
return;
|
||||
while (1) {
|
||||
room = av_bprint_room(buf);
|
||||
if (room && (l = strftime(buf->str + buf->len, room, fmt, tm)))
|
||||
break;
|
||||
/* strftime does not tell us how much room it would need: let us
|
||||
retry with twice as much until the buffer is large enough */
|
||||
room = !room ? strlen(fmt) + 1 :
|
||||
room <= INT_MAX / 2 ? room * 2 : INT_MAX;
|
||||
if (av_bprint_alloc(buf, room)) {
|
||||
/* impossible to grow, try to manage something useful anyway */
|
||||
room = av_bprint_room(buf);
|
||||
if (room < 1024) {
|
||||
/* if strftime fails because the buffer has (almost) reached
|
||||
its maximum size, let us try in a local buffer; 1k should
|
||||
be enough to format any real date+time string */
|
||||
char buf2[1024];
|
||||
if ((l = strftime(buf2, sizeof(buf2), fmt, tm))) {
|
||||
av_bprintf(buf, "%s", buf2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (room) {
|
||||
/* if anything else failed and the buffer is not already
|
||||
truncated, let us add a stock string and force truncation */
|
||||
static const char txt[] = "[truncated strftime output]";
|
||||
memset(buf->str + buf->len, '!', room);
|
||||
memcpy(buf->str + buf->len, txt, FFMIN(sizeof(txt) - 1, room));
|
||||
av_bprint_grow(buf, room); /* force truncation */
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
av_bprint_grow(buf, l);
|
||||
}
|
||||
|
||||
void av_bprint_get_buffer(AVBPrint *buf, unsigned size,
|
||||
unsigned char **mem, unsigned *actual_size)
|
||||
{
|
||||
if (size > av_bprint_room(buf))
|
||||
av_bprint_alloc(buf, size);
|
||||
*actual_size = av_bprint_room(buf);
|
||||
*mem = *actual_size ? buf->str + buf->len : NULL;
|
||||
}
|
||||
|
||||
void av_bprint_clear(AVBPrint *buf)
|
||||
{
|
||||
if (buf->len) {
|
||||
*buf->str = 0;
|
||||
buf->len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
|
||||
{
|
||||
unsigned real_size = FFMIN(buf->len + 1, buf->size);
|
||||
char *str;
|
||||
int ret = 0;
|
||||
|
||||
if (ret_str) {
|
||||
if (av_bprint_is_allocated(buf)) {
|
||||
str = av_realloc(buf->str, real_size);
|
||||
if (!str)
|
||||
str = buf->str;
|
||||
buf->str = NULL;
|
||||
} else {
|
||||
str = av_malloc(real_size);
|
||||
if (str)
|
||||
memcpy(str, buf->str, real_size);
|
||||
else
|
||||
ret = AVERROR(ENOMEM);
|
||||
}
|
||||
*ret_str = str;
|
||||
} else {
|
||||
if (av_bprint_is_allocated(buf))
|
||||
av_freep(&buf->str);
|
||||
}
|
||||
buf->size = real_size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#undef printf
|
||||
|
||||
static void bprint_pascal(AVBPrint *b, unsigned size)
|
||||
{
|
||||
unsigned i, j;
|
||||
unsigned p[42];
|
||||
|
||||
av_assert0(size < FF_ARRAY_ELEMS(p));
|
||||
|
||||
p[0] = 1;
|
||||
av_bprintf(b, "%8d\n", 1);
|
||||
for (i = 1; i <= size; i++) {
|
||||
p[i] = 1;
|
||||
for (j = i - 1; j > 0; j--)
|
||||
p[j] = p[j] + p[j - 1];
|
||||
for (j = 0; j <= i; j++)
|
||||
av_bprintf(b, "%8d", p[j]);
|
||||
av_bprintf(b, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVBPrint b;
|
||||
char buf[256];
|
||||
struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
|
||||
|
||||
av_bprint_init(&b, 0, -1);
|
||||
bprint_pascal(&b, 5);
|
||||
printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
|
||||
printf("%s\n", b.str);
|
||||
av_bprint_finalize(&b, NULL);
|
||||
|
||||
av_bprint_init(&b, 0, -1);
|
||||
bprint_pascal(&b, 25);
|
||||
printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
|
||||
av_bprint_finalize(&b, NULL);
|
||||
|
||||
av_bprint_init(&b, 0, 2048);
|
||||
bprint_pascal(&b, 25);
|
||||
printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
|
||||
av_bprint_finalize(&b, NULL);
|
||||
|
||||
av_bprint_init(&b, 0, 1);
|
||||
bprint_pascal(&b, 5);
|
||||
printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
|
||||
|
||||
av_bprint_init(&b, 0, 1);
|
||||
bprint_pascal(&b, 25);
|
||||
printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len);
|
||||
/* Note that the size of the automatic buffer is arch-dependant. */
|
||||
|
||||
av_bprint_init(&b, 0, 0);
|
||||
bprint_pascal(&b, 25);
|
||||
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
|
||||
|
||||
av_bprint_init_for_buffer(&b, buf, sizeof(buf));
|
||||
bprint_pascal(&b, 25);
|
||||
printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len);
|
||||
|
||||
av_bprint_init(&b, 0, -1);
|
||||
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
|
||||
printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
|
||||
av_bprint_finalize(&b, NULL);
|
||||
|
||||
av_bprint_init(&b, 0, 8);
|
||||
av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
|
||||
printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
183
project/jni/ffmpeg/libavutil/bprint.h
Normal file
183
project/jni/ffmpeg/libavutil/bprint.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Nicolas George
|
||||
*
|
||||
* 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 AVUTIL_BPRINT_H
|
||||
#define AVUTIL_BPRINT_H
|
||||
|
||||
#include "attributes.h"
|
||||
|
||||
/**
|
||||
* Define a structure with extra padding to a fixed size
|
||||
* This helps ensuring binary compatibility with future versions.
|
||||
*/
|
||||
#define FF_PAD_STRUCTURE(size, ...) \
|
||||
__VA_ARGS__ \
|
||||
char reserved_padding[size - sizeof(struct { __VA_ARGS__ })];
|
||||
|
||||
/**
|
||||
* Buffer to print data progressively
|
||||
*
|
||||
* The string buffer grows as necessary and is always 0-terminated.
|
||||
* The content of the string is never accessed, and thus is
|
||||
* encoding-agnostic and can even hold binary data.
|
||||
*
|
||||
* Small buffers are kept in the structure itself, and thus require no
|
||||
* memory allocation at all (unless the contents of the buffer is needed
|
||||
* after the structure goes out of scope). This is almost as lightweight as
|
||||
* declaring a local "char buf[512]".
|
||||
*
|
||||
* The length of the string can go beyond the allocated size: the buffer is
|
||||
* then truncated, but the functions still keep account of the actual total
|
||||
* length.
|
||||
*
|
||||
* In other words, buf->len can be greater than buf->size and records the
|
||||
* total length of what would have been to the buffer if there had been
|
||||
* enough memory.
|
||||
*
|
||||
* Append operations do not need to be tested for failure: if a memory
|
||||
* allocation fails, data stop being appended to the buffer, but the length
|
||||
* is still updated. This situation can be tested with
|
||||
* av_bprint_is_complete().
|
||||
*
|
||||
* The size_max field determines several possible behaviours:
|
||||
*
|
||||
* size_max = -1 (= UINT_MAX) or any large value will let the buffer be
|
||||
* reallocated as necessary, with an amortized linear cost.
|
||||
*
|
||||
* size_max = 0 prevents writing anything to the buffer: only the total
|
||||
* length is computed. The write operations can then possibly be repeated in
|
||||
* a buffer with exactly the necessary size
|
||||
* (using size_init = size_max = len + 1).
|
||||
*
|
||||
* size_max = 1 is automatically replaced by the exact size available in the
|
||||
* structure itself, thus ensuring no dynamic memory allocation. The
|
||||
* internal buffer is large enough to hold a reasonable paragraph of text,
|
||||
* such as the current paragraph.
|
||||
*/
|
||||
typedef struct AVBPrint {
|
||||
FF_PAD_STRUCTURE(1024,
|
||||
char *str; /** string so far */
|
||||
unsigned len; /** length so far */
|
||||
unsigned size; /** allocated memory */
|
||||
unsigned size_max; /** maximum allocated memory */
|
||||
char reserved_internal_buffer[1];
|
||||
)
|
||||
} AVBPrint;
|
||||
|
||||
/**
|
||||
* Convenience macros for special values for av_bprint_init() size_max
|
||||
* parameter.
|
||||
*/
|
||||
#define AV_BPRINT_SIZE_UNLIMITED ((unsigned)-1)
|
||||
#define AV_BPRINT_SIZE_AUTOMATIC 1
|
||||
#define AV_BPRINT_SIZE_COUNT_ONLY 0
|
||||
|
||||
/**
|
||||
* Init a print buffer.
|
||||
*
|
||||
* @param buf buffer to init
|
||||
* @param size_init initial size (including the final 0)
|
||||
* @param size_max maximum size;
|
||||
* 0 means do not write anything, just count the length;
|
||||
* 1 is replaced by the maximum value for automatic storage;
|
||||
* any large value means that the internal buffer will be
|
||||
* reallocated as needed up to that limit; -1 is converted to
|
||||
* UINT_MAX, the largest limit possible.
|
||||
* Check also AV_BPRINT_SIZE_* macros.
|
||||
*/
|
||||
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max);
|
||||
|
||||
/**
|
||||
* Init a print buffer using a pre-existing buffer.
|
||||
*
|
||||
* The buffer will not be reallocated.
|
||||
*
|
||||
* @param buf buffer structure to init
|
||||
* @param buffer byte buffer to use for the string data
|
||||
* @param size size of buffer
|
||||
*/
|
||||
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size);
|
||||
|
||||
/**
|
||||
* Append a formatted string to a print buffer.
|
||||
*/
|
||||
void av_bprintf(AVBPrint *buf, const char *fmt, ...) av_printf_format(2, 3);
|
||||
|
||||
/**
|
||||
* Append char c n times to a print buffer.
|
||||
*/
|
||||
void av_bprint_chars(AVBPrint *buf, char c, unsigned n);
|
||||
|
||||
struct tm;
|
||||
/**
|
||||
* Append a formatted date and time to a print buffer.
|
||||
*
|
||||
* param buf bprint buffer to use
|
||||
* param fmt date and time format string, see strftime()
|
||||
* param tm broken-down time structure to translate
|
||||
*
|
||||
* @note due to poor design of the standard strftime function, it may
|
||||
* produce poor results if the format string expands to a very long text and
|
||||
* the bprint buffer is near the limit stated by the size_max option.
|
||||
*/
|
||||
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm);
|
||||
|
||||
/**
|
||||
* Allocate bytes in the buffer for external use.
|
||||
*
|
||||
* @param[in] buf buffer structure
|
||||
* @param[in] size required size
|
||||
* @param[out] mem pointer to the memory area
|
||||
* @param[out] actual_size size of the memory area after allocation;
|
||||
* can be larger or smaller than size
|
||||
*/
|
||||
void av_bprint_get_buffer(AVBPrint *buf, unsigned size,
|
||||
unsigned char **mem, unsigned *actual_size);
|
||||
|
||||
/**
|
||||
* Reset the string to "" but keep internal allocated data.
|
||||
*/
|
||||
void av_bprint_clear(AVBPrint *buf);
|
||||
|
||||
/**
|
||||
* Test if the print buffer is complete (not truncated).
|
||||
*
|
||||
* It may have been truncated due to a memory allocation failure
|
||||
* or the size_max limit (compare size and size_max if necessary).
|
||||
*/
|
||||
static inline int av_bprint_is_complete(AVBPrint *buf)
|
||||
{
|
||||
return buf->len < buf->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize a print buffer.
|
||||
*
|
||||
* The print buffer can no longer be used afterwards,
|
||||
* but the len and size fields are still valid.
|
||||
*
|
||||
* @arg[out] ret_str if not NULL, used to return a permanent copy of the
|
||||
* buffer contents, or NULL if memory allocation fails;
|
||||
* if NULL, the buffer is discarded and freed
|
||||
* @return 0 for success or error code (probably AVERROR(ENOMEM))
|
||||
*/
|
||||
int av_bprint_finalize(AVBPrint *buf, char **ret_str);
|
||||
|
||||
#endif /* AVUTIL_BPRINT_H */
|
||||
109
project/jni/ffmpeg/libavutil/bswap.h
Normal file
109
project/jni/ffmpeg/libavutil/bswap.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_BSWAP_H
|
||||
#define AVUTIL_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/avconfig.h"
|
||||
#include "attributes.h"
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if ARCH_ARM
|
||||
# include "arm/bswap.h"
|
||||
#elif ARCH_AVR32
|
||||
# include "avr32/bswap.h"
|
||||
#elif ARCH_BFIN
|
||||
# include "bfin/bswap.h"
|
||||
#elif ARCH_SH4
|
||||
# include "sh4/bswap.h"
|
||||
#elif ARCH_X86
|
||||
# include "x86/bswap.h"
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
#define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff))
|
||||
#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
|
||||
#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
|
||||
|
||||
#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
|
||||
|
||||
#ifndef av_bswap16
|
||||
static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
|
||||
{
|
||||
x= (x>>8) | (x<<8);
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef av_bswap32
|
||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||
{
|
||||
return AV_BSWAP32C(x);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef av_bswap64
|
||||
static inline uint64_t av_const av_bswap64(uint64_t x)
|
||||
{
|
||||
return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
|
||||
}
|
||||
#endif
|
||||
|
||||
// be2ne ... big-endian to native-endian
|
||||
// le2ne ... little-endian to native-endian
|
||||
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
#define av_be2ne16(x) (x)
|
||||
#define av_be2ne32(x) (x)
|
||||
#define av_be2ne64(x) (x)
|
||||
#define av_le2ne16(x) av_bswap16(x)
|
||||
#define av_le2ne32(x) av_bswap32(x)
|
||||
#define av_le2ne64(x) av_bswap64(x)
|
||||
#define AV_BE2NEC(s, x) (x)
|
||||
#define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
|
||||
#else
|
||||
#define av_be2ne16(x) av_bswap16(x)
|
||||
#define av_be2ne32(x) av_bswap32(x)
|
||||
#define av_be2ne64(x) av_bswap64(x)
|
||||
#define av_le2ne16(x) (x)
|
||||
#define av_le2ne32(x) (x)
|
||||
#define av_le2ne64(x) (x)
|
||||
#define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
|
||||
#define AV_LE2NEC(s, x) (x)
|
||||
#endif
|
||||
|
||||
#define AV_BE2NE16C(x) AV_BE2NEC(16, x)
|
||||
#define AV_BE2NE32C(x) AV_BE2NEC(32, x)
|
||||
#define AV_BE2NE64C(x) AV_BE2NEC(64, x)
|
||||
#define AV_LE2NE16C(x) AV_LE2NEC(16, x)
|
||||
#define AV_LE2NE32C(x) AV_LE2NEC(32, x)
|
||||
#define AV_LE2NE64C(x) AV_LE2NEC(64, x)
|
||||
|
||||
#endif /* AVUTIL_BSWAP_H */
|
||||
257
project/jni/ffmpeg/libavutil/channel_layout.c
Normal file
257
project/jni/ffmpeg/libavutil/channel_layout.c
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* 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
|
||||
* audio channel layout utility functions
|
||||
*/
|
||||
|
||||
#include "avstring.h"
|
||||
#include "avutil.h"
|
||||
#include "channel_layout.h"
|
||||
#include "bprint.h"
|
||||
#include "common.h"
|
||||
|
||||
struct channel_name {
|
||||
const char *name;
|
||||
const char *description;
|
||||
};
|
||||
|
||||
static const struct channel_name channel_names[] = {
|
||||
[0] = { "FL", "front left" },
|
||||
[1] = { "FR", "front right" },
|
||||
[2] = { "FC", "front center" },
|
||||
[3] = { "LFE", "low frequency" },
|
||||
[4] = { "BL", "back left" },
|
||||
[5] = { "BR", "back right" },
|
||||
[6] = { "FLC", "front left-of-center" },
|
||||
[7] = { "FRC", "front right-of-center" },
|
||||
[8] = { "BC", "back center" },
|
||||
[9] = { "SL", "side left" },
|
||||
[10] = { "SR", "side right" },
|
||||
[11] = { "TC", "top center" },
|
||||
[12] = { "TFL", "top front left" },
|
||||
[13] = { "TFC", "top front center" },
|
||||
[14] = { "TFR", "top front right" },
|
||||
[15] = { "TBL", "top back left" },
|
||||
[16] = { "TBC", "top back center" },
|
||||
[17] = { "TBR", "top back right" },
|
||||
[29] = { "DL", "downmix left" },
|
||||
[30] = { "DR", "downmix right" },
|
||||
[31] = { "WL", "wide left" },
|
||||
[32] = { "WR", "wide right" },
|
||||
[33] = { "SDL", "surround direct left" },
|
||||
[34] = { "SDR", "surround direct right" },
|
||||
[35] = { "LFE2", "low frequency 2" },
|
||||
};
|
||||
|
||||
static const char *get_channel_name(int channel_id)
|
||||
{
|
||||
if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
|
||||
return NULL;
|
||||
return channel_names[channel_id].name;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
int nb_channels;
|
||||
uint64_t layout;
|
||||
} channel_layout_map[] = {
|
||||
{ "mono", 1, AV_CH_LAYOUT_MONO },
|
||||
{ "stereo", 2, AV_CH_LAYOUT_STEREO },
|
||||
{ "2.1", 3, AV_CH_LAYOUT_2POINT1 },
|
||||
{ "3.0", 3, AV_CH_LAYOUT_SURROUND },
|
||||
{ "3.0(back)", 3, AV_CH_LAYOUT_2_1 },
|
||||
{ "4.0", 4, AV_CH_LAYOUT_4POINT0 },
|
||||
{ "quad", 4, AV_CH_LAYOUT_QUAD },
|
||||
{ "quad(side)", 4, AV_CH_LAYOUT_2_2 },
|
||||
{ "3.1", 4, AV_CH_LAYOUT_3POINT1 },
|
||||
{ "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK },
|
||||
{ "5.0(side)", 5, AV_CH_LAYOUT_5POINT0 },
|
||||
{ "4.1", 5, AV_CH_LAYOUT_4POINT1 },
|
||||
{ "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK },
|
||||
{ "5.1(side)", 6, AV_CH_LAYOUT_5POINT1 },
|
||||
{ "6.0", 6, AV_CH_LAYOUT_6POINT0 },
|
||||
{ "6.0(front)", 6, AV_CH_LAYOUT_6POINT0_FRONT },
|
||||
{ "hexagonal", 6, AV_CH_LAYOUT_HEXAGONAL },
|
||||
{ "6.1", 7, AV_CH_LAYOUT_6POINT1 },
|
||||
{ "6.1", 7, AV_CH_LAYOUT_6POINT1_BACK },
|
||||
{ "6.1(front)", 7, AV_CH_LAYOUT_6POINT1_FRONT },
|
||||
{ "7.0", 7, AV_CH_LAYOUT_7POINT0 },
|
||||
{ "7.0(front)", 7, AV_CH_LAYOUT_7POINT0_FRONT },
|
||||
{ "7.1", 8, AV_CH_LAYOUT_7POINT1 },
|
||||
{ "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE },
|
||||
{ "octagonal", 8, AV_CH_LAYOUT_OCTAGONAL },
|
||||
{ "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, },
|
||||
};
|
||||
|
||||
static uint64_t get_channel_layout_single(const char *name, int name_len)
|
||||
{
|
||||
int i;
|
||||
char *end;
|
||||
int64_t layout;
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
|
||||
if (strlen(channel_layout_map[i].name) == name_len &&
|
||||
!memcmp(channel_layout_map[i].name, name, name_len))
|
||||
return channel_layout_map[i].layout;
|
||||
}
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
|
||||
if (channel_names[i].name &&
|
||||
strlen(channel_names[i].name) == name_len &&
|
||||
!memcmp(channel_names[i].name, name, name_len))
|
||||
return (int64_t)1 << i;
|
||||
i = strtol(name, &end, 10);
|
||||
if (end - name == name_len ||
|
||||
(end + 1 - name == name_len && *end == 'c'))
|
||||
return av_get_default_channel_layout(i);
|
||||
layout = strtoll(name, &end, 0);
|
||||
if (end - name == name_len)
|
||||
return FFMAX(layout, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t av_get_channel_layout(const char *name)
|
||||
{
|
||||
const char *n, *e;
|
||||
const char *name_end = name + strlen(name);
|
||||
int64_t layout = 0, layout_single;
|
||||
|
||||
for (n = name; n < name_end; n = e + 1) {
|
||||
for (e = n; e < name_end && *e != '+' && *e != '|'; e++);
|
||||
layout_single = get_channel_layout_single(n, e - n);
|
||||
if (!layout_single)
|
||||
return 0;
|
||||
layout |= layout_single;
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
void av_bprint_channel_layout(struct AVBPrint *bp,
|
||||
int nb_channels, uint64_t channel_layout)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (nb_channels <= 0)
|
||||
nb_channels = av_get_channel_layout_nb_channels(channel_layout);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
|
||||
if (nb_channels == channel_layout_map[i].nb_channels &&
|
||||
channel_layout == channel_layout_map[i].layout) {
|
||||
av_bprintf(bp, "%s", channel_layout_map[i].name);
|
||||
return;
|
||||
}
|
||||
|
||||
av_bprintf(bp, "%d channels", nb_channels);
|
||||
if (channel_layout) {
|
||||
int i, ch;
|
||||
av_bprintf(bp, " (");
|
||||
for (i = 0, ch = 0; i < 64; i++) {
|
||||
if ((channel_layout & (UINT64_C(1) << i))) {
|
||||
const char *name = get_channel_name(i);
|
||||
if (name) {
|
||||
if (ch > 0)
|
||||
av_bprintf(bp, "+");
|
||||
av_bprintf(bp, "%s", name);
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
}
|
||||
av_bprintf(bp, ")");
|
||||
}
|
||||
}
|
||||
|
||||
void av_get_channel_layout_string(char *buf, int buf_size,
|
||||
int nb_channels, uint64_t channel_layout)
|
||||
{
|
||||
AVBPrint bp;
|
||||
|
||||
av_bprint_init_for_buffer(&bp, buf, buf_size);
|
||||
av_bprint_channel_layout(&bp, nb_channels, channel_layout);
|
||||
}
|
||||
|
||||
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
|
||||
{
|
||||
return av_popcount64(channel_layout);
|
||||
}
|
||||
|
||||
int64_t av_get_default_channel_layout(int nb_channels) {
|
||||
int i;
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
|
||||
if (nb_channels == channel_layout_map[i].nb_channels)
|
||||
return channel_layout_map[i].layout;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_get_channel_layout_channel_index(uint64_t channel_layout,
|
||||
uint64_t channel)
|
||||
{
|
||||
if (!(channel_layout & channel) ||
|
||||
av_get_channel_layout_nb_channels(channel) != 1)
|
||||
return AVERROR(EINVAL);
|
||||
channel_layout &= channel - 1;
|
||||
return av_get_channel_layout_nb_channels(channel_layout);
|
||||
}
|
||||
|
||||
const char *av_get_channel_name(uint64_t channel)
|
||||
{
|
||||
int i;
|
||||
if (av_get_channel_layout_nb_channels(channel) != 1)
|
||||
return NULL;
|
||||
for (i = 0; i < 64; i++)
|
||||
if ((1ULL<<i) & channel)
|
||||
return get_channel_name(i);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *av_get_channel_description(uint64_t channel)
|
||||
{
|
||||
int i;
|
||||
if (av_get_channel_layout_nb_channels(channel) != 1)
|
||||
return NULL;
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
|
||||
if ((1ULL<<i) & channel)
|
||||
return channel_names[i].description;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (av_get_channel_layout_nb_channels(channel_layout) <= index)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
if ((1ULL << i) & channel_layout && !index--)
|
||||
return 1ULL << i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
|
||||
const char **name)
|
||||
{
|
||||
if (index >= FF_ARRAY_ELEMS(channel_layout_map))
|
||||
return AVERROR_EOF;
|
||||
if (layout) *layout = channel_layout_map[index].layout;
|
||||
if (name) *name = channel_layout_map[index].name;
|
||||
return 0;
|
||||
}
|
||||
216
project/jni/ffmpeg/libavutil/channel_layout.h
Normal file
216
project/jni/ffmpeg/libavutil/channel_layout.h
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
* Copyright (c) 2008 Peter Ross
|
||||
*
|
||||
* 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 AVUTIL_CHANNEL_LAYOUT_H
|
||||
#define AVUTIL_CHANNEL_LAYOUT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @file
|
||||
* audio channel layout utility functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_audio
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup channel_masks Audio channel masks
|
||||
*
|
||||
* A channel layout is a 64-bits integer with a bit set for every channel.
|
||||
* The number of bits set must be equal to the number of channels.
|
||||
* The value 0 means that the channel layout is not known.
|
||||
* @note this data structure is not powerful enough to handle channels
|
||||
* combinations that have the same channel multiple times, such as
|
||||
* dual-mono.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define AV_CH_FRONT_LEFT 0x00000001
|
||||
#define AV_CH_FRONT_RIGHT 0x00000002
|
||||
#define AV_CH_FRONT_CENTER 0x00000004
|
||||
#define AV_CH_LOW_FREQUENCY 0x00000008
|
||||
#define AV_CH_BACK_LEFT 0x00000010
|
||||
#define AV_CH_BACK_RIGHT 0x00000020
|
||||
#define AV_CH_FRONT_LEFT_OF_CENTER 0x00000040
|
||||
#define AV_CH_FRONT_RIGHT_OF_CENTER 0x00000080
|
||||
#define AV_CH_BACK_CENTER 0x00000100
|
||||
#define AV_CH_SIDE_LEFT 0x00000200
|
||||
#define AV_CH_SIDE_RIGHT 0x00000400
|
||||
#define AV_CH_TOP_CENTER 0x00000800
|
||||
#define AV_CH_TOP_FRONT_LEFT 0x00001000
|
||||
#define AV_CH_TOP_FRONT_CENTER 0x00002000
|
||||
#define AV_CH_TOP_FRONT_RIGHT 0x00004000
|
||||
#define AV_CH_TOP_BACK_LEFT 0x00008000
|
||||
#define AV_CH_TOP_BACK_CENTER 0x00010000
|
||||
#define AV_CH_TOP_BACK_RIGHT 0x00020000
|
||||
#define AV_CH_STEREO_LEFT 0x20000000 ///< Stereo downmix.
|
||||
#define AV_CH_STEREO_RIGHT 0x40000000 ///< See AV_CH_STEREO_LEFT.
|
||||
#define AV_CH_WIDE_LEFT 0x0000000080000000ULL
|
||||
#define AV_CH_WIDE_RIGHT 0x0000000100000000ULL
|
||||
#define AV_CH_SURROUND_DIRECT_LEFT 0x0000000200000000ULL
|
||||
#define AV_CH_SURROUND_DIRECT_RIGHT 0x0000000400000000ULL
|
||||
#define AV_CH_LOW_FREQUENCY_2 0x0000000800000000ULL
|
||||
|
||||
/** Channel mask value used for AVCodecContext.request_channel_layout
|
||||
to indicate that the user requests the channel order of the decoder output
|
||||
to be the native codec channel order. */
|
||||
#define AV_CH_LAYOUT_NATIVE 0x8000000000000000ULL
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @defgroup channel_mask_c Audio channel convenience macros
|
||||
* @{
|
||||
* */
|
||||
#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER)
|
||||
#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT)
|
||||
#define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER)
|
||||
#define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
|
||||
#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
|
||||
#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
|
||||
#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
|
||||
#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_6POINT0_FRONT (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
|
||||
#define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_6POINT1_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER)
|
||||
#define AV_CH_LAYOUT_6POINT1_FRONT (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY)
|
||||
#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
|
||||
#define AV_CH_LAYOUT_7POINT0_FRONT (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
|
||||
#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
|
||||
#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
|
||||
#define AV_CH_LAYOUT_7POINT1_WIDE_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
|
||||
#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)
|
||||
#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
|
||||
|
||||
enum AVMatrixEncoding {
|
||||
AV_MATRIX_ENCODING_NONE,
|
||||
AV_MATRIX_ENCODING_DOLBY,
|
||||
AV_MATRIX_ENCODING_DPLII,
|
||||
AV_MATRIX_ENCODING_NB
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return a channel layout id that matches name, or 0 if no match is found.
|
||||
*
|
||||
* name can be one or several of the following notations,
|
||||
* separated by '+' or '|':
|
||||
* - the name of an usual channel layout (mono, stereo, 4.0, quad, 5.0,
|
||||
* 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix);
|
||||
* - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC,
|
||||
* SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR);
|
||||
* - a number of channels, in decimal, optionally followed by 'c', yielding
|
||||
* the default channel layout for that number of channels (@see
|
||||
* av_get_default_channel_layout);
|
||||
* - a channel layout mask, in hexadecimal starting with "0x" (see the
|
||||
* AV_CH_* macros).
|
||||
*
|
||||
* Example: "stereo+FC" = "2+FC" = "2c+1c" = "0x7"
|
||||
*/
|
||||
uint64_t av_get_channel_layout(const char *name);
|
||||
|
||||
/**
|
||||
* Return a description of a channel layout.
|
||||
* If nb_channels is <= 0, it is guessed from the channel_layout.
|
||||
*
|
||||
* @param buf put here the string containing the channel layout
|
||||
* @param buf_size size in bytes of the buffer
|
||||
*/
|
||||
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout);
|
||||
|
||||
struct AVBPrint;
|
||||
/**
|
||||
* Append a description of a channel layout to a bprint buffer.
|
||||
*/
|
||||
void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout);
|
||||
|
||||
/**
|
||||
* Return the number of channels in the channel layout.
|
||||
*/
|
||||
int av_get_channel_layout_nb_channels(uint64_t channel_layout);
|
||||
|
||||
/**
|
||||
* Return default channel layout for a given number of channels.
|
||||
*/
|
||||
int64_t av_get_default_channel_layout(int nb_channels);
|
||||
|
||||
/**
|
||||
* Get the index of a channel in channel_layout.
|
||||
*
|
||||
* @param channel a channel layout describing exactly one channel which must be
|
||||
* present in channel_layout.
|
||||
*
|
||||
* @return index of channel in channel_layout on success, a negative AVERROR
|
||||
* on error.
|
||||
*/
|
||||
int av_get_channel_layout_channel_index(uint64_t channel_layout,
|
||||
uint64_t channel);
|
||||
|
||||
/**
|
||||
* Get the channel with the given index in channel_layout.
|
||||
*/
|
||||
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index);
|
||||
|
||||
/**
|
||||
* Get the name of a given channel.
|
||||
*
|
||||
* @return channel name on success, NULL on error.
|
||||
*/
|
||||
const char *av_get_channel_name(uint64_t channel);
|
||||
|
||||
/**
|
||||
* Get the description of a given channel.
|
||||
*
|
||||
* @param channel a channel layout with a single channel
|
||||
* @return channel description on success, NULL on error
|
||||
*/
|
||||
const char *av_get_channel_description(uint64_t channel);
|
||||
|
||||
/**
|
||||
* Get the value and name of a standard channel layout.
|
||||
*
|
||||
* @param[in] index index in an internal list, starting at 0
|
||||
* @param[out] layout channel layout mask
|
||||
* @param[out] name name of the layout
|
||||
* @return 0 if the layout exists,
|
||||
* <0 if index is beyond the limits
|
||||
*/
|
||||
int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
|
||||
const char **name);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_CHANNEL_LAYOUT_H */
|
||||
111
project/jni/ffmpeg/libavutil/colorspace.h
Normal file
111
project/jni/ffmpeg/libavutil/colorspace.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Colorspace conversion defines
|
||||
* Copyright (c) 2001, 2002, 2003 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
|
||||
* Various defines for YUV<->RGB conversion
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_COLORSPACE_H
|
||||
#define AVUTIL_COLORSPACE_H
|
||||
|
||||
#define SCALEBITS 10
|
||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
|
||||
|
||||
#define YUV_TO_RGB1_CCIR(cb1, cr1)\
|
||||
{\
|
||||
cb = (cb1) - 128;\
|
||||
cr = (cr1) - 128;\
|
||||
r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
|
||||
g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
|
||||
ONE_HALF;\
|
||||
b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
|
||||
}
|
||||
|
||||
#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
|
||||
{\
|
||||
y = ((y1) - 16) * FIX(255.0/219.0);\
|
||||
r = cm[(y + r_add) >> SCALEBITS];\
|
||||
g = cm[(y + g_add) >> SCALEBITS];\
|
||||
b = cm[(y + b_add) >> SCALEBITS];\
|
||||
}
|
||||
|
||||
#define YUV_TO_RGB1(cb1, cr1)\
|
||||
{\
|
||||
cb = (cb1) - 128;\
|
||||
cr = (cr1) - 128;\
|
||||
r_add = FIX(1.40200) * cr + ONE_HALF;\
|
||||
g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
|
||||
b_add = FIX(1.77200) * cb + ONE_HALF;\
|
||||
}
|
||||
|
||||
#define YUV_TO_RGB2(r, g, b, y1)\
|
||||
{\
|
||||
y = (y1) << SCALEBITS;\
|
||||
r = cm[(y + r_add) >> SCALEBITS];\
|
||||
g = cm[(y + g_add) >> SCALEBITS];\
|
||||
b = cm[(y + b_add) >> SCALEBITS];\
|
||||
}
|
||||
|
||||
#define Y_CCIR_TO_JPEG(y)\
|
||||
cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
|
||||
|
||||
#define Y_JPEG_TO_CCIR(y)\
|
||||
(((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
||||
|
||||
#define C_CCIR_TO_JPEG(y)\
|
||||
cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
|
||||
|
||||
/* NOTE: the clamp is really necessary! */
|
||||
static inline int C_JPEG_TO_CCIR(int y) {
|
||||
y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
|
||||
if (y < 16)
|
||||
y = 16;
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
#define RGB_TO_Y(r, g, b) \
|
||||
((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
|
||||
FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
|
||||
|
||||
#define RGB_TO_U(r1, g1, b1, shift)\
|
||||
(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
|
||||
FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||
|
||||
#define RGB_TO_V(r1, g1, b1, shift)\
|
||||
(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
|
||||
FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||
|
||||
#define RGB_TO_Y_CCIR(r, g, b) \
|
||||
((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
|
||||
FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
|
||||
|
||||
#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
|
||||
(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
|
||||
FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||
|
||||
#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
|
||||
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
|
||||
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
|
||||
|
||||
#endif /* AVUTIL_COLORSPACE_H */
|
||||
437
project/jni/ffmpeg/libavutil/common.h
Normal file
437
project/jni/ffmpeg/libavutil/common.h
Normal file
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* 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 internal and external API header
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_COMMON_H
|
||||
#define AVUTIL_COMMON_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
#include "libavutil/avconfig.h"
|
||||
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
# define AV_NE(be, le) (be)
|
||||
#else
|
||||
# define AV_NE(be, le) (le)
|
||||
#endif
|
||||
|
||||
//rounded division & 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 FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b))
|
||||
#define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,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)
|
||||
#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
|
||||
|
||||
/* misc math functions */
|
||||
|
||||
/**
|
||||
* Reverse the order of the bits of an 8-bits unsigned integer.
|
||||
*/
|
||||
#if FF_API_AV_REVERSE
|
||||
extern attribute_deprecated const uint8_t av_reverse[256];
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "config.h"
|
||||
# include "intmath.h"
|
||||
#endif
|
||||
|
||||
/* Pull in unguarded fallback defines at the end of this file. */
|
||||
#include "common.h"
|
||||
|
||||
#ifndef av_log2
|
||||
av_const int av_log2(unsigned v);
|
||||
#endif
|
||||
|
||||
#ifndef av_log2_16bit
|
||||
av_const int av_log2_16bit(unsigned v);
|
||||
#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 av_always_inline av_const int av_clip_c(int a, int amin, int amax)
|
||||
{
|
||||
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
|
||||
if (amin > amax) abort();
|
||||
#endif
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip a signed 64bit 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 av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax)
|
||||
{
|
||||
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
|
||||
if (amin > amax) abort();
|
||||
#endif
|
||||
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 av_always_inline av_const uint8_t av_clip_uint8_c(int a)
|
||||
{
|
||||
if (a&(~0xFF)) return (-a)>>31;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip a signed integer value into the -128,127 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static av_always_inline av_const int8_t av_clip_int8_c(int a)
|
||||
{
|
||||
if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip a signed integer value into the 0-65535 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static av_always_inline av_const uint16_t av_clip_uint16_c(int a)
|
||||
{
|
||||
if (a&(~0xFFFF)) 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 av_always_inline av_const int16_t av_clip_int16_c(int a)
|
||||
{
|
||||
if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip a signed 64-bit integer value into the -2147483648,2147483647 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
|
||||
{
|
||||
if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (a>>63) ^ 0x7FFFFFFF;
|
||||
else return (int32_t)a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clip a signed integer to an unsigned power of two range.
|
||||
* @param a value to clip
|
||||
* @param p bit position to clip at
|
||||
* @return clipped value
|
||||
*/
|
||||
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
|
||||
{
|
||||
if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1);
|
||||
else return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two signed 32-bit values with saturation.
|
||||
*
|
||||
* @param a one value
|
||||
* @param b another value
|
||||
* @return sum with signed saturation
|
||||
*/
|
||||
static av_always_inline int av_sat_add32_c(int a, int b)
|
||||
{
|
||||
return av_clipl_int32((int64_t)a + b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a doubled value to another value with saturation at both stages.
|
||||
*
|
||||
* @param a first value
|
||||
* @param b value doubled and added to a
|
||||
* @return sum with signed saturation
|
||||
*/
|
||||
static av_always_inline int av_sat_dadd32_c(int a, int b)
|
||||
{
|
||||
return av_sat_add32(a, av_sat_add32(b, b));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 av_always_inline av_const float av_clipf_c(float a, float amin, float amax)
|
||||
{
|
||||
#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
|
||||
if (amin > amax) abort();
|
||||
#endif
|
||||
if (a < amin) return amin;
|
||||
else if (a > amax) return amax;
|
||||
else return a;
|
||||
}
|
||||
|
||||
/** Compute ceil(log2(x)).
|
||||
* @param x value used to compute ceil(log2(x))
|
||||
* @return computed ceiling of log2(x)
|
||||
*/
|
||||
static av_always_inline av_const int av_ceil_log2_c(int x)
|
||||
{
|
||||
return av_log2((x - 1) << 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of bits set to one in x
|
||||
* @param x value to count bits of
|
||||
* @return the number of bits set to one in x
|
||||
*/
|
||||
static av_always_inline av_const int av_popcount_c(uint32_t x)
|
||||
{
|
||||
x -= (x >> 1) & 0x55555555;
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
x = (x + (x >> 4)) & 0x0F0F0F0F;
|
||||
x += x >> 8;
|
||||
return (x + (x >> 16)) & 0x3F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of bits set to one in x
|
||||
* @param x value to count bits of
|
||||
* @return the number of bits set to one in x
|
||||
*/
|
||||
static av_always_inline av_const int av_popcount64_c(uint64_t x)
|
||||
{
|
||||
return av_popcount((uint32_t)x) + av_popcount(x >> 32);
|
||||
}
|
||||
|
||||
#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
|
||||
#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
|
||||
*
|
||||
* @param val Output value, must be an lvalue of type uint32_t.
|
||||
* @param GET_BYTE Expression reading one byte from the input.
|
||||
* Evaluated up to 7 times (4 for the currently
|
||||
* assigned Unicode range). With a memory buffer
|
||||
* input, this could be *ptr++.
|
||||
* @param ERROR Expression to be evaluated on invalid input,
|
||||
* typically a goto statement.
|
||||
*/
|
||||
#define GET_UTF8(val, GET_BYTE, ERROR)\
|
||||
val= GET_BYTE;\
|
||||
{\
|
||||
uint32_t top = (val & 128) >> 1;\
|
||||
if ((val & 0xc0) == 0x80)\
|
||||
ERROR\
|
||||
while (val & top) {\
|
||||
int tmp= GET_BYTE - 128;\
|
||||
if(tmp>>6)\
|
||||
ERROR\
|
||||
val= (val<<6) + tmp;\
|
||||
top <<= 5;\
|
||||
}\
|
||||
val &= (top << 1) - 1;\
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
|
||||
*
|
||||
* @param val Output value, must be an lvalue of type uint32_t.
|
||||
* @param GET_16BIT Expression returning two bytes of UTF-16 data converted
|
||||
* to native byte order. Evaluated one or two times.
|
||||
* @param ERROR Expression to be evaluated on invalid input,
|
||||
* typically a goto statement.
|
||||
*/
|
||||
#define GET_UTF16(val, GET_16BIT, ERROR)\
|
||||
val = GET_16BIT;\
|
||||
{\
|
||||
unsigned int hi = val - 0xD800;\
|
||||
if (hi < 0x800) {\
|
||||
val = GET_16BIT - 0xDC00;\
|
||||
if (val > 0x3FFU || hi > 0x3FFU)\
|
||||
ERROR\
|
||||
val += (hi<<10) + 0x10000;\
|
||||
}\
|
||||
}\
|
||||
|
||||
/**
|
||||
* @def PUT_UTF8(val, tmp, PUT_BYTE)
|
||||
* Convert 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 UCS-4 encoded Unicode character that is to be converted to UTF-8. If
|
||||
* val is given as a function it is 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
|
||||
* output 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\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
/**
|
||||
* @def PUT_UTF16(val, tmp, PUT_16BIT)
|
||||
* Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
|
||||
* @param val is an input-only argument and should be of type uint32_t. It holds
|
||||
* a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
|
||||
* val is given as a function it is executed only once.
|
||||
* @param tmp is a temporary variable and should be of type uint16_t. It
|
||||
* represents an intermediate value during conversion that is to be
|
||||
* output by PUT_16BIT.
|
||||
* @param PUT_16BIT writes the converted UTF-16 data to any proper destination
|
||||
* in desired endianness. 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 1 or 2 times depending on input character.
|
||||
*/
|
||||
#define PUT_UTF16(val, tmp, PUT_16BIT)\
|
||||
{\
|
||||
uint32_t in = val;\
|
||||
if (in < 0x10000) {\
|
||||
tmp = in;\
|
||||
PUT_16BIT\
|
||||
} else {\
|
||||
tmp = 0xD800 | ((in - 0x10000) >> 10);\
|
||||
PUT_16BIT\
|
||||
tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
|
||||
PUT_16BIT\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "internal.h"
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
#endif /* AVUTIL_COMMON_H */
|
||||
|
||||
/*
|
||||
* The following definitions are outside the multiple inclusion guard
|
||||
* to ensure they are immediately available in intmath.h.
|
||||
*/
|
||||
|
||||
#ifndef av_ceil_log2
|
||||
# define av_ceil_log2 av_ceil_log2_c
|
||||
#endif
|
||||
#ifndef av_clip
|
||||
# define av_clip av_clip_c
|
||||
#endif
|
||||
#ifndef av_clip64
|
||||
# define av_clip64 av_clip64_c
|
||||
#endif
|
||||
#ifndef av_clip_uint8
|
||||
# define av_clip_uint8 av_clip_uint8_c
|
||||
#endif
|
||||
#ifndef av_clip_int8
|
||||
# define av_clip_int8 av_clip_int8_c
|
||||
#endif
|
||||
#ifndef av_clip_uint16
|
||||
# define av_clip_uint16 av_clip_uint16_c
|
||||
#endif
|
||||
#ifndef av_clip_int16
|
||||
# define av_clip_int16 av_clip_int16_c
|
||||
#endif
|
||||
#ifndef av_clipl_int32
|
||||
# define av_clipl_int32 av_clipl_int32_c
|
||||
#endif
|
||||
#ifndef av_clip_uintp2
|
||||
# define av_clip_uintp2 av_clip_uintp2_c
|
||||
#endif
|
||||
#ifndef av_sat_add32
|
||||
# define av_sat_add32 av_sat_add32_c
|
||||
#endif
|
||||
#ifndef av_sat_dadd32
|
||||
# define av_sat_dadd32 av_sat_dadd32_c
|
||||
#endif
|
||||
#ifndef av_clipf
|
||||
# define av_clipf av_clipf_c
|
||||
#endif
|
||||
#ifndef av_popcount
|
||||
# define av_popcount av_popcount_c
|
||||
#endif
|
||||
#ifndef av_popcount64
|
||||
# define av_popcount64 av_popcount64_c
|
||||
#endif
|
||||
230
project/jni/ffmpeg/libavutil/cpu.c
Normal file
230
project/jni/ffmpeg/libavutil/cpu.c
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* 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 "cpu.h"
|
||||
#include "config.h"
|
||||
#include "opt.h"
|
||||
|
||||
static int flags, checked;
|
||||
|
||||
void av_force_cpu_flags(int arg){
|
||||
flags = arg;
|
||||
checked = arg != -1;
|
||||
}
|
||||
|
||||
int av_get_cpu_flags(void)
|
||||
{
|
||||
if (checked)
|
||||
return flags;
|
||||
|
||||
if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
|
||||
if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
|
||||
if (ARCH_X86) flags = ff_get_cpu_flags_x86();
|
||||
|
||||
checked = 1;
|
||||
return flags;
|
||||
}
|
||||
|
||||
void av_set_cpu_flags_mask(int mask)
|
||||
{
|
||||
checked = 0;
|
||||
flags = av_get_cpu_flags() & mask;
|
||||
checked = 1;
|
||||
}
|
||||
|
||||
int av_parse_cpu_flags(const char *s)
|
||||
{
|
||||
#define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
|
||||
#define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
|
||||
#define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
|
||||
#define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
|
||||
#define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
|
||||
#define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
|
||||
#define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
|
||||
#define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
|
||||
#define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
|
||||
#define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
|
||||
#define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
|
||||
#define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
|
||||
#define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
|
||||
#define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
|
||||
static const AVOption cpuflags_opts[] = {
|
||||
{ "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
|
||||
#if ARCH_PPC
|
||||
{ "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ALTIVEC }, .unit = "flags" },
|
||||
#elif ARCH_X86
|
||||
{ "mmx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX }, .unit = "flags" },
|
||||
{ "mmxext" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_MMXEXT }, .unit = "flags" },
|
||||
{ "sse" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE }, .unit = "flags" },
|
||||
{ "sse2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2 }, .unit = "flags" },
|
||||
{ "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2SLOW }, .unit = "flags" },
|
||||
{ "sse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3 }, .unit = "flags" },
|
||||
{ "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3SLOW }, .unit = "flags" },
|
||||
{ "ssse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSSE3 }, .unit = "flags" },
|
||||
{ "atom" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ATOM }, .unit = "flags" },
|
||||
{ "sse4.1" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE4 }, .unit = "flags" },
|
||||
{ "sse4.2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE42 }, .unit = "flags" },
|
||||
{ "avx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX }, .unit = "flags" },
|
||||
{ "xop" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_XOP }, .unit = "flags" },
|
||||
{ "fma4" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA4 }, .unit = "flags" },
|
||||
{ "3dnow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOW }, .unit = "flags" },
|
||||
{ "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOWEXT }, .unit = "flags" },
|
||||
{ "cmov", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV }, .unit = "flags" },
|
||||
#elif ARCH_ARM
|
||||
{ "armv5te", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV5TE }, .unit = "flags" },
|
||||
{ "armv6", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6 }, .unit = "flags" },
|
||||
{ "armv6t2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6T2 }, .unit = "flags" },
|
||||
{ "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" },
|
||||
{ "vfpv3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3 }, .unit = "flags" },
|
||||
{ "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" },
|
||||
#endif
|
||||
{ NULL },
|
||||
};
|
||||
static const AVClass class = {
|
||||
.class_name = "cpuflags",
|
||||
.item_name = av_default_item_name,
|
||||
.option = cpuflags_opts,
|
||||
.version = LIBAVUTIL_VERSION_INT,
|
||||
};
|
||||
|
||||
int flags = 0, ret;
|
||||
const AVClass *pclass = &class;
|
||||
|
||||
if ((ret = av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, &flags)) < 0)
|
||||
return ret;
|
||||
|
||||
return flags & INT_MAX;
|
||||
}
|
||||
|
||||
int av_parse_cpu_caps(unsigned *flags, const char *s)
|
||||
{
|
||||
static const AVOption cpuflags_opts[] = {
|
||||
{ "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
|
||||
#if ARCH_PPC
|
||||
{ "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ALTIVEC }, .unit = "flags" },
|
||||
#elif ARCH_X86
|
||||
{ "mmx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX }, .unit = "flags" },
|
||||
{ "mmx2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX2 }, .unit = "flags" },
|
||||
{ "mmxext" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX2 }, .unit = "flags" },
|
||||
{ "sse" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE }, .unit = "flags" },
|
||||
{ "sse2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE2 }, .unit = "flags" },
|
||||
{ "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE2SLOW }, .unit = "flags" },
|
||||
{ "sse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE3 }, .unit = "flags" },
|
||||
{ "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE3SLOW }, .unit = "flags" },
|
||||
{ "ssse3" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSSE3 }, .unit = "flags" },
|
||||
{ "atom" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ATOM }, .unit = "flags" },
|
||||
{ "sse4.1" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE4 }, .unit = "flags" },
|
||||
{ "sse4.2" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE42 }, .unit = "flags" },
|
||||
{ "avx" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_AVX }, .unit = "flags" },
|
||||
{ "xop" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_XOP }, .unit = "flags" },
|
||||
{ "fma4" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_FMA4 }, .unit = "flags" },
|
||||
{ "3dnow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_3DNOW }, .unit = "flags" },
|
||||
{ "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_3DNOWEXT }, .unit = "flags" },
|
||||
{ "cmov", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV }, .unit = "flags" },
|
||||
|
||||
#define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
|
||||
#define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
|
||||
#define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
|
||||
{ "pentium2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit = "flags" },
|
||||
{ "pentium3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit = "flags" },
|
||||
{ "pentium4", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit = "flags" },
|
||||
|
||||
#define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
|
||||
#define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
|
||||
#define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
|
||||
#define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
|
||||
{ "k6", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX }, .unit = "flags" },
|
||||
{ "k62", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_K62 }, .unit = "flags" },
|
||||
{ "athlon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit = "flags" },
|
||||
{ "athlonxp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit = "flags" },
|
||||
{ "k8", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_K8 }, .unit = "flags" },
|
||||
#elif ARCH_ARM
|
||||
{ "armv5te", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV5TE }, .unit = "flags" },
|
||||
{ "armv6", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6 }, .unit = "flags" },
|
||||
{ "armv6t2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6T2 }, .unit = "flags" },
|
||||
{ "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" },
|
||||
{ "vfpv3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3 }, .unit = "flags" },
|
||||
{ "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" },
|
||||
#endif
|
||||
{ NULL },
|
||||
};
|
||||
static const AVClass class = {
|
||||
.class_name = "cpuflags",
|
||||
.item_name = av_default_item_name,
|
||||
.option = cpuflags_opts,
|
||||
.version = LIBAVUTIL_VERSION_INT,
|
||||
};
|
||||
const AVClass *pclass = &class;
|
||||
|
||||
return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
|
||||
}
|
||||
#ifdef TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const struct {
|
||||
int flag;
|
||||
const char *name;
|
||||
} cpu_flag_tab[] = {
|
||||
#if ARCH_ARM
|
||||
{ AV_CPU_FLAG_ARMV5TE, "armv5te" },
|
||||
{ AV_CPU_FLAG_ARMV6, "armv6" },
|
||||
{ AV_CPU_FLAG_ARMV6T2, "armv6t2" },
|
||||
{ AV_CPU_FLAG_VFP, "vfp" },
|
||||
{ AV_CPU_FLAG_VFPV3, "vfpv3" },
|
||||
{ AV_CPU_FLAG_NEON, "neon" },
|
||||
#elif ARCH_PPC
|
||||
{ AV_CPU_FLAG_ALTIVEC, "altivec" },
|
||||
#elif ARCH_X86
|
||||
{ AV_CPU_FLAG_MMX, "mmx" },
|
||||
{ AV_CPU_FLAG_MMXEXT, "mmxext" },
|
||||
{ AV_CPU_FLAG_SSE, "sse" },
|
||||
{ AV_CPU_FLAG_SSE2, "sse2" },
|
||||
{ AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
|
||||
{ AV_CPU_FLAG_SSE3, "sse3" },
|
||||
{ AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
|
||||
{ AV_CPU_FLAG_SSSE3, "ssse3" },
|
||||
{ AV_CPU_FLAG_ATOM, "atom" },
|
||||
{ AV_CPU_FLAG_SSE4, "sse4.1" },
|
||||
{ AV_CPU_FLAG_SSE42, "sse4.2" },
|
||||
{ AV_CPU_FLAG_AVX, "avx" },
|
||||
{ AV_CPU_FLAG_XOP, "xop" },
|
||||
{ AV_CPU_FLAG_FMA4, "fma4" },
|
||||
{ AV_CPU_FLAG_3DNOW, "3dnow" },
|
||||
{ AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
|
||||
{ AV_CPU_FLAG_CMOV, "cmov" },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int cpu_flags = av_get_cpu_flags();
|
||||
int i;
|
||||
|
||||
printf("cpu_flags = 0x%08X\n", cpu_flags);
|
||||
printf("cpu_flags =");
|
||||
for (i = 0; cpu_flag_tab[i].flag; i++)
|
||||
if (cpu_flags & cpu_flag_tab[i].flag)
|
||||
printf(" %s", cpu_flag_tab[i].name);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
108
project/jni/ffmpeg/libavutil/cpu.h
Normal file
108
project/jni/ffmpeg/libavutil/cpu.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2001, 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
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_CPU_H
|
||||
#define AVUTIL_CPU_H
|
||||
|
||||
#include "attributes.h"
|
||||
|
||||
#define AV_CPU_FLAG_FORCE 0x80000000 /* force usage of selected flags (OR) */
|
||||
|
||||
/* lower 16 bits - CPU features */
|
||||
#define AV_CPU_FLAG_MMX 0x0001 ///< standard MMX
|
||||
#define AV_CPU_FLAG_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext
|
||||
#define AV_CPU_FLAG_MMX2 0x0002 ///< SSE integer functions or AMD MMX ext
|
||||
#define AV_CPU_FLAG_3DNOW 0x0004 ///< AMD 3DNOW
|
||||
#define AV_CPU_FLAG_SSE 0x0008 ///< SSE functions
|
||||
#define AV_CPU_FLAG_SSE2 0x0010 ///< PIV SSE2 functions
|
||||
#define AV_CPU_FLAG_SSE2SLOW 0x40000000 ///< SSE2 supported, but usually not faster
|
||||
#define AV_CPU_FLAG_3DNOWEXT 0x0020 ///< AMD 3DNowExt
|
||||
#define AV_CPU_FLAG_SSE3 0x0040 ///< Prescott SSE3 functions
|
||||
#define AV_CPU_FLAG_SSE3SLOW 0x20000000 ///< SSE3 supported, but usually not faster
|
||||
#define AV_CPU_FLAG_SSSE3 0x0080 ///< Conroe SSSE3 functions
|
||||
#define AV_CPU_FLAG_ATOM 0x10000000 ///< Atom processor, some SSSE3 instructions are slower
|
||||
#define AV_CPU_FLAG_SSE4 0x0100 ///< Penryn SSE4.1 functions
|
||||
#define AV_CPU_FLAG_SSE42 0x0200 ///< Nehalem SSE4.2 functions
|
||||
#define AV_CPU_FLAG_AVX 0x4000 ///< AVX functions: requires OS support even if YMM registers aren't used
|
||||
#define AV_CPU_FLAG_XOP 0x0400 ///< Bulldozer XOP functions
|
||||
#define AV_CPU_FLAG_FMA4 0x0800 ///< Bulldozer FMA4 functions
|
||||
// #if LIBAVUTIL_VERSION_MAJOR <52
|
||||
#define AV_CPU_FLAG_CMOV 0x1001000 ///< supports cmov instruction
|
||||
// #else
|
||||
// #define AV_CPU_FLAG_CMOV 0x1000 ///< supports cmov instruction
|
||||
// #endif
|
||||
|
||||
#define AV_CPU_FLAG_ALTIVEC 0x0001 ///< standard
|
||||
|
||||
#define AV_CPU_FLAG_ARMV5TE (1 << 0)
|
||||
#define AV_CPU_FLAG_ARMV6 (1 << 1)
|
||||
#define AV_CPU_FLAG_ARMV6T2 (1 << 2)
|
||||
#define AV_CPU_FLAG_VFP (1 << 3)
|
||||
#define AV_CPU_FLAG_VFPV3 (1 << 4)
|
||||
#define AV_CPU_FLAG_NEON (1 << 5)
|
||||
|
||||
/**
|
||||
* Return the flags which specify extensions supported by the CPU.
|
||||
* The returned value is affected by av_force_cpu_flags() if that was used
|
||||
* before. So av_get_cpu_flags() can easily be used in a application to
|
||||
* detect the enabled cpu flags.
|
||||
*/
|
||||
int av_get_cpu_flags(void);
|
||||
|
||||
/**
|
||||
* Disables cpu detection and forces the specified flags.
|
||||
* -1 is a special case that disables forcing of specific flags.
|
||||
*/
|
||||
void av_force_cpu_flags(int flags);
|
||||
|
||||
/**
|
||||
* Set a mask on flags returned by av_get_cpu_flags().
|
||||
* This function is mainly useful for testing.
|
||||
* Please use av_force_cpu_flags() and av_get_cpu_flags() instead which are more flexible
|
||||
*
|
||||
* @warning this function is not thread safe.
|
||||
*/
|
||||
attribute_deprecated void av_set_cpu_flags_mask(int mask);
|
||||
|
||||
/**
|
||||
* Parse CPU flags from a string.
|
||||
*
|
||||
* The returned flags contain the specified flags as well as related unspecified flags.
|
||||
*
|
||||
* This function exists only for compatibility with libav.
|
||||
* Please use av_parse_cpu_caps() when possible.
|
||||
* @return a combination of AV_CPU_* flags, negative on error.
|
||||
*/
|
||||
attribute_deprecated
|
||||
int av_parse_cpu_flags(const char *s);
|
||||
|
||||
/**
|
||||
* Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
|
||||
*
|
||||
* @return negative on error.
|
||||
*/
|
||||
int av_parse_cpu_caps(unsigned *flags, const char *s);
|
||||
|
||||
/* The following CPU-specific functions shall not be called directly. */
|
||||
int ff_get_cpu_flags_arm(void);
|
||||
int ff_get_cpu_flags_ppc(void);
|
||||
int ff_get_cpu_flags_x86(void);
|
||||
|
||||
#endif /* AVUTIL_CPU_H */
|
||||
136
project/jni/ffmpeg/libavutil/crc.c
Normal file
136
project/jni/ffmpeg/libavutil/crc.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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 "config.h"
|
||||
#include "common.h"
|
||||
#include "bswap.h"
|
||||
#include "crc.h"
|
||||
|
||||
#if 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
|
||||
|
||||
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size)
|
||||
{
|
||||
unsigned 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] = av_bswap32(c);
|
||||
}
|
||||
}
|
||||
ctx[256] = 1;
|
||||
#if !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;
|
||||
}
|
||||
|
||||
const AVCRC *av_crc_get_table(AVCRCId crc_id)
|
||||
{
|
||||
#if !CONFIG_HARDCODED_TABLES
|
||||
if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id]) - 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];
|
||||
}
|
||||
|
||||
uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
|
||||
const uint8_t *buffer, size_t length)
|
||||
{
|
||||
const uint8_t *end = buffer + length;
|
||||
|
||||
#if !CONFIG_SMALL
|
||||
if (!ctx[256]) {
|
||||
while (((intptr_t) buffer & 3) && buffer < end)
|
||||
crc = ctx[((uint8_t) crc) ^ *buffer++] ^ (crc >> 8);
|
||||
|
||||
while (buffer < end - 3) {
|
||||
crc ^= av_le2ne32(*(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
|
||||
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
|
||||
74
project/jni/ffmpeg/libavutil/crc.h
Normal file
74
project/jni/ffmpeg/libavutil/crc.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 AVUTIL_CRC_H
|
||||
#define AVUTIL_CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "attributes.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! Do not use outside libavutil. */
|
||||
}AVCRCId;
|
||||
|
||||
/**
|
||||
* Initialize a CRC table.
|
||||
* @param ctx must be an array of size sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
|
||||
* @param le If 1, the lowest bit represents the coefficient for the highest
|
||||
* exponent of the 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):
|
||||
* av_bswap32(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
|
||||
* @param ctx_size size of ctx in bytes
|
||||
* @return <0 on failure
|
||||
*/
|
||||
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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) av_pure;
|
||||
|
||||
#endif /* AVUTIL_CRC_H */
|
||||
213
project/jni/ffmpeg/libavutil/crc_data.h
Normal file
213
project/jni/ffmpeg/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 AVUTIL_CRC_DATA_H
|
||||
#define AVUTIL_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 /* AVUTIL_CRC_DATA_H */
|
||||
441
project/jni/ffmpeg/libavutil/des.c
Normal file
441
project/jni/ffmpeg/libavutil/des.c
Normal file
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
* 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 "avutil.h"
|
||||
#include "common.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "des.h"
|
||||
|
||||
typedef struct AVDES AVDES;
|
||||
|
||||
#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
|
||||
|
||||
#if CONFIG_SMALL || defined(GENTABLES)
|
||||
#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
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#if 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;
|
||||
#if 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;
|
||||
}
|
||||
#if 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;
|
||||
}
|
||||
|
||||
static void gen_roundkeys(uint64_t K[16], uint64_t key) {
|
||||
int i;
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt) {
|
||||
int i;
|
||||
// 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;
|
||||
}
|
||||
|
||||
int av_des_init(AVDES *d, const uint8_t *key, int key_bits, av_unused int decrypt) {
|
||||
if (key_bits != 64 && key_bits != 192)
|
||||
return -1;
|
||||
d->triple_des = key_bits > 64;
|
||||
gen_roundkeys(d->round_keys[0], AV_RB64(key));
|
||||
if (d->triple_des) {
|
||||
gen_roundkeys(d->round_keys[1], AV_RB64(key + 8));
|
||||
gen_roundkeys(d->round_keys[2], AV_RB64(key + 16));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac) {
|
||||
uint64_t iv_val = iv ? AV_RB64(iv) : 0;
|
||||
while (count-- > 0) {
|
||||
uint64_t dst_val;
|
||||
uint64_t src_val = src ? AV_RB64(src) : 0;
|
||||
if (decrypt) {
|
||||
uint64_t tmp = src_val;
|
||||
if (d->triple_des) {
|
||||
src_val = des_encdec(src_val, d->round_keys[2], 1);
|
||||
src_val = des_encdec(src_val, d->round_keys[1], 0);
|
||||
}
|
||||
dst_val = des_encdec(src_val, d->round_keys[0], 1) ^ iv_val;
|
||||
iv_val = iv ? tmp : 0;
|
||||
} else {
|
||||
dst_val = des_encdec(src_val ^ iv_val, d->round_keys[0], 0);
|
||||
if (d->triple_des) {
|
||||
dst_val = des_encdec(dst_val, d->round_keys[1], 1);
|
||||
dst_val = des_encdec(dst_val, d->round_keys[2], 0);
|
||||
}
|
||||
iv_val = iv ? dst_val : 0;
|
||||
}
|
||||
AV_WB64(dst, dst_val);
|
||||
src += 8;
|
||||
if (!mac)
|
||||
dst += 8;
|
||||
}
|
||||
if (iv)
|
||||
AV_WB64(iv, iv_val);
|
||||
}
|
||||
|
||||
void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
|
||||
av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0);
|
||||
}
|
||||
|
||||
void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) {
|
||||
av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "libavutil/time.h"
|
||||
static uint64_t rand64(void) {
|
||||
uint64_t r = rand();
|
||||
r = (r << 32) | rand();
|
||||
return r;
|
||||
}
|
||||
|
||||
static const uint8_t test_key[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
|
||||
static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10};
|
||||
static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = {0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18};
|
||||
static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
|
||||
static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
|
||||
static const uint8_t cbc_key[] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
|
||||
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
|
||||
};
|
||||
|
||||
static int run_test(int cbc, int decrypt) {
|
||||
AVDES d;
|
||||
int delay = cbc && !decrypt ? 2 : 1;
|
||||
uint64_t res;
|
||||
AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
|
||||
AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
|
||||
AV_WB64(tmp, 0x1234567890abcdefULL);
|
||||
av_des_init(&d, cbc_key, 192, decrypt);
|
||||
av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
|
||||
res = AV_RB64(large_buffer[9999 + delay]);
|
||||
if (cbc) {
|
||||
if (decrypt)
|
||||
return res == 0xc5cecf63ecec514cULL;
|
||||
else
|
||||
return res == 0xcb191f85d1ed8439ULL;
|
||||
} else {
|
||||
if (decrypt)
|
||||
return res == 0x8325397644091a0aULL;
|
||||
else
|
||||
return res == 0xdd17e8b8b437d232ULL;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
AVDES d;
|
||||
int i;
|
||||
#ifdef GENTABLES
|
||||
int j;
|
||||
#endif
|
||||
uint64_t key[3];
|
||||
uint64_t data;
|
||||
uint64_t ct;
|
||||
uint64_t roundkeys[16];
|
||||
srand(av_gettime());
|
||||
key[0] = AV_RB64(test_key);
|
||||
data = AV_RB64(plain);
|
||||
gen_roundkeys(roundkeys, key[0]);
|
||||
if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
|
||||
printf("Test 1 failed\n");
|
||||
return 1;
|
||||
}
|
||||
av_des_init(&d, test_key, 64, 0);
|
||||
av_des_crypt(&d, tmp, plain, 1, NULL, 0);
|
||||
if (memcmp(tmp, crypt, sizeof(crypt))) {
|
||||
printf("Public API decryption failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
|
||||
printf("Partial Monte-Carlo test failed\n");
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < 1000; i++) {
|
||||
key[0] = rand64(); key[1] = rand64(); key[2] = rand64();
|
||||
data = rand64();
|
||||
av_des_init(&d, (uint8_t*)key, 192, 0);
|
||||
av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&data, 1, NULL, 0);
|
||||
av_des_init(&d, (uint8_t*)key, 192, 1);
|
||||
av_des_crypt(&d, (uint8_t*)&ct, (uint8_t*)&ct, 1, NULL, 1);
|
||||
if (ct != 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
|
||||
61
project/jni/ffmpeg/libavutil/des.h
Normal file
61
project/jni/ffmpeg/libavutil/des.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 AVUTIL_DES_H
|
||||
#define AVUTIL_DES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct AVDES {
|
||||
uint64_t round_keys[3][16];
|
||||
int triple_des;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes an AVDES context.
|
||||
*
|
||||
* @param key_bits must be 64 or 192
|
||||
* @param decrypt 0 for encryption/CBC-MAC, 1 for decryption
|
||||
*/
|
||||
int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
|
||||
|
||||
/**
|
||||
* @brief Encrypts / decrypts using the DES algorithm.
|
||||
*
|
||||
* @param count number of 8 byte blocks
|
||||
* @param dst destination array, can be equal to src, must be 8-byte aligned
|
||||
* @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
|
||||
* @param iv initialization vector for CBC mode, if NULL then ECB will be used,
|
||||
* must be 8-byte aligned
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
|
||||
/**
|
||||
* @brief Calculates CBC-MAC using the DES algorithm.
|
||||
*
|
||||
* @param count number of 8 byte blocks
|
||||
* @param dst destination array, can be equal to src, must be 8-byte aligned
|
||||
* @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
|
||||
*/
|
||||
void av_des_mac(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count);
|
||||
|
||||
#endif /* AVUTIL_DES_H */
|
||||
133
project/jni/ffmpeg/libavutil/dict.c
Normal file
133
project/jni/ffmpeg/libavutil/dict.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* copyright (c) 2009 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 <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "avstring.h"
|
||||
#include "dict.h"
|
||||
#include "internal.h"
|
||||
#include "mem.h"
|
||||
|
||||
struct AVDictionary {
|
||||
int count;
|
||||
AVDictionaryEntry *elems;
|
||||
};
|
||||
|
||||
int av_dict_count(const AVDictionary *m)
|
||||
{
|
||||
return m ? m->count : 0;
|
||||
}
|
||||
|
||||
AVDictionaryEntry *
|
||||
av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
if(!m)
|
||||
return NULL;
|
||||
|
||||
if(prev) i= prev - m->elems + 1;
|
||||
else i= 0;
|
||||
|
||||
for(; i<m->count; i++){
|
||||
const char *s= m->elems[i].key;
|
||||
if(flags & AV_DICT_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++);
|
||||
else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
|
||||
if(key[j])
|
||||
continue;
|
||||
if(s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))
|
||||
continue;
|
||||
return &m->elems[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
|
||||
{
|
||||
AVDictionary *m = *pm;
|
||||
AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
|
||||
char *oldval = NULL;
|
||||
|
||||
if(!m)
|
||||
m = *pm = av_mallocz(sizeof(*m));
|
||||
|
||||
if(tag) {
|
||||
if (flags & AV_DICT_DONT_OVERWRITE)
|
||||
return 0;
|
||||
if (flags & AV_DICT_APPEND)
|
||||
oldval = tag->value;
|
||||
else
|
||||
av_free(tag->value);
|
||||
av_free(tag->key);
|
||||
*tag = m->elems[--m->count];
|
||||
} else {
|
||||
AVDictionaryEntry *tmp = av_realloc(m->elems, (m->count+1) * sizeof(*m->elems));
|
||||
if(tmp) {
|
||||
m->elems = tmp;
|
||||
} else
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
if (value) {
|
||||
if (flags & AV_DICT_DONT_STRDUP_KEY) {
|
||||
m->elems[m->count].key = (char*)(intptr_t)key;
|
||||
} else
|
||||
m->elems[m->count].key = av_strdup(key );
|
||||
if (flags & AV_DICT_DONT_STRDUP_VAL) {
|
||||
m->elems[m->count].value = (char*)(intptr_t)value;
|
||||
} else if (oldval && flags & AV_DICT_APPEND) {
|
||||
int len = strlen(oldval) + strlen(value) + 1;
|
||||
if (!(oldval = av_realloc(oldval, len)))
|
||||
return AVERROR(ENOMEM);
|
||||
av_strlcat(oldval, value, len);
|
||||
m->elems[m->count].value = oldval;
|
||||
} else
|
||||
m->elems[m->count].value = av_strdup(value);
|
||||
m->count++;
|
||||
}
|
||||
if (!m->count) {
|
||||
av_free(m->elems);
|
||||
av_freep(pm);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_dict_free(AVDictionary **pm)
|
||||
{
|
||||
AVDictionary *m = *pm;
|
||||
|
||||
if (m) {
|
||||
while(m->count--) {
|
||||
av_free(m->elems[m->count].key);
|
||||
av_free(m->elems[m->count].value);
|
||||
}
|
||||
av_free(m->elems);
|
||||
}
|
||||
av_freep(pm);
|
||||
}
|
||||
|
||||
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
|
||||
{
|
||||
AVDictionaryEntry *t = NULL;
|
||||
|
||||
while ((t = av_dict_get(src, "", t, AV_DICT_IGNORE_SUFFIX)))
|
||||
av_dict_set(dst, t->key, t->value, flags);
|
||||
}
|
||||
135
project/jni/ffmpeg/libavutil/dict.h
Normal file
135
project/jni/ffmpeg/libavutil/dict.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
*
|
||||
* 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
|
||||
* Public dictionary API.
|
||||
* @deprecated
|
||||
* AVDictionary is provided for compatibility with libav. It is both in
|
||||
* implementation as well as API inefficient. It does not scale and is
|
||||
* extremely slow with large dictionaries.
|
||||
* It is recommended that new code uses our tree container from tree.c/h
|
||||
* where applicable, which uses AVL trees to achieve O(log n) performance.
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_DICT_H
|
||||
#define AVUTIL_DICT_H
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_dict AVDictionary
|
||||
* @ingroup lavu_data
|
||||
*
|
||||
* @brief Simple key:value store
|
||||
*
|
||||
* @{
|
||||
* Dictionaries are used for storing key:value pairs. To create
|
||||
* an AVDictionary, simply pass an address of a NULL pointer to
|
||||
* av_dict_set(). NULL can be used as an empty dictionary wherever
|
||||
* a pointer to an AVDictionary is required.
|
||||
* Use av_dict_get() to retrieve an entry or iterate over all
|
||||
* entries and finally av_dict_free() to free the dictionary
|
||||
* and all its contents.
|
||||
*
|
||||
* @code
|
||||
* AVDictionary *d = NULL; // "create" an empty dictionary
|
||||
* av_dict_set(&d, "foo", "bar", 0); // add an entry
|
||||
*
|
||||
* char *k = av_strdup("key"); // if your strings are already allocated,
|
||||
* char *v = av_strdup("value"); // you can avoid copying them like this
|
||||
* av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
|
||||
*
|
||||
* AVDictionaryEntry *t = NULL;
|
||||
* while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {
|
||||
* <....> // iterate over all entries in d
|
||||
* }
|
||||
*
|
||||
* av_dict_free(&d);
|
||||
* @endcode
|
||||
*
|
||||
*/
|
||||
|
||||
#define AV_DICT_MATCH_CASE 1
|
||||
#define AV_DICT_IGNORE_SUFFIX 2
|
||||
#define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been
|
||||
allocated with av_malloc() and children. */
|
||||
#define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been
|
||||
allocated with av_malloc() and chilren. */
|
||||
#define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries.
|
||||
#define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no
|
||||
delimiter is added, the strings are simply concatenated. */
|
||||
|
||||
typedef struct AVDictionaryEntry {
|
||||
char *key;
|
||||
char *value;
|
||||
} AVDictionaryEntry;
|
||||
|
||||
typedef struct AVDictionary AVDictionary;
|
||||
|
||||
/**
|
||||
* Get a dictionary entry with matching key.
|
||||
*
|
||||
* @param prev Set to the previous matching element to find the next.
|
||||
* If set to NULL the first matching element is returned.
|
||||
* @param flags Allows case as well as suffix-insensitive comparisons.
|
||||
* @return Found entry or NULL, changing key or value leads to undefined behavior.
|
||||
*/
|
||||
AVDictionaryEntry *
|
||||
av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
|
||||
|
||||
/**
|
||||
* Get number of entries in dictionary.
|
||||
*
|
||||
* @param m dictionary
|
||||
* @return number of entries in dictionary
|
||||
*/
|
||||
int av_dict_count(const AVDictionary *m);
|
||||
|
||||
/**
|
||||
* Set the given entry in *pm, overwriting an existing entry.
|
||||
*
|
||||
* @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
|
||||
* a dictionary struct is allocated and put in *pm.
|
||||
* @param key entry key to add to *pm (will be av_strduped depending on flags)
|
||||
* @param value entry value to add to *pm (will be av_strduped depending on flags).
|
||||
* Passing a NULL value will cause an existing entry to be deleted.
|
||||
* @return >= 0 on success otherwise an error code <0
|
||||
*/
|
||||
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags);
|
||||
|
||||
/**
|
||||
* Copy entries from one AVDictionary struct into another.
|
||||
* @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
|
||||
* this function will allocate a struct for you and put it in *dst
|
||||
* @param src pointer to source AVDictionary struct
|
||||
* @param flags flags to use when setting entries in *dst
|
||||
* @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
|
||||
*/
|
||||
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags);
|
||||
|
||||
/**
|
||||
* Free all the memory allocated for an AVDictionary struct
|
||||
* and all keys and values.
|
||||
*/
|
||||
void av_dict_free(AVDictionary **m);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_DICT_H */
|
||||
99
project/jni/ffmpeg/libavutil/error.c
Normal file
99
project/jni/ffmpeg/libavutil/error.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#undef _GNU_SOURCE
|
||||
#include "avutil.h"
|
||||
#include "avstring.h"
|
||||
#include "common.h"
|
||||
|
||||
struct error_entry {
|
||||
int num;
|
||||
const char *tag;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
#define ERROR_TAG(tag) AVERROR_##tag, #tag
|
||||
static const struct error_entry error_entries[] = {
|
||||
{ ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
|
||||
{ ERROR_TAG(BUG), "Internal bug, should not have happened" },
|
||||
{ ERROR_TAG(BUG2), "Internal bug, should not have happened" },
|
||||
{ ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
|
||||
{ ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
|
||||
{ ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
|
||||
{ ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
|
||||
{ ERROR_TAG(EOF), "End of file" },
|
||||
{ ERROR_TAG(EXIT), "Immediate exit requested" },
|
||||
{ ERROR_TAG(EXTERNAL), "Generic error in an external library" },
|
||||
{ ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
|
||||
{ ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
|
||||
{ ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
|
||||
{ ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
|
||||
{ ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
|
||||
{ ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
|
||||
{ ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
|
||||
{ ERROR_TAG(UNKNOWN), "Unknown error occurred" },
|
||||
{ ERROR_TAG(EXPERIMENTAL), "Experimental feature" },
|
||||
};
|
||||
|
||||
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
|
||||
{
|
||||
int ret = 0, i;
|
||||
const struct error_entry *entry = NULL;
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
|
||||
if (errnum == error_entries[i].num) {
|
||||
entry = &error_entries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry) {
|
||||
av_strlcpy(errbuf, entry->str, errbuf_size);
|
||||
} else {
|
||||
#if HAVE_STRERROR_R
|
||||
ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
|
||||
#else
|
||||
ret = -1;
|
||||
#endif
|
||||
if (ret < 0)
|
||||
snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#undef printf
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
|
||||
const struct error_entry *entry = &error_entries[i];
|
||||
printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
printf("%d: %s\n", -i, av_err2str(-i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
117
project/jni/ffmpeg/libavutil/error.h
Normal file
117
project/jni/ffmpeg/libavutil/error.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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
|
||||
* error code definitions
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_ERROR_H
|
||||
#define AVUTIL_ERROR_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_error
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* error handling */
|
||||
#if EDOM > 0
|
||||
#define AVERROR(e) (-(e)) ///< Returns a negative error code from a POSIX error code, to return from library functions.
|
||||
#define AVUNERROR(e) (-(e)) ///< Returns a POSIX error code from a library function error return value.
|
||||
#else
|
||||
/* Some platforms have E* and errno already negated. */
|
||||
#define AVERROR(e) (e)
|
||||
#define AVUNERROR(e) (e)
|
||||
#endif
|
||||
|
||||
#define FFERRTAG(a, b, c, d) (-(int)MKTAG(a, b, c, d))
|
||||
|
||||
#define AVERROR_BSF_NOT_FOUND FFERRTAG(0xF8,'B','S','F') ///< Bitstream filter not found
|
||||
#define AVERROR_BUG FFERRTAG( 'B','U','G','!') ///< Internal bug, also see AVERROR_BUG2
|
||||
#define AVERROR_BUFFER_TOO_SMALL FFERRTAG( 'B','U','F','S') ///< Buffer too small
|
||||
#define AVERROR_DECODER_NOT_FOUND FFERRTAG(0xF8,'D','E','C') ///< Decoder not found
|
||||
#define AVERROR_DEMUXER_NOT_FOUND FFERRTAG(0xF8,'D','E','M') ///< Demuxer not found
|
||||
#define AVERROR_ENCODER_NOT_FOUND FFERRTAG(0xF8,'E','N','C') ///< Encoder not found
|
||||
#define AVERROR_EOF FFERRTAG( 'E','O','F',' ') ///< End of file
|
||||
#define AVERROR_EXIT FFERRTAG( 'E','X','I','T') ///< Immediate exit was requested; the called function should not be restarted
|
||||
#define AVERROR_EXTERNAL FFERRTAG( 'E','X','T',' ') ///< Generic error in an external library
|
||||
#define AVERROR_FILTER_NOT_FOUND FFERRTAG(0xF8,'F','I','L') ///< Filter not found
|
||||
#define AVERROR_INVALIDDATA FFERRTAG( 'I','N','D','A') ///< Invalid data found when processing input
|
||||
#define AVERROR_MUXER_NOT_FOUND FFERRTAG(0xF8,'M','U','X') ///< Muxer not found
|
||||
#define AVERROR_OPTION_NOT_FOUND FFERRTAG(0xF8,'O','P','T') ///< Option not found
|
||||
#define AVERROR_PATCHWELCOME FFERRTAG( 'P','A','W','E') ///< Not yet implemented in FFmpeg, patches welcome
|
||||
#define AVERROR_PROTOCOL_NOT_FOUND FFERRTAG(0xF8,'P','R','O') ///< Protocol not found
|
||||
|
||||
#define AVERROR_STREAM_NOT_FOUND FFERRTAG(0xF8,'S','T','R') ///< Stream not found
|
||||
/**
|
||||
* This is semantically identical to AVERROR_BUG
|
||||
* it has been introduced in Libav after our AVERROR_BUG and with a modified value.
|
||||
*/
|
||||
#define AVERROR_BUG2 FFERRTAG( 'B','U','G',' ')
|
||||
#define AVERROR_UNKNOWN FFERRTAG( 'U','N','K','N') ///< Unknown error, typically from an external library
|
||||
#define AVERROR_EXPERIMENTAL (-0x2bb2afa8) ///< Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
|
||||
|
||||
#define AV_ERROR_MAX_STRING_SIZE 64
|
||||
|
||||
/**
|
||||
* Put a description of the AVERROR code errnum in errbuf.
|
||||
* In case of failure the global variable errno is set to indicate the
|
||||
* error. Even in case of failure av_strerror() will print a generic
|
||||
* error message indicating the errnum provided to errbuf.
|
||||
*
|
||||
* @param errnum error code to describe
|
||||
* @param errbuf buffer to which description is written
|
||||
* @param errbuf_size the size in bytes of errbuf
|
||||
* @return 0 on success, a negative value if a description for errnum
|
||||
* cannot be found
|
||||
*/
|
||||
int av_strerror(int errnum, char *errbuf, size_t errbuf_size);
|
||||
|
||||
/**
|
||||
* Fill the provided buffer with a string containing an error string
|
||||
* corresponding to the AVERROR code errnum.
|
||||
*
|
||||
* @param errbuf a buffer
|
||||
* @param errbuf_size size in bytes of errbuf
|
||||
* @param errnum error code to describe
|
||||
* @return the buffer in input, filled with the error description
|
||||
* @see av_strerror()
|
||||
*/
|
||||
static inline char *av_make_error_string(char *errbuf, size_t errbuf_size, int errnum)
|
||||
{
|
||||
av_strerror(errnum, errbuf, errbuf_size);
|
||||
return errbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience macro, the return value should be used only directly in
|
||||
* function arguments but never stand-alone.
|
||||
*/
|
||||
#define av_err2str(errnum) \
|
||||
av_make_error_string((char[AV_ERROR_MAX_STRING_SIZE]){0}, AV_ERROR_MAX_STRING_SIZE, errnum)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_ERROR_H */
|
||||
819
project/jni/ffmpeg/libavutil/eval.c
Normal file
819
project/jni/ffmpeg/libavutil/eval.c
Normal file
@@ -0,0 +1,819 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
* Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* simple arithmetic expression evaluator.
|
||||
*
|
||||
* see http://joe.hotchkiss.com/programming/eval/eval.html
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "eval.h"
|
||||
#include "log.h"
|
||||
#include "mathematics.h"
|
||||
|
||||
typedef struct Parser {
|
||||
const AVClass *class;
|
||||
int stack_index;
|
||||
char *s;
|
||||
const double *const_values;
|
||||
const char * const *const_names; // NULL terminated
|
||||
double (* const *funcs1)(void *, double a); // NULL terminated
|
||||
const char * const *func1_names; // NULL terminated
|
||||
double (* const *funcs2)(void *, double a, double b); // NULL terminated
|
||||
const char * const *func2_names; // NULL terminated
|
||||
void *opaque;
|
||||
int log_offset;
|
||||
void *log_ctx;
|
||||
#define VARS 10
|
||||
double *var;
|
||||
} Parser;
|
||||
|
||||
static const AVClass class = { "Eval", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(Parser,log_offset), offsetof(Parser,log_ctx) };
|
||||
|
||||
static const int8_t si_prefixes['z' - 'E' + 1] = {
|
||||
['y'-'E']= -24,
|
||||
['z'-'E']= -21,
|
||||
['a'-'E']= -18,
|
||||
['f'-'E']= -15,
|
||||
['p'-'E']= -12,
|
||||
['n'-'E']= - 9,
|
||||
['u'-'E']= - 6,
|
||||
['m'-'E']= - 3,
|
||||
['c'-'E']= - 2,
|
||||
['d'-'E']= - 1,
|
||||
['h'-'E']= 2,
|
||||
['k'-'E']= 3,
|
||||
['K'-'E']= 3,
|
||||
['M'-'E']= 6,
|
||||
['G'-'E']= 9,
|
||||
['T'-'E']= 12,
|
||||
['P'-'E']= 15,
|
||||
['E'-'E']= 18,
|
||||
['Z'-'E']= 21,
|
||||
['Y'-'E']= 24,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
double value;
|
||||
} constants[] = {
|
||||
{ "E", M_E },
|
||||
{ "PI", M_PI },
|
||||
{ "PHI", M_PHI },
|
||||
};
|
||||
|
||||
double av_strtod(const char *numstr, char **tail)
|
||||
{
|
||||
double d;
|
||||
char *next;
|
||||
if(numstr[0]=='0' && (numstr[1]|0x20)=='x') {
|
||||
d = strtoul(numstr, &next, 16);
|
||||
} else
|
||||
d = strtod(numstr, &next);
|
||||
/* if parsing succeeded, check for and interpret postfixes */
|
||||
if (next!=numstr) {
|
||||
if (next[0] == 'd' && next[1] == 'B') {
|
||||
/* treat dB as decibels instead of decibytes */
|
||||
d = pow(10, d / 20);
|
||||
next += 2;
|
||||
} else if (*next >= 'E' && *next <= 'z') {
|
||||
int e= si_prefixes[*next - 'E'];
|
||||
if (e) {
|
||||
if (next[1] == 'i') {
|
||||
d*= pow( 2, e/0.3);
|
||||
next+=2;
|
||||
} else {
|
||||
d*= pow(10, e);
|
||||
next++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (*next=='B') {
|
||||
d*=8;
|
||||
next++;
|
||||
}
|
||||
}
|
||||
/* if requested, fill in tail with the position after the last parsed
|
||||
character */
|
||||
if (tail)
|
||||
*tail = next;
|
||||
return d;
|
||||
}
|
||||
|
||||
#define IS_IDENTIFIER_CHAR(c) ((c) - '0' <= 9U || (c) - 'a' <= 25U || (c) - 'A' <= 25U || (c) == '_')
|
||||
|
||||
static int strmatch(const char *s, const char *prefix)
|
||||
{
|
||||
int i;
|
||||
for (i=0; prefix[i]; i++) {
|
||||
if (prefix[i] != s[i]) return 0;
|
||||
}
|
||||
/* return 1 only if the s identifier is terminated */
|
||||
return !IS_IDENTIFIER_CHAR(s[i]);
|
||||
}
|
||||
|
||||
struct AVExpr {
|
||||
enum {
|
||||
e_value, e_const, e_func0, e_func1, e_func2,
|
||||
e_squish, e_gauss, e_ld, e_isnan, e_isinf,
|
||||
e_mod, e_max, e_min, e_eq, e_gt, e_gte,
|
||||
e_pow, e_mul, e_div, e_add,
|
||||
e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc,
|
||||
e_sqrt, e_not, e_random, e_hypot, e_gcd,
|
||||
e_if, e_ifnot,
|
||||
} type;
|
||||
double value; // is sign in other types
|
||||
union {
|
||||
int const_index;
|
||||
double (*func0)(double);
|
||||
double (*func1)(void *, double);
|
||||
double (*func2)(void *, double, double);
|
||||
} a;
|
||||
struct AVExpr *param[3];
|
||||
double *var;
|
||||
};
|
||||
|
||||
static double eval_expr(Parser *p, AVExpr *e)
|
||||
{
|
||||
switch (e->type) {
|
||||
case e_value: return e->value;
|
||||
case e_const: return e->value * p->const_values[e->a.const_index];
|
||||
case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
|
||||
case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
|
||||
case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
|
||||
case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
|
||||
case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
|
||||
case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
|
||||
case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0]));
|
||||
case e_isinf: return e->value * !!isinf(eval_expr(p, e->param[0]));
|
||||
case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
|
||||
case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
|
||||
case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
|
||||
case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
|
||||
case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);
|
||||
case e_if: return e->value * ( eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
|
||||
case e_ifnot: return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0);
|
||||
case e_random:{
|
||||
int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
|
||||
uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
|
||||
r= r*1664525+1013904223;
|
||||
p->var[idx]= r;
|
||||
return e->value * (r * (1.0/UINT64_MAX));
|
||||
}
|
||||
case e_while: {
|
||||
double d = NAN;
|
||||
while (eval_expr(p, e->param[0]))
|
||||
d=eval_expr(p, e->param[1]);
|
||||
return d;
|
||||
}
|
||||
case e_taylor: {
|
||||
double t = 1, d = 0, v;
|
||||
double x = eval_expr(p, e->param[1]);
|
||||
int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, VARS-1) : 0;
|
||||
int i;
|
||||
double var0 = p->var[id];
|
||||
for(i=0; i<1000; i++) {
|
||||
double ld = d;
|
||||
p->var[id] = i;
|
||||
v = eval_expr(p, e->param[0]);
|
||||
d += t*v;
|
||||
if(ld==d && v)
|
||||
break;
|
||||
t *= x / (i+1);
|
||||
}
|
||||
p->var[id] = var0;
|
||||
return d;
|
||||
}
|
||||
case e_root: {
|
||||
int i, j;
|
||||
double low = -1, high = -1, v, low_v = -DBL_MAX, high_v = DBL_MAX;
|
||||
double var0 = p->var[0];
|
||||
double x_max = eval_expr(p, e->param[1]);
|
||||
for(i=-1; i<1024; i++) {
|
||||
if(i<255) {
|
||||
p->var[0] = av_reverse[i&255]*x_max/255;
|
||||
} else {
|
||||
p->var[0] = x_max*pow(0.9, i-255);
|
||||
if (i&1) p->var[0] *= -1;
|
||||
if (i&2) p->var[0] += low;
|
||||
else p->var[0] += high;
|
||||
}
|
||||
v = eval_expr(p, e->param[0]);
|
||||
if (v<=0 && v>low_v) {
|
||||
low = p->var[0];
|
||||
low_v = v;
|
||||
}
|
||||
if (v>=0 && v<high_v) {
|
||||
high = p->var[0];
|
||||
high_v = v;
|
||||
}
|
||||
if (low>=0 && high>=0){
|
||||
for (j=0; j<1000; j++) {
|
||||
p->var[0] = (low+high)*0.5;
|
||||
if (low == p->var[0] || high == p->var[0])
|
||||
break;
|
||||
v = eval_expr(p, e->param[0]);
|
||||
if (v<=0) low = p->var[0];
|
||||
if (v>=0) high= p->var[0];
|
||||
if (isnan(v)) {
|
||||
low = high = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
p->var[0] = var0;
|
||||
return -low_v<high_v ? low : high;
|
||||
}
|
||||
default: {
|
||||
double d = eval_expr(p, e->param[0]);
|
||||
double d2 = eval_expr(p, e->param[1]);
|
||||
switch (e->type) {
|
||||
case e_mod: return e->value * (d - floor((!CONFIG_FTRAPV || d2) ? d / d2 : d * INFINITY) * d2);
|
||||
case e_gcd: return e->value * av_gcd(d,d2);
|
||||
case e_max: return e->value * (d > d2 ? d : d2);
|
||||
case e_min: return e->value * (d < d2 ? d : d2);
|
||||
case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
|
||||
case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
|
||||
case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
|
||||
case e_pow: return e->value * pow(d, d2);
|
||||
case e_mul: return e->value * (d * d2);
|
||||
case e_div: return e->value * ((!CONFIG_FTRAPV || d2 ) ? (d / d2) : d * INFINITY);
|
||||
case e_add: return e->value * (d + d2);
|
||||
case e_last:return e->value * d2;
|
||||
case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
|
||||
case e_hypot:return e->value * (sqrt(d*d + d2*d2));
|
||||
}
|
||||
}
|
||||
}
|
||||
return NAN;
|
||||
}
|
||||
|
||||
static int parse_expr(AVExpr **e, Parser *p);
|
||||
|
||||
void av_expr_free(AVExpr *e)
|
||||
{
|
||||
if (!e) return;
|
||||
av_expr_free(e->param[0]);
|
||||
av_expr_free(e->param[1]);
|
||||
av_expr_free(e->param[2]);
|
||||
av_freep(&e->var);
|
||||
av_freep(&e);
|
||||
}
|
||||
|
||||
static int parse_primary(AVExpr **e, Parser *p)
|
||||
{
|
||||
AVExpr *d = av_mallocz(sizeof(AVExpr));
|
||||
char *next = p->s, *s0 = p->s;
|
||||
int ret, i;
|
||||
|
||||
if (!d)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
/* number */
|
||||
d->value = av_strtod(p->s, &next);
|
||||
if (next != p->s) {
|
||||
d->type = e_value;
|
||||
p->s= next;
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
d->value = 1;
|
||||
|
||||
/* named constants */
|
||||
for (i=0; p->const_names && p->const_names[i]; i++) {
|
||||
if (strmatch(p->s, p->const_names[i])) {
|
||||
p->s+= strlen(p->const_names[i]);
|
||||
d->type = e_const;
|
||||
d->a.const_index = i;
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(constants); i++) {
|
||||
if (strmatch(p->s, constants[i].name)) {
|
||||
p->s += strlen(constants[i].name);
|
||||
d->type = e_value;
|
||||
d->value = constants[i].value;
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
p->s= strchr(p->s, '(');
|
||||
if (p->s==NULL) {
|
||||
av_log(p, AV_LOG_ERROR, "Undefined constant or missing '(' in '%s'\n", s0);
|
||||
p->s= next;
|
||||
av_expr_free(d);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
p->s++; // "("
|
||||
if (*next == '(') { // special case do-nothing
|
||||
av_freep(&d);
|
||||
if ((ret = parse_expr(&d, p)) < 0)
|
||||
return ret;
|
||||
if (p->s[0] != ')') {
|
||||
av_log(p, AV_LOG_ERROR, "Missing ')' in '%s'\n", s0);
|
||||
av_expr_free(d);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
p->s++; // ")"
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
if ((ret = parse_expr(&(d->param[0]), p)) < 0) {
|
||||
av_expr_free(d);
|
||||
return ret;
|
||||
}
|
||||
if (p->s[0]== ',') {
|
||||
p->s++; // ","
|
||||
parse_expr(&d->param[1], p);
|
||||
}
|
||||
if (p->s[0]== ',') {
|
||||
p->s++; // ","
|
||||
parse_expr(&d->param[2], p);
|
||||
}
|
||||
if (p->s[0] != ')') {
|
||||
av_log(p, AV_LOG_ERROR, "Missing ')' or too many args in '%s'\n", s0);
|
||||
av_expr_free(d);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
p->s++; // ")"
|
||||
|
||||
d->type = e_func0;
|
||||
if (strmatch(next, "sinh" )) d->a.func0 = sinh;
|
||||
else if (strmatch(next, "cosh" )) d->a.func0 = cosh;
|
||||
else if (strmatch(next, "tanh" )) d->a.func0 = tanh;
|
||||
else if (strmatch(next, "sin" )) d->a.func0 = sin;
|
||||
else if (strmatch(next, "cos" )) d->a.func0 = cos;
|
||||
else if (strmatch(next, "tan" )) d->a.func0 = tan;
|
||||
else if (strmatch(next, "atan" )) d->a.func0 = atan;
|
||||
else if (strmatch(next, "asin" )) d->a.func0 = asin;
|
||||
else if (strmatch(next, "acos" )) d->a.func0 = acos;
|
||||
else if (strmatch(next, "exp" )) d->a.func0 = exp;
|
||||
else if (strmatch(next, "log" )) d->a.func0 = log;
|
||||
else if (strmatch(next, "abs" )) d->a.func0 = fabs;
|
||||
else if (strmatch(next, "squish")) d->type = e_squish;
|
||||
else if (strmatch(next, "gauss" )) d->type = e_gauss;
|
||||
else if (strmatch(next, "mod" )) d->type = e_mod;
|
||||
else if (strmatch(next, "max" )) d->type = e_max;
|
||||
else if (strmatch(next, "min" )) d->type = e_min;
|
||||
else if (strmatch(next, "eq" )) d->type = e_eq;
|
||||
else if (strmatch(next, "gte" )) d->type = e_gte;
|
||||
else if (strmatch(next, "gt" )) d->type = e_gt;
|
||||
else if (strmatch(next, "lte" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
|
||||
else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
|
||||
else if (strmatch(next, "ld" )) d->type = e_ld;
|
||||
else if (strmatch(next, "isnan" )) d->type = e_isnan;
|
||||
else if (strmatch(next, "isinf" )) d->type = e_isinf;
|
||||
else if (strmatch(next, "st" )) d->type = e_st;
|
||||
else if (strmatch(next, "while" )) d->type = e_while;
|
||||
else if (strmatch(next, "taylor")) d->type = e_taylor;
|
||||
else if (strmatch(next, "root" )) d->type = e_root;
|
||||
else if (strmatch(next, "floor" )) d->type = e_floor;
|
||||
else if (strmatch(next, "ceil" )) d->type = e_ceil;
|
||||
else if (strmatch(next, "trunc" )) d->type = e_trunc;
|
||||
else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
|
||||
else if (strmatch(next, "not" )) d->type = e_not;
|
||||
else if (strmatch(next, "pow" )) d->type = e_pow;
|
||||
else if (strmatch(next, "random")) d->type = e_random;
|
||||
else if (strmatch(next, "hypot" )) d->type = e_hypot;
|
||||
else if (strmatch(next, "gcd" )) d->type = e_gcd;
|
||||
else if (strmatch(next, "if" )) d->type = e_if;
|
||||
else if (strmatch(next, "ifnot" )) d->type = e_ifnot;
|
||||
else {
|
||||
for (i=0; p->func1_names && p->func1_names[i]; i++) {
|
||||
if (strmatch(next, p->func1_names[i])) {
|
||||
d->a.func1 = p->funcs1[i];
|
||||
d->type = e_func1;
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; p->func2_names && p->func2_names[i]; i++) {
|
||||
if (strmatch(next, p->func2_names[i])) {
|
||||
d->a.func2 = p->funcs2[i];
|
||||
d->type = e_func2;
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
av_log(p, AV_LOG_ERROR, "Unknown function in '%s'\n", s0);
|
||||
av_expr_free(d);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
*e = d;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static AVExpr *new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
|
||||
{
|
||||
AVExpr *e = av_mallocz(sizeof(AVExpr));
|
||||
if (!e)
|
||||
return NULL;
|
||||
e->type =type ;
|
||||
e->value =value ;
|
||||
e->param[0] =p0 ;
|
||||
e->param[1] =p1 ;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int parse_pow(AVExpr **e, Parser *p, int *sign)
|
||||
{
|
||||
*sign= (*p->s == '+') - (*p->s == '-');
|
||||
p->s += *sign&1;
|
||||
return parse_primary(e, p);
|
||||
}
|
||||
|
||||
static int parse_dB(AVExpr **e, Parser *p, int *sign)
|
||||
{
|
||||
/* do not filter out the negative sign when parsing a dB value.
|
||||
for example, -3dB is not the same as -(3dB) */
|
||||
if (*p->s == '-') {
|
||||
char *next;
|
||||
strtod(p->s, &next);
|
||||
if (next != p->s && next[0] == 'd' && next[1] == 'B') {
|
||||
*sign = 0;
|
||||
return parse_primary(e, p);
|
||||
}
|
||||
}
|
||||
return parse_pow(e, p, sign);
|
||||
}
|
||||
|
||||
static int parse_factor(AVExpr **e, Parser *p)
|
||||
{
|
||||
int sign, sign2, ret;
|
||||
AVExpr *e0, *e1, *e2;
|
||||
if ((ret = parse_dB(&e0, p, &sign)) < 0)
|
||||
return ret;
|
||||
while(p->s[0]=='^'){
|
||||
e1 = e0;
|
||||
p->s++;
|
||||
if ((ret = parse_dB(&e2, p, &sign2)) < 0) {
|
||||
av_expr_free(e1);
|
||||
return ret;
|
||||
}
|
||||
e0 = new_eval_expr(e_pow, 1, e1, e2);
|
||||
if (!e0) {
|
||||
av_expr_free(e1);
|
||||
av_expr_free(e2);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
if (e0->param[1]) e0->param[1]->value *= (sign2|1);
|
||||
}
|
||||
if (e0) e0->value *= (sign|1);
|
||||
|
||||
*e = e0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_term(AVExpr **e, Parser *p)
|
||||
{
|
||||
int ret;
|
||||
AVExpr *e0, *e1, *e2;
|
||||
if ((ret = parse_factor(&e0, p)) < 0)
|
||||
return ret;
|
||||
while (p->s[0]=='*' || p->s[0]=='/') {
|
||||
int c= *p->s++;
|
||||
e1 = e0;
|
||||
if ((ret = parse_factor(&e2, p)) < 0) {
|
||||
av_expr_free(e1);
|
||||
return ret;
|
||||
}
|
||||
e0 = new_eval_expr(c == '*' ? e_mul : e_div, 1, e1, e2);
|
||||
if (!e0) {
|
||||
av_expr_free(e1);
|
||||
av_expr_free(e2);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
}
|
||||
*e = e0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_subexpr(AVExpr **e, Parser *p)
|
||||
{
|
||||
int ret;
|
||||
AVExpr *e0, *e1, *e2;
|
||||
if ((ret = parse_term(&e0, p)) < 0)
|
||||
return ret;
|
||||
while (*p->s == '+' || *p->s == '-') {
|
||||
e1 = e0;
|
||||
if ((ret = parse_term(&e2, p)) < 0) {
|
||||
av_expr_free(e1);
|
||||
return ret;
|
||||
}
|
||||
e0 = new_eval_expr(e_add, 1, e1, e2);
|
||||
if (!e0) {
|
||||
av_expr_free(e1);
|
||||
av_expr_free(e2);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
};
|
||||
|
||||
*e = e0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_expr(AVExpr **e, Parser *p)
|
||||
{
|
||||
int ret;
|
||||
AVExpr *e0, *e1, *e2;
|
||||
if (p->stack_index <= 0) //protect against stack overflows
|
||||
return AVERROR(EINVAL);
|
||||
p->stack_index--;
|
||||
|
||||
if ((ret = parse_subexpr(&e0, p)) < 0)
|
||||
return ret;
|
||||
while (*p->s == ';') {
|
||||
p->s++;
|
||||
e1 = e0;
|
||||
if ((ret = parse_subexpr(&e2, p)) < 0) {
|
||||
av_expr_free(e1);
|
||||
return ret;
|
||||
}
|
||||
e0 = new_eval_expr(e_last, 1, e1, e2);
|
||||
if (!e0) {
|
||||
av_expr_free(e1);
|
||||
av_expr_free(e2);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
};
|
||||
|
||||
p->stack_index++;
|
||||
*e = e0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verify_expr(AVExpr *e)
|
||||
{
|
||||
if (!e) return 0;
|
||||
switch (e->type) {
|
||||
case e_value:
|
||||
case e_const: return 1;
|
||||
case e_func0:
|
||||
case e_func1:
|
||||
case e_squish:
|
||||
case e_ld:
|
||||
case e_gauss:
|
||||
case e_isnan:
|
||||
case e_isinf:
|
||||
case e_floor:
|
||||
case e_ceil:
|
||||
case e_trunc:
|
||||
case e_sqrt:
|
||||
case e_not:
|
||||
case e_random:
|
||||
return verify_expr(e->param[0]) && !e->param[1];
|
||||
case e_taylor:
|
||||
return verify_expr(e->param[0]) && verify_expr(e->param[1])
|
||||
&& (!e->param[2] || verify_expr(e->param[2]));
|
||||
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]) && !e->param[2];
|
||||
}
|
||||
}
|
||||
|
||||
int av_expr_parse(AVExpr **expr, const char *s,
|
||||
const char * const *const_names,
|
||||
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
||||
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
||||
int log_offset, void *log_ctx)
|
||||
{
|
||||
Parser p = { 0 };
|
||||
AVExpr *e = NULL;
|
||||
char *w = av_malloc(strlen(s) + 1);
|
||||
char *wp = w;
|
||||
const char *s0 = s;
|
||||
int ret = 0;
|
||||
|
||||
if (!w)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
while (*s)
|
||||
if (!isspace(*s++)) *wp++ = s[-1];
|
||||
*wp++ = 0;
|
||||
|
||||
p.class = &class;
|
||||
p.stack_index=100;
|
||||
p.s= w;
|
||||
p.const_names = const_names;
|
||||
p.funcs1 = funcs1;
|
||||
p.func1_names = func1_names;
|
||||
p.funcs2 = funcs2;
|
||||
p.func2_names = func2_names;
|
||||
p.log_offset = log_offset;
|
||||
p.log_ctx = log_ctx;
|
||||
|
||||
if ((ret = parse_expr(&e, &p)) < 0)
|
||||
goto end;
|
||||
if (*p.s) {
|
||||
av_expr_free(e);
|
||||
av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
|
||||
ret = AVERROR(EINVAL);
|
||||
goto end;
|
||||
}
|
||||
if (!verify_expr(e)) {
|
||||
av_expr_free(e);
|
||||
ret = AVERROR(EINVAL);
|
||||
goto end;
|
||||
}
|
||||
e->var= av_mallocz(sizeof(double) *VARS);
|
||||
*expr = e;
|
||||
end:
|
||||
av_free(w);
|
||||
return ret;
|
||||
}
|
||||
|
||||
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
|
||||
{
|
||||
Parser p = { 0 };
|
||||
p.var= e->var;
|
||||
|
||||
p.const_values = const_values;
|
||||
p.opaque = opaque;
|
||||
return eval_expr(&p, e);
|
||||
}
|
||||
|
||||
int av_expr_parse_and_eval(double *d, const char *s,
|
||||
const char * const *const_names, const double *const_values,
|
||||
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
||||
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
||||
void *opaque, int log_offset, void *log_ctx)
|
||||
{
|
||||
AVExpr *e = NULL;
|
||||
int ret = av_expr_parse(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
|
||||
|
||||
if (ret < 0) {
|
||||
*d = NAN;
|
||||
return ret;
|
||||
}
|
||||
*d = av_expr_eval(e, const_values, opaque);
|
||||
av_expr_free(e);
|
||||
return isnan(*d) ? AVERROR(EINVAL) : 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <string.h>
|
||||
|
||||
static const double const_values[] = {
|
||||
M_PI,
|
||||
M_E,
|
||||
0
|
||||
};
|
||||
|
||||
static const char *const const_names[] = {
|
||||
"PI",
|
||||
"E",
|
||||
0
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
double d;
|
||||
const char *const *expr;
|
||||
static const char *const exprs[] = {
|
||||
"",
|
||||
"1;2",
|
||||
"-20",
|
||||
"-PI",
|
||||
"+PI",
|
||||
"1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
||||
"80G/80Gi",
|
||||
"1k",
|
||||
"1Gi",
|
||||
"1gi",
|
||||
"1GiFoo",
|
||||
"1k+1k",
|
||||
"1Gi*3foo",
|
||||
"foo",
|
||||
"foo(",
|
||||
"foo()",
|
||||
"foo)",
|
||||
"sin",
|
||||
"sin(",
|
||||
"sin()",
|
||||
"sin)",
|
||||
"sin 10",
|
||||
"sin(1,2,3)",
|
||||
"sin(1 )",
|
||||
"1",
|
||||
"1foo",
|
||||
"bar + PI + E + 100f*2 + foo",
|
||||
"13k + 12f - foo(1, 2)",
|
||||
"1gi",
|
||||
"1Gi",
|
||||
"st(0, 123)",
|
||||
"st(1, 123); ld(1)",
|
||||
"lte(0, 1)",
|
||||
"lte(1, 1)",
|
||||
"lte(1, 0)",
|
||||
"lt(0, 1)",
|
||||
"lt(1, 1)",
|
||||
"gt(1, 0)",
|
||||
"gt(2, 7)",
|
||||
"gte(122, 122)",
|
||||
/* compute 1+2+...+N */
|
||||
"st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
|
||||
/* compute Fib(N) */
|
||||
"st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
|
||||
"while(0, 10)",
|
||||
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
|
||||
"isnan(1)",
|
||||
"isnan(NAN)",
|
||||
"isnan(INF)",
|
||||
"isinf(1)",
|
||||
"isinf(NAN)",
|
||||
"isinf(INF)",
|
||||
"floor(NAN)",
|
||||
"floor(123.123)",
|
||||
"floor(-123.123)",
|
||||
"trunc(123.123)",
|
||||
"trunc(-123.123)",
|
||||
"ceil(123.123)",
|
||||
"ceil(-123.123)",
|
||||
"sqrt(1764)",
|
||||
"isnan(sqrt(-1))",
|
||||
"not(1)",
|
||||
"not(NAN)",
|
||||
"not(0)",
|
||||
"6.0206dB",
|
||||
"-3.0103dB",
|
||||
"pow(0,1.23)",
|
||||
"pow(PI,1.23)",
|
||||
"PI^1.23",
|
||||
"pow(-1,1.23)",
|
||||
"if(1, 2)",
|
||||
"ifnot(0, 23)",
|
||||
"ifnot(1, NaN) + if(0, 1)",
|
||||
"taylor(1, 1)",
|
||||
"taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
|
||||
"root(sin(ld(0))-1, 2)",
|
||||
"root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
|
||||
"7000000B*random(0)",
|
||||
"squish(2)",
|
||||
"gauss(0.1)",
|
||||
"hypot(4,3)",
|
||||
"gcd(30,55)*min(9,1)",
|
||||
NULL
|
||||
};
|
||||
|
||||
for (expr = exprs; *expr; expr++) {
|
||||
printf("Evaluating '%s'\n", *expr);
|
||||
av_expr_parse_and_eval(&d, *expr,
|
||||
const_names, const_values,
|
||||
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
||||
if (isnan(d))
|
||||
printf("'%s' -> nan\n\n", *expr);
|
||||
else
|
||||
printf("'%s' -> %f\n\n", *expr, d);
|
||||
}
|
||||
|
||||
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
||||
const_names, const_values,
|
||||
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
||||
printf("%f == 12.7\n", d);
|
||||
av_expr_parse_and_eval(&d, "80G/80Gi",
|
||||
const_names, const_values,
|
||||
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
||||
printf("%f == 0.931322575\n", d);
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-t")) {
|
||||
for (i = 0; i < 1050; i++) {
|
||||
START_TIMER;
|
||||
av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
|
||||
const_names, const_values,
|
||||
NULL, NULL, NULL, NULL, NULL, 0, NULL);
|
||||
STOP_TIMER("av_expr_parse_and_eval");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
113
project/jni/ffmpeg/libavutil/eval.h
Normal file
113
project/jni/ffmpeg/libavutil/eval.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2002 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
|
||||
* simple arithmetic expression evaluator
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_EVAL_H
|
||||
#define AVUTIL_EVAL_H
|
||||
|
||||
#include "avutil.h"
|
||||
|
||||
typedef struct AVExpr AVExpr;
|
||||
|
||||
/**
|
||||
* Parse and evaluate an expression.
|
||||
* Note, this is significantly slower than av_expr_eval().
|
||||
*
|
||||
* @param res a pointer to a double where is put the result value of
|
||||
* the expression, or NAN in case of error
|
||||
* @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
|
||||
* @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
|
||||
* @param const_values a zero terminated array of values for the identifiers from const_names
|
||||
* @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
|
||||
* @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
|
||||
* @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
|
||||
* @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
|
||||
* @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
|
||||
* @param log_ctx parent logging context
|
||||
* @return 0 in case of success, a negative value corresponding to an
|
||||
* AVERROR code otherwise
|
||||
*/
|
||||
int av_expr_parse_and_eval(double *res, const char *s,
|
||||
const char * const *const_names, const double *const_values,
|
||||
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
||||
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
||||
void *opaque, int log_offset, void *log_ctx);
|
||||
|
||||
/**
|
||||
* Parse an expression.
|
||||
*
|
||||
* @param expr a pointer where is put an AVExpr containing the parsed
|
||||
* value in case of successful parsing, or NULL otherwise.
|
||||
* The pointed to AVExpr must be freed with av_expr_free() by the user
|
||||
* when it is not needed anymore.
|
||||
* @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
|
||||
* @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
|
||||
* @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
|
||||
* @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
|
||||
* @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
|
||||
* @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
|
||||
* @param log_ctx parent logging context
|
||||
* @return 0 in case of success, a negative value corresponding to an
|
||||
* AVERROR code otherwise
|
||||
*/
|
||||
int av_expr_parse(AVExpr **expr, const char *s,
|
||||
const char * const *const_names,
|
||||
const char * const *func1_names, double (* const *funcs1)(void *, double),
|
||||
const char * const *func2_names, double (* const *funcs2)(void *, double, double),
|
||||
int log_offset, void *log_ctx);
|
||||
|
||||
/**
|
||||
* Evaluate a previously parsed expression.
|
||||
*
|
||||
* @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
|
||||
* @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
|
||||
* @return the value of the expression
|
||||
*/
|
||||
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
|
||||
|
||||
/**
|
||||
* Free a parsed expression previously created with av_expr_parse().
|
||||
*/
|
||||
void av_expr_free(AVExpr *e);
|
||||
|
||||
/**
|
||||
* Parse the string in numstr and return its value as a double. If
|
||||
* the string is empty, contains only whitespaces, or does not contain
|
||||
* an initial substring that has the expected syntax for a
|
||||
* floating-point number, no conversion is performed. In this case,
|
||||
* returns a value of zero and the value returned in tail is the value
|
||||
* of numstr.
|
||||
*
|
||||
* @param numstr a string representing a number, may contain one of
|
||||
* the International System number postfixes, for example 'K', 'M',
|
||||
* 'G'. If 'i' is appended after the postfix, powers of 2 are used
|
||||
* instead of powers of 10. The 'B' postfix multiplies the value for
|
||||
* 8, and can be appended after another postfix or used alone. This
|
||||
* allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
|
||||
* @param tail if non-NULL puts here the pointer to the char next
|
||||
* after the last parsed character
|
||||
*/
|
||||
double av_strtod(const char *numstr, char **tail);
|
||||
|
||||
#endif /* AVUTIL_EVAL_H */
|
||||
182
project/jni/ffmpeg/libavutil/fifo.c
Normal file
182
project/jni/ffmpeg/libavutil/fifo.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
AVFifoBuffer *av_fifo_alloc(unsigned int size)
|
||||
{
|
||||
AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer));
|
||||
if (!f)
|
||||
return NULL;
|
||||
f->buffer = av_malloc(size);
|
||||
f->end = f->buffer + size;
|
||||
av_fifo_reset(f);
|
||||
if (!f->buffer)
|
||||
av_freep(&f);
|
||||
return f;
|
||||
}
|
||||
|
||||
void av_fifo_free(AVFifoBuffer *f)
|
||||
{
|
||||
if (f) {
|
||||
av_freep(&f->buffer);
|
||||
av_free(f);
|
||||
}
|
||||
}
|
||||
|
||||
void av_fifo_reset(AVFifoBuffer *f)
|
||||
{
|
||||
f->wptr = f->rptr = f->buffer;
|
||||
f->wndx = f->rndx = 0;
|
||||
}
|
||||
|
||||
int av_fifo_size(AVFifoBuffer *f)
|
||||
{
|
||||
return (uint32_t)(f->wndx - f->rndx);
|
||||
}
|
||||
|
||||
int av_fifo_space(AVFifoBuffer *f)
|
||||
{
|
||||
return f->end - f->buffer - av_fifo_size(f);
|
||||
}
|
||||
|
||||
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 = av_fifo_alloc(new_size);
|
||||
|
||||
if (!f2)
|
||||
return AVERROR(ENOMEM);
|
||||
av_fifo_generic_read(f, f2->buffer, len, NULL);
|
||||
f2->wptr += len;
|
||||
f2->wndx += len;
|
||||
av_free(f->buffer);
|
||||
*f = *f2;
|
||||
av_free(f2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_fifo_grow(AVFifoBuffer *f, unsigned int size)
|
||||
{
|
||||
unsigned int old_size = f->end - f->buffer;
|
||||
if(size + (unsigned)av_fifo_size(f) < size)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
size += av_fifo_size(f);
|
||||
|
||||
if (old_size < size)
|
||||
return av_fifo_realloc2(f, FFMAX(size, 2*size));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter)
|
||||
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
|
||||
{
|
||||
int total = size;
|
||||
uint32_t wndx= f->wndx;
|
||||
uint8_t *wptr= f->wptr;
|
||||
|
||||
do {
|
||||
int len = FFMIN(f->end - wptr, size);
|
||||
if (func) {
|
||||
if (func(src, wptr, len) <= 0)
|
||||
break;
|
||||
} else {
|
||||
memcpy(wptr, src, len);
|
||||
src = (uint8_t*)src + len;
|
||||
}
|
||||
// Write memory barrier needed for SMP here in theory
|
||||
wptr += len;
|
||||
if (wptr >= f->end)
|
||||
wptr = f->buffer;
|
||||
wndx += len;
|
||||
size -= len;
|
||||
} while (size > 0);
|
||||
f->wndx= wndx;
|
||||
f->wptr= wptr;
|
||||
return total - size;
|
||||
}
|
||||
|
||||
|
||||
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int))
|
||||
{
|
||||
// Read memory barrier needed for SMP here in theory
|
||||
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;
|
||||
}
|
||||
// memory barrier needed for SMP here in theory
|
||||
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;
|
||||
f->rndx += size;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* create a FIFO buffer */
|
||||
AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
|
||||
int i, j, n;
|
||||
|
||||
/* fill data */
|
||||
for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
|
||||
av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
|
||||
|
||||
/* peek at FIFO */
|
||||
n = av_fifo_size(fifo)/sizeof(int);
|
||||
for (i = -n+1; i < n; i++) {
|
||||
int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int));
|
||||
printf("%d: %d\n", i, *v);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/* read data */
|
||||
for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
|
||||
av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
|
||||
printf("%d ", j);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
av_fifo_free(fifo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
144
project/jni/ffmpeg/libavutil/fifo.h
Normal file
144
project/jni/ffmpeg/libavutil/fifo.h
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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
|
||||
* a very simple circular buffer FIFO implementation
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_FIFO_H
|
||||
#define AVUTIL_FIFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "avutil.h"
|
||||
#include "attributes.h"
|
||||
|
||||
typedef struct AVFifoBuffer {
|
||||
uint8_t *buffer;
|
||||
uint8_t *rptr, *wptr, *end;
|
||||
uint32_t rndx, wndx;
|
||||
} AVFifoBuffer;
|
||||
|
||||
/**
|
||||
* Initialize an AVFifoBuffer.
|
||||
* @param size of FIFO
|
||||
* @return AVFifoBuffer or NULL in case of memory allocation failure
|
||||
*/
|
||||
AVFifoBuffer *av_fifo_alloc(unsigned int size);
|
||||
|
||||
/**
|
||||
* Free an AVFifoBuffer.
|
||||
* @param f AVFifoBuffer to free
|
||||
*/
|
||||
void av_fifo_free(AVFifoBuffer *f);
|
||||
|
||||
/**
|
||||
* Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
|
||||
* @param f AVFifoBuffer to reset
|
||||
*/
|
||||
void av_fifo_reset(AVFifoBuffer *f);
|
||||
|
||||
/**
|
||||
* Return 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);
|
||||
|
||||
/**
|
||||
* Return the amount of space in bytes in the AVFifoBuffer, that is the
|
||||
* amount of data you can write into it.
|
||||
* @param f AVFifoBuffer to write into
|
||||
* @return size
|
||||
*/
|
||||
int av_fifo_space(AVFifoBuffer *f);
|
||||
|
||||
/**
|
||||
* Feed 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, void *dest, int buf_size, void (*func)(void*, void*, int));
|
||||
|
||||
/**
|
||||
* Feed data from a user-supplied callback to an AVFifoBuffer.
|
||||
* @param f AVFifoBuffer to write to
|
||||
* @param src data source; non-const since it may be used as a
|
||||
* modifiable context by the function defined in func
|
||||
* @param size number of bytes to write
|
||||
* @param func generic write function; the first parameter is src,
|
||||
* the second is dest_buf, the 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));
|
||||
|
||||
/**
|
||||
* Resize an AVFifoBuffer.
|
||||
* In case of reallocation failure, the old FIFO is kept unchanged.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Enlarge an AVFifoBuffer.
|
||||
* In case of reallocation failure, the old FIFO is kept unchanged.
|
||||
* The new fifo size may be larger than the requested size.
|
||||
*
|
||||
* @param f AVFifoBuffer to resize
|
||||
* @param additional_space the amount of space in bytes to allocate in addition to av_fifo_size()
|
||||
* @return <0 for failure, >=0 otherwise
|
||||
*/
|
||||
int av_fifo_grow(AVFifoBuffer *f, unsigned int additional_space);
|
||||
|
||||
/**
|
||||
* Read and discard 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);
|
||||
|
||||
/**
|
||||
* Return a pointer to the data stored in a FIFO buffer at a certain offset.
|
||||
* The FIFO buffer is not modified.
|
||||
*
|
||||
* @param f AVFifoBuffer to peek at, f must be non-NULL
|
||||
* @param offs an offset in bytes, its absolute value must be less
|
||||
* than the used buffer size or the returned pointer will
|
||||
* point outside to the buffer data.
|
||||
* The used buffer size can be checked with av_fifo_size().
|
||||
*/
|
||||
static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs)
|
||||
{
|
||||
uint8_t *ptr = f->rptr + offs;
|
||||
if (ptr >= f->end)
|
||||
ptr = f->buffer + (ptr - f->end);
|
||||
else if (ptr < f->buffer)
|
||||
ptr = f->end - (f->buffer - ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endif /* AVUTIL_FIFO_H */
|
||||
203
project/jni/ffmpeg/libavutil/file.c
Normal file
203
project/jni/ffmpeg/libavutil/file.c
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "file.h"
|
||||
#include "log.h"
|
||||
#include "mem.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
#if HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#elif HAVE_MAPVIEWOFFILE
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const AVClass *class;
|
||||
int log_offset;
|
||||
void *log_ctx;
|
||||
} FileLogContext;
|
||||
|
||||
static const AVClass file_log_ctx_class = {
|
||||
"FILE", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT,
|
||||
offsetof(FileLogContext, log_offset), offsetof(FileLogContext, log_ctx)
|
||||
};
|
||||
|
||||
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
|
||||
int log_offset, void *log_ctx)
|
||||
{
|
||||
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
|
||||
int err, fd = open(filename, O_RDONLY);
|
||||
struct stat st;
|
||||
av_unused void *ptr;
|
||||
off_t off_size;
|
||||
char errbuf[128];
|
||||
*bufptr = NULL;
|
||||
|
||||
if (fd < 0) {
|
||||
err = AVERROR(errno);
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, errbuf);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (fstat(fd, &st) < 0) {
|
||||
err = AVERROR(errno);
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in fstat(): %s\n", errbuf);
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
||||
|
||||
off_size = st.st_size;
|
||||
if (off_size > SIZE_MAX) {
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR,
|
||||
"File size for file '%s' is too big\n", filename);
|
||||
close(fd);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
*size = off_size;
|
||||
|
||||
#if HAVE_MMAP
|
||||
ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
if (ptr == MAP_FAILED) {
|
||||
err = AVERROR(errno);
|
||||
av_strerror(err, errbuf, sizeof(errbuf));
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
||||
*bufptr = ptr;
|
||||
#elif HAVE_MAPVIEWOFFILE
|
||||
{
|
||||
HANDLE mh, fh = (HANDLE)_get_osfhandle(fd);
|
||||
|
||||
mh = CreateFileMapping(fh, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
if (!mh) {
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ptr = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, *size);
|
||||
CloseHandle(mh);
|
||||
if (!ptr) {
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*bufptr = ptr;
|
||||
}
|
||||
#else
|
||||
*bufptr = av_malloc(*size);
|
||||
if (!*bufptr) {
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");
|
||||
close(fd);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
read(fd, *bufptr, *size);
|
||||
#endif
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_file_unmap(uint8_t *bufptr, size_t size)
|
||||
{
|
||||
#if HAVE_MMAP
|
||||
munmap(bufptr, size);
|
||||
#elif HAVE_MAPVIEWOFFILE
|
||||
UnmapViewOfFile(bufptr);
|
||||
#else
|
||||
av_free(bufptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) {
|
||||
FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx };
|
||||
int fd=-1;
|
||||
#if !HAVE_MKSTEMP
|
||||
void *ptr= tempnam(NULL, prefix);
|
||||
if(!ptr)
|
||||
ptr= tempnam(".", prefix);
|
||||
*filename = av_strdup(ptr);
|
||||
#undef free
|
||||
free(ptr);
|
||||
#else
|
||||
size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
|
||||
*filename = av_malloc(len);
|
||||
#endif
|
||||
/* -----common section-----*/
|
||||
if (*filename == NULL) {
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
#if !HAVE_MKSTEMP
|
||||
# ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
# endif
|
||||
# ifndef O_EXCL
|
||||
# define O_EXCL 0
|
||||
# endif
|
||||
fd = open(*filename, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
|
||||
#else
|
||||
snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
|
||||
fd = mkstemp(*filename);
|
||||
#ifdef _WIN32
|
||||
if (fd < 0) {
|
||||
snprintf(*filename, len, "./%sXXXXXX", prefix);
|
||||
fd = mkstemp(*filename);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/* -----common section-----*/
|
||||
if (fd < 0) {
|
||||
int err = AVERROR(errno);
|
||||
av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
|
||||
av_freep(filename);
|
||||
return err;
|
||||
}
|
||||
return fd; /* success */
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#undef printf
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t *buf;
|
||||
size_t size;
|
||||
if (av_file_map("file.c", &buf, &size, 0, NULL) < 0)
|
||||
return 1;
|
||||
|
||||
buf[0] = 's';
|
||||
printf("%s", buf);
|
||||
av_file_unmap(buf, size);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
66
project/jni/ffmpeg/libavutil/file.h
Normal file
66
project/jni/ffmpeg/libavutil/file.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 AVUTIL_FILE_H
|
||||
#define AVUTIL_FILE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "avutil.h"
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Misc file utilities.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read the file with name filename, and put its content in a newly
|
||||
* allocated buffer or map it with mmap() when available.
|
||||
* In case of success set *bufptr to the read or mmapped buffer, and
|
||||
* *size to the size in bytes of the buffer in *bufptr.
|
||||
* The returned buffer must be released with av_file_unmap().
|
||||
*
|
||||
* @param log_offset loglevel offset used for logging
|
||||
* @param log_ctx context used for logging
|
||||
* @return a non negative number in case of success, a negative value
|
||||
* corresponding to an AVERROR error code in case of failure
|
||||
*/
|
||||
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
|
||||
int log_offset, void *log_ctx);
|
||||
|
||||
/**
|
||||
* Unmap or free the buffer bufptr created by av_file_map().
|
||||
*
|
||||
* @param size size in bytes of bufptr, must be the same as returned
|
||||
* by av_file_map()
|
||||
*/
|
||||
void av_file_unmap(uint8_t *bufptr, size_t size);
|
||||
|
||||
/**
|
||||
* Wrapper to work around the lack of mkstemp() on mingw.
|
||||
* Also, tries to create file in /tmp first, if possible.
|
||||
* *prefix can be a character constant; *filename will be allocated internally.
|
||||
* @return file descriptor of opened file (or -1 on error)
|
||||
* and opened file name in **filename.
|
||||
* @note On very old libcs it is necessary to set a secure umask before
|
||||
* calling this, av_tempfile() cant call umask itself as it is used in
|
||||
* libraries and could interfere with the calling application.
|
||||
*/
|
||||
int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
|
||||
|
||||
#endif /* AVUTIL_FILE_H */
|
||||
74
project/jni/ffmpeg/libavutil/float_dsp.c
Normal file
74
project/jni/ffmpeg/libavutil/float_dsp.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2005 Balatoni Denes
|
||||
* Copyright 2006 Loren Merritt
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "float_dsp.h"
|
||||
|
||||
static void vector_fmul_c(float *dst, const float *src0, const float *src1,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = src0[i] * src1[i];
|
||||
}
|
||||
|
||||
static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] += src[i] * mul;
|
||||
}
|
||||
|
||||
static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = src[i] * mul;
|
||||
}
|
||||
|
||||
static void vector_dmul_scalar_c(double *dst, const double *src, double mul,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = src[i] * mul;
|
||||
}
|
||||
|
||||
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
|
||||
{
|
||||
fdsp->vector_fmul = vector_fmul_c;
|
||||
fdsp->vector_fmac_scalar = vector_fmac_scalar_c;
|
||||
fdsp->vector_fmul_scalar = vector_fmul_scalar_c;
|
||||
fdsp->vector_dmul_scalar = vector_dmul_scalar_c;
|
||||
|
||||
#if ARCH_ARM
|
||||
ff_float_dsp_init_arm(fdsp);
|
||||
#elif ARCH_PPC
|
||||
ff_float_dsp_init_ppc(fdsp, bit_exact);
|
||||
#elif ARCH_X86
|
||||
ff_float_dsp_init_x86(fdsp);
|
||||
#elif ARCH_MIPS
|
||||
ff_float_dsp_init_mips(fdsp);
|
||||
#endif
|
||||
}
|
||||
100
project/jni/ffmpeg/libavutil/float_dsp.h
Normal file
100
project/jni/ffmpeg/libavutil/float_dsp.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 AVUTIL_FLOAT_DSP_H
|
||||
#define AVUTIL_FLOAT_DSP_H
|
||||
|
||||
typedef struct AVFloatDSPContext {
|
||||
/**
|
||||
* Calculate the product of two vectors of floats and store the result in
|
||||
* a vector of floats.
|
||||
*
|
||||
* @param dst output vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param src0 first input vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param src1 second input vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param len number of elements in the input
|
||||
* constraints: multiple of 16
|
||||
*/
|
||||
void (*vector_fmul)(float *dst, const float *src0, const float *src1,
|
||||
int len);
|
||||
|
||||
/**
|
||||
* Multiply a vector of floats by a scalar float and add to
|
||||
* destination vector. Source and destination vectors must
|
||||
* overlap exactly or not at all.
|
||||
*
|
||||
* @param dst result vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param src input vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param mul scalar value
|
||||
* @param len length of vector
|
||||
* constraints: multiple of 16
|
||||
*/
|
||||
void (*vector_fmac_scalar)(float *dst, const float *src, float mul,
|
||||
int len);
|
||||
|
||||
/**
|
||||
* Multiply a vector of floats by a scalar float. Source and
|
||||
* destination vectors must overlap exactly or not at all.
|
||||
*
|
||||
* @param dst result vector
|
||||
* constraints: 16-byte aligned
|
||||
* @param src input vector
|
||||
* constraints: 16-byte aligned
|
||||
* @param mul scalar value
|
||||
* @param len length of vector
|
||||
* constraints: multiple of 4
|
||||
*/
|
||||
void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
|
||||
int len);
|
||||
|
||||
/**
|
||||
* Multiply a vector of double by a scalar double. Source and
|
||||
* destination vectors must overlap exactly or not at all.
|
||||
*
|
||||
* @param dst result vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param src input vector
|
||||
* constraints: 32-byte aligned
|
||||
* @param mul scalar value
|
||||
* @param len length of vector
|
||||
* constraints: multiple of 8
|
||||
*/
|
||||
void (*vector_dmul_scalar)(double *dst, const double *src, double mul,
|
||||
int len);
|
||||
} AVFloatDSPContext;
|
||||
|
||||
/**
|
||||
* Initialize a float DSP context.
|
||||
*
|
||||
* @param fdsp float DSP context
|
||||
* @param strict setting to non-zero avoids using functions which may not be IEEE-754 compliant
|
||||
*/
|
||||
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int strict);
|
||||
|
||||
|
||||
void ff_float_dsp_init_arm(AVFloatDSPContext *fdsp);
|
||||
void ff_float_dsp_init_ppc(AVFloatDSPContext *fdsp, int strict);
|
||||
void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp);
|
||||
void ff_float_dsp_init_mips(AVFloatDSPContext *fdsp);
|
||||
|
||||
#endif /* AVUTIL_FLOAT_DSP_H */
|
||||
368
project/jni/ffmpeg/libavutil/imgutils.c
Normal file
368
project/jni/ffmpeg/libavutil/imgutils.c
Normal file
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* 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
|
||||
* misc image utilities
|
||||
*/
|
||||
|
||||
#include "avassert.h"
|
||||
#include "common.h"
|
||||
#include "imgutils.h"
|
||||
#include "internal.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "log.h"
|
||||
#include "pixdesc.h"
|
||||
|
||||
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
|
||||
const AVPixFmtDescriptor *pixdesc)
|
||||
{
|
||||
int i;
|
||||
memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0]));
|
||||
if (max_pixstep_comps)
|
||||
memset(max_pixstep_comps, 0, 4*sizeof(max_pixstep_comps[0]));
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
const AVComponentDescriptor *comp = &(pixdesc->comp[i]);
|
||||
if ((comp->step_minus1+1) > max_pixsteps[comp->plane]) {
|
||||
max_pixsteps[comp->plane] = comp->step_minus1+1;
|
||||
if (max_pixstep_comps)
|
||||
max_pixstep_comps[comp->plane] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline
|
||||
int image_get_linesize(int width, int plane,
|
||||
int max_step, int max_step_comp,
|
||||
const AVPixFmtDescriptor *desc)
|
||||
{
|
||||
int s, shifted_w, linesize;
|
||||
|
||||
if (!desc)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
if (width < 0)
|
||||
return AVERROR(EINVAL);
|
||||
s = (max_step_comp == 1 || max_step_comp == 2) ? desc->log2_chroma_w : 0;
|
||||
shifted_w = ((width + (1 << s) - 1)) >> s;
|
||||
if (shifted_w && max_step > INT_MAX / shifted_w)
|
||||
return AVERROR(EINVAL);
|
||||
linesize = max_step * shifted_w;
|
||||
|
||||
if (desc->flags & PIX_FMT_BITSTREAM)
|
||||
linesize = (linesize + 7) >> 3;
|
||||
return linesize;
|
||||
}
|
||||
|
||||
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
int max_step [4]; /* max pixel step for each plane */
|
||||
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
|
||||
|
||||
if ((unsigned)pix_fmt >= AV_PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
|
||||
return image_get_linesize(width, plane, max_step[plane], max_step_comp[plane], desc);
|
||||
}
|
||||
|
||||
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
|
||||
{
|
||||
int i, ret;
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
int max_step [4]; /* max pixel step for each plane */
|
||||
int max_step_comp[4]; /* the component for each plane which has the max pixel step */
|
||||
|
||||
memset(linesizes, 0, 4*sizeof(linesizes[0]));
|
||||
|
||||
if (!desc || desc->flags & PIX_FMT_HWACCEL)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
av_image_fill_max_pixsteps(max_step, max_step_comp, desc);
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((ret = image_get_linesize(width, i, max_step[i], max_step_comp[i], desc)) < 0)
|
||||
return ret;
|
||||
linesizes[i] = ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height,
|
||||
uint8_t *ptr, const int linesizes[4])
|
||||
{
|
||||
int i, total_size, size[4] = { 0 }, has_plane[4] = { 0 };
|
||||
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
memset(data , 0, sizeof(data[0])*4);
|
||||
|
||||
if (!desc || desc->flags & PIX_FMT_HWACCEL)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
data[0] = ptr;
|
||||
if (linesizes[0] > (INT_MAX - 1024) / height)
|
||||
return AVERROR(EINVAL);
|
||||
size[0] = linesizes[0] * height;
|
||||
|
||||
if (desc->flags & PIX_FMT_PAL ||
|
||||
desc->flags & PIX_FMT_PSEUDOPAL) {
|
||||
size[0] = (size[0] + 3) & ~3;
|
||||
data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */
|
||||
return size[0] + 256 * 4;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
has_plane[desc->comp[i].plane] = 1;
|
||||
|
||||
total_size = size[0];
|
||||
for (i = 1; i < 4 && has_plane[i]; i++) {
|
||||
int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
|
||||
data[i] = data[i-1] + size[i-1];
|
||||
h = (height + (1 << s) - 1) >> s;
|
||||
if (linesizes[i] > INT_MAX / h)
|
||||
return AVERROR(EINVAL);
|
||||
size[i] = h * linesizes[i];
|
||||
if (total_size > INT_MAX - size[i])
|
||||
return AVERROR(EINVAL);
|
||||
total_size += size[i];
|
||||
}
|
||||
|
||||
return total_size;
|
||||
}
|
||||
|
||||
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
int r, g, b;
|
||||
|
||||
switch (pix_fmt) {
|
||||
case AV_PIX_FMT_RGB8:
|
||||
r = (i>>5 )*36;
|
||||
g = ((i>>2)&7)*36;
|
||||
b = (i&3 )*85;
|
||||
break;
|
||||
case AV_PIX_FMT_BGR8:
|
||||
b = (i>>6 )*85;
|
||||
g = ((i>>3)&7)*36;
|
||||
r = (i&7 )*36;
|
||||
break;
|
||||
case AV_PIX_FMT_RGB4_BYTE:
|
||||
r = (i>>3 )*255;
|
||||
g = ((i>>1)&3)*85;
|
||||
b = (i&1 )*255;
|
||||
break;
|
||||
case AV_PIX_FMT_BGR4_BYTE:
|
||||
b = (i>>3 )*255;
|
||||
g = ((i>>1)&3)*85;
|
||||
r = (i&1 )*255;
|
||||
break;
|
||||
case AV_PIX_FMT_GRAY8:
|
||||
r = b = g = i;
|
||||
break;
|
||||
default:
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
pal[i] = b + (g<<8) + (r<<16) + (0xFFU<<24);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
|
||||
int w, int h, enum AVPixelFormat pix_fmt, int align)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
int i, ret;
|
||||
uint8_t *buf;
|
||||
|
||||
if (!desc)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
|
||||
return ret;
|
||||
if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, align>7 ? FFALIGN(w, 8) : w)) < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
linesizes[i] = FFALIGN(linesizes[i], align);
|
||||
|
||||
if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, NULL, linesizes)) < 0)
|
||||
return ret;
|
||||
buf = av_malloc(ret + align);
|
||||
if (!buf)
|
||||
return AVERROR(ENOMEM);
|
||||
if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) {
|
||||
av_free(buf);
|
||||
return ret;
|
||||
}
|
||||
if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL)
|
||||
avpriv_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct ImgUtils {
|
||||
const AVClass *class;
|
||||
int log_offset;
|
||||
void *log_ctx;
|
||||
} ImgUtils;
|
||||
|
||||
static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) };
|
||||
|
||||
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
|
||||
{
|
||||
ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx };
|
||||
|
||||
if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
|
||||
return 0;
|
||||
|
||||
av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
void av_image_copy_plane(uint8_t *dst, int dst_linesize,
|
||||
const uint8_t *src, int src_linesize,
|
||||
int bytewidth, int height)
|
||||
{
|
||||
if (!dst || !src)
|
||||
return;
|
||||
av_assert0(abs(src_linesize) >= bytewidth);
|
||||
av_assert0(abs(dst_linesize) >= bytewidth);
|
||||
for (;height > 0; height--) {
|
||||
memcpy(dst, src, bytewidth);
|
||||
dst += dst_linesize;
|
||||
src += src_linesize;
|
||||
}
|
||||
}
|
||||
|
||||
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
|
||||
const uint8_t *src_data[4], const int src_linesizes[4],
|
||||
enum AVPixelFormat pix_fmt, int width, int height)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
|
||||
if (!desc || desc->flags & PIX_FMT_HWACCEL)
|
||||
return;
|
||||
|
||||
if (desc->flags & PIX_FMT_PAL ||
|
||||
desc->flags & PIX_FMT_PSEUDOPAL) {
|
||||
av_image_copy_plane(dst_data[0], dst_linesizes[0],
|
||||
src_data[0], src_linesizes[0],
|
||||
width, height);
|
||||
/* copy the palette */
|
||||
memcpy(dst_data[1], src_data[1], 4*256);
|
||||
} else {
|
||||
int i, planes_nb = 0;
|
||||
|
||||
for (i = 0; i < desc->nb_components; i++)
|
||||
planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);
|
||||
|
||||
for (i = 0; i < planes_nb; i++) {
|
||||
int h = height;
|
||||
int bwidth = av_image_get_linesize(pix_fmt, width, i);
|
||||
if (bwidth < 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "av_image_get_linesize failed\n");
|
||||
return;
|
||||
}
|
||||
if (i == 1 || i == 2) {
|
||||
h= -((-height)>>desc->log2_chroma_h);
|
||||
}
|
||||
av_image_copy_plane(dst_data[i], dst_linesizes[i],
|
||||
src_data[i], src_linesizes[i],
|
||||
bwidth, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
|
||||
const uint8_t *src,
|
||||
enum AVPixelFormat pix_fmt, int width, int height, int align)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
if ((ret = av_image_check_size(width, height, 0, NULL)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = av_image_fill_linesizes(dst_linesize, pix_fmt, width)) < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
dst_linesize[i] = FFALIGN(dst_linesize[i], align);
|
||||
|
||||
if ((ret = av_image_fill_pointers(dst_data, pix_fmt, width, NULL, dst_linesize)) < 0)
|
||||
return ret;
|
||||
|
||||
return av_image_fill_pointers(dst_data, pix_fmt, height, (uint8_t *)src, dst_linesize);
|
||||
}
|
||||
|
||||
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
|
||||
{
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
uint8_t *data[4];
|
||||
int linesize[4];
|
||||
|
||||
if (!desc)
|
||||
return AVERROR(EINVAL);
|
||||
if (av_image_check_size(width, height, 0, NULL) < 0)
|
||||
return AVERROR(EINVAL);
|
||||
if (desc->flags & PIX_FMT_PSEUDOPAL)
|
||||
// do not include palette for these pseudo-paletted formats
|
||||
return width * height;
|
||||
return av_image_fill_arrays(data, linesize, NULL, pix_fmt, width, height, align);
|
||||
}
|
||||
|
||||
int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
|
||||
const uint8_t * const src_data[4], const int src_linesize[4],
|
||||
enum AVPixelFormat pix_fmt, int width, int height, int align)
|
||||
{
|
||||
int i, j, nb_planes = 0, linesize[4];
|
||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
|
||||
int size = av_image_get_buffer_size(pix_fmt, width, height, align);
|
||||
|
||||
if (size > dst_size || size < 0)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
for (i = 0; i < desc->nb_components; i++)
|
||||
nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
|
||||
nb_planes++;
|
||||
|
||||
av_image_fill_linesizes(linesize, pix_fmt, width);
|
||||
for (i = 0; i < nb_planes; i++) {
|
||||
int h, shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
|
||||
const uint8_t *src = src_data[i];
|
||||
h = (height + (1 << shift) - 1) >> shift;
|
||||
|
||||
for (j = 0; j < h; j++) {
|
||||
memcpy(dst, src, linesize[i]);
|
||||
dst += FFALIGN(linesize[i], align);
|
||||
src += src_linesize[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (desc->flags & PIX_FMT_PAL) {
|
||||
uint32_t *d32 = (uint32_t *)(((size_t)dst + 3) & ~3);
|
||||
for (i = 0; i<256; i++)
|
||||
AV_WL32(d32 + i, AV_RN32(src_data[1] + 4*i));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
200
project/jni/ffmpeg/libavutil/imgutils.h
Normal file
200
project/jni/ffmpeg/libavutil/imgutils.h
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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 AVUTIL_IMGUTILS_H
|
||||
#define AVUTIL_IMGUTILS_H
|
||||
|
||||
/**
|
||||
* @file
|
||||
* misc image utilities
|
||||
*
|
||||
* @addtogroup lavu_picture
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
#include "pixdesc.h"
|
||||
|
||||
/**
|
||||
* Compute the max pixel step for each plane of an image with a
|
||||
* format described by pixdesc.
|
||||
*
|
||||
* The pixel step is the distance in bytes between the first byte of
|
||||
* the group of bytes which describe a pixel component and the first
|
||||
* byte of the successive group in the same plane for the same
|
||||
* component.
|
||||
*
|
||||
* @param max_pixsteps an array which is filled with the max pixel step
|
||||
* for each plane. Since a plane may contain different pixel
|
||||
* components, the computed max_pixsteps[plane] is relative to the
|
||||
* component in the plane with the max pixel step.
|
||||
* @param max_pixstep_comps an array which is filled with the component
|
||||
* for each plane which has the max pixel step. May be NULL.
|
||||
*/
|
||||
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4],
|
||||
const AVPixFmtDescriptor *pixdesc);
|
||||
|
||||
/**
|
||||
* Compute the size of an image line with format pix_fmt and width
|
||||
* width for the plane plane.
|
||||
*
|
||||
* @return the computed size in bytes
|
||||
*/
|
||||
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane);
|
||||
|
||||
/**
|
||||
* Fill plane linesizes for an image with pixel format pix_fmt and
|
||||
* width width.
|
||||
*
|
||||
* @param linesizes array to be filled with the linesize for each plane
|
||||
* @return >= 0 in case of success, a negative error code otherwise
|
||||
*/
|
||||
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width);
|
||||
|
||||
/**
|
||||
* Fill plane data pointers for an image with pixel format pix_fmt and
|
||||
* height height.
|
||||
*
|
||||
* @param data pointers array to be filled with the pointer for each image plane
|
||||
* @param ptr the pointer to a buffer which will contain the image
|
||||
* @param linesizes the array containing the linesize for each
|
||||
* plane, should be filled by av_image_fill_linesizes()
|
||||
* @return the size in bytes required for the image buffer, a negative
|
||||
* error code in case of failure
|
||||
*/
|
||||
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height,
|
||||
uint8_t *ptr, const int linesizes[4]);
|
||||
|
||||
/**
|
||||
* Allocate an image with size w and h and pixel format pix_fmt, and
|
||||
* fill pointers and linesizes accordingly.
|
||||
* The allocated image buffer has to be freed by using
|
||||
* av_freep(&pointers[0]).
|
||||
*
|
||||
* @param align the value to use for buffer size alignment
|
||||
* @return the size in bytes required for the image buffer, a negative
|
||||
* error code in case of failure
|
||||
*/
|
||||
int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
|
||||
int w, int h, enum AVPixelFormat pix_fmt, int align);
|
||||
|
||||
/**
|
||||
* Copy image plane from src to dst.
|
||||
* That is, copy "height" number of lines of "bytewidth" bytes each.
|
||||
* The first byte of each successive line is separated by *_linesize
|
||||
* bytes.
|
||||
*
|
||||
* bytewidth must be contained by both absolute values of dst_linesize
|
||||
* and src_linesize, otherwise the function behavior is undefined.
|
||||
*
|
||||
* @param dst_linesize linesize for the image plane in dst
|
||||
* @param src_linesize linesize for the image plane in src
|
||||
*/
|
||||
void av_image_copy_plane(uint8_t *dst, int dst_linesize,
|
||||
const uint8_t *src, int src_linesize,
|
||||
int bytewidth, int height);
|
||||
|
||||
/**
|
||||
* Copy image in src_data to dst_data.
|
||||
*
|
||||
* @param dst_linesizes linesizes for the image in dst_data
|
||||
* @param src_linesizes linesizes for the image in src_data
|
||||
*/
|
||||
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],
|
||||
const uint8_t *src_data[4], const int src_linesizes[4],
|
||||
enum AVPixelFormat pix_fmt, int width, int height);
|
||||
|
||||
/**
|
||||
* Setup the data pointers and linesizes based on the specified image
|
||||
* parameters and the provided array.
|
||||
*
|
||||
* The fields of the given image are filled in by using the src
|
||||
* address which points to the image data buffer. Depending on the
|
||||
* specified pixel format, one or multiple image data pointers and
|
||||
* line sizes will be set. If a planar format is specified, several
|
||||
* pointers will be set pointing to the different picture planes and
|
||||
* the line sizes of the different planes will be stored in the
|
||||
* lines_sizes array. Call with src == NULL to get the required
|
||||
* size for the src buffer.
|
||||
*
|
||||
* To allocate the buffer and fill in the dst_data and dst_linesize in
|
||||
* one call, use av_image_alloc().
|
||||
*
|
||||
* @param dst_data data pointers to be filled in
|
||||
* @param dst_linesizes linesizes for the image in dst_data to be filled in
|
||||
* @param src buffer which will contain or contains the actual image data, can be NULL
|
||||
* @param pix_fmt the pixel format of the image
|
||||
* @param width the width of the image in pixels
|
||||
* @param height the height of the image in pixels
|
||||
* @param align the value used in src for linesize alignment
|
||||
* @return the size in bytes required for src, a negative error code
|
||||
* in case of failure
|
||||
*/
|
||||
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
|
||||
const uint8_t *src,
|
||||
enum AVPixelFormat pix_fmt, int width, int height, int align);
|
||||
|
||||
/**
|
||||
* Return the size in bytes of the amount of data required to store an
|
||||
* image with the given parameters.
|
||||
*
|
||||
* @param[in] align the assumed linesize alignment
|
||||
*/
|
||||
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);
|
||||
|
||||
/**
|
||||
* Copy image data from an image into a buffer.
|
||||
*
|
||||
* av_image_get_buffer_size() can be used to compute the required size
|
||||
* for the buffer to fill.
|
||||
*
|
||||
* @param dst a buffer into which picture data will be copied
|
||||
* @param dst_size the size in bytes of dst
|
||||
* @param src_data pointers containing the source image data
|
||||
* @param src_linesizes linesizes for the image in src_data
|
||||
* @param pix_fmt the pixel format of the source image
|
||||
* @param width the width of the source image in pixels
|
||||
* @param height the height of the source image in pixels
|
||||
* @param align the assumed linesize alignment for dst
|
||||
* @return the number of bytes written to dst, or a negative value
|
||||
* (error code) on error
|
||||
*/
|
||||
int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
|
||||
const uint8_t * const src_data[4], const int src_linesize[4],
|
||||
enum AVPixelFormat pix_fmt, int width, int height, int align);
|
||||
|
||||
/**
|
||||
* Check if the given dimension of an image is valid, meaning that all
|
||||
* bytes of the image can be addressed with a signed int.
|
||||
*
|
||||
* @param w the width of the picture
|
||||
* @param h the height of the picture
|
||||
* @param log_offset the offset to sum to the log level for logging with log_ctx
|
||||
* @param log_ctx the parent logging context, it may be NULL
|
||||
* @return >= 0 if valid, a negative error code otherwise
|
||||
*/
|
||||
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx);
|
||||
|
||||
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif /* AVUTIL_IMGUTILS_H */
|
||||
196
project/jni/ffmpeg/libavutil/integer.c
Normal file
196
project/jni/ffmpeg/libavutil/integer.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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
|
||||
* arbitrary precision integers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "integer.h"
|
||||
#include "avassert.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;
|
||||
|
||||
av_assert2((int16_t)a.v[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b.v[AV_INTEGER_SIZE-1] >= 0);
|
||||
av_assert2(av_log2_i(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
|
||||
|
||||
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);
|
||||
|
||||
av_assert0(av_i2int(ai) == a);
|
||||
av_assert0(av_i2int(bi) == b);
|
||||
av_assert0(av_i2int(av_add_i(ai,bi)) == a+b);
|
||||
av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b);
|
||||
av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b);
|
||||
av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9);
|
||||
av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9);
|
||||
av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17);
|
||||
av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17);
|
||||
av_assert0(av_log2_i(ai) == av_log2(a));
|
||||
av_assert0(av_i2int(av_div_i(ai,bi)) == a/b);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
86
project/jni/ffmpeg/libavutil/integer.h
Normal file
86
project/jni/ffmpeg/libavutil/integer.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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
|
||||
* arbitrary precision integers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_INTEGER_H
|
||||
#define AVUTIL_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;
|
||||
|
||||
/**
|
||||
* Return the rounded-down value of the base 2 logarithm of the given
|
||||
* AVInteger. This is simply the index of the most significant bit
|
||||
* which is 1, or 0 if all bits are 0.
|
||||
*/
|
||||
int av_log2_i(AVInteger a) av_const;
|
||||
AVInteger av_mul_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* Return 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;
|
||||
|
||||
/**
|
||||
* Return a % b.
|
||||
* @param quot a/b will be stored here.
|
||||
*/
|
||||
AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
|
||||
|
||||
/**
|
||||
* Return a/b.
|
||||
*/
|
||||
AVInteger av_div_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* Convert the given int64_t to an AVInteger.
|
||||
*/
|
||||
AVInteger av_int2i(int64_t a) av_const;
|
||||
|
||||
/**
|
||||
* Convert the given AVInteger to an int64_t.
|
||||
* If the AVInteger is too large to fit into an int64_t,
|
||||
* then only the least significant 64 bits will be used.
|
||||
*/
|
||||
int64_t av_i2int(AVInteger a) av_const;
|
||||
|
||||
#endif /* AVUTIL_INTEGER_H */
|
||||
149
project/jni/ffmpeg/libavutil/internal.h
Normal file
149
project/jni/ffmpeg/libavutil/internal.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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 internal API header
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_INTERNAL_H
|
||||
#define AVUTIL_INTERNAL_H
|
||||
|
||||
#if !defined(DEBUG) && !defined(NDEBUG)
|
||||
# define NDEBUG
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include "config.h"
|
||||
#include "attributes.h"
|
||||
#include "timer.h"
|
||||
#include "cpu.h"
|
||||
#include "dict.h"
|
||||
|
||||
#ifndef attribute_align_arg
|
||||
#if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
|
||||
# define attribute_align_arg __attribute__((force_align_arg_pointer))
|
||||
#else
|
||||
# define attribute_align_arg
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && CONFIG_SHARED
|
||||
# define av_export __declspec(dllimport)
|
||||
#else
|
||||
# define av_export
|
||||
#endif
|
||||
|
||||
#ifndef INT_BIT
|
||||
# define INT_BIT (CHAR_BIT * sizeof(int))
|
||||
#endif
|
||||
|
||||
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
|
||||
{\
|
||||
p = av_malloc(size);\
|
||||
if (p == NULL && (size) != 0) {\
|
||||
av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
|
||||
goto label;\
|
||||
}\
|
||||
}
|
||||
|
||||
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
|
||||
{\
|
||||
p = av_mallocz(size);\
|
||||
if (p == NULL && (size) != 0) {\
|
||||
av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
|
||||
goto label;\
|
||||
}\
|
||||
}
|
||||
|
||||
#include "libm.h"
|
||||
|
||||
/**
|
||||
* Return NULL if CONFIG_SMALL is true, otherwise the argument
|
||||
* without modification. Used to disable the definition of strings
|
||||
* (for example AVCodec long_names).
|
||||
*/
|
||||
#if CONFIG_SMALL
|
||||
# define NULL_IF_CONFIG_SMALL(x) NULL
|
||||
#else
|
||||
# define NULL_IF_CONFIG_SMALL(x) x
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Define a function with only the non-default version specified.
|
||||
*
|
||||
* On systems with ELF shared libraries, all symbols exported from
|
||||
* FFmpeg libraries are tagged with the name and major version of the
|
||||
* library to which they belong. If a function is moved from one
|
||||
* library to another, a wrapper must be retained in the original
|
||||
* location to preserve binary compatibility.
|
||||
*
|
||||
* Functions defined with this macro will never be used to resolve
|
||||
* symbols by the build-time linker.
|
||||
*
|
||||
* @param type return type of function
|
||||
* @param name name of function
|
||||
* @param args argument list of function
|
||||
* @param ver version tag to assign function
|
||||
*/
|
||||
#if HAVE_SYMVER_ASM_LABEL
|
||||
# define FF_SYMVER(type, name, args, ver) \
|
||||
type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
|
||||
type ff_##name args
|
||||
#elif HAVE_SYMVER_GNU_ASM
|
||||
# define FF_SYMVER(type, name, args, ver) \
|
||||
__asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
|
||||
type ff_##name args; \
|
||||
type ff_##name args
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Return NULL if a threading library has not been enabled.
|
||||
* Used to disable threading functions in AVCodec definitions
|
||||
* when not needed.
|
||||
*/
|
||||
#if HAVE_THREADS
|
||||
# define ONLY_IF_THREADS_ENABLED(x) x
|
||||
#else
|
||||
# define ONLY_IF_THREADS_ENABLED(x) NULL
|
||||
#endif
|
||||
|
||||
#if HAVE_MMX_INLINE
|
||||
/**
|
||||
* Empty mmx state.
|
||||
* this must be called between any dsp function and float/double code.
|
||||
* for example sin(); dsp->idct_put(); emms_c(); cos()
|
||||
*/
|
||||
static av_always_inline void emms_c(void)
|
||||
{
|
||||
if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
|
||||
__asm__ volatile ("emms" ::: "memory");
|
||||
}
|
||||
#elif HAVE_MMX && HAVE_MM_EMPTY
|
||||
# include <mmintrin.h>
|
||||
# define emms_c _mm_empty
|
||||
#else
|
||||
# define emms_c()
|
||||
#endif /* HAVE_MMX_INLINE */
|
||||
|
||||
#endif /* AVUTIL_INTERNAL_H */
|
||||
77
project/jni/ffmpeg/libavutil/intfloat.h
Normal file
77
project/jni/ffmpeg/libavutil/intfloat.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Mans Rullgard
|
||||
*
|
||||
* This file is part of Libav.
|
||||
*
|
||||
* Libav 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.
|
||||
*
|
||||
* Libav 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 Libav; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_INTFLOAT_H
|
||||
#define AVUTIL_INTFLOAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "attributes.h"
|
||||
|
||||
union av_intfloat32 {
|
||||
uint32_t i;
|
||||
float f;
|
||||
};
|
||||
|
||||
union av_intfloat64 {
|
||||
uint64_t i;
|
||||
double f;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reinterpret a 32-bit integer as a float.
|
||||
*/
|
||||
static av_always_inline float av_int2float(uint32_t i)
|
||||
{
|
||||
union av_intfloat32 v;
|
||||
v.i = i;
|
||||
return v.f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinterpret a float as a 32-bit integer.
|
||||
*/
|
||||
static av_always_inline uint32_t av_float2int(float f)
|
||||
{
|
||||
union av_intfloat32 v;
|
||||
v.f = f;
|
||||
return v.i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinterpret a 64-bit integer as a double.
|
||||
*/
|
||||
static av_always_inline double av_int2double(uint64_t i)
|
||||
{
|
||||
union av_intfloat64 v;
|
||||
v.i = i;
|
||||
return v.f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinterpret a double as a 64-bit integer.
|
||||
*/
|
||||
static av_always_inline uint64_t av_double2int(double f)
|
||||
{
|
||||
union av_intfloat64 v;
|
||||
v.f = f;
|
||||
return v.i;
|
||||
}
|
||||
|
||||
#endif /* AVUTIL_INTFLOAT_H */
|
||||
97
project/jni/ffmpeg/libavutil/intfloat_readwrite.c
Normal file
97
project/jni/ffmpeg/libavutil/intfloat_readwrite.c
Normal file
@@ -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
|
||||
* portable IEEE float/double read/write functions
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mathematics.h"
|
||||
#include "intfloat_readwrite.h"
|
||||
|
||||
double av_int2dbl(int64_t v){
|
||||
if((uint64_t)v+v > 0xFFEULL<<52)
|
||||
return NAN;
|
||||
return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
|
||||
}
|
||||
|
||||
float av_int2flt(int32_t v){
|
||||
if((uint32_t)v+v > 0xFF000000U)
|
||||
return NAN;
|
||||
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 NAN;
|
||||
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 != INFINITY)
|
||||
ext.mantissa[0] = ~0;
|
||||
}
|
||||
if (d < 0)
|
||||
ext.exponent[0] |= 0x80;
|
||||
return ext;
|
||||
}
|
||||
40
project/jni/ffmpeg/libavutil/intfloat_readwrite.h
Normal file
40
project/jni/ffmpeg/libavutil/intfloat_readwrite.h
Normal file
@@ -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 AVUTIL_INTFLOAT_READWRITE_H
|
||||
#define AVUTIL_INTFLOAT_READWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "attributes.h"
|
||||
|
||||
/* IEEE 80 bits extended float */
|
||||
typedef struct AVExtFloat {
|
||||
uint8_t exponent[2];
|
||||
uint8_t mantissa[8];
|
||||
} AVExtFloat;
|
||||
|
||||
attribute_deprecated double av_int2dbl(int64_t v) av_const;
|
||||
attribute_deprecated float av_int2flt(int32_t v) av_const;
|
||||
attribute_deprecated double av_ext2dbl(const AVExtFloat ext) av_const;
|
||||
attribute_deprecated int64_t av_dbl2int(double d) av_const;
|
||||
attribute_deprecated int32_t av_flt2int(float d) av_const;
|
||||
attribute_deprecated AVExtFloat av_dbl2ext(double d) av_const;
|
||||
|
||||
#endif /* AVUTIL_INTFLOAT_READWRITE_H */
|
||||
39
project/jni/ffmpeg/libavutil/intmath.c
Normal file
39
project/jni/ffmpeg/libavutil/intmath.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 "intmath.h"
|
||||
|
||||
/* undef these to get the function prototypes from common.h */
|
||||
#undef av_log2
|
||||
#undef av_log2_16bit
|
||||
#include "common.h"
|
||||
|
||||
int av_log2(unsigned v)
|
||||
{
|
||||
return ff_log2(v);
|
||||
}
|
||||
|
||||
int av_log2_16bit(unsigned v)
|
||||
{
|
||||
return ff_log2_16bit(v);
|
||||
}
|
||||
|
||||
int av_ctz(int v)
|
||||
{
|
||||
return ff_ctz(v);
|
||||
}
|
||||
150
project/jni/ffmpeg/libavutil/intmath.h
Normal file
150
project/jni/ffmpeg/libavutil/intmath.h
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Mans Rullgard <mans@mansr.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 AVUTIL_INTMATH_H
|
||||
#define AVUTIL_INTMATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "attributes.h"
|
||||
|
||||
#if ARCH_ARM
|
||||
# include "arm/intmath.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_internal
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if ARCH_ARM
|
||||
# include "arm/intmath.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
|
||||
|
||||
#ifndef ff_log2
|
||||
# define ff_log2(x) (31 - __builtin_clz((x)|1))
|
||||
# ifndef ff_log2_16bit
|
||||
# define ff_log2_16bit av_log2
|
||||
# endif
|
||||
#endif /* ff_log2 */
|
||||
|
||||
#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
|
||||
|
||||
extern const uint8_t ff_log2_tab[256];
|
||||
|
||||
#ifndef ff_log2
|
||||
#define ff_log2 ff_log2_c
|
||||
static av_always_inline av_const int ff_log2_c(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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ff_log2_16bit
|
||||
#define ff_log2_16bit ff_log2_16bit_c
|
||||
static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
|
||||
{
|
||||
int n = 0;
|
||||
if (v & 0xff00) {
|
||||
v >>= 8;
|
||||
n += 8;
|
||||
}
|
||||
n += ff_log2_tab[v];
|
||||
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define av_log2 ff_log2
|
||||
#define av_log2_16bit ff_log2_16bit
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_math
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
|
||||
#ifndef ff_ctz
|
||||
#define ff_ctz(v) __builtin_ctz(v)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ff_ctz
|
||||
#define ff_ctz ff_ctz_c
|
||||
static av_always_inline av_const int ff_ctz_c(int v)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (v & 0x1)
|
||||
return 0;
|
||||
|
||||
c = 1;
|
||||
if (!(v & 0xffff)) {
|
||||
v >>= 16;
|
||||
c += 16;
|
||||
}
|
||||
if (!(v & 0xff)) {
|
||||
v >>= 8;
|
||||
c += 8;
|
||||
}
|
||||
if (!(v & 0xf)) {
|
||||
v >>= 4;
|
||||
c += 4;
|
||||
}
|
||||
if (!(v & 0x3)) {
|
||||
v >>= 2;
|
||||
c += 2;
|
||||
}
|
||||
c -= v & 0x1;
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Trailing zero bit count.
|
||||
*
|
||||
* @param v input value. If v is 0, the result is undefined.
|
||||
* @return the number of trailing 0-bits
|
||||
*/
|
||||
int av_ctz(int v);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* AVUTIL_INTMATH_H */
|
||||
555
project/jni/ffmpeg/libavutil/intreadwrite.h
Normal file
555
project/jni/ffmpeg/libavutil/intreadwrite.h
Normal file
@@ -0,0 +1,555 @@
|
||||
/*
|
||||
* 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 AVUTIL_INTREADWRITE_H
|
||||
#define AVUTIL_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "libavutil/avconfig.h"
|
||||
#include "attributes.h"
|
||||
#include "bswap.h"
|
||||
|
||||
typedef union {
|
||||
uint64_t u64;
|
||||
uint32_t u32[2];
|
||||
uint16_t u16[4];
|
||||
uint8_t u8 [8];
|
||||
double f64;
|
||||
float f32[2];
|
||||
} av_alias av_alias64;
|
||||
|
||||
typedef union {
|
||||
uint32_t u32;
|
||||
uint16_t u16[2];
|
||||
uint8_t u8 [4];
|
||||
float f32;
|
||||
} av_alias av_alias32;
|
||||
|
||||
typedef union {
|
||||
uint16_t u16;
|
||||
uint8_t u8 [2];
|
||||
} av_alias av_alias16;
|
||||
|
||||
/*
|
||||
* Arch-specific headers can provide any combination of
|
||||
* AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros.
|
||||
* Preprocessor symbols must be defined, even if these are implemented
|
||||
* as inline functions.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if ARCH_ARM
|
||||
# include "arm/intreadwrite.h"
|
||||
#elif ARCH_AVR32
|
||||
# include "avr32/intreadwrite.h"
|
||||
#elif ARCH_MIPS
|
||||
# include "mips/intreadwrite.h"
|
||||
#elif ARCH_PPC
|
||||
# include "ppc/intreadwrite.h"
|
||||
#elif ARCH_TOMI
|
||||
# include "tomi/intreadwrite.h"
|
||||
#elif ARCH_X86
|
||||
# include "x86/intreadwrite.h"
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
/*
|
||||
* Map AV_RNXX <-> AV_R[BL]XX for all variants provided by per-arch headers.
|
||||
*/
|
||||
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
|
||||
# if defined(AV_RN16) && !defined(AV_RB16)
|
||||
# define AV_RB16(p) AV_RN16(p)
|
||||
# elif !defined(AV_RN16) && defined(AV_RB16)
|
||||
# define AV_RN16(p) AV_RB16(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN16) && !defined(AV_WB16)
|
||||
# define AV_WB16(p, v) AV_WN16(p, v)
|
||||
# elif !defined(AV_WN16) && defined(AV_WB16)
|
||||
# define AV_WN16(p, v) AV_WB16(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN24) && !defined(AV_RB24)
|
||||
# define AV_RB24(p) AV_RN24(p)
|
||||
# elif !defined(AV_RN24) && defined(AV_RB24)
|
||||
# define AV_RN24(p) AV_RB24(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN24) && !defined(AV_WB24)
|
||||
# define AV_WB24(p, v) AV_WN24(p, v)
|
||||
# elif !defined(AV_WN24) && defined(AV_WB24)
|
||||
# define AV_WN24(p, v) AV_WB24(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN32) && !defined(AV_RB32)
|
||||
# define AV_RB32(p) AV_RN32(p)
|
||||
# elif !defined(AV_RN32) && defined(AV_RB32)
|
||||
# define AV_RN32(p) AV_RB32(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN32) && !defined(AV_WB32)
|
||||
# define AV_WB32(p, v) AV_WN32(p, v)
|
||||
# elif !defined(AV_WN32) && defined(AV_WB32)
|
||||
# define AV_WN32(p, v) AV_WB32(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN64) && !defined(AV_RB64)
|
||||
# define AV_RB64(p) AV_RN64(p)
|
||||
# elif !defined(AV_RN64) && defined(AV_RB64)
|
||||
# define AV_RN64(p) AV_RB64(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN64) && !defined(AV_WB64)
|
||||
# define AV_WB64(p, v) AV_WN64(p, v)
|
||||
# elif !defined(AV_WN64) && defined(AV_WB64)
|
||||
# define AV_WN64(p, v) AV_WB64(p, v)
|
||||
# endif
|
||||
|
||||
#else /* AV_HAVE_BIGENDIAN */
|
||||
|
||||
# if defined(AV_RN16) && !defined(AV_RL16)
|
||||
# define AV_RL16(p) AV_RN16(p)
|
||||
# elif !defined(AV_RN16) && defined(AV_RL16)
|
||||
# define AV_RN16(p) AV_RL16(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN16) && !defined(AV_WL16)
|
||||
# define AV_WL16(p, v) AV_WN16(p, v)
|
||||
# elif !defined(AV_WN16) && defined(AV_WL16)
|
||||
# define AV_WN16(p, v) AV_WL16(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN24) && !defined(AV_RL24)
|
||||
# define AV_RL24(p) AV_RN24(p)
|
||||
# elif !defined(AV_RN24) && defined(AV_RL24)
|
||||
# define AV_RN24(p) AV_RL24(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN24) && !defined(AV_WL24)
|
||||
# define AV_WL24(p, v) AV_WN24(p, v)
|
||||
# elif !defined(AV_WN24) && defined(AV_WL24)
|
||||
# define AV_WN24(p, v) AV_WL24(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN32) && !defined(AV_RL32)
|
||||
# define AV_RL32(p) AV_RN32(p)
|
||||
# elif !defined(AV_RN32) && defined(AV_RL32)
|
||||
# define AV_RN32(p) AV_RL32(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN32) && !defined(AV_WL32)
|
||||
# define AV_WL32(p, v) AV_WN32(p, v)
|
||||
# elif !defined(AV_WN32) && defined(AV_WL32)
|
||||
# define AV_WN32(p, v) AV_WL32(p, v)
|
||||
# endif
|
||||
|
||||
# if defined(AV_RN64) && !defined(AV_RL64)
|
||||
# define AV_RL64(p) AV_RN64(p)
|
||||
# elif !defined(AV_RN64) && defined(AV_RL64)
|
||||
# define AV_RN64(p) AV_RL64(p)
|
||||
# endif
|
||||
|
||||
# if defined(AV_WN64) && !defined(AV_WL64)
|
||||
# define AV_WL64(p, v) AV_WN64(p, v)
|
||||
# elif !defined(AV_WN64) && defined(AV_WL64)
|
||||
# define AV_WN64(p, v) AV_WL64(p, v)
|
||||
# endif
|
||||
|
||||
#endif /* !AV_HAVE_BIGENDIAN */
|
||||
|
||||
/*
|
||||
* Define AV_[RW]N helper macros to simplify definitions not provided
|
||||
* by per-arch headers.
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && !defined(__TI_COMPILER_VERSION__)
|
||||
|
||||
union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias;
|
||||
union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias;
|
||||
union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias;
|
||||
|
||||
# define AV_RN(s, p) (((const union unaligned_##s *) (p))->l)
|
||||
# define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v))
|
||||
|
||||
#elif defined(__DECC)
|
||||
|
||||
# define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
|
||||
# define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
|
||||
|
||||
#elif AV_HAVE_FAST_UNALIGNED
|
||||
|
||||
# define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
|
||||
# define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
|
||||
|
||||
#else
|
||||
|
||||
#ifndef AV_RB16
|
||||
# define AV_RB16(x) \
|
||||
((((const uint8_t*)(x))[0] << 8) | \
|
||||
((const uint8_t*)(x))[1])
|
||||
#endif
|
||||
#ifndef AV_WB16
|
||||
# define AV_WB16(p, darg) do { \
|
||||
unsigned d = (darg); \
|
||||
((uint8_t*)(p))[1] = (d); \
|
||||
((uint8_t*)(p))[0] = (d)>>8; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL16
|
||||
# define AV_RL16(x) \
|
||||
((((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#endif
|
||||
#ifndef AV_WL16
|
||||
# define AV_WL16(p, darg) do { \
|
||||
unsigned d = (darg); \
|
||||
((uint8_t*)(p))[0] = (d); \
|
||||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB32
|
||||
# define AV_RB32(x) \
|
||||
(((uint32_t)((const uint8_t*)(x))[0] << 24) | \
|
||||
(((const uint8_t*)(x))[1] << 16) | \
|
||||
(((const uint8_t*)(x))[2] << 8) | \
|
||||
((const uint8_t*)(x))[3])
|
||||
#endif
|
||||
#ifndef AV_WB32
|
||||
# define AV_WB32(p, darg) do { \
|
||||
unsigned d = (darg); \
|
||||
((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)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL32
|
||||
# define AV_RL32(x) \
|
||||
(((uint32_t)((const uint8_t*)(x))[3] << 24) | \
|
||||
(((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#endif
|
||||
#ifndef AV_WL32
|
||||
# define AV_WL32(p, darg) do { \
|
||||
unsigned d = (darg); \
|
||||
((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)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB64
|
||||
# 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])
|
||||
#endif
|
||||
#ifndef AV_WB64
|
||||
# define AV_WB64(p, darg) do { \
|
||||
uint64_t d = (darg); \
|
||||
((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)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL64
|
||||
# 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])
|
||||
#endif
|
||||
#ifndef AV_WL64
|
||||
# define AV_WL64(p, darg) do { \
|
||||
uint64_t d = (darg); \
|
||||
((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
|
||||
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
# define AV_RN(s, p) AV_RB##s(p)
|
||||
# define AV_WN(s, p, v) AV_WB##s(p, v)
|
||||
#else
|
||||
# define AV_RN(s, p) AV_RL##s(p)
|
||||
# define AV_WN(s, p, v) AV_WL##s(p, v)
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_FAST_UNALIGNED */
|
||||
|
||||
#ifndef AV_RN16
|
||||
# define AV_RN16(p) AV_RN(16, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RN32
|
||||
# define AV_RN32(p) AV_RN(32, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RN64
|
||||
# define AV_RN64(p) AV_RN(64, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN16
|
||||
# define AV_WN16(p, v) AV_WN(16, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN32
|
||||
# define AV_WN32(p, v) AV_WN(32, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN64
|
||||
# define AV_WN64(p, v) AV_WN(64, p, v)
|
||||
#endif
|
||||
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
# define AV_RB(s, p) AV_RN##s(p)
|
||||
# define AV_WB(s, p, v) AV_WN##s(p, v)
|
||||
# define AV_RL(s, p) av_bswap##s(AV_RN##s(p))
|
||||
# define AV_WL(s, p, v) AV_WN##s(p, av_bswap##s(v))
|
||||
#else
|
||||
# define AV_RB(s, p) av_bswap##s(AV_RN##s(p))
|
||||
# define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
|
||||
# define AV_RL(s, p) AV_RN##s(p)
|
||||
# define AV_WL(s, p, v) AV_WN##s(p, v)
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
#ifndef AV_RB16
|
||||
# define AV_RB16(p) AV_RB(16, p)
|
||||
#endif
|
||||
#ifndef AV_WB16
|
||||
# define AV_WB16(p, v) AV_WB(16, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL16
|
||||
# define AV_RL16(p) AV_RL(16, p)
|
||||
#endif
|
||||
#ifndef AV_WL16
|
||||
# define AV_WL16(p, v) AV_WL(16, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB32
|
||||
# define AV_RB32(p) AV_RB(32, p)
|
||||
#endif
|
||||
#ifndef AV_WB32
|
||||
# define AV_WB32(p, v) AV_WB(32, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL32
|
||||
# define AV_RL32(p) AV_RL(32, p)
|
||||
#endif
|
||||
#ifndef AV_WL32
|
||||
# define AV_WL32(p, v) AV_WL(32, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB64
|
||||
# define AV_RB64(p) AV_RB(64, p)
|
||||
#endif
|
||||
#ifndef AV_WB64
|
||||
# define AV_WB64(p, v) AV_WB(64, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL64
|
||||
# define AV_RL64(p) AV_RL(64, p)
|
||||
#endif
|
||||
#ifndef AV_WL64
|
||||
# define AV_WL64(p, v) AV_WL(64, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RB24
|
||||
# define AV_RB24(x) \
|
||||
((((const uint8_t*)(x))[0] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[2])
|
||||
#endif
|
||||
#ifndef AV_WB24
|
||||
# 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)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RL24
|
||||
# define AV_RL24(x) \
|
||||
((((const uint8_t*)(x))[2] << 16) | \
|
||||
(((const uint8_t*)(x))[1] << 8) | \
|
||||
((const uint8_t*)(x))[0])
|
||||
#endif
|
||||
#ifndef AV_WL24
|
||||
# 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
|
||||
|
||||
/*
|
||||
* The AV_[RW]NA macros access naturally aligned data
|
||||
* in a type-safe way.
|
||||
*/
|
||||
|
||||
#define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s)
|
||||
#define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v))
|
||||
|
||||
#ifndef AV_RN16A
|
||||
# define AV_RN16A(p) AV_RNA(16, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RN32A
|
||||
# define AV_RN32A(p) AV_RNA(32, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_RN64A
|
||||
# define AV_RN64A(p) AV_RNA(64, p)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN16A
|
||||
# define AV_WN16A(p, v) AV_WNA(16, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN32A
|
||||
# define AV_WN32A(p, v) AV_WNA(32, p, v)
|
||||
#endif
|
||||
|
||||
#ifndef AV_WN64A
|
||||
# define AV_WN64A(p, v) AV_WNA(64, p, v)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The AV_COPYxxU macros are suitable for copying data to/from unaligned
|
||||
* memory locations.
|
||||
*/
|
||||
|
||||
#define AV_COPYU(n, d, s) AV_WN##n(d, AV_RN##n(s));
|
||||
|
||||
#ifndef AV_COPY16U
|
||||
# define AV_COPY16U(d, s) AV_COPYU(16, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY32U
|
||||
# define AV_COPY32U(d, s) AV_COPYU(32, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY64U
|
||||
# define AV_COPY64U(d, s) AV_COPYU(64, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY128U
|
||||
# define AV_COPY128U(d, s) \
|
||||
do { \
|
||||
AV_COPY64U(d, s); \
|
||||
AV_COPY64U((char *)(d) + 8, (const char *)(s) + 8); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
/* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be
|
||||
* naturally aligned. They may be implemented using MMX,
|
||||
* so emms_c() must be called before using any float code
|
||||
* afterwards.
|
||||
*/
|
||||
|
||||
#define AV_COPY(n, d, s) \
|
||||
(((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n)
|
||||
|
||||
#ifndef AV_COPY16
|
||||
# define AV_COPY16(d, s) AV_COPY(16, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY32
|
||||
# define AV_COPY32(d, s) AV_COPY(32, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY64
|
||||
# define AV_COPY64(d, s) AV_COPY(64, d, s)
|
||||
#endif
|
||||
|
||||
#ifndef AV_COPY128
|
||||
# define AV_COPY128(d, s) \
|
||||
do { \
|
||||
AV_COPY64(d, s); \
|
||||
AV_COPY64((char*)(d)+8, (char*)(s)+8); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b))
|
||||
|
||||
#ifndef AV_SWAP64
|
||||
# define AV_SWAP64(a, b) AV_SWAP(64, a, b)
|
||||
#endif
|
||||
|
||||
#define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0)
|
||||
|
||||
#ifndef AV_ZERO16
|
||||
# define AV_ZERO16(d) AV_ZERO(16, d)
|
||||
#endif
|
||||
|
||||
#ifndef AV_ZERO32
|
||||
# define AV_ZERO32(d) AV_ZERO(32, d)
|
||||
#endif
|
||||
|
||||
#ifndef AV_ZERO64
|
||||
# define AV_ZERO64(d) AV_ZERO(64, d)
|
||||
#endif
|
||||
|
||||
#ifndef AV_ZERO128
|
||||
# define AV_ZERO128(d) \
|
||||
do { \
|
||||
AV_ZERO64(d); \
|
||||
AV_ZERO64((char*)(d)+8); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_INTREADWRITE_H */
|
||||
102
project/jni/ffmpeg/libavutil/lfg.c
Normal file
102
project/jni/ffmpeg/libavutil/lfg.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 <limits.h>
|
||||
#include <math.h>
|
||||
#include "lfg.h"
|
||||
#include "md5.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "attributes.h"
|
||||
|
||||
av_cold void 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;
|
||||
}
|
||||
|
||||
void av_bmg_get(AVLFG *lfg, double out[2])
|
||||
{
|
||||
double x1, x2, w;
|
||||
|
||||
do {
|
||||
x1 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0;
|
||||
x2 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0;
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while (w >= 1.0);
|
||||
|
||||
w = sqrt((-2.0 * log(w)) / w);
|
||||
out[0] = x1 * w;
|
||||
out[1] = x2 * w;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include "log.h"
|
||||
#include "timer.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_lfg_get");
|
||||
}
|
||||
av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
|
||||
|
||||
/* BMG usage example */
|
||||
{
|
||||
double mean = 1000;
|
||||
double stddev = 53;
|
||||
|
||||
av_lfg_init(&state, 42);
|
||||
|
||||
for (i = 0; i < 1000; i += 2) {
|
||||
double bmg_out[2];
|
||||
av_bmg_get(&state, bmg_out);
|
||||
av_log(NULL, AV_LOG_INFO,
|
||||
"%f\n%f\n",
|
||||
bmg_out[0] * stddev + mean,
|
||||
bmg_out[1] * stddev + mean);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
62
project/jni/ffmpeg/libavutil/lfg.h
Normal file
62
project/jni/ffmpeg/libavutil/lfg.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 AVUTIL_LFG_H
|
||||
#define AVUTIL_LFG_H
|
||||
|
||||
typedef struct AVLFG {
|
||||
unsigned int state[64];
|
||||
int index;
|
||||
} AVLFG;
|
||||
|
||||
void av_lfg_init(AVLFG *c, unsigned int seed);
|
||||
|
||||
/**
|
||||
* Get the next random unsigned 32-bit number using an 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];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next random unsigned 32-bit number using a MLFG.
|
||||
*
|
||||
* Please also consider 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next two numbers generated by a Box-Muller Gaussian
|
||||
* generator using the random numbers issued by lfg.
|
||||
*
|
||||
* @param out array where the two generated numbers are placed
|
||||
*/
|
||||
void av_bmg_get(AVLFG *lfg, double out[2]);
|
||||
|
||||
#endif /* AVUTIL_LFG_H */
|
||||
4
project/jni/ffmpeg/libavutil/libavutil.v
Normal file
4
project/jni/ffmpeg/libavutil/libavutil.v
Normal file
@@ -0,0 +1,4 @@
|
||||
LIBAVUTIL_$MAJOR {
|
||||
global: av*; ff_*;
|
||||
local: *;
|
||||
};
|
||||
182
project/jni/ffmpeg/libavutil/libm.h
Normal file
182
project/jni/ffmpeg/libavutil/libm.h
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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
|
||||
* Replacements for frequently missing libm functions
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_LIBM_H
|
||||
#define AVUTIL_LIBM_H
|
||||
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
#include "attributes.h"
|
||||
#include "intfloat.h"
|
||||
|
||||
#if HAVE_MIPSFPU && HAVE_INLINE_ASM
|
||||
#include "libavutil/mips/libm_mips.h"
|
||||
#endif /* HAVE_MIPSFPU && HAVE_INLINE_ASM*/
|
||||
|
||||
#if !HAVE_ATANF
|
||||
#undef atanf
|
||||
#define atanf(x) ((float)atan(x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_ATAN2F
|
||||
#undef atan2f
|
||||
#define atan2f(y, x) ((float)atan2(y, x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_POWF
|
||||
#undef powf
|
||||
#define powf(x, y) ((float)pow(x, y))
|
||||
#endif
|
||||
|
||||
#if !HAVE_CBRTF
|
||||
static av_always_inline float cbrtf(float x)
|
||||
{
|
||||
return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !HAVE_COSF
|
||||
#undef cosf
|
||||
#define cosf(x) ((float)cos(x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_EXPF
|
||||
#undef expf
|
||||
#define expf(x) ((float)exp(x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_EXP2
|
||||
#undef exp2
|
||||
#define exp2(x) exp((x) * 0.693147180559945)
|
||||
#endif /* HAVE_EXP2 */
|
||||
|
||||
#if !HAVE_EXP2F
|
||||
#undef exp2f
|
||||
#define exp2f(x) ((float)exp2(x))
|
||||
#endif /* HAVE_EXP2F */
|
||||
|
||||
#if !HAVE_ISINF
|
||||
static av_always_inline av_const int isinf(float x)
|
||||
{
|
||||
uint32_t v = av_float2int(x);
|
||||
if ((v & 0x7f800000) != 0x7f800000)
|
||||
return 0;
|
||||
return !(v & 0x007fffff);
|
||||
}
|
||||
#endif /* HAVE_ISINF */
|
||||
|
||||
#if !HAVE_ISNAN
|
||||
static av_always_inline av_const int isnan(float x)
|
||||
{
|
||||
uint32_t v = av_float2int(x);
|
||||
if ((v & 0x7f800000) != 0x7f800000)
|
||||
return 0;
|
||||
return v & 0x007fffff;
|
||||
}
|
||||
#endif /* HAVE_ISNAN */
|
||||
|
||||
#if !HAVE_LDEXPF
|
||||
#undef ldexpf
|
||||
#define ldexpf(x, exp) ((float)ldexp(x, exp))
|
||||
#endif
|
||||
|
||||
#if !HAVE_LLRINT
|
||||
#undef llrint
|
||||
#define llrint(x) ((long long)rint(x))
|
||||
#endif /* HAVE_LLRINT */
|
||||
|
||||
#if !HAVE_LLRINTF
|
||||
#undef llrintf
|
||||
#define llrintf(x) ((long long)rint(x))
|
||||
#endif /* HAVE_LLRINT */
|
||||
|
||||
#if !HAVE_LOG2
|
||||
#undef log2
|
||||
#define log2(x) (log(x) * 1.44269504088896340736)
|
||||
#endif /* HAVE_LOG2 */
|
||||
|
||||
#if !HAVE_LOG2F
|
||||
#undef log2f
|
||||
#define log2f(x) ((float)log2(x))
|
||||
#endif /* HAVE_LOG2F */
|
||||
|
||||
#if !HAVE_LOG10F
|
||||
#undef log10f
|
||||
#define log10f(x) ((float)log10(x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_SINF
|
||||
#undef sinf
|
||||
#define sinf(x) ((float)sin(x))
|
||||
#endif
|
||||
|
||||
#if !HAVE_RINT
|
||||
static inline double rint(double x)
|
||||
{
|
||||
return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
|
||||
}
|
||||
#endif /* HAVE_RINT */
|
||||
|
||||
#if !HAVE_LRINT
|
||||
static av_always_inline av_const long int lrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif /* HAVE_LRINT */
|
||||
|
||||
#if !HAVE_LRINTF
|
||||
static av_always_inline av_const long int lrintf(float x)
|
||||
{
|
||||
return (int)(rint(x));
|
||||
}
|
||||
#endif /* HAVE_LRINTF */
|
||||
|
||||
#if !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 */
|
||||
|
||||
#if !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 */
|
||||
|
||||
#if !HAVE_TRUNC
|
||||
static av_always_inline av_const double trunc(double x)
|
||||
{
|
||||
return (x > 0) ? floor(x) : ceil(x);
|
||||
}
|
||||
#endif /* HAVE_TRUNC */
|
||||
|
||||
#if !HAVE_TRUNCF
|
||||
static av_always_inline av_const float truncf(float x)
|
||||
{
|
||||
return (x > 0) ? floor(x) : ceil(x);
|
||||
}
|
||||
#endif /* HAVE_TRUNCF */
|
||||
|
||||
#endif /* AVUTIL_LIBM_H */
|
||||
155
project/jni/ffmpeg/libavutil/lls.c
Normal file
155
project/jni/ffmpeg/libavutil/lls.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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
|
||||
* 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 <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "lfg.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
LLSModel m;
|
||||
int i, order;
|
||||
AVLFG lfg;
|
||||
|
||||
av_lfg_init(&lfg, 1);
|
||||
av_init_lls(&m, 3);
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
double var[4];
|
||||
double eval;
|
||||
|
||||
var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
|
||||
var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
|
||||
var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
|
||||
var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
|
||||
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:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\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
project/jni/ffmpeg/libavutil/lls.h
Normal file
45
project/jni/ffmpeg/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 AVUTIL_LLS_H
|
||||
#define AVUTIL_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 /* AVUTIL_LLS_H */
|
||||
280
project/jni/ffmpeg/libavutil/log.c
Normal file
280
project/jni/ffmpeg/libavutil/log.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* 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
|
||||
* logging functions
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if HAVE_IO_H
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
#define LINE_SZ 1024
|
||||
|
||||
static int av_log_level = AV_LOG_INFO;
|
||||
static int flags;
|
||||
|
||||
#if HAVE_SETCONSOLETEXTATTRIBUTE
|
||||
#include <windows.h>
|
||||
static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = {
|
||||
[AV_LOG_PANIC /8] = 12,
|
||||
[AV_LOG_FATAL /8] = 12,
|
||||
[AV_LOG_ERROR /8] = 12,
|
||||
[AV_LOG_WARNING/8] = 14,
|
||||
[AV_LOG_INFO /8] = 7,
|
||||
[AV_LOG_VERBOSE/8] = 10,
|
||||
[AV_LOG_DEBUG /8] = 10,
|
||||
[16+AV_CLASS_CATEGORY_NA ] = 7,
|
||||
[16+AV_CLASS_CATEGORY_INPUT ] = 13,
|
||||
[16+AV_CLASS_CATEGORY_OUTPUT ] = 5,
|
||||
[16+AV_CLASS_CATEGORY_MUXER ] = 13,
|
||||
[16+AV_CLASS_CATEGORY_DEMUXER ] = 5,
|
||||
[16+AV_CLASS_CATEGORY_ENCODER ] = 11,
|
||||
[16+AV_CLASS_CATEGORY_DECODER ] = 3,
|
||||
[16+AV_CLASS_CATEGORY_FILTER ] = 10,
|
||||
[16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 9,
|
||||
[16+AV_CLASS_CATEGORY_SWSCALER ] = 7,
|
||||
[16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 7,
|
||||
};
|
||||
|
||||
static int16_t background, attr_orig;
|
||||
static HANDLE con;
|
||||
#define set_color(x) SetConsoleTextAttribute(con, background | color[x])
|
||||
#define set_256color set_color
|
||||
#define reset_color() SetConsoleTextAttribute(con, attr_orig)
|
||||
#else
|
||||
|
||||
static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = {
|
||||
[AV_LOG_PANIC /8] = 52 << 16 | 196 << 8 | 0x41,
|
||||
[AV_LOG_FATAL /8] = 208 << 8 | 0x41,
|
||||
[AV_LOG_ERROR /8] = 196 << 8 | 0x11,
|
||||
[AV_LOG_WARNING/8] = 226 << 8 | 0x03,
|
||||
[AV_LOG_INFO /8] = 253 << 8 | 0x09,
|
||||
[AV_LOG_VERBOSE/8] = 40 << 8 | 0x02,
|
||||
[AV_LOG_DEBUG /8] = 34 << 8 | 0x02,
|
||||
[16+AV_CLASS_CATEGORY_NA ] = 250 << 8 | 0x09,
|
||||
[16+AV_CLASS_CATEGORY_INPUT ] = 219 << 8 | 0x15,
|
||||
[16+AV_CLASS_CATEGORY_OUTPUT ] = 201 << 8 | 0x05,
|
||||
[16+AV_CLASS_CATEGORY_MUXER ] = 213 << 8 | 0x15,
|
||||
[16+AV_CLASS_CATEGORY_DEMUXER ] = 207 << 8 | 0x05,
|
||||
[16+AV_CLASS_CATEGORY_ENCODER ] = 51 << 8 | 0x16,
|
||||
[16+AV_CLASS_CATEGORY_DECODER ] = 39 << 8 | 0x06,
|
||||
[16+AV_CLASS_CATEGORY_FILTER ] = 155 << 8 | 0x12,
|
||||
[16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 192 << 8 | 0x14,
|
||||
[16+AV_CLASS_CATEGORY_SWSCALER ] = 153 << 8 | 0x14,
|
||||
[16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 147 << 8 | 0x14,
|
||||
};
|
||||
|
||||
#define set_color(x) fprintf(stderr, "\033[%d;3%dm", (color[x] >> 4) & 15, color[x] & 15)
|
||||
#define set_256color(x) fprintf(stderr, "\033[48;5;%dm\033[38;5;%dm", (color[x] >> 16) & 0xff, (color[x] >> 8) & 0xff)
|
||||
#define reset_color() fprintf(stderr, "\033[0m")
|
||||
#endif
|
||||
static int use_color = -1;
|
||||
|
||||
static void colored_fputs(int level, const char *str)
|
||||
{
|
||||
if (use_color < 0) {
|
||||
#if HAVE_SETCONSOLETEXTATTRIBUTE
|
||||
CONSOLE_SCREEN_BUFFER_INFO con_info;
|
||||
con = GetStdHandle(STD_ERROR_HANDLE);
|
||||
use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") &&
|
||||
!getenv("AV_LOG_FORCE_NOCOLOR");
|
||||
if (use_color) {
|
||||
GetConsoleScreenBufferInfo(con, &con_info);
|
||||
attr_orig = con_info.wAttributes;
|
||||
background = attr_orig & 0xF0;
|
||||
}
|
||||
#elif HAVE_ISATTY
|
||||
use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") &&
|
||||
(getenv("TERM") && isatty(2) ||
|
||||
getenv("AV_LOG_FORCE_COLOR"));
|
||||
if (getenv("AV_LOG_FORCE_256COLOR"))
|
||||
use_color *= 256;
|
||||
#else
|
||||
use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") &&
|
||||
!getenv("AV_LOG_FORCE_NOCOLOR");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (use_color == 1) {
|
||||
set_color(level);
|
||||
} else if (use_color == 256)
|
||||
set_256color(level);
|
||||
fputs(str, stderr);
|
||||
if (use_color) {
|
||||
reset_color();
|
||||
}
|
||||
}
|
||||
|
||||
const char *av_default_item_name(void *ptr)
|
||||
{
|
||||
return (*(AVClass **) ptr)->class_name;
|
||||
}
|
||||
|
||||
AVClassCategory av_default_get_category(void *ptr)
|
||||
{
|
||||
return (*(AVClass **) ptr)->category;
|
||||
}
|
||||
|
||||
static void sanitize(uint8_t *line){
|
||||
while(*line){
|
||||
if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
|
||||
*line='?';
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_category(void *ptr){
|
||||
AVClass *avc = *(AVClass **) ptr;
|
||||
if( !avc
|
||||
|| (avc->version&0xFF)<100
|
||||
|| avc->version < (51 << 16 | 59 << 8)
|
||||
|| avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16;
|
||||
|
||||
if(avc->get_category)
|
||||
return avc->get_category(ptr) + 16;
|
||||
|
||||
return avc->category + 16;
|
||||
}
|
||||
|
||||
static void format_line(void *ptr, int level, const char *fmt, va_list vl,
|
||||
char part[3][LINE_SZ], int part_size, int *print_prefix, int type[2])
|
||||
{
|
||||
AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
|
||||
part[0][0] = part[1][0] = part[2][0] = 0;
|
||||
if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
|
||||
if (*print_prefix && avc) {
|
||||
if (avc->parent_log_context_offset) {
|
||||
AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
|
||||
avc->parent_log_context_offset);
|
||||
if (parent && *parent) {
|
||||
snprintf(part[0], part_size, "[%s @ %p] ",
|
||||
(*parent)->item_name(parent), parent);
|
||||
if(type) type[0] = get_category(((uint8_t *) ptr) + avc->parent_log_context_offset);
|
||||
}
|
||||
}
|
||||
snprintf(part[1], part_size, "[%s @ %p] ",
|
||||
avc->item_name(ptr), ptr);
|
||||
if(type) type[1] = get_category(ptr);
|
||||
}
|
||||
|
||||
vsnprintf(part[2], part_size, fmt, vl);
|
||||
|
||||
*print_prefix = strlen(part[2]) && part[2][strlen(part[2]) - 1] == '\n';
|
||||
}
|
||||
|
||||
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
|
||||
char *line, int line_size, int *print_prefix)
|
||||
{
|
||||
char part[3][LINE_SZ];
|
||||
format_line(ptr, level, fmt, vl, part, sizeof(part[0]), print_prefix, NULL);
|
||||
snprintf(line, line_size, "%s%s%s", part[0], part[1], part[2]);
|
||||
}
|
||||
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
{
|
||||
static int print_prefix = 1;
|
||||
static int count;
|
||||
static char prev[LINE_SZ];
|
||||
char part[3][LINE_SZ];
|
||||
char line[LINE_SZ];
|
||||
static int is_atty;
|
||||
int type[2];
|
||||
|
||||
if (level > av_log_level)
|
||||
return;
|
||||
format_line(ptr, level, fmt, vl, part, sizeof(part[0]), &print_prefix, type);
|
||||
snprintf(line, sizeof(line), "%s%s%s", part[0], part[1], part[2]);
|
||||
|
||||
#if HAVE_ISATTY
|
||||
if (!is_atty)
|
||||
is_atty = isatty(2) ? 1 : -1;
|
||||
#endif
|
||||
|
||||
if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
|
||||
count++;
|
||||
if (is_atty == 1)
|
||||
fprintf(stderr, " Last message repeated %d times\r", count);
|
||||
return;
|
||||
}
|
||||
if (count > 0) {
|
||||
fprintf(stderr, " Last message repeated %d times\n", count);
|
||||
count = 0;
|
||||
}
|
||||
strcpy(prev, line);
|
||||
sanitize(part[0]);
|
||||
colored_fputs(type[0], part[0]);
|
||||
sanitize(part[1]);
|
||||
colored_fputs(type[1], part[1]);
|
||||
sanitize(part[2]);
|
||||
colored_fputs(av_clip(level >> 3, 0, 6), part[2]);
|
||||
}
|
||||
|
||||
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, ...)
|
||||
{
|
||||
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
|
||||
avc->log_level_offset_offset && level >= AV_LOG_FATAL)
|
||||
level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);
|
||||
av_vlog(avcl, level, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
if(av_log_callback)
|
||||
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_flags(int arg)
|
||||
{
|
||||
flags = arg;
|
||||
}
|
||||
|
||||
void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
|
||||
{
|
||||
av_log_callback = callback;
|
||||
}
|
||||
222
project/jni/ffmpeg/libavutil/log.h
Normal file
222
project/jni/ffmpeg/libavutil/log.h
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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 AVUTIL_LOG_H
|
||||
#define AVUTIL_LOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "avutil.h"
|
||||
#include "attributes.h"
|
||||
|
||||
typedef enum {
|
||||
AV_CLASS_CATEGORY_NA = 0,
|
||||
AV_CLASS_CATEGORY_INPUT,
|
||||
AV_CLASS_CATEGORY_OUTPUT,
|
||||
AV_CLASS_CATEGORY_MUXER,
|
||||
AV_CLASS_CATEGORY_DEMUXER,
|
||||
AV_CLASS_CATEGORY_ENCODER,
|
||||
AV_CLASS_CATEGORY_DECODER,
|
||||
AV_CLASS_CATEGORY_FILTER,
|
||||
AV_CLASS_CATEGORY_BITSTREAM_FILTER,
|
||||
AV_CLASS_CATEGORY_SWSCALER,
|
||||
AV_CLASS_CATEGORY_SWRESAMPLER,
|
||||
AV_CLASS_CATEGORY_NB, ///< not part of ABI/API
|
||||
}AVClassCategory;
|
||||
|
||||
struct AVOptionRanges;
|
||||
|
||||
/**
|
||||
* Describe 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 {
|
||||
/**
|
||||
* 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 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;
|
||||
|
||||
/**
|
||||
* LIBAVUTIL_VERSION with which this structure was created.
|
||||
* This is used to allow fields to be added without requiring major
|
||||
* version bumps everywhere.
|
||||
*/
|
||||
|
||||
int version;
|
||||
|
||||
/**
|
||||
* Offset in the structure where log_level_offset is stored.
|
||||
* 0 means there is no such variable
|
||||
*/
|
||||
int log_level_offset_offset;
|
||||
|
||||
/**
|
||||
* Offset in the structure where a pointer to the parent context for
|
||||
* logging is stored. For example a decoder could pass its AVCodecContext
|
||||
* to eval as such a parent context, which an av_log() implementation
|
||||
* could then leverage to display the parent context.
|
||||
* The offset can be NULL.
|
||||
*/
|
||||
int parent_log_context_offset;
|
||||
|
||||
/**
|
||||
* Return next AVOptions-enabled child or NULL
|
||||
*/
|
||||
void* (*child_next)(void *obj, void *prev);
|
||||
|
||||
/**
|
||||
* Return an AVClass corresponding to the next potential
|
||||
* AVOptions-enabled child.
|
||||
*
|
||||
* The difference between child_next and this is that
|
||||
* child_next iterates over _already existing_ objects, while
|
||||
* child_class_next iterates over _all possible_ children.
|
||||
*/
|
||||
const struct AVClass* (*child_class_next)(const struct AVClass *prev);
|
||||
|
||||
/**
|
||||
* Category used for visualization (like color)
|
||||
* This is only set if the category is equal for all objects using this class.
|
||||
* available since version (51 << 16 | 56 << 8 | 100)
|
||||
*/
|
||||
AVClassCategory category;
|
||||
|
||||
/**
|
||||
* Callback to return the category.
|
||||
* available since version (51 << 16 | 59 << 8 | 100)
|
||||
*/
|
||||
AVClassCategory (*get_category)(void* ctx);
|
||||
|
||||
/**
|
||||
* Callback to return the supported/allowed ranges.
|
||||
* available since version (52.12)
|
||||
*/
|
||||
int (*query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags);
|
||||
} AVClass;
|
||||
|
||||
/* av_log API */
|
||||
|
||||
#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.
|
||||
* For example, no header was found for a format which depends
|
||||
* on headers or an illegal combination of parameters is used.
|
||||
*/
|
||||
#define AV_LOG_FATAL 8
|
||||
|
||||
/**
|
||||
* Something went wrong and cannot losslessly be recovered.
|
||||
* However, not all future data is affected.
|
||||
*/
|
||||
#define AV_LOG_ERROR 16
|
||||
|
||||
/**
|
||||
* Something somehow does not look correct. This may or may not
|
||||
* lead to problems. An example would be the 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
|
||||
|
||||
#define AV_LOG_MAX_OFFSET (AV_LOG_DEBUG - AV_LOG_QUIET)
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
|
||||
|
||||
void av_vlog(void *avcl, 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);
|
||||
const char* av_default_item_name(void* ctx);
|
||||
AVClassCategory av_default_get_category(void *ptr);
|
||||
|
||||
/**
|
||||
* Format a line of log the same way as the default callback.
|
||||
* @param line buffer to receive the formated line
|
||||
* @param line_size size of the buffer
|
||||
* @param print_prefix used to store whether the prefix must be printed;
|
||||
* must point to a persistent integer initially set to 1
|
||||
*/
|
||||
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
|
||||
char *line, int line_size, int *print_prefix);
|
||||
|
||||
/**
|
||||
* av_dlog macros
|
||||
* Useful to print debug messages that shouldn't get compiled in normally.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
# define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
# define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Skip repeated messages, this requires the user app to use av_log() instead of
|
||||
* (f)printf as the 2 would otherwise interfere and lead to
|
||||
* "Last message repeated x times" messages below (f)printf messages with some
|
||||
* bad luck.
|
||||
* Also to receive the last, "last repeated" line if any, the user app must
|
||||
* call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
|
||||
*/
|
||||
#define AV_LOG_SKIP_REPEATED 1
|
||||
void av_log_set_flags(int arg);
|
||||
|
||||
#endif /* AVUTIL_LOG_H */
|
||||
32
project/jni/ffmpeg/libavutil/log2_tab.c
Normal file
32
project/jni/ffmpeg/libavutil/log2_tab.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2012 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 <stdint.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
|
||||
};
|
||||
242
project/jni/ffmpeg/libavutil/lzo.c
Normal file
242
project/jni/ffmpeg/libavutil/lzo.c
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "intreadwrite.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 Reads one byte from the input buffer, avoiding an overrun.
|
||||
* @return byte read
|
||||
*/
|
||||
static inline int get_byte(LZOContext *c)
|
||||
{
|
||||
if (c->in < c->in_end)
|
||||
return *c->in++;
|
||||
c->error |= AV_LZO_INPUT_DEPLETED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef INBUF_PADDED
|
||||
#define GETB(c) (*(c).in++)
|
||||
#else
|
||||
#define GETB(c) get_byte(&(c))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Decodes 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copies 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 |= AV_LZO_INPUT_DEPLETED;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= AV_LZO_OUTPUT_FULL;
|
||||
}
|
||||
#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
|
||||
AV_COPY32U(dst, src);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
if (cnt > 0)
|
||||
#endif
|
||||
memcpy(dst, src, cnt);
|
||||
c->in = src + cnt;
|
||||
c->out = dst + cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copies previously decoded bytes to current position.
|
||||
* @param back how many bytes back we start, must be > 0
|
||||
* @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 |= AV_LZO_INVALID_BACKPTR;
|
||||
return;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= AV_LZO_OUTPUT_FULL;
|
||||
}
|
||||
av_memcpy_backptr(dst, back, cnt);
|
||||
c->out = dst + cnt;
|
||||
}
|
||||
|
||||
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen)
|
||||
{
|
||||
int state = 0;
|
||||
int x;
|
||||
LZOContext c;
|
||||
if (*outlen <= 0 || *inlen <= 0) {
|
||||
int res = 0;
|
||||
if (*outlen <= 0)
|
||||
res |= AV_LZO_OUTPUT_FULL;
|
||||
if (*inlen <= 0)
|
||||
res |= AV_LZO_INPUT_DEPLETED;
|
||||
return res;
|
||||
}
|
||||
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 |= AV_LZO_ERROR;
|
||||
}
|
||||
if (c.in > c.in_end)
|
||||
c.error |= AV_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 |= AV_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)
|
||||
|
||||
/* Define one of these to 1 if you wish to benchmark liblzo
|
||||
* instead of our native implementation. */
|
||||
#define BENCHMARK_LIBLZO_SAFE 0
|
||||
#define BENCHMARK_LIBLZO_UNSAFE 0
|
||||
|
||||
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_set_level(AV_LOG_DEBUG);
|
||||
lzo1x_999_compress(orig, s, comp, &clen, tmp);
|
||||
for (i = 0; i < 300; i++) {
|
||||
START_TIMER
|
||||
inlen = clen; outlen = MAXSZ;
|
||||
#if BENCHMARK_LIBLZO_SAFE
|
||||
if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL))
|
||||
#elif BENCHMARK_LIBLZO_UNSAFE
|
||||
if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
|
||||
#else
|
||||
if (av_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
|
||||
66
project/jni/ffmpeg/libavutil/lzo.h
Normal file
66
project/jni/ffmpeg/libavutil/lzo.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 AVUTIL_LZO_H
|
||||
#define AVUTIL_LZO_H
|
||||
|
||||
/**
|
||||
* @defgroup lavu_lzo LZO
|
||||
* @ingroup lavu_crypto
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** @name Error flags returned by av_lzo1x_decode
|
||||
* @{ */
|
||||
/// end of the input buffer reached before decoding finished
|
||||
#define AV_LZO_INPUT_DEPLETED 1
|
||||
/// decoded data did not fit into output buffer
|
||||
#define AV_LZO_OUTPUT_FULL 2
|
||||
/// a reference to previously decoded data was wrong
|
||||
#define AV_LZO_INVALID_BACKPTR 4
|
||||
/// a non-specific error in the compressed bitstream
|
||||
#define AV_LZO_ERROR 8
|
||||
/** @} */
|
||||
|
||||
#define AV_LZO_INPUT_PADDING 8
|
||||
#define AV_LZO_OUTPUT_PADDING 12
|
||||
|
||||
/**
|
||||
* @brief Decodes 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 a combination of the error flags above
|
||||
*
|
||||
* Make sure all buffers are appropriately padded, in must provide
|
||||
* AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes.
|
||||
*/
|
||||
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_LZO_H */
|
||||
173
project/jni/ffmpeg/libavutil/mathematics.c
Normal file
173
project/jni/ffmpeg/libavutil/mathematics.c
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2005-2012 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
|
||||
* miscellaneous math routines and tables
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "mathematics.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "avassert.h"
|
||||
#include "version.h"
|
||||
|
||||
#if FF_API_AV_REVERSE
|
||||
const uint8_t av_reverse[256]={
|
||||
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
|
||||
0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
|
||||
0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
|
||||
0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
|
||||
0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
|
||||
0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
|
||||
0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
|
||||
0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
|
||||
0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
|
||||
0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
|
||||
0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
|
||||
0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
|
||||
0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
|
||||
0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
|
||||
0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
|
||||
0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
|
||||
};
|
||||
#endif
|
||||
|
||||
int64_t av_gcd(int64_t a, int64_t b){
|
||||
if(b) return av_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;
|
||||
av_assert2(c > 0);
|
||||
av_assert2(b >=0);
|
||||
av_assert2((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4);
|
||||
|
||||
if (rnd & AV_ROUND_PASS_MINMAX) {
|
||||
if (a == INT64_MIN || a == INT64_MAX)
|
||||
return a;
|
||||
rnd -= AV_ROUND_PASS_MINMAX;
|
||||
}
|
||||
|
||||
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_rnd(int64_t a, AVRational bq, AVRational cq,
|
||||
enum AVRounding rnd)
|
||||
{
|
||||
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, rnd);
|
||||
}
|
||||
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
|
||||
{
|
||||
return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);
|
||||
}
|
||||
|
||||
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
|
||||
int64_t a= tb_a.num * (int64_t)tb_b.den;
|
||||
int64_t b= tb_b.num * (int64_t)tb_a.den;
|
||||
if((FFABS(ts_a)|a|FFABS(ts_b)|b)<=INT_MAX)
|
||||
return (ts_a*a > ts_b*b) - (ts_a*a < ts_b*b);
|
||||
if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
|
||||
if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){
|
||||
int64_t c= (a-b) & (mod-1);
|
||||
if(c > (mod>>1))
|
||||
c-= mod;
|
||||
return c;
|
||||
}
|
||||
|
||||
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb){
|
||||
int64_t a, b, this;
|
||||
|
||||
av_assert0(in_ts != AV_NOPTS_VALUE);
|
||||
av_assert0(duration >= 0);
|
||||
|
||||
if (*last == AV_NOPTS_VALUE || !duration || in_tb.num*(int64_t)out_tb.den <= out_tb.num*(int64_t)in_tb.den) {
|
||||
simple_round:
|
||||
*last = av_rescale_q(in_ts, in_tb, fs_tb) + duration;
|
||||
return av_rescale_q(in_ts, in_tb, out_tb);
|
||||
}
|
||||
|
||||
a = av_rescale_q_rnd(2*in_ts-1, in_tb, fs_tb, AV_ROUND_DOWN) >>1;
|
||||
b = (av_rescale_q_rnd(2*in_ts+1, in_tb, fs_tb, AV_ROUND_UP )+1)>>1;
|
||||
if (*last < 2*a - b || *last > 2*b - a)
|
||||
goto simple_round;
|
||||
|
||||
this = av_clip64(*last, a, b);
|
||||
*last = this + duration;
|
||||
|
||||
return av_rescale_q(this, fs_tb, out_tb);
|
||||
}
|
||||
147
project/jni/ffmpeg/libavutil/mathematics.h
Normal file
147
project/jni/ffmpeg/libavutil/mathematics.h
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* copyright (c) 2005-2012 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 AVUTIL_MATHEMATICS_H
|
||||
#define AVUTIL_MATHEMATICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "attributes.h"
|
||||
#include "rational.h"
|
||||
#include "intfloat.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_LOG2_10
|
||||
#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */
|
||||
#endif
|
||||
#ifndef M_PHI
|
||||
#define M_PHI 1.61803398874989484820 /* phi / golden ratio */
|
||||
#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
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#endif
|
||||
#ifndef NAN
|
||||
#define NAN av_int2float(0x7fc00000)
|
||||
#endif
|
||||
#ifndef INFINITY
|
||||
#define INFINITY av_int2float(0x7f800000)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_math
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
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.
|
||||
AV_ROUND_PASS_MINMAX = 8192, ///< Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the greatest common divisor of a and b.
|
||||
* If both a and b are 0 or either or both are <0 then behavior is
|
||||
* undefined.
|
||||
*/
|
||||
int64_t av_const av_gcd(int64_t a, int64_t b);
|
||||
|
||||
/**
|
||||
* Rescale a 64-bit 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 64-bit integer with specified rounding.
|
||||
* A simple a*b/c isn't possible as it can overflow.
|
||||
*
|
||||
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
|
||||
* INT64_MIN or INT64_MAX then a is passed through unchanged.
|
||||
*/
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
|
||||
|
||||
/**
|
||||
* Rescale a 64-bit integer by 2 rational numbers.
|
||||
*/
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
|
||||
|
||||
/**
|
||||
* Rescale a 64-bit integer by 2 rational numbers with specified rounding.
|
||||
*
|
||||
* @return rescaled value a, or if AV_ROUND_PASS_MINMAX is set and a is
|
||||
* INT64_MIN or INT64_MAX then a is passed through unchanged.
|
||||
*/
|
||||
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
|
||||
enum AVRounding) av_const;
|
||||
|
||||
/**
|
||||
* Compare 2 timestamps each in its own timebases.
|
||||
* The result of the function is undefined if one of the timestamps
|
||||
* is outside the int64_t range when represented in the others timebase.
|
||||
* @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
|
||||
*/
|
||||
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
|
||||
|
||||
/**
|
||||
* Compare 2 integers modulo mod.
|
||||
* That is we compare integers a and b for which only the least
|
||||
* significant log2(mod) bits are known.
|
||||
*
|
||||
* @param mod must be a power of 2
|
||||
* @return a negative value if a is smaller than b
|
||||
* a positive value if a is greater than b
|
||||
* 0 if a equals b
|
||||
*/
|
||||
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
|
||||
|
||||
/**
|
||||
* Rescale a timestamp while preserving known durations.
|
||||
*
|
||||
* @param in_ts Input timestamp
|
||||
* @param in_tb Input timesbase
|
||||
* @param fs_tb Duration and *last timebase
|
||||
* @param duration duration till the next call
|
||||
* @param out_tb Output timesbase
|
||||
*/
|
||||
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_MATHEMATICS_H */
|
||||
210
project/jni/ffmpeg/libavutil/md5.c
Normal file
210
project/jni/ffmpeg/libavutil/md5.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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 <stdint.h>
|
||||
#include "bswap.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "md5.h"
|
||||
#include "mem.h"
|
||||
|
||||
typedef struct AVMD5{
|
||||
uint64_t len;
|
||||
uint8_t block[64];
|
||||
uint32_t ABCD[4];
|
||||
} AVMD5;
|
||||
|
||||
const int av_md5_size = sizeof(AVMD5);
|
||||
|
||||
struct AVMD5 *av_md5_alloc(void)
|
||||
{
|
||||
return av_mallocz(sizeof(struct 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) do { \
|
||||
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)); \
|
||||
} while (0)
|
||||
|
||||
static void body(uint32_t ABCD[4], uint32_t X[16])
|
||||
{
|
||||
int i av_unused;
|
||||
uint32_t t;
|
||||
uint32_t a = ABCD[3];
|
||||
uint32_t b = ABCD[2];
|
||||
uint32_t c = ABCD[1];
|
||||
uint32_t d = ABCD[0];
|
||||
|
||||
#if HAVE_BIGENDIAN
|
||||
for (i = 0; i < 16; i++)
|
||||
X[i] = av_bswap32(X[i]);
|
||||
#endif
|
||||
|
||||
#if 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 (j == 64) {
|
||||
body(ctx->ABCD, (uint32_t *) ctx->block);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
|
||||
{
|
||||
int i;
|
||||
uint64_t finalcount = av_le2ne64(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++)
|
||||
AV_WL32(dst + 4*i, ctx->ABCD[3 - i]);
|
||||
}
|
||||
|
||||
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
|
||||
{
|
||||
AVMD5 ctx;
|
||||
|
||||
av_md5_init(&ctx);
|
||||
av_md5_update(&ctx, src, len);
|
||||
av_md5_final(&ctx, dst);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
|
||||
static void print_md5(uint8_t *md5)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02x", md5[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void){
|
||||
uint8_t md5val[16];
|
||||
int i;
|
||||
uint8_t in[1000];
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
in[i] = i * i;
|
||||
av_md5_sum(md5val, in, 1000); print_md5(md5val);
|
||||
av_md5_sum(md5val, in, 63); print_md5(md5val);
|
||||
av_md5_sum(md5val, in, 64); print_md5(md5val);
|
||||
av_md5_sum(md5val, in, 65); print_md5(md5val);
|
||||
for (i = 0; i < 1000; i++)
|
||||
in[i] = i % 127;
|
||||
av_md5_sum(md5val, in, 999); print_md5(md5val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
49
project/jni/ffmpeg/libavutil/md5.h
Normal file
49
project/jni/ffmpeg/libavutil/md5.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 AVUTIL_MD5_H
|
||||
#define AVUTIL_MD5_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "version.h"
|
||||
|
||||
/**
|
||||
* @defgroup lavu_md5 MD5
|
||||
* @ingroup lavu_crypto
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const int av_md5_size;
|
||||
|
||||
struct AVMD5;
|
||||
|
||||
struct AVMD5 *av_md5_alloc(void);
|
||||
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 /* AVUTIL_MD5_H */
|
||||
364
project/jni/ffmpeg/libavutil/mem.c
Normal file
364
project/jni/ffmpeg/libavutil/mem.c
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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
|
||||
* default memory allocator for libavutil
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 600
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include "avutil.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef MALLOC_PREFIX
|
||||
|
||||
#define malloc AV_JOIN(MALLOC_PREFIX, malloc)
|
||||
#define memalign AV_JOIN(MALLOC_PREFIX, memalign)
|
||||
#define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
|
||||
#define realloc AV_JOIN(MALLOC_PREFIX, realloc)
|
||||
#define free AV_JOIN(MALLOC_PREFIX, free)
|
||||
|
||||
void *malloc(size_t size);
|
||||
void *memalign(size_t align, size_t size);
|
||||
int posix_memalign(void **ptr, size_t align, size_t size);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
void free(void *ptr);
|
||||
|
||||
#endif /* MALLOC_PREFIX */
|
||||
|
||||
#define ALIGN (HAVE_AVX ? 32 : 16)
|
||||
|
||||
/* NOTE: if you want to override these functions with your own
|
||||
* implementations (not recommended) you have to link libav* as
|
||||
* dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
|
||||
* Note that this will cost performance. */
|
||||
|
||||
static size_t max_alloc_size= INT_MAX;
|
||||
|
||||
void av_max_alloc(size_t max){
|
||||
max_alloc_size = max;
|
||||
}
|
||||
|
||||
void *av_malloc(size_t size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
long diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if (size > (max_alloc_size - 32))
|
||||
return NULL;
|
||||
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
ptr = malloc(size + ALIGN);
|
||||
if (!ptr)
|
||||
return ptr;
|
||||
diff = ((~(long)ptr)&(ALIGN - 1)) + 1;
|
||||
ptr = (char *)ptr + diff;
|
||||
((char *)ptr)[-1] = diff;
|
||||
#elif HAVE_POSIX_MEMALIGN
|
||||
if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
|
||||
if (posix_memalign(&ptr, ALIGN, size))
|
||||
ptr = NULL;
|
||||
#elif HAVE_ALIGNED_MALLOC
|
||||
ptr = _aligned_malloc(size, ALIGN);
|
||||
#elif HAVE_MEMALIGN
|
||||
ptr = memalign(ALIGN, 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 32?
|
||||
* For AVX ASM. SSE / NEON needs only 16.
|
||||
* 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
|
||||
if(!ptr && !size) {
|
||||
size = 1;
|
||||
ptr= av_malloc(1);
|
||||
}
|
||||
#if CONFIG_MEMORY_POISONING
|
||||
if (ptr)
|
||||
memset(ptr, 0x2a, size);
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *av_realloc(void *ptr, size_t size)
|
||||
{
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
int diff;
|
||||
#endif
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if (size > (max_alloc_size - 32))
|
||||
return NULL;
|
||||
|
||||
#if 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];
|
||||
ptr = realloc((char *)ptr - diff, size + diff);
|
||||
if (ptr)
|
||||
ptr = (char *)ptr + diff;
|
||||
return ptr;
|
||||
#elif HAVE_ALIGNED_MALLOC
|
||||
return _aligned_realloc(ptr, size + !size, ALIGN);
|
||||
#else
|
||||
return realloc(ptr, size + !size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
|
||||
{
|
||||
size_t size;
|
||||
void *r;
|
||||
|
||||
if (av_size_mult(elsize, nelem, &size)) {
|
||||
av_free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
r = av_realloc(ptr, size);
|
||||
if (!r && size)
|
||||
av_free(ptr);
|
||||
return r;
|
||||
}
|
||||
|
||||
void av_free(void *ptr)
|
||||
{
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
if (ptr)
|
||||
free((char *)ptr - ((char *)ptr)[-1]);
|
||||
#elif HAVE_ALIGNED_MALLOC
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void av_freep(void *arg)
|
||||
{
|
||||
void **ptr = (void **)arg;
|
||||
av_free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
|
||||
void *av_mallocz(size_t size)
|
||||
{
|
||||
void *ptr = av_malloc(size);
|
||||
if (ptr)
|
||||
memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *av_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
if (size <= 0 || nmemb >= INT_MAX / size)
|
||||
return NULL;
|
||||
return av_mallocz(nmemb * size);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* add one element to a dynamic array */
|
||||
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
|
||||
{
|
||||
/* see similar ffmpeg.c:grow_array() */
|
||||
int nb, nb_alloc;
|
||||
intptr_t *tab;
|
||||
|
||||
nb = *nb_ptr;
|
||||
tab = *(intptr_t**)tab_ptr;
|
||||
if ((nb & (nb - 1)) == 0) {
|
||||
if (nb == 0)
|
||||
nb_alloc = 1;
|
||||
else
|
||||
nb_alloc = nb * 2;
|
||||
tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
|
||||
*(intptr_t**)tab_ptr = tab;
|
||||
}
|
||||
tab[nb++] = (intptr_t)elem;
|
||||
*nb_ptr = nb;
|
||||
}
|
||||
|
||||
static void fill16(uint8_t *dst, int len)
|
||||
{
|
||||
uint32_t v = AV_RN16(dst - 2);
|
||||
|
||||
v |= v << 16;
|
||||
|
||||
while (len >= 4) {
|
||||
AV_WN32(dst, v);
|
||||
dst += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
while (len--) {
|
||||
*dst = dst[-2];
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
static void fill24(uint8_t *dst, int len)
|
||||
{
|
||||
#if HAVE_BIGENDIAN
|
||||
uint32_t v = AV_RB24(dst - 3);
|
||||
uint32_t a = v << 8 | v >> 16;
|
||||
uint32_t b = v << 16 | v >> 8;
|
||||
uint32_t c = v << 24 | v;
|
||||
#else
|
||||
uint32_t v = AV_RL24(dst - 3);
|
||||
uint32_t a = v | v << 24;
|
||||
uint32_t b = v >> 8 | v << 16;
|
||||
uint32_t c = v >> 16 | v << 8;
|
||||
#endif
|
||||
|
||||
while (len >= 12) {
|
||||
AV_WN32(dst, a);
|
||||
AV_WN32(dst + 4, b);
|
||||
AV_WN32(dst + 8, c);
|
||||
dst += 12;
|
||||
len -= 12;
|
||||
}
|
||||
|
||||
if (len >= 4) {
|
||||
AV_WN32(dst, a);
|
||||
dst += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
if (len >= 4) {
|
||||
AV_WN32(dst, b);
|
||||
dst += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
while (len--) {
|
||||
*dst = dst[-3];
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
static void fill32(uint8_t *dst, int len)
|
||||
{
|
||||
uint32_t v = AV_RN32(dst - 4);
|
||||
|
||||
while (len >= 4) {
|
||||
AV_WN32(dst, v);
|
||||
dst += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
while (len--) {
|
||||
*dst = dst[-4];
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
|
||||
{
|
||||
const uint8_t *src = &dst[-back];
|
||||
if (back <= 1) {
|
||||
memset(dst, *src, cnt);
|
||||
} else if (back == 2) {
|
||||
fill16(dst, cnt);
|
||||
} else if (back == 3) {
|
||||
fill24(dst, cnt);
|
||||
} else if (back == 4) {
|
||||
fill32(dst, cnt);
|
||||
} else {
|
||||
if (cnt >= 16) {
|
||||
int blocklen = back;
|
||||
while (cnt > blocklen) {
|
||||
memcpy(dst, src, blocklen);
|
||||
dst += blocklen;
|
||||
cnt -= blocklen;
|
||||
blocklen <<= 1;
|
||||
}
|
||||
memcpy(dst, src, cnt);
|
||||
return;
|
||||
}
|
||||
if (cnt >= 8) {
|
||||
AV_COPY32U(dst, src);
|
||||
AV_COPY32U(dst + 4, src + 4);
|
||||
src += 8;
|
||||
dst += 8;
|
||||
cnt -= 8;
|
||||
}
|
||||
if (cnt >= 4) {
|
||||
AV_COPY32U(dst, src);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
cnt -= 4;
|
||||
}
|
||||
if (cnt >= 2) {
|
||||
AV_COPY16U(dst, src);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
cnt -= 2;
|
||||
}
|
||||
if (cnt)
|
||||
*dst = *src;
|
||||
}
|
||||
}
|
||||
|
||||
235
project/jni/ffmpeg/libavutil/mem.h
Normal file
235
project/jni/ffmpeg/libavutil/mem.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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
|
||||
* memory handling functions
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_MEM_H
|
||||
#define AVUTIL_MEM_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "error.h"
|
||||
#include "avutil.h"
|
||||
|
||||
/**
|
||||
* @addtogroup lavu_mem
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
|
||||
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
|
||||
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
|
||||
#elif defined(__TI_COMPILER_VERSION__)
|
||||
#define DECLARE_ALIGNED(n,t,v) \
|
||||
AV_PRAGMA(DATA_ALIGN(v,n)) \
|
||||
t __attribute__((aligned(n))) v
|
||||
#define DECLARE_ASM_CONST(n,t,v) \
|
||||
AV_PRAGMA(DATA_ALIGN(v,n)) \
|
||||
static const t __attribute__((aligned(n))) v
|
||||
#elif defined(__GNUC__)
|
||||
#define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
|
||||
#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
|
||||
#else
|
||||
#define DECLARE_ALIGNED(n,t,v) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
#define av_malloc_attrib __attribute__((__malloc__))
|
||||
#else
|
||||
#define av_malloc_attrib
|
||||
#endif
|
||||
|
||||
#if AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
#define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
|
||||
#else
|
||||
#define av_alloc_size(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocate a block of 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 the block cannot
|
||||
* be allocated.
|
||||
* @see av_mallocz()
|
||||
*/
|
||||
void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Helper function to allocate a block of size * nmemb bytes with
|
||||
* using av_malloc()
|
||||
* @param nmemb Number of elements
|
||||
* @param size Size of the single element
|
||||
* @return Pointer to the allocated block, NULL if the block cannot
|
||||
* be allocated.
|
||||
* @see av_malloc()
|
||||
*/
|
||||
av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size)
|
||||
{
|
||||
if (size <= 0 || nmemb >= INT_MAX / size)
|
||||
return NULL;
|
||||
return av_malloc(nmemb * size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate or reallocate a block of memory.
|
||||
* If ptr is NULL and size > 0, allocate a new block. If
|
||||
* size is zero, free the memory block pointed to by ptr.
|
||||
* @param ptr Pointer to a memory block already allocated with
|
||||
* av_malloc(z)() or av_realloc() or NULL.
|
||||
* @param size Size in bytes for the memory block to be allocated or
|
||||
* reallocated.
|
||||
* @return Pointer to a newly reallocated block or NULL if the block
|
||||
* cannot be reallocated or the function is used to free the memory block.
|
||||
* @see av_fast_realloc()
|
||||
*/
|
||||
void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
|
||||
|
||||
/**
|
||||
* Allocate or reallocate a block of memory.
|
||||
* This function does the same thing as av_realloc, except:
|
||||
* - It takes two arguments and checks the result of the multiplication for
|
||||
* integer overflow.
|
||||
* - It frees the input block in case of failure, thus avoiding the memory
|
||||
* leak with the classic "buf = realloc(buf); if (!buf) return -1;".
|
||||
*/
|
||||
void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
|
||||
|
||||
/**
|
||||
* 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 size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU) and
|
||||
* zero 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 be allocated.
|
||||
* @see av_malloc()
|
||||
*/
|
||||
void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Allocate a block of nmemb * size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU) and
|
||||
* zero all the bytes of the block.
|
||||
* The allocation will fail if nmemb * size is greater than or equal
|
||||
* to INT_MAX.
|
||||
* @param nmemb
|
||||
* @param size
|
||||
* @return Pointer to the allocated block, NULL if it cannot be allocated.
|
||||
*/
|
||||
void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
|
||||
|
||||
/**
|
||||
* Helper function to allocate a block of size * nmemb bytes with
|
||||
* using av_mallocz()
|
||||
* @param nmemb Number of elements
|
||||
* @param size Size of the single element
|
||||
* @return Pointer to the allocated block, NULL if the block cannot
|
||||
* be allocated.
|
||||
* @see av_mallocz()
|
||||
* @see av_malloc_array()
|
||||
*/
|
||||
av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
|
||||
{
|
||||
if (size <= 0 || nmemb >= INT_MAX / size)
|
||||
return NULL;
|
||||
return av_mallocz(nmemb * size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the string s.
|
||||
* @param s string to be duplicated
|
||||
* @return Pointer to a newly allocated string containing a
|
||||
* copy of s or NULL if the string 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 the pointer pointing to it to NULL.
|
||||
* @param ptr Pointer to the pointer to the memory block which should
|
||||
* be freed.
|
||||
* @see av_free()
|
||||
*/
|
||||
void av_freep(void *ptr);
|
||||
|
||||
/**
|
||||
* Add an element to a dynamic array.
|
||||
*
|
||||
* @param tab_ptr Pointer to the array.
|
||||
* @param nb_ptr Pointer to the number of elements in the array.
|
||||
* @param elem Element to be added.
|
||||
*/
|
||||
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
|
||||
|
||||
/**
|
||||
* Multiply two size_t values checking for overflow.
|
||||
* @return 0 if success, AVERROR(EINVAL) if overflow.
|
||||
*/
|
||||
static inline int av_size_mult(size_t a, size_t b, size_t *r)
|
||||
{
|
||||
size_t t = a * b;
|
||||
/* Hack inspired from glibc: only try the division if nelem and elsize
|
||||
* are both greater than sqrt(SIZE_MAX). */
|
||||
if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
|
||||
return AVERROR(EINVAL);
|
||||
*r = t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum size that may me allocated in one block.
|
||||
*/
|
||||
void av_max_alloc(size_t max);
|
||||
|
||||
/**
|
||||
* @brief deliberately overlapping memcpy implementation
|
||||
* @param dst destination buffer
|
||||
* @param back how many bytes back we start (the initial size of the overlapping window), must be > 0
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_MEM_H */
|
||||
1
project/jni/ffmpeg/libavutil/mips/Makefile
Normal file
1
project/jni/ffmpeg/libavutil/mips/Makefile
Normal file
@@ -0,0 +1 @@
|
||||
OBJS += mips/float_dsp_mips.o
|
||||
113
project/jni/ffmpeg/libavutil/mips/float_dsp_mips.c
Normal file
113
project/jni/ffmpeg/libavutil/mips/float_dsp_mips.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2012
|
||||
* MIPS Technologies, Inc., California.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Author: Branimir Vasic (bvasic@mips.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
|
||||
* Reference: libavutil/float_dsp.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/float_dsp.h"
|
||||
|
||||
#if HAVE_INLINE_ASM && HAVE_MIPSFPU
|
||||
static void vector_fmul_mips(float *dst, const float *src0, const float *src1,
|
||||
int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (len & 3) {
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = src0[i] * src1[i];
|
||||
} else {
|
||||
float *d = (float *)dst;
|
||||
float *d_end = d + len;
|
||||
float *s0 = (float *)src0;
|
||||
float *s1 = (float *)src1;
|
||||
|
||||
float src0_0, src0_1, src0_2, src0_3;
|
||||
float src1_0, src1_1, src1_2, src1_3;
|
||||
|
||||
__asm__ volatile (
|
||||
"1: \n\t"
|
||||
"lwc1 %[src0_0], 0(%[s0]) \n\t"
|
||||
"lwc1 %[src1_0], 0(%[s1]) \n\t"
|
||||
"lwc1 %[src0_1], 4(%[s0]) \n\t"
|
||||
"lwc1 %[src1_1], 4(%[s1]) \n\t"
|
||||
"lwc1 %[src0_2], 8(%[s0]) \n\t"
|
||||
"lwc1 %[src1_2], 8(%[s1]) \n\t"
|
||||
"lwc1 %[src0_3], 12(%[s0]) \n\t"
|
||||
"lwc1 %[src1_3], 12(%[s1]) \n\t"
|
||||
"mul.s %[src0_0], %[src0_0], %[src1_0] \n\t"
|
||||
"mul.s %[src0_1], %[src0_1], %[src1_1] \n\t"
|
||||
"mul.s %[src0_2], %[src0_2], %[src1_2] \n\t"
|
||||
"mul.s %[src0_3], %[src0_3], %[src1_3] \n\t"
|
||||
"swc1 %[src0_0], 0(%[d]) \n\t"
|
||||
"swc1 %[src0_1], 4(%[d]) \n\t"
|
||||
"swc1 %[src0_2], 8(%[d]) \n\t"
|
||||
"swc1 %[src0_3], 12(%[d]) \n\t"
|
||||
"addiu %[s0], %[s0], 16 \n\t"
|
||||
"addiu %[s1], %[s1], 16 \n\t"
|
||||
"addiu %[d], %[d], 16 \n\t"
|
||||
"bne %[d], %[d_end], 1b \n\t"
|
||||
|
||||
: [src0_0]"=&f"(src0_0), [src0_1]"=&f"(src0_1),
|
||||
[src0_2]"=&f"(src0_2), [src0_3]"=&f"(src0_3),
|
||||
[src1_0]"=&f"(src1_0), [src1_1]"=&f"(src1_1),
|
||||
[src1_2]"=&f"(src1_2), [src1_3]"=&f"(src1_3),
|
||||
[d]"+r"(d), [s0]"+r"(s0), [s1]"+r"(s1)
|
||||
: [d_end]"r"(d_end)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
|
||||
|
||||
void ff_float_dsp_init_mips(AVFloatDSPContext *fdsp) {
|
||||
#if HAVE_INLINE_ASM && HAVE_MIPSFPU
|
||||
fdsp->vector_fmul = vector_fmul_mips;
|
||||
#endif /* HAVE_INLINE_ASM && HAVE_MIPSFPU */
|
||||
}
|
||||
46
project/jni/ffmpeg/libavutil/mips/intreadwrite.h
Normal file
46
project/jni/ffmpeg/libavutil/mips/intreadwrite.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Mans Rullgard <mans@mansr.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 AVUTIL_MIPS_INTREADWRITE_H
|
||||
#define AVUTIL_MIPS_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#if ARCH_MIPS64 && HAVE_INLINE_ASM
|
||||
|
||||
#define AV_RN32 AV_RN32
|
||||
static av_always_inline uint32_t AV_RN32(const void *p)
|
||||
{
|
||||
struct __attribute__((packed)) u32 { uint32_t v; };
|
||||
const uint8_t *q = p;
|
||||
const struct u32 *pl = (const struct u32 *)(q + 3 * !HAVE_BIGENDIAN);
|
||||
const struct u32 *pr = (const struct u32 *)(q + 3 * HAVE_BIGENDIAN);
|
||||
uint32_t v;
|
||||
__asm__ ("lwl %0, %1 \n\t"
|
||||
"lwr %0, %2 \n\t"
|
||||
: "=&r"(v)
|
||||
: "m"(*pl), "m"(*pr));
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* ARCH_MIPS64 && HAVE_INLINE_ASM */
|
||||
|
||||
#endif /* AVUTIL_MIPS_INTREADWRITE_H */
|
||||
73
project/jni/ffmpeg/libavutil/mips/libm_mips.h
Normal file
73
project/jni/ffmpeg/libavutil/mips/libm_mips.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2012
|
||||
* MIPS Technologies, Inc., California.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Author: Nedeljko Babic (nbabic@mips.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
|
||||
* MIPS optimization for some libm functions
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_LIBM_MIPS_H
|
||||
#define AVUTIL_LIBM_MIPS_H
|
||||
|
||||
static av_always_inline av_const long int lrintf_mips(float x)
|
||||
{
|
||||
register int ret_int;
|
||||
|
||||
__asm__ volatile (
|
||||
"cvt.w.s %[x], %[x] \n\t"
|
||||
"mfc1 %[ret_int], %[x] \n\t"
|
||||
|
||||
:[x]"+f"(x), [ret_int]"=r"(ret_int)
|
||||
);
|
||||
return ret_int;
|
||||
}
|
||||
|
||||
#undef lrintf
|
||||
#define lrintf(x) lrintf_mips(x)
|
||||
|
||||
#define HAVE_LRINTF 1
|
||||
#endif /* AVUTIL_LIBM_MIPS_H */
|
||||
171
project/jni/ffmpeg/libavutil/old_pix_fmts.h
Normal file
171
project/jni/ffmpeg/libavutil/old_pix_fmts.h
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* copyright (c) 2006-2012 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 AVUTIL_OLD_PIX_FMTS_H
|
||||
#define AVUTIL_OLD_PIX_FMTS_H
|
||||
|
||||
/*
|
||||
* This header exists to prevent new pixel formats from being accidentally added
|
||||
* to the deprecated list.
|
||||
* Do not include it directly. It will be removed on next major bump
|
||||
*
|
||||
* Do not add new items to this list. Use the AVPixelFormat enum instead.
|
||||
*/
|
||||
PIX_FMT_NONE = AV_PIX_FMT_NONE,
|
||||
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_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_GRAY8, ///< Y , 8bpp
|
||||
PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
|
||||
PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
|
||||
PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
|
||||
PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_range
|
||||
PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_range
|
||||
PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_range
|
||||
PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
|
||||
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_BGR8, ///< packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
|
||||
PIX_FMT_BGR4, ///< packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
|
||||
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 bitstream, 4bpp, (msb)1R 2G 1B(lsb), a byte contains two pixels, the first pixel in the byte is the one composed by the 4 msb bits
|
||||
PIX_FMT_RGB4_BYTE, ///< packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
|
||||
PIX_FMT_NV12, ///< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V)
|
||||
PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
|
||||
|
||||
PIX_FMT_ARGB, ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
|
||||
PIX_FMT_RGBA, ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
|
||||
PIX_FMT_ABGR, ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
|
||||
PIX_FMT_BGRA, ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
|
||||
|
||||
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), deprecated in favor of PIX_FMT_YUV440P and setting color_range
|
||||
PIX_FMT_YUVA420P, ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
|
||||
PIX_FMT_VDPAU_H264,///< H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_VDPAU_MPEG1,///< MPEG-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_VDPAU_MPEG2,///< MPEG-2 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_VDPAU_WMV3,///< WMV3 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_VDPAU_VC1, ///< VC-1 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_RGB48BE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big-endian
|
||||
PIX_FMT_RGB48LE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as little-endian
|
||||
|
||||
PIX_FMT_RGB565BE, ///< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
|
||||
PIX_FMT_RGB565LE, ///< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
|
||||
PIX_FMT_RGB555BE, ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0
|
||||
PIX_FMT_RGB555LE, ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0
|
||||
|
||||
PIX_FMT_BGR565BE, ///< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
|
||||
PIX_FMT_BGR565LE, ///< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
|
||||
PIX_FMT_BGR555BE, ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1
|
||||
PIX_FMT_BGR555LE, ///< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1
|
||||
|
||||
PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[3] contains a vaapi_render_state struct which contains macroblocks as well as various fields extracted from headers
|
||||
PIX_FMT_VAAPI_IDCT, ///< HW acceleration through VA API at IDCT entry-point, Picture.data[3] contains a vaapi_render_state struct which contains fields extracted from headers
|
||||
PIX_FMT_VAAPI_VLD, ///< HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
|
||||
PIX_FMT_YUV420P16LE, ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
|
||||
PIX_FMT_YUV420P16BE, ///< planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
|
||||
PIX_FMT_YUV422P16LE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
|
||||
PIX_FMT_YUV422P16BE, ///< planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
|
||||
PIX_FMT_YUV444P16LE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
|
||||
PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
|
||||
PIX_FMT_VDPAU_MPEG4, ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer
|
||||
|
||||
PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0
|
||||
PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0
|
||||
PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1
|
||||
PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1
|
||||
PIX_FMT_GRAY8A, ///< 8bit gray, 8bit alpha
|
||||
PIX_FMT_BGR48BE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian
|
||||
PIX_FMT_BGR48LE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian
|
||||
|
||||
//the following 10 formats have the disadvantage of needing 1 format for each bit depth, thus
|
||||
//If you want to support multiple bit depths, then using PIX_FMT_YUV420P16* with the bpp stored separately
|
||||
//is better
|
||||
PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
|
||||
PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
|
||||
PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
|
||||
PIX_FMT_YUV420P10LE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
|
||||
PIX_FMT_YUV422P10BE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
|
||||
PIX_FMT_YUV422P10LE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
|
||||
PIX_FMT_YUV444P9BE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
|
||||
PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
|
||||
PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
|
||||
PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
|
||||
PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
|
||||
PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
|
||||
PIX_FMT_VDA_VLD, ///< hardware decoding through VDA
|
||||
|
||||
#ifdef AV_PIX_FMT_ABI_GIT_MASTER
|
||||
PIX_FMT_RGBA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
|
||||
PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
|
||||
PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
|
||||
PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
|
||||
#endif
|
||||
PIX_FMT_GBRP, ///< planar GBR 4:4:4 24bpp
|
||||
PIX_FMT_GBRP9BE, ///< planar GBR 4:4:4 27bpp, big endian
|
||||
PIX_FMT_GBRP9LE, ///< planar GBR 4:4:4 27bpp, little endian
|
||||
PIX_FMT_GBRP10BE, ///< planar GBR 4:4:4 30bpp, big endian
|
||||
PIX_FMT_GBRP10LE, ///< planar GBR 4:4:4 30bpp, little endian
|
||||
PIX_FMT_GBRP16BE, ///< planar GBR 4:4:4 48bpp, big endian
|
||||
PIX_FMT_GBRP16LE, ///< planar GBR 4:4:4 48bpp, little endian
|
||||
|
||||
#ifndef AV_PIX_FMT_ABI_GIT_MASTER
|
||||
PIX_FMT_RGBA64BE=0x123, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
|
||||
PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
|
||||
PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian
|
||||
PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian
|
||||
#endif
|
||||
PIX_FMT_0RGB=0x123+4, ///< packed RGB 8:8:8, 32bpp, 0RGB0RGB...
|
||||
PIX_FMT_RGB0, ///< packed RGB 8:8:8, 32bpp, RGB0RGB0...
|
||||
PIX_FMT_0BGR, ///< packed BGR 8:8:8, 32bpp, 0BGR0BGR...
|
||||
PIX_FMT_BGR0, ///< packed BGR 8:8:8, 32bpp, BGR0BGR0...
|
||||
PIX_FMT_YUVA444P, ///< planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
|
||||
PIX_FMT_YUVA422P, ///< planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
|
||||
|
||||
PIX_FMT_YUV420P12BE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
|
||||
PIX_FMT_YUV420P12LE, ///< planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
|
||||
PIX_FMT_YUV420P14BE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
|
||||
PIX_FMT_YUV420P14LE, ///< planar YUV 4:2:0,21bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
|
||||
PIX_FMT_YUV422P12BE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
|
||||
PIX_FMT_YUV422P12LE, ///< planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
|
||||
PIX_FMT_YUV422P14BE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
|
||||
PIX_FMT_YUV422P14LE, ///< planar YUV 4:2:2,28bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
|
||||
PIX_FMT_YUV444P12BE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
|
||||
PIX_FMT_YUV444P12LE, ///< planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
|
||||
PIX_FMT_YUV444P14BE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
|
||||
PIX_FMT_YUV444P14LE, ///< planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
|
||||
PIX_FMT_GBRP12BE, ///< planar GBR 4:4:4 36bpp, big endian
|
||||
PIX_FMT_GBRP12LE, ///< planar GBR 4:4:4 36bpp, little endian
|
||||
PIX_FMT_GBRP14BE, ///< planar GBR 4:4:4 42bpp, big endian
|
||||
PIX_FMT_GBRP14LE, ///< planar GBR 4:4:4 42bpp, little endian
|
||||
|
||||
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
|
||||
#endif /* AVUTIL_OLD_PIX_FMTS_H */
|
||||
1435
project/jni/ffmpeg/libavutil/opt.c
Normal file
1435
project/jni/ffmpeg/libavutil/opt.c
Normal file
File diff suppressed because it is too large
Load Diff
733
project/jni/ffmpeg/libavutil/opt.h
Normal file
733
project/jni/ffmpeg/libavutil/opt.h
Normal file
@@ -0,0 +1,733 @@
|
||||
/*
|
||||
* AVOptions
|
||||
* 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 AVUTIL_OPT_H
|
||||
#define AVUTIL_OPT_H
|
||||
|
||||
/**
|
||||
* @file
|
||||
* AVOptions
|
||||
*/
|
||||
|
||||
#include "rational.h"
|
||||
#include "avutil.h"
|
||||
#include "dict.h"
|
||||
#include "log.h"
|
||||
#include "pixfmt.h"
|
||||
#include "samplefmt.h"
|
||||
|
||||
/**
|
||||
* @defgroup avoptions AVOptions
|
||||
* @ingroup lavu_data
|
||||
* @{
|
||||
* AVOptions provide a generic system to declare options on arbitrary structs
|
||||
* ("objects"). An option can have a help text, a type and a range of possible
|
||||
* values. Options may then be enumerated, read and written to.
|
||||
*
|
||||
* @section avoptions_implement Implementing AVOptions
|
||||
* This section describes how to add AVOptions capabilities to a struct.
|
||||
*
|
||||
* All AVOptions-related information is stored in an AVClass. Therefore
|
||||
* the first member of the struct should be a pointer to an AVClass describing it.
|
||||
* The option field of the AVClass must be set to a NULL-terminated static array
|
||||
* of AVOptions. Each AVOption must have a non-empty name, a type, a default
|
||||
* value and for number-type AVOptions also a range of allowed values. It must
|
||||
* also declare an offset in bytes from the start of the struct, where the field
|
||||
* associated with this AVOption is located. Other fields in the AVOption struct
|
||||
* should also be set when applicable, but are not required.
|
||||
*
|
||||
* The following example illustrates an AVOptions-enabled struct:
|
||||
* @code
|
||||
* typedef struct test_struct {
|
||||
* AVClass *class;
|
||||
* int int_opt;
|
||||
* char *str_opt;
|
||||
* uint8_t *bin_opt;
|
||||
* int bin_len;
|
||||
* } test_struct;
|
||||
*
|
||||
* static const AVOption options[] = {
|
||||
* { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
|
||||
* AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX },
|
||||
* { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
|
||||
* AV_OPT_TYPE_STRING },
|
||||
* { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
|
||||
* AV_OPT_TYPE_BINARY },
|
||||
* { NULL },
|
||||
* };
|
||||
*
|
||||
* static const AVClass test_class = {
|
||||
* .class_name = "test class",
|
||||
* .item_name = av_default_item_name,
|
||||
* .option = options,
|
||||
* .version = LIBAVUTIL_VERSION_INT,
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* Next, when allocating your struct, you must ensure that the AVClass pointer
|
||||
* is set to the correct value. Then, av_opt_set_defaults() can be called to
|
||||
* initialize defaults. After that the struct is ready to be used with the
|
||||
* AVOptions API.
|
||||
*
|
||||
* When cleaning up, you may use the av_opt_free() function to automatically
|
||||
* free all the allocated string and binary options.
|
||||
*
|
||||
* Continuing with the above example:
|
||||
*
|
||||
* @code
|
||||
* test_struct *alloc_test_struct(void)
|
||||
* {
|
||||
* test_struct *ret = av_malloc(sizeof(*ret));
|
||||
* ret->class = &test_class;
|
||||
* av_opt_set_defaults(ret);
|
||||
* return ret;
|
||||
* }
|
||||
* void free_test_struct(test_struct **foo)
|
||||
* {
|
||||
* av_opt_free(*foo);
|
||||
* av_freep(foo);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @subsection avoptions_implement_nesting Nesting
|
||||
* It may happen that an AVOptions-enabled struct contains another
|
||||
* AVOptions-enabled struct as a member (e.g. AVCodecContext in
|
||||
* libavcodec exports generic options, while its priv_data field exports
|
||||
* codec-specific options). In such a case, it is possible to set up the
|
||||
* parent struct to export a child's options. To do that, simply
|
||||
* implement AVClass.child_next() and AVClass.child_class_next() in the
|
||||
* parent struct's AVClass.
|
||||
* Assuming that the test_struct from above now also contains a
|
||||
* child_struct field:
|
||||
*
|
||||
* @code
|
||||
* typedef struct child_struct {
|
||||
* AVClass *class;
|
||||
* int flags_opt;
|
||||
* } child_struct;
|
||||
* static const AVOption child_opts[] = {
|
||||
* { "test_flags", "This is a test option of flags type.",
|
||||
* offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX },
|
||||
* { NULL },
|
||||
* };
|
||||
* static const AVClass child_class = {
|
||||
* .class_name = "child class",
|
||||
* .item_name = av_default_item_name,
|
||||
* .option = child_opts,
|
||||
* .version = LIBAVUTIL_VERSION_INT,
|
||||
* };
|
||||
*
|
||||
* void *child_next(void *obj, void *prev)
|
||||
* {
|
||||
* test_struct *t = obj;
|
||||
* if (!prev && t->child_struct)
|
||||
* return t->child_struct;
|
||||
* return NULL
|
||||
* }
|
||||
* const AVClass child_class_next(const AVClass *prev)
|
||||
* {
|
||||
* return prev ? NULL : &child_class;
|
||||
* }
|
||||
* @endcode
|
||||
* Putting child_next() and child_class_next() as defined above into
|
||||
* test_class will now make child_struct's options accessible through
|
||||
* test_struct (again, proper setup as described above needs to be done on
|
||||
* child_struct right after it is created).
|
||||
*
|
||||
* From the above example it might not be clear why both child_next()
|
||||
* and child_class_next() are needed. The distinction is that child_next()
|
||||
* iterates over actually existing objects, while child_class_next()
|
||||
* iterates over all possible child classes. E.g. if an AVCodecContext
|
||||
* was initialized to use a codec which has private options, then its
|
||||
* child_next() will return AVCodecContext.priv_data and finish
|
||||
* iterating. OTOH child_class_next() on AVCodecContext.av_class will
|
||||
* iterate over all available codecs with private options.
|
||||
*
|
||||
* @subsection avoptions_implement_named_constants Named constants
|
||||
* It is possible to create named constants for options. Simply set the unit
|
||||
* field of the option the constants should apply to to a string and
|
||||
* create the constants themselves as options of type AV_OPT_TYPE_CONST
|
||||
* with their unit field set to the same string.
|
||||
* Their default_val field should contain the value of the named
|
||||
* constant.
|
||||
* For example, to add some named constants for the test_flags option
|
||||
* above, put the following into the child_opts array:
|
||||
* @code
|
||||
* { "test_flags", "This is a test option of flags type.",
|
||||
* offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" },
|
||||
* { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" },
|
||||
* @endcode
|
||||
*
|
||||
* @section avoptions_use Using AVOptions
|
||||
* This section deals with accessing options in an AVOptions-enabled struct.
|
||||
* Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or
|
||||
* AVFormatContext in libavformat.
|
||||
*
|
||||
* @subsection avoptions_use_examine Examining AVOptions
|
||||
* The basic functions for examining options are av_opt_next(), which iterates
|
||||
* over all options defined for one object, and av_opt_find(), which searches
|
||||
* for an option with the given name.
|
||||
*
|
||||
* The situation is more complicated with nesting. An AVOptions-enabled struct
|
||||
* may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag
|
||||
* to av_opt_find() will make the function search children recursively.
|
||||
*
|
||||
* For enumerating there are basically two cases. The first is when you want to
|
||||
* get all options that may potentially exist on the struct and its children
|
||||
* (e.g. when constructing documentation). In that case you should call
|
||||
* av_opt_child_class_next() recursively on the parent struct's AVClass. The
|
||||
* second case is when you have an already initialized struct with all its
|
||||
* children and you want to get all options that can be actually written or read
|
||||
* from it. In that case you should call av_opt_child_next() recursively (and
|
||||
* av_opt_next() on each result).
|
||||
*
|
||||
* @subsection avoptions_use_get_set Reading and writing AVOptions
|
||||
* When setting options, you often have a string read directly from the
|
||||
* user. In such a case, simply passing it to av_opt_set() is enough. For
|
||||
* non-string type options, av_opt_set() will parse the string according to the
|
||||
* option type.
|
||||
*
|
||||
* Similarly av_opt_get() will read any option type and convert it to a string
|
||||
* which will be returned. Do not forget that the string is allocated, so you
|
||||
* have to free it with av_free().
|
||||
*
|
||||
* In some cases it may be more convenient to put all options into an
|
||||
* AVDictionary and call av_opt_set_dict() on it. A specific case of this
|
||||
* are the format/codec open functions in lavf/lavc which take a dictionary
|
||||
* filled with option as a parameter. This allows to set some options
|
||||
* that cannot be set otherwise, since e.g. the input file format is not known
|
||||
* before the file is actually opened.
|
||||
*/
|
||||
|
||||
enum AVOptionType{
|
||||
AV_OPT_TYPE_FLAGS,
|
||||
AV_OPT_TYPE_INT,
|
||||
AV_OPT_TYPE_INT64,
|
||||
AV_OPT_TYPE_DOUBLE,
|
||||
AV_OPT_TYPE_FLOAT,
|
||||
AV_OPT_TYPE_STRING,
|
||||
AV_OPT_TYPE_RATIONAL,
|
||||
AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
|
||||
AV_OPT_TYPE_CONST = 128,
|
||||
AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers
|
||||
AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P','F','M','T'),
|
||||
AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
|
||||
#if FF_API_OLD_AVOPTIONS
|
||||
FF_OPT_TYPE_FLAGS = 0,
|
||||
FF_OPT_TYPE_INT,
|
||||
FF_OPT_TYPE_INT64,
|
||||
FF_OPT_TYPE_DOUBLE,
|
||||
FF_OPT_TYPE_FLOAT,
|
||||
FF_OPT_TYPE_STRING,
|
||||
FF_OPT_TYPE_RATIONAL,
|
||||
FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
|
||||
FF_OPT_TYPE_CONST=128,
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* AVOption
|
||||
*/
|
||||
typedef struct AVOption {
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* short English help text
|
||||
* @todo What about other languages?
|
||||
*/
|
||||
const char *help;
|
||||
|
||||
/**
|
||||
* The offset relative to the context structure where the option
|
||||
* value is stored. It should be 0 for named constants.
|
||||
*/
|
||||
int offset;
|
||||
enum AVOptionType type;
|
||||
|
||||
/**
|
||||
* the default value for scalar options
|
||||
*/
|
||||
union {
|
||||
int64_t i64;
|
||||
double dbl;
|
||||
const char *str;
|
||||
/* TODO those are unused now */
|
||||
AVRational q;
|
||||
} default_val;
|
||||
double min; ///< minimum valid value for the option
|
||||
double max; ///< maximum valid value for the option
|
||||
|
||||
int flags;
|
||||
#define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
|
||||
#define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
|
||||
#define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
|
||||
#define AV_OPT_FLAG_AUDIO_PARAM 8
|
||||
#define AV_OPT_FLAG_VIDEO_PARAM 16
|
||||
#define AV_OPT_FLAG_SUBTITLE_PARAM 32
|
||||
#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
|
||||
//FIXME think about enc-audio, ... style flags
|
||||
|
||||
/**
|
||||
* The logical unit to which the option belongs. Non-constant
|
||||
* options and corresponding named constants share the same
|
||||
* unit. May be NULL.
|
||||
*/
|
||||
const char *unit;
|
||||
} AVOption;
|
||||
|
||||
/**
|
||||
* A single allowed range of values, or a single allowed value.
|
||||
*/
|
||||
typedef struct AVOptionRange {
|
||||
const char *str;
|
||||
double value_min, value_max; ///< For string ranges this represents the min/max length, for dimensions this represents the min/max pixel count
|
||||
double component_min, component_max; ///< For string this represents the unicode range for chars, 0-127 limits to ASCII
|
||||
int is_range; ///< if set to 1 the struct encodes a range, if set to 0 a single value
|
||||
} AVOptionRange;
|
||||
|
||||
/**
|
||||
* List of AVOptionRange structs
|
||||
*/
|
||||
typedef struct AVOptionRanges {
|
||||
AVOptionRange **range;
|
||||
int nb_ranges;
|
||||
} AVOptionRanges;
|
||||
|
||||
|
||||
#if FF_API_FIND_OPT
|
||||
/**
|
||||
* Look for an option in obj. Look only for the options which
|
||||
* have the flags set as specified in mask and flags (that is,
|
||||
* for which it is the case that opt->flags & mask == flags).
|
||||
*
|
||||
* @param[in] obj a pointer to a struct whose first element is a
|
||||
* pointer to an AVClass
|
||||
* @param[in] name the name of the option to look for
|
||||
* @param[in] unit the unit of the option to look for, or any if NULL
|
||||
* @return a pointer to the option found, or NULL if no option
|
||||
* has been found
|
||||
*
|
||||
* @deprecated use av_opt_find.
|
||||
*/
|
||||
attribute_deprecated
|
||||
const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
|
||||
#endif
|
||||
|
||||
#if FF_API_OLD_AVOPTIONS
|
||||
/**
|
||||
* Set the field of obj with the given name to value.
|
||||
*
|
||||
* @param[in] obj A struct whose first element is a pointer to an
|
||||
* AVClass.
|
||||
* @param[in] name the name of the field to set
|
||||
* @param[in] val The value to set. If the field is not of a string
|
||||
* type, then the given string is parsed.
|
||||
* SI postfixes and some named scalars are supported.
|
||||
* If the field is of a numeric type, it has to be a numeric or named
|
||||
* scalar. Behavior with more than one scalar and +- infix operators
|
||||
* is undefined.
|
||||
* If the field is of a flags type, it has to be a sequence of numeric
|
||||
* scalars or named flags separated by '+' or '-'. Prefixing a flag
|
||||
* with '+' causes it to be set without affecting the other flags;
|
||||
* similarly, '-' unsets a flag.
|
||||
* @param[out] o_out if non-NULL put here a pointer to the AVOption
|
||||
* found
|
||||
* @param alloc this parameter is currently ignored
|
||||
* @return 0 if the value has been set, or an AVERROR code in case of
|
||||
* error:
|
||||
* AVERROR_OPTION_NOT_FOUND if no matching option exists
|
||||
* AVERROR(ERANGE) if the value is out of range
|
||||
* AVERROR(EINVAL) if the value is not valid
|
||||
* @deprecated use av_opt_set()
|
||||
*/
|
||||
attribute_deprecated
|
||||
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
|
||||
|
||||
attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
|
||||
attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
|
||||
attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
|
||||
|
||||
double av_get_double(void *obj, const char *name, const AVOption **o_out);
|
||||
AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
|
||||
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
|
||||
attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
|
||||
attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Show the obj options.
|
||||
*
|
||||
* @param req_flags requested flags for the options to show. Show only the
|
||||
* options for which it is opt->flags & req_flags.
|
||||
* @param rej_flags rejected flags for the options to show. Show only the
|
||||
* options for which it is !(opt->flags & req_flags).
|
||||
* @param av_log_obj log context to use for showing the options
|
||||
*/
|
||||
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
|
||||
|
||||
/**
|
||||
* Set the values of all AVOption fields to their default values.
|
||||
*
|
||||
* @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
|
||||
*/
|
||||
void av_opt_set_defaults(void *s);
|
||||
|
||||
#if FF_API_OLD_AVOPTIONS
|
||||
attribute_deprecated
|
||||
void av_opt_set_defaults2(void *s, int mask, int flags);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Parse the key/value pairs list in opts. For each key/value pair
|
||||
* found, stores the value in the field in ctx that is named like the
|
||||
* key. ctx must be an AVClass context, storing is done using
|
||||
* AVOptions.
|
||||
*
|
||||
* @param opts options string to parse, may be NULL
|
||||
* @param key_val_sep a 0-terminated list of characters used to
|
||||
* separate key from value
|
||||
* @param pairs_sep a 0-terminated list of characters used to separate
|
||||
* two pairs from each other
|
||||
* @return the number of successfully set key/value pairs, or a negative
|
||||
* value corresponding to an AVERROR code in case of error:
|
||||
* AVERROR(EINVAL) if opts cannot be parsed,
|
||||
* the error code issued by av_set_string3() if a key/value pair
|
||||
* cannot be set
|
||||
*/
|
||||
int av_set_options_string(void *ctx, const char *opts,
|
||||
const char *key_val_sep, const char *pairs_sep);
|
||||
|
||||
/**
|
||||
* Parse the key-value pairs list in opts. For each key=value pair found,
|
||||
* set the value of the corresponding option in ctx.
|
||||
*
|
||||
* @param ctx the AVClass object to set options on
|
||||
* @param opts the options string, key-value pairs separated by a
|
||||
* delimiter
|
||||
* @param shorthand a NULL-terminated array of options names for shorthand
|
||||
* notation: if the first field in opts has no key part,
|
||||
* the key is taken from the first element of shorthand;
|
||||
* then again for the second, etc., until either opts is
|
||||
* finished, shorthand is finished or a named option is
|
||||
* found; after that, all options must be named
|
||||
* @param key_val_sep a 0-terminated list of characters used to separate
|
||||
* key from value, for example '='
|
||||
* @param pairs_sep a 0-terminated list of characters used to separate
|
||||
* two pairs from each other, for example ':' or ','
|
||||
* @return the number of successfully set key=value pairs, or a negative
|
||||
* value corresponding to an AVERROR code in case of error:
|
||||
* AVERROR(EINVAL) if opts cannot be parsed,
|
||||
* the error code issued by av_set_string3() if a key/value pair
|
||||
* cannot be set
|
||||
*
|
||||
* Options names must use only the following characters: a-z A-Z 0-9 - . / _
|
||||
* Separators must use characters distinct from option names and from each
|
||||
* other.
|
||||
*/
|
||||
int av_opt_set_from_string(void *ctx, const char *opts,
|
||||
const char *const *shorthand,
|
||||
const char *key_val_sep, const char *pairs_sep);
|
||||
/**
|
||||
* Free all string and binary options in obj.
|
||||
*/
|
||||
void av_opt_free(void *obj);
|
||||
|
||||
/**
|
||||
* Check whether a particular flag is set in a flags field.
|
||||
*
|
||||
* @param field_name the name of the flag field option
|
||||
* @param flag_name the name of the flag to check
|
||||
* @return non-zero if the flag is set, zero if the flag isn't set,
|
||||
* isn't of the right type, or the flags field doesn't exist.
|
||||
*/
|
||||
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
|
||||
|
||||
/**
|
||||
* Set all the options from a given dictionary on an object.
|
||||
*
|
||||
* @param obj a struct whose first element is a pointer to AVClass
|
||||
* @param options options to process. This dictionary will be freed and replaced
|
||||
* by a new one containing all options not found in obj.
|
||||
* Of course this new dictionary needs to be freed by caller
|
||||
* with av_dict_free().
|
||||
*
|
||||
* @return 0 on success, a negative AVERROR if some option was found in obj,
|
||||
* but could not be set.
|
||||
*
|
||||
* @see av_dict_copy()
|
||||
*/
|
||||
int av_opt_set_dict(void *obj, struct AVDictionary **options);
|
||||
|
||||
/**
|
||||
* Extract a key-value pair from the beginning of a string.
|
||||
*
|
||||
* @param ropts pointer to the options string, will be updated to
|
||||
* point to the rest of the string (one of the pairs_sep
|
||||
* or the final NUL)
|
||||
* @param key_val_sep a 0-terminated list of characters used to separate
|
||||
* key from value, for example '='
|
||||
* @param pairs_sep a 0-terminated list of characters used to separate
|
||||
* two pairs from each other, for example ':' or ','
|
||||
* @param flags flags; see the AV_OPT_FLAG_* values below
|
||||
* @param rkey parsed key; must be freed using av_free()
|
||||
* @param rval parsed value; must be freed using av_free()
|
||||
*
|
||||
* @return >=0 for success, or a negative value corresponding to an
|
||||
* AVERROR code in case of error; in particular:
|
||||
* AVERROR(EINVAL) if no key is present
|
||||
*
|
||||
*/
|
||||
int av_opt_get_key_value(const char **ropts,
|
||||
const char *key_val_sep, const char *pairs_sep,
|
||||
unsigned flags,
|
||||
char **rkey, char **rval);
|
||||
|
||||
enum {
|
||||
|
||||
/**
|
||||
* Accept to parse a value without a key; the key will then be returned
|
||||
* as NULL.
|
||||
*/
|
||||
AV_OPT_FLAG_IMPLICIT_KEY = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup opt_eval_funcs Evaluating option strings
|
||||
* @{
|
||||
* This group of functions can be used to evaluate option strings
|
||||
* and get numbers out of them. They do the same thing as av_opt_set(),
|
||||
* except the result is written into the caller-supplied pointer.
|
||||
*
|
||||
* @param obj a struct whose first element is a pointer to AVClass.
|
||||
* @param o an option for which the string is to be evaluated.
|
||||
* @param val string to be evaluated.
|
||||
* @param *_out value of the string will be written here.
|
||||
*
|
||||
* @return 0 on success, a negative number on failure.
|
||||
*/
|
||||
int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
|
||||
int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
|
||||
int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
|
||||
int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
|
||||
int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
|
||||
int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
|
||||
given object first. */
|
||||
/**
|
||||
* The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
|
||||
* instead of a required pointer to a struct containing AVClass. This is
|
||||
* useful for searching for options without needing to allocate the corresponding
|
||||
* object.
|
||||
*/
|
||||
#define AV_OPT_SEARCH_FAKE_OBJ 0x0002
|
||||
|
||||
/**
|
||||
* Look for an option in an object. Consider only options which
|
||||
* have all the specified flags set.
|
||||
*
|
||||
* @param[in] obj A pointer to a struct whose first element is a
|
||||
* pointer to an AVClass.
|
||||
* Alternatively a double pointer to an AVClass, if
|
||||
* AV_OPT_SEARCH_FAKE_OBJ search flag is set.
|
||||
* @param[in] name The name of the option to look for.
|
||||
* @param[in] unit When searching for named constants, name of the unit
|
||||
* it belongs to.
|
||||
* @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
|
||||
* @param search_flags A combination of AV_OPT_SEARCH_*.
|
||||
*
|
||||
* @return A pointer to the option found, or NULL if no option
|
||||
* was found.
|
||||
*
|
||||
* @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
|
||||
* directly with av_set_string3(). Use special calls which take an options
|
||||
* AVDictionary (e.g. avformat_open_input()) to set options found with this
|
||||
* flag.
|
||||
*/
|
||||
const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
|
||||
int opt_flags, int search_flags);
|
||||
|
||||
/**
|
||||
* Look for an option in an object. Consider only options which
|
||||
* have all the specified flags set.
|
||||
*
|
||||
* @param[in] obj A pointer to a struct whose first element is a
|
||||
* pointer to an AVClass.
|
||||
* Alternatively a double pointer to an AVClass, if
|
||||
* AV_OPT_SEARCH_FAKE_OBJ search flag is set.
|
||||
* @param[in] name The name of the option to look for.
|
||||
* @param[in] unit When searching for named constants, name of the unit
|
||||
* it belongs to.
|
||||
* @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
|
||||
* @param search_flags A combination of AV_OPT_SEARCH_*.
|
||||
* @param[out] target_obj if non-NULL, an object to which the option belongs will be
|
||||
* written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
|
||||
* in search_flags. This parameter is ignored if search_flags contain
|
||||
* AV_OPT_SEARCH_FAKE_OBJ.
|
||||
*
|
||||
* @return A pointer to the option found, or NULL if no option
|
||||
* was found.
|
||||
*/
|
||||
const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
|
||||
int opt_flags, int search_flags, void **target_obj);
|
||||
|
||||
/**
|
||||
* Iterate over all AVOptions belonging to obj.
|
||||
*
|
||||
* @param obj an AVOptions-enabled struct or a double pointer to an
|
||||
* AVClass describing it.
|
||||
* @param prev result of the previous call to av_opt_next() on this object
|
||||
* or NULL
|
||||
* @return next AVOption or NULL
|
||||
*/
|
||||
const AVOption *av_opt_next(void *obj, const AVOption *prev);
|
||||
|
||||
/**
|
||||
* Iterate over AVOptions-enabled children of obj.
|
||||
*
|
||||
* @param prev result of a previous call to this function or NULL
|
||||
* @return next AVOptions-enabled child or NULL
|
||||
*/
|
||||
void *av_opt_child_next(void *obj, void *prev);
|
||||
|
||||
/**
|
||||
* Iterate over potential AVOptions-enabled children of parent.
|
||||
*
|
||||
* @param prev result of a previous call to this function or NULL
|
||||
* @return AVClass corresponding to next potential child or NULL
|
||||
*/
|
||||
const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
|
||||
|
||||
/**
|
||||
* @defgroup opt_set_funcs Option setting functions
|
||||
* @{
|
||||
* Those functions set the field of obj with the given name to value.
|
||||
*
|
||||
* @param[in] obj A struct whose first element is a pointer to an AVClass.
|
||||
* @param[in] name the name of the field to set
|
||||
* @param[in] val The value to set. In case of av_opt_set() if the field is not
|
||||
* of a string type, then the given string is parsed.
|
||||
* SI postfixes and some named scalars are supported.
|
||||
* If the field is of a numeric type, it has to be a numeric or named
|
||||
* scalar. Behavior with more than one scalar and +- infix operators
|
||||
* is undefined.
|
||||
* If the field is of a flags type, it has to be a sequence of numeric
|
||||
* scalars or named flags separated by '+' or '-'. Prefixing a flag
|
||||
* with '+' causes it to be set without affecting the other flags;
|
||||
* similarly, '-' unsets a flag.
|
||||
* @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
|
||||
* is passed here, then the option may be set on a child of obj.
|
||||
*
|
||||
* @return 0 if the value has been set, or an AVERROR code in case of
|
||||
* error:
|
||||
* AVERROR_OPTION_NOT_FOUND if no matching option exists
|
||||
* AVERROR(ERANGE) if the value is out of range
|
||||
* AVERROR(EINVAL) if the value is not valid
|
||||
*/
|
||||
int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
|
||||
int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
|
||||
int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
|
||||
int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
|
||||
int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
|
||||
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);
|
||||
int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
|
||||
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup opt_get_funcs Option getting functions
|
||||
* @{
|
||||
* Those functions get a value of the option with the given name from an object.
|
||||
*
|
||||
* @param[in] obj a struct whose first element is a pointer to an AVClass.
|
||||
* @param[in] name name of the option to get.
|
||||
* @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
|
||||
* is passed here, then the option may be found in a child of obj.
|
||||
* @param[out] out_val value of the option will be written here
|
||||
* @return 0 on success, a negative error code otherwise
|
||||
*/
|
||||
/**
|
||||
* @note the returned string will av_malloc()ed and must be av_free()ed by the caller
|
||||
*/
|
||||
int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
|
||||
int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
|
||||
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
|
||||
int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
|
||||
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out);
|
||||
int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt);
|
||||
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* Gets a pointer to the requested field in a struct.
|
||||
* This function allows accessing a struct even when its fields are moved or
|
||||
* renamed since the application making the access has been compiled,
|
||||
*
|
||||
* @returns a pointer to the field, it can be cast to the correct type and read
|
||||
* or written to.
|
||||
*/
|
||||
void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
|
||||
|
||||
/**
|
||||
* Free an AVOptionRanges struct and set it to NULL.
|
||||
*/
|
||||
void av_opt_freep_ranges(AVOptionRanges **ranges);
|
||||
|
||||
/**
|
||||
* Get a list of allowed ranges for the given option.
|
||||
*
|
||||
* The returned list may depend on other fields in obj like for example profile.
|
||||
*
|
||||
* @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
|
||||
* AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
|
||||
*
|
||||
* The result must be freed with av_opt_freep_ranges.
|
||||
*
|
||||
* @return >= 0 on success, a negative errro code otherwise
|
||||
*/
|
||||
int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
|
||||
|
||||
/**
|
||||
* Get a default list of allowed ranges for the given option.
|
||||
*
|
||||
* This list is constructed without using the AVClass.query_ranges() callback
|
||||
* and can be used as fallback from within the callback.
|
||||
*
|
||||
* @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
|
||||
* AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
|
||||
*
|
||||
* The result must be freed with av_opt_free_ranges.
|
||||
*
|
||||
* @return >= 0 on success, a negative errro code otherwise
|
||||
*/
|
||||
int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* AVUTIL_OPT_H */
|
||||
859
project/jni/ffmpeg/libavutil/parseutils.c
Normal file
859
project/jni/ffmpeg/libavutil/parseutils.c
Normal file
@@ -0,0 +1,859 @@
|
||||
/*
|
||||
* 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
|
||||
* misc parsing utilities
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "avstring.h"
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "eval.h"
|
||||
#include "log.h"
|
||||
#include "random_seed.h"
|
||||
#include "parseutils.h"
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
#define av_get_random_seed av_get_random_seed_deterministic
|
||||
static uint32_t av_get_random_seed_deterministic(void);
|
||||
|
||||
#define time(t) 1331972053
|
||||
|
||||
#endif
|
||||
|
||||
int av_parse_ratio(AVRational *q, const char *str, int max,
|
||||
int log_offset, void *log_ctx)
|
||||
{
|
||||
char c;
|
||||
int ret;
|
||||
|
||||
if (sscanf(str, "%d:%d%c", &q->num, &q->den, &c) != 2) {
|
||||
double d;
|
||||
ret = av_expr_parse_and_eval(&d, str, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, log_offset, log_ctx);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*q = av_d2q(d, max);
|
||||
} else {
|
||||
av_reduce(&q->num, &q->den, q->num, q->den, max);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *abbr;
|
||||
int width, height;
|
||||
} VideoSizeAbbr;
|
||||
|
||||
typedef struct {
|
||||
const char *abbr;
|
||||
AVRational rate;
|
||||
} VideoRateAbbr;
|
||||
|
||||
static const VideoSizeAbbr video_size_abbrs[] = {
|
||||
{ "ntsc", 720, 480 },
|
||||
{ "pal", 720, 576 },
|
||||
{ "qntsc", 352, 240 }, /* VCD compliant NTSC */
|
||||
{ "qpal", 352, 288 }, /* VCD compliant PAL */
|
||||
{ "sntsc", 640, 480 }, /* square pixel NTSC */
|
||||
{ "spal", 768, 576 }, /* square pixel PAL */
|
||||
{ "film", 352, 240 },
|
||||
{ "ntsc-film", 352, 240 },
|
||||
{ "sqcif", 128, 96 },
|
||||
{ "qcif", 176, 144 },
|
||||
{ "cif", 352, 288 },
|
||||
{ "4cif", 704, 576 },
|
||||
{ "16cif", 1408,1152 },
|
||||
{ "qqvga", 160, 120 },
|
||||
{ "qvga", 320, 240 },
|
||||
{ "vga", 640, 480 },
|
||||
{ "svga", 800, 600 },
|
||||
{ "xga", 1024, 768 },
|
||||
{ "uxga", 1600,1200 },
|
||||
{ "qxga", 2048,1536 },
|
||||
{ "sxga", 1280,1024 },
|
||||
{ "qsxga", 2560,2048 },
|
||||
{ "hsxga", 5120,4096 },
|
||||
{ "wvga", 852, 480 },
|
||||
{ "wxga", 1366, 768 },
|
||||
{ "wsxga", 1600,1024 },
|
||||
{ "wuxga", 1920,1200 },
|
||||
{ "woxga", 2560,1600 },
|
||||
{ "wqsxga", 3200,2048 },
|
||||
{ "wquxga", 3840,2400 },
|
||||
{ "whsxga", 6400,4096 },
|
||||
{ "whuxga", 7680,4800 },
|
||||
{ "cga", 320, 200 },
|
||||
{ "ega", 640, 350 },
|
||||
{ "hd480", 852, 480 },
|
||||
{ "hd720", 1280, 720 },
|
||||
{ "hd1080", 1920,1080 },
|
||||
};
|
||||
|
||||
static const VideoRateAbbr video_rate_abbrs[]= {
|
||||
{ "ntsc", { 30000, 1001 } },
|
||||
{ "pal", { 25, 1 } },
|
||||
{ "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */
|
||||
{ "qpal", { 25, 1 } }, /* VCD compliant PAL */
|
||||
{ "sntsc", { 30000, 1001 } }, /* square pixel NTSC */
|
||||
{ "spal", { 25, 1 } }, /* square pixel PAL */
|
||||
{ "film", { 24, 1 } },
|
||||
{ "ntsc-film", { 24000, 1001 } },
|
||||
};
|
||||
|
||||
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
|
||||
{
|
||||
int i;
|
||||
int n = FF_ARRAY_ELEMS(video_size_abbrs);
|
||||
const char *p;
|
||||
int width = 0, height = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!strcmp(video_size_abbrs[i].abbr, str)) {
|
||||
width = video_size_abbrs[i].width;
|
||||
height = video_size_abbrs[i].height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == n) {
|
||||
width = strtol(str, (void*)&p, 10);
|
||||
if (*p)
|
||||
p++;
|
||||
height = strtol(p, (void*)&p, 10);
|
||||
|
||||
/* trailing extraneous data detected, like in 123x345foobar */
|
||||
if (*p)
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
if (width <= 0 || height <= 0)
|
||||
return AVERROR(EINVAL);
|
||||
*width_ptr = width;
|
||||
*height_ptr = height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_parse_video_rate(AVRational *rate, const char *arg)
|
||||
{
|
||||
int i, ret;
|
||||
int n = FF_ARRAY_ELEMS(video_rate_abbrs);
|
||||
|
||||
/* First, we check our abbreviation table */
|
||||
for (i = 0; i < n; ++i)
|
||||
if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
|
||||
*rate = video_rate_abbrs[i].rate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Then, we try to parse it as fraction */
|
||||
if ((ret = av_parse_ratio_quiet(rate, arg, 1001000)) < 0)
|
||||
return ret;
|
||||
if (rate->num <= 0 || rate->den <= 0)
|
||||
return AVERROR(EINVAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *name; ///< a string representing the name of the color
|
||||
uint8_t rgb_color[3]; ///< RGB values for the color
|
||||
} ColorEntry;
|
||||
|
||||
static const ColorEntry color_table[] = {
|
||||
{ "AliceBlue", { 0xF0, 0xF8, 0xFF } },
|
||||
{ "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } },
|
||||
{ "Aqua", { 0x00, 0xFF, 0xFF } },
|
||||
{ "Aquamarine", { 0x7F, 0xFF, 0xD4 } },
|
||||
{ "Azure", { 0xF0, 0xFF, 0xFF } },
|
||||
{ "Beige", { 0xF5, 0xF5, 0xDC } },
|
||||
{ "Bisque", { 0xFF, 0xE4, 0xC4 } },
|
||||
{ "Black", { 0x00, 0x00, 0x00 } },
|
||||
{ "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } },
|
||||
{ "Blue", { 0x00, 0x00, 0xFF } },
|
||||
{ "BlueViolet", { 0x8A, 0x2B, 0xE2 } },
|
||||
{ "Brown", { 0xA5, 0x2A, 0x2A } },
|
||||
{ "BurlyWood", { 0xDE, 0xB8, 0x87 } },
|
||||
{ "CadetBlue", { 0x5F, 0x9E, 0xA0 } },
|
||||
{ "Chartreuse", { 0x7F, 0xFF, 0x00 } },
|
||||
{ "Chocolate", { 0xD2, 0x69, 0x1E } },
|
||||
{ "Coral", { 0xFF, 0x7F, 0x50 } },
|
||||
{ "CornflowerBlue", { 0x64, 0x95, 0xED } },
|
||||
{ "Cornsilk", { 0xFF, 0xF8, 0xDC } },
|
||||
{ "Crimson", { 0xDC, 0x14, 0x3C } },
|
||||
{ "Cyan", { 0x00, 0xFF, 0xFF } },
|
||||
{ "DarkBlue", { 0x00, 0x00, 0x8B } },
|
||||
{ "DarkCyan", { 0x00, 0x8B, 0x8B } },
|
||||
{ "DarkGoldenRod", { 0xB8, 0x86, 0x0B } },
|
||||
{ "DarkGray", { 0xA9, 0xA9, 0xA9 } },
|
||||
{ "DarkGreen", { 0x00, 0x64, 0x00 } },
|
||||
{ "DarkKhaki", { 0xBD, 0xB7, 0x6B } },
|
||||
{ "DarkMagenta", { 0x8B, 0x00, 0x8B } },
|
||||
{ "DarkOliveGreen", { 0x55, 0x6B, 0x2F } },
|
||||
{ "Darkorange", { 0xFF, 0x8C, 0x00 } },
|
||||
{ "DarkOrchid", { 0x99, 0x32, 0xCC } },
|
||||
{ "DarkRed", { 0x8B, 0x00, 0x00 } },
|
||||
{ "DarkSalmon", { 0xE9, 0x96, 0x7A } },
|
||||
{ "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } },
|
||||
{ "DarkSlateBlue", { 0x48, 0x3D, 0x8B } },
|
||||
{ "DarkSlateGray", { 0x2F, 0x4F, 0x4F } },
|
||||
{ "DarkTurquoise", { 0x00, 0xCE, 0xD1 } },
|
||||
{ "DarkViolet", { 0x94, 0x00, 0xD3 } },
|
||||
{ "DeepPink", { 0xFF, 0x14, 0x93 } },
|
||||
{ "DeepSkyBlue", { 0x00, 0xBF, 0xFF } },
|
||||
{ "DimGray", { 0x69, 0x69, 0x69 } },
|
||||
{ "DodgerBlue", { 0x1E, 0x90, 0xFF } },
|
||||
{ "FireBrick", { 0xB2, 0x22, 0x22 } },
|
||||
{ "FloralWhite", { 0xFF, 0xFA, 0xF0 } },
|
||||
{ "ForestGreen", { 0x22, 0x8B, 0x22 } },
|
||||
{ "Fuchsia", { 0xFF, 0x00, 0xFF } },
|
||||
{ "Gainsboro", { 0xDC, 0xDC, 0xDC } },
|
||||
{ "GhostWhite", { 0xF8, 0xF8, 0xFF } },
|
||||
{ "Gold", { 0xFF, 0xD7, 0x00 } },
|
||||
{ "GoldenRod", { 0xDA, 0xA5, 0x20 } },
|
||||
{ "Gray", { 0x80, 0x80, 0x80 } },
|
||||
{ "Green", { 0x00, 0x80, 0x00 } },
|
||||
{ "GreenYellow", { 0xAD, 0xFF, 0x2F } },
|
||||
{ "HoneyDew", { 0xF0, 0xFF, 0xF0 } },
|
||||
{ "HotPink", { 0xFF, 0x69, 0xB4 } },
|
||||
{ "IndianRed", { 0xCD, 0x5C, 0x5C } },
|
||||
{ "Indigo", { 0x4B, 0x00, 0x82 } },
|
||||
{ "Ivory", { 0xFF, 0xFF, 0xF0 } },
|
||||
{ "Khaki", { 0xF0, 0xE6, 0x8C } },
|
||||
{ "Lavender", { 0xE6, 0xE6, 0xFA } },
|
||||
{ "LavenderBlush", { 0xFF, 0xF0, 0xF5 } },
|
||||
{ "LawnGreen", { 0x7C, 0xFC, 0x00 } },
|
||||
{ "LemonChiffon", { 0xFF, 0xFA, 0xCD } },
|
||||
{ "LightBlue", { 0xAD, 0xD8, 0xE6 } },
|
||||
{ "LightCoral", { 0xF0, 0x80, 0x80 } },
|
||||
{ "LightCyan", { 0xE0, 0xFF, 0xFF } },
|
||||
{ "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } },
|
||||
{ "LightGreen", { 0x90, 0xEE, 0x90 } },
|
||||
{ "LightGrey", { 0xD3, 0xD3, 0xD3 } },
|
||||
{ "LightPink", { 0xFF, 0xB6, 0xC1 } },
|
||||
{ "LightSalmon", { 0xFF, 0xA0, 0x7A } },
|
||||
{ "LightSeaGreen", { 0x20, 0xB2, 0xAA } },
|
||||
{ "LightSkyBlue", { 0x87, 0xCE, 0xFA } },
|
||||
{ "LightSlateGray", { 0x77, 0x88, 0x99 } },
|
||||
{ "LightSteelBlue", { 0xB0, 0xC4, 0xDE } },
|
||||
{ "LightYellow", { 0xFF, 0xFF, 0xE0 } },
|
||||
{ "Lime", { 0x00, 0xFF, 0x00 } },
|
||||
{ "LimeGreen", { 0x32, 0xCD, 0x32 } },
|
||||
{ "Linen", { 0xFA, 0xF0, 0xE6 } },
|
||||
{ "Magenta", { 0xFF, 0x00, 0xFF } },
|
||||
{ "Maroon", { 0x80, 0x00, 0x00 } },
|
||||
{ "MediumAquaMarine", { 0x66, 0xCD, 0xAA } },
|
||||
{ "MediumBlue", { 0x00, 0x00, 0xCD } },
|
||||
{ "MediumOrchid", { 0xBA, 0x55, 0xD3 } },
|
||||
{ "MediumPurple", { 0x93, 0x70, 0xD8 } },
|
||||
{ "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } },
|
||||
{ "MediumSlateBlue", { 0x7B, 0x68, 0xEE } },
|
||||
{ "MediumSpringGreen", { 0x00, 0xFA, 0x9A } },
|
||||
{ "MediumTurquoise", { 0x48, 0xD1, 0xCC } },
|
||||
{ "MediumVioletRed", { 0xC7, 0x15, 0x85 } },
|
||||
{ "MidnightBlue", { 0x19, 0x19, 0x70 } },
|
||||
{ "MintCream", { 0xF5, 0xFF, 0xFA } },
|
||||
{ "MistyRose", { 0xFF, 0xE4, 0xE1 } },
|
||||
{ "Moccasin", { 0xFF, 0xE4, 0xB5 } },
|
||||
{ "NavajoWhite", { 0xFF, 0xDE, 0xAD } },
|
||||
{ "Navy", { 0x00, 0x00, 0x80 } },
|
||||
{ "OldLace", { 0xFD, 0xF5, 0xE6 } },
|
||||
{ "Olive", { 0x80, 0x80, 0x00 } },
|
||||
{ "OliveDrab", { 0x6B, 0x8E, 0x23 } },
|
||||
{ "Orange", { 0xFF, 0xA5, 0x00 } },
|
||||
{ "OrangeRed", { 0xFF, 0x45, 0x00 } },
|
||||
{ "Orchid", { 0xDA, 0x70, 0xD6 } },
|
||||
{ "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } },
|
||||
{ "PaleGreen", { 0x98, 0xFB, 0x98 } },
|
||||
{ "PaleTurquoise", { 0xAF, 0xEE, 0xEE } },
|
||||
{ "PaleVioletRed", { 0xD8, 0x70, 0x93 } },
|
||||
{ "PapayaWhip", { 0xFF, 0xEF, 0xD5 } },
|
||||
{ "PeachPuff", { 0xFF, 0xDA, 0xB9 } },
|
||||
{ "Peru", { 0xCD, 0x85, 0x3F } },
|
||||
{ "Pink", { 0xFF, 0xC0, 0xCB } },
|
||||
{ "Plum", { 0xDD, 0xA0, 0xDD } },
|
||||
{ "PowderBlue", { 0xB0, 0xE0, 0xE6 } },
|
||||
{ "Purple", { 0x80, 0x00, 0x80 } },
|
||||
{ "Red", { 0xFF, 0x00, 0x00 } },
|
||||
{ "RosyBrown", { 0xBC, 0x8F, 0x8F } },
|
||||
{ "RoyalBlue", { 0x41, 0x69, 0xE1 } },
|
||||
{ "SaddleBrown", { 0x8B, 0x45, 0x13 } },
|
||||
{ "Salmon", { 0xFA, 0x80, 0x72 } },
|
||||
{ "SandyBrown", { 0xF4, 0xA4, 0x60 } },
|
||||
{ "SeaGreen", { 0x2E, 0x8B, 0x57 } },
|
||||
{ "SeaShell", { 0xFF, 0xF5, 0xEE } },
|
||||
{ "Sienna", { 0xA0, 0x52, 0x2D } },
|
||||
{ "Silver", { 0xC0, 0xC0, 0xC0 } },
|
||||
{ "SkyBlue", { 0x87, 0xCE, 0xEB } },
|
||||
{ "SlateBlue", { 0x6A, 0x5A, 0xCD } },
|
||||
{ "SlateGray", { 0x70, 0x80, 0x90 } },
|
||||
{ "Snow", { 0xFF, 0xFA, 0xFA } },
|
||||
{ "SpringGreen", { 0x00, 0xFF, 0x7F } },
|
||||
{ "SteelBlue", { 0x46, 0x82, 0xB4 } },
|
||||
{ "Tan", { 0xD2, 0xB4, 0x8C } },
|
||||
{ "Teal", { 0x00, 0x80, 0x80 } },
|
||||
{ "Thistle", { 0xD8, 0xBF, 0xD8 } },
|
||||
{ "Tomato", { 0xFF, 0x63, 0x47 } },
|
||||
{ "Turquoise", { 0x40, 0xE0, 0xD0 } },
|
||||
{ "Violet", { 0xEE, 0x82, 0xEE } },
|
||||
{ "Wheat", { 0xF5, 0xDE, 0xB3 } },
|
||||
{ "White", { 0xFF, 0xFF, 0xFF } },
|
||||
{ "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } },
|
||||
{ "Yellow", { 0xFF, 0xFF, 0x00 } },
|
||||
{ "YellowGreen", { 0x9A, 0xCD, 0x32 } },
|
||||
};
|
||||
|
||||
static int color_table_compare(const void *lhs, const void *rhs)
|
||||
{
|
||||
return av_strcasecmp(lhs, ((const ColorEntry *)rhs)->name);
|
||||
}
|
||||
|
||||
#define ALPHA_SEP '@'
|
||||
|
||||
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
|
||||
void *log_ctx)
|
||||
{
|
||||
char *tail, color_string2[128];
|
||||
const ColorEntry *entry;
|
||||
int len, hex_offset = 0;
|
||||
|
||||
if (color_string[0] == '#') {
|
||||
hex_offset = 1;
|
||||
} else if (!strncmp(color_string, "0x", 2))
|
||||
hex_offset = 2;
|
||||
|
||||
if (slen < 0)
|
||||
slen = strlen(color_string);
|
||||
av_strlcpy(color_string2, color_string + hex_offset,
|
||||
FFMIN(slen-hex_offset+1, sizeof(color_string2)));
|
||||
if ((tail = strchr(color_string2, ALPHA_SEP)))
|
||||
*tail++ = 0;
|
||||
len = strlen(color_string2);
|
||||
rgba_color[3] = 255;
|
||||
|
||||
if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) {
|
||||
int rgba = av_get_random_seed();
|
||||
rgba_color[0] = rgba >> 24;
|
||||
rgba_color[1] = rgba >> 16;
|
||||
rgba_color[2] = rgba >> 8;
|
||||
rgba_color[3] = rgba;
|
||||
} else if (hex_offset ||
|
||||
strspn(color_string2, "0123456789ABCDEFabcdef") == len) {
|
||||
char *tail;
|
||||
unsigned int rgba = strtoul(color_string2, &tail, 16);
|
||||
|
||||
if (*tail || (len != 6 && len != 8)) {
|
||||
av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
if (len == 8) {
|
||||
rgba_color[3] = rgba;
|
||||
rgba >>= 8;
|
||||
}
|
||||
rgba_color[0] = rgba >> 16;
|
||||
rgba_color[1] = rgba >> 8;
|
||||
rgba_color[2] = rgba;
|
||||
} else {
|
||||
entry = bsearch(color_string2,
|
||||
color_table,
|
||||
FF_ARRAY_ELEMS(color_table),
|
||||
sizeof(ColorEntry),
|
||||
color_table_compare);
|
||||
if (!entry) {
|
||||
av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
memcpy(rgba_color, entry->rgb_color, 3);
|
||||
}
|
||||
|
||||
if (tail) {
|
||||
double alpha;
|
||||
const char *alpha_string = tail;
|
||||
if (!strncmp(alpha_string, "0x", 2)) {
|
||||
alpha = strtoul(alpha_string, &tail, 16);
|
||||
} else {
|
||||
double norm_alpha = strtod(alpha_string, &tail);
|
||||
if (norm_alpha < 0.0 || norm_alpha > 1.0)
|
||||
alpha = 256;
|
||||
else
|
||||
alpha = 255 * norm_alpha;
|
||||
}
|
||||
|
||||
if (tail == alpha_string || *tail || alpha > 255 || alpha < 0) {
|
||||
av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n",
|
||||
alpha_string, color_string);
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
rgba_color[3] = alpha;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get a positive number between n_min and n_max, for a maximum length
|
||||
of len_max. Return -1 if error. */
|
||||
static int date_get_num(const char **pp,
|
||||
int n_min, int n_max, int len_max)
|
||||
{
|
||||
int i, val, c;
|
||||
const char *p;
|
||||
|
||||
p = *pp;
|
||||
val = 0;
|
||||
for(i = 0; i < len_max; i++) {
|
||||
c = *p;
|
||||
if (!isdigit(c))
|
||||
break;
|
||||
val = (val * 10) + c - '0';
|
||||
p++;
|
||||
}
|
||||
/* no number read ? */
|
||||
if (p == *pp)
|
||||
return -1;
|
||||
if (val < n_min || val > n_max)
|
||||
return -1;
|
||||
*pp = p;
|
||||
return val;
|
||||
}
|
||||
|
||||
char *av_small_strptime(const char *p, const char *fmt, struct tm *dt)
|
||||
{
|
||||
int c, val;
|
||||
|
||||
for(;;) {
|
||||
/* consume time string until a non whitespace char is found */
|
||||
while (isspace(*fmt)) {
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
fmt++;
|
||||
}
|
||||
c = *fmt++;
|
||||
if (c == '\0') {
|
||||
return (char *)p;
|
||||
} else if (c == '%') {
|
||||
c = *fmt++;
|
||||
switch(c) {
|
||||
case 'H':
|
||||
case 'J':
|
||||
val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, 2);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_hour = val;
|
||||
break;
|
||||
case 'M':
|
||||
val = date_get_num(&p, 0, 59, 2);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_min = val;
|
||||
break;
|
||||
case 'S':
|
||||
val = date_get_num(&p, 0, 59, 2);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_sec = val;
|
||||
break;
|
||||
case 'Y':
|
||||
val = date_get_num(&p, 0, 9999, 4);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_year = val - 1900;
|
||||
break;
|
||||
case 'm':
|
||||
val = date_get_num(&p, 1, 12, 2);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_mon = val - 1;
|
||||
break;
|
||||
case 'd':
|
||||
val = date_get_num(&p, 1, 31, 2);
|
||||
if (val == -1)
|
||||
return NULL;
|
||||
dt->tm_mday = val;
|
||||
break;
|
||||
case '%':
|
||||
goto match;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
match:
|
||||
if (c != *p)
|
||||
return NULL;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
time_t av_timegm(struct tm *tm)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
|
||||
|
||||
if (m < 3) {
|
||||
m += 12;
|
||||
y--;
|
||||
}
|
||||
|
||||
t = 86400 *
|
||||
(d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
|
||||
|
||||
t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
|
||||
{
|
||||
const char *p, *q;
|
||||
int64_t t;
|
||||
time_t now;
|
||||
struct tm dt = { 0 };
|
||||
int today = 0, negative = 0, microseconds = 0;
|
||||
int i;
|
||||
static const char * const date_fmt[] = {
|
||||
"%Y-%m-%d",
|
||||
"%Y%m%d",
|
||||
};
|
||||
static const char * const time_fmt[] = {
|
||||
"%H:%M:%S",
|
||||
"%H%M%S",
|
||||
};
|
||||
|
||||
p = timestr;
|
||||
q = NULL;
|
||||
*timeval = INT64_MIN;
|
||||
if (!duration) {
|
||||
now = time(0);
|
||||
|
||||
if (!av_strcasecmp(timestr, "now")) {
|
||||
*timeval = (int64_t) now * 1000000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* parse the year-month-day part */
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {
|
||||
q = av_small_strptime(p, date_fmt[i], &dt);
|
||||
if (q)
|
||||
break;
|
||||
}
|
||||
|
||||
/* if the year-month-day part is missing, then take the
|
||||
* current year-month-day time */
|
||||
if (!q) {
|
||||
today = 1;
|
||||
q = p;
|
||||
}
|
||||
p = q;
|
||||
|
||||
if (*p == 'T' || *p == 't' || *p == ' ')
|
||||
p++;
|
||||
|
||||
/* parse the hour-minute-second part */
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {
|
||||
q = av_small_strptime(p, time_fmt[i], &dt);
|
||||
if (q)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* parse timestr as a duration */
|
||||
if (p[0] == '-') {
|
||||
negative = 1;
|
||||
++p;
|
||||
}
|
||||
/* parse timestr as HH:MM:SS */
|
||||
q = av_small_strptime(p, "%J:%M:%S", &dt);
|
||||
if (!q) {
|
||||
/* parse timestr as S+ */
|
||||
dt.tm_sec = strtol(p, (void *)&q, 10);
|
||||
if (q == p) /* the parsing didn't succeed */
|
||||
return AVERROR(EINVAL);
|
||||
dt.tm_min = 0;
|
||||
dt.tm_hour = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we have all the fields that we can get */
|
||||
if (!q)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
/* parse the .m... part */
|
||||
if (*q == '.') {
|
||||
int n;
|
||||
q++;
|
||||
for (n = 100000; n >= 1; n /= 10, q++) {
|
||||
if (!isdigit(*q))
|
||||
break;
|
||||
microseconds += n * (*q - '0');
|
||||
}
|
||||
while (isdigit(*q))
|
||||
q++;
|
||||
}
|
||||
|
||||
if (duration) {
|
||||
t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
|
||||
} else {
|
||||
int is_utc = *q == 'Z' || *q == 'z';
|
||||
q += is_utc;
|
||||
if (today) { /* fill in today's date */
|
||||
struct tm dt2 = is_utc ? *gmtime(&now) : *localtime(&now);
|
||||
dt2.tm_hour = dt.tm_hour;
|
||||
dt2.tm_min = dt.tm_min;
|
||||
dt2.tm_sec = dt.tm_sec;
|
||||
dt = dt2;
|
||||
}
|
||||
t = is_utc ? av_timegm(&dt) : mktime(&dt);
|
||||
}
|
||||
|
||||
/* Check that we are at the end of the string */
|
||||
if (*q)
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
t *= 1000000;
|
||||
t += microseconds;
|
||||
*timeval = negative ? -t : t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
|
||||
{
|
||||
const char *p;
|
||||
char tag[128], *q;
|
||||
|
||||
p = info;
|
||||
if (*p == '?')
|
||||
p++;
|
||||
for(;;) {
|
||||
q = tag;
|
||||
while (*p != '\0' && *p != '=' && *p != '&') {
|
||||
if ((q - tag) < sizeof(tag) - 1)
|
||||
*q++ = *p;
|
||||
p++;
|
||||
}
|
||||
*q = '\0';
|
||||
q = arg;
|
||||
if (*p == '=') {
|
||||
p++;
|
||||
while (*p != '&' && *p != '\0') {
|
||||
if ((q - arg) < arg_size - 1) {
|
||||
if (*p == '+')
|
||||
*q++ = ' ';
|
||||
else
|
||||
*q++ = *p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
*q = '\0';
|
||||
if (!strcmp(tag, tag1))
|
||||
return 1;
|
||||
if (*p != '&')
|
||||
break;
|
||||
p++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
static uint32_t randomv = MKTAG('L','A','V','U');
|
||||
|
||||
static uint32_t av_get_random_seed_deterministic(void)
|
||||
{
|
||||
return randomv = randomv * 1664525 + 1013904223;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("Testing av_parse_video_rate()\n");
|
||||
{
|
||||
int i;
|
||||
static const char *const rates[] = {
|
||||
"-inf",
|
||||
"inf",
|
||||
"nan",
|
||||
"123/0",
|
||||
"-123 / 0",
|
||||
"",
|
||||
"/",
|
||||
" 123 / 321",
|
||||
"foo/foo",
|
||||
"foo/1",
|
||||
"1/foo",
|
||||
"0/0",
|
||||
"/0",
|
||||
"1/",
|
||||
"1",
|
||||
"0",
|
||||
"-123/123",
|
||||
"-foo",
|
||||
"123.23",
|
||||
".23",
|
||||
"-.23",
|
||||
"-0.234",
|
||||
"-0.0000001",
|
||||
" 21332.2324 ",
|
||||
" -21332.2324 ",
|
||||
};
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
|
||||
int ret;
|
||||
AVRational q = { 0, 0 };
|
||||
ret = av_parse_video_rate(&q, rates[i]);
|
||||
printf("'%s' -> %d/%d %s\n",
|
||||
rates[i], q.num, q.den, ret ? "ERROR" : "OK");
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nTesting av_parse_color()\n");
|
||||
{
|
||||
int i;
|
||||
uint8_t rgba[4];
|
||||
static const char *const color_names[] = {
|
||||
"bikeshed",
|
||||
"RaNdOm",
|
||||
"foo",
|
||||
"red",
|
||||
"Red ",
|
||||
"RED",
|
||||
"Violet",
|
||||
"Yellow",
|
||||
"Red",
|
||||
"0x000000",
|
||||
"0x0000000",
|
||||
"0xff000000",
|
||||
"0x3e34ff",
|
||||
"0x3e34ffaa",
|
||||
"0xffXXee",
|
||||
"0xfoobar",
|
||||
"0xffffeeeeeeee",
|
||||
"#ff0000",
|
||||
"#ffXX00",
|
||||
"ff0000",
|
||||
"ffXX00",
|
||||
"red@foo",
|
||||
"random@10",
|
||||
"0xff0000@1.0",
|
||||
"red@",
|
||||
"red@0xfff",
|
||||
"red@0xf",
|
||||
"red@2",
|
||||
"red@0.1",
|
||||
"red@-1",
|
||||
"red@0.5",
|
||||
"red@1.0",
|
||||
"red@256",
|
||||
"red@10foo",
|
||||
"red@-1.0",
|
||||
"red@-0.0",
|
||||
};
|
||||
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
|
||||
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
|
||||
printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
|
||||
color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
else
|
||||
printf("%s -> error\n", color_names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nTesting av_small_strptime()\n");
|
||||
{
|
||||
int i;
|
||||
struct tm tm = { 0 };
|
||||
struct fmt_timespec_entry {
|
||||
const char *fmt, *timespec;
|
||||
} fmt_timespec_entries[] = {
|
||||
{ "%Y-%m-%d", "2012-12-21" },
|
||||
{ "%Y - %m - %d", "2012-12-21" },
|
||||
{ "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" },
|
||||
{ " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" },
|
||||
};
|
||||
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(fmt_timespec_entries); i++) {
|
||||
char *p;
|
||||
struct fmt_timespec_entry *e = &fmt_timespec_entries[i];
|
||||
printf("fmt:'%s' spec:'%s' -> ", e->fmt, e->timespec);
|
||||
p = av_small_strptime(e->timespec, e->fmt, &tm);
|
||||
if (p) {
|
||||
printf("%04d-%02d-%2d %02d:%02d:%02d\n",
|
||||
1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
} else {
|
||||
printf("error\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nTesting av_parse_time()\n");
|
||||
{
|
||||
int i;
|
||||
int64_t tv;
|
||||
time_t tvi;
|
||||
struct tm *tm;
|
||||
static char tzstr[] = "TZ=CET-1";
|
||||
const char *time_string[] = {
|
||||
"now",
|
||||
"12:35:46",
|
||||
"2000-12-20 0:02:47.5z",
|
||||
"2000-12-20T010247.6",
|
||||
};
|
||||
const char *duration_string[] = {
|
||||
"2:34:56.79",
|
||||
"-1:23:45.67",
|
||||
"42.1729",
|
||||
"-1729.42",
|
||||
"12:34",
|
||||
};
|
||||
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
putenv(tzstr);
|
||||
printf("(now is 2012-03-17 09:14:13 +0100, local time is UTC+1)\n");
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) {
|
||||
printf("%-24s -> ", time_string[i]);
|
||||
if (av_parse_time(&tv, time_string[i], 0)) {
|
||||
printf("error\n");
|
||||
} else {
|
||||
tvi = tv / 1000000;
|
||||
tm = gmtime(&tvi);
|
||||
printf("%14"PRIi64".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n",
|
||||
tv / 1000000, (int)(tv % 1000000),
|
||||
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < FF_ARRAY_ELEMS(duration_string); i++) {
|
||||
printf("%-24s -> ", duration_string[i]);
|
||||
if (av_parse_time(&tv, duration_string[i], 1)) {
|
||||
printf("error\n");
|
||||
} else {
|
||||
printf("%+21"PRIi64"\n", tv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
174
project/jni/ffmpeg/libavutil/parseutils.h
Normal file
174
project/jni/ffmpeg/libavutil/parseutils.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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 AVUTIL_PARSEUTILS_H
|
||||
#define AVUTIL_PARSEUTILS_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "rational.h"
|
||||
|
||||
/**
|
||||
* @file
|
||||
* misc parsing utilities
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse str and store the parsed ratio in q.
|
||||
*
|
||||
* Note that a ratio with infinite (1/0) or negative value is
|
||||
* considered valid, so you should check on the returned value if you
|
||||
* want to exclude those values.
|
||||
*
|
||||
* The undefined value can be expressed using the "0:0" string.
|
||||
*
|
||||
* @param[in,out] q pointer to the AVRational which will contain the ratio
|
||||
* @param[in] str the string to parse: it has to be a string in the format
|
||||
* num:den, a float number or an expression
|
||||
* @param[in] max the maximum allowed numerator and denominator
|
||||
* @param[in] log_offset log level offset which is applied to the log
|
||||
* level of log_ctx
|
||||
* @param[in] log_ctx parent logging context
|
||||
* @return >= 0 on success, a negative error code otherwise
|
||||
*/
|
||||
int av_parse_ratio(AVRational *q, const char *str, int max,
|
||||
int log_offset, void *log_ctx);
|
||||
|
||||
#define av_parse_ratio_quiet(rate, str, max) \
|
||||
av_parse_ratio(rate, str, max, AV_LOG_MAX_OFFSET, NULL)
|
||||
|
||||
/**
|
||||
* Parse str and put in width_ptr and height_ptr the detected values.
|
||||
*
|
||||
* @param[in,out] width_ptr pointer to the variable which will contain the detected
|
||||
* width value
|
||||
* @param[in,out] height_ptr pointer to the variable which will contain the detected
|
||||
* height value
|
||||
* @param[in] str the string to parse: it has to be a string in the format
|
||||
* width x height or a valid video size abbreviation.
|
||||
* @return >= 0 on success, a negative error code otherwise
|
||||
*/
|
||||
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str);
|
||||
|
||||
/**
|
||||
* Parse str and store the detected values in *rate.
|
||||
*
|
||||
* @param[in,out] rate pointer to the AVRational which will contain the detected
|
||||
* frame rate
|
||||
* @param[in] str the string to parse: it has to be a string in the format
|
||||
* rate_num / rate_den, a float number or a valid video rate abbreviation
|
||||
* @return >= 0 on success, a negative error code otherwise
|
||||
*/
|
||||
int av_parse_video_rate(AVRational *rate, const char *str);
|
||||
|
||||
/**
|
||||
* Put the RGBA values that correspond to color_string in rgba_color.
|
||||
*
|
||||
* @param color_string a string specifying a color. It can be the name of
|
||||
* a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence,
|
||||
* possibly followed by "@" and a string representing the alpha
|
||||
* component.
|
||||
* The alpha component may be a string composed by "0x" followed by an
|
||||
* hexadecimal number or a decimal number between 0.0 and 1.0, which
|
||||
* represents the opacity value (0x00/0.0 means completely transparent,
|
||||
* 0xff/1.0 completely opaque).
|
||||
* If the alpha component is not specified then 0xff is assumed.
|
||||
* The string "random" will result in a random color.
|
||||
* @param slen length of the initial part of color_string containing the
|
||||
* color. It can be set to -1 if color_string is a null terminated string
|
||||
* containing nothing else than the color.
|
||||
* @return >= 0 in case of success, a negative value in case of
|
||||
* failure (for example if color_string cannot be parsed).
|
||||
*/
|
||||
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
|
||||
void *log_ctx);
|
||||
|
||||
/**
|
||||
* Parse timestr and return in *time a corresponding number of
|
||||
* microseconds.
|
||||
*
|
||||
* @param timeval puts here the number of microseconds corresponding
|
||||
* to the string in timestr. If the string represents a duration, it
|
||||
* is the number of microseconds contained in the time interval. If
|
||||
* the string is a date, is the number of microseconds since 1st of
|
||||
* January, 1970 up to the time of the parsed date. If timestr cannot
|
||||
* be successfully parsed, set *time to INT64_MIN.
|
||||
|
||||
* @param timestr a string representing a date or a duration.
|
||||
* - If a date the syntax is:
|
||||
* @code
|
||||
* [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH:MM:SS[.m...]]]}|{HHMMSS[.m...]]]}}[Z]
|
||||
* now
|
||||
* @endcode
|
||||
* If the value is "now" it takes the current time.
|
||||
* Time is local time unless Z is appended, in which case it is
|
||||
* interpreted as UTC.
|
||||
* If the year-month-day part is not specified it takes the current
|
||||
* year-month-day.
|
||||
* - If a duration the syntax is:
|
||||
* @code
|
||||
* [-]HH:MM:SS[.m...]]]
|
||||
* [-]S+[.m...]
|
||||
* @endcode
|
||||
* @param duration flag which tells how to interpret timestr, if not
|
||||
* zero timestr is interpreted as a duration, otherwise as a date
|
||||
* @return 0 in case of success, a negative value corresponding to an
|
||||
* AVERROR code otherwise
|
||||
*/
|
||||
int av_parse_time(int64_t *timeval, const char *timestr, int duration);
|
||||
|
||||
/**
|
||||
* Parse the input string p according to the format string fmt and
|
||||
* store its results in the structure dt.
|
||||
* This implementation supports only a subset of the formats supported
|
||||
* by the standard strptime().
|
||||
*
|
||||
* In particular it actually supports the parameters:
|
||||
* - %H: the hour as a decimal number, using a 24-hour clock, in the
|
||||
* range '00' through '23'
|
||||
* - %J: hours as a decimal number, in the range '0' through INT_MAX
|
||||
* - %M: the minute as a decimal number, using a 24-hour clock, in the
|
||||
* range '00' through '59'
|
||||
* - %S: the second as a decimal number, using a 24-hour clock, in the
|
||||
* range '00' through '59'
|
||||
* - %Y: the year as a decimal number, using the Gregorian calendar
|
||||
* - %m: the month as a decimal number, in the range '1' through '12'
|
||||
* - %d: the day of the month as a decimal number, in the range '1'
|
||||
* through '31'
|
||||
* - %%: a literal '%'
|
||||
*
|
||||
* @return a pointer to the first character not processed in this
|
||||
* function call, or NULL in case the function fails to match all of
|
||||
* the fmt string and therefore an error occurred
|
||||
*/
|
||||
char *av_small_strptime(const char *p, const char *fmt, struct tm *dt);
|
||||
|
||||
/**
|
||||
* Attempt to find a specific tag in a URL.
|
||||
*
|
||||
* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
|
||||
* Return 1 if found.
|
||||
*/
|
||||
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
|
||||
|
||||
/**
|
||||
* Convert the decomposed UTC time in tm to a time_t value.
|
||||
*/
|
||||
time_t av_timegm(struct tm *tm);
|
||||
|
||||
#endif /* AVUTIL_PARSEUTILS_H */
|
||||
248
project/jni/ffmpeg/libavutil/pca.c
Normal file
248
project/jni/ffmpeg/libavutil/pca.c
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* principal component analysis (PCA)
|
||||
* 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
|
||||
* principal component analysis (PCA)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "pca.h"
|
||||
|
||||
typedef struct PCA{
|
||||
int count;
|
||||
int n;
|
||||
double *covariance;
|
||||
double *mean;
|
||||
double *z;
|
||||
}PCA;
|
||||
|
||||
PCA *ff_pca_init(int n){
|
||||
PCA *pca;
|
||||
if(n<=0)
|
||||
return NULL;
|
||||
|
||||
pca= av_mallocz(sizeof(PCA));
|
||||
pca->n= n;
|
||||
pca->z = av_malloc(sizeof(*pca->z) * 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_freep(&pca->z);
|
||||
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, pass;
|
||||
int k=0;
|
||||
const int n= pca->n;
|
||||
double *z = pca->z;
|
||||
|
||||
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 should not 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
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lfg.h"
|
||||
|
||||
int main(void){
|
||||
PCA *pca;
|
||||
int i, j, k;
|
||||
#define LEN 8
|
||||
double eigenvector[LEN*LEN];
|
||||
double eigenvalue[LEN];
|
||||
AVLFG prng;
|
||||
|
||||
av_lfg_init(&prng, 1);
|
||||
|
||||
pca= ff_pca_init(LEN);
|
||||
|
||||
for(i=0; i<9000000; i++){
|
||||
double v[2*LEN+100];
|
||||
double sum=0;
|
||||
int pos = av_lfg_get(&prng) % LEN;
|
||||
int v2 = av_lfg_get(&prng) % 101 - 50;
|
||||
v[0] = av_lfg_get(&prng) % 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 += av_lfg_get(&prng) % 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");
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user