Skip to content

Commit

Permalink
tidy: Convert some macros to constexpr. (libmythtv 2)
Browse files Browse the repository at this point in the history
This converts the values from untyped to typed.
  • Loading branch information
linuxdude42 committed Jul 8, 2022
1 parent 6439619 commit fb15353
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 47 deletions.
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/mheg/dsmccbiop.h
Expand Up @@ -10,8 +10,8 @@

#include "dsmcccache.h"

#define BIOP_OBJ_OFFSET 11
#define BIOP_TAG_OFFSET 17
static constexpr uint8_t BIOP_OBJ_OFFSET { 11 };
static constexpr uint8_t BIOP_TAG_OFFSET { 17 };

class DSMCCCacheModuleData;
class Dsmcc;
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mheg/mhi.cpp
Expand Up @@ -45,9 +45,9 @@ extern "C" {
static bool ft_loaded = false;
static FT_Library ft_library;

#define FONT_WIDTHRES 54
#define FONT_HEIGHTRES 72 // 1 pixel per point
#define FONT_TO_USE "FreeSans.ttf" // Tiresias Screenfont.ttf is mandated
static constexpr uint8_t FONT_WIDTHRES { 54 };
static constexpr uint8_t FONT_HEIGHTRES { 72 }; // 1 pixel per point
static constexpr const char * FONT_TO_USE { "FreeSans.ttf" }; // Tiresias Screenfont.ttf is mandated


// LifecycleExtension tuneinfo:
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mheg/mhi.h
Expand Up @@ -42,7 +42,7 @@ class MThread;
class QByteArray;

// Special value for the NetworkBootInfo version. Real values are a byte.
#define NBI_VERSION_UNSET 257
static constexpr uint16_t NBI_VERSION_UNSET { 257 };

/** \class MHIContext
* \brief Contains various utility functions for interactive television.
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mpeg/dvbstreamdata.cpp
Expand Up @@ -10,7 +10,7 @@
#include "premieretables.h"
#include "eithelper.h"

#define MCA_EIT_TSID 136
static constexpr uint8_t MCA_EIT_TSID { 136 };

#define LOC QString("DVBStream[%1]: ").arg(m_cardId)

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mpeg/freesat_huffman.cpp
@@ -1,8 +1,8 @@
#include "freesat_huffman.h"

#define START '\0'
#define STOP '\0'
#define ESCAPE '\1'
static constexpr uint8_t START { '\0' };
static constexpr uint8_t STOP { '\0' };
static constexpr uint8_t ESCAPE { '\1' };

QString freesat_huffman_to_string(const unsigned char *compressed, uint size)
{
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/mpeg/mpegtables.h
Expand Up @@ -28,10 +28,10 @@
/** Seconds between start of GPS time and the start of UNIX time.
* i.e. from Jan 1st, 1970 UTC to Jan 6th, 1980 UTC
*/
#define GPS_EPOCH 315964800
static constexpr qint64 GPS_EPOCH { 315964800 };

/** Leap seconds as of June 30th, 2012. */
#define GPS_LEAP_SECONDS 16
static constexpr uint8_t GPS_LEAP_SECONDS { 16 };
// Note: You can obtain this number by adding one
// for every leap second added to UTC since Jan 6th, 1980
// and subtracting one for every leap second removed.
Expand Down
10 changes: 4 additions & 6 deletions mythtv/libs/libmythtv/mpeg/pespacket.cpp
Expand Up @@ -252,15 +252,15 @@ static std::vector<unsigned char*> mem4096;
static std::vector<unsigned char*> free4096;
static std::map<unsigned char*, bool> alloc4096;

#define BLOCKS188 512
static constexpr size_t BLOCKS188 { 512 };
static unsigned char* get_188_block()
{
if (free188.empty())
{
mem188.push_back((unsigned char*) malloc(188_UZ * BLOCKS188));
free188.reserve(BLOCKS188);
unsigned char* block_start = mem188.back();
for (uint i = 0; i < BLOCKS188; ++i)
for (size_t i = 0; i < BLOCKS188; ++i)
free188.push_back(i * 188_UZ + block_start);
}

Expand All @@ -269,7 +269,6 @@ static unsigned char* get_188_block()
alloc188[ptr] = true;
return ptr;
}
#undef BLOCKS188

static bool is_188_block(unsigned char* ptr)
{
Expand All @@ -294,15 +293,15 @@ static void return_188_block(unsigned char* ptr)
}
}

