⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cam_msg_handler.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
        med_start_timer(CAM_READY_POLLING_TIMER, CAM_PREVIEW_POLLING_TIME, cam_preview_check, 0);
        CAM_SET_EVENT(CAM_EVT_PREVIEW);
    }
    else
    {
        cam_set_result(MED_RES_BUSY);
        CAM_SET_EVENT(CAM_EVT_PREVIEW);
    }
}


/*****************************************************************************
 * FUNCTION
 *  cam_stop_req_hdlr
 * DESCRIPTION
 *  This function is to handle camera stop request.
 * PARAMETERS
 *  ilm_ptr     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void cam_stop_req_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cam_context_p->src_mod = ilm_ptr->src_mod_id;

    if (CAM_IN_STATE(CAM_PREVIEW))
    {
    #ifdef __MTK_TARGET__
        med_stop_timer(CAM_READY_POLLING_TIMER);
        exit_ext_camera_preview();
    #endif /* __MTK_TARGET__ */ 
        CAM_ENTER_STATE(CAM_READY);
    }
    CAM_SET_EVENT(CAM_EVT_STOP);

}


/*****************************************************************************
 * FUNCTION
 *  cam_capture_check
 * DESCRIPTION
 *  This function is to check the capture state.
 * PARAMETERS
 *  arg     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void cam_capture_check(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 file_size;
    kal_int32 res;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!CAM_IN_STATE(CAM_CAPTURE))
    {
        return;
    }
    if ((file_size = ext_camera_ready_check()) != 0xffffffff && file_size >= MIN_JPG_FILE_SIZE)
    {
        if (cam_context_p->media_mode == MED_MODE_FILE)
        {
            res = cam_close_image_file(file_size);
            cam_set_result(res);
        }
        else if (cam_context_p->media_mode == MED_MODE_BUFFER)
        {
            *(cam_context_p->file_size_p) = file_size;
            *(cam_context_p->capture_buffer_pp) = (void*)cam_context_p->capture_buffer_p;
            cam_set_result(MED_RES_OK);
        }
        else
        {
            *(cam_context_p->file_size_p) = file_size;
            cam_set_result(MED_RES_OK);
        }
        CAM_ENTER_STATE(CAM_READY);
        CAM_SET_EVENT(CAM_EVT_CAPTURE);
    }
    else if (file_size < MIN_JPG_FILE_SIZE || cam_context_p->capture_check_conut > MAX_CAPTURE_CHECK_COUNT)
    {
        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 */ 
        /* to release the memory allocated in MED_MODE_BUFFER mode */
        CAM_FREE_CAPTURE_BUFFER();
        if (cam_context_p->media_mode == MED_MODE_FILE)
        {
            cam_close_image_file(0);
        }
        cam_set_result(MED_RES_FAIL);
        CAM_ENTER_STATE(CAM_IDLE);
        CAM_SET_EVENT(CAM_EVT_CAPTURE);
    }
    else
    {
        cam_context_p->capture_check_conut++;
        med_start_timer(CAM_READY_POLLING_TIMER, CAM_CAPTURE_POLLING_TIME, cam_capture_check, 0);
    }
}


