CVideoHandler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * CVideoHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #ifndef DISABLE_VIDEO
  12. #include "IVideoPlayer.h"
  13. #include "../lib/Rect.h"
  14. struct SDL_Surface;
  15. struct SDL_Texture;
  16. struct AVFormatContext;
  17. struct AVCodecContext;
  18. struct AVCodec;
  19. struct AVFrame;
  20. struct AVIOContext;
  21. VCMI_LIB_NAMESPACE_BEGIN
  22. class CInputStream;
  23. VCMI_LIB_NAMESPACE_END
  24. class CVideoPlayer final : public IVideoPlayer
  25. {
  26. int stream; // stream index in video
  27. AVFormatContext *format;
  28. AVCodecContext *codecContext; // codec context for stream
  29. const AVCodec *codec;
  30. AVFrame *frame;
  31. struct SwsContext *sws;
  32. AVIOContext * context;
  33. VideoPath fname; //name of current video file (empty if idle)
  34. // Destination. Either overlay or dest.
  35. SDL_Texture *texture;
  36. SDL_Surface *dest;
  37. Rect destRect; // valid when dest is used
  38. Rect pos; // destination on screen
  39. /// video playback currnet progress, in seconds
  40. double frameTime;
  41. bool doLoop; // loop through video
  42. bool playVideo(int x, int y, bool stopOnKey, bool overlay);
  43. bool open(const VideoPath & fname, bool loop, bool useOverlay, bool scale);
  44. public:
  45. CVideoPlayer();
  46. ~CVideoPlayer();
  47. bool init();
  48. bool open(const VideoPath & fname, bool scale) override;
  49. void close() override;
  50. bool nextFrame() override; // display next frame
  51. void show(int x, int y, SDL_Surface *dst, bool update) override; //blit current frame
  52. void redraw(int x, int y, SDL_Surface *dst, bool update) override; //reblits buffer
  53. void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update, std::function<void()> onVideoRestart) override; //moves to next frame if appropriate, and blits it or blits only if redraw parameter is set true
  54. // Opens video, calls playVideo, closes video; returns playVideo result (if whole video has been played)
  55. bool openAndPlayVideo(const VideoPath & name, int x, int y, EVideoType videoType) override;
  56. std::pair<std::unique_ptr<ui8 []>, si64> getAudio(const VideoPath & videoToOpen) override;
  57. Point size() override;
  58. //TODO:
  59. bool wait() override {return false;};
  60. int curFrame() const override {return -1;};
  61. int frameCount() const override {return -1;};
  62. // public to allow access from ffmpeg IO functions
  63. std::unique_ptr<CInputStream> data;
  64. std::unique_ptr<CInputStream> dataAudio;
  65. };
  66. #endif