#define BLOCKS4096 128
static constexpr size_t BLOCKS4096 { 128 };
static unsigned char* get_4096_block()
{
if (free4096.empty())
{
mem4096.push_back((unsigned char*) malloc(4096_UZ * BLOCKS4096));
free4096.reserve(BLOCKS4096);
unsigned char* block_start = mem4096.back();
for (uint i = 0; i < BLOCKS4096; ++i)
for (size_t i = 0; i < BLOCKS4096; ++i)
free4096.push_back(i * 4096_UZ + block_start);
}

Expand All @@ -311,7 +310,6 @@ static unsigned char* get_4096_block()
alloc4096[ptr] = true;
return ptr;
}
#undef BLOCKS4096

static bool is_4096_block(unsigned char* ptr)
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/mpeg/tablestatus.cpp
Expand Up @@ -3,7 +3,7 @@

#include "tablestatus.h"

#define BIT_SEL(x) (1 << (x))
static inline uint8_t BIT_SEL(uint8_t x) { return 1 << x; }

const std::array<const uint8_t,8> TableStatus::kInitBits = {0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};

Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mpeg/tspacket.h
Expand Up @@ -14,9 +14,9 @@

// n.b. these PID relationships are only a recommendation from ATSC,
// but seem to be universal
#define VIDEO_PID(bp) ((bp)+1)
#define AUDIO_PID(bp) ((bp)+4)
#define SYNC_BYTE 0x0047
//static constexpr uint16_t VIDEO_PID(uint16_t bp) { return bp+1; };
//static constexpr uint16_t AUDIO_PID(uint16_t bp) { return bp+4; };
static constexpr uint8_t SYNC_BYTE { 0x47 };

using TSHeaderArray = std::array<uint8_t,4>;

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/opengl/mythopenglvideo.cpp
Expand Up @@ -19,7 +19,7 @@ extern "C" {
}

#define LOC QString("GLVid: ")
#define MAX_VIDEO_TEXTURES 10 // YV12 Kernel deinterlacer + 1
// static constexpr int8_t MAX_VIDEO_TEXTURES { 10 }; // YV12 Kernel deinterlacer + 1

/**
* \class MythOpenGLVideo
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.cpp
Expand Up @@ -1032,7 +1032,7 @@ bool NuppelVideoRecorder::SetFormatV4L2(void) { return false; }
#endif // !USING_V4L2

#ifdef USING_V4L2
#define MAX_VIDEO_BUFFERS 5
static constexpr size_t MAX_VIDEO_BUFFERS { 5 };
void NuppelVideoRecorder::DoV4L2(void)
{
struct v4l2_buffer vbuf {};
Expand Down Expand Up @@ -2275,7 +2275,7 @@ void NuppelVideoRecorder::WriteVideo(MythVideoFrame *frame, bool skipsync,
bool forcekey)
{
int tmp = 0;
lzo_uint out_len = OUT_LEN;
lzo_uint out_len = kOutLen;
struct rtframeheader frameheader {};
int raw = 0;
int compressthis = m_compression;
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/recorders/NuppelVideoRecorder.h
Expand Up @@ -36,7 +36,7 @@ extern "C" {
#include "libavcodec/avcodec.h"
}

#define KEYFRAMEDIST 30
static constexpr int8_t KEYFRAMEDIST { 30 };

struct video_audio;
class RTjpeg;
Expand Down Expand Up @@ -185,8 +185,8 @@ class MTV_PUBLIC NuppelVideoRecorder : public V4LRecorder, public CC608Input

RTjpeg *m_rtjc {nullptr};

#define OUT_LEN (1024*1024 + 1024*1024 / 64 + 16 + 3)
std::array<lzo_byte,OUT_LEN> m_out {};
static constexpr size_t kOutLen {1024*1024 + 1024*1024 / 64 + 16 + 3};
std::array<lzo_byte,kOutLen> m_out {};
#define HEAP_ALLOC(var,size) \
std::array<long,((size) + (sizeof(long) - 1)) / sizeof(long)> __LZO_MMODEL var
HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS) {};
Expand Down
12 changes: 7 additions & 5 deletions mythtv/libs/libmythtv/recorders/RTjpegN.h
Expand Up @@ -32,8 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Macros and definitions used internally to RTjpeg
*/

#define RTJPEG_FILE_VERSION 0
#define RTJPEG_HEADER_SIZE 12
static constexpr uint8_t RTJPEG_FILE_VERSION { 0 };
static constexpr uint8_t RTJPEG_HEADER_SIZE { 12 };

using RTjpegData16 = std::array<int16_t,64>;
using RTjpegData32 = std::array<int32_t,64>;
Expand All @@ -44,9 +44,11 @@ using RTjpegData32 = std::array<int32_t,64>;

