Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017, 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 | |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 17 | #ifndef _ANDROID_MEDIA_DATASOURCECALLBACK_H_ |
| 18 | #define _ANDROID_MEDIA_DATASOURCECALLBACK_H_ |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 19 | |
| 20 | #include "jni.h" |
| 21 | |
| 22 | #include <media/DataSource.h> |
| 23 | #include <media/stagefright/foundation/ABase.h> |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/Mutex.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 29 | // The native counterpart to a Java android.media.DataSourceCallback. It inherits from |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 30 | // DataSource. |
| 31 | // |
| 32 | // If the java DataSource returns an error or throws an exception it |
| 33 | // will be considered to be in a broken state, and the only further call this |
| 34 | // will make is to close(). |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 35 | class JDataSourceCallback : public DataSource { |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 36 | public: |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 37 | JDataSourceCallback(JNIEnv *env, jobject source); |
| 38 | virtual ~JDataSourceCallback(); |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 39 | |
| 40 | virtual status_t initCheck() const override; |
| 41 | virtual ssize_t readAt(off64_t offset, void *data, size_t size) override; |
| 42 | virtual status_t getSize(off64_t *size) override; |
| 43 | |
| 44 | virtual String8 toString() override; |
| 45 | virtual String8 getMIMEType() const override; |
| 46 | virtual void close() override; |
| 47 | private: |
| 48 | // Protect all member variables with mLock because this object will be |
| 49 | // accessed on different threads. |
| 50 | Mutex mLock; |
| 51 | |
| 52 | // The status of the java DataSource. Set to OK unless an error occurred or |
| 53 | // close() was called. |
| 54 | status_t mJavaObjStatus; |
| 55 | // Only call the java getSize() once so the app can't change the size on us. |
| 56 | bool mSizeIsCached; |
| 57 | off64_t mCachedSize; |
| 58 | |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 59 | jobject mDataSourceCallbackObj; |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 60 | jmethodID mReadAtMethod; |
| 61 | jmethodID mGetSizeMethod; |
| 62 | jmethodID mCloseMethod; |
| 63 | jbyteArray mByteArrayObj; |
| 64 | |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 65 | DISALLOW_EVIL_CONSTRUCTORS(JDataSourceCallback); |
Wei Jia | 0a8a8f0 | 2017-12-05 17:05:29 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace android |
| 69 | |
Wei Jia | 073e1b1 | 2018-11-28 11:57:03 -0800 | [diff] [blame] | 70 | #endif // _ANDROID_MEDIA_DATASOURCECALLBACK_H_ |