Changeset 1669

Show
Ignore:
Timestamp:
02/13/12 03:56:24 (3 months ago)
Author:
reyalp
Message:

merge live view code from philmoz branch (not svn merged due to unrelated changes), not tested

Location:
branches/reyalp-ptp-live/core
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/reyalp-ptp-live/core/Makefile

    r1632 r1669  
    5454# in top level 
    5555#CFLAGS+=-DOPT_PTP 
    56 OPT_OBJS+=ptp.o  
     56OPT_OBJS+=ptp.o live_view.o 
    5757endif  
    5858ifdef OPT_EXMEM_MALLOC 
  • branches/reyalp-ptp-live/core/luascript.c

    r1663 r1669  
    16891689} 
    16901690  
    1691 #ifdef CAM_CHDK_PTP 
    1692 // PTP Live View functions 
    1693  
    1694 // Function used to get viewport, bitmap and palette data via PTP 
    1695 // Address of this function sent back to client program which then 
    1696 // calls this with options to determine what to transfer 
    1697 static int handle_video_transfer(ptp_data *data, int flags, int arg2) 
    1698 { 
    1699     int total_size;             // Calculated total size of data to transfer to client 
    1700  
    1701     // Structure containing the info for the current live view frame 
    1702     // This information may change across calls 
    1703     struct { 
    1704         int vp_xoffset;             // Viewport X offset in pixels (for cameras with variable image size) 
    1705         int vp_yoffset;             // Viewpoer Y offset in pixels (for cameras with variable image size) 
    1706         int vp_width;               // Actual viewport width in pixels (for cameras with variable image size) 
    1707         int vp_height;              // Actual viewport height in pixels (for cameras with variable image size) 
    1708         int vp_buffer_start;        // Offset in data transferred where the viewport data starts 
    1709         int vp_buffer_size;         // Size of viewport data sent (in bytes) 
    1710         int bm_buffer_start;        // Offset in data transferred where the bitmap data starts 
    1711         int bm_buffer_size;         // Size of bitmap data sent (in bytes) 
    1712         int palette_type;           // Camera palette type  
    1713                                     // (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) 
    1714         int palette_buffer_start;   // Offset in data transferred where the palette data starts 
    1715         int palette_buffer_size;    // Size of palette data sent (in bytes) 
    1716     } vid_info; 
    1717  
    1718     // Populate the above structure with the current default details 
    1719     vid_info.vp_xoffset = vid_get_viewport_xoffset_proper(); 
    1720     vid_info.vp_yoffset = vid_get_viewport_yoffset_proper(); 
    1721     vid_info.vp_width = vid_get_viewport_width_proper(); 
    1722     vid_info.vp_height = vid_get_viewport_height_proper(); 
    1723     vid_info.vp_buffer_start = 0; 
    1724     vid_info.vp_buffer_size = 0; 
    1725     vid_info.bm_buffer_start = 0; 
    1726     vid_info.bm_buffer_size = 0; 
    1727     vid_info.palette_type = vid_get_palette_type(); 
    1728     vid_info.palette_buffer_start = 0; 
    1729     vid_info.palette_buffer_size = 0; 
    1730  
    1731     total_size = sizeof(vid_info); 
    1732  
    1733     // Add viewport details if requested 
    1734     if ( flags & 0x1 ) // live buffer 
    1735     { 
    1736         vid_info.vp_buffer_start = total_size; 
    1737         vid_info.vp_buffer_size = (vid_get_viewport_buffer_width_proper()*vid_get_viewport_max_height()*6)/4; 
    1738         total_size += vid_info.vp_buffer_size; 
    1739     } 
    1740  
    1741     // Add bitmap details if requested 
    1742     if ( flags & 0x4 ) // bitmap buffer 
    1743     { 
    1744         vid_info.bm_buffer_start = total_size; 
    1745         vid_info.bm_buffer_size = camera_screen.buffer_width*camera_screen.height; 
    1746         total_size += vid_info.bm_buffer_size; 
    1747     } 
    1748  
    1749     // Add palette detals if requested 
    1750     if ( flags & 0x8 ) // bitmap palette 
    1751     { 
    1752         vid_info.palette_buffer_start = total_size; 
    1753         vid_info.palette_buffer_size = vid_get_palette_size(); 
    1754         total_size += vid_info.palette_buffer_size; 
    1755     } 
    1756  
    1757     // Send header structure (along with total size to be sent) 
    1758     data->send_data(data->handle,(char*)&vid_info,sizeof(vid_info),total_size,0,0,0); 
    1759  
    1760     // Send viewport data if requested 
    1761     if ( flags & 0x1 ) 
    1762     { 
    1763         data->send_data(data->handle,vid_get_viewport_active_buffer(),vid_info.vp_buffer_size,0,0,0,0); 
    1764     } 
    1765  
    1766     // Send bitmap data if requested 
    1767     if ( flags & 0x4 ) 
    1768     { 
    1769         data->send_data(data->handle,vid_get_bitmap_active_buffer(),vid_info.bm_buffer_size,0,0,0,0); 
    1770     } 
    1771  
    1772     // Send palette data if requested 
    1773     if ( flags & 0x8 ) 
    1774     { 
    1775         data->send_data(data->handle,vid_get_bitmap_active_palette(),vid_info.palette_buffer_size,0,0,0,0); 
    1776     } 
    1777  
    1778     return 0; 
    1779 } 
    1780  
    1781 // Lua function to return base info for PTP live view, including address of above transfer function 
    1782 static int luaCB_get_video_details( lua_State* L ) 
    1783 { 
    1784     // Structure to popualate with live view details 
    1785     // These details are static and only need to be retrieved once 
    1786     struct { 
    1787         int transfer_function;      // Address of transfer function above 
    1788         int vp_max_width;           // Maximum viewport width (in pixels) 
    1789         int vp_max_height;          // Maximum viewport height (in pixels) 
    1790         int vp_buffer_width;        // Viewport buffer width in case buffer is wider than visible viewport (in pixels) 
    1791         int bm_max_width;           // Maximum width of bitmap (in pixels) 
    1792         int bm_max_height;          // Maximum height of bitmap (in pixels) 
    1793         int bm_buffer_width;        // Bitmap buffer width in case buffer is wider than visible bitmap (in pixels) 
    1794         int lcd_aspect_ratio;       // 0 = 4:3, 1 = 16:9 
    1795     } details; 
    1796  
    1797     // Populate structure info 
    1798     details.transfer_function = (int) handle_video_transfer; 
    1799     details.vp_max_width = vid_get_viewport_max_width(); 
    1800     details.vp_max_height = vid_get_viewport_max_height(); 
    1801     details.vp_buffer_width = vid_get_viewport_buffer_width_proper(); 
    1802 #if CAM_USES_ASPECT_CORRECTION 
    1803     details.bm_max_width = ASPECT_XCORRECTION(camera_screen.width); 
    1804 #else 
    1805     details.bm_max_width = camera_screen.width; 
    1806 #endif 
    1807     details.bm_max_height = camera_screen.height; 
    1808     details.bm_buffer_width = camera_screen.buffer_width; 
    1809     details.lcd_aspect_ratio = vid_get_aspect_ratio(); 
    1810  
    1811     // Send data back to client 
    1812     lua_pushlstring( L, (char *) &details, sizeof(details) ); 
    1813  
    1814     return 1; 
    1815 } 
    1816 #endif 
    1817  
    18181691/* 
    18191692pack the lua args into a buffer to pass to the native code calling functions  
     
    23462219   FUNC(set_record) 
    23472220   FUNC(switch_mode_usb) 
    2348 #ifdef CAM_CHDK_PTP 
    2349    FUNC(get_video_details) 
    2350 #endif 
    23512221 
    23522222#ifdef OPT_LUA_CALL_NATIVE 
  • branches/reyalp-ptp-live/core/ptp.c

    r1527 r1669  
    88 
    99#include "core.h" 
    10    
     10#include "live_view.h" 
     11 
    1112static int buf_size=0; 
    1213 
     
    300301 
    301302    case PTP_CHDK_CallFunction: 
    302       if ( (param2 & 0x1) == 0 ) 
    303303      { 
    304304        int s; 
     
    322322 
    323323        free(buf); 
    324         break; 
    325       } else { // if ( (param2 & 0x1) != 0 ) 
    326         ptp.num_param = 1; 
    327         ptp.param1 = ((int (*)(ptp_data*,int,int)) param3)(data,param4,param5); 
    328324        break; 
    329325      } 
     
    625621#endif 
    626622 
     623    case PTP_CHDK_GetHandler: 
     624// Define which handler function to return the address of 
     625        ptp.num_param = 1; 
     626        ptp.param1 = 0; 
     627        switch (param2) 
     628        { 
     629        case PTP_CHDK_LIVE_VIEW_HANDLER_ID: 
     630            ptp.param1 = (int) live_view_data_handler; 
     631            break; 
     632        } 
     633        break; 
     634 
     635    case PTP_CHDK_CallHandler: 
     636        ptp.num_param = 1; 
     637        ptp.param1 = ((int (*)(ptp_data*,int,int)) param2)(data,param3,param4); 
     638        break; 
     639 
    627640    default: 
    628641      ptp.code = PTP_RC_ParameterNotSupported; 
  • branches/reyalp-ptp-live/core/ptp.h

    r1527 r1669  
    22#define __CHDK_PTP_H 
    33#define PTP_CHDK_VERSION_MAJOR 2  // increase only with backwards incompatible changes (and reset minor) 
    4 #define PTP_CHDK_VERSION_MINOR 1  // increase with extensions of functionality 
     4#define PTP_CHDK_VERSION_MINOR 2  // increase with extensions of functionality 
    55/* 
    66protocol version history 
     
    991.0 - removed old script result code (luar), replace with message system 
    10102.0 - return PTP_CHDK_TYPE_TABLE for tables instead of TYPE_STRING, allow return of empty strings 
     112.1 - eperimental live view, not formally released 
     122.2 - live view (work in progress) 
    1113*/ 
    1214 
     
    3133                            // param3 is size (in bytes) 
    3234                            // data is new memory block 
    33   PTP_CHDK_CallFunction,    // param2 are flags: 0x1 means use rest of params for pointer and args to allow function to send back data 
    34                             // (return) data is either: 
    35                             //   - array of function pointer and (long) arguments if flag 0x1 is not set  (max: 10 args) 
    36                             //   - return data provided by called function if flag 0x1 is set 
     35  PTP_CHDK_CallFunction,    // data is array of function pointer and (long) arguments  (max: 10 args) 
    3736                            // return param1 is return value 
    3837  PTP_CHDK_TempData,        // data is data to be stored for later 
     
    6766                            // input messages do not have type or subtype, they are always a string destined for the script (similar to USER/string) 
    6867                            // output param1 is ptp_chdk_script_msg_status 
     68  PTP_CHDK_GetHandler,      // Get the function address of a custom handler. 
     69                            //   param2 = ID of custom handler to return 
     70                            //   output param1 = custom handler address (0 if not implemented 
     71  PTP_CHDK_CallHandler,     // Call a custom handler function 
     72                            //   param2 = handler address to call 
     73                            //   param3 & param4 = parameters to pass to handler function 
     74                            //   output param1 = return value from handler function 
    6975}; 
    7076 
     
    121127    PTP_CHDK_S_MSGSTATUS_BADID,  // specified ID is not running 
    122128}; 
     129 
     130// function handler id 
     131enum ptp_chdk_handler_id { 
     132    PTP_CHDK_LIVE_VIEW_HANDLER_ID = 1,  // Live View handler 
     133}; 
    123134#endif // __CHDK_PTP_H