From 9766e419efe9f70c7d5b9757b2c04c23c9f449e9 Mon Sep 17 00:00:00 2001 From: Philip de Nier Date: Mon, 11 Nov 2024 15:56:42 +0000 Subject: [PATCH] Fix conversion warnings from MSVC compiler --- apps/bmxparse/bmxparse.cpp | 4 ++-- include/bmx/essence_parser/JXSEssenceParser.h | 4 ++-- include/bmx/essence_parser/RawEssenceReader.h | 8 +++---- src/apps/AppUtils.cpp | 2 +- src/essence_parser/JXSEssenceParser.cpp | 5 +--- src/essence_parser/KLVEssenceReader.cpp | 23 +++++++++++-------- src/essence_parser/RawEssenceReader.cpp | 8 +++++-- src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp | 2 +- test/create_test_essence.cpp | 8 +++---- tools/h264dump.c | 2 +- 10 files changed, 36 insertions(+), 30 deletions(-) diff --git a/apps/bmxparse/bmxparse.cpp b/apps/bmxparse/bmxparse.cpp index 6069a464..fd9951f6 100644 --- a/apps/bmxparse/bmxparse.cpp +++ b/apps/bmxparse/bmxparse.cpp @@ -948,7 +948,7 @@ int main(int argc, const char **argv) frame_start = 0; } - frame_size = parser->ParseFrameSize2(buffer.data, buffer.size); + frame_size = parser->ParseFrameSize2(buffer.data, (uint32_t)buffer.size); if (frame_size.IsNull()) { log_error("Failed to parse frame size\n"); @@ -959,7 +959,7 @@ int main(int argc, const char **argv) if (frame_size.IsUnknown()) { if (buffer.Fill(file) == 0) { // Try create a complete frame from the available data assuming it's a valid frame - if (!frame_size.CompleteSize(buffer.size)) + if (!frame_size.CompleteSize((uint32_t)buffer.size)) break; BMX_ASSERT(frame_size.IsComplete()); diff --git a/include/bmx/essence_parser/JXSEssenceParser.h b/include/bmx/essence_parser/JXSEssenceParser.h index 50bacaed..0f55664c 100644 --- a/include/bmx/essence_parser/JXSEssenceParser.h +++ b/include/bmx/essence_parser/JXSEssenceParser.h @@ -139,7 +139,7 @@ namespace bmx class CAP { const unsigned char* m_MarkerData; - uint32_t m_DataSize; + size_t m_DataSize; NO_COPY_CONSTRUCT(CAP); CAP(); @@ -181,7 +181,7 @@ namespace bmx class PIH { const unsigned char* m_MarkerData; - uint32_t m_DataSize; + size_t m_DataSize; NO_COPY_CONSTRUCT(PIH); PIH(); diff --git a/include/bmx/essence_parser/RawEssenceReader.h b/include/bmx/essence_parser/RawEssenceReader.h index f8f0954e..7d19af5c 100644 --- a/include/bmx/essence_parser/RawEssenceReader.h +++ b/include/bmx/essence_parser/RawEssenceReader.h @@ -51,8 +51,8 @@ class RawEssenceReader void SetMaxReadLength(int64_t len); - void SetFrameStartSize(int64_t len); - void SetReadBlockSize(int64_t len); + void SetFrameStartSize(int64_t len); // len <= uint32 max + void SetReadBlockSize(int64_t len); // len <= uint32 max void SetFixedSampleSize(uint32_t size); @@ -84,8 +84,8 @@ class RawEssenceReader EssenceSource *mEssenceSource; int64_t mMaxReadLength; - int64_t mFrameStartSize; - int64_t mReadBlockSize; + uint32_t mFrameStartSize; + uint32_t mReadBlockSize; int64_t mTotalReadLength; uint32_t mMaxSampleSize; diff --git a/src/apps/AppUtils.cpp b/src/apps/AppUtils.cpp index 6af0a5ae..8e6c8a9c 100644 --- a/src/apps/AppUtils.cpp +++ b/src/apps/AppUtils.cpp @@ -1563,6 +1563,6 @@ void bmx::rt_sleep(float rt_factor, uint64_t start_tick, Rational sample_rate, i sample_rate.denominator / (rt_factor * sample_rate.numerator)); uint64_t delta_tick = delta_tick_count(tick, target_tick); if (delta_tick) - sleep_msec(delta_tick); + sleep_msec((delta_tick <= UINT32_MAX ? (uint32_t)delta_tick : UINT32_MAX)); } diff --git a/src/essence_parser/JXSEssenceParser.cpp b/src/essence_parser/JXSEssenceParser.cpp index 8b081ed3..533c5704 100644 --- a/src/essence_parser/JXSEssenceParser.cpp +++ b/src/essence_parser/JXSEssenceParser.cpp @@ -146,7 +146,6 @@ void JXSEssenceParser::ParseFrameInfo(const unsigned char *data, uint32_t data_s { int32_t result = 0; Marker NextMarker; - unsigned char *start_of_data = 0; const unsigned char* p = data; const unsigned char* end_p = p + data_size; mFrameSize = 0; @@ -248,7 +247,7 @@ void JXSEssenceParser::ParseFrameInfo(const unsigned char *data, uint32_t data_s { if (pih) { Accessor::CDT CDT_(NextMarker); - int i, count = NextMarker.m_DataSize >> 1; + int i, count = (int)(NextMarker.m_DataSize >> 1); for (i = 0; i < count && i < m_subDesc.JPEGXSNc; i++) { image_components[i].Bc = CDT_.Bc(i); image_components[i].Sx = CDT_.Sx(i); // subsampling in x @@ -262,8 +261,6 @@ void JXSEssenceParser::ParseFrameInfo(const unsigned char *data, uint32_t data_s } break; case MRK_SLH: // slice header: the entropy coded data starts here - if (start_of_data != 0) - *start_of_data = p - data; p = end_p; break; case MRK_NIL: diff --git a/src/essence_parser/KLVEssenceReader.cpp b/src/essence_parser/KLVEssenceReader.cpp index 7c08a665..30d8253c 100644 --- a/src/essence_parser/KLVEssenceReader.cpp +++ b/src/essence_parser/KLVEssenceReader.cpp @@ -56,24 +56,29 @@ KLVEssenceReader::~KLVEssenceReader() uint32_t KLVEssenceReader::ReadValue() { // Position at the next non-zero Value - uint64_t v_size = 0; - while (v_size == 0) { - if (!mEssenceSource->PositionInV(&v_size) || v_size > UINT32_MAX) { - if (v_size > UINT32_MAX) - log_warn("KLV value size %" PRIu64 " > max uint32 is not supported\n", v_size); + uint64_t v_size64 = 0; + while (v_size64 == 0) { + if (!mEssenceSource->PositionInV(&v_size64)) { mValueBuffer.SetSize(0); return 0; } } + if (v_size64 > UINT32_MAX) { + log_warn("KLV value size %" PRIu64 " > max uint32 is not supported\n", v_size64); + mValueBuffer.SetSize(0); + return 0; + } + uint32_t value_size = (uint32_t)v_size64; + // Expect to be at the start of the V because the read below reads the whole V BMX_CHECK(mEssenceSource->GetOffsetInV() == 0); - mValueBuffer.Allocate(v_size); + mValueBuffer.Allocate(value_size); - uint32_t read_size = mEssenceSource->Read(mValueBuffer.GetBytes(), v_size); - if (read_size != v_size) { - log_warn("Incomplete KLV; only read %u of %u\n", read_size, v_size); + uint32_t read_size = mEssenceSource->Read(mValueBuffer.GetBytes(), value_size); + if (read_size != value_size) { + log_warn("Incomplete KLV; only read %u of %u\n", read_size, value_size); mValueBuffer.SetSize(0); return 0; } diff --git a/src/essence_parser/RawEssenceReader.cpp b/src/essence_parser/RawEssenceReader.cpp index 5af65ce2..bf13c4bd 100644 --- a/src/essence_parser/RawEssenceReader.cpp +++ b/src/essence_parser/RawEssenceReader.cpp @@ -34,6 +34,7 @@ #endif #define __STDC_FORMAT_MACROS +#define __STDC_LIMIT_MACROS #include #include @@ -43,6 +44,7 @@ #ifdef HAVE_UNISTD_H #include #endif +#include #include #include @@ -90,12 +92,14 @@ void RawEssenceReader::SetMaxReadLength(int64_t len) void RawEssenceReader::SetFrameStartSize(int64_t len) { - mFrameStartSize = len; + BMX_CHECK(len <= UINT32_MAX); + mFrameStartSize = (uint32_t)len; } void RawEssenceReader::SetReadBlockSize(int64_t len) { - mReadBlockSize = len; + BMX_CHECK(len <= UINT32_MAX); + mReadBlockSize = (uint32_t)len; } void RawEssenceReader::SetFixedSampleSize(uint32_t size) diff --git a/src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp b/src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp index 56b59fe2..672d449c 100644 --- a/src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp +++ b/src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp @@ -69,7 +69,7 @@ void JPEGXSMXFDescriptorHelper::SetJPEGXSComponentTable(std::vector val { mxfpp::ByteArray arr; arr.data = (unsigned char*)value.data(); - arr.length = value.size(); + arr.length = (uint16_t)value.size(); mJPEGXSSubDescriptor->setJPEGXSComponentTable(arr); mComponentTable = value; diff --git a/test/create_test_essence.cpp b/test/create_test_essence.cpp index 269088f1..8904db03 100644 --- a/test/create_test_essence.cpp +++ b/test/create_test_essence.cpp @@ -922,14 +922,14 @@ static void write_anc_data(FILE *file, unsigned int duration, bool klv_var_size) anc_data_size[0] = 16 + 1 + sizeof(core_anc_frame); anc_data[0] = new unsigned char[anc_data_size[0]]; memcpy(anc_data[0], klv_key, 16); - anc_data[0][16] = anc_data_size[0] - 17; + anc_data[0][16] = (unsigned char)(anc_data_size[0] - 17); memcpy(&anc_data[0][17], core_anc_frame, sizeof(core_anc_frame)); // Add an extra padding byte to the odd frame anc_data_size[1] = 16 + 1 + sizeof(core_anc_frame) + 1; anc_data[1] = new unsigned char[anc_data_size[1]]; memcpy(anc_data[1], klv_key, 16); - anc_data[1][16] = anc_data_size[1] - 17; + anc_data[1][16] = (unsigned char)(anc_data_size[1] - 17); memcpy(&anc_data[1][17], core_anc_frame, sizeof(core_anc_frame)); anc_data[1][16 + 1 + 11] = 0x09; anc_data[1][anc_data_size[1] - 1] = 0x00; @@ -968,14 +968,14 @@ static void write_vbi_data(FILE *file, unsigned int duration, bool klv_var_size) vbi_data_size[0] = 16 + 1 + sizeof(core_vbi_frame); vbi_data[0] = new unsigned char[vbi_data_size[0]]; memcpy(vbi_data[0], klv_key, 16); - vbi_data[0][16] = vbi_data_size[0] - 17; + vbi_data[0][16] = (unsigned char)(vbi_data_size[0] - 17); memcpy(&vbi_data[0][17], core_vbi_frame, sizeof(core_vbi_frame)); // Add an extra padding byte to the odd frame vbi_data_size[1] = 16 + 1 + sizeof(core_vbi_frame) + 1; vbi_data[1] = new unsigned char[vbi_data_size[1]]; memcpy(vbi_data[1], klv_key, 16); - vbi_data[1][16] = vbi_data_size[1] - 17; + vbi_data[1][16] = (unsigned char)(vbi_data_size[1] - 17); memcpy(&vbi_data[1][17], core_vbi_frame, sizeof(core_vbi_frame)); vbi_data[1][16 + 1 + 11] = 0x09; vbi_data[1][vbi_data_size[1] - 1] = 0x00; diff --git a/tools/h264dump.c b/tools/h264dump.c index 198f5f50..3676aed8 100644 --- a/tools/h264dump.c +++ b/tools/h264dump.c @@ -1861,7 +1861,7 @@ static int skip_sei_payload(ParseContext *context, uint64_t num_bytes) while (rem_num_bytes > 0) { uint8_t read_num_bytes = 8; if (read_num_bytes > rem_num_bytes) - read_num_bytes = rem_num_bytes; + read_num_bytes = (uint8_t)rem_num_bytes; /* Skip payload by calling read_bits to ensure context->emu_prevention_count is updated */ if (!read_bits(context, read_num_bytes * 8))