4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "bluetooth-api.h"
23 #include "bluetooth-media-control.h"
24 #include "bt-internal-types.h"
26 #include "bt-common.h"
27 #include "bt-request-sender.h"
28 #include "bt-event-handler.h"
30 BT_EXPORT_API int bluetooth_media_player_init(media_cb_func_ptr callback_ptr,
35 /* Register AVRCP events */
36 ret = _bt_register_event(BT_AVRCP_EVENT , (void *)callback_ptr, user_data);
38 if (ret != BLUETOOTH_ERROR_NONE &&
39 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
40 BT_ERR("Fail to init the event handler");
44 _bt_set_user_data(BT_AVRCP, (void *)callback_ptr, user_data);
46 return BLUETOOTH_ERROR_NONE;
49 BT_EXPORT_API int bluetooth_media_player_deinit(void)
53 ret = _bt_unregister_event(BT_AVRCP_EVENT);
55 if (ret != BLUETOOTH_ERROR_NONE) {
56 BT_ERR("Fail to deinit the event handler");
60 _bt_set_user_data(BT_AVRCP, NULL, NULL);
62 return BLUETOOTH_ERROR_NONE;
65 BT_EXPORT_API int bluetooth_media_player_change_property(
66 media_player_property_type type,
71 BT_CHECK_ENABLED(return);
74 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
76 g_array_append_vals(in_param1, &type, sizeof(int));
77 g_array_append_vals(in_param2, &value, sizeof(unsigned int));
79 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_AVRCP_SET_PROPERTY,
80 in_param1, in_param2, in_param3, in_param4, &out_param);
82 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
87 BT_EXPORT_API int bluetooth_media_player_set_properties(
88 media_player_settings_t *setting)
92 BT_CHECK_PARAMETER(setting, return);
93 BT_CHECK_ENABLED(return);
96 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
98 g_array_append_vals(in_param1, setting, sizeof(media_player_settings_t));
100 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_AVRCP_SET_PROPERTIES,
101 in_param1, in_param2, in_param3, in_param4, &out_param);
103 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
108 BT_EXPORT_API int bluetooth_media_player_change_track(
109 media_metadata_attributes_t *metadata)
112 media_metadata_t meta_data;
114 BT_CHECK_PARAMETER(metadata, return);
115 BT_CHECK_ENABLED(return);
118 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
120 memset(&meta_data, 0x00, sizeof(media_metadata_t));
122 if (_bt_copy_utf8_string(meta_data.title, metadata->title, BT_NAME_MAX))
123 BT_DBG("Error in copying Title\n");
124 if (_bt_copy_utf8_string(meta_data.artist, metadata->artists[0], BT_NAME_MAX))
125 BT_DBG("Error in copying Artist\n");
126 if (_bt_copy_utf8_string(meta_data.album, metadata->album, BT_NAME_MAX))
127 BT_DBG("Error in copying Album\n");
128 if (_bt_copy_utf8_string(meta_data.genre, metadata->genres[0], BT_NAME_MAX))
129 BT_DBG("Error in copying Genre\n");
131 meta_data.number = metadata->tracknumber;
132 meta_data.duration = metadata->duration;
134 g_array_append_vals(in_param1, &meta_data, sizeof(media_metadata_t));
136 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_AVRCP_SET_TRACK_INFO,
137 in_param1, in_param2, in_param3, in_param4, &out_param);
139 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);