Advertisement
jeanleflambeur

private_impl.h

Jan 6th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  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. -------------------------------------------------------------------
  6. Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es)
  7. All rights reserved.
  8.  
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. 1. Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. 2. 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.
  17. 3. 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.  
  22. 4. 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.  
  26. THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY
  27. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  28. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY
  30. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  33. ON 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
  35. SOFTWARE, 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/mmal_connection.h"
  42. #include <mutex>
  43. #include <string>
  44. #include "raspicamtypes.h"
  45. #include "private_types.h"
  46. #include "threadcondition.h"
  47. namespace raspicam {
  48. namespace _private
  49. {
  50.  
  51. /**Base class that do all the hard work
  52. */
  53. class Private_Impl
  54. {
  55. /** Struct used to pass information in encoder port userdata to callback
  56. */
  57. struct PORT_USERDATA
  58. {
  59. PORT_USERDATA() {
  60. wantToGrab=false;
  61. pstate=0;
  62. }
  63. void waitForFrame() {
  64. std::unique_lock<std::mutex> lck ( _mutex );
  65. wantToGrab=true;
  66. Thcond.Wait(lck); //this will unlock the mutex and wait atomically
  67. };
  68.  
  69.  
  70.  
  71. RASPIVID_STATE *pstate; /// pointer to our state in case required in callback
  72. std::mutex _mutex;
  73. ThreadCondition Thcond;
  74. bool wantToGrab;
  75. membuf<unsigned char> _buffData;
  76. };
  77.  
  78. public:
  79.  
  80. /**Constructor
  81. */
  82. Private_Impl();
  83. /**Destructor
  84. */
  85. ~Private_Impl();
  86. /**Opens the camera and start capturing
  87. */
  88. bool open ( bool StartCapture=true );
  89. /**indicates if camera is open
  90. */
  91. bool isOpened() const
  92. {
  93. return _isOpened;
  94. }
  95. /**Starts camera capture
  96. */
  97. bool startCapture();
  98. /**Indicates if is capturing
  99. */
  100. bool isCapturing() const{return _isCapturing;}
  101. /**Grabs the next frame and keeps it in internal buffer. Blocks until next frame arrives
  102. */
  103. bool grab();
  104. /**Retrieves the buffer previously grabbed.
  105. * NOTE: Change in version 0.0.5. Format is stablished in setFormat function
  106. * So type param is ignored. Do not use this parameter.
  107. * You can use getFormat to know the current format
  108. */
  109. void retrieve ( unsigned char *data,RASPICAM_FORMAT type=RASPICAM_FORMAT_IGNORE );
  110. /**Alternative to retrieve. Returns a pointer to the original image data buffer.
  111. * Be careful, if you call grab(), this will be rewritten with the new data
  112. */
  113. unsigned char *getImageBufferData() const;
  114. /**
  115. * Returns the size of the buffer returned in getImagePtr. If is like calling getImageTypeSize(getFormat()). Just for dummies :P
  116. */
  117. size_t getImageBufferSize() const;
  118.  
  119. /** Stops camera and free resources
  120. */
  121. void release();
  122.  
  123. //sets capture format. Can not be changed once camera is opened
  124. void setFormat ( RASPICAM_FORMAT fmt );
  125. void setWidth ( unsigned int width ) ;
  126. void setHeight ( unsigned int height );
  127. void setCaptureSize ( unsigned int width, unsigned int height );
  128. void setBrightness ( unsigned int brightness );
  129. void setRotation ( int rotation );
  130. void setISO ( int iso );
  131. void setSharpness ( int sharpness );
  132. void setContrast ( int contrast );
  133. void setSaturation ( int saturation );
  134. void setExposure ( RASPICAM_EXPOSURE exposure );
  135. void setVideoStabilization ( bool v );
  136. void setExposureCompensation ( int val ); //-10,10
  137. void setAWB ( RASPICAM_AWB awb );
  138. void setImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect );
  139. void setMetering ( RASPICAM_METERING metering );
  140. void setHorizontalFlip ( bool hFlip );
  141. void setVerticalFlip ( bool vFlip );
  142. /**
  143. *Set the shutter speed to the specified value (in microseconds).
  144. *There is currently an upper limit of approximately 330000us (330ms, 0.33s) past which operation is undefined.
  145. */
  146. void setShutterSpeed ( unsigned int shutter ); //currently not supported
  147.  
  148. RASPICAM_FORMAT getFormat() const {return State.captureFtm;}
  149. //Accessors
  150. unsigned int getWidth() const
  151. {
  152. return State.width;
  153. }
  154. unsigned int getHeight() const
  155. {
  156. return State.height;
  157. }
  158. unsigned int getBrightness() const
  159. {
  160. return State.brightness;
  161. }
  162. unsigned int getRotation() const
  163. {
  164. return State.rotation;
  165. }
  166. int getISO() const
  167. {
  168. return State.ISO;
  169. }
  170. int getSharpness() const
  171. {
  172. return State.sharpness;
  173. }
  174. int getContrast() const
  175. {
  176. return State.contrast;
  177. }
  178. int getSaturation() const
  179. {
  180. return State.saturation;
  181. }
  182. int getShutterSpeed() const
  183. {
  184. return State.shutterSpeed;
  185. }
  186. RASPICAM_EXPOSURE getExposure() const
  187. {
  188. return State.rpc_exposureMode;
  189. }
  190. RASPICAM_AWB getAWB() const
  191. {
  192. return State.rpc_awbMode;
  193. }
  194. RASPICAM_IMAGE_EFFECT getImageEffect() const
  195. {
  196. return State.rpc_imageEffect;
  197. }
  198. RASPICAM_METERING getMetering() const
  199. {
  200. return State.rpc_exposureMeterMode;
  201. }
  202. bool isHorizontallyFlipped() const
  203. {
  204. return State.hflip;
  205. }
  206. bool isVerticallyFlipped() const
  207. {
  208. return State.vflip;
  209. }
  210.  
  211.  
  212. //Returns an id of the camera. We assume the camera id is the one of the raspberry
  213. //the id is obtained using raspberry serial number obtained in /proc/cpuinfo
  214. std::string getId() const;
  215.  
  216. /**Returns the size of the required buffer for the different image types in retrieve
  217. */
  218. size_t getImageTypeSize ( RASPICAM_FORMAT type ) const;
  219.  
  220. private:
  221. static void video_buffer_callback ( MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer );
  222. void setDefaultStateParams();
  223. MMAL_COMPONENT_T *create_camera_component ( RASPIVID_STATE *state );
  224. void destroy_camera_component ( RASPIVID_STATE *state );
  225.  
  226.  
  227. //Commit
  228. void commitParameters( );
  229. void commitBrightness();
  230. void commitRotation() ;
  231. void commitISO() ;
  232. void commitSharpness();
  233. void commitContrast();
  234. void commitSaturation();
  235. void commitExposure();
  236. void commitAWB();
  237. void commitImageEffect();
  238. void commitMetering();
  239. void commitFlips();
  240. void commitExposureCompensation();
  241. void commitVideoStabilization();
  242. void commitShutterSpeed();
  243.  
  244.  
  245. MMAL_PARAM_EXPOSUREMODE_T convertExposure ( RASPICAM_EXPOSURE exposure ) ;
  246. MMAL_PARAM_AWBMODE_T convertAWB ( RASPICAM_AWB awb ) ;
  247. MMAL_PARAM_IMAGEFX_T convertImageEffect ( RASPICAM_IMAGE_EFFECT imageEffect ) ;
  248. MMAL_PARAM_EXPOSUREMETERINGMODE_T convertMetering ( RASPICAM_METERING metering ) ;
  249. int convertFormat ( RASPICAM_FORMAT fmt ) ;
  250.  
  251.  
  252. //Color conversion
  253. void convertBGR2RGB(unsigned char * in_bgr,unsigned char * out_rgb,int size);
  254. float VIDEO_FRAME_RATE_NUM;
  255. RASPIVID_STATE State;
  256. MMAL_STATUS_T status;
  257. MMAL_PORT_T *camera_video_port;//,*camera_still_port
  258. PORT_USERDATA callback_data;
  259. bool _isOpened;
  260. bool _isCapturing;
  261.  
  262.  
  263. };
  264. };
  265. };
  266.  
  267. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement