📄 app_yuv_to_jpeg_support.c
字号:
//////////////////////////////////////////////////////////////////////////////////////////////////////// app_yuv_to_jpeg_support.h //// Notice: COPYRIGHT (C) STREAM PROCESSORS, INC. 2005-2007// THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE SPI// END-USER LICENSE AGREEMENT (EULA). THE PROGRAM MAY ONLY// BE USED IN A MANNER EXPLICITLY SPECIFIED IN THE EULA,// WHICH INCLUDES LIMITATIONS ON COPYING, MODIFYING,// REDISTRIBUTION AND WARANTIES. UNAUTHORIZED USE OF THIS// PROGRAM IS STRICTLY PROHIBITED. YOU MAY OBTAIN A COPY OF// THE EULA FROM WWW.STREAMPROCESSORS.COM. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #includes ////////////////////////////////////////////////////////////////////////////////#include <stdio.h>#include <string.h>#include <stdlib.h>#include "spi_macros.h"#include "spi_fw_client.h"#include "app_config.h"#include "task_context.h"#include "dsp_mips_dpam_attribs.h"#include "spvejpeg_dpam.h"#include "jpeg_to_avi.h"// Functions for executing channel encoding.int read_yuv(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data);int write_jpeg(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data, int size);int open_avi_handle(CHANNEL_CONTEXT_T *p_channel_context);int write_avi(CHANNEL_CONTEXT_T *p_channel_context, unsigned char *p_data, int size);int configure_channel(CHANNEL_CONFIG_T *p_channel_config, CHANNEL_CONTEXT_T *p_channel_context){ p_channel_context->channel_id = p_channel_config->channel_id; p_channel_context->status = E_RUN; strcpy(p_channel_context->yuv_filename, p_channel_config->yuv_filename); strcpy(p_channel_context->avi_filename, p_channel_config->avi_filename); strcpy(p_channel_context->jpeg_filename, p_channel_config->jpeg_filename); p_channel_context->enable_avi = p_channel_config->enable_avi; p_channel_context->enable_jpeg = p_channel_config->enable_jpeg; p_channel_context->avi_fps = p_channel_config->avi_fps; p_channel_context->width = p_channel_config->width; p_channel_context->height = p_channel_config->height; p_channel_context->format = p_channel_config->format; p_channel_context->quality = p_channel_config->quality; p_channel_context->skip_count = p_channel_config->skip_count; p_channel_context->total_frames = p_channel_config->tot_frames; p_channel_context->frame_number = 0; p_channel_context->quality = p_channel_config->quality; return SUCCESS;}int get_handles(CHANNEL_CONTEXT_T *p_channel_context){ SPVEJPEG_FW_SETTINGS_T fw_settings;/* Init dpam and get dpam handles */ fw_settings.channel_id = 0; fw_settings.status = SPVEJPEG_DPAM_RUN; fw_settings.width = p_channel_context->width; fw_settings.height = p_channel_context->height; fw_settings.format = p_channel_context->format; fw_settings.quality = p_channel_context->quality; ERR_HANDLE(spi_fw_init(&p_channel_context->fw_venc_dpam_handle, &spvejpeg_fw_attributes, (void *)&fw_settings, sizeof(fw_settings), NULL));/* Get dpam pin handles */ ERR_HANDLE(spi_fw_get_pin(p_channel_context->fw_venc_dpam_handle, SPVEJPEG_IN_PIN_NAME, &p_channel_context->fw_venc_in_pin_handle)); ERR_HANDLE(spi_fw_get_pin(p_channel_context->fw_venc_dpam_handle, SPVEJPEG_OUT_PIN_NAME, &p_channel_context->fw_venc_out_pin_handle));/* Get file handles */ /* TBD: Init the vcap dpam handle and pin if live video selected - ui needed */ p_channel_context->f_yuv_file = fopen(p_channel_context->yuv_filename, "rb"); if (p_channel_context->f_yuv_file == NULL) { printf("Cannot open %s \n",p_channel_context->yuv_filename); return ERROR; } if (p_channel_context->enable_avi) { if (open_avi_handle(p_channel_context) == ERROR) return ERROR; } /* Since new jpeg file is created for every frame, file is opened and close while handling output*/ return SUCCESS;}int connect_dpams(CHANNEL_CONTEXT_T *p_channel_context){ SPI_FW_PIN_CONN_SETTINGS_T fw_pin_conn_settings;/* Connect dpam pins */ memset(&fw_pin_conn_settings, 0, sizeof(fw_pin_conn_settings)); fw_pin_conn_settings.no_buffer_malloc = 0; // Explicit /* Connect NULL to JPEG encoder input pin */ /* TBD - connect vcap instead of NULL for live video */ fw_pin_conn_settings.queue_depth = SPVEJPEG_IN_BUFFER_DEPTH; ERR_HANDLE(spi_fw_pin_connect(NULL, p_channel_context->fw_venc_in_pin_handle, &fw_pin_conn_settings)); /* Connect JPEG encoder output pin to NULL*/ fw_pin_conn_settings.queue_depth = SPVEJPEG_OUT_BUFFER_DEPTH; ERR_HANDLE(spi_fw_pin_connect(p_channel_context->fw_venc_out_pin_handle, NULL, &fw_pin_conn_settings));/* Activate dpam */ ERR_HANDLE(spi_fw_activate(p_channel_context->fw_venc_dpam_handle)); return SUCCESS;}int handle_input(CHANNEL_CONTEXT_T *p_channel_context){ unsigned char *p_in_data; SPI_FW_BUFFER_T *p_fw_in_bufdesc; /* Pass the yuv buffer to spvejpeg dpam */ ERR_HANDLE(spi_fw_get_empty(p_channel_context->fw_venc_in_pin_handle, &p_fw_in_bufdesc, SPI_FW_ADDR_VIRT_UNCACHED, SPI_FW_BLOCKING)); p_in_data = (unsigned char *)p_fw_in_bufdesc + p_fw_in_bufdesc->data_offset; if (read_yuv(p_channel_context, p_in_data) == ERROR) return ERROR; ERR_HANDLE(spi_fw_put_full(p_channel_context->fw_venc_in_pin_handle, p_fw_in_bufdesc)); return SUCCESS;}int encode_frame(CHANNEL_CONTEXT_T *p_channel_context){ p_channel_context->frame_number++; return SUCCESS;}int handle_output(CHANNEL_CONTEXT_T *p_channel_context){ unsigned char *p_out_data; SPI_FW_BUFFER_T *p_fw_out_bufdesc;/* Receive the jpeg bitstream from spvejpeg dpam */ ERR_HANDLE(spi_fw_get_full(p_channel_context->fw_venc_out_pin_handle, &p_fw_out_bufdesc, SPI_FW_ADDR_VIRT_UNCACHED, SPI_FW_BLOCKING)); if (p_channel_context->enable_avi) { p_out_data = (unsigned char *)p_fw_out_bufdesc + p_fw_out_bufdesc->data_offset; if (write_avi(p_channel_context, p_out_data, p_fw_out_bufdesc->size) == ERROR) return ERROR; } if (p_channel_context->enable_jpeg) { p_out_data = (unsigned char *)p_fw_out_bufdesc + p_fw_out_bufdesc->data_offset; if (write_jpeg(p_channel_context, p_out_data, p_fw_out_bufdesc->size) == ERROR) return ERROR; } ERR_HANDLE(spi_fw_put_empty(p_channel_context->fw_venc_out_pin_handle, p_fw_out_bufdesc)); return SUCCESS;}int close_handles(CHANNEL_CONTEXT_T *p_channel_context){/* TBD - Close DPAMs and free pins*//* Close file handles */ fclose(p_channel_context->f_yuv_file); if (p_channel_context->enable_avi) { if (spi_jpeg_to_avi_close(p_channel_context->avi_handle) == ERROR) return ERROR; } return SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -