30 #include "VideoShMFeeder.hh"
31 #include <Base/Common/BIASpragma.hh>
46 MemoryLengthTotal_ = 0;
51 bIsInitialized_ =
false;
53 FileName_ =
"/VideoSource_Shm.shm";
55 FileName_ =
"VideoSource_Shm.shm";
69 MemoryLengthTotal_ = 0;
74 bIsInitialized_ =
false;
81 bIsInitialized_ =
false;
83 UnmapViewOfFile(Shm_);
84 CloseHandle(Mapping_ );
85 DeleteFile(FileName_.c_str());
87 shm_unlink(FileName_.c_str());
97 GetSystemInfo( &sSysInfo );
98 Granularity_ = sSysInfo.dwAllocationGranularity;
99 while(
long(MemoryLengthTotal_) > Granularity_ )
100 Granularity_ += sSysInfo.dwAllocationGranularity;
101 MemoryLengthTotal_ = Granularity_;
104 if( Mapping_ == NULL )
105 Mapping_ = OpenFileMapping( FILE_MAP_ALL_ACCESS,FALSE,FileName_.c_str());
109 HANDLE File_ = CreateFile(FileName_.c_str(),GENERIC_WRITE
111 FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,
112 FILE_ATTRIBUTE_TEMPORARY,NULL );
114 Mapping_= CreateFileMapping(File_,
119 Granularity_ + MemoryLengthTotal_,
122 if (Mapping_ == NULL) {
123 BIASERR(
"Failed to memory map file");
127 Shm_= (
unsigned char*)MapViewOfFile(Mapping_,FILE_MAP_ALL_ACCESS,0,0,0);
130 BIASERR(
"Failed to memory map file");
135 ShmContext_ = shm_open(FileName_.c_str(),O_RDWR,S_IRWXU| S_IRWXG| S_IRWXO);
136 if (ShmContext_ <0) {
138 ShmContext_ = shm_open(FileName_.c_str(),O_RDWR| O_CREAT,
139 S_IRWXU| S_IRWXG| S_IRWXO);
144 if (ShmContext_ <0) {
145 BIASERR(
"Unable to create VideoSource_Shm.shm");
149 res = ftruncate(ShmContext_, MemoryLengthTotal_);
151 perror(FileName_.c_str());
155 Shm_ = mmap(0,MemoryLengthTotal_, PROT_WRITE,MAP_SHARED, ShmContext_, 0 );
156 if (Shm_ == MAP_FAILED) {
157 BIASERR(
"Unable to create memory-mapping!!!");
165 Header_->AxisX_ = Header_->AxisY_ = Header_->AxisZ_ = Header_->Angle_ = 0;
166 Header_->C1_ = Header_->C2_ = Header_->C3_ = 0;
171 bIsInitialized_ =
true;
185 int size = ImgBuffer_.str().length();
186 if (!bIsInitialized_) {
190 BIASASSERT(size <=DataLength_);
192 Header_->Size_ = DataLength_;
194 memcpy(Data_,ImgBuffer_.str().c_str() ,Header_->Size_);
196 Header_->Time_ = Image->GetTime();
199 (Image->GetR()).GetRotationAxisAngle(tmpVec, Header_->Angle_);
200 Header_->AxisX_ = tmpVec[0];
201 Header_->AxisY_ = tmpVec[1];
202 Header_->AxisZ_ = tmpVec[2];
203 tmpVec = Image->GetC();
204 Header_->C1_ = tmpVec[0];
205 Header_->C2_ = tmpVec[1];
206 Header_->C3_ = tmpVec[2];
class BIASImageBase_EXPORT Image
bool ProcessImage(BIAS::Camera< unsigned char > *Image)
The image template class for specific storage types.