Loading...
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 | /*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <zephyr/autoconf.h>
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/audio/mcc.h>
#include <zephyr/bluetooth/audio/media_proxy.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/services/ots.h>
#include <zephyr/sys/printk.h>
#include "bstests.h"
#include "common.h"
#ifdef CONFIG_BT_MCS
extern enum bst_result_t bst_result;
static uint64_t g_icon_object_id;
static uint64_t g_track_segments_object_id;
static uint64_t g_current_track_object_id;
static uint64_t g_next_track_object_id;
static uint64_t g_parent_group_object_id;
static uint64_t g_current_group_object_id;
static uint64_t g_search_results_object_id;
static int32_t g_pos;
static int8_t g_pb_speed;
static uint8_t g_playing_order;
static uint8_t g_state;
static uint8_t g_command_result;
static uint32_t g_commands_supported;
static uint8_t g_search_control_point_result_code;
CREATE_FLAG(ble_is_initialized);
CREATE_FLAG(local_player_instance);
CREATE_FLAG(remote_player_instance);
CREATE_FLAG(player_name_read);
CREATE_FLAG(icon_object_id_read);
CREATE_FLAG(icon_url_read);
CREATE_FLAG(track_title_read);
CREATE_FLAG(track_duration_read);
CREATE_FLAG(track_position);
CREATE_FLAG(playback_speed);
CREATE_FLAG(seeking_speed_read);
CREATE_FLAG(track_segments_object_id_read);
CREATE_FLAG(current_track_object_id_read);
CREATE_FLAG(next_track_object_id_read);
CREATE_FLAG(parent_group_object_id_read);
CREATE_FLAG(current_group_object_id_read);
CREATE_FLAG(search_results_object_id_read);
CREATE_FLAG(playing_order_flag);
CREATE_FLAG(playing_orders_supported_read);
CREATE_FLAG(ccid_read);
CREATE_FLAG(media_state_read);
CREATE_FLAG(command_sent_flag);
CREATE_FLAG(command_results_flag);
CREATE_FLAG(commands_supported);
CREATE_FLAG(search_sent_flag);
CREATE_FLAG(search_result_code_flag);
static struct media_proxy_ctrl_cbs cbs;
static struct media_player *local_player;
static struct media_player *remote_player;
static struct media_player *current_player;
static void local_player_instance_cb(struct media_player *player, int err)
{
if (err) {
FAIL("Local player instance failed (%d)", err);
return;
}
local_player = player;
SET_FLAG(local_player_instance);
}
static void discover_player_cb(struct media_player *player, int err)
{
if (err) {
FAIL("Discover player failed (%d)\n", err);
return;
}
remote_player = player;
SET_FLAG(remote_player_instance);
}
static void player_name_cb(struct media_player *plr, int err, const char *name)
{
if (err) {
FAIL("Player Name read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(player_name_read);
}
static void icon_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Icon Object ID read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_icon_object_id = id;
SET_FLAG(icon_object_id_read);
}
static void icon_url_cb(struct media_player *plr, int err, const char *url)
{
if (err) {
FAIL("Icon URL read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
}
SET_FLAG(icon_url_read);
}
static void track_title_cb(struct media_player *plr, int err, const char *title)
{
if (err) {
FAIL("Track title read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(track_title_read);
}
static void track_duration_cb(struct media_player *plr, int err, int32_t duration)
{
if (err) {
FAIL("Track duration read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(track_duration_read);
}
static void track_position_recv_cb(struct media_player *plr, int err, int32_t position)
{
if (err) {
FAIL("Track position read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_pos = position;
SET_FLAG(track_position);
}
static void track_position_write_cb(struct media_player *plr, int err, int32_t position)
{
if (err) {
FAIL("Track position write failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_pos = position;
SET_FLAG(track_position);
}
static void playback_speed_recv_cb(struct media_player *plr, int err, int8_t speed)
{
if (err) {
FAIL("Playback speed read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_pb_speed = speed;
SET_FLAG(playback_speed);
}
static void playback_speed_write_cb(struct media_player *plr, int err, int8_t speed)
{
if (err) {
FAIL("Playback speed write failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_pb_speed = speed;
SET_FLAG(playback_speed);
}
static void seeking_speed_cb(struct media_player *plr, int err, int8_t speed)
{
if (err) {
FAIL("Seeking speed read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(seeking_speed_read);
}
static void track_segments_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Track Segments ID read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_track_segments_object_id = id;
SET_FLAG(track_segments_object_id_read);
}
static void current_track_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Current Track Object ID read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_current_track_object_id = id;
SET_FLAG(current_track_object_id_read);
}
static void next_track_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Next Track Object ID read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_next_track_object_id = id;
SET_FLAG(next_track_object_id_read);
}
static void parent_group_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Parent Group Object ID read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_parent_group_object_id = id;
SET_FLAG(parent_group_object_id_read);
}
static void current_group_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Current Group Object ID read failed (%d)\n", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_current_group_object_id = id;
SET_FLAG(current_group_object_id_read);
}
static void playing_order_recv_cb(struct media_player *plr, int err, uint8_t order)
{
if (err) {
FAIL("Playing order read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_playing_order = order;
SET_FLAG(playing_order_flag);
}
static void playing_order_write_cb(struct media_player *plr, int err, uint8_t order)
{
if (err) {
FAIL("Playing order write failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_playing_order = order;
SET_FLAG(playing_order_flag);
}
static void playing_orders_supported_cb(struct media_player *plr, int err, uint16_t orders)
{
if (err) {
FAIL("Playing orders supported read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(playing_orders_supported_read);
}
static void media_state_cb(struct media_player *plr, int err, uint8_t state)
{
if (err) {
FAIL("Media State read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_state = state;
SET_FLAG(media_state_read);
}
static void command_send_cb(struct media_player *plr, int err, const struct mpl_cmd *cmd)
{
if (err) {
FAIL("Command send failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(command_sent_flag);
}
static void command_recv_cb(struct media_player *plr, int err, const struct mpl_cmd_ntf *cmd_ntf)
{
if (err) {
FAIL("Command failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_command_result = cmd_ntf->result_code;
SET_FLAG(command_results_flag);
}
static void commands_supported_cb(struct media_player *plr, int err, uint32_t opcodes)
{
if (err) {
FAIL("Commands supported failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_commands_supported = opcodes;
SET_FLAG(commands_supported);
}
static void search_send_cb(struct media_player *plr, int err, const struct mpl_search *search)
{
if (err) {
FAIL("Search failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(search_sent_flag);
}
static void search_recv_cb(struct media_player *plr, int err, uint8_t result_code)
{
if (err) {
FAIL("Search failed (%d), result code: %u", err, result_code);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_search_control_point_result_code = result_code;
SET_FLAG(search_result_code_flag);
}
static void search_results_id_cb(struct media_player *plr, int err, uint64_t id)
{
if (err) {
FAIL("Search Results Object ID read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
g_search_results_object_id = id;
SET_FLAG(search_results_object_id_read);
}
static void content_ctrl_id_cb(struct media_player *plr, int err, uint8_t ccid)
{
if (err) {
FAIL("Content control ID read failed (%d)", err);
return;
}
if (plr != current_player) {
FAIL("Wrong player\n");
return;
}
SET_FLAG(ccid_read);
}
void initialize_media(void)
{
int err = media_proxy_pl_init(); /* TODO: Fix direct call to player */
if (err) {
FAIL("Could not init mpl: %d", err);
return;
}
/* Set up the callback structure */
cbs.local_player_instance = local_player_instance_cb;
cbs.discover_player = discover_player_cb;
cbs.player_name_recv = player_name_cb;
cbs.icon_id_recv = icon_id_cb;
cbs.icon_url_recv = icon_url_cb;
cbs.track_title_recv = track_title_cb;
cbs.track_duration_recv = track_duration_cb;
cbs.track_position_recv = track_position_recv_cb;
cbs.track_position_write = track_position_write_cb;
cbs.playback_speed_recv = playback_speed_recv_cb;
cbs.playback_speed_write = playback_speed_write_cb;
cbs.seeking_speed_recv = seeking_speed_cb;
#ifdef CONFIG_BT_OTS
cbs.track_segments_id_recv = track_segments_id_cb;
cbs.current_track_id_recv = current_track_id_cb;
cbs.next_track_id_recv = next_track_id_cb;
cbs.parent_group_id_recv = parent_group_id_cb;
cbs.current_group_id_recv = current_group_id_cb;
#endif /* CONFIG_BT_OTS */
cbs.playing_order_recv = playing_order_recv_cb;
cbs.playing_order_write = playing_order_write_cb;
cbs.playing_orders_supported_recv = playing_orders_supported_cb;
cbs.media_state_recv = media_state_cb;
cbs.command_send = command_send_cb;
cbs.command_recv = command_recv_cb;
cbs.commands_supported_recv = commands_supported_cb;
#ifdef CONFIG_BT_OTS
cbs.search_send = search_send_cb;
cbs.search_recv = search_recv_cb;
cbs.search_results_id_recv = search_results_id_cb;
#endif /* CONFIG_BT_OTS */
cbs.content_ctrl_id_recv = content_ctrl_id_cb;
UNSET_FLAG(local_player_instance);
err = media_proxy_ctrl_register(&cbs);
if (err) {
FAIL("Could not init mpl: %d", err);
return;
}
WAIT_FOR_FLAG(local_player_instance);
printk("media init and local player instance succeeded\n");
}
/* Callback after Bluetoot initialization attempt */
static void bt_ready(int err)
{
if (err) {
FAIL("Bluetooth init failed (err %d)\n", err);
return;
}
SET_FLAG(ble_is_initialized);
}
/* Helper function to read the media state and verify that it is as expected
* Will FAIL on error reading the media state
* Will FAIL if the state is not as expected
*
* Returns true if the state is as expected
* Returns false in case of errors, or if the state is not as expected
*/
static bool test_verify_media_state_wait_flags(uint8_t expected_state)
{
int err;
UNSET_FLAG(media_state_read);
err = media_proxy_ctrl_get_media_state(current_player);
if (err) {
FAIL("Failed to read media state: %d", err);
return false;
}
WAIT_FOR_FLAG(media_state_read);
if (g_state != expected_state) {
FAIL("Server is not in expected state: %d, expected: %d\n",
g_state, expected_state);
return false;
}
return true;
}
/* Helper function to write commands to the control point, including the
* flag handling.
* Will FAIL on error to send the command.
* Will WAIT for the required flags before returning.
*/
static void test_send_cmd_wait_flags(struct mpl_cmd *cmd)
{
int err;
UNSET_FLAG(command_sent_flag);
UNSET_FLAG(command_results_flag);
err = media_proxy_ctrl_send_command(current_player, cmd);
if (err) {
FAIL("Failed to send command: %d, opcode: %u",
err, cmd->opcode);
return;
}
WAIT_FOR_FLAG(command_sent_flag);
WAIT_FOR_FLAG(command_results_flag);
}
static void test_cp_play(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_PLAY;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("PLAY command failed\n");
return;
}
if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PLAYING)) {
printk("PLAY command succeeded\n");
}
}
static void test_cp_pause(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_PAUSE;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("PAUSE command failed\n");
return;
}
if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED)) {
printk("PAUSE command succeeded\n");
}
}
static void test_cp_fast_rewind(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_FAST_REWIND;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("FAST REWIND command failed\n");
return;
}
if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_SEEKING)) {
printk("FAST REWIND command succeeded\n");
}
}
static void test_cp_fast_forward(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_FAST_FORWARD;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("FAST FORWARD command failed\n");
return;
}
if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_SEEKING)) {
printk("FAST FORWARD command succeeded\n");
}
}
static void test_cp_stop(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_STOP;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("STOP command failed\n");
return;
}
/* There is no "STOPPED" state in the spec - STOP goes to PAUSED */
if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED)) {
printk("STOP command succeeded\n");
}
}
static void test_cp_move_relative(void)
{
int err;
struct mpl_cmd cmd;
/* Assumes that the server is in a state where it is able to change
* the current track position
* Also assumes position will not change by itself, which is wrong if
* if the player is playing.
*/
UNSET_FLAG(track_position);
err = media_proxy_ctrl_get_track_position(current_player);
if (err) {
FAIL("Failed to read track position: %d\n", err);
return;
}
WAIT_FOR_FLAG(track_position);
uint32_t tmp_pos = g_pos;
cmd.opcode = MEDIA_PROXY_OP_MOVE_RELATIVE;
cmd.use_param = true;
cmd.param = 1000; /* Position change, measured in 1/100 of a second */
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("MOVE RELATIVE command failed\n");
return;
}
UNSET_FLAG(track_position);
err = media_proxy_ctrl_get_track_position(current_player);
if (err) {
FAIL("Failed to read track position: %d\n", err);
return;
}
WAIT_FOR_FLAG(track_position);
if (g_pos == tmp_pos) {
/* Position did not change */
FAIL("Server did not move track position\n");
return;
}
printk("MOVE RELATIVE command succeeded\n");
}
static void test_cp_prev_segment(void)
{
struct mpl_cmd cmd;
/* Assumes that the server is in a state where there is a current
* track that has segments, and where the server may switch between
* these
*/
/* To properly verify track segment changes, the track segments
* object must be downloaded and parsed. That is somewhat complex,
* and is getting close to what the qualification tests do.
* Alternatively, the track position may be checked, but the server
* implementation does not set that for segment changes yet.
* For now, we will settle for seeing that the opcodes are accepted.
*/
cmd.opcode = MEDIA_PROXY_OP_PREV_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("PREV SEGMENT command failed\n");
return;
}
printk("PREV SEGMENT command succeeded\n");
}
static void test_cp_next_segment(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_NEXT_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("NEXT SEGMENT command failed\n");
return;
}
printk("NEXT SEGMENT command succeeded\n");
}
static void test_cp_first_segment(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_FIRST_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("FIRST SEGMENT command failed\n");
return;
}
printk("FIRST SEGMENT command succeeded\n");
}
static void test_cp_last_segment(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_LAST_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("LAST SEGMENT command failed\n");
return;
}
printk("LAST SEGMENT command succeeded\n");
}
static void test_cp_goto_segment(void)
{
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_GOTO_SEGMENT;
cmd.use_param = true;
cmd.param = 2; /* Second segment - not the first, maybe not last */
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("GOTO SEGMENT command failed\n");
return;
}
printk("GOTO SEGMENT command succeeded\n");
}
/* Helper function to read the current track object ID, including flag handling
* Will FAIL on error reading object ID
* Will WAIT until the read is completed (object ID flag read flag is set)
*/
static void test_read_current_track_object_id_wait_flags(void)
{
int err;
UNSET_FLAG(current_track_object_id_read);
err = media_proxy_ctrl_get_current_track_id(current_player);
if (err) {
FAIL("Failed to read current track object ID: %d", err);
return;
}
WAIT_FOR_FLAG(current_track_object_id_read);
}
static void test_cp_prev_track(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
/* Assumes that the server is in a state where it has multiple tracks
* and can change between them.
*/
/* To verify that a track change has happened, the test checks that the
* current track object ID has changed.
*/
cmd.opcode = MEDIA_PROXY_OP_PREV_TRACK;
cmd.use_param = false;
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("PREV TRACK command failed\n");
return;
}
test_read_current_track_object_id_wait_flags();
if (g_current_track_object_id == object_id) {
/* Track did not change */
FAIL("Server did not change track\n");
return;
}
printk("PREV TRACK command succeeded\n");
}
static void test_cp_next_track(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_NEXT_TRACK;
cmd.use_param = false;
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("NEXT TRACK command failed\n");
return;
}
test_read_current_track_object_id_wait_flags();
if (g_current_track_object_id == object_id) {
FAIL("Server did not change track\n");
return;
}
printk("NEXT TRACK command succeeded\n");
}
static void test_cp_first_track(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_FIRST_TRACK;
cmd.use_param = false;
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("FIRST TRACK command failed\n");
return;
}
test_read_current_track_object_id_wait_flags();
if (g_current_track_object_id == object_id) {
FAIL("Server did not change track\n");
return;
}
printk("FIRST TRACK command succeeded\n");
}
static void test_cp_last_track(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_LAST_TRACK;
cmd.use_param = false;
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("LAST TRACK command failed\n");
return;
}
test_read_current_track_object_id_wait_flags();
if (g_current_track_object_id == object_id) {
FAIL("Server did not change track\n");
return;
}
printk("LAST TRACK command succeeded\n");
}
static void test_cp_goto_track(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_GOTO_TRACK;
cmd.use_param = true;
cmd.param = 2; /* Second track, not the first, maybe not the last */
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("GOTO TRACK command failed\n");
return;
}
test_read_current_track_object_id_wait_flags();
if (g_current_track_object_id == object_id) {
FAIL("Server did not change track\n");
return;
}
printk("GOTO TRACK command succeeded\n");
}
/* Helper function to read the current group object ID, including flag handling
* Will FAIL on error reading object ID
* Will WAIT until the read is completed (object ID flag read flag is set)
*/
static void test_read_current_group_object_id_wait_flags(void)
{
int err;
UNSET_FLAG(current_group_object_id_read);
err = media_proxy_ctrl_get_current_group_id(current_player);
if (err) {
FAIL("Failed to read current group object ID: %d", err);
return;
}
WAIT_FOR_FLAG(current_group_object_id_read);
}
static void test_cp_prev_group(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
/* Assumes that the server is in a state where it has multiple groups
* and can change between them.
*/
/* To verify that a group change has happened, the test checks that the
* current group object ID has changed.
*/
cmd.opcode = MEDIA_PROXY_OP_PREV_GROUP;
cmd.use_param = false;
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("PREV GROUP command failed\n");
return;
}
test_read_current_group_object_id_wait_flags();
if (g_current_group_object_id == object_id) {
/* Group did not change */
FAIL("Server did not change group\n");
return;
}
printk("PREV GROUP command succeeded\n");
}
static void test_cp_next_group(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_NEXT_GROUP;
cmd.use_param = false;
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("NEXT GROUP command failed\n");
return;
}
test_read_current_group_object_id_wait_flags();
if (g_current_group_object_id == object_id) {
FAIL("Server did not change group\n");
return;
}
printk("NEXT GROUP command succeeded\n");
}
static void test_cp_first_group(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_FIRST_GROUP;
cmd.use_param = false;
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("FIRST GROUP command failed\n");
return;
}
test_read_current_group_object_id_wait_flags();
if (g_current_group_object_id == object_id) {
FAIL("Server did not change group\n");
return;
}
printk("FIRST GROUP command succeeded\n");
}
static void test_cp_last_group(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_LAST_GROUP;
cmd.use_param = false;
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("LAST GROUP command failed\n");
return;
}
test_read_current_group_object_id_wait_flags();
if (g_current_group_object_id == object_id) {
FAIL("Server did not change group\n");
return;
}
printk("LAST GROUP command succeeded\n");
}
static void test_cp_goto_group(void)
{
uint64_t object_id;
struct mpl_cmd cmd;
cmd.opcode = MEDIA_PROXY_OP_GOTO_GROUP;
cmd.use_param = true;
cmd.param = 2; /* Second group, not the first, maybe not the last */
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(&cmd);
if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) {
FAIL("GOTO GROUP command failed\n");
return;
}
test_read_current_group_object_id_wait_flags();
if (g_current_group_object_id == object_id) {
FAIL("Server did not change group\n");
return;
}
printk("GOTO GROUP command succeeded\n");
}
static void test_scp(void)
{
struct mpl_search search;
struct mpl_sci sci = {0};
int err;
/* Test outline:
* - verify that the search results object ID is zero before search
* - write a search (one search control item) to the search control point,
* get write callback and notification
* - verify that the search results object ID is non-zero
*/
UNSET_FLAG(search_results_object_id_read);
err = media_proxy_ctrl_get_search_results_id(current_player);
if (err) {
FAIL("Failed to read search results object ID: %d", err);
return;
}
WAIT_FOR_FLAG(search_results_object_id_read);
if (g_search_results_object_id != 0) {
FAIL("Search results object ID not zero before search\n");
return;
}
/* Set up the search control item, then the search
* Note: As of now, the server implementation only fakes the search,
* so it makes no difference what we search for. The result is the
* same anyway.
*/
sci.type = MEDIA_PROXY_SEARCH_TYPE_TRACK_NAME;
strcpy(sci.param, "Some track name");
/* Length is length of type, plus length of param w/o termination */
sci.len = sizeof(sci.type) + strlen(sci.param);
search.len = 0;
memcpy(&search.search[search.len], &sci.len, sizeof(sci.len));
search.len += sizeof(sci.len);
memcpy(&search.search[search.len], &sci.type, sizeof(sci.type));
search.len += sizeof(sci.type);
memcpy(&search.search[search.len], &sci.param, strlen(sci.param));
search.len += strlen(sci.param);
UNSET_FLAG(search_sent_flag);
UNSET_FLAG(search_result_code_flag);
UNSET_FLAG(search_results_object_id_read);
err = media_proxy_ctrl_send_search(current_player, &search);
if (err) {
FAIL("Failed to write to search control point\n");
return;
}
WAIT_FOR_FLAG(search_sent_flag);
WAIT_FOR_FLAG(search_result_code_flag);
if (g_search_control_point_result_code != MEDIA_PROXY_SEARCH_SUCCESS) {
FAIL("SEARCH operation failed\n");
return;
}
/* A search results object will have been created and the search
* results object ID will have been notified if the search gave results
*/
WAIT_FOR_FLAG(search_results_object_id_read);
if (g_search_results_object_id == 0) {
FAIL("No search results\n");
return;
}
printk("SEARCH operation succeeded\n");
}
/* This function tests all commands in the API in sequence for the provided player.
* (Works by setting the provided player as the "current player".)
*
* The order of the sequence follows the order of the characterstics in the
* Media Control Service specification
*/
void test_media_controller_player(struct media_player *player)
{
current_player = player;
int err;
UNSET_FLAG(player_name_read);
err = media_proxy_ctrl_get_player_name(current_player);
if (err) {
FAIL("Failed to read media player name ID: %d", err);
return;
}
WAIT_FOR_FLAG(player_name_read);
printk("Player Name read succeeded\n");
/* Read icon object id ******************************************/
UNSET_FLAG(icon_object_id_read);
err = media_proxy_ctrl_get_icon_id(current_player);
if (err) {
FAIL("Failed to read icon object ID: %d", err);
return;
}
WAIT_FOR_FLAG(icon_object_id_read);
printk("Icon Object ID read succeeded\n");
/* Read icon url *************************************************/
UNSET_FLAG(icon_url_read);
err = media_proxy_ctrl_get_icon_url(current_player);
if (err) {
FAIL("Failed to read icon url: %d", err);
return;
}
WAIT_FOR_FLAG(icon_url_read);
printk("Icon URL read succeeded\n");
/* Read track_title ******************************************/
UNSET_FLAG(track_title_read);
err = media_proxy_ctrl_get_track_title(current_player);
if (err) {
FAIL("Failed to read track_title: %d", err);
return;
}
WAIT_FOR_FLAG(track_title_read);
printk("Track title read succeeded\n");
/* Read track_duration ******************************************/
UNSET_FLAG(track_duration_read);
err = media_proxy_ctrl_get_track_duration(current_player);
if (err) {
FAIL("Failed to read track_duration: %d", err);
return;
}
WAIT_FOR_FLAG(track_duration_read);
printk("Track duration read succeeded\n");
/* Read and set track_position *************************************/
UNSET_FLAG(track_position);
err = media_proxy_ctrl_get_track_position(current_player);
if (err) {
FAIL("Failed to read track position: %d", err);
return;
}
WAIT_FOR_FLAG(track_position);
printk("Track position read succeeded\n");
int32_t pos = g_pos + 1200; /*12 seconds further into the track */
UNSET_FLAG(track_position);
err = media_proxy_ctrl_set_track_position(current_player, pos);
if (err) {
FAIL("Failed to set track position: %d", err);
return;
}
WAIT_FOR_FLAG(track_position);
if (g_pos != pos) {
/* In this controlled case, we expect that the resulting */
/* position is the position given in the set command */
FAIL("Track position set failed: Incorrect position\n");
}
printk("Track position set succeeded\n");
/* Read and set playback speed *************************************/
UNSET_FLAG(playback_speed);
err = media_proxy_ctrl_get_playback_speed(current_player);
if (err) {
FAIL("Failed to read playback speed: %d", err);
return;
}
WAIT_FOR_FLAG(playback_speed);
printk("Playback speed read succeeded\n");
int8_t pb_speed = g_pb_speed + 8; /* 2^(8/64) faster than current speed */
UNSET_FLAG(playback_speed);
err = media_proxy_ctrl_set_playback_speed(current_player, pb_speed);
if (err) {
FAIL("Failed to set playback speed: %d", err);
return;
}
WAIT_FOR_FLAG(playback_speed);
if (g_pb_speed != pb_speed) {
FAIL("Playback speed failed: Incorrect playback speed\n");
}
printk("Playback speed set succeeded\n");
/* Read seeking speed *************************************/
UNSET_FLAG(seeking_speed_read);
err = media_proxy_ctrl_get_seeking_speed(current_player);
if (err) {
FAIL("Failed to read seeking speed: %d", err);
return;
}
WAIT_FOR_FLAG(seeking_speed_read);
printk("Seeking speed read succeeded\n");
/* Read track segments object *****************************************/
UNSET_FLAG(track_segments_object_id_read);
err = media_proxy_ctrl_get_track_segments_id(current_player);
if (err) {
FAIL("Failed to read track segments object ID: %d", err);
return;
}
WAIT_FOR_FLAG(track_segments_object_id_read);
printk("Track Segments Object ID read succeeded\n");
/* Read current track object ******************************************/
UNSET_FLAG(current_track_object_id_read);
err = media_proxy_ctrl_get_current_track_id(current_player);
if (err) {
FAIL("Failed to read current track object ID: %d", err);
return;
}
WAIT_FOR_FLAG(current_track_object_id_read);
printk("Current Track Object ID read succeeded\n");
/* Read next track object ******************************************/
UNSET_FLAG(next_track_object_id_read);
err = media_proxy_ctrl_get_next_track_id(current_player);
if (err) {
FAIL("Failed to read next track object ID: %d", err);
return;
}
WAIT_FOR_FLAG(next_track_object_id_read);
printk("Next Track Object ID read succeeded\n");
/* Read parent group object ******************************************/
UNSET_FLAG(parent_group_object_id_read);
err = media_proxy_ctrl_get_parent_group_id(current_player);
if (err) {
FAIL("Failed to read parent group object ID: %d", err);
return;
}
WAIT_FOR_FLAG(parent_group_object_id_read);
printk("Parent Group Object ID read succeeded\n");
/* Read current group object ******************************************/
UNSET_FLAG(current_group_object_id_read);
err = media_proxy_ctrl_get_current_group_id(current_player);
if (err) {
FAIL("Failed to read current group object ID: %d", err);
return;
}
WAIT_FOR_FLAG(current_group_object_id_read);
printk("Current Group Object ID read succeeded\n");
/* Read and set playing order *************************************/
UNSET_FLAG(playing_order_flag);
err = media_proxy_ctrl_get_playing_order(current_player);
if (err) {
FAIL("Failed to read playing order: %d", err);
return;
}
WAIT_FOR_FLAG(playing_order_flag);
printk("Playing order read succeeded\n");
uint8_t playing_order;
if (g_playing_order != MEDIA_PROXY_PLAYING_ORDER_INORDER_ONCE) {
playing_order = MEDIA_PROXY_PLAYING_ORDER_INORDER_ONCE;
} else {
playing_order = MEDIA_PROXY_PLAYING_ORDER_INORDER_REPEAT;
}
UNSET_FLAG(playing_order_flag);
err = media_proxy_ctrl_set_playing_order(current_player, playing_order);
if (err) {
FAIL("Failed to set playing_order: %d", err);
return;
}
WAIT_FOR_FLAG(playing_order_flag);
if (g_playing_order != playing_order) {
FAIL("Playing order set failed: Incorrect playing_order\n");
}
printk("Playing order set succeeded\n");
/* Read playing orders supported *************************************/
UNSET_FLAG(playing_orders_supported_read);
err = media_proxy_ctrl_get_playing_orders_supported(current_player);
if (err) {
FAIL("Failed to read playing orders supported: %d", err);
return;
}
WAIT_FOR_FLAG(playing_orders_supported_read);
printk("Playing orders supported read succeeded\n");
/* Read media state ***************************************************/
UNSET_FLAG(media_state_read);
err = media_proxy_ctrl_get_media_state(current_player);
if (err) {
FAIL("Failed to read media state: %d", err);
return;
}
WAIT_FOR_FLAG(media_state_read);
printk("Media state read succeeded\n");
/* Read content control ID *******************************************/
UNSET_FLAG(ccid_read);
err = media_proxy_ctrl_get_content_ctrl_id(current_player);
if (err) {
FAIL("Failed to read content control ID: %d", err);
return;
}
WAIT_FOR_FLAG(ccid_read);
printk("Content control ID read succeeded\n");
/* Control point - "state" opcodes */
/* This part of the test not only checks that the opcodes are accepted
* by the server, but also that they actually do lead to the expected
* state changes. This may lean too much upon knowledge or assumptions,
* and therefore be too fragile.
* It may be more robust to just give commands and check for the success
* code in the control point notifications
*/
/* It is assumed that the server starts the test in the paused state */
test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED);
/* The tests are ordered to ensure that each command changes state */
test_cp_play();
test_cp_fast_forward();
test_cp_pause();
test_cp_fast_rewind();
test_cp_stop();
/* Control point - move relative opcode */
test_cp_move_relative();
/* Control point - segment change opcodes */
test_cp_prev_segment();
test_cp_next_segment();
test_cp_first_segment();
test_cp_last_segment();
test_cp_goto_segment();
/* Control point - track change opcodes */
/* The tests are ordered to ensure that each command changes track */
/* Assumes we are not starting on the last track */
test_cp_next_track();
test_cp_prev_track();
test_cp_last_track();
test_cp_first_track();
test_cp_goto_track();
/* Control point - group change opcodes *******************************/
/* The tests are ordered to ensure that each command changes group */
/* Assumes we are not starting on the last group */
test_cp_next_group();
test_cp_prev_group();
test_cp_last_group();
test_cp_first_group();
test_cp_goto_group();
/* Search control point */
test_scp();
}
void initialize_bluetooth(void)
{
int err;
UNSET_FLAG(ble_is_initialized);
err = bt_enable(bt_ready);
if (err) {
FAIL("Bluetooth init failed (err %d)\n", err);
return;
}
WAIT_FOR_FLAG(ble_is_initialized);
printk("Bluetooth initialized\n");
bt_le_scan_cb_register(&common_scan_cb);
}
void scan_and_connect(void)
{
char addr[BT_ADDR_LE_STR_LEN];
int err;
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL);
if (err) {
FAIL("Failed to start scanning (err %d\n)", err);
return;
}
printk("Scanning started successfully\n");
WAIT_FOR_FLAG(flag_connected);
bt_addr_le_to_str(bt_conn_get_dst(default_conn), addr, sizeof(addr));
printk("Connected: %s\n", addr);
}
void discover_remote_player(void)
{
int err;
UNSET_FLAG(remote_player_instance);
err = media_proxy_ctrl_discover_player(default_conn);
if (err) {
FAIL("Remote player discovery failed (err %d)\n", err);
return;
}
WAIT_FOR_FLAG(remote_player_instance);
}
/* BabbleSim entry point for local player test */
void test_media_controller_local_player(void)
{
printk("Media Control local player test application. Board: %s\n", CONFIG_BOARD);
initialize_bluetooth();
initialize_media(); /* Sets local_player global variable */
printk("Local player instance: %p\n", local_player);
test_media_controller_player(local_player);
/* TEST IS COMPLETE */
PASS("Test media_controller_local_player passed\n");
}
/* BabbleSim entry point for remote player test */
void test_media_controller_remote_player(void)
{
int err;
printk("Media Control remote player test application. Board: %s\n", CONFIG_BOARD);
initialize_bluetooth();
initialize_media();
err = bt_le_adv_start(BT_LE_ADV_CONN_ONE_TIME, ad, AD_SIZE, NULL, 0);
if (err) {
FAIL("Advertising failed to start (err %d)\n", err);
}
WAIT_FOR_FLAG(flag_connected);
discover_remote_player(); /* Sets global variable */
printk("Remote player instance: %p\n", remote_player);
test_media_controller_player(remote_player);
/* TEST IS COMPLETE */
PASS("Test media_controller_remote_player passed\n");
}
/* BabbleSim entry point for server for remote player test */
void test_media_controller_server(void)
{
printk("Media Control server test application. Board: %s\n", CONFIG_BOARD);
initialize_bluetooth();
initialize_media();
/* The server side will also get callbacks, from its local player.
* And if the current player is not set, the callbacks will fail the test.
*/
printk("Local player instance: %p\n", local_player);
current_player = local_player;
scan_and_connect();
/* TEST IS COMPLETE */
PASS("Test media_controller_server passed\n");
}
static const struct bst_test_instance test_media_controller[] = {
{
.test_id = "media_controller_local_player",
.test_pre_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = test_media_controller_local_player
},
{
.test_id = "media_controller_remote_player",
.test_pre_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = test_media_controller_remote_player
},
{
.test_id = "media_controller_server",
.test_pre_init_f = test_init,
.test_tick_f = test_tick,
.test_main_f = test_media_controller_server
},
BSTEST_END_MARKER
};
struct bst_test_list *test_media_controller_install(struct bst_test_list *tests)
{
return bst_add_tests(tests, test_media_controller);
}
#else
struct bst_test_list *test_media_controller_install(struct bst_test_list *tests)
{
return tests;
}
#endif /* CONFIG_BT_MCS */
|