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 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/dbus/audio/cras_audio_client.h"
#include <stdint.h>
#include <utility>
#include "ash/constants/ash_switches.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/dbus/audio/fake_cras_audio_client.h"
#include "chromeos/ash/components/dbus/audio/voice_isolation_ui_appearance.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "third_party/cros_system_api/dbus/audio/dbus-constants.h"
namespace ash {
namespace {
CrasAudioClient* g_instance = nullptr;
// The CrasAudioClient implementation used in production.
class CrasAudioClientImpl : public CrasAudioClient {
public:
explicit CrasAudioClientImpl(dbus::Bus* bus) {
cras_proxy_ = bus->GetObjectProxy(cras::kCrasServiceName,
dbus::ObjectPath(cras::kCrasServicePath));
// Monitor NameOwnerChanged signal.
cras_proxy_->SetNameOwnerChangedCallback(
base::BindRepeating(&CrasAudioClientImpl::NameOwnerChangedReceived,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for output mute change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kOutputMuteChanged,
base::BindRepeating(&CrasAudioClientImpl::OutputMuteChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for input mute change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kInputMuteChanged,
base::BindRepeating(&CrasAudioClientImpl::InputMuteChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for nodes change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kNodesChanged,
base::BindRepeating(&CrasAudioClientImpl::NodesChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for active output node change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kActiveOutputNodeChanged,
base::BindRepeating(
&CrasAudioClientImpl::ActiveOutputNodeChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for active input node change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kActiveInputNodeChanged,
base::BindRepeating(
&CrasAudioClientImpl::ActiveInputNodeChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for output node volume change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kOutputNodeVolumeChanged,
base::BindRepeating(
&CrasAudioClientImpl::OutputNodeVolumeChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for input node gain change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kInputNodeGainChanged,
base::BindRepeating(&CrasAudioClientImpl::InputNodeGainChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for hotword.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kHotwordTriggered,
base::BindRepeating(&CrasAudioClientImpl::HotwordTriggeredReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for changes in number of active streams.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kNumberOfActiveStreamsChanged,
base::BindRepeating(
&CrasAudioClientImpl::NumberOfActiveStreamsChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for changes in number of input streams with
// permission per client type.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface,
cras::kNumberOfInputStreamsWithPermissionChanged,
base::BindRepeating(
&CrasAudioClientImpl::NumberOfInputStreamsWithPermissionReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr())
);
// Monitor the D-Bus signal for changes in Bluetooth headset battery level.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kBluetoothBatteryChanged,
base::BindRepeating(
&CrasAudioClientImpl::BluetoothBatteryChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for CRAS to trigger an audio related survey.
// The HaTS survey framework lives in Chrome and we use this signal as an
// interface for CRAS to suggest when is proper to trigger the survey from
// the system's perspective.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kSurveyTrigger,
base::BindRepeating(&CrasAudioClientImpl::SurveyTriggerReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for new speak-on-mute detection.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kSpeakOnMuteDetected,
base::BindRepeating(&CrasAudioClientImpl::SpeakOnMuteDetectedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, "EwmaPowerReported",
base::BindRepeating(&CrasAudioClientImpl::EwmaPowerReportedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface,
cras::kNumberOfNonChromeOutputStreamsChanged,
base::BindRepeating(
&CrasAudioClientImpl::NumberOfNonChromeOutputStreamsChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for is any stream ignore ui gains changed.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kNumStreamIgnoreUiGainsChanged,
base::BindRepeating(
&CrasAudioClientImpl::NumStreamIgnoreUiGainsReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for number of ARC streams changed.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, cras::kNumberOfArcStreamsChanged,
base::BindRepeating(
&CrasAudioClientImpl::NumberOfArcStreamsChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for sidetone supported.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface,
"SidetoneSupportedChanged", // TODO: Change to variable
base::BindRepeating(
&CrasAudioClientImpl::SidetoneSupportedChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Monitor the D-Bus signal for audio effect ui appearance.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface, "AudioEffectUIAppearanceChanged",
base::BindRepeating(
&CrasAudioClientImpl::AudioEffectUIAppearanceChangedReceived,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CrasAudioClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr()));
}
CrasAudioClientImpl(const CrasAudioClientImpl&) = delete;
CrasAudioClientImpl& operator=(const CrasAudioClientImpl&) = delete;
~CrasAudioClientImpl() override = default;
// CrasAudioClient overrides:
void AddObserver(Observer* observer) override {
observers_.AddObserver(observer);
}
void RemoveObserver(Observer* observer) override {
observers_.RemoveObserver(observer);
}
bool HasObserver(const Observer* observer) const override {
return observers_.HasObserver(observer);
}
void GetVolumeState(
chromeos::DBusMethodCallback<VolumeState> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetVolumeState);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetVolumeState,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetDefaultOutputBufferSize(
chromeos::DBusMethodCallback<int> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetDefaultOutputBufferSize);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetDefaultOutputBufferSize,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetSystemAecSupported(
chromeos::DBusMethodCallback<bool> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetSystemAecSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSystemAecSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetSystemAecGroupId(
chromeos::DBusMethodCallback<int32_t> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetSystemAecGroupId);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSystemAecGroupId,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetSystemNsSupported(
chromeos::DBusMethodCallback<bool> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetSystemNsSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSystemNsSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetSystemAgcSupported(
chromeos::DBusMethodCallback<bool> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetSystemAgcSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSystemAgcSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNodes(chromeos::DBusMethodCallback<AudioNodeList> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface, cras::kGetNodes);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetNodes,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNumberOfActiveOutputStreams(
chromeos::DBusMethodCallback<int> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetNumberOfActiveOutputStreams);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetNumberOfActiveOutputStreams,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNumberOfInputStreamsWithPermission(
chromeos::DBusMethodCallback<base::flat_map<std::string, uint32_t>>
callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetNumberOfInputStreamsWithPermission);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(
&CrasAudioClientImpl::OnGetNumberOfInputStreamsWithPermission,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNumberOfNonChromeOutputStreams(
chromeos::DBusMethodCallback<int32_t> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetNumberOfNonChromeOutputStreams);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(
&CrasAudioClientImpl::OnGetNumberOfNonChromeOutputStreams,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetSpeakOnMuteDetectionEnabled(
chromeos::DBusMethodCallback<bool> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSpeakOnMuteDetectionEnabled);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSpeakOnMuteDetectionEnabled,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetOutputNodeVolume(uint64_t node_id, int32_t volume) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetOutputNodeVolume);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
writer.AppendInt32(volume);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetOutputUserMute(bool mute_on) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetOutputUserMute);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(mute_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetInputNodeGain(uint64_t node_id, int32_t input_gain) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetInputNodeGain);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
writer.AppendInt32(input_gain);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetInputMute(bool mute_on) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetInputMute);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(mute_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetVoiceIsolationUIAppearance(
chromeos::DBusMethodCallback<VoiceIsolationUIAppearance> callback)
override {
VLOG(1) << "cras_audio_client: Requesting voice isolation UI appearance.";
// TODO(hunghsienchen): Use cras::kGetVoiceIsolationUIAppearance after
// dbus-constants.h is updated.
dbus::MethodCall method_call(cras::kCrasControlInterface,
"GetVoiceIsolationUIAppearance");
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetVoiceIsolationUIAppearance,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetVoiceIsolationUIEnabled(bool voice_isolation_on) override {
VLOG(1) << "cras_audio_client: Setting voice isolation state: "
<< voice_isolation_on;
// TODO(hunghsienchen): Use cras::kSetVoiceIsolationUIEnabled after
// dbus-constants.h is updated.
dbus::MethodCall method_call(cras::kCrasControlInterface,
"SetVoiceIsolationUIEnabled");
dbus::MessageWriter writer(&method_call);
writer.AppendBool(voice_isolation_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetVoiceIsolationUIPreferredEffect(uint32_t effect_mode) override {
VLOG(1) << "cras_audio_client: Setting voice isolation preferred effect: "
<< effect_mode;
dbus::MethodCall method_call(cras::kCrasControlInterface,
"SetVoiceIsolationUIPreferredEffect");
dbus::MessageWriter writer(&method_call);
writer.AppendUint32(effect_mode);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetNoiseCancellationEnabled(bool noise_cancellation_on) override {
VLOG(1) << "cras_audio_client: Setting noise cancellation state: "
<< noise_cancellation_on;
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetNoiseCancellationEnabled);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(noise_cancellation_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetAudioEffectDlcs(
chromeos::DBusMethodCallback<std::string> callback) override {
VLOG(1) << "cras_audio_client: Requesting getting audio effect dlcs.";
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetAudioEffectDlcs);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetAudioEffectDlcs,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNoiseCancellationSupported(
chromeos::DBusMethodCallback<bool> callback) override {
VLOG(1) << "cras_audio_client: Requesting noise cancellation support.";
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kIsNoiseCancellationSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetNoiseCancellationSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetStyleTransferEnabled(bool style_transfer_on) override {
VLOG(1) << "cras_audio_client: Setting style transfer state: "
<< style_transfer_on;
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetStyleTransferEnabled);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(style_transfer_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetStyleTransferSupported(
chromeos::DBusMethodCallback<bool> callback) override {
VLOG(1) << "cras_audio_client: Requesting style transfer support.";
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kIsStyleTransferSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetStyleTransferSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetHfpMicSrEnabled(bool hfp_mic_sr_on) override {
VLOG(1) << "cras_audio_client: Setting hfp_mic_sr state: " << hfp_mic_sr_on;
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetHfpMicSrEnabled);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(hfp_mic_sr_on);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetHfpMicSrSupported(
chromeos::DBusMethodCallback<bool> callback) override {
VLOG(1) << "cras_audio_client: Requesting hfp_mic_sr support.";
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kIsHfpMicSrSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetHfpMicSrSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetActiveOutputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetActiveOutputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetActiveInputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetActiveInputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetHotwordModel(uint64_t node_id,
const std::string& hotword_model,
chromeos::VoidDBusMethodCallback callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetHotwordModel);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
writer.AppendString(hotword_model);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnSetHotwordModel,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetFixA2dpPacketSize(bool enabled) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetFixA2dpPacketSize);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(enabled);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetFlossEnabled(bool enabled) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetFlossEnabled);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(enabled);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetSpeakOnMuteDetection(bool enabled) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetSpeakOnMuteDetection);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(enabled);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetEwmaPowerReportEnabled(bool enabled) override {
dbus::MethodCall method_call(
cras::kCrasControlInterface,
"SetEwmaPowerReportEnabled"); // TODO change to variable;
dbus::MessageWriter writer(&method_call);
writer.AppendBool(enabled);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetSidetoneEnabled(bool enabled) override {
dbus::MethodCall method_call(
cras::kCrasControlInterface,
"SetSidetoneEnabled"); // TODO change to variable;
dbus::MessageWriter writer(&method_call);
writer.AppendBool(enabled);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetSidetoneSupported(
chromeos::DBusMethodCallback<bool> callback) override {
dbus::MethodCall method_call(
cras::kCrasControlInterface,
"GetSidetoneSupported"); // TODO: Change to variable
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSidetoneSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void AddActiveInputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kAddActiveInputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void RemoveActiveInputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kRemoveActiveInputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void AddActiveOutputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kAddActiveOutputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void RemoveActiveOutputNode(uint64_t node_id) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kRemoveActiveOutputNode);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SwapLeftRight(uint64_t node_id, bool swap) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSwapLeftRight);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
writer.AppendBool(swap);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetDisplayRotation(uint64_t node_id,
cras::DisplayRotation rotation) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetDisplayRotation);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(node_id);
writer.AppendUint32(static_cast<uint32_t>(rotation));
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetGlobalOutputChannelRemix(int32_t channels,
const std::vector<double>& mixer) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetGlobalOutputChannelRemix);
dbus::MessageWriter writer(&method_call);
writer.AppendInt32(channels);
writer.AppendArrayOfDoubles(mixer);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerPlaybackStatus(const std::string& playback_status) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerPlaybackStatus);
dbus::MessageWriter writer(&method_call);
writer.AppendString(playback_status);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerIdentity(const std::string& identity) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerIdentity);
dbus::MessageWriter writer(&method_call);
writer.AppendString(identity);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerPosition(const int64_t& position) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerPosition);
dbus::MessageWriter writer(&method_call);
writer.AppendInt64(position);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerDuration(const int64_t& duration) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerMetadata);
dbus::MessageWriter writer(&method_call);
dbus::MessageWriter array_writer(nullptr);
dbus::MessageWriter dict_entry_writer(nullptr);
writer.OpenArray("{sv}", &array_writer);
array_writer.OpenDictEntry(&dict_entry_writer);
dict_entry_writer.AppendString("length");
dict_entry_writer.AppendVariantOfInt64(duration);
array_writer.CloseContainer(&dict_entry_writer);
writer.CloseContainer(&array_writer);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void SetPlayerMetadata(
const std::map<std::string, std::string>& metadata) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetPlayerMetadata);
dbus::MessageWriter writer(&method_call);
dbus::MessageWriter array_writer(nullptr);
dbus::MessageWriter dict_entry_writer(nullptr);
writer.OpenArray("{sv}", &array_writer);
for (auto& it : metadata) {
array_writer.OpenDictEntry(&dict_entry_writer);
dict_entry_writer.AppendString(it.first);
dict_entry_writer.AppendVariantOfString(it.second);
array_writer.CloseContainer(&dict_entry_writer);
}
writer.CloseContainer(&array_writer);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void ResendBluetoothBattery() override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kResendBluetoothBattery);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void WaitForServiceToBeAvailable(
chromeos::WaitForServiceToBeAvailableCallback callback) override {
cras_proxy_->WaitForServiceToBeAvailable(std::move(callback));
}
void SetForceRespectUiGains(bool force_respect_ui_gains) override {
VLOG(1) << "cras_audio_client: Setting force_respect_ui_gains state: "
<< force_respect_ui_gains;
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetForceRespectUiGains);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(force_respect_ui_gains);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetNumStreamIgnoreUiGains(
chromeos::DBusMethodCallback<int32_t> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetNumStreamIgnoreUiGains);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetNumStreamIgnoreUiGains,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNumberOfArcStreams(
chromeos::DBusMethodCallback<int32_t> callback) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kGetNumberOfArcStreams);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetNumberOfArcStreams,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetSpatialAudio(bool spatial_audio) override {
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kSetSpatialAudio);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(spatial_audio);
cras_proxy_->CallMethod(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::DoNothing());
}
void GetSpatialAudioSupported(
chromeos::DBusMethodCallback<bool> callback) override {
VLOG(1) << "cras_audio_client: Requesting spatial audio support.";
dbus::MethodCall method_call(cras::kCrasControlInterface,
cras::kIsSpatialAudioSupported);
cras_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&CrasAudioClientImpl::OnGetSpatialAudioSupported,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
private:
// Called when the cras signal is initially connected.
void SignalConnected(const std::string& interface_name,
const std::string& signal_name,
bool success) {
LOG_IF(ERROR, !success)
<< "Failed to connect to cras signal:" << signal_name;
}
void NameOwnerChangedReceived(const std::string& old_owner,
const std::string& new_owner) {
for (auto& observer : observers_) {
observer.AudioClientRestarted();
}
}
// Called when a OutputMuteChanged signal is received.
void OutputMuteChangedReceived(dbus::Signal* signal) {
// Chrome should always call SetOutputUserMute api to set the output
// mute state and monitor user_mute state from OutputMuteChanged signal.
dbus::MessageReader reader(signal);
bool system_mute, user_mute;
if (!reader.PopBool(&system_mute) || !reader.PopBool(&user_mute)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.OutputMuteChanged(user_mute);
}
}
// Called when a InputMuteChanged signal is received.
void InputMuteChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
bool mute;
if (!reader.PopBool(&mute)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.InputMuteChanged(mute);
}
}
void NodesChangedReceived(dbus::Signal* signal) {
for (auto& observer : observers_) {
observer.NodesChanged();
}
}
void ActiveOutputNodeChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
uint64_t node_id;
if (!reader.PopUint64(&node_id)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.ActiveOutputNodeChanged(node_id);
}
}
void ActiveInputNodeChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
uint64_t node_id;
if (!reader.PopUint64(&node_id)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.ActiveInputNodeChanged(node_id);
}
}
void OutputNodeVolumeChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
uint64_t node_id;
int volume;
if (!reader.PopUint64(&node_id)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
if (!reader.PopInt32(&volume)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.OutputNodeVolumeChanged(node_id, volume);
}
}
void InputNodeGainChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
uint64_t node_id;
int gain;
if (!reader.PopUint64(&node_id)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
if (!reader.PopInt32(&gain)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.InputNodeGainChanged(node_id, gain);
}
}
void HotwordTriggeredReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
int64_t tv_sec, tv_nsec;
if (!reader.PopInt64(&tv_sec)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
return;
}
if (!reader.PopInt64(&tv_nsec)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
return;
}
for (auto& observer : observers_) {
observer.HotwordTriggered(tv_sec, tv_nsec);
}
}
void NumberOfActiveStreamsChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
// We skip reading the output because it is not used by the observers.
for (auto& observer : observers_) {
observer.NumberOfActiveStreamsChanged();
}
}
void NumberOfInputStreamsWithPermissionReceived(dbus::Signal* signal) {
dbus::MessageReader signal_reader(signal);
dbus::MessageReader array_reader(nullptr);
base::flat_map<std::string, uint32_t> res;
while (signal_reader.HasMoreData()) {
if (!signal_reader.PopArray(&array_reader)) {
LOG(ERROR) << "Error reading signal from cras: " << signal->ToString();
return;
}
std::string client_type;
uint32_t num_input_streams;
if (!GetNumerInputStreams(&array_reader, &client_type,
&num_input_streams)) {
LOG(ERROR) << "Error reading number of input streams from cras: "
<< signal->ToString();
return;
}
res[client_type] = num_input_streams;
}
for (auto& observer : observers_) {
observer.NumberOfInputStreamsWithPermissionChanged(res);
}
}
void BluetoothBatteryChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
std::string address;
uint32_t level;
if (!reader.PopString(&address)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
return;
}
if (!reader.PopUint32(&level)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
return;
}
for (auto& observer : observers_) {
observer.BluetoothBatteryChanged(address, level);
}
}
void OnGetVolumeState(chromeos::DBusMethodCallback<VolumeState> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetVolumeState;
std::move(callback).Run(std::nullopt);
return;
}
VolumeState volume_state;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&volume_state.output_volume) ||
!reader.PopBool(&volume_state.output_system_mute) ||
!reader.PopInt32(&volume_state.input_gain) ||
!reader.PopBool(&volume_state.input_mute) ||
!reader.PopBool(&volume_state.output_user_mute)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(std::move(volume_state));
}
bool PopSurveyKeyValue(dbus::MessageReader* array_reader,
std::string* key,
std::string* val) {
dbus::MessageReader dict_entry_reader(nullptr);
if (!array_reader->HasMoreData() ||
!array_reader->PopDictEntry(&dict_entry_reader) ||
!dict_entry_reader.PopString(key) ||
!dict_entry_reader.PopVariantOfString(val)) {
return false;
}
return true;
}
void SurveyTriggerReceived(dbus::Signal* signal) {
dbus::MessageReader signal_reader(signal);
dbus::MessageReader array_reader(nullptr);
base::flat_map<std::string, std::string> res;
while (signal_reader.HasMoreData()) {
if (!signal_reader.PopArray(&array_reader)) {
LOG(ERROR) << "Error reading signal from cras: " << signal->ToString();
return;
}
// Chrome HaTS survey system supports logging a map of survey specific
// data for better data interpretation.
// For general audio satisfaction survey as an example, we shall get the
// snapshot of stream type, client type and also active node type pair
// when the user closes a stream living longer than a specified perioid
// of time. We can use the data to identify the user scenario we'd like
// to improve, such as voice communication on Chrome through Bluetooth.
std::string key;
std::string val;
while (array_reader.HasMoreData()) {
if (!PopSurveyKeyValue(&array_reader, &key, &val)) {
LOG(ERROR) << "Error reading key value pairs of the data from cras: "
<< signal->ToString();
return;
}
res[key] = val;
}
}
for (auto& observer : observers_) {
observer.SurveyTriggered(res);
}
}
void SpeakOnMuteDetectedReceived(dbus::Signal* signal) {
for (auto& observer : observers_) {
observer.SpeakOnMuteDetected();
}
}
void EwmaPowerReportedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
double power;
if (!reader.PopDouble(&power)) {
LOG(ERROR) << "Error reading signal from cras: " << signal->ToString();
}
for (auto& observer : observers_) {
observer.EwmaPowerReported(power);
}
}
void NumberOfNonChromeOutputStreamsChangedReceived(dbus::Signal* signal) {
for (auto& observer : observers_) {
observer.NumberOfNonChromeOutputStreamsChanged();
}
}
void NumStreamIgnoreUiGainsReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
int32_t num;
if (!reader.PopInt32(&num)) {
LOG(ERROR) << "Error reading signal from cras:" << signal->ToString();
}
for (auto& observer : observers_) {
observer.NumStreamIgnoreUiGains(num);
}
}
void NumberOfArcStreamsChangedReceived(dbus::Signal* signal) {
for (auto& observer : observers_) {
observer.NumberOfArcStreamsChanged();
}
}
void SidetoneSupportedChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
bool supported;
if (!reader.PopBool(&supported)) {
LOG(ERROR) << "Error reading signal from cras: " << signal->ToString();
}
for (auto& observer : observers_) {
observer.SidetoneSupportedChanged(supported);
}
}
void AudioEffectUIAppearanceChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
VoiceIsolationUIAppearance appearance;
if (!ReadVoiceIsolationUIAppearanceFromDBus(signal, appearance)) {
return;
}
for (auto& observer : observers_) {
observer.AudioEffectUIAppearanceChanged(appearance);
}
}
void OnGetDefaultOutputBufferSize(chromeos::DBusMethodCallback<int> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetDefaultOutputBufferSize;
std::move(callback).Run(std::nullopt);
return;
}
int32_t buffer_size = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&buffer_size)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(buffer_size);
}
void OnGetSystemAecSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetSystemAecSupported;
std::move(callback).Run(std::nullopt);
return;
}
bool system_aec_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&system_aec_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(system_aec_supported);
}
void OnGetSystemAecGroupId(chromeos::DBusMethodCallback<int32_t> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetSystemAecGroupId;
std::move(callback).Run(std::nullopt);
return;
}
int32_t system_aec_group_id = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&system_aec_group_id)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(system_aec_group_id);
}
void OnGetSystemNsSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetSystemNsSupported;
std::move(callback).Run(std::nullopt);
return;
}
bool system_ns_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&system_ns_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(system_ns_supported);
}
void OnGetSystemAgcSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetSystemAgcSupported;
std::move(callback).Run(std::nullopt);
return;
}
bool system_agc_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&system_agc_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(system_agc_supported);
}
void OnGetNodes(chromeos::DBusMethodCallback<AudioNodeList> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(std::nullopt);
return;
}
AudioNodeList node_list;
dbus::MessageReader response_reader(response);
dbus::MessageReader array_reader(response);
while (response_reader.HasMoreData()) {
if (!response_reader.PopArray(&array_reader)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
AudioNode node;
if (!GetAudioNode(response, &array_reader, &node)) {
LOG(WARNING) << "Error reading audio node data from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
// Filter out the "UNKNOWN" type of audio devices.
if (node.type != "UNKNOWN") {
node_list.push_back(std::move(node));
}
}
std::move(callback).Run(std::move(node_list));
}
void OnGetSidetoneSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling GetSidetoneSupported";
std::move(callback).Run(std::nullopt);
return;
}
bool available = false;
dbus::MessageReader reader(response);
if (!reader.PopBool(&available)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(available);
}
void OnGetNumberOfNonChromeOutputStreams(
chromeos::DBusMethodCallback<int32_t> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling "
<< cras::kGetNumberOfNonChromeOutputStreams;
std::move(callback).Run(std::nullopt);
return;
}
int32_t num_active_streams = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&num_active_streams)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(num_active_streams);
}
void OnGetNumberOfActiveOutputStreams(
chromeos::DBusMethodCallback<int> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetNumberOfActiveOutputStreams;
std::move(callback).Run(std::nullopt);
return;
}
int32_t num_active_streams = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&num_active_streams)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(num_active_streams);
}
bool GetNumerInputStreams(dbus::MessageReader* array_reader,
std::string* client_type,
uint32_t* num_input_streams) {
while (array_reader->HasMoreData()) {
dbus::MessageReader dict_entry_reader(nullptr);
dbus::MessageReader value_reader(nullptr);
std::string key;
if (!array_reader->PopDictEntry(&dict_entry_reader) ||
!dict_entry_reader.PopString(&key) ||
!dict_entry_reader.PopVariant(&value_reader)) {
return false;
}
if (key == cras::kClientType) {
if (!value_reader.PopString(client_type)) {
return false;
}
} else if (key == cras::kNumStreamsWithPermission) {
if (!value_reader.PopUint32(num_input_streams)) {
return false;
}
}
}
return true;
}
void OnGetNumberOfInputStreamsWithPermission(
chromeos::DBusMethodCallback<base::flat_map<std::string, uint32_t>>
callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling "
<< cras::kGetNumberOfInputStreamsWithPermission;
std::move(callback).Run(std::nullopt);
return;
}
dbus::MessageReader response_reader(response);
dbus::MessageReader array_reader(nullptr);
base::flat_map<std::string, uint32_t> res;
while (response_reader.HasMoreData()) {
if (!response_reader.PopArray(&array_reader)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::string client_type;
uint32_t num_input_streams;
if (!GetNumerInputStreams(&array_reader, &client_type,
&num_input_streams)) {
LOG(ERROR) << "Error reading number of input streams from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
res[client_type] = num_input_streams;
}
std::move(callback).Run(std::move(res));
}
void OnSetHotwordModel(chromeos::VoidDBusMethodCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to call SetHotwordModel.";
std::move(callback).Run(false);
return;
}
dbus::MessageReader reader(response);
int32_t result;
if (!reader.PopInt32(&result)) {
LOG(ERROR) << "Failed to parse results from SetHotwordModel.";
std::move(callback).Run(false);
return;
}
if (result != 0) {
LOG(ERROR) << "Errors in SetHotwordModel.";
std::move(callback).Run(false);
return;
}
std::move(callback).Run(true);
}
void OnGetAudioEffectDlcs(chromeos::DBusMethodCallback<std::string> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling GetAudioEffectDlcs";
std::move(callback).Run(std::nullopt);
return;
}
std::string audio_effect_dlcs;
dbus::MessageReader reader(response);
if (!reader.PopString(&audio_effect_dlcs)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(audio_effect_dlcs);
VLOG(1) << "cras_audio_client: Retrieved audio effect dlcs: "
<< audio_effect_dlcs;
}
bool ReadVoiceIsolationUIAppearanceFromDBus(
dbus::Message* message,
VoiceIsolationUIAppearance& appearance) {
uint32_t toggle_type = 0;
uint32_t effect_mode_options = 0;
bool show_effect_fallback_message = false;
dbus::MessageReader reader(message);
if (!reader.PopUint32(&toggle_type) ||
!reader.PopUint32(&effect_mode_options) ||
!reader.PopBool(&show_effect_fallback_message)) {
LOG(ERROR) << "Error reading message from cras: " << message->ToString();
return false;
}
appearance.toggle_type = static_cast<cras::AudioEffectType>(toggle_type);
appearance.effect_mode_options = effect_mode_options;
appearance.show_effect_fallback_message = show_effect_fallback_message;
return true;
}
void OnGetVoiceIsolationUIAppearance(
chromeos::DBusMethodCallback<VoiceIsolationUIAppearance> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << "GetVoiceIsolationUIAppearance";
std::move(callback).Run(std::nullopt);
return;
}
VoiceIsolationUIAppearance appearance;
if (!ReadVoiceIsolationUIAppearanceFromDBus(response, appearance)) {
std::move(callback).Run(std::nullopt);
return;
}
VLOG(1) << "cras_audio_client: Retrieved voice isolation appearance: "
<< appearance.ToString();
std::move(callback).Run(std::move(appearance));
}
void OnGetNoiseCancellationSupported(
chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling "
<< "GetNoiseCancellationSupported";
std::move(callback).Run(std::nullopt);
return;
}
bool is_noise_cancellation_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&is_noise_cancellation_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(is_noise_cancellation_supported);
VLOG(1) << "cras_audio_client: Retrieved noise cancellation support: "
<< is_noise_cancellation_supported;
}
void OnGetStyleTransferSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling GetStyleTransferSupported";
std::move(callback).Run(std::nullopt);
return;
}
bool is_style_transfer_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&is_style_transfer_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(is_style_transfer_supported);
VLOG(1) << "cras_audio_client: Retrieved style transfer support: "
<< is_style_transfer_supported;
}
void OnGetHfpMicSrSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling "
<< "IsHfpMicSrSupported";
std::move(callback).Run(std::nullopt);
return;
}
bool is_hfp_mic_sr_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&is_hfp_mic_sr_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(is_hfp_mic_sr_supported);
VLOG(1) << "cras_audio_client: Retrieved hfp_mic_sr support: "
<< is_hfp_mic_sr_supported;
}
void OnGetSpatialAudioSupported(chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << "IsSpatialAudioSupported";
std::move(callback).Run(std::nullopt);
return;
}
bool is_spatial_audio_supported = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&is_spatial_audio_supported)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(is_spatial_audio_supported);
VLOG(1) << "cras_audio_client: Retrieved spatial_audio support: "
<< is_spatial_audio_supported;
}
bool GetAudioNode(dbus::Response* response,
dbus::MessageReader* array_reader,
AudioNode* node) {
while (array_reader->HasMoreData()) {
dbus::MessageReader dict_entry_reader(response);
dbus::MessageReader value_reader(response);
std::string key;
if (!array_reader->PopDictEntry(&dict_entry_reader) ||
!dict_entry_reader.PopString(&key) ||
!dict_entry_reader.PopVariant(&value_reader)) {
return false;
}
if (key == cras::kIsInputProperty) {
if (!value_reader.PopBool(&node->is_input)) {
return false;
}
} else if (key == cras::kIdProperty) {
if (!value_reader.PopUint64(&node->id)) {
return false;
}
} else if (key == cras::kDeviceNameProperty) {
if (!value_reader.PopString(&node->device_name)) {
return false;
}
} else if (key == cras::kTypeProperty) {
if (!value_reader.PopString(&node->type)) {
return false;
}
} else if (key == cras::kNameProperty) {
if (!value_reader.PopString(&node->name)) {
return false;
}
} else if (key == cras::kActiveProperty) {
if (!value_reader.PopBool(&node->active)) {
return false;
}
} else if (key == cras::kPluggedTimeProperty) {
if (!value_reader.PopUint64(&node->plugged_time)) {
return false;
}
} else if (key == cras::kStableDeviceIdProperty) {
if (!value_reader.PopUint64(&node->stable_device_id_v1)) {
return false;
}
} else if (key == cras::kStableDeviceIdNewProperty) {
if (!value_reader.PopUint64(&node->stable_device_id_v2)) {
return false;
}
node->has_v2_stable_device_id = true;
} else if (key == cras::kMaxSupportedChannelsProperty) {
if (!value_reader.PopUint32(&node->max_supported_channels)) {
return false;
}
} else if (key == cras::kAudioEffectProperty) {
if (!value_reader.PopUint32(&node->audio_effect)) {
return false;
}
} else if (key == cras::kNumberOfVolumeStepsProperty) {
if (!value_reader.PopInt32(&node->number_of_volume_steps)) {
return false;
}
}
}
return true;
}
void OnGetSpeakOnMuteDetectionEnabled(
chromeos::DBusMethodCallback<bool> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling "
<< "GetSpeakOnMuteDetectionEnabled";
std::move(callback).Run(std::nullopt);
return;
}
bool speak_on_mute_detection_enabled = false;
dbus::MessageReader reader(response);
if (!reader.PopBool(&speak_on_mute_detection_enabled)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(speak_on_mute_detection_enabled);
}
void OnGetNumStreamIgnoreUiGains(
chromeos::DBusMethodCallback<int32_t> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetNumStreamIgnoreUiGains;
std::move(callback).Run(std::nullopt);
return;
}
int32_t num_stream_ignore_ui_gains = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&num_stream_ignore_ui_gains)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(num_stream_ignore_ui_gains);
}
void OnGetNumberOfArcStreams(chromeos::DBusMethodCallback<int32_t> callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Error calling " << cras::kGetNumberOfArcStreams;
std::move(callback).Run(std::nullopt);
return;
}
int32_t num_arc_streams = 0;
dbus::MessageReader reader(response);
if (!reader.PopInt32(&num_arc_streams)) {
LOG(ERROR) << "Error reading response from cras: "
<< response->ToString();
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(num_arc_streams);
}
raw_ptr<dbus::ObjectProxy> cras_proxy_ = nullptr;
base::ObserverList<Observer>::Unchecked observers_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<CrasAudioClientImpl> weak_ptr_factory_{this};
};
} // namespace
CrasAudioClient::Observer::~Observer() = default;
void CrasAudioClient::Observer::AudioClientRestarted() {}
void CrasAudioClient::Observer::OutputMuteChanged(bool mute_on) {}
void CrasAudioClient::Observer::InputMuteChanged(bool mute_on) {}
void CrasAudioClient::Observer::NodesChanged() {}
void CrasAudioClient::Observer::ActiveOutputNodeChanged(uint64_t node_id) {}
void CrasAudioClient::Observer::ActiveInputNodeChanged(uint64_t node_id) {}
void CrasAudioClient::Observer::OutputNodeVolumeChanged(uint64_t node_id,
int volume) {}
void CrasAudioClient::Observer::InputNodeGainChanged(uint64_t node_id,
int gain) {}
void CrasAudioClient::Observer::HotwordTriggered(uint64_t tv_sec,
uint64_t tv_nsec) {}
void CrasAudioClient::Observer::NumberOfActiveStreamsChanged() {}
void CrasAudioClient::Observer::BluetoothBatteryChanged(
const std::string& address,
uint32_t level) {}
void CrasAudioClient::Observer::NumberOfInputStreamsWithPermissionChanged(
const base::flat_map<std::string, uint32_t>& num_input_streams) {}
void CrasAudioClient::Observer::SurveyTriggered(
const base::flat_map<std::string, std::string>& survey_specific_data) {}
void CrasAudioClient::Observer::SpeakOnMuteDetected() {}
void CrasAudioClient::Observer::EwmaPowerReported(double power) {}
void CrasAudioClient::Observer::NumberOfNonChromeOutputStreamsChanged() {}
void CrasAudioClient::Observer::NumStreamIgnoreUiGains(int32_t num) {}
void CrasAudioClient::Observer::NumberOfArcStreamsChanged() {}
void CrasAudioClient::Observer::SidetoneSupportedChanged(bool supported) {}
void CrasAudioClient::Observer::AudioEffectUIAppearanceChanged(
VoiceIsolationUIAppearance appearance) {}
CrasAudioClient::CrasAudioClient() {
DCHECK(!g_instance);
g_instance = this;
}
CrasAudioClient::~CrasAudioClient() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
// static
void CrasAudioClient::Initialize(dbus::Bus* bus) {
DCHECK(bus);
if (ash::switches::UseFakeCrasAudioClientForDBus()) {
LOG(WARNING) << "Using FakeCrasAudioClient due to switch: "
<< ash::switches::kUseFakeCrasAudioClientForDBus;
InitializeFake();
} else {
new CrasAudioClientImpl(bus);
}
}
// static
void CrasAudioClient::InitializeFake() {
new FakeCrasAudioClient();
}
// static
void CrasAudioClient::Shutdown() {
delete g_instance;
}
// static
CrasAudioClient* CrasAudioClient::Get() {
return g_instance;
}
} // namespace ash
|