Skip to content
Snippets Groups Projects
Commit daa6feb4 authored by Silas Della Contrada's avatar Silas Della Contrada
Browse files

Added support for YUV420P with 8 or 10 bpp to OpenGLRenderer

 - These pixel formats are necessary for QSV decoding
 - QSV decoding is theoretically supported, but not implemented
parent 37815631
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
/codestream.xml
/statistic.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
/httpRequests/
\ No newline at end of file
......@@ -318,4 +318,4 @@ namespace AVQt {
}
}
}
}
}
\ No newline at end of file
......@@ -102,17 +102,17 @@ namespace AVQt {
d->m_vao.destroy();
if (d->m_yTexture) {
d->m_yTexture->destroy();
// d->m_yTexture->destroy();
delete d->m_yTexture;
}
if (d->m_uTexture) {
d->m_uTexture->destroy();
// d->m_uTexture->destroy();
delete d->m_uTexture;
}
if (d->m_yTexture) {
d->m_yTexture->destroy();
// d->m_yTexture->destroy();
delete d->m_yTexture;
}
......@@ -361,16 +361,26 @@ namespace AVQt {
}
if (firstFrame) {
d->m_yTexture = new QOpenGLTexture(
QImage(d->m_currentFrame->width, d->m_currentFrame->height, QImage::Format_ARGB32));
d->m_uTexture = new QOpenGLTexture(
QImage(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2, QImage::Format_ARGB32));
d->m_vTexture = new QOpenGLTexture(
QImage(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2, QImage::Format_ARGB32));
d->m_yTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::LinearMipMapLinear);
d->m_uTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::LinearMipMapLinear);
d->m_vTexture->setMinMagFilters(QOpenGLTexture::LinearMipMapLinear, QOpenGLTexture::LinearMipMapLinear);
d->m_yTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
d->m_uTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
d->m_vTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
d->m_yTexture->setSize(d->m_currentFrame->width, d->m_currentFrame->height);
d->m_uTexture->setSize(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2);
d->m_vTexture->setSize(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2);
d->m_yTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
d->m_uTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
d->m_vTexture->setFormat(QOpenGLTexture::RGBA16_UNorm);
d->m_yTexture->allocateStorage(QOpenGLTexture::Red, QOpenGLTexture::UInt16);
d->m_uTexture->allocateStorage(QOpenGLTexture::RG, QOpenGLTexture::UInt16);
d->m_vTexture->allocateStorage(QOpenGLTexture::Red, QOpenGLTexture::UInt16);
// d->m_uTexture = new QOpenGLTexture(
// QImage(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2, QImage::Format_RGBX64));
// d->m_vTexture = new QOpenGLTexture(
// QImage(d->m_currentFrame->width / 2, d->m_currentFrame->height / 2, QImage::Format_RGBX64));
d->m_yTexture->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Nearest);
d->m_uTexture->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Nearest);
d->m_vTexture->setMinMagFilters(QOpenGLTexture::Nearest, QOpenGLTexture::Nearest);
}
// qDebug("Frame duration: %ld ms", d->m_currentFrameTimeout);
if (differentPixFmt) {
......@@ -396,7 +406,7 @@ namespace AVQt {
break;
case AV_PIX_FMT_P010:
d->m_yTexture->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt16, d->m_currentFrame->data[0]);
d->m_uTexture->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt16, d->m_currentFrame->data[1]);
d->m_uTexture->setData(QOpenGLTexture::RG, QOpenGLTexture::UInt16, d->m_currentFrame->data[1]);
if (differentPixFmt) {
d->m_program->setUniformValue("inputFormat", 1);
}
......@@ -410,7 +420,7 @@ namespace AVQt {
}
break;
case AV_PIX_FMT_YUV420P10:
// TODO: Fix crappy and low-res colors with 10bit YUV420P
// TODO: Fix crappy and low-res colors with 10bit YUV420P10LE, caused by data in lsb
d->m_yTexture->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt16, d->m_currentFrame->data[0]);
d->m_uTexture->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt16, d->m_currentFrame->data[1]);
d->m_vTexture->setData(QOpenGLTexture::Red, QOpenGLTexture::UInt16, d->m_currentFrame->data[2]);
......@@ -565,4 +575,4 @@ namespace AVQt {
#undef M
}
}
}
\ No newline at end of file
......@@ -67,7 +67,7 @@ namespace AVQt {
d->m_lastPauseTimestamp = d->m_elapsedTime->nsecsElapsed() / 1000;
}
} else {
if (d->m_elapsedTime) {
if (d->m_elapsedTime && d->m_lastPauseTimestamp >= 0) {
d->m_pausedTime += (d->m_elapsedTime->nsecsElapsed() / 1000) - d->m_lastPauseTimestamp;
}
}
......
......@@ -12,12 +12,11 @@ uniform sampler2D textureV;
uniform int inputFormat;
void main() {
vec3 rgb;
vec2 newTexCoord = vec2(1.0f - texCoord.x, texCoord.y);
if (inputFormat == 0) { // RGB(A)
finalColor = texture(textureY, newTexCoord);
finalColor.a = 1.0;
vec3 rgb = texture(textureY, newTexCoord).rgb;
finalColor = vec4(rgb, 1.0);
} else if (inputFormat == 1) { // YUV 4:2:0 with Y plane interleaved UV plane (e.g. NV12 or P010)
vec3 yuv;
......@@ -29,10 +28,10 @@ void main() {
yuv.y = texture(textureU, newTexCoord.st).r - 0.5;
yuv.z = texture(textureU, newTexCoord.st).g - 0.5;
// The numbers are just YUV to RGB conversion constants
rgb = mat3(1, 1, 1,
vec3 rgb = mat3(1, 1, 1,
0, -0.39465, 2.03211,
1.13983, -0.58060, 0) * yuv;
finalColor = vec4(rgb, 1.0);
finalColor = vec4(rgb, 1.0f);
} else if (inputFormat == 2) { // YUV420P
vec3 yuv;
......@@ -44,23 +43,24 @@ void main() {
yuv.y = texture(textureU, newTexCoord.st).r - 0.5;
yuv.z = texture(textureV, newTexCoord.st).r - 0.5;
// The numbers are just YUV to RGB conversion constants
rgb = mat3(1, 1, 1,
vec3 rgb = mat3(1, 1, 1,
0, -0.39465, 2.03211,
1.13983, -0.58060, 0) * yuv;
finalColor = vec4(rgb, 1.0);
finalColor = vec4(rgb, 1.0f);
} else if (inputFormat == 3) { // YUV420P10
vec3 yuv;
// Multiply every value with 2^6 = 64, because the values are stored in the lower 10 bits,
// but have to be in the upper 10 bits for correct calculation
// We had put the Y values of each pixel to the R component of every texture by using GL_RED
yuv.x = texture(textureY, newTexCoord.st).r * 32 - 0.0625;
yuv.y = texture(textureU, newTexCoord.st).r * 32 - 0.5;
yuv.z = texture(textureV, newTexCoord.st).r * 32 - 0.5;
yuv.x = texture(textureY, newTexCoord.st).r * 64 - 0.0625;
yuv.y = texture(textureU, newTexCoord.st).r * 64 - 0.5;
yuv.z = texture(textureV, newTexCoord.st).r * 64 - 0.5;
// The numbers are just YUV to RGB conversion constants
rgb = mat3(1, 1, 1,
vec3 rgb = mat3(1, 1, 1,
0, -0.39465, 2.03211,
1.13983, -0.58060, 0) * yuv;
finalColor = vec4(rgb, 1.0);
}
}
}
\ No newline at end of file
......@@ -57,11 +57,11 @@ int main(int argc, char *argv[]) {
inputFile->open(QIODevice::ReadOnly);
AVQt::Demuxer demuxer(inputFile);
AVQt::AudioDecoder decoder;
AVQt::OpenALAudioOutput output;
// AVQt::AudioDecoder decoder;
// AVQt::OpenALAudioOutput output;
demuxer.registerCallback(&decoder, AVQt::IPacketSource::CB_AUDIO);
decoder.registerCallback(&output);
// demuxer.registerCallback(&decoder, AVQt::IPacketSource::CB_AUDIO);
// decoder.registerCallback(&output);
AVQt::DecoderVAAPI decoderVaapi;
AVQt::OpenGLRenderer renderer;
......@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
demuxer.init();
output.syncToOutput(&renderer);
// output.syncToOutput(&renderer);
demuxer.start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment