Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Fix check for PDU size
@ 2011-10-26 13:02 Lucas De Marchi
  2011-10-26 13:02 ` [PATCH] AVRCP: implement TRACK-REACHED-END event Lucas De Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Lucas De Marchi @ 2011-10-26 13:02 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi

Company ID became part of the avrcp header so its size is already
accounted in the AVRCP_HEADER_LENGTH define.
---
 audio/avrcp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/audio/avrcp.c b/audio/avrcp.c
index f06afbf..879e959 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1053,7 +1053,7 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
 	pdu->packet_type = 0;
 	pdu->rsvd = 0;
 
-	if (operand_count + 3 < AVRCP_HEADER_LENGTH) {
+	if (operand_count < AVRCP_HEADER_LENGTH) {
 		pdu->params[0] = E_INVALID_COMMAND;
 		goto err_metadata;
 	}
-- 
1.7.7.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-10-26 13:02 [PATCH] Fix check for PDU size Lucas De Marchi
@ 2011-10-26 13:02 ` Lucas De Marchi
  2011-10-26 13:38   ` Luiz Augusto von Dentz
  2011-10-28  7:34 ` [PATCH] Fix check for PDU size Luiz Augusto von Dentz
  2011-10-28 11:01 ` Johan Hedberg
  2 siblings, 1 reply; 9+ messages in thread
From: Lucas De Marchi @ 2011-10-26 13:02 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi

---

I had this originally implemented using timeouts, setting them up once the
track started, the status or the position changed. It works, but IMO it's ugly
since it relies on having the track duration and we can't handle it properly
when we are in fast-forward/backward state. Thus I think it's better to rely on
user setting the position as we do for "track reached start" event.

 audio/avrcp.c     |    2 ++
 audio/avrcp.h     |    1 +
 audio/media.c     |   11 +++++++++++
 doc/media-api.txt |    6 +++++-
 4 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/audio/avrcp.c b/audio/avrcp.c
index 879e959..c9ec314 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -383,6 +383,7 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
 		memcpy(&pdu->params[1], data, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		size = 1;
 		break;
@@ -904,6 +905,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
 		memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		len = 1;
 		break;
diff --git a/audio/avrcp.h b/audio/avrcp.h
index c798658..fb64f3b 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -71,6 +71,7 @@
 /* Notification events */
 #define AVRCP_EVENT_STATUS_CHANGED	0x01
 #define AVRCP_EVENT_TRACK_CHANGED	0x02
+#define AVRCP_EVENT_TRACK_REACHED_END	0x03
 #define AVRCP_EVENT_TRACK_REACHED_START	0x04
 #define AVRCP_EVENT_LAST		AVRCP_EVENT_TRACK_REACHED_START
 
diff --git a/audio/media.c b/audio/media.c
index 5528ada..587544d 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1293,6 +1293,17 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
 	if (!mp->position) {
 		avrcp_player_event(mp->player,
 					AVRCP_EVENT_TRACK_REACHED_START, NULL);
+	} else {
+		struct metadata_value *value;
+
+		value = g_hash_table_lookup(mp->track, GUINT_TO_POINTER(
+					AVRCP_MEDIA_ATTRIBUTE_DURATION));
+
+		if ((value == NULL && mp->position == UINT32_MAX) ||
+				(value && value->value.num == mp->position)) {
+			avrcp_player_event(mp->player,
+					AVRCP_EVENT_TRACK_REACHED_END, NULL);
+		}
 	}
 
 	return TRUE;
diff --git a/doc/media-api.txt b/doc/media-api.txt
index c748e50..01eb11a 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -84,7 +84,11 @@ Methods		void RegisterEndpoint(object endpoint, dict properties)
 
 				uint32 Position
 
-					Playback position in milliseconds
+					Playback position in milliseconds.
+					"Track reached start" and "track
+					reached end" event will be sent once 0
+					or track's duration are set
+					respectively.
 
 			Metadata:
 
-- 
1.7.7.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-10-26 13:02 ` [PATCH] AVRCP: implement TRACK-REACHED-END event Lucas De Marchi
@ 2011-10-26 13:38   ` Luiz Augusto von Dentz
  2011-10-26 23:20     ` Lucas De Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2011-10-26 13:38 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth

Hi Lucas,

On Wed, Oct 26, 2011 at 4:02 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> ---
>
> I had this originally implemented using timeouts, setting them up once the
> track started, the status or the position changed. It works, but IMO it's ugly
> since it relies on having the track duration and we can't handle it properly
> when we are in fast-forward/backward state. Thus I think it's better to rely on
> user setting the position as we do for "track reached start" event.
>
>  audio/avrcp.c     |    2 ++
>  audio/avrcp.h     |    1 +
>  audio/media.c     |   11 +++++++++++
>  doc/media-api.txt |    6 +++++-
>  4 files changed, 19 insertions(+), 1 deletions(-)
>
> diff --git a/audio/avrcp.c b/audio/avrcp.c
> index 879e959..c9ec314 100644
> --- a/audio/avrcp.c
> +++ b/audio/avrcp.c
> @@ -383,6 +383,7 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
>                memcpy(&pdu->params[1], data, sizeof(uint64_t));
>
>                break;
> +       case AVRCP_EVENT_TRACK_REACHED_END:
>        case AVRCP_EVENT_TRACK_REACHED_START:
>                size = 1;
>                break;
> @@ -904,6 +905,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
>                memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
>
>                break;
> +       case AVRCP_EVENT_TRACK_REACHED_END:
>        case AVRCP_EVENT_TRACK_REACHED_START:
>                len = 1;
>                break;
> diff --git a/audio/avrcp.h b/audio/avrcp.h
> index c798658..fb64f3b 100644
> --- a/audio/avrcp.h
> +++ b/audio/avrcp.h
> @@ -71,6 +71,7 @@
>  /* Notification events */
>  #define AVRCP_EVENT_STATUS_CHANGED     0x01
>  #define AVRCP_EVENT_TRACK_CHANGED      0x02
> +#define AVRCP_EVENT_TRACK_REACHED_END  0x03
>  #define AVRCP_EVENT_TRACK_REACHED_START        0x04
>  #define AVRCP_EVENT_LAST               AVRCP_EVENT_TRACK_REACHED_START
>
> diff --git a/audio/media.c b/audio/media.c
> index 5528ada..587544d 100644
> --- a/audio/media.c
> +++ b/audio/media.c
> @@ -1293,6 +1293,17 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
>        if (!mp->position) {
>                avrcp_player_event(mp->player,
>                                        AVRCP_EVENT_TRACK_REACHED_START, NULL);
> +       } else {
> +               struct metadata_value *value;
> +
> +               value = g_hash_table_lookup(mp->track, GUINT_TO_POINTER(
> +                                       AVRCP_MEDIA_ATTRIBUTE_DURATION));
> +
> +               if ((value == NULL && mp->position == UINT32_MAX) ||
> +                               (value && value->value.num == mp->position)) {
> +                       avrcp_player_event(mp->player,
> +                                       AVRCP_EVENT_TRACK_REACHED_END, NULL);
> +               }

I would suggest you to check value/duration against NULL, 0 and
UINT32_MAX, in those cases we probably cannot say when the track has
ended because either duration is not supported or over 32 bits so you
should just bail out then after that you can check if position and
duration matches.

Also in this case I would name the variable duration instead of value
to better indicate what it represents.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-10-26 13:38   ` Luiz Augusto von Dentz
@ 2011-10-26 23:20     ` Lucas De Marchi
  2011-10-28  7:46       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 9+ messages in thread
From: Lucas De Marchi @ 2011-10-26 23:20 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi

---
 audio/avrcp.c     |    2 ++
 audio/avrcp.h     |    1 +
 audio/media.c     |   18 ++++++++++++++++++
 doc/media-api.txt |    6 +++++-
 4 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/audio/avrcp.c b/audio/avrcp.c
index 879e959..c9ec314 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -383,6 +383,7 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
 		memcpy(&pdu->params[1], data, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		size = 1;
 		break;
@@ -904,6 +905,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
 		memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		len = 1;
 		break;
diff --git a/audio/avrcp.h b/audio/avrcp.h
index c798658..fb64f3b 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -71,6 +71,7 @@
 /* Notification events */
 #define AVRCP_EVENT_STATUS_CHANGED	0x01
 #define AVRCP_EVENT_TRACK_CHANGED	0x02
+#define AVRCP_EVENT_TRACK_REACHED_END	0x03
 #define AVRCP_EVENT_TRACK_REACHED_START	0x04
 #define AVRCP_EVENT_LAST		AVRCP_EVENT_TRACK_REACHED_START
 
diff --git a/audio/media.c b/audio/media.c
index 5528ada..dd8ed6b 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1280,6 +1280,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
 static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
 {
 	uint32_t value;
+	struct metadata_value *duration;
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
 			return FALSE;
@@ -1293,6 +1294,23 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
 	if (!mp->position) {
 		avrcp_player_event(mp->player,
 					AVRCP_EVENT_TRACK_REACHED_START, NULL);
+		return TRUE;
+	}
+
+	duration = g_hash_table_lookup(mp->track, GUINT_TO_POINTER(
+					AVRCP_MEDIA_ATTRIBUTE_DURATION));
+
+	/*
+	 * If either there's no duration available in metadata and the user
+	 * set 'position' to the maximum value allowed or the position matches
+	 * the duration, send a track-reached-end event.
+	 */
+	if (duration == NULL && mp->position == UINT32_MAX) {
+		avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
+									NULL);
+	} else if (duration != NULL && mp->position == duration->value.num) {
+		avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
+									NULL);
 	}
 
 	return TRUE;
diff --git a/doc/media-api.txt b/doc/media-api.txt
index c748e50..01eb11a 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -84,7 +84,11 @@ Methods		void RegisterEndpoint(object endpoint, dict properties)
 
 				uint32 Position
 
-					Playback position in milliseconds
+					Playback position in milliseconds.
+					"Track reached start" and "track
+					reached end" event will be sent once 0
+					or track's duration are set
+					respectively.
 
 			Metadata:
 
-- 
1.7.7.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Fix check for PDU size
  2011-10-26 13:02 [PATCH] Fix check for PDU size Lucas De Marchi
  2011-10-26 13:02 ` [PATCH] AVRCP: implement TRACK-REACHED-END event Lucas De Marchi
@ 2011-10-28  7:34 ` Luiz Augusto von Dentz
  2011-10-28 11:01 ` Johan Hedberg
  2 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2011-10-28  7:34 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth

Hi Lucas,

On Wed, Oct 26, 2011 at 4:02 PM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> Company ID became part of the avrcp header so its size is already
> accounted in the AVRCP_HEADER_LENGTH define.
> ---
>  audio/avrcp.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/audio/avrcp.c b/audio/avrcp.c
> index f06afbf..879e959 100644
> --- a/audio/avrcp.c
> +++ b/audio/avrcp.c
> @@ -1053,7 +1053,7 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
>        pdu->packet_type = 0;
>        pdu->rsvd = 0;
>
> -       if (operand_count + 3 < AVRCP_HEADER_LENGTH) {
> +       if (operand_count < AVRCP_HEADER_LENGTH) {
>                pdu->params[0] = E_INVALID_COMMAND;
>                goto err_metadata;
>        }
> --
> 1.7.7.1
>
> --

Ack.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-10-26 23:20     ` Lucas De Marchi
@ 2011-10-28  7:46       ` Luiz Augusto von Dentz
  2011-11-03 16:28         ` Lucas De Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2011-10-28  7:46 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth

Hi Lucas,

On Thu, Oct 27, 2011 at 2:20 AM, Lucas De Marchi
<lucas.demarchi@profusion.mobi> wrote:
> ---
>  audio/avrcp.c     |    2 ++
>  audio/avrcp.h     |    1 +
>  audio/media.c     |   18 ++++++++++++++++++
>  doc/media-api.txt |    6 +++++-
>  4 files changed, 26 insertions(+), 1 deletions(-)
>
> diff --git a/audio/avrcp.c b/audio/avrcp.c
> index 879e959..c9ec314 100644
> --- a/audio/avrcp.c
> +++ b/audio/avrcp.c
> @@ -383,6 +383,7 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
>                memcpy(&pdu->params[1], data, sizeof(uint64_t));
>
>                break;
> +       case AVRCP_EVENT_TRACK_REACHED_END:
>        case AVRCP_EVENT_TRACK_REACHED_START:
>                size = 1;
>                break;
> @@ -904,6 +905,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
>                memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
>
>                break;
> +       case AVRCP_EVENT_TRACK_REACHED_END:
>        case AVRCP_EVENT_TRACK_REACHED_START:
>                len = 1;
>                break;
> diff --git a/audio/avrcp.h b/audio/avrcp.h
> index c798658..fb64f3b 100644
> --- a/audio/avrcp.h
> +++ b/audio/avrcp.h
> @@ -71,6 +71,7 @@
>  /* Notification events */
>  #define AVRCP_EVENT_STATUS_CHANGED     0x01
>  #define AVRCP_EVENT_TRACK_CHANGED      0x02
> +#define AVRCP_EVENT_TRACK_REACHED_END  0x03
>  #define AVRCP_EVENT_TRACK_REACHED_START        0x04
>  #define AVRCP_EVENT_LAST               AVRCP_EVENT_TRACK_REACHED_START
>
> diff --git a/audio/media.c b/audio/media.c
> index 5528ada..dd8ed6b 100644
> --- a/audio/media.c
> +++ b/audio/media.c
> @@ -1280,6 +1280,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
>  static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
>  {
>        uint32_t value;
> +       struct metadata_value *duration;
>
>        if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
>                        return FALSE;
> @@ -1293,6 +1294,23 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
>        if (!mp->position) {
>                avrcp_player_event(mp->player,
>                                        AVRCP_EVENT_TRACK_REACHED_START, NULL);
> +               return TRUE;
> +       }
> +
> +       duration = g_hash_table_lookup(mp->track, GUINT_TO_POINTER(
> +                                       AVRCP_MEDIA_ATTRIBUTE_DURATION));
> +
> +       /*
> +        * If either there's no duration available in metadata and the user
> +        * set 'position' to the maximum value allowed or the position matches
> +        * the duration, send a track-reached-end event.
> +        */
> +       if (duration == NULL && mp->position == UINT32_MAX) {
> +               avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
> +                                                                       NULL);

Does the duration really matter if the position is UINT32_MAX? I
thought the idea was that the player could for end of track by setting
it to maximum possible and IMO that should work regardless of the
duration being supported or not.

> +       } else if (duration != NULL && mp->position == duration->value.num) {
> +               avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
> +                                                                       NULL);
>        }
>
>        return TRUE;
> diff --git a/doc/media-api.txt b/doc/media-api.txt
> index c748e50..01eb11a 100644
> --- a/doc/media-api.txt
> +++ b/doc/media-api.txt
> @@ -84,7 +84,11 @@ Methods              void RegisterEndpoint(object endpoint, dict properties)
>
>                                uint32 Position
>
> -                                       Playback position in milliseconds
> +                                       Playback position in milliseconds.
> +                                       "Track reached start" and "track
> +                                       reached end" event will be sent once 0
> +                                       or track's duration are set
> +                                       respectively.

