Changeset 1669

User picture

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

Affected files

Added branches/reyalp-ptp-live/core/live_view.c

Show contents

Added branches/reyalp-ptp-live/core/live_view.h

Show contents

Updated branches/reyalp-ptp-live/core/luascript.c Download diff

16681669
1688
  return switch_mode_usb(mode);
1688
  return switch_mode_usb(mode);
1689
}
1689
}
1690
 
1690
 
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
1818
/*
1691
/*
1819
pack the lua args into a buffer to pass to the native code calling functions 
1692
pack the lua args into a buffer to pass to the native code calling functions 
1820
currently only handles strings/numbers
1693
currently only handles strings/numbers
...
...
2345
2218
2346
   FUNC(set_record)
2219
   FUNC(set_record)
2347
   FUNC(switch_mode_usb)
2220
   FUNC(switch_mode_usb)
2348
#ifdef CAM_CHDK_PTP
2349
   FUNC(get_video_details)
2350
#endif
2351
2221
2352
#ifdef OPT_LUA_CALL_NATIVE
2222
#ifdef OPT_LUA_CALL_NATIVE
2353
   FUNC(call_event_proc)
2223
   FUNC(call_event_proc)

Updated branches/reyalp-ptp-live/core/Makefile Download diff

16681669
53
ifdef OPT_PTP
53
ifdef OPT_PTP
54
# in top level
54
# in top level
55
#CFLAGS+=-DOPT_PTP
55
#CFLAGS+=-DOPT_PTP
56
OPT_OBJS+=ptp.o 
56
OPT_OBJS+=ptp.o live_view.o
57
endif 
57
endif 
58
ifdef OPT_EXMEM_MALLOC
58
ifdef OPT_EXMEM_MALLOC
59
#CFLAGS+=-DOPT_EXMEM_MALLOC
59
#CFLAGS+=-DOPT_EXMEM_MALLOC

Updated branches/reyalp-ptp-live/core/ptp.c Download diff

16681669
7
#include "kbd.h"
7
#include "kbd.h"
8
8
9
#include "core.h"
9
#include "core.h"
10
  
10
#include "live_view.h"
11
11
static int buf_size=0;
12
static int buf_size=0;
12
13
13
#ifdef OPT_LUA
14
#ifdef OPT_LUA
...
...
299
      break;
300
      break;
300
301
301
    case PTP_CHDK_CallFunction:
302
    case PTP_CHDK_CallFunction:
302
      if ( (param2 & 0x1) == 0 )
303
      {
303
      {
304
        int s;
304
        int s;
305
        int *buf = (int *) malloc((10+1)*sizeof(int));
305
        int *buf = (int *) malloc((10+1)*sizeof(int));
...
...
322
322
323
        free(buf);
323
        free(buf);
324
        break;
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);
328
        break;
329
      }
325
      }
330
326
331
    case PTP_CHDK_TempData:
327
    case PTP_CHDK_TempData:
...
...
624
    }
620
    }
625
#endif
621
#endif
626
622
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
627
    default:
640
    default:
628
      ptp.code = PTP_RC_ParameterNotSupported;
641
      ptp.code = PTP_RC_ParameterNotSupported;
629
      break;
642
      break;

Updated branches/reyalp-ptp-live/core/ptp.h Download diff

16681669
1
#ifndef __CHDK_PTP_H
1
#ifndef __CHDK_PTP_H
2
#define __CHDK_PTP_H
2
#define __CHDK_PTP_H
3
#define PTP_CHDK_VERSION_MAJOR 2  // increase only with backwards incompatible changes (and reset minor)
3
#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
5
/*
5
/*
6
protocol version history
6
protocol version history
7
0.1 - initial proposal from mweerden, + luar
7
0.1 - initial proposal from mweerden, + luar
8
0.2 - Added ScriptStatus and ScriptSupport, based on work by ultimA
8
0.2 - Added ScriptStatus and ScriptSupport, based on work by ultimA
9
1.0 - removed old script result code (luar), replace with message system
9
1.0 - removed old script result code (luar), replace with message system
10
2.0 - return PTP_CHDK_TYPE_TABLE for tables instead of TYPE_STRING, allow return of empty strings
10
2.0 - return PTP_CHDK_TYPE_TABLE for tables instead of TYPE_STRING, allow return of empty strings
11
2.1 - eperimental live view, not formally released
12
2.2 - live view (work in progress)
11
*/
13
*/
12
14
13
#define PTP_OC_CHDK 0x9999
15
#define PTP_OC_CHDK 0x9999
...
...
30
  PTP_CHDK_SetMemory,       // param2 is address
32
  PTP_CHDK_SetMemory,       // param2 is address
31
                            // param3 is size (in bytes)
33
                            // param3 is size (in bytes)
32
                            // data is new memory block
34
                            // 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
35
  PTP_CHDK_CallFunction,    // data is array of function pointer and (long) arguments  (max: 10 args)
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
37
                            // return param1 is return value
36
                            // return param1 is return value
38
  PTP_CHDK_TempData,        // data is data to be stored for later
37
  PTP_CHDK_TempData,        // data is data to be stored for later
39
                            // param2 is for the TD flags below
38
                            // param2 is for the TD flags below
...
...
66
                            // data length is handled by ptp data phase
65
                            // data length is handled by ptp data phase
67
                            // input messages do not have type or subtype, they are always a string destined for the script (similar to USER/string)
66
                            // input messages do not have type or subtype, they are always a string destined for the script (similar to USER/string)
68
                            // output param1 is ptp_chdk_script_msg_status
67
                            // 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
69
};
75
};
70
76
71
// data types as used by ReadScriptMessage
77
// data types as used by ReadScriptMessage
...
...
120
    PTP_CHDK_S_MSGSTATUS_QFULL,  // queue is full
126
    PTP_CHDK_S_MSGSTATUS_QFULL,  // queue is full
121
    PTP_CHDK_S_MSGSTATUS_BADID,  // specified ID is not running
127
    PTP_CHDK_S_MSGSTATUS_BADID,  // specified ID is not running
122
};
128
};
129
130
// function handler id
131
enum ptp_chdk_handler_id {
132
    PTP_CHDK_LIVE_VIEW_HANDLER_ID = 1,  // Live View handler
133
};
123
#endif // __CHDK_PTP_H
134
#endif // __CHDK_PTP_H