Changeset 1669
Author: reyalp
(2012/02/13 08:56) 3 months ago
merge live view code from philmoz branch (not svn merged due to unrelated changes), not tested
Author: reyalp
(2012/02/13 08:56) 3 months ago
merge live view code from philmoz branch (not svn merged due to unrelated changes), not tested
#ifdef CAM_CHDK_PTP// PTP Live View functions// Function used to get viewport, bitmap and palette data via PTP// Address of this function sent back to client program which then// calls this with options to determine what to transferstatic int handle_video_transfer(ptp_data *data, int flags, int arg2){int total_size; // Calculated total size of data to transfer to client// Structure containing the info for the current live view frame// This information may change across callsstruct {int vp_xoffset; // Viewport X offset in pixels (for cameras with variable image size)int vp_yoffset; // Viewpoer Y offset in pixels (for cameras with variable image size)int vp_width; // Actual viewport width in pixels (for cameras with variable image size)int vp_height; // Actual viewport height in pixels (for cameras with variable image size)int vp_buffer_start; // Offset in data transferred where the viewport data startsint vp_buffer_size; // Size of viewport data sent (in bytes)int bm_buffer_start; // Offset in data transferred where the bitmap data startsint bm_buffer_size; // Size of bitmap data sent (in bytes)int palette_type; // Camera palette type// (0 = no palette, 1 = 16 x 4 byte AYUV values, 2 = 16 x 4 byte AYUV values with A = 0..3, 3 = 256 x 4 byte AYUV values with A = 0..3)int palette_buffer_start; // Offset in data transferred where the palette data startsint palette_buffer_size; // Size of palette data sent (in bytes)} vid_info;// Populate the above structure with the current default detailsvid_info.vp_xoffset = vid_get_viewport_xoffset_proper();vid_info.vp_yoffset = vid_get_viewport_yoffset_proper();vid_info.vp_width = vid_get_viewport_width_proper();vid_info.vp_height = vid_get_viewport_height_proper();vid_info.vp_buffer_start = 0;vid_info.vp_buffer_size = 0;vid_info.bm_buffer_start = 0;vid_info.bm_buffer_size = 0;vid_info.palette_type = vid_get_palette_type();vid_info.palette_buffer_start = 0;vid_info.palette_buffer_size = 0;total_size = sizeof(vid_info);// Add viewport details if requestedif ( flags & 0x1 ) // live buffer{vid_info.vp_buffer_start = total_size;vid_info.vp_buffer_size = (vid_get_viewport_buffer_width_proper()*vid_get_viewport_max_height()*6)/4;total_size += vid_info.vp_buffer_size;}// Add bitmap details if requestedif ( flags & 0x4 ) // bitmap buffer{vid_info.bm_buffer_start = total_size;vid_info.bm_buffer_size = camera_screen.buffer_width*camera_screen.height;total_size += vid_info.bm_buffer_size;}// Add palette detals if requestedif ( flags & 0x8 ) // bitmap palette{vid_info.palette_buffer_start = total_size;vid_info.palette_buffer_size = vid_get_palette_size();total_size += vid_info.palette_buffer_size;}// Send header structure (along with total size to be sent)data->send_data(data->handle,(char*)&vid_info,sizeof(vid_info),total_size,0,0,0);// Send viewport data if requestedif ( flags & 0x1 ){data->send_data(data->handle,vid_get_viewport_active_buffer(),vid_info.vp_buffer_size,0,0,0,0);}// Send bitmap data if requestedif ( flags & 0x4 ){data->send_data(data->handle,vid_get_bitmap_active_buffer(),vid_info.bm_buffer_size,0,0,0,0);}// Send palette data if requestedif ( flags & 0x8 ){data->send_data(data->handle,vid_get_bitmap_active_palette(),vid_info.palette_buffer_size,0,0,0,0);}return 0;}// Lua function to return base info for PTP live view, including address of above transfer functionstatic int luaCB_get_video_details( lua_State* L ){// Structure to popualate with live view details// These details are static and only need to be retrieved oncestruct {int transfer_function; // Address of transfer function aboveint vp_max_width; // Maximum viewport width (in pixels)int vp_max_height; // Maximum viewport height (in pixels)int vp_buffer_width; // Viewport buffer width in case buffer is wider than visible viewport (in pixels)int bm_max_width; // Maximum width of bitmap (in pixels)int bm_max_height; // Maximum height of bitmap (in pixels)int bm_buffer_width; // Bitmap buffer width in case buffer is wider than visible bitmap (in pixels)int lcd_aspect_ratio; // 0 = 4:3, 1 = 16:9} details;// Populate structure infodetails.transfer_function = (int) handle_video_transfer;details.vp_max_width = vid_get_viewport_max_width();details.vp_max_height = vid_get_viewport_max_height();details.vp_buffer_width = vid_get_viewport_buffer_width_proper();#if CAM_USES_ASPECT_CORRECTIONdetails.bm_max_width = ASPECT_XCORRECTION(camera_screen.width);#elsedetails.bm_max_width = camera_screen.width;#endifdetails.bm_max_height = camera_screen.height;details.bm_buffer_width = camera_screen.buffer_width;details.lcd_aspect_ratio = vid_get_aspect_ratio();// Send data back to clientlua_pushlstring( L, (char *) &details, sizeof(details) );return 1;}#endif#ifdef CAM_CHDK_PTPFUNC(get_video_details)#endifOPT_OBJS+=ptp.o live_view.o#include "live_view.h"if ( (param2 & 0x1) == 0 ){{} else { // if ( (param2 & 0x1) != 0 )ptp.num_param = 1;ptp.param1 = ((int (*)(ptp_data*,int,int)) param3)(data,param4,param5);break;{#define PTP_CHDK_VERSION_MINOR 1 // increase with extensions of functionality#define PTP_CHDK_VERSION_MINOR 2 // increase with extensions of functionalityPTP_CHDK_CallFunction, // param2 are flags: 0x1 means use rest of params for pointer and args to allow function to send back dataPTP_CHDK_CallFunction, // data is array of function pointer and (long) arguments (max: 10 args)// (return) data is either:// - array of function pointer and (long) arguments if flag 0x1 is not set (max: 10 args)// - return data provided by called function if flag 0x1 is setenum ptp_chdk_handler_id {