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; }
static bool recorder_output_open(void *data, struct audio_format *audio_format, GError **error_r) { struct recorder_output *recorder = data; bool success; /* create the output file */ recorder->fd = open_cloexec(recorder->path, O_CREAT|O_WRONLY|O_TRUNC, 0666); if (recorder->fd < 0) { g_set_error(error_r, recorder_output_quark(), 0, "Failed to create '%s': %s", recorder->path, g_strerror(errno)); return false; } /* open the encoder */ success = encoder_open(recorder->encoder, audio_format, error_r); if (!success) { close(recorder->fd); unlink(recorder->path); return false; } return true; }
static bool httpd_output_encoder_open(struct httpd_output *httpd, struct audio_format *audio_format, GError **error) { bool success; success = encoder_open(httpd->encoder, audio_format, error); if (!success) return false; /* we have to remember the encoder header, i.e. the first bytes of encoder output after opening it, because it has to be sent to every new client */ httpd->header = httpd_output_read_page(httpd); return true; }
int main(int argc, char **argv) { GError *error = NULL; struct audio_format audio_format; bool ret; const char *encoder_name; const struct encoder_plugin *plugin; struct encoder *encoder; struct config_param *param; static char buffer[32768]; ssize_t nbytes; /* parse command line */ if (argc > 3) { g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); return 1; } if (argc > 1) encoder_name = argv[1]; else encoder_name = "vorbis"; audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2); /* create the encoder */ plugin = encoder_plugin_get(encoder_name); if (plugin == NULL) { g_printerr("No such encoder: %s\n", encoder_name); return 1; } param = config_new_param(NULL, -1); config_add_block_param(param, "quality", "5.0", -1); encoder = encoder_init(plugin, param, &error); if (encoder == NULL) { g_printerr("Failed to initialize encoder: %s\n", error->message); g_error_free(error); return 1; } /* open the encoder */ if (argc > 2) { ret = audio_format_parse(&audio_format, argv[2], false, &error); if (!ret) { g_printerr("Failed to parse audio format: %s\n", error->message); g_error_free(error); return 1; } } ret = encoder_open(encoder, &audio_format, &error); if (encoder == NULL) { g_printerr("Failed to open encoder: %s\n", error->message); g_error_free(error); return 1; } /* do it */ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { ret = encoder_write(encoder, buffer, nbytes, &error); if (!ret) { g_printerr("encoder_write() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); } ret = encoder_flush(encoder, &error); if (!ret) { g_printerr("encoder_flush() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); }
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; }