summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_bt_player.h
blob: 25a6c8c53f11a2b3e60dcec7076b24b69dccda36 (plain)
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
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef CRAS_BT_PLAYER_H_
#define CRAS_BT_PLAYER_H_

#include <dbus/dbus.h>
#include <stdbool.h>

#include "cras_bt_adapter.h"

/* Object to hold current metadata. This is not a full list of what BlueZ/MPRIS
 * supports but a subset because Chromium only provides the following.
 */
struct cras_bt_player_metadata {
	char *title;
	char *artist;
	char *album;
	int64_t length;
};

/* Object to register as media player so that bluetoothd will report hardware
 * volume from device through bt_transport. Properties of the player are defined
 * in BlueZ's media API.
 */
struct cras_bt_player {
	const char *object_path;
	char *playback_status;
	char *identity;
	const char *loop_status;
	struct cras_bt_player_metadata *metadata;
	int64_t position;
	bool can_go_next;
	bool can_go_prev;
	bool can_play;
	bool can_pause;
	bool can_control;
	bool shuffle;
	void (*message_cb)(const char *message);
};

/* Creates a player object and register it to bluetoothd.
 * Args:
 *    conn - The dbus connection.
 */
int cras_bt_player_create(DBusConnection *conn);

/* Registers created player to bluetoothd. This is used when an bluetooth
 * adapter got enumerated.
 * Args:
 *    conn - The dbus connection.
 *    adapter - The enumerated bluetooth adapter.
 */
int cras_bt_register_player(DBusConnection *conn,
			    const struct cras_bt_adapter *adapter);

/* Updates playback status for player and notifies bluetoothd
 * Args:
 *    conn - The dbus connection.
 *    status - The player playback status.
 */
int cras_bt_player_update_playback_status(DBusConnection *conn,
					  const char *status);

/* Updates the player identity and notifies bluetoothd.
 * Args:
 *    conn - The dbus connection.
 *    identity - The identity of the registered player. This could be the name
 *               of the app or the name of the site playing media.
 */
int cras_bt_player_update_identity(DBusConnection *conn, const char *identity);

/* Updates the player current track's position and notifies bluetoothd.
 * Args:
 *    conn - The dbus connection.
 *    position - The current track position in microseconds.
 */
int cras_bt_player_update_position(DBusConnection *conn,
				   const dbus_int64_t position);

/* Updates the player current metadata and notifies bluetoothd.
 * Args:
 *    conn - The dbus connection.
 *    title - The title associated to the current media session.
 *    artist - The artist associated to the current media session.
 *    album - The album associated to the current media session.
 *    length - The duration in microseconds associated to the current media
 *             session.
 */
int cras_bt_player_update_metadata(DBusConnection *conn, const char *title,
				   const char *artist, const char *album,
				   const dbus_int64_t length);
#endif /* CRAS_BT_PLAYER_H_ */