blob: d555279371a3f5eb7fae088d829b0e458b7b9393 [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>
Marco Nelissen544ad2b2013-11-13 14:18:21 -080024#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080025#include <pthread.h>
26
Jeff Brown7188e552011-07-20 16:38:43 -070027struct dirent;
28
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080029namespace android {
30
31class MediaScannerClient;
32class StringArray;
Marco Nelissen544ad2b2013-11-13 14:18:21 -080033class CharacterEncodingDetector;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034
Jeff Brown7188e552011-07-20 16:38:43 -070035enum MediaScanResult {
36 // This file or directory was scanned successfully.
37 MEDIA_SCAN_RESULT_OK,
38 // This file or directory was skipped because it was not found, could
39 // not be opened, was of an unsupported type, or was malfored in some way.
40 MEDIA_SCAN_RESULT_SKIPPED,
41 // The scan should be aborted due to a fatal error such as out of memory
42 // or an exception.
43 MEDIA_SCAN_RESULT_ERROR,
44};
45
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070046struct MediaAlbumArt {
47public:
48 static MediaAlbumArt *fromData(int32_t size, const void* data);
49
50 static void init(MediaAlbumArt* instance, int32_t size, const void* data);
51
52 MediaAlbumArt *clone();
53
54 const char *data() {
55 return &mData[0];
56 }
57
58 int32_t size() {
59 return mSize;
60 }
61
62private:
63 int32_t mSize;
Elliott Hughes4177a192014-06-12 18:17:11 -070064 char mData[];
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070065
66 // You can't construct instances of this class directly because this is a
67 // variable-sized object passed through the binder.
68 MediaAlbumArt();
69} __packed;
70
Andreas Huber413f5232009-12-03 11:31:19 -080071struct MediaScanner {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 MediaScanner();
Andreas Huber413f5232009-12-03 11:31:19 -080073 virtual ~MediaScanner();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074
Jeff Brown7188e552011-07-20 16:38:43 -070075 virtual MediaScanResult processFile(
76 const char *path, const char *mimeType, MediaScannerClient &client) = 0;
Andreas Huber413f5232009-12-03 11:31:19 -080077
Jeff Brown7188e552011-07-20 16:38:43 -070078 virtual MediaScanResult processDirectory(
79 const char *path, MediaScannerClient &client);
Andreas Huber413f5232009-12-03 11:31:19 -080080
81 void setLocale(const char *locale);
82
Elliott Hughesf3e80dd2014-06-10 16:55:38 -070083 virtual MediaAlbumArt *extractAlbumArt(int fd) = 0;
Andreas Huber413f5232009-12-03 11:31:19 -080084
85protected:
86 const char *locale() const;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080087
88private:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080089 // current locale (like "ja_JP"), created/destroyed with strdup()/free()
Andreas Huber413f5232009-12-03 11:31:19 -080090 char *mLocale;
Guang Zhufb6f0342011-09-07 23:55:27 -070091 char *mSkipList;
92 int *mSkipIndex;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080093
Jeff Brown7188e552011-07-20 16:38:43 -070094 MediaScanResult doProcessDirectory(
95 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia);
96 MediaScanResult doProcessDirectoryEntry(
97 char *path, int pathRemaining, MediaScannerClient &client, bool noMedia,
98 struct dirent* entry, char* fileSpot);
Guang Zhufb6f0342011-09-07 23:55:27 -070099 void loadSkipList();
100 bool shouldSkipDirectory(char *path);
101
Andreas Huber413f5232009-12-03 11:31:19 -0800102
103 MediaScanner(const MediaScanner &);
104 MediaScanner &operator=(const MediaScanner &);
105};
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106
107class MediaScannerClient
108{
109public:
Marco Nelissenf482a412009-09-03 10:49:55 -0700110 MediaScannerClient();
111 virtual ~MediaScannerClient();
112 void setLocale(const char* locale);
113 void beginFile();
Jeff Brown7188e552011-07-20 16:38:43 -0700114 status_t addStringTag(const char* name, const char* value);
Marco Nelissenf482a412009-09-03 10:49:55 -0700115 void endFile();
116
Jeff Brown7188e552011-07-20 16:38:43 -0700117 virtual status_t scanFile(const char* path, long long lastModified,
Mike Lockwoodc5182e32011-04-24 11:15:09 -0700118 long long fileSize, bool isDirectory, bool noMedia) = 0;
Jeff Brown7188e552011-07-20 16:38:43 -0700119 virtual status_t handleStringTag(const char* name, const char* value) = 0;
120 virtual status_t setMimeType(const char* mimeType) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800121
122protected:
Marco Nelissen544ad2b2013-11-13 14:18:21 -0800123 // default encoding from MediaScanner::mLocale
124 String8 mLocale;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125};
126
127}; // namespace android
128
129#endif // MEDIASCANNER_H