diff --git a/src/lib_ccx/mp4.c b/src/lib_ccx/mp4.c index 6f8392a4b..c9b7970d1 100644 --- a/src/lib_ccx/mp4.c +++ b/src/lib_ccx/mp4.c @@ -31,15 +31,17 @@ #define GF_ISOM_SUBTYPE_MPEG4 GF_4CC('M', 'P', 'E', 'G') #endif -static short bswap16(short v) +static int16_t bswap16(int16_t v) { return ((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00); } -static long bswap32(long v) +static int32_t bswap32(int32_t v) { // For 0x12345678 returns 78563412 - long swapped = ((v & 0xFF) << 24) | ((v & 0xFF00) << 8) | ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24); + // Use int32_t instead of long for consistent behavior across platforms + // (long is 4 bytes on Windows x64 but 8 bytes on Linux x64) + int32_t swapped = ((v & 0xFF) << 24) | ((v & 0xFF00) << 8) | ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24); return swapped; } static struct @@ -82,10 +84,10 @@ static int process_avc_sample(struct lib_ccx_ctx *ctx, u32 timescale, GF_AVCConf nal_length = s->data[i]; break; case 2: - nal_length = bswap16(*(short *)&s->data[i]); + nal_length = bswap16(*(int16_t *)&s->data[i]); break; case 4: - nal_length = bswap32(*(long *)&s->data[i]); + nal_length = bswap32(*(int32_t *)&s->data[i]); break; } const u32 previous_index = i; @@ -151,10 +153,10 @@ static int process_hevc_sample(struct lib_ccx_ctx *ctx, u32 timescale, GF_HEVCCo nal_length = s->data[i]; break; case 2: - nal_length = bswap16(*(short *)&s->data[i]); + nal_length = bswap16(*(int16_t *)&s->data[i]); break; case 4: - nal_length = bswap32(*(long *)&s->data[i]); + nal_length = bswap32(*(int32_t *)&s->data[i]); break; default: mprint("Unexpected nal_unit_size %u in HEVC config\n", c->nal_unit_size);