/* Format definitions */

#define RTJ_YUV420 0
#define RTJ_YUV422 1
#define RTJ_RGB8 2
enum RTJFormat {
RTJ_YUV420 = 0,
RTJ_YUV422 = 1,
RTJ_RGB8 = 2
};

class RTjpeg
{
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/recorders/iptvstreamhandler.cpp
Expand Up @@ -166,7 +166,7 @@ void IPTVStreamHandler::run(void)
bool error = false;

int start_port = 0;
for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
for (size_t i = 0; i < IPTV_SOCKET_COUNT; i++)
{
QUrl url = tuning.GetURL(i);
if (url.port() < 0)
Expand Down Expand Up @@ -307,7 +307,7 @@ void IPTVStreamHandler::run(void)
}

// Clean up
for (uint i = 0; i < IPTV_SOCKET_COUNT; i++)
for (size_t i = 0; i < IPTV_SOCKET_COUNT; i++)
{
if (m_sockets[i])
{
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/iptvstreamhandler.h
Expand Up @@ -17,7 +17,7 @@
#include "channelutil.h"
#include "streamhandler.h"

#define IPTV_SOCKET_COUNT 3
static constexpr size_t IPTV_SOCKET_COUNT { 3 };
static constexpr std::chrono::milliseconds RTCP_TIMER { 10s };

class IPTVStreamHandler;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/satiprtcppacket.h
Expand Up @@ -9,7 +9,7 @@
// MythTV includes
#include "libmythbase/mythlogging.h"

#define RTCP_TYPE_APP 204
static constexpr uint8_t RTCP_TYPE_APP { 204 };

class SatIPRTCPPacket
{
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/recorders/vbitext/vbi.cpp
Expand Up @@ -114,9 +114,9 @@ vbi_send_page(struct vbi *vbi, struct raw_page *rvtp, int page)
// it collects parity and hamming errors and moves the sampling point
// a 10th of a bitlength left or right.

#define PLL_SAMPLES 4 // number of err vals to collect
#define PLL_ERROR 4 // if this err val is crossed, readjust
//#define PLL_ADJUST 4 // max/min adjust (10th of bitlength)
static constexpr int8_t PLL_SAMPLES { 4 }; // number of err vals to collect
static constexpr int8_t PLL_ERROR { 4 }; // if this err val is crossed, readjust
//static constexpr int8_t PLL_ADJUST { 4 }; // max/min adjust (10th of bitlength)

static void
pll_add(struct vbi *vbi, int n, int err)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/vbitext/vbi.h
Expand Up @@ -6,7 +6,7 @@
#include "lang.h"
//#include "cache.h"

#define PLL_ADJUST 4
static constexpr int8_t PLL_ADJUST { 4 };

struct raw_page
{
Expand Down
12 changes: 7 additions & 5 deletions mythtv/libs/libmythtv/recorders/vboxutils.cpp
Expand Up @@ -15,13 +15,15 @@

#define LOC QString("VBox: ")

#define QUERY_BOARDINFO "http://{URL}/cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=QueryBoardInfo"
#define QUERY_CHANNELS "http://{URL}/cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetXmltvChannelsList"\
"&FromChIndex=FirstChannel&ToChIndex=LastChannel&FilterBy=All"
static constexpr const char* QUERY_BOARDINFO
{ "http://{URL}/cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=QueryBoardInfo" };
static constexpr const char* QUERY_CHANNELS
{ "http://{URL}/cgi-bin/HttpControl/HttpControlApp?OPTION=1&Method=GetXmltvChannelsList" \
"&FromChIndex=FirstChannel&ToChIndex=LastChannel&FilterBy=All" };

static constexpr std::chrono::milliseconds SEARCH_TIME { 3s };
#define VBOX_URI "urn:schemas-upnp-org:device:MediaServer:1"
#define VBOX_UDN "uuid:b7531642-0123-3210"
static constexpr const char* VBOX_URI { "urn:schemas-upnp-org:device:MediaServer:1" };
static constexpr const char* VBOX_UDN { "uuid:b7531642-0123-3210" };

// static method
QStringList VBox::probeDevices(void)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/recorders/vboxutils.h
Expand Up @@ -11,7 +11,7 @@
// MythTV headers
#include "channelscan/vboxchannelfetcher.h"

#define VBOX_MIN_API_VERSION "VB.2.50"
static constexpr const char* VBOX_MIN_API_VERSION { "VB.2.50" };

class VBox
{
Expand Down

0 comments on commit fb15353

Please sign in to comment.