#ifndef VIDEOPLAY_H
#define VIDEOPLAY_H

#include "avdef.h"
#include "HVideoPlayerFactory.h"

#include <iostream>

enum renderer_type_e
{
    RENDERER_TYPE_OPENGL,
    RENDERER_TYPE_SDL2,
    // Windows only
    // RENDERER_TYPE_D3D,
    // RENDERER_TYPE_DDRAW,
    // RENDERER_TYPE_GDI,
};
#define DEFAULT_RENDERER_TYPE RENDERER_TYPE_OPENGL

class VideoPlay
{
public:
    enum Status
    {
        STOP,
        PAUSE,
        PLAY,
    };

    explicit VideoPlay();
    ~VideoPlay();

    // 视频解析虚基类
    HVideoPlayer* pImpl_player;
public:
    void open(HMedia& media);
    void close();

    void start();
    void stop();
    void pause();
    void resume();
    void restart();
    void retry();

    void onTimerUpdate();
    void onOpenSucceed();
    void onOpenFailed();
    void onPlayerEOF();
    void onPlayerError();

    void setAspectRatio(aspect_ratio_t aspect_ratio);

protected:


public:
    int playerid;
    int status;
    std::string title;
    int fps = 20;
    aspect_ratio_t aspect_ratio;
    renderer_type_e renderer_type;

private:
    // 视频媒体，可以是本地视频文件、流媒体ip和摄像头
    HMedia media;

    // 视频解析虚基类
    //HVideoPlayer* pImpl_player;

    // for retry when SIGNAL_END_OF_FILE
    int retry_interval;
    int retry_maxcnt;
    int64_t last_retry_time;
    int retry_cnt;

    // 视频当前帧
    HFrame last_frame;

    // 设置视频的宽和高
    int width;
    int height;
};

#endif // VIDEOPLAY_H
