ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / linux / api_ethernet_raw_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_Stages/vp_stages_buffer_to_picture.h>
14 #include <VP_Os/vp_os_print.h>
15 #include <VP_Os/vp_os_malloc.h>
16 #include <VP_Os/vp_os_delay.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 vp_stages_buffer_to_picture_config_t  bpc;
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( &bpc,     0, sizeof(bpc) );
136   vp_os_memset( &osc,     0, sizeof(osc) );
137
138   icc.com               = COM_VIDEO();
139   icc.buffer_size       = ACQ_WIDTH*ACQ_HEIGHT*3/2;
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   bpc.picture             = &picture;
158   bpc.block_mode_enable   = FALSE;
159   bpc.y_buffer_size       = ACQ_WIDTH * ACQ_HEIGHT;
160   bpc.y_blockline_size    = ACQ_WIDTH * 16; // each blockline have 16 lines
161   bpc.y_current_size      = 0;
162   bpc.num_frames          = 0;
163   bpc.y_buf_ptr           = NULL;
164   bpc.luma_only           = FALSE;
165   bpc.cr_buf_ptr          = NULL;
166   bpc.cb_buf_ptr          = NULL;
167
168   osc.width           = ACQ_WIDTH;
169   osc.height          = ACQ_HEIGHT;
170   osc.bpp             = 16;
171   osc.window_width    = ACQ_WIDTH;
172   osc.window_height   = ACQ_HEIGHT;
173   osc.pic_width       = ACQ_WIDTH;
174   osc.pic_height      = ACQ_HEIGHT;
175   osc.y_size          = ACQ_WIDTH*ACQ_HEIGHT;
176   osc.c_size          = (ACQ_WIDTH*ACQ_HEIGHT) >> 2;
177
178   pipeline.nb_stages                 = 0;
179
180   stages[pipeline.nb_stages].type    = VP_API_INPUT_SOCKET;
181   stages[pipeline.nb_stages].cfg     = (void *)&icc;
182   stages[pipeline.nb_stages++].funcs = vp_stages_input_com_funcs;
183
184   stages[pipeline.nb_stages].type    = VP_API_FILTER_DECODER;
185   stages[pipeline.nb_stages].cfg     = (void*)&bpc;
186   stages[pipeline.nb_stages++].funcs = vp_stages_buffer_to_picture_funcs;
187
188   stages[pipeline.nb_stages].type    = VP_API_OUTPUT_SDL;
189   stages[pipeline.nb_stages].cfg     = (void *)&osc;
190   stages[pipeline.nb_stages++].funcs = vp_stages_output_sdl_funcs;
191
192   pipeline.stages                    = &stages[0];
193
194   vp_api_open(&pipeline, &pipeline_handle);
195   out.status = VP_API_STATUS_PROCESSING;
196   while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING))
197     {
198     }
199
200   vp_api_close(&pipeline, &pipeline_handle);
201
202   return EXIT_SUCCESS;
203 }
204