Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2011 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_URI_SOURCE_H_
     18 
     19 #define DATA_URI_SOURCE_H_
     20 
     21 #include <stdio.h>
     22 
     23 #include <media/stagefright/DataSource.h>
     24 #include <media/stagefright/MediaErrors.h>
     25 #include <media/stagefright/foundation/AString.h>
     26 
     27 namespace android {
     28 
     29 class DataUriSource : public DataSource {
     30 public:
     31     DataUriSource(const char *uri);
     32 
     33     virtual status_t initCheck() const {
     34         return mInited;
     35     }
     36 
     37     virtual ssize_t readAt(off64_t offset, void *data, size_t size);
     38 
     39     virtual status_t getSize(off64_t *size) {
     40         if (mInited != OK) {
     41             return mInited;
     42         }
     43 
     44         *size = mData.size();
     45         return OK;
     46     }
     47 
     48     virtual String8 getUri() {
     49         return mDataUri;
     50     }
     51 
     52     virtual String8 getMIMEType() const {
     53         return mMimeType;
     54     }
     55 
     56 protected:
     57     virtual ~DataUriSource() {
     58         // Nothing to delete.
     59     }
     60 
     61 private:
     62     const String8 mDataUri;
     63 
     64     String8 mMimeType;
     65     // Use AString because individual bytes may not be valid UTF8 chars.
     66     AString mData;
     67     status_t mInited;
     68 
     69     // Disallow copy and assign.
     70     DataUriSource(const DataUriSource &);
     71     DataUriSource &operator=(const DataUriSource &);
     72 };
     73 
     74 }  // namespace android
     75 
     76 #endif  // DATA_URI_SOURCE_H_
     77