return MEDIA_CONTROLLER_ERROR_NONE;
}
+static int __mc_db_get_metadata(sqlite3_stmt *stmt, int col, mc_metadata_h *metadata)
+{
+ media_controller_metadata_s *_metadata = NULL;
+
+ mc_retvm_if(metadata == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "metadata is NULL");
+
+ _metadata = (media_controller_metadata_s *)calloc(1, sizeof(media_controller_metadata_s));
+ mc_retvm_if(_metadata == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+
+ _metadata->title = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->artist = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->album = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->author = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->genre = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->duration = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->date = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->copyright = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->description = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->track_num = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+ _metadata->picture = g_strdup((const char *)sqlite3_column_text(stmt, col++));
+
+ *metadata = (mc_metadata_h)_metadata;
+
+ return MEDIA_CONTROLLER_ERROR_NONE;
+}
+
int mc_db_get_metadata_info(void *handle, const char *server_name, mc_metadata_h *metadata)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
char *sql_str = NULL;
sqlite3_stmt *stmt = NULL;
sqlite3 *db_handle = (sqlite3 *)handle;
- media_controller_metadata_s *_metadata = NULL;
mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
mc_retvm_if(server_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
SQLITE3_FINALIZE(stmt);
SQLITE3_SAFE_FREE(sql_str);
return MEDIA_CONTROLLER_ERROR_NONE;
- } else {
- _metadata = (media_controller_metadata_s *)calloc(1, sizeof(media_controller_metadata_s));
- if (_metadata == NULL) {
- mc_error("OUT_OF_MEMORY");
- SQLITE3_FINALIZE(stmt);
- SQLITE3_SAFE_FREE(sql_str);
- return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
- }
-
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TITLE)))
- _metadata->title = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TITLE));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ARTIST)))
- _metadata->artist = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ARTIST));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ALBUM)))
- _metadata->album = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ALBUM));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_AUTHOR)))
- _metadata->author = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_AUTHOR));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_GENRE)))
- _metadata->genre = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_GENRE));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DURATION)))
- _metadata->duration = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DURATION));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DATE)))
- _metadata->date = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DATE));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_COPYRIGHT)))
- _metadata->copyright = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_COPYRIGHT));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DESCRIPTION)))
- _metadata->description = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DESCRIPTION));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TRACK_NUM)))
- _metadata->track_num = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TRACK_NUM));
- if (MC_STRING_VALID((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_PICTURE)))
- _metadata->picture = strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_PICTURE));
}
- *metadata = (mc_metadata_h)_metadata;
+ ret = __mc_db_get_metadata(stmt, MC_SERVER_FIELD_TITLE, metadata);
SQLITE3_FINALIZE(stmt);
SQLITE3_SAFE_FREE(sql_str);
- return MEDIA_CONTROLLER_ERROR_NONE;
+ return ret;
}
int mc_db_get_server_state(void *handle, const char *server_name, mc_server_state_e *state)
sqlite3 *db_handle = (sqlite3 *)handle;
char *sql_str = NULL;
sqlite3_stmt *stmt = NULL;
+ char *index = NULL;
+ mc_metadata_h _metadata = NULL;
sql_str = sqlite3_mprintf("SELECT * from %s WHERE server_name = %Q and playlist_name = %Q and item_index IS NOT NULL ORDER BY rowid", MC_DB_TABLE_PLAYLIST, server_name, playlist_name);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
ret = sqlite3_prepare_v2(db_handle, sql_str, strlen(sql_str), &stmt, NULL);
- if (SQLITE_OK != ret) {
- mc_error("prepare error [%s]", sqlite3_errmsg(db_handle));
- SQLITE3_SAFE_FREE(sql_str);
- return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION;
- }
+ SQLITE3_SAFE_FREE(sql_str);
+ mc_retvm_if(SQLITE_OK != ret, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "prepare error [%s]", sqlite3_errmsg(db_handle));
ret = sqlite3_step(stmt);
if (SQLITE_ROW != ret) {
mc_error("[No-Error] There is no playlist itemt [%s]", sqlite3_errmsg(db_handle));
SQLITE3_FINALIZE(stmt);
- SQLITE3_SAFE_FREE(sql_str);
return MEDIA_CONTROLLER_ERROR_NONE;
}
while (SQLITE_ROW == ret) {
- char *index = NULL;
- media_controller_metadata_s *_metadata = NULL;
-
- _metadata = (media_controller_metadata_s *)calloc(1, sizeof(media_controller_metadata_s));
- if (_metadata == NULL) {
- mc_error("OUT_OF_MEMORY");
+ ret = __mc_db_get_metadata(stmt, 3, &_metadata); //0 : server_name, 1 : playlist_name, 2 : item_index, from 3 : metadata such as title, artist
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
+ mc_error("fail to __mc_db_get_metadata");
SQLITE3_FINALIZE(stmt);
- SQLITE3_SAFE_FREE(sql_str);
- return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY;
+ return ret;
}
- index = g_strdup((char *)sqlite3_column_text(stmt, 2)); //0 : server_name, 1 : playlist_name
- _metadata->title = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TITLE -5));
- _metadata->artist = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ARTIST -5));
- _metadata->album = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_ALBUM -5));
- _metadata->author = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_AUTHOR -5));
- _metadata->genre = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_GENRE -5));
- _metadata->duration = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DURATION -5));
- _metadata->date = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DATE -5));
- _metadata->copyright = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_COPYRIGHT -5));
- _metadata->description = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_DESCRIPTION -5));
- _metadata->track_num = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_TRACK_NUM -5));
- _metadata->picture = g_strdup((const char *)sqlite3_column_text(stmt, MC_SERVER_FIELD_PICTURE -5));
+ index = g_strdup((char *)sqlite3_column_text(stmt, 2));
if (callback(index, (mc_metadata_h)_metadata, user_data) == false) {
MC_SAFE_FREE(index);
}
MC_SAFE_FREE(index);
- mc_metadata_destroy((mc_metadata_h)_metadata);
+ mc_metadata_destroy(_metadata);
ret = sqlite3_step(stmt);
}
SQLITE3_FINALIZE(stmt);
- SQLITE3_SAFE_FREE(sql_str);
return MEDIA_CONTROLLER_ERROR_NONE;
}
| LOCAL FUNCTION PROTOTYPES: |
---------------------------------------------------------------------------*/
+static void __get_and_check_metadata(mc_metadata_h metadata)
+{
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ int idx = 0;
+ char *value = NULL;
+
+ for (idx = 0; idx <= MC_META_MEDIA_PICTURE; idx++) {
+ ret = mc_metadata_get(metadata, idx, &value);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE)
+ mc_error("Fail to mc_metadata_get");
+
+ mc_debug("metadata [%d] value [%s]\n", idx, value);
+ MC_SAFE_FREE(value);
+ }
+}
+
void _mc_server_state_updated_cb(const char *server_name, mc_server_state_e state, void *user_data)
{
media_controller_client_s *_client = (media_controller_client_s *)g_mc_client;
void _mc_metadata_updated_cb(const char *server_name, mc_metadata_h metadata, void *user_data)
{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- int idx = 0;
- char *str_val = NULL;
media_controller_client_s *_client = (media_controller_client_s *)g_mc_client;
mc_debug("[Client:%s] Metadata updated from server[%s] ", _client->client_name, server_name);
- for (idx = 0; idx <= MC_META_MEDIA_PICTURE; idx++) {
- ret = mc_metadata_get(metadata, idx, &str_val);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE)
- mc_error("Fail to mc_metadata_get");
- mc_debug("metadata [%d] val [%s]\n", idx, str_val);
-
- if (str_val)
- g_free(str_val);
- }
+ __get_and_check_metadata(metadata);
}
void _mc_shuffle_mode_updated_cb(const char *server_name, mc_shuffle_mode_e mode, void *user_data)
mc_debug("[Client:%s] Repeat mode(%d) updated from server[%s]", _client->client_name, mode, server_name);
}
+bool _mc_playlist_item_cb(const char *index, mc_metadata_h metadata, void *user_data)
+{
+ mc_debug("playlist index [%s]", index);
+ __get_and_check_metadata(metadata);
+
+ return true;
+}
+
void _mc_playlist_updated_cb(const char *server_name, mc_playlist_update_mode_e mode, const char *playlist_name, mc_playlist_h playlist, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
mc_debug("playlist_name [%s]", _name);
MC_SAFE_FREE(_name);
+
+ ret = mc_playlist_foreach_item(playlist, _mc_playlist_item_cb, NULL);
+ if (ret != MEDIA_CONTROLLER_ERROR_NONE)
+ mc_error("Fail to mc_playlist_foreach_item [%d]", ret);
}
}
return TRUE;
}
-bool server_playlist_item_cb(const char *index, mc_metadata_h meta, void *user_data)
-{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
- int idx = 0;
- char *value = NULL;
-
- for (idx = 0; idx <= MC_META_MEDIA_PICTURE; idx++) {
- ret = mc_metadata_get(meta, idx, &value);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE)
- mc_error("Fail to mc_metadata_get [%d]", ret);
-
- mc_debug("index [%s] value [%s]", index, value);
- MC_SAFE_FREE(value);
- }
-
- return true;
-}
-
-bool server_playlist_list_cb(mc_playlist_h playlist, void *user_data)
+bool server_playlist_cb(mc_playlist_h playlist, void *user_data)
{
int ret = MEDIA_CONTROLLER_ERROR_NONE;
mc_debug("playlist_name [%s]", g_playlist_name);
- ret = mc_playlist_foreach_item(playlist, server_playlist_item_cb, NULL);
+ ret = mc_playlist_foreach_item(playlist, _mc_playlist_item_cb, NULL);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
mc_error("Fail to mc_playlist_foreach_item [%d]", ret);
g_print("repeate mode: %d", repeate_mode);
break;
case 6:
- ret = mc_client_foreach_server_playlist(g_mc_client, g_server_name, server_playlist_list_cb, NULL);
+ ret = mc_client_foreach_server_playlist(g_mc_client, g_server_name, server_playlist_cb, NULL);
mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, FALSE, "Fail to mc_client_get_server_playlist [%d]", ret);
break;
mc_repeat_mode_e repeat_mode = MC_REPEAT_MODE_OFF;
mc_metadata_h metadata = NULL;
mc_playback_h playback = NULL;
- char *str_val = NULL;
- int idx = 0;
mc_playback_states_e playback_state = MC_PLAYBACK_STATE_REWINDING;
unsigned long long playback_position = 0;
if (ret != MEDIA_CONTROLLER_ERROR_NONE)
g_print("Fail to mc_client_get_server_metadata\n");
- for (idx = 0; idx <= MC_META_MEDIA_PICTURE; idx++) {
- ret = mc_metadata_get(metadata, idx, &str_val);
- if (ret != MEDIA_CONTROLLER_ERROR_NONE)
- g_print("Fail to mc_metadata_get\n");
- g_print("metadata [%d] val [%s]\n", idx, str_val);
- if (str_val)
- g_free(str_val);
- }
+ __get_and_check_metadata(metadata);
ret = mc_metadata_destroy(metadata);
if (ret != MEDIA_CONTROLLER_ERROR_NONE)