Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 249 lines (229 sloc) 9.123 kb
c729c0f Importing existing code
Diego Dompe authored
1 /**
2 * ipiped/src/ipiped.vala
3 *
4 * Ipipe class - framework for controlling and configuring ipipe using D-Bus messages
5 *
6 * Copyright(c) 2010, RidgeRun
7 * All rights reserved.
8 *
9 * GPL2 license - See http://www.opensource.org/licenses/gpl-2.0.php for complete text.
10 */
11
12 using Posix,V4l2,ImpPrev,dm365aew;
13 #if (RRAEW)
14 using rraew;
15 #endif
16 [DBus(name = "com.ridgerun.ipiped.IpipeInterface", signals = "Error")]
17 public class Ipipe:GLib.Object {
18
19 /* Private data */
20 /** Flag to enable/disable debug information */
21 private static bool debug = false;
22 /** Flag to indicate if the previewer is initialized*/
23 private static bool initialized = false;
24 private string sensor = "";
25 private string video_processor = "";
26 public AbstcVideoProcessor video_processor_abstract;
27 public AbstcSensor sensor_abstract;
28 public signal void Error(string err_message);
29 #if (RRAEW)
30 /** Thread for aew*/
31 unowned Thread<void*> thread;
32 /** Flag to indicate if the aew thread is running*/
33 bool aew_running = false;
34 /** Indicates if we can close the execution thread wihtout failing **/
35 bool clean_close = false;
36 /** Pointer to aew structure*/
37 void *rraew = null;
38 /** Time between aew iterations*/
39 int wait_time=0;
40 #endif
41 /**
42 * Create a new instance of a Ipipe daemon
43 */
44 public Ipipe(string _sensor, string _video_processor, AbstcVideoProcessor _video_processor_abstract,
45 AbstcSensor _sensor_abstract){
46 /* Initialize private variables */
47 initialized = false;
48 sensor =_sensor;
49 video_processor=_video_processor;
50 video_processor_abstract=_video_processor_abstract;
51 sensor_abstract=_sensor_abstract;
52 this.debug = false;
53 }
54 /**
55 * Destroy a instance of Ipipe
56 */
57 ~Ipipe(){
58 /* Destroy the ipipe instance */
59 }
60
61 /**
62 * Debug
63 * Enable/Disable the debug information in all the functions
64 * @param enable if true print debug information
65 */
66 public void enable_debug(bool enable) throws IOError{
67 this.debug = enable;
68 video_processor_abstract.debug = true;
69 sensor_abstract.debug = true;
70 }
71 /**
72 * Ping
73 * Show to the ipipe-client that an instance of the ipiped daemon is
74 * alive
75 */
76 public bool ping() throws IOError{
77 return true;
78 }
79
80 public string get_sensor() throws IOError{
81 return sensor;
82 }
83
84 public string get_video_processor() throws IOError{
85 return video_processor;
86 }
87
88 #if (RRAEW)
89 private void* aew_thread_func(){
90 try {
91 while (aew_running) {
92 Thread.usleep(wait_time);
93 if (run_rraew(rraew)<0){
94 clean_close = false;
95 close_aew();
96 }
97 }
98 }catch(IOError e) {
99 Posix.stderr.printf("Fail to execute:%s\n", e.message);
100 }
101 return null;
102 }
103
104
105 /**
106 * AEW Algorithm initialization
107 * Uses the parameters given by the user to configure the aew library,
108 * sets the functions to access the sensor and the dm365 interface
109 * (vpfe ipipe). Creates an aew structure and a thread for the aew loop
110 * @param wb string that chooses the auto white balance algorithm,
111 * can be "G" for gray world or "W" for white balance or "N" to do not
112 * apply an auto white balance.
113 * @param ae string that chooses the auto exposure algorithm, can be
114 * "EC" for electronic centric or "N" to do not apply an auto exposure.
115 * @param g string that chooses the gain type, can be "S" for sensor
116 * gain or "D" for digital gain.
117 * @param meter string that chooses the metering system for the auto
118 * exposure algorithm, can be "S" for spot or "P" for partial or "C" for
119 * electronic centric or "SG" for segmented image or "A" for average.
120 * @param time it is the time between aew algorithms iterations
121 * @param fps is the minimum allowed frame rate
122 * @param segment_factor a percentage of the maximun image divisions
123 */
124 public int init_aew(string wb, string ae, string g, string meter,
125 int time, int fps, int segment_factor, int width, int height,
126 int center_percentage) throws IOError
127 {
128 /** File descriptors information*/
129 FileDescriptors fd = FileDescriptors();
130
131 wait_time = time;
132 WhiteBalanceAlgo wb_algo;
133 ExposureAlgo ae_algo;
134 GainType gain_type;
135 MeteringType meter_type;
136 Sensor sensor = Sensor();
137 Interface interf = Interface();
138
139 if(aew_running) {
140 Posix.stderr.printf("The AEW algorithm is alreadty being " +
141 "executed. Please finish the current session\n by using " +
142 "close-aew. Then you will be able to start a new one\n");
143 return -1;
144 }
145
146 if (time > 1000000) {
147 Posix.stderr.printf("\nIpiped:Wait time is greater than the maximum\n");
148 return -1;
149 }
150
151 if ((segment_factor > 100)|| (segment_factor) < 1) {
152 Posix.stderr.printf("\nIpiped:Segmentation factor must be between 1 and 100\n");
153 return -1;
154 }
155
156 /* Define the gain module to be used*/
157 if (g == "S")
158 gain_type = GainType.SENSOR;
159 else if (g == "D")
160 gain_type = GainType.DIGITAL;
161 else {
162 Posix.stderr.printf("\nIpiped:Invalid gain type\n");
163 return -1;
164 }
165 /* Define the ae algorithm*/
166 if (ae == "EC")
167 ae_algo = ExposureAlgo.EC;
168 else if(ae == "N")
169 ae_algo = ExposureAlgo.NONE;
170 else {
171 Posix.stderr.printf("\nIpiped:Invalid auto exposure algorithm\n");
172 return -1;
173 }
174 /* Define the awb algorithm*/
175 if (wb == "W")
176 wb_algo = WhiteBalanceAlgo.WHITE_PATCH;
177 else if (wb == "W2")
178 wb_algo = WhiteBalanceAlgo.WHITE_PATCH_2;
179 else if (wb == "G")
180 wb_algo = WhiteBalanceAlgo.GRAY_WORLD;
181 else if (wb == "N")
182 wb_algo = WhiteBalanceAlgo.NONE;
183 else{
184 Posix.stderr.printf("\nIpiped:Invalid white-balance algorithm\n");
185 return -1;
186 }
187 /* Define the metering method*/
188 if (meter == "P")
189 meter_type = MeteringType.PARTIAL_AREA;
190 else if (meter == "C")
191 meter_type = MeteringType.CENTER_WEIGHTED;
192 else if (meter == "A")
193 meter_type = MeteringType.AVERAGE;
194 else if (meter == "SG"){
195 meter_type = MeteringType.SEGMENT;
196 }else{
197 Posix.stderr.printf("\nIpiped:Invalid metering type\n");
198 return -1;
199 }
200
201 /* Sensor information */
202 sensor_abstract.get_sensor_data(&sensor);
203 if (!video_processor_abstract.get_video_processor_data(&interf)) {
204 Posix.stderr.printf ("Can't get video processor data\n");
205 return -1;
206 }
207
208 fd.previewer_fd = video_processor_abstract.previewer_fd;
209 fd.owner_previewer_fd = video_processor_abstract.owner_previewer_fd;
210 fd.aew_fd = video_processor_abstract.aew_fd;
211 fd.owner_aew_fd = video_processor_abstract.owner_aew_fd;
212 fd.capture_fd = sensor_abstract.capture_fd;
213 fd.owner_capture_fd = sensor_abstract.owner_capture_fd;
214
215 rraew = create_rraew(wb_algo, ae_algo, meter_type,
216 width, height, fps, segment_factor, center_percentage, gain_type,
217 &fd, &sensor, &interf);
218
219 aew_running = true;
220 clean_close = true;
221 if (!Thread.supported ()) {
222 error ("Cannot run without thread support");
223 }
224 try {
225 thread = Thread.create<void*>(aew_thread_func, true);
226 } catch (ThreadError e) {
227 return -1;
228 }
229 return 0;
230 }
231
232 /**
233 * End AEW Algorithm, disable AEW engine
234 */
235 public void close_aew() throws IOError{
236 aew_running = false;
237 if(clean_close) {
238 thread.join();
239 clean_close = false;
240 }
241 if (rraew != null){
242 destroy_rraew(rraew);
243 rraew = null;
244 }
245 }
246 #endif
247 }
248
Something went wrong with that request. Please try again.