blob: 77495666f53821a58ba8483623ce3be914f2c433 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
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 Agopian273d0982009-05-31 19:13:00 -070020#include <utils/Log.h>
21#include <utils/threads.h>
22#include <utils/List.h>
23#include <utils/Errors.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080024#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
73protected:
74 void convertValues(uint32_t encoding);
75
76protected:
77 // cached name and value strings, for native encoding support.
78 StringArray* mNames;
79 StringArray* mValues;
80
81 // default encoding based on MediaScanner::mLocale string
82 uint32_t mLocaleEncoding;
83};
84
85}; // namespace android
86
87#endif // MEDIASCANNER_H
88