static int cook_decode_init(AVCodecContext *avctx) { uint8_t *edata_ptr = avctx->extradata; int codingDelay; HX_RESULT retVal = HXR_FAIL; avctx->sample_fmt = SAMPLE_FMT_S16; if (avctx->extradata_size <= 0) { av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n"); return -1; } memset(&unpackedData,0,sizeof(unpackedData)); retVal = ra8lbr_unpack_opaque_data(&unpackedData,edata_ptr,avctx->extradata_size); if(retVal == -1) { av_log(avctx,AV_LOG_ERROR,"Necessary extradata error!\n"); return -1; } F("unpackedData.nSamples = %d\n",unpackedData.nSamples); F("avctx->channels = %d\n",avctx->channels); F("avctx->block_align = %d\n",avctx->block_align); F("avctx->sample_rate = %d\n",avctx->sample_rate); F("avctx->bit_rate = %d\n",avctx->bit_rate); gecko2Decoder = Gecko2InitDecoder( unpackedData.nSamples / avctx->channels, avctx->channels, unpackedData.nRegions, avctx->block_align * 8, avctx->sample_rate, unpackedData.cplStart, unpackedData.cplQBits, &codingDelay); F("-------------------------------------------\ncodingDelay = %d\n",codingDelay); if (!gecko2Decoder) { av_log(avctx,AV_LOG_ERROR,"memory overflow!\n"); return -1 ; } return 0; }
/* *rm parse and initialize *add sheen */ HX_RESULT rm_init(FILE_HDL fpIn, rmInfo *pRmInfo) { HX_RESULT retVal = HXR_OK; INT32 lBytesRead = 0; unsigned char ucBuf[RM2YUV_INITIAL_READ_SIZE]; UINT32 ulNumStreams = 0; UINT32 i = 0; //UINT32 ulFramesPerSec = 0; //UINT32 ulOutFrameSize = 0; rm_stream_header* pHdr=HXNULL; UINT32 ulRaCodec4CC = 0; //UINT32 ulMaxSamples = 0; rm_parser_internal* pInt = HXNULL; pParser = HXNULL; pRvHdr = HXNULL; pRaHdr =HXNULL; usRvStreamNum = 0; usRaStreamNum = 0; pRvPacket = HXNULL; pRaPacket =HXNULL; pRvDepack = HXNULL; pRaDepack =HXNULL; pRvInfo = HXNULL; pRaInfo = HXNULL; pRvDecode = HXNULL; pRaDecode = HXNULL; //pRvOutFrame = HXNULL; pRaOutBuf =HXNULL; pRaTempBuf= HXNULL; pRaTempBufPos=HXNULL; RaTempRemain=0; RaReadLen=0; RaOutLen=0; RV_GET_ONE_FRAME=0; rv_Timestamp_dis=0; ra_Timestamp_start=0; raFileOffset=0; rvFileOffset=0; needBackUpFileOffset=0; g_number_of_loads=0; memset(&rvInfo, 0, sizeof(rm2yuv_info)); memset(&raInfo, 0, sizeof(rm2wav_info)); retVal=rm_memory_default_init(); if(retVal!=0) { rm_printf("rm_memory_default_init fail!!!\n"); retVal=HXR_OUTOFMEMORY; goto cleanup; } #if 1 /* Read the first few bytes of the file */ lBytesRead = (INT32) rm_io_default_read((void*)fpIn, (void*) ucBuf, RM2YUV_INITIAL_READ_SIZE); if (lBytesRead != RM2YUV_INITIAL_READ_SIZE) { rm_printf("Could not read %d bytes at the beginning of rm file, lBytesRead=%d\n", RM2YUV_INITIAL_READ_SIZE, lBytesRead); retVal=HXR_INVALID_FILE; goto cleanup; } /* Seek back to the beginning */ rm_io_default_seek((void*)fpIn, 0, HX_SEEK_ORIGIN_SET); /* Make sure this is an .rm file */ if (!rm_parser_is_rm_file(ucBuf, RM2YUV_INITIAL_READ_SIZE)) { rm_printf("it is not an .rm file.\n"); retVal=HXR_NOT_SUPPORTED; goto cleanup; } /* Create the parser struct */ pParser = rm_parser_create(NULL, rm2yuv_error); if (!pParser) { retVal=HXR_DEC_INIT_FAILED; rm_printf("rm_parser_create err!\n"); goto cleanup; } /* Set the FILE* into the parser */ retVal = rm_parser_init_stdio(pParser, fpIn); if (retVal != HXR_OK) { rm_printf("rm_parser_init_stdio err!\n"); goto cleanup; } /* Read all the headers at the beginning of the .rm file */ retVal = rm_parser_read_headers(pParser); if (retVal != HXR_OK) { rm_printf("rm_parser_read_headers err!\n"); goto cleanup; } /* Get the number of streams */ ulNumStreams = rm_parser_get_num_streams(pParser); if (ulNumStreams == 0) { rm_printf("Error: rm_parser_get_num_streams() returns 0\n"); retVal=HXR_INVALID_STREAM; goto cleanup; } /* Now loop through the stream headers and find the video */ for (i = 0; i < ulNumStreams && retVal == HXR_OK; i++) { retVal = rm_parser_get_stream_header(pParser, i, &pHdr); if (retVal == HXR_OK) { if (rm_stream_is_realvideo(pHdr)) { usRvStreamNum = (UINT16) i; pRvHdr=pHdr; if(pRaHdr!=HXNULL)break; } else if(rm_stream_is_realaudio(pHdr)) { usRaStreamNum = (UINT16) i; pRaHdr=pHdr; if(pRvHdr!=HXNULL)break; } else { /* Destroy the stream header */ rm_parser_destroy_stream_header(pParser, &pHdr); } } } /* Do we have RealVideo and RealAudio stream in this .rm file? */ if (!pRvHdr) { rm_printf("There is no RealVideo stream in this file.\n"); retVal=HXR_UNSUPPORTED_VIDEO; goto cleanup; } else if(!pRaHdr) { rm_printf("There is no RealAudio stream in this file.\n"); retVal=HXR_UNSUPPORTED_AUDIO; goto cleanup; } /* Create the RealVideo depacketizer */ pRvDepack = rv_depack_create((void*) &rvInfo, rv_frame_available, NULL, rm2yuv_error); if (!pRvDepack) { retVal=HXR_DEC_INIT_FAILED; rm_printf("rv_depack_create err!\n"); goto cleanup; } /* Assign the rv_depack pointer to the info struct */ rvInfo.pDepack = pRvDepack; /* Create the RealAudio depacketizer */ pRaDepack = ra_depack_create((void*) &raInfo, ra_block_available, NULL, rm2wav_error); if (!pRaDepack) { retVal=HXR_DEC_INIT_FAILED; rm_printf("ra_depack_create err!\n"); goto cleanup; } /* Assign the ra_depack pointer to the info struct */ raInfo.pDepack = pRaDepack; /* Initialize the RV depacketizer with the stream header */ retVal = rv_depack_init(pRvDepack, pRvHdr); if (retVal != HXR_OK) { rm_printf("rv_depack_init err!\n"); goto cleanup; } /* Initialize the RA depacketizer with the stream header */ retVal = ra_depack_init(pRaDepack, pRaHdr); if (retVal != HXR_OK) { rm_printf("ra_depack_init err!\n"); goto cleanup; } /* Get the bitstream header information */ retVal = rv_depack_get_codec_init_info(pRvDepack, &pRvInfo); if (retVal != HXR_OK) { rm_printf("rv_depack_get_codec_init_info err!\n"); goto cleanup; } /* Fill in the width and height */ rvInfo.ulWidth = (UINT32) pRvInfo->usWidth; rvInfo.ulHeight = (UINT32) pRvInfo->usHeight; /* * Get the codec 4CC of substream 0. We * arbitrarily choose substream 0 here. */ ulRaCodec4CC = ra_depack_get_codec_4cc(pRaDepack, 0); /* * Get the bitstream header information. Again, * we arbitrarily choose substream 0. */ retVal = ra_depack_get_codec_init_info(pRaDepack, 0, &pRaInfo); if (retVal != HXR_OK) { rm_printf("ra_depack_get_codec_init_info err!\n"); goto cleanup; } /* * Print out the width and height so the user * can input this into their YUV-viewing program. */ //rm_printf( "Video dimensions %lu x %lu pixels (width x height)\n", // info.ulWidth, info.ulHeight); /* * Get the frames per second. This value is in 32-bit * fixed point, where the upper 16 bits is the integer * part of the fps, and the lower 16 bits is the fractional * part. We're going to truncate to integer, so all * we need is the upper 16 bits. */ //ulFramesPerSec = pInfo->ufFramesPerSecond >> 16; /* Create an rv_decode object */ pRvDecode = rv_decode_create(HXNULL, rm2yuv_error); if (!pRvDecode) { rm_printf("rv_decode_create err!\n"); retVal=HXR_DEC_INIT_FAILED; goto cleanup; } /* Assign the decode object into the rm2yuv_info struct */ rvInfo.pDecode = pRvDecode; /* Create the ra_decode object */ /* pRaDecode = ra_decode_create(HXNULL, rm2wav_error); if (!pRaDecode) { goto cleanup; }*/ /* Assign the decode object into the rm2wav_info struct */ //raInfo.pDecode = pRaDecode; /* Init the rv_decode object */ retVal = rv_decode_init(pRvDecode, pRvInfo); if (retVal != HXR_OK) { rm_printf("rv_decode_init err!\n"); goto cleanup; } /* Init the ra_decode object */ /* retVal = ra_decode_init(pRaDecode, ulRaCodec4CC, HXNULL, 0, pRaInfo); if (retVal != HXR_OK) { goto cleanup; }*/ #if 0 /* Get the size of an output frame */ ulOutFrameSize = rv_decode_max_output_size(pRvDecode); if (!ulOutFrameSize) { retVal=HXR_UNSUPPORTED_VIDEO; rm_printf("rv_decode_max_output_size err!\n"); goto cleanup; } /* Allocate an output frame buffer */ pRvOutFrame = (BYTE*) rm_memory_default_malloc(0, ulOutFrameSize); #else /* 20 bytes in head store 5 int value: [0]Y pos [1]U pos [2]V pos [3]width [4]high. then the padding U V buffer for reorder interlace line UV data. Y use the decoder buffer.sheen */ //if(rvInfo.ulWidth && rvInfo.ulHeight) // pRvOutFrame = (BYTE*) rm_memory_default_malloc(0, 4*5 + (rvInfo.ulWidth+YUV_UV_PADDING*4)*(rvInfo.ulHeight>>1)); #endif /* if (!pRvOutFrame) { retVal=HXR_OUTOFMEMORY; rm_printf("pRvOutFrame err!\n"); goto cleanup; }*/ /* Assign the output frame into the info struct */ // rvInfo.pOutFrame = pRvOutFrame; // rvInfo.ulOutFrameSize = ulOutFrameSize; /* Get the maximum number of output samples */ /* retVal = ra_decode_getmaxsize(pRaDecode, &ulMaxSamples); if (retVal != HXR_OK) { goto cleanup; }*/ /* Compute the size of the output buffer */ // ulOutFrameSize = ulMaxSamples * sizeof(UINT16); /* Allocate an output buffer */ /* pOutBuf = (BYTE*) malloc(ulOutFrameSize); if (!pOutBuf) { goto cleanup; }*/ /* Assign the output frame into the info struct */ /* raInfo.pOutBuf = pOutBuf; raInfo.ulOutBufSize = ulOutBufSize; */ #endif if(ulRaCodec4CC==RA_CODEC_COOK ) pRaTempBuf= (BYTE*) rm_memory_default_malloc(0, RA_SUPERBLK_SIZE); else//for AAC pRaTempBuf= (BYTE*) rm_memory_default_malloc(0, RA_TEMPNUF_SIZE); if (!pRaTempBuf) { retVal=HXR_OUTOFMEMORY; rm_printf("pRaTempBuf err!\n"); goto cleanup; } pRaTempBufPos=pRaTempBuf; pInt = (rm_parser_internal*) pParser; raFileOffset=rvFileOffset=pInt->ulCurFileOffset; if(ulRaCodec4CC==RA_CODEC_COOK && pRaInfo->ulOpaqueDataSize > 0) { ra8lbr_data codecData = {0, 0, 0, 0, 0, 0, 0}; retVal = ra8lbr_unpack_opaque_data(&codecData, &pRaInfo->pOpaqueData, &pRaInfo->ulOpaqueDataSize); if (retVal == HXR_OK) { pRmInfo->ra_SamplePerFrame=codecData.nSamples; pRmInfo->ra_Regions=codecData.nRegions; pRmInfo->ra_cplStart=codecData.cplStart; pRmInfo->ra_cplQBits=codecData.cplQBits; } } /*output rm information*/ pRmInfo->rm_Duration=((rm_parser_internal*) pParser)->pMediaPropsHdr[usRvStreamNum].duration; // use video time to repalce a/v longest time rm_parser_get_duration( pParser); pRmInfo->rm_NumStream=rm_parser_get_num_streams( pParser); pRmInfo->rv_Format=pRvInfo->ulSubMOFTag; pRmInfo->rv_Width=rvInfo.ulWidth; pRmInfo->rv_Height=rvInfo.ulHeight; pRmInfo->rv_Fps= pRvInfo->ufFramesPerSecond >> 16; pRmInfo->ra_Format= ulRaCodec4CC; pRmInfo->ra_SampleRate= pRaInfo->ulSampleRate; pRmInfo->ra_BitsPerSample= pRaInfo->usBitsPerSample; pRmInfo->ra_NumChannels= pRaInfo->usNumChannels; pRmInfo->ra_BitsPerFrame=pRaInfo->ulBitsPerFrame; if(ulRaCodec4CC==RA_CODEC_RAAC || ulRaCodec4CC==RA_CODEC_RACP) { rm_BitToInt bs; BYTE aacType; INT32 sampRateIdx; memset(raacHead, 0, RAAC_HEAD_SIZE); bs.stream=raacHead; bs.current=0; bs.nbBits=0; aacType=ra_depack_get_codec_aac_type(pRaDepack, 0); for(sampRateIdx=0;sampRateIdx<RAAC_SR_TAB_NUM;sampRateIdx++) { if(pRaInfo->ulSampleRate==sampRateTab[sampRateIdx]) break; } rm_bit_to_int(&bs, 0xFFF, 12);/*sync*/ rm_bit_to_int(&bs, ((aacType&0x7)==0)?0:1, 1);/*1=mpeg2 aac / 0=mpeg4 aac*/ rm_bit_to_int(&bs, 0, 2); /*layer*/ rm_bit_to_int(&bs, 1, 1); /* protection_absent. 0 = CRC word follows, 1 = no CRC word */ rm_bit_to_int(&bs, /*(aacType>>3)*/1, 2); /*profile, 0 = main, 1 = LC, 2 = SSR, 3 = reserved, only LC now */ rm_bit_to_int(&bs, sampRateIdx, 4);/* sample rate index range = [0, 11] */ rm_bit_to_int(&bs, 0, 1);/* ignore */ rm_bit_to_int(&bs, pRaInfo->usNumChannels, 3);/* channel, 0 = implicit, >0 = use default table */ rm_bit_to_int(&bs, 0, 4);/* ignore */ rm_bit_to_int(&bs, 0, 13);//frame size.13bit will be rewrite when every sample read rm_bit_to_int(&bs, 0x7FF, 11);/* number of 32-bit words left in enc buffer, 0x7FF = VBR */ rm_bit_to_int(&bs, 0, 2);/* number of raw data blocks in frame */ } rm_video_key_seek_event=0; return retVal; cleanup: rm_destroy(fpIn); return retVal; }