EncodingInstance vpu_create_encoding_instance(const int src_width, const int src_height, const char* filename) { EncodingInstance instance = NULL; instance = calloc(1, sizeof(struct EncodingInstance)); instance->mem_desc.size = STREAM_BUF_SIZE; IOGetPhyMem(&(instance->mem_desc)); instance->virt_bsbuf_addr = IOGetVirtMem(&(instance->mem_desc)); instance->phy_bsbuf_addr = instance->mem_desc.phy_addr; instance->src_picwidth = src_width; instance->src_picheight = src_height; // instance->enc_picwidth = 640; // instance->enc_picheight = 480; instance->fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); encoder_open(instance); encoder_configure(instance); encoder_allocate_framebuffer(instance); encoder_fill_headers(instance); instance->enc_param.sourceFrame = &instance->fb[instance->src_fbid]; instance->enc_param.quantParam = 23; instance->enc_param.forceIPicture = 0; instance->enc_param.skipPicture = 0; instance->enc_param.enableAutoSkip = 1; instance->enc_param.encLeftOffset = 0; instance->enc_param.encTopOffset = 0; return instance; }
int32_t encoder_setup(void *arg) { struct codec_control *codecctrl = NULL; vpu_mem_desc mem_desc = { 0 }; vpu_mem_desc scratch_mem_desc = { 0 }; struct encode *enc; int32_t ret = 0; /*set the parameters of encoder input here!! */ codecctrl = (struct codec_control *)arg; /* allocate memory for must remember stuff */ enc = (struct encode *)calloc(1, sizeof(struct encode)); if (enc == NULL) { err_msg("Failed to allocate encode structure\n"); return -1; } /* get the contigous bit stream buffer */ mem_desc.size = STREAM_BUF_SIZE; ret = vpu_malloc(&mem_desc); if (ret) { err_msg("Unable to obtain physical memory\n"); free(enc); return -1; } /* mmap that physical buffer, in OS the virt and phy addr could be different */ enc->virt_bsbuf_addr = mem_desc.virt_addr; enc->phy_bsbuf_addr = mem_desc.phy_addr; enc->codecctrl = codecctrl; /* get the contigous bit stream buffer */ mem_desc.size = ENCODER_OUTPUT_SIZE; ret = vpu_malloc(&mem_desc); if (ret) { err_msg("Unable to obtain physical memory\n"); free(enc); return -1; } enc->codecctrl->output_mem_addr = mem_desc.phy_addr; g_bs_memory.bs_start = enc->codecctrl->output_mem_addr; g_bs_memory.bs_end = enc->codecctrl->output_mem_addr; if (enc->codecctrl->mapType) { enc->linear2TiledEnable = 1; enc->codecctrl->chromaInterleave = 1; /* Must be CbCrInterleave for tiled */ } else enc->linear2TiledEnable = 0; /* open the encoder */ ret = encoder_open(enc); if (ret) goto err; /* configure the encoder */ ret = encoder_configure(enc); if (ret) goto err1; if ((codecctrl->format == STD_MPEG4) && enc->mp4_dataPartitionEnable) { scratch_mem_desc.size = MPEG4_SCRATCH_SIZE; ret = vpu_malloc(&scratch_mem_desc); if (ret) { err_msg("Unable to obtain physical slice save mem\n"); goto err1; } enc->scratchBuf.bufferBase = scratch_mem_desc.phy_addr; enc->scratchBuf.bufferSize = scratch_mem_desc.size; } /* allocate memory for the frame buffers */ ret = encoder_allocate_framebuffer(enc); if (ret) goto err1; /* start encoding */ ret = encoder_start(enc); if (enc->codecctrl->dst_scheme == PATH_MEM) printf("Encoded output is stored from 0x%08x to 0x%08x\n", g_bs_memory.bs_start, g_bs_memory.bs_end); /* free the allocated framebuffers */ encoder_free_framebuffer(enc); err1: /* close the encoder */ encoder_close(enc); err: free(enc); return ret; }