From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 03/13] player: Add support for button controls
Date: Thu, 10 Jan 2013 15:24:30 +0200 [thread overview]
Message-ID: <1357824283-19233-3-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1357824283-19233-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds support for buttons controls in MediaPlayer1
---
profiles/audio/avrcp.c | 75 +++++++++++++++++++++++++++-
profiles/audio/player.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++
profiles/audio/player.h | 7 +++
3 files changed, 210 insertions(+), 1 deletion(-)
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index a139606..9ca5a3a 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1965,8 +1965,80 @@ static bool ct_set_setting(struct media_player *mp, const char *key,
return true;
}
+static int ct_press(struct avrcp_player *player, uint8_t op)
+{
+ int err;
+ struct avrcp *session;
+
+ session = player->sessions->data;
+ if (session == NULL)
+ return -ENOTCONN;
+
+ err = avctp_send_passthrough(session->conn, op);
+ if (err < 0)
+ return err;
+
+ return 0;
+}
+
+static int ct_play(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_PLAY);
+}
+
+static int ct_pause(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_PAUSE);
+}
+
+static int ct_stop(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_STOP);
+}
+
+static int ct_next(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_FORWARD);
+}
+
+static int ct_previous(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_BACKWARD);
+}
+
+static int ct_fast_forward(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_FAST_FORWARD);
+}
+
+static int ct_rewind(struct media_player *mp, void *user_data)
+{
+ struct avrcp_player *player = user_data;
+
+ return ct_press(player, AVC_REWIND);
+}
+
static const struct media_player_callback ct_cbs = {
- .set_setting = ct_set_setting,
+ .set_setting = ct_set_setting,
+ .play = ct_play,
+ .pause = ct_pause,
+ .stop = ct_stop,
+ .next = ct_next,
+ .previous = ct_previous,
+ .fast_forward = ct_fast_forward,
+ .rewind = ct_rewind,
};
static gboolean avrcp_get_capabilities_resp(struct avctp *conn,
@@ -1988,6 +2060,7 @@ static gboolean avrcp_get_capabilities_resp(struct avctp *conn,
count = pdu->params[1];
path = device_get_path(session->dev->btd_dev);
+
mp = media_player_controller_create(path);
if (mp == NULL)
return FALSE;
diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 9add1b8..2e5c386 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -242,7 +242,136 @@ static gboolean get_track(const GDBusPropertyTable *property,
return TRUE;
}
+static DBusMessage *media_player_play(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->play == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->play(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_pause(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->pause == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->pause(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_stop(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->stop == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->stop(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_next(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->next == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->next(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_previous(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->previous == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->previous(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_fast_forward(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->fast_forward == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->fast_forward(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
+static DBusMessage *media_player_rewind(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ struct media_player *mp = data;
+ struct player_callback *cb = mp->cb;
+ int err;
+
+ if (cb->cbs->rewind == NULL)
+ return btd_error_not_supported(msg);
+
+ err = cb->cbs->rewind(mp, cb->user_data);
+ if (err < 0)
+ return btd_error_failed(msg, strerror(-err));
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
static const GDBusMethodTable media_player_methods[] = {
+ { GDBUS_EXPERIMENTAL_METHOD("Play", NULL, NULL, media_player_play) },
+ { GDBUS_EXPERIMENTAL_METHOD("Pause", NULL, NULL, media_player_pause) },
+ { GDBUS_EXPERIMENTAL_METHOD("Stop", NULL, NULL, media_player_stop) },
+ { GDBUS_EXPERIMENTAL_METHOD("Next", NULL, NULL, media_player_next) },
+ { GDBUS_EXPERIMENTAL_METHOD("Previous", NULL, NULL,
+ media_player_previous) },
+ { GDBUS_EXPERIMENTAL_METHOD("FastForward", NULL, NULL,
+ media_player_fast_forward) },
+ { GDBUS_EXPERIMENTAL_METHOD("Rewind", NULL, NULL,
+ media_player_rewind) },
{ }
};
diff --git a/profiles/audio/player.h b/profiles/audio/player.h
index 87dfb66..212a5a6 100644
--- a/profiles/audio/player.h
+++ b/profiles/audio/player.h
@@ -28,6 +28,13 @@ struct media_player;
struct media_player_callback {
bool (*set_setting) (struct media_player *mp, const char *key,
const char *value, void *user_data);
+ int (*play) (struct media_player *mp, void *user_data);
+ int (*pause) (struct media_player *mp, void *user_data);
+ int (*stop) (struct media_player *mp, void *user_data);
+ int (*next) (struct media_player *mp, void *user_data);
+ int (*previous) (struct media_player *mp, void *user_data);
+ int (*fast_forward) (struct media_player *mp, void *user_data);
+ int (*rewind) (struct media_player *mp, void *user_data);
};
struct media_player *media_player_controller_create(const char *path);
--
1.8.0.1
next prev parent reply other threads:[~2013-01-10 13:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-10 13:24 [PATCH BlueZ 01/13] media-api: Add playback control methods to MediaPlayer1 Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 02/13] player: Remove GetTrack and TrackChanged Luiz Augusto von Dentz
2013-01-10 13:24 ` Luiz Augusto von Dentz [this message]
2013-01-10 13:24 ` [PATCH BlueZ 04/13] player: Fix documentation to use TrackNumber in track metadata Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 05/13] AVRCP: Always create a controller player even for version 1.0 Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 6/8 v2] control: Mark all members of MediaControl1 as deprecated Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 06/13] player: Add Device property Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 07/13] media: Adapt RegisterPlayer to changes in MediaPlayer1 Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 7/8 v2] player: Remove experimental flag from MediaPlayer1 Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 8/8 v2] player: Add Device property Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 08/13] test: Adapt simple-player to the new API of MediaPlayer1 Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 09/13] tools: Adapt mpris-player to " Luiz Augusto von Dentz
2013-01-10 13:24 ` [PATCH BlueZ 10/13] media-api: Change RegisterPlayer to use MPRIS spec Luiz Augusto von Dentz
2013-01-10 13:26 ` [PATCH BlueZ 01/13] media-api: Add playback control methods to MediaPlayer1 Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357824283-19233-3-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox