int media_svc_set_folder_validity(MediaSvcHandle *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid);
int media_svc_insert_item_pass1(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid);
-int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int scan_type, const char* extract_path, int is_burst, uid_t uid);
int media_svc_insert_folder_begin(int data_cnt);
int media_svc_insert_folder_end(uid_t uid);
int get_extract_list(void* handle, const char* storage_id, int storage_type, int scan_type, const char* path, int burst, uid_t uid, void* array, char** err_msg)
{
-#if 0
- int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
-
- if (handle == NULL) {
- __set_error_message(ERR_HANDLE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- if (!STORAGE_VALID(storage_type)) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- ret = media_svc_pass2_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, array);
- if (ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-#endif
+ /* For scanner V2 */
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
{
-#if 0
- int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
-
- if (handle == NULL) {
- __set_error_message(ERR_HANDLE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- if (!STORAGE_VALID(storage_type)) {
- __set_error_message(ERR_STORAGE_TYPE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- ret = media_svc_insert_one_item_pass2(handle, storage_id, storage_type, data, burst);
- if (ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-#endif
+ /* For scanner V2 */
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
int query_do_update_list(void* handle, char** err_msg)
{
-#if 0
- int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
-
- if (handle == NULL) {
- __set_error_message(ERR_HANDLE, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-
- ret = media_svc_query_do_update_list(handle);
- if (ret < 0) {
- __set_error_message(ret, err_msg);
- return MEDIA_SVC_PLUGIN_ERROR;
- }
-#endif
+ /* For scanner V2 */
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
SQLITE3_SAFE_FREE(sql);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /**album_id = sqlite3_last_insert_rowid(handle); */
int inserted_album_id = 0;
ret = _media_svc_get_album_id(handle, album, artist, &inserted_album_id);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
*/
#include <unistd.h>
-#include <sys/stat.h>
-#include <db-util.h>
#include <media-util.h>
#include <errno.h>
#include "media-svc-env.h"
media_svc_debug("END");
return MS_MEDIA_ERR_NONE;
}
-
-int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
-
- media_svc_debug_fenter();
-
- /*Update Pinyin If Support Pinyin*/
- if (_media_svc_check_pinyin_support()) {
- if (STRING_VALID(content_info->file_name))
- _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
- if (STRING_VALID(content_info->media_meta.title))
- _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
- if (STRING_VALID(content_info->media_meta.album))
- _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
- if (STRING_VALID(content_info->media_meta.artist))
- _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
- if (STRING_VALID(content_info->media_meta.album_artist))
- _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
- if (STRING_VALID(content_info->media_meta.genre))
- _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
- if (STRING_VALID(content_info->media_meta.composer))
- _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
- if (STRING_VALID(content_info->media_meta.copyright))
- _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
- if (STRING_VALID(content_info->media_meta.description))
- _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
- }
-
- char *sql = sqlite3_mprintf("UPDATE '%s' SET \
- thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, year=%Q, \
- recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, \
- duration=%d, longitude=%.6f, latitude=%.6f, altitude=%.6f, width=%d, height=%d, datetaken=%Q, orientation=%d, exposure_time=%Q,\
- fnumber=%.6f, iso=%d, model=%Q, rating=%d, weather=%Q, file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, \
- artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q, is_360=%d WHERE path=%Q;",
- storage_id,
- /* content_info->folder_uuid, */
- content_info->thumbnail_path,
- content_info->media_meta.title,
- content_info->album_id,
- content_info->media_meta.album,
- content_info->media_meta.artist,
- content_info->media_meta.album_artist,
- content_info->media_meta.genre,
- content_info->media_meta.composer,
- content_info->media_meta.year,
- content_info->media_meta.recorded_date,
- content_info->media_meta.copyright,
- content_info->media_meta.track_num,
- content_info->media_meta.description,
- content_info->media_meta.bitrate,
- content_info->media_meta.bitpersample,
- content_info->media_meta.samplerate,
- content_info->media_meta.channel,
- content_info->media_meta.duration,
- content_info->media_meta.longitude,
- content_info->media_meta.latitude,
- content_info->media_meta.altitude,
- content_info->media_meta.width,
- content_info->media_meta.height,
- content_info->media_meta.datetaken,
- content_info->media_meta.orientation,
- content_info->media_meta.exposure_time,
- content_info->media_meta.fnumber,
- content_info->media_meta.iso,
- content_info->media_meta.model,
- content_info->media_meta.rating,
- content_info->media_meta.weather,
- content_info->file_name_pinyin,
- content_info->media_meta.title_pinyin,
- content_info->media_meta.album_pinyin,
- content_info->media_meta.artist_pinyin,
- content_info->media_meta.album_artist_pinyin,
- content_info->media_meta.genre_pinyin,
- content_info->media_meta.composer_pinyin,
- content_info->media_meta.copyright_pinyin,
- content_info->media_meta.description_pinyin,
- content_info->media_meta.is_360,
- content_info->path
- );
-
- if (!stack_query) {
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
-
- media_svc_error("failed to insert item");
- return ret;
- }
- } else {
- /*media_svc_debug("query : %s", sql);*/
- _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
- }
-
- media_svc_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
return MS_MEDIA_ERR_NONE;
}
-static int __media_svc_check_thumb_dir(const char *thumb_dir)
-{
- DIR *dir = NULL;
-
- dir = opendir(thumb_dir);
- if (dir != NULL)
- closedir(dir);
- else
- return MS_MEDIA_ERR_INTERNAL;
-
- return MS_MEDIA_ERR_NONE;
-}
-
int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
return MS_MEDIA_ERR_INTERNAL;
}
- ret = __media_svc_check_thumb_dir(thumb_dir);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("__media_svc_check_thumb_dir");
+ if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
+ media_svc_error("Wrong path[%s]", thumb_dir);
SAFE_FREE(thumb_dir);
return MS_MEDIA_ERR_INTERNAL;
}
{
int ret = MS_MEDIA_ERR_NONE;
char * media_uuid = NULL;
- char * file_name = NULL;
bool drm_type = false;
char mime_type[256] = {0, };
content_info->media_uuid = g_strdup(media_uuid);
media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
- file_name = g_path_get_basename(path);
- content_info->file_name = g_strdup(file_name);
- SAFE_FREE(file_name);
+ content_info->file_name = g_path_get_basename(path);
media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
/* if the file is DRM file, drm_type value is DRM_TRUE(1).
return;
}
-char *_media_svc_replace_path(char *s, const char *olds, const char *news)
-{
- char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- memset(result, 0x00, sizeof(result));
-
- if (STRING_VALID(s) && STRING_VALID(olds) && STRING_VALID(news)) {
- if (strncmp(s, olds, strlen(olds)) == 0)
- snprintf(result, sizeof(result), "%s%s", news, s + strlen(olds));
- }
-
- if (STRING_VALID(result))
- return g_strdup(result);
- else
- return NULL;
-}
-
int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
static __thread int g_insert_with_noti = FALSE;
#define BATCH_REQUEST_MAX 300
-typedef struct {
- int media_type;
- char *path;
-} media_svc_item_info_s;
static bool __media_svc_check_storage(media_svc_storage_type_e storage_type)
{
media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- int ret = MS_MEDIA_ERR_NONE;
-
- ret = media_db_disconnect(db_handle);
- return ret;
+ return media_db_disconnect(db_handle);
}
int media_svc_cleanup_db(MediaSvcHandle *handle, uid_t uid)
return MS_MEDIA_ERR_NONE;
}
-int media_svc_insert_item_pass2(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e storage_type, int scan_type, const char *extract_path, int is_burst, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3 * db_handle = (sqlite3 *)handle;
- sqlite3_stmt *sql_stmt = NULL;
- media_svc_media_type_e media_type;
- media_svc_content_info_s content_info;
- GArray *db_data_array = NULL;
- media_svc_item_info_s *db_data = NULL;
- int idx = 0;
-
- media_svc_debug_fenter();
-
- media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
-
- if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB)) {
- media_svc_error("storage type is incorrect[%d]", storage_type);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- db_data_array = g_array_new(FALSE, FALSE, sizeof(media_svc_item_info_s*));
- if (db_data_array == NULL) {
- media_svc_error("db_data_array is NULL. Out of memory");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- char *sql;
- char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
- if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
- ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, extract_path, folder_uuid, uid);
-
- if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && ret == MS_MEDIA_ERR_NONE) {
- media_svc_error("folder no recursive extract");
- if (is_burst == 1)
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL and folder_uuid = '%q' ", storage_id, folder_uuid);
- else
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 AND title IS NULL and folder_uuid = '%q' LIMIT %d", storage_id, folder_uuid, BATCH_REQUEST_MAX);
- } else if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
- media_svc_error("folder recursive extract");
- if (is_burst == 1)
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL and path LIKE '%q%%' ", storage_id, extract_path);
- else
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL and path LIKE '%q%%' LIMIT %d", storage_id, extract_path, BATCH_REQUEST_MAX);
- } else {
- if (is_burst == 1)
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL", storage_id);
- else
- sql = sqlite3_mprintf("SELECT path, media_type FROM '%s' WHERE validity = 1 and title IS NULL LIMIT %d", storage_id, BATCH_REQUEST_MAX);
- }
-
- ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when get list. err = [%d]", ret);
- g_array_free(db_data_array, FALSE);
- return ret;
- }
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- db_data = NULL;
- db_data = malloc(sizeof(media_svc_item_info_s));
- if (db_data == NULL) {
- media_svc_error("Out of memory");
- continue;
- }
-
- db_data->path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- db_data->media_type = (int)sqlite3_column_int(sql_stmt, 1);
-
- g_array_append_val(db_data_array, db_data);
- }
-
- SQLITE3_FINALIZE(sql_stmt);
- media_svc_error("Insert Pass 2 get %d items!", db_data_array->len);
-
- while (db_data_array->len != 0) {
- db_data = NULL;
- db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
- g_array_remove_index(db_data_array, 0);
-
- if ((db_data == NULL) || (db_data->path == NULL)) {
- media_svc_error("invalid db data");
- continue;
- }
-
- media_type = db_data->media_type;
- /* media_svc_debug("path is %s, media type %d", db_data->path, media_type); */
- memset(&content_info, 0, sizeof(media_svc_content_info_s));
- content_info.path = g_strdup(db_data->path);
-
- content_info.media_type = media_type;
- content_info.storage_type = storage_type;
-
- _media_svc_set_default_value(&content_info, FALSE);
-
- if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
- || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
- || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
- || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
- media_svc_debug("Do nothing[%d]", media_type);
- else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
- ret = _media_svc_extract_image_metadata(db_handle, &content_info);
- else
- ret = _media_svc_extract_media_metadata(db_handle, &content_info, uid);
-
- ret = _media_svc_insert_item_pass2(storage_id, &content_info, is_burst, TRUE, uid);
-
- _media_svc_destroy_content_info(&content_info);
- SAFE_FREE(db_data->path);
- SAFE_FREE(db_data);
- idx++;
- }
-
- if (idx > 0) {
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
- if (0) {
- _media_svc_publish_noti_list(idx);
- _media_svc_destroy_noti_list(idx);
-
- /* Recreate noti list */
- ret = _media_svc_create_noti_list(idx);
- }
- }
-
- while (db_data_array->len != 0) {
- db_data = NULL;
- db_data = g_array_index(db_data_array, media_svc_item_info_s*, 0);
- g_array_remove_index(db_data_array, 0);
-
- if (db_data) {
- SAFE_FREE(db_data->path);
- SAFE_FREE(db_data);
- }
- }
-
- g_array_free(db_data_array, FALSE);
- db_data_array = NULL;
-
- media_svc_debug_fleave();
-
- return MS_MEDIA_ERR_NONE;
-}
-
int media_svc_get_folder_scan_status(MediaSvcHandle *handle, const char *storage_id, const char *path, int *storage_status)
{
int ret = MS_MEDIA_ERR_NONE;
int _media_svc_change_validity_item_batch(const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid);
int _media_svc_insert_item_pass1(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid);
-int _media_svc_insert_item_pass2(const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid);
int _media_svc_append_query_list(const char *query, uid_t uid);
int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid);
time_t __media_svc_get_timeline_from_str(const char *timstr);
void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
-char *_media_svc_replace_path(char *s, const char *olds, const char *news);
int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid);
int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);
bool _media_svc_check_pinyin_support(void);