The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 3b4062e | 2009-05-31 19:13:00 -0700 | [diff] [blame] | 20 | #include <utils/Log.h> |
| 21 | #include <utils/threads.h> |
| 22 | #include <utils/List.h> |
| 23 | #include <utils/Errors.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <pthread.h> |
| 25 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 26 | struct dirent; |
| 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | class MediaScannerClient; |
| 31 | class StringArray; |
| 32 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 33 | enum MediaScanResult { |
| 34 | // This file or directory was scanned successfully. |
| 35 | MEDIA_SCAN_RESULT_OK, |
| 36 | // This file or directory was skipped because it was not found, could |
| 37 | // not be opened, was of an unsupported type, or was malfored in some way. |
| 38 | MEDIA_SCAN_RESULT_SKIPPED, |
| 39 | // The scan should be aborted due to a fatal error such as out of memory |
| 40 | // or an exception. |
| 41 | MEDIA_SCAN_RESULT_ERROR, |
| 42 | }; |
| 43 | |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 44 | struct MediaScanner { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | MediaScanner(); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 46 | virtual ~MediaScanner(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 48 | virtual MediaScanResult processFile( |
| 49 | const char *path, const char *mimeType, MediaScannerClient &client) = 0; |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 50 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 51 | virtual MediaScanResult processDirectory( |
| 52 | const char *path, MediaScannerClient &client); |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 53 | |
| 54 | void setLocale(const char *locale); |
| 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | // extracts album art as a block of data |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 57 | virtual char *extractAlbumArt(int fd) = 0; |
| 58 | |
| 59 | protected: |
| 60 | const char *locale() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | private: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | // current locale (like "ja_JP"), created/destroyed with strdup()/free() |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 64 | char *mLocale; |
Guang Zhu | 973f553 | 2011-09-07 23:55:27 -0700 | [diff] [blame] | 65 | char *mSkipList; |
| 66 | int *mSkipIndex; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 68 | MediaScanResult doProcessDirectory( |
| 69 | char *path, int pathRemaining, MediaScannerClient &client, bool noMedia); |
| 70 | MediaScanResult doProcessDirectoryEntry( |
| 71 | char *path, int pathRemaining, MediaScannerClient &client, bool noMedia, |
| 72 | struct dirent* entry, char* fileSpot); |
Guang Zhu | 973f553 | 2011-09-07 23:55:27 -0700 | [diff] [blame] | 73 | void loadSkipList(); |
| 74 | bool shouldSkipDirectory(char *path); |
| 75 | |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 76 | |
| 77 | MediaScanner(const MediaScanner &); |
| 78 | MediaScanner &operator=(const MediaScanner &); |
| 79 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
| 81 | class MediaScannerClient |
| 82 | { |
| 83 | public: |
Marco Nelissen | 8b04661 | 2009-09-03 10:49:55 -0700 | [diff] [blame] | 84 | MediaScannerClient(); |
| 85 | virtual ~MediaScannerClient(); |
| 86 | void setLocale(const char* locale); |
| 87 | void beginFile(); |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 88 | status_t addStringTag(const char* name, const char* value); |
Marco Nelissen | 8b04661 | 2009-09-03 10:49:55 -0700 | [diff] [blame] | 89 | void endFile(); |
| 90 | |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 91 | virtual status_t scanFile(const char* path, long long lastModified, |
Mike Lockwood | 997354e | 2011-04-24 11:15:09 -0700 | [diff] [blame] | 92 | long long fileSize, bool isDirectory, bool noMedia) = 0; |
Jeff Brown | 2c70d4a | 2011-07-20 16:38:43 -0700 | [diff] [blame] | 93 | virtual status_t handleStringTag(const char* name, const char* value) = 0; |
| 94 | virtual status_t setMimeType(const char* mimeType) = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | |
| 96 | protected: |
| 97 | void convertValues(uint32_t encoding); |
| 98 | |
| 99 | protected: |
| 100 | // cached name and value strings, for native encoding support. |
| 101 | StringArray* mNames; |
| 102 | StringArray* mValues; |
Andreas Huber | bfb9fb1 | 2009-12-03 11:31:19 -0800 | [diff] [blame] | 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | // default encoding based on MediaScanner::mLocale string |
| 105 | uint32_t mLocaleEncoding; |
| 106 | }; |
| 107 | |
| 108 | }; // namespace android |
| 109 | |
| 110 | #endif // MEDIASCANNER_H |