ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / linux / api_v4l_vlib_ethernet.c
1 #include <VP_Api/vp_api.h>
2 #include <VP_Api/vp_api_error.h>
3 #include <VP_Stages/vp_stages_configs.h>
4 #include <VP_Stages/vp_stages_i_v4l.h>
5 #include <VP_Stages/vp_stages_io_com.h>
6 #include <VP_Stages/vp_stages_buffer_to_picture.h>
7 #include <VP_Os/vp_os_print.h>
8 #include <VP_Os/vp_os_malloc.h>
9 #include <VP_Os/vp_os_delay.h>
10 #include <VP_Api/vp_api_thread_helper.h>
11 #include <VLIB/Stages/vlib_stage_encode.h>
12
13
14 #define VIDEO_DEVICE_PATH "/dev/video0"
15
16 #undef BLOCK_MODE
17 #undef ACQ_WIDTH
18 #undef ACQ_HEIGHT
19
20 #define ACQ_WIDTH 320
21 #define ACQ_HEIGHT 240
22
23 #define COM_VIDEO()             wired_com()
24 #define COM_CONFIG_VIDEO()      wired_config()
25 #define COM_CONNECTION_VIDEO()  wired_connection()
26
27
28 PROTO_THREAD_ROUTINE(app,nomParams);
29
30 BEGIN_THREAD_TABLE
31   THREAD_TABLE_ENTRY(app,20)
32 END_THREAD_TABLE
33
34
35 #define NB_STAGES_MAX 10
36
37
38 static vp_stages_input_v4l_config_t         ivc;
39 static vp_stages_buffer_to_picture_config_t bpc;
40 static vlib_stage_encoding_config_t         vec;
41 static vp_stages_output_com_config_t        occ;
42
43 static PIPELINE_HANDLE pipeline_handle;
44
45 static vp_api_picture_t picture;
46
47
48 vp_com_t* wired_com(void)
49 {
50   static vp_com_t com = {
51     VP_COM_WIRED,
52     FALSE,
53     0,
54     { { 0 } },
55     NULL,
56     NULL,
57     0,
58     NULL,
59     NULL,
60     NULL,
61     NULL,
62     NULL,
63     NULL,
64     NULL,
65     NULL,
66     NULL,
67     NULL,
68     NULL
69   };
70
71   return &com;
72 }
73
74 vp_com_config_t* wired_config(void)
75 {
76   static vp_com_wired_config_t config = {
77     "eth0",
78     "172.20.22.245",
79     "255.255.255.0",
80     "172.20.22.255"
81   };
82
83   return (vp_com_config_t*) &config;
84 }
85
86 vp_com_connection_t* wired_connection(void)
87 {
88   static vp_com_wired_connection_t connection = {
89     0
90   };
91
92   return (vp_com_connection_t*) (void*) &connection;
93 }
94
95
96 int main(int argc, char **argv)
97 {
98   if(argc < 2)
99     {
100       PRINT("You need to specify video device path\n");
101       PRINT("Ex : %s /dev/video0\n", argv[0]);
102       return EXIT_FAILURE;
103     }
104
105   START_THREAD(app, argv);
106   JOIN_THREAD(app);
107
108   return EXIT_SUCCESS;
109 }
110
111
112 PROTO_THREAD_ROUTINE(app,argv)
113 {
114   vp_api_io_pipeline_t pipeline;
115   vp_api_io_data_t out;
116   vp_api_io_stage_t stages[NB_STAGES_MAX];
117
118   uint16_t time1,time2;
119   uint16_t i;
120
121   time1 = clock();
122
123   vp_os_memset(&ivc,0,sizeof(ivc));
124   vp_os_memset(&bpc,0,sizeof(bpc));
125   vp_os_memset(&vec,0,sizeof(vec));
126   vp_os_memset(&occ,0,sizeof(occ));
127
128   ivc.device = ((char**)argv)[1];
129   ivc.width = ACQ_WIDTH;
130   ivc.height = ACQ_HEIGHT;
131   ivc.vp_api_picture = &picture;
132
133   vec.width                               = ACQ_WIDTH;
134   vec.height                              = ACQ_HEIGHT;
135   vec.block_mode_enable                   = FALSE;
136   vec.picture                             = &picture;
137
138   occ.com                           = COM_VIDEO();
139   occ.config                        = COM_CONFIG_VIDEO();
140   occ.connection                    = COM_CONNECTION_VIDEO();
141   occ.socket.type                   = VP_COM_SERVER;
142   occ.socket.protocol               = VP_COM_TCP;
143   occ.socket.port                   = 5555;
144   occ.buffer_size                   = 1500;
145
146   pipeline.nb_stages = 0;
147
148   stages[pipeline.nb_stages].type    = VP_API_INPUT_FILE;
149   stages[pipeline.nb_stages].cfg     = (void *)&ivc;
150   stages[pipeline.nb_stages++].funcs = vp_stages_input_v4l_funcs;
151   
152   stages[pipeline.nb_stages].type    = VP_API_FILTER_ENCODER;
153   stages[pipeline.nb_stages].cfg     = (void*)&vec;
154   stages[pipeline.nb_stages++].funcs = vlib_encoding_funcs;
155
156   stages[pipeline.nb_stages].type    = VP_API_OUTPUT_SOCKET;
157   stages[pipeline.nb_stages].cfg     = (void *)&occ;
158   stages[pipeline.nb_stages++].funcs = vp_stages_output_com_funcs;
159
160   pipeline.stages = &stages[0];
161
162   vp_api_open(&pipeline, &pipeline_handle);
163  
164   out.status = VP_API_STATUS_PROCESSING;
165
166   /////////////////////////////////////////////////////////////////////////////////////////
167   i = 0;
168   while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING))
169     {
170       i++;
171       PRINT("image %d \n",i);
172       //vp_os_delay(50);
173     }
174   /////////////////////////////////////////////////////////////////////////////////////////
175
176   time2 = clock();
177   printf("temps ecoule : %d \n",time2-time1);
178     
179   vp_api_close(&pipeline, &pipeline_handle);
180
181   return EXIT_SUCCESS;
182 }
183