1背景
上一篇找了window下的依赖库和头文件,这一篇分析渲染。
2步骤
2.1 单个视频渲染
class HVideoWidget : public QFrame
{
public:
int playerid;
int status;
QString title;
int fps;
aspect_ratio_t aspect_ratio;
renderer_type_e renderer_type;
HVideoWnd *videownd;
HVideoTitlebar *titlebar;
HVideoToolbar *toolbar;
QPushButton *btnMedia;
之前初始化了HVideoWidget,只关注了open和start方法,没关注界面渲染。这里先关注HVideoWnd,另外的控制可以后面再关注。
2.2 HVideoWnd声明
先看声明文件(src/ui/HVideoWnd.h)
class HVideoWnd {
public:
HVideoWnd(QWidget* parent = nullptr);
virtual ~HVideoWnd() {}
virtual void setGeometry(const QRect& rc) = 0;
virtual void update() = 0;
protected:
void calcFPS();
public:
HFrame last_frame;
int fps;
bool draw_time;
bool draw_fps;
bool draw_resolution;
protected:
// for calFPS
uint64_t tick;
int framecnt;
};
再看cpp文件,除了构造器和calcFPS方法,其他的都没处理。
2.3 HVideoWnd 初始化
在HVideoWidget的cpp中可以找到如下代码
void HVideoWidget::initUI() {
setFocusPolicy(Qt::ClickFocus);
videownd = HVideoWndFactory::create(renderer_type, this);
从这里可以看到videownd是通过工厂方法创建的实例 查看参数
HVideoWidget::HVideoWidget(QWidget *parent) : QFrame(parent)
{
str = g_confile->GetValue("renderer", "video");
if (str.empty()) {
renderer_type = RENDERER_TYPE_OPENGL;
}
else {
renderer_type = renderer_type_enum(str.c_str());
}
上面默认使用了RENDERER_TYPE_OPENGL
从bin的config文件来看(bin/xxx/config),也是默认配置的OpenGL
[video]
frame_cache = 5
# fps = 25
# aspect_ratio = [x%, w:h, x:y, wxh]
# aspect_ratio = 100% # FULL
# aspect_ratio = 50% # PERCENT
# aspect_ratio = w:h # ORIGINAL_RATIO
# aspect_ratio = 4:3 # CUSTOM_RATIO
# aspect_ratio = wxh # ORIGINAL_SIZE
# aspect_ratio = 800x600 # CUSTOM_SIZE
# renderer = [opengl, sdl, ...]
renderer = opengl
继续看工厂方法实现
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 HVideoWndFactory {
public:
static HVideoWnd* create(renderer_type_e type = DEFAULT_RENDERER_TYPE, QWidget* parent = NULL) {
switch(type) {
case RENDERER_TYPE_OPENGL:
return new GLWnd(parent);
case RENDERER_TYPE_SDL2:
return new SDL2Wnd(parent);
default:
return NULL;
}
}
};