Home | History | Annotate | Download | only in libstagefright
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <arpa/inet.h>
     18 
     19 #include <media/stagefright/Utils.h>
     20 
     21 namespace android {
     22 
     23 uint16_t U16_AT(const uint8_t *ptr) {
     24     return ptr[0] << 8 | ptr[1];
     25 }
     26 
     27 uint32_t U32_AT(const uint8_t *ptr) {
     28     return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
     29 }
     30 
     31 uint64_t U64_AT(const uint8_t *ptr) {
     32     return ((uint64_t)U32_AT(ptr)) << 32 | U32_AT(ptr + 4);
     33 }
     34 
     35 uint16_t U16LE_AT(const uint8_t *ptr) {
     36     return ptr[0] | (ptr[1] << 8);
     37 }
     38 
     39 uint32_t U32LE_AT(const uint8_t *ptr) {
     40     return ptr[3] << 24 | ptr[2] << 16 | ptr[1] << 8 | ptr[0];
     41 }
     42 
     43 uint64_t U64LE_AT(const uint8_t *ptr) {
     44     return ((uint64_t)U32LE_AT(ptr + 4)) << 32 | U32LE_AT(ptr);
     45 }
     46 
     47 // XXX warning: these won't work on big-endian host.
     48 uint64_t ntoh64(uint64_t x) {
     49     return ((uint64_t)ntohl(x & 0xffffffff) << 32) | ntohl(x >> 32);
     50 }
     51 
     52 uint64_t hton64(uint64_t x) {
     53     return ((uint64_t)htonl(x & 0xffffffff) << 32) | htonl(x >> 32);
     54 }
     55 
     56 }  // namespace android
     57 
     58