sync with ffmpeg 0.5 release
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29535 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6608bd7c78
commit
3d50ba22de
|
@ -4,14 +4,16 @@ SubDir HAIKU_TOP src add-ons media plugins avcodec libavutil ;
|
|||
TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS)
|
||||
: -Wall -Wmissing-prototypes -Wsign-compare -Wpointer-arith ] ;
|
||||
|
||||
SubDirHdrs [ FDirName $(SUBDIR) .. ] ;
|
||||
SubDirHdrs [ FDirName $(SUBDIR) ../libavcodec ] ;
|
||||
|
||||
SubDirCcFlags -fomit-frame-pointer -DPIC ;
|
||||
SubDirCcFlags -DHAVE_AV_CONFIG_H=1 ;
|
||||
#SubDirCcFlags -DHAVE_AV_CONFIG_H=1 ;
|
||||
|
||||
StaticLibrary libavutil.a :
|
||||
adler32.c
|
||||
aes.c
|
||||
avstring.c
|
||||
base64.c
|
||||
crc.c
|
||||
des.c
|
||||
|
@ -27,10 +29,10 @@ StaticLibrary libavutil.a :
|
|||
mem.c
|
||||
pca.c
|
||||
random.c
|
||||
random_seed.c
|
||||
rational.c
|
||||
rc4.c
|
||||
sha1.c
|
||||
softfloat.c
|
||||
string.c
|
||||
tree.c
|
||||
utils.c
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
/*
|
||||
* 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
|
||||
|
@ -35,7 +36,7 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigne
|
|||
unsigned long s2 = adler >> 16;
|
||||
|
||||
while (len>0) {
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
while(len>4 && s2 < (1U<<31)){
|
||||
DO4(buf); len-=4;
|
||||
#else
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_ADLER32_H
|
||||
#define FFMPEG_ADLER32_H
|
||||
#ifndef AVUTIL_ADLER32_H
|
||||
#define AVUTIL_ADLER32_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
@ -27,4 +27,4 @@
|
|||
unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
|
||||
unsigned int len) av_pure;
|
||||
|
||||
#endif /* FFMPEG_ADLER32_H */
|
||||
#endif /* AVUTIL_ADLER32_H */
|
||||
|
|
|
@ -39,7 +39,7 @@ static const uint8_t rcon[10] = {
|
|||
|
||||
static uint8_t sbox[256];
|
||||
static uint8_t inv_sbox[256];
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
static uint32_t enc_multbl[1][256];
|
||||
static uint32_t dec_multbl[1][256];
|
||||
#else
|
||||
|
@ -47,12 +47,12 @@ static uint32_t enc_multbl[4][256];
|
|||
static uint32_t dec_multbl[4][256];
|
||||
#endif
|
||||
|
||||
static inline void addkey(uint64_t dst[2], uint64_t src[2], uint64_t round_key[2]){
|
||||
static inline void addkey(uint64_t dst[2], const uint64_t src[2], const uint64_t round_key[2]){
|
||||
dst[0] = src[0] ^ round_key[0];
|
||||
dst[1] = src[1] ^ round_key[1];
|
||||
}
|
||||
|
||||
static void subshift(uint8_t s0[2][16], int s, uint8_t *box){
|
||||
static void subshift(uint8_t s0[2][16], int s, const uint8_t *box){
|
||||
uint8_t (*s1)[16]= s0[0] - s;
|
||||
uint8_t (*s3)[16]= s0[0] + s;
|
||||
s0[0][0]=box[s0[1][ 0]]; s0[0][ 4]=box[s0[1][ 4]]; s0[0][ 8]=box[s0[1][ 8]]; s0[0][12]=box[s0[1][12]];
|
||||
|
@ -62,7 +62,7 @@ static void subshift(uint8_t s0[2][16], int s, uint8_t *box){
|
|||
}
|
||||
|
||||
static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
#define ROT(x,s) ((x<<s)|(x>>(32-s)))
|
||||
return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24);
|
||||
#else
|
||||
|
@ -77,7 +77,7 @@ static inline void mix(uint8_t state[2][4][4], uint32_t multbl[4][256], int s1,
|
|||
((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]);
|
||||
}
|
||||
|
||||
static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
|
||||
static inline void crypt(AVAES *a, int s, const uint8_t *sbox, const uint32_t *multbl){
|
||||
int r;
|
||||
|
||||
for(r=a->rounds-1; r>0; r--){
|
||||
|
@ -87,7 +87,7 @@ static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
|
|||
subshift(a->state[0][0], s, sbox);
|
||||
}
|
||||
|
||||
void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){
|
||||
void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt){
|
||||
while(count--){
|
||||
addkey(a->state[1], src, a->round_key[a->rounds]);
|
||||
if(decrypt) {
|
||||
|
@ -108,13 +108,13 @@ void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv,
|
|||
}
|
||||
}
|
||||
|
||||
static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *alog8, uint8_t *sbox){
|
||||
static void init_multbl2(uint8_t tbl[1024], const int c[4], const uint8_t *log8, const uint8_t *alog8, const uint8_t *sbox){
|
||||
int i, j;
|
||||
for(i=0; i<1024; i++){
|
||||
int x= sbox[i>>2];
|
||||
if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ];
|
||||
}
|
||||
#ifndef CONFIG_SMALL
|
||||
#if !CONFIG_SMALL
|
||||
for(j=256; j<1024; j++)
|
||||
for(i=0; i<4; i++)
|
||||
tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024];
|
||||
|
@ -146,8 +146,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
|
|||
inv_sbox[j]= i;
|
||||
sbox [i]= j;
|
||||
}
|
||||
init_multbl2(dec_multbl[0], (int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox);
|
||||
init_multbl2(enc_multbl[0], (int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox);
|
||||
init_multbl2(dec_multbl[0], (const int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox);
|
||||
init_multbl2(enc_multbl[0], (const int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox);
|
||||
}
|
||||
|
||||
if(key_bits!=128 && key_bits!=192 && key_bits!=256)
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AES_H
|
||||
#define FFMPEG_AES_H
|
||||
#ifndef AVUTIL_AES_H
|
||||
#define AVUTIL_AES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -42,6 +42,6 @@ int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
|
|||
* @param iv initialization vector for CBC mode, if NULL then ECB will be used
|
||||
* @param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
void av_aes_crypt(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
|
||||
#endif /* FFMPEG_AES_H */
|
||||
#endif /* AVUTIL_AES_H */
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2007 Mans Rullgard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "avstring.h"
|
||||
|
||||
int av_strstart(const char *str, const char *pfx, const char **ptr)
|
||||
{
|
||||
while (*pfx && *pfx == *str) {
|
||||
pfx++;
|
||||
str++;
|
||||
}
|
||||
if (!*pfx && ptr)
|
||||
*ptr = str;
|
||||
return !*pfx;
|
||||
}
|
||||
|
||||
int av_stristart(const char *str, const char *pfx, const char **ptr)
|
||||
{
|
||||
while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) {
|
||||
pfx++;
|
||||
str++;
|
||||
}
|
||||
if (!*pfx && ptr)
|
||||
*ptr = str;
|
||||
return !*pfx;
|
||||
}
|
||||
|
||||
size_t av_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t len = 0;
|
||||
while (++len < size && *src)
|
||||
*dst++ = *src++;
|
||||
if (len <= size)
|
||||
*dst = 0;
|
||||
return len + strlen(src) - 1;
|
||||
}
|
||||
|
||||
size_t av_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t len = strlen(dst);
|
||||
if (size <= len + 1)
|
||||
return len + strlen(src);
|
||||
return len + av_strlcpy(dst + len, src, size - len);
|
||||
}
|
||||
|
||||
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
|
||||
{
|
||||
int len = strlen(dst);
|
||||
va_list vl;
|
||||
|
||||
va_start(vl, fmt);
|
||||
len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);
|
||||
va_end(vl);
|
||||
|
||||
return len;
|
||||
}
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AVSTRING_H
|
||||
#define FFMPEG_AVSTRING_H
|
||||
#ifndef AVUTIL_AVSTRING_H
|
||||
#define AVUTIL_AVSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
*
|
||||
* @param str input string
|
||||
* @param pfx prefix to test
|
||||
* @param ptr updated after the prefix in str in there is a match
|
||||
* @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);
|
||||
|
@ -41,14 +41,14 @@ int av_strstart(const char *str, const char *pfx, const char **ptr);
|
|||
*
|
||||
* @param str input string
|
||||
* @param pfx prefix to test
|
||||
* @param ptr updated after the prefix in str in there is a match
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Copy the string src to dst, but no more than size - 1 bytes, and
|
||||
* null terminate dst.
|
||||
* null-terminate dst.
|
||||
*
|
||||
* This function is the same as BSD strlcpy().
|
||||
*
|
||||
|
@ -61,7 +61,7 @@ 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.
|
||||
* no more than size - 1 bytes, and null-terminate dst.
|
||||
*
|
||||
* This function is similar to BSD strlcat(), but differs when
|
||||
* size <= strlen(dst).
|
||||
|
@ -87,4 +87,4 @@ size_t av_strlcat(char *dst, const char *src, size_t size);
|
|||
*/
|
||||
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
|
||||
|
||||
#endif /* FFMPEG_AVSTRING_H */
|
||||
#endif /* AVUTIL_AVSTRING_H */
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_AVUTIL_H
|
||||
#define FFMPEG_AVUTIL_H
|
||||
#ifndef AVUTIL_AVUTIL_H
|
||||
#define AVUTIL_AVUTIL_H
|
||||
|
||||
/**
|
||||
* @file avutil.h
|
||||
* @file libavutil/avutil.h
|
||||
* external API header
|
||||
*/
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
|||
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
|
||||
|
||||
#define LIBAVUTIL_VERSION_MAJOR 49
|
||||
#define LIBAVUTIL_VERSION_MINOR 10
|
||||
#define LIBAVUTIL_VERSION_MINOR 15
|
||||
#define LIBAVUTIL_VERSION_MICRO 0
|
||||
|
||||
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
|
||||
|
@ -58,90 +58,6 @@ unsigned avutil_version(void);
|
|||
#include "rational.h"
|
||||
#include "intfloat_readwrite.h"
|
||||
#include "log.h"
|
||||
#include "pixfmt.h"
|
||||
|
||||
/**
|
||||
* Pixel format. Notes:
|
||||
*
|
||||
* PIX_FMT_RGB32 is handled in an endian-specific manner. A RGBA
|
||||
* color is put together as:
|
||||
* (A << 24) | (R << 16) | (G << 8) | B
|
||||
* This is stored as BGRA on little endian CPU architectures and ARGB on
|
||||
* big endian CPUs.
|
||||
*
|
||||
* When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
|
||||
* image data is stored in AVFrame.data[0]. The palette is transported in
|
||||
* AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
|
||||
* formatted the same as in PIX_FMT_RGB32 described above (i.e., it is
|
||||
* also endian-specific). Note also that the individual RGB palette
|
||||
* components stored in AVFrame.data[1] should be in the range 0..255.
|
||||
* This is important as many custom PAL8 video codecs that were designed
|
||||
* to run on the IBM VGA graphics adapter use 6-bit palette components.
|
||||
*/
|
||||
enum PixelFormat {
|
||||
PIX_FMT_NONE= -1,
|
||||
PIX_FMT_YUV420P, ///< Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
|
||||
PIX_FMT_YUYV422, ///< Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
|
||||
PIX_FMT_RGB24, ///< Packed RGB 8:8:8, 24bpp, RGBRGB...
|
||||
PIX_FMT_BGR24, ///< Packed RGB 8:8:8, 24bpp, BGRBGR...
|
||||
PIX_FMT_YUV422P, ///< Planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
|
||||
PIX_FMT_YUV444P, ///< Planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
|
||||
PIX_FMT_RGB32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness
|
||||
PIX_FMT_YUV410P, ///< Planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
|
||||
PIX_FMT_YUV411P, ///< Planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
|
||||
PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness
|
||||
PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0
|
||||
PIX_FMT_GRAY8, ///< Y , 8bpp
|
||||
PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black
|
||||
PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white
|
||||
PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
|
||||
PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg)
|
||||
PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg)
|
||||
PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4, 24bpp, full scale (jpeg)
|
||||
PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
|
||||
PIX_FMT_XVMC_MPEG2_IDCT,
|
||||
PIX_FMT_UYVY422, ///< Packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
|
||||
PIX_FMT_UYYVYY411, ///< Packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
|
||||
PIX_FMT_BGR32, ///< Packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in cpu endianness
|
||||
PIX_FMT_BGR565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in cpu endianness
|
||||
PIX_FMT_BGR555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in cpu endianness most significant bit to 1
|
||||
PIX_FMT_BGR8, ///< Packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
|
||||
PIX_FMT_BGR4, ///< Packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_BGR4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_RGB8, ///< Packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_RGB4, ///< Packed RGB 1:2:1, 4bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_RGB4_BYTE, ///< Packed RGB 1:2:1, 8bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_NV12, ///< Planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 for UV
|
||||
PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
|
||||
|
||||
PIX_FMT_RGB32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in cpu endianness
|
||||
PIX_FMT_BGR32_1, ///< Packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in cpu endianness
|
||||
|
||||
PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian
|
||||
PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian
|
||||
PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
|
||||
PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg)
|
||||
PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
|
||||
PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
|
||||
};
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PIX_FMT_RGBA PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_BGRA PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ARGB PIX_FMT_RGB32
|
||||
#define PIX_FMT_ABGR PIX_FMT_BGR32
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE
|
||||
#else
|
||||
#define PIX_FMT_RGBA PIX_FMT_BGR32
|
||||
#define PIX_FMT_BGRA PIX_FMT_RGB32
|
||||
#define PIX_FMT_ARGB PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ABGR PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE
|
||||
#endif
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT < (50<<16)
|
||||
#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411
|
||||
#define PIX_FMT_RGBA32 PIX_FMT_RGB32
|
||||
#define PIX_FMT_YUV422 PIX_FMT_YUYV422
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_AVUTIL_H */
|
||||
#endif /* AVUTIL_AVUTIL_H */
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
* Base64.c
|
||||
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -20,8 +19,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file base64.c
|
||||
* @brief Base64 Encode/Decode
|
||||
* @file libavutil/base64.c
|
||||
* @brief Base64 encode/decode
|
||||
* @author Ryan Martell <rdm4@martellventures.com> (with lots of Michael)
|
||||
*/
|
||||
|
||||
|
@ -43,7 +42,7 @@ static const uint8_t map2[] =
|
|||
0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
|
||||
};
|
||||
|
||||
int av_base64_decode(uint8_t * out, const char *in, int out_length)
|
||||
int av_base64_decode(uint8_t *out, const char *in, int out_size)
|
||||
{
|
||||
int i, v;
|
||||
uint8_t *dst = out;
|
||||
|
@ -51,11 +50,11 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length)
|
|||
v = 0;
|
||||
for (i = 0; in[i] && in[i] != '='; i++) {
|
||||
unsigned int index= in[i]-43;
|
||||
if (index>=(sizeof(map2)/sizeof(map2[0])) || map2[index] == 0xff)
|
||||
if (index>=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff)
|
||||
return -1;
|
||||
v = (v << 6) + map2[index];
|
||||
if (i & 3) {
|
||||
if (dst - out < out_length) {
|
||||
if (dst - out < out_size) {
|
||||
*dst++ = v >> (6 - 2 * (i & 3));
|
||||
}
|
||||
}
|
||||
|
@ -65,26 +64,26 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length)
|
|||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* b64_encode: stolen from VLC's http.c
|
||||
* simplified by michael
|
||||
* fixed edge cases and made it work from data (vs. strings) by ryan.
|
||||
* b64_encode: Stolen from VLC's http.c.
|
||||
* Simplified by Michael.
|
||||
* Fixed edge cases and made it work from data (vs. strings) by Ryan.
|
||||
*****************************************************************************/
|
||||
|
||||
char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len)
|
||||
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 = len;
|
||||
int bytes_remaining = in_size;
|
||||
|
||||
if (len >= UINT_MAX / 4 ||
|
||||
buf_len < len * 4 / 3 + 12)
|
||||
if (in_size >= UINT_MAX / 4 ||
|
||||
out_size < (in_size+2) / 3 * 4 + 1)
|
||||
return NULL;
|
||||
ret = dst = buf;
|
||||
ret = dst = out;
|
||||
while (bytes_remaining) {
|
||||
i_bits = (i_bits << 8) + *src++;
|
||||
i_bits = (i_bits << 8) + *in++;
|
||||
bytes_remaining--;
|
||||
i_shift += 8;
|
||||
|
||||
|
@ -100,129 +99,65 @@ char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// #define TEST_BASE64
|
||||
#ifdef TEST
|
||||
|
||||
#ifdef TEST_BASE64
|
||||
#include "avutil.h"
|
||||
#undef printf
|
||||
|
||||
int b64test()
|
||||
#define MAX_DATA_SIZE 1024
|
||||
#define MAX_ENCODED_SIZE 2048
|
||||
|
||||
int test_encode_decode(const uint8_t *data, unsigned int data_size, const char *encoded_ref)
|
||||
{
|
||||
int numerr = 0;
|
||||
int len;
|
||||
int numtest = 1;
|
||||
uint8_t decode[1000];
|
||||
struct test {
|
||||
void *data;
|
||||
int len;
|
||||
const char *result;
|
||||
} *t, tests[] = {
|
||||
{
|
||||
"", 0, ""}, {
|
||||
"1", 1, "MQ=="}, {
|
||||
"22", 2, "MjI="}, {
|
||||
"333", 3, "MzMz"}, {
|
||||
"4444", 4, "NDQ0NA=="}, {
|
||||
"55555", 5, "NTU1NTU="}, {
|
||||
"abc:def", 7, "YWJjOmRlZg=="}, {
|
||||
NULL}
|
||||
};
|
||||
for (t = tests; t->data; t++) {
|
||||
char *str;
|
||||
char encoded[MAX_ENCODED_SIZE];
|
||||
uint8_t data2[MAX_DATA_SIZE];
|
||||
int data2_size, max_data2_size = MAX_DATA_SIZE;
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Encoding %s...\n", (char *) t->data);
|
||||
str = av_base64_encode(t->data, t->len);
|
||||
if (str) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Encoded to %s...\n", str);
|
||||
if (strcmp(str, t->result) != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: %s != %s\n",
|
||||
numtest, str, t->result);
|
||||
numerr++;
|
||||
}
|
||||
av_free(str);
|
||||
}
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Done encoding, about to decode...\n");
|
||||
len = av_base64_decode(decode, t->result, sizeof(decode));
|
||||
if (len != t->len) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: len %d != %d\n",
|
||||
numtest, len, t->len);
|
||||
numerr++;
|
||||
} else if (memcmp(decode, t->data, t->len) != 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "failed test %d: data\n", numtest);
|
||||
numerr++;
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR, "Decoded to %s\n",
|
||||
(char *) t->data);
|
||||
}
|
||||
numtest++;
|
||||
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;
|
||||
}
|
||||
|
||||
#undef srand
|
||||
#undef rand
|
||||
|
||||
{
|
||||
int test_count;
|
||||
srand(123141); // time(NULL));
|
||||
for (test_count = 0; test_count < 100; test_count++) {
|
||||
int size = rand() % 1024;
|
||||
int ii;
|
||||
uint8_t *data;
|
||||
char *encoded_result;
|
||||
|
||||
av_log(NULL, AV_LOG_ERROR, "Test %d: Size %d bytes...",
|
||||
test_count, size);
|
||||
data = (uint8_t *) av_malloc(size);
|
||||
for (ii = 0; ii < size; ii++) {
|
||||
data[ii] = rand() % 255;
|
||||
}
|
||||
|
||||
encoded_result = av_base64_encode(data, size);
|
||||
if (encoded_result) {
|
||||
int decode_buffer_size = size + 10; // try without 10 as well
|
||||
uint8_t *decode_buffer = av_malloc(decode_buffer_size);
|
||||
if (decode_buffer) {
|
||||
int decoded_size =
|
||||
av_base64_decode(decode_buffer, encoded_result,
|
||||
decode_buffer_size);
|
||||
|
||||
if (decoded_size != size) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Decoded/Encoded size mismatch (%d != %d)\n",
|
||||
decoded_size, size);
|
||||
} else {
|
||||
if (memcmp(decode_buffer, data, decoded_size) == 0) {
|
||||
av_log(NULL, AV_LOG_ERROR, "Passed!\n");
|
||||
} else {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"Failed (Data differs)!\n");
|
||||
}
|
||||
}
|
||||
av_free(decode_buffer);
|
||||
}
|
||||
|
||||
av_free(encoded_result);
|
||||
}
|
||||
}
|
||||
if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) {
|
||||
printf("Failed: cannot decode the encoded string\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;
|
||||
}
|
||||
|
||||
// these are invalid strings, that it currently decodes (which it probably shouldn't?)
|
||||
{
|
||||
uint8_t str[32];
|
||||
if (av_base64_decode(str, "M=M=", sizeof(str)) != -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"failed test %d: successful decode of `M=M='\n",
|
||||
numtest++);
|
||||
numerr++;
|
||||
}
|
||||
if (av_base64_decode(str, "MQ===", sizeof(str)) != -1) {
|
||||
av_log(NULL, AV_LOG_ERROR,
|
||||
"failed test %d: successful decode of `MQ==='\n",
|
||||
numtest++);
|
||||
numerr++;
|
||||
}
|
||||
}
|
||||
|
||||
return numerr;
|
||||
printf("Passed!\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
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=="},
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
return error_count;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
* Base64.c
|
||||
* Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -19,22 +18,32 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_BASE64_H
|
||||
#define FFMPEG_BASE64_H
|
||||
#ifndef AVUTIL_BASE64_H
|
||||
#define AVUTIL_BASE64_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* decodes base64
|
||||
* param order as strncpy()
|
||||
* Decodes the base64-encoded string in \p in and puts the decoded
|
||||
* data in \p out.
|
||||
*
|
||||
* @param out_size size in bytes of the \p out buffer, it should be at
|
||||
* least 3/4 of the length of \p in
|
||||
* @return the number of bytes written, or a negative value in case of
|
||||
* error
|
||||
*/
|
||||
int av_base64_decode(uint8_t * out, const char *in, int out_length);
|
||||
int av_base64_decode(uint8_t *out, const char *in, int out_size);
|
||||
|
||||
/**
|
||||
* encodes base64
|
||||
* @param src data, not a string
|
||||
* @param buf output string
|
||||
* Encodes in base64 the data in \p in and puts the resulting string
|
||||
* in \p out.
|
||||
*
|
||||
* @param out_size size in bytes of the \p out string, it should be at
|
||||
* least ((\p in_size + 2) / 3) * 4 + 1
|
||||
* @param in_size size in bytes of the \p in buffer
|
||||
* @return the string containing the encoded data, or NULL in case of
|
||||
* error
|
||||
*/
|
||||
char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len);
|
||||
char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
|
||||
|
||||
#endif /* FFMPEG_BASE64_H */
|
||||
#endif /* AVUTIL_BASE64_H */
|
||||
|
|
|
@ -19,83 +19,51 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file bswap.h
|
||||
* @file libavutil/bswap.h
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_BSWAP_H
|
||||
#define FFMPEG_BSWAP_H
|
||||
#ifndef AVUTIL_BSWAP_H
|
||||
#define AVUTIL_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#ifdef HAVE_BYTESWAP_H
|
||||
#include <byteswap.h>
|
||||
#else
|
||||
#if ARCH_ARM
|
||||
# include "arm/bswap.h"
|
||||
#elif ARCH_BFIN
|
||||
# include "bfin/bswap.h"
|
||||
#elif ARCH_SH4
|
||||
# include "sh4/bswap.h"
|
||||
#elif ARCH_X86
|
||||
# include "x86/bswap.h"
|
||||
#endif
|
||||
|
||||
#ifndef bswap_16
|
||||
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
#if defined(ARCH_X86)
|
||||
asm("rorw $8, %0" : "+r"(x));
|
||||
#elif defined(ARCH_SH4)
|
||||
asm("swap.b %0,%0" : "=r"(x) : "0"(x));
|
||||
#elif defined(HAVE_ARMV6)
|
||||
asm("rev16 %0, %0" : "+r"(x));
|
||||
#else
|
||||
x= (x>>8) | (x<<8);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef bswap_32
|
||||
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
#if defined(ARCH_X86)
|
||||
#ifdef HAVE_BSWAP
|
||||
asm("bswap %0" : "+r" (x));
|
||||
#else
|
||||
asm("rorw $8, %w0 \n\t"
|
||||
"rorl $16, %0 \n\t"
|
||||
"rorw $8, %w0"
|
||||
: "+r"(x));
|
||||
#endif
|
||||
#elif defined(ARCH_SH4)
|
||||
asm("swap.b %0,%0\n"
|
||||
"swap.w %0,%0\n"
|
||||
"swap.b %0,%0\n"
|
||||
: "=r"(x) : "0"(x));
|
||||
#elif defined(HAVE_ARMV6)
|
||||
asm("rev %0, %0" : "+r"(x));
|
||||
#elif defined(ARCH_ARMV4L)
|
||||
uint32_t t;
|
||||
asm ("eor %1, %0, %0, ror #16 \n\t"
|
||||
"bic %1, %1, #0xFF0000 \n\t"
|
||||
"mov %0, %0, ror #8 \n\t"
|
||||
"eor %0, %0, %1, lsr #8 \n\t"
|
||||
: "+r"(x), "+r"(t));
|
||||
#elif defined(ARCH_BFIN)
|
||||
unsigned tmp;
|
||||
asm("%1 = %0 >> 8 (V); \n\t"
|
||||
"%0 = %0 << 8 (V); \n\t"
|
||||
"%0 = %0 | %1; \n\t"
|
||||
"%0 = PACK(%0.L, %0.H); \n\t"
|
||||
: "+d"(x), "=&d"(tmp));
|
||||
#else
|
||||
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
||||
x= (x>>16) | (x<<16);
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef bswap_64
|
||||
static inline uint64_t av_const bswap_64(uint64_t x)
|
||||
{
|
||||
#if 0
|
||||
x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
|
||||
x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
|
||||
return (x>>32) | (x<<32);
|
||||
#elif defined(ARCH_X86_64)
|
||||
asm("bswap %0": "=r" (x) : "0" (x));
|
||||
return x;
|
||||
#else
|
||||
union {
|
||||
uint64_t ll;
|
||||
|
@ -107,11 +75,10 @@ static inline uint64_t av_const bswap_64(uint64_t x)
|
|||
return r.ll;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !HAVE_BYTESWAP_H */
|
||||
|
||||
// be2me ... BigEndian to MachineEndian
|
||||
// le2me ... LittleEndian to MachineEndian
|
||||
// be2me ... big-endian to machine-endian
|
||||
// le2me ... little-endian to machine-endian
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define be2me_16(x) (x)
|
||||
|
@ -129,4 +96,4 @@ static inline uint64_t av_const bswap_64(uint64_t x)
|
|||
#define le2me_64(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_BSWAP_H */
|
||||
#endif /* AVUTIL_BSWAP_H */
|
||||
|
|
|
@ -19,30 +19,30 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file common.h
|
||||
* @file libavutil/common.h
|
||||
* common internal and external API header
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_COMMON_H
|
||||
#define FFMPEG_COMMON_H
|
||||
#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>
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
/* only include the following when compiling package */
|
||||
# include "config.h"
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <ctype.h>
|
||||
# include <limits.h>
|
||||
# include <errno.h>
|
||||
# include <math.h>
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
#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 defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_always_inline __attribute__((always_inline)) inline
|
||||
#else
|
||||
# define av_always_inline inline
|
||||
|
@ -50,7 +50,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef av_noinline
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_noinline __attribute__((noinline))
|
||||
#else
|
||||
# define av_noinline
|
||||
|
@ -58,7 +58,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef av_pure
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define av_pure __attribute__((pure))
|
||||
#else
|
||||
# define av_pure
|
||||
|
@ -66,7 +66,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef av_const
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 5)
|
||||
#if AV_GCC_VERSION_AT_LEAST(2,6)
|
||||
# define av_const __attribute__((const))
|
||||
#else
|
||||
# define av_const
|
||||
|
@ -74,19 +74,23 @@
|
|||
#endif
|
||||
|
||||
#ifndef av_cold
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
|
||||
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
# define av_cold __attribute__((cold))
|
||||
#else
|
||||
# define av_cold
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "internal.h"
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
#ifndef av_flatten
|
||||
#if AV_GCC_VERSION_AT_LEAST(4,1)
|
||||
# define av_flatten __attribute__((flatten))
|
||||
#else
|
||||
# define av_flatten
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef attribute_deprecated
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define attribute_deprecated __attribute__((deprecated))
|
||||
#else
|
||||
# define attribute_deprecated
|
||||
|
@ -101,9 +105,15 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
#ifndef av_uninit
|
||||
#if defined(__GNUC__) && !defined(__ICC)
|
||||
# define av_uninit(x) x=x
|
||||
#else
|
||||
# define av_uninit(x) x
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//rounded divison & shift
|
||||
//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))
|
||||
|
@ -116,6 +126,7 @@
|
|||
#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]))
|
||||
|
||||
/* misc math functions */
|
||||
extern const uint8_t ff_log2_tab[256];
|
||||
|
@ -148,49 +159,8 @@ static inline av_const int av_log2_16bit(unsigned int v)
|
|||
return n;
|
||||
}
|
||||
|
||||
/* median of 3 */
|
||||
static inline av_const int mid_pred(int a, int b, int c)
|
||||
{
|
||||
#ifdef HAVE_CMOV
|
||||
int i=b;
|
||||
asm volatile(
|
||||
"cmp %2, %1 \n\t"
|
||||
"cmovg %1, %0 \n\t"
|
||||
"cmovg %2, %1 \n\t"
|
||||
"cmp %3, %1 \n\t"
|
||||
"cmovl %3, %1 \n\t"
|
||||
"cmp %1, %0 \n\t"
|
||||
"cmovg %1, %0 \n\t"
|
||||
:"+&r"(i), "+&r"(a)
|
||||
:"r"(b), "r"(c)
|
||||
);
|
||||
return i;
|
||||
#elif 0
|
||||
int t= (a-b)&((a-b)>>31);
|
||||
a-=t;
|
||||
b+=t;
|
||||
b-= (b-c)&((b-c)>>31);
|
||||
b+= (a-b)&((a-b)>>31);
|
||||
|
||||
return b;
|
||||
#else
|
||||
if(a>b){
|
||||
if(c>b){
|
||||
if(c>a) b=a;
|
||||
else b=c;
|
||||
}
|
||||
}else{
|
||||
if(b>c){
|
||||
if(c>a) b=c;
|
||||
else b=a;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the amin-amax range
|
||||
* Clips 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
|
||||
|
@ -204,7 +174,7 @@ static inline av_const int av_clip(int a, int amin, int amax)
|
|||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the 0-255 range
|
||||
* Clips a signed integer value into the 0-255 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
|
@ -215,7 +185,7 @@ static inline av_const uint8_t av_clip_uint8(int a)
|
|||
}
|
||||
|
||||
/**
|
||||
* clip a signed integer value into the -32768,32767 range
|
||||
* Clips a signed integer value into the -32768,32767 range.
|
||||
* @param a value to clip
|
||||
* @return clipped value
|
||||
*/
|
||||
|
@ -226,7 +196,7 @@ static inline av_const int16_t av_clip_int16(int a)
|
|||
}
|
||||
|
||||
/**
|
||||
* clip a float value into the amin-amax range
|
||||
* Clips 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
|
||||
|
@ -239,26 +209,12 @@ static inline av_const float av_clipf(float a, float amin, float amax)
|
|||
else return a;
|
||||
}
|
||||
|
||||
/* math */
|
||||
int64_t av_const ff_gcd(int64_t a, int64_t b);
|
||||
|
||||
/**
|
||||
* converts fourcc string to int
|
||||
*/
|
||||
static inline av_pure int ff_get_fourcc(const char *s){
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
assert( strlen(s)==4 );
|
||||
#endif
|
||||
|
||||
return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
|
||||
}
|
||||
|
||||
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
|
||||
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
|
||||
|
||||
/*!
|
||||
* \def GET_UTF8(val, GET_BYTE, ERROR)
|
||||
* converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
|
||||
* Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
|
||||
* \param val is the output and should be of type uint32_t. It holds the converted
|
||||
* UCS-4 character and should be a left value.
|
||||
* \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
|
||||
|
@ -286,19 +242,19 @@ static inline av_pure int ff_get_fourcc(const char *s){
|
|||
|
||||
/*!
|
||||
* \def PUT_UTF8(val, tmp, PUT_BYTE)
|
||||
* converts a 32-bit unicode character to its UTF-8 encoded form (up to 4 bytes long).
|
||||
* \param val is an input only argument and should be of type uint32_t. It holds
|
||||
* a ucs4 encoded unicode character that is to be converted to UTF-8. If
|
||||
* val is given as a function it's executed only once.
|
||||
* Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
|
||||
* \param val is an input-only argument and should be of type uint32_t. It holds
|
||||
* a 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
|
||||
* outputted by PUT_BYTE.
|
||||
* 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.
|
||||
* Unicode character.
|
||||
*/
|
||||
#define PUT_UTF8(val, tmp, PUT_BYTE)\
|
||||
{\
|
||||
|
@ -320,96 +276,11 @@ static inline av_pure int ff_get_fourcc(const char *s){
|
|||
}\
|
||||
}
|
||||
|
||||
#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN)
|
||||
#define AV_READ_TIME read_time
|
||||
#if defined(ARCH_X86_64)
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint64_t a, d;
|
||||
asm volatile("rdtsc\n\t"
|
||||
: "=a" (a), "=d" (d));
|
||||
return (d << 32) | (a & 0xffffffff);
|
||||
}
|
||||
#elif defined(ARCH_X86_32)
|
||||
static inline long long read_time(void)
|
||||
{
|
||||
long long l;
|
||||
asm volatile("rdtsc\n\t"
|
||||
: "=A" (l));
|
||||
return l;
|
||||
}
|
||||
#elif ARCH_BFIN
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned lo;
|
||||
unsigned hi;
|
||||
} p;
|
||||
unsigned long long c;
|
||||
} t;
|
||||
asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
|
||||
return t.c;
|
||||
}
|
||||
#else //FIXME check ppc64
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint32_t tbu, tbl, temp;
|
||||
#include "mem.h"
|
||||
|
||||
/* from section 2.2.1 of the 32-bit PowerPC PEM */
|
||||
asm volatile(
|
||||
"1:\n"
|
||||
"mftbu %2\n"
|
||||
"mftb %0\n"
|
||||
"mftbu %1\n"
|
||||
"cmpw %2,%1\n"
|
||||
"bne 1b\n"
|
||||
: "=r"(tbl), "=r"(tbu), "=r"(temp)
|
||||
:
|
||||
: "cc");
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
# include "libavcodec/config.h"
|
||||
# include "libavutil/internal.h"
|
||||
#endif /* HAVE_AV_CONFIG_H */
|
||||
|
||||
return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
|
||||
}
|
||||
#endif
|
||||
#elif defined(HAVE_GETHRTIME)
|
||||
#define AV_READ_TIME gethrtime
|
||||
#endif
|
||||
|
||||
#ifdef AV_READ_TIME
|
||||
#define START_TIMER \
|
||||
uint64_t tend;\
|
||||
uint64_t tstart= AV_READ_TIME();\
|
||||
|
||||
#define STOP_TIMER(id) \
|
||||
tend= AV_READ_TIME();\
|
||||
{\
|
||||
static uint64_t tsum=0;\
|
||||
static int tcount=0;\
|
||||
static int tskip_count=0;\
|
||||
if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\
|
||||
tsum+= tend - tstart;\
|
||||
tcount++;\
|
||||
}else\
|
||||
tskip_count++;\
|
||||
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
|
||||
av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
|
||||
tsum*10/tcount, id, tcount, tskip_count);\
|
||||
}\
|
||||
}
|
||||
#else
|
||||
#define START_TIMER
|
||||
#define STOP_TIMER(id) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns NULL if CONFIG_SMALL is defined otherwise the argument
|
||||
* without modifications, used to disable the definition of strings
|
||||
* (for example AVCodec long_names).
|
||||
*/
|
||||
#ifdef CONFIG_SMALL
|
||||
# define NULL_IF_CONFIG_SMALL(x) NULL
|
||||
#else
|
||||
# define NULL_IF_CONFIG_SMALL(x) x
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_COMMON_H */
|
||||
#endif /* AVUTIL_COMMON_H */
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "bswap.h"
|
||||
#include "crc.h"
|
||||
|
||||
#ifdef CONFIG_HARDCODED_TABLES
|
||||
#if CONFIG_HARDCODED_TABLES
|
||||
#include "crc_data.h"
|
||||
#else
|
||||
static struct {
|
||||
|
@ -39,12 +40,13 @@ static AVCRC av_crc_table[AV_CRC_MAX][257];
|
|||
#endif
|
||||
|
||||
/**
|
||||
* Inits a crc table.
|
||||
* @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
|
||||
* Initializes a CRC table.
|
||||
* @param ctx must be an array of size sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
|
||||
* @param cts_size size of ctx in bytes
|
||||
* @param le if 1, lowest bit represents coefficient for highest exponent
|
||||
* of corresponding polynomial (both for poly and actual CRC).
|
||||
* If 0, you must swap the crc parameter and the result of av_crc
|
||||
* @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):
|
||||
* bswap_32(crc << (32-bits))
|
||||
|
@ -74,7 +76,7 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
|
|||
}
|
||||
}
|
||||
ctx[256]=1;
|
||||
#ifndef CONFIG_SMALL
|
||||
#if !CONFIG_SMALL
|
||||
if(ctx_size >= sizeof(AVCRC)*1024)
|
||||
for (i = 0; i < 256; i++)
|
||||
for(j=0; j<3; j++)
|
||||
|
@ -85,13 +87,13 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){
|
|||
}
|
||||
|
||||
/**
|
||||
* Get an initialized standard CRC table.
|
||||
* Gets an initialized standard CRC table.
|
||||
* @param crc_id ID of a standard CRC
|
||||
* @return a pointer to the CRC table or NULL on failure
|
||||
*/
|
||||
const AVCRC *av_crc_get_table(AVCRCId crc_id){
|
||||
#ifndef CONFIG_HARDCODED_TABLES
|
||||
if (!av_crc_table[crc_id][sizeof(av_crc_table[crc_id])/sizeof(av_crc_table[crc_id][0])-1])
|
||||
#if !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,
|
||||
|
@ -103,8 +105,8 @@ 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.
|
||||
* Calculates 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
|
||||
|
@ -112,7 +114,7 @@ const AVCRC *av_crc_get_table(AVCRCId 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;
|
||||
|
||||
#ifndef CONFIG_SMALL
|
||||
#if !CONFIG_SMALL
|
||||
if(!ctx[256])
|
||||
while(buffer<end-3){
|
||||
crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_CRC_H
|
||||
#define FFMPEG_CRC_H
|
||||
#ifndef AVUTIL_CRC_H
|
||||
#define AVUTIL_CRC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
@ -33,12 +33,12 @@ typedef enum {
|
|||
AV_CRC_16_CCITT,
|
||||
AV_CRC_32_IEEE,
|
||||
AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */
|
||||
AV_CRC_MAX, /*< not part of public API! don't use outside lavu */
|
||||
AV_CRC_MAX, /*< Not part of public API! Do not use outside libavutil. */
|
||||
}AVCRCId;
|
||||
|
||||
int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
|
||||
const AVCRC *av_crc_get_table(AVCRCId crc_id);
|
||||
uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length) av_pure;
|
||||
|
||||
#endif /* FFMPEG_CRC_H */
|
||||
#endif /* AVUTIL_CRC_H */
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_CRC_DATA_H
|
||||
#define FFMPEG_CRC_DATA_H
|
||||
#ifndef AVUTIL_CRC_DATA_H
|
||||
#define AVUTIL_CRC_DATA_H
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
|
@ -210,4 +210,4 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
|
|||
},
|
||||
};
|
||||
|
||||
#endif /* FFMPEG_CRC_DATA_H */
|
||||
#endif /* AVUTIL_CRC_DATA_H */
|
||||
|
|
|
@ -19,9 +19,13 @@
|
|||
* 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),
|
||||
|
@ -74,7 +78,7 @@ static const uint8_t PC2_shuffle[] = {
|
|||
};
|
||||
#undef T
|
||||
|
||||
#ifdef CONFIG_SMALL
|
||||
#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,
|
||||
|
@ -218,7 +222,7 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
|
|||
// apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits
|
||||
for (i = 7; i >= 0; i--) {
|
||||
uint8_t tmp = (r ^ k) & 0x3f;
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
uint8_t v = S_boxes[i][tmp >> 1];
|
||||
if (tmp & 1) v >>= 4;
|
||||
out = (out >> 4) | (v << 28);
|
||||
|
@ -229,7 +233,7 @@ static uint32_t f_func(uint32_t r, uint64_t k) {
|
|||
r = (r >> 4) | (r << 28);
|
||||
k >>= 6;
|
||||
}
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
out = shuffle(out, P_shuffle, sizeof(P_shuffle));
|
||||
#endif
|
||||
return out;
|
||||
|
@ -249,9 +253,8 @@ static uint64_t key_shift_left(uint64_t CDn) {
|
|||
return CDn;
|
||||
}
|
||||
|
||||
uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) {
|
||||
static void gen_roundkeys(uint64_t K[16], uint64_t key) {
|
||||
int i;
|
||||
uint64_t K[16];
|
||||
// discard parity bits from key and shuffle it into C and D parts
|
||||
uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle));
|
||||
// generate round keys
|
||||
|
@ -261,6 +264,10 @@ uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) {
|
|||
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
|
||||
|
@ -277,6 +284,55 @@ uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) {
|
|||
return in;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) {
|
||||
uint64_t K[16];
|
||||
gen_roundkeys(K, key);
|
||||
return des_encdec(in, K, decrypt);
|
||||
}
|
||||
#endif
|
||||
|
||||
int av_des_init(AVDES *d, const uint8_t *key, int key_bits, 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;
|
||||
}
|
||||
|
||||
void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
|
||||
uint64_t iv_val = iv ? be2me_64(*(uint64_t *)iv) : 0;
|
||||
while (count-- > 0) {
|
||||
uint64_t dst_val;
|
||||
uint64_t src_val = src ? be2me_64(*(const uint64_t *)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;
|
||||
}
|
||||
*(uint64_t *)dst = be2me_64(dst_val);
|
||||
src += 8;
|
||||
dst += 8;
|
||||
}
|
||||
if (iv)
|
||||
*(uint64_t *)iv = be2me_64(iv_val);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#undef printf
|
||||
#undef rand
|
||||
|
@ -290,25 +346,78 @@ static uint64_t rand64(void) {
|
|||
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
|
||||
};
|
||||
|
||||
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) {
|
||||
int i, j;
|
||||
AVDES d;
|
||||
int i;
|
||||
#ifdef GENTABLES
|
||||
int j;
|
||||
#endif
|
||||
struct timeval tv;
|
||||
uint64_t key;
|
||||
uint64_t key[3];
|
||||
uint64_t data;
|
||||
uint64_t ct;
|
||||
gettimeofday(&tv, NULL);
|
||||
srand(tv.tv_sec * 1000 * 1000 + tv.tv_usec);
|
||||
key = 0x123456789abcdef0ULL;
|
||||
data = 0xfedcba9876543210ULL;
|
||||
if (ff_des_encdec(data, key, 0) != 0x4ab65b3d4b061518ULL) {
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
key[0] = AV_RB64(test_key);
|
||||
data = AV_RB64(plain);
|
||||
if (ff_des_encdec(data, key[0], 0) != AV_RB64(crypt)) {
|
||||
printf("Test 1 failed\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
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 < 1000000; i++) {
|
||||
key = rand64();
|
||||
key[0] = rand64(); key[1] = rand64(); key[2] = rand64();
|
||||
data = rand64();
|
||||
ct = ff_des_encdec(data, key, 0);
|
||||
if (ff_des_encdec(ct, key, 1) != data) {
|
||||
av_des_init(&d, key, 192, 0);
|
||||
av_des_crypt(&d, &ct, &data, 1, NULL, 0);
|
||||
av_des_init(&d, key, 192, 1);
|
||||
av_des_crypt(&d, &ct, &ct, 1, NULL, 1);
|
||||
if (ct != data) {
|
||||
printf("Test 2 failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -19,22 +19,34 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_DES_H
|
||||
#define FFMPEG_DES_H
|
||||
#ifndef AVUTIL_DES_H
|
||||
#define AVUTIL_DES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
struct AVDES {
|
||||
uint64_t round_keys[3][16];
|
||||
int triple_des;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief en- or decrypt an 64-bit block of data with DES
|
||||
* \param in data to process.
|
||||
* \param key key to use for en-/decryption.
|
||||
* \param decrypt if 0 encrypt, else decrypt.
|
||||
* \return processed data
|
||||
* \brief Initializes an AVDES context.
|
||||
*
|
||||
* If your input data is in 8-bit blocks treat it as big-endian
|
||||
* (use e.g. AV_RB64 and AV_WB64).
|
||||
* \param key_bits must be 64 or 192
|
||||
* \param decrypt 0 for encryption, 1 for decryption
|
||||
*/
|
||||
uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) av_const;
|
||||
int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
|
||||
|
||||
#endif /* FFMPEG_DES_H */
|
||||
/**
|
||||
* \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);
|
||||
|
||||
#endif /* AVUTIL_DES_H */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* A very simple circular buffer FIFO implementation
|
||||
* a very simple circular buffer FIFO implementation
|
||||
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
|
||||
* Copyright (c) 2006 Roman Shaposhnik
|
||||
*
|
||||
|
@ -74,10 +74,12 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
|
||||
{
|
||||
av_fifo_generic_write(f, (void *)buf, size, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int))
|
||||
{
|
||||
|
@ -115,7 +117,7 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** discard data from the fifo */
|
||||
/** Discard data from the FIFO. */
|
||||
void av_fifo_drain(AVFifoBuffer *f, int size)
|
||||
{
|
||||
f->rptr += size;
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file fifo.h
|
||||
* A very simple circular buffer FIFO implementation.
|
||||
* @file libavutil/fifo.h
|
||||
* a very simple circular buffer FIFO implementation
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_FIFO_H
|
||||
#define FFMPEG_FIFO_H
|
||||
#ifndef AVUTIL_FIFO_H
|
||||
#define AVUTIL_FIFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
|
||||
typedef struct AVFifoBuffer {
|
||||
|
@ -63,7 +64,7 @@ int av_fifo_size(AVFifoBuffer *f);
|
|||
int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
|
||||
|
||||
/**
|
||||
* Feeds data from an AVFifoBuffer to a user supplied callback.
|
||||
* Feeds data from an AVFifoBuffer to a user-supplied callback.
|
||||
* @param *f AVFifoBuffer to read from
|
||||
* @param buf_size number of bytes to read
|
||||
* @param *func generic read function
|
||||
|
@ -71,6 +72,7 @@ int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size);
|
|||
*/
|
||||
int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
/**
|
||||
* Writes data into an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to write to
|
||||
|
@ -78,18 +80,19 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void
|
|||
* @param size data size
|
||||
*/
|
||||
attribute_deprecated void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Feeds data from a user supplied callback to an AVFifoBuffer.
|
||||
* Feeds data from a user-supplied callback to an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to write to
|
||||
* @param *src data source
|
||||
* @param size number of bytes to write
|
||||
* @param *func generic write function. First parameter is src,
|
||||
* second is dest_buf, third is dest_buf_size.
|
||||
* @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.
|
||||
* @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));
|
||||
|
||||
|
@ -107,7 +110,7 @@ attribute_deprecated void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
|
|||
* Resizes an AVFifoBuffer.
|
||||
* @param *f AVFifoBuffer to resize
|
||||
* @param size new AVFifoBuffer size in bytes
|
||||
* @return <0 for failure >=0 otherwise
|
||||
* @return <0 for failure, >=0 otherwise
|
||||
*/
|
||||
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
|
||||
|
||||
|
@ -125,4 +128,4 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs)
|
|||
ptr -= f->end - f->buffer;
|
||||
return *ptr;
|
||||
}
|
||||
#endif /* FFMPEG_FIFO_H */
|
||||
#endif /* AVUTIL_FIFO_H */
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file integer.c
|
||||
* arbitrary precision integers.
|
||||
* @file libavutil/integer.c
|
||||
* arbitrary precision integers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
|
@ -110,8 +110,8 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){
|
|||
AVInteger quot_temp;
|
||||
if(!quot) quot = "_temp;
|
||||
|
||||
assert((int16_t)a[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b[AV_INTEGER_SIZE-1] >= 0);
|
||||
assert(av_log2(b)>=0);
|
||||
assert((int16_t)a.v[AV_INTEGER_SIZE-1] >= 0 && (int16_t)b.v[AV_INTEGER_SIZE-1] >= 0);
|
||||
assert(av_log2_i(b)>=0);
|
||||
|
||||
if(i > 0)
|
||||
b= av_shr_i(b, -i);
|
||||
|
|
|
@ -20,13 +20,13 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file integer.h
|
||||
* @file libavutil/integer.h
|
||||
* arbitrary precision integers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTEGER_H
|
||||
#define FFMPEG_INTEGER_H
|
||||
#ifndef AVUTIL_INTEGER_H
|
||||
#define AVUTIL_INTEGER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
@ -41,44 +41,46 @@ AVInteger av_add_i(AVInteger a, AVInteger b) av_const;
|
|||
AVInteger av_sub_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* returns the rounded down value of the logarithm of base 2 of the given AVInteger.
|
||||
* this is simply the index of the most significant bit which is 1. Or 0 of all bits are 0
|
||||
* Returns 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;
|
||||
|
||||
/**
|
||||
* returns 0 if a==b, 1 if a>b and -1 if a<b.
|
||||
* Returns 0 if a==b, 1 if a>b and -1 if a<b.
|
||||
*/
|
||||
int av_cmp_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* bitwise shift.
|
||||
* @param s the number of bits by which the value should be shifted right, may be negative for shifting left
|
||||
* bitwise shift
|
||||
* @param s the number of bits by which the value should be shifted right,
|
||||
may be negative for shifting left
|
||||
*/
|
||||
AVInteger av_shr_i(AVInteger a, int s) av_const;
|
||||
|
||||
/**
|
||||
* returns a % b.
|
||||
* @param quot a/b will be stored here
|
||||
* Returns a % b.
|
||||
* @param quot a/b will be stored here.
|
||||
*/
|
||||
AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b);
|
||||
|
||||
/**
|
||||
* returns a/b.
|
||||
* Returns a/b.
|
||||
*/
|
||||
AVInteger av_div_i(AVInteger a, AVInteger b) av_const;
|
||||
|
||||
/**
|
||||
* converts the given int64_t to an AVInteger.
|
||||
* Converts the given int64_t to an AVInteger.
|
||||
*/
|
||||
AVInteger av_int2i(int64_t a) av_const;
|
||||
|
||||
/**
|
||||
* converts the given AVInteger to an int64_t.
|
||||
* if the AVInteger is too large to fit into an int64_t,
|
||||
* then only the least significant 64bit will be used
|
||||
* Converts the given AVInteger to an int64_t.
|
||||
* If the AVInteger is too large to fit into an int64_t,
|
||||
* then only the least significant 64 bits will be used.
|
||||
*/
|
||||
int64_t av_i2int(AVInteger a) av_const;
|
||||
|
||||
#endif /* FFMPEG_INTEGER_H */
|
||||
#endif /* AVUTIL_INTEGER_H */
|
||||
|
|
|
@ -19,23 +19,28 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file internal.h
|
||||
* common internal api header.
|
||||
* @file libavutil/internal.h
|
||||
* common internal API header
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTERNAL_H
|
||||
#define FFMPEG_INTERNAL_H
|
||||
#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 "common.h"
|
||||
#include "mem.h"
|
||||
#include "timer.h"
|
||||
|
||||
#ifndef attribute_align_arg
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
|
||||
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2)
|
||||
# define attribute_align_arg __attribute__((force_align_arg_pointer))
|
||||
#else
|
||||
# define attribute_align_arg
|
||||
|
@ -43,7 +48,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef attribute_used
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
# define attribute_used __attribute__((used))
|
||||
#else
|
||||
# define attribute_used
|
||||
|
@ -83,27 +88,19 @@
|
|||
#endif
|
||||
|
||||
#ifndef INT_BIT
|
||||
# if INT_MAX != 2147483647
|
||||
# define INT_BIT 64
|
||||
# else
|
||||
# define INT_BIT 32
|
||||
# endif
|
||||
# define INT_BIT (CHAR_BIT * sizeof(int))
|
||||
#endif
|
||||
|
||||
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
|
||||
# define PIC
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "intreadwrite.h"
|
||||
#include "bswap.h"
|
||||
|
||||
#ifndef offsetof
|
||||
# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
|
||||
#endif
|
||||
|
||||
// Use rip-relative addressing if compiling PIC code on x86-64.
|
||||
#if defined(ARCH_X86_64) && defined(PIC)
|
||||
#if ARCH_X86_64 && defined(PIC)
|
||||
# define LOCAL_MANGLE(a) #a "(%%rip)"
|
||||
#else
|
||||
# define LOCAL_MANGLE(a) #a
|
||||
|
@ -126,39 +123,37 @@
|
|||
|
||||
extern const uint32_t ff_inverse[256];
|
||||
|
||||
#if defined(ARCH_X86)
|
||||
#if ARCH_X86
|
||||
# define FASTDIV(a,b) \
|
||||
({\
|
||||
int ret,dmy;\
|
||||
asm volatile(\
|
||||
__asm__ volatile(\
|
||||
"mull %3"\
|
||||
:"=d"(ret),"=a"(dmy)\
|
||||
:"1"(a),"g"(ff_inverse[b])\
|
||||
);\
|
||||
ret;\
|
||||
})
|
||||
#elif defined(HAVE_ARMV6)
|
||||
#elif HAVE_ARMV6
|
||||
static inline av_const int FASTDIV(int a, int b)
|
||||
{
|
||||
int r;
|
||||
asm volatile("cmp %2, #0 \n\t"
|
||||
"smmul %0, %1, %2 \n\t"
|
||||
"rsblt %0, %0, #0 \n\t"
|
||||
: "=r"(r) : "r"(a), "r"(ff_inverse[b]));
|
||||
int r, t;
|
||||
__asm__ volatile("cmp %3, #2 \n\t"
|
||||
"ldr %1, [%4, %3, lsl #2] \n\t"
|
||||
"lsrle %0, %2, #1 \n\t"
|
||||
"smmulgt %0, %1, %2 \n\t"
|
||||
: "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse));
|
||||
return r;
|
||||
}
|
||||
#elif defined(ARCH_ARMV4L)
|
||||
# define FASTDIV(a,b) \
|
||||
({\
|
||||
int ret,dmy;\
|
||||
asm volatile(\
|
||||
"umull %1, %0, %2, %3"\
|
||||
:"=&r"(ret),"=&r"(dmy)\
|
||||
:"r"(a),"r"(ff_inverse[b])\
|
||||
);\
|
||||
ret;\
|
||||
})
|
||||
#elif defined(CONFIG_FASTDIV)
|
||||
#elif ARCH_ARM
|
||||
static inline av_const int FASTDIV(int a, int b)
|
||||
{
|
||||
int r, t;
|
||||
__asm__ volatile ("umull %1, %0, %2, %3"
|
||||
: "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
|
||||
return r;
|
||||
}
|
||||
#elif CONFIG_FASTDIV
|
||||
# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
|
||||
#else
|
||||
# define FASTDIV(a,b) ((a)/(b))
|
||||
|
@ -166,15 +161,13 @@ static inline av_const int FASTDIV(int a, int b)
|
|||
|
||||
extern const uint8_t ff_sqrt_tab[256];
|
||||
|
||||
static inline int av_log2_16bit(unsigned int v);
|
||||
|
||||
static inline av_const unsigned int ff_sqrt(unsigned int a)
|
||||
{
|
||||
unsigned int b;
|
||||
|
||||
if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
|
||||
else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
|
||||
#ifndef CONFIG_SMALL
|
||||
#if !CONFIG_SMALL
|
||||
else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
|
||||
else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ;
|
||||
#endif
|
||||
|
@ -188,9 +181,9 @@ static inline av_const unsigned int ff_sqrt(unsigned int a)
|
|||
return b - (a<b*b);
|
||||
}
|
||||
|
||||
#if defined(ARCH_X86)
|
||||
#if ARCH_X86
|
||||
#define MASK_ABS(mask, level)\
|
||||
asm volatile(\
|
||||
__asm__ volatile(\
|
||||
"cltd \n\t"\
|
||||
"xorl %1, %0 \n\t"\
|
||||
"subl %1, %0 \n\t"\
|
||||
|
@ -202,9 +195,9 @@ static inline av_const unsigned int ff_sqrt(unsigned int a)
|
|||
level= (level^mask)-mask;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CMOV
|
||||
#if HAVE_CMOV
|
||||
#define COPY3_IF_LT(x,y,a,b,c,d)\
|
||||
asm volatile (\
|
||||
__asm__ volatile (\
|
||||
"cmpl %0, %3 \n\t"\
|
||||
"cmovl %3, %0 \n\t"\
|
||||
"cmovl %4, %1 \n\t"\
|
||||
|
@ -221,7 +214,7 @@ if((y)<(x)){\
|
|||
}
|
||||
#endif
|
||||
|
||||
/* avoid usage of various functions */
|
||||
/* avoid usage of dangerous/inappropriate system functions */
|
||||
#undef malloc
|
||||
#define malloc please_use_av_malloc
|
||||
#undef free
|
||||
|
@ -233,7 +226,7 @@ if((y)<(x)){\
|
|||
#undef rand
|
||||
#define rand rand_is_forbidden_due_to_state_trashing_use_av_random
|
||||
#undef srand
|
||||
#define srand srand_is_forbidden_due_to_state_trashing_use_av_init_random
|
||||
#define srand srand_is_forbidden_due_to_state_trashing_use_av_random_init
|
||||
#undef random
|
||||
#define random random_is_forbidden_due_to_state_trashing_use_av_random
|
||||
#undef sprintf
|
||||
|
@ -242,13 +235,13 @@ if((y)<(x)){\
|
|||
#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
|
||||
#undef exit
|
||||
#define exit exit_is_forbidden
|
||||
#if !(defined(LIBAVFORMAT_BUILD) || defined(FFMPEG_FRAMEHOOK_H))
|
||||
#ifndef LIBAVFORMAT_BUILD
|
||||
#undef printf
|
||||
#define printf please_use_av_log
|
||||
#define printf please_use_av_log_instead_of_printf
|
||||
#undef fprintf
|
||||
#define fprintf please_use_av_log
|
||||
#define fprintf please_use_av_log_instead_of_fprintf
|
||||
#undef puts
|
||||
#define puts please_use_av_log
|
||||
#define puts please_use_av_log_instead_of_puts
|
||||
#undef perror
|
||||
#define perror please_use_av_log_instead_of_perror
|
||||
#endif
|
||||
|
@ -262,39 +255,74 @@ if((y)<(x)){\
|
|||
}\
|
||||
}
|
||||
|
||||
#ifndef HAVE_LLRINT
|
||||
#if defined(__ICC) || defined(__SUNPRO_C)
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
|
||||
#elif defined(__GNUC__)
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
|
||||
#elif HAVE_INLINE_ASM
|
||||
#error The asm code needs alignment, but we do not know how to do it for this compiler.
|
||||
#else
|
||||
#define DECLARE_ALIGNED(n,t,v) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v
|
||||
#endif
|
||||
|
||||
|
||||
#if !HAVE_LLRINT
|
||||
static av_always_inline av_const long long llrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif /* HAVE_LLRINT */
|
||||
|
||||
#ifndef HAVE_LRINT
|
||||
#if !HAVE_LRINT
|
||||
static av_always_inline av_const long int lrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif /* HAVE_LRINT */
|
||||
|
||||
#ifndef HAVE_LRINTF
|
||||
#if !HAVE_LRINTF
|
||||
static av_always_inline av_const long int lrintf(float x)
|
||||
{
|
||||
return (int)(rint(x));
|
||||
}
|
||||
#endif /* HAVE_LRINTF */
|
||||
|
||||
#ifndef HAVE_ROUND
|
||||
#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 */
|
||||
|
||||
#ifndef HAVE_ROUNDF
|
||||
#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 */
|
||||
|
||||
#endif /* FFMPEG_INTERNAL_H */
|
||||
#if !HAVE_TRUNCF
|
||||
static av_always_inline av_const float truncf(float x)
|
||||
{
|
||||
return (x > 0) ? floor(x) : ceil(x);
|
||||
}
|
||||
#endif /* HAVE_TRUNCF */
|
||||
|
||||
/**
|
||||
* Returns 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
|
||||
|
||||
#endif /* AVUTIL_INTERNAL_H */
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file intfloat_readwrite.c
|
||||
* Portable IEEE float/double read/write functions.
|
||||
* @file libavutil/intfloat_readwrite.c
|
||||
* portable IEEE float/double read/write functions
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
@ -51,7 +51,7 @@ double av_ext2dbl(const AVExtFloat ext){
|
|||
return 0.0/0.0;
|
||||
e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
|
||||
* mantissa bit is written as opposed to the
|
||||
* single and double precision formats */
|
||||
* single and double precision formats. */
|
||||
if (ext.exponent[0]&0x80)
|
||||
m= -m;
|
||||
return ldexp(m, e);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTFLOAT_READWRITE_H
|
||||
#define FFMPEG_INTFLOAT_READWRITE_H
|
||||
#ifndef AVUTIL_INTFLOAT_READWRITE_H
|
||||
#define AVUTIL_INTFLOAT_READWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
@ -37,4 +37,4 @@ int64_t av_dbl2int(double d) av_const;
|
|||
int32_t av_flt2int(float d) av_const;
|
||||
AVExtFloat av_dbl2ext(double d) av_const;
|
||||
|
||||
#endif /* FFMPEG_INTFLOAT_READWRITE_H */
|
||||
#endif /* AVUTIL_INTFLOAT_READWRITE_H */
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_INTREADWRITE_H
|
||||
#define FFMPEG_INTREADWRITE_H
|
||||
#ifndef AVUTIL_INTREADWRITE_H
|
||||
#define AVUTIL_INTREADWRITE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
@ -66,7 +66,7 @@ struct unaligned_16 { uint16_t l; } __attribute__((packed));
|
|||
#define AV_RL8(x) AV_RB8(x)
|
||||
#define AV_WL8(p, d) AV_WB8(p, d)
|
||||
|
||||
#ifdef HAVE_FAST_UNALIGNED
|
||||
#if HAVE_FAST_UNALIGNED
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define AV_RB16(x) AV_RN16(x)
|
||||
# define AV_WB16(p, d) AV_WN16(p, d)
|
||||
|
@ -189,4 +189,4 @@ struct unaligned_16 { uint16_t l; } __attribute__((packed));
|
|||
((uint8_t*)(p))[1] = (d)>>8; \
|
||||
((uint8_t*)(p))[2] = (d)>>16; } while(0)
|
||||
|
||||
#endif /* FFMPEG_INTREADWRITE_H */
|
||||
#endif /* AVUTIL_INTREADWRITE_H */
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LFG_H
|
||||
#define FFMPEG_LFG_H
|
||||
#ifndef AVUTIL_LFG_H
|
||||
#define AVUTIL_LFG_H
|
||||
|
||||
typedef struct {
|
||||
unsigned int state[64];
|
||||
|
@ -30,7 +30,7 @@ typedef struct {
|
|||
void av_lfg_init(AVLFG *c, unsigned int seed);
|
||||
|
||||
/**
|
||||
* Gets the next random unsigned 32bit number using a ALFG.
|
||||
* Gets 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.
|
||||
|
@ -41,9 +41,9 @@ static inline unsigned int av_lfg_get(AVLFG *c){
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the next random unsigned 32bit number using a MLFG.
|
||||
* Gets the next random unsigned 32-bit number using a MLFG.
|
||||
*
|
||||
* Please also consider the av_lfg_get() above, it is faster.
|
||||
* 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];
|
||||
|
@ -51,4 +51,4 @@ static inline unsigned int av_mlfg_get(AVLFG *c){
|
|||
return c->state[c->index++ & 63] = 2*a*b+a+b;
|
||||
}
|
||||
|
||||
#endif //FFMPEG_LFG_H
|
||||
#endif /* AVUTIL_LFG_H */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file lls.c
|
||||
* @file libavutil/lls.c
|
||||
* linear least squares model
|
||||
*/
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LLS_H
|
||||
#define FFMPEG_LLS_H
|
||||
#ifndef AVUTIL_LLS_H
|
||||
#define AVUTIL_LLS_H
|
||||
|
||||
#define MAX_VARS 32
|
||||
|
||||
|
@ -42,4 +42,4 @@ void av_update_lls(LLSModel *m, double *param, double decay);
|
|||
void av_solve_lls(LLSModel *m, double threshold, int min_order);
|
||||
double av_evaluate_lls(LLSModel *m, double *param, int order);
|
||||
|
||||
#endif /* FFMPEG_LLS_H */
|
||||
#endif /* AVUTIL_LLS_H */
|
||||
|
|
|
@ -20,28 +20,42 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file log.c
|
||||
* log.
|
||||
* @file libavutil/log.c
|
||||
* logging functions
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
#include "log.h"
|
||||
|
||||
int av_log_level = AV_LOG_INFO;
|
||||
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
{
|
||||
static int print_prefix=1;
|
||||
static int count;
|
||||
static char line[1024], prev[1024];
|
||||
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
|
||||
if(level>av_log_level)
|
||||
return;
|
||||
#undef fprintf
|
||||
if(print_prefix && avc) {
|
||||
fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), ptr);
|
||||
snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
|
||||
}else
|
||||
line[0]=0;
|
||||
|
||||
vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
|
||||
|
||||
print_prefix= line[strlen(line)-1] == '\n';
|
||||
if(print_prefix && !strcmp(line, prev)){
|
||||
count++;
|
||||
return;
|
||||
}
|
||||
|
||||
print_prefix= strstr(fmt, "\n") != NULL;
|
||||
|
||||
vfprintf(stderr, fmt, vl);
|
||||
if(count>0){
|
||||
fprintf(stderr, " Last message repeated %d times\n", count);
|
||||
count=0;
|
||||
}
|
||||
fputs(line, stderr);
|
||||
strcpy(prev, line);
|
||||
}
|
||||
|
||||
static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
|
||||
|
|
|
@ -18,13 +18,14 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LOG_H
|
||||
#define FFMPEG_LOG_H
|
||||
#ifndef AVUTIL_LOG_H
|
||||
#define AVUTIL_LOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "avutil.h"
|
||||
|
||||
/**
|
||||
* Describes the class of an AVClass context structure, that is an
|
||||
* Describes the class of an AVClass context structure. That is an
|
||||
* arbitrary struct of which the first field is a pointer to an
|
||||
* AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
|
||||
*/
|
||||
|
@ -37,8 +38,8 @@ struct AVCLASS {
|
|||
const char* class_name;
|
||||
|
||||
/**
|
||||
* a pointer to a function which returns the name of a context
|
||||
* instance \p ctx associated with the class
|
||||
* A pointer to a function which returns the name of a context
|
||||
* instance \p ctx associated with the class.
|
||||
*/
|
||||
const char* (*item_name)(void* ctx);
|
||||
|
||||
|
@ -64,26 +65,26 @@ struct AVCLASS {
|
|||
#define AV_LOG_QUIET -8
|
||||
|
||||
/**
|
||||
* something went really wrong and we will crash now
|
||||
* Something went really wrong and we will crash now.
|
||||
*/
|
||||
#define AV_LOG_PANIC 0
|
||||
|
||||
/**
|
||||
* something went wrong and recovery is not possible
|
||||
* like no header in a format which depends on it or a combination
|
||||
* of parameters which are not allowed
|
||||
* 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
|
||||
* but not all future data is affected
|
||||
* 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 / something which may or may not
|
||||
* lead to some problems like use of -vstrict -2
|
||||
* 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
|
||||
|
||||
|
@ -91,7 +92,7 @@ struct AVCLASS {
|
|||
#define AV_LOG_VERBOSE 40
|
||||
|
||||
/**
|
||||
* stuff which is only useful for libav* developers
|
||||
* Stuff which is only useful for libav* developers.
|
||||
*/
|
||||
#define AV_LOG_DEBUG 48
|
||||
#endif
|
||||
|
@ -101,8 +102,8 @@ extern int av_log_level;
|
|||
#endif
|
||||
|
||||
/**
|
||||
* Send the specified message to the log if the level is less than or equal to
|
||||
* the current av_log_level. By default, all logging messages are sent to
|
||||
* Sends 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.
|
||||
*
|
||||
|
@ -126,4 +127,4 @@ void av_log_set_level(int);
|
|||
void av_log_set_callback(void (*)(void*, int, const char*, va_list));
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
|
||||
|
||||
#endif /* FFMPEG_LOG_H */
|
||||
#endif /* AVUTIL_LOG_H */
|
||||
|
|
|
@ -18,15 +18,17 @@
|
|||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
//! avoid e.g. MPlayers fast_memcpy, it slows things down here
|
||||
//! Avoid e.g. MPlayers fast_memcpy, it slows things down here.
|
||||
#undef memcpy
|
||||
#include <string.h>
|
||||
#include "lzo.h"
|
||||
|
||||
//! define if we may write up to 12 bytes beyond the output buffer
|
||||
//! Define 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 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;
|
||||
|
@ -35,13 +37,13 @@ typedef struct LZOContext {
|
|||
} LZOContext;
|
||||
|
||||
/**
|
||||
* \brief read one byte from input buffer, avoiding overrun
|
||||
* \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 |= LZO_INPUT_DEPLETED;
|
||||
c->error |= AV_LZO_INPUT_DEPLETED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -52,7 +54,7 @@ static inline int get_byte(LZOContext *c) {
|
|||
#endif
|
||||
|
||||
/**
|
||||
* \brief decode a length value in the coding used by lzo
|
||||
* \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
|
||||
|
@ -80,7 +82,7 @@ static inline int get_len(LZOContext *c, int x, int mask) {
|
|||
#endif
|
||||
|
||||
/**
|
||||
* \brief copy bytes from input to output buffer with checking
|
||||
* \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) {
|
||||
|
@ -88,11 +90,11 @@ static inline void copy(LZOContext *c, int cnt) {
|
|||
register uint8_t *dst = c->out;
|
||||
if (cnt > c->in_end - src) {
|
||||
cnt = FFMAX(c->in_end - src, 0);
|
||||
c->error |= LZO_INPUT_DEPLETED;
|
||||
c->error |= AV_LZO_INPUT_DEPLETED;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
c->error |= AV_LZO_OUTPUT_FULL;
|
||||
}
|
||||
#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
|
||||
COPY4(dst, src);
|
||||
|
@ -109,7 +111,7 @@ static inline void copy(LZOContext *c, int cnt) {
|
|||
static inline void memcpy_backptr(uint8_t *dst, int back, int cnt);
|
||||
|
||||
/**
|
||||
* \brief copy previously decoded bytes to current position
|
||||
* \brief Copies previously decoded bytes to current position.
|
||||
* \param back how many bytes back we start
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*
|
||||
|
@ -120,12 +122,12 @@ static inline void copy_backptr(LZOContext *c, int back, int cnt) {
|
|||
register const uint8_t *src = &c->out[-back];
|
||||
register uint8_t *dst = c->out;
|
||||
if (src < c->out_start || src > dst) {
|
||||
c->error |= LZO_INVALID_BACKPTR;
|
||||
c->error |= AV_LZO_INVALID_BACKPTR;
|
||||
return;
|
||||
}
|
||||
if (cnt > c->out_end - dst) {
|
||||
cnt = FFMAX(c->out_end - dst, 0);
|
||||
c->error |= LZO_OUTPUT_FULL;
|
||||
c->error |= AV_LZO_OUTPUT_FULL;
|
||||
}
|
||||
memcpy_backptr(dst, back, cnt);
|
||||
c->out = dst + cnt;
|
||||
|
@ -165,31 +167,11 @@ static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief deliberately overlapping memcpy implementation
|
||||
* \param dst destination buffer; must be padded with 12 additional bytes
|
||||
* \param back how many bytes back we start (the initial size of the overlapping window)
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*
|
||||
* cnt > back is valid, this will copy the bytes we just copied,
|
||||
* thus creating a repeating pattern with a period length of back.
|
||||
*/
|
||||
void av_memcpy_backptr(uint8_t *dst, int back, int cnt) {
|
||||
memcpy_backptr(dst, back, cnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief decode LZO 1x compressed data
|
||||
* \param out output buffer
|
||||
* \param outlen size of output buffer, number of bytes left are returned here
|
||||
* \param in input buffer
|
||||
* \param inlen size of input buffer, number of bytes left are returned here
|
||||
* \return 0 on success, otherwise error flags, see lzo.h
|
||||
*
|
||||
* make sure all buffers are appropriately padded, in must provide
|
||||
* LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes
|
||||
*/
|
||||
int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
||||
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
||||
int state= 0;
|
||||
int x;
|
||||
LZOContext c;
|
||||
|
@ -202,10 +184,10 @@ int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
|||
if (x > 17) {
|
||||
copy(&c, x - 17);
|
||||
x = GETB(c);
|
||||
if (x < 16) c.error |= LZO_ERROR;
|
||||
if (x < 16) c.error |= AV_LZO_ERROR;
|
||||
}
|
||||
if (c.in > c.in_end)
|
||||
c.error |= LZO_INPUT_DEPLETED;
|
||||
c.error |= AV_LZO_INPUT_DEPLETED;
|
||||
while (!c.error) {
|
||||
int cnt, back;
|
||||
if (x > 15) {
|
||||
|
@ -223,7 +205,7 @@ int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
|||
back += (GETB(c) << 6) + (x >> 2);
|
||||
if (back == (1 << 14)) {
|
||||
if (cnt != 1)
|
||||
c.error |= LZO_ERROR;
|
||||
c.error |= AV_LZO_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -252,6 +234,12 @@ int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
|||
return c.error;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
|
||||
return av_lzo1x_decode(out, outlen, in, inlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
#include <lzo/lzo1x.h>
|
||||
|
@ -277,7 +265,7 @@ START_TIMER
|
|||
#elif defined(LIBLZO_UNSAFE)
|
||||
if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
|
||||
#else
|
||||
if (lzo1x_decode(decomp, &outlen, comp, &inlen))
|
||||
if (av_lzo1x_decode(decomp, &outlen, comp, &inlen))
|
||||
#endif
|
||||
av_log(NULL, AV_LOG_ERROR, "decompression error\n");
|
||||
STOP_TIMER("lzod")
|
||||
|
@ -285,7 +273,7 @@ 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");
|
||||
av_log(NULL, AV_LOG_ERROR, "decompression OK\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,21 +19,48 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_LZO_H
|
||||
#define FFMPEG_LZO_H
|
||||
#ifndef AVUTIL_LZO_H
|
||||
#define AVUTIL_LZO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define LZO_INPUT_DEPLETED 1
|
||||
#define LZO_OUTPUT_FULL 2
|
||||
#define LZO_INVALID_BACKPTR 4
|
||||
#define LZO_ERROR 8
|
||||
/** \defgroup errflags 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 LZO_INPUT_PADDING 8
|
||||
#define LZO_OUTPUT_PADDING 12
|
||||
#define AV_LZO_INPUT_PADDING 8
|
||||
#define AV_LZO_OUTPUT_PADDING 12
|
||||
|
||||
int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
|
||||
/**
|
||||
* \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);
|
||||
|
||||
/**
|
||||
* \brief deliberately overlapping memcpy implementation
|
||||
* \param dst destination buffer; must be padded with 12 additional bytes
|
||||
* \param back how many bytes back we start (the initial size of the overlapping window)
|
||||
* \param cnt number of bytes to copy, must be >= 0
|
||||
*
|
||||
* cnt > back is valid, this will copy the bytes we just copied,
|
||||
* thus creating a repeating pattern with a period length of back.
|
||||
*/
|
||||
void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
|
||||
|
||||
#endif /* FFMPEG_LZO_H */
|
||||
#endif /* AVUTIL_LZO_H */
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file mathematics.c
|
||||
* Miscellaneous math routines and tables.
|
||||
* @file libavutil/mathematics.c
|
||||
* miscellaneous math routines and tables
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "mathematics.h"
|
||||
|
||||
|
@ -48,11 +50,17 @@ const uint8_t ff_log2_tab[256]={
|
|||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
int64_t ff_gcd(int64_t a, int64_t b){
|
||||
if(b) return ff_gcd(b, a%b);
|
||||
int64_t av_gcd(int64_t a, int64_t b){
|
||||
if(b) return av_gcd(b, a%b);
|
||||
else return a;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
int64_t ff_gcd(int64_t a, int64_t b){
|
||||
return av_gcd(a, b);
|
||||
}
|
||||
#endif
|
||||
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
|
||||
int64_t r=0;
|
||||
assert(c > 0);
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MATHEMATICS_H
|
||||
#define FFMPEG_MATHEMATICS_H
|
||||
#ifndef AVUTIL_MATHEMATICS_H
|
||||
#define AVUTIL_MATHEMATICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
#include "rational.h"
|
||||
|
||||
#ifndef M_E
|
||||
|
@ -42,28 +43,30 @@
|
|||
#endif
|
||||
|
||||
enum AVRounding {
|
||||
AV_ROUND_ZERO = 0, ///< round toward zero
|
||||
AV_ROUND_INF = 1, ///< round away from zero
|
||||
AV_ROUND_DOWN = 2, ///< round toward -infinity
|
||||
AV_ROUND_UP = 3, ///< round toward +infinity
|
||||
AV_ROUND_NEAR_INF = 5, ///< round to nearest and halfway cases away from zero
|
||||
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.
|
||||
};
|
||||
|
||||
int64_t av_const av_gcd(int64_t a, int64_t b);
|
||||
|
||||
/**
|
||||
* rescale a 64bit integer with rounding to nearest.
|
||||
* a simple a*b/c isn't possible as it can overflow
|
||||
* Rescales 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 64bit integer with specified rounding.
|
||||
* a simple a*b/c isn't possible as it can overflow
|
||||
* Rescales a 64-bit integer with specified rounding.
|
||||
* A simple a*b/c isn't possible as it can overflow.
|
||||
*/
|
||||
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const;
|
||||
|
||||
/**
|
||||
* rescale a 64bit integer by 2 rational numbers.
|
||||
* Rescales a 64-bit integer by 2 rational numbers.
|
||||
*/
|
||||
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
|
||||
|
||||
#endif /* FFMPEG_MATHEMATICS_H */
|
||||
#endif /* AVUTIL_MATHEMATICS_H */
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include <string.h>
|
||||
#include "bswap.h"
|
||||
#include "md5.h"
|
||||
|
||||
typedef struct AVMD5{
|
||||
|
@ -43,29 +43,29 @@ typedef struct AVMD5{
|
|||
const int av_md5_size= sizeof(AVMD5);
|
||||
|
||||
static const uint8_t S[4][4] = {
|
||||
{ 7, 12, 17, 22 }, /* Round 1 */
|
||||
{ 5, 9, 14, 20 }, /* Round 2 */
|
||||
{ 4, 11, 16, 23 }, /* Round 3 */
|
||||
{ 6, 10, 15, 21 } /* Round 4 */
|
||||
{ 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 */
|
||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* round 1 */
|
||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* Round 2 */
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* round 2 */
|
||||
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* Round 3 */
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* round 3 */
|
||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* Round 4 */
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* round 4 */
|
||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
|
||||
|
@ -98,7 +98,7 @@ static void body(uint32_t ABCD[4], uint32_t X[16]){
|
|||
X[i]= bswap_32(X[i]);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SMALL
|
||||
#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;
|
||||
|
@ -144,7 +144,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst){
|
|||
uint64_t finalcount= le2me_64(ctx->len<<3);
|
||||
|
||||
av_md5_update(ctx, "\200", 1);
|
||||
while((ctx->len & 63)<56)
|
||||
while((ctx->len & 63)!=56)
|
||||
av_md5_update(ctx, "", 1);
|
||||
|
||||
av_md5_update(ctx, (uint8_t*)&finalcount, 8);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MD5_H
|
||||
#define FFMPEG_MD5_H
|
||||
#ifndef AVUTIL_MD5_H
|
||||
#define AVUTIL_MD5_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -32,5 +32,5 @@ void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
|
|||
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
|
||||
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
|
||||
|
||||
#endif /* FFMPEG_MD5_H */
|
||||
#endif /* AVUTIL_MD5_H */
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* default memory allocator for libavutil
|
||||
* Copyright (c) 2002 Fabrice Bellard.
|
||||
* Copyright (c) 2002 Fabrice Bellard
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
|
@ -20,29 +20,34 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file mem.c
|
||||
* default memory allocator for libavutil.
|
||||
* @file libavutil/mem.c
|
||||
* default memory allocator for libavutil
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
/* here we can use OS dependent allocation functions */
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef realloc
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
/* you can redefine av_malloc and av_free in your project to use your
|
||||
#include "mem.h"
|
||||
|
||||
/* here we can use OS-dependent allocation functions */
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
|
||||
/* You can redefine av_malloc and av_free in your project to use your
|
||||
memory allocator. You do not need to suppress this file because the
|
||||
linker will do it automatically */
|
||||
linker will do it automatically. */
|
||||
|
||||
void *av_malloc(unsigned int size)
|
||||
{
|
||||
void *ptr;
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
void *ptr = NULL;
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
long diff;
|
||||
#endif
|
||||
|
||||
|
@ -50,20 +55,23 @@ void *av_malloc(unsigned int size)
|
|||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
ptr = malloc(size+16);
|
||||
if(!ptr)
|
||||
return ptr;
|
||||
diff= ((-(long)ptr - 1)&15) + 1;
|
||||
ptr = (char*)ptr + diff;
|
||||
((char*)ptr)[-1]= diff;
|
||||
#elif defined (HAVE_MEMALIGN)
|
||||
#elif HAVE_POSIX_MEMALIGN
|
||||
if (posix_memalign(&ptr,16,size))
|
||||
ptr = NULL;
|
||||
#elif HAVE_MEMALIGN
|
||||
ptr = memalign(16,size);
|
||||
/* Why 64?
|
||||
Indeed, we should align it:
|
||||
on 4 for 386
|
||||
on 16 for 486
|
||||
on 32 for 586, PPro - k6-III
|
||||
on 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!
|
||||
|
@ -71,10 +79,10 @@ void *av_malloc(unsigned int size)
|
|||
/* Why 16?
|
||||
Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
|
||||
it will just trigger an exception and the unaligned load will be done in the
|
||||
exception handler or it will just segfault (SSE2 on P4)
|
||||
exception handler or it will just segfault (SSE2 on P4).
|
||||
Why not larger? Because I did not see a difference in benchmarks ...
|
||||
*/
|
||||
/* benchmarks with p3
|
||||
/* benchmarks with P3
|
||||
memalign(64)+1 3071,3051,3032
|
||||
memalign(64)+2 3051,3032,3041
|
||||
memalign(64)+4 2911,2896,2915
|
||||
|
@ -83,7 +91,7 @@ void *av_malloc(unsigned int size)
|
|||
memalign(64)+32 2546,2545,2571
|
||||
memalign(64)+64 2570,2533,2558
|
||||
|
||||
btw, malloc seems to do 8 byte alignment by default here
|
||||
BTW, malloc seems to do 8-byte alignment by default here.
|
||||
*/
|
||||
#else
|
||||
ptr = malloc(size);
|
||||
|
@ -93,7 +101,7 @@ void *av_malloc(unsigned int size)
|
|||
|
||||
void *av_realloc(void *ptr, unsigned int size)
|
||||
{
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
int diff;
|
||||
#endif
|
||||
|
||||
|
@ -101,7 +109,7 @@ void *av_realloc(void *ptr, unsigned int size)
|
|||
if(size > (INT_MAX-16) )
|
||||
return NULL;
|
||||
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
#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];
|
||||
|
@ -115,7 +123,7 @@ void av_free(void *ptr)
|
|||
{
|
||||
/* XXX: this test should not be needed on most libcs */
|
||||
if (ptr)
|
||||
#ifdef CONFIG_MEMALIGN_HACK
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
free((char*)ptr - ((char*)ptr)[-1]);
|
||||
#else
|
||||
free(ptr);
|
||||
|
|
|
@ -19,67 +19,53 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file mem.h
|
||||
* Memory handling functions.
|
||||
* @file libavutil/mem.h
|
||||
* memory handling functions
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_MEM_H
|
||||
#define FFMPEG_MEM_H
|
||||
#ifndef AVUTIL_MEM_H
|
||||
#define AVUTIL_MEM_H
|
||||
|
||||
#ifdef __ICC
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
|
||||
#elif defined(__GNUC__)
|
||||
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
|
||||
#elif defined(HAVE_INLINE_ASM)
|
||||
#error The asm code needs alignment, but we do not know how to do it for this compiler.
|
||||
#else
|
||||
#define DECLARE_ALIGNED(n,t,v) t v
|
||||
#define DECLARE_ASM_CONST(n,t,v) static const t v
|
||||
#endif
|
||||
#include "common.h"
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
|
||||
#if AV_GCC_VERSION_AT_LEAST(3,1)
|
||||
#define av_malloc_attrib __attribute__((__malloc__))
|
||||
#else
|
||||
#define av_malloc_attrib
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2)
|
||||
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
|
||||
#define av_alloc_size(n) __attribute__((alloc_size(n)))
|
||||
#else
|
||||
#define av_alloc_size(n)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Allocate a block of \p size bytes with alignment suitable for all
|
||||
* Allocates a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU).
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if it cannot allocate
|
||||
* it.
|
||||
* @return Pointer to the allocated block, NULL if the block cannot
|
||||
* be allocated.
|
||||
* @see av_mallocz()
|
||||
*/
|
||||
void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Allocate or reallocate a block of memory.
|
||||
* If \p ptr is NULL and \p size > 0, allocate a new block. If \p
|
||||
* size is zero, free the memory block pointed by \p ptr.
|
||||
* Allocates or reallocates a block of memory.
|
||||
* If \p ptr is NULL and \p size > 0, allocates a new block. If \p
|
||||
* size is zero, frees the memory block pointed to by \p ptr.
|
||||
* @param size Size in bytes for the memory block to be allocated or
|
||||
* reallocated.
|
||||
* @param ptr Pointer to a memory block already allocated with
|
||||
* av_malloc(z)() or av_realloc() or NULL.
|
||||
* @return Pointer to a newly reallocated block or NULL if it cannot
|
||||
* reallocate or the function is used to free the memory block.
|
||||
* @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, unsigned int size) av_alloc_size(2);
|
||||
|
||||
/**
|
||||
* Free a memory block which has been allocated with av_malloc(z)() or
|
||||
* Frees 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.
|
||||
|
@ -89,31 +75,30 @@ void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
|
|||
void av_free(void *ptr);
|
||||
|
||||
/**
|
||||
* Allocate a block of \p size bytes with alignment suitable for all
|
||||
* Allocates a block of \p size bytes with alignment suitable for all
|
||||
* memory accesses (including vectors if available on the CPU) and
|
||||
* set to zeroes all the bytes of the block.
|
||||
* zeroes all the bytes of the block.
|
||||
* @param size Size in bytes for the memory block to be allocated.
|
||||
* @return Pointer to the allocated block, NULL if it cannot allocate
|
||||
* it.
|
||||
* @return Pointer to the allocated block, NULL if it cannot be allocated.
|
||||
* @see av_malloc()
|
||||
*/
|
||||
void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
|
||||
|
||||
/**
|
||||
* Duplicate the string \p s.
|
||||
* @param s String to be duplicated.
|
||||
* Duplicates the string \p s.
|
||||
* @param s string to be duplicated
|
||||
* @return Pointer to a newly allocated string containing a
|
||||
* copy of \p s or NULL if it cannot be allocated.
|
||||
* copy of \p 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 to NULL the pointer to it.
|
||||
* Frees 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);
|
||||
|
||||
#endif /* FFMPEG_MEM_H */
|
||||
#endif /* AVUTIL_MEM_H */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Principal component analysis
|
||||
* principal component analysis (PCA)
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -20,8 +20,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file pca.c
|
||||
* Principal component analysis
|
||||
* @file libavutil/pca.c
|
||||
* principal component analysis (PCA)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
@ -67,7 +67,8 @@ void ff_pca_add(PCA *pca, double *v){
|
|||
}
|
||||
|
||||
int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
|
||||
int i, j, k, pass;
|
||||
int i, j, pass;
|
||||
int k=0;
|
||||
const int n= pca->n;
|
||||
double z[n];
|
||||
|
||||
|
@ -119,7 +120,7 @@ int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
|
|||
|
||||
if(pass < 3 && fabs(covar) < sum / (5*n*n)) //FIXME why pass < 3
|
||||
continue;
|
||||
if(fabs(covar) == 0.0) //FIXME shouldnt be needed
|
||||
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;
|
||||
|
@ -167,7 +168,7 @@ int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(){
|
||||
int main(void){
|
||||
PCA *pca;
|
||||
int i, j, k;
|
||||
#define LEN 8
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Principal component analysis
|
||||
* principal component analysis (PCA)
|
||||
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -20,16 +20,16 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file pca.h
|
||||
* Principal component analysis
|
||||
* @file libavutil/pca.h
|
||||
* principal component analysis (PCA)
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_PCA_H
|
||||
#define FFMPEG_PCA_H
|
||||
#ifndef AVUTIL_PCA_H
|
||||
#define AVUTIL_PCA_H
|
||||
|
||||
struct PCA *ff_pca_init(int n);
|
||||
void ff_pca_free(struct PCA *pca);
|
||||
void ff_pca_add(struct PCA *pca, double *v);
|
||||
int ff_pca(struct PCA *pca, double *eigenvector, double *eigenvalue);
|
||||
|
||||
#endif /* FFMPEG_PCA_H */
|
||||
#endif /* AVUTIL_PCA_H */
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* 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_PIXFMT_H
|
||||
#define AVUTIL_PIXFMT_H
|
||||
|
||||
/**
|
||||
* @file libavutil/pixfmt.h
|
||||
* pixel format definitions
|
||||
*
|
||||
* @warning This file has to be considered an internal but installed
|
||||
* header, so it should not be directly included in your projects.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pixel format. Notes:
|
||||
*
|
||||
* PIX_FMT_RGB32 is handled in an endian-specific manner. An RGBA
|
||||
* color is put together as:
|
||||
* (A << 24) | (R << 16) | (G << 8) | B
|
||||
* This is stored as BGRA on little-endian CPU architectures and ARGB on
|
||||
* big-endian CPUs.
|
||||
*
|
||||
* When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
|
||||
* image data is stored in AVFrame.data[0]. The palette is transported in
|
||||
* AVFrame.data[1], is 1024 bytes long (256 4-byte entries) and is
|
||||
* formatted the same as in PIX_FMT_RGB32 described above (i.e., it is
|
||||
* also endian-specific). Note also that the individual RGB palette
|
||||
* components stored in AVFrame.data[1] should be in the range 0..255.
|
||||
* This is important as many custom PAL8 video codecs that were designed
|
||||
* to run on the IBM VGA graphics adapter use 6-bit palette components.
|
||||
*
|
||||
* For all the 8bit per pixel formats, an RGB32 palette is in data[1] like
|
||||
* for pal8. This palette is filled in automatically by the function
|
||||
* allocating the picture.
|
||||
*
|
||||
* Note, make sure that all newly added big endian formats have pix_fmt&1==1
|
||||
* and that all newly added little endian formats have pix_fmt&1==0
|
||||
* this allows simpler detection of big vs little endian.
|
||||
*/
|
||||
enum PixelFormat {
|
||||
PIX_FMT_NONE= -1,
|
||||
PIX_FMT_YUV420P, ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
|
||||
PIX_FMT_YUYV422, ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
|
||||
PIX_FMT_RGB24, ///< packed RGB 8:8:8, 24bpp, RGBRGB...
|
||||
PIX_FMT_BGR24, ///< packed RGB 8:8:8, 24bpp, BGRBGR...
|
||||
PIX_FMT_YUV422P, ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
|
||||
PIX_FMT_YUV444P, ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
|
||||
PIX_FMT_RGB32, ///< packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in CPU endianness
|
||||
PIX_FMT_YUV410P, ///< planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
|
||||
PIX_FMT_YUV411P, ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
|
||||
PIX_FMT_RGB565, ///< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in CPU endianness
|
||||
PIX_FMT_RGB555, ///< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in CPU endianness, most significant bit to 0
|
||||
PIX_FMT_GRAY8, ///< Y , 8bpp
|
||||
PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black
|
||||
PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white
|
||||
PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette
|
||||
PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG)
|
||||
PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG)
|
||||
PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG)
|
||||
PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing
|
||||
PIX_FMT_XVMC_MPEG2_IDCT,
|
||||
PIX_FMT_UYVY422, ///< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
|
||||
PIX_FMT_UYYVYY411, ///< packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
|
||||
PIX_FMT_BGR32, ///< packed RGB 8:8:8, 32bpp, (msb)8A 8B 8G 8R(lsb), in CPU endianness
|
||||
PIX_FMT_BGR565, ///< packed RGB 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), in CPU endianness
|
||||
PIX_FMT_BGR555, ///< packed RGB 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), in CPU endianness, most significant bit to 1
|
||||
PIX_FMT_BGR8, ///< packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
|
||||
PIX_FMT_BGR4, ///< packed RGB 1:2:1, 4bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_BGR4_BYTE, ///< packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
|
||||
PIX_FMT_RGB8, ///< packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
|
||||
PIX_FMT_RGB4, ///< packed RGB 1:2:1, 4bpp, (msb)1R 2G 1B(lsb)
|
||||
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 for UV
|
||||
PIX_FMT_NV21, ///< as above, but U and V bytes are swapped
|
||||
|
||||
PIX_FMT_RGB32_1, ///< packed RGB 8:8:8, 32bpp, (msb)8R 8G 8B 8A(lsb), in CPU endianness
|
||||
PIX_FMT_BGR32_1, ///< packed RGB 8:8:8, 32bpp, (msb)8B 8G 8R 8A(lsb), in CPU endianness
|
||||
|
||||
PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian
|
||||
PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian
|
||||
PIX_FMT_YUV440P, ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
|
||||
PIX_FMT_YUVJ440P, ///< planar YUV 4:4:0 full scale (JPEG)
|
||||
PIX_FMT_YUVA420P, ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
|
||||
PIX_FMT_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, big-endian
|
||||
PIX_FMT_RGB48LE, ///< packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, little-endian
|
||||
PIX_FMT_VAAPI_MOCO, ///< HW acceleration through VA API at motion compensation entry-point, Picture.data[0] 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[0] contains a vaapi_render_state struct which contains fields extracted from headers
|
||||
PIX_FMT_VAAPI_VLD, ///< HW decoding through VA API, Picture.data[0] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers
|
||||
PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
|
||||
};
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PIX_FMT_RGBA PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_BGRA PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ARGB PIX_FMT_RGB32
|
||||
#define PIX_FMT_ABGR PIX_FMT_BGR32
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16BE
|
||||
#define PIX_FMT_RGB48 PIX_FMT_RGB48BE
|
||||
#else
|
||||
#define PIX_FMT_RGBA PIX_FMT_BGR32
|
||||
#define PIX_FMT_BGRA PIX_FMT_RGB32
|
||||
#define PIX_FMT_ARGB PIX_FMT_BGR32_1
|
||||
#define PIX_FMT_ABGR PIX_FMT_RGB32_1
|
||||
#define PIX_FMT_GRAY16 PIX_FMT_GRAY16LE
|
||||
#define PIX_FMT_RGB48 PIX_FMT_RGB48LE
|
||||
#endif
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT < (50<<16)
|
||||
#define PIX_FMT_UYVY411 PIX_FMT_UYYVYY411
|
||||
#define PIX_FMT_RGBA32 PIX_FMT_RGB32
|
||||
#define PIX_FMT_YUV422 PIX_FMT_YUYV422
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_PIXFMT_H */
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Mersenne Twister Random Algorithm
|
||||
* Copyright (c) 2006 Ryan Martell.
|
||||
* Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
|
||||
* Takuji Nishimura and Makoto Matsumoto.
|
||||
* Mersenne Twister PRNG algorithm
|
||||
* Copyright (c) 2006 Ryan Martell
|
||||
* Based on a C program for MT19937, with initialization improved 2002/1/26.
|
||||
* Coded by Takuji Nishimura and Makoto Matsumoto.
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
|
@ -23,25 +23,26 @@
|
|||
|
||||
|
||||
/**
|
||||
see http://en.wikipedia.org/wiki/Mersenne_twister for an explanation of this algorithm.
|
||||
*/
|
||||
* See http://en.wikipedia.org/wiki/Mersenne_twister
|
||||
* for an explanation of this algorithm.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "random.h"
|
||||
|
||||
|
||||
/* Period parameters */
|
||||
/* period parameters */
|
||||
#define M 397
|
||||
#define A 0x9908b0df /* constant vector a */
|
||||
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffff /* least significant r bits */
|
||||
|
||||
/** initializes mt[AV_RANDOM_N] with a seed */
|
||||
void av_init_random(unsigned int seed, AVRandomState *state)
|
||||
/** Initializes mt[AV_RANDOM_N] with a seed. */
|
||||
void av_random_init(AVRandomState *state, unsigned int seed)
|
||||
{
|
||||
int index;
|
||||
|
||||
/*
|
||||
This differs from the wikipedia article. Source is from the
|
||||
This differs from the Wikipedia article. Source is from the
|
||||
Makoto Matsumoto and Takuji Nishimura code, with the following comment:
|
||||
*/
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
|
@ -52,10 +53,18 @@ void av_init_random(unsigned int seed, AVRandomState *state)
|
|||
unsigned int prev= state->mt[index - 1];
|
||||
state->mt[index] = (1812433253UL * (prev ^ (prev>>30)) + index) & 0xffffffff;
|
||||
}
|
||||
state->index= index; // will cause it to generate untempered numbers the first iteration
|
||||
state->index= index; // Will cause it to generate untempered numbers in the first iteration.
|
||||
}
|
||||
|
||||
/** generate AV_RANDOM_N words at one time (which will then be tempered later) (av_random calls this; you shouldn't) */
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
void av_init_random(unsigned int seed, AVRandomState *state)
|
||||
{
|
||||
av_random_init(state, seed);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Generates AV_RANDOM_N words at one time (which will then be tempered later).
|
||||
* av_random calls this; you shouldn't. */
|
||||
void av_random_generate_untempered_numbers(AVRandomState *state)
|
||||
{
|
||||
int kk;
|
||||
|
@ -83,7 +92,7 @@ int main(void)
|
|||
int i, j;
|
||||
AVRandomState state;
|
||||
|
||||
av_init_random(0xdeadbeef, &state);
|
||||
av_random_init(&state, 0xdeadbeef);
|
||||
for (j = 0; j < 10000; j++) {
|
||||
START_TIMER
|
||||
for (i = 0; i < 624; i++) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Mersenne Twister Random Algorithm
|
||||
* Copyright (c) 2006 Ryan Martell.
|
||||
* Based on A C-program for MT19937, with initialization improved 2002/1/26. Coded by
|
||||
* Takuji Nishimura and Makoto Matsumoto.
|
||||
* Mersenne Twister PRNG algorithm
|
||||
* Copyright (c) 2006 Ryan Martell
|
||||
* Based on a C program for MT19937, with initialization improved 2002/1/26.
|
||||
* Coded by Takuji Nishimura and Makoto Matsumoto.
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
|
@ -21,25 +21,31 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RANDOM_H
|
||||
#define FFMPEG_RANDOM_H
|
||||
#ifndef AVUTIL_RANDOM_H
|
||||
#define AVUTIL_RANDOM_H
|
||||
|
||||
#define AV_RANDOM_N 624
|
||||
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
unsigned int mt[AV_RANDOM_N]; ///< the array for the state vector
|
||||
int index; ///< Current untempered value we use as the base.
|
||||
} AVRandomState;
|
||||
|
||||
|
||||
void av_init_random(unsigned int seed, AVRandomState *state); ///< To be inlined, the struct must be visible. So it does not make sense to try and keep it opaque with malloc/free-like calls.
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
attribute_deprecated void av_init_random(unsigned int seed, AVRandomState *state);
|
||||
#endif
|
||||
void av_random_init(AVRandomState *state, unsigned int seed); ///< To be inlined, the struct must be visible. So it does not make sense to try and keep it opaque with malloc/free-like calls.
|
||||
void av_random_generate_untempered_numbers(AVRandomState *state); ///< Regenerate the untempered numbers (must be done every 624 iterations, or it will loop).
|
||||
|
||||
/**
|
||||
* Generates a random number from the interval [0,0xffffffff].
|
||||
*
|
||||
* Please do NOT use the Mersenne Twister, it is slow. Use the random generator
|
||||
* from lfg.c/h or a simple LCG like state= state*1664525+1013904223.
|
||||
* Please do NOT use the Mersenne Twister, it is slow. Use the random number
|
||||
* generator from lfg.c/h or a simple LCG like state = state*1664525+1013904223.
|
||||
* If you still choose to use MT, expect that you will have to provide
|
||||
* some evidence that it makes a difference for the case where you use it.
|
||||
*/
|
||||
|
@ -63,11 +69,11 @@ static inline unsigned int av_random(AVRandomState *state)
|
|||
return y;
|
||||
}
|
||||
|
||||
/** Return random in range [0-1] as double. */
|
||||
/** Returns a random number in the range [0-1] as double. */
|
||||
static inline double av_random_real1(AVRandomState *state)
|
||||
{
|
||||
/* divided by 2^32-1 */
|
||||
return av_random(state) * (1.0 / 4294967296.0);
|
||||
}
|
||||
|
||||
#endif /* FFMPEG_RANDOM_H */
|
||||
#endif /* AVUTIL_RANDOM_H */
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.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 <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "timer.h"
|
||||
#include "random_seed.h"
|
||||
|
||||
uint32_t ff_random_get_seed(void)
|
||||
{
|
||||
uint32_t seed;
|
||||
int fd;
|
||||
|
||||
if ((fd = open("/dev/random", O_RDONLY)) == -1)
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd != -1){
|
||||
read(fd, &seed, 4);
|
||||
close(fd);
|
||||
return seed;
|
||||
}
|
||||
#ifdef AV_READ_TIME
|
||||
seed = AV_READ_TIME();
|
||||
#endif
|
||||
// XXX what to do ?
|
||||
return seed;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.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_RANDOM_SEED_H
|
||||
#define AVUTIL_RANDOM_SEED_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Get a seed to use in conjuction with random functions
|
||||
*/
|
||||
uint32_t ff_random_get_seed();
|
||||
|
||||
#endif /* AVUTIL_RANDOM_SEED_H */
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Rational numbers
|
||||
* rational numbers
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -20,11 +20,12 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file rational.c
|
||||
* Rational numbers
|
||||
* @file libavutil/rational.c
|
||||
* rational numbers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
//#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -32,23 +33,23 @@
|
|||
#include "mathematics.h"
|
||||
#include "rational.h"
|
||||
|
||||
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
||||
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max){
|
||||
AVRational a0={0,1}, a1={1,0};
|
||||
int sign= (nom<0) ^ (den<0);
|
||||
int64_t gcd= ff_gcd(FFABS(nom), FFABS(den));
|
||||
int sign= (num<0) ^ (den<0);
|
||||
int64_t gcd= av_gcd(FFABS(num), FFABS(den));
|
||||
|
||||
if(gcd){
|
||||
nom = FFABS(nom)/gcd;
|
||||
num = FFABS(num)/gcd;
|
||||
den = FFABS(den)/gcd;
|
||||
}
|
||||
if(nom<=max && den<=max){
|
||||
a1= (AVRational){nom, den};
|
||||
if(num<=max && den<=max){
|
||||
a1= (AVRational){num, den};
|
||||
den=0;
|
||||
}
|
||||
|
||||
while(den){
|
||||
uint64_t x = nom / den;
|
||||
int64_t next_den= nom - den*x;
|
||||
uint64_t x = num / den;
|
||||
int64_t next_den= num - den*x;
|
||||
int64_t a2n= x*a1.num + a0.num;
|
||||
int64_t a2d= x*a1.den + a0.den;
|
||||
|
||||
|
@ -56,19 +57,19 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max)
|
|||
if(a1.num) x= (max - a0.num) / a1.num;
|
||||
if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den);
|
||||
|
||||
if (den*(2*x*a1.den + a0.den) > nom*a1.den)
|
||||
if (den*(2*x*a1.den + a0.den) > num*a1.den)
|
||||
a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den};
|
||||
break;
|
||||
}
|
||||
|
||||
a0= a1;
|
||||
a1= (AVRational){a2n, a2d};
|
||||
nom= den;
|
||||
num= den;
|
||||
den= next_den;
|
||||
}
|
||||
assert(ff_gcd(a1.num, a1.den) <= 1U);
|
||||
assert(av_gcd(a1.num, a1.den) <= 1U);
|
||||
|
||||
*dst_nom = sign ? -a1.num : a1.num;
|
||||
*dst_num = sign ? -a1.num : a1.num;
|
||||
*dst_den = a1.den;
|
||||
|
||||
return den==0;
|
||||
|
@ -101,3 +102,28 @@ AVRational av_d2q(double d, int max){
|
|||
|
||||
return a;
|
||||
}
|
||||
|
||||
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
|
||||
{
|
||||
/* n/d is q, a/b is the median between q1 and q2 */
|
||||
int64_t a = q1.num * (int64_t)q2.den + q2.num * (int64_t)q1.den;
|
||||
int64_t b = 2 * (int64_t)q1.den * q2.den;
|
||||
|
||||
/* rnd_up(a*d/b) > n => a*d/b > n */
|
||||
int64_t x_up = av_rescale_rnd(a, q.den, b, AV_ROUND_UP);
|
||||
|
||||
/* rnd_down(a*d/b) < n => a*d/b < n */
|
||||
int64_t x_down = av_rescale_rnd(a, q.den, b, AV_ROUND_DOWN);
|
||||
|
||||
return ((x_up > q.num) - (x_down < q.num)) * av_cmp_q(q2, q1);
|
||||
}
|
||||
|
||||
int av_find_nearest_q_idx(AVRational q, const AVRational* q_list)
|
||||
{
|
||||
int i, nearest_q_idx = 0;
|
||||
for(i=0; q_list[i].den; i++)
|
||||
if (av_nearer_q(q, q_list[i], q_list[nearest_q_idx]) > 0)
|
||||
nearest_q_idx = i;
|
||||
|
||||
return nearest_q_idx;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Rational numbers
|
||||
* rational numbers
|
||||
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
|
@ -20,19 +20,19 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file rational.h
|
||||
* Rational numbers.
|
||||
* @file libavutil/rational.h
|
||||
* rational numbers
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RATIONAL_H
|
||||
#define FFMPEG_RATIONAL_H
|
||||
#ifndef AVUTIL_RATIONAL_H
|
||||
#define AVUTIL_RATIONAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Rational number num/den.
|
||||
* rational number numerator/denominator
|
||||
*/
|
||||
typedef struct AVRational{
|
||||
int num; ///< numerator
|
||||
|
@ -40,10 +40,10 @@ typedef struct AVRational{
|
|||
} AVRational;
|
||||
|
||||
/**
|
||||
* Compare two rationals.
|
||||
* Compares two rationals.
|
||||
* @param a first rational
|
||||
* @param b second rational
|
||||
* @return 0 if a==b, 1 if a>b and -1 if a<b.
|
||||
* @return 0 if a==b, 1 if a>b and -1 if a<b
|
||||
*/
|
||||
static inline int av_cmp_q(AVRational a, AVRational b){
|
||||
const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
|
||||
|
@ -53,7 +53,7 @@ static inline int av_cmp_q(AVRational a, AVRational b){
|
|||
}
|
||||
|
||||
/**
|
||||
* Rational to double conversion.
|
||||
* Converts rational to double.
|
||||
* @param a rational to convert
|
||||
* @return (double) a
|
||||
*/
|
||||
|
@ -62,46 +62,46 @@ static inline double av_q2d(AVRational a){
|
|||
}
|
||||
|
||||
/**
|
||||
* Reduce a fraction.
|
||||
* Reduces a fraction.
|
||||
* This is useful for framerate calculations.
|
||||
* @param dst_nom destination numerator
|
||||
* @param dst_num destination numerator
|
||||
* @param dst_den destination denominator
|
||||
* @param nom source numerator
|
||||
* @param num source numerator
|
||||
* @param den source denominator
|
||||
* @param max the maximum allowed for dst_nom & dst_den
|
||||
* @param max the maximum allowed for dst_num & dst_den
|
||||
* @return 1 if exact, 0 otherwise
|
||||
*/
|
||||
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
|
||||
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max);
|
||||
|
||||
/**
|
||||
* Multiplies two rationals.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b*c.
|
||||
* @param b first rational
|
||||
* @param c second rational
|
||||
* @return b*c
|
||||
*/
|
||||
AVRational av_mul_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Divides one rational by another.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b/c.
|
||||
* @param b first rational
|
||||
* @param c second rational
|
||||
* @return b/c
|
||||
*/
|
||||
AVRational av_div_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Adds two rationals.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b+c.
|
||||
* @param b first rational
|
||||
* @param c second rational
|
||||
* @return b+c
|
||||
*/
|
||||
AVRational av_add_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
/**
|
||||
* Subtracts one rational from another.
|
||||
* @param b first rational.
|
||||
* @param c second rational.
|
||||
* @return b-c.
|
||||
* @param b first rational
|
||||
* @param c second rational
|
||||
* @return b-c
|
||||
*/
|
||||
AVRational av_sub_q(AVRational b, AVRational c) av_const;
|
||||
|
||||
|
@ -109,8 +109,21 @@ AVRational av_sub_q(AVRational b, AVRational c) av_const;
|
|||
* Converts a double precision floating point number to a rational.
|
||||
* @param d double to convert
|
||||
* @param max the maximum allowed numerator and denominator
|
||||
* @return (AVRational) d.
|
||||
* @return (AVRational) d
|
||||
*/
|
||||
AVRational av_d2q(double d, int max) av_const;
|
||||
|
||||
#endif /* FFMPEG_RATIONAL_H */
|
||||
/**
|
||||
* @return 1 if \q1 is nearer to \p q than \p q2, -1 if \p q2 is nearer
|
||||
* than \p q1, 0 if they have the same distance.
|
||||
*/
|
||||
int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
|
||||
|
||||
/**
|
||||
* Finds the nearest value in \p q_list to \p q.
|
||||
* @param q_list an array of rationals terminated by {0, 0}
|
||||
* @return the index of the nearest value found in the array
|
||||
*/
|
||||
int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
|
||||
|
||||
#endif /* AVUTIL_RATIONAL_H */
|
||||
|
|
|
@ -20,13 +20,19 @@
|
|||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "avutil.h"
|
||||
#include "common.h"
|
||||
#include "rc4.h"
|
||||
|
||||
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) {
|
||||
typedef struct AVRC4 AVRC4;
|
||||
|
||||
int av_rc4_init(AVRC4 *r, const uint8_t *key, int key_bits, int decrypt) {
|
||||
int i, j;
|
||||
uint8_t x, y;
|
||||
uint8_t state[256];
|
||||
uint8_t y;
|
||||
uint8_t *state = r->state;
|
||||
int keylen = key_bits >> 3;
|
||||
if (key_bits & 7)
|
||||
return -1;
|
||||
for (i = 0; i < 256; i++)
|
||||
state[i] = i;
|
||||
y = 0;
|
||||
|
@ -36,13 +42,28 @@ void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) {
|
|||
y += state[i] + key[j];
|
||||
FFSWAP(uint8_t, state[i], state[y]);
|
||||
}
|
||||
// state initialized, now do the real encryption
|
||||
x = 1; y = state[1];
|
||||
while (datalen-- > 0) {
|
||||
r->x = 1;
|
||||
r->y = state[1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void av_rc4_crypt(AVRC4 *r, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) {
|
||||
uint8_t x = r->x, y = r->y;
|
||||
uint8_t *state = r->state;
|
||||
while (count-- > 0) {
|
||||
uint8_t sum = state[x] + state[y];
|
||||
FFSWAP(uint8_t, state[x], state[y]);
|
||||
*data++ ^= state[sum];
|
||||
*dst++ = src ? *src++ ^ state[sum] : state[sum];
|
||||
x++;
|
||||
y += state[x];
|
||||
}
|
||||
r->x = x; r->y = y;
|
||||
}
|
||||
|
||||
#if LIBAVUTIL_VERSION_MAJOR < 50
|
||||
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) {
|
||||
AVRC4 r;
|
||||
av_rc4_init(&r, key, keylen * 8, 0);
|
||||
av_rc4_crypt(&r, data, data, datalen, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,11 +18,33 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_RC4_H
|
||||
#define FFMPEG_RC4_H
|
||||
#ifndef AVUTIL_RC4_H
|
||||
#define AVUTIL_RC4_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen);
|
||||
struct AVRC4 {
|
||||
uint8_t state[256];
|
||||
int x, y;
|
||||
};
|
||||
|
||||
#endif /* FFMPEG_RC4_H */
|
||||
/**
|
||||
* \brief Initializes an AVRC4 context.
|
||||
*
|
||||
* \param key_bits must be a multiple of 8
|
||||
* \param decrypt 0 for encryption, 1 for decryption, currently has no effect
|
||||
*/
|
||||
int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt);
|
||||
|
||||
/**
|
||||
* \brief Encrypts / decrypts using the RC4 algorithm.
|
||||
*
|
||||
* \param count number of bytes
|
||||
* \param dst destination array, can be equal to src
|
||||
* \param src source array, can be equal to dst, may be NULL
|
||||
* \param iv not (yet) used for RC4, should be NULL
|
||||
* \param decrypt 0 for encryption, 1 for decryption, not (yet) used
|
||||
*/
|
||||
void av_rc4_crypt(struct AVRC4 *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
|
||||
|
||||
#endif /* AVUTIL_RC4_H */
|
||||
|
|
|
@ -54,7 +54,7 @@ static void transform(uint32_t state[5], const uint8_t buffer[64]){
|
|||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
for(i=0; i<80; i++){
|
||||
int t;
|
||||
if(i<16) t= be2me_32(((uint32_t*)buffer)[i]);
|
||||
|
@ -110,7 +110,7 @@ void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len){
|
|||
|
||||
j = ctx->count & 63;
|
||||
ctx->count += len;
|
||||
#ifdef CONFIG_SMALL
|
||||
#if CONFIG_SMALL
|
||||
for( i = 0; i < len; i++ ){
|
||||
ctx->buffer[ j++ ] = data[i];
|
||||
if( 64 == j ){
|
||||
|
@ -145,8 +145,6 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){
|
|||
((uint32_t*)digest)[i]= be2me_32(ctx->state[i]);
|
||||
}
|
||||
|
||||
// use the following to test
|
||||
// gcc -DTEST -DHAVE_AV_CONFIG_H -I.. sha1.c -O2 -W -Wall -o sha1 && time ./sha1
|
||||
#ifdef TEST
|
||||
#include <stdio.h>
|
||||
#undef printf
|
||||
|
@ -170,7 +168,7 @@ int main(void){
|
|||
printf("%02X", digest[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
//Test Vectors (from FIPS PUB 180-1)
|
||||
//test vectors (from FIPS PUB 180-1)
|
||||
printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
|
||||
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
|
||||
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_SHA1_H
|
||||
#define FFMPEG_SHA1_H
|
||||
#ifndef AVUTIL_SHA1_H
|
||||
#define AVUTIL_SHA1_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -31,4 +31,4 @@ void av_sha1_init(struct AVSHA1* context);
|
|||
void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len);
|
||||
void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]);
|
||||
|
||||
#endif /* FFMPEG_SHA1_H */
|
||||
#endif /* AVUTIL_SHA1_H */
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "softfloat.h"
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef printf
|
||||
|
||||
int main(void){
|
||||
SoftFloat one= av_int2sf(1, 0);
|
||||
SoftFloat sf1, sf2;
|
||||
double d1, d2;
|
||||
int i, j;
|
||||
av_log_level = AV_LOG_DEBUG;
|
||||
|
||||
d1= 1;
|
||||
for(i= 0; i<10; i++){
|
||||
d1= 1/(d1+1);
|
||||
}
|
||||
printf("test1 double=%d\n", (int)(d1 * (1<<24)));
|
||||
|
||||
sf1= one;
|
||||
for(i= 0; i<10; i++){
|
||||
sf1= av_div_sf(one, av_normalize_sf(av_add_sf(one, sf1)));
|
||||
}
|
||||
printf("test1 sf =%d\n", av_sf2int(sf1, 24));
|
||||
|
||||
|
||||
for(i= 0; i<100; i++){
|
||||
START_TIMER
|
||||
d1= i;
|
||||
d2= i/100.0;
|
||||
for(j= 0; j<1000; j++){
|
||||
d1= (d1+1)*d2;
|
||||
}
|
||||
STOP_TIMER("float add mul")
|
||||
}
|
||||
printf("test2 double=%d\n", (int)(d1 * (1<<24)));
|
||||
|
||||
for(i= 0; i<100; i++){
|
||||
START_TIMER
|
||||
sf1= av_int2sf(i, 0);
|
||||
sf2= av_div_sf(av_int2sf(i, 2), av_int2sf(200, 3));
|
||||
for(j= 0; j<1000; j++){
|
||||
sf1= av_mul_sf(av_add_sf(sf1, one),sf2);
|
||||
}
|
||||
STOP_TIMER("softfloat add mul")
|
||||
}
|
||||
printf("test2 sf =%d (%d %d)\n", av_sf2int(sf1, 24), sf1.exp, sf1.mant);
|
||||
return 0;
|
||||
}
|
|
@ -18,8 +18,8 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_SOFTFLOAT_H
|
||||
#define FFMPEG_SOFTFLOAT_H
|
||||
#ifndef AVUTIL_SOFTFLOAT_H
|
||||
#define AVUTIL_SOFTFLOAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
@ -72,10 +72,9 @@ static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return will not be more denormalized then a+b, so if either input is
|
||||
* normalized then the output will not be worse then the other input
|
||||
* if both are normalized then the output will be normalized
|
||||
* @return Will not be more denormalized than a+b. So if either input is
|
||||
* normalized, then the output will not be worse then the other input.
|
||||
* If both are normalized, then the output will be normalized.
|
||||
*/
|
||||
static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
|
||||
a.exp += b.exp;
|
||||
|
@ -84,9 +83,8 @@ static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* b has to be normalized and not zero
|
||||
* @return will not be more denormalized then a
|
||||
* b has to be normalized and not zero.
|
||||
* @return Will not be more denormalized than a.
|
||||
*/
|
||||
static av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
|
||||
a.exp -= b.exp+1;
|
||||
|
@ -117,8 +115,7 @@ static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rounding is to -inf
|
||||
* Rounding is to -inf.
|
||||
*/
|
||||
static inline av_const int av_sf2int(SoftFloat v, int frac_bits){
|
||||
v.exp += frac_bits - ONE_BITS;
|
||||
|
@ -126,4 +123,4 @@ static inline av_const int av_sf2int(SoftFloat v, int frac_bits){
|
|||
else return v.mant >>(-v.exp);
|
||||
}
|
||||
|
||||
#endif /* FFMPEG_SOFTFLOAT_H */
|
||||
#endif /* AVUTIL_SOFTFLOAT_H */
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* @file libavutil/timer.h
|
||||
* high precision timer, useful to profile code
|
||||
*
|
||||
* 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_TIMER_H
|
||||
#define AVUTIL_TIMER_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#if ARCH_X86 || ARCH_PPC || ARCH_BFIN
|
||||
#define AV_READ_TIME read_time
|
||||
#if ARCH_X86
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint32_t a, d;
|
||||
__asm__ volatile("rdtsc\n\t"
|
||||
: "=a" (a), "=d" (d));
|
||||
return ((uint64_t)d << 32) + a;
|
||||
}
|
||||
#elif ARCH_BFIN
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned lo;
|
||||
unsigned hi;
|
||||
} p;
|
||||
unsigned long long c;
|
||||
} t;
|
||||
__asm__ volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi));
|
||||
return t.c;
|
||||
}
|
||||
#else //FIXME check ppc64
|
||||
static inline uint64_t read_time(void)
|
||||
{
|
||||
uint32_t tbu, tbl, temp;
|
||||
|
||||
/* from section 2.2.1 of the 32-bit PowerPC PEM */
|
||||
__asm__ volatile(
|
||||
"1:\n"
|
||||
"mftbu %2\n"
|
||||
"mftb %0\n"
|
||||
"mftbu %1\n"
|
||||
"cmpw %2,%1\n"
|
||||
"bne 1b\n"
|
||||
: "=r"(tbl), "=r"(tbu), "=r"(temp)
|
||||
:
|
||||
: "cc");
|
||||
|
||||
return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
|
||||
}
|
||||
#endif
|
||||
#elif HAVE_GETHRTIME
|
||||
#define AV_READ_TIME gethrtime
|
||||
#endif
|
||||
|
||||
#ifdef AV_READ_TIME
|
||||
#define START_TIMER \
|
||||
uint64_t tend;\
|
||||
uint64_t tstart= AV_READ_TIME();\
|
||||
|
||||
#define STOP_TIMER(id) \
|
||||
tend= AV_READ_TIME();\
|
||||
{\
|
||||
static uint64_t tsum=0;\
|
||||
static int tcount=0;\
|
||||
static int tskip_count=0;\
|
||||
if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\
|
||||
tsum+= tend - tstart;\
|
||||
tcount++;\
|
||||
}else\
|
||||
tskip_count++;\
|
||||
if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
|
||||
av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\
|
||||
tsum*10/tcount, id, tcount, tskip_count);\
|
||||
}\
|
||||
}
|
||||
#else
|
||||
#define START_TIMER
|
||||
#define STOP_TIMER(id) {}
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_TIMER_H */
|
|
@ -119,15 +119,20 @@ void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const voi
|
|||
return ret;
|
||||
}else{
|
||||
*tp= *next; *next= NULL;
|
||||
(*tp)->elem= key;
|
||||
return NULL;
|
||||
if(*tp){
|
||||
(*tp)->elem= key;
|
||||
return NULL;
|
||||
}else
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
void av_tree_destroy(AVTreeNode *t){
|
||||
av_tree_destroy(t->child[0]);
|
||||
av_tree_destroy(t->child[1]);
|
||||
av_free(t);
|
||||
if(t){
|
||||
av_tree_destroy(t->child[0]);
|
||||
av_tree_destroy(t->child[1]);
|
||||
av_free(t);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -188,14 +193,13 @@ int main(void){
|
|||
av_tree_insert(&root, (void*)(j+1), cmp, &node);
|
||||
|
||||
j= (random()%86294);
|
||||
k= av_tree_find(root, (void*)(j+1), cmp, NULL);
|
||||
if(k){
|
||||
{
|
||||
AVTreeNode *node2=NULL;
|
||||
av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j);
|
||||
av_tree_insert(&root, (void*)(j+1), cmp, &node2);
|
||||
k= av_tree_find(root, (void*)(j+1), cmp, NULL);
|
||||
if(k)
|
||||
av_log(NULL, AV_LOG_ERROR, "removial failure %d\n", i);
|
||||
av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file tree.h
|
||||
* @file libavutil/tree.h
|
||||
* A tree container.
|
||||
* Insertion, Removial, Finding equal, largest which is smaller than and
|
||||
* smallest which is larger than all have O(log n) worst case time.
|
||||
* Insertion, removal, finding equal, largest which is smaller than and
|
||||
* smallest which is larger than, all have O(log n) worst case complexity.
|
||||
* @author Michael Niedermayer <michaelni@gmx.at>
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_TREE_H
|
||||
#define FFMPEG_TREE_H
|
||||
#ifndef AVUTIL_TREE_H
|
||||
#define AVUTIL_TREE_H
|
||||
|
||||
struct AVTreeNode;
|
||||
extern const int av_tree_node_size;
|
||||
|
@ -35,8 +35,8 @@ extern const int av_tree_node_size;
|
|||
/**
|
||||
* Finds an element.
|
||||
* @param root a pointer to the root node of the tree
|
||||
* @param next If next is not NULL then next[0] will contain the previous
|
||||
* element and next[1] the next element if either does not exist
|
||||
* @param next If next is not NULL, then next[0] will contain the previous
|
||||
* element and next[1] the next element. If either does not exist,
|
||||
* then the corresponding entry in next is unchanged.
|
||||
* @return An element with cmp(key, elem)==0 or NULL if no such element exists in
|
||||
* the tree.
|
||||
|
@ -45,11 +45,10 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke
|
|||
|
||||
/**
|
||||
* Inserts or removes an element.
|
||||
* If *next is NULL then the element supplied will be removed, if no such
|
||||
* element exists behavior is undefined.
|
||||
* If *next is not NULL then the element supplied will be inserted, unless
|
||||
* If *next is NULL, then the supplied element will be removed if it exists.
|
||||
* If *next is not NULL, then the supplied element will be inserted, unless
|
||||
* it already exists in the tree.
|
||||
* @param rootp A pointer to a pointer to the root node of the tree. Note that
|
||||
* @param rootp A pointer to a pointer to the root node of the tree; note that
|
||||
* the root node can change during insertions, this is required
|
||||
* to keep the tree balanced.
|
||||
* @param next Used to allocate and free AVTreeNodes. For insertion the user
|
||||
|
@ -71,12 +70,12 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke
|
|||
* return av_tree_insert(rootp, key, cmp, next);
|
||||
* }
|
||||
*
|
||||
* @return If no insertion happened, the found element.
|
||||
* If an insertion or removial happened, then either key or NULL will be returned.
|
||||
* @return If no insertion happened, the found element; if an insertion or
|
||||
removal happened, then either key or NULL will be returned.
|
||||
* Which one it is depends on the tree state and the implementation. You
|
||||
* should make no assumptions that it's one or the other in the code.
|
||||
*/
|
||||
void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next);
|
||||
void av_tree_destroy(struct AVTreeNode *t);
|
||||
|
||||
#endif /* FFMPEG_TREE_H */
|
||||
#endif /* AVUTIL_TREE_H */
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 libavutil/x86/bswap.h
|
||||
* byte swapping routines
|
||||
*/
|
||||
|
||||
#ifndef AVUTIL_X86_BSWAP_H
|
||||
#define AVUTIL_X86_BSWAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
#include "libavutil/common.h"
|
||||
|
||||
#define bswap_16 bswap_16
|
||||
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
__asm__("rorw $8, %0" : "+r"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
#define bswap_32 bswap_32
|
||||
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
#if HAVE_BSWAP
|
||||
__asm__("bswap %0" : "+r" (x));
|
||||
#else
|
||||
__asm__("rorw $8, %w0 \n\t"
|
||||
"rorl $16, %0 \n\t"
|
||||
"rorw $8, %w0"
|
||||
: "+r"(x));
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
#if ARCH_X86_64
|
||||
#define bswap_64 bswap_64
|
||||
static inline uint64_t av_const bswap_64(uint64_t x)
|
||||
{
|
||||
__asm__("bswap %0": "=r" (x) : "0" (x));
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AVUTIL_X86_BSWAP_H */
|
|
@ -18,13 +18,13 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FFMPEG_X86CPU_H
|
||||
#define FFMPEG_X86CPU_H
|
||||
#ifndef AVUTIL_X86_CPU_H
|
||||
#define AVUTIL_X86_CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ARCH_X86_64
|
||||
#if ARCH_X86_64
|
||||
# define REG_a "rax"
|
||||
# define REG_b "rbx"
|
||||
# define REG_c "rcx"
|
||||
|
@ -43,7 +43,7 @@ typedef int64_t x86_reg;
|
|||
# define REGd rdx
|
||||
# define REGSP rsp
|
||||
|
||||
#else
|
||||
#elif ARCH_X86_32
|
||||
|
||||
# define REG_a "eax"
|
||||
# define REG_b "ebx"
|
||||
|
@ -64,16 +64,11 @@ typedef int32_t x86_reg;
|
|||
# define REGSP esp
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(HAVE_EBX_AVAILABLE) && defined(HAVE_EBP_AVAILABLE))
|
||||
# define HAVE_7REGS 1
|
||||
#endif
|
||||
#define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))
|
||||
#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE))
|
||||
|
||||
#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && (defined(HAVE_EBX_AVAILABLE) || defined(HAVE_EBP_AVAILABLE)))
|
||||
# define HAVE_6REGS 1
|
||||
#endif
|
||||
|
||||
#if defined(ARCH_X86_64) && defined(PIC)
|
||||
#if ARCH_X86_64 && defined(PIC)
|
||||
# define BROKEN_RELOCATIONS 1
|
||||
#endif
|
||||
|
||||
#endif /* FFMPEG_X86CPU_H */
|
||||
#endif /* AVUTIL_X86_CPU_H */
|
||||
|
|
Loading…
Reference in New Issue