4eaa293808
This allows apps to implement MediaDataSource, which is modeled on stagefright's DataSource, to supply media data to the framework. This was already implemented for MediaExtractor, but it was renamed from DataSource. MediaExtractor, MediaPlayer and MediaMetadataRetriever each have a new overload: #setDataSource(android.media.MediaDataSource) Only NuPlayer supports this new data source. The change introduces: * IDataSource: The binder interface for DataSource. * JMediaDataSource: The native counterpart to the java interface. It implements IDataSource. * CallbackDataSource: A stagefright DataSource that wraps an IDataSource. Change-Id: I6d9c1167b4a7384c469b1e928f31791a7ebed716
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
/*
|
|
* Copyright 2015, The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef _ANDROID_MEDIA_MEDIADATASOURCE_H_
|
|
#define _ANDROID_MEDIA_MEDIADATASOURCE_H_
|
|
|
|
#include "jni.h"
|
|
|
|
#include <media/IDataSource.h>
|
|
#include <media/stagefright/foundation/ABase.h>
|
|
#include <utils/Errors.h>
|
|
#include <utils/Mutex.h>
|
|
|
|
namespace android {
|
|
|
|
// The native counterpart to a Java android.media.MediaDataSource. It inherits from
|
|
// IDataSource so that it can be accessed remotely.
|
|
//
|
|
// If the java DataSource returns an error or throws an exception it
|
|
// will be considered to be in a broken state, and the only further call this
|
|
// will make is to close().
|
|
class JMediaDataSource : public BnDataSource {
|
|
public:
|
|
enum {
|
|
kBufferSize = 64 * 1024,
|
|
};
|
|
|
|
JMediaDataSource(JNIEnv *env, jobject source);
|
|
virtual ~JMediaDataSource();
|
|
|
|
virtual sp<IMemory> getIMemory();
|
|
virtual ssize_t readAt(off64_t offset, size_t size);
|
|
virtual status_t getSize(off64_t* size);
|
|
virtual void close();
|
|
|
|
private:
|
|
// Protect all member variables with mLock because this object will be
|
|
// accessed on different binder worker threads.
|
|
Mutex mLock;
|
|
|
|
// The status of the java DataSource. Set to OK unless an error occurred or
|
|
// close() was called.
|
|
status_t mJavaObjStatus;
|
|
// Only call the java getSize() once so the app can't change the size on us.
|
|
bool mSizeIsCached;
|
|
off64_t mCachedSize;
|
|
sp<IMemory> mMemory;
|
|
|
|
jobject mMediaDataSourceObj;
|
|
jmethodID mReadMethod;
|
|
jmethodID mGetSizeMethod;
|
|
jmethodID mCloseMethod;
|
|
jbyteArray mByteArrayObj;
|
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(JMediaDataSource);
|
|
};
|
|
|
|
} // namespace android
|
|
|
|
#endif // _ANDROID_MEDIA_MEDIADATASOURCE_H_
|