Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_ShmPMD.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 #include <string>
25 #include <sstream>
26 #include <iostream>
27 #include <sstream>
28 
29 #include <Image/Camera.hh>
30 #include <VideoSource/VideoSource_ShmPMD.hh>
31 
32 #ifdef WIN32
33 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
34 # include <windows.h>
35 #else
36 # include <sys/types.h>
37 # include <sys/mman.h>
38 #include <fcntl.h>
39 #endif
40 
41 
42 #include <Base/Common/BIASpragma.hh>
43 
44 
45 using namespace BIAS;
46 using namespace std;
47 
50 {}
51 
54 {}
55 
56 
58 {
59  bool gotit = false;
60  do {
61 
62  if (Header_->Time_ >LastTime_) {
63 // cout <<"VideoShmFeeder: Header is: "<<setw(20)<<setprecision(20)
64 // <<Header_->Time_<<" , "<<Header_->Size_<<endl;
66 
67  pImgBuffer_->str("");
68  if ((int)pImgBuffer_->rdbuf()->sputn(Data_,Header_->Size_) < (int) Header_->Size_) {
69  BIASERR("Could not write data to streambuffer!");
70  BIASABORT;
71  }
72  image.Release();
73  *pImgBuffer_>>image;
74  image.InvalidateUID();
75  image.SetTime(Header_->Time_);
77  DepthImg_.InvalidateUID();
78  DepthImg_.SetTime(Header_->Time_);
80  ModCoeffImg_.InvalidateUID();
81  ModCoeffImg_.SetTime(Header_->Time_);
83  gotit = true;
84 
85  //cout << "shm: cm: "<<boolalpha<< (image.GetColorModel()==ImageBase::CM_Bayer_RGGB)<<endl;
86  }
87  else biasusleep(1000);
88  } while (!gotit);
89  image.SetUID(UUID::GenerateUUID());
90  DepthImg_.SetUID(image.GetUID());
91  ModCoeffImg_.SetUID(image.GetUID());
92  return 0;
93 }
94 
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
This class implements a video streaming client using shared memory to receive images from another app...
const BIAS::UUID & GetUID() const
returns the UUID of the image
Definition: ImageBase.hh:449
BIAS::Camera< float > ModCoeffImg_
int Resize_(int newsize)
int GrabSingle(BIAS::Camera< unsigned char > &image)
ShmImageHeader * Header_
BIAS::Camera< float > DepthImg_
void InvalidateUID()
sets the image&#39;s uid to invalid
Definition: ImageBase.hh:597
void SetUID(const BIAS::UUID &id)
Definition: ImageBase.hh:589
std::stringstream * pImgBuffer_
static UUID GenerateUUID(const bool &consecutively=DEFAULT_UUID_CONSECUTIVELY)
static function which simply produces a uuid and returns
Definition: UUID.cpp:235