Ignore:
Timestamp:
09/05/11 09:34:01 (21 months ago)
Author:
philmoz
Message:

PTP 'Live View' extensions.
Based on mweerden's original work - https://github.com/mweerden/CHDKPTPRemote/tree/remote-preview
Tested on G12, SX30, SX130IS and IXUS310.
Sample .Net client code - http://chdk.setepontos.com/index.php?topic=4338.msg72684#msg72684
Pre-compiled sample client - http://chdk.setepontos.com/index.php?topic=4338.msg72684#msg72684
Sample client is in the early stages and still needs work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/luascript.c

    r1306 r1316  
    14391439  return switch_mode_usb(mode); 
    14401440} 
     1441  
     1442#ifdef CAM_CHDK_PTP 
     1443// PTP Live View functions 
     1444 
     1445// Function used to get viewport, bitmap and palette data via PTP 
     1446// Address of this function sent back to client program which then 
     1447// calls this with options to determine what to transfer 
     1448static int handle_video_transfer(ptp_data *data, int flags, int arg2) 
     1449{ 
     1450    int total_size;             // Calculated total size of data to transfer to client 
     1451 
     1452    // Structure containing the info for the current live view frame 
     1453    // This information may change across calls 
     1454    struct { 
     1455        int vp_xoffset;             // Viewport X offset in pixels (for cameras with variable image size) 
     1456        int vp_yoffset;             // Viewpoer Y offset in pixels (for cameras with variable image size) 
     1457        int vp_width;               // Actual viewport width in pixels (for cameras with variable image size) 
     1458        int vp_height;              // Actual viewport height in pixels (for cameras with variable image size) 
     1459        int vp_buffer_start;        // Offset in data transferred where the viewport data starts 
     1460        int vp_buffer_size;         // Size of viewport data sent (in bytes) 
     1461        int bm_buffer_start;        // Offset in data transferred where the bitmap data starts 
     1462        int bm_buffer_size;         // Size of bitmap data sent (in bytes) 
     1463        int palette_type;           // Camera palette type  
     1464                                    // (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) 
     1465        int palette_buffer_start;   // Offset in data transferred where the palette data starts 
     1466        int palette_buffer_size;    // Size of palette data sent (in bytes) 
     1467    } vid_info; 
     1468 
     1469    // Populate the above structure with the current default details 
     1470    vid_info.vp_xoffset = vid_get_viewport_xoffset_proper(); 
     1471    vid_info.vp_yoffset = vid_get_viewport_yoffset_proper(); 
     1472    vid_info.vp_width = vid_get_viewport_width_proper(); 
     1473    vid_info.vp_height = vid_get_viewport_height_proper(); 
     1474    vid_info.vp_buffer_start = 0; 
     1475    vid_info.vp_buffer_size = 0; 
     1476    vid_info.bm_buffer_start = 0; 
     1477    vid_info.bm_buffer_size = 0; 
     1478    vid_info.palette_type = vid_get_palette_type(); 
     1479    vid_info.palette_buffer_start = 0; 
     1480    vid_info.palette_buffer_size = 0; 
     1481 
     1482    total_size = sizeof(vid_info); 
     1483 
     1484    // Add viewport details if requested 
     1485    if ( flags & 0x1 ) // live buffer 
     1486    { 
     1487        vid_info.vp_buffer_start = total_size; 
     1488        vid_info.vp_buffer_size = (vid_get_viewport_buffer_width_proper()*vid_get_viewport_max_height()*6)/4; 
     1489        total_size += vid_info.vp_buffer_size; 
     1490    } 
     1491 
     1492    // Add bitmap details if requested 
     1493    if ( flags & 0x4 ) // bitmap buffer 
     1494    { 
     1495        vid_info.bm_buffer_start = total_size; 
     1496        vid_info.bm_buffer_size = vid_get_bitmap_buffer_width()*vid_get_bitmap_screen_height(); 
     1497        total_size += vid_info.bm_buffer_size; 
     1498    } 
     1499 
     1500    // Add palette detals if requested 
     1501    if ( flags & 0x8 ) // bitmap palette 
     1502    { 
     1503        vid_info.palette_buffer_start = total_size; 
     1504        vid_info.palette_buffer_size = vid_get_palette_size(); 
     1505        total_size += vid_info.palette_buffer_size; 
     1506    } 
     1507 
     1508    // Send header structure (along with total size to be sent) 
     1509    data->send_data(data->handle,(char*)&vid_info,sizeof(vid_info),total_size,0,0,0); 
     1510 
     1511    // Send viewport data if requested 
     1512    if ( flags & 0x1 ) 
     1513    { 
     1514        data->send_data(data->handle,vid_get_viewport_active_buffer(),vid_info.vp_buffer_size,0,0,0,0); 
     1515    } 
     1516 
     1517    // Send bitmap data if requested 
     1518    if ( flags & 0x4 ) 
     1519    { 
     1520        data->send_data(data->handle,vid_get_bitmap_active_buffer(),vid_info.bm_buffer_size,0,0,0,0); 
     1521    } 
     1522 
     1523    // Send palette data if requested 
     1524    if ( flags & 0x8 ) 
     1525    { 
     1526        data->send_data(data->handle,vid_get_bitmap_active_palette(),vid_info.palette_buffer_size,0,0,0,0); 
     1527    } 
     1528 
     1529    return 0; 
     1530} 
     1531 
     1532// Lua function to return base info for PTP live view, including address of above transfer function 
     1533static int luaCB_get_video_details( lua_State* L ) 
     1534{ 
     1535    // Structure to popualate with live view details 
     1536    // These details are static and only need to be retrieved once 
     1537    struct { 
     1538        int transfer_function;      // Address of transfer function above 
     1539        int vp_max_width;           // Maximum viewport width (in pixels) 
     1540        int vp_max_height;          // Maximum viewport height (in pixels) 
     1541        int vp_buffer_width;        // Viewport buffer width in case buffer is wider than visible viewport (in pixels) 
     1542        int bm_max_width;           // Maximum width of bitmap (in pixels) 
     1543        int bm_max_height;          // Maximum height of bitmap (in pixels) 
     1544        int bm_buffer_width;        // Bitmap buffer width in case buffer is wider than visible bitmap (in pixels) 
     1545        int lcd_aspect_ratio;       // 0 = 4:3, 1 = 16:9 
     1546    } details; 
     1547 
     1548    // Populate structure info 
     1549    details.transfer_function = (int) handle_video_transfer; 
     1550    details.vp_max_width = vid_get_viewport_max_width(); 
     1551    details.vp_max_height = vid_get_viewport_max_height(); 
     1552    details.vp_buffer_width = vid_get_viewport_buffer_width_proper(); 
     1553#if CAM_USES_ASPECT_CORRECTION 
     1554    details.bm_max_width = ASPECT_XCORRECTION(vid_get_bitmap_screen_width()); 
     1555#else 
     1556    details.bm_max_width = vid_get_bitmap_screen_width(); 
     1557#endif 
     1558    details.bm_max_height = vid_get_bitmap_screen_height(); 
     1559    details.bm_buffer_width = vid_get_bitmap_buffer_width(); 
     1560    details.lcd_aspect_ratio = vid_get_aspect_ratio(); 
     1561 
     1562    // Send data back to client 
     1563    lua_pushlstring( L, (char *) &details, sizeof(details) ); 
     1564 
     1565    return 1; 
     1566} 
     1567#endif 
    14411568 
    14421569/* 
     
    18711998   FUNC(set_record) 
    18721999   FUNC(switch_mode_usb) 
     2000#ifdef CAM_CHDK_PTP 
     2001   FUNC(get_video_details) 
     2002#endif 
    18732003 
    18742004#ifdef OPT_LUA_CALL_NATIVE 
Note: See TracChangeset for help on using the changeset viewer.