Skip to content

Commit

Permalink
增加打折功能
Browse files Browse the repository at this point in the history
  • Loading branch information
qht1003077897 committed Aug 5, 2020
1 parent b51fee7 commit cf9dce9
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 15 deletions.
27 changes: 26 additions & 1 deletion examples/player/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV Player Demo: this file is part of QtAV examples
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Expand Down Expand Up @@ -161,6 161,31 @@ void MainWindow::initPlayer()
QMessageBox::critical(0, QString::fromLatin1("QtAV"), tr("Video renderer is ") tr("not availabe on your platform!"));
}
setRenderer(vo);
static GLfloat vertexVertices[] = {
// 顶点从左下角逆时针旋转
// 左上角区域
-1.0f, 0.0f, 0.0f, 1 - 0.5f,
0.0f, 0.0f, 0.5f, 1 - 0.5f,
0.0f, 1.0f, 0.5f, 1 - 1.0f,
-1.0f, 1.0f, 0.0f, 1 - 1.0f,
// 右上角区域
0.2f, 0.2f, 0.5f, 1 - 0.5f,
1.0f, 0.2f, 1.0f, 1 - 0.5f,
1.0f, 1.0f, 1.0f, 1 - 1.0f,
0.2f, 1.0f, 0.5f, 1 - 1.0f,
// 左下角区域
-1.0f, -1.0f, 0.0f, 1 - (0.5f - 0.5f),
0.0f, -1.0f, 0.5f, 1 - (0.5f - 0.5f),
0.0f, -0.2f, 0.5f, 1 - (1.0f - 0.5f),
-1.0f, -0.2f, 0.0f, 1 - (1.0f - 0.5f),
// 右下角区域
0.2f, -1.0f, 0.5f, 1 - (0.5f - 0.5f),
1.0f, -1.0f, 1.0f, 1 - (0.5f - 0.5f),
1.0f, 0.0f, 1.0f, 1 - (1.0f - 0.5f),
0.2f, 0.0f, 0.5f, 1 - (1.0f - 0.5f),
};
mpPlayer->openFold(4);
mpPlayer->setVertexData(vertexVertices,sizeof(vertexVertices));
//mpSubtitle->installTo(mpPlayer); //filter on frame
mpSubtitle->setPlayer(mpPlayer);
//mpPlayer->setAudioOutput(AudioOutputFactory::create(AudioOutputId_OpenAL));
Expand Down
21 changes: 20 additions & 1 deletion src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 48,7 @@
extern "C" {
#include <libavutil/mathematics.h>
}

