• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
31 namespace android {
32 
33 struct AMessage;
34 struct AString;
35 struct IMediaHTTPService;
36 class String8;
37 struct HTTPBase;
38 
39 class DataSource : public RefBase {
40 public:
41     enum Flags {
42         kWantsPrefetching      = 1,
43         kStreamedFromLocalHost = 2,
44         kIsCachingDataSource   = 4,
45         kIsHTTPBasedSource     = 8,
46     };
47 
48     static sp<DataSource> CreateFromURI(
49             const sp<IMediaHTTPService> &httpService,
50             const char *uri,
51             const KeyedVector<String8, String8> *headers = NULL,
52             String8 *contentType = NULL,
53             HTTPBase *httpSource = NULL);
54 
55     static sp<DataSource> CreateMediaHTTP(const sp<IMediaHTTPService> &httpService);
56 
DataSource()57     DataSource() {}
58 
59     virtual status_t initCheck() const = 0;
60 
61     virtual ssize_t readAt(off64_t offset, void *data, size_t size) = 0;
62 
63     // Convenience methods:
64     bool getUInt16(off64_t offset, uint16_t *x);
65     bool getUInt24(off64_t offset, uint32_t *x); // 3 byte int, returned as a 32-bit int
66     bool getUInt32(off64_t offset, uint32_t *x);
67     bool getUInt64(off64_t offset, uint64_t *x);
68 
69     // May return ERROR_UNSUPPORTED.
70     virtual status_t getSize(off64_t *size);
71 
flags()72     virtual uint32_t flags() {
73         return 0;
74     }
75 
reconnectAtOffset(off64_t offset)76     virtual status_t reconnectAtOffset(off64_t offset) {
77         return ERROR_UNSUPPORTED;
78     }
79 
80     ////////////////////////////////////////////////////////////////////////////
81 
82     bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);
83 
84     // The sniffer can optionally fill in "meta" with an AMessage containing
85     // a dictionary of values that helps the corresponding extractor initialize
86     // its state without duplicating effort already exerted by the sniffer.
87     typedef bool (*SnifferFunc)(
88             const sp<DataSource> &source, String8 *mimeType,
89             float *confidence, sp<AMessage> *meta);
90 
91     static void RegisterDefaultSniffers();
92 
93     // for DRM
94     virtual sp<DecryptHandle> DrmInitialization(const char *mime = NULL) {
95         return NULL;
96     }
getDrmInfo(sp<DecryptHandle> & handle,DrmManagerClient ** client)97     virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {};
98 
getUri()99     virtual String8 getUri() {
100         return String8();
101     }
102 
103     virtual String8 getMIMEType() const;
104 
105 protected:
~DataSource()106     virtual ~DataSource() {}
107 
108 private:
109     static Mutex gSnifferMutex;
110     static List<SnifferFunc> gSniffers;
111     static bool gSniffersRegistered;
112 
113     static void RegisterSniffer_l(SnifferFunc func);
114 
115     DataSource(const DataSource &);
116     DataSource &operator=(const DataSource &);
117 };
118 
119 }  // namespace android
120 
121 #endif  // DATA_SOURCE_H_
122