From: hj kim Date: Thu, 5 Apr 2018 06:26:35 +0000 (+0900) Subject: [ACR-1200] Add APIs to set and get index of playlist X-Git-Tag: accepted/tizen/unified/20180423.062727~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c18e081789492ba88170355143faebec4b4843af;p=platform%2Fcore%2Fapi%2Fmedia-controller.git [ACR-1200] Add APIs to set and get index of playlist Change-Id: I03562cc9d738b01c56715be74ce3414e8f09727c --- diff --git a/doc/media_controller_doc.h b/doc/media_controller_doc.h index c66a94f..af32a7f 100755 --- a/doc/media_controller_doc.h +++ b/doc/media_controller_doc.h @@ -51,7 +51,7 @@ * \#include * * @section CAPI_MEDIA_CONTROLLER_SERVER_MODULE_OVERVIEW Overview -* The @ref CAPI_MEDIA_CONTROLLER_SERVER_MODULE API allows you to send the playback info(#mc_server_set_playback_state(), #mc_server_set_playback_position), or the metadata(#mc_server_set_metadata()). and to receive the custom command(#mc_server_set_custom_command_received_cb()), to update the status information on the latest server(#mc_server_update_playback_info, #mc_server_update_metadata), or to create/destroy the handle(#mc_server_create()/#mc_server_destroy()). \n +* The @ref CAPI_MEDIA_CONTROLLER_SERVER_MODULE API allows you to send the playback info (#mc_server_set_playback_state(), #mc_server_set_playback_position(), #mc_server_set_playlist_item_index()), or the metadata (#mc_server_set_metadata()). and to receive the custom command (#mc_server_set_custom_command_received_cb()), to update the status information on the latest server (#mc_server_update_playback_info(), #mc_server_update_metadata()), or to create/destroy the handle (#mc_server_create()/#mc_server_destroy()). \n * */ @@ -63,7 +63,7 @@ * \#include * * @section CAPI_MEDIA_CONTROLLER_CLIENT_MODULE_OVERVIEW Overview -* The @ref CAPI_MEDIA_CONTROLLER_CLIENT_MODULE API allows you to check the activated server status(#mc_client_set_server_update_cb()), the playback info(#mc_client_set_playback_update_cb()), or the metadata(#mc_client_set_metadata_update_cb()). to send the custom command(#mc_client_send_custom_command()), to create/destroy the handle(#mc_client_create()/#mc_client_destroy()). \n +* The @ref CAPI_MEDIA_CONTROLLER_CLIENT_MODULE API allows you to check the activated server status (#mc_client_set_server_update_cb()), the playback info (#mc_client_set_playback_update_cb()), or the metadata (#mc_client_set_metadata_update_cb()). to send the custom command (#mc_client_send_custom_command()), to create/destroy the handle (#mc_client_create()/#mc_client_destroy()). \n * If there is no the activated server, you can get the latest server information by using #mc_client_get_latest_server_info(). * */ diff --git a/include/media_controller_client.h b/include/media_controller_client.h index 7f5c718..199f09b 100755 --- a/include/media_controller_client.h +++ b/include/media_controller_client.h @@ -539,8 +539,6 @@ int mc_client_foreach_server_subscribed(mc_client_h client, mc_subscription_type * @privlevel public * @privilege %http://tizen.org/privilege/mediacontroller.client * - * @remarks The @a playback should be released using @c mc_client_destroy_playback(). - * * @param[in] playback The handle to playback * @param[out] state The state of the playback * @return @c 0 on success, @@ -548,7 +546,7 @@ int mc_client_foreach_server_subscribed(mc_client_h client, mc_subscription_type * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied - * @pre Sets mc_client_set_playback_update_cb() function to get the state + * @pre The playback update callback should be set with mc_client_set_playback_update_cb(). * @see mc_client_set_playback_update_cb() */ int mc_client_get_playback_state(mc_playback_h playback, mc_playback_states_e *state); @@ -560,8 +558,6 @@ int mc_client_get_playback_state(mc_playback_h playback, mc_playback_states_e *s * @privlevel public * @privilege %http://tizen.org/privilege/mediacontroller.client * - * @remarks The @a playback should be released using @c mc_client_destroy_playback(). - * * @param[in] playback The handle to playback * @param[out] position The position of the playback in milliseconds * @return @c 0 on success, @@ -569,12 +565,35 @@ int mc_client_get_playback_state(mc_playback_h playback, mc_playback_states_e *s * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied - * @pre Sets mc_client_set_playback_update_cb() function to get the position + * @pre The playback update callback should be set with mc_client_set_playback_update_cb(). * @see mc_client_set_playback_update_cb() */ int mc_client_get_playback_position(mc_playback_h playback, unsigned long long *position); /** + * @brief Gets the index of the media in playlist. + * @details Gets the index of the current playing media in a playlist. If the media controller server didn't set the index, the value is NULL. + * @since_tizen 5.0 + * + * @privlevel public + * @privilege %http://tizen.org/privilege/mediacontroller.client + * + * @remarks The @a index should be released using free(). + * + * @param[in] playback The handle to playback + * @param[out] index The index of the media + * @return @c 0 on success, + * otherwise a negative error value + * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful + * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED Permission denied + * @pre The playback update callback should be set with mc_client_set_playback_update_cb(). + * @see mc_client_set_playback_update_cb() + * @see mc_client_get_server_playlist() + */ +int mc_client_get_playlist_item_index(mc_playback_h playback, char **index); + +/** * @brief Destroys playback. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @@ -583,7 +602,7 @@ int mc_client_get_playback_position(mc_playback_h playback, unsigned long long * * otherwise a negative error value * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter - * @pre Sets mc_client_set_playback_update_cb() function to create playback + * @pre The playback update callback should be set with mc_client_set_playback_update_cb(). * @see mc_client_set_playback_update_cb() */ int mc_client_destroy_playback(mc_playback_h playback); diff --git a/include/media_controller_db.h b/include/media_controller_db.h index 7cc718b..1239f85 100755 --- a/include/media_controller_db.h +++ b/include/media_controller_db.h @@ -26,51 +26,30 @@ #define MC_FILE_PATH_LEN_MAX FAT_FILEPATH_LEN_MAX /**< File path max length (include file name) on file system */ #define MC_DB_NAME ".media_controller.db" -#define MC_DB_PATH tzplatform_mkpath(TZ_USER_DB, MC_DB_NAME) #define MC_DB_TABLE_SERVER_LIST "server_list" #define MC_DB_TABLE_LATEST_SERVER "latest_server" -#define DB_DELETE_ALL_FROM_TABLE "DELETE FROM '%q';" -#define DB_SELECT_META_FROM_TABLE "SELECT * FROM '%q';" -#define DB_SELECT_SERVER_INFO_FROM_TABLE "SELECT '%q' FROM '%q' WHERE '%q' = '%q';" -#define DB_SELECT_SERVER_STATE_FROM_TABLE "SELECT server_state FROM '%q';" -#define DB_SELECT_PLAYBACK_STATE_FROM_DB "SELECT playback_state FROM '%q';" -#define DB_SELECT_PLAYBACK_POSITION_FROM_DB "SELECT playback_position FROM '%q';" #define DB_SELECT_METADATA_FROM_DB "SELECT * FROM '%q';" -#define DB_SELECT_SHUFFLE_MODE_FROM_DB "SELECT shuffle_mode FROM '%q';" -#define DB_SELECT_REPEAT_MODE_FROM_DB "SELECT repeat_mode FROM '%q';" #define DB_SELECT_VALUE_OF_KEY "SELECT %s FROM '%q';" -#define DB_UPDATE_PLAYBACK_INFO_INTO_SERVER_TABLE "UPDATE '%q' SET playback_state=%d, playback_position=%llu;" -#define DB_UPDATE_METADATA_INTO_SERVER_TABLE "UPDATE '%q' SET %s='%q';" #define DB_UPDATE_SHUFFLE_MODE_INTO_SERVER_TABLE "UPDATE '%q' SET shuffle_mode=%d;" #define DB_UPDATE_REPEAT_MODE_INTO_SERVER_TABLE "UPDATE '%q' SET repeat_mode=%d;" #define DB_UPDATE_METADATA_INFO_INFO_SERVER_TABLE "UPDATE '%q' SET title=%Q, artist=%Q, album=%Q, author=%Q, genre=%Q, duration=%Q, date=%Q, copyright=%Q, description=%Q, track_num=%Q, picture=%Q" #define DB_INSERT_INTO_SERVER_TABLE "INSERT INTO '%q' (server_name) VALUES ('%q');" #define DB_DELETE_FROM_SERVER_TABLE "DELETE FROM %q WHERE server_name = '%q';" -#define DB_UPDATE_VALUE_SERVER_TABLE "UPDATE '%q' set '%q'='%q' where server_name='%q';" #define DB_SELECT_LATEST_SERVER_NAME "SELECT server_name FROM "MC_DB_TABLE_LATEST_SERVER";" #define DB_SELECT_ALL_SERVER_LIST "SELECT server_name FROM "MC_DB_TABLE_SERVER_LIST";" - -#define DB_COLUMN_SERVER_NAME "server_name" -#define DB_COLUMN_SERVER_STATE "server_state" -#define DB_COLUMN_PLAYBACK_STATE "playback_state" -#define DB_COLUMN_PLAYBACK_POSITION "playback_position" - -#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) { sqlite3_free(sql_string); sql_string = NULL; } } -#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); } - int mc_db_connect(void **db_handle); int mc_db_disconnect(void *db_handle); int mc_db_create_server_table(void *handle, const char *server_name); int mc_db_delete_server_table(void *handle, const char *server_name); int mc_db_check_server_table_exist(void *handle, const char *server_name, bool *exist); -int mc_db_update_playback_info(void *handle, const char *table_name, int playback_state, unsigned long long playback_position); +int mc_db_update_playback_info(void *handle, const char *table_name, int playback_state, unsigned long long playback_position, const char *index); int mc_db_update_whole_metadata(void *handle, const char *server_name, const char *title, const char *artist, const char *album, const char *author, const char *genre, const char *duration, const char *date, const char *copyright, const char *description, const char *track_num, const char *picture); diff --git a/include/media_controller_private.h b/include/media_controller_private.h index 8f78787..84105ca 100755 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -194,6 +194,7 @@ typedef struct { typedef struct { mc_playback_states_e state; unsigned long long position; + char *index; } media_controller_playback_s; typedef struct { diff --git a/include/media_controller_server.h b/include/media_controller_server.h index 6d5b8d4..e33240a 100755 --- a/include/media_controller_server.h +++ b/include/media_controller_server.h @@ -210,6 +210,27 @@ int mc_server_set_playback_state(mc_server_h server, mc_playback_states_e state) int mc_server_set_playback_position(mc_server_h server, unsigned long long position); /** + * @brief Sets the index of the current playing media in the playlist to update the latest playback info. \n + * @defails If a media controller server has a playlist, the server can register and share it with media controller client. A playlist is a set of key-value pairs. "index" is the key and "media metadata" is the value.\n + * The media controller server can let media controller clients know the index of current playling media by using this function. + * @since_tizen 5.0 + * @param[in] server The handle to media controller server + * @param[in] index The index of the current playing media in the playlist + * @return @c 0 on success, + * otherwise a negative error value + * @retval #MEDIA_CONTROLLER_ERROR_NONE Successful + * @retval #MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY File does not exist + * @pre Create a media controller server handle by calling mc_server_create(). + * @post Apply the updated playback information by calling mc_server_update_playback_info(). + * @see mc_server_create() + * @see mc_server_destroy() + * @see mc_server_update_playback_info() + * @see mc_server_update_playlist() + */ +int mc_server_set_playlist_item_index(mc_server_h server, const char *index); + +/** * @brief Updates the modified playback info. * @details If this function is called, the updated playback information will be sent to the controller. * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif diff --git a/packaging/capi-media-controller.spec b/packaging/capi-media-controller.spec index 6902a9e..fac0a65 100755 --- a/packaging/capi-media-controller.spec +++ b/packaging/capi-media-controller.spec @@ -1,6 +1,6 @@ Name: capi-media-controller Summary: A media controller library in Tizen Native API -Version: 0.1.53 +Version: 0.1.54 Release: 1 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_controller_client.c b/src/media_controller_client.c index 79e55ee..e6c4b0b 100755 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -64,6 +64,7 @@ static void __client_playback_cb(const char *interface_name, const char *signal_ playback->state = atoi(params[1]); playback->position = strtoull(params[2], NULL, 10); + playback->index = g_strdup(params[3]); callback(params[0], (mc_playback_h) playback, reciever->user_data); @@ -813,6 +814,18 @@ int mc_client_get_playback_position(mc_playback_h playback, unsigned long long * return MEDIA_CONTROLLER_ERROR_NONE; } +int mc_client_get_playlist_item_index(mc_playback_h playback, char **index) +{ + media_controller_playback_s *mc_playback = (media_controller_playback_s *)playback; + + mc_retvm_if(mc_playback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + mc_retvm_if(index == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "index is NULL"); + + *index = g_strdup(mc_playback->index); + + return MEDIA_CONTROLLER_ERROR_NONE; +} + int mc_client_get_metadata(mc_metadata_h metadata, mc_meta_e attribute, char **value) { char *meta_val = NULL; @@ -886,6 +899,7 @@ int mc_client_destroy_playback(mc_playback_h playback) mc_retvm_if(mc_playback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + MC_SAFE_FREE(mc_playback->index); MC_SAFE_FREE(mc_playback); return MEDIA_CONTROLLER_ERROR_NONE; diff --git a/src/media_controller_db.c b/src/media_controller_db.c index 6d36d36..493347c 100755 --- a/src/media_controller_db.c +++ b/src/media_controller_db.c @@ -48,6 +48,9 @@ typedef enum { #define MC_DB_TABLE_PLAYLIST "server_playlist" +#define SQLITE3_SAFE_FREE(sql_string) {if (sql_string) { sqlite3_free(sql_string); sql_string = NULL; } } +#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); } + static int __mc_db_busy_handler(void *pData, int count) { MC_MILLISEC_SLEEP(50); @@ -109,45 +112,6 @@ static int __mc_db_get_int_value_of_key(void *handle, const char *server_name, c return MEDIA_CONTROLLER_ERROR_NONE; } -static int __mc_db_get_ulong_value_of_key(void *handle, const char *server_name, const char *key, unsigned long long *value) -{ - int ret = MEDIA_CONTROLLER_ERROR_NONE; - char *sql_str = NULL; - sqlite3_stmt *stmt = NULL; - sqlite3 *db_handle = (sqlite3 *)handle; - - 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"); - mc_retvm_if(key == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "key is NULL"); - - sql_str = sqlite3_mprintf(DB_SELECT_VALUE_OF_KEY, key, server_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; - } - - ret = sqlite3_step(stmt); - if (SQLITE_ROW != ret) { - mc_error("end of row [%s]", sqlite3_errmsg(db_handle)); - SQLITE3_FINALIZE(stmt); - SQLITE3_SAFE_FREE(sql_str); - return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; - } - while (SQLITE_ROW == ret) { - *value = (unsigned long long)sqlite3_column_int64(stmt, 0); - ret = sqlite3_step(stmt); - } - - SQLITE3_FINALIZE(stmt); - SQLITE3_SAFE_FREE(sql_str); - - return MEDIA_CONTROLLER_ERROR_NONE; -} - static int __db_get_playlist(void *handle, const char *server_name, char **playlist_name, bundle **playlist) { int ret = MEDIA_CONTROLLER_ERROR_NONE; @@ -303,7 +267,7 @@ int mc_db_connect(void **handle) return MEDIA_CONTROLLER_ERROR_NONE; } -int mc_db_update_playback_info(void *handle, const char *server_name, int playback_state, unsigned long long playback_position) +int mc_db_update_playback_info(void *handle, const char *server_name, int playback_state, unsigned long long playback_position, const char *index) { int ret = MEDIA_CONTROLLER_ERROR_NONE; char *sql_str = NULL; @@ -311,7 +275,7 @@ int mc_db_update_playback_info(void *handle, const char *server_name, int playba 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"); - sql_str = sqlite3_mprintf(DB_UPDATE_PLAYBACK_INFO_INTO_SERVER_TABLE, server_name, playback_state, playback_position); + sql_str = sqlite3_mprintf("UPDATE '%q' SET playback_state=%d, playback_position=%llu, index=%Q;", server_name, playback_state, playback_position, index); ret = __mc_db_update_db(handle, sql_str); @@ -425,21 +389,46 @@ int mc_db_get_playback_info(void *handle, const char *server_name, mc_playback_h mc_playback_states_e playback_state = MC_PLAYBACK_STATE_PLAYING; unsigned long long position = 0; media_controller_playback_s *_playback = NULL; + char *sql_str = NULL; + sqlite3_stmt *stmt = NULL; + sqlite3 *db_handle = (sqlite3 *)handle; + char *index = 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"); + mc_retvm_if(playback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playback is NULL"); + + sql_str = sqlite3_mprintf("SELECT playback_state, playback_position, index FROM '%q';", server_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; + } - ret = __mc_db_get_int_value_of_key(handle, server_name, "playback_state", (int *)&playback_state); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "Fail to get playback_state"); + ret = sqlite3_step(stmt); + if (SQLITE_ROW != ret) { + mc_error("end of row [%s]", sqlite3_errmsg(db_handle)); + SQLITE3_FINALIZE(stmt); + SQLITE3_SAFE_FREE(sql_str); + return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; + } - ret = __mc_db_get_ulong_value_of_key(handle, server_name, "playback_position", &position); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "Fail to get position"); + playback_state = sqlite3_column_int(stmt, 0); + position = (unsigned long long)sqlite3_column_int64(stmt, 1); + index = g_strdup((const char *)sqlite3_column_text(stmt, 2)); + + SQLITE3_FINALIZE(stmt); + SQLITE3_SAFE_FREE(sql_str); _playback = (media_controller_playback_s *)calloc(1, sizeof(media_controller_playback_s)); mc_retvm_if(_playback == NULL, MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); _playback->state = playback_state; _playback->position = position; + _playback->index = index; *playback = (mc_playback_h)_playback; @@ -621,6 +610,7 @@ int mc_db_create_server_table(void *handle, const char *server_name) server_state INTEGER DEFAULT 1, \ playback_state INTEGER DEFAULT 0, \ playback_position INTEGER DEFAULT 0, \ + index TEXT, \ title TEXT, \ artist TEXT, \ album TEXT, \ diff --git a/src/media_controller_server.c b/src/media_controller_server.c index f27f325..dfab1a3 100755 --- a/src/media_controller_server.c +++ b/src/media_controller_server.c @@ -97,6 +97,7 @@ static int __mc_server_destoy(media_controller_server_s *mc_server) if (mc_server->metadata != NULL) mc_client_destroy_metadata(mc_server->metadata); + MC_SAFE_FREE(mc_server->playback.index); MC_SAFE_FREE(mc_server); return ret; @@ -387,7 +388,7 @@ static int __mc_server_send_message(media_controller_server_s *mc_server, const mc_retvm_if(signal_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "signal_name is NULL"); if (!g_strcmp0(MC_DBUS_SIGNAL_NAME_PLAY_BACK, signal_name)) - message = g_strdup_printf("%s%s%d%s%llu", mc_server->server_name, MC_STRING_DELIMITER, param1, MC_STRING_DELIMITER, param2); + message = g_strdup_printf("%s%s%d%s%llu%s%s", mc_server->server_name, MC_STRING_DELIMITER, param1, MC_STRING_DELIMITER, param2, MC_STRING_DELIMITER, param3); else if (!g_strcmp0(MC_DBUS_SIGNAL_NAME_METADATA, signal_name)) message = g_strdup_printf("%s", mc_server->server_name); else if (!g_strcmp0(MC_DBUS_SIGNAL_NAME_PLAYLIST, signal_name)) @@ -450,6 +451,22 @@ int mc_server_set_playback_position(mc_server_h server, unsigned long long posit return MEDIA_CONTROLLER_ERROR_NONE; } +int mc_server_set_playlist_item_index(mc_server_h server, const char *index) +{ + media_controller_server_s *mc_server = (media_controller_server_s *)server; + + mc_retvm_if(mc_server == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); + mc_retvm_if(!MC_STRING_VALID(index), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid index"); + + mc_debug("index update [%s]", index); + + MC_SAFE_FREE(mc_server->playback.index); + + mc_server->playback.index = g_strdup(index); + + return MEDIA_CONTROLLER_ERROR_NONE; +} + int mc_server_update_playback_info(mc_server_h server) { int ret = MEDIA_CONTROLLER_ERROR_NONE; @@ -459,20 +476,20 @@ int mc_server_update_playback_info(mc_server_h server) mc_debug("playback info update: state [%d], position [%llu]", mc_server->playback.state, mc_server->playback.position); - ret = mc_db_update_playback_info(mc_server->db_handle, mc_server->server_name, (int)mc_server->playback.state, mc_server->playback.position); + ret = mc_db_update_playback_info(mc_server->db_handle, mc_server->server_name, (int)mc_server->playback.state, mc_server->playback.position, mc_server->playback.index); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { mc_error("fail mc_db_update_playback_info [%d]", ret); return ret; } - ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK, mc_server->playback.state, mc_server->playback.position, NULL); + ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_PLAY_BACK, mc_server->playback.state, mc_server->playback.position, mc_server->playback.index); if (ret != MEDIA_CONTROLLER_ERROR_NONE) mc_error("Error __mc_server_send_message [%d]", ret); if (mc_server->playback.state == MC_PLAYBACK_STATE_PLAYING) { ret = mc_db_update_latest_server_table(mc_server->db_handle, mc_server->server_name); if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("fail mc_db_update_playback_info [%d]", ret); + mc_error("fail mc_db_update_latest_server_table [%d]", ret); return ret; } } diff --git a/test/client_test/media_controller_client_test.c b/test/client_test/media_controller_client_test.c index c6d1de4..aaccbdb 100755 --- a/test/client_test/media_controller_client_test.c +++ b/test/client_test/media_controller_client_test.c @@ -86,11 +86,15 @@ void _mc_playback_updated_cb(const char *server_name, mc_playback_h playback, vo media_controller_client_s *_client = (media_controller_client_s *)g_mc_client; unsigned long long position = 0; mc_playback_states_e playback_state = MC_PLAYBACK_STATE_NONE; + char *index = NULL; mc_client_get_playback_position(playback, &position); mc_client_get_playback_state(playback, &playback_state); + mc_client_get_playlist_item_index(playback, &index); - mc_debug("[Client:%s] Playback updated from server[%s] playback_state[%d] position[%lld]", _client->client_name, server_name, playback_state, position); + mc_debug("[Client:%s] Playback updated from server[%s] playback_state[%d] position[%lld] index[%s]", _client->client_name, server_name, playback_state, position, index); + + MC_SAFE_FREE(index); } void _mc_metadata_updated_cb(const char *server_name, mc_metadata_h metadata, void *user_data) @@ -275,6 +279,7 @@ static gboolean _get_info(int type) mc_shuffle_mode_e shuffle_mode; mc_repeat_mode_e repeate_mode; bundle *playlist = NULL; + char *index = NULL; int bundle_cnt = 0; mc_debug_fenter(); @@ -299,7 +304,13 @@ static gboolean _get_info(int type) if (ret != MEDIA_CONTROLLER_ERROR_NONE) g_print("Fail to get playback position"); - g_print("playback state: %d, position: %lld", playback_state, playback_position); + ret = mc_client_get_playlist_item_index(playback, &index); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) + g_print("Fail to get playback position"); + + g_print("playback state [%d], position [%lld], index [%s]", playback_state, playback_position, index); + + MC_SAFE_FREE(index); ret = mc_client_destroy_playback(playback); mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, FALSE, "Fail to mc_client_destroy_playback [%d]", ret); diff --git a/test/server_test/media_controller_server_test.c b/test/server_test/media_controller_server_test.c index a1437e6..64759a6 100755 --- a/test/server_test/media_controller_server_test.c +++ b/test/server_test/media_controller_server_test.c @@ -60,6 +60,7 @@ enum { CURRENT_STATE_SET_MODE_NONE, CURRENT_STATE_SET_PLAYBACK_STATE, CURRENT_STATE_SET_PLAYBACK_POSITION, + CURRENT_STATE_SET_ITEM_ID, CURRENT_STATE_SET_METADATA_NAME, CURRENT_STATE_SET_METADATA_VALUE, }; @@ -278,12 +279,13 @@ static gboolean _set_cb() static gboolean _set_info(int type, char *cmd) { - g_print("== get information \n"); int ret = MEDIA_CONTROLLER_ERROR_NONE; int playback_state = 0; unsigned long long playback_position; char *metadata = NULL; + g_print("== get information [%d]\n", type); + switch (type) { case CURRENT_STATE_SET_PLAYBACK_STATE: playback_state = atoi(cmd); @@ -294,6 +296,7 @@ static gboolean _set_info(int type, char *cmd) } g_print("set state: %d", playback_state); break; + case CURRENT_STATE_SET_PLAYBACK_POSITION: playback_position = strtoull(cmd, NULL, 10); ret = mc_server_set_playback_position(g_mc_server, playback_position); @@ -303,10 +306,21 @@ static gboolean _set_info(int type, char *cmd) } g_print("set position: %lld", playback_position); break; + + case CURRENT_STATE_SET_ITEM_ID: + ret = mc_server_set_playlist_item_index(g_mc_server, cmd); + if (ret != MEDIA_CONTROLLER_ERROR_NONE) { + g_print("Fail to set media id"); + return FALSE; + } + g_print("set media id: %s", cmd); + break; + case CURRENT_STATE_SET_METADATA_NAME: g_metadata_type = atoi(cmd); g_print("set metadata name: %d", g_metadata_type); break; + case CURRENT_STATE_SET_METADATA_VALUE: metadata = strdup(cmd); ret = mc_server_set_metadata(g_mc_server, g_metadata_type, metadata); @@ -459,8 +473,9 @@ static void display_set_info_menu(void) g_print("----------------------------------------------------\n"); g_print("1. set server playback state\n"); g_print("2. set server playback position \n"); - g_print("3. set server metadata name\n"); - g_print("4. set server metadata value\n"); + g_print("3. set server media id \n"); + g_print("4. set server metadata name\n"); + g_print("5. set server metadata value\n"); g_print("0. back \n"); g_print("----------------------------------------------------\n"); g_print("====================================================\n"); @@ -529,8 +544,10 @@ void _interpret_set_info_menu(char *cmd) else if (!strncmp(cmd, "2", len)) g_menu_set_state = CURRENT_STATE_SET_PLAYBACK_POSITION; else if (!strncmp(cmd, "3", len)) - g_menu_set_state = CURRENT_STATE_SET_METADATA_NAME; + g_menu_set_state = CURRENT_STATE_SET_ITEM_ID; else if (!strncmp(cmd, "4", len)) + g_menu_set_state = CURRENT_STATE_SET_METADATA_NAME; + else if (!strncmp(cmd, "5", len)) g_menu_set_state = CURRENT_STATE_SET_METADATA_VALUE; else if (!strncmp(cmd, "0", len)) { reset_current_menu_state(); @@ -579,6 +596,7 @@ static void interpret_cmd(char *cmd) break; case CURRENT_STATE_SET_PLAYBACK_STATE: case CURRENT_STATE_SET_PLAYBACK_POSITION: + case CURRENT_STATE_SET_ITEM_ID: case CURRENT_STATE_SET_METADATA_NAME: case CURRENT_STATE_SET_METADATA_VALUE: _set_info(g_menu_set_state, cmd);