From fceef46513db3507b413f604cea89e3c7f352663 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Fri, 14 May 2010 15:35:17 -0400 Subject: MTP: More prototyping work: New media scanner test program Media scanner now cleans up after files that no longer exist Separate database table for audio files Extract metadata from audio files with libstagefright Change-Id: I2bd0fe877836c741658e72fcfeb89c11be0d9b41 Signed-off-by: Mike Lockwood --- media/mtp/MtpStorage.cpp | 62 +++--------------------------------------------- 1 file changed, 3 insertions(+), 59 deletions(-) (limited to 'media/mtp/MtpStorage.cpp') diff --git a/media/mtp/MtpStorage.cpp b/media/mtp/MtpStorage.cpp index d4de819..f176148 100644 --- a/media/mtp/MtpStorage.cpp +++ b/media/mtp/MtpStorage.cpp @@ -16,6 +16,7 @@ #include "MtpDatabase.h" #include "MtpStorage.h" +#include "MtpMediaScanner.h" #include #include @@ -74,65 +75,8 @@ const char* MtpStorage::getDescription() const { } bool MtpStorage::scanFiles() { - mDatabase->beginTransaction(); - int ret = scanDirectory(mFilePath, MTP_PARENT_ROOT); - mDatabase->commitTransaction(); - return (ret == 0); -} - -int MtpStorage::scanDirectory(const char* path, MtpObjectHandle parent) -{ - char buffer[PATH_MAX]; - struct dirent* entry; - - int length = strlen(path); - if (length > sizeof(buffer) + 2) { - fprintf(stderr, "path too long: %s\n", path); - } - - DIR* dir = opendir(path); - if (!dir) { - fprintf(stderr, "opendir %s failed, errno: %d", path, errno); - return -1; - } - - strncpy(buffer, path, sizeof(buffer)); - char* fileStart = buffer + length; - // make sure we have a trailing slash - if (fileStart[-1] != '/') { - *(fileStart++) = '/'; - } - int fileNameLength = sizeof(buffer) + fileStart - buffer; - - while ((entry = readdir(dir))) { - const char* name = entry->d_name; - - // ignore "." and "..", as well as any files or directories staring with dot - if (name[0] == '.') { - continue; - } - if (strlen(name) + 1 > fileNameLength) { - fprintf(stderr, "path too long for %s\n", name); - continue; - } - strcpy(fileStart, name); - - struct stat statbuf; - memset(&statbuf, 0, sizeof(statbuf)); - stat(buffer, &statbuf); - - if (entry->d_type == DT_DIR) { - MtpObjectHandle handle = mDatabase->addFile(buffer, MTP_FORMAT_ASSOCIATION, - parent, mStorageID, 0, 0, statbuf.st_mtime); - scanDirectory(buffer, handle); - } else if (entry->d_type == DT_REG) { - mDatabase->addFile(buffer, MTP_FORMAT_UNDEFINED, parent, mStorageID, - statbuf.st_size, 0, statbuf.st_mtime); - } - } - - closedir(dir); - return 0; + MtpMediaScanner scanner(mStorageID, mFilePath, mDatabase); + return scanner.scanFiles(); } } // namespace android -- cgit v1.1