Skip to content

Commit

Permalink
Update gl_videorenderer.cpp
Browse files Browse the repository at this point in the history
Update avcodec_decoder.cpp
  • Loading branch information
raphaelscholle committed Mar 1, 2025
1 parent a9ef608 commit 986e075
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 21 deletions.
29 changes: 19 additions & 10 deletions app/videostreaming/avcodec/avcodec_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

#include "ExternalDecodeService.hpp"

static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type){
static int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type) {
int err = 0;
ctx->hw_frames_ctx = NULL;
// ctx->hw_device_ctx gets freed when we call avcodec_free_context
if ((err = av_hwdevice_ctx_create(&ctx->hw_device_ctx, type,
NULL, NULL, 0)) < 0) {
fprintf(stderr, "Failed to create specified HW device.\n");
if ((err = av_hwdevice_ctx_create(&ctx->hw_device_ctx, type, NULL, NULL, 0)) < 0) {
char errbuf[128];
av_strerror(err, errbuf, sizeof(errbuf));
fprintf(stderr, "Failed to create HW device (%s): %s\n", av_hwdevice_get_type_name(type), errbuf);
return err;
}
qDebug() << "HW device created: " << av_hwdevice_get_type_name(type);
return err;
}

Expand Down Expand Up @@ -353,11 +354,11 @@ void AVCodecDecoder::on_new_frame(AVFrame *frame)
std::stringstream ss;
ss<<safe_av_get_pix_fmt_name((AVPixelFormat)frame->format)<<" "<<frame->width<<"x"<<frame->height;
DecodingStatistcs::instance().set_primary_stream_frame_format(QString(ss.str().c_str()));
//qDebug()<<"Got frame:"<<ss.str().c_str();
// qDebug()<<"Got frame:"<<ss.str().c_str();
}
// Once we got the first frame, reduce the log level
av_log_set_level(AV_LOG_WARNING);
//qDebug()<<debug_frame(frame).c_str();
// qDebug()<<debug_frame(frame).c_str();
TextureRenderer::instance().queue_new_frame_for_display(frame);
if(last_frame_width==-1 || last_frame_height==-1){
last_frame_width=frame->width;
Expand Down Expand Up @@ -508,14 +509,21 @@ int AVCodecDecoder::open_and_decode_until_error(const QOpenHDVideoHelper::VideoS
return 0;
}

const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_DRM;
#ifdef _WIN32
const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_D3D11VA;
#else
const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_DRM;
#endif

//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_D3D11VA;
//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_DXVA2;
//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_DRM;
//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_VAAPI;
//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_CUDA;
//const AVHWDeviceType kAvhwDeviceType = AV_HWDEVICE_TYPE_VDPAU;

bool is_mjpeg=false;
if (decoder->id == AV_CODEC_ID_H264) {
qDebug()<<"H264 decode";
qDebug()<<all_hw_configs_for_this_codec(decoder).c_str();
if(!stream_config.enable_software_video_decoder){
// weird workaround needed for pi + DRM_PRIME
Expand Down Expand Up @@ -719,7 +727,8 @@ void AVCodecDecoder::open_and_decode_until_error_custom_rtp(const QOpenHDVideoHe
wanted_hw_pix_fmt = AV_PIX_FMT_MMAL;
use_pi_hw_decode=true;
}else{
wanted_hw_pix_fmt = AV_PIX_FMT_YUV420P;
qDebug()<<"Starting HW decode";
wanted_hw_pix_fmt = AV_PIX_FMT_DXVA2_VLD;
}
}else{
wanted_hw_pix_fmt = AV_PIX_FMT_YUV420P;
Expand Down
73 changes: 62 additions & 11 deletions app/videostreaming/avcodec/gl/gl_videorenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../avcodec_helper.hpp"
#include <libavutil/error.h>
#include <vector>
#include <cmath> // For dithering calculations

static EGLint texgen_attrs[] = {
EGL_DMA_BUF_PLANE0_FD_EXT,
Expand Down Expand Up @@ -357,18 +358,68 @@ static std::string safe_glGetString(GLenum name){
return std::string((const char*)tmp); // NOLINT(modernize-return-braced-init-list)
}
std::string GL_VideoRenderer::debug_info() {
const auto gl_vendor= safe_glGetString(GL_VENDOR);
const auto gl_renderer= safe_glGetString(GL_RENDERER);
const auto gl_version= safe_glGetString(GL_VERSION);
const auto gl_shading_language_version= safe_glGetString(GL_SHADING_LANGUAGE_VERSION);
std::stringstream ss;
ss<<"GL_VENDOR : "<< gl_vendor<<"\n";
ss<<"GL_RENDERER : "<< gl_renderer<<"\n";
ss<<"GL_VERSION : "<< gl_version<<"\n";
ss<<"GL_SHADING_LANGUAGE_VERSION : "<< gl_shading_language_version<<"\n";
return ss.str();
}
const auto gl_vendor = safe_glGetString(GL_VENDOR);
const auto gl_renderer = safe_glGetString(GL_RENDERER);
const auto gl_version = safe_glGetString(GL_VERSION);
const auto gl_shading_language_version = safe_glGetString(GL_SHADING_LANGUAGE_VERSION);
std::stringstream ss;

// Basic OpenGL Information
ss << "GL_VENDOR : " << gl_vendor << "\n";
ss << "GL_RENDERER : " << gl_renderer << "\n";
ss << "GL_VERSION : " << gl_version << "\n";
ss << "GL_SHADING_LANGUAGE_VERSION : " << gl_shading_language_version << "\n";

// Maximum texture size
GLint maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
ss << "GL_MAX_TEXTURE_SIZE : " << maxTextureSize << "\n";

// Maximum texture units
GLint maxTextureUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
ss << "GL_MAX_TEXTURE_IMAGE_UNITS : " << maxTextureUnits << "\n";

// Extensions
std::string extensions = (const char*)glGetString(GL_EXTENSIONS);
ss << "Supported Extensions:\n" << extensions << "\n";

if (extensions.find("GL_OES_texture_float") != std::string::npos) {
ss << "Supports GL_OES_texture_float\n";
} else {
ss << "Does not support GL_OES_texture_float\n";
}

if (extensions.find("GL_OES_texture_half_float") != std::string::npos) {
ss << "Supports GL_OES_texture_half_float\n";
} else {
ss << "Does not support GL_OES_texture_half_float\n";
}

if (extensions.find("GL_EXT_color_buffer_half_float") != std::string::npos) {
ss << "Supports GL_EXT_color_buffer_half_float\n";
} else {
ss << "Does not support GL_EXT_color_buffer_half_float\n";
}

// Shader precision
GLint precisionRange[2];
GLint precisionBits;

glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, precisionRange, &precisionBits);
ss << "Fragment Shader High Float Precision: Range [" << precisionRange[0] << ", " << precisionRange[1]
<< "], Bits: " << precisionBits << "\n";

glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, precisionRange, &precisionBits);
ss << "Fragment Shader Medium Float Precision: Range [" << precisionRange[0] << ", " << precisionRange[1]
<< "], Bits: " << precisionBits << "\n";

glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_LOW_FLOAT, precisionRange, &precisionBits);
ss << "Fragment Shader Low Float Precision: Range [" << precisionRange[0] << ", " << precisionRange[1]
<< "], Bits: " << precisionBits << "\n";

return ss.str();
}

std::vector<int> GL_VideoRenderer::supported_av_hw_formats()
{
Expand Down

0 comments on commit 986e075

Please sign in to comment.