Home | History | Annotate | Download | only in stagefright
      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 class String8;
     35 
     36 class DataSource : public RefBase {
     37 public:
     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 
     58     // May return ERROR_UNSUPPORTED.
     59     virtual status_t getSize(off64_t *size);
     60 
     61     virtual uint32_t flags() {
     62         return 0;
     63     }
     64 
     65     virtual status_t reconnectAtOffset(off64_t offset) {
     66         return ERROR_UNSUPPORTED;
     67     }
     68 
     69     ////////////////////////////////////////////////////////////////////////////
     70 
     71     bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);
     72 
     73     // The sniffer can optionally fill in "meta" with an AMessage containing
     74     // a dictionary of values that helps the corresponding extractor initialize
     75     // its state without duplicating effort already exerted by the sniffer.
     76     typedef bool (*SnifferFunc)(
     77             const sp<DataSource> &source, String8 *mimeType,
     78             float *confidence, sp<AMessage> *meta);
     79 
     80     static void RegisterSniffer(SnifferFunc func);
     81     static void RegisterDefaultSniffers();
     82 
     83     // for DRM
     84     virtual sp<DecryptHandle> DrmInitialization() {
     85         return NULL;
     86     }
     87     virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {};
     88 
     89     virtual String8 getUri() {
     90         return String8();
     91     }
     92 
     93     virtual String8 getMIMEType() const;
     94 
     95 protected:
     96     virtual ~DataSource() {}
     97 
     98 private:
     99     static Mutex gSnifferMutex;
    100     static List<SnifferFunc> gSniffers;
    101 
    102     DataSource(const DataSource &);
    103     DataSource &operator=(const DataSource &);
    104 };
    105 
    106 }  // namespace android
    107 
    108 #endif  // DATA_SOURCE_H_
    109