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

📄 prmdec.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) 2007 ROCK-CHIPS FUZHOU . All Rights Reserved. */
/*
File : \Audio\RMDec
Desc : RM音频解码【LBR,AAC】,RV视频解包。

Author : Vincent Hisung
Date :   2007-08-xx
Notes :   部分功能未经测试

$Log :
*
* vincent     2007/08/xx    建立此文件
*
*/
/****************************************************************/


#define ARM_ADS

#include <stdlib.h>
#include <time.h>
#include "pRmDec.h"
//#include "rv_depack_internal.h"
#include "include.h"
#include "../include/audio_globals.h"
#include "../include/CommonCmd.h"

//#include "core.h"

#include "../include/file_access.h"
extern   MY_FILE* pRawFileCache;

static long OutLength;
static long ra_seek_to_time = (-1);

short  *rm_OutLeft = NULL;
short  *rm_OutRight = NULL;

#define RM2WAV_INITIAL_READ_SIZE 16
volatile int IS_RA_BLOCK_SEND = 0 ;
volatile int IS_RA_BLOCK_SEND2 = 0 ;
volatile unsigned long g_VT_ulNumAU = 0;
volatile rm_packet* g_VT_pPacket = NULL;
volatile int g_VT_i;

//this is define in that Vedio decode
//unsigned long maxPacketSize = 0;

//char* p_decode_a_new_packetData;
extern int real_is_V_or_A; // 0 - V . 1 - A
extern char* p_decode_a_new_packetData_a;

static ra_block decode_a_Block;

static int decode_a_i = 0;
static UINT32    decode_a_ulTimeOffset = 0;
static UINT32    decode_a_ulTimestamp  = 0;
static HXDOUBLE  decode_a_dTimeOffset  = 0.0;
static int ra_seekable = 0;

static int while_cnt = 0;
typedef unsigned int            CPU_STATUS;

/***************************************************************************/
#define     DECLARE_CUP_SR                              CPU_STATUS  cpu_sr
DECLARE_CUP_SR;

typedef struct
{
    MY_FILE*      fpOut;
    ra_depack* pDepack;
    ra_decode* pDecode;
    BYTE*      pOutBuf;
    UINT32     ulOutBufSize;
    UINT32     ulDataBytesWritten;
} rm2wav_info;

//-----------------------
static    HX_RESULT           retVal         = HXR_OK;
static    MY_FILE*               fp             = HXNULL;
static    INT32               lBytesRead     = 0;
static    UINT32              ulNumStreams   = 0;
static    UINT32              i              = 0;
static   UINT16              usStreamNum_a    = (-1);
static    UINT32              ulOutFrameSize = 0;
static    UINT32              ulRIFFSizeOff  = 0;
static    UINT32              ulTotFramesOff = 0;
static    UINT32              ulStrHdrLenOff = 0;
static    UINT32              ulMoviLenOff   = 0;
static    UINT32              ulHdrLen       = 0;
static    BYTE*               pTmp           = HXNULL;
static    rm_parser*          pParser        = HXNULL;
static   rm_stream_header*   pHdr_a         = HXNULL;
static    rm_packet*          pPacket        = HXNULL;

static    BYTE         ucBuf[RM2WAV_INITIAL_READ_SIZE];
static    UINT32              ulCodec4CC     = 0;
static    UINT32              ulMaxSamples   = 0;
static    UINT32              ulChannels     = 0;
static    UINT32              ulSampleRate   = 0;
static    UINT32              ulByteRate     = 0;
static    UINT32              ulOutBufSize   = 0;
static    UINT32              ulNumOutSamp   = 0;
static    UINT32              ulBytesOut     = 0;
static    UINT32              ulRIFFSize     = 0;
static    UINT16              usWavFormat    = 0;
static    UINT16              usWavFormatChunkSize = 0;
static    BYTE*               pOutBuf        = HXNULL;
static   ra_depack*          pDepack_a      = HXNULL;
static    ra_decode*          pDecode_a      = HXNULL;
static    ra_format_info*     pInfo_a        = HXNULL;
static    rm2wav_info         info_a;
static    UINT32              ulTmp          = 0;
static    BYTE                ucTmp[68];
static    UINT32          ulAbr          = 0;
static    UINT32           ulCurrentTime  = 0;
static int isPacketRdy = 0;

