/*------------------------------------------------------------------------------ FreeRes Release all resources allcoated byt AllocRes() ------------------------------------------------------------------------------*/ void On2_AvcEncoder::FreeRes() { if(pictureMem.vir_addr != NULL) VPUFreeLinear(&pictureMem); if(pictureStabMem.vir_addr != NULL) VPUFreeLinear(&pictureStabMem); if(outbufMem.vir_addr != NULL) VPUFreeLinear(&outbufMem); }
/*************************************************************************************************** Func: free_frame Description: malloc a new empty frame Return: VPU_OK: malloc sucessfully VPU_ERR: malloc failed Author: Jian Huan Jesan Date: 2010-12-7 17:29:53 2010-12-13 15:30:30 **************************************************************************************************/ RK_S32 framemanager::free_frame(VPU_FRAME *frame) { if (!frame) return 0; if (frame->employ_cnt <= 1) { //if (frame->vpumem.offset) VPUFreeLinear(&frame->vpumem); memset(frame,0,sizeof(VPU_FRAME)); push_empty(frame); } else frame->employ_cnt--; return VPU_OK; }
framemanager::~framemanager() { VPU_FRAME *frame; RK_U32 i; if (FrmBufBase) { for (i=0; i<frameNum; i++) { if (FrmBufBase[i].vpumem.vir_addr) VPUFreeLinear(&FrmBufBase[i].vpumem); } free(FrmBufBase); } memset(this,0,sizeof(framemanager)); }
status_t deinterlace_dev::perform(VPU_FRAME *frm, uint32_t bypass) { status_t ret = NO_INIT; VPUMemLinear_t deInterlaceFrame; ret = VPUMallocLinear(&deInterlaceFrame, frm->FrameHeight*frm->FrameWidth*3/2); if (!ret) { uint32_t width = frm->FrameWidth; uint32_t height = frm->FrameHeight; uint32_t srcYAddr = frm->FrameBusAddr[0]; uint32_t srcCAddr = frm->FrameBusAddr[1]; uint32_t dstYAddr = deInterlaceFrame.phy_addr; uint32_t dstCAddr = deInterlaceFrame.phy_addr + width*height; frm->FrameBusAddr[0] = dstYAddr; frm->FrameBusAddr[1] = dstCAddr; switch (dev_status) { case USING_IPP : { struct rk29_ipp_req ipp_req; memset(&ipp_req,0,sizeof(rk29_ipp_req)); ipp_req.src0.YrgbMst = srcYAddr; ipp_req.src0.CbrMst = srcCAddr; ipp_req.src0.w = width; ipp_req.src0.h = height; ipp_req.src0.fmt = IPP_Y_CBCR_H2V2; ipp_req.dst0.w = width; ipp_req.dst0.h = height; ipp_req.src_vir_w = width; ipp_req.dst_vir_w = width; ipp_req.timeout = 100; ipp_req.flag = IPP_ROT_0; ipp_req.deinterlace_enable = bypass ? 0 : 1; ipp_req.deinterlace_para0 = 8; ipp_req.deinterlace_para1 = 16; ipp_req.deinterlace_para2 = 8; ipp_req.dst0.YrgbMst = dstYAddr; ipp_req.dst0.CbrMst = dstCAddr; ret = ioctl(dev_fd, IPP_BLIT_ASYNC, &ipp_req); } break; case USING_IEP : { /** IEP_FORMAT_ARGB_8888 = 0x0, IEP_FORMAT_ABGR_8888 = 0x1, IEP_FORMAT_RGBA_8888 = 0x2, IEP_FORMAT_BGRA_8888 = 0x3, IEP_FORMAT_RGB_565 = 0x4, IEP_FORMAT_BGR_565 = 0x5, IEP_FORMAT_YCbCr_422_SP = 0x10, IEP_FORMAT_YCbCr_422_P = 0x11, IEP_FORMAT_YCbCr_420_SP = 0x12, IEP_FORMAT_YCbCr_420_P = 0x13, IEP_FORMAT_YCrCb_422_SP = 0x14, IEP_FORMAT_YCrCb_422_P = 0x15, IEP_FORMAT_YCrCb_420_SP = 0x16, IEP_FORMAT_YCrCb_420_P = 0x17 */ ops.init_discrete(api, width, height, 0, 0, width, height, 0x12, srcYAddr, srcCAddr, 0, width, height, 0, 0, width, height, 0x12, dstYAddr, dstCAddr, 0); if (!bypass) { if (0 > ops.config_yuv_deinterlace(api)) { DEINTER_ERR("Failure to Configure YUV DEINTERLACE\n"); } } ops.run_async_ncb(api); } break; case USING_PP : { if (NULL == priv_data) { PP_OPERATION opt; memset(&opt, 0, sizeof(opt)); opt.srcAddr = srcYAddr; opt.srcFormat = PP_IN_FORMAT_YUV420SEMI; opt.srcWidth = opt.srcHStride = width; opt.srcHeight = opt.srcVStride = height; opt.dstAddr = dstYAddr; opt.dstFormat = PP_OUT_FORMAT_YUV420INTERLAVE; opt.dstWidth = opt.dstHStride = width; opt.dstHeight = opt.dstVStride = height; opt.deinterlace = 1; opt.vpuFd = dev_fd; ret = ppOpInit(&priv_data, &opt); if (ret) { DEINTER_ERR("ppOpInit failed"); priv_data = NULL; } } if (NULL != priv_data) { PP_OP_HANDLE hnd = (PP_OP_HANDLE)priv_data; ppOpSet(hnd, PP_SET_SRC_ADDR, srcYAddr); ppOpSet(hnd, PP_SET_DST_ADDR, dstYAddr); ret = ppOpPerform(hnd); } } break; default : { ret = BAD_VALUE; } break; } if (!ret) { VPUMemDuplicate(&frm->vpumem,&deInterlaceFrame); } else { DEINTER_ERR("ioctl: IPP_BLIT_ASYNC faild!"); } VPUFreeLinear(&deInterlaceFrame); } return ret; }
/*放大: 重视速度:fast_bilinear, point 重视质量:cubic, spline, lanczos 缩小: 重视速度:fast_bilinear, point 重视质量:gauss, bilinear 重视锐度:cubic,spline,lanczos */ int main(int argc, char **argv){ printf(" <%s>_%d \n", __func__, __LINE__); VpuApiDemoCmdContext_t demoCmdCtx; VpuApiDemoCmdContext_t* cmd = &demoCmdCtx; RK_S32 ret =0; if ((ret = parse_options(argc, argv, cmd)) !=0) { if (ret == VPU_DEMO_PARSE_HELP_OK) { return 0; } printf(" <%s>_%d error argv ..... \n", __func__, __LINE__); return 0; } #if TEST_SCALE VPUMemLinear_t inMem; //VPUMemLinear_t outMem; int inputw = 2592; int inputh = 1944; int outw = 160; int outh = 128; FILE *yuvFile = NULL; int in_size = inputw*inputh*3; VPUMallocLinear(&inMem, in_size); yuvFile = fopen("/flash/yuv2592_1944.yuv","rb"); fread(inMem.vir_addr,1,in_size,yuvFile); VPUMemFlush(&inMem); fclose(yuvFile); { int w = inputw; int h = inputh; uint8_t * src = (uint8_t*)inMem.vir_addr; uint8_t * yuvsrc[4] = {src, src+w*h, NULL, NULL}; int yuvsrcstride[4] = {inputw, inputw, 0, 0}; uint8_t * dst = (uint8_t*)malloc(outw*outh*3/2); uint8_t * yuvdst[4] = {dst, dst+outw*outh, NULL, NULL}; int yuvdststride[4] = {outw, outw, 0, 0}; struct SwsContext *sws = sws_getContext(w,h, PIX_FMT_NV12, outw, outh, PIX_FMT_NV12, SWS_FAST_BILINEAR, NULL, NULL, NULL); ALOGE("before sws_scale."); sws_scale(sws, yuvsrc, yuvsrcstride, 0, inputh, yuvdst, yuvdststride); ALOGE("after sws_scale."); sws_freeContext(sws); yuvFile = fopen("/flash/yuv160_128.yuv", "wb"); fwrite(dst, 1, outw*outh*3/2, yuvFile); fclose(yuvFile); free(dst); } VPUFreeLinear(&inMem); #else int loopCounts = 0; JpegEncInInfo JpegInInfo; RkExifInfo exifInfo; RkGPSInfo gpsInfo; char* maker = "rockchip sb"; char* model = "rockchip camera"; JpegEncOutInfo JpegOutInfo; char *time = "2011:07:05 17:53:53"; char* gpsprocessmethod = "GPS chuli ge mao a."; int jpegw = cmd->width;//1680;//2592; int jpegh = cmd->height;//1050;//1944; //int jpegw = 160; //int jpegh = 120; VPUMemLinear_t inMem; VPUMemLinear_t outMem; printf(" <%s>_%d <%d, %d>\n", __func__, __LINE__, jpegw, jpegh); VPUMemLinear_t tmp180Mem; //#define RGB_DEBUG #ifndef RGB_DEBUG int in_size = jpegw*jpegh*3/2+897;//yuv420 #else int in_size; int pixelBytes = 2; int in_rgb_size = in_size = jpegw*jpegh*pixelBytes;//xrgb888 rgb565 int in_yuv420_size = jpegw*jpegh*3/2;//yuv420 #endif printf(" <%s>_%d \n", __func__, __LINE__); int out_size = jpegw*jpegh + 160 * 128*16; //void* thumbBuf = NULL; //FILE *tFile = NULL; int thumbfilelen = -1; FILE *file = NULL; FILE *yuvFile = NULL; #ifdef RGB_DEBUG char* yuvdata = (char*)malloc(in_yuv420_size); printf(" <%s>_%d \n", __func__, __LINE__); if(yuvdata == NULL){ ALOGE("f**k 1."); } printf(" <%s>_%d \n", __func__, __LINE__); VPUMallocLinear(&inMem, in_rgb_size); #else printf(" <%s>_%d \n", __func__, __LINE__); VPUMallocLinear(&inMem, in_size); printf(" <%s>_%d \n", __func__, __LINE__); #endif VPUMallocLinear(&outMem, out_size); gMem = &outMem; //yuvFile = fopen("/sdcard/1680_1050_yuv420sp.yuv","rb"); yuvFile = fopen(cmd->input_file,"rb"); //yuvFile = fopen("/flash/160_120_yuv420sp.yuv","rb"); #ifdef RGB_DEBUG//rgb fread(yuvdata, 1, in_yuv420_size, yuvFile); //memset(yuvdata, 0xf0, in_yuv420_size); #if 1 { int w = jpegw; int h = jpegh; uint8_t * dst = (uint8_t*)inMem.vir_addr; uint8_t * yuvdst[4] = {dst, NULL, NULL, NULL}; int yuvdststride[4] = {pixelBytes*w, 0, 0, 0}; uint8_t * src = (uint8_t*)yuvdata; uint8_t * yuvsrc[4] = {src, src+w*h, NULL, NULL}; int yuvsrcstride[4] = {w, w, 0, 0}; struct SwsContext *sws = sws_getContext(w,h, PIX_FMT_NV12, w, h, PIX_FMT_RGB565,//PIX_FMT_RGB32 SWS_FAST_BILINEAR, NULL, NULL, NULL); ALOGE("before sws_scale1."); sws_scale(sws, yuvsrc, yuvsrcstride, 0, h, yuvdst, yuvdststride); ALOGE("after sws_scale1."); sws_freeContext(sws); //yuvFile = fopen("/flash/yuv160_128.yuv", "wb"); //fwrite(dst, 1, outw*outh*3/2, yuvFile); //fclose(yuvFile); //free(dst); } free(yuvdata); #else free(yuvdata); { int i = 0; unsigned char* st = (unsigned char*)inMem.vir_addr; unsigned int c = 0xff; int j = 0; for(;i<jpegh;i++){ for(j = 0; j<jpegw; j++){ *st++ = 0; *st++ = 0; *st++ = 0xff; *st++ = 0; } //c += 0xff; } printf("color: 0x%x\n", *(unsigned int*)inMem.vir_addr); } #endif #else fread(inMem.vir_addr,1,in_size,yuvFile); #endif VPUMemFlush(&inMem); fclose(yuvFile); exifInfo.maker = maker; exifInfo.makerchars = 12; exifInfo.modelstr = model; exifInfo.modelchars = 16; exifInfo.Orientation = 1; memcpy(exifInfo.DateTime, time, 20); exifInfo.ExposureTime.num = 400; exifInfo.ExposureTime.denom = 1; exifInfo.ApertureFNumber.num = 0x118; exifInfo.ApertureFNumber.denom = 0x64; exifInfo.ISOSpeedRatings = 0x59; exifInfo.CompressedBitsPerPixel.num = 0x4; exifInfo.CompressedBitsPerPixel.denom = 0x1; exifInfo.ShutterSpeedValue.num = 0x452; exifInfo.ShutterSpeedValue.denom = 0x100; exifInfo.ApertureValue.num = 0x2f8; exifInfo.ApertureValue.denom = 0x100; exifInfo.ExposureBiasValue.num = 0; exifInfo.ExposureBiasValue.denom = 0x100; exifInfo.MaxApertureValue.num = 0x02f8; exifInfo.MaxApertureValue.denom = 0x100; exifInfo.MeteringMode = 02; exifInfo.Flash = 0x10; exifInfo.FocalLength.num = 0x4; exifInfo.FocalLength.denom = 0x1; exifInfo.FocalPlaneXResolution.num = 0x8383; exifInfo.FocalPlaneXResolution.denom = 0x67; exifInfo.FocalPlaneYResolution.num = 0x7878; exifInfo.FocalPlaneYResolution.denom = 0x76; exifInfo.SensingMethod = 2; exifInfo.FileSource = 3; exifInfo.CustomRendered = 1; exifInfo.ExposureMode = 0; exifInfo.WhiteBalance = 0; exifInfo.DigitalZoomRatio.num = jpegw; exifInfo.DigitalZoomRatio.denom = jpegw; exifInfo.SceneCaptureType = 0x01; gpsInfo.GPSLatitudeRef[0] = 'N'; gpsInfo.GPSLatitudeRef[1] = '\0'; gpsInfo.GPSLatitude[0].num = 0x77; gpsInfo.GPSLatitude[0].denom = 1; gpsInfo.GPSLatitude[1].num = 0x66; gpsInfo.GPSLatitude[1].denom = 1; gpsInfo.GPSLatitude[2].num = 0x55; gpsInfo.GPSLatitude[2].denom = 1; gpsInfo.GPSLongitudeRef[0] = 'E'; gpsInfo.GPSLongitudeRef[1] = '\0'; gpsInfo.GPSLongitude[0].num = 0x44; gpsInfo.GPSLongitude[0].denom = 1; gpsInfo.GPSLongitude[1].num = 0x33; gpsInfo.GPSLongitude[1].denom = 1; gpsInfo.GPSLongitude[2].num = 0x22; gpsInfo.GPSLongitude[2].denom = 1; gpsInfo.GPSAltitudeRef = 1; gpsInfo.GPSAltitude.num = 0x88; gpsInfo.GPSAltitude.denom = 0x1; gpsInfo.GpsTimeStamp[0].num = 18; gpsInfo.GpsTimeStamp[0].denom = 1; gpsInfo.GpsTimeStamp[1].num = 36; gpsInfo.GpsTimeStamp[1].denom = 1; gpsInfo.GpsTimeStamp[2].num = 48; gpsInfo.GpsTimeStamp[2].denom = 1; memcpy(gpsInfo.GpsDateStamp,"2011:07:05",11);//"YYYY:MM:DD\0" gpsInfo.GPSProcessingMethod = gpsprocessmethod; gpsInfo.GpsProcessingMethodchars = 20;//length of GpsProcessingMethod JpegInInfo.frameHeader = 1; JpegInInfo.rotateDegree = DEGREE_0; JpegInInfo.y_rgb_addr = inMem.phy_addr; #ifndef RGB_DEBUG JpegInInfo.uv_addr = inMem.phy_addr + (jpegw*jpegh); #else JpegInInfo.uv_addr = 0; #endif JpegInInfo.y_vir_addr = (unsigned char*)inMem.vir_addr; #ifndef RGB_DEBUG JpegInInfo.uv_vir_addr = ((unsigned char*)inMem.vir_addr + jpegw*jpegh); #else JpegInInfo.uv_vir_addr = 0; #endif if(JpegInInfo.rotateDegree == DEGREE_180){ VPUMallocLinear(&tmp180Mem, in_size); JpegInInfo.yuvaddrfor180 = tmp180Mem.phy_addr; }else{ JpegInInfo.yuvaddrfor180 = NULL; } JpegInInfo.inputW = jpegw; JpegInInfo.inputH = jpegh; #ifdef RGB_DEBUG JpegInInfo.type = HWJPEGENC_RGB565;//HWJPEGENC_RGB888; #else JpegInInfo.type = JPEGENC_YUV420_SP; #endif JpegInInfo.qLvl = 9; //tFile = fopen("/flash/thumbtest.jpg","rb"); //fseek(tFile, SEEK_SET, SEEK_END); //thumbfilelen = ftell(tFile);//bu chao guo 2G //thumbBuf = malloc(thumbfilelen); //fseek(tFile, SEEK_SET, SEEK_SET); //fread(thumbBuf,1, thumbfilelen, tFile); //fclose(tFile); #ifdef RGB_DEBUG JpegInInfo.doThumbNail = 1; #else JpegInInfo.doThumbNail = 0;//insert thumbnail at APP0 extension if motionjpeg, else at APP1 extension #endif JpegInInfo.thumbData = NULL;//if thumbData is NULL, do scale, the type above can not be 420_P or 422_UYVY JpegInInfo.thumbDataLen = -1; JpegInInfo.thumbW = 160; JpegInInfo.thumbH = 128;//128; JpegInInfo.thumbqLvl = 5; JpegInInfo.exifInfo = &exifInfo; JpegInInfo.gpsInfo = &gpsInfo; JpegOutInfo.outBufPhyAddr = outMem.phy_addr; JpegOutInfo.outBufVirAddr = (unsigned char*)outMem.vir_addr; JpegOutInfo.outBuflen = out_size; JpegOutInfo.jpegFileLen = 0; JpegOutInfo.cacheflush = flush; ALOGE("outbuflen: %d", out_size); static char str[32] = {'\0'}; for(loopCounts = 0; loopCounts < 1; loopCounts++){ if(hw_jpeg_encode(&JpegInInfo, &JpegOutInfo) < 0 || JpegOutInfo.jpegFileLen <= 0){ ALOGE("hw jpeg encode fail."); }else{ ALOGD("final file offset: %d, size: %d", JpegOutInfo.finalOffset, JpegOutInfo.jpegFileLen); //VPUMemFlush(&outMem); //SkBitmap bitmap; //SkImageDecoder::DecodeMemory(JpegOutInfo.outBufVirAddr + JpegOutInfo.finalOffset, JpegOutInfo.jpegFileLen, &bitmap, // SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode); //ALOGE("decode complete. %p", bitmap.getPixels()); sprintf(str, cmd->output_file, loopCounts); file = fopen(str,"wb"); fwrite(JpegOutInfo.outBufVirAddr + JpegOutInfo.finalOffset, 1, JpegOutInfo.jpegFileLen, file); fclose(file); //ALOGE(); } } //free(thumbBuf); VPUFreeLinear(&inMem); VPUFreeLinear(&outMem); if(JpegInInfo.rotateDegree == DEGREE_180){ VPUFreeLinear(&tmp180Mem); } #endif return 0; }
static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd) { if (cmd == NULL) { return -1; } FILE* pInFile = NULL; FILE* pOutFile = NULL; struct VpuCodecContext* ctx = NULL; RK_S32 fileSize =0, pkt_size =0; RK_S32 ret = 0, frame_count = 0; DecoderOut_t decOut; VideoPacket_t demoPkt; VideoPacket_t* pkt =NULL; DecoderOut_t *pOut = NULL; VPU_FRAME *frame = NULL; RK_S64 fakeTimeUs =0; RK_U8* pExtra = NULL; RK_U32 extraSize = 0; if ((cmd->have_input == NULL) || (cmd->width <=0) || (cmd->height <=0) || (cmd->coding <= OMX_ON2_VIDEO_CodingAutoDetect)) { VPU_DEMO_LOG("Warning: missing needed parameters for vpu api demo\n"); } if (cmd->have_input) { VPU_DEMO_LOG("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n", cmd->width, cmd->height, cmd->coding, cmd->codec_type == CODEC_DECODER ? "decode" : "encode", cmd->input_file); pInFile = fopen(cmd->input_file, "rb"); if (pInFile == NULL) { VPU_DEMO_LOG("input file not exsist\n"); DECODE_ERR_RET(ERROR_INVALID_PARAM); } } else { VPU_DEMO_LOG("please set input bitstream file\n"); DECODE_ERR_RET(ERROR_INVALID_PARAM); } if (cmd->have_output) { VPU_DEMO_LOG("vpu api demo output file: %s\n", cmd->output_file); pOutFile = fopen(cmd->output_file, "wb"); if (pOutFile == NULL) { VPU_DEMO_LOG("can not write output file\n"); DECODE_ERR_RET(ERROR_INVALID_PARAM); } if (cmd->record_frames ==0) cmd->record_frames = 5; } fseek(pInFile, 0L, SEEK_END); fileSize = ftell(pInFile); fseek(pInFile, 0L, SEEK_SET); VPU_DEMO_LOG(" fileSize = %d \n", fileSize); memset(&demoPkt, 0, sizeof(VideoPacket_t)); pkt = &demoPkt; pkt->data = NULL; pkt->pts = VPU_API_NOPTS_VALUE; pkt->dts = VPU_API_NOPTS_VALUE; memset(&decOut, 0, sizeof(DecoderOut_t)); pOut = &decOut; pOut->data = (RK_U8*)(malloc)(sizeof(VPU_FRAME)); if (pOut->data ==NULL) { DECODE_ERR_RET(ERROR_MEMORY); } memset(pOut->data, 0, sizeof(VPU_FRAME)); ret = vpu_open_context(&ctx); if (ret || (ctx ==NULL)) { DECODE_ERR_RET(ERROR_MEMORY); } /* ** read codec extra data from input stream file. */ if (readBytesFromFile((RK_U8*)(&extraSize), 4, pInFile)) { DECODE_ERR_RET(ERROR_IO); } // extraSize = fileSize; VPU_DEMO_LOG("codec extra data size: %d", extraSize); pExtra = (RK_U8*)(malloc)(extraSize); if (pExtra ==NULL) { DECODE_ERR_RET(ERROR_MEMORY); } memset(pExtra, 0, extraSize); if (readBytesFromFile(pExtra, extraSize, pInFile)) { DECODE_ERR_RET(ERROR_IO); } /* ** now init vpu api context. codecType, codingType, width ,height ** are all needed before init. */ ctx->codecType = cmd->codec_type; ctx->videoCoding = cmd->coding; ctx->width = cmd->width; ctx->height = cmd->height; ctx->no_thread = 1; if ((ret = ctx->init(ctx, pExtra, extraSize)) !=0) { VPU_DEMO_LOG("init vpu api context fail, ret: 0x%X", ret); DECODE_ERR_RET(ERROR_INIT_VPU); } /* ** vpu api decoder process. */ VPU_DEMO_LOG("init vpu api context ok, fileSize: %d", fileSize); do { if (ftell(pInFile) >=fileSize) { VPU_DEMO_LOG("read end of file, complete"); break; } if (pkt && (pkt->size ==0)) { if (readBytesFromFile((RK_U8*)(&pkt_size), 4, pInFile)) { break; } if (pkt->data ==NULL) { pkt->data = (RK_U8*)(malloc)(pkt_size); if (pkt->data ==NULL) { DECODE_ERR_RET(ERROR_MEMORY); } pkt->capability = pkt_size; } if (pkt->capability <((RK_U32)pkt_size)) { pkt->data = (RK_U8*)(realloc)((void*)(pkt->data), pkt_size); if (pkt->data ==NULL) { DECODE_ERR_RET(ERROR_MEMORY); } pkt->capability = pkt_size; } if (readBytesFromFile(pkt->data, pkt_size, pInFile)) { break; } else { pkt->size = pkt_size; pkt->pts = fakeTimeUs; fakeTimeUs +=40000; } VPU_DEMO_LOG("read one packet, size: %d, pts: %lld, filePos: %ld", pkt->size, pkt->pts, ftell(pInFile)); } /* note: must set out put size to 0 before do decoder. */ pOut->size = 0; if ((ret = ctx->decode(ctx, pkt, pOut)) !=0) { DECODE_ERR_RET(ERROR_VPU_DECODE); } else { VPU_DEMO_LOG("vpu decode one frame, out len: %d, left size: %d", pOut->size, pkt->size); /* ** both virtual and physical address of the decoded frame are contained ** in structure named VPU_FRAME, if you want to use virtual address, make ** sure you have done VPUMemLink before. */ if ((pOut->size) && (pOut->data)) { VPU_FRAME *frame = (VPU_FRAME *)(pOut->data); VPUMemLink(&frame->vpumem); RK_U32 wAlign16 = ((frame->DisplayWidth+ 15) & (~15)); RK_U32 hAlign16 = ((frame->DisplayHeight + 15) & (~15)); RK_U32 frameSize = wAlign16*hAlign16*3/2; if(pOutFile && (frame_count++ <cmd->record_frames)) { VPU_DEMO_LOG("write %d frame(yuv420sp) data, %d bytes to file", frame_count, frameSize); fwrite((RK_U8*)(frame->vpumem.vir_addr), 1, frameSize, pOutFile); fflush(pOutFile); } /* ** remember use VPUFreeLinear to free, other wise memory leak will ** give you a surprise. */ VPUFreeLinear(&frame->vpumem); pOut->size = 0; } } usleep(30); }while(!(ctx->decoder_err)); DECODE_OUT: if (pkt && pkt->data) { free(pkt->data); pkt->data = NULL; } if (pOut && (pOut->data)) { free(pOut->data); pOut->data = NULL; } if (pExtra) { free(pExtra); pExtra = NULL; } if (ctx) { vpu_close_context(&ctx); ctx = NULL; } if (pInFile) { fclose(pInFile); pInFile = NULL; } if (pOutFile) { fclose(pOutFile); pOutFile = NULL; } if (ret) { VPU_DEMO_LOG("decode demo fail, err: %d", ret); } else { VPU_DEMO_LOG("encode demo complete OK."); } return ret; }
int main(int argc, char **argv) { int i; pthread_t td; int ch; int pmem_phy_head; uint8_t *pmem_vir_head; VPUMemLinear_t vpumem; mem_region_t mr; mr.src_fmt = IEP_FORMAT_YCbCr_420_SP; mr.src_w = 640; mr.src_h = 480; mr.dst_fmt = IEP_FORMAT_YCbCr_420_SP; mr.dst_w = 640; mr.dst_h = 480; /// get options opterr = 0; while ((ch = getopt(argc, argv, "f:w:h:c:F:W:H:C:t:x:")) != -1) { switch (ch) { case 'w': mr.src_w = atoi(optarg); break; case 'h': mr.src_h = atoi(optarg); break; case 'c': if (strcmp(optarg, "argb8888") == 0) { mr.src_fmt = IEP_FORMAT_ARGB_8888; } else if (strcmp(optarg, "abgr8888") == 0) { mr.src_fmt = IEP_FORMAT_ABGR_8888; } else if (strcmp(optarg, "rgba8888") == 0) { mr.src_fmt = IEP_FORMAT_BGRA_8888; } else if (strcmp(optarg, "bgra8888") == 0) { mr.src_fmt = IEP_FORMAT_BGRA_8888; } else if (strcmp(optarg, "rgb565") == 0) { mr.src_fmt = IEP_FORMAT_RGB_565; } else if (strcmp(optarg, "bgr565") == 0) { mr.src_fmt = IEP_FORMAT_BGR_565; } else if (strcmp(optarg, "yuv422sp") == 0) { mr.src_fmt = IEP_FORMAT_YCbCr_422_SP; } else if (strcmp(optarg, "yuv422p") == 0) { mr.src_fmt = IEP_FORMAT_YCbCr_422_P; } else if (strcmp(optarg, "yuv420sp") == 0) { mr.src_fmt = IEP_FORMAT_YCbCr_420_SP; } else if (strcmp(optarg, "yuv420p") == 0) { mr.src_fmt = IEP_FORMAT_YCbCr_420_P; } else if (strcmp(optarg, "yvu422sp") == 0) { mr.src_fmt = IEP_FORMAT_YCrCb_422_SP; } else if (strcmp(optarg, "yvu422p") == 0) { mr.src_fmt = IEP_FORMAT_YCrCb_422_P; } else if (strcmp(optarg, "yvu420sp") == 0) { mr.src_fmt = IEP_FORMAT_YCrCb_420_SP; } else if (strcmp(optarg, "yvu420p") == 0) { mr.src_fmt = IEP_FORMAT_YCrCb_420_P; } break; case 'W': mr.dst_w = atoi(optarg); break; case 'H': mr.dst_h = atoi(optarg); break; case 'C': if (strcmp(optarg, "argb8888") == 0) { mr.dst_fmt = IEP_FORMAT_ARGB_8888; } else if (strcmp(optarg, "abgr8888") == 0) { mr.dst_fmt = IEP_FORMAT_ABGR_8888; } else if (strcmp(optarg, "rgba8888") == 0) { mr.dst_fmt = IEP_FORMAT_BGRA_8888; } else if (strcmp(optarg, "bgra8888") == 0) { mr.dst_fmt = IEP_FORMAT_BGRA_8888; } else if (strcmp(optarg, "rgb565") == 0) { mr.dst_fmt = IEP_FORMAT_RGB_565; } else if (strcmp(optarg, "bgr565") == 0) { mr.dst_fmt = IEP_FORMAT_BGR_565; } else if (strcmp(optarg, "yuv422sp") == 0) { mr.dst_fmt = IEP_FORMAT_YCbCr_422_SP; } else if (strcmp(optarg, "yuv422p") == 0) { mr.dst_fmt = IEP_FORMAT_YCbCr_422_P; } else if (strcmp(optarg, "yuv420sp") == 0) { mr.dst_fmt = IEP_FORMAT_YCbCr_420_SP; } else if (strcmp(optarg, "yuv420p") == 0) { mr.dst_fmt = IEP_FORMAT_YCbCr_420_P; } else if (strcmp(optarg, "yvu422sp") == 0) { mr.dst_fmt = IEP_FORMAT_YCrCb_422_SP; } else if (strcmp(optarg, "yvu422p") == 0) { mr.dst_fmt = IEP_FORMAT_YCrCb_422_P; } else if (strcmp(optarg, "yvu420sp") == 0) { mr.dst_fmt = IEP_FORMAT_YCrCb_420_SP; } else if (strcmp(optarg, "yvu420p") == 0) { mr.dst_fmt = IEP_FORMAT_YCrCb_420_P; } break; case 'f': ALOGD("input filename: %s\n", optarg); strcpy(mr.src_url, optarg); break; case 'F': ALOGD("output filename: %s\n", optarg); strcpy(mr.dst_url, optarg); break; case 't': if (strcmp(optarg, "denoise") == 0) { mr.testcase = TEST_CASE_DENOISE; } else if (strcmp(optarg, "yuvenhance") == 0) { mr.testcase = TEST_CASE_YUVENHANCE; } else if (strcmp(optarg, "rgbenhance") == 0) { mr.testcase = TEST_CASE_RGBENHANCE; } else if (strcmp(optarg, "deinterlace") == 0) { mr.testcase = TEST_CASE_DEINTERLACE; } else { mr.testcase = TEST_CASE_NONE; } break; case 'x': ALOGD("configure filename: %s\n", optarg); strcpy(mr.cfg_url, optarg); break; default: ; } } /// allocate in/out memory and initialize memory address VPUMallocLinear(&vpumem, 12<<20); pmem_phy_head = vpumem.phy_addr;//region.offset; pmem_vir_head = (uint8_t*)vpumem.vir_addr; mr.len_reg = 0x100; mr.len_src = 5<<20; mr.len_dst = 5<<20; mr.phy_reg = vpumem.phy_addr; pmem_phy_head += mr.len_reg; mr.phy_src = pmem_phy_head; pmem_phy_head += mr.len_src; mr.phy_dst = pmem_phy_head; pmem_phy_head += mr.len_dst; mr.vir_reg = (uint8_t*)vpumem.vir_addr; pmem_vir_head += mr.len_reg; mr.vir_src = pmem_vir_head; pmem_vir_head += mr.len_src; mr.vir_dst = pmem_vir_head; pmem_vir_head += mr.len_dst; pthread_create(&td, NULL, iep_process_thread, &mr); pthread_join(td, NULL); VPUFreeLinear(&vpumem); return 0; }