I would extend the documentation saying the UINT32_MAX can be used to
say the track has ended or something else went wrong and the position
is no longer valid.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Fix check for PDU size
  2011-10-26 13:02 [PATCH] Fix check for PDU size Lucas De Marchi
  2011-10-26 13:02 ` [PATCH] AVRCP: implement TRACK-REACHED-END event Lucas De Marchi
  2011-10-28  7:34 ` [PATCH] Fix check for PDU size Luiz Augusto von Dentz
@ 2011-10-28 11:01 ` Johan Hedberg
  2 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2011-10-28 11:01 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth

Hi Lucas,

On Wed, Oct 26, 2011, Lucas De Marchi wrote:
> Company ID became part of the avrcp header so its size is already
> accounted in the AVRCP_HEADER_LENGTH define.
> ---
>  audio/avrcp.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-10-28  7:46       ` Luiz Augusto von Dentz
@ 2011-11-03 16:28         ` Lucas De Marchi
  2011-11-04 13:39           ` Johan Hedberg
  0 siblings, 1 reply; 9+ messages in thread
From: Lucas De Marchi @ 2011-11-03 16:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Lucas De Marchi

---
 audio/avrcp.c     |    2 ++
 audio/avrcp.h     |    1 +
 audio/media.c     |   15 +++++++++++++++
 doc/media-api.txt |    9 ++++++++-
 4 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/audio/avrcp.c b/audio/avrcp.c
index 879e959..c9ec314 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -383,6 +383,7 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
 		memcpy(&pdu->params[1], data, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		size = 1;
 		break;
@@ -904,6 +905,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
 		memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
 
 		break;
+	case AVRCP_EVENT_TRACK_REACHED_END:
 	case AVRCP_EVENT_TRACK_REACHED_START:
 		len = 1;
 		break;
diff --git a/audio/avrcp.h b/audio/avrcp.h
index c798658..fb64f3b 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -71,6 +71,7 @@
 /* Notification events */
 #define AVRCP_EVENT_STATUS_CHANGED	0x01
 #define AVRCP_EVENT_TRACK_CHANGED	0x02
+#define AVRCP_EVENT_TRACK_REACHED_END	0x03
 #define AVRCP_EVENT_TRACK_REACHED_START	0x04
 #define AVRCP_EVENT_LAST		AVRCP_EVENT_TRACK_REACHED_START
 
diff --git a/audio/media.c b/audio/media.c
index cf157d7..9ee3be5 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1304,6 +1304,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
 static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
 {
 	uint32_t value;
+	struct metadata_value *duration;
 
 	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT32)
 			return FALSE;
@@ -1317,6 +1318,20 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
 	if (!mp->position) {
 		avrcp_player_event(mp->player,
 					AVRCP_EVENT_TRACK_REACHED_START, NULL);
+		return TRUE;
+	}
+
+	duration = g_hash_table_lookup(mp->track, GUINT_TO_POINTER(
+					AVRCP_MEDIA_ATTRIBUTE_DURATION));
+
+	/*
+	 * If position is the maximum value allowed or greater than track's
+	 * duration, we send a track-reached-end event.
+	 */
+	if (mp->position == UINT32_MAX ||
+			(duration && mp->position >= duration->value.num)) {
+		avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
+									NULL);
 	}
 
 	return TRUE;
diff --git a/doc/media-api.txt b/doc/media-api.txt
index 690f373..c53ab7b 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -213,7 +213,14 @@ Properties	string Equalizer [readwrite]
 
 		uint32 Position [readonly]
 
-			Playback position in milliseconds
+			Playback position in milliseconds. Changing the
+			position may generate additional events that will be
+			sent to the remote device. When position is 0 it means
+			the track is starting and when it's greater than or
+			equal to track's duration the track has ended. Note
+			that even if duration is not available in metadata it's
+			possible to signal its end by setting position to the
+			maximum uint32 value.
 
 MediaEndpoint hierarchy
 =======================
-- 
1.7.7.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] AVRCP: implement TRACK-REACHED-END event
  2011-11-03 16:28         ` Lucas De Marchi
@ 2011-11-04 13:39           ` Johan Hedberg
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2011-11-04 13:39 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-bluetooth, luiz.dentz

Hi Lucas,

On Thu, Nov 03, 2011, Lucas De Marchi wrote:
> ---
>  audio/avrcp.c     |    2 ++
>  audio/avrcp.h     |    1 +
>  audio/media.c     |   15 +++++++++++++++
>  doc/media-api.txt |    9 ++++++++-
>  4 files changed, 26 insertions(+), 1 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-11-04 13:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-26 13:02 [PATCH] Fix check for PDU size Lucas De Marchi
2011-10-26 13:02 ` [PATCH] AVRCP: implement TRACK-REACHED-END event Lucas De Marchi
2011-10-26 13:38   ` Luiz Augusto von Dentz
2011-10-26 23:20     ` Lucas De Marchi
2011-10-28  7:46       ` Luiz Augusto von Dentz
2011-11-03 16:28         ` Lucas De Marchi
2011-11-04 13:39           ` Johan Hedberg
2011-10-28  7:34 ` [PATCH] Fix check for PDU size Luiz Augusto von Dentz
2011-10-28 11:01 ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox