1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dlog.h>
#include <stdbool.h>
#include <bluetooth-api.h>
#include "bluetooth.h"
#include "bluetooth_private.h"
#include "bluetooth-audio-api.h"
#include "bluetooth-media-control.h"
static bool is_avrcp_target_initialized = false;
#define BT_CHECK_AVRCP_TARGET_INIT_STATUS() \
if (__bt_check_avrcp_target_init_status() == BT_ERROR_NOT_INITIALIZED) \
{ \
LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \
return BT_ERROR_NOT_INITIALIZED; \
}
int __bt_check_avrcp_target_init_status(void)
{
if (is_avrcp_target_initialized != true) {
BT_ERR("NOT_INITIALIZED(0x%08x)", BT_ERROR_NOT_INITIALIZED);
return BT_ERROR_NOT_INITIALIZED;
}
return BT_ERROR_NONE;
}
/*The below API is just to conver the error from Audio API's to CAPI error codes,
* this is temporary change and changes to proper error code will be done in
* subsequent check ins.*/
int _bt_convert_avrcp_error_code(int error)
{
switch(error) {
case BT_MEDIA_ERROR_NONE:
return BT_ERROR_NONE;
case BT_MEDIA_ERROR_INTERNAL:
return BT_ERROR_INVALID_PARAMETER;
case BT_MEDIA_ERROR_ALREADY_INITIALIZED:
return BT_ERROR_OPERATION_FAILED;
default:
return BT_ERROR_NONE;
}
}
int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(callback);
_bt_set_cb(BT_EVENT_AVRCP_CONNECTION_STATUS, callback, user_data);
error = bluetooth_media_player_init(_bt_avrcp_event_proxy, NULL);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
return error;
}
is_avrcp_target_initialized = true;
return BT_ERROR_NONE;
}
int bt_avrcp_target_deinitialize(void)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
if (_bt_check_cb(BT_EVENT_AVRCP_CONNECTION_STATUS) == true)
_bt_unset_cb(BT_EVENT_AVRCP_CONNECTION_STATUS);
error = bluetooth_media_player_deinit();
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
return error;
}
is_avrcp_target_initialized = false;
return BT_ERROR_NONE;
}
int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(EQUALIZER, state);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(REPEAT, mode);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(SHUFFLE, mode);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(SCAN, mode);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(STATUS, state);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_position(unsigned int position)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
error = bluetooth_media_player_change_property(POSITION, position);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album,
const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration)
{
int error;
BT_CHECK_INIT_STATUS();
BT_CHECK_AVRCP_TARGET_INIT_STATUS();
media_metadata_attributes_t metadata;
metadata.title = title;
metadata.artist = artist;
metadata.duration = duration;
metadata.genre = genre;
metadata.number = track_num;
metadata.album = album;
metadata.total_tracks = total_tracks;
error = bluetooth_media_player_change_track(&metadata);
error = _bt_convert_avrcp_error_code(error);
error = _bt_get_error_code(error);
if (BT_ERROR_NONE != error) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error);
}
return error;
}
int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data)
{
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(callback);
_bt_set_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, callback, user_data);
return BT_ERROR_NONE;
}
int bt_avrcp_unset_equalizer_state_changed_cb(void)
{
BT_CHECK_INIT_STATUS();
_bt_unset_cb(BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED);
return BT_ERROR_NONE;
}
int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data)
{
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(callback);
_bt_set_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, callback, user_data);
return BT_ERROR_NONE;
}
int bt_avrcp_unset_repeat_mode_changed_cb(void)
{
BT_CHECK_INIT_STATUS();
_bt_unset_cb(BT_EVENT_AVRCP_REPEAT_MODE_CHANGED);
return BT_ERROR_NONE;
}
int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data)
{
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(callback);
_bt_set_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, callback, user_data);
return BT_ERROR_NONE;
}
int bt_avrcp_unset_shuffle_mode_changed_cb(void)
{
BT_CHECK_INIT_STATUS();
_bt_unset_cb(BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED);
return BT_ERROR_NONE;
}
int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data)
{
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(callback);
_bt_set_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED, callback, user_data);
return BT_ERROR_NONE;
}
int bt_avrcp_unset_scan_mode_changed_cb(void)
{
BT_CHECK_INIT_STATUS();
_bt_unset_cb(BT_EVENT_AVRCP_SCAN_MODE_CHANGED);
return BT_ERROR_NONE;
}
|