AIDLize MediaExtractorService
Use .aidl instead of handwritten binder code for MediaExtractorService.
Test: build, CTS
Change-Id: Ibc93eca9128552c23359218ac3bf12319391e1b1
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index b064f08..0750fd2 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -23,6 +23,14 @@
path: "aidl",
}
+filegroup {
+ name: "mediaextractorservice_aidl",
+ srcs: [
+ "aidl/android/IMediaExtractorService.aidl",
+ ],
+ path: "aidl",
+}
+
aidl_interface {
name: "resourcemanager_aidl_interface",
local_include_dir: "aidl",
@@ -249,13 +257,13 @@
name: "libmedia",
srcs: [
+ ":mediaextractorservice_aidl",
"IDataSource.cpp",
"BufferingSettings.cpp",
"mediaplayer.cpp",
"IMediaHTTPConnection.cpp",
"IMediaHTTPService.cpp",
"IMediaExtractor.cpp",
- "IMediaExtractorService.cpp",
"IMediaPlayerService.cpp",
"IMediaPlayerClient.cpp",
"IMediaRecorderClient.cpp",
diff --git a/media/libmedia/IDataSource.cpp b/media/libmedia/IDataSource.cpp
index 61f0a68..e96a113 100644
--- a/media/libmedia/IDataSource.cpp
+++ b/media/libmedia/IDataSource.cpp
@@ -19,8 +19,7 @@
#include <utils/Log.h>
#include <utils/Timers.h>
-#include <media/IDataSource.h>
-
+#include <android/IDataSource.h>
#include <binder/IMemory.h>
#include <binder/Parcel.h>
#include <media/stagefright/foundation/ADebug.h>
diff --git a/media/libmedia/IMediaExtractor.cpp b/media/libmedia/IMediaExtractor.cpp
index fb6d3a2..7389851 100644
--- a/media/libmedia/IMediaExtractor.cpp
+++ b/media/libmedia/IMediaExtractor.cpp
@@ -25,7 +25,7 @@
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
#include <binder/PermissionCache.h>
-#include <media/IMediaExtractor.h>
+#include <android/IMediaExtractor.h>
#include <media/stagefright/MetaData.h>
namespace android {
diff --git a/media/libmedia/IMediaExtractorService.cpp b/media/libmedia/IMediaExtractorService.cpp
deleted file mode 100644
index 243b09d..0000000
--- a/media/libmedia/IMediaExtractorService.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
-**
-** Copyright 2007, 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.
-*/
-
-#define LOG_TAG "IMediaExtractorService"
-//#define LOG_NDEBUG 0
-
-#include <utils/Log.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <binder/Parcel.h>
-#include <media/IMediaExtractorService.h>
-
-namespace android {
-
-enum {
- MAKE_EXTRACTOR = IBinder::FIRST_CALL_TRANSACTION,
- MAKE_IDATA_SOURCE_FD,
- GET_SUPPORTED_TYPES,
-};
-
-class BpMediaExtractorService : public BpInterface<IMediaExtractorService>
-{
-public:
- explicit BpMediaExtractorService(const sp<IBinder>& impl)
- : BpInterface<IMediaExtractorService>(impl)
- {
- }
-
- virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime) {
- Parcel data, reply;
- data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(source));
- if (mime != NULL) {
- data.writeCString(mime);
- }
- status_t ret = remote()->transact(MAKE_EXTRACTOR, data, &reply);
- if (ret == NO_ERROR) {
- return interface_cast<IMediaExtractor>(reply.readStrongBinder());
- }
- return NULL;
- }
-
- virtual sp<IDataSource> makeIDataSource(int fd, int64_t offset, int64_t length)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
- data.writeFileDescriptor(fd);
- data.writeInt64(offset);
- data.writeInt64(length);
- status_t ret = remote()->transact(MAKE_IDATA_SOURCE_FD, data, &reply);
- ALOGV("fd:%d offset:%lld length:%lld ret:%d",
- fd, (long long)offset, (long long)length, ret);
- if (ret == NO_ERROR) {
- return interface_cast<IDataSource>(reply.readStrongBinder());
- }
- return nullptr;
- }
-
- virtual std::unordered_set<std::string> getSupportedTypes() {
- std::unordered_set<std::string> supportedTypes;
- Parcel data, reply;
- data.writeInterfaceToken(IMediaExtractorService::getInterfaceDescriptor());
- status_t ret = remote()->transact(GET_SUPPORTED_TYPES, data, &reply);
- if (ret == NO_ERROR) {
- // process reply
- while(true) {
- const char *ext = reply.readCString();
- if (!ext) {
- break;
- }
- supportedTypes.insert(std::string(ext));
- }
- }
- return supportedTypes;
- }
-};
-
-IMPLEMENT_META_INTERFACE(MediaExtractorService, "android.media.IMediaExtractorService");
-
-// ----------------------------------------------------------------------
-
-status_t BnMediaExtractorService::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- switch (code) {
-
- case MAKE_EXTRACTOR: {
- CHECK_INTERFACE(IMediaExtractorService, data, reply);
- sp<IBinder> b;
- status_t ret = data.readStrongBinder(&b);
- if (ret != NO_ERROR || b == NULL) {
- ALOGE("Error reading source from parcel");
- return ret;
- }
- // If we make an extractor through Binder, enabled shared memory
- // for MediaBuffers for this process.
- MediaBuffer::useSharedMemory();
- sp<IDataSource> source = interface_cast<IDataSource>(b);
- const char *mime = data.readCString();
- sp<IMediaExtractor> ex = makeExtractor(source, mime);
- reply->writeStrongBinder(IInterface::asBinder(ex));
- return NO_ERROR;
- }
-
- case MAKE_IDATA_SOURCE_FD: {
- CHECK_INTERFACE(IMediaExtractorService, data, reply);
- const int fd = dup(data.readFileDescriptor()); // -1 fd checked in makeIDataSource
- const int64_t offset = data.readInt64();
- const int64_t length = data.readInt64();
- ALOGV("fd %d offset%lld length:%lld", fd, (long long)offset, (long long)length);
- sp<IDataSource> source = makeIDataSource(fd, offset, length);
- reply->writeStrongBinder(IInterface::asBinder(source));
- // The FileSource closes the descriptor, so if it is not created
- // we need to close the descriptor explicitly.
- if (source.get() == nullptr && fd != -1) {
- close(fd);
- }
- return NO_ERROR;
- }
-
- case GET_SUPPORTED_TYPES:
- {
- CHECK_INTERFACE(IMediaExtractorService, data, reply);
- std::unordered_set<std::string> supportedTypes = getSupportedTypes();
- for (auto it = supportedTypes.begin(); it != supportedTypes.end(); ++it) {
- reply->writeCString((*it).c_str());
- }
- return NO_ERROR;
- }
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------------
-
-} // namespace android
diff --git a/media/libmedia/IMediaMetadataRetriever.cpp b/media/libmedia/IMediaMetadataRetriever.cpp
index d95bc8e..8a3b84e 100644
--- a/media/libmedia/IMediaMetadataRetriever.cpp
+++ b/media/libmedia/IMediaMetadataRetriever.cpp
@@ -19,8 +19,8 @@
#include <stdint.h>
#include <sys/types.h>
+#include <android/IDataSource.h>
#include <binder/Parcel.h>
-#include <media/IDataSource.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaMetadataRetriever.h>
#include <processgroup/sched_policy.h>
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index ea06665..20bc23d 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -19,18 +19,15 @@
#include <stdint.h>
#include <sys/types.h>
+#include <android/IDataSource.h>
#include <binder/Parcel.h>
-
+#include <gui/IGraphicBufferProducer.h>
#include <media/AudioResamplerPublic.h>
#include <media/AVSyncSettings.h>
#include <media/BufferingSettings.h>
-
-#include <media/IDataSource.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaPlayer.h>
#include <media/IStreamSource.h>
-
-#include <gui/IGraphicBufferProducer.h>
#include <utils/String8.h>
namespace android {
diff --git a/media/libmedia/aidl/android/IDataSource.aidl b/media/libmedia/aidl/android/IDataSource.aidl
new file mode 100644
index 0000000..fb954bf
--- /dev/null
+++ b/media/libmedia/aidl/android/IDataSource.aidl
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android;
+
+/** @hide */
+interface IDataSource {
+ // Stub for manual implementation
+}
diff --git a/media/libmedia/aidl/android/IMediaExtractor.aidl b/media/libmedia/aidl/android/IMediaExtractor.aidl
new file mode 100644
index 0000000..5ba68e6
--- /dev/null
+++ b/media/libmedia/aidl/android/IMediaExtractor.aidl
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android;
+
+/** @hide */
+interface IMediaExtractor {
+ // Stub for manual implementation
+}
diff --git a/media/libmedia/aidl/android/IMediaExtractorService.aidl b/media/libmedia/aidl/android/IMediaExtractorService.aidl
new file mode 100644
index 0000000..c57fa16
--- /dev/null
+++ b/media/libmedia/aidl/android/IMediaExtractorService.aidl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android;
+
+import android.IDataSource;
+import android.IMediaExtractor;
+
+/**
+ * Binder interface for the media extractor service
+ *
+ * @hide
+ */
+interface IMediaExtractorService {
+
+ IMediaExtractor makeExtractor(IDataSource source, @nullable @utf8InCpp String mime);
+ IDataSource makeIDataSource(in FileDescriptor fd, long offset, long length);
+ @utf8InCpp String[] getSupportedTypes();
+}
diff --git a/media/libmedia/include/media/IDataSource.h b/media/libmedia/include/android/IDataSource.h
similarity index 100%
rename from media/libmedia/include/media/IDataSource.h
rename to media/libmedia/include/android/IDataSource.h
diff --git a/media/libmedia/include/media/IMediaExtractor.h b/media/libmedia/include/android/IMediaExtractor.h
similarity index 100%
rename from media/libmedia/include/media/IMediaExtractor.h
rename to media/libmedia/include/android/IMediaExtractor.h
diff --git a/media/libmedia/include/media/IMediaExtractorService.h b/media/libmedia/include/media/IMediaExtractorService.h
deleted file mode 100644
index 5ce2cdb..0000000
--- a/media/libmedia/include/media/IMediaExtractorService.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2013 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_IMEDIAEXTRACTORSERVICE_H
-#define ANDROID_IMEDIAEXTRACTORSERVICE_H
-
-#include <unordered_set>
-
-#include <binder/IInterface.h>
-#include <binder/IMemory.h>
-#include <binder/Parcel.h>
-#include <media/IDataSource.h>
-#include <media/IMediaExtractor.h>
-
-namespace android {
-
-class IMediaExtractorService: public IInterface
-{
-public:
- DECLARE_META_INTERFACE(MediaExtractorService);
-
- virtual sp<IMediaExtractor> makeExtractor(const sp<IDataSource> &source, const char *mime) = 0;
-
- virtual sp<IDataSource> makeIDataSource(int fd, int64_t offset, int64_t length) = 0;
-
- virtual std::unordered_set<std::string> getSupportedTypes() = 0;
-};
-
-class BnMediaExtractorService: public BnInterface<IMediaExtractorService>
-{
-public:
- virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags = 0);
-};
-
-} // namespace android
-
-#endif // ANDROID_IMEDIAEXTRACTORSERVICE_H
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 26908e5..60d2f85 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -17,6 +17,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "MediaPlayerNative"
+#include <utils/Log.h>
#include <fcntl.h>
#include <inttypes.h>
@@ -24,25 +25,15 @@
#include <sys/types.h>
#include <unistd.h>
-#include <utils/Log.h>
-#include <binder/IServiceManager.h>
+#include <android/IDataSource.h>
#include <binder/IPCThreadState.h>
-
-#include <gui/Surface.h>
-
#include <media/mediaplayer.h>
#include <media/AudioResamplerPublic.h>
#include <media/AudioSystem.h>
#include <media/AVSyncSettings.h>
-#include <media/IDataSource.h>
-#include <media/MediaAnalyticsItem.h>
-
-#include <binder/MemoryBase.h>
-
#include <utils/KeyedVector.h>
#include <utils/String8.h>
-
#include <system/audio.h>
#include <system/window.h>