1
0
Fork 0
forked from len0rd/rockbox

-Remove all dynamic allocations, hence remove cook_decode_close() which was basically

needed for freeing allocated memory.
-Remove any ffmpeg-specific attributes (av_const,av_always_inline .. etc.).
-Move some math functions to cook_fixpoint.h - libavutil/common.h is no longer 
needed.
-Remove libavutil/mem.[c/h], libavutil/common.h and libavutil/internal.h.
-Fix a warning in cookdata_fixpoint.h.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20922 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Mohamed Tarek 2009-05-12 20:50:35 +00:00
parent 49fccaf2d9
commit 49ba646d57
13 changed files with 91 additions and 971 deletions

View file

@ -1,5 +1,5 @@
CFLAGS = -Wall -O3
OBJS = main.o bitstream.o cook.o libavutil/mem.o rm2wav.o
OBJS = main.o bitstream.o cook.o rm2wav.o
cooktest: $(OBJS)
gcc -o cooktest $(OBJS)

View file

@ -45,6 +45,8 @@ const uint8_t ff_log2_run[32]={
* @deprecated. Code which uses ff_realloc_static is broken/misdesigned
* and should correctly use static arrays
*/
#if 0
attribute_deprecated av_alloc_size(2)
static void *ff_realloc_static(void *ptr, unsigned int size);
@ -61,6 +63,7 @@ void align_put_bits(PutBitContext *s)
put_bits(s,s->bit_left & 7,0);
#endif
}
#endif
void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
{
@ -123,15 +126,11 @@ static int alloc_table(VLC *vlc, int size, int use_static)
index = vlc->table_size;
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
if(use_static>1)
if(use_static>1){
printf("init_vlc() used with too little memory : table_size > allocated_memory\n");
abort(); //cant do anything, init_vlc() is used with too little memory
vlc->table_allocated += (1 << vlc->bits);
if(use_static)
vlc->table = ff_realloc_static(vlc->table,
sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
else
vlc->table = av_realloc(vlc->table,
sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
}
if (!vlc->table)
return -1;
}
@ -305,10 +304,13 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
codes, codes_wrap, codes_size,
symbols, symbols_wrap, symbols_size,
0, 0, flags) < 0) {
av_freep(&vlc->table);
free(&vlc->table);
return -1;
}
if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
/* Changed the following condition to be true if table_size > table_allocated. *
* This would be more sensible for static tables since we want warnings for *
* memory shortages only. */
if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated)
printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated);
return 0;
}
@ -316,6 +318,6 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
void free_vlc(VLC *vlc)
{
av_freep(&vlc->table);
free(&vlc->table);
}

View file

@ -29,10 +29,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "libavutil/bswap.h"
#include "libavutil/common.h"
//#include "libavutil/log.h"
//#include "mathops.h"
/* The following 2 defines are taken from libavutil/intreadwrite.h */
#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
@ -881,7 +880,7 @@ void free_vlc(VLC *vlc);
* read the longest vlc code
* = (max_vlc_length + bits - 1) / bits
*/
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
static inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
int bits, int max_depth)
{
int code;

View file

@ -45,22 +45,12 @@
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include "cook.h"
#include "cookdata.h"
/* The following table is taken from libavutil/mathematics.c */
const uint8_t ff_log2_tab[256]={
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
};
/* the different Cook versions */
#define MONO 0x1000001
#define STEREO 0x1000002
@ -112,26 +102,35 @@ static void dump_short_table(short* table, int size, int delimiter) {
#endif
/*************** init functions ***************/
static av_cold int init_cook_vlc_tables(COOKContext *q) {
#define VLCBUFSIZE 1500
VLC_TYPE vlcbuf[21][VLCBUFSIZE][2];
static int init_cook_vlc_tables(COOKContext *q) {
int i, result;
result = 0;
for (i=0 ; i<13 ; i++) {
q->envelope_quant_index[i].table = vlcbuf[i];
q->envelope_quant_index[i].table_allocated = VLCBUFSIZE;
result |= init_vlc (&q->envelope_quant_index[i], 9, 24,
envelope_quant_index_huffbits[i], 1, 1,
envelope_quant_index_huffcodes[i], 2, 2, 0);
envelope_quant_index_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
DEBUGF("sqvh VLC init\n");
for (i=0 ; i<7 ; i++) {
q->sqvh[i].table = vlcbuf[i+13];
q->sqvh[i].table_allocated = VLCBUFSIZE;
result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
cvh_huffbits[i], 1, 1,
cvh_huffcodes[i], 2, 2, 0);
cvh_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
if (q->nb_channels==2 && q->joint_stereo==1){
q->ccpl.table = vlcbuf[20];
q->ccpl.table_allocated = VLCBUFSIZE;
result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, INIT_VLC_USE_NEW_STATIC);
DEBUGF("Joint-stereo VLC used.\n");
}
@ -184,35 +183,6 @@ static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes)
return off;
}
/**
* Cook uninit
*/
av_cold int cook_decode_close(COOKContext *q)
{
int i;
//COOKContext *q = avctx->priv_data;
DEBUGF( "Deallocating memory.\n");
/* Free allocated memory buffers. */
av_free(q->decoded_bytes_buffer);
/* Free the VLC tables. */
for (i=0 ; i<13 ; i++) {
free_vlc(&q->envelope_quant_index[i]);
}
for (i=0 ; i<7 ; i++) {
free_vlc(&q->sqvh[i]);
}
if(q->nb_channels==2 && q->joint_stereo==1 ){
free_vlc(&q->ccpl);
}
DEBUGF("Memory deallocated.\n");
return 0;
}
/**
* Fill the gain array for the timedomain quantization.
*
@ -739,7 +709,7 @@ static void dump_cook_context(COOKContext *q)
* Cook initialization
*/
av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
int cook_decode_init(RMContext *rmctx, COOKContext *q)
{
/* cook extradata */
q->cookversion = rmctx->cook_version;
@ -822,25 +792,6 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
if(q->block_align >= UINT_MAX/2)
return -1;
/* Pad the databuffer with:
DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(),
INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */
#define INPUT_BUFFER_PADDING_SIZE 8
if (q->nb_channels==2 && q->joint_stereo==0) {
q->decoded_bytes_buffer =
av_mallocz(rmctx->block_align/2
+ DECODE_BYTES_PAD2(q->block_align/2)
+ INPUT_BUFFER_PADDING_SIZE);
} else {
q->decoded_bytes_buffer =
av_mallocz(rmctx->block_align
+ DECODE_BYTES_PAD1(q->block_align)
+ INPUT_BUFFER_PADDING_SIZE);
}
if (q->decoded_bytes_buffer == NULL)
return -1;
q->gains1.now = q->gain_1;
q->gains1.previous = q->gain_2;
q->gains2.now = q->gain_3;

View file

@ -34,7 +34,7 @@ typedef struct {
typedef struct cook {
/*
* The following 5 functions provide the lowlevel arithmetic on
* The following 2 functions provide the lowlevel arithmetic on
* the internal audio buffers.
*/
void (* scalar_dequant)(struct cook *q, int index, int quant_index,
@ -86,7 +86,7 @@ typedef struct cook {
/* data buffers */
uint8_t* decoded_bytes_buffer;
uint8_t decoded_bytes_buffer[1024];
REAL_T mono_mdct_output[2048] __attribute__ ((aligned(16)));
REAL_T mono_previous_buffer1[1024];
REAL_T mono_previous_buffer2[1024];
@ -95,9 +95,8 @@ typedef struct cook {
REAL_T decode_buffer_0[1060]; /* static allocation for joint decode */
} COOKContext;
av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q);
int cook_decode_init(RMContext *rmctx, COOKContext *q);
int cook_decode_frame(RMContext *rmctx,COOKContext *q,
int16_t *outbuffer, int *data_size,
const uint8_t *inbuffer, int buf_size);
av_cold int cook_decode_close(COOKContext *q);
#endif

View file

@ -35,6 +35,24 @@
* in C using two 32 bit integer multiplications.
*/
/* The following table is taken from libavutil/mathematics.c */
const uint8_t ff_log2_tab[256]={
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
};
/* cplscales was moved from cookdata_fixpoint.h since only *
* cook_fixpoint.h should see/use it. */
static const FIXPU* cplscales[5] = {
cplscale2, cplscale3, cplscale4, cplscale5, cplscale6
};
/**
* Initialise fixed point implementation.
* Nothing to do for fixed point.
@ -86,6 +104,37 @@ static inline FIXP fixp_mult_su(FIXP a, FIXPU b)
return hb + (lb >> 16) + ((lb & 0x8000) >> 15);
}
/* math functions taken from libavutil/common.h */
static inline int av_log2(unsigned int v)
{
int n = 0;
if (v & 0xffff0000) {
v >>= 16;
n += 16;
}
if (v & 0xff00) {
v >>= 8;
n += 8;
}
n += ff_log2_tab[v];
return n;
}
/**
* 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
* @return clipped value
*/
static inline int av_clip(int a, int amin, int amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
/**
* The real requantization of the mltcoefs

View file

@ -427,7 +427,3 @@ static const FIXPU cplscale6[63] = {
0x450d, 0x408b, 0x3bcd, 0x36c1, 0x314d, 0x2b4a, 0x246e, 0x1c1a, 0x1029
};
static const FIXPU* cplscales[5] = {
cplscale2, cplscale3, cplscale4, cplscale5, cplscale6
};

View file

@ -28,7 +28,7 @@
#include <stdint.h>
//#include "ffmpeg_config.h"
#include "common.h"
//#include "common.h"
#if ARCH_ARM
# include "arm/bswap.h"
@ -41,7 +41,7 @@
#endif
#ifndef bswap_16
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
static inline uint16_t bswap_16(uint16_t x)
{
x= (x>>8) | (x<<8);
return x;
@ -49,7 +49,7 @@ static av_always_inline av_const uint16_t bswap_16(uint16_t x)
#endif
#ifndef bswap_32
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
static inline uint32_t bswap_32(uint32_t x)
{
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
x= (x>>16) | (x<<16);
@ -58,7 +58,7 @@ static av_always_inline av_const uint32_t bswap_32(uint32_t x)
#endif
#ifndef bswap_64
static inline uint64_t av_const bswap_64(uint64_t x)
static inline uint64_t bswap_64(uint64_t x)
{
#if 0
x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);

View file

@ -1,286 +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
*/
/**
* @file libavutil/common.h
* common internal and external API header
*/
#ifndef AVUTIL_COMMON_H
#define AVUTIL_COMMON_H
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __GNUC__
# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
#else
# define AV_GCC_VERSION_AT_LEAST(x,y) 0
#endif
#ifndef av_always_inline
#if AV_GCC_VERSION_AT_LEAST(3,1)
# define av_always_inline __attribute__((always_inline)) inline
#else
# define av_always_inline inline
#endif
#endif
#ifndef av_noinline
#if AV_GCC_VERSION_AT_LEAST(3,1)
# define av_noinline __attribute__((noinline))
#else
# define av_noinline
#endif
#endif
#ifndef av_pure
#if AV_GCC_VERSION_AT_LEAST(3,1)
# define av_pure __attribute__((pure))
#else
# define av_pure
#endif
#endif
#ifndef av_const
#if AV_GCC_VERSION_AT_LEAST(2,6)
# define av_const __attribute__((const))
#else
# define av_const
#endif
#endif
#ifndef av_cold
#if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
# define av_cold __attribute__((cold))
#else
# define av_cold
#endif
#endif
#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 AV_GCC_VERSION_AT_LEAST(3,1)
# define attribute_deprecated __attribute__((deprecated))
#else
# define attribute_deprecated
#endif
#endif
#ifndef av_unused
#if defined(__GNUC__)
# define av_unused __attribute__((unused))
#else
# define av_unused
#endif
#endif
#ifndef av_uninit
#if defined(__GNUC__) && !defined(__ICC)
# define av_uninit(x) x=x
#else
# define av_uninit(x) x
#endif
#endif
//rounded division & shift
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
/* assume b>0 */
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
#define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
/* misc math functions */
extern const uint8_t ff_log2_tab[256];
static inline av_const int av_log2(unsigned int v)
{
int n = 0;
if (v & 0xffff0000) {
v >>= 16;
n += 16;
}
if (v & 0xff00) {
v >>= 8;
n += 8;
}
n += ff_log2_tab[v];
return n;
}
static inline av_const int av_log2_16bit(unsigned int v)
{
int n = 0;
if (v & 0xff00) {
v >>= 8;
n += 8;
}
n += ff_log2_tab[v];
return n;
}
/**
* 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
* @return clipped value
*/
static inline av_const int av_clip(int a, int amin, int amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
/**
* Clips a signed integer value into the 0-255 range.
* @param a value to clip
* @return clipped value
*/
static inline av_const uint8_t av_clip_uint8(int a)
{
if (a&(~255)) return (-a)>>31;
else return a;
}
/**
* Clips a signed integer value into the -32768,32767 range.
* @param a value to clip
* @return clipped value
*/
static inline av_const int16_t av_clip_int16(int a)
{
if ((a+32768) & ~65535) return (a>>31) ^ 32767;
else return a;
}
/**
* 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
* @return clipped value
*/
static inline av_const float av_clipf(float a, float amin, float amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
/*!
* \def GET_UTF8(val, GET_BYTE, ERROR)
* Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form
* \param val is the output and should be of type uint32_t. It holds the converted
* UCS-4 character and should be a left value.
* \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be
* a function or a statement whose return value or evaluated value is of type
* uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range,
* and up to 7 times in the general case.
* \param ERROR action that should be taken when an invalid UTF-8 byte is returned
* from GET_BYTE. It should be a statement that jumps out of the macro,
* like exit(), goto, return, break, or continue.
*/
#define GET_UTF8(val, GET_BYTE, ERROR)\
val= GET_BYTE;\
{\
int ones= 7 - av_log2(val ^ 255);\
if(ones==1)\
ERROR\
val&= 127>>ones;\
while(--ones > 0){\
int tmp= GET_BYTE - 128;\
if(tmp>>6)\
ERROR\
val= (val<<6) + tmp;\
}\
}
/*!
* \def PUT_UTF8(val, tmp, PUT_BYTE)
* Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
* \param val is an input-only argument and should be of type uint32_t. It holds
* a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
* val is given as a function it is executed only once.
* \param tmp is a temporary variable and should be of type uint8_t. It
* represents an intermediate value during conversion that is to be
* output by PUT_BYTE.
* \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
* It could be a function or a statement, and uses tmp as the input byte.
* For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
* executed up to 4 times for values in the valid UTF-8 range and up to
* 7 times in the general case, depending on the length of the converted
* Unicode character.
*/
#define PUT_UTF8(val, tmp, PUT_BYTE)\
{\
int bytes, shift;\
uint32_t in = val;\
if (in < 0x80) {\
tmp = in;\
PUT_BYTE\
} else {\
bytes = (av_log2(in) + 4) / 5;\
shift = (bytes - 1) * 6;\
tmp = (256 - (256 >> bytes)) | (in >> shift);\
PUT_BYTE\
while (shift >= 6) {\
shift -= 6;\
tmp = 0x80 | ((in >> shift) & 0x3f);\
PUT_BYTE\
}\
}\
}
#include "mem.h"
//#ifdef HAVE_AV_CONFIG_H
//# include "ffmpeg_config.h"
# include "internal.h"
//#endif /* HAVE_AV_CONFIG_H */
#endif /* AVUTIL_COMMON_H */

View file

@ -1,328 +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
*/
/**
* @file libavutil/internal.h
* common internal API header
*/
#ifndef AVUTIL_INTERNAL_H
#define AVUTIL_INTERNAL_H
#if !defined(DEBUG) && !defined(NDEBUG)
# define NDEBUG
#endif
#include <limits.h>
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
//#include "ffmpeg_config.h"
#include "common.h"
#include "mem.h"
//#include "timer.h"
#ifndef attribute_align_arg
#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
#endif
#endif
#ifndef attribute_used
#if AV_GCC_VERSION_AT_LEAST(3,1)
# define attribute_used __attribute__((used))
#else
# define attribute_used
#endif
#endif
#ifndef INT16_MIN
#define INT16_MIN (-0x7fff-1)
#endif
#ifndef INT16_MAX
#define INT16_MAX 0x7fff
#endif
#ifndef INT32_MIN
#define INT32_MIN (-0x7fffffff-1)
#endif
#ifndef INT32_MAX
#define INT32_MAX 0x7fffffff
#endif
#ifndef UINT32_MAX
#define UINT32_MAX 0xffffffff
#endif
#ifndef INT64_MIN
#define INT64_MIN (-0x7fffffffffffffffLL-1)
#endif
#ifndef INT64_MAX
#define INT64_MAX INT64_C(9223372036854775807)
#endif
#ifndef UINT64_MAX
#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
#endif
#ifndef INT_BIT
# define INT_BIT (CHAR_BIT * sizeof(int))
#endif
#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
# define PIC
#endif
#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 ARCH_X86_64 && defined(PIC)
# define LOCAL_MANGLE(a) #a "(%%rip)"
#else
# define LOCAL_MANGLE(a) #a
#endif
#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
/* debug stuff */
/* dprintf macros */
#ifdef DEBUG
# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
#else
# define dprintf(pctx, ...)
#endif
#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
/* math */
extern const uint32_t ff_inverse[256];
#if ARCH_X86
# define FASTDIV(a,b) \
({\
int ret,dmy;\
__asm__ volatile(\
"mull %3"\
:"=d"(ret),"=a"(dmy)\
:"1"(a),"g"(ff_inverse[b])\
);\
ret;\
})
#elif HAVE_ARMV6 && HAVE_INLINE_ASM
static inline av_const int FASTDIV(int a, int 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 ARCH_ARM && HAVE_INLINE_ASM
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))
#endif
extern const uint8_t ff_sqrt_tab[256];
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;
#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
else{
int s= av_log2_16bit(a>>16)>>1;
unsigned int c= a>>(s+2);
b= ff_sqrt_tab[c>>(s+8)];
b= FASTDIV(c,b) + (b<<s);
}
return b - (a<b*b);
}
#if ARCH_X86
#define MASK_ABS(mask, level)\
__asm__ volatile(\
"cltd \n\t"\
"xorl %1, %0 \n\t"\
"subl %1, %0 \n\t"\
: "+a" (level), "=&d" (mask)\
);
#else
#define MASK_ABS(mask, level)\
mask= level>>31;\
level= (level^mask)-mask;
#endif
#if HAVE_CMOV
#define COPY3_IF_LT(x,y,a,b,c,d)\
__asm__ volatile (\
"cmpl %0, %3 \n\t"\
"cmovl %3, %0 \n\t"\
"cmovl %4, %1 \n\t"\
"cmovl %5, %2 \n\t"\
: "+&r" (x), "+&r" (a), "+r" (c)\
: "r" (y), "r" (b), "r" (d)\
);
#else
#define COPY3_IF_LT(x,y,a,b,c,d)\
if((y)<(x)){\
(x)=(y);\
(a)=(b);\
(c)=(d);\
}
#endif
/* avoid usage of dangerous/inappropriate system functions */
#undef malloc
#define malloc please_use_av_malloc
#undef free
#define free please_use_av_free
#undef realloc
#define realloc please_use_av_realloc
#undef time
#define time time_is_forbidden_due_to_security_issues
//#undef rand
//#define rand rand_is_forbidden_due_to_state_trashing_use_av_random
//#undef srand
//#define srand srand_is_forbidden_due_to_state_trashing_use_av_random_init
#undef random
#define random random_is_forbidden_due_to_state_trashing_use_av_random
#undef sprintf
#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
#undef strcat
#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
#undef exit
#define exit exit_is_forbidden
#ifndef LIBAVFORMAT_BUILD
//#undef printf
//#define printf please_use_av_log_instead_of_printf
#undef fprintf
#define fprintf please_use_av_log_instead_of_fprintf
#undef puts
#define puts please_use_av_log_instead_of_puts
#undef perror
#define perror please_use_av_log_instead_of_perror
#endif
#define CHECKED_ALLOCZ(p, size)\
{\
p= av_mallocz(size);\
if(p==NULL && (size)!=0){\
av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\
goto fail;\
}\
}
#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 */
#if !HAVE_LRINT
static av_always_inline av_const long int lrint(double x)
{
return rint(x);
}
#endif /* HAVE_LRINT */
#if !HAVE_LRINTF
static av_always_inline av_const long int lrintf(float x)
{
return (int)(rint(x));
}
#endif /* HAVE_LRINTF */
#if !HAVE_ROUND
static av_always_inline av_const double round(double x)
{
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif /* HAVE_ROUND */
#if !HAVE_ROUNDF
static av_always_inline av_const float roundf(float x)
{
return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
}
#endif /* HAVE_ROUNDF */
#if !HAVE_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 */

View file

@ -1,158 +0,0 @@
/*
* default memory allocator for libavutil
* Copyright (c) 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file libavutil/mem.c
* default memory allocator for libavutil
*/
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#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. */
void *av_malloc(unsigned int size)
{
void *ptr = NULL;
#if CONFIG_MEMALIGN_HACK
long diff;
#endif
/* let's disallow possible ambiguous cases */
if(size > (INT_MAX-16) )
return NULL;
#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 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 64 for K7 (maybe for P3 too).
Because L1 and L2 caches are aligned on those values.
But I don't want to code such logic here!
*/
/* Why 16?
Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
it will just trigger an exception and the unaligned load will be done in the
exception handler or it will just segfault (SSE2 on P4).
Why not larger? Because I did not see a difference in benchmarks ...
*/
/* benchmarks with P3
memalign(64)+1 3071,3051,3032
memalign(64)+2 3051,3032,3041
memalign(64)+4 2911,2896,2915
memalign(64)+8 2545,2554,2550
memalign(64)+16 2543,2572,2563
memalign(64)+32 2546,2545,2571
memalign(64)+64 2570,2533,2558
BTW, malloc seems to do 8-byte alignment by default here.
*/
#else
ptr = malloc(size);
#endif
return ptr;
}
void *av_realloc(void *ptr, unsigned int size)
{
#if CONFIG_MEMALIGN_HACK
int diff;
#endif
/* let's disallow possible ambiguous cases */
if(size > (INT_MAX-16) )
return NULL;
#if CONFIG_MEMALIGN_HACK
//FIXME this isn't aligned correctly, though it probably isn't needed
if(!ptr) return av_malloc(size);
diff= ((char*)ptr)[-1];
return (char*)realloc((char*)ptr - diff, size + diff) + diff;
#else
return realloc(ptr, size);
#endif
}
void av_free(void *ptr)
{
/* XXX: this test should not be needed on most libcs */
if (ptr)
#if CONFIG_MEMALIGN_HACK
free((char*)ptr - ((char*)ptr)[-1]);
#else
free(ptr);
#endif
}
void av_freep(void *arg)
{
void **ptr= (void**)arg;
av_free(*ptr);
*ptr = NULL;
}
void *av_mallocz(unsigned int size)
{
void *ptr = av_malloc(size);
if (ptr)
memset(ptr, 0, size);
return ptr;
}
char *av_strdup(const char *s)
{
char *ptr= NULL;
if(s){
int len = strlen(s) + 1;
ptr = av_malloc(len);
if (ptr)
memcpy(ptr, s, len);
}
return ptr;
}

View file

@ -1,104 +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
*/
/**
* @file libavutil/mem.h
* memory handling functions
*/
#ifndef AVUTIL_MEM_H
#define AVUTIL_MEM_H
#include "common.h"
#if AV_GCC_VERSION_AT_LEAST(3,1)
#define av_malloc_attrib __attribute__((__malloc__))
#else
#define av_malloc_attrib
#endif
#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
/**
* 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 the block cannot
* be allocated.
* @see av_mallocz()
*/
void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
/**
* 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 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);
/**
* 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.
* @note It is recommended that you use av_freep() instead.
* @see av_freep()
*/
void av_free(void *ptr);
/**
* Allocates a block of \p size bytes with alignment suitable for all
* memory accesses (including vectors if available on the CPU) and
* 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 be allocated.
* @see av_malloc()
*/
void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
/**
* 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 the string cannot be allocated.
*/
char *av_strdup(const char *s) av_malloc_attrib;
/**
* 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 /* AVUTIL_MEM_H */

View file

@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "rm2wav.h"
#include "cook.h"
@ -112,7 +113,6 @@ int main(int argc, char *argv[])
packet_count -= rmctx.audio_pkt_cnt;
rmctx.audio_pkt_cnt = 0;
}
cook_decode_close(&q);
close_wav(fd_dec,&rmctx);
close(fd);