CVideoHandler.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #ifndef __CVIDEOHANDLER_H__
  2. #define __CVIDEOHANDLER_H__
  3. #include "../global.h"
  4. #ifdef _WIN32
  5. #include <windows.h>
  6. struct SDL_Surface;
  7. #pragma pack(push,1)
  8. struct BINK_STRUCT
  9. {
  10. si32 width;
  11. si32 height;
  12. si32 frameCount;
  13. si32 currentFrame;
  14. si32 lastFrame;
  15. si32 FPSMul;
  16. si32 FPSDiv;
  17. si32 unknown0;
  18. ui8 flags;
  19. ui8 unknown1[260];
  20. si32 CurPlane; // current plane
  21. void *plane0; // posi32er to plane 0
  22. void *plane1; // posi32er to plane 1
  23. si32 unknown2;
  24. si32 unknown3;
  25. si32 yWidth; // Y plane width
  26. si32 yHeight; // Y plane height
  27. si32 uvWidth; // U&V plane width
  28. si32 uvHeight; // U&V plane height
  29. };
  30. #pragma pack(pop)
  31. typedef BINK_STRUCT* HBINK;
  32. class DLLHandler
  33. {
  34. public:
  35. std::string name;
  36. HINSTANCE dll;
  37. void Instantiate(const char *filename);
  38. const char *GetLibExtension();
  39. void *FindAddress(const char *symbol);
  40. DLLHandler();
  41. virtual ~DLLHandler(); //d-tor
  42. };
  43. typedef void*(__stdcall* BinkSetSoundSystem)(void * soundfun, void*);
  44. typedef HBINK(__stdcall* BinkOpen)(HANDLE bikfile, int flags);
  45. typedef void(__stdcall* BinkClose)(HBINK);
  46. //typedef si32(__stdcall* BinkGetPalette)(HBINK);
  47. typedef void(__stdcall* BinkNextFrame)(HBINK);
  48. typedef void(__stdcall* BinkDoFrame)(HBINK);
  49. typedef ui8(__stdcall* BinkWait)(HBINK);
  50. typedef si32(__stdcall* BinkCopyToBuffer)(HBINK, void* buffer, int stride, int height, int x, int y, int mode);
  51. class IVideoPlayer
  52. {
  53. public:
  54. virtual void open(std::string name)=0;
  55. virtual void close()=0;
  56. virtual void nextFrame()=0;
  57. virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
  58. virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
  59. virtual bool wait()=0;
  60. virtual int curFrame() const =0;
  61. virtual int frameCount() const =0;
  62. };
  63. class CBIKHandler : public DLLHandler, public IVideoPlayer
  64. {
  65. public:
  66. HANDLE hBinkFile;
  67. HBINK hBink;
  68. char * buffer;
  69. BinkSetSoundSystem binkSetSoundSystem;
  70. BinkOpen binkOpen;
  71. //BinkGetPalette getPalette;
  72. BinkNextFrame binkNextFrame;
  73. BinkDoFrame binkDoFrame;
  74. BinkCopyToBuffer binkCopyToBuffer;
  75. BinkWait binkWait;
  76. BinkClose binkClose;
  77. CBIKHandler();
  78. void open(std::string name);
  79. void close();
  80. void nextFrame();
  81. void show(int x, int y, SDL_Surface *dst, bool update = true);
  82. void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
  83. bool wait();
  84. int curFrame() const;
  85. int frameCount() const;
  86. };
  87. //////////SMK Player ///////////////////////////////////////////////////////
  88. struct SmackStruct
  89. {
  90. si32 version;
  91. si32 width;
  92. si32 height;
  93. si32 frameCount;
  94. si32 mspf;
  95. ui8 unk1[88];
  96. ui8 palette[776];
  97. si32 currentFrame; // Starting with 0
  98. ui8 unk[56];
  99. ui32 fileHandle; // exact type is HANDLE in windows.h
  100. };
  101. // defines function pointer types
  102. typedef SmackStruct* (__stdcall* SmackOpen)(void* , ui32, si32 );
  103. typedef int (__stdcall* SmackDoFrame)( SmackStruct * );
  104. typedef void (__stdcall * SmackGoto )(SmackStruct *, int frameNumber);
  105. typedef void (__stdcall* SmackNextFrame)(SmackStruct*);
  106. typedef void (__stdcall* SmackClose)(SmackStruct*);
  107. typedef void (__stdcall* SmackToBuffer) (SmackStruct*, int, int, int, int, char *, ui32);
  108. typedef bool (__stdcall* SmackWait)(SmackStruct*);
  109. typedef void (__stdcall* SmackSoundOnOff) (SmackStruct*, bool);
  110. class CSmackPlayer: public DLLHandler, public IVideoPlayer
  111. {
  112. public:
  113. SmackOpen ptrSmackOpen;
  114. SmackDoFrame ptrSmackDoFrame;
  115. SmackToBuffer ptrSmackToBuffer;
  116. SmackNextFrame ptrSmackNextFrame;
  117. SmackWait ptrSmackWait;
  118. SmackSoundOnOff ptrSmackSoundOnOff;
  119. SmackClose ptrSmackClose;
  120. char *buffer, *buf;
  121. SmackStruct* data;
  122. CSmackPlayer();
  123. ~CSmackPlayer();
  124. void open(std::string name);
  125. void close();
  126. void nextFrame();
  127. void show(int x, int y, SDL_Surface *dst, bool update = true);
  128. void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
  129. bool wait();
  130. int curFrame() const;
  131. int frameCount() const;
  132. };
  133. class CVidHandler;
  134. class CVideoPlayer : public IVideoPlayer
  135. {
  136. private:
  137. CVidHandler * vidh; //.vid file handling
  138. CSmackPlayer smkPlayer; //for .SMK
  139. CBIKHandler bikPlayer; //for .BIK
  140. IVideoPlayer *current; //points to bik or smk player, appropriate to type of currently played video
  141. std::string fname; //name of current video file (empty if idle)
  142. bool first; //are we about to display the first frame (blocks update)
  143. public:
  144. CVideoPlayer(); //c-tor
  145. ~CVideoPlayer(); //d-tor
  146. void open(std::string name);
  147. void close();
  148. void nextFrame(); //move animation to the next frame
  149. void show(int x, int y, SDL_Surface *dst, bool update = true); //blit current frame
  150. void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
  151. void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
  152. bool wait(); //true if we should wait before displaying next frame (for keeping FPS)
  153. int curFrame() const; //current frame number <1, framecount>
  154. int frameCount() const;
  155. bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false); //opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
  156. bool playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey = false); //plays whole opened video; returns: true when whole video has been shown, false when it has been interrupted
  157. };
  158. #else
  159. #include <SDL_video.h>
  160. typedef struct AVFormatContext AVFormatContext;
  161. typedef struct AVCodecContext AVCodecContext;
  162. typedef struct AVCodec AVCodec;
  163. typedef struct AVFrame AVFrame;
  164. struct SwsContext;
  165. class CVidHandler;
  166. class CVideoPlayer
  167. {
  168. private:
  169. int stream; // stream index in video
  170. AVFormatContext *format;
  171. AVCodecContext *codecContext; // codec context for stream
  172. AVCodec *codec;
  173. AVFrame *frame;
  174. struct SwsContext *sws;
  175. SDL_Overlay *overlay;
  176. SDL_Rect pos; // overlay position
  177. CVidHandler *vidh;
  178. public:
  179. CVideoPlayer();
  180. ~CVideoPlayer();
  181. bool init();
  182. bool open(std::string fname, int x, int y);
  183. void close();
  184. bool nextFrame(); // display next frame
  185. const char *data; // video buffer
  186. int length; // video size
  187. unsigned int offset; // current data offset
  188. };
  189. #endif
  190. #endif // __CVIDEOHANDLER_H__