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

📄 mpegaudalloc.c

📁 au1200 linux2.6.11 硬件解码mae驱动和maiplayer播放器源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        ci = ci_table[i];        cs = 1.0 / sqrt(1.0 + ci * ci);        ca = cs * ci;        csa_table[i][0] = FIX(cs);        csa_table[i][1] = FIX(ca);      }      printf("static int32_t csa_table[8][2] =\n{");      for (i=0;i<8;i++)      {        printf("\n  {\n    ");        for (j=0;j<2;j++)        {          printf("%d, ", csa_table[i][j]);        }        printf("\n  },");      }      printf("\n};\n\n");      /* compute mdct windows */      for (i=0;i<36;i++)       {          int v;          v = FIXR(sin(M_PI * (i + 0.5) / 36.0));          mdct_win[0][i] = v;          mdct_win[1][i] = v;          mdct_win[3][i] = v;      }      for (i=0;i<6;i++)       {          mdct_win[1][18 + i] = FIXR(1.0);          mdct_win[1][24 + i] = FIXR(sin(M_PI * ((i + 6) + 0.5) / 12.0));          mdct_win[1][30 + i] = FIXR(0.0);          mdct_win[3][i] = FIXR(0.0);          mdct_win[3][6 + i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));          mdct_win[3][12 + i] = FIXR(1.0);      }      for (i=0;i<12;i++)          mdct_win[2][i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));            /* NOTE: we do frequency inversion after the MDCT by changing         the sign of the right window coefs */      for (j=0;j<4;j++)       {        for (i=0;i<36;i+=2)         {          mdct_win[j + 4][i] = mdct_win[j][i];          mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];        }      }      printf("static int32_t mdct_win[8][36] =\n{");      for (i=0;i<8;i++)      {        printf("\n  {\n    ");        for (j=0;j<36;j++)        {          printf("%d, ", mdct_win[i][j]);        }        printf("\n  },");      }      printf("\n};\n\n");      init = 1;    }    s->inbuf_index = 0;    s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];    s->inbuf_ptr = s->inbuf;    s->frame_count = 0;    return 0;  }/* } */#else  #define cos intentionally generate compiler error  #define sin intentionally generate compiler error  #define tan intentionally generate compiler error  #define sqrt intentionally generate compiler error  static int init;  static int decode_init(MPEG_codecContext * avctx)  {    MPADecodeContext *s = avctx->priv_data;    int i, j;    if (!init && !avctx->parse_only)     {      /* huffman decode tables */      huff_code_table[0][MAX_HUFF_STATIC_SIZE-1] = 0; /* flag used in decode */      for (i=1;i<16;i++)       {        const HuffTable *h = &mpa_huff_tables[i];        int xsize, x, y;        unsigned int n;        uint8_t *code_table;        xsize = h->xsize;        n = xsize * xsize;        /* XXX: fail test */        huff_vlc[i].table = NULL;        huff_vlc[i].table_size = 0;        init_vlc(&huff_vlc[i], 8, n, h->bits, 1, 1, h->codes, 2, 2);        if (n > MAX_HUFF_STATIC_SIZE)          printf("Error!!!!! mpegaudalloc: table too large %d\n", n);        code_table = &huff_code_table[i][0];        huff_code_table[i][MAX_HUFF_STATIC_SIZE-1] = 1;        j = 0;        for (x=0;x<xsize;x++)         {          for (y=0;y<xsize;y++)            code_table[j++] = (x << 4) | y;        }      }      for (i=0;i<2;i++)       {        huff_quad_vlc[i].table = NULL;        huff_quad_vlc[i].table_size = 0;        init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16, mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1);      }      init = 1;    }    s->inbuf_index = 0;    s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];    s->inbuf_ptr = s->inbuf;    s->outbuf = (uint8_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);    //m emset(s->outbuf, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE);    s->frame_count = 0;    return 0;  }#endif#define GET_DATA(v, table, i, wrap, size) \{\    const uint8_t *ptr = (const uint8_t *)table + i * wrap;\    switch (size) {\    case 1:\        v = *(const uint8_t *)ptr;\        break;\    case 2:\        v = *(const uint16_t *)ptr;\        break;\    default:\        v = *(const uint32_t *)ptr;\        break;\    }\}/** * av_realloc semantics (same as glibc): if ptr is NULL and size > 0, * identical to malloc(size). If size is zero, it is identical to * free(ptr) and NULL is returned.   */static void *av_realloc(void *ptr, unsigned int size){    return (void *)realloc(ptr, size);}static int build_alloc_table(VLC *vlc, int size){    int index;    index = vlc->table_size;    vlc->table_size += size;    if (vlc->table_size > vlc->table_allocated) {        vlc->table_allocated += (1 << vlc->bits);        vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated);        if (!vlc->table)            return -1;    }    return index;}static int build_table(VLC *vlc, int table_nb_bits,                       int nb_codes,                       const void *bits, int bits_wrap, int bits_size,                       const void *codes, int codes_wrap, int codes_size,                       uint32_t code_prefix, int n_prefix){    int i, j, k, n, table_size, table_index, nb, n1, index;    uint32_t code;    VLC_TYPE (*table)[2];    table_size = 1 << table_nb_bits;    table_index = build_alloc_table(vlc, table_size);#ifdef DEBUG_VLC    printf("new table index=%d size=%d code_prefix=%x n=%d\n",           table_index, table_size, code_prefix, n_prefix);#endif    if (table_index < 0)        return -1;    table = &vlc->table[table_index];    for (i=0;i<table_size;i++)     {        table[i][1] = 0; //bits        table[i][0] = -1; //codes    }    /* first pass: map codes and compute auxillary table sizes */    for (i=0;i<nb_codes;i++) {        GET_DATA(n, bits, i, bits_wrap, bits_size);        GET_DATA(code, codes, i, codes_wrap, codes_size);        /* we accept tables with holes */        if (n <= 0)            continue;#if defined(DEBUG_VLC) && 0        printf("i=%d n=%d code=0x%x\n", i, n, code);#endif        /* if code matches the prefix, it is in the table */        n -= n_prefix;        if (n > 0 && (code >> n) == code_prefix) {            if (n <= table_nb_bits) {                /* no need to add another table */                j = (code << (table_nb_bits - n)) & (table_size - 1);                nb = 1 << (table_nb_bits - n);                for (k=0;k<nb;k++) {#ifdef DEBUG_VLC                    dprintf("%4x: code=%d n=%d\n",  j, i, n);#endif                    if (table[j][1] /*bits*/ != 0) {                        dprintf("incorrect codes\n");                        av_abort();                    }                    table[j][1] = n; //bits                    table[j][0] = i; //code                    j++;                }            } else {                n -= table_nb_bits;                j = (code >> n) & ((1 << table_nb_bits) - 1);#ifdef DEBUG_VLC                printf("%4x: n=%d (subtable)\n",                       j, n);#endif                /* compute table size */                n1 = -table[j][1]; //bits                if (n > n1)                    n1 = n;                table[j][1] = -n1; //bits            }        }    }    /* second pass : fill auxillary tables recursively */    for (i=0;i<table_size;i++) {        n = table[i][1]; //bits        if (n < 0) {            n = -n;            if (n > table_nb_bits) {                n = table_nb_bits;                table[i][1] = -n; //bits            }            index = build_table(vlc, n, nb_codes,                                bits, bits_wrap, bits_size,                                codes, codes_wrap, codes_size,                                (code_prefix << table_nb_bits) | i,                                n_prefix + table_nb_bits);            if (index < 0)                return -1;            /* note: realloc has been done, so reload tables */            table = &vlc->table[table_index];            table[i][0] = index; //code        }    }    return table_index;}/* Build VLC decoding tables suitable for use with get_vlc().   'nb_bits' set thee decoding table size (2^nb_bits) entries. The   bigger it is, the faster is the decoding. But it should not be too   big to save memory and L1 cache. '9' is a good compromise.      'nb_codes' : number of vlcs codes   'bits' : table which gives the size (in bits) of each vlc code.   'codes' : table which gives the bit pattern of of each vlc code.   'xxx_wrap' : give the number of bytes between each entry of the   'bits' or 'codes' tables.   'xxx_size' : gives the number of bytes of each entry of the 'bits'   or 'codes' tables.   'wrap' and 'size' allows to use any memory configuration and types   (byte/word/long) to store the 'bits' and 'codes' tables.  */static int init_vlc(VLC *vlc, int nb_bits, int nb_codes,             const void *bits, int bits_wrap, int bits_size,             const void *codes, int codes_wrap, int codes_size){  vlc->bits = nb_bits;  vlc->table = NULL;  vlc->table_allocated = 0;  vlc->table_size = 0;#ifdef DEBUG_VLC   printf("build table nb_codes=%d\n", nb_codes);#endif  if (build_table(vlc, nb_bits, nb_codes,                  bits, bits_wrap, bits_size,                  codes, codes_wrap, codes_size,                  0, 0) < 0)   {    free(vlc->table);    return -1;  }  return 0;}int avcodec_open(MPEG_codecContext *avctx, MPEG_codec *codec){  if (avctx->codec) /* already open */    return -1;  init = 0; /* otherwise the tables will not be allocated or regenerated */  avctx->codec = codec;  avctx->priv_data = &codec->decode_context;  return decode_init(avctx);}int avcodec_close(MPEG_codecContext *avctx){  int ii;  MPADecodeContext *s = avctx->priv_data;  free(s->outbuf);  avctx->codec = NULL;  for (ii = 1; ii < 16; ii++)  {    if ((huff_vlc[ii].table != NULL) && (huff_vlc[ii].table_size > 0))      free(huff_vlc[ii].table);    huff_vlc[ii].table_size = 0;    huff_vlc[ii].table = NULL;  }  for (ii = 0; ii < 2; ii++)  {    if ((huff_quad_vlc[ii].table != NULL) && (huff_quad_vlc[ii].table_size > 0))      free(huff_quad_vlc[ii].table);    huff_quad_vlc[ii].table_size = 0;    huff_quad_vlc[ii].table = NULL;  }  return 0;}

⌨️ 快捷键说明

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