libalvision  1.14.5
alvision/alvideo.h
Go to the documentation of this file.
00001 
00006 #pragma once
00007 #ifndef _LIBALVISION_ALVISION_ALVIDEO_H_
00008 #define _LIBALVISION_ALVISION_ALVIDEO_H_
00009 
00010 
00011 # include <alvision/alvisiondefinitions.h>
00012 # include <alvision/alimage.h>
00013 # include <iostream>
00014 # include <fstream>
00015 # include <vector>
00016 
00021 namespace AL
00022 {
00023   //structures for video raw stream recording
00024   /*
00025    * streamHeader
00026    * @brief single stream header
00027    */
00028   struct streamHeader
00029   {
00030     unsigned int width : 32;
00031     unsigned int height: 32;
00032     unsigned int colorSpace : 32;
00033     unsigned int pixelDepth : 32;
00034   };
00035 
00036   /*
00037    * videoHeader
00038    * @brief multiple stream header global header with version field
00039    */
00040   struct videoHeader
00041   {
00042     unsigned int magicNumber : 32;  // magic number
00043     unsigned int userSpaceSize : 32;
00044     unsigned int numberOfFrames : 32;
00045     unsigned int numberOfStreams : 32;
00046   };
00047 
00048   struct streamProperties
00049   {
00050     unsigned int width;
00051     unsigned int height;
00052     unsigned int resolution;
00053     unsigned int colorSpace;
00054     unsigned int nbLayers;
00055     unsigned int pixelDepth;
00056     unsigned int sizePerImage;
00057   };
00058 
00059 
00060   class ALVideo
00061   {
00062 
00063   // .:: methods ::
00064 
00065   public:
00066     ALVideo();
00067     ~ALVideo();
00068 
00069     bool recordVideo(const std::string pFilePath, const unsigned int pUserSpaceSize, const std::vector<streamHeader>& pStreamHeaderVector);
00070     bool readVideo(const std::string pFilePath);
00071     void closeVideo();
00072     bool goToFrame(const unsigned int pFrameNumber, const unsigned int pStreamNumber);
00073     bool getFrame(ALImage & pImage, const unsigned int pFrameNumber, const unsigned int pStreamNumber, const bool pCheckFormat = true);
00074     bool getNextFrame(ALImage & pImage, const bool pCheckFormat = true);
00075     bool getPrecedingFrame(ALImage & pImage, const bool pCheckFormat = true);
00076     bool write(char* ptrImageData, const int pSizeData, const long long pTimeStamp = 0, const char pCameraId = 0,
00077                const float pLeftAngle = 0, const float pTopAngle = 0, const float pRightAngle = 0, const float pBottomAngle = 0);
00078     bool write(int height, int width, char *imageData, const long long pTimeStamp, const char pCameraId,
00079                const float pLeftAngle, const float pTopAngle, const float pRightAngle, const float pBottomAngle);
00080     //deprecated
00081     bool write(IplImage* pImage, const long long pTimeStamp = 0, const char pCameraId = 0,
00082                const float pLeftAngle = 0, const float pTopAngle = 0, const float pRightAngle = 0, const float pBottomAngle = 0);
00083 
00084     inline const unsigned char* getMagicNumber() const       { return (unsigned char*)&fMagicNumber; };
00085     inline const unsigned int getNumberOfFrames() const      { return fNumberOfFrames; };
00086     inline const unsigned int getNumberOfStreams() const     { return fNumberOfStreams; };
00087     inline const unsigned int getCurrentFrameNumber() const  { return fCurrentFrameNumber; };
00088     inline const unsigned int getCurrentStreamNumber() const { return fCurrentStreamNumber; };
00089     inline const bool isOpenForReading() const               { return fIsOpenForReading; };
00090     inline const bool isOpenForWriting() const               { return fIsOpenForWriting; };
00091 
00092     inline const int getStreamWidth(const unsigned int pStreamNumber) const       { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].width        : -1; };
00093     inline const int getStreamHeight(const unsigned int pStreamNumber)const       { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].height       : -1; };
00094     inline const int getStreamResolution(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].resolution   : -1; };
00095     inline const int getStreamColorSpace(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].colorSpace   : -1; };
00096     inline const int getStreamNbLayers(const unsigned int pStreamNumber) const    { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].nbLayers     : -1; };
00097     inline const int getStreamPixelDepth(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].pixelDepth   : -1; };
00098     inline const int getStreamSizePerImage(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].sizePerImage : -1; };
00099 
00100 
00101   // .:: members ::
00102 
00103   private:
00104     volatile bool fIsOpenForReading;
00105     volatile bool fIsOpenForWriting;
00106 
00107     std::ifstream     fVideoStreamIn;
00108     std::ofstream     fVideoStreamOut;
00109     std::string       fFilePath;
00110 
00111     unsigned int fMagicNumber;
00112     unsigned int fUserSpaceSize;
00113     unsigned int fNumberOfFrames;
00114     unsigned int fNumberOfStreams;
00115     unsigned int fSizeOfHeader;
00116     unsigned int fSizePerMultiplexedFrame;
00117     std::vector<struct streamProperties> fStreamPropertiesVector;
00118 
00119     unsigned int fCurrentStreamNumber;
00120     unsigned int fCurrentFrameNumber;
00121   };
00122 }
00123 
00124 #endif  // _LIBALVISION_ALVISION_ALVIDEO_H_
 All Classes Namespaces Files Functions Variables