static unsigned long seeked_time = 0;

static unsigned int rmaudiocodec4cc = 0;
unsigned int GetRmAudioCodec4cc(void)
{
    return rmaudiocodec4cc;
}
/******************************************************
Name:  rm2wav_error
Desc:  RA解包错误回调函数
Param: pError    出错结构体指针
    result    结果
    pszMsg   信息
Return: 无
Global: 无
Note:   无
Author: Vincent Hisung
Log:
/******************************************************/
void rm2wav_error(void* pError, HX_RESULT result, const char* pszMsg)
{
    //fprintf(stderr, "rm2wav_error pError=0x%08x result=0x%08x msg=%s\n", pError, result, pszMsg);
}

unsigned long GetRACurTime()
{
    return  ulCurrentTime;
}

unsigned long GetRASeekedTime()
{
    return seeked_time;
}

//回调函数,由音频解码器适时调用,用户无需调用
/******************************************************
Name:  ra_block_available
Desc:  RA块解码回调函数
Param: pAvail    解码结构体指针
    ulSubStream 流编号
    pBlock   音频块指针
Return: HXR_FAIL-失败 HXR_OK-成功
Global: 无
Note: 无
Author: Vincent Hisung
Log:
/******************************************************/
HX_RESULT ra_block_available(void* pAvail, UINT32 ulSubStream, ra_block* pBlock)
{
    HX_RESULT retVal = HXR_FAIL;

    if (pAvail && pBlock && pBlock->pData && pBlock->ulDataLen)
    {
        /* Init local variables */
        UINT32 ulBytesConsumed = 0;
        UINT32 ulTotalConsumed = 0;
        UINT32 ulNumSamplesOut = 0;
        UINT32 ulBytesLeft     = 0;
        UINT32 ulBytesWritten  = 0;
        UINT32 i               = 0;
        BYTE*  pTmp            = HXNULL;
        BYTE   ucTmp           = 0;
        /* Get the info pointer */
        rm2wav_info* pInfo = (rm2wav_info*) pAvail;
        /* Sanity check to make sure pInfo has what we need */
        if (pInfo->fpOut && pInfo->pDepack && pInfo->pDecode &&
                pInfo->pOutBuf && pInfo->ulOutBufSize)
        {
            /* Clear the return value */
            retVal = HXR_OK;
            /* Init the bytes left */
            ulBytesLeft = pBlock->ulDataLen;
            /* Loop until we've consumed all the data */
            OutLength = 0;
            while ((retVal == HXR_OK) && ulBytesLeft)
            {
                /* Decode the block */
                //ENTER_CRITICAL();

//Just Debug,Move these lines away,By Vincent Hisung
                if (ra_seek_to_time != (-1))
                {
                    seeked_time = pBlock->ulTimestamp;
                    ra_seek_to_time = (-1);
                }
#if 0
                if (ra_seek_to_time != (-1))
                {
                    if (pBlock->ulTimestamp < ra_seek_to_time)
                        return;
                    else
                        ra_seek_to_time = (-1);
                }
#endif

                retVal = ra_decode_decode(pInfo->pDecode,
                                          (UINT8*)(pBlock->pData + ulTotalConsumed),
                                          pBlock->ulDataLen - ulTotalConsumed,
                                          &ulBytesConsumed,
                                          (UINT16*) pInfo->pOutBuf,
                                          pInfo->ulOutBufSize / 2,
                                          &ulNumSamplesOut,
                                          pBlock->ulDataFlags);

                //EXIT_CRITICAL();

                if (retVal == HXR_OK)
                {
                    ulBytesWritten = ulNumSamplesOut << 1;
                    while_cnt = 0;
                    {
                        int i;

                        char *p_tmp1 = (char*)rm_OutLeft;//AudioIOBuf.OutLeft;
                        char *p_tmp2 = (char*)rm_OutRight;//AudioIOBuf.OutRight;

                        OutLength = ulNumSamplesOut / ulChannels;

                        for (i = 0;i < ulBytesWritten;)
                        {
                            *(p_tmp1++) = pInfo->pOutBuf[i];
                            i++;
                            *(p_tmp1++) = pInfo->pOutBuf[i];
                            i++;

                            if (ulChannels == 2)
                            {
                                *(p_tmp2++) = pInfo->pOutBuf[i];
                                i++;
                                *(p_tmp2++) = pInfo->pOutBuf[i];
                                i++;
                            }
                            else
                            {
                                //*
                                *(p_tmp2++) = pInfo->pOutBuf[i-2];
                                *(p_tmp2++) = pInfo->pOutBuf[i-1];
                                //*/
                                /*
                                *(p_tmp2++)=0;
                                *(p_tmp2++)=0;
                                */
                            }
                        }
                    }

                    /* Update the number of data bytes written */
                    pInfo->ulDataBytesWritten += ulBytesWritten;
                    /* Update the total amount consumed */
                    ulTotalConsumed += ulBytesConsumed;
                    /* Update the bytes left */
                    ulBytesLeft -= ulBytesConsumed;
                }
                else
                {
                    volatile aa = 0;
                    aa++;
                    aa *= aa;
                    retVal = retVal;
                }
            }
        }
        //below added by vincent
        //ra_depack_destroy_block(pDepack_a,&pBlock);
        rm_memory_default_free(0, pBlock->pData);
        pBlock->pData = NULL;
    }

    return retVal;
}

