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 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730
|
= Spice Protocol
:revnumber: v1.0
:revdate: 01.01.2009
:revremark: Draft 1
Copyright (C) 2009 Red Hat, Inc. +
Licensed under a Creative Commons Attribution-Share Alike 3.0 +
United States License (see
http://creativecommons.org/licenses/by-sa/3.0/us/legalcode) +
:toc:
== Introduction
Spice protocol defines a set of protocol messages for accessing, controlling,
and receiving inputs from remote computing devices (e.g., keyboard, video,
mouse) across networks, and sending output to them. A controlled device can
reside on either side, client and/or server. In addition, the protocol defines
a set of calls for supporting migration of a remote server from one network
address to another. Encryption of transported data, with one exception, was
kept out of the protocol for maximum flexibility in choosing an encryption
method. Spice uses simple messaging and does not depend on any RPC standard or
a specific transport layer.
Spice communication session is split into multiple communication channels
(e.g., every channel is a remote device) in order to have the ability to
control communication and execution of messages according to the channel type
(e.g. QoS encryption), and to add and remove communication channels during run
time (which is supported by spice protocol definition). The following
communication channels are defined in the current protocol definition: a). the
main channel serves as the main spice session connection b). display channel
for receiving remote display updates c). inputs channel for sending mouse and
keyboard events d). cursor channel for receiving pointer shape and position e).
Playback channel for receiving audio stream, and f). Record channel for sending
audio capture. More channel types will be added as the protocol evolves. Spice
also defines a set of protocol definitions for synchronizing channels`
execution on the remote site.
== Common Protocol definition
. Endianness
+
Unless stated otherwise, all data structures are packed and byte and bit order
is in little endian format.
+
. Data types
+
.. UINT8 – 8 bits unsigned integer
.. INT16 – 16 bits signed integer
.. UINT16 – 16 bits unsigned integer
.. UINT32 – 32 bits unsigned integer
.. INT32 - 32 bits signed integer
.. UINT64 – 64 bits unsigned integer
.. SPICE_ADDRESS - 64 bits unsigned integer, value is the offset of the addressed
data from the beginning of spice protocol message body (i.e., data following
SpiceDataHeader or SpicedSubMessage).
.. SPICE_FIXED28_4 – 32 bits fixed point number. 28 high bits are signed integer. Low
4 bits is unsigned integer numerator of a fraction with denominator 16.
.. POINT
+
INT32 x +
INT32 y +
+
.. POINT16
+
INT16 x +
INT16 y +
+
.. RECT
+
INT32 top +
INT32 left +
INT32 bottom +
INT32 right +
+
.. POINTFIX
+
SPICE_FIXED28_4 x +
SPICE_FIXED28_4 y +
+
. Protocol Magic number UINT8[4]
+
SPICE_MAGIC = { 0x52, 0x45, 0x44, 0x51} // "REDQ"
+
. Protocol version
+
Protocol version defined as two UINT32 values, major protocol version and
minor protocol version. Server and client having the same major version must
keep compatibility regardless of minor version (i.e., incrementing the major
version brakes compatibility). Major protocol version with "huge" value are
reserved for development purposes and are considered unsupported and
unreliable. "huge" values are defined as having bit 31 set. The minor protocol
version is incremented on every protocol change that does not break
compatibility. It is set to zero on major protocol version increment.
+
.. Current Protocol version
+
[source,c]
----
SPICE_VERSION_MAJOR = 2
SPICE_VERSION_MINOR = 2
----
+
. Compatibility – UINT32[]
+
In order to allow some degree of flexibility in client and server
implementation and in order to improve compatibility, spice protocol supports
bidirectional exchange of channels compatibilities. Compatibilities are
expressed in UINT32 vector that is split into two groups: common
compatibilities and channels compatibilities. Common compatibilities stands for
compatibilities shared by all channels, and channels compatibilities stands
for channel specific compatibilities. Splitting the vector into two types
allows us to add channel compatibilities independently. Each compatibility is
expressed using one or more bits in the compatibilities vector.
For example capability 0 will be the low bit of the first (index 0) UINT32.
+
. Channel types – UINT8
+
[source,c]
----
SPICE_CHANNEL_MAIN = 1
SPICE_CHANNEL_DISPLAY = 2
SPICE_CHANNEL_INPUTS = 3
SPICE_CHANNEL_CURSOR = 4
SPICE_CHANNEL_PLAYBACK = 5
SPICE_CHANNEL_RECORD = 6
SPICE_CHANNEL_TUNNEL = 7 // obsolete
SPICE_CHANNEL_SMARTCARD = 8
SPICE_CHANNEL_USBREDIR = 9
SPICE_CHANNEL_PORT = 10
SPICE_CHANNEL_WEBDAV = 11
----
+
. Error codes UINT32
+
[source,c]
----
SPICE_LINK_ERR_OK = 0
SPICE_LINK_ERR_ERROR = 1
SPICE_LINK_ERR_INVALID_MAGIC = 2
SPICE_LINK_ERR_INVALID_DATA = 3
SPICE_LINK_ERR_VERSION_MISMATCH = 4
SPICE_LINK_ERR_NEED_SECURED = 5
SPICE_LINK_ERR_NEED_UNSECURED = 6
SPICE_LINK_ERR_PERMISSION_DENIED = 7
SPICE_LINK_ERR_BAD_CONNECTION_ID = 8
SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE = 9
----
+
. Warning codes
+
[source,c]
----
SPICE_WARN_GENERAL = 0
----
+
. Information codes
+
[source,c]
----
SPICE_INFO_GENERAL = 0
----
+
. public key buffer size.
+
[source,c]
----
SPICE_TICKET_PUBKEY_BYTES = 162 /* size needed for holding 1024 bit RSA public
key in X.509 SubjectPublicKeyInfo format. */
----
+
. Channel link: establishing a channel connection.
+
.. Connection process
+
The channel connection process is initiated by the client. The client sends
SpiceLinkMess. In response, the server sends SpiceLinkReply. When the client
receives SpiceLinkReply, it examines the error code and in case there is no
error it encrypts its password with public key received in SpiceLinkReply and
sends it to the server. The server receive the password and sends the link
result to the client. The client examines the link result, and in case the
result equals to SPICE_LINK_ERR_OK, a valid connection is established.
+
Channel connection for channel types other then SPICE_CHANNEL_MAIN is allowed
only after the client has active SPICE_CHANNEL_MAIN channel connection. Only one
SPICE_CHANNEL_MAIN connection is allowed, and this channel connection establishes
spice session with the remote server.
+
.. Ticketing
+
Ticketing is a mechanism implemented in spice to ensure connections are opened
only from authorized sources. To enable this mechanism a ticket is set in spice
server consisting of a password and time validity. After time validity passes,
the whole ticket is expired. The ticket is encrypted. To encrypt, server
generates a 1024 bit RSA key and send the public part to the client (via
RedLinkInfo). Client uses this key to encrypt the password and send it back to
server (after SpiceLinkMess). Server decrypt the password, compare it to ticket
and ensure it was received within the allowed time-frame.
+
.. SpiceLinkMess definition.
+
[cols="2*"]
|===
|UINT32 magic
|value of this fields must be equal to SPICE_MAGIC
|UINT32 major_version
| value of this fields must be equal to SPICE_VERSION_MAJOR
|UINT32 minor_version
|value of this fields must be equal to SPICE_VERSION_MINOR
|UINT32 size
|number of bytes following this field to the end of this message.
|UINT32 connection_id
|In case of a new session (i.e., channel type is SPICE_CHANNEL_MAIN) this field
is set to zero, and in response the server will allocate session id and will
send it via the SpiceLinkReply message. In case of all other channel types, this
field will be equal to the allocated session id.
|UINT8 channel_type
|one of SPICE_CHANNEL_?
|UINT8 channel_id
|channel id to connect to. This enables having multiple channels of the same
type.
|UINT32 num_common_caps
|number of common client channel capabilities words
|UINT32 num_channel_caps
|number of specific client channel capabilities words
|UINT32 caps_offset
|location of the start of the capabilities vector given by the bytes offset
from the “ size” member (i.e., from the address of the “connection_id” member).
|===
+
.. SpiceLinkReply definition
+
[cols="2*"]
|===
|UINT32 magic
|value of this field must be equal to SPICE_MAGIC
|UINT32 major_version
|server major protocol version.
|UINT32 minor_version
|server minor protocol version.
|UINT32 size
|number of bytes following this field to the end of this message.
|UINT32 error
|Error codes (i.e., SPICE_LINK_ERR_?)
|UINT8[SPICE_TICKET_PUBKEY_BYTES] pub_key
|1024 bit RSA public key in X.509 SubjectPublicKeyInfo format.
|UINT32 num_common_caps
|number of common server channel capabilities words
|UINT32 num_channel_caps
|number of specific server channel capabilities words
|UINT32 caps_offset
|location of the start of the capabilities vector given by the bytes offset
from the “ size” member (i.e., from the address of
the “connection_id” member)
|===
+
.. Encrypted Password
+
Client sends RSA encrypted password, with public key received from server (in
SpiceLinkReply). Format is EME-OAEP as described in PKCS#1 v2.0 with SHA-1, MGF1
and an empty encoding parameter.
+
.. Link Result UINT32
+
The server sends link result error code (i.e., SPICE_LINK_ERR_?)
+
. Protocol message definition
+
All messages transmitted after the link stage have a common message layout. It
begins with SpiceDataHeader which describes one main message and an optional sub
messages list.
+
.. SpiceDataHeader
+
[cols="2*"]
|===
|UINT64 serial
|serial number of the message within the channel. Serial numbers start with a
value of 1 and are incremented on every message transmitted.
|UINT16 type
|message type can be one that is accepted by all channel (e.g., SPICE_MSG_MIGRATE),
or specific to a channel type (e.g., SPICE_MSG_DISPLAY_MODE for display channel).
|UINT32 size
|size of the message body in bytes. In case sub_list (see below) is not zero
then the actual main message size is sub_list. The message body follows
SpiceDataHeader
|UINT32 sub_list
|optional sub-messages list. If this field is not zero then sub_list is the
offset in bytes to SpiceSubMessageList from the end of SpiceDataHeader. All
sub-messages need to be executed before the main message, and in the order they
appear in the sub-messageslist.
|===
+
.. SpiceSubMessageList
+
[cols="2*"]
|===
|UINT16 size
|number of sub-messages in this list.
|UINT32[] sub_messages
|array of offsets to sub message, offset is number of bytes from the end of
SpiceDataHeader to start of SpicedSubMessage.
|===
+
.. SpicedSubMessage
+
[cols="2*"]
|===
|UINT16 type
|message type can be one that is accepted by all channel (e.g., SPICE_MSG_MIGRATE),
or specific to a channel type (e.g., SPICE_MSG_DISPLAY_MODE for display channel).
|UINT32 size
|size of the message body in bytes. The message body follows SpicedSubMessage.
|===
+
. Common messages and messaging naming convention
+
Messages types and message body structures are prefixed according to the
source of the message. The prefixes for messages sent from the server to the
client are SPICE_MSG for types and SpiceMsg for structures. For messages sent from the
client the prefixes are SPICE_MSGC and SpiceMsgc.
+
. Server messages that are common to all channels
+
[source,c]
----
SPICE_MSG_MIGRATE = 1
SPICE_MSG_MIGRATE_DATA = 2
SPICE_MSG_SET_ACK = 3
SPICE_MSG_PING = 4
SPICE_MSG_WAIT_FOR_CHANNELS = 5
SPICE_MSG_DISCONNECTING = 6
SPICE_MSG_NOTIFY = 7
SPICE_MSG_FIRST_AVAIL = 101
----
+
Specific channel server messages start from SPICE_MSG_FIRST_AVAIL. All
message types from SPICE_MSG_NOTIFY + 1 to SPICE_MSG_FIRST_AVAIL – 1 are reserved
for further use.
+
. Client messages that are common to all channels
+
[source,c]
----
SPICE_MSGC_ACK_SYNC = 1
SPICE_MSGC_ACK = 2
SPICE_MSGC_PONG = 3
SPICE_MSGC_MIGRATE_FLUSH_MARK = 4
SPICE_MSGC_MIGRATE_DATA = 5
SPICE_MSGC_DISCONNECTING = 6
SPICE_MSGC_FIRST_AVAIL = 101
----
+
Specific channel client messages start from SPICE_MSGC_FIRST_AVAIL. All
message types from SPICE_MSGC_ACK_SYNC+ 1 to SPICE_MSGC_FIRST_AVAIL – 1 are
reserved for further use.
+
. Messages acknowledgment.
+
Spice provides a set of messages for requesting an acknowledgment on every one
or more messages that the client consumes. In order to request acknowledgment
messages, the server sends SPICE_MSG_SET_ACK with the requested acknowledgment
frequency – after how many received messages the client sends acknowledgment. .
In response, the client sends SPICE_MSGC_ACK_SYNC. From this point, for every
requested number of messages that the client receive, it will send a SPICE_MSGC_ACK
message.
+
.. SPICE_MSG_SET_ACK, SpiceMsgSetAck
+
[cols="2*"]
|===
|UINT32 generation
|the generation of the acknowledgment sequence. This value will be sent back by
SPICE_MSGC_ACK_SYNC. It is used for acknowledgment accounting synchronization.
|UINT32 window
|the window size. Spice client will send acknowledgment for every “window”
messages. Zero window size will disable messages acknowledgment.
|===
+
.. SPICE_MSGC_ACK_SYNC, UINT32
+
[cols="2*"]
|===
|UINT32
|Spice client sends SpiceMsgSetAck.generation in response to SPICE_MSG_SET_ACK
|===
+
.. SPICE_MSGC_ACK, VOID
+
Spice client sends SPICE_MSGC_ACK message for every SpiceMsgSetAck.window messages it
consumes.
+
. Ping
+
Spice protocol provides ping messages for debugging purpose. Spice server sends
SPICE_MSG_PING and the client responses with SPICE_MSGC_PONG. The server can measure round
trip time by subtracting current time with the time that is returned in
SPICE_MSGC_PONG message.
+
.. SPICE_MSG_PING, SpiceMsgPing
+
[cols="2*"]
|===
|UINT32 id
|the id of this message
|UINT64 time
|time stamp of this message
|===
+
.. SPICE_MSGC_PONG, SpiceMsgPing
+
[cols="2*"]
|===
|UINT32 id
|Spice client copies it from SpiceMsgPing.id
|UINT64 time
|Spice client copies it from SpiceMsgPing.time
|===
+
. Channel migration
+
Spice supports migration of Spice server. The following common messages
combined with specific main channel messages is used for migrating channels
connections between spice servers. We will refer these servers as source and
destination. Main channel is used for initiating and controlling the migration
process. The following describes the actual channel migration process.
+
Channel migration process starts with sending SPICE_MSG_MIGRATE message from the
server. The client receives the message, examine the attached flags and: if the
server requests messages flush (i.e., SPICE_MIGRATE_NEED_FLUSH flag is on), the
client sends SPICE_MSGC_MIGRATE_FLUSH_MARK message to the server. This procedure can
be used to ensure safe delivery of all mid air messages before performing the
migration action. if the server requests data transfer (i.e.,
SPICE_MIGRATE_NEED_DATA_TRANSFER flag is on), the client expects to receive one
last message from the server before migrating to destination. This message type
must be SPICE_MSG_MIGRATE_DATA type. The content of the received message will be
transmitted to the destination on connection swap.
+
Afterward, the client swaps communication channels (i.e., starts using the
connection with the destination server). The client can close connection with
the source server only after all other channels also have finished the
migration process. If the server side has requested data transfer, the client
first transmits SPICE_MSGC_MIGRATE_DATA message containing the data received on
SPICE_MSG_MIGRATE_DATA.
+
.. Migration flags
+
[source,c]
----
SPICE_MIGRATE_NEED_FLUSH = 1
SPICE_MIGRATE_NEED_DATA_TRANSFER = 2
----
+
.. SPICE_MSG_MIGRATE, SpiceMsgMigrate
+
[cols="2*"]
|===
|UINT32 flags
|combination of SPICE migration flags.
|===
+
... SPICE_MSG_MIGRATE_DATA, UINT8[]
+
Server migrate data, body of this message is variable length raw data that is
determined by each channel type independently
+
... SPICE_MSGC_MIGRATE_FLUSH_MARK, VOID
+
This messages mark completion of client communication channel flushing.
+
.. SPICE_MSGC_MIGRATE_DATA, UINT8[]
+
Post migration data, sent by client to the destination, containing the data
sent by the source using the SPICE_MSG_MIGRATE_DATA message.
+
[[channel_sync]]
. Channel synchronization
+
Spice provides mechanism for synchronizing channels message execution on the
client side. The server sends SPICE_MSG_WAIT_FOR_CHANNELS message which contains a
list of channels messages to wait for (i.e., SpiceMsgWaitForChannels). The Spice
client will wait for completion of all the messages that are in that list
before executing any more messages.
+
.. SpiceWaitForChannel
+
[cols="2*"]
|===
|UINT8 type
|channel type (e.g., SPICE_CHANNEL_INPUTS)
|UINT8 id
|channel id.
|UIN64 serial
|message serial id (i.e, SpiceDataHeader.serial) to wait for
|===
+
... SPICE_MSG_WAIT_FOR_CHANNELS, SpiceMsgWaitForChannels
+
[cols="2*"]
|===
|UINT8 wait_count
|number of items in wait_list
|SpiceWaitForChannel[] wait_list
|list of channels to wait for.
|===
+
. Disconnect reason
+
The following messages are used for notification about orderly disconnection
of the server or client.
+
.. SPICE_MSG_DISCONNECTING, SpiceMsgDisconnect
+
[cols="2*"]
|===
|UINT64 time_stamp
|time stamp of disconnect action on the server.
|UINT32 reason
|disconnect reason, SPICE_LINK_ERR_?
|===
+
.. SPICE_MSGC_DISCONNECTING, SpiceMsgDisconnect
+
[cols="2*"]
|===
|UINT64 time_stamp
|time stamp of disconnect action on the client.
|UINT32 reason
|disconnect reason, SPICE_LINK_ERR_?
|===
+
. Server notification
+
Spice protocol defines message for delivering notifications to the client using
SPICE_MSG_NOTIFY message. Messages are categorized by severity and visibility. The
later can be used as hint for the way the message is displayed to the user. For
example high visibility notifications will trigger message box and low
visibility notifications will be directed to the log.
+
.. SPICE_MSG_NOTIFY, SpiceMsgNotify
+
[cols="2*"]
|===
|UINT64 time_stamp
|server side time stamp of this message.
|UINT32 severity
|one of SPICE_NOTIFY_SEVERITY_?
|UINT32 visibility
|one of SPICE_NOTIFY_VISIBILITY_?
|UINT32 what
|one of SPICE_LINK_ERR_?, SPICE_WARN_? Or SPICE_INFO_?, depending on severity.
|UINT32 message_len
|size of message
|UINT8[] message
|message string in UTF8.
|UINT8 0
|string zero termination
|===
== Main Channel definition
. Server messages
+
[source,c]
----
SPICE_MSG_MAIN_MIGRATE_BEGIN = 101
SPICE_MSG_MAIN_MIGRATE_CANCEL = 102
SPICE_MSG_MAIN_INIT = 103
SPICE_MSG_MAIN_CHANNELS_LIST = 104
SPICE_MSG_MAIN_MOUSE_MODE = 105
SPICE_MSG_MAIN_MULTI_MEDIA_TIME = 106
SPICE_MSG_MAIN_AGENT_CONNECTED = 107
SPICE_MSG_MAIN_AGENT_DISCONNECTED = 108
SPICE_MSG_MAIN_AGENT_DATA = 109
SPICE_MSG_MAIN_AGENT_TOKEN = 110
----
+
. Client messages
+
[source,c]
----
SPICE_MSGC_MAIN_CLIENT_INFO = 101
SPICE_MSGC_MAIN_MIGRATE_CONNECTED = 102
SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR = 103
SPICE_MSGC_MAIN_ATTACH_CHANNELS = 104
SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST = 105
SPICE_MSGC_MAIN_AGENT_START = 106
SPICE_MSGC_MAIN_AGENT_DATA = 107
SPICE_MSGC_MAIN_AGENT_TOKEN = 108
----
+
. Migration control
+
Spice migration control is performed using the main channel messages. Spice
server initiates migration process by sending SPICE_MSG_MAIN_MIGRATE_BEGIN message.
Once the client has completed its pre-migrate procedure it notifies the server
by transmitting SPICE_MSGC_MAIN_MIGRATE_CONNECTED message. In case of pre-migrate
procedure error, the client sends SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR. Once the server
receives SPICE_MSGC_MAIN_MIGRATE_CONNECTED he can commence the migration process. The
server can send SPICE_MSG_MAIN_MIGRATE_CANCEL in order to instruct the client to
cancel the migration process.
+
.. SPICE_MSG_MAIN_MIGRATE_BEGIN, SpiceMsgMainMigrationBegin
+
[cols="2*"]
|===
|UINT16 port
|port of destination server
|UINT16 sport
|secure port of destination server
|UINT8[] host_name
|host name of destination server
|===
+
.. SPICE_MSG_MAIN_MIGRATE_CANCEL, VOID
+
Instruct the client to cancel migration process
+
.. SPICE_MSGC_MAIN_MIGRATE_CONNECTED, VOID
+
Notify the server of successful completion of the pre-migrate stage
+
.. SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR, VOID
+
Notify the server of pre-migrate stage error
+
[[mouse_modes]]
. Mouse modes
+
Spice protocol specifies two mouse modes, client mode and server mode. In
client mode, the affective mouse is the client side mouse: the client sends
mouse position within the display and the server sends mouse shape messages. In
server mode, the client sends relative mouse movements and the server sends
position and shape commands. Spice main channel is used for mouse mode control.
+
.. Modes
+
[source,c]
----
SPICE_MOUSE_MODE_SERVER = 1
SPICE_MOUSE_MODE_CLIENT = 2
----
+
.. SPICE_MSG_MAIN_MOUSE_MODE, SpiceMsgMainMouseMode
+
Spice server sends this message on every mouse mode change
+
[cols="2*"]
|===
|UINT32 supported_modes
|current supported mouse mode, this is any combination of SPICE_MOUSE_MODE_?
|UINT32 current_mode
|the current mouse mode. Can be one of SPICE_MOUSE_MODE_?
|===
+
.. SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST, UINT32
+
Spice client sends this message to request specific mouse mode. It is not
guarantied that the server will accept the request. Only on receiving
SPICE_MSG_MAIN_MOUSE_MODE message, the client can know of actual mouse mode change.
+
[cols="2*"]
|===
|UINT32
|requested mode, one of SPICE_MOUSE_MODE_?
|===
+
. Main channel init message
+
Spice server must send SpiceMsgMainInit as the first transmitted message t and is
disallowed to send it at any other point.
+
.. SPICE_MSG_MAIN_INIT, SpiceMsgMainInit
+
[cols="2*"]
|===
|UINT32 session_id
|session id is generated by the server. This id will be send on every new
channel connection within this session (i.e., in SpiceLinkMess.connection_id).
|UINT32 display_channels_hint
|optional hint of expected number of display channels. Zero is defined as an
invalid value
|UINT32 supported_mouse_modes
|supported mouse modes. This is any combination of SPICE_MOUSE_MODE_?
|UINT32 current_mouse_mode
|the current mouse mode, one of SPICE_MOUSE_MODE_?
|UINT32 agent_connected
|current state of Spice agent (see <<spice_agent,This Section>>), 0 and 1 stand
for disconnected and connected state respectively.
|UINT32 agent_tokens
|number of available tokens for sending messages to Spice agent.
|UINT32 multi_media_time
|current server multimedia time. The multimedia time is used for synchronizing
video (for more information see <<multimedia_time,Multimedia time>>)
|UINT32 ram_hint
|optional hint for help in determining global LZ compression dictionary size
(for more information see section <<spice_image,Spice Image>> in “Display
Channel”).
|===
+
. Server side channels notification
+
In order to have the ability to dynamically attach to the server side channels,
Spice protocol includes SPICE_MSG_MAIN_CHANNELS_LIST message. This massage informs
the client of available channels in the server side. In response to this
message the client can decide to link with the new available channel(s). The
server must receive SPICE_MSGC_MAIN_ATTACH_CHANNELS before sending any
SPICE_MSG_MAIN_CHANNELS_LIST message.
+
.. SPICE_MSG_MAIN_CHANNELS_LIST, SpiceMsgChannels
+
[cols="2*"]
|===
|UINT32 num_of_channels
|number of channels in this list
|SpiceChannelId[] channels
|vector of “num_of_channels” channel ids
|===
+
.. SpiceChannelId
+
[cols="2*"]
|===
|UINT8 type
|channel type, one of SPICE_CHANNEL_? channel types, except for SPICE_CHANNEL_MAIN
|UINT8 id
|channel id
|===
+
[[multimedia_time]]
. Multimedia time
+
Spice defines messages for setting multimedia time for synchronization of video
and audio streams. Two methods for updating multimedia time are supported. The
first method uses the time stamp of data that arrives on the playback
channel.The second method uses the main channel SPICE_MSG_MAIN_MULTI_MEDIA_TIME
message. The latter method is used when no active playback channel exist.
+
.. SPICE_MSG_MAIN_MULTI_MEDIA_TIME, UINT32
+
[cols="2*"]
|===
|UINT32
|multimedia time
|===
+
[[spice_agent]]
. Spice agent
+
Spice protocol defines a set of messages for bidirectional communication
channel between Spice client and spice client agent on the remote server. Spice
provides a communication channel only, the actual transferred data content is
opaque to the protocol. This channel can be used for various purposes, for
example, client-guest clipboard sharing, authentication and display
configuration.
+
Spice client receives notifications of remote site agent connection as part of
the SPICE_MSG_MAIN_INIT message or by a specific server SPICE_MSG_MAIN_AGENT_CONNECTED.
Remote agent disconnection notification is delivered by
SPICE_MSG_MAIN_AGENT_DISCONNECTED message. A bidirectional tokens mechanism is used
in order to prevent blocking of the main channel with agent messages (e.g., in
case the agent stops consuming the data). Each side is not allowed to send more
messages than the tokens allocated to it by the other side. The number of
tokens that are allocated for the client is initialized from SPICE_MSG_MAIN_INIT
message, and farther allocation of tokens is done using SPICE_MSG_MAIN_AGENT_TOKEN.
Server tokens initial count is delivered in SPICE_MSGC_MAIN_AGENT_START message. This
message must be the first agent related message that the client sends to the
server. Farther tokens allocation for the server is done using
SPICE_MSGC_MAIN_AGENT_TOKEN. Actual data packets are delivered using
SPICE_MSG_MAIN_AGENT_DATA and SPICE_MSGC_MAIN_AGENT_DATA.
+
.. Although agent messages are opaque for the protocol, agent data stream is
defined by Spice protocol in order to delineate messages. Still, the
client-server communication is independent from the agent channel, e.g., agent
protocol conflicts don't affect the rest of the channels. Agent stream is
defined as a run of messages having the following format:
+
[cols="2*"]
|===
|UINT32 protocol
|unique protocol of this message. The protocol id must be registered in order
to prevent conflicts.
|UINT32 type
|protocol dependent message type.
|UINT64 opaque
|protocol dependent opaque data.
|UINT32 size
|size of data in bytes.
|UINT8 data[0]
|data of this message.
|===
+
Client and server must continue processing unknown protocols messages or
messages having unknown type (i.e., receive and dump).
+
.. SPICE_MSG_MAIN_AGENT_CONNECTED, VOID
.. SPICE_MSG_MAIN_AGENT_DISCONNECTED, UINT32
+
[cols="2*"]
|===
|UINT32
|disconnect error code SPICE_LINK_ERR_?
|===
+
.. SPICE_AGENT_MAX_DATA_SIZE = 2048
.. SPICE_MSG_MAIN_AGENT_DATA, UINT8[]
+
Agent packet is the entire message body (i.e. SpiceDataHeader.size). The maximum
packet size is SPICE_AGENT_MAX_DATA_SIZE.
+
.. SPICE_MSG_MAIN_AGENT_TOKEN, UINT32
+
[cols="2*"]
|===
|UINT32
|allocated tokens count for the client
|===
+
.. SPICE_MSGC_MAIN_AGENT_START, UINT32
+
[cols="2*"]
|===
|UINT32
|allocated tokens count for the server
|===
+
.. SPICE_MSGC_MAIN_AGENT_DATA, UINT8[]
+
Agent packet is the entire message body (i.e. SpiceDataHeader.size). The maximum
packet size is SPICE_AGENT_MAX_DATA_SIZE.
+
.. SPICE_MSGC_MAIN_AGENT_TOKEN, UINT32
+
[cols="2*"]
|===
|UINT32
|allocated tokens count for the server
|===
== Inputs channel definition
Spice Inputs channel controls the server mouse and the keyboard.
. Client messages
+
[source,c]
----
SPICE_MSGC_INPUTS_KEY_DOWN = 101
SPICE_MSGC_INPUTS_KEY_UP = 102
SPICE_MSGC_INPUTS_KEY_MODIFIERS = 103
SPICE_MSGC_INPUTS_MOUSE_MOTION = 111
SPICE_MSGC_INPUTS_MOUSE_POSITION = 112
SPICE_MSGC_INPUTS_MOUSE_PRESS = 113
SPICE_MSGC_INPUTS_MOUSE_RELEASE = 114
----
+
. Server Messages
+
[source,c]
----
SPICE_MSG_INPUTS_INIT = 101
SPICE_MSG_INPUTS_KEY_MODIFIERS = 102
SPICE_MSG_INPUTS_MOUSE_MOTION_ACK = 111
----
+
. Keyboard messages
+
Spice supports sending keyboard key events and keyboard leds synchronization.
The client sends key event using SPICE_MSGC_INPUTS_KEY_DOWN and SPICE_MSGC_INPUTS_KEY_UP
messages. Key value is expressed using PC AT scan code (see
<<key_code,KeyCode>>). Keyboard leds synchronization is done by sending
SPICE_MSG_INPUTS_KEY_MODIFIERS message by the server or by sending
SPICE_MSGC_INPUTS_KEY_MODIFIERS by the client, these messages contain keyboard leds
state. Keyboard modifiers is also sent by the server using SPICE_MSG_INPUTS_INIT,
this message must be sent as the first server message and the server mustn't
send it at any other point.
+
.. Keyboard led bits
+
[source,c]
----
SPICE_SCROLL_LOCK_MODIFIER = 1
SPICE_NUM_LOCK_MODIFIER = 2
SPICE_CAPS_LOCK_MODIFIER = 4
----
+
.. SPICE_MSG_INPUTS_INIT, UINT32
+
[cols="2*"]
|===
|UINT32
|any combination of keyboard led bits. If bit is set then the led is on.
|===
+
.. SPICE_MSG_INPUTS_KEY_MODIFIERS, UINT32
+
[cols="2*"]
|===
|UINT32
|any combination of keyboard led bits. If bit is set then the led is on.
|===
+
.. SPICE_MSGC_INPUTS_KEY_MODIFIERS, UINT32
+
[cols="2*"]
|===
|UINT32
|any combination of keyboard led bits. If bit is set then the led is on.
|===
+
[[key_code]]
.. KeyCode
+
[cols="2*"]
|===
|UINT8[4]
|the value of key code is a PC AT scan code. The code is composed by up to four
bytes for supporting extended codes. A code is terminated by a zero byte.
|===
+
.. SPICE_MSGC_INPUTS_KEY_DOWN, KeyCode
+
[cols="2*"]
|===
|KeyCode
|client sends this message to notify of key press event.
|===
+
.. SPICE_MSGC_INPUTS_KEY_UP, KeyCode
+
KeyCode – client sends this message to notify of key release event.
+
. Mouse messages
+
spice support two modes of mouse operation: client mouse and server mouse (for
more information see <<mouse_modes,mouse modes>>). in server mouse mode the
client sends mouse motion message (i.e., msgc_inputs_mouse_motion), and in
client mouse mode it sends position message (i.e., msgc_inputs_mouse_position).
position message holds the position of the client mouse on the display and the
id of the display channel, which is derived from SpiceLinkMess.channel_id. in
order to prevent flood of mouse motion/position events, the server sends
red_inputs_mouse_motion_ack message on every red_motion_ack_bunch messages it
receive. this mechanism allows the client to keep track on the server's
messages consumption rate and to change the event pushing policy according to
it. mouse button events are sent to the server using msgc_inputs_mouse_press
and msgc_inputs_mouse_release messages.
+
.. Spice Button ID
+
[source,c]
----
SPICE_MOUSE_BUTTON_LEFT = 1, left button
SPICE_MOUSE_BUTTON_MIDDLE = 2, middle button
SPICE_MOUSE_BUTTON_RIGHT = 3, right button
SPICE_MOUSE_BUTTON_UP = 4, scroll up button
SPICE_MOUSE_BUTTON_DOWN = 5, scroll down button
----
+
.. Buttons masks
+
[source,c]
----
SPICE_MOUSE_BUTTON_MASK_LEFT = 1, left button mask
SPICE_MOUSE_BUTTON_MASK_MIDDLE = 2, middle button mask
SPICE_MOUSE_BUTTON_MASK_RIGHT = 4, right button mask
----
+
.. SPICE_INPUT_MOTION_ACK_BUNCH
+
[source,c]
----
SPICE_INPUT_MOTION_ACK_BUNCH = 4
----
+
.. SPICE_MSGC_INPUTS_MOUSE_MOTION, SpiceMsgcMouseMotion
+
[cols="2*"]
|===
|INT32 dx
|number of pixels the mouse had moved on x axis
|INT32 dy
|number of pixels the mouse had moved on y axis
|UINT32 buttons_state
|any combination of buttons mask. Set bit describe pressed button and clear bit
describe unpressed button.
|===
+
.. SPICE_MSGC_INPUTS_MOUSE_POSITION, SpiceMsgcMousePosition
+
[cols="2*"]
|===
|UINT32 x
|position on x axis
|UINT32 y
|position on y axis
|UINT32 buttons_state
|any combination of buttons mask. Set bit describe pressed button and clear bit
describe unpressed button.
|UINT8 display_id
|id of the display that client mouse is on.
|===
+
.. SPICE_MSGC_INPUTS_MOUSE_PRESS, SpiceMsgcMousePress
+
[cols="2*"]
|===
|UINT32 button
|one of SPICE_MOUSE_?BUTTON
|UINT32 buttons_state
|any combination of buttons masks. Set bit describes pressed button, and clear
bit describes unpressed button.
|===
+
.. SPICE_MSGC_INPUTS_MOUSE_RELEASE, SpiceMsgcMouseRelease
+
[cols="2*"]
|===
|UINT32 button
|one of SPICE_MOUSE_?BUTTON
|UINT32 buttons_state
|any combination of buttons mask. Set bit describes pressed button and clear
bit describes unpressed button.
|===
== Display channel definition
Spice protocol defines a set of messages for supporting rendering of the remote
display area on the client display. The protocol supports rendering of graphics
primitives (e.g., lines, images) and video streams. The protocol also supports
caching of images and color palettes on the client side. Spice display channel
supports several images compression methods for reducing network traffic.
. Server messages
+
[source,c]
----
SPICE_MSG_DISPLAY_MODE = 101
SPICE_MSG_DISPLAY_MARK = 102
SPICE_MSG_DISPLAY_RESET = 103
SPICE_MSG_DISPLAY_COPY_BITS = 104
SPICE_MSG_DISPLAY_INVAL_LIST = 105
SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS = 106
SPICE_MSG_DISPLAY_INVAL_PALETTE = 107
SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES = 108
SPICE_MSG_DISPLAY_STREAM_CREATE = 122
SPICE_MSG_DISPLAY_STREAM_DATA = 123
SPICE_MSG_DISPLAY_STREAM_CLIP = 124
SPICE_MSG_DISPLAY_STREAM_DESTROY = 125
SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL = 126
SPICE_MSG_DISPLAY_DRAW_FILL = 302
SPICE_MSG_DISPLAY_DRAW_OPAQUE = 303
SPICE_MSG_DISPLAY_DRAW_COPY = 304
SPICE_MSG_DISPLAY_DRAW_BLEND = 305
SPICE_MSG_DISPLAY_DRAW_BLACKNESS = 306
SPICE_MSG_DISPLAY_DRAW_WHITENESS = 307
SPICE_MSG_DISPLAY_DRAW_INVERS = 308
SPICE_MSG_DISPLAY_DRAW_ROP3 = 309
SPICE_MSG_DISPLAY_DRAW_STROKE = 310
SPICE_MSG_DISPLAY_DRAW_TEXT = 311
SPICE_MSG_DISPLAY_DRAW_TRANSPARENT = 312
SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND = 313
----
+
. Client messages
+
[source,c]
----
SPICE_MSGC_DISPLAY_INIT = 101
----
+
. Operation flow
+
Spice server sends to the client a mode message using SPICE_MSG_DISPLAY_MODE for
specifying the current draw area size and format. In response the client
creates a draw area for rendering all the followed rendering commands sent by
the server. The client will expose the new remote display area content (i.e.,
after mode command) only after it receives a mark command (i.e.,
SPICE_MSG_DISPLAY_MARK) from the server. The server can send a reset command using
SPICE_MSG_DISPLAY_RESET to instruct the client to drop its draw area and palette
cache. Sending mode message is allowed only while no active draw area exists
on the client side. Sending reset message is allowed only while active draw
area exists on client side. Sending mark message is allowed only once, between
mode and reset messages. Draw commands, copy bits command and stream commands
are allowed only if the client have an active display area (i.e., between
SPICE_MSG_DISPLAY_MODE to SPICE_MSG_DISPLAY_RESET).
+
On channel connection, the client optionally sends an init message, using
SPICE_MSGC_DISPLAY_INIT, in order to enable image caching and global dictionary
compression. The message includes the cache id and its size and the size of the
dictionary compression window. These sizes and id are determined by the client.
It is disallowed to send more then one init message.
+
Color pallets cache are manged by the server.
Items cache insertion commands are sent as part of the rendering commands.
Cache items removal are sent explicitly using SPICE_MSG_DISPLAY_INVAL_LIST or
SPICE_MSG_DISPLAY_INVAL_LIST server messages. Resetting client caches is done by
sending SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS or SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES server
messages.
+
. Draw area control
+
.. SPICE_MSG_DISPLAY_MODE, SpiceMsgDisplayMode
+
[cols="2*"]
|===
|UINT32 width
|width of the display area
|UINT32 height
|height of the display area
|UINT32 depth
|color depth of the display area. Valid values are 16bpp or 32bpp.
|===
+
.. SPICE_MSG_DISPLAY_MARK, VOID
+
Mark the beginning of the display area visibility
+
.. SPICE_MSG_DISPLAY_RESET, VOID
+
Drop current display area of the channel and reset palette cache
+
. Raster operation descriptor
+
The following defines a set of flags for describing raster operations that can
be applied on a source image, source brush, destination and the result during a
rendering operation. Combination of those flags defines the necessary steps
that are needed to be preformed during a rendering operation. In the
following definitions of rendering commands this combination is referred to by
'rop_descriptor'.
+
[source,c]
----
SPICE_ROPD_INVERS_SRC = 1
----
+
Source Image need to be inverted before rendering
+
[source,c]
----
SPICE_ROPD_INVERS_BRUSH = 2
----
+
SpiceBrush need to be inverted before rendering
+
[source,c]
----
SPICE_ROPD_INVERS_DEST = 4
----
+
Destination area need to be inverted before rendering
+
[source,c]
----
SPICE_ROPD_OP_PUT = 8
----
+
SpiceCopy operation should be used.
+
[source,c]
----
SPICE_ROPD_OP_OR = 16
----
+
OR operation should be used.
+
[source,c]
----
SPICE_ROPD_OP_AND = 32
----
+
AND operation should be used.
+
[source,c]
----
SPICE_ROPD_OP_XOR = 64
----
+
XOR operation should be used.
+
[source,c]
----
SPICE_ROPD_OP_BLACKNESS = 128
----
+
Destination pixel should be replaced by black
+
[source,c]
----
SPICE_ROPD_OP_WHITENESS = 256
----
+
Destination pixel should be replaced by white
+
[source,c]
----
SPICE_ROPD_OP_INVERS = 512
----
+
Destination pixel should be inverted
+
[source,c]
----
SPICE_ROPD_INVERS_RES = 1024
----
+
Result of the operation needs to be inverted
+
OP_PUT, OP_OR, OP_AND, OP_XOR, OP_BLACKNESS, OP_WHITENESS, and OP_INVERS are
mutually exclusive
+
OP_BLACKNESS, OP_WHITENESS, and OP_INVERS are exclusive
+
. Raw raster image
+
The following section describes Spice raw raster image (Pixmap). Pixmap is one
of several ways to transfer images in Spice protocol (for more information see
<<spice_image,Spice Image>>).
+
.. Pixmap format types
+
[source,c]
----
PIXMAP_FORMAT_1BIT_LE = 1
----
+
1 bit per pixel and bits order is little endian. Each pixel value is an index
in a color table. The color table size is 2.
+
[source,c]
----
PIXMAP_FORMAT_1BIT_BE = 2
----
+
1 bit per pixel and bits order is big endian. Each pixel value is index in a
color table. The color table size is 2.
+
[source,c]
----
PIXMAP_FORMAT_4BIT_LE = 3
----
+
4 bits per pixel and nibble order inside a byte is little endian. Each pixel
value is an index in a color table. The color table size is 16.
+
[source,c]
----
PIXMAP_FORMAT_4BIT_BE = 4
----
+
4 bits per pixel and nibble order inside a byte is big endian. Each pixel value
is an index in a color table. The color table size is 16.
+
[source,c]
----
PIXMAP_FORMAT_8BIT = 5
----
+
8 bits per pixel. Each pixel value is an index in a color table. The color
table size is 256.
+
[source,c]
----
PIXMAP_FORMAT_16BIT = 6
----
+
pixel format is 16 bits RGB555.
+
[source,c]
----
PIXMAP_FORMAT_24BIT = 7
----
+
pixel format is 24 bits RGB888.
+
[source,c]
----
PIXMAP_FORMAT_32BIT = 8
----
+
pixel format is 32 bits RGB888.
+
[source,c]
----
PIXMAP_FORMAT_RGBA = 9
----
+
pixel format is 32 bits ARGB8888.
+
.. SpicePalette
+
[cols="2*"]
|===
|UINT64 id
|unique id of the palette
|UINT16 table_size
|number of entries in the color table
|UINT32[] color_table
|each entry is RGB555 or RGB888 color depending on the current display area
mode. If display area mode color depth is 32, the effective format is RGB888.
If display area mode color depth is 16 the effective format is RGB555.
|===
+
.. Pixmap flags
+
[source,c]
----
PIXMAP_FLAG_PAL_CACHE_ME = 1
----
+
Instruct the client to add the palette to cache
+
[source,c]
----
PIXMAP_FLAG_PAL_FROM_CACHE = 2
----
+
Instruct the client to retrieve palette from cache.
+
[source,c]
----
PIXMAP_FLAG_TOP_DOWN = 4
----
+
Pixmap lines are ordered from top to bottom (i.e., line 0 is the highest line).
+
.. Pixmap
+
[cols="2*"]
|===
|UINT8 format
|one of PIXMAP_FORMAT_?
|UINT8 flags
|combination of PIXMAP_FLAG_?
|UINT32 width
|width of the pixmap
|UINT32 height
|height of the pixmap
|UINT32 stride
|number of bytes to add for moving from the beginning of line n to the
beginning of line n+1
a|
[source,c]
----
union {
SPICE_ADDRESS palette;
UINT64 palette_id;
}
----
|address of the color palette (must be zero if no color table is required for format) *or* id of the palette (valid if FLAG_PAL_FROM_CACHE is set).
|SPICE_ADDRESS data
|address of line 0 of the pixmap.
|===
+
. LZ with palette
+
This section describes a data structure that is combination of a color palette
and a compressed pixmap data. The pixmap is compressed using our implementation
of LZSS algorithm (see next section). Each decoded pixel value is an index in
the color palette.
+
.. LZPalette Flags
+
[source,c]
----
LZPALETTE_FLAG_PAL_CACHE_ME = 1
----
+
Instruct the client to add the palette to the cache
+
[source,c]
----
LZPALETTE_FLAG_PAL_FROM_CACHE = 2
----
+
Instruct the client to retrieve palette from the cache.
+
[source,c]
----
LZPALETTE_FLAG_TOP_DOWN = 4
----
+
pixmap lines are ordered from top to bottom (i.e. line 0 is the highest line).
+
.. LZPalette
+
[cols="2*"]
|===
|UINT8 flags
|combination of LZPALETTE_FLAG_?
|UINT32 data_size
|size of compressed data
a|
[source,c]
----
union {
SPICE_ADDRESS palette;
UINT64 palette_id;
}
----
|address of the color palette (see SpicePalette section in “Raw raster image”)[zero value
is disallowed] *or* id of the palette (valid if FLAG_PAL_FROM_CACHE).
|UINT8[] data
|compressed pixmap
|===
+
[[spice_image]]
. Spice Image
+
The following section describes Spice image. Spice image is used in various
commands and data structures for representing a raster image. Spice image
supports several compression types in addition to the raw mode: Quic, LZ and
GLZ. Quic is a predictive coding algorithm. It is a generalization of SFALIC
from gray-scale to color images withe addition of RLE encoding. By LZ we refer
to the our implementation of the LZSS algorithm, which was adjusted for images
in different formats. By GLZ we refer to an extension of LZ that allows it to
use a dictionary that is based on a set of images and not just on the image
being compressed.
+
.. Image types
+
[source,c]
----
IMAGE_TYPE_PIXMAP = 0
SPICE_IMAGE_TYPE_QUIC = 1
SPICE_IMAGE_TYPE_LZ_PLT = 100
SPICE_IMAGE_TYPE_LZ_RGB = 101
SPICE_IMAGE_TYPE_GLZ_RGB = 102
SPICE_IMAGE_TYPE_FROM_CACHE = 103
----
+
.. Image flags
+
IMAGE_FLAG_CACHE_ME = 1, this flag instruct the client to add the image to
image cache, cache key is SpiceImageDescriptor.id (see below).
+
.. SpiceImageDescriptor
+
[cols="2*"]
|===
|UINT64 id
|unique id of the image
|UINT8 type
|type of the image. One of IMAGE_TYPE_?
|UINT8 flags
|any combination of IMAGE_FLAG_?
|UINT32 width
|width of the image
|UINT32 height
|height of the image
|===
+
.. Image data
+
Image data follows SpiceImageDescriptor and its content depends on
SpiceImageDescriptor.type:
+
* In case of PIXMAP – content is Pixmap.
* In case of QUIC – content is Quic compressed image. Data begins with the
size of the compressed data, represented by UINT32, followed by the compressed
data.
* In case of LZ_PLT – content is LZPalette.
* In case of LZ_RGB – content is LZ_RGB – LZ encoding of an RGB image. Data
begins with the size of the compressed data, represented by UINT32, followed
by the compressed data.
* In case of GLZ_RGB – content is GLZ_RGB – GLZ encoding of an RGB image. Data
begins with the size of the compressed data, represented by UINT32, , followed
by the compressed data.
* In case of FROM_CACHE – No image data. The client should use
SpiceImageDescriptor.id to retrieve the relevant image from cache.
+
. Glyph SpiceString
+
Glyph string defines an array of glyphs for rendering. Glyphs in a string can
be in A1, A4 or A8 format (i.e., 1bpp, 4bpp, or 8bpp alpha mask). Every glyph
contains its rendering position on the destination draw area.
+
.. SpiceRasterGlyph
+
[cols="2*"]
|===
|POINT render_pos
|location of the glyph on the draw area
|POINT glyph_origin
|origin of the glyph. The origin is relative to the upper left corner of the
draw area. Positive value on x axis advances leftward and positive value on y
axis advances upward.
|UINT16 width
|glyph's width
|UINT16 height
|glyph's height
|UINT8[] data
|alpha mask of the glyph. Actual mask data depends on the glyph string's flags.
If the format is A1 then the line stride is ALIGN(width, 8) / 8. If the format
is A4, the line stride is ALIGN(width, 2) / 2. If the format is A8, the line
stride is width.
|===
+
.. Glyph SpiceString flags
+
[source,c]
----
GLYPH_STRING_FLAG_RASTER_A1 = 1
----
+
Glyphs type is 1bpp alpha value (i.e., 0 is transparent 1 is opaque)
+
[source,c]
----
GLYPH_STRING_FLAG_RASTER_A4 = 2
----
+
Glyphs type is 4bpp alpha value (i.e., 0 is transparent 16 is opaque)
+
[source,c]
----
GLYPH_STRING_FLAG_RASTER_A8 = 4
----
+
Glyphs type is 4bpp alpha value (i.e., 0 is transparent 256 is opaque)
+
[source,c]
----
GLYPH_STRING_FLAG_RASTER_TOP_DOWN = 8
----
+
Line 0 is the top line of the mask
+
.. GlyphString
+
[cols="2*"]
|===
|UINT16 length
|number of glyphs
|UINT16 flags
|combination of GLYPH_STRING_FLAG_?
|UINT8[] data
|glyphs
|===
+
. Data Types
+
.. RectList
+
[cols="2*"]
|===
|UINT32 count
|number of RECT items in rects
|RECT[] rects
|array of <count> RECT
|===
+
.. Path segment flags
+
[source,c]
----
PATH_SEGMENT_FLAG_BEGIN = 1
----
+
this segment begins a new path
+
[source,c]
----
PATH_SEGMENT_FLAG_END = 2
----
+
this segment ends the current path
+
[source,c]
----
PATH_SEGMENT_FLAG_CLOSE = 8
----
+
this segment closes the path and is invalid if PATH_SEGMENT_FLAG_END is not set
+
[source,c]
----
PATH_SEGMENT_FLAG_BEZIER = 16
----
+
this segment content is a Bezier curve
+
.. SpicePathSeg
+
[cols="2*"]
|===
|UINT32 flags
|any combination of PATH_SEGMENT_FLAG_?
|UINT32 count
|number of points in the segment
|POINTFIX[] points
|segment points
|===
+
.. PathSegList
+
List of SpicePathSeg items. End of the list is reached if the sum of all previous
PathSegs' sizes is equal to list_size. Address of next segment is the address
of SpicePathSeg.points[SpicePathSeg.count]
+
[cols="2*"]
|===
|UINT32 list_size
|total size of in bytes of all PathSegs in the list,
|===
+
SpicePathSeg seg0 – first path segment.
+
.. SpiceClip types
+
[source,c]
----
SPICE_CLIP_TYPE_NONE = 0
----
+
no clipping
+
[source,c]
----
SPICE_CLIP_TYPE_RECTS = 1
----
+
data is RectList and union of all rectangles in RectList is the effective clip
+
[source,c]
----
SPICE_CLIP_TYPE_PATH = 2
----
+
data is PathSegList and the figure described by PathSegList is the effective
clip
+
.. SpiceClip
+
[cols="2*"]
|===
|UIN32 type
|one of CLIP_TYPE_?
|SPICE_ADDRESS data
|address of clip data. The content depends on <type>
|===
+
.. Mask flags
+
[source,c]
----
MASK_FLAG_INVERS = 1, the effective mask is the inverse of the mask
----
+
.. Mask
+
[cols="2*"]
|===
|UINT8 flags | flags of the mask, combination of MASK_FLAG_?
|POINT position | origin of the mask in bitmap coordinates
|SPICE_ADDRESS bitmap | address of the mask's image, the format of the image must be
1bpp. If the bitmap is zero then no masking operation needs to be preformed.
|===
+
In all rendering commands, the mask must be big enough to cover the destination
rectangle
+
.. SpiceBrush types
+
[source,c]
----
SPICE_BRUSH_TYPE_NONE = 0 /* the brush is invalid */
SPICE_BRUSH_TYPE_SOLID = 1 /* the brush is solid RGB color */
SPICE_BRUSH_TYPE_PATTERN = 2 /* the brush is a pattern */
----
+
.. SpicePattern
+
[cols="2*"]
|===
|SPICE_ADDRESS image
|address of the pattern's Image
|POINT position
|origin coordinates of the pattern in the image
|===
+
.. SpiceBrush
+
[cols="2*"]
|===
|UINT32 type
|one of BRUSH_TYPE_?
|===
+
[source,c]
----
Union {
UINT32 color; */ RGB color. The format of the color depends on current
draw area mode.*/
SpicePattern pattern;
}
----
+
.. Image scale mode
+
The following defines the method for scaling image
+
[source,c]
----
SPICE_IMAGE_SCALE_MODE_INTERPOLATE = 0
----
+
The client is allowed to INTERPOLATE pixel color.
+
[source,c]
----
SPICE_IMAGE_SCALE_MODE_NEAREST = 1
----
+
The client must use the nearest pixel.
+
.. LineAtrr flags
+
[source,c]
----
LINE_ATTR_FLAG_START_WITH_GAP = 4
----
+
first style segment if gap (i.e., foreground)
+
[source,c]
----
LINE_ATTR_FLAG_STYLED = 8
----
+
style member of LineAtrr is valid and contains effective line style for the
rendering operation.
+
.. LineAtrr join style
+
[source,c]
----
LINE_ATTR_JOIN_ROUND = 0
LINE_ATTR_JOIN_BEVEL = 1
LINE_ATTR_JOIN_MITER = 2
----
+
.. LineAtrr cap style
+
[source,c]
----
LINE_ATTR_CAP_ROUND = 0
LINE_ATTR_CAP_SQUARE = 1
LINE_ATTR_CAP_BUTT = 2
----
+
.. SpiceLineAttr
+
[cols="2*"]
|===
|UINT8 flags
|combination of LINE_ATTR_?
|UINT8 join_style
|one of LINE_ATTR_JOIN_?
|UINT8 cap_style
|one of LINE_ATTR_CAP_?
|UINT8 style_num_segments
|number of style segments in line style
|SPICE_FIXED28_4 width
|width of the line in pixels
|SPICE_FIXED28_4 miter_limit
|miter limit in pixels
| SPICE_ADDRESS style
|address of line style line style is array of SPICE_FIXED28_4. The array defines
segments that each represents length of foreground or background pixels in the
style. If FLAG_START_WITH_GAP is defined then the first segment in the style is
background, otherwise it is foreground. Renderer uses this array of segments
repeatedly during rendering operation.
|===
+
. Rendering command
+
.. SpiceMsgDisplayBase
+
Common field to all rendering command
+
[cols="2*"]
|===
|RECT bounding_box
|the affected area on the display area
|SpiceClip clip
|the effective clip to set before rendering a command
|===
+
.. SPICE_MSG_DISPLAY_COPY_BITS
+
[source,c]
----
SpiceMsgDisplayBase
POINT source_position
----
+
SpiceCopy bits from the draw area to bounding_box on the draw area. Source area left
top corner is source_position and its height and width is equal to bounding_box
height and width. Source and destination rectangles can overlap.
+
.. SPICE_MSG_DISPLAY_DRAW_FILL
+
[source,c]
----
SpiceMsgDisplayBase
SpiceBrush brush
UINT16 rop_descriptor
Mask mask
----
+
SpiceFill bounding_box using brush as the fill pattern and rop_descriptor
instructions. If the mask is valid, it will limit the modified area (i.e., only
pixels on the destination area that their corresponding bits are set will be
affected).
+
.. SPICE_MSG_DISPLAY_DRAW_OPAQUE
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS source_image
RECT source_area
SpiceBrush brush
UINT16 rop_descriptor
UINT8 scale_mode
Mask mask
----
+
Combine pixels from source_area in source_image with the brush's pattern using
rop_descriptor instructions. The result image will be rendered into
bounding_box. In case scaling of source image is required it will be performed
according to scale_mode and before the combination with brush pixels. If mask
is valid it will limit the modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_COPY
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS source_image
RECT source_area
UINT16 rop_descriptor
UINT8 scale_mode
Mask mask
----
+
SpiceCopy pixels from source_area in source_image to bounding_box using
rop_descriptor instructions. In case scaling of source image is required it
will be performed according to scale_mode and before the copying to the draw
area. If mask is valid it will limit the modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_BLEND
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS source_image
RECT source_area
UINT16 rop_descriptor
UINT8 scale_mode
Mask mask
----
+
Mixing pixels from source_area in source_image with bounding_box pixels on the
draw area using rop_descriptor instructions. In case scaling of source image is
required it will be performed according to scale_mode and before the mixing
with the draw area. If mask is valid it will limit the modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_BLACKNESS
+
[source,c]
----
SpiceMsgDisplayBase
Mask mask
----
+
SpiceFill bounding_box with black pixels. If mask is valid it will limit the
modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_WHITENESS
+
[source,c]
----
SpiceMsgDisplayBase
Mask mask
----
+
SpiceFill bounding_box with white pixels. If mask is valid it will limit the
modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_INVERS
+
[source,c]
----
SpiceMsgDisplayBase
Mask mask
----
+
Inverse all pixels in bounding_box. If mask is valid it will limit the modified
area.
+
.. SPICE_MSG_DISPLAY_DRAW_ROP3
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS source_image
RECT source_area
SpiceBrush brush
UINT8 rop3
UINT8 scale_mode
Mask mask
----
+
Mix pixels from source_area in source_image, bounding_box pixels in the draw
area, and the brush pattern. The method for mixing three pixels into the
destination area (i.e., bounding_box) is defined by rop3 (i.e., ternary raster
operations). In case scaling of source image is required it will be performed
according to scale_mode and before the mixing. If mask is valid it will limit
the modified area.
+
.. SPICE_MSG_DISPLAY_DRAW_TRANSPARENT
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS source_image
RECT source_area
UINT32 transparent_color
UINT32 transparent _true_color
----
+
SpiceCopy pixels from source_area on source_image to bounding_box on the draw area.
In case scaling of source image is required it will use SPICE_IMAGE_SCALE_MODE_NEAREST.
Pixels with value equal to the transparent color will be masked out.
SpiceTransparent color is provided in two forms: true color (i.e., RGB888) and the
color in the original format (i.e., before compression) .
+
.. SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND
+
[source,c]
----
SpiceMsgDisplayBase
UINT8 alpha
SPICE_ADDRESS source_image
RECT source_area
----
+
Alpha blend source_area of source_image on bounding_box of draw area using
alpha value or alternatively per pixel alpha value. In case scaling of source
image is required, it will use SPICE_IMAGE_SCALE_MODE_INTERPOLATE mode. Alpha value is
defined as 0 is full transparency and 255 is full opacity. Format of source
image can be pre-multiplied ARGB8888 for per pixel alpha value.
+
New RGB color is defined as:
+
[source,c]
----
color' = (source_color * alpha) / 255
alpha' = (source_alpha * alpha) / 255
new_color = color' + ((255 - alpha' ) * destination_color) / 255
----
+
.. SPICE_MSG_DISPLAY_DRAW_STROKE
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS path – address of the PathSegList that defines the path to render
SpiceLineAttr attr
Bush brush
UINT16 fore_mode - foreground rop_descriptor
UINT16 back_mode – background rop_descriptor
----
+
Render path using brush line attribute and rop descriptors. If the line is
styled (i.e., LINE_ATTR_FLAG_STYLED is set in attr.falgs) then background
(i.e., inverse of the style) is drawn using back_mode and the foreground is
drawn using fore_mode. If the line is not styled, the entire path is rendered
using fore_mode.
+
.. SPICE_MSG_DISPLAY_DRAW_TEXT
+
[source,c]
----
SpiceMsgDisplayBase
SPICE_ADDRESS string – address of GlyphString
RECT back_area
SpiceBrush fore_brush
SpiceBrush back_brush
UINT16 fore_mode
UINT16 back_mode
----
+
Render string of glyph on the display area using brush fore_brush and the
rop_descriptor fore_mode. If back_area is not empty the renderer fill back_area
on the display area prior to rendering the glyph string. back_area is filled
using back_brush and the rop_descriptor back_mode.
+
. Video streaming commands
+
Spice supports the creation of video streams by the server for rendering video
content on the client display area. Unlike other rendering commands, the
stream data can be compressed using lossy or video specific compression
algorithms. It is not required to render video frames as they arrive and it is
also allowed to drop video frames. This enables using video frames buffering
for having smoother playback and audio synchronization. Audio synchronization
is achieved by using time stamp that is attached to audio and video streams.
By using video streaming the network traffic can be dramatically reduced. When
the stream is created, the server sends create message using
SPICE_MSG_DISPLAY_STREAM_CREATE. After the server creates a stream he can send data
using SPICE_MSG_DISPLAY_STREAM_DATA, or set new stream clipping by sending clip
message using SPICE_MSG_DISPLAY_STREAM_CLIP. Once the server no longer needs the
stream, he can send destroy command using SPICE_MSG_DISPLAY_STREAM_DESTROY. The
server can also destroy all active streams by sending destroy all message using
SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL.
+
.. Stream flags
+
[source,c]
----
STREAM_FLAG_TOP_DOWN = 1 /* stream frame line order is from top to bottom */
----
+
.. Codec types
+
[source,c]
----
STREAM_CODEC_TYPE_MJPEG = 1 /* this stream uses motion JPEG codec */
----
+
.. SPICE_MSG_DISPLAY_STREAM_CREATE, SpiceMsgDisplayStreamCreate
+
[cols="2*"]
|===
|UINT32 id
|id of the new stream. It is the server's responsibility to manage stream ids
|UINT32 flags
|flags of the stream, any combination of STREAM_FLAG_?
|UINT32 codec_type
|type of codec used for this stream, one of STREAM_CODEC_TYPE_?
|UINT64 reserved
|must be zero
|UINT32 stream_width
|width of the source frame.
|UINT32 stream_height
|height of the source frame
|UINT32 source_width
|actual frame width to use, must be less or equal to stream_width.
|UINT32 source_height
|actual frame height to use, must be less or equal to stream_height.
|RECT destination
|area to render into on the client display area
|SpiceClip clip
|clipping of the stream
|===
+
.. SPICE_MSG_DISPLAY_STREAM_DATA, SpiceMsgDisplayStreamData
+
[cols="2*"]
|===
|UINT32 id
|stream id (i.e., SpiceMsgDisplayStreamCreate.id)
|UINT32 multimedia_time
|frame time stamp
|UINT32 data_size
|stream data size to consume in bytes
|UINT32 pad_size
|additional data padding in bytes
|UINT8[] data
|stream data depending on SpiceMsgDisplayStreamCreate.codec_type. Size of data is (
data_size + pad_size)
|===
+
.. SPICE_MSG_DISPLAY_STREAM_CLIP, SpiceMsgDisplayStreamClip
+
[cols="2*"]
|===
|UINT32 id
|stream id (i.e., SpiceMsgDisplayStreamCreate.id)
|===
+
SpiceClip clip – new clipping of the stream
+
.. SPICE_MSG_DISPLAY_STREAM_DESTROY, UINT32
+
[cols="2*"]
|===
|UINT32
|id of stream to destroy
|===
+
.. SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL, VOID
+
Destroy all active streams
+
. Cache control
+
.. Resource type
+
[source,c]
----
SPICE_RES_TYPE_PIXMAP = 1
----
+
.. SpiceResourceID
+
[cols="2*"]
|===
|UINT8 type
|type of the resource, one of SPICE_RES_TYPE_?
|UINT64 id
|id of the resource
|===
+
.. SpiceResourceList
+
[cols="2*"]
|===
|UINT16 count
|number of items in resources
|SpiceResourceID[] resources
|list of resources id
|===
+
.. SPICE_MSG_DISPLAY_INVAL_LIST, SpiceResourceList
+
[cols="2*"]
|===
|SpiceResourceList
|list of resources to remove from cache
|===
+
.. SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS, SpiceMsgWaitForChannels
+
Remove all images from the image cache. The client must use SpiceMsgWaitForChannels
(for more info see <<channel_sync,Channel synchronization>>) to synchronize
with other channels before clearing the cache.
+
.. SPICE_MSG_DISPLAY_INVAL_PALETTE, UINT64
+
[cols="2*"]
|===
|UINT64 id of palette
|client needs to remove palette with that id from the cache
|===
+
.. SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES, VOID
+
Remove all palettes from palette cache
== Cursor channel definition
Spice protocol defines a set of messages for controlling cursor shape and
position on the remote display area, cursor position messages are irrelevant
for client mouse mode (see <<mouse_modes,Mouse Modes>>). Spice protocol also
defines a set of messages for managing cursor shape cache on the client site.
Client must strictly obey all such instructions. The server sends
SPICE_MSG_CURSOR_INIT to set current pointer state (i.e., shape, position, visibility
etc.) and to clear shape cache. After the server sends init message it can send
any other cursor command except for SPICE_MSG_CURSOR_INIT. The server can send
SPICE_MSG_CURSOR_RESET message - this will disable the cursor and reset the cursor
cache. After this message the only valid message the server can send is
SPICE_MSG_CURSOR_INIT. The relevant remote display area for a cursor channel is the
one of the display channel that has the same channel id (i.e.,
SpiceLinkMess.channel_id).
. Server messages
+
[source,c]
----
SPICE_MSG_CURSOR_INIT = 101
SPICE_MSG_CURSOR_RESET = 102
SPICE_MSG_CURSOR_SET = 103
SPICE_MSG_CURSOR_MOVE = 104
SPICE_MSG_CURSOR_HIDE = 105
SPICE_MSG_CURSOR_TRAIL = 106
SPICE_MSG_CURSOR_INVAL_ONE = 107
SPICE_MSG_CURSOR_INVAL_ALL = 108
----
+
.. Cursors types
+
[source,c]
----
SPICE_CURSOR_TYPE_ALPHA = 0
SPICE_CURSOR_TYPE_MONO = 1
SPICE_CURSOR_TYPE_COLOR4 = 2
SPICE_CURSOR_TYPE_COLOR8 = 3
SPICE_CURSOR_TYPE_COLOR16 = 4
SPICE_CURSOR_TYPE_COLOR24 = 5
SPICE_CURSOR_TYPE_COLOR32 = 6
----
+
.. SpiceCursorHeader
+
[cols="2*"]
|===
|UINT64 unique
|unique identifier of the corresponding cursor shape. It is used for storing
and retrieving cursors from the cursor cache.
|UINT16 type
|type of the shape, one of CURSOR_TYPE_?
|UINT16 width
|width of the shape
|UINT16 height
|height of the shape
|UINT16 hot_spot_x
|position of hot spot on x axis
|UINT16 hot_spot_y
|position of hot spot on y axis
|===
+
.. Cursor flags
+
[source,c]
----
CURSOR_FLAGS_NONE = 1
----
+
set when SpiceCursor (see below) is invalid
+
[source,c]
----
CURSOR_CURSOR_FLAGS _CACHE_ME = 2
----
+
set when the client should add this shape to the shapes cache. The client will
use SpiceCursorHeader.unique as cache key.
+
[source,c]
----
CURSOR_FLAGS_FROM_CACHE = 4
----
+
set when the client should retrieve the cursor shape, using SpiceCursorHeader.unique
as key, from the shapes cache. In this case all fields of SpiceCursorHeader except
for 'unique' are invalid.
+
.. SpiceCursor
+
[cols="2*"]
|===
|UINT32 flags
|any valid combination of SPICE_CURSOR_FLAGS_?
|SpiceCursorHeader header
|
|UINT8[] data
|actual cursor shape data, the size is determine by width, height and type from
SpiceCursorHeader. Next we will describe in detail the shape data format according
to cursor type:
|ALPHA, alpha shape
|data contains pre-multiplied ARGB8888 pixmap. Line stride is <width * 4>.
|MONO, monochrome shape
|data contains two bitmaps with size <width> * <height>. The first bitmap is
AND mask and the second is XOR mask. Line stride is ALIGN(<width>, 8) / 8.
Bits order within every byte is big endian.
|COLOR4, 4 bits per pixel shape
|First data region is pixmap: the stride of the pixmap is ALIGN(width , 2) / 2;
every nibble is translated to a color usingthe color palette; Nibble order is
big endian. Second data region contain 16 colors palette: each entry is 32 bit
RGB color. Third region is a bitmap mask: line stride is ALIGN(<width>, 8) /
8; bits order within every byte is big endian.
|COLOR4, 8 bits per pixel shape
|First data region is pixmap: the stride of the pixmap is <width>; every byte
is translated to color using the color palette. Second data region contain 256
colors palette: each entry is 32 bit RGB color. Third region is a bitmap mask:
line stride is ALIGN(<width>, 8) / 8; bits order within every byte is big
endian.
|COLOR16, 16 bits per pixel shape
|First data region is pixmap: the stride of the pixmap is <width * 2>; every
UINT16 is RGB_555. Second region is a bitmap mask: line stride is
ALIGN(<width>, 8) / 8; bits order within every byte is big endian.
|COLOR24, 24 bits per pixel shape
|First data region is pixmap: the stride of the pixmap is <width * 3>; every
UINT8[3] is RGB_888. Second region is a bitmap mask: line stride is
ALIGN(<width>, 8) / 8; bits order within every byte is big endian.
|COLOR32, 32 bits per pixel shape
|First data region is pixmap: the stride of the pixmap is <width * 4>,;every
UINT32 is RGB_888. Second region is a bitmap mask: line stride is
ALIGN(<width>, 8) / 8; bits order within every byte is big endian.
|===
+
For more deatails on drawing the cursor shape see <<cursor_shape, this
section>>
+
.. SPICE_MSG_CURSOR_INIT, SpiceMsgCursorInit
+
[cols="2*"]
|===
|POINT16 position
|position of mouse pointer on the relevant display area. Not relevant in
client mode.
|UINT16 trail_length
|number of cursors in the trail excluding main cursor.
|UINT16 trail_frequency
|millisecond interval between trail updates.
|UIN8 visible
|if 1, the cursor is visible. If 0, the cursor is invisible.
|SpiceCursor cursor
|current cursor shape
|===
+
.. SPICE_MSG_CURSOR_RESET, VOID
+
.. SPICE_MSG_CURSOR_SET, SpiceMsgCursorSet
+
[cols="2*"]
|===
|POINT16 position
|position of mouse pointer on the relevant display area. not relevant in client
mode.
|UINT8 visible
|if 1, the cursor is visible. If 0, the cursor is invisible.
|SpiceCursor cursor
|current cursor shape
|===
+
.. SPICE_MSG_CURSOR_MOVE, POINT16
+
[cols="2*"]
|===
|POINT16
|new mouse position. Not relevant in client mode. This message also implicitly
sets cursor visibility to 1.
|===
+
.. SPICE_MSG_CURSOR_HIDE, VOID
+
Hide pointer on the relevant display area.
+
.. SPICE_MSG_CURSOR_TRAIL
+
[cols="2*"]
|===
|UINT16 length
|number of cursors in the trail excluding main cursor.
|UINT16 frequency
|millisecond interval between trail updates
|===
+
.. SPICE_MSG_CURSOR_INVAL_ONE, UINT64
+
[cols="2*"]
|===
|UINT64
|id of cursor shape to remove from the cursor cache
|===
+
.. SPICE_MSG_CURSOR_INVAL_ALL, VOLD
+
Clear cursor cache
+
[[cursor_shape]]
. Drawing the cursor shape according to the cursor type
+
This section is relevant only for server mouse mode. Cursor shape positioning
on the display area is done by placing cursor hot spot on the current cursor
position.
+
.. Alpha - no spacial handling, just bland the shape on the display area.
+
.. Monochrome
+
For each cleared bit in the AND mask clear the corresponding bits in the
relevant pixel on the display area
For each set bit in the XOR mask reverse the
corresponding bits in the relevant pixel on the display area
+
.. Color
+
If the source color is black and mask bit is set, NOP.
Else, if the source color is white and the mask bit is set, reverse all bits in
the relevant pixel on the display area.
Else, put source color.
== Playback channel definition
Spice supports sending audio streams for playback on the client side. An audio
stream is sent by the server in an audio packet using SPICE_MSG_PLAYBACK_DATA
message. The content of the audio packet is controlled by the playback mode
that the server sends using SPICE_MSG_PLAYBACK_MODE message. The server can start and
stop the stream using SPICE_MSG_PLAYBACK_START and SPICE_MSG_PLAYBACK_STOP messages.
Sending audio packet is allowed only between start and stop messages. Sending
start message is allowed only in stop state and after at least one mode message
was sent. Sending a stop message is allowed only during a start state.
. Server messages
+
[source,c]
----
SPICE_MSG_PLAYBACK_DATA = 101
SPICE_MSG_PLAYBACK_MODE = 102
SPICE_MSG_PLAYBACK_START = 103
SPICE_MSG_PLAYBACK_STOP = 104
----
+
. Audio format
+
[source,c]
----
SPICE_AUDIO_FMT_S16 = 1 /* each channel sample is a 16 bit
signed integer */
----
+
. Playback data mode
+
Two types of data mode are available: (1) raw PCM data, (2) compressed data
in CELT 0_5_1 format (obsolete) and (3) compressed data in OPUS format.
+
[source,c]
----
SPICE_AUDIO_DATA_MODE_RAW = 1
SPICE_AUDIO_DATA_MODE_CELT_0_5_1 = 2
SPICE_AUDIO_DATA_MODE_OPUS = 3
----
+
. Playback channel capabilities
+
[source,c]
----
SPICE_PLAYBACK_CAP_CELT_0_5_1 = 0
SPICE_PLAYBACK_CAP_VOLUME = 1
SPICE_PLAYBACK_CAP_LATENCY = 2
SPICE_PLAYBACK_CAP_OPUS = 3
----
+
Spice client needs to declare support of OPUS in channel capabilities in
order to allow the server to send playback packets in OPUS format.
+
. SPICE_MSG_PLAYBACK_MODE, SpiceMsgPlaybackMode
+
[cols="2*"]
|===
|UINT32 time
|server time stamp
|UINT32 mode
|one of SPICE_AUDIO_DATA_MODE_?
|UINT8[] data
|specific data, content depend on mode
|===
+
. SPICE_MSG_PLAYBACK_START, SpiceMsgRecordStart
+
[cols="2*"]
|===
|UINT32 channels
|number of audio channels
|UINT32 format
|one of SPICE_AUDIO_FMT_?
|UINT32 frequency
|channel samples per second
|===
+
. SPICE_MSG_PLAYBACK_DATA, SpiceMsgPlaybackPacket
+
[cols="2*"]
|===
|UINT32 time
|server time stamp
|UINT8[] data
|playback data , content depend on mode
|===
+
. SPICE_MSG_PLAYBACK_STOP, VOID
+
Stop current audio playback
== Record Channel definition
Spice supports transmitting of audio captured streams from the client to the
server. Spice server starts audio capturing using SPICE_MSG_RECORD_START message.
This message instructs the client to start transmitting captured audio . In
response, the client sends time stamp of the stream start using
SPICE_MSGC_RECORD_START_MARK. After the client sends start mark it can start
transmitting audio stream data using SPICE_MSGC_RECORD_DATA. One mode message must be
sent by the client before any other message using SPICE_MSGC_RECORD_MODE. This, in
order to inform the server on what type of data will be transferred. Mode
message can also be transmitted at any other time in order to switch the data
type delivered by SPICE_MSGC_RECORD_DATA. The Server can send SPICE_MSG_RECORD_STOP for
stopping captured audio streaming. Sending a start message is allowed only
while the stream is in stop state. Sending a stop message and data messages is
allowed only while the stream is in start state. Sending mark message is
allowed only between start message and the first data message.
. Server messages
+
[source,c]
----
SPICE_MSG_RECORD_START = 101
SPICE_MSG_RECORD_STOP = 102
----
+
. Client messages
+
[source,c]
----
SPICE_MSGC_RECORD_DATA = 101
SPICE_MSGC_RECORD_MODE = 102
SPICE_MSGC_RECORD_START_MARK = 103
----
+
. Audio format
+
[source,c]
----
SPICE_AUDIO_FMT_S16 = 1 /* each channel sample is a 16 bit signed integer */
----
+
. Record data mode
+
Two types of data mode are available: (1) raw PCM data (2) compressed data in
CELT 0.5.1 format (obsolete) (3) compressed data in OPUS format.
+
[source,c]
----
SPICE_AUDIO_DATA_MODE_RAW = 1
SPICE_AUDIO_DATA_MODE_CELT_0_5_1 = 2
SPICE_AUDIO_DATA_MODE_OPUS = 3
----
+
. Record channel capabilities
+
[source,c]
----
SPICE_RECORD_CAP_CELT_0_5_1 = 0
SPICE_RECORD_CAP_VOLUME = 1
SPICE_RECORD_CAP_OPUS = 2
----
+
Spice server needs to declare support of OPUS in channel capabilities in
order to allow the client to send recorded packets in OPUS format.
+
. SPICE_MSGC_RECORD_MODE, SpiceMsgcRecordMode
+
[cols="2*"]
|===
|UINT32 time
|client time stamp
|UINT32 mode
|one of SPICE_AUDIO_DATA_MODE_?
|UINT8[] data
|specific data, content depend on mode
|===
+
. SPICE_MSG_RECORD_START, SpiceMsgRecordStart
+
[cols="2*"]
|===
|UINT32 channel
|number of audio channels
|UINT32 format
|one of SPICE_AUDIO_FMT_?
|UINT32 frequency
|channel samples per second
|===
+
. SPICE_MSGC_RECORD_START_MARK, UINT32
+
[cols="2*"]
|===
|UINT32
|client time stamp of stream start
|===
+
. SPICE_MSGC_RECORD_DATA, SpiceMsgcRecordPacket
+
[cols="2*"]
|===
|UINT32 time
|client time stamp
|UINT8[] data
|recorded data , content depend on mode
|===
+
. SPICE_MSG_RECORD_STOP, VOID
+
Stop current audio capture
|