6d292f401e4e73743de67b29cc9c067e000fc949
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / VP_Stages / vp_stages_io_buffer.c
1 /**
2  *  \brief    VP Stages. Buffer stage declaration
3  *  \author   Sylvain Gaeremynck <sylvain.gaeremynck@parrot.fr>
4  *  \author   Aurelien Morelle <aurelien.morelle@parrot.fr>
5  *  \author   Thomas Landais <thomas.landais@parrot.fr>
6  *  \version  2.0
7  *  \date     first release 16/03/2007
8  *  \date     modification  19/03/2007
9  */
10
11 ///////////////////////////////////////////////
12 // INCLUDES
13
14
15 #include <VP_Stages/vp_stages_io_buffer.h>
16 #include <VP_Api/vp_api_error.h>
17 #include <VP_Os/vp_os_print.h>
18 #include <VP_Os/vp_os_malloc.h>
19 #include <VP_Os/vp_os_assert.h>
20
21
22 C_RESULT
23 vp_stages_input_buffer_stage_open(vp_stages_input_buffer_config_t *cfg)
24 {
25   VP_OS_ASSERT(cfg->buffer);
26   return (VP_SUCCESS);
27 }
28
29
30 C_RESULT
31 vp_stages_input_buffer_stage_transform(vp_stages_input_buffer_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
32 {
33   vp_os_mutex_lock(&out->lock);
34
35   if(out->status == VP_API_STATUS_INIT)
36     {
37       out->numBuffers = 1;
38       out->size = 0;
39       out->buffers = &cfg->buffer;
40       out->indexBuffer = 0;
41       cfg->remaining_size = cfg->total_size;
42     }
43
44   if(cfg->remaining_size != 0)
45     {
46       out->status = VP_API_STATUS_PROCESSING;
47       out->buffers[out->indexBuffer] += out->size;
48       out->size = (cfg->remaining_size < cfg->send_size ? cfg->remaining_size : cfg->send_size);
49       cfg->remaining_size -= out->size;
50     }
51   else
52     {
53       out->status = VP_API_STATUS_ENDED;
54     }
55
56   vp_os_mutex_unlock(&out->lock);
57
58   DEBUG_PRINT_SDK("vp_stages_input_buffer : size=%d buffer=%08X remaining=%d\n", (int)out->size, (int)out->buffers[out->indexBuffer], (int)cfg->remaining_size);
59
60   return (VP_SUCCESS);
61 }
62
63
64 C_RESULT
65 vp_stages_input_buffer_stage_close(vp_stages_input_buffer_config_t *cfg)
66 {
67   return (VP_SUCCESS);
68 }
69
70
71 C_RESULT
72 vp_stages_output_buffer_stage_open(vp_stages_output_buffer_config_t *cfg)
73 {
74   return (VP_SUCCESS);
75 }
76
77
78 C_RESULT
79 vp_stages_output_buffer_stage_transform(vp_stages_output_buffer_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
80 {
81   vp_os_mutex_lock(&out->lock);
82
83   if(out->status == VP_API_STATUS_INIT)
84     {
85       out->numBuffers = 1;
86       out->size = in->size;
87       out->buffers = (int8_t **)vp_os_malloc(sizeof(int8_t *)+out->size*sizeof(int8_t));
88       out->buffers[0] = (int8_t *)(out->buffers+1);
89       out->indexBuffer = 0;
90       // out->lineSize not used
91       out->status = VP_API_STATUS_PROCESSING;
92     }
93
94   // \todo test
95   if(in->status == VP_API_STATUS_PROCESSING)
96     {
97       PRINT("One frame.\n");
98       vp_os_memcpy(out->buffers[0], &in->buffers[in->indexBuffer][0], in->size*sizeof(int8_t));
99     }
100
101   if(in->status == VP_API_STATUS_ENDED)
102     vp_os_free(out->buffers);
103
104   out->status = in->status;
105
106   vp_os_mutex_unlock(&out->lock);
107
108   return (VP_SUCCESS);
109 }
110
111
112 C_RESULT
113 vp_stages_output_buffer_stage_close(vp_stages_output_buffer_config_t *cfg)
114 {
115   return (VP_SUCCESS);
116 }