From 6300d0810744d1b96ed71c20c06cef4d7a088eb5 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Thu, 23 Apr 2020 01:15:01 -0400 Subject: [PATCH] Convert to std::array and std::string. (mythframe and opengl) --- mythtv/libs/libmythtv/DetectLetterbox.cpp | 4 +- mythtv/libs/libmythtv/mythavutil.cpp | 8 +- mythtv/libs/libmythtv/mythframe.h | 81 +++++++++---------- .../libmythtv/opengl/mythopengltonemap.cpp | 1 + .../libs/libmythtv/opengl/mythopenglvideo.cpp | 38 ++++----- .../libs/libmythtv/opengl/mythopenglvideo.h | 6 +- .../test/test_copyframes/test_copyframes.h | 60 +++++++------- .../visualisations/videovisualgoom.cpp | 3 +- .../libs/libmythui/opengl/mythpainteropengl.h | 2 +- .../libmythui/opengl/mythrenderopengl.cpp | 24 ++++-- .../libs/libmythui/opengl/mythrenderopengl.h | 9 ++- mythtv/programs/mythtranscode/transcode.cpp | 2 +- 12 files changed, 123 insertions(+), 115 deletions(-) diff --git a/mythtv/libs/libmythtv/DetectLetterbox.cpp b/mythtv/libs/libmythtv/DetectLetterbox.cpp index f5a8db668b8..568521c435d 100644 --- a/mythtv/libs/libmythtv/DetectLetterbox.cpp +++ b/mythtv/libs/libmythtv/DetectLetterbox.cpp @@ -35,8 +35,8 @@ void DetectLetterbox::Detect(VideoFrame *Frame) return; unsigned char *buf = Frame->buf; - int *pitches = Frame->pitches; - int *offsets = Frame->offsets; + const FramePitches pitches = Frame->pitches; + const FrameOffsets offsets = Frame->offsets; const int height = Frame->height; // If the black bars is larger than this limit we switch to Half or Full Mode diff --git a/mythtv/libs/libmythtv/mythavutil.cpp b/mythtv/libs/libmythtv/mythavutil.cpp index 0d9b93951ff..2781b6bbd74 100644 --- a/mythtv/libs/libmythtv/mythavutil.cpp +++ b/mythtv/libs/libmythtv/mythavutil.cpp @@ -268,18 +268,18 @@ void MythAVCopy::FillFrame(VideoFrame *frame, const AVFrame *pic, int pitch, { int chroma_pitch = pitch >> 1; int chroma_height = height >> 1; - int offsets[3] = + FrameOffsets offsets { 0, pitch * height, pitch * height + chroma_pitch * chroma_height }; - int pitches[3] = { pitch, chroma_pitch, chroma_pitch }; + FramePitches pitches { pitch, chroma_pitch, chroma_pitch }; init(frame, FMT_YV12, pic->data[0], width, height, size, pitches, offsets); } else if (pix_fmt == AV_PIX_FMT_NV12) { - int offsets[3] = { 0, pitch * height, 0 }; - int pitches[3] = { pitch, pitch, 0 }; + FrameOffsets offsets { 0, pitch * height, 0 }; + FramePitches pitches { pitch, pitch, 0 }; init(frame, FMT_NV12, pic->data[0], width, height, size, pitches, offsets); } diff --git a/mythtv/libs/libmythtv/mythframe.h b/mythtv/libs/libmythtv/mythframe.h index 2dab9d9bc63..17285b8a8e4 100644 --- a/mythtv/libs/libmythtv/mythframe.h +++ b/mythtv/libs/libmythtv/mythframe.h @@ -1,13 +1,11 @@ #ifndef MYTHFRAME_H #define MYTHFRAME_H -#ifdef __cplusplus +#include #include #include -#else -#include -#include -#endif +#include + #include "mythtvexp.h" // for MTV_PUBLIC #include "mythaverror.h" @@ -15,10 +13,6 @@ extern "C" { #include "libavcodec/avcodec.h" } -#ifdef __cplusplus -extern "C" { -#endif - #define MYTH_WIDTH_ALIGNMENT 64 #define MYTH_HEIGHT_ALIGNMENT 16 enum VideoFrameType @@ -134,6 +128,9 @@ inline MythDeintType operator| (MythDeintType a, MythDeintType b) { return stati inline MythDeintType operator& (MythDeintType a, MythDeintType b) { return static_cast(static_cast(a) & static_cast(b)); } inline MythDeintType operator~ (MythDeintType a) { return static_cast(~(static_cast(a))); } +using FramePitches = std::array; +using FrameOffsets = std::array; + struct VideoFrame { VideoFrameType codec; @@ -149,7 +146,7 @@ struct VideoFrame long long frameCounter; ///< raw frame counter/ticker for discontinuity checks long long timecode; int64_t disp_timecode; - unsigned char *priv[4]; ///< random empty storage + std::array priv; ///< random empty storage int interlaced_frame; ///< 1 if interlaced. 0 if not interlaced. -1 if unknown. bool top_field_first; ///< true if top field is first. bool interlaced_reversed; /// true for user override of scan @@ -158,8 +155,8 @@ struct VideoFrame bool forcekey; ///< hardware encoded .nuv bool dummy; bool pause_frame; - int pitches[3]; ///< Y, U, & V pitches - int offsets[3]; ///< Y, U, & V offsets + FramePitches pitches; ///< Y, U, & V pitches + FrameOffsets offsets; ///< Y, U, & V offsets int pix_fmt; int sw_pix_fmt; bool directrendering; ///< true if managed by FFmpeg @@ -180,14 +177,8 @@ struct VideoFrame using VideoFrameVec = std::vector; -#ifdef __cplusplus -} -#endif - int MTV_PUBLIC ColorDepth(int Format); -#ifdef __cplusplus - MythDeintType MTV_PUBLIC GetSingleRateOption(const VideoFrame* Frame, MythDeintType Type, MythDeintType Override = DEINT_NONE); MythDeintType MTV_PUBLIC GetDoubleRateOption(const VideoFrame* Frame, MythDeintType Type, MythDeintType Override = DEINT_NONE); MythDeintType MTV_PUBLIC GetDeinterlacer(MythDeintType Option); @@ -220,21 +211,21 @@ class MTV_PUBLIC MythUSWCCopy void MTV_PUBLIC framecopy(VideoFrame *dst, const VideoFrame *src, bool useSSE = true); -static inline void init(VideoFrame *vf, VideoFrameType _codec, - unsigned char *_buf, int _width, int _height, int _size, - const int *p = nullptr, - const int *o = nullptr, - float _aspect = -1.0F, double _rate = -1.0F, - int _aligned = MYTH_WIDTH_ALIGNMENT); -static inline void clear(VideoFrame *vf); static inline int bitsperpixel(VideoFrameType type); static inline int pitch_for_plane(VideoFrameType Type, int Width, uint Plane); static inline int height_for_plane(VideoFrameType Type, int Height, uint Plane); +using mavtriplet = std::array; +using mavtripletptr = mavtriplet::const_pointer; + static inline void init(VideoFrame *vf, VideoFrameType _codec, unsigned char *_buf, int _width, int _height, - int _size, const int *p, const int *o, - float _aspect, double _rate, int _aligned) + int _size, + const FramePitches p, + const FrameOffsets o, + bool arrays_valid = true, + float _aspect = -1.0F, double _rate = -1.0F, + int _aligned = MYTH_WIDTH_ALIGNMENT) { vf->bpp = bitsperpixel(_codec); vf->codec = _codec; @@ -271,7 +262,7 @@ static inline void init(VideoFrame *vf, VideoFrameType _codec, vf->deinterlace_allowed = DEINT_NONE; vf->deinterlace_inuse = DEINT_NONE; vf->deinterlace_inuse2x = false; - memset(vf->priv, 0, 4 * sizeof(unsigned char *)); + vf->priv.fill(nullptr); int width_aligned = 0; int height_aligned = (_height + MYTH_HEIGHT_ALIGNMENT - 1) & ~(MYTH_HEIGHT_ALIGNMENT -1); @@ -280,9 +271,9 @@ static inline void init(VideoFrame *vf, VideoFrameType _codec, else width_aligned = (_width + _aligned - 1) & ~(_aligned - 1); - if (p) + if (arrays_valid) { - memcpy(vf->pitches, p, 3 * sizeof(int)); + vf->pitches = p; } else { @@ -290,9 +281,9 @@ static inline void init(VideoFrame *vf, VideoFrameType _codec, vf->pitches[i] = pitch_for_plane(_codec, width_aligned, i); } - if (o) + if (arrays_valid) { - memcpy(vf->offsets, o, 3 * sizeof(int)); + vf->offsets = o; } else { @@ -344,6 +335,15 @@ static inline void init(VideoFrame *vf, VideoFrameType _codec, } } +static inline void init(VideoFrame *vf, VideoFrameType _codec, + unsigned char *_buf, int _width, int _height, int _size, + float _aspect = -1.0F, double _rate = -1.0F, + int _aligned = MYTH_WIDTH_ALIGNMENT) +{ + init(vf, _codec, _buf, _width, _height, _size, {}, {}, false, + _aspect, _rate, _aligned); +} + static inline int pitch_for_plane(VideoFrameType Type, int Width, uint Plane) { switch (Type) @@ -708,11 +708,11 @@ static inline void copybuffer(VideoFrame *dst, uint8_t *buffer, VideoFrame framein {}; int chroma_pitch = pitch >> 1; int chroma_height = dst->height >> 1; - int offsets[3] = + FrameOffsets offsets { 0, pitch * dst->height, pitch * dst->height + chroma_pitch * chroma_height }; - int pitches[3] = { pitch, chroma_pitch, chroma_pitch }; + FramePitches pitches { pitch, chroma_pitch, chroma_pitch }; init(&framein, type, buffer, dst->width, dst->height, dst->size, pitches, offsets); @@ -721,8 +721,8 @@ static inline void copybuffer(VideoFrame *dst, uint8_t *buffer, else if (type == FMT_NV12) { VideoFrame framein {}; - int offsets[3] = { 0, pitch * dst->height, 0 }; - int pitches[3] = { pitch, pitch, 0 }; + FrameOffsets offsets { 0, pitch * dst->height, 0 }; + FramePitches pitches { pitch, pitch, 0 }; init(&framein, type, buffer, dst->width, dst->height, dst->size, pitches, offsets); @@ -741,11 +741,11 @@ static inline void copybuffer(uint8_t *dstbuffer, const VideoFrame *src, VideoFrame frameout {}; int chroma_pitch = pitch >> 1; int chroma_height = src->height >> 1; - int offsets[3] = + FrameOffsets offsets { 0, pitch * src->height, pitch * src->height + chroma_pitch * chroma_height }; - int pitches[3] = { pitch, chroma_pitch, chroma_pitch }; + FramePitches pitches { pitch, chroma_pitch, chroma_pitch }; init(&frameout, type, dstbuffer, src->width, src->height, src->size, pitches, offsets); @@ -754,14 +754,13 @@ static inline void copybuffer(uint8_t *dstbuffer, const VideoFrame *src, else if (type == FMT_NV12) { VideoFrame frameout {}; - int offsets[3] = { 0, pitch * src->height, 0 }; - int pitches[3] = { pitch, pitch, 0 }; + FrameOffsets offsets { 0, pitch * src->height, 0 }; + FramePitches pitches { pitch, pitch, 0 }; init(&frameout, type, dstbuffer, src->width, src->height, src->size, pitches, offsets); copy(&frameout, src); } } -#endif /* __cplusplus */ #endif /* MYTHFRAME_H */ diff --git a/mythtv/libs/libmythtv/opengl/mythopengltonemap.cpp b/mythtv/libs/libmythtv/opengl/mythopengltonemap.cpp index 6dc84f5e632..a4fcea871e8 100644 --- a/mythtv/libs/libmythtv/opengl/mythopengltonemap.cpp +++ b/mythtv/libs/libmythtv/opengl/mythopengltonemap.cpp @@ -100,6 +100,7 @@ MythVideoTexture* MythOpenGLTonemap::Map(vector &Inputs, QSi return nullptr; } m_render->glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_storageBuffer); + // Data structure passed to kernel. NOLINTNEXTLINE(modernize-avoid-c-arrays) struct dummy { float a[2] {0.0F}; uint32_t b {0}; uint32_t c {0}; uint32_t d {0}; } buffer; m_render->glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(dummy), &buffer, GL_STREAM_COPY); m_render->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); diff --git a/mythtv/libs/libmythtv/opengl/mythopenglvideo.cpp b/mythtv/libs/libmythtv/opengl/mythopenglvideo.cpp index 17c7fcdef9d..f3b9a7a2701 100644 --- a/mythtv/libs/libmythtv/opengl/mythopenglvideo.cpp +++ b/mythtv/libs/libmythtv/opengl/mythopenglvideo.cpp @@ -563,8 +563,8 @@ void MythOpenGLVideo::ResetFrameFormat(void) for (auto & shader : m_shaders) if (shader) m_render->DeleteShaderProgram(shader); - memset(m_shaders, 0, sizeof(m_shaders)); - memset(m_shaderCost, 1, sizeof(m_shaderCost)); + m_shaders.fill(nullptr); + m_shaderCost.fill(1); MythVideoTexture::DeleteTextures(m_render, m_inputTextures); MythVideoTexture::DeleteTextures(m_render, m_prevTextures); MythVideoTexture::DeleteTextures(m_render, m_nextTextures); @@ -659,21 +659,19 @@ void MythOpenGLVideo::ProcessFrame(VideoFrame *Frame, FrameScanType Scan) if (m_deinterlacer == DEINT_BASIC) { // first field. Fake the pitches - int pitches[3]; - memcpy(pitches, Frame->pitches, sizeof(int) * 3); + FramePitches pitches = Frame->pitches; Frame->pitches[0] = Frame->pitches[0] << 1; Frame->pitches[1] = Frame->pitches[1] << 1; Frame->pitches[2] = Frame->pitches[2] << 1; MythVideoTexture::UpdateTextures(m_render, Frame, m_inputTextures); // second field. Fake the offsets as well. - int offsets[3]; - memcpy(offsets, Frame->offsets, sizeof(int) * 3); + FrameOffsets offsets = Frame->offsets; Frame->offsets[0] = Frame->offsets[0] + pitches[0]; Frame->offsets[1] = Frame->offsets[1] + pitches[1]; Frame->offsets[2] = Frame->offsets[2] + pitches[2]; MythVideoTexture::UpdateTextures(m_render, Frame, m_nextTextures); - memcpy(Frame->pitches, pitches, sizeof(int) * 3); - memcpy(Frame->offsets, offsets, sizeof(int) * 3); + Frame->pitches = pitches; + Frame->offsets = offsets; } else { @@ -941,12 +939,11 @@ void MythOpenGLVideo::PrepareFrame(VideoFrame *Frame, bool TopFieldFirst, FrameS m_render->SetViewPort(vrect); // bind correct textures - MythGLTexture* textures[MAX_VIDEO_TEXTURES]; - uint numtextures = 0; - BindTextures(deinterlacing, inputtextures, &textures[0], numtextures); + vector textures {}; + BindTextures(deinterlacing, inputtextures, textures); // render - m_render->DrawBitmap(textures, numtextures, m_frameBuffer, + m_render->DrawBitmap(textures, m_frameBuffer, trect2, vrect, m_shaders[program], 0); nexttexture = m_frameBufferTexture; } @@ -982,9 +979,8 @@ void MythOpenGLVideo::PrepareFrame(VideoFrame *Frame, bool TopFieldFirst, FrameS } // bind correct textures - MythGLTexture* textures[MAX_VIDEO_TEXTURES]; - uint numtextures = 0; - BindTextures(deinterlacing, inputtextures, &textures[0], numtextures); + vector textures; + BindTextures(deinterlacing, inputtextures, textures); // rotation if (Frame) @@ -1000,7 +996,7 @@ void MythOpenGLVideo::PrepareFrame(VideoFrame *Frame, bool TopFieldFirst, FrameS } // draw - m_render->DrawBitmap(textures, numtextures, nullptr, trect, + m_render->DrawBitmap(textures, nullptr, trect, m_displayVideoRect, m_shaders[program], m_lastRotation); // disable scissoring @@ -1023,7 +1019,7 @@ void MythOpenGLVideo::ResetTextures(void) } void MythOpenGLVideo::BindTextures(bool Deinterlacing, vector &Current, - MythGLTexture **Textures, uint &TextureCount) + vector&Textures) { bool usecurrent = true; if (Deinterlacing) @@ -1042,17 +1038,17 @@ void MythOpenGLVideo::BindTextures(bool Deinterlacing, vector vector &prev = m_prevTextures[0]->m_valid ? m_prevTextures : current; for (uint i = 0; i < count; ++i) - Textures[TextureCount++] = reinterpret_cast(prev[i]); + Textures.push_back(reinterpret_cast(prev[i])); for (uint i = 0; i < count; ++i) - Textures[TextureCount++] = reinterpret_cast(current[i]); + Textures.push_back(reinterpret_cast(current[i])); for (uint i = 0; i < count; ++i) - Textures[TextureCount++] = reinterpret_cast(m_nextTextures[i]); + Textures.push_back(reinterpret_cast(m_nextTextures[i])); } } if (usecurrent) for (auto & texture : Current) - Textures[TextureCount++] = reinterpret_cast(texture); + Textures.push_back(reinterpret_cast(texture)); } QString MythOpenGLVideo::TypeToProfile(VideoFrameType Type) diff --git a/mythtv/libs/libmythtv/opengl/mythopenglvideo.h b/mythtv/libs/libmythtv/opengl/mythopenglvideo.h index 2528f968a08..a135a2f3b2f 100644 --- a/mythtv/libs/libmythtv/opengl/mythopenglvideo.h +++ b/mythtv/libs/libmythtv/opengl/mythopenglvideo.h @@ -81,7 +81,7 @@ class MythOpenGLVideo : public QObject QSize Size, GLenum TextureTarget); bool CreateVideoShader(VideoShaderType Type, MythDeintType Deint = DEINT_NONE); void BindTextures(bool Deinterlacing, vector &Current, - MythGLTexture** Textures, uint &TextureCount); + vector&Textures); bool AddDeinterlacer(const VideoFrame *Frame, FrameScanType Scan, MythDeintType Filter = DEINT_SHADER, bool CreateReferences = true); QOpenGLFramebufferObject* CreateVideoFrameBuffer(VideoFrameType OutputType, QSize Size); @@ -103,8 +103,8 @@ class MythOpenGLVideo : public QObject MythDeintType m_fallbackDeinterlacer { MythDeintType::DEINT_NONE }; ///< Only used if there are insufficient texture units (for kernel) VideoColourSpace *m_videoColourSpace; bool m_viewportControl; ///< Video has control over view port - QOpenGLShaderProgram* m_shaders[ShaderCount] { nullptr }; - int m_shaderCost[ShaderCount] { 1 }; + std::array m_shaders { nullptr }; + std::array m_shaderCost { 1 }; vector m_inputTextures; ///< Current textures with raw video data vector m_prevTextures; ///< Previous textures with raw video data vector m_nextTextures; ///< Next textures with raw video data diff --git a/mythtv/libs/libmythtv/test/test_copyframes/test_copyframes.h b/mythtv/libs/libmythtv/test/test_copyframes/test_copyframes.h index 9816dcd1c43..162e129af83 100644 --- a/mythtv/libs/libmythtv/test/test_copyframes/test_copyframes.h +++ b/mythtv/libs/libmythtv/test/test_copyframes/test_copyframes.h @@ -58,7 +58,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_YV12, bufsrc, WIDTH, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); @@ -83,7 +83,7 @@ class TestCopyFrames: public QObject auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; // test the stride sizes QCOMPARE(stride2, dst.pitches[0]); @@ -148,7 +148,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -169,7 +169,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); QBENCHMARK { @@ -225,7 +225,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -246,7 +246,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride2, dst.pitches[0]); QCOMPARE(stride2 / 2, dst.pitches[1]); @@ -306,7 +306,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -327,7 +327,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride2, dst.pitches[0]); @@ -388,7 +388,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -409,7 +409,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST /* align */); + 0, 0, ALIGNDST /* align */); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); QCOMPARE(stride / 2, dst.pitches[1]); @@ -469,7 +469,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -490,7 +490,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); @@ -552,7 +552,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -573,7 +573,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); @@ -636,7 +636,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_NV12, bufsrc, width, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (width + ALIGN - 1) & ~(ALIGN -1) : width; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -657,7 +657,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, width, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, width, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); QBENCHMARK { @@ -706,7 +706,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_YV12, bufsrc, WIDTH, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); @@ -731,7 +731,7 @@ class TestCopyFrames: public QObject auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; // test the stride sizes QCOMPARE(stride2, dst.pitches[0]); @@ -799,7 +799,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -820,7 +820,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride2, dst.pitches[0]); QCOMPARE(stride2 / 2, dst.pitches[1]); @@ -882,7 +882,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -903,7 +903,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride2 = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride2, dst.pitches[0]); @@ -966,7 +966,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -987,7 +987,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST /* align */); + 0, 0, ALIGNDST /* align */); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); QCOMPARE(stride / 2, dst.pitches[1]); @@ -1049,7 +1049,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -1070,7 +1070,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); @@ -1134,7 +1134,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_NV12, WIDTH, HEIGHT, ALIGN)); init(&src, FMT_NV12, bufsrc + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGN), - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[0]); QCOMPARE(ALIGN ? (WIDTH + ALIGN - 1) & ~(ALIGN -1) : WIDTH , src.pitches[1]); @@ -1155,7 +1155,7 @@ class TestCopyFrames: public QObject (unsigned char*)av_malloc(GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST)); init(&dst, FMT_YV12, bufdst + 1, WIDTH, HEIGHT, GetBufferSize(FMT_YV12, WIDTH, HEIGHT, ALIGNDST), - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); int stride = ALIGNDST ? (WIDTH + ALIGNDST - 1) & ~(ALIGNDST -1) : WIDTH; QCOMPARE(stride, dst.pitches[0]); @@ -1220,7 +1220,7 @@ class TestCopyFrames: public QObject auto* bufsrc = (unsigned char*)av_malloc(sizesrc); init(&src, FMT_NV12, bufsrc, width, HEIGHT, sizesrc, - nullptr, nullptr, 0, 0, ALIGN); + 0, 0, ALIGN); int stride = ALIGN ? (width + ALIGN - 1) & ~(ALIGN -1) : width; QCOMPARE(stride, src.pitches[0]); QCOMPARE(stride, src.pitches[1]); @@ -1241,7 +1241,7 @@ class TestCopyFrames: public QObject int sizedst = GetBufferSize(FMT_YV12, width, HEIGHT, ALIGNDST); auto* bufdst = (unsigned char*)av_malloc(sizedst); init(&dst, FMT_YV12, bufdst, width, HEIGHT, sizedst, - nullptr, nullptr, 0, 0, ALIGNDST); + 0, 0, ALIGNDST); QBENCHMARK { diff --git a/mythtv/libs/libmythtv/visualisations/videovisualgoom.cpp b/mythtv/libs/libmythtv/visualisations/videovisualgoom.cpp index 6c6519e203d..01b3af55b18 100644 --- a/mythtv/libs/libmythtv/visualisations/videovisualgoom.cpp +++ b/mythtv/libs/libmythtv/visualisations/videovisualgoom.cpp @@ -92,7 +92,8 @@ void VideoVisualGoom::Draw(const QRect &area, MythPainter */*painter*/, // goom doesn't render properly due to changes in video alpha blending // so turn blend off glrender->SetBlend(false); - glrender->DrawBitmap(&m_glSurface, 1, nullptr, m_area, area, nullptr, 0); + std::vector surfaces {m_glSurface}; + glrender->DrawBitmap(surfaces, nullptr, m_area, area, nullptr, 0); glrender->SetBlend(true); } glrender->doneCurrent(); diff --git a/mythtv/libs/libmythui/opengl/mythpainteropengl.h b/mythtv/libs/libmythui/opengl/mythpainteropengl.h index 8b696417784..3653094f6a3 100644 --- a/mythtv/libs/libmythui/opengl/mythpainteropengl.h +++ b/mythtv/libs/libmythui/opengl/mythpainteropengl.h @@ -74,7 +74,7 @@ class MUI_PUBLIC MythOpenGLPainter : public MythPainter QMutex m_textureDeleteLock; QVector m_mappedTextures; - QOpenGLBuffer* m_mappedBufferPool[MAX_BUFFER_POOL] { nullptr }; + std::array m_mappedBufferPool { nullptr }; int m_mappedBufferPoolIdx { 0 }; bool m_mappedBufferPoolReady { false }; }; diff --git a/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp b/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp index 9b4be54dc94..3fed68adfb1 100644 --- a/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp +++ b/mythtv/libs/libmythui/opengl/mythrenderopengl.cpp @@ -824,12 +824,16 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture *Texture, QOpenGLFramebufferObje { void* target = buffer->map(QOpenGLBuffer::WriteOnly); if (target) - memcpy(target, Texture->m_vertexData, kVertexSize); + { + std::copy(Texture->m_vertexData.cbegin(), + Texture->m_vertexData.cend(), + static_cast(target)); + } buffer->unmap(); } else { - buffer->write(0, Texture->m_vertexData, kVertexSize); + buffer->write(0, Texture->m_vertexData.data(), kVertexSize); } } @@ -845,13 +849,13 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture *Texture, QOpenGLFramebufferObje doneCurrent(); } -void MythRenderOpenGL::DrawBitmap(MythGLTexture **Textures, uint TextureCount, +void MythRenderOpenGL::DrawBitmap(std::vector &Textures, QOpenGLFramebufferObject *Target, const QRect &Source, const QRect &Destination, QOpenGLShaderProgram *Program, int Rotation) { - if (!Textures || !TextureCount) + if (Textures.empty()) return; makeCurrent(); @@ -867,7 +871,7 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture **Textures, uint TextureCount, SetShaderProjection(Program); GLenum textarget = first->m_target; - for (uint i = 0; i < TextureCount; i++) + for (uint i = 0; i < Textures.size(); i++) { QString uniform = QString("s_texture%1").arg(i); Program->setUniformValue(qPrintable(uniform), i); @@ -886,12 +890,16 @@ void MythRenderOpenGL::DrawBitmap(MythGLTexture **Textures, uint TextureCount, { void* target = buffer->map(QOpenGLBuffer::WriteOnly); if (target) - memcpy(target, first->m_vertexData, kVertexSize); + { + std::copy(first->m_vertexData.cbegin(), + first->m_vertexData.cend(), + static_cast(target)); + } buffer->unmap(); } else { - buffer->write(0, first->m_vertexData, kVertexSize); + buffer->write(0, first->m_vertexData.data(), kVertexSize); } } @@ -1266,7 +1274,7 @@ bool MythRenderOpenGL::UpdateTextureVertices(MythGLTexture *Texture, const QRect Texture->m_destination = Destination; Texture->m_rotation = Rotation; - GLfloat *data = Texture->m_vertexData; + GLfloat *data = Texture->m_vertexData.data(); QSize size = Texture->m_size; int width = Texture->m_crop ? min(Source.width(), size.width()) : Source.width(); diff --git a/mythtv/libs/libmythui/opengl/mythrenderopengl.h b/mythtv/libs/libmythui/opengl/mythrenderopengl.h index c9a88db3a45..57004ad9065 100644 --- a/mythtv/libs/libmythui/opengl/mythrenderopengl.h +++ b/mythtv/libs/libmythui/opengl/mythrenderopengl.h @@ -1,6 +1,9 @@ #ifndef MYTHRENDER_OPENGL_H_ #define MYTHRENDER_OPENGL_H_ +// C++ +#include + // Qt #include #include @@ -69,7 +72,7 @@ class MUI_PUBLIC MythGLTexture bool m_crop { false }; QRect m_source { QRect() }; QRect m_destination { QRect() }; - GLfloat m_vertexData[16] { 0.0F }; + std::array m_vertexData { 0.0F }; GLenum m_target { QOpenGLTexture::Target2D }; int m_rotation { 0 }; @@ -152,7 +155,7 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio void DrawBitmap(MythGLTexture *Texture, QOpenGLFramebufferObject *Target, const QRect &Source, const QRect &Destination, QOpenGLShaderProgram *Program, int Alpha = 255, qreal Scale = 1.0); - void DrawBitmap(MythGLTexture **Textures, uint TextureCount, + void DrawBitmap(std::vector &Textures, QOpenGLFramebufferObject *Target, const QRect &Source, const QRect &Destination, QOpenGLShaderProgram *Program, int Rotation); @@ -203,7 +206,7 @@ class MUI_PUBLIC MythRenderOpenGL : public QOpenGLContext, public QOpenGLFunctio GLuint m_fence { 0 }; // Shaders - QOpenGLShaderProgram* m_defaultPrograms[kShaderCount] { nullptr }; + std::array m_defaultPrograms { nullptr }; QOpenGLShaderProgram* m_activeProgram { nullptr }; // Vertices diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp index f219eeeb771..2f7edb06d9f 100644 --- a/mythtv/programs/mythtranscode/transcode.cpp +++ b/mythtv/programs/mythtranscode/transcode.cpp @@ -881,7 +881,7 @@ int Transcode::TranscodeFile(const QString &inputname, { // Set a stride identical to actual width, to ease fifo post-conversion process. init(&frame, FMT_YV12, newFrame, video_width, video_height, - static_cast(newSize), nullptr, nullptr, -1, -1, 0 /* aligned */); + static_cast(newSize), {}, {}, -1, -1, 0 /* aligned */); } else {