BitmapToolkit Scol plugin
private_impl.h
Go to the documentation of this file.
1/**********************************************************
2 Software developed by AVA ( Ava Group of the University of Cordoba, ava at uco dot es)
3 Main author Rafael Munoz Salinas (rmsalinas at uco dot es)
4 This software is released under BSD license as expressed below
5-------------------------------------------------------------------
6Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es)
7All rights reserved.
8
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
121. Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
142. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
173. All advertising materials mentioning features or use of this software
18 must display the following acknowledgement:
19
20 This product includes software developed by the Ava group of the University of Cordoba.
21
224. Neither the name of the University nor the names of its contributors
23 may be used to endorse or promote products derived from this software
24 without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY
27EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY
30DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36****************************************************************/
37
38#ifndef _Private_RaspiCam_IMPL_H
39#define _Private_RaspiCam_IMPL_H
40#include "mmal/mmal.h"
41//#include "mmal_connection.h"
42#include <mutex>
43#include <string>
47
48namespace raspicam
49{
50 namespace _private
51 {
52
56 {
59 struct PORT_USERDATA
60 {
61 PORT_USERDATA() {
62 wantToGrab=false;
63 pstate=0;
64 }
65 void waitForFrame() {
66 //_mutex.lock();
67 std::unique_lock<std::mutex> lck ( _mutex );
68
69 wantToGrab=true;
70// _mutex.unlock();
71// Thcond.Wait();
72 Thcond.Wait(lck); //this will unlock the mutex and wait atomically
73 };
74
75
76
77 RASPIVID_STATE *pstate;
78 std::mutex _mutex;
79 ThreadCondition Thcond;
80 bool wantToGrab;
81 membuf<unsigned char> _buffData;
82 };
83
84 public:
85
94 bool open ( bool StartCapture=true );
97 bool isOpened() const
98 {
99 return _isOpened;
100 }
103 bool startCapture();
106 bool isCapturing() const{return _isCapturing;}
109 bool grab();
115 void retrieve ( unsigned char *data,RASPICAM_FORMAT type=RASPICAM_FORMAT_IGNORE );
119 unsigned char *getImageBufferData() const;
123 size_t getImageBufferSize() const;
124
127 void release();
128
129 //sets capture format. Can not be changed once camera is opened
130 void setFormat ( RASPICAM_FORMAT fmt );
131 void setWidth ( unsigned int width ) ;
132 void setHeight ( unsigned int height );
133 void setCaptureSize ( unsigned int width, unsigned int height );
134 void setBrightness ( unsigned int brightness );
135 void setRotation ( int rotation );
136 void setISO ( int iso );
137 void setSharpness ( int sharpness );
138 void setContrast ( int contrast );
139 void setSaturation ( int saturation );
140 void setExposure ( RASPICAM_EXPOSURE exposure );
141 void setVideoStabilization ( bool v );
142 void setExposureCompensation ( int val ); //-10,10
143 void setAWB ( RASPICAM_AWB awb );
144 void setAWB_RB ( float red,float blue );//ranges [0,1]
145 void setFrameRate ( unsigned int frame_rate ) ;
146
147 void setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect );
148 void setMetering ( RASPICAM_METERING metering );
149 void setHorizontalFlip ( bool hFlip );
150 void setVerticalFlip ( bool vFlip );
155 void setShutterSpeed ( unsigned int shutter ); //currently not supported
156
157 RASPICAM_FORMAT getFormat() const {return State.captureFtm;}
158 //Accessors
159 unsigned int getWidth() const
160 {
161 return State.width;
162 }
163 unsigned int getHeight() const
164 {
165 return State.height;
166 }
167 unsigned int getBrightness() const
168 {
169 return State.brightness;
170 }
171 unsigned int getRotation() const
172 {
173 return State.rotation;
174 }
175 int getISO() const
176 {
177 return State.ISO;
178 }
179 int getSharpness() const
180 {
181 return State.sharpness;
182 }
183 int getContrast() const
184 {
185 return State.contrast;
186 }
187 int getSaturation() const
188 {
189 return State.saturation;
190 }
191 int getShutterSpeed() const
192 {
193 return State.shutterSpeed;
194 }
195 unsigned int getFrameRate() const
196 {
197 return State.framerate;
198 }
200 {
201 return State.rpc_exposureMode;
202 }
204 {
205 return State.rpc_awbMode;
206 }
207
208 float getAWBG_red(){return State.awbg_red;}
209
210 float getAWBG_blue(){return State.awbg_blue;}
211
213 {
214 return State.rpc_imageEffect;
215 }
217 {
218 return State.rpc_exposureMeterMode;
219 }
221 {
222 return State.hflip;
223 }
225 {
226 return State.vflip;
227 }
228
229
230 //Returns an id of the camera. We assume the camera id is the one of the raspberry
231 //the id is obtained using raspberry serial number obtained in /proc/cpuinfo
232 std::string getId() const;
233
236 size_t getImageTypeSize ( RASPICAM_FORMAT type ) const;
237
238 private:
239 static void video_buffer_callback ( MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer );
240 void setDefaultStateParams();
241 MMAL_COMPONENT_T *create_camera_component ( RASPIVID_STATE *state );
242 void destroy_camera_component ( RASPIVID_STATE *state );
243
244
245 //Commit
246 void commitParameters( );
247 void commitBrightness();
248 void commitRotation() ;
249 void commitISO() ;
250 void commitSharpness();
251 void commitContrast();
252 void commitSaturation();
253 void commitExposure();
254 void commitAWB();
255 void commitImageEffect();
256 void commitMetering();
257 void commitFlips();
258 void commitExposureCompensation();
259 void commitVideoStabilization();
260 void commitShutterSpeed();
261 void commitAWB_RB();
262
263 MMAL_PARAM_EXPOSUREMODE_T convertExposure ( RASPICAM_EXPOSURE exposure ) ;
264 MMAL_PARAM_AWBMODE_T convertAWB ( RASPICAM_AWB awb ) ;
265 MMAL_PARAM_IMAGEFX_T convertImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect ) ;
266 MMAL_PARAM_EXPOSUREMETERINGMODE_T convertMetering ( RASPICAM_METERING metering ) ;
267 int convertFormat ( RASPICAM_FORMAT fmt ) ;
268
269
270 //Color conversion
271 void convertBGR2RGB(unsigned char * in_bgr,unsigned char * out_rgb,int size);
272 float VIDEO_FRAME_RATE_NUM;
273 RASPIVID_STATE State;
274 MMAL_STATUS_T status;
275 MMAL_PORT_T *camera_video_port;//,*camera_still_port
276 PORT_USERDATA callback_data;
277 bool _isOpened;
278 bool _isCapturing;
279 MMAL_ES_FORMAT_T *format=nullptr;
280
281
282 };
283 };
284};
285
286#endif
287
288
unsigned int getWidth() const
void setHeight(unsigned int height)
void setFormat(RASPICAM_FORMAT fmt)
RASPICAM_METERING getMetering() const
RASPICAM_IMAGE_EFFECT getImageEffect() const
void setWidth(unsigned int width)
unsigned int getRotation() const
size_t getImageTypeSize(RASPICAM_FORMAT type) const
unsigned int getHeight() const
unsigned int getBrightness() const
void setImageEffect(RASPICAM_IMAGE_EFFECT imageEffect)
void setBrightness(unsigned int brightness)
void setAWB_RB(float red, float blue)
RASPICAM_FORMAT getFormat() const
void setExposure(RASPICAM_EXPOSURE exposure)
unsigned int getFrameRate() const
void setShutterSpeed(unsigned int shutter)
bool open(bool StartCapture=true)
void setAWB(RASPICAM_AWB awb)
void setFrameRate(unsigned int frame_rate)
unsigned char * getImageBufferData() const
void setSaturation(int saturation)
void setMetering(RASPICAM_METERING metering)
RASPICAM_EXPOSURE getExposure() const
void setCaptureSize(unsigned int width, unsigned int height)
void retrieve(unsigned char *data, RASPICAM_FORMAT type=RASPICAM_FORMAT_IGNORE)
This class implements a condition to stop a thread until the condition is reached.
@ RASPICAM_FORMAT_IGNORE
int height
Requested width of image.
float awbg_red
region of interest to use on the sensor. Normalised [0,1] values in the rect
RASPICAM_METERING rpc_exposureMeterMode
RASPICAM_IMAGE_EFFECT rpc_imageEffect
int framerate
requested height of image
int sharpness
Pointer to the pool of buffers used by encoder output port.