ChunkParser.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2006-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Lutz Koschorreck
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Low Level API: Definition of the IChunkParser interface.
  10. */
  11. #pragma once
  12. #ifndef CHUNKPARSER_H__
  13. #define CHUNKPARSER_H__
  14. #include <pylon/Platform.h>
  15. #ifdef _MSC_VER
  16. # pragma pack(push, PYLON_PACKING)
  17. #endif /* _MSC_VER */
  18. #include <GenICamFwd.h>
  19. #include <pylon/stdinclude.h>
  20. #include <pylon/PylonBase.h>
  21. // additional forwards
  22. namespace GENAPI_NAMESPACE
  23. {
  24. class CChunkAdapter;
  25. struct AttachStatistics_t;
  26. }
  27. namespace Pylon
  28. {
  29. /*! \interface IChunkParser
  30. \brief Low Level API: The interface for chunk parsers analyzing a data stream consisting of chunks
  31. When chunk data is enabled in the camera the stream sends additional data along with
  32. the image. This data needs to be extracted with help of a chunk parser.
  33. These are created using the camera's member function IPylonDevice::CreateChunkParser().
  34. When an image buffer containing chunked data is passed to a chunk parser,
  35. the camera's chunk related parameters are updated. After changing the data
  36. layout either by changing the AOI or enabling/disabling chunk features the
  37. parser needs to be reinitialized by calling IChunkParser::AttachBuffer().
  38. Thereafter buffers with the same layout are processed with the
  39. IChunkParser::UpdateBuffer() method. Chunk related properties remain unchanged
  40. until a new buffer is passed in.
  41. After usage return the chunk parser with a call of the camera's
  42. IPylonDevice::DestroyChunkParser() member function.
  43. The code snippet below demonstrates the usage of a chunk parser. A
  44. complete program is found in the sample AcquireSingleFrame_ChunkImage.
  45. \note Check the payload type of the GrabResult_t before attaching or
  46. updating the buffer.
  47. \ingroup Pylon_LowLevelApi
  48. \code
  49. IChunkParser &ChunkParser = *Camera.CreateChunkParser();
  50. // enable Frame Counter chunk
  51. Camera.ChunkModeActive.SetValue( true );
  52. Camera.ChunkSelector.SetValue( ChunkSelector_Framecounter );
  53. Camera.ChunkEnable.SetValue( true );
  54. // retrieve data from the chunk
  55. GrabResult Result;
  56. if (StreamGrabber.RetrieveResult( Result ) &&
  57. Result.Succeeded() &&
  58. Result.PayloadType() == PayloadType_ChunkData)
  59. {
  60. ChunkParser.AttachBuffer( Result.Buffer(), Result.GetPayloadSize() );
  61. int64_t frameCounter = Camera.ChunkFramecounter.GetValue();
  62. }
  63. \endcode
  64. */
  65. interface PUBLIC_INTERFACE IChunkParser
  66. {
  67. public:
  68. /// Pass in a buffer and let the chunk parser analyze it.
  69. /*! Corresponding parameters of the camera object reflecting the chunked data
  70. will be updated.
  71. \param pBuffer Pointer to the new buffer
  72. \param BufferLength Size of the new buffer in bytes
  73. \param pAttachStatistics (optional) Pointer to a record taking statistic
  74. data of the analyzed buffer
  75. */
  76. virtual void AttachBuffer( const void* pBuffer, int64_t BufferLength, GenApi::AttachStatistics_t* pAttachStatistics = NULL ) = 0;
  77. /// \brief Detaches a buffer from the chunk parser. The buffer will no longer accessed by the chunk parser
  78. /*!
  79. // An attached buffer must be detached before freeing it. When attaching a new buffer, the previous
  80. // one gets detached automatically.
  81. */
  82. virtual void DetachBuffer() = 0;
  83. /// \brief Pass in a buffer and let the chunk parser update the camera object's parameters.
  84. /*!
  85. This method can be used when the layout of the chunk data hasn't changed since a previous buffer
  86. has been attached to the chunk parser. In this case UpdateBuffer is slightly faster than AttachBuffer,
  87. because the buffer's layout is reused.
  88. If you call UpdateBuffer without having called AttachBuffer first, a LogicalErrorException is raised.
  89. \param pBaseAddress Pointer to the new buffer
  90. */
  91. virtual void UpdateBuffer( const void* pBaseAddress ) = 0;
  92. /// Checks if buffer has a CRC attached
  93. /*!
  94. \return true if the buffer contains CRC value.
  95. */
  96. virtual bool HasCRC() const = 0;
  97. /// Checks CRC sum of buffer
  98. /*!
  99. \return true if the contained CRC equals the computed value.
  100. */
  101. virtual bool CheckCRC() const = 0;
  102. };
  103. /*!
  104. \interface ISelfReliantChunkParser
  105. \brief Low Level API: Interface for chunk parsers with an own chunk data node map attached.
  106. This type of chunk parser updates the an own node map containing
  107. only the chunk data nodes instead of updating the devices node map.
  108. This is useful for attaching the chunk data to a grab result.
  109. \ingroup Pylon_LowLevelApi
  110. */
  111. interface ISelfReliantChunkParser : public IChunkParser
  112. {
  113. /// Provides access to the chunk data node map that the parser updates.
  114. /*!
  115. \return The chunk data node map of the parser
  116. */
  117. virtual GenApi::INodeMap* GetChunkDataNodeMap() = 0;
  118. /// Makes the object to destroy itself.
  119. /*!
  120. This is an alternative to destroying it via the IPylonDevice interface.
  121. It is used when the device has been destroyed already.
  122. */
  123. virtual void Destroy() = 0;
  124. };
  125. /// Low Level API: Base class for chunk parsers returned by camera objects
  126. /*!
  127. Part implementation of chunk parser of common functionality.
  128. \ingroup Pylon_LowLevelApi
  129. */
  130. class PYLONBASE_API CChunkParser : public ISelfReliantChunkParser
  131. {
  132. public:
  133. // \name IChunkParser implementation
  134. // \{
  135. void AttachBuffer( const void* pBuffer, int64_t BufferLength, GenApi::AttachStatistics_t* pAttachStatistics = NULL );
  136. void DetachBuffer();
  137. void UpdateBuffer( const void* pBaseAddress );
  138. GenApi::INodeMap* GetChunkDataNodeMap();
  139. void Destroy();
  140. // \}
  141. protected:
  142. /// default constructor - make it protected to prevent this class from instantiation
  143. explicit CChunkParser( GenApi::CChunkAdapter* pParser );
  144. /// destructor
  145. virtual ~CChunkParser();
  146. protected:
  147. /// Pointer to the GenApi workhorse.
  148. GenApi::CChunkAdapter* m_pParser;
  149. class PYLONBASE_API CBuffer
  150. {
  151. public:
  152. CBuffer( const void* pBuffer, int64_t BufferSize_by );
  153. ~CBuffer();
  154. operator bool() const;
  155. int64_t GetSize() const;
  156. const void* operator&() const;
  157. private:
  158. const void* m_pBuffer;
  159. int64_t m_BufferLength_by;
  160. } m_AttachedBuffer;
  161. bool m_IsBufferAttached;
  162. };
  163. }
  164. #ifdef _MSC_VER
  165. # pragma pack(pop)
  166. #endif /* _MSC_VER */
  167. #endif // __CHUNKPARSER_H__