5#include <GLES2/gl2ext.h>
10#include "private/qsgvideotexture_p.h"
12#include <QOpenGLContext>
17#include <QtMultimedia/private/qtmultimediaglobal_p.h>
18#include "private/qgstvideobuffer_p.h"
19#if GST_CHECK_VERSION(1,14,0)
20#include <gst/allocators/gstphysmemory.h>
34#ifdef QT_VIVANTE_VIDEO_DEBUG
60 if (this->mBitsToTextureMap ==
m->mBitsToTextureMap)
75 mCurrentFrame =
frame;
76 mMappable = mMapError == GL_NO_ERROR;
78#ifdef QT_VIVANTE_VIDEO_DEBUG
95 glBindTexture(GL_TEXTURE_2D, mCurrentTexture);
98void QSGVivanteVideoMaterial::clearTextures()
102#ifdef QT_VIVANTE_VIDEO_DEBUG
103 qDebug() <<
"delete texture: " <<
id;
105 glDeleteTextures(1, &
id);
107 mBitsToTextureMap.
clear();
109 if (mTexDirectTexture) {
110 glDeleteTextures(1, &mTexDirectTexture);
111 mTexDirectTexture = 0;
118 if (glcontext == 0) {
123 static PFNGLTEXDIRECTVIVPROC glTexDirectVIV_LOCAL = 0;
124 static PFNGLTEXDIRECTVIVMAPPROC glTexDirectVIVMap_LOCAL = 0;
125 static PFNGLTEXDIRECTINVALIDATEVIVPROC glTexDirectInvalidateVIV_LOCAL = 0;
127 if (glTexDirectVIV_LOCAL == 0 || glTexDirectVIVMap_LOCAL == 0 || glTexDirectInvalidateVIV_LOCAL == 0) {
128 glTexDirectVIV_LOCAL =
reinterpret_cast<PFNGLTEXDIRECTVIVPROC
>(glcontext->
getProcAddress(
"glTexDirectVIV"));
129 glTexDirectVIVMap_LOCAL =
reinterpret_cast<PFNGLTEXDIRECTVIVMAPPROC
>(glcontext->
getProcAddress(
"glTexDirectVIVMap"));
130 glTexDirectInvalidateVIV_LOCAL =
reinterpret_cast<PFNGLTEXDIRECTINVALIDATEVIVPROC
>(glcontext->
getProcAddress(
"glTexDirectInvalidateVIV"));
132 if (glTexDirectVIV_LOCAL == 0 || glTexDirectVIVMap_LOCAL == 0 || glTexDirectInvalidateVIV_LOCAL == 0) {
133 qWarning() <<
Q_FUNC_INFO <<
"couldn't find \"glTexDirectVIVMap\" and/or \"glTexDirectInvalidateVIV\" => do nothing and return";
141 mMapError = GL_NO_ERROR;
151 glGenTextures(1, &tmpTexId);
152 mBitsToTextureMap.
insert(vF.
bits(), tmpTexId);
176 float uScale = float(vF.
width()) / float(fullWidth);
177 float vScale = float(vF.
height()) / float(fullHeight);
181 void *
bits = (
void*)constBits;
183#ifdef QT_VIVANTE_VIDEO_DEBUG
185 <<
"new texture, texId: " << tmpTexId
186 <<
"; constBits: " << constBits
187 <<
"; actual/full width: " << vF.
width() <<
"/" << fullWidth
188 <<
"; actual/full height: " << vF.
height() <<
"/" << fullHeight
189 <<
"; UV scale: U " << uScale <<
" V " << vScale;
193#if GST_CHECK_VERSION(1,14,0)
195 auto mem = gst_buffer_peek_memory(
buffer->buffer(), 0);
196 auto phys_addr = gst_is_phys_memory(mem) ? gst_phys_memory_get_phys_addr(mem) : 0;
198 physical = phys_addr;
200 glBindTexture(GL_TEXTURE_2D, tmpTexId);
201 glTexDirectVIVMap_LOCAL(GL_TEXTURE_2D,
202 fullWidth, fullHeight,
206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
210 glTexDirectInvalidateVIV_LOCAL(GL_TEXTURE_2D);
212 mMapError = glGetError();
213 if (mMapError == GL_NO_ERROR)
221 glBindTexture(GL_TEXTURE_2D, mBitsToTextureMap.
value(vF.
bits()));
222 glTexDirectInvalidateVIV_LOCAL(GL_TEXTURE_2D);
223 return mBitsToTextureMap.
value(vF.
bits());
228 if (!mTexDirectTexture) {
229 glGenTextures(1, &mTexDirectTexture);
230 glBindTexture(GL_TEXTURE_2D, mTexDirectTexture);
231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
235 glTexDirectVIV_LOCAL(GL_TEXTURE_2D, mCurrentFrame.
width(), mCurrentFrame.
height(),
237 (GLvoid **) &mTexDirectPlanes);
239 glBindTexture(GL_TEXTURE_2D, mTexDirectTexture);
244 memcpy(mTexDirectPlanes[0], mCurrentFrame.
bits(0), mCurrentFrame.
height() * mCurrentFrame.
bytesPerLine(0));
245 memcpy(mTexDirectPlanes[1], mCurrentFrame.
bits(1), mCurrentFrame.
height() / 2 * mCurrentFrame.
bytesPerLine(1));
246 memcpy(mTexDirectPlanes[2], mCurrentFrame.
bits(2), mCurrentFrame.
height() / 2 * mCurrentFrame.
bytesPerLine(2));
250 memcpy(mTexDirectPlanes[0], mCurrentFrame.
bits(0), mCurrentFrame.
height() * mCurrentFrame.
bytesPerLine(0));
251 memcpy(mTexDirectPlanes[1], mCurrentFrame.
bits(1), mCurrentFrame.
height() / 2 * mCurrentFrame.
bytesPerLine(1));
257 glTexDirectInvalidateVIV_LOCAL(GL_TEXTURE_2D);
258 return mTexDirectTexture;
261#ifdef QT_VIVANTE_VIDEO_DEBUG
262 qWarning() <<
" couldn't map the QVideoFrame vF: " << vF;
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
const_iterator cend() const
const_iterator cbegin() const
QFunctionPointer getProcAddress(const QByteArray &procName) const
Resolves the function pointer to an OpenGL extension function, identified by procName.
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
The QSGMaterialShader class represents a graphics API independent shader program.
The QSGMaterial class encapsulates rendering state for a shader program.
virtual QSGMaterialType * type() const =0
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
void setUVScale(float uScale, float vScale)
~QSGVivanteVideoMaterial()
void setCurrentFrame(const QVideoFrame &frame, QSGVideoNode::FrameFlags flags)
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGVivanteVideoMaterial()
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
GLuint vivanteMapping(QVideoFrame texIdVideoFramePair)
friend class QSGVivanteVideoMaterialShader
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
static int getBytesForPixelFormat(QVideoFrameFormat::PixelFormat pixelformat)
static const QMap< QVideoFrameFormat::PixelFormat, GLenum > & getVideoFormat2GLFormatMap()
The QVideoFrame class represents a frame of video data.
int planeCount() const
Returns the number of planes in the video frame.
int height() const
Returns the height of a video frame.
uchar * bits(int plane)
Returns a pointer to the start of the frame data buffer for a plane.
bool map(QVideoFrame::MapMode mode)
Maps the contents of a video frame to system (CPU addressable) memory.
QVideoFrameFormat::PixelFormat pixelFormat() const
Returns the pixel format of this video frame.
bool isValid() const
Identifies whether a video frame is valid.
int width() const
Returns the width of a video frame.
int bytesPerLine(int plane) const
Returns the number of bytes in a scan line of a plane.
QSet< QString >::iterator it
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.