ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / linux / api_ethernet_vlib_sdl.c
1 #include <stdlib.h>
2 #include <ctype.h>
3
4 #include <VP_Api/vp_api.h>
5 #include <VP_Api/vp_api_thread_helper.h>
6 #include <VP_Api/vp_api_error.h>
7 #include <VP_Stages/vp_stages_configs.h>
8 #include <VP_Stages/vp_stages_io_console.h>
9 #include <VP_Stages/vp_stages_o_sdl.h>
10 #include <VP_Stages/vp_stages_io_console.h>
11 #include <VP_Stages/vp_stages_io_com.h>
12 #include <VP_Stages/vp_stages_io_file.h>
13 #include <VP_Os/vp_os_print.h>
14 #include <VP_Os/vp_os_malloc.h>
15 #include <VP_Os/vp_os_delay.h>
16 #include <VLIB/Stages/vlib_stage_decode.h>
17
18
19 #define SERVER_HOST "172.20.22.245"
20
21 #undef BLOCK_MODE
22 #undef ACQ_WIDTH
23 #undef ACQ_HEIGHT
24
25 #define NB_STAGES_MAX 10
26
27 #define ACQ_WIDTH     320
28 #define ACQ_HEIGHT    240
29
30
31 #define COM_VIDEO()             wired_com()
32 #define COM_CONFIG_VIDEO()      wired_config()
33 #define COM_CONNECTION_VIDEO()  wired_connection()
34 #define COM_CONFIG_SOCKET_VIDEO(socket, type, opt, serverhost)  wired_config_socket(socket, type, opt, serverhost)
35
36
37 PROTO_THREAD_ROUTINE(escaper,nomParams);
38 PROTO_THREAD_ROUTINE(app,nomParams);
39
40 BEGIN_THREAD_TABLE
41   THREAD_TABLE_ENTRY(escaper,20)
42   THREAD_TABLE_ENTRY(app,10)
43 END_THREAD_TABLE
44
45
46 static vp_stages_input_com_config_t  icc;
47 static vlib_stage_decoding_config_t  vdc;
48 static vp_stages_output_sdl_config_t osc;
49
50 static PIPELINE_HANDLE pipeline_handle;
51
52 static vp_api_picture_t picture;
53
54
55 vp_com_t* wired_com(void)
56 {
57   static vp_com_t com = {
58     VP_COM_WIRED,
59     FALSE,
60     0,
61     { { 0 } },
62     NULL,
63     NULL,
64     0,
65     NULL,
66     NULL,
67     NULL,
68     NULL,
69     NULL,
70     NULL,
71     NULL,
72     NULL,
73     NULL,
74     NULL,
75     NULL
76   };
77
78   return &com;
79 }
80
81 vp_com_config_t* wired_config(void)
82 {
83   static vp_com_wired_config_t config = {
84     "eth1",
85     "172.20.22.245",
86     "255.255.255.0",
87     "172.20.22.255"
88   };
89
90   return (vp_com_config_t*) &config;
91 }
92
93 vp_com_connection_t* wired_connection(void)
94 {
95   static vp_com_wired_connection_t connection = {
96     0
97   };
98
99   return (vp_com_connection_t*) (void*) &connection;
100 }
101
102 void wired_config_socket(vp_com_socket_t* socket, VP_COM_SOCKET_TYPE type, int32_t port, const char* serverhost)
103 {
104   vp_os_memset(socket, 0, sizeof(vp_com_socket_t));
105
106   socket->type           = type;
107   socket->protocol       = VP_COM_TCP;
108   socket->port           = port;
109
110   if(serverhost && socket->type == VP_COM_CLIENT)
111     strcpy(socket->serverHost, serverhost);
112 }
113
114
115 int
116 main(int argc, char **argv)
117 {
118   START_THREAD(escaper, NO_PARAM);
119   START_THREAD(app, argv);
120
121   JOIN_THREAD(escaper);
122   JOIN_THREAD(app);
123
124   return EXIT_SUCCESS;
125 }
126
127
128 PROTO_THREAD_ROUTINE(app,argv)
129 {
130   vp_api_io_pipeline_t    pipeline;
131   vp_api_io_data_t        out;
132   vp_api_io_stage_t       stages[NB_STAGES_MAX];
133
134   vp_os_memset( &icc,     0, sizeof(icc) );
135   vp_os_memset( &vdc,     0, sizeof(vdc) );
136   vp_os_memset( &osc,     0, sizeof(osc) );
137
138   icc.com               = COM_VIDEO();
139   icc.buffer_size       = 1024;
140   icc.socket.protocol   = VP_COM_TCP;
141   COM_CONFIG_SOCKET_VIDEO(&icc.socket, VP_COM_CLIENT, 5555, SERVER_HOST);
142
143   /// Picture configuration
144   picture.format        = PIX_FMT_YUV420P;
145   picture.width         = ACQ_WIDTH;
146   picture.height        = ACQ_HEIGHT;
147   picture.framerate     = 30;
148   picture.y_buf         = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT );
149   picture.cr_buf        = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT/4 );
150   picture.cb_buf        = vp_os_malloc( ACQ_WIDTH*ACQ_HEIGHT/4 );
151   picture.y_line_size   = ACQ_WIDTH;
152   picture.cb_line_size  = ACQ_WIDTH / 2;
153   picture.cr_line_size  = ACQ_WIDTH / 2;
154   picture.y_pad         = 0;
155   picture.c_pad         = 0;
156
157   vdc.width           = ACQ_WIDTH;
158   vdc.height          = ACQ_HEIGHT;
159   vdc.picture         = &picture;
160   vdc.luma_only       = FALSE;
161   vdc.block_mode_enable = FALSE;
162
163   osc.width           = ACQ_WIDTH;
164   osc.height          = ACQ_HEIGHT;
165   osc.bpp             = 16;
166   osc.window_width    = ACQ_WIDTH;
167   osc.window_height   = ACQ_HEIGHT;
168   osc.pic_width       = ACQ_WIDTH;
169   osc.pic_height      = ACQ_HEIGHT;
170   osc.y_size          = ACQ_WIDTH*ACQ_HEIGHT;
171   osc.c_size          = (ACQ_WIDTH*ACQ_HEIGHT) >> 2;
172
173   pipeline.nb_stages                 = 0;
174
175   stages[pipeline.nb_stages].type    = VP_API_INPUT_SOCKET;
176   stages[pipeline.nb_stages].cfg     = (void *)&icc;
177   stages[pipeline.nb_stages++].funcs = vp_stages_input_com_funcs;
178
179   stages[pipeline.nb_stages].type    = VP_API_FILTER_DECODER;
180   stages[pipeline.nb_stages].cfg     = (void*)&vdc;
181   stages[pipeline.nb_stages++].funcs = vlib_decoding_funcs;
182
183   stages[pipeline.nb_stages].type    = VP_API_OUTPUT_SDL;
184   stages[pipeline.nb_stages].cfg     = (void *)&osc;
185   stages[pipeline.nb_stages++].funcs = vp_stages_output_sdl_funcs;
186
187   pipeline.stages                    = &stages[0];
188
189   vp_api_open(&pipeline, &pipeline_handle);
190   out.status = VP_API_STATUS_PROCESSING;
191   while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING))
192     {
193     }
194
195   vp_api_close(&pipeline, &pipeline_handle);
196
197   return EXIT_SUCCESS;
198 }
199