#include<QDebug>
#define EOF_ISSUE_SOLVED 0
namespace QtAV {
namespace {
Expand Down Expand Up @@ -1120,6 1120,25 @@ void AVPlayer::setState(State value)

}

void AVPlayer::setVertexData(float *arrayVdata, int arrayVdataSize)
{
auto outs = videoOutputs();
qDebug()<< "QHT AVPlayer::setVertexData:" << arrayVdata << "arrayVdataSize:" << arrayVdataSize;
qDebug()<< "QHT AVPlayer::setVertexData:" << "outs.size():" << outs.size();
for (auto output : outs) {
output->setVertexData(arrayVdata,arrayVdataSize);
}
}

void AVPlayer::openFold(int foldSize)
{
auto outs = videoOutputs();
qDebug()<< "QHT AVPlayer::openFold:" <<"foldSize:" << foldSize << "outs.size():" << outs.size();
for (auto output : outs) {
output->openFold(foldSize);
}
}

bool AVPlayer::load()
{
if (!d->current_source.isValid()) {
Expand Down
5 changes: 4 additions & 1 deletion src/QtAV/AVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 286,10 @@ class Q_AV_EXPORT AVPlayer : public QObject
*/
State state() const;
void setState(State value);

//QHT insert
void setVertexData(float *arrayVdata, int arrayVdataSize);
/*打开打折功能,需要调用setVertexData设置顶点数据和纹理数据(交叉格式)*/
void openFold(int foldSize);
// TODO: use id as parameter and return ptr?
void addVideoRenderer(VideoRenderer *renderer);
void removeVideoRenderer(VideoRenderer *renderer);
Expand Down
12 changes: 10 additions & 2 deletions src/QtAV/GeometryRenderer.h
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Expand Down Expand Up @@ -57,6 57,10 @@ class Q_AV_EXPORT GeometryRenderer
int features() const;
int actualFeatures() const;
bool testFeatures(int value) const;
//QHT insert
void setVertexData(float *arrayVdata, int arrayVdataSize);
/*打开打折功能,需要调用setVertexData设置顶点数据和纹理数据(交叉格式)*/
void openFold(int foldSize);
/*!
* \brief updateGeometry
* Update geometry buffer. Rebind VBO, IBO to VAO if geometry attributes is changed.
Expand All @@ -66,11 70,15 @@ class Q_AV_EXPORT GeometryRenderer
*/
void updateGeometry(Geometry* geo = NULL);
virtual void render();
int m_foldSize = 0;
bool m_bIsFold = false;
int m_arrayVdataSize = 0;
float *m_arrayVdata = nullptr;
protected:
void bindBuffers();
void unbindBuffers();
private:
Geometry *g;
Geometry *g = nullptr;
int features_;
int vbo_size, ibo_size; // QOpenGLBuffer.size() may get error 0x501
QOpenGLBuffer vbo; //VertexBuffer
Expand Down
6 changes: 5 additions & 1 deletion src/QtAV/OpenGLRendererBase.h
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Expand Down Expand Up @@ -48,6 48,10 @@ class Q_AV_EXPORT OpenGLRendererBase : public VideoRenderer
virtual ~OpenGLRendererBase();
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
OpenGLVideo* opengl() const Q_DECL_OVERRIDE;
//QHT insert
void setVertexData(float *arrayVdata, int arrayVdataSize)Q_DECL_OVERRIDE;
/*打开打折功能,需要调用setVertexData设置顶点数据和纹理数据(交叉格式)*/
void openFold(int foldSize)Q_DECL_OVERRIDE;
protected:
virtual bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
//called in paintEvent before drawFrame() when required
Expand Down
7 changes: 6 additions & 1 deletion src/QtAV/OpenGLVideo.h
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2018 Wang Bin <[email protected]>
Expand Down Expand Up @@ -99,6 99,11 @@ class Q_AV_EXPORT OpenGLVideo : public QObject

void setMeshType(MeshType value);
MeshType meshType() const;

//QHT insert
/*打开打折功能,需要调用setVertexData设置顶点数据和纹理数据(交叉格式)*/
void openFold(int foldSize);
void setVertexData(float *arrayVdata, int arrayVdataSize);
Q_SIGNALS:
void beforeRendering();
/*!
Expand Down
6 changes: 5 additions & 1 deletion src/QtAV/VideoRenderer.h
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Expand Down Expand Up @@ -204,6 204,10 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
* Currently you can only use it to set custom shader OpenGLVideo.setUserShader()
*/
virtual OpenGLVideo* opengl() const { return NULL;}
//QHT insert
virtual void setVertexData(float *arrayVdata, int arrayVdataSize){};
/*打开打折功能,需要调用setVertexData设置顶点数据和纹理数据(交叉格式)*/
virtual void openFold(int foldSize){};
protected:
VideoRenderer(VideoRendererPrivate &d);
//TODO: batch drawBackground(color, region)=>loop drawBackground(color,rect)
Expand Down
47 changes: 44 additions & 3 deletions src/opengl/GeometryRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Expand Down Expand Up @@ -80,6 80,22 @@ bool GeometryRenderer::testFeatures(int value) const
return !!(features() & value);
}

void GeometryRenderer::setVertexData(float *arrayVdata, int arrayVdataSize)
{
qDebug()<< "QHT GeometryRenderer::setVertexData--" << arrayVdata << "arrayVdataSize:" << arrayVdataSize;
qDebug()<< "QHT GeometryRenderer::setVertexData~~~~~~~~~~~~~" << (void*)this;
m_arrayVdataSize = arrayVdataSize;
m_arrayVdata = arrayVdata;
m_bIsFold = true;
qDebug()<< "QHT GeometryRenderer::end";
}

void GeometryRenderer::openFold(int foldSize)
{
qDebug()<< "QHT GeometryRenderer::openFold--" << "foldSize:" << foldSize;
m_foldSize = foldSize;
}

void GeometryRenderer::updateGeometry(Geometry *geo)
{
g = geo;
Expand Down Expand Up @@ -152,7 168,14 @@ void GeometryRenderer::updateGeometry(Geometry *geo)
vbo_size = bs;
}
} else {
vbo.allocate(g->vertexData(), bs);
qDebug()<< "GeometryRenderer::m_bIsFold:" << m_bIsFold;
if(m_bIsFold)
{
qDebug()<< "GeometryRenderer::m_arrayVdata:" << m_arrayVdata << "m_arrayVdataSize:"<< m_arrayVdataSize;
vbo.allocate(m_arrayVdata, m_arrayVdataSize);
}else {
vbo.allocate(g->vertexData(), bs);
}
}
vbo.release();
}
Expand All @@ -177,11 200,20 @@ void GeometryRenderer::updateGeometry(Geometry *geo)
// call once is enough if no feature and no geometry attribute is changed
if (vbo.isCreated()) {
vbo.bind();
qDebug()<< "GeometryRenderer::updateGeometry:" << m_arrayVdata << "m_bIsFold:"<< m_bIsFold;
if(m_bIsFold)
{
QGLF(glVertexAttribPointer(0, 2, GL_FLOAT, 0, 4 * sizeof(float) , reinterpret_cast<const void *>(qptrdiff(0)))); //TODO: in setActiveShader
QGLF(glEnableVertexAttribArray(0));
QGLF(glVertexAttribPointer(1, 2,GL_FLOAT, 0, 4 * sizeof(float) , reinterpret_cast<const void *>(qptrdiff(2*sizeof(float))))); //TODO: in setActiveShader
QGLF(glEnableVertexAttribArray(1));
}else {
for (int an = 0; an < g->attributes().size(); an) {
// FIXME: assume bind order is 0,1,2...
const Attribute& a = g->attributes().at(an);
QGLF(glVertexAttribPointer(an, a.tupleSize(), a.type(), a.normalize(), g->stride(), reinterpret_cast<const void *>(qptrdiff(a.offset())))); //TODO: in setActiveShader
QGLF(glEnableVertexAttribArray(an));
}
}
vbo.release(); // unbind after vao unbind? http://www.zwqxin.com/archives/opengl/vao-and-vbo-stuff.html
} // TODO: bind pointers if vbo is disabled
Expand Down Expand Up @@ -269,7 301,16 @@ void GeometryRenderer::render()
if (g->indexCount() > 0) {
DYGL(glDrawElements(g->primitive(), g->indexCount(), g->indexType(), ibo.isCreated() ? NULL : g->indexData())); // null: data in vao or ibo. not null: data in memory
} else {
DYGL(glDrawArrays(g->primitive(), 0, g->vertexCount()));
if(m_bIsFold)
{
for (int i = 0; i < m_foldSize; i )
{
DYGL(glDrawArrays(GL_TRIANGLE_FAN, 4 * i, 4));
}
}else {
// GL_TRIANGLE_STRIP g->vertexCount: 4
DYGL(glDrawArrays(g->primitive(), 0, g->vertexCount()));
}
}
unbindBuffers();
}
Expand Down
41 changes: 38 additions & 3 deletions src/opengl/OpenGLVideo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2018 Wang Bin <[email protected]>
Expand Down Expand Up @@ -80,6 80,19 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
material = 0;
}
}
void setVertexData(float *arrayVdata, int arrayVdataSize)
{
qDebug()<< "QHT OpenGLVideoPrivate::setVertexData--" << arrayVdata << "arrayVdataSize:" << arrayVdataSize;
m_arrayVdataSize = arrayVdataSize;
m_arrayVdata = arrayVdata;
}

void openFold(int foldSize)
{
qDebug()<< "QHT OpenGLVideoPrivate::openFold--" << "foldSize:" << foldSize;
m_foldSize = foldSize;
m_bIsFold = true;
}
// update geometry(vertex array) set attributes or bind VAO/VBO.
void updateGeometry(VideoShader* shader, const QRectF& t, const QRectF& r);
public:
Expand All @@ -96,11 109,16 @@ class OpenGLVideoPrivate : public DPtrPrivate<OpenGLVideo>
QRectF target;
QRectF roi; //including invalid padding width
OpenGLVideo::MeshType mesh_type;
TexturedGeometry *geometry;
GeometryRenderer* gr;
TexturedGeometry *geometry = nullptr;
GeometryRenderer* gr = nullptr;
QRectF rect;
QMatrix4x4 matrix;
VideoShader *user_shader;
private:
int m_foldSize = 0;
bool m_bIsFold = false;
int m_arrayVdataSize = 0;
float *m_arrayVdata = nullptr;
};

void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, const QRectF &r)
Expand Down Expand Up @@ -128,6 146,11 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
new_thread.setLocalData(false);
GeometryRenderer *r = new GeometryRenderer(); // local var is captured by lambda
gr = r;
if(m_bIsFold)
{
gr->setVertexData(m_arrayVdata,m_arrayVdataSize);
gr->openFold(m_foldSize);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) && defined(Q_COMPILER_LAMBDA)
QObject::connect(QOpenGLContext::currentContext(), &QOpenGLContext::aboutToBeDestroyed, [r]{
qDebug("destroy GeometryRenderer %p", r);
Expand Down Expand Up @@ -335,6 358,18 @@ OpenGLVideo::MeshType OpenGLVideo::meshType() const
return d_func().mesh_type;
}

void OpenGLVideo::openFold(int foldSize)
{
qDebug()<< "QHT OpenGLVideo::openFold-- " << "foldSize:" << foldSize;
d_func().openFold(foldSize);
}

void OpenGLVideo::setVertexData(float *arrayVdata, int arrayVdataSize)
{
qDebug()<< "QHT OpenGLVideo::setVertexData:" << arrayVdata << "arrayVdataSize:" << arrayVdataSize;
d_func().setVertexData(arrayVdata,arrayVdataSize);
}

void OpenGLVideo::fill(const QColor &color)
{
DYGL(glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()));
Expand Down
16 changes: 15 additions & 1 deletion src/output/video/OpenGLRendererBase.cpp
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
/******************************************************************************
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Expand Down Expand Up @@ -101,6 101,20 @@ void OpenGLRendererBase::drawFrame()
d.glv.render(QRectF(), roi, d.matrix);
}

void OpenGLRendererBase::setVertexData(float *arrayVdata, int arrayVdataSize)
{
qDebug()<< "QHT OpenGLRendererBase::setVertexData:" << arrayVdata << "arrayVdataSize:" << arrayVdataSize;
DPTR_D(OpenGLRendererBase);
d.glv.setVertexData(arrayVdata, arrayVdataSize);
}

void OpenGLRendererBase::openFold(int foldSize)
{
qDebug()<< "QHT OpenGLRendererBase::openFold--" <<"openFold:" << foldSize;
DPTR_D(OpenGLRendererBase);
d.glv.openFold(foldSize);
}

void OpenGLRendererBase::onInitializeGL()
{
DPTR_D(OpenGLRendererBase);
Expand Down

0 comments on commit cf9dce9

Please sign in to comment.