DataSource.h revision ec77122351b4e78c1fe5b60a208f76baf8c67591
1200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung/* 2200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * Copyright (C) 2009 The Android Open Source Project 3200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * 4200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * Licensed under the Apache License, Version 2.0 (the "License"); 5200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * you may not use this file except in compliance with the License. 6200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * You may obtain a copy of the License at 7200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * 8200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * http://www.apache.org/licenses/LICENSE-2.0 9200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * 10200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * Unless required by applicable law or agreed to in writing, software 11200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * distributed under the License is distributed on an "AS IS" BASIS, 12200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * See the License for the specific language governing permissions and 14200f040af3e4fe9e178cb63c90860d58d90ef665Douglas Leung * limitations under the License. 15 */ 16 17#ifndef DATA_SOURCE_H_ 18 19#define DATA_SOURCE_H_ 20 21#include <sys/types.h> 22 23#include <media/stagefright/MediaErrors.h> 24#include <utils/Errors.h> 25#include <utils/KeyedVector.h> 26#include <utils/List.h> 27#include <utils/RefBase.h> 28#include <utils/threads.h> 29#include <drm/DrmManagerClient.h> 30 31namespace android { 32 33struct AMessage; 34class String8; 35 36class DataSource : public RefBase { 37public: 38 enum Flags { 39 kWantsPrefetching = 1, 40 kStreamedFromLocalHost = 2, 41 kIsCachingDataSource = 4, 42 kIsHTTPBasedSource = 8, 43 }; 44 45 static sp<DataSource> CreateFromURI( 46 const char *uri, 47 const KeyedVector<String8, String8> *headers = NULL); 48 49 DataSource() {} 50 51 virtual status_t initCheck() const = 0; 52 53 virtual ssize_t readAt(off64_t offset, void *data, size_t size) = 0; 54 55 // Convenience methods: 56 bool getUInt16(off64_t offset, uint16_t *x); 57 bool getUInt24(off64_t offset, uint32_t *x); // 3 byte int, returned as a 32-bit int 58 bool getUInt32(off64_t offset, uint32_t *x); 59 bool getUInt64(off64_t offset, uint64_t *x); 60 61 // May return ERROR_UNSUPPORTED. 62 virtual status_t getSize(off64_t *size); 63 64 virtual uint32_t flags() { 65 return 0; 66 } 67 68 virtual status_t reconnectAtOffset(off64_t offset) { 69 return ERROR_UNSUPPORTED; 70 } 71 72 //////////////////////////////////////////////////////////////////////////// 73 74 bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta); 75 76 // The sniffer can optionally fill in "meta" with an AMessage containing 77 // a dictionary of values that helps the corresponding extractor initialize 78 // its state without duplicating effort already exerted by the sniffer. 79 typedef bool (*SnifferFunc)( 80 const sp<DataSource> &source, String8 *mimeType, 81 float *confidence, sp<AMessage> *meta); 82 83 static void RegisterSniffer(SnifferFunc func); 84 static void RegisterDefaultSniffers(); 85 86 // for DRM 87 virtual sp<DecryptHandle> DrmInitialization(const char *mime = NULL) { 88 return NULL; 89 } 90 virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {}; 91 92 virtual String8 getUri() { 93 return String8(); 94 } 95 96 virtual String8 getMIMEType() const; 97 98protected: 99 virtual ~DataSource() {} 100 101private: 102 static Mutex gSnifferMutex; 103 static List<SnifferFunc> gSniffers; 104 105 DataSource(const DataSource &); 106 DataSource &operator=(const DataSource &); 107}; 108 109} // namespace android 110 111#endif // DATA_SOURCE_H_ 112