📄 spvejpeg_dpam.c
字号:
////////////////////////////////////////////////////////////////////////////////// spvejpeg_dpam.c//// 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 "spi_common.h"#include "spi_fw_server.h"#include "spvejpeg_fw_context.h"#include "dsp_mips_dpam_attribs.h"#include "spvejpeg_dpam.h"void set_context(SPVEJPEG_FW_CONTEXT_T *p_spvejpeg_fw_context, SPVEJPEG_FW_SETTINGS_T *p_fw_settings, int channel_no){ p_spvejpeg_fw_context->channel_id = channel_no; ERR_HANDLE (p_spvejpeg_fw_context->channel_id != p_fw_settings->channel_id); p_spvejpeg_fw_context->configuration.channel_status = p_fw_settings->status; p_spvejpeg_fw_context->configuration.quality = p_fw_settings->quality; p_spvejpeg_fw_context->image_spec.x_offset = 0; p_spvejpeg_fw_context->image_spec.y_offset = 0; p_spvejpeg_fw_context->image_spec.width = p_fw_settings->width; p_spvejpeg_fw_context->image_spec.height = p_fw_settings->height; switch (p_fw_settings->format) { case SPI_VISUAL_FMT_YUV420: p_spvejpeg_fw_context->image_spec.format = SPVEJPEG_YUV420_PLANAR; break; default: spi_printf("Err: Image format not supported.\n"); ERR_HANDLE(1); break; } p_spvejpeg_fw_context->image_spec.buffer.frame_width = p_fw_settings->width; p_spvejpeg_fw_context->image_spec.buffer.frame_height = p_fw_settings->height; p_spvejpeg_fw_context->frame_number = 0; p_spvejpeg_fw_context->bitbuffer.total_num_bytes = SPVEJPEG_OUT_BUFFER_CAPACITY;}int spvejpeg_task(void){ int channel_no = 0; SPVEJPEG_FW_CONTEXT_T *spvejpeg_fw_context; SPVEJPEG_FW_SETTINGS_T fw_settings; int fw_settings_size; SPI_FW_BUFFER_T *p_fw_in_bufdesc; SPI_FW_BUFFER_T *p_fw_out_bufdesc; unsigned char *p_in_data; unsigned char *p_out_data; int y_size; SPVEJPEG_IMAGE_SPECS *p_image_spec; SPVEJPEG_BITSTREAM_BUFFER *p_bitbuffer;#if (defined(PROFILE_SPVEJPEG) && (defined(SPI_TARGET_DEVICE))) SPI_PERF_T spvejpeg_timer ; spi_perf_init (&spvejpeg_timer , "spvejpeg_timer") ;#endif/* Allocate the spvejpeg dpam context */ spvejpeg_fw_context = spi_malloc(sizeof(SPVEJPEG_FW_CONTEXT_T)); if (spvejpeg_fw_context == NULL) { RAISE_ERR(("Err: Failed to allocate SPVEJPEG_FW_CONTEXT_T. \n")); }/* Init spvejpeg_dpam server */ spi_printf("spvejpeg_fw_server_create()... \n"); ERR_HANDLE(spi_fw_server_init(&spvejpeg_fw_context->fw_dpam_handle, &spvejpeg_fw_attributes));/* Initialise the server configuration */ spi_printf("spvejpeg_fw_server_get_settings()... \n"); ERR_HANDLE(spi_fw_server_get_settings(spvejpeg_fw_context->fw_dpam_handle, (void *)&fw_settings, &fw_settings_size)); ERR_HANDLE(fw_settings_size != sizeof(SPVEJPEG_FW_SETTINGS_T)); set_context(spvejpeg_fw_context, &fw_settings, channel_no); spi_printf("width = %d\n", spvejpeg_fw_context->image_spec.width); spi_printf("height = %d\n", spvejpeg_fw_context->image_spec.height); spi_printf("quality = %d\n", spvejpeg_fw_context->configuration.quality);/* Get the server pins */ spi_printf("spvejpeg_fw_server_get_pins()... \n"); ERR_HANDLE(spi_fw_server_get_pin(spvejpeg_fw_context->fw_dpam_handle, SPVEJPEG_IN_PIN_NAME, &spvejpeg_fw_context->fw_in_pin_handle)); ERR_HANDLE(spi_fw_server_get_pin(spvejpeg_fw_context->fw_dpam_handle, SPVEJPEG_OUT_PIN_NAME, &spvejpeg_fw_context->fw_out_pin_handle)); if ( (spvejpeg_open (&spvejpeg_fw_context->spvejpeg_handle)) != SPVEJPEG_ERR_SUCCESS) { spi_printf("\n Error: spvejpeg_open failed. \n"); ERR_HANDLE(ERROR); } if ( (spvejpeg_set_quality (spvejpeg_fw_context->spvejpeg_handle, spvejpeg_fw_context->configuration.quality)) != SPVEJPEG_ERR_SUCCESS) { spi_printf("\n Error: spvejpeg_set_quality failed. \n"); ERR_HANDLE(ERROR); } p_image_spec = &spvejpeg_fw_context->image_spec; p_bitbuffer = &spvejpeg_fw_context->bitbuffer; y_size = (p_image_spec->width * p_image_spec->height); while(1) {/* Get a full input buffer and an empty output buffer */ ERR_HANDLE(spi_fw_server_get_full(spvejpeg_fw_context->fw_in_pin_handle, &p_fw_in_bufdesc, SPI_FW_ADDR_VIRT_UNCACHED, SPI_FW_BLOCKING)); ERR_HANDLE(spi_fw_server_get_empty(spvejpeg_fw_context->fw_out_pin_handle, &p_fw_out_bufdesc, SPI_FW_ADDR_VIRT_UNCACHED, SPI_FW_BLOCKING)); p_in_data = (unsigned char *)p_fw_in_bufdesc + p_fw_in_bufdesc->data_offset; p_out_data = (unsigned char *)p_fw_out_bufdesc + p_fw_out_bufdesc->data_offset;/* Process the input data and fill the output buffer */#if (defined(PROFILE_SPVEJPEG) && (defined(SPI_TARGET_DEVICE))) spi_perf_start (&spvejpeg_timer) ;#endif /* Prepare encoder */ p_image_spec->buffer.p_y_buffer = p_in_data; p_image_spec->buffer.p_u_buffer = p_in_data + y_size; p_image_spec->buffer.p_v_buffer = p_in_data + y_size + (y_size>>2); if ( (spvejpeg_prep_encode_frame (spvejpeg_fw_context->spvejpeg_handle, p_image_spec)) != SPVEJPEG_ERR_SUCCESS) { spi_printf("\n Error: spvejpeg_prep_encode_frame failed. \n"); ERR_HANDLE(ERROR); } /* Encode the frame */ p_bitbuffer->p_buffer = p_out_data; if ( (spvejpeg_encode_frame (spvejpeg_fw_context->spvejpeg_handle, p_bitbuffer)) != SPVEJPEG_ERR_SUCCESS) { spi_printf("\n Error: spvejpeg_encode_frame failed. \n"); ERR_HANDLE(ERROR); }#if (defined(PROFILE_SPVEJPEG) && (defined(SPI_TARGET_DEVICE))) spi_perf_stop (&spvejpeg_timer) ; spi_perf_print(&spvejpeg_timer, 1);#endif/* Put the processed output buffer (full) and used input buffer (empty) */ p_fw_out_bufdesc->size = p_bitbuffer->used_num_bytes; ERR_HANDLE(spi_fw_server_put_full(spvejpeg_fw_context->fw_out_pin_handle, p_fw_out_bufdesc)); ERR_HANDLE(spi_fw_server_put_empty(spvejpeg_fw_context->fw_in_pin_handle, p_fw_in_bufdesc)); } spi_printf("Closing JPEG encoder\n"); if ( (spvejpeg_close (spvejpeg_fw_context->spvejpeg_handle)) != SPVEJPEG_ERR_SUCCESS) { spi_printf("\n Error: spvejpeg_close failed. \n"); ERR_HANDLE(ERROR); } if (spvejpeg_fw_context) spi_free(spvejpeg_fw_context);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -