Reorganize some of the stagefright implementation related to metadata.
diff --git a/media/libmedia/StagefrightMediaScanner.h b/include/media/stagefright/StagefrightMediaScanner.h
similarity index 93%
rename from media/libmedia/StagefrightMediaScanner.h
rename to include/media/stagefright/StagefrightMediaScanner.h
index 108acb4..af125dc 100644
--- a/media/libmedia/StagefrightMediaScanner.h
+++ b/include/media/stagefright/StagefrightMediaScanner.h
@@ -22,6 +22,8 @@
 
 namespace android {
 
+struct StagefrightMetadataRetriever;
+
 struct StagefrightMediaScanner : public MediaScanner {
     StagefrightMediaScanner();
     virtual ~StagefrightMediaScanner();
@@ -33,6 +35,8 @@
     virtual char *extractAlbumArt(int fd);
 
 private:
+    sp<StagefrightMetadataRetriever> mRetriever;
+
     StagefrightMediaScanner(const StagefrightMediaScanner &);
     StagefrightMediaScanner &operator=(const StagefrightMediaScanner &);
 };
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index 088ad6d..fc234ee 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -26,11 +26,6 @@
     MediaScannerClient.cpp \
     autodetect.cpp
 
-ifneq ($(BUILD_WITHOUT_PV),true)
-else
-LOCAL_SRC_FILES += StagefrightMediaScanner.cpp
-endif
-
 LOCAL_SHARED_LIBRARIES := \
 	libui libcutils libutils libbinder libsonivox libicuuc
 
diff --git a/media/libmedia/StagefrightMediaScanner.cpp b/media/libmedia/StagefrightMediaScanner.cpp
deleted file mode 100644
index 522ab5a..0000000
--- a/media/libmedia/StagefrightMediaScanner.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-#include "StagefrightMediaScanner.h"
-
-namespace android {
-
-StagefrightMediaScanner::StagefrightMediaScanner() {}
-
-StagefrightMediaScanner::~StagefrightMediaScanner() {}
-
-status_t StagefrightMediaScanner::processFile(
-        const char *path, const char *mimeType,
-        MediaScannerClient &client) {
-    client.setLocale(locale());
-    client.beginFile();
-    client.endFile();
-
-    return OK;
-}
-
-char *StagefrightMediaScanner::extractAlbumArt(int fd) {
-    return NULL;
-}
-
-}  // namespace android
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index 5e59710..d51ab30 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -19,7 +19,6 @@
 ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true)
 
 LOCAL_SRC_FILES +=                      \
-    StagefrightMetadataRetriever.cpp    \
     StagefrightPlayer.cpp               \
     StagefrightRecorder.cpp
 
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index f7df69c..30b4506 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -31,6 +31,8 @@
         MediaExtractor.cpp        \
         SampleTable.cpp           \
         ShoutcastSource.cpp       \
+        StagefrightMediaScanner.cpp \
+        StagefrightMetadataRetriever.cpp \
         TimeSource.cpp            \
         TimedEventQueue.cpp       \
         WAVExtractor.cpp          \
diff --git a/media/libstagefright/StagefrightMediaScanner.cpp b/media/libstagefright/StagefrightMediaScanner.cpp
new file mode 100644
index 0000000..9b41929
--- /dev/null
+++ b/media/libstagefright/StagefrightMediaScanner.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#include <media/stagefright/StagefrightMediaScanner.h>
+
+#include "include/StagefrightMetadataRetriever.h"
+
+namespace android {
+
+StagefrightMediaScanner::StagefrightMediaScanner()
+    : mRetriever(new StagefrightMetadataRetriever) {
+}
+
+StagefrightMediaScanner::~StagefrightMediaScanner() {}
+
+status_t StagefrightMediaScanner::processFile(
+        const char *path, const char *mimeType,
+        MediaScannerClient &client) {
+    client.setLocale(locale());
+    client.beginFile();
+
+    if (mRetriever->setDataSource(path) == OK
+            && mRetriever->setMode(
+                METADATA_MODE_METADATA_RETRIEVAL_ONLY) == OK) {
+        struct KeyMap {
+            const char *tag;
+            int key;
+        };
+        static const KeyMap kKeyMap[] = {
+            { "tracknumber", METADATA_KEY_CD_TRACK_NUMBER },
+            { "album", METADATA_KEY_ALBUM },
+            { "artist", METADATA_KEY_ARTIST },
+            { "composer", METADATA_KEY_COMPOSER },
+            { "genre", METADATA_KEY_GENRE },
+            { "title", METADATA_KEY_TITLE },
+            { "year", METADATA_KEY_YEAR },
+            { "duration", METADATA_KEY_DURATION },
+            { "writer", METADATA_KEY_WRITER },
+        };
+        static const size_t kNumEntries = sizeof(kKeyMap) / sizeof(kKeyMap[0]);
+
+        for (size_t i = 0; i < kNumEntries; ++i) {
+            const char *value;
+            if ((value = mRetriever->extractMetadata(kKeyMap[i].key)) != NULL) {
+                client.addStringTag(kKeyMap[i].tag, value);
+            }
+        }
+    }
+
+    client.endFile();
+
+    return OK;
+}
+
+char *StagefrightMediaScanner::extractAlbumArt(int fd) {
+    if (mRetriever->setDataSource(fd, 0, 0) == OK
+            && mRetriever->setMode(
+                METADATA_MODE_FRAME_CAPTURE_ONLY) == OK) {
+        MediaAlbumArt *art = mRetriever->extractAlbumArt();
+
+        // TODO: figure out what format the result should be in.
+    }
+
+    return NULL;
+}
+
+}  // namespace android
diff --git a/media/libmediaplayerservice/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp
similarity index 98%
rename from media/libmediaplayerservice/StagefrightMetadataRetriever.cpp
rename to media/libstagefright/StagefrightMetadataRetriever.cpp
index 42c1877..128e776 100644
--- a/media/libmediaplayerservice/StagefrightMetadataRetriever.cpp
+++ b/media/libstagefright/StagefrightMetadataRetriever.cpp
@@ -19,7 +19,7 @@
 #define LOG_TAG "StagefrightMetadataRetriever"
 #include <utils/Log.h>
 
-#include "StagefrightMetadataRetriever.h"
+#include "include/StagefrightMetadataRetriever.h"
 
 #include <media/stagefright/CachingDataSource.h>
 #include <media/stagefright/ColorConverter.h>
diff --git a/media/libmediaplayerservice/StagefrightMetadataRetriever.h b/media/libstagefright/include/StagefrightMetadataRetriever.h
similarity index 100%
rename from media/libmediaplayerservice/StagefrightMetadataRetriever.h
rename to media/libstagefright/include/StagefrightMetadataRetriever.h