buffer.cc
Go to the documentation of this file.
00001 /*
00002  * This file is part of the rc_genicam_api package.
00003  *
00004  * Copyright (c) 2017 Roboception GmbH
00005  * All rights reserved
00006  *
00007  * Author: Heiko Hirschmueller
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright notice,
00013  * this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  *
00019  * 3. Neither the name of the copyright holder nor the names of its contributors
00020  * may be used to endorse or promote products derived from this software without
00021  * specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 #include "buffer.h"
00037 #include "stream.h"
00038 
00039 #include "gentl_wrapper.h"
00040 #include "exception.h"
00041 
00042 namespace rcg
00043 {
00044 
00045 Buffer::Buffer(const std::shared_ptr<const GenTLWrapper> &_gentl, Stream *_parent)
00046 {
00047   parent=_parent;
00048   gentl=_gentl;
00049   buffer=0;
00050 }
00051 
00052 void Buffer::setHandle(void *handle)
00053 {
00054   buffer=handle;
00055 }
00056 
00057 namespace
00058 {
00059 
00060 template<class T> inline T getBufferValue(const std::shared_ptr<const GenTLWrapper> &gentl,
00061                                           void *stream, void *buffer, GenTL::BUFFER_INFO_CMD cmd)
00062 {
00063   T ret=0;
00064 
00065   GenTL::INFO_DATATYPE type;
00066   size_t size=sizeof(T);
00067 
00068   if (stream != 0 && buffer != 0)
00069   {
00070     gentl->DSGetBufferInfo(stream, buffer, cmd, &type, &ret, &size);
00071   }
00072 
00073   return ret;
00074 }
00075 
00076 inline bool getBufferBool(const std::shared_ptr<const GenTLWrapper> &gentl,
00077                           void *stream, void *buffer, GenTL::BUFFER_INFO_CMD cmd)
00078 {
00079   bool8_t ret=0;
00080 
00081   GenTL::INFO_DATATYPE type;
00082   size_t size=sizeof(ret);
00083 
00084   if (stream != 0 && buffer != 0)
00085   {
00086     gentl->DSGetBufferInfo(stream, buffer, cmd, &type, &ret, &size);
00087   }
00088 
00089   return ret != 0;
00090 }
00091 
00092 inline std::string getBufferString(const std::shared_ptr<const GenTLWrapper> &gentl,
00093                                    void *stream, void *buffer, GenTL::BUFFER_INFO_CMD cmd)
00094 {
00095   std::string ret;
00096 
00097   GenTL::INFO_DATATYPE type;
00098   char tmp[1024]="";
00099   size_t size=sizeof(tmp);
00100 
00101   if (stream != 0 && buffer != 0)
00102   {
00103     if (gentl->DSGetBufferInfo(stream, buffer, cmd, &type, &ret, &size) == GenTL::GC_ERR_SUCCESS)
00104     {
00105       if (type == GenTL::INFO_DATATYPE_STRING)
00106       {
00107         ret=tmp;
00108       }
00109     }
00110   }
00111 
00112   return ret;
00113 }
00114 
00115 }
00116 
00117 void *Buffer::getBase() const
00118 {
00119   return getBufferValue<void *>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_BASE);
00120 }
00121 
00122 size_t Buffer::getSize() const
00123 {
00124   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_SIZE);
00125 }
00126 
00127 void *Buffer::getUserPtr() const
00128 {
00129   return getBufferValue<void *>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_USER_PTR);
00130 }
00131 
00132 uint64_t Buffer::getTimestamp() const
00133 {
00134   return getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00135                                   GenTL::BUFFER_INFO_TIMESTAMP);
00136 }
00137 
00138 bool Buffer::getNewData() const
00139 {
00140   return getBufferBool(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_NEW_DATA);
00141 }
00142 
00143 bool Buffer::getIsQueued() const
00144 {
00145   return getBufferBool(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_IS_QUEUED);
00146 }
00147 
00148 bool Buffer::getIsAcquiring() const
00149 {
00150   return getBufferBool(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_IS_ACQUIRING);
00151 }
00152 
00153 bool Buffer::getIsIncomplete() const
00154 {
00155   return getBufferBool(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_IS_INCOMPLETE);
00156 }
00157 
00158 std::string Buffer::getTLType() const
00159 {
00160   return getBufferString(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_TLTYPE);
00161 }
00162 
00163 size_t Buffer::getSizeFilled() const
00164 {
00165   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer,
00166                                 GenTL::BUFFER_INFO_SIZE_FILLED);
00167 }
00168 
00169 size_t Buffer::getWidth() const
00170 {
00171   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_WIDTH);
00172 }
00173 
00174 size_t Buffer::getHeight() const
00175 {
00176   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_HEIGHT);
00177 }
00178 
00179 size_t Buffer::getXOffset() const
00180 {
00181   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_XOFFSET);
00182 }
00183 
00184 size_t Buffer::getYOffset() const
00185 {
00186   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_YOFFSET);
00187 }
00188 
00189 size_t Buffer::getXPadding() const
00190 {
00191   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_XPADDING);
00192 }
00193 
00194 size_t Buffer::getYPadding() const
00195 {
00196   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_YPADDING);
00197 }
00198 
00199 uint64_t Buffer::getFrameID() const
00200 {
00201   return getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_FRAMEID);
00202 }
00203 
00204 bool Buffer::getImagePresent() const
00205 {
00206   return getBufferBool(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_IMAGEPRESENT);
00207 }
00208 
00209 size_t Buffer::getImageOffset() const
00210 {
00211   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer,
00212                                 GenTL::BUFFER_INFO_IMAGEOFFSET);
00213 }
00214 
00215 size_t Buffer::getPayloadType() const
00216 {
00217   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer,
00218                                 GenTL::BUFFER_INFO_PAYLOADTYPE);
00219 }
00220 
00221 uint64_t Buffer::getPixelFormat() const
00222 {
00223   return getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00224                                   GenTL::BUFFER_INFO_PIXELFORMAT);
00225 }
00226 
00227 uint64_t Buffer::getPixelFormatNamespace() const
00228 {
00229   return getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00230                                   GenTL::BUFFER_INFO_PIXELFORMAT_NAMESPACE);
00231 }
00232 
00233 size_t Buffer::getDeliveredImageHeight() const
00234 {
00235   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer,
00236                                 GenTL::BUFFER_INFO_DELIVERED_IMAGEHEIGHT);
00237 }
00238 
00239 size_t Buffer::getDeliveredChunkPayloadSize() const
00240 {
00241   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer,
00242                                 GenTL::BUFFER_INFO_DELIVERED_CHUNKPAYLOADSIZE);
00243 }
00244 
00245 uint64_t Buffer::getChunkLayoutID() const
00246 {
00247   return getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00248                                   GenTL::BUFFER_INFO_CHUNKLAYOUTID);
00249 }
00250 
00251 std::string Buffer::getFilename() const
00252 {
00253   return getBufferString(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_FILENAME);
00254 }
00255 
00256 bool Buffer::isBigEndian() const
00257 {
00258   bool ret=false;
00259 
00260   GenTL::INFO_DATATYPE type;
00261   int32_t v;
00262   size_t size=sizeof(v);
00263   GenTL::GC_ERROR err=GenTL::GC_ERR_SUCCESS;
00264 
00265   if (parent->getHandle() != 0 && buffer != 0)
00266   {
00267     err=gentl->DSGetBufferInfo(parent->getHandle(), buffer, GenTL::BUFFER_INFO_PIXEL_ENDIANNESS,
00268                                &type, &v, &size);
00269 
00270     if (err == GenTL::GC_ERR_SUCCESS && type == GenTL::INFO_DATATYPE_INT32 &&
00271         v == GenTL::PIXELENDIANNESS_BIG)
00272     {
00273       ret=true;
00274     }
00275   }
00276 
00277   return ret;
00278 }
00279 
00280 size_t Buffer::getDataSize() const
00281 {
00282   return getBufferValue<size_t>(gentl, parent->getHandle(), buffer, GenTL::BUFFER_INFO_DATA_SIZE);
00283 }
00284 
00285 uint64_t Buffer::getTimestampNS() const
00286 {
00287   uint64_t ret=getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00288                                         GenTL::BUFFER_INFO_TIMESTAMP_NS);
00289 
00290   // if timestamp in nano seconds is not available, then compute it from
00291   // timestamp and device frequency
00292 
00293   if (ret == 0)
00294   {
00295     const uint64_t ns_freq=1000000000ul;
00296     uint64_t freq=parent->getParent()->getTimestampFrequency();
00297 
00298     if (freq == 0)
00299     {
00300       freq=ns_freq;
00301     }
00302 
00303     ret=getBufferValue<uint64_t>(gentl, parent->getHandle(), buffer,
00304                                  GenTL::BUFFER_INFO_TIMESTAMP);
00305 
00306     if (freq != ns_freq)
00307     {
00308       ret=ret/freq*ns_freq+(ns_freq*(ret%freq))/freq;
00309     }
00310   }
00311 
00312   return ret;
00313 }
00314 
00315 bool Buffer::getDataLargerThanBuffer() const
00316 {
00317   return getBufferBool(gentl, parent->getHandle(), buffer,
00318                        GenTL::BUFFER_INFO_DATA_LARGER_THAN_BUFFER);
00319 }
00320 
00321 bool Buffer::getContainsChunkdata() const
00322 {
00323   return getBufferBool(gentl, parent->getHandle(), buffer,
00324                        GenTL::BUFFER_INFO_CONTAINS_CHUNKDATA);
00325 }
00326 
00327 void *Buffer::getHandle() const
00328 {
00329   return buffer;
00330 }
00331 
00332 bool isHostBigEndian()
00333 {
00334   int p=1;
00335   char *c=reinterpret_cast<char *>(&p);
00336 
00337   if (c[0] == 1)
00338   {
00339     return false;
00340   }
00341 
00342   return true;
00343 }
00344 
00345 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01