Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Shm.hh
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 #ifndef __BIASVIDEOSOURCE_SHM_HH__
25 #define __BIASVIDEOSOURCE_SHM_HH__
26 
27 
28 
29 #include <iostream>
30 #include <sstream>
31 #include <VideoSource/VideoSource_Base.hh>
32 #include <Geometry/RMatrix.hh>
33 
34 #ifdef WIN32
35 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
36 # include <windows.h>
37 # ifdef BIAS_HAVE_WXWIDGETS
38 # include <wx/msw/winundef.h>
39 # endif
40 #endif
41 
42 
43 namespace BIAS{
44 
45 
46 
47  /**
48  \class VideoSource_Shm
49  \ingroup g_videosource
50  \author evers
51  \brief This class implements a video streaming client using shared memory to receive images from another application.
52  */
53  class BIASVideoSource_EXPORT VideoSource_Shm : public VideoSource {
54 
55  public:
56  struct ShmImageHeader {
57  //transmission size
58  unsigned int Size_;
59  //images timestamp
60  double Time_;
61  //images rotation matrix
62  double AxisX_, AxisY_, AxisZ_, Angle_;
63  //images CVector
64  double C1_,C2_,C3_;
65  };
66 
67  /**
68  @author Jan-Friso Evers
69  **/
71  ~VideoSource_Shm();
72 
73  int OpenDevice(const char *name);
74 
75  int OpenDevice();
76 
77  int PreGrab();
78  int GrabSingle(BIAS::Camera <unsigned char> &image);
79  int PostGrab();
80 
81  void SetSize(int w, int h, int bytesperpixel);
82 
83  /**
84  In blocking-mode each call to GrabSingle waits for a NEW (evaluated
85  via images timestamp) image to arrive in shm. That means the program
86  will block until a new image is available (!this is standard!).
87 
88  In nonblocking-mode allways the last received image will be returned!
89  The program won't block in GrabSingle-calls.
90  **/
91  inline void SetBlockingMode(bool block) {bSync_ = block;}
92 
93  int CloseDevice();
94 
95  protected:
96  int Resize_(int newsize);
97 #ifdef WIN32
98  HANDLE Context_; // _hFile
99  HANDLE Mapping_;//! header describing the memory layout
100  long int Granularity_;
101 #else
102  int Context_;
103 #endif
104 
106  bool bSync_;
107  std::string FileName_;
108  void *Shm_;
109  unsigned int DataLength_;
110  unsigned int TotalLength_;
111  std::stringstream *pImgBuffer_; // pointer needed to free mem
113  char *Data_;
114  double LastTime_;
115 
116  protected:
117  /*!\brief prohibit default function (move to 'public' if needed) */
118  VideoSource_Shm(const VideoSource_Shm &source);
119  /*!\brief prohibit default function (move to 'public' if needed) */
120  VideoSource_Shm& operator =(const VideoSource_Shm &source);
121 
122 
123  };
124 
125 
126 } // namespace MIP
127 
128 #endif
Defines a common interface to different devices.
This class implements a video streaming client using shared memory to receive images from another app...
void SetBlockingMode(bool block)
In blocking-mode each call to GrabSingle waits for a NEW (evaluated via images timestamp) image to ar...
ShmImageHeader * Header_
std::stringstream * pImgBuffer_