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

📄 decoder.c

📁 the mpeg2/4 aac decoder
💻 C
📖 第 1 页 / 共 3 页
字号:
                        for (i = ch1; i < ch; i+=2)                        {                            hInfo->channel_position[i] = BACK_CHANNEL_LEFT;                            hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;                        }                    }                }                hInfo->num_lfe_channels = hDecoder->has_lfe;                for (i = ch; i < hDecoder->fr_channels; i++)                {                    hInfo->channel_position[i] = LFE_CHANNEL;                }            }            break;        }    }}void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,                                 NeAACDecFrameInfo *hInfo,                                 uint8_t *buffer, uint32_t buffer_size){    return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0);}void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,                                  NeAACDecFrameInfo *hInfo,                                  uint8_t *buffer, uint32_t buffer_size,                                  void **sample_buffer, uint32_t sample_buffer_size){    if ((sample_buffer == NULL) || (sample_buffer_size == 0))    {        hInfo->error = 27;        return NULL;    }    return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size,        sample_buffer, sample_buffer_size);}static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,                              uint8_t *buffer, uint32_t buffer_size,                              void **sample_buffer2, uint32_t sample_buffer_size){    uint8_t channels = 0;    uint8_t output_channels = 0;    bitfile ld;    uint32_t bitsconsumed;    uint16_t frame_len;    void *sample_buffer;#ifdef PROFILE    int64_t count = faad_get_ts();#endif    /* safety checks */    if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL))    {        return NULL;    }#if 0    printf("%d\n", buffer_size*8);#endif    frame_len = hDecoder->frameLength;    memset(hInfo, 0, sizeof(NeAACDecFrameInfo));    memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));    /* initialize the bitstream */    faad_initbits(&ld, buffer, buffer_size);#if 0    {        int i;        for (i = 0; i < ((buffer_size+3)>>2); i++)        {            uint8_t *buf;            uint32_t temp = 0;            buf = faad_getbitbuffer(&ld, 32);            //temp = getdword((void*)buf);            temp = *((uint32_t*)buf);            printf("0x%.8X\n", temp);            free(buf);        }        faad_endbits(&ld);        faad_initbits(&ld, buffer, buffer_size);    }#endif#ifdef DRM    if (hDecoder->object_type == DRM_ER_LC)    {        /* We do not support stereo right now */        if (0) //(hDecoder->channelConfiguration == 2)        {            hInfo->error = 8; // Throw CRC error            goto error;        }        faad_getbits(&ld, 8            DEBUGVAR(1,1,"NeAACDecDecode(): skip CRC"));    }#endif    if (hDecoder->adts_header_present)    {        adts_header adts;        adts.old_format = hDecoder->config.useOldADTSFormat;        if ((hInfo->error = adts_frame(&adts, &ld)) > 0)            goto error;        /* MPEG2 does byte_alignment() here,         * but ADTS header is always multiple of 8 bits in MPEG2         * so not needed to actually do it.         */    }#ifdef ANALYSIS    dbg_count = 0;#endif    /* decode the complete bitstream */#ifdef SCALABLE_DEC    if ((hDecoder->object_type == 6) || (hDecoder->object_type == DRM_ER_LC))    {        aac_scalable_main_element(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);    } else {#endif        raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);#ifdef SCALABLE_DEC    }#endif    channels = hDecoder->fr_channels;    if (hInfo->error > 0)        goto error;    /* safety check */    if (channels == 0 || channels > MAX_CHANNELS)    {        /* invalid number of channels */        hInfo->error = 12;        goto error;    }    /* no more bit reading after this */    bitsconsumed = faad_get_processed_bits(&ld);    hInfo->bytesconsumed = bit2byte(bitsconsumed);    if (ld.error)    {        hInfo->error = 14;        goto error;    }    faad_endbits(&ld);    if (!hDecoder->adts_header_present && !hDecoder->adif_header_present)    {        if (hDecoder->channelConfiguration == 0)            hDecoder->channelConfiguration = channels;        if (channels == 8) /* 7.1 */            hDecoder->channelConfiguration = 7;        if (channels == 7) /* not a standard channelConfiguration */            hDecoder->channelConfiguration = 0;    }    if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix)    {        hDecoder->downMatrix = 1;        output_channels = 2;    } else {        output_channels = channels;    }#if (defined(PS_DEC) || defined(DRM_PS))    hDecoder->upMatrix = 0;    /* check if we have a mono file */    if (output_channels == 1)    {        /* upMatrix to 2 channels for implicit signalling of PS */        hDecoder->upMatrix = 1;        output_channels = 2;    }#endif    /* Make a channel configuration based on either a PCE or a channelConfiguration */    create_channel_config(hDecoder, hInfo);    /* number of samples in this frame */    hInfo->samples = frame_len*output_channels;    /* number of channels in this frame */    hInfo->channels = output_channels;    /* samplerate */    hInfo->samplerate = get_sample_rate(hDecoder->sf_index);    /* object type */    hInfo->object_type = hDecoder->object_type;    /* sbr */    hInfo->sbr = NO_SBR;    /* header type */    hInfo->header_type = RAW;    if (hDecoder->adif_header_present)        hInfo->header_type = ADIF;    if (hDecoder->adts_header_present)        hInfo->header_type = ADTS;#if (defined(PS_DEC) || defined(DRM_PS))    hInfo->ps = hDecoder->ps_used_global;#endif    /* check if frame has channel elements */    if (channels == 0)    {        hDecoder->frame++;        return NULL;    }    /* allocate the buffer for the final samples */    if ((hDecoder->sample_buffer == NULL) ||        (hDecoder->alloced_channels != output_channels))    {        static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),            sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),            sizeof(int16_t), sizeof(int16_t), 0, 0, 0        };        uint8_t stride = str[hDecoder->config.outputFormat-1];#ifdef SBR_DEC        if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))        {            stride = 2 * stride;        }#endif        /* check if we want to use internal sample_buffer */        if (sample_buffer_size == 0)        {            if (hDecoder->sample_buffer)                faad_free(hDecoder->sample_buffer);            hDecoder->sample_buffer = NULL;            hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride);        } else if (sample_buffer_size < frame_len*output_channels*stride) {            /* provided sample buffer is not big enough */            hInfo->error = 27;            return NULL;        }        hDecoder->alloced_channels = output_channels;    }    if (sample_buffer_size == 0)    {        sample_buffer = hDecoder->sample_buffer;    } else {        sample_buffer = *sample_buffer2;    }#ifdef SBR_DEC    if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))    {        uint8_t ele;        /* this data is different when SBR is used or when the data is upsampled */        if (!hDecoder->downSampledSBR)        {            frame_len *= 2;            hInfo->samples *= 2;            hInfo->samplerate *= 2;        }        /* check if every element was provided with SBR data */        for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)        {            if (hDecoder->sbr[ele] == NULL)            {                hInfo->error = 25;                goto error;            }        }        /* sbr */        if (hDecoder->sbr_present_flag == 1)        {            hInfo->object_type = HE_AAC;            hInfo->sbr = SBR_UPSAMPLED;        } else {            hInfo->sbr = NO_SBR_UPSAMPLED;        }        if (hDecoder->downSampledSBR)        {            hInfo->sbr = SBR_DOWNSAMPLED;        }    }#endif    sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,        output_channels, frame_len, hDecoder->config.outputFormat);    hDecoder->postSeekResetFlag = 0;    hDecoder->frame++;#ifdef LD_DEC    if (hDecoder->object_type != LD)    {#endif        if (hDecoder->frame <= 1)            hInfo->samples = 0;#ifdef LD_DEC    } else {        /* LD encoders will give lower delay */        if (hDecoder->frame <= 0)            hInfo->samples = 0;    }#endif    /* cleanup */#ifdef ANALYSIS    fflush(stdout);#endif#ifdef PROFILE    count = faad_get_ts() - count;    hDecoder->cycles += count;#endif    return sample_buffer;error:    faad_endbits(&ld);    /* cleanup */#ifdef ANALYSIS    fflush(stdout);#endif    return NULL;}

⌨️ 快捷键说明

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