MediaPlayer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /// MediaPlayer.h
  2. #ifndef __MEDIAPLAYER_H__
  3. #define __MEDIAPLAYER_H__
  4. #include <QtWidgets>
  5. #include <QTimer>
  6. #include <QTime>
  7. #include <QPainter>
  8. #include <QThread>
  9. #include "VideoExtractor.h"
  10. #include "EquirectangularToFovVideo.h"
  11. /// The following class tries to imitate the QMediaPlayer, but it comes with
  12. /// some differentitaions. The functions that start in lower case imitate the
  13. /// Qt ones/ The functions that start with upper case are unique toi this
  14. /// implementation
  15. class MediaPlayer : public QObject
  16. {
  17. Q_OBJECT
  18. signals:
  19. void positionChanged(qint64);
  20. ///< emits the current time of player in ms
  21. private slots:
  22. void HandleTimerTick();
  23. ///< handle for timer tick
  24. public:
  25. MediaPlayer(QObject *parent=0);
  26. ~MediaPlayer();
  27. enum State {PausedState, StoppedState, PlayingState};
  28. ///< Enumerator holding the player state.
  29. void setPosition(qint64 position);
  30. ///< Sets the position of the player in ms.
  31. bool setMedia(QUrl videoFile);
  32. ///< Sets the input file.
  33. void play();
  34. ///< Starts player.
  35. void pause();
  36. ///< Pauses player.
  37. State state() const;
  38. ///< Returns the current state of the player.
  39. qint64 duration();
  40. ///< Returns duration fo the video in ms.
  41. bool isVideoAvailable() const;
  42. ///< Returns true if video is available.
  43. void Paint(QPainter *painter, QSize size);
  44. ///< Paints the current image to the provided painter.
  45. void SetConverter(EquirectangularToFovVideo *pEqToFov);
  46. private:
  47. QTimer *m_pFpsTimer; // timer emulating the fps of the initial video
  48. QImage m_image;
  49. QImage m_tmpImage;
  50. QTime m_time; // hold time since start of player
  51. int m_startPlayFrame; // frame since we started playing video
  52. int m_startPlayMs; // presentaion time of first frame since started playing video
  53. VideoParams m_videoParams;
  54. double m_frameDur; // duration of frame in ms
  55. State m_state; // state of the player
  56. int m_curFrame; // currently loaded frame
  57. bool m_bVideoAv;
  58. EquirectangularToFovVideo *m_pEqToFov; // convert from equirectangular to field of view
  59. void LoadFrame(int frameNum);
  60. ///< Loads te provided frame and updates current frame state.
  61. };
  62. #endif /*__MEDIAPLAYER_H__*/