Bug 1202012 - P2. Make stagefright works on big-endian systems. r=rillian, a=sylvestre
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 12 Sep 2015 02:29:36 +1000
changeset 289289 8fefcb8ca48c45eab3f1a951183779cb0f120828
parent 289288 8c8a7797bf0e66fa4ce66b8ec6f66e146dad612d
child 289290 d88e4c36106e9b18916cb737ee5e2088ceb136f7
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, sylvestre
bugs1202012
milestone42.0a2
Bug 1202012 - P2. Make stagefright works on big-endian systems. r=rillian, a=sylvestre
media/libstagefright/frameworks/av/media/libstagefright/Utils.cpp
--- a/media/libstagefright/frameworks/av/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/Utils.cpp
@@ -55,21 +55,28 @@ uint16_t U16LE_AT(const uint8_t *ptr) {
 uint32_t U32LE_AT(const uint8_t *ptr) {
     return ptr[3] << 24 | ptr[2] << 16 | ptr[1] << 8 | ptr[0];
 }
 
 uint64_t U64LE_AT(const uint8_t *ptr) {
     return ((uint64_t)U32LE_AT(ptr + 4)) << 32 | U32LE_AT(ptr);
 }
 
-// XXX warning: these won't work on big-endian host.
 uint64_t ntoh64(uint64_t x) {
-    return ((uint64_t)ntohl(x & 0xffffffff) << 32) | ntohl(x >> 32);
+    return ((x & 0xFF00000000000000ull) >> 56) |
+           ((x & 0x00FF000000000000ull) >> 40) |
+           ((x & 0x0000FF0000000000ull) >> 24) |
+           ((x & 0x000000FF00000000ull) >>  8) |
+           ((x & 0x00000000FF000000ull) <<  8) |
+           ((x & 0x0000000000FF0000ull) << 24) |
+           ((x & 0x000000000000FF00ull) << 40) |
+           ((x & 0x00000000000000FFull) << 56);
 }
 
+// XXX warning: this won't work on big-endian host.
 uint64_t hton64(uint64_t x) {
     return ((uint64_t)htonl(x & 0xffffffff) << 32) | htonl(x >> 32);
 }
 
 #if 0
 status_t convertMetaDataToMessage(
         const sp<MetaData> &meta, sp<AMessage> *format) {
     format->clear();