Commit 20609d34 authored by conrad's avatar conrad

Mozilla #511038: Fix Ogg/Theora on ARM

"liboggz unaligned access fixes v2" patch by Vladimir Vukicevic (:vlad)
parent 81ed0473
......@@ -58,10 +58,6 @@ int oggz_set_metric_linear (OGGZ * oggz, long serialno,
ogg_int64_t granule_rate_numerator,
ogg_int64_t granule_rate_denominator);
#define INT16_BE_AT(x) _be_16((*(ogg_int32_t *)(x)))
#define INT32_LE_AT(x) _le_32((*(ogg_int32_t *)(x)))
#define INT64_LE_AT(x) _le_64((*(ogg_int64_t *)(x)))
static int
oggz_stream_set_numheaders (OGGZ * oggz, long serialno, int numheaders)
{
......@@ -86,7 +82,7 @@ auto_speex (OGGZ * oggz, long serialno, unsigned char * data, long length, void
if (length < 68) return 0;
granule_rate = (ogg_int64_t) INT32_LE_AT(&header[36]);
granule_rate = (ogg_int64_t) int32_le_at(&header[36]);
#ifdef DEBUG
printf ("Got speex rate %d\n", (int)granule_rate);
#endif
......@@ -95,7 +91,7 @@ auto_speex (OGGZ * oggz, long serialno, unsigned char * data, long length, void
oggz_set_preroll (oggz, serialno, 3);
numheaders = (ogg_int64_t) INT32_LE_AT(&header[68]) + 2;
numheaders = (ogg_int64_t) int32_le_at(&header[68]) + 2;
oggz_stream_set_numheaders (oggz, serialno, numheaders);
return 1;
......@@ -109,7 +105,7 @@ auto_vorbis (OGGZ * oggz, long serialno, unsigned char * data, long length, void
if (length < 30) return 0;
granule_rate = (ogg_int64_t) INT32_LE_AT(&header[12]);
granule_rate = (ogg_int64_t) int32_le_at(&header[12]);
#ifdef DEBUG
printf ("Got vorbis rate %d\n", (int)granule_rate);
#endif
......@@ -203,8 +199,8 @@ auto_anxdata (OGGZ * oggz, long serialno, unsigned char * data, long length, voi
if (length < 28) return 0;
granule_rate_numerator = INT64_LE_AT(&header[8]);
granule_rate_denominator = INT64_LE_AT(&header[16]);
granule_rate_numerator = int64_le_at(&header[8]);
granule_rate_denominator = int64_le_at(&header[16]);
#ifdef DEBUG
printf ("Got AnxData rate %lld/%lld\n", granule_rate_numerator,
granule_rate_denominator);
......@@ -253,7 +249,7 @@ auto_flac (OGGZ * oggz, long serialno, unsigned char * data, long length, void *
oggz_set_granulerate (oggz, serialno, granule_rate, OGGZ_AUTO_MULT);
numheaders = INT16_BE_AT(&header[7]);
numheaders = int16_be_at(&header[7]);
oggz_stream_set_numheaders (oggz, serialno, numheaders);
return 1;
......@@ -292,14 +288,14 @@ auto_celt (OGGZ * oggz, long serialno, unsigned char * data, long length, void *
if (length < 56) return 0;
granule_rate = (ogg_int64_t) INT32_LE_AT(&header[40]);
granule_rate = (ogg_int64_t) int32_le_at(&header[40]);
#ifdef DEBUG
printf ("Got celt sample rate %d\n", (int)granule_rate);
#endif
oggz_set_granulerate (oggz, serialno, granule_rate, OGGZ_AUTO_MULT);
numheaders = (ogg_int64_t) INT32_LE_AT(&header[52]) + 2;
numheaders = (ogg_int64_t) int32_le_at(&header[52]) + 2;
oggz_stream_set_numheaders (oggz, serialno, numheaders);
return 1;
......@@ -314,8 +310,8 @@ auto_cmml (OGGZ * oggz, long serialno, unsigned char * data, long length, void *
if (length < 28) return 0;
granule_rate_numerator = INT64_LE_AT(&header[12]);
granule_rate_denominator = INT64_LE_AT(&header[20]);
granule_rate_numerator = int64_le_at(&header[12]);
granule_rate_denominator = int64_le_at(&header[20]);
if (length > 28)
granuleshift = (int)header[28];
else
......@@ -346,8 +342,8 @@ auto_kate (OGGZ * oggz, long serialno, unsigned char * data, long length, void *
if (length < 64) return 0;
gps_numerator = INT32_LE_AT(&header[24]);
gps_denominator = INT32_LE_AT(&header[28]);
gps_numerator = int32_le_at(&header[24]);
gps_denominator = int32_le_at(&header[28]);
granule_shift = (header[15]);
numheaders = (header[11]);
......@@ -399,13 +395,13 @@ auto_fisbone (OGGZ * oggz, long serialno, unsigned char * data, long length, voi
if (length < 48) return 0;
fisbone_serialno = (long) INT32_LE_AT(&header[12]);
fisbone_serialno = (long) int32_le_at(&header[12]);
/* Don't override an already assigned metric */
if (oggz_stream_has_metric (oggz, fisbone_serialno)) return 1;
granule_rate_numerator = INT64_LE_AT(&header[20]);
granule_rate_denominator = INT64_LE_AT(&header[28]);
granule_rate_numerator = int64_le_at(&header[20]);
granule_rate_denominator = int64_le_at(&header[28]);
granuleshift = (int)header[48];
#ifdef DEBUG
......
......@@ -116,7 +116,28 @@ _le_64 (ogg_int64_t l)
static ogg_int32_t
int32_be_at (unsigned char *c)
{
return (c [0] << 24) + (c [1] << 16) + (c [2] << 8) + c [3] ;
return (c [0] << 24) | (c [1] << 16) | (c [2] << 8) | c [3] ;
}
static unsigned short
int16_be_at (unsigned char *c)
{
return (c [0] << 8) | c [1];
}
static ogg_int32_t
int32_le_at (unsigned char *c)
{
return c [0] | (c [1] << 8) | (c [2] << 16) | (c [3] << 24);
}
static ogg_int64_t
int64_le_at (unsigned char *c)
{
ogg_uint32_t a = c [0] | (c [1] << 8) | (c [2] << 16) | (c [3] << 24);
ogg_uint32_t b = c [4] | (c [5] << 8) | (c [6] << 16) | (c [7] << 24);
return (((ogg_int64_t)b) << 32) | a;
}
#endif /* __OGGZ_BYTEORDER_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment