remove OMXCodec.cpp dependency

Switched to SimpleDecodingSource from OMXSource, as we don't do
pause/seek.

Switched to tracking only the capability of the first video codec
for each type, as we only use the first one.

Bug: 17108024
Change-Id: I6bf8e90b6658366b68329494d5805f5a122c8b8a
diff --git a/src/android/AacBqToPcmCbRenderer.cpp b/src/android/AacBqToPcmCbRenderer.cpp
index 3438c91..82b50f9 100644
--- a/src/android/AacBqToPcmCbRenderer.cpp
+++ b/src/android/AacBqToPcmCbRenderer.cpp
@@ -19,7 +19,7 @@
 #include "sles_allinclusive.h"
 #include "android/include/AacBqToPcmCbRenderer.h"
 #include "android/channels.h"
-#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/SimpleDecodingSource.h>
 
 namespace android {
 
@@ -157,15 +157,9 @@
         notifyPrepared(ERROR_UNSUPPORTED);
         return;
     }
-    sp<MetaData> meta = extractor->getTrackMetaData(kTrackToDecode);
 
     // the audio content is not raw PCM, so we need a decoder
-    OMXClient client;
-    CHECK_EQ(client.connect(), (status_t)OK);
-
-    source = OMXCodec::Create(
-            client.interface(), meta, false /* createEncoder */,
-            source);
+    source = SimpleDecodingSource::Create(source);
 
     if (source == NULL) {
         SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate decoder.");
@@ -173,7 +167,7 @@
         return;
     }
 
-    meta = source->getFormat();
+    sp<MetaData> meta = source->getFormat();
 
     SL_LOGD("AacBqToPcmCbRenderer::onPrepare() after instantiating decoder");
 
diff --git a/src/android/VideoCodec_to_android.cpp b/src/android/VideoCodec_to_android.cpp
index 0d5dd22..cca86eb 100644
--- a/src/android/VideoCodec_to_android.cpp
+++ b/src/android/VideoCodec_to_android.cpp
@@ -16,11 +16,9 @@
 
 #include "sles_allinclusive.h"
 
-#include <media/IMediaPlayerService.h>
-#include <media/stagefright/OMXClient.h>
-#include <media/stagefright/OMXCodec.h>
-#include <media/IOMX.h>
+#include <media/stagefright/MediaCodecList.h>
 #include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/SimpleDecodingSource.h>
 
 
 namespace android {
@@ -38,8 +36,11 @@
 static const size_t kNbVideoMimeTypes = sizeof(kVideoMimeTypes) / sizeof(kVideoMimeTypes[0]);
 
 // codec capabilities in the following arrays maps to the mime types defined in kVideoMimeTypes
-// CodecCapabilities is from OMXCodec.h
-static Vector<CodecCapabilities> VideoDecoderCapabilities[kNbVideoMimeTypes];
+struct CodecCapabilities {
+    Vector<MediaCodecInfo::ProfileLevel> mProfileLevels;
+};
+
+static CodecCapabilities VideoDecoderCapabilities[kNbVideoMimeTypes];
 static XAuint32 VideoDecoderNbProfLevel[kNbVideoMimeTypes];
 
 static XAuint32 NbSupportedDecoderTypes = 0;
@@ -58,54 +59,60 @@
 bool android_videoCodec_expose() {
     SL_LOGV("android_videoCodec_expose()");
 
-    sp<IMediaPlayerService> service(IMediaDeathNotifier::getMediaPlayerService());
-    if (service == NULL) {
-        // no need to SL_LOGE; getMediaPlayerService already will have done so
-        return false;
-    }
-
-    sp<IOMX> omx(service->getOMX());
-    if (omx.get() == NULL) {
-        ALOGE("android_videoCodec_expose() couldn't access OMX interface");
+    sp<IMediaCodecList> list = MediaCodecList::getInstance();
+    if (list == NULL) {
+        SL_LOGE("could not get MediaCodecList");
         return false;
     }
 
     // used to check whether no codecs were found, which is a sign of failure
     NbSupportedDecoderTypes = 0;
     for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) {
-        // QueryCodecs is from OMXCodec.h
-        if (OK == QueryCodecs(omx, kVideoMimeTypes[m], true /* queryDecoders */,
-                true /* hwCodecOnly */, &VideoDecoderCapabilities[m])) {
-            if (VideoDecoderCapabilities[m].empty()) {
-                VideoDecoderNbProfLevel[m] = 0;
-            } else {
-                // get the number of profiles and levels for the first codec implementation
-                // for a given decoder ID / MIME type
-                Vector<CodecProfileLevel> &profileLevels =
-                        VideoDecoderCapabilities[m].editItemAt(0).mProfileLevels;
+        VideoDecoderNbProfLevel[m] = 0;
+        for (ssize_t index = 0;;) {
+            index = list->findCodecByType(
+                    kVideoMimeTypes[m], false /* encoder */, index);
+            if (index < 0) {
+                break;
+            }
+
+            sp<MediaCodecInfo> info = list->getCodecInfo(index);
+            if (info == NULL || MediaCodecList::isSoftwareCodec(info->getCodecName())) {
+                continue; // HW codec only
+            }
+
+            sp<MediaCodecInfo::Capabilities> caps = info->getCapabilitiesFor(kVideoMimeTypes[m]);
+            if (caps == NULL) {
+                continue; // this should not happen
+            }
+
+            // get the number of profiles and levels
+            Vector<MediaCodecInfo::ProfileLevel> &profileLevels =
+                VideoDecoderCapabilities[m].mProfileLevels;
+            caps->getSupportedProfileLevels(&profileLevels);
 #if 0   // Intentionally disabled example of making modifications to profile / level combinations
-                if (VideoDecoderIds[m] == XA_VIDEOCODEC_AVC) {
-                    // remove non-core profile / level combinations
-                    for (size_t i = 0, size = profileLevels.size(); i < size; ) {
-                        CodecProfileLevel profileLevel = profileLevels.itemAt(i);
-                        if (profileLevel.mProfile == XA_VIDEOPROFILE_AVC_BASELINE) {
-                            // either skip past this item and don't change vector size
-                            ++i;
-                        } else {
-                            // or remove this item, decrement the vector size,
-                            // and next time through the loop check a different item at same index
-                            profileLevels.removeAt(i);
-                            --size;
-                        }
+            if (VideoDecoderIds[m] == XA_VIDEOCODEC_AVC) {
+                // remove non-core profile / level combinations
+                for (size_t i = 0, size = profileLevels.size(); i < size; ) {
+                    MediaCodecInfo::ProfileLevel profileLevel = profileLevels.itemAt(i);
+                    if (profileLevel.mProfile == XA_VIDEOPROFILE_AVC_BASELINE) {
+                        // either skip past this item and don't change vector size
+                        ++i;
+                    } else {
+                        // or remove this item, decrement the vector size,
+                        // and next time through the loop check a different item at same index
+                        profileLevels.removeAt(i);
+                        --size;
                     }
                 }
-#endif
-                if ((VideoDecoderNbProfLevel[m] = profileLevels.size()) > 0) {
-                    NbSupportedDecoderTypes++;
-                } else {
-                    VideoDecoderCapabilities[m].clear();
-                }
             }
+#endif
+            if ((VideoDecoderNbProfLevel[m] = profileLevels.size()) > 0) {
+                NbSupportedDecoderTypes++;
+            }
+
+            // only consider first codec implementation for given decoder ID / MIME type
+            break;
         }
     }
 
@@ -115,9 +122,6 @@
 
 void android_videoCodec_deinit() {
     SL_LOGV("android_videoCodec_deinit()");
-    for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) {
-        VideoDecoderCapabilities[m].clear();
-    }
     // not needed
     // memset(VideoDecoderNbProfLevel, 0, sizeof(VideoDecoderNbProfLevel));
     // NbSupportedDecoderTypes = 0;
@@ -133,7 +137,7 @@
     XAuint32 *pIds = pDecoderIds;
     XAuint32 nbFound = 0;
     for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) {
-        if (!VideoDecoderCapabilities[m].empty()) {
+        if (VideoDecoderNbProfLevel[m] > 0) {
             *pIds = VideoDecoderIds[m];
             pIds++;
             nbFound++;
@@ -173,7 +177,7 @@
         if (decoderId == VideoDecoderIds[decoderIndex]) {
             // We only look at the first codec implementation for a given decoder ID / MIME type.
             // OpenMAX AL doesn't let you expose the capabilities of multiple codec implementations.
-            if (!(plIndex < VideoDecoderCapabilities[decoderIndex].itemAt(0).mProfileLevels.size()))
+            if (!(plIndex < VideoDecoderCapabilities[decoderIndex].mProfileLevels.size()))
             {
                 // asking for invalid profile/level
                 return XA_RESULT_PARAMETER_INVALID;
@@ -181,9 +185,9 @@
             //     set the fields we know about
             pDescr->codecId = decoderId;
             pDescr->profileSetting = convertOpenMaxIlToAl(VideoDecoderCapabilities[decoderIndex].
-                    itemAt(0).mProfileLevels.itemAt(plIndex).mProfile);
+                    mProfileLevels.itemAt(plIndex).mProfile);
             pDescr->levelSetting = convertOpenMaxIlToAl(VideoDecoderCapabilities[decoderIndex].
-                    itemAt(0).mProfileLevels.itemAt(plIndex).mLevel);
+                    mProfileLevels.itemAt(plIndex).mLevel);
             //     initialize the fields we don't know about
             pDescr->maxWidth = 0;
             pDescr->maxHeight = 0;
diff --git a/src/android/android_AudioSfDecoder.cpp b/src/android/android_AudioSfDecoder.cpp
index d95a235..d3d9e67 100644
--- a/src/android/android_AudioSfDecoder.cpp
+++ b/src/android/android_AudioSfDecoder.cpp
@@ -23,6 +23,7 @@
 #include <binder/IServiceManager.h>
 #include <media/IMediaHTTPService.h>
 #include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/SimpleDecodingSource.h>
 
 
 #define SIZE_CACHED_HIGH_BYTES 1000000
@@ -297,13 +298,7 @@
 
     // the audio content is not raw PCM, so we need a decoder
     if (!isRawAudio) {
-        OMXClient client;
-        CHECK_EQ(client.connect(), (status_t)OK);
-
-        source = OMXCodec::Create(
-                client.interface(), meta, false /* createEncoder */,
-                source);
-
+        source = SimpleDecodingSource::Create(source);
         if (source == NULL) {
             SL_LOGE("AudioSfDecoder::onPrepare: Could not instantiate decoder.");
             notifyPrepared(ERROR_UNSUPPORTED);