2 * Copyright 2015, The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _ANDROID_MEDIA_MEDIADATASOURCE_H_
18 #define _ANDROID_MEDIA_MEDIADATASOURCE_H_
22 #include <media/IDataSource.h>
23 #include <media/stagefright/foundation/ABase.h>
24 #include <utils/Errors.h>
25 #include <utils/Mutex.h>
29 // The native counterpart to a Java android.media.MediaDataSource. It inherits from
30 // IDataSource so that it can be accessed remotely.
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 {
38 kBufferSize = 64 * 1024,
41 JMediaDataSource(JNIEnv *env, jobject source);
42 virtual ~JMediaDataSource();
44 virtual sp<IMemory> getIMemory();
45 virtual ssize_t readAt(off64_t offset, size_t size);
46 virtual status_t getSize(off64_t* size);
50 // Protect all member variables with mLock because this object will be
51 // accessed on different binder worker threads.
54 // The status of the java DataSource. Set to OK unless an error occurred or
55 // close() was called.
56 status_t mJavaObjStatus;
57 // Only call the java getSize() once so the app can't change the size on us.
62 jobject mMediaDataSourceObj;
63 jmethodID mReadMethod;
64 jmethodID mGetSizeMethod;
65 jmethodID mCloseMethod;
66 jbyteArray mByteArrayObj;
68 DISALLOW_EVIL_CONSTRUCTORS(JMediaDataSource);
71 } // namespace android
73 #endif // _ANDROID_MEDIA_MEDIADATASOURCE_H_