📄 cam_msg_handler.c
字号:
#include "image_effect.h"
#include "img_comm.h"
#endif /* ISP_SUPPORT */
/* local includes */
#include "med_global.h"
#include "med_main.h"
#include "aud_defs.h"
#include "med_struct.h"
#include "med_api.h"
#include "med_context.h"
#include "med_smalloc.h"
#include "med_utility.h"
#include "cam_main.h"
#include "img_main.h"
#if defined(__MED_VID_MOD__) || defined(__MED_MJPG_MOD__)
#include "vid_main.h"
#endif
#ifdef MP4_CODEC
#include "med_c_main.h"
#include "med_c_struct.h"
#endif /* MP4_CODEC */
#ifdef __MED_TVO_MOD__
#include "tv_out.h"
#include "tvo_main.h"
#endif /* __MED_TVO_MOD__ */
#ifdef __CAM_TRACE_ON__
#include "med_trc.h"
#endif
#ifdef BARCODE_DECODER_SCANBUY
#include "SBDecode.h"
#if defined(MT6227) || defined(MT6226) || defined(MT6226M)
#include "dcmgr.h"
#endif
AppendEncodeInfo g_barcode_ae_info;
#endif
#ifdef __MED_CAM_MOD__
#if (defined(MT6228) || defined(MT6229))
extern void set_overlay_palette(kal_uint8 palette_size, kal_uint32 *palette_addr_ptr);
#endif
#define CAM_FREE_CAPTURE_BUFFER() if (cam_context_p->capture_buffer_p) \
med_free_ext_mem((void**)&cam_context_p->capture_buffer_p)
#define CAM_FREE_INT_BUFFER() if (cam_context_p->intmem_start_address) \
med_free_int_mem((void**)&cam_context_p->intmem_start_address)
#define CAM_FREE_EXT_BUFFER() if (cam_context_p->extmem_start_address) \
med_free_ext_mem((void**)&cam_context_p->extmem_start_address)
#ifdef BARCODE_SUPPORT
#define CAME_FREE_BARCODE_BUFFER() if(cam_context_p->barcode_buffer_address) \
med_free_ext_mem((void**)&cam_context_p->barcode_buffer_address)
#endif
#if defined(ISP_SUPPORT)
#if MT6219_SERIES
kal_int32 cam_capture_mem[2] = {MAX_CAM_CAP_INT_MEM_SIZE, MAX_CAM_CAP_EXT_MEM_SIZE};
kal_int32 cam_preview_mem[2] = {3840, 0};
#else /* MT6219_SERIES */
kal_int32 cam_capture_mem[2] = {MAX_CAM_CAP_INT_MEM_SIZE, MAX_CAM_CAP_EXT_MEM_SIZE};
kal_int32 cam_preview_mem[2] = {46080, 0};
#endif /* MT6219_SERIES */
/* rotate mapping for MT6219 */
kal_uint8 cam_rotate_map[CAM_NO_OF_IMAGE_ROTATE] =
{
IMAGE_NORMAL,
IMAGE_NORMAL,
IMAGE_HV_MIRROR,
IMAGE_NORMAL,
IMAGE_H_MIRROR,
IMAGE_NORMAL,
IMAGE_V_MIRROR,
IMAGE_NORMAL
};
/* wb mapping for MT6219 */
kal_uint8 cam_wb_map[CAM_NO_OF_WB] =
{
0,
DAYLIGHT,
TUNGSTEN,
FLUORESCENT,
CLOUD,
INCANDESCENCE
};
#endif /* defined(ISP_SUPPORT) */
#if defined (CAMERA_MODULE)
ext_camera_para_struct cam_param;
lcd_frame_update_struct lcd_param;
#elif defined (ISP_SUPPORT)
camera_capture_mem_struct capture_mem_param;
jpeg_encode_process_struct jpg_encode;
#ifdef BARCODE_DECODER_SCANBUY
camera_capture_barcode_struct capture_barcode_param;
#endif
#endif
/*==== FUNCTIONS ===========*/
/*****************************************************************************
* FUNCTION
* cam_open_image_file
* DESCRIPTION
* This function is to open image file for capture.
* PARAMETERS
* file_name [?]
* buffer_size [IN]
* RETURNS
* void
*****************************************************************************/
kal_int32 cam_open_image_file(kal_wchar *file_name, kal_uint32 buffer_size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 result;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* check if the format valid */
/* open the file */
cam_context_p->file_handle = FS_Open((kal_wchar*) file_name, FS_CREATE | FS_READ_WRITE);
if (cam_context_p->file_handle >= 0)
{
/* Check free memory space first */
if ((result = med_check_disc_space(file_name, CAPTURE_MEM_MARGIN)) != MED_RES_OK)
{
FS_Close(cam_context_p->file_handle);
FS_Delete((kal_wchar*) file_name);
return result;
}
/* to release the memory allocated in MED_MODE_BUFFER mode */
CAM_FREE_CAPTURE_BUFFER();
cam_context_p->capture_buffer_p = (kal_uint32) med_alloc_ext_mem(buffer_size);
if (cam_context_p->capture_buffer_p == NULL)
{
FS_Close(cam_context_p->file_handle);
FS_Delete((kal_wchar*) file_name);
return MED_RES_MEM_INSUFFICIENT;
}
else
{
cam_context_p->file_name_p = (kal_wchar*) file_name;
return MED_RES_OK;
}
}
else if (cam_context_p->file_handle == FS_WRITE_PROTECTION)
{
return MED_RES_WRITE_PROTECTION;
}
else if ((cam_context_p->file_handle == FS_ROOT_DIR_FULL) || (cam_context_p->file_handle == FS_DISK_FULL))
{
return MED_RES_DISC_FULL;
}
else
{
return MED_RES_OPEN_FILE_FAIL;
}
}
/*****************************************************************************
* FUNCTION
* cam_close_image_file
* DESCRIPTION
* This function is to close image file for capture.
* PARAMETERS
* size [IN]
* RETURNS
* void
*****************************************************************************/
kal_int32 cam_close_image_file(kal_uint32 size)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 result;
kal_uint32 len;
kal_int32 res = MED_RES_OK;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (size > 0)
{
result = FS_Write(cam_context_p->file_handle, (void*)cam_context_p->capture_buffer_p, size, &len);
FS_Close(cam_context_p->file_handle);
if (result != FS_NO_ERROR)
{
CAM_CLOSE_IMAGE_RESULT_TRACE(result);
FS_Delete((kal_wchar*) cam_context_p->file_name_p);
if (result == FS_DRIVE_NOT_FOUND)
{
res = MED_RES_NO_DISC;
}
else if (result == FS_DISK_FULL)
{
res = MED_RES_DISC_FULL;
}
else
{
res = MED_RES_OPEN_FILE_FAIL;
}
}
else if (size != len)
{
FS_Delete((kal_wchar*) cam_context_p->file_name_p);
res = MED_RES_DISC_FULL;
}
}
else
{
/* Close and delete the file */
FS_Close(cam_context_p->file_handle);
FS_Delete((kal_wchar*) cam_context_p->file_name_p);
res = MED_RES_DISC_FULL;
}
/* to release the memory allocated in MED_MODE_BUFFER mode */
CAM_FREE_CAPTURE_BUFFER();
return res;
}
/*****************************************************************************
* FUNCTION
* cam_set_flash
* DESCRIPTION
* This function is to set the flash.
* PARAMETERS
* flash_mode [IN]
* kal_int16 value(?)
* RETURNS
* void
*****************************************************************************/
kal_int16 cam_set_flash(kal_int16 flash_mode)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
#if defined (CAMERA_MODULE)
ext_camera_set_parameter(cam_command_map[CAM_PARAM_FLASH], flash_mode);
#endif
return MED_RES_OK;
}
/*****************************************************************************
* FUNCTION
* cam_set_flash_req_hdlr
* DESCRIPTION
* This function is to handle camera set flash request.
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void cam_set_flash_req_hdlr(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
media_cam_set_flash_req_struct *req_p;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
cam_context_p->src_mod = ilm_ptr->src_mod_id;
req_p = (media_cam_set_flash_req_struct*) ilm_ptr->local_para_ptr;
cam_set_flash(req_p->flash_mode);
}
#if defined (CAMERA_MODULE)
void cam_preview_check(void *arg);
/*****************************************************************************
* FUNCTION
* cam_power_up_check
* DESCRIPTION
* This function is to check the power up state.
* PARAMETERS
* arg [?]
* RETURNS
* void
*****************************************************************************/
void cam_power_up_check(void *arg)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (CAM_IN_STATE(CAM_POWER_UP))
{
if (ext_camera_reset_status())
{
CAM_ENTER_STATE(CAM_READY);
cam_send_ready_ind(MED_RES_OK);
CAM_SET_EVENT(CAM_EVT_POWER_UP);
}
else
{
ext_camera_power_off();
#ifdef CAMERA_MODULE_WITH_LCD
if (cam_context_p->osd_buffer_p)
{
med_free_ext_mem((void **)&cam_context_p->osd_buffer_p);
}
#endif /* CAMERA_MODULE_WITH_LCD */
cam_context_p->power_up_check_conut++;
if (cam_context_p->power_up_check_conut > MAX_POWER_UP_CHECK_COUNT)
{
/* to release the memory allocated in MED_MODE_BUFFER mode */
CAM_FREE_CAPTURE_BUFFER();
CAM_SET_EVENT(CAM_EVT_POWER_UP);
/* power up failed */
CAM_ENTER_STATE(CAM_IDLE);
cam_send_ready_ind(MED_RES_FAIL);
}
else
{
#ifdef CAMERA_MODULE_WITH_LCD
cam_context_p->osd_buffer_p = (kal_uint32) med_alloc_ext_mem(LCD_WIDTH * LCD_HEIGHT * 2);
if (cam_context_p->osd_buffer_p)
{
ext_camera_set_osd_buffer(cam_context_p->osd_buffer_p, LCD_WIDTH * LCD_HEIGHT * 2);
}
#endif /* CAMERA_MODULE_WITH_LCD */
ext_camera_power_on();
med_start_timer(CAM_POWER_UP_TIMER, CAM_POWER_UP_INIT_TIME, cam_power_up_check, 0);
}
}
}
else if (CAM_IN_STATE(CAM_START_PREVIEW))
{
if (ext_camera_reset_status())
{
cam_context_p->preview_check_conut = 0;
cam_context_p->preview_retry_conut++;
cam_set_night_mode((kal_int16) cam_context_p->night_mode);
ext_camera_preview(&cam_param, &lcd_param);
cam_set_zoom_factor(cam_context_p->zoom_factor);
cam_set_flash(cam_context_p->flash_mode);
med_start_timer(CAM_READY_POLLING_TIMER, CAM_PREVIEW_POLLING_TIME, cam_preview_check, 0);
}
else
{
ext_camera_power_off();
#ifdef CAMERA_MODULE_WITH_LCD
if (cam_context_p->osd_buffer_p)
{
med_free_ext_mem((void **)&cam_context_p->osd_buffer_p);
}
#endif /* CAMERA_MODULE_WITH_LCD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -