typedef int (*DELETE_INVALID_FOLDER_BY_PATH)(sqlite3 *, const char *, const char *, uid_t);
typedef int (*CHECK_FOLDER_EXIST)(sqlite3*, const char*, const char*);
-typedef int (*GET_AND_EXTRACT_MEDIA)(sqlite3*, const char*, int, const char *);
+typedef int (*GET_EXTRACT_LIST)(sqlite3*, const char*, int, const char*, int, void*);
+typedef int (*UPDATE_ONE_EXTRACT_ITEM)(sqlite3*, const char*, int, void *);
typedef int (*GET_MEDIA_TYPE)(const char *, int *);
typedef int (*REFRESH_ITEM)(sqlite3 *, const char *, const char *, uid_t);
eDELETE_INVALID_FOLDER_BY_PATH,
eCHECK_FOLDER_EXIST,
eGET_MEDIA_TYPE,
- eGET_AND_EXTRACT_MEDIA,
+ eGET_EXTRACT_LIST,
+ eUPDATE_ONE_EXTRACT_ITEM,
eREFRESH_ITEM,
eFUNC_MAX
};
"delete_invalid_folder_by_path",
"check_folder_exist",
"get_media_type",
- "get_and_extract_media",
+ "get_extract_list",
+ "update_one_extract_item",
"refresh_item",
};
return ret;
}
-int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, ms_msg_type_e msg_type, const char *path)
+int ms_get_extract_list(sqlite3 *handle, const char* storage_id, int scan_type, const char* path, int is_end, void *array)
{
int ret = MS_MEDIA_ERR_NONE;
- ret = ((GET_AND_EXTRACT_MEDIA)func_array[eGET_AND_EXTRACT_MEDIA])(handle, storage_id, msg_type, path);
- if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
- MS_DBG_ERR("GET_AND_EXTRACT_MEDIA failed [%d]", ret);
+ ret = ((GET_EXTRACT_LIST)func_array[eGET_EXTRACT_LIST])(handle, storage_id, scan_type, path, is_end, array);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_EXTRACT_LIST failed [%d]", ret);
+
+ return ret;
+}
+
+int ms_update_one_extract_item(sqlite3 *handle, const char* storage_id, int storage_type, void *data)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = ((UPDATE_ONE_EXTRACT_ITEM)func_array[eUPDATE_ONE_EXTRACT_ITEM])(handle, storage_id, storage_type, data);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_ONE_EXTRACT_ITEM failed [%d]", ret);
return ret;
}
static int stg_extract_status;
static GMutex extract_item_mutex;
+static GMutex decode_mutex;
static s_extract_item *cancel_extract_item = NULL;
static s_extract_item *cur_extract_item = NULL;
static GCond extract_data_cond;
static GMutex extract_data_mutex;
#define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
+#define LAST_EVENT 1
+#define NORMAL_EVENT 0
static int __msc_check_extract_stop_status(ms_msg_type_e msg_type, const char *start_path, int pid);
static void __msc_set_storage_extract_status(ms_storage_scan_status_e status);
static void __msc_del_cur_extract_item(void);
static void __msc_del_extract_blocked_path(const char* blocked_path);
+
+typedef struct {
+ int media_type;
+ char *path;
+} ms_item_info_s;
+
void msc_init_extract_thread(void)
{
if (!storage_extract_queue) storage_extract_queue = g_async_queue_new();
g_mutex_init(&extract_data_mutex);
g_mutex_init(&extract_item_mutex);
+ g_mutex_init(&decode_mutex);
g_cond_init(&extract_data_cond);
}
g_mutex_clear(&extract_data_mutex);
g_mutex_clear(&extract_item_mutex);
+ g_mutex_clear(&decode_mutex);
g_cond_clear(&extract_data_cond);
}
-static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, const char *path, ms_msg_type_e msg_type, int pid)
+static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, int storage_type, const char *path, int scan_type, int pid, bool is_end)
{
+ MS_DBG_WARN("begin of __msc_folder_bulk_extract");
int ret = MS_MEDIA_ERR_NONE;
+ GArray *data_array = NULL;
+ ms_item_info_s* db_data = NULL;
+ int sleep_count = 0;
- MS_DBG_FENTER();
+ ret = ms_get_extract_list(handle, storage_id, scan_type, path, is_end, (void *)&data_array);
+ MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_NONE, "ms_get_extract_list failed!!!");
+ MS_DBG_RETVM_IF(!data_array, MS_MEDIA_ERR_NONE, "data_array is NULL!!!");
- while (1) {
- ret = __msc_check_extract_stop_status(msg_type, path, pid);
+ while (data_array->len != 0) {
+ db_data = NULL;
+
+ ret = __msc_check_extract_stop_status(scan_type, path, pid);
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
break;
}
- ret = ms_get_and_extract_media(handle, storage_id, msg_type, path);
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- MS_DBG("Extract done");
- else
- MS_DBG_ERR("ms_get_and_extract_media failed!!!");
+ db_data = g_array_index(data_array, ms_item_info_s *, 0);
+ g_array_remove_index(data_array, 0);
- break;
+ g_mutex_lock(&decode_mutex);
+ ms_update_one_extract_item(handle, storage_id, storage_type, db_data);
+ g_mutex_unlock(&decode_mutex);
+
+ if (db_data) {
+ g_free(db_data->path);
+ g_free(db_data);
+ db_data = NULL;
+ }
+
+ if (++sleep_count == 5) {
+ sleep_count = 0;
+ usleep(SCAN_SLEEP_TIME);
}
- /* Sleep per 10 items. refer to META_UPDATE_MAX */
- usleep(SCAN_SLEEP_TIME);
}
- MS_DBG_FLEAVE();
+ while (data_array->len != 0) {
+ db_data = g_array_index(data_array, ms_item_info_s *, 0);
+ g_array_remove_index(data_array, 0);
- return MS_MEDIA_ERR_NONE;
+ if (db_data) {
+ g_free(db_data->path);
+ g_free(db_data);
+ db_data = NULL;
+ }
+ }
+ g_array_free(data_array, FALSE);
+ data_array = NULL;
+
+ MS_DBG_WARN("end of __msc_folder_bulk_extract");
+ return ret;
}
gpointer msc_folder_extract_thread(gpointer data)
ms_comm_msg_s *extract_data = NULL;
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
+ int end_flag = NORMAL_EVENT;
+ ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
while (1) {
extract_data = g_async_queue_pop(folder_extract_queue);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
goto NEXT;
}
+ end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
+
+ ret = ms_user_get_storage_type(extract_data->uid, extract_data->msg, &storage_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_user_get_storage_type failed");
+ goto NEXT;
+ }
ret = __msc_check_extract_stop_status(extract_data->msg_type, extract_data->msg, extract_data->pid);
if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
goto NEXT;
}
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag);
NEXT:
g_directory_extract_processing = false;
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *handle = NULL;
ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
+ int end_flag = NORMAL_EVENT;
while (1) {
__msc_set_storage_extract_status(MS_STORAGE_SCAN_DONE);
continue;
}
+ end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
MS_DBG("path[%.*s] storage_id[%.*s]", MAX_MSG_SIZE, extract_data->msg, MS_UUID_SIZE, extract_data->storage_id);
if (strlen(extract_data->storage_id) == 0) {
}
/*extract meta*/
- ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, extract_data->msg, extract_data->msg_type, extract_data->pid);
+ ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, extract_data->msg, extract_data->msg_type, extract_data->pid, end_flag);
MS_DBG_WARN("extract PAUSE");
__msc_pause_extract();
MS_DBG_WARN("extract RESUME");