libalvision  2.0.6.8
/home/opennao/work/master/sdk/libnaoqi/libalvision/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 
00081     inline const unsigned char* getMagicNumber() const       { return (unsigned char*)&fMagicNumber; };
00082     inline unsigned int getNumberOfFrames() const      { return fNumberOfFrames; };
00083     inline unsigned int getNumberOfStreams() const     { return fNumberOfStreams; };
00084     inline unsigned int getCurrentFrameNumber() const  { return fCurrentFrameNumber; };
00085     inline unsigned int getCurrentStreamNumber() const { return fCurrentStreamNumber; };
00086     inline bool isOpenForReading() const               { return fIsOpenForReading; };
00087     inline bool isOpenForWriting() const               { return fIsOpenForWriting; };
00088 
00089     inline int getStreamWidth(const unsigned int pStreamNumber) const       { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].width        : -1; };
00090     inline int getStreamHeight(const unsigned int pStreamNumber)const       { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].height       : -1; };
00091     inline int getStreamResolution(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].resolution   : -1; };
00092     inline int getStreamColorSpace(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].colorSpace   : -1; };
00093     inline int getStreamNbLayers(const unsigned int pStreamNumber) const    { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].nbLayers     : -1; };
00094     inline int getStreamPixelDepth(const unsigned int pStreamNumber) const  { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].pixelDepth   : -1; };
00095     inline int getStreamSizePerImage(const unsigned int pStreamNumber)const { return (pStreamNumber<fNumberOfStreams) ? fStreamPropertiesVector[pStreamNumber].sizePerImage : -1; };
00096 
00097 
00098   // .:: members ::
00099 
00100   private:
00101     volatile bool fIsOpenForReading;
00102     volatile bool fIsOpenForWriting;
00103 
00104     std::ifstream     fVideoStreamIn;
00105     std::ofstream     fVideoStreamOut;
00106     std::string       fFilePath;
00107 
00108     unsigned int fMagicNumber;
00109     unsigned int fUserSpaceSize;
00110     unsigned int fNumberOfFrames;
00111     unsigned int fNumberOfStreams;
00112     unsigned int fSizeOfHeader;
00113     unsigned int fSizePerMultiplexedFrame;
00114     std::vector<struct streamProperties> fStreamPropertiesVector;
00115 
00116     unsigned int fCurrentStreamNumber;
00117     unsigned int fCurrentFrameNumber;
00118   };
00119 }
00120 
00121 #endif  // _LIBALVISION_ALVISION_ALVIDEO_H_
 All Classes Namespaces Files Functions Variables Defines