/*****************************************************************************
 * FUNCTION
 *  cam_capture_req_hdlr
 * DESCRIPTION
 *  This function is to handle camera capture request.
 * PARAMETERS
 *  ilm_ptr     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void cam_capture_req_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    media_cam_capture_req_struct *req_p;
    ext_camera_para_struct cam_param;
    kal_int32 result = MED_RES_OK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cam_context_p->src_mod = ilm_ptr->src_mod_id;

    req_p = (media_cam_capture_req_struct*) ilm_ptr->local_para_ptr;

    if (CAM_IN_STATE(CAM_PREVIEW))
    {
        cam_context_p->media_mode = req_p->media_mode;
        if (req_p->media_mode == MED_MODE_FILE)
        {
            kal_uint32 file_buffer_size;

            if (req_p->source_device == CAM_SRC_ISP)
            {
                file_buffer_size = MAX_CAM_FILE_BUFFER_LEN;
            }
            else
            {
                file_buffer_size = 60 * 1024;   /* MAX_IMG_ENC_FILE_BUFFER_LEN; */
            }

            cam_param.image_width = img_context_p->image_width = req_p->image_width;
            cam_param.image_height = img_context_p->image_height = req_p->image_height;
            cam_param.jpeg_compression_ratio = cam_context_p->image_quality =
                (kal_uint8) cam_jpg_qty_param_map[req_p->image_quality];
            cam_param.image_buffer_size = file_buffer_size;
            cam_param.snapshot_number = req_p->snapshot_number;
            cam_param.continue_capture = req_p->continue_capture;
            if (cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
            {
                ASSERT(cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
                    cam_param.burst_capture_ptr = (ext_camera_burst_struct*) req_p->jpegs_p;
            }

            /* stop preview timer */
            med_stop_timer(CAM_READY_POLLING_TIMER);
            if ((result = cam_open_image_file((kal_wchar*) req_p->data, file_buffer_size)) == MED_RES_OK)
            {
                if (req_p->source_device == CAM_SRC_ISP)
                {
                    cam_param.jpeg_buffer_ptr = (kal_uint8*) cam_context_p->capture_buffer_p;
                    cam_context_p->capture_check_conut = 0;
                    cam_context_p->capture_retry_conut = 0;
                #ifdef __MTK_TARGET__
                    ext_camera_capture(&cam_param);
                    med_start_timer(CAM_READY_POLLING_TIMER, CAM_CAPTURE_POLLING_TIME, cam_capture_check, 0);
                #endif /* __MTK_TARGET__ */ 
                    CAM_ENTER_STATE(CAM_CAPTURE);
                }
                else
                {
                    lcd_frame_update_to_mem_struct lcd_param;
                    kal_int32 file_size;

                    cam_param.jpeg_buffer_ptr = (kal_uint8*) cam_context_p->capture_buffer_p;

                    lcd_param.fb_update_mode = LCD_SW_TRIGGER_MODE;
                    lcd_param.block_mode = LCD_WM_CONT_MODE;
                    /* for lcd if */
                    lcd_param.dest_buffer_size = req_p->image_width * req_p->image_height * 2;
                    lcd_param.dest_buffer_address = cam_context_p->extmem_start_address =
                        (kal_uint32) med_alloc_ext_mem(lcd_param.dest_buffer_size);
                    lcd_param.roi_offset_x = req_p->roi_offset_x;
                    lcd_param.roi_offset_y = req_p->roi_offset_y;
                    lcd_param.roi_width = req_p->image_width;
                    lcd_param.roi_height = req_p->image_height;
                    lcd_param.update_layer = req_p->capture_layer;
                    lcd_param.hw_update_layer = cam_context_p->hw_update_layer;
                    if ((file_size = ext_camera_sticker_capture(&cam_param, &lcd_param)) != NULL_JPEG_FILE)
                    {
                        result = cam_close_image_file(file_size);
                    }
                    else
                    {
                        cam_close_image_file(0);
                        result = MED_RES_ERROR;
                    }
                    med_free_ext_mem((void **)(&cam_context_p->extmem_start_address));
                    cam_set_result(result);
                    CAM_ENTER_STATE(CAM_READY);
                    CAM_SET_EVENT(CAM_EVT_CAPTURE);
                }
            }
            else
            {
                cam_set_result(result);
            #ifdef __MTK_TARGET__
                exit_ext_camera_preview();
            #endif 
                CAM_ENTER_STATE(CAM_READY);
                CAM_SET_EVENT(CAM_EVT_CAPTURE);
            }

        }
        else if (req_p->media_mode == MED_MODE_ARRAY)
        {
            cam_param.image_width = img_context_p->image_width = req_p->image_width;
            cam_param.image_height = img_context_p->image_height = req_p->image_height;
            cam_param.jpeg_compression_ratio = cam_context_p->image_quality =
                (kal_uint8) cam_jpg_qty_param_map[req_p->image_quality];

            cam_param.snapshot_number = req_p->snapshot_number;
            if (cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
            {
                ASSERT(cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
                    cam_param.burst_capture_ptr = (ext_camera_burst_struct*) req_p->jpegs_p;
            }
            /* stop preview timer */
            med_stop_timer(CAM_READY_POLLING_TIMER);

            if (req_p->data != NULL && req_p->file_buffer_len > 0)
            {
                if (req_p->source_device == CAM_SRC_ISP)
                {
                    cam_param.jpeg_buffer_ptr = (kal_uint8*) req_p->data;
                    cam_param.image_buffer_size = req_p->file_buffer_len;
                    cam_context_p->file_size_p = req_p->file_size_p;
                    cam_context_p->capture_check_conut = 0;
                    cam_context_p->capture_retry_conut = 0;
                #ifdef __MTK_TARGET__
                    ext_camera_capture(&cam_param);
                    med_start_timer(CAM_READY_POLLING_TIMER, CAM_CAPTURE_POLLING_TIME, cam_capture_check, 0);
                #endif /* __MTK_TARGET__ */ 
                    CAM_ENTER_STATE(CAM_CAPTURE);
                }
                else
                {
                    lcd_frame_update_to_mem_struct lcd_param;
                    kal_int32 file_size;

                    cam_param.jpeg_buffer_ptr = (kal_uint8*) req_p->data;
                    cam_param.image_buffer_size = req_p->file_buffer_len;
                    cam_context_p->file_size_p = req_p->file_size_p;

                    lcd_param.fb_update_mode = LCD_SW_TRIGGER_MODE;
                    lcd_param.block_mode = LCD_WM_CONT_MODE;
                    /* for lcd if */
                    lcd_param.dest_buffer_size = req_p->image_width * req_p->image_height * 2;
                    lcd_param.dest_buffer_address = cam_context_p->extmem_start_address =
                        (kal_uint32) med_alloc_ext_mem(lcd_param.dest_buffer_size);
                    lcd_param.roi_offset_x = req_p->roi_offset_x;
                    lcd_param.roi_offset_y = req_p->roi_offset_y;
                    lcd_param.roi_width = req_p->image_width;
                    lcd_param.roi_height = req_p->image_height;
                    lcd_param.update_layer = req_p->capture_layer;
                    lcd_param.hw_update_layer = cam_context_p->hw_update_layer;
                    if ((file_size = ext_camera_sticker_capture(&cam_param, &lcd_param)) != NULL_JPEG_FILE)
                    {
                        *(cam_context_p->file_size_p) = file_size;
                        result = MED_RES_OK;
                    }
                    else
                    {
                        result = MED_RES_ERROR;
                    }
                    med_free_ext_mem((void **)(&cam_context_p->extmem_start_address));
                    cam_set_result(result);
                    CAM_ENTER_STATE(CAM_READY);
                    CAM_SET_EVENT(CAM_EVT_CAPTURE);
                }
            }
            else
            {
                cam_set_result(result);
            #ifdef __MTK_TARGET__
                exit_ext_camera_preview();
            #endif 
                CAM_ENTER_STATE(CAM_READY);
                CAM_SET_EVENT(CAM_EVT_CAPTURE);
            }

        }
        else if (req_p->media_mode == MED_MODE_BUFFER)
        {
            kal_uint32 file_buffer_size;

            /* stop prevew before capture */
            cam_param.image_width = img_context_p->image_width = req_p->image_width;
            cam_param.image_height = img_context_p->image_height = req_p->image_height;
            cam_param.jpeg_compression_ratio = cam_context_p->image_quality =
                (kal_uint8) cam_jpg_qty_param_map[req_p->image_quality];

            cam_param.snapshot_number = req_p->snapshot_number;
            if (cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
            {
                ASSERT(cam_param.snapshot_number > 1 && req_p->jpegs_p != NULL)
                    cam_param.burst_capture_ptr = (ext_camera_burst_struct*) req_p->jpegs_p;
            }
            /* stop preview timer */
            med_stop_timer(CAM_READY_POLLING_TIMER);

            if (req_p->source_device == CAM_SRC_ISP)
            {
                file_buffer_size = MAX_CAM_FILE_BUFFER_LEN;
            }
            else
            {
                file_buffer_size = 60 * 1024;
            }

            CAM_FREE_CAPTURE_BUFFER();
            cam_context_p->capture_buffer_p = (kal_uint32) med_alloc_ext_mem(file_buffer_size);

            cam_context_p->capture_buffer_pp = req_p->capture_buffer_p;

            if (cam_context_p->capture_buffer_p != NULL)
            {
                if (req_p->source_device == CAM_SRC_ISP)
                {
                    cam_param.jpeg_buffer_ptr = (kal_uint8*) cam_context_p->capture_buffer_p;
                    cam_param.image_buffer_size = file_buffer_size;
                    cam_context_p->file_size_p = req_p->file_size_p;
                    cam_context_p->capture_check_conut = 0;
                    cam_context_p->capture_retry_conut = 0;
                #ifdef __MTK_TARGET__
                    ext_camera_capture(&cam_param);
                    med_start_timer(CAM_READY_POLLING_TIMER, CAM_CAPTURE_POLLING_TIME, cam_capture_check, 0);
                #endif /* __MTK_TARGET__ */ 
                    CAM_ENTER_STATE(CAM_CAPTURE);
                }
                else
                {
                    lcd_frame_update_to_mem_struct lcd_param;
                    kal_int32 file_size;

                    cam_param.jpeg_buffer_ptr = (kal_uint8*) cam_context_p->capture_buffer_p;
                    cam_param.image_buffer_size = file_buffer_size;
                    cam_context_p->file_size_p = req_p->file_size_p;

                    lcd_param.fb_update_mode = LCD_SW_TRIGGER_MODE;
                    lcd_param.block_mode = LCD_WM_CONT_MODE;
                    /* for lcd if */
                    lcd_param.dest_buffer_size = req_p->image_width * req_p->image_height * 2;
                    lcd_param.dest_buffer_address = cam_context_p->extmem_start_address =
                        (kal_uint32) med_alloc_ext_mem(lcd_param.dest_buffer_size);
                    lcd_param.roi_offset_x = req_p->roi_offset_x;
                    lcd_param.roi_offset_y = req_p->roi_offset_y;
                    lcd_param.roi_width = req_p->image_width;
                    lcd_param.roi_height = req_p->image_height;
                    lcd_param.update_layer = req_p->capture_layer;
                    lcd_param.hw_update_layer = cam_context_p->hw_update_layer;
                    if ((file_size = ext_camera_sticker_capture(&cam_param, &lcd_param)) != NULL_JPEG_FILE)
                    {
                        *(cam_context_p->file_size_p) = file_size;
                        *(cam_context_p->capture_buffer_pp) = (void*)cam_context_p->capture_buffer_p;
                        result = MED_RES_OK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -