sprint 1-alpha
sprint/video/avi.h
00001 /******************************************************************************
00002 *   SPRINT::thread_group
00003 *
00004 *   Copyright (C) 2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 
00022 #ifndef _SPRINT_AVI_H
00023 #define _SPRINT_AVI_H
00024 
00025 // AviPlayer 0.7
00026 // TODO: rewrite
00027 
00028 #include <pmimage.h>
00029 #include <dsound.h>
00030 
00031 class AviReader {
00032 private:
00033 CRITICAL_SECTION    m_csAccessBuffer;  // non mi serve...
00034 
00035 PAVISTREAM m_pasMovie;               // the Handle to the AVI-Videostream
00036 AVISTREAMINFO m_asiMovie;            // The Video-Information
00037 
00038 HIC  m_hicDecompressor;                      // Handle to the AVI-Decompressor
00039 LONG m_lLength;                                          // Input-Bufferlength
00040 
00041 protected:
00042 
00043 LONG m_lLinePitch;                   // Bitmap-Linepitch
00044 
00045 int m_iTimeTick;                     // Time between two frames 
00046 
00047 BOOL m_bPixelFormat;                             // Pixel Format Initialized?
00048 
00049 BOOL bFreeMemory;                                       // liberare la memoria in uscita
00050 
00051 public :
00052 
00053  int m_update;                                            // nuovo frame in memoria
00054  int m_bLoop;                                             // Loop CountDown
00055 
00056  LPBITMAPV4HEADER m_lpb4hTargetFmt;   // Format of Target Surface
00057  LPBITMAPINFOHEADER m_lpScrFmt;       // Format of VideoInput
00058 
00059  BYTE *m_lpInput,*m_lpOutput;
00060  LONG m_lIndex,                                          // actual Frame - Index
00061                 m_lFrames;                       // Video-Frames in AVI-File
00062 
00063  DWORD m_dwFps;                       // Freames per Second
00064  
00065  AviReader();
00066  ~AviReader();
00067 
00068  HRESULT Initialize(LPDDPIXELFORMAT, BOOL bMemory=TRUE); // inizializza da una generica superficie
00069  
00070  HRESULT Open(LPCSTR);
00071 
00072  LPBYTE ReadFrame(LONG);
00073  
00074  virtual LPBYTE ReadNextFrame();        
00075  // ReadNextFrame deve essere virtual perchè i timer sono solo in DDAviPlayer 
00076 
00077  void Close();
00078 
00079  // Copia i dati in modo da essere visibili agli umani
00080  DWORD CopyFrameData(LPBYTE dst, LONG lPitch, DWORD dwHeight);
00081 
00082  // Resituisce la dimensione del buffer di ingresso
00083  DWORD GetInputInfo(LPDWORD dwWidth, LONG *lPitch, LPDWORD dwHeight);
00084  DWORD GetOutputBufferSize();
00085 };
00086 
00087 class DDAviPlayer: public AviReader {
00088 protected:
00089 BOOL m_AutoFlip;
00090 BOOL m_bRunning;
00091 int m_iTimerID;                                  // TimerID of timeEvents
00092 
00093 BOOL bAuto;                                                      // Automatic Play
00094 
00095 LPDIRECTDRAWSURFACE m_lpdds;                    // mmmh
00096 
00097 public:
00098 
00099  HRESULT Open(LPCSTR, DWORD dwMemory);
00100 
00101  BOOL SetAuto(BOOL bAuto);
00102  BOOL SetAutoFlip(BOOL bAutoFlip);
00103 
00104  void InstallTimer();
00105  void ReleaseTimer();
00106 
00107  BOOL Start(); 
00108  BOOL Stop();
00109 
00110  void Close();
00111 
00112  LPBYTE ReadFrame(LONG iFrame);
00113 
00114  HRESULT InitializeFromDirectDraw(LPDIRECTDRAW, DWORD dwMemoryFlag);
00115  
00116 /* void WriteToSurface(LPDIRECTDRAWSURFACE);
00117  void WriteToSurfaceEx(LPDIRECTDRAWSURFACE, UINT x, UINT y, DWORD dwFlag);*/
00118  
00119  LPDIRECTDRAWSURFACE GetClientSurface();
00120 };
00121 
00122 
00123 class AviPlayerWithSound: public DDAviPlayer {
00124 private:
00125         HRESULT InitSound();
00126 // called ba the Constructor 
00127         void CloseSound();
00128 // called by the Destructor, or when construction fails
00129 
00130 private:
00131         BOOL m_sound;                                   // sound access right?
00132 
00133         LPDIRECTSOUND lpDS;
00134 
00135         PAVISTREAM m_pasSound;           // Handle to Soundstream in AVI-File
00136         AVISTREAMINFO m_asiSound;        // Formatinformation of Soundstream
00137         WAVEFORMATEX *m_lpSoundScrFmt;   // Fromat of Sampledata
00138         LPDIRECTSOUNDBUFFER m_lpdsbTon;  // The streaming Soundbuffer
00139     DWORD m_dwLoadPos,               // Loadpos in streaming Buffer
00140                   m_dwLoadSize;              // Bytes to load per frames
00141         DWORD m_dwSpf;                                   // Samples to load per frames
00142 
00143         int m_iSoundFramesAhead;         // Frames of sound to load befor Videoplayback starts
00144                                          // (I belive the way I set this value is currently buggy
00145                                                                          //  cos I am not really sure about the AVISTREAMINFO.dwInitialFrames
00146                                          //  value)
00147         DWORD m_dwSoundFrame;                    // numero di frame bufferizzati
00148         DWORD m_dwBufferSize;
00149 public:
00150 
00151  inline BOOL IsSound()
00152  {
00153          return m_sound;
00154  }
00155 
00156  HRESULT Open(LPCSTR, DWORD dwMemory);
00157 
00158  LPBYTE ReadFrame(LONG); 
00159 
00160  virtual LPBYTE ReadNextFrame();        
00161  // ReadNextFrame deve essere virtual perchè i timer sono solo in DDAviPlayer 
00162 
00163  BOOL Start();
00164  BOOL Stop();
00165  void Close();
00166 
00167  HRESULT GetFrameSound();
00168 
00169  
00170 };
00171 
00172 #define ERRORAVI_OK             0
00173 #define ERRORAVI_STREAM 1
00174 #define ERRORAVI_VIDEO  2
00175 #define ERRORAVI_SOUND  3
00176 
00177 // Ex dwFlag
00178 // espande le linee per ottenere l'effetto della blizzard
00179 #define AF_SCREENFX             0x00000001
00180 
00181 // Immagine x2
00182 #define AF_SCREENDOUBLE 0x00000002
00183 
00184 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines