blob: 37a83c68000d4e9de2144764cd0b40846a3ebc43 [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
Jeff Brown7188e552011-07-20 16:38:43 -070026struct dirent;
27
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028namespace android {
29
30class MediaScannerClient;
31class StringArray;
32
Jeff Brown7188e552011-07-20 16:38:43 -070033enum 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
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070044struct MediaAlbumArt {
45public:
46 static MediaAlbumArt *fromData(int32_t size, const void* data);
47
48 static void init(MediaAlbumArt* instance, int32_t size, const void* data);
49
50 MediaAlbumArt *clone();
51
52 const char *data() {
53 return &mData[0];
54 }
55
56 int32_t size() {
57 return mSize;
58 }
59
60private:
61 int32_t mSize;
Elliott Hughes4177a192014-06-12 18:17:11 -070062 char mData[];
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070063
64 // You can't construct instances of this class directly because this is a
65 // variable-sized object passed through the binder.
66 MediaAlbumArt();
67} __packed;
68
Andreas Huber413f5232009-12-03 11:31:19 -080069struct MediaScanner {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070 MediaScanner();
Andreas Huber413f5232009-12-03 11:31:19 -080071 virtual ~MediaScanner();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072
Jeff Brown7188e552011-07-20 16:38:43 -070073 virtual MediaScanResult processFile(
74 const char *path, const char *mimeType, MediaScannerClient &client) = 0;
Andreas Huber413f5232009-12-03 11:31:19 -080075
Jeff Brown7188e552011-07-20 16:38:43 -070076 virtual MediaScanResult processDirectory(
77 const char *path, MediaScannerClient &client);
Andreas Huber413f5232009-12-03 11:31:19 -080078
79 void setLocale(const char *locale);
80
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070081 virtual MediaAlbumArt *extractAlbumArt(int fd) = 0;
Andreas Huber413f5232009-12-03 11:31:19 -080082
83protected:
84 const char *locale() const;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085
86private:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080087 // current locale (like "ja_JP"), created/destroyed with strdup()/free()
Andreas Huber413f5232009-12-03 11:31:19 -080088 char *mLocale;
Guang Zhufb6f0342011-09-07 23:55:27 -070089 char *mSkipList;
90 int *mSkipIndex;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080091
Jeff Brown7188e552011-07-20 16:38:43 -070092 MediaScanResult doProcessDirectory(
93 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia);
94 MediaScanResult doProcessDirectoryEntry(
95 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia,
96 struct dirent* entry, char* fileSpot);
Guang Zhufb6f0342011-09-07 23:55:27 -070097 void loadSkipList();
98 bool shouldSkipDirectory(char *path);
99
Andreas Huber413f5232009-12-03 11:31:19 -0800100
101 MediaScanner(const MediaScanner &);
102 MediaScanner &operator=(const MediaScanner &);
103};
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104
105class MediaScannerClient
106{
107public:
Marco Nelissenf482a412009-09-03 10:49:55 -0700108 MediaScannerClient();
109 virtual ~MediaScannerClient();
110 void setLocale(const char* locale);
111 void beginFile();
Jeff Brown7188e552011-07-20 16:38:43 -0700112 status_t addStringTag(const char* name, const char* value);
Marco Nelissenf482a412009-09-03 10:49:55 -0700113 void endFile();
114
Jeff Brown7188e552011-07-20 16:38:43 -0700115 virtual status_t scanFile(const char* path, long long lastModified,
Mike Lockwoodc5182e32011-04-24 11:15:09 -0700116 long long fileSize, bool isDirectory, bool noMedia) = 0;
Jeff Brown7188e552011-07-20 16:38:43 -0700117 virtual status_t handleStringTag(const char* name, const char* value) = 0;
118 virtual status_t setMimeType(const char* mimeType) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800119
120protected:
121 void convertValues(uint32_t encoding);
122
123protected:
124 // cached name and value strings, for native encoding support.
125 StringArray* mNames;
126 StringArray* mValues;
Andreas Huber413f5232009-12-03 11:31:19 -0800127
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 // default encoding based on MediaScanner::mLocale string
129 uint32_t mLocaleEncoding;
130};
131
132}; // namespace android
133
134#endif // MEDIASCANNER_H