#if 0
void SEND_IT(rv_depack_internal* pInt, unsigned long len, unsigned int type, unsigned int timestamp)
{
#if 0
    //In fact,if I check the ECC packet and drop it may occour the stream has not end packet..
    //So the wisdom is to check ECC in DSP, not here
    //By Vincent Hisung,Nov 5,2007
    //ulCurrentTime=timestamp;
    if ((pInt->pCurFrame->pData[0]&pDecode_v->ulECCMask) == 0) // This check whether it is ECC packet. By Vincent Hisung
    {
        /*
        fwrite(&type , 2, 1, info_v.fpOut);    //type
        fwrite(&len , 4, 1, info_v.fpOut);    //len
        fwrite(&timestamp , 4, 1, info_v.fpOut); //timestamp
        //*/
        //if Len is Odd, make it be Even
        //By Vincent Hisung,Nov 6,2007
        //if (len & 0x01)
        // len++;
        //------------------------------
        //fwrite(pInt->pCurFrame->pData, 1, len, info_v.fpOut); //data
        //printf("RV out: %i , type : %i ,timestamp: %i \n",len,type,timestamp);
    }
    else
    {
        //printf("This is ECC Packet. %i\n",pInt->pCurFrame->pData[0]);
    }
#endif
}
#endif

//****************************************************************************
//
// The codec plug-in entry point for the RM decoder.
//
//****************************************************************************
//功能实现情况:
//SUBFN_CODEC_GETNAME  :   不支持
//SUBFN_CODEC_GETARTIST:   得到艺术家名称
//SUBFN_CODEC_GETTITLE :   得到曲名
//SUBFN_CODEC_GETBITRATE:  得到码率
//SUBFN_CODEC_GETSAMPLERATE: 得到采样率
//SUBFN_CODEC_GETCHANNELS: 得到声道数目
//SUBFN_CODEC_GETLENGTH :  得到时长 [单位:毫秒]
//SUBFN_CODEC_GETTIME  :   得到当前播放时间 [单位:毫秒] !注意:此处时间通过"时间戳"获得,若文件被破坏或许出错.
//SUBFN_CODEC_OPEN_DEC :   打开解码器(初始化)
//SUBFN_CODEC_SETBUFFER:   不支持
//SUBFN_CODEC_DECODE   :   解码
//SUBFN_CODEC_ENCODE   :   不支持
//SUBFN_CODEC_SEEK     :   按时间直接定位 [单位:毫秒]
//SUBFN_CODEC_CLOSE    :   关闭解码器
/******************************************************
Name:  RMFunction
Desc:  RM解码器接口函数
Param: ulIoctl 子功能号
    ulParam1 子功能参数1
    ulParam2 子功能参数2
    ulParam3 子功能参数3
    ulParam4 子功能参数4

Return: 0-失败 1-成功
Global: 无
Note: 无
Author: Vincent Hisung
Log:
/******************************************************/
unsigned long
RMFunction(unsigned long ulSubFn, unsigned long ulParam1, unsigned long ulParam2,
           unsigned long ulParam3, unsigned long ulParam4)
{

⌨️ 快捷键说明

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