Utils.cpp revision ee7ff20e69498ebd53dd9717a0f984188341a75e
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 21namespace android { 22 23uint16_t U16_AT(const uint8_t *ptr) { 24 return ptr[0] << 8 | ptr[1]; 25} 26 27uint32_t U32_AT(const uint8_t *ptr) { 28 return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3]; 29} 30 31uint64_t U64_AT(const uint8_t *ptr) { 32 return ((uint64_t)U32_AT(ptr)) << 32 | U32_AT(ptr + 4); 33} 34 35uint16_t U16LE_AT(const uint8_t *ptr) { 36 return ptr[0] | (ptr[1] << 8); 37} 38 39uint32_t U32LE_AT(const uint8_t *ptr) { 40 return ptr[3] << 24 | ptr[2] << 16 | ptr[1] << 8 | ptr[0]; 41} 42 43uint64_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. 48uint64_t ntoh64(uint64_t x) { 49 return ((uint64_t)ntohl(x & 0xffffffff) << 32) | ntohl(x >> 32); 50} 51 52uint64_t hton64(uint64_t x) { 53 return ((uint64_t)htonl(x & 0xffffffff) << 32) | htonl(x >> 32); 54} 55 56} // namespace android 57 58