00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00291
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 }