Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/lib_ccx/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading