ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / elinux / api_ifile_upper_ofile.c
1 #include <stdlib.h>
2 #include <ctype.h>
3
4 #include <VP_Api/vp_api.h>
5 #include <VP_Api/vp_api_error.h>
6 #include <VP_Stages/vp_stages_io_file.h>
7 #include <VP_Os/vp_os_print.h>
8
9
10 #define NB_STAGES 3
11
12
13 static PIPELINE_HANDLE pipeline_handle;
14
15
16 C_RESULT
17 my_transform_open(void *cfg)
18 {
19   return (SUCCESS);
20 }
21
22 C_RESULT
23 my_transform_transform(void *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
24 {
25   int i;
26
27   vp_os_mutex_lock(&out->lock);
28
29   if(out->status == VP_API_STATUS_INIT)
30     {
31       out->numBuffers = 1;
32       out->size = in->size; // to be cleaned ...
33       out->buffers = (int8_t **)malloc(sizeof(int8_t *)+out->size*sizeof(int8_t));
34       out->buffers[0] = (int8_t *)(out->buffers+1);
35       out->indexBuffer = 0;
36       // out->lineSize not used
37       out->status = VP_API_STATUS_PROCESSING;
38     }
39
40   if(in->status == VP_API_STATUS_ENDED)
41     {
42       free(out->buffers);
43     }
44   else if(in->status == VP_API_STATUS_PROCESSING)
45     {
46       // uppercase
47       for(i = 0 ; i < in->size ; i++)
48         {
49           out->buffers[0][i] = toupper(in->buffers[in->indexBuffer][i]);
50         }
51     }
52
53   out->status = in->status;
54
55   vp_os_mutex_unlock(&out->lock);
56
57   return (SUCCESS);
58 }
59
60 C_RESULT
61 my_transform_close(void *cfg)
62 {
63   return (SUCCESS);
64 }
65
66
67 const vp_api_stage_funcs_t my_transform_funcs =
68 {
69   NULL,
70   (vp_api_stage_open_t)my_transform_open,
71   (vp_api_stage_transform_t)my_transform_transform,
72   (vp_api_stage_close_t)my_transform_close
73 };
74
75
76 int
77 main(int argc, char **argv)
78 {
79   vp_api_io_pipeline_t pipeline;
80   vp_api_io_data_t out;
81   vp_api_io_stage_t stages[NB_STAGES];
82
83   vp_stages_input_file_config_t ifc;
84   vp_stages_output_file_config_t ofc;
85
86   ifc.name = "toto.in";
87   ifc.buffer_size = 512;
88
89   ofc.name = "toto.out";
90
91   stages[0].type = VP_API_INPUT_FILE;
92   stages[0].cfg = (void *)&ifc;
93   stages[0].funcs = vp_stages_input_file_funcs;
94
95   stages[1].type = VP_API_FILTER_ENCODER;
96   stages[1].cfg = NULL;
97   stages[1].funcs = my_transform_funcs;
98
99   stages[2].type = VP_API_OUTPUT_FILE;
100   stages[2].cfg = (void *)&ofc;
101   stages[2].funcs = vp_stages_output_file_funcs;
102
103   pipeline.nb_stages = NB_STAGES;
104   pipeline.stages = &stages[0];
105
106   vp_api_open(&pipeline, &pipeline_handle);
107
108   out.status = VP_API_STATUS_PROCESSING;
109   while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING));
110
111   // \todo tests
112
113   vp_api_close(&pipeline, &pipeline_handle);
114   return EXIT_SUCCESS;
115 }