Skip to content

Commit

Permalink
Fix conversion warnings from MSVC compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
philipnbbc committed Nov 11, 2024
1 parent 8cb3b1d commit 7463215
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions apps/bmxparse/bmxparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions include/bmx/essence_parser/JXSEssenceParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions include/bmx/essence_parser/RawEssenceReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/apps/AppUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

5 changes: 1 addition & 4 deletions src/essence_parser/JXSEssenceParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
size_t i, count = 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
Expand All @@ -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:
Expand Down
23 changes: 14 additions & 9 deletions src/essence_parser/KLVEssenceReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/essence_parser/RawEssenceReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#endif

#define __STDC_FORMAT_MACROS
#define __STDC_LIMIT_MACROS

#include <cstdio>
#include <cstring>
Expand All @@ -43,6 +44,7 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <limits.h>

#include <bmx/essence_parser/RawEssenceReader.h>
#include <bmx/essence_parser/AVCEssenceParser.h>
Expand Down Expand Up @@ -90,11 +92,13 @@ void RawEssenceReader::SetMaxReadLength(int64_t len)

void RawEssenceReader::SetFrameStartSize(int64_t len)
{
BMX_CHECK(len <= UINT32_MAX);
mFrameStartSize = len;
}

void RawEssenceReader::SetReadBlockSize(int64_t len)
{
BMX_CHECK(len <= UINT32_MAX);
mReadBlockSize = len;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mxf_helper/JPEGXSMXFDescriptorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void JPEGXSMXFDescriptorHelper::SetJPEGXSComponentTable(std::vector<uint8_t> 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;
Expand Down
8 changes: 4 additions & 4 deletions test/create_test_essence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/h264dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7463215

Please sign in to comment.