StreamGrabber.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2006-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Hartmut Nebelung
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Low Level API: Definition of IStreamGrabber interface
  10. \attention
  11. The Low Level API has been deprecated in pylon 6.0. It is recommended
  12. to use the Instant Camera classes instead.
  13. */
  14. #ifndef __ISTREAMGRABBER_H__
  15. #define __ISTREAMGRABBER_H__
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif //_MSC_VER > 1000
  19. #include <pylon/Platform.h>
  20. #ifdef _MSC_VER
  21. # pragma pack(push, PYLON_PACKING)
  22. #endif /* _MSC_VER */
  23. #include <GenICamFwd.h>
  24. #include <pylon/stdinclude.h>
  25. namespace Pylon
  26. {
  27. /*!
  28. \ingroup Pylon_LowLevelApi
  29. \brief Used to configure how starting and stopping of streaming are handled.
  30. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  31. */
  32. class GrabResult;
  33. class WaitObject;
  34. /// This opaque type represents a registered buffer.
  35. typedef void* StreamBufferHandle;
  36. // -------------------------------------------------------------------------
  37. // interface IStreamGrabber
  38. // -------------------------------------------------------------------------
  39. /*!
  40. \ingroup Pylon_LowLevelApi
  41. \interface IStreamGrabber
  42. \brief Low Level API: Interface to an (input) data stream
  43. \attention
  44. The Low Level API has been deprecated in pylon 6.0. It is recommended
  45. to use the Instant Camera classes instead.
  46. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  47. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  48. */
  49. interface IStreamGrabber
  50. {
  51. /*!
  52. \brief Opens the stream grabber.
  53. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  54. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  55. \pre
  56. <ul>
  57. <li> The corresponding device is open.
  58. <li> The stream grabber is closed.
  59. </ul>
  60. \post
  61. <ul>
  62. <li> The stream grabber is open.
  63. <li> If the device is closed while the stream grabber is open, the stream grabber is closed automatically.
  64. </ul>
  65. \threading
  66. This method is synchronized using an internal stream grabber lock.
  67. \error
  68. <ul>
  69. <li> Throws a LogicalErrorException if the stream grabber is already open or prepared. The stream grabber remains in the same state after raising the exception in this case.
  70. <li> Throws an exception if the stream grabber is closed and opening the stream grabber fails. The stream grabber remains closed after raising the exception.
  71. </ul>
  72. */
  73. virtual void Open() = 0;
  74. /*!
  75. \brief Closes the stream grabber.
  76. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  77. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  78. This method calls FinishGrab() automatically if needed.
  79. \post
  80. <ul>
  81. <li> Any running grab has been stopped by calling FinishGrab().
  82. <li> The stream grabber is closed.
  83. <li> All results waiting in the output queue are discarded.
  84. </ul>
  85. \threading
  86. This method is synchronized using an internal stream grabber lock.
  87. \error
  88. Does not throw C++ exceptions.
  89. */
  90. virtual void Close() = 0;
  91. /*!
  92. \brief Retrieve whether the stream grabber is open.
  93. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  94. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  95. \return Returns true if the stream grabber is open.
  96. \threading
  97. This method can be synchronized using an internal stream grabber lock.
  98. \error
  99. Does not throw C++ exceptions.
  100. */
  101. virtual bool IsOpen() const = 0;
  102. /*!
  103. \brief Registers a buffer for subsequent use.
  104. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  105. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  106. \param[in] pBuffer The pointer of the buffer that is to be used for grabbing e.g., for grabbing images.
  107. \param[in] bufferSize The size of the provided buffer in bytes.
  108. \return Returns a handle for the registered buffer that can be used in subsequent calls.
  109. \pre
  110. <ul>
  111. <li> pBuffer must not be NULL.
  112. <li> The buffer size must not exceed the value of the node map integer parameter MaxBufferSize specified when PrepareGrab was called.
  113. <li> Less buffers are already registered than value of the node map integer parameter MaxNumBuffer specified when PrepareGrab was called.
  114. <li> The stream grabber is prepared, see PrepareGrab().
  115. <li> The buffer has not been registered already.
  116. </ul>
  117. \post
  118. <ul>
  119. <li> The buffer is registered.
  120. <li> Transport Layer specific preparations have been executed e.g., locking the memory pages of the buffer.
  121. <li> The buffer must not be freed while being registered.
  122. <li> If the stream grabber requires the additional streaming state, streaming must not be started, see IsStartAndStopStreamingMandatory() and StartStreamingIfMandatory().
  123. </ul>
  124. \threading
  125. This method can be synchronized using an internal stream grabber lock.
  126. \error
  127. <ul>
  128. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  129. <li> Throws an exception if registering the buffer fails. The buffer is not registered after raising an exception.
  130. </ul>
  131. */
  132. virtual StreamBufferHandle RegisterBuffer( void* pBuffer, size_t bufferSize ) = 0;
  133. /*!
  134. \brief Deregisters the buffer.
  135. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  136. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  137. \param[in] hStreamBuffer The handle of a buffer that has been provided by RegisterBuffer()
  138. \return Returns the pointer of the corresponding buffer.
  139. \pre
  140. <ul>
  141. <li> The buffer is registered.
  142. <li> The buffer is not queued. Either it has not been queued yet, see QueueBuffer(), or it has been retrieved after grabbing using RetrieveResult().
  143. <li> FinishGrab() or Close() have not been called for the grab session yet.
  144. <li> If the stream grabber requires the additional streaming state, streaming must not be started, see IsStartAndStopStreamingMandatory() and StartStreamingIfMandatory().
  145. </ul>
  146. \post
  147. <ul>
  148. <li> Transport layer-specific preparations have been reversed.
  149. <li> The buffer is deregistered.
  150. <li> The buffer can be freed if needed e.g., by calling delete.
  151. </ul>
  152. \error
  153. Throws an exception if deregistering the buffer fails.
  154. */
  155. virtual const void* DeregisterBuffer( StreamBufferHandle hStreamBuffer ) = 0;
  156. /*!
  157. \brief Prepares grabbing
  158. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  159. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  160. \note pylon uses a pool of buffers with a fixed amount of buffers to grab images. This is required because certain
  161. preparations e.g., locking the buffer's memory pages, must be made by the driver to be able to grab images into a buffer.
  162. Thus, using a pool of buffers is much more efficient than allocating a new buffer for every grabbed image.
  163. The node map integer parameters MaxBufferSize and MaxNumBuffer need to be set before calling PrepareGrab().
  164. MaxNumBuffer should be set to the number of buffers you plan to use for grabbing.
  165. \note There can be limitations depending on the transport layer technology used when using a large amount of buffers.
  166. MaxBufferSize needs to be set according to the PayloadSize parameter of the camera device or the stream grabber.
  167. If the stream grabber provides a PayloadSize parameter, the MaxBufferSize must be at least the size reported
  168. by the stream grabber payload size. This is the case if for instance a frame grabber or additional preprocessing
  169. is used.
  170. If the stream grabber does not provide a PayloadSize parameter, the MaxBufferSize must be at least the size reported
  171. by the camera device PayloadSize parameter.
  172. \pre
  173. <ul>
  174. <li> The node map integer parameter MaxBufferSize is set, see GetNodeNap().
  175. <li> The node map integer parameter MaxNumBuffer is set, see GetNodeNap().
  176. <li> The stream grabber is open.
  177. <li> No grab session is currently in progress.
  178. </ul>
  179. \post
  180. <ul>
  181. <li> Resources required for grabbing are allocated.
  182. <li> The camera is set up for grabbing.
  183. <li> Critical camera parameters, provided by IPylonDevice::GetNodeMap(), are locked.
  184. <li> The stream grabber is prepared.
  185. </ul>
  186. \threading
  187. This method is synchronized using an internal stream grabber lock.
  188. \error
  189. <ul>
  190. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  191. <li> Throws an exception if preparing the stream grabber fails. The stream grabber is not prepared after raising the exception.
  192. </ul>
  193. */
  194. virtual void PrepareGrab() = 0;
  195. /*!
  196. \brief Returns true if the Stream Grabber requires calling StartStreamingIfMandatory() for operation.
  197. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  198. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  199. \threading
  200. This method is synchronized using an internal stream grabber lock.
  201. \error
  202. Does not throw C++ exceptions.
  203. */
  204. virtual bool IsStartAndStopStreamingMandatory() = 0;
  205. /*!
  206. \brief Starts streaming for the stream grabber if this is mandatory for operation.
  207. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  208. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  209. Some stream grabbers e.g., some stream grabbers based on GenTL, have limitations on when buffers can
  210. be registered. For these stream grabbers it is mandatory to register all buffers first and
  211. call StartStreamingIfMandatory() aftwards.
  212. Between the StartStreamingIfMandatory() and StopStreamingIfMandatory() calls no buffers can be
  213. registered or deregistered if such a limitation exists.
  214. \note This method has been added in pylon 6.0 for supporting CoaXPress. Prior implementations
  215. of pylon stream grabbers did not require calling start and stop streaming.
  216. The IsStartAndStopStreamingMandatory(), StartStreamingIfMandatory(), and StopStreamingIfMandatory()
  217. methods allow backward-compatible operation.
  218. \pre
  219. <ul>
  220. <li> The stream grabber is prepared.
  221. </ul>
  222. \post
  223. <ul>
  224. <li> If the stream grabber does not require StartStreamingIfMandatory(), nothing is done.
  225. <li> Streaming is started. For GenTL-based stream grabbers DSStartAcquistion is called
  226. </ul>
  227. \threading
  228. This method is synchronized using an internal stream grabber lock.
  229. \error
  230. <ul>
  231. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  232. <li> Throws an exception if start streaming fails. The stream grabber is not streaming after raising the exception.
  233. </ul>
  234. */
  235. virtual void StartStreamingIfMandatory() = 0;
  236. /*!
  237. \brief Stops streaming for the stream grabber if this is mandatory for operation.
  238. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  239. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  240. Some stream grabbers e.g., some stream grabbers based on GenTL, have limitations on when buffers can
  241. be registered. For these stream grabbers it is mandatory to call StopStreamingIfMandatory to be able to deregister buffer afterwards.
  242. \pre
  243. <ul>
  244. <li> The stream grabber is in streaming mode if start and stop streaming is mandatory.
  245. </ul>
  246. \post
  247. <ul>
  248. <li> If the stream grabber does not require StopStreamingIfMandatory(), nothing is done.
  249. <li> Streaming is stopped. For GenTL-based stream grabbers DSStopAcquistion is called.
  250. </ul>
  251. \threading
  252. This method is synchronized using an internal stream grabber lock.
  253. \error
  254. <ul>
  255. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  256. <li> Throws an exception if stop streaming fails. The stream grabber is not streaming after raising the exception.
  257. </ul>
  258. */
  259. virtual void StopStreamingIfMandatory() = 0;
  260. /*!
  261. \brief Stops grabbing finally
  262. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  263. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  264. This method calls FlushBuffersToOutput() automatically if needed.
  265. \pre
  266. <ul>
  267. <li> The stream grabber is prepared.
  268. </ul>
  269. \post
  270. <ul>
  271. <li> Resources required for grabbing are freed.
  272. <li> The camera is not set up for grabbing anymore
  273. <li> Critical camera parameters, provided by IPylonDevice::GetNodeMap(), are unlocked.
  274. <li> The stream grabber is open.
  275. <li> Queued buffers are available in the output queue of the stream grabber and can be retrieved calling RetrieveResult().
  276. <li> All buffers are deregistered.
  277. </ul>
  278. \threading
  279. This method is synchronized using an internal stream grabber lock.
  280. \error
  281. <ul>
  282. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  283. <li> Throws an exception if finishing the grab fails. The stream grabber is in open state after raising the exception.
  284. </ul>
  285. */
  286. virtual void FinishGrab() = 0;
  287. /*!
  288. \brief Enqueues a buffer in the input queue.
  289. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  290. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  291. \param[in] hStreamBuffer The handle of a buffer that has been provided by RegisterBuffer().
  292. \param[in] pContext A user-provided pointer passed along with buffer in the internal input and output queues.
  293. \pre
  294. <ul>
  295. <li> The buffer is registered, see RegisterBuffer().
  296. <li> The stream grabber is prepared.
  297. <li> The buffer has not been queued for grabbing yet.
  298. <li> The buffer is not waiting in the output queue of the stream grabber. The buffer can be queued again after it has been retrieved using RetrieveResult().
  299. </ul>
  300. \post
  301. <ul>
  302. <li> The buffer is queued to input queue of the stream grabber.
  303. <li> The buffer cannot be deregistered until it has been retrieved using RetrieveResult().
  304. </ul>
  305. \threading
  306. This method is synchronized using an internal stream grabber lock.
  307. \error
  308. <ul>
  309. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  310. <li> Throws an exception if queuing the buffer fails.
  311. </ul>
  312. */
  313. virtual void QueueBuffer( StreamBufferHandle hStreamBuffer, const void* pContext = NULL ) = 0;
  314. /*!
  315. \brief Cancels grabbing the current buffer and flushes all buffers to the output queue.
  316. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  317. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  318. \pre
  319. <ul>
  320. <li> The stream grabber is prepared.
  321. </ul>
  322. \post
  323. <ul>
  324. <li> All queued buffers are placed in the output queue of the stream grabber and can be retrieved using RetrieveResult().
  325. <li> Buffers that have not been grabbed completely before calling FlushBuffersToOutput are marked with the EGrabStatus Canceled.
  326. <li> The stream grabber is prepared.
  327. <li> Buffers can be queued again to continue grabbing.
  328. </ul>
  329. \threading
  330. This method is synchronized using an internal stream grabber lock.
  331. \error
  332. <ul>
  333. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  334. <li> Throws an exception if canceling the grab fails.
  335. </ul>
  336. */
  337. virtual void FlushBuffersToOutput() = 0;
  338. ///This method has been renamed to FlushBuffersToOutput(). Calling CancelGrab calls FlushBuffersToOutput();
  339. virtual void CancelGrab() = 0;
  340. /*!
  341. \brief Retrieves one grab result from the output queue.
  342. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  343. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  344. param[out] grabResult The object the grab result data is returned in if true is returned. The \c grabResult remains unchanged if false is returned.
  345. \return Returns true when result was available.
  346. \pre
  347. <ul>
  348. <li> The stream grabber is open.
  349. </ul>
  350. \post
  351. <ul>
  352. <li> If a grab result was available, it has been removed from the ouput queue.
  353. <li> The corresponding buffer can be queued again for grabbing.
  354. </ul>
  355. \threading
  356. This method is synchronized using an internal stream grabber lock.
  357. \error
  358. <ul>
  359. <li> Throws a LogicalErrorException if the stream grabber state does not match the preconditions.
  360. <li> Throws an exception if retrieving the result fails. This does not change the stream grabber state.
  361. </ul>
  362. */
  363. virtual bool RetrieveResult( GrabResult& grabResult ) = 0;
  364. /*!
  365. \brief Returns the result event object of the stream grabber.
  366. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  367. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  368. This object is associated with the output queue of the stream grabber.
  369. The event is signaled when output queue is non-empty.
  370. \return Returns the result event object of the stream grabber.
  371. \threading
  372. This method can be synchronized using an internal stream grabber lock.
  373. \error
  374. Does not throw C++ exceptions.
  375. */
  376. virtual WaitObject& GetWaitObject() const = 0;
  377. /*!
  378. \brief Returns the associated stream grabber parameters.
  379. \note Basler recommends using one of the Instant Camera classes CBaslerUniversalInstantCamera or CInstantCamera for new projects.
  380. If you want to control which buffers are used for grabbing, you can use the Pylon::IBufferFactory.
  381. \return Returns the associated stream grabber parameters. The returned pointer is never NULL.
  382. \threading
  383. This method can be synchronized using an internal stream grabber lock.
  384. \error
  385. Does not throw C++ exceptions.
  386. */
  387. virtual GenApi::INodeMap* GetNodeMap() = 0;
  388. };
  389. }
  390. #ifdef _MSC_VER
  391. # pragma pack(pop)
  392. #endif /* _MSC_VER */
  393. #endif //__ISTREAMGRABBER_H__