⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.h

📁 This the source release kit for the following system configuration(s): - AMD Alchemy(TM) DBAu1200(
💻 H
字号:
/*
 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file common.h
 * common internal and external api header.
 */

#ifndef COMMON_H
#define COMMON_H

#ifdef _MIPS_LINUX_
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <ctype.h>
  #include <limits.h>
  typedef long long LONGLONG;
  typedef unsigned long DWORD;
  #define STATIC_FUNC static
  #ifdef assert
    #undef assert
  #endif
  #define assert(xx)
#else
  #include <windows.h>
  #ifdef USE_ASSERTS
    #include <assert.h>
  #else
    #define assert(x) 
  #endif
  #define inline _inline
  #define __attribute__(x) 
  #define __attribute(x)
  #define STATIC_FUNC static
#endif


#ifdef MEMCPY_FAST
  #include "memcpy_fast.h"
  #define memcpy memcpy_fast
#endif

#ifndef NAN
  #define NAN 0.0        /*TODO: FIXIT should be -> 0.0/0.0 */
  #define INF MAXDOUBLE  /*TODO: FIXIT should be -> 1/0.0 */
#endif

#ifndef M_PI
  #define M_PI    3.14159265358979323846
#endif

#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>
//#    ifndef __BEOS__
//#        include <errno.h>
//#    else
//#        include "berrno.h"
//#    endif
#    include <math.h>
#endif /* HAVE_AV_CONFIG_H */

/* Suppress restrict if it was not defined in config.h.  */
#ifndef restrict
#    define restrict
#endif

#ifndef always_inline
  #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
    #define always_inline __attribute__((always_inline)) inline
  #else
    #define always_inline inline
  #endif
#endif

#ifndef attribute_used
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
#    define attribute_used __attribute__((used))
#else
#    define attribute_used
#endif
#endif

#ifndef attribute_unused
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
#    define attribute_unused __attribute__((unused))
#else
#    define attribute_unused
#endif
#endif

#ifndef attribute_deprecated
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
#    define attribute_deprecated __attribute__((deprecated))
#else
#    define attribute_deprecated
#endif
#endif

#ifndef EMULATE_INTTYPES
#   include <inttypes.h>
#else
    typedef signed char  int8_t;
    typedef signed short int16_t;
    typedef signed int   int32_t;
    typedef unsigned char  uint8_t;
    typedef unsigned short uint16_t;
    typedef unsigned int   uint32_t;
    typedef signed long long   int64_t;
    typedef unsigned long long uint64_t;
#endif /* EMULATE_INTTYPES */

#ifndef PRId64
#define PRId64 "lld"
#endif

#ifndef PRIu64
#define PRIu64 "llu"
#endif

#ifndef PRIx64
#define PRIx64 "llx"
#endif

#ifndef PRId32
#define PRId32 "d"
#endif

#ifndef PRIdFAST16
#define PRIdFAST16 PRId32
#endif

#ifndef PRIdFAST32
#define PRIdFAST32 PRId32
#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_t_C(9223372036854775807)
#endif

#ifndef UINT64_MAX
#define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF)
#endif

#ifdef EMULATE_FAST_INT
typedef signed char int_fast8_t;
typedef signed int  int_fast16_t;
typedef signed int  int_fast32_t;
typedef unsigned char uint_fast8_t;
typedef unsigned int  uint_fast16_t;
typedef unsigned int  uint_fast32_t;
typedef uint64_t      uint_fast64_t;
#endif

#ifndef INT_BIT
#    if INT_MAX != 2147483647
#        define INT_BIT 64
#    else
#        define INT_BIT 32
#    endif
#endif

#ifndef int64_t_C
#define int64_t_C(c)     (c ## LL)
#define uint64_t_C(c)    (c ## ULL)
#endif

#if defined(__MINGW32__) && !defined(BUILD_AVUTIL) && defined(BUILD_SHARED_AV)
#  define FF_IMPORT_ATTR __declspec(dllimport)
#else
#  define FF_IMPORT_ATTR
#endif


#ifdef HAVE_AV_CONFIG_H
/* only include the following when compiling package */
#    include "internal.h"
#endif

//rounded divison & shift
#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
/* assume b>0 */
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
#define FFSIGN(a) ((a) > 0 ? 1 : -1)

#ifdef _MIPS_LINUX_ 
  static always_inline unsigned int FFABS(aa) 
  {
    unsigned int tt;
    asm volatile ("abs %0,%1":"=r"(tt):"r"(aa));
    return tt;
  }
#else
  #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
#endif


#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))

#define SWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)

/* misc math functions */
extern const uint8_t ff_log2_tab[256];

static always_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;
}

static inline int av_log2_16bit(unsigned int v)
{
    int n =0;

    if (v & 0xff00) {
        v >>= 8;
        n += 8;
    }
    n += ff_log2_tab[v];

    return n;
}

/* median of 3 */
static always_inline int mid_pred(int a, int b, int c)
{
#if 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;
#else
    if(a>b){
        if(c>b){
            if(c>a) b=a;
            else    b=c;
        }
    }else{
        if(b>c){
            if(c>a) b=c;
            else    b=a;
        }
    }
    return b;
#endif
}

/**
 * clip a signed integer value into the amin-amax range
 * @param a value to clip
 * @param amin minimum value of the clip range
 * @param amax maximum value of the clip range
 * @return cliped value
 */
#define m_clip(aa, amin, amax) (((aa) < (amin)) ? (amin) : (((aa) > (amax)) ? (amax) : (aa)))
#if 0
  #define clip(aa, amin, amax) (((aa) < (amin)) ? (amin) : (((aa) > (amax)) ? (amax) : (aa)))
#else
  static always_inline int clip(int aa, int amin, int amax)
  {
    if (aa < amin)     
      return amin;
    else if (aa > amax) 
      return amax;
    else 
      return aa;
  }
#endif

/**
 * clip a signed integer value into the 0-255 range
 * @param a value to clip
 * @return cliped value
 */
#define mc_clip_uint8(aa) ((uint8_t)((aa) & 255))
#define m_clip_uint8(aa) ((uint8_t)(((aa) & (~255)) ? ((-((int)(aa)))>>31) : (aa)))
#if 1
  //#define clip_uint8(aa) ((uint8_t)(((aa) & (~255)) ? ((-((int)(aa)))>>31) : (aa)))
  #define clip_uint8(aa) ((uint8_t)((aa) & 255)) /* Cheaper but different results. Can you see any difference in the picture? */
#else
  static always_inline uint8_t clip_uint8(int aa)
  {
    if (aa & (~255)) 
      return (-aa) >> 31;
    else 
      return aa;
  }
#endif

/* math */
int64_t ff_gcd(int64_t a, int64_t b);

/**
 * converts fourcc string to int
 */
#define ff_get_fourcc(s) (int)((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))


#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;\
        }\
    }

#define START_TIMER
#define STOP_TIMER(id) {}

/* memory */

#ifdef __GNUC__
  #define DECLARE_ALIGNED(n,t,v)       t v __attribute__ ((aligned (n)))
#else
  #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
#endif

/* memory */
void *av_malloc(unsigned int size);
void *av_realloc(void *ptr, unsigned int size);
void av_free(void *ptr);

void *av_mallocz(unsigned int size);
char *av_strdup(const char *s);
void av_freep(void *ptr);

#endif /* COMMON_H */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -