Video.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /******************************************************************************
  2. Use 'Video' to display video files.
  3. /******************************************************************************/
  4. enum VIDEO_CODEC : Byte
  5. {
  6. VIDEO_NONE ,
  7. VIDEO_THEORA, // doesn't support random seeking
  8. VIDEO_VP9 , // doesn't support random seeking
  9. };
  10. #if EE_PRIVATE
  11. struct VideoCodec
  12. {
  13. enum RESULT
  14. {
  15. ERROR,
  16. OK ,
  17. END ,
  18. };
  19. virtual Bool create (Video &video ) {return false;}
  20. virtual RESULT nextFrame (Video &video, Flt &time) {return ERROR;}
  21. virtual void frameToImage(Video &video ) {}
  22. virtual ~VideoCodec() {} // set virtual destructor so 'Delete' can be used together with extended classes
  23. };
  24. #endif
  25. /******************************************************************************/
  26. struct Video // Video Decoder
  27. {
  28. enum MODE
  29. {
  30. DEFAULT, // default video mode, use for most cases, allows 'Video.draw' methods, but not 'Video.image'
  31. IMAGE , // video will be accessible as texture , allows 'Video.draw' methods AND 'Video.image'
  32. ALPHA , // video will be used only as alpha channel for 'Video.drawAlpha' methods
  33. };
  34. // manage
  35. void del ( ); // delete manually
  36. Bool create(C Str &name, Bool loop=false, MODE mode=DEFAULT); // create from 'name' file name , 'loop'=if this video should be looped, false on fail
  37. Bool create(C UID &id , Bool loop=false, MODE mode=DEFAULT); // create from 'id' file name ID, 'loop'=if this video should be looped, false on fail
  38. // get
  39. Bool is ()C {return _codec!=VIDEO_NONE;} // if created
  40. VIDEO_CODEC codec ()C {return _codec ;} // get video codec
  41. CChar8* codecName()C; // get video codec name
  42. Flt time ()C {return _time ;} // get current time position of the video
  43. Int width ()C {return _w ;} // get video width
  44. Int height ()C {return _h ;} // get video height
  45. Flt aspect ()C {return Flt(_w)/_h ;} // get video aspect ratio "width/height"
  46. Int bitRate ()C {return _br ;} // get video bit rate
  47. Flt fps ()C {return _fps ;} // get video frames per second
  48. C Image& image()C; // get video as image, this will be valid only if the video was created with 'mode'=IMAGE, you may no longer use this image once the video got deleted
  49. // update
  50. Bool update(Flt time); // update to 'time' video time, returns false when finished playing, some codecs don't support random seeking, only continuous playback is supported
  51. // fit
  52. Rect fit(C Rect &rect, FIT_MODE fit=FIT_FULL)C {return Fit(aspect(), rect, fit);} // get rectangle that can be used for drawing of the video to the 'rect' destination while preserving video proportions according to specified 'fit' mode
  53. // draw
  54. void drawFs (FIT_MODE fit=FIT_FULL)C; // draw full screen
  55. void drawFit(C Rect &rect )C; // draw to fit best in given space, while preserving video proportions
  56. void draw (C Rect &rect )C; // draw to specified rectangle
  57. // draw using alpha from another 'Video'
  58. void drawAlphaFs (C Video &alpha, FIT_MODE fit=FIT_FULL)C; // 'alpha'=video to use as opacity, draw full screen
  59. void drawAlphaFit(C Video &alpha, C Rect &rect )C; // 'alpha'=video to use as opacity, draw to fit best in given space, while preserving video proportions
  60. void drawAlpha (C Video &alpha, C Rect &rect )C; // 'alpha'=video to use as opacity, draw to specified rectangle
  61. #if EE_PRIVATE
  62. void zero ();
  63. void release ();
  64. Bool frameToImage(Int w, Int h, Int w2, Int h2, CPtr lum_data, CPtr u_data, CPtr v_data, Int lum_pitch, Int u_pitch, Int v_pitch);
  65. void frameToImage();
  66. Bool nextFrame ();
  67. #endif
  68. ~Video() {del();}
  69. Video();
  70. #if !EE_PRIVATE
  71. private:
  72. #endif
  73. VIDEO_CODEC _codec;
  74. MODE _mode;
  75. Bool _loop;
  76. Int _w, _h, _br;
  77. Flt _time, _time_past, _fps;
  78. File _file;
  79. Image _lum, _u, _v, _tex, *_tex_ptr;
  80. #if EE_PRIVATE
  81. VideoCodec *_d;
  82. #else
  83. Ptr _d;
  84. #endif
  85. NO_COPY_CONSTRUCTOR(Video);
  86. };
  87. /******************************************************************************/
  88. CChar8* CodecName(VIDEO_CODEC codec);
  89. #if EE_PRIVATE
  90. #if DX9
  91. extern Memx<Image> VideoTextures;
  92. void VideoTexturesLost ();
  93. void VideoTexturesReset();
  94. #endif
  95. #endif
  96. /******************************************************************************/