DataSource.h revision 78f00edc6376657e8931a45a80abf36f2f6ac841
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#ifndef DATA_SOURCE_H_ 18 19#define DATA_SOURCE_H_ 20 21#include <sys/types.h> 22#include <media/stagefright/MediaErrors.h> 23#include <utils/Errors.h> 24#include <utils/RefBase.h> 25#include <utils/threads.h> 26#include <drm/DrmManagerClient.h> 27 28namespace android { 29 30class String8; 31 32class DataSource : public RefBase { 33public: 34 enum Flags { 35 kWantsPrefetching = 1, 36 kStreamedFromLocalHost = 2, 37 kIsCachingDataSource = 4, 38 kIsHTTPBasedSource = 8, 39 kIsLocalFileSource = 16, 40 }; 41 42 DataSource() {} 43 44 virtual status_t initCheck() const = 0; 45 46 // Returns the number of bytes read, or -1 on failure. It's not an error if 47 // this returns zero; it just means the given offset is equal to, or 48 // beyond, the end of the source. 49 virtual ssize_t readAt(off64_t offset, void *data, size_t size) = 0; 50 51 // Convenience methods: 52 bool getUInt16(off64_t offset, uint16_t *x); 53 bool getUInt24(off64_t offset, uint32_t *x); // 3 byte int, returned as a 32-bit int 54 bool getUInt32(off64_t offset, uint32_t *x); 55 bool getUInt64(off64_t offset, uint64_t *x); 56 57 // read either int<N> or int<2N> into a uint<2N>_t, size is the int size in bytes. 58 bool getUInt16Var(off64_t offset, uint16_t *x, size_t size); 59 bool getUInt32Var(off64_t offset, uint32_t *x, size_t size); 60 bool getUInt64Var(off64_t offset, uint64_t *x, size_t size); 61 62 // May return ERROR_UNSUPPORTED. 63 virtual status_t getSize(off64_t *size); 64 65 virtual uint32_t flags() { 66 return 0; 67 } 68 69 virtual String8 toString() { 70 return String8("<unspecified>"); 71 } 72 73 virtual status_t reconnectAtOffset(off64_t /*offset*/) { 74 return ERROR_UNSUPPORTED; 75 } 76 77 //////////////////////////////////////////////////////////////////////////// 78 79 // for DRM 80 virtual sp<DecryptHandle> DrmInitialization(const char * /*mime*/ = NULL) { 81 return NULL; 82 } 83 84 virtual String8 getUri() { 85 return String8(); 86 } 87 88 virtual String8 getMIMEType() const; 89 90 virtual void close() {}; 91 92protected: 93 virtual ~DataSource() {} 94 95private: 96 DataSource(const DataSource &); 97 DataSource &operator=(const DataSource &); 98}; 99 100} // namespace android 101 102#endif // DATA_SOURCE_H_ 103