|
31 | 31 | #define GF_ISOM_SUBTYPE_MPEG4 GF_4CC('M', 'P', 'E', 'G') |
32 | 32 | #endif |
33 | 33 |
|
34 | | -static short bswap16(short v) |
| 34 | +static int16_t bswap16(int16_t v) |
35 | 35 | { |
36 | 36 | return ((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00); |
37 | 37 | } |
38 | 38 |
|
39 | | -static long bswap32(long v) |
| 39 | +static int32_t bswap32(int32_t v) |
40 | 40 | { |
41 | 41 | // For 0x12345678 returns 78563412 |
42 | | - long swapped = ((v & 0xFF) << 24) | ((v & 0xFF00) << 8) | ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24); |
| 42 | + // Use int32_t instead of long for consistent behavior across platforms |
| 43 | + // (long is 4 bytes on Windows x64 but 8 bytes on Linux x64) |
| 44 | + int32_t swapped = ((v & 0xFF) << 24) | ((v & 0xFF00) << 8) | ((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24); |
43 | 45 | return swapped; |
44 | 46 | } |
45 | 47 | static struct |
@@ -82,10 +84,10 @@ static int process_avc_sample(struct lib_ccx_ctx *ctx, u32 timescale, GF_AVCConf |
82 | 84 | nal_length = s->data[i]; |
83 | 85 | break; |
84 | 86 | case 2: |
85 | | - nal_length = bswap16(*(short *)&s->data[i]); |
| 87 | + nal_length = bswap16(*(int16_t *)&s->data[i]); |
86 | 88 | break; |
87 | 89 | case 4: |
88 | | - nal_length = bswap32(*(long *)&s->data[i]); |
| 90 | + nal_length = bswap32(*(int32_t *)&s->data[i]); |
89 | 91 | break; |
90 | 92 | } |
91 | 93 | const u32 previous_index = i; |
@@ -151,10 +153,10 @@ static int process_hevc_sample(struct lib_ccx_ctx *ctx, u32 timescale, GF_HEVCCo |
151 | 153 | nal_length = s->data[i]; |
152 | 154 | break; |
153 | 155 | case 2: |
154 | | - nal_length = bswap16(*(short *)&s->data[i]); |
| 156 | + nal_length = bswap16(*(int16_t *)&s->data[i]); |
155 | 157 | break; |
156 | 158 | case 4: |
157 | | - nal_length = bswap32(*(long *)&s->data[i]); |
| 159 | + nal_length = bswap32(*(int32_t *)&s->data[i]); |
158 | 160 | break; |
159 | 161 | default: |
160 | 162 | mprint("Unexpected nal_unit_size %u in HEVC config\n", c->nal_unit_size); |
|
0 commit comments