forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b51fee7
commit cf9dce9
Showing
10 changed files
with
173 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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. | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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(); | ||
/*! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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; | ||
|
@@ -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(); | ||
} | ||
|
@@ -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 | ||
|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
@@ -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); | ||
|
@@ -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())); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
|