libalvision  2.4.3.28-r2
 All Classes Namespaces Files Functions Variables Friends 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 
81  inline const unsigned char* getMagicNumber() const { return (unsigned char*)&fMagicNumber; };
82  inline unsigned int getNumberOfFrames() const { return fNumberOfFrames; };
83  inline unsigned int getNumberOfStreams() const { return fNumberOfStreams; };
84  inline unsigned int getCurrentFrameNumber() const { return fCurrentFrameNumber; };
85  inline unsigned int getCurrentStreamNumber() const { return fCurrentStreamNumber; };
86  inline bool isOpenForReading() const { return fIsOpenForReading; };
87  inline bool isOpenForWriting() const { return fIsOpenForWriting; };
88 
89  inline int getStreamWidth(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].width : -1; };
90  inline int getStreamHeight(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].height : -1; };
91  inline int getStreamResolution(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].resolution : -1; };
92  inline int getStreamColorSpace(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].colorSpace : -1; };
93  inline int getStreamNbLayers(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].nbLayers : -1; };
94  inline int getStreamPixelDepth(const unsigned int pStreamNumber) const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].pixelDepth : -1; };
95  inline int getStreamSizePerImage(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].sizePerImage : -1; };
96 
97 
98  // .:: members ::
99 
100  private:
101  volatile bool fIsOpenForReading;
102  volatile bool fIsOpenForWriting;
103 
104  std::ifstream fVideoStreamIn;
105  std::ofstream fVideoStreamOut;
106  std::string fFilePath;
107 
108  unsigned int fMagicNumber;
109  unsigned int fUserSpaceSize;
110  unsigned int fNumberOfFrames;
111  unsigned int fNumberOfStreams;
112  unsigned int fSizeOfHeader;
113  unsigned int fSizePerMultiplexedFrame;
114  std::vector<struct streamProperties> fStreamPropertiesVector;
115 
116  unsigned int fCurrentStreamNumber;
117  unsigned int fCurrentFrameNumber;
118  };
119 }
120 
121 #endif // _LIBALVISION_ALVISION_ALVIDEO_H_
unsigned int numberOfStreams
Definition: alvideo.h:45
bool getNextFrame(ALImage &pImage, const bool pCheckFormat=true)
unsigned int sizePerImage
Definition: alvideo.h:56
bool recordVideo(const std::string pFilePath, const unsigned int pUserSpaceSize, const std::vector< streamHeader > &pStreamHeaderVector)
unsigned int numberOfFrames
Definition: alvideo.h:44
int getStreamPixelDepth(const unsigned int pStreamNumber) const
Definition: alvideo.h:94
unsigned int userSpaceSize
Definition: alvideo.h:43
unsigned int getCurrentStreamNumber() const
Definition: alvideo.h:85
vision defines
unsigned int height
Definition: alvideo.h:51
unsigned int pixelDepth
Definition: alvideo.h:33
int getStreamHeight(const unsigned int pStreamNumber) const
Definition: alvideo.h:90
void closeVideo()
unsigned int getNumberOfStreams() const
Definition: alvideo.h:83
unsigned int colorSpace
Definition: alvideo.h:32
int getStreamWidth(const unsigned int pStreamNumber) const
Definition: alvideo.h:89
unsigned int pixelDepth
Definition: alvideo.h:55
bool write(char *ptrImageData, const int pSizeData, const long long pTimeStamp=0, const char pCameraId=0, const float pLeftAngle=0, const float pTopAngle=0, const float pRightAngle=0, const float pBottomAngle=0)
unsigned int width
Definition: alvideo.h:50
int getStreamSizePerImage(const unsigned int pStreamNumber) const
Definition: alvideo.h:95
int getStreamResolution(const unsigned int pStreamNumber) const
Definition: alvideo.h:91
unsigned int colorSpace
Definition: alvideo.h:53
handle image
unsigned int height
Definition: alvideo.h:31
bool isOpenForWriting() const
Definition: alvideo.h:87
bool getPrecedingFrame(ALImage &pImage, const bool pCheckFormat=true)
unsigned int getNumberOfFrames() const
Definition: alvideo.h:82
unsigned int width
Definition: alvideo.h:30
unsigned int resolution
Definition: alvideo.h:52
int getStreamNbLayers(const unsigned int pStreamNumber) const
Definition: alvideo.h:93
unsigned int nbLayers
Definition: alvideo.h:54
int getStreamColorSpace(const unsigned int pStreamNumber) const
Definition: alvideo.h:92
bool goToFrame(const unsigned int pFrameNumber, const unsigned int pStreamNumber)
bool readVideo(const std::string pFilePath)
unsigned int magicNumber
Definition: alvideo.h:42
unsigned int getCurrentFrameNumber() const
Definition: alvideo.h:84
bool isOpenForReading() const
Definition: alvideo.h:86
const unsigned char * getMagicNumber() const
Definition: alvideo.h:81
bool getFrame(ALImage &pImage, const unsigned int pFrameNumber, const unsigned int pStreamNumber, const bool pCheckFormat=true)