1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_MEDIA_PROXY_INTERNAL_H_
8 #define ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_MEDIA_PROXY_INTERNAL_H_
9 
10 /** @brief Internal APIs for Bluetooth Media Control */
11 
12 #include <stdint.h>
13 
14 #include <zephyr/autoconf.h>
15 #include <zephyr/bluetooth/audio/media_proxy.h>
16 #include <zephyr/sys/util_macro.h>
17 
18 #define MPL_NO_TRACK_ID 0
19 
20 /* Debug output of 48 bit Object ID value */
21 /* (Zephyr does not yet support debug output of more than 32 bit values.) */
22 /* Takes a text and a 64-bit integer as input */
23 #define LOG_DBG_OBJ_ID(text, id64) \
24 	do { \
25 		if (IS_ENABLED(CONFIG_BT_MCS_LOG_LEVEL_DBG)) { \
26 			char t[BT_OTS_OBJ_ID_STR_LEN]; \
27 			(void)bt_ots_obj_id_to_str(id64, t, sizeof(t)); \
28 			LOG_DBG(text "0x%s", t); \
29 		} \
30 	} while (0)
31 
32 
33 /* SYNCHRONOUS (CALL/RETURN) API FOR CONTROLLERS */
34 
35 /** @brief Callbacks to a controller, from the media proxy */
36 struct media_proxy_sctrl_cbs {
37 	void (*player_name)(const char *name);
38 
39 	void (*icon_url)(const char *url);
40 
41 	void (*track_changed)(void);
42 
43 	void (*track_title)(const char *title);
44 
45 	void (*track_duration)(int32_t duration);
46 
47 	void (*track_position)(int32_t position);
48 
49 	void (*playback_speed)(int8_t speed);
50 
51 	void (*seeking_speed)(int8_t speed);
52 #ifdef CONFIG_BT_OTS
53 	void (*current_track_id)(uint64_t id);
54 
55 	void (*next_track_id)(uint64_t id);
56 
57 	void (*current_group_id)(uint64_t id);
58 
59 	void (*parent_group_id)(uint64_t id);
60 #endif /* CONFIG_BT_OTS */
61 
62 	void (*playing_order)(uint8_t order);
63 
64 	void (*media_state)(uint8_t state);
65 
66 	void (*command)(const struct mpl_cmd_ntf *cmd_ntf);
67 
68 	void (*commands_supported)(uint32_t opcodes);
69 
70 #ifdef CONFIG_BT_OTS
71 	void (*search)(uint8_t result_code);
72 
73 	void (*search_results_id)(uint64_t id);
74 #endif /* CONFIG_BT_OTS */
75 };
76 
77 /** @brief Register a controller with the media proxy */
78 int media_proxy_sctrl_register(struct media_proxy_sctrl_cbs *sctrl_cbs);
79 
80 
81 const char *media_proxy_sctrl_get_player_name(void);
82 
83 #ifdef CONFIG_BT_OTS
84 uint64_t media_proxy_sctrl_get_icon_id(void);
85 #endif /* CONFIG_BT_OTS */
86 
87 const char *media_proxy_sctrl_get_icon_url(void);
88 
89 
90 const char *media_proxy_sctrl_get_track_title(void);
91 
92 int32_t media_proxy_sctrl_get_track_duration(void);
93 
94 int32_t media_proxy_sctrl_get_track_position(void);
95 void media_proxy_sctrl_set_track_position(int32_t position);
96 
97 int8_t media_proxy_sctrl_get_playback_speed(void);
98 void media_proxy_sctrl_set_playback_speed(int8_t speed);
99 
100 int8_t media_proxy_sctrl_get_seeking_speed(void);
101 
102 #ifdef CONFIG_BT_OTS
103 uint64_t media_proxy_sctrl_get_track_segments_id(void);
104 
105 uint64_t media_proxy_sctrl_get_current_track_id(void);
106 void media_proxy_sctrl_set_current_track_id(uint64_t id);
107 
108 uint64_t media_proxy_sctrl_get_next_track_id(void);
109 void media_proxy_sctrl_set_next_track_id(uint64_t id);
110 
111 uint64_t media_proxy_sctrl_get_current_group_id(void);
112 void media_proxy_sctrl_set_current_group_id(uint64_t id);
113 
114 uint64_t media_proxy_sctrl_get_parent_group_id(void);
115 #endif /* CONFIG_BT_OTS */
116 
117 uint8_t media_proxy_sctrl_get_playing_order(void);
118 void media_proxy_sctrl_set_playing_order(uint8_t order);
119 
120 uint16_t media_proxy_sctrl_get_playing_orders_supported(void);
121 
122 uint8_t media_proxy_sctrl_get_media_state(void);
123 
124 void media_proxy_sctrl_send_command(const struct mpl_cmd *command);
125 
126 uint32_t media_proxy_sctrl_get_commands_supported(void);
127 
128 #ifdef CONFIG_BT_OTS
129 void media_proxy_sctrl_send_search(const struct mpl_search *search);
130 
131 uint64_t media_proxy_sctrl_get_search_results_id(void);
132 #endif /* CONFIG_BT_OTS */
133 
134 uint8_t media_proxy_sctrl_get_content_ctrl_id(void);
135 
136 #endif /* ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_MEDIA_PROXY_INTERNAL_H_ */
137