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