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 //#define LOG_NDEBUG 0 17 #define LOG_TAG "DataSourceBase" 18 19 #include <media/DataSourceBase.h> 20 #include <media/stagefright/foundation/ByteUtils.h> 21 #include <media/stagefright/MediaErrors.h> 22 #include <utils/String8.h> 23 24 namespace android { 25 26 bool DataSourceBase::getUInt16(off64_t offset, uint16_t *x) { 27 *x = 0; 28 29 uint8_t byte[2]; 30 if (readAt(offset, byte, 2) != 2) { 31 return false; 32 } 33 34 *x = (byte[0] << 8) | byte[1]; 35 36 return true; 37 } 38 39 bool DataSourceBase::getUInt24(off64_t offset, uint32_t *x) { 40 *x = 0; 41 42 uint8_t byte[3]; 43 if (readAt(offset, byte, 3) != 3) { 44 return false; 45 } 46 47 *x = (byte[0] << 16) | (byte[1] << 8) | byte[2]; 48 49 return true; 50 } 51 52 bool DataSourceBase::getUInt32(off64_t offset, uint32_t *x) { 53 *x = 0; 54 55 uint32_t tmp; 56 if (readAt(offset, &tmp, 4) != 4) { 57 return false; 58 } 59 60 *x = ntohl(tmp); 61 62 return true; 63 } 64 65 bool DataSourceBase::getUInt64(off64_t offset, uint64_t *x) { 66 *x = 0; 67 68 uint64_t tmp; 69 if (readAt(offset, &tmp, 8) != 8) { 70 return false; 71 } 72 73 *x = ntoh64(tmp); 74 75 return true; 76 } 77 78 bool DataSourceBase::getUInt16Var(off64_t offset, uint16_t *x, size_t size) { 79 if (size == 2) { 80 return getUInt16(offset, x); 81 } 82 if (size == 1) { 83 uint8_t tmp; 84 if (readAt(offset, &tmp, 1) == 1) { 85 *x = tmp; 86 return true; 87 } 88 } 89 return false; 90 } 91 92 bool DataSourceBase::getUInt32Var(off64_t offset, uint32_t *x, size_t size) { 93 if (size == 4) { 94 return getUInt32(offset, x); 95 } 96 if (size == 2) { 97 uint16_t tmp; 98 if (getUInt16(offset, &tmp)) { 99 *x = tmp; 100 return true; 101 } 102 } 103 return false; 104 } 105 106 bool DataSourceBase::getUInt64Var(off64_t offset, uint64_t *x, size_t size) { 107 if (size == 8) { 108 return getUInt64(offset, x); 109 } 110 if (size == 4) { 111 uint32_t tmp; 112 if (getUInt32(offset, &tmp)) { 113 *x = tmp; 114 return true; 115 } 116 } 117 return false; 118 } 119 120 status_t DataSourceBase::getSize(off64_t *size) { 121 *size = 0; 122 123 return ERROR_UNSUPPORTED; 124 } 125 126 bool DataSourceBase::getUri(char *uriString __unused, size_t bufferSize __unused) { 127 return false; 128 } 129 130 } // namespace android 131