Lines Matching +full:track +full:- +full:count
4 * Copyright (c) 2019 - 2023 Nordic Semiconductor ASA
6 * SPDX-License-Identifier: Apache-2.0
51 /* The first track of the first group has track segments, other tracks not. */
53 /* Track segments */
132 .title = "Track 2.1",
140 .title = "Track 2.2",
148 .title = "Track 2.3",
159 .title = "Track 3.1",
167 .title = "Track 3.2",
175 .title = "Track 3.3",
185 .title = "Track 4.1",
193 .title = "Track 4.2",
207 .title = "Joe Pass - Guitar Interludes",
208 .track = &track_1_1,
216 .track = &track_2_2,
224 .track = &track_3_3,
232 .track = &track_4_2,
240 .track = &track_4_1,
303 /* Pointer to track being added */
333 /* Size may be larger than what fits in 8 bits, use 16-bit for index */ in setup_icon_object()
341 return obj.content->len; in setup_icon_object()
344 /* Set up content buffer for a track segments object */
345 static uint32_t setup_segments_object(struct mpl_track *track) in setup_segments_object() argument
347 struct mpl_tseg *seg = track->segment; in setup_segments_object()
354 while (seg->prev) { in setup_segments_object()
355 seg = seg->prev; in setup_segments_object()
358 uint32_t seg_size = sizeof(seg->name_len); in setup_segments_object()
360 seg_size += seg->name_len; in setup_segments_object()
361 seg_size += sizeof(seg->pos); in setup_segments_object()
362 if (tot_size + seg_size > obj.content->size) { in setup_segments_object()
366 net_buf_simple_add_u8(obj.content, seg->name_len); in setup_segments_object()
367 net_buf_simple_add_mem(obj.content, seg->name, in setup_segments_object()
368 seg->name_len); in setup_segments_object()
369 net_buf_simple_add_le32(obj.content, seg->pos); in setup_segments_object()
372 seg = seg->next; in setup_segments_object()
375 LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Segments Object"); in setup_segments_object()
376 LOG_DBG("Segments object length: %d", obj.content->len); in setup_segments_object()
381 return obj.content->len; in setup_segments_object()
384 /* Set up content buffer for a track object */
385 static uint32_t setup_track_object(struct mpl_track *track) in setup_track_object() argument
390 /* The track object is supposed to be in Id3v2 format */ in setup_track_object()
395 /* Size may be larger than what fits in 8 bits, use 16-bit for index */ in setup_track_object()
403 return obj.content->len; in setup_track_object()
413 /* The track groups have a pointer to the parent, but there is no */ in setup_parent_group_object()
424 while (group->prev) { in setup_parent_group_object()
425 group = group->prev; in setup_parent_group_object()
428 while (group && (next_size <= obj.content->size)) { in setup_parent_group_object()
430 net_buf_simple_add_le48(obj.content, group->id); in setup_parent_group_object()
431 group = group->next; in setup_parent_group_object()
434 if (next_size > obj.content->size) { in setup_parent_group_object()
437 LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Parent Group Object"); in setup_parent_group_object()
438 LOG_DBG("Group object length: %d", obj.content->len); in setup_parent_group_object()
440 return obj.content->len; in setup_parent_group_object()
448 struct mpl_track *track = group->track; in setup_group_object() local
455 if (track) { in setup_group_object()
456 while (track->prev) { in setup_group_object()
457 track = track->prev; in setup_group_object()
459 /* While there is a track, and the record fits in the object */ in setup_group_object()
460 while (track && (next_size <= obj.content->size)) { in setup_group_object()
462 net_buf_simple_add_le48(obj.content, track->id); in setup_group_object()
463 track = track->next; in setup_group_object()
466 if (next_size > obj.content->size) { in setup_group_object()
469 LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Group Object"); in setup_group_object()
470 LOG_DBG("Group object length: %d", obj.content->len); in setup_group_object()
472 return obj.content->len; in setup_group_object()
487 obj.desc->size.alloc = obj.desc->size.cur = setup_icon_object(); in add_icon_object()
488 obj.desc->name = icon_name; in add_icon_object()
489 BT_OTS_OBJ_SET_PROP_READ(obj.desc->props); in add_icon_object()
491 add_param.size = obj.desc->size.alloc; in add_icon_object()
493 add_param.type.uuid_16.val = BT_UUID_16(icon_type)->val; in add_icon_object()
505 /* Add a track segments object to the OTS */
516 obj.desc->size.alloc = obj.desc->size.cur = setup_segments_object(pl->group->track); in add_current_track_segments_object()
517 obj.desc->name = pl->group->track->title; in add_current_track_segments_object()
518 BT_OTS_OBJ_SET_PROP_READ(obj.desc->props); in add_current_track_segments_object()
520 add_param.size = obj.desc->size.alloc; in add_current_track_segments_object()
522 add_param.type.uuid_16.val = BT_UUID_16(segs_type)->val; in add_current_track_segments_object()
526 LOG_WRN("Unable to add track segments object: %d", ret); in add_current_track_segments_object()
534 /* Add a single track to the OTS */
535 static int add_track_object(struct mpl_track *track) in add_track_object() argument
542 if (!track) { in add_track_object()
543 LOG_ERR("No track"); in add_track_object()
544 return -EINVAL; in add_track_object()
548 obj.add_track = track; in add_track_object()
551 obj.desc->size.alloc = obj.desc->size.cur = setup_track_object(track); in add_track_object()
552 obj.desc->name = track->title; in add_track_object()
553 BT_OTS_OBJ_SET_PROP_READ(obj.desc->props); in add_track_object()
555 add_param.size = obj.desc->size.alloc; in add_track_object()
557 add_param.type.uuid_16.val = BT_UUID_16(track_type)->val; in add_track_object()
561 LOG_WRN("Unable to add track object: %d", ret); in add_track_object()
580 obj.desc->size.alloc = obj.desc->size.cur = setup_parent_group_object(pl->group); in add_parent_group_object()
581 obj.desc->name = pl->group->parent->title; in add_parent_group_object()
582 BT_OTS_OBJ_SET_PROP_READ(obj.desc->props); in add_parent_group_object()
584 add_param.size = obj.desc->size.alloc; in add_parent_group_object()
586 add_param.type.uuid_16.val = BT_UUID_16(group_type)->val; in add_parent_group_object()
608 return -EINVAL; in add_group_object()
615 obj.desc->size.alloc = obj.desc->size.cur = setup_group_object(group); in add_group_object()
616 obj.desc->name = group->title; in add_group_object()
617 BT_OTS_OBJ_SET_PROP_READ(obj.desc->props); in add_group_object()
619 add_param.size = obj.desc->size.alloc; in add_group_object()
621 add_param.type.uuid_16.val = BT_UUID_16(group_type)->val; in add_group_object()
637 struct mpl_track *track = group->track; in add_group_tracks() local
639 if (track) { in add_group_tracks()
640 while (track->prev) { in add_group_tracks()
641 track = track->prev; in add_group_tracks()
644 while (track) { in add_group_tracks()
645 int ret = add_track_object(track); in add_group_tracks()
650 track = track->next; in add_group_tracks()
661 struct mpl_group *group = pl->group; in add_group_and_track_objects()
664 while (group->prev) { in add_group_and_track_objects()
665 group = group->prev; in add_group_and_track_objects()
678 group = group->next; in add_group_and_track_objects()
706 LOG_ERR("Object busy - select not performed"); in on_obj_selected()
715 } else if (id == media_player.group->track->segments_id) { in on_obj_selected()
716 LOG_DBG("Current Track Segments Object ID"); in on_obj_selected()
717 (void)setup_segments_object(media_player.group->track); in on_obj_selected()
718 } else if (id == media_player.group->track->id) { in on_obj_selected()
719 LOG_DBG("Current Track Object ID"); in on_obj_selected()
720 (void)setup_track_object(media_player.group->track); in on_obj_selected()
721 } else if (media_player.next_track_set && id == media_player.next.track->id) { in on_obj_selected()
722 /* Next track, if the next track has been explicitly set */ in on_obj_selected()
723 LOG_DBG("Next Track Object ID"); in on_obj_selected()
724 (void)setup_track_object(media_player.next.track); in on_obj_selected()
725 } else if (id == media_player.group->track->next->id) { in on_obj_selected()
726 /* Next track, if next track has not been explicitly set */ in on_obj_selected()
727 LOG_DBG("Next Track Object ID"); in on_obj_selected()
728 (void)setup_track_object(media_player.group->track->next); in on_obj_selected()
729 } else if (id == media_player.group->parent->id) { in on_obj_selected()
732 } else if (id == media_player.group->id) { in on_obj_selected()
755 if (!bt_uuid_cmp(&add_param->type.uuid, BT_UUID_OTS_TYPE_MPL_ICON)) { in on_obj_created()
764 } else if (!bt_uuid_cmp(&add_param->type.uuid, in on_obj_created()
766 LOG_DBG("Track Segments Obj Type"); in on_obj_created()
769 media_player.group->track->segments_id = id; in on_obj_created()
774 } else if (!bt_uuid_cmp(&add_param->type.uuid, in on_obj_created()
776 LOG_DBG("Track Obj Type"); in on_obj_created()
779 obj.add_track->id = id; in on_obj_created()
785 } else if (!bt_uuid_cmp(&add_param->type.uuid, in on_obj_created()
791 media_player.group->parent->id = id; in on_obj_created()
795 obj.add_group->id = id; in on_obj_created()
816 return -EBUSY; in on_object_send()
828 return -EINVAL; in on_object_send()
837 if (offset >= obj.content->len) { in on_object_send()
840 return -EINVAL; in on_object_send()
844 if (len > obj.content->len - offset) { in on_object_send()
849 *data = &obj.content->data[offset]; in on_object_send()
852 return MIN(len, obj.content->len - offset); in on_object_send()
871 LOG_DBG("Segment name before: %s", pl->group->track->segment->name); in do_prev_segment()
873 if (pl->group->track->segment->prev != NULL) { in do_prev_segment()
874 pl->group->track->segment = pl->group->track->segment->prev; in do_prev_segment()
877 LOG_DBG("Segment name after: %s", pl->group->track->segment->name); in do_prev_segment()
882 LOG_DBG("Segment name before: %s", pl->group->track->segment->name); in do_next_segment()
884 if (pl->group->track->segment->next != NULL) { in do_next_segment()
885 pl->group->track->segment = pl->group->track->segment->next; in do_next_segment()
888 LOG_DBG("Segment name after: %s", pl->group->track->segment->name); in do_next_segment()
893 LOG_DBG("Segment name before: %s", pl->group->track->segment->name); in do_first_segment()
895 while (pl->group->track->segment->prev != NULL) { in do_first_segment()
896 pl->group->track->segment = pl->group->track->segment->prev; in do_first_segment()
899 LOG_DBG("Segment name after: %s", pl->group->track->segment->name); in do_first_segment()
904 LOG_DBG("Segment name before: %s", pl->group->track->segment->name); in do_last_segment()
906 while (pl->group->track->segment->next != NULL) { in do_last_segment()
907 pl->group->track->segment = pl->group->track->segment->next; in do_last_segment()
910 LOG_DBG("Segment name after: %s", pl->group->track->segment->name); in do_last_segment()
917 LOG_DBG("Segment name before: %s", pl->group->track->segment->name); in do_goto_segment()
921 while (pl->group->track->segment->prev != NULL) { in do_goto_segment()
922 pl->group->track->segment = in do_goto_segment()
923 pl->group->track->segment->prev; in do_goto_segment()
926 /* Then go segnum - 1 tracks forward */ in do_goto_segment()
927 for (k = 0; k < (segnum - 1); k++) { in do_goto_segment()
928 if (pl->group->track->segment->next != NULL) { in do_goto_segment()
929 pl->group->track->segment = in do_goto_segment()
930 pl->group->track->segment->next; in do_goto_segment()
934 /* Goto last track */ in do_goto_segment()
935 while (pl->group->track->segment->next != NULL) { in do_goto_segment()
936 pl->group->track->segment = in do_goto_segment()
937 pl->group->track->segment->next; in do_goto_segment()
940 /* Then go |segnum - 1| tracks back */ in do_goto_segment()
941 for (k = 0; k < (-segnum - 1); k++) { in do_goto_segment()
942 if (pl->group->track->segment->prev != NULL) { in do_goto_segment()
943 pl->group->track->segment = in do_goto_segment()
944 pl->group->track->segment->prev; in do_goto_segment()
949 LOG_DBG("Segment name after: %s", pl->group->track->segment->name); in do_goto_segment()
951 set_track_position(pl->group->track->segment->pos); in do_goto_segment()
957 LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); in do_prev_track()
960 if (pl->group->track->prev != NULL) { in do_prev_track()
961 pl->group->track = pl->group->track->prev; in do_prev_track()
962 pl->track_pos = 0; in do_prev_track()
965 /* For previous track, the position is reset to 0 */ in do_prev_track()
966 /* even if we stay at the same track (goto start of */ in do_prev_track()
967 /* track) */ in do_prev_track()
972 LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); in do_prev_track()
976 /* Change to next track according to the current track's next track */
980 LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); in do_next_track_normal_order()
983 if (pl->group->track->next != NULL) { in do_next_track_normal_order()
984 pl->group->track = pl->group->track->next; in do_next_track_normal_order()
985 pl->track_pos = 0; in do_next_track_normal_order()
990 LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); in do_next_track_normal_order()
994 /* Change to next track when the next track has been explicitly set
996 * ALWAYS changes the track, changes the group if required
1003 if (pl->next.group != pl->group) { in do_next_track_next_track_set()
1004 pl->group = pl->next.group; in do_next_track_next_track_set()
1008 pl->group->track = pl->next.track; in do_next_track_next_track_set()
1010 pl->next.track = NULL; in do_next_track_next_track_set()
1011 pl->next.group = NULL; in do_next_track_next_track_set()
1012 pl->next_track_set = false; in do_next_track_next_track_set()
1013 pl->track_pos = 0; in do_next_track_next_track_set()
1019 if (pl->next_track_set) { in do_next_track()
1020 LOG_DBG("Next track set"); in do_next_track()
1032 LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); in do_first_track()
1035 /* Set first track */ in do_first_track()
1036 while (pl->group->track->prev != NULL) { in do_first_track()
1037 pl->group->track = pl->group->track->prev; in do_first_track()
1041 /* Notify about new track */ in do_first_track()
1046 /* For first track, the position is reset to 0 even */ in do_first_track()
1047 /* if we stay at the same track (goto start of track) */ in do_first_track()
1052 LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); in do_first_track()
1059 LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); in do_last_track()
1062 if (pl->group->track->next != NULL) { in do_last_track()
1063 pl->group->track = pl->group->track->next; in do_last_track()
1068 /* For last track, the position is reset to 0 even */ in do_last_track()
1069 /* if we stay at the same track (goto start of track) */ in do_last_track()
1073 while (pl->group->track->next != NULL) { in do_last_track()
1074 pl->group->track = pl->group->track->next; in do_last_track()
1078 LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); in do_last_track()
1084 int32_t count = 0; in do_goto_track() local
1088 LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); in do_goto_track()
1092 /* Goto first track */ in do_goto_track()
1093 while (pl->group->track->prev != NULL) { in do_goto_track()
1094 pl->group->track = pl->group->track->prev; in do_goto_track()
1095 count--; in do_goto_track()
1098 /* Then go tracknum - 1 tracks forward */ in do_goto_track()
1099 for (k = 0; k < (tracknum - 1); k++) { in do_goto_track()
1100 if (pl->group->track->next != NULL) { in do_goto_track()
1101 pl->group->track = pl->group->track->next; in do_goto_track()
1102 count++; in do_goto_track()
1106 /* Goto last track */ in do_goto_track()
1107 while (pl->group->track->next != NULL) { in do_goto_track()
1108 pl->group->track = pl->group->track->next; in do_goto_track()
1109 count++; in do_goto_track()
1112 /* Then go |tracknum - 1| tracks back */ in do_goto_track()
1113 for (k = 0; k < (-tracknum - 1); k++) { in do_goto_track()
1114 if (pl->group->track->prev != NULL) { in do_goto_track()
1115 pl->group->track = pl->group->track->prev; in do_goto_track()
1116 count--; in do_goto_track()
1122 LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); in do_goto_track()
1125 /* The track has changed if we have moved more in one direction */ in do_goto_track()
1127 if (count != 0) { in do_goto_track()
1131 /* For goto track, the position is reset to 0 */ in do_goto_track()
1132 /* even if we stay at the same track (goto */ in do_goto_track()
1133 /* start of track) */ in do_goto_track()
1141 LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id); in do_prev_group()
1144 if (pl->group->prev != NULL) { in do_prev_group()
1145 pl->group = pl->group->prev; in do_prev_group()
1150 LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id); in do_prev_group()
1158 LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id); in do_next_group()
1161 if (pl->group->next != NULL) { in do_next_group()
1162 pl->group = pl->group->next; in do_next_group()
1167 LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id); in do_next_group()
1174 LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id); in do_first_group()
1177 if (pl->group->prev != NULL) { in do_first_group()
1178 pl->group = pl->group->prev; in do_first_group()
1182 while (pl->group->prev != NULL) { in do_first_group()
1183 pl->group = pl->group->prev; in do_first_group()
1187 LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id); in do_first_group()
1194 LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id); in do_last_group()
1197 if (pl->group->next != NULL) { in do_last_group()
1198 pl->group = pl->group->next; in do_last_group()
1202 while (pl->group->next != NULL) { in do_last_group()
1203 pl->group = pl->group->next; in do_last_group()
1207 LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id); in do_last_group()
1213 int32_t count = 0; in do_goto_group() local
1217 LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id); in do_goto_group()
1222 while (pl->group->prev != NULL) { in do_goto_group()
1223 pl->group = pl->group->prev; in do_goto_group()
1224 count--; in do_goto_group()
1227 /* Then go groupnum - 1 groups forward */ in do_goto_group()
1228 for (k = 0; k < (groupnum - 1); k++) { in do_goto_group()
1229 if (pl->group->next != NULL) { in do_goto_group()
1230 pl->group = pl->group->next; in do_goto_group()
1231 count++; in do_goto_group()
1236 while (pl->group->next != NULL) { in do_goto_group()
1237 pl->group = pl->group->next; in do_goto_group()
1238 count++; in do_goto_group()
1241 /* Then go |groupnum - 1| groups back */ in do_goto_group()
1242 for (k = 0; k < (-groupnum - 1); k++) { in do_goto_group()
1243 if (pl->group->prev != NULL) { in do_goto_group()
1244 pl->group = pl->group->prev; in do_goto_group()
1245 count--; in do_goto_group()
1251 LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id); in do_goto_group()
1256 if (count != 0) { in do_goto_group()
1264 media_proxy_pl_track_title_cb(pl->group->track->title); in do_track_change_notifications()
1265 media_proxy_pl_track_duration_cb(pl->group->track->duration); in do_track_change_notifications()
1266 media_proxy_pl_track_position_cb(pl->track_pos); in do_track_change_notifications()
1268 media_proxy_pl_current_track_id_cb(pl->group->track->id); in do_track_change_notifications()
1269 if (pl->group->track->next) { in do_track_change_notifications()
1270 media_proxy_pl_next_track_id_cb(pl->group->track->next->id); in do_track_change_notifications()
1272 /* Send a zero value to indicate that there is no next track */ in do_track_change_notifications()
1281 media_proxy_pl_current_group_id_cb(pl->group->id); in do_group_change_notifications()
1290 /* Whether there is a group change or not, we always go to the first track */ in do_full_prev_group()
1299 /* Whether there is a group change or not, we always go to the first track */ in do_full_next_group()
1308 /* Whether there is a group change or not, we always go to the first track */ in do_full_first_group()
1317 /* Whether there is a group change or not, we always go to the first track */ in do_full_last_group()
1326 /* Whether there is a group change or not, we always go to the first track */ in do_full_goto_group()
1354 LOG_DBG("Command opcode: %d", command->opcode); in inactive_state_command_handler()
1356 if (command->use_param) { in inactive_state_command_handler()
1357 LOG_DBG("Command parameter: %d", command->param); in inactive_state_command_handler()
1360 switch (command->opcode) { in inactive_state_command_handler()
1361 case MEDIA_PROXY_OP_PLAY: /* Fall-through - handle several cases identically */ in inactive_state_command_handler()
1380 * The case where the next track has been set explicitly breaks somewhat in inactive_state_command_handler()
1381 * with the "next" order hardcoded into the group and track structure in inactive_state_command_handler()
1385 /* For next track, the position is kept if the track */ in inactive_state_command_handler()
1398 if (command->use_param) { in inactive_state_command_handler()
1399 do_goto_track(&media_player, command->param); in inactive_state_command_handler()
1422 if (command->use_param) { in inactive_state_command_handler()
1423 do_full_goto_group(&media_player, command->param); in inactive_state_command_handler()
1431 LOG_DBG("Invalid command: %d", command->opcode); in inactive_state_command_handler()
1443 LOG_DBG("Command opcode: %d", command->opcode); in playing_state_command_handler()
1445 if (command->use_param) { in playing_state_command_handler()
1446 LOG_DBG("Command parameter: %d", command->param); in playing_state_command_handler()
1450 switch (command->opcode) { in playing_state_command_handler()
1452 /* Continue playing - i.e. do nothing */ in playing_state_command_handler()
1459 media_player.seeking_speed_factor = -MPL_SEEKING_SPEED_FACTOR_STEP; in playing_state_command_handler()
1474 if (command->use_param) { in playing_state_command_handler()
1475 set_relative_track_position(command->param); in playing_state_command_handler()
1484 if (media_player.track_pos - PREV_MARGIN < in playing_state_command_handler()
1485 media_player.group->track->segment->pos) { in playing_state_command_handler()
1488 set_track_position(media_player.group->track->segment->pos); in playing_state_command_handler()
1492 set_track_position(media_player.group->track->segment->pos); in playing_state_command_handler()
1496 set_track_position(media_player.group->track->segment->pos); in playing_state_command_handler()
1500 set_track_position(media_player.group->track->segment->pos); in playing_state_command_handler()
1503 if (command->use_param) { in playing_state_command_handler()
1504 if (command->param != 0) { in playing_state_command_handler()
1505 do_goto_segment(&media_player, command->param); in playing_state_command_handler()
1509 /* track position shall not change. */ in playing_state_command_handler()
1528 if (command->use_param) { in playing_state_command_handler()
1529 do_goto_track(&media_player, command->param); in playing_state_command_handler()
1548 if (command->use_param) { in playing_state_command_handler()
1549 do_full_goto_group(&media_player, command->param); in playing_state_command_handler()
1555 LOG_DBG("Invalid command: %d", command->opcode); in playing_state_command_handler()
1567 LOG_DBG("Command opcode: %d", command->opcode); in paused_state_command_handler()
1569 if (command->use_param) { in paused_state_command_handler()
1570 LOG_DBG("Command parameter: %d", command->param); in paused_state_command_handler()
1574 switch (command->opcode) { in paused_state_command_handler()
1583 media_player.seeking_speed_factor = -MPL_SEEKING_SPEED_FACTOR_STEP; in paused_state_command_handler()
1598 if (command->use_param) { in paused_state_command_handler()
1599 set_relative_track_position(command->param); in paused_state_command_handler()
1608 if (media_player.group->track->segment != NULL) { in paused_state_command_handler()
1609 if (media_player.track_pos - PREV_MARGIN < in paused_state_command_handler()
1610 media_player.group->track->segment->pos) { in paused_state_command_handler()
1614 set_track_position(media_player.group->track->segment->pos); in paused_state_command_handler()
1621 if (media_player.group->track->segment != NULL) { in paused_state_command_handler()
1623 set_track_position(media_player.group->track->segment->pos); in paused_state_command_handler()
1630 if (media_player.group->track->segment != NULL) { in paused_state_command_handler()
1632 set_track_position(media_player.group->track->segment->pos); in paused_state_command_handler()
1639 if (media_player.group->track->segment != NULL) { in paused_state_command_handler()
1641 set_track_position(media_player.group->track->segment->pos); in paused_state_command_handler()
1648 if (command->use_param && media_player.group->track->segment != NULL) { in paused_state_command_handler()
1649 if (command->param != 0) { in paused_state_command_handler()
1650 do_goto_segment(&media_player, command->param); in paused_state_command_handler()
1654 /* track position shall not change. */ in paused_state_command_handler()
1665 /* For next track, the position is kept if the track */ in paused_state_command_handler()
1675 if (command->use_param) { in paused_state_command_handler()
1676 do_goto_track(&media_player, command->param); in paused_state_command_handler()
1695 if (command->use_param) { in paused_state_command_handler()
1696 do_full_goto_group(&media_player, command->param); in paused_state_command_handler()
1703 LOG_DBG("Invalid command: %d", command->opcode); in paused_state_command_handler()
1715 LOG_DBG("Command opcode: %d", command->opcode); in seeking_state_command_handler()
1717 if (command->use_param) { in seeking_state_command_handler()
1718 LOG_DBG("Command parameter: %d", command->param); in seeking_state_command_handler()
1722 switch (command->opcode) { in seeking_state_command_handler()
1730 /* TODO: Set track and track position */ in seeking_state_command_handler()
1736 /* Decide on algorithm for multiple presses - add step (as */ in seeking_state_command_handler()
1740 /* Lowest value allowed by spec is -64, notify on change only */ in seeking_state_command_handler()
1741 if (media_player.seeking_speed_factor >= -(MEDIA_PROXY_SEEKING_SPEED_FACTOR_MAX in seeking_state_command_handler()
1742 - MPL_SEEKING_SPEED_FACTOR_STEP)) { in seeking_state_command_handler()
1743 media_player.seeking_speed_factor -= MPL_SEEKING_SPEED_FACTOR_STEP; in seeking_state_command_handler()
1750 - MPL_SEEKING_SPEED_FACTOR_STEP)) { in seeking_state_command_handler()
1762 if (command->use_param) { in seeking_state_command_handler()
1763 set_relative_track_position(command->param); in seeking_state_command_handler()
1772 if (media_player.track_pos - PREV_MARGIN < in seeking_state_command_handler()
1773 media_player.group->track->segment->pos) { in seeking_state_command_handler()
1776 set_track_position(media_player.group->track->segment->pos); in seeking_state_command_handler()
1780 set_track_position(media_player.group->track->segment->pos); in seeking_state_command_handler()
1784 set_track_position(media_player.group->track->segment->pos); in seeking_state_command_handler()
1788 set_track_position(media_player.group->track->segment->pos); in seeking_state_command_handler()
1791 if (command->use_param) { in seeking_state_command_handler()
1792 if (command->param != 0) { in seeking_state_command_handler()
1793 do_goto_segment(&media_player, command->param); in seeking_state_command_handler()
1797 /* track position shall not change. */ in seeking_state_command_handler()
1809 /* For next track, the position is kept if the track */ in seeking_state_command_handler()
1825 if (command->use_param) { in seeking_state_command_handler()
1826 do_goto_track(&media_player, command->param); in seeking_state_command_handler()
1850 if (command->use_param) { in seeking_state_command_handler()
1851 do_full_goto_group(&media_player, command->param); in seeking_state_command_handler()
1858 LOG_DBG("Invalid command: %d", command->opcode); in seeking_state_command_handler()
1874 /* Find a track by ID
1876 * If found, return pointers to the group of the track and the track,
1882 struct mpl_group **group, struct mpl_track **track) in find_track_by_id() argument
1884 struct mpl_group *tmp_group = pl->group; in find_track_by_id()
1887 while (tmp_group->prev != NULL) { in find_track_by_id()
1888 tmp_group = tmp_group->prev; in find_track_by_id()
1892 tmp_track = tmp_group->track; in find_track_by_id()
1894 while (tmp_track->prev != NULL) { in find_track_by_id()
1895 tmp_track = tmp_track->prev; in find_track_by_id()
1899 if (tmp_track->id == id) { in find_track_by_id()
1900 /* Found the track */ in find_track_by_id()
1902 *track = tmp_track; in find_track_by_id()
1906 tmp_track = tmp_track->next; in find_track_by_id()
1909 tmp_group = tmp_group->next; in find_track_by_id()
1912 /* Track not found */ in find_track_by_id()
1914 *track = NULL; in find_track_by_id()
1927 struct mpl_group *tmp_group = pl->group; in find_group_by_id()
1929 while (tmp_group->prev != NULL) { in find_group_by_id()
1930 tmp_group = tmp_group->prev; in find_group_by_id()
1934 if (tmp_group->id == id) { in find_group_by_id()
1940 tmp_group = tmp_group->next; in find_group_by_id()
1968 return media_player.group->track->title; in get_track_title()
1973 return media_player.group->track->duration; in get_track_duration()
1987 if (position > media_player.group->track->duration) { in set_track_position()
1988 /* Do not go beyond end of track */ in set_track_position()
1989 new_pos = media_player.group->track->duration; in set_track_position()
1994 /* Negative position, handle as offset from _end_ of track */ in set_track_position()
1996 if (position < -media_player.group->track->duration) { in set_track_position()
2000 new_pos = media_player.group->track->duration + position; in set_track_position()
2005 media_player.group->track->duration); in set_track_position()
2008 * to 0 which is a special value that typically indicates that the track has stopped or in set_track_position()
2009 * changed. Since this might occur when media_player.group->track->duration is still 0, we in set_track_position()
2017 * to avoid an excessive number of notifications, the Track Position should in set_track_position()
2033 pos = CLAMP(pos, 0, media_player.group->track->duration); in set_relative_track_position()
2060 return media_player.group->track->segments_id; in get_track_segments_id()
2065 return media_player.group->track->id; in get_current_track_id()
2071 struct mpl_track *track; in set_current_track_id() local
2073 LOG_DBG_OBJ_ID("Track ID to set: ", id); in set_current_track_id()
2075 if (find_track_by_id(&media_player, id, &group, &track)) { in set_current_track_id()
2080 /* Group change implies track change (even if same track in other group) */ in set_current_track_id()
2081 media_player.group->track = track; in set_current_track_id()
2084 } else if (media_player.group->track != track) { in set_current_track_id()
2085 media_player.group->track = track; in set_current_track_id()
2091 LOG_DBG("Track not found"); in set_current_track_id()
2100 /* If the next track has been set explicitly */ in get_next_track_id()
2102 return media_player.next.track->id; in get_next_track_id()
2106 if (media_player.group->track->next) { in get_next_track_id()
2107 return media_player.group->track->next->id; in get_next_track_id()
2110 /* Return zero value to indicate that there is no next track */ in get_next_track_id()
2117 struct mpl_track *track; in set_next_track_id() local
2119 LOG_DBG_OBJ_ID("Next Track ID to set: ", id); in set_next_track_id()
2121 if (find_track_by_id(&media_player, id, &group, &track)) { in set_next_track_id()
2125 media_player.next.track = track; in set_next_track_id()
2130 LOG_DBG("Track not found"); in set_next_track_id()
2135 return media_player.group->parent->id; in get_parent_group_id()
2140 return media_player.group->id; in get_current_group_id()
2156 /* And change to first track in group */ in set_current_group_id()
2174 if (BIT(order - 1) & media_player.playing_orders_supported) { in set_playing_order()
2195 if (command->use_param) { in send_command()
2196 LOG_DBG("opcode: %d, param: %d", command->opcode, command->param); in send_command()
2198 LOG_DBG("opcode: %d", command->opcode); in send_command()
2202 ntf.requested_opcode = command->opcode; in send_command()
2220 LOG_DBG("type: %u len %u", data->type, data->data_len); in parse_sci()
2221 LOG_HEXDUMP_DBG(data->data, data->data_len, "param:"); in parse_sci()
2223 if (data->type < MEDIA_PROXY_SEARCH_TYPE_TRACK_NAME || in parse_sci()
2224 data->type > MEDIA_PROXY_SEARCH_TYPE_ONLY_GROUPS) { in parse_sci()
2225 LOG_DBG("Invalid search type: %u", data->type); in parse_sci()
2236 if (search->len > SEARCH_LEN_MAX) { in parse_search()
2237 LOG_WRN("Search too long (%d) - aborting", search->len); in parse_search()
2244 memcpy(search_ltv, search->search, search->len); in parse_search()
2246 net_buf_simple_init_with_data(&buf, search_ltv, search->len); in parse_search()
2263 media_player.search_results_id = media_player.group->id; in parse_search()
2272 if (search->len > SEARCH_LEN_MAX) { in send_search()
2273 LOG_WRN("Search too long: %d", search->len); in send_search()
2276 LOG_HEXDUMP_DBG(search->search, search->len, "Search"); in send_search()
2303 if (media_player.track_pos == media_player.group->track->duration) { in pos_work_cb()
2304 /* Go to next track */ in pos_work_cb()
2318 return -EALREADY; in media_proxy_pl_init()
2330 /* TODO: Fix initialization - who initializes what in media_proxy_pl_init()
2331 * https://github.com/zephyrproject-rtos/zephyr/issues/42965 in media_proxy_pl_init()
2341 return -EBUSY; in media_proxy_pl_init()
2383 /* Initial setup of Track Segments Object */ in media_proxy_pl_init()
2388 LOG_ERR("Error adding Track Segments Object to OTS, error %d", ret); in media_proxy_pl_init()
2450 struct mpl_track *track; in mpl_debug_dump_state() local
2461 LOG_DBG("Track position: %d", media_player.track_pos); in mpl_debug_dump_state()
2471 (void)bt_ots_obj_id_to_str(media_player.group->parent->id, t, sizeof(t)); in mpl_debug_dump_state()
2474 (void)bt_ots_obj_id_to_str(media_player.group->id, t, sizeof(t)); in mpl_debug_dump_state()
2477 (void)bt_ots_obj_id_to_str(media_player.group->track->id, t, sizeof(t)); in mpl_debug_dump_state()
2478 LOG_DBG("Current track: %s", t); in mpl_debug_dump_state()
2481 (void)bt_ots_obj_id_to_str(media_player.next.track->id, t, sizeof(t)); in mpl_debug_dump_state()
2482 LOG_DBG("Next track: %s", t); in mpl_debug_dump_state()
2483 } else if (media_player.group->track->next) { in mpl_debug_dump_state()
2484 (void)bt_ots_obj_id_to_str(media_player.group->track->next->id, t, in mpl_debug_dump_state()
2486 LOG_DBG("Next track: %s", t); in mpl_debug_dump_state()
2488 LOG_DBG("No next track"); in mpl_debug_dump_state()
2501 while (group->prev != NULL) { in mpl_debug_dump_state()
2502 group = group->prev; in mpl_debug_dump_state()
2506 (void)bt_ots_obj_id_to_str(group->id, t, sizeof(t)); in mpl_debug_dump_state()
2507 LOG_DBG("Group: %s, %s", t, group->title); in mpl_debug_dump_state()
2509 (void)bt_ots_obj_id_to_str(group->parent->id, t, sizeof(t)); in mpl_debug_dump_state()
2510 LOG_DBG("\tParent: %s, %s", t, group->parent->title); in mpl_debug_dump_state()
2512 track = group->track; in mpl_debug_dump_state()
2513 while (track->prev != NULL) { in mpl_debug_dump_state()
2514 track = track->prev; in mpl_debug_dump_state()
2517 while (track) { in mpl_debug_dump_state()
2518 (void)bt_ots_obj_id_to_str(track->id, t, sizeof(t)); in mpl_debug_dump_state()
2519 LOG_DBG("\tTrack: %s, %s, duration: %d", t, track->title, track->duration); in mpl_debug_dump_state()
2520 track = track->next; in mpl_debug_dump_state()
2523 group = group->next; in mpl_debug_dump_state()
2536 media_player.group->parent = media_player.group; in mpl_test_unset_parent_group()
2562 media_proxy_pl_track_title_cb(media_player.group->track->title); in mpl_test_title_changed_cb()
2567 media_proxy_pl_track_duration_cb(media_player.group->track->duration); in mpl_test_duration_changed_cb()
2588 media_proxy_pl_current_track_id_cb(media_player.group->track->id); in mpl_test_current_track_id_changed_cb()
2593 media_proxy_pl_next_track_id_cb(media_player.group->track->next->id); in mpl_test_next_track_id_changed_cb()
2598 media_proxy_pl_parent_group_id_cb(media_player.group->id); in mpl_test_parent_group_id_changed_cb()
2603 media_proxy_pl_current_group_id_cb(media_player.group->id); in mpl_test_current_group_id_changed_cb()