Diff between d0ae9987607d0b3cad0b37d5980360f68fa5d2a0 and 3adcd9ed77e1708cd6869e350d8d3727db92ce5c

Changed Files

File Additions Deletions Status
audio/avrcp.c +2 -0 modified
audio/avrcp.h +1 -0 modified
audio/media.c +14 -0 modified
doc/media-api.txt +8 -1 modified

Full Patch

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..e5373b8 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,8 +1318,21 @@ 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
 =======================