1 /* 2 * Copyright 2015, 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 _ANDROID_MEDIA_MEDIADATASOURCE_H_ 18 #define _ANDROID_MEDIA_MEDIADATASOURCE_H_ 19 20 #include "jni.h" 21 22 #include <android/IDataSource.h> 23 #include <media/stagefright/foundation/ABase.h> 24 #include <utils/Errors.h> 25 #include <utils/Mutex.h> 26 27 namespace android { 28 29 // The native counterpart to a Java android.media.MediaDataSource. It inherits from 30 // IDataSource so that it can be accessed remotely. 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(). 35 class JMediaDataSource : public BnDataSource { 36 public: 37 enum { 38 kBufferSize = 64 * 1024, 39 }; 40 41 JMediaDataSource(JNIEnv *env, jobject source); 42 virtual ~JMediaDataSource(); 43 44 virtual sp<IMemory> getIMemory(); 45 virtual ssize_t readAt(off64_t offset, size_t size); 46 virtual status_t getSize(off64_t* size); 47 virtual void close(); 48 virtual uint32_t getFlags(); 49 virtual String8 toString(); 50 51 private: 52 // Protect all member variables with mLock because this object will be 53 // accessed on different binder worker threads. 54 Mutex mLock; 55 56 // The status of the java DataSource. Set to OK unless an error occurred or 57 // close() was called. 58 status_t mJavaObjStatus; 59 // Only call the java getSize() once so the app can't change the size on us. 60 bool mSizeIsCached; 61 off64_t mCachedSize; 62 sp<IMemory> mMemory; 63 64 jobject mMediaDataSourceObj; 65 jmethodID mReadMethod; 66 jmethodID mGetSizeMethod; 67 jmethodID mCloseMethod; 68 jbyteArray mByteArrayObj; 69 70 DISALLOW_EVIL_CONSTRUCTORS(JMediaDataSource); 71 }; 72 73 } // namespace android 74 75 #endif // _ANDROID_MEDIA_MEDIADATASOURCE_H_ 76