mediascanner.h revision 2ffcb6c4fe5be89b38b72803182cbc5f3fbad43a
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef MEDIASCANNER_H 18#define MEDIASCANNER_H 19 20#include <utils/Log.h> 21#include <utils/threads.h> 22#include <utils/List.h> 23#include <utils/Errors.h> 24#include <pthread.h> 25 26namespace android { 27 28class MediaScannerClient; 29class StringArray; 30 31class MediaScanner 32{ 33public: 34 MediaScanner(); 35 ~MediaScanner(); 36 37 typedef bool (*ExceptionCheck)(void* env); 38 39 status_t processFile(const char *path, const char *mimeType, MediaScannerClient& client); 40 status_t processDirectory(const char *path, const char* extensions, 41 MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv); 42 void setLocale(const char* locale); 43 44 // extracts album art as a block of data 45 char* extractAlbumArt(int fd); 46 47 static void uninitializeForThread(); 48 49private: 50 status_t doProcessDirectory(char *path, int pathRemaining, const char* extensions, 51 MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv); 52 void initializeForThread(); 53 54 // current locale (like "ja_JP"), created/destroyed with strdup()/free() 55 char* mLocale; 56}; 57 58 59class MediaScannerClient 60{ 61public: 62 MediaScannerClient(); 63 virtual ~MediaScannerClient(); 64 void setLocale(const char* locale); 65 void beginFile(); 66 bool addStringTag(const char* name, const char* value); 67 void endFile(); 68 69 virtual bool scanFile(const char* path, long long lastModified, long long fileSize) = 0; 70 virtual bool handleStringTag(const char* name, const char* value) = 0; 71 virtual bool setMimeType(const char* mimeType) = 0; 72 virtual bool addNoMediaFolder(const char* path) = 0; 73 74protected: 75 void convertValues(uint32_t encoding); 76 77protected: 78 // cached name and value strings, for native encoding support. 79 StringArray* mNames; 80 StringArray* mValues; 81 82 // default encoding based on MediaScanner::mLocale string 83 uint32_t mLocaleEncoding; 84}; 85 86}; // namespace android 87 88#endif // MEDIASCANNER_H 89 90