blob: 8f47ee56cb447aed652640de5a07933a231d143a [file] [log] [blame]
Andreas Huber20111aa2009-07-14 16:56:47 -07001/*
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 */
Chong Zhang3de157d2014-08-05 20:54:44 -070016//#define LOG_NDEBUG 0
Marco Nelissen2a243f02018-01-30 08:29:57 -080017#define LOG_TAG "DataSourceBase"
Andreas Huber20111aa2009-07-14 16:56:47 -070018
Marco Nelissen2a243f02018-01-30 08:29:57 -080019#include <media/DataSourceBase.h>
Dongwon Kang60761282017-10-09 11:16:48 -070020#include <media/stagefright/foundation/ByteUtils.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070021#include <media/stagefright/MediaErrors.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070022#include <utils/String8.h>
23
24namespace android {
25
Marco Nelissen2a243f02018-01-30 08:29:57 -080026bool DataSourceBase::getUInt16(off64_t offset, uint16_t *x) {
Andreas Huber693d2712009-08-14 14:37:10 -070027 *x = 0;
28
29 uint8_t byte[2];
Andreas Huber34769bc2009-10-23 10:22:30 -070030 if (readAt(offset, byte, 2) != 2) {
Andreas Huber693d2712009-08-14 14:37:10 -070031 return false;
32 }
33
34 *x = (byte[0] << 8) | byte[1];
35
36 return true;
37}
38
Marco Nelissen2a243f02018-01-30 08:29:57 -080039bool DataSourceBase::getUInt24(off64_t offset, uint32_t *x) {
Marco Nelissenec771222013-04-08 14:30:57 -070040 *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
Marco Nelissen2a243f02018-01-30 08:29:57 -080052bool DataSourceBase::getUInt32(off64_t offset, uint32_t *x) {
Marco Nelissen05f625c2013-02-13 09:27:28 -080053 *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
Marco Nelissen2a243f02018-01-30 08:29:57 -080065bool DataSourceBase::getUInt64(off64_t offset, uint64_t *x) {
Marco Nelissen05f625c2013-02-13 09:27:28 -080066 *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
Marco Nelissen2a243f02018-01-30 08:29:57 -080078bool DataSourceBase::getUInt16Var(off64_t offset, uint16_t *x, size_t size) {
Chong Zhangb51ca282017-07-26 16:25:28 -070079 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
Marco Nelissen2a243f02018-01-30 08:29:57 -080092bool DataSourceBase::getUInt32Var(off64_t offset, uint32_t *x, size_t size) {
Chong Zhangb51ca282017-07-26 16:25:28 -070093 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
Marco Nelissen2a243f02018-01-30 08:29:57 -0800106bool DataSourceBase::getUInt64Var(off64_t offset, uint64_t *x, size_t size) {
Chong Zhangb51ca282017-07-26 16:25:28 -0700107 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
Marco Nelissen2a243f02018-01-30 08:29:57 -0800120status_t DataSourceBase::getSize(off64_t *size) {
Andreas Huber20111aa2009-07-14 16:56:47 -0700121 *size = 0;
122
123 return ERROR_UNSUPPORTED;
124}
125
Dongwon Kangb486b522018-02-16 15:46:53 -0800126bool DataSourceBase::getUri(char *uriString __unused, size_t bufferSize __unused) {
127 return false;
Andreas Huber6511c972011-03-30 11:15:27 -0700128}
129
Andreas Huber20111aa2009-07-14 16:56:47 -0700130} // namespace android