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 <media/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 virtual sp<DecryptHandle> DrmInitialization(const char *mime); 51 52 private: 53 // Protect all member variables with mLock because this object will be 54 // accessed on different binder worker threads. 55 Mutex mLock; 56 57 // The status of the java DataSource. Set to OK unless an error occurred or 58 // close() was called. 59 status_t mJavaObjStatus; 60 // Only call the java getSize() once so the app can't change the size on us. 61 bool mSizeIsCached; 62 off64_t mCachedSize; 63 sp<IMemory> mMemory; 64 65 jobject mMediaDataSourceObj; 66 jmethodID mReadMethod; 67 jmethodID mGetSizeMethod; 68 jmethodID mCloseMethod; 69 jbyteArray mByteArrayObj; 70 71 DISALLOW_EVIL_CONSTRUCTORS(JMediaDataSource); 72 }; 73 74 } // namespace android 75 76 #endif // _ANDROID_MEDIA_MEDIADATASOURCE_H_ 77