Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 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> |
Marco Nelissen | dab79b3 | 2019-11-18 08:25:47 -0800 | [diff] [blame] | 22 | |
| 23 | #include <android/IDataSource.h> |
Andreas Huber | 0683eba | 2011-07-18 13:47:55 -0700 | [diff] [blame] | 24 | #include <media/stagefright/MediaErrors.h> |
Marco Nelissen | 7291da6 | 2019-12-17 13:01:55 -0800 | [diff] [blame] | 25 | #include <media/stagefright/DataSourceBase.h> |
Marco Nelissen | 0e043b6 | 2018-11-14 11:26:05 -0800 | [diff] [blame] | 26 | #include <media/MediaExtractorPluginApi.h> |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 27 | #include <utils/Errors.h> |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 29 | #include <utils/threads.h> |
| 30 | |
Marco Nelissen | 2a243f0 | 2018-01-30 08:29:57 -0800 | [diff] [blame] | 31 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | class String8; |
| 35 | |
Marco Nelissen | 2a243f0 | 2018-01-30 08:29:57 -0800 | [diff] [blame] | 36 | class DataSource : public DataSourceBase, public virtual RefBase { |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 37 | public: |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 38 | DataSource() : mWrapper(NULL) {} |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 39 | |
Dongwon Kang | 6969da6 | 2018-02-12 20:55:14 -0800 | [diff] [blame] | 40 | // returns a pointer to IDataSource if it is wrapped. |
| 41 | virtual sp<IDataSource> getIDataSource() const { |
| 42 | return nullptr; |
| 43 | } |
| 44 | |
Dongwon Kang | b486b52 | 2018-02-16 15:46:53 -0800 | [diff] [blame] | 45 | virtual String8 toString() { |
| 46 | return String8("<unspecified>"); |
| 47 | } |
| 48 | |
| 49 | virtual status_t reconnectAtOffset(off64_t /*offset*/) { |
| 50 | return ERROR_UNSUPPORTED; |
| 51 | } |
| 52 | |
| 53 | //////////////////////////////////////////////////////////////////////////// |
| 54 | |
Dongwon Kang | b486b52 | 2018-02-16 15:46:53 -0800 | [diff] [blame] | 55 | virtual String8 getUri() { |
| 56 | return String8(); |
| 57 | } |
| 58 | |
| 59 | virtual bool getUri(char *uriString, size_t bufferSize) final { |
| 60 | int ret = snprintf(uriString, bufferSize, "%s", getUri().c_str()); |
| 61 | return ret >= 0 && static_cast<size_t>(ret) < bufferSize; |
| 62 | } |
| 63 | |
| 64 | virtual String8 getMIMEType() const { |
| 65 | return String8("application/octet-stream"); |
| 66 | } |
| 67 | |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 68 | CDataSource *wrap() { |
| 69 | if (mWrapper) { |
| 70 | return mWrapper; |
| 71 | } |
| 72 | mWrapper = new CDataSource(); |
| 73 | mWrapper->handle = this; |
| 74 | |
| 75 | mWrapper->readAt = [](void *handle, off64_t offset, void *data, size_t size) -> ssize_t { |
| 76 | return ((DataSource*)handle)->readAt(offset, data, size); |
| 77 | }; |
| 78 | mWrapper->getSize = [](void *handle, off64_t *size) -> status_t { |
| 79 | return ((DataSource*)handle)->getSize(size); |
| 80 | }; |
| 81 | mWrapper->flags = [](void *handle) -> uint32_t { |
| 82 | return ((DataSource*)handle)->flags(); |
| 83 | }; |
| 84 | mWrapper->getUri = [](void *handle, char *uriString, size_t bufferSize) -> bool { |
| 85 | return ((DataSource*)handle)->getUri(uriString, bufferSize); |
| 86 | }; |
| 87 | return mWrapper; |
| 88 | } |
| 89 | |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 90 | protected: |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 91 | virtual ~DataSource() { |
| 92 | delete mWrapper; |
| 93 | } |
Andreas Huber | 693d271 | 2009-08-14 14:37:10 -0700 | [diff] [blame] | 94 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 95 | private: |
Marco Nelissen | cec44d0 | 2018-06-17 22:21:09 -0700 | [diff] [blame] | 96 | CDataSource *mWrapper; |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 97 | DataSource(const DataSource &); |
| 98 | DataSource &operator=(const DataSource &); |
| 99 | }; |
| 100 | |
Andreas Huber | 20111aa | 2009-07-14 16:56:47 -0700 | [diff] [blame] | 101 | } // namespace android |
| 102 | |
| 103 | #endif // DATA_SOURCE_H_ |