#include <regex.h>
#include "para.h"
+#include "portable_io.h"
#include "string.h"
#include "mp4.h"
return result;
}
-/* parse atom header size */
-static int32_t atom_get_size(const int8_t * data)
-{
- uint32_t result;
- uint32_t a, b, c, d;
-
- a = (uint8_t) data[0];
- b = (uint8_t) data[1];
- c = (uint8_t) data[2];
- d = (uint8_t) data[3];
-
- result = (a << 24) | (b << 16) | (c << 8) | d;
- return (int32_t) result;
-}
-
static uint64_t read_int64(mp4ff_t * f)
{
uint8_t data[8];
- uint64_t result = 0;
- int8_t i;
read_data(f, data, 8);
-
- for (i = 0; i < 8; i++) {
- result |= ((uint64_t) data[i]) << ((7 - i) * 8);
- }
-
- return result;
+ return read_u64_be(data);
}
/* comnapre 2 atom names, returns 1 for equal, 0 for unequal */
if (ret != 8)
return 0;
- size = atom_get_size(atom_header);
+ size = read_u32_be(atom_header);
*header_size = 8;
/* check for 64 bit atom size */
static uint32_t read_int24(mp4ff_t * f)
{
- uint32_t result;
- uint32_t a, b, c;
int8_t data[4];
read_data(f, data, 3);
- a = (uint8_t) data[0];
- b = (uint8_t) data[1];
- c = (uint8_t) data[2];
-
- result = (a << 16) | (b << 8) | c;
- return (uint32_t) result;
+ return read_u24_be(data);
}
static uint32_t read_int32(mp4ff_t * f)
{
- uint32_t result;
- uint32_t a, b, c, d;
int8_t data[4];
read_data(f, data, 4);
- a = (uint8_t) data[0];
- b = (uint8_t) data[1];
- c = (uint8_t) data[2];
- d = (uint8_t) data[3];
-
- result = (a << 24) | (b << 16) | (c << 8) | d;
- return (uint32_t) result;
+ return read_u32_be(data);
}
static int32_t read_stsz(mp4ff_t * f)
static uint16_t read_int16(mp4ff_t * f)
{
- uint32_t result;
- uint32_t a, b;
int8_t data[2];
read_data(f, data, 2);
- a = (uint8_t) data[0];
- b = (uint8_t) data[1];
-
- result = (a << 8) | b;
- return (uint16_t) result;
+ return read_u16_be(data);
}
static uint32_t read_mp4_descr_length(mp4ff_t * f)
static unsigned membuffer_write_int16(membuffer * buf, uint16_t data)
{
- uint8_t temp[2] = { (uint8_t) (data >> 8), (uint8_t) data };
+ uint8_t temp[2];
+
+ write_u16_be(temp, data);
return membuffer_write(buf, temp, 2);
}
static unsigned membuffer_write_int32(membuffer * buf, uint32_t data)
{
- uint8_t temp[4] = { (uint8_t) (data >> 24), (uint8_t) (data >> 16),
- (uint8_t) (data >> 8), (uint8_t) data };
+ uint8_t temp[4];
+ write_u32_be(temp, data);
return membuffer_write(buf, temp, 4);
}
static uint32_t fix_byte_order_32(uint32_t src)
{
- uint32_t result;
- uint32_t a, b, c, d;
- int8_t data[4];
-
- memcpy(data, &src, sizeof (src));
- a = (uint8_t) data[0];
- b = (uint8_t) data[1];
- c = (uint8_t) data[2];
- d = (uint8_t) data[3];
-
- result = (a << 24) | (b << 16) | (c << 8) | d;
- return (uint32_t) result;
+ return read_u32_be(&src);
}
static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data,
static int32_t write_int32(mp4ff_t * f, const uint32_t data)
{
- uint32_t result;
- uint32_t a, b, c, d;
int8_t temp[4];
-
- *(uint32_t *) temp = data;
- a = (uint8_t) temp[0];
- b = (uint8_t) temp[1];
- c = (uint8_t) temp[2];
- d = (uint8_t) temp[3];
-
- result = (a << 24) | (b << 16) | (c << 8) | d;
-
- return write_data(f, (uint8_t *) & result, sizeof (result));
+ write_u32_be(temp, data);
+ return write_data(f, temp, sizeof(temp));
}
static int32_t truncate_stream(mp4ff_t * f)