libalvision  1.14
 All Classes Namespaces Files Functions Variables Macros Pages
alvideo.h
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef _LIBALVISION_ALVISION_ALVIDEO_H_
8 #define _LIBALVISION_ALVISION_ALVIDEO_H_
9 
10 
12 # include <alvision/alimage.h>
13 # include <iostream>
14 # include <fstream>
15 # include <vector>
16 
21 namespace AL
22 {
23  //structures for video raw stream recording
24  /*
25  * streamHeader
26  * @brief single stream header
27  */
28  struct streamHeader
29  {
30  unsigned int width : 32;
31  unsigned int height: 32;
32  unsigned int colorSpace : 32;
33  unsigned int pixelDepth : 32;
34  };
35 
36  /*
37  * videoHeader
38  * @brief multiple stream header global header with version field
39  */
40  struct videoHeader
41  {
42  unsigned int magicNumber : 32; // magic number
43  unsigned int userSpaceSize : 32;
44  unsigned int numberOfFrames : 32;
45  unsigned int numberOfStreams : 32;
46  };
47 
49  {
50  unsigned int width;
51  unsigned int height;
52  unsigned int resolution;
53  unsigned int colorSpace;
54  unsigned int nbLayers;
55  unsigned int pixelDepth;
56  unsigned int sizePerImage;
57  };
58 
59 
60  class ALVideo
61  {
62 
63  // .:: methods ::
64 
65  public:
66  ALVideo();
67  ~ALVideo();
68 
69  bool recordVideo(const std::string pFilePath, const unsigned int pUserSpaceSize, const std::vector<streamHeader>& pStreamHeaderVector);
70  bool readVideo(const std::string pFilePath);
71  void closeVideo();
72  bool goToFrame(const unsigned int pFrameNumber, const unsigned int pStreamNumber);
73  bool getFrame(ALImage & pImage, const unsigned int pFrameNumber, const unsigned int pStreamNumber, const bool pCheckFormat = true);
74  bool getNextFrame(ALImage & pImage, const bool pCheckFormat = true);
75  bool getPrecedingFrame(ALImage & pImage, const bool pCheckFormat = true);
76  bool write(char* ptrImageData, const int pSizeData, const long long pTimeStamp = 0, const char pCameraId = 0,
77  const float pLeftAngle = 0, const float pTopAngle = 0, const float pRightAngle = 0, const float pBottomAngle = 0);
78  bool write(int height, int width, char *imageData, const long long pTimeStamp, const char pCameraId,
79  const float pLeftAngle, const float pTopAngle, const float pRightAngle, const float pBottomAngle);
80  //deprecated
81  bool write(IplImage* pImage, const long long pTimeStamp = 0, const char pCameraId = 0,
82  const float pLeftAngle = 0, const float pTopAngle = 0, const float pRightAngle = 0, const float pBottomAngle = 0);
83 
84  inline const unsigned char* getMagicNumber() const { return (unsigned char*)&fMagicNumber; };
85  inline const unsigned int getNumberOfFrames() const { return fNumberOfFrames; };
86  inline const unsigned int getNumberOfStreams() const { return fNumberOfStreams; };
87  inline const unsigned int getCurrentFrameNumber() const { return fCurrentFrameNumber; };
88  inline const unsigned int getCurrentStreamNumber() const { return fCurrentStreamNumber; };
89  inline const bool isOpenForReading() const { return fIsOpenForReading; };
90  inline const bool isOpenForWriting() const { return fIsOpenForWriting; };
91 
92  inline const int getStreamWidth(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].width : -1; };
93  inline const int getStreamHeight(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].height : -1; };
94  inline const int getStreamResolution(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].resolution : -1; };
95  inline const int getStreamColorSpace(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].colorSpace : -1; };
96  inline const int getStreamNbLayers(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].nbLayers : -1; };
97  inline const int getStreamPixelDepth(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].pixelDepth : -1; };
98  inline const int getStreamSizePerImage(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].sizePerImage : -1; };
99 
100 
101  // .:: members ::
102 
103  private:
104  volatile bool fIsOpenForReading;
105  volatile bool fIsOpenForWriting;
106 
107  std::ifstream fVideoStreamIn;
108  std::ofstream fVideoStreamOut;
109  std::string fFilePath;
110 
111  unsigned int fMagicNumber;
112  unsigned int fUserSpaceSize;
113  unsigned int fNumberOfFrames;
114  unsigned int fNumberOfStreams;
115  unsigned int fSizeOfHeader;
116  unsigned int fSizePerMultiplexedFrame;
117  std::vector<struct streamProperties> fStreamPropertiesVector;
118 
119  unsigned int fCurrentStreamNumber;
120  unsigned int fCurrentFrameNumber;
121  };
122 }
123 
124 #endif // _LIBALVISION_ALVISION_ALVIDEO_H_