C-ify DataSource
Add a C API for DataSource/Base, and a helper so extractors
can continue using a C++ API.
Bug: 111407253
Test: build, boot, play some files
Change-Id: I1c8b2990e17d18eee53c9abf7ebef2ced0e8b7fd
diff --git a/media/libmedia/MidiIoWrapper.cpp b/media/libmedia/MidiIoWrapper.cpp
index 5ca3b48..1150d61 100644
--- a/media/libmedia/MidiIoWrapper.cpp
+++ b/media/libmedia/MidiIoWrapper.cpp
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <media/MidiIoWrapper.h>
+#include <media/MediaExtractorPluginApi.h>
static int readAt(void *handle, void *buffer, int pos, int size) {
return ((android::MidiIoWrapper*)handle)->readAt(buffer, pos, size);
@@ -61,6 +62,51 @@
}
}
+class DataSourceUnwrapper : public DataSourceBase {
+
+public:
+ explicit DataSourceUnwrapper(CDataSource *csource) {
+ mSource = csource;
+ }
+ virtual status_t initCheck() const { return OK; }
+
+ // Returns the number of bytes read, or -1 on failure. It's not an error if
+ // this returns zero; it just means the given offset is equal to, or
+ // beyond, the end of the source.
+ virtual ssize_t readAt(off64_t offset, void *data, size_t size) {
+ return mSource->readAt(mSource->handle, offset, data, size);
+ }
+
+ // May return ERROR_UNSUPPORTED.
+ virtual status_t getSize(off64_t *size) {
+ return mSource->getSize(mSource->handle, size);
+ }
+
+ virtual bool getUri(char * /*uriString*/, size_t /*bufferSize*/) {
+ return false;
+ }
+
+ virtual uint32_t flags() {
+ return 0;
+ }
+
+ virtual void close() {};
+private:
+ CDataSource *mSource;
+};
+
+MidiIoWrapper::MidiIoWrapper(CDataSource *csource) {
+ ALOGV("MidiIoWrapper(CDataSource)");
+ mFd = -1;
+ mDataSource = new DataSourceUnwrapper(csource);
+ off64_t l;
+ if (mDataSource->getSize(&l) == OK) {
+ mLength = l;
+ } else {
+ mLength = 0;
+ }
+}
+
MidiIoWrapper::~MidiIoWrapper() {
ALOGV("~MidiIoWrapper");
if (mFd >= 0) {