├── .github └── FUNDING.yml ├── .travis.yml ├── .travis ├── 01-shared-linking.sh └── 02-dso-linking.sh ├── LICENSE ├── Makefile.am ├── README.md ├── autogen.sh ├── configure.ac ├── docs └── man1 │ ├── Makefile.am │ └── vdi-stream-client.1 ├── include └── font.h ├── src ├── Makefile.am ├── audio.c ├── audio.h ├── client.c ├── client.h ├── parsec.c ├── parsec.h ├── redirect.c ├── redirect.h ├── video.c └── video.h └── tools └── parsec-login /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mbroemme 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.com/donate/?hosted_button_id=TJLZRF9BPVX22'] 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Maik Broemme 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation; either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | # environment settings. 17 | dist: bionic 18 | os: linux 19 | language: c 20 | compiler: gcc 21 | 22 | # variables. 23 | env: 24 | - PARSEC_VERSION=5.0 25 | 26 | # dependencies. 27 | install: 28 | - sudo apt-get install libgl-dev libsdl2-dev libsdl2-ttf-dev libusb-1.0-0-dev libusbredirhost-dev libusbredirparser-dev libx11-dev sudo tar wget 29 | 30 | # preparation. 31 | before_script: 32 | - sh autogen.sh 33 | 34 | # compilation. 35 | script: 36 | - set -o errexit; source .travis/01-shared-linking.sh 37 | - set -o errexit; source .travis/02-dso-linking.sh 38 | -------------------------------------------------------------------------------- /.travis/01-shared-linking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | # 3 | # 01-shared-linking.sh -- shared linking against parsec sdk. 4 | # 5 | # Copyright (c) 2021 Maik Broemme 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | # parsec sdk download. 21 | wget "https://github.com/parsec-cloud/parsec-sdk/archive/${PARSEC_VERSION}.tar.gz" 22 | tar xzf "${PARSEC_VERSION}.tar.gz" 23 | 24 | # parsec sdk installation. 25 | sudo install -D -m 0755 "parsec-sdk-${PARSEC_VERSION}/sdk/linux/libparsec.so" "/usr/lib/parsec/sdk/linux/libparsec.so" 26 | sudo install -D -m 0644 "parsec-sdk-${PARSEC_VERSION}/sdk/parsec.h" "/usr/include/parsec/sdk/parsec.h" 27 | 28 | # parsec sdk link shared libraries. 29 | sudo ln -s "parsec/sdk/linux/libparsec.so" "/usr/lib/libparsec.so" 30 | sudo ln -s "parsec/sdk/linux/libparsec.so" "/usr/lib/libparsec.so.${PARSEC_VERSION}" 31 | 32 | # parsec sdk link include files. 33 | sudo ln -s "sdk/parsec.h" "/usr/include/parsec/parsec.h" 34 | 35 | # compilation. 36 | ./configure --prefix=/usr 37 | make 38 | make distclean 39 | -------------------------------------------------------------------------------- /.travis/02-dso-linking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | # 3 | # 02-dso-linking.sh -- dso linking against parsec sdk. 4 | # 5 | # Copyright (c) 2021 Maik Broemme 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | # parsec sdk download. 21 | wget "https://github.com/parsec-cloud/parsec-sdk/archive/${PARSEC_VERSION}.tar.gz" 22 | tar xzf "${PARSEC_VERSION}.tar.gz" 23 | 24 | # parsec sdk installation. 25 | mv "parsec-sdk-${PARSEC_VERSION}" "parsec-sdk" 26 | 27 | # compilation. 28 | ./configure --prefix=/usr 29 | make 30 | make distclean 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # any directories which should be built and installed. 2 | SUBDIRS = src docs/man1 3 | 4 | # the directories which are part of the distribution. 5 | DIST_SUBDIRS = $(SUBDIRS) 6 | 7 | # extra stuff. 8 | LICENSE \ 9 | README.md 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VDI Stream Client 2 | 3 | [![Build Status](https://travis-ci.com/mbroemme/vdi-stream-client.svg?branch=main)](https://travis-ci.com/mbroemme/vdi-stream-client) 4 | [![GitHub release](https://img.shields.io/github/release/mbroemme/vdi-stream-client.svg)](https://github.com/mbroemme/vdi-stream-client/releases) 5 | [![GitHub issues](https://img.shields.io/github/issues/mbroemme/vdi-stream-client.svg)](https://github.com/mbroemme/vdi-stream-client/issues) 6 | [![GitHub forks](https://img.shields.io/github/forks/mbroemme/vdi-stream-client.svg)](https://github.com/mbroemme/vdi-stream-client/network/members) 7 | [![GitHub stars](https://img.shields.io/github/stars/mbroemme/vdi-stream-client.svg)](https://github.com/mbroemme/vdi-stream-client/stargazers) 8 | [![GitHub license](https://img.shields.io/github/license/mbroemme/vdi-stream-client.svg)](https://github.com/mbroemme/vdi-stream-client/blob/main/LICENSE) 9 | [![GitHub downloads](https://img.shields.io/github/downloads/mbroemme/vdi-stream-client/total.svg)](https://github.com/mbroemme/vdi-stream-client/releases) 10 | 11 | A very tiny and low latency desktop streaming client for remote Windows guests 12 | with GPU passthrough which supports [Nvidia NVENC](https://en.wikipedia.org/wiki/Nvidia_NVENC), 13 | [AMD VCE](https://en.wikipedia.org/wiki/Video_Coding_Engine), [VCN](https://en.wikipedia.org/wiki/Video_Core_Next) 14 | and [Intel Quick Sync Video](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video). 15 | 16 | # Overview 17 | 18 | VDI Stream Client is a tiny and low latency Linux client which connects to [Parsec Host](https://parsec.app/) 19 | running on Windows. It allows to run fully GPU accelerated Windows desktop 20 | environment on a remote machine while streaming the content to a local Linux 21 | system which process keyboard and mouse input. The remote server can be a 22 | virtual machine running on-top of on-premise deployments of [Virtuozzo Hybrid 23 | Server](https://www.virtuozzo.com/support/all-products/virtuozzo-hybrid-server.html), 24 | [KVM](https://www.linux-kvm.org/page/Main_Page) or [Xen](https://xenproject.org/). 25 | It can also connect to public clouds like [Amazon (EC2 G3 Accelerated)](https://aws.amazon.com/ec2/instance-types/g3/) 26 | or [Microsoft Azure (NV6)](https://azure.microsoft.com/en-us/pricing/details/virtual-machines/windows/). 27 | It uses [Simple DirectMedia Layer (SDL2)](https://libsdl.org/) for low-level 28 | access to audio, video, keyboard, mouse and clipboard. 29 | 30 | # Motivation 31 | 32 | I'm using Linux on Desktop since more than 20 years already for several 33 | reasons - customization, small and tiny floating window managers like [Fluxbox](http://fluxbox.org/), 34 | ideal platform for engineers and developers and many more. However over the 35 | past couple of years my daily job required more attention which rely on 36 | Microsoft Windows applications like Microsoft Office and full fledged groupware 37 | solution like Microsoft Outlook. There exist open source alternative like [LibreOffice](https://www.libreoffice.org/) 38 | and [Thunderbird](https://www.thunderbird.net/) plus various Exchange 39 | connectors or even [SOGo](https://sogo.nu/). They are all good in their niche 40 | but they didn't reach compatibility to satisfy me. I tried a lot of different 41 | ways of solving the problem (see below in the comparison table) but at the end 42 | I have only three main goals: 43 | 44 | 1. GPU passthrough with remote support. Using hosted remote Windows desktop 45 | with full-fledged GPU acceleration for 3D, video decoding and encoding to 46 | run any kind of application with full GPU support as they would have been 47 | used locally. 48 | 2. Low latency network connection. Using laptop running Linux to connect from 49 | anywhere to the Windows desktop and do my daily work. This must work via 50 | fast network like ethernet, roaming wireless and low bandwidth with unstable 51 | mobile broadband. 52 | 3. Being very energy efficient on client. The laptop battery drain should not 53 | significantly increase while working on the remote desktop. Also the server 54 | should not become more energy hungry than needed for simple streaming. 55 | 56 | # Comparison 57 | 58 | In Linux ecosystem there exist already wide range of options to run Windows 59 | guest environment as virtual machine on-top of a Linux host and access either 60 | its local display or via remote display protocol, all of them have their pros 61 | and cons. Look at the table below for brief comparison. 62 | 63 | Method | Local | Remote | 3D 64 | ----------------------|-------|--------|------------------ 65 | [QXL with Spice](https://www.spice-space.org/) | Yes | Yes | No 66 | [GPU Passthrough](https://www.kernel.org/doc/Documentation/vfio.txt) | Yes | No | Yes 67 | [KVM FrameRelay](https://looking-glass.io/) | Yes | No | Yes 68 | [iGVT-g](https://www.kernel.org/doc/Documentation/vfio-mediated-device.txt) | Yes | No | Yes (Intel only) 69 | [Virgil 3D](https://virgil3d.github.io/) | Yes | Yes | Yes (Linux only) 70 | [SPICE Streaming Agent](https://gitlab.freedesktop.org/spice/spice-streaming-agent) | Yes | Yes | Yes (Linux only) 71 | [Moonlight](https://moonlight-stream.org/) | Yes | Yes | Yes (Nvidia only) 72 | [Parsec](https://parsec.app/) | Yes | Yes | Yes 73 | 74 | So why another streaming client is needed if one for Windows, Linux and macOS 75 | exist already? Well the Parsec client is focusing on gaming capabilities while 76 | VDI Stream Client is focusing on having a reliable daily working environment. 77 | The table below gives a brief overview about differences. 78 | 79 | Features | VDI Stream Client | Parsec 80 | ------------------------|-------------------|--------------- 81 | Keyboard Input | Full | Partial 82 | Mouse Input | Full | Partial 83 | Gamepad Input | No | Yes 84 | Clipboard Sharing | Text only | Text only 85 | Remote | Yes | Yes 86 | DirectX | Yes | Yes 87 | OpenGL | Yes | Yes 88 | Resolution Sync | Host-to-Client | Client-to-Host 89 | Alt+Tab Integration | Yes | No 90 | Minimal GUI | Yes | No 91 | System SDL2 | Yes | No 92 | Auto Reconnect | Yes | No 93 | Screensaver Integration | Yes | No 94 | USB Redirection | Yes | No 95 | [Color Mode 4:4:4](https://en.wikipedia.org/wiki/Chroma_subsampling) | [SDK Bug](https://github.com/parsec-cloud/parsec-sdk/issues/36) | Yes 96 | 97 | # Requirements 98 | 99 | Any recent GPU with [OpenGL](https://en.wikipedia.org/wiki/OpenGL) and [VA-API](https://en.wikipedia.org/wiki/Video_Acceleration_API) 100 | support will work. When it comes to 4:4:4 color mode, part of the decoding work 101 | is made with [FFmpeg](https://ffmpeg.org/) (see notes below regarding 4:4:4 102 | status). Nothing exist without drawbacks and that one for Parsec is that it is 103 | mandatory to have an [account](https://parsec.app/signup) which is 104 | completely free. However communication between client and host is always made 105 | directly. Also the SDK is only available as pre-compiled library, so for those 106 | who fully rely on an open-source system, stop reading here. Some features are 107 | only available with a commercial subscription under [Parsec Warp](https://parsec.app/warp). 108 | It applies to 4:4:4 color mode which is required to encode images and streams 109 | without chroma subsampling for sharp and crystal clear text. 110 | 111 | # Features 112 | 113 | * Fully CLI based customization. User can specify all required parameters via 114 | command line switches, allow perfect integration into different window 115 | managers. 116 | * Desktop in window support with [XGrabKeyboard](https://tronche.com/gui/x/xlib/input/XGrabKeyboard.html) 117 | and [XUngrabKeyboard](https://tronche.com/gui/x/xlib/input/XUngrabKeyboard.html) 118 | while leaving mouse pointer ungrabbed. Supporting Alt+Tab and Windows special 119 | keys grab, even if assigned to the window manager. 120 | * SDL window is created without `SDL_WINDOW_RESIZABLE` flag set, so window 121 | cannot be resized by window manager and always uses native host resolution 122 | (no more blurry desktop). 123 | * Host to client resolution sync with automatic window resize. User can change 124 | resolution in Windows control panel and client polls for the changes and 125 | adjust client window size. 126 | * Specify client window size via command line and host will change native 127 | resolution to it once the connection has been established. 128 | * Configurable mouse wheel sensitivity. User can specify mouse scroll speed via 129 | command line switch serving different needs and requirements. 130 | * Modular architecture and can be extended with additional streaming host 131 | services like Nvidia GameStream via Moonlight libraries. 132 | * Screen saver and screen locker support. By default screen saver support is 133 | enabled but user can specify command line switch to avoid setting [SDL_EnableScreenSaver](https://wiki.libsdl.org/SDL_EnableScreenSaver) 134 | and disallow X server to lock the local screen. 135 | * Built-in USB redirection with automatic reconnect support using 136 | [usbredir protocol](https://gitlab.freedesktop.org/spice/usbredir). User can 137 | specify via command line which local USB devices will be redirected to the 138 | host (e.g. to forward a webcam with microphone). However usbredir protocol is 139 | currently only supported if using KVM, Xen or Virtuozzo Hybrid Server with 140 | QEMU. Other virtualization solutions may use standard Linux USB/IP server and 141 | native [Windows client driver](https://github.com/cezanne/usbip-win). 142 | 143 | # Parsec Warp 144 | 145 | * Support for disabling chroma subsampling to support color mode 4:4:4 with 146 | sharp and crisp text and better colors. Available for Nvidia Hosts running 147 | GTX 900 or better. 148 | 149 | # Known Issues 150 | 151 | * Color mode 4:4:4 is not yet supported by the SDK. There is an open bug at [Parsec SDK GitHub](https://github.com/parsec-cloud/parsec-sdk/issues/36) 152 | and Parsec team want to fix it with next SDK release. In official [Parsec](https://parsec.app/downloads) 153 | client it works already with some internal callbacks in the SDK. 154 | * Resolution changes from client connected to the host are not persistent and 155 | only valid within the session. Once the last client disconnects the host 156 | restores original resolution. 157 | * No macOS and Windows support yet. However porting should be fairly easy but I 158 | haven't tested it and pull requests are welcome. 159 | 160 | # Building 161 | 162 | VDI Stream Client uses GNU Build System to configure, build and install the 163 | application. It requires `sdl2`, `sdl2_ttf`, `libx11`, `libglvnd`, `libusb`, 164 | `usbredir` and the [Parsec SDK](https://github.com/parsec-cloud/parsec-sdk). 165 | The build system will search the SDK first in build directory and use DSO 166 | linking, the resulting binary will be redistributable but you need to ship 167 | Parsec library somehow. If not found, it will search in system-wide include and 168 | library directories and link accordingly, binary may not be redistributable. 169 | For build and install use the commands below and if `--prefix=/usr` is used, 170 | the `make install` command must be run as root user. 171 | 172 | ``` 173 | git clone https://github.com/parsec-cloud/parsec-sdk 174 | ./configure --prefix=/usr && 175 | make && 176 | make install 177 | ``` 178 | 179 | Arch Linux users can download ready-to-use `PKGBUILD` file available from 180 | [Arch User Repository (AUR)](https://aur.archlinux.org/packages/vdi-stream-client/), following these [build](https://wiki.archlinux.org/index.php/Arch_User_Repository#Build_the_package) and [install](https://wiki.archlinux.org/index.php/Arch_User_Repository#Install_the_package) instructions. 181 | 182 | # Usage 183 | 184 | VDI Stream Client requires that the Parsec Windows host ([x86_64](https://builds.parsecgaming.com/package/parsec-windows.exe) 185 | or [x86](https://builds.parsecgaming.com/package/parsec-windows32.exe)) is 186 | running and you have created a [free account](https://parsec.app/signup). 187 | There are several advanced configuration options for visual and network 188 | latency improvements described in the Parsec [documentation](https://support.parsec.app/hc/en-us/articles/360001562772-All-Advanced-Configuration-Options) 189 | in the "Hosting Settings" chapter. 190 | 191 | The client requires a `sessionID` and a `peerID` obtained through the Parsec 192 | API to identify users to make secure connections. For convenience you can use 193 | [tools/parsec-login](tools/parsec-login) script to retrieve list of available 194 | hosts. This is one-time operation whenever you add Parsec host application to 195 | another Windows machine. 196 | 197 | ## USB Redirection 198 | 199 | If you are using [libvirt](https://libvirt.org/) for virtualization, you can 200 | redirect local USB devices to your Windows host. It is highly recommended to 201 | add XHCI controller because it is the only one which supports USB 1.1, USB 2.0 202 | and USB 3.0, the QEMU UHCI and EHCI controllers support only their respective 203 | USB standard. Windows 10 is shipped by default with an XHCI USB 3.0 driver. Add 204 | the following to your `` section in domain XML for an USB 3.0 205 | controller: 206 | 207 | ``` 208 | 209 | ``` 210 | 211 | With the controller you can start using USB redirection via TCP/IP protocol. 212 | Each USB device is redirected through an independent port and the firewall of 213 | your server must allow incoming TCP/IP connection for that. VDI Stream Client 214 | supports monitoring of hotplug events (e.g. plug and unplug) of the redirected 215 | USB devices to allow automatic reassignment to the Windows host. Add the 216 | following to your `` section in domain XML to enable redirection of 217 | one local USB device and replace `` with the IP address of your 218 | virtualization host: 219 | 220 | ``` 221 | 222 | 223 | 224 | ``` 225 | 226 | You need to add additional `` sections to redirect multiple devices 227 | and increase the port number accordingly. After reloading libvirt and starting 228 | the Virtual Machine with the configuration above, you can redirect a local USB 229 | device. You can get a list of available devices with their `` and 230 | `` with `lsusb` command. 231 | 232 | ``` 233 | vdi-stream-client --session --peer --redirect :@#4000 234 | ``` 235 | 236 | Once connection is established it will redirect the local USB device to the 237 | host and setup drivers. Multiple USB devices can be redirected using `,` 238 | separator to the `--redirect` switch. They will be reassigned if the client 239 | reconnects to the host. Moreover, devices are reconnected to the host 240 | automatically when you unplug and plug them again to the USB port. If the 241 | devices are not connected during startup of the client, they are monitored and 242 | redirected as soon as they are attached to the client. 243 | 244 | # Notes 245 | 246 | USB redirection integration doesn't support any kind of encryption. The main 247 | goal of this client is to support in-house desktop streaming between client and 248 | host. Please use a VPN like [WireGuard](https://www.wireguard.com/) if you are 249 | using it across [WAN](https://en.wikipedia.org/wiki/Wide_area_network) 250 | connections. 251 | 252 | # Future 253 | 254 | Building a truly and fully open-source GPU accelerated desktop streaming 255 | solution requires a host service running inside the Windows environment. 256 | Hardware encoding is supported by FFmpeg for the major GPU vendors. VDI Stream 257 | Host application seems reasonable. 258 | 259 | # Thanks 260 | 261 | A special thanks goes to Parsec Cloud, Inc. as they provided a Parsec Warp 262 | subscription to support this project. 263 | 264 | # Support 265 | 266 | If you want to help out with development without providing code yourself, you 267 | can always donate to the project directly using the following platforms. 268 | 269 | * [GitHub](https://github.com/sponsors/mbroemme) 270 | * [PayPal](https://www.paypal.com/donate?hosted_button_id=TJLZRF9BPVX22) 271 | * Bitcoin - bc1qh2pssvhac7629k3ndmmpw3azsm4yjz9jvaaycr 272 | * Litecoin - ltc1qfz93z928vr36d9ksp5mstt385t84mdx4shsv35 273 | 274 | # Videos 275 | 276 | | [![Unigine Valley](http://img.youtube.com/vi/QU3rVi3JyvY/mqdefault.jpg)](http://www.youtube.com/watch?v=QU3rVi3JyvY "Unigine Valley") | [![3DMark Night Raid Demo](http://img.youtube.com/vi/NLhCHEwChzM/mqdefault.jpg)](https://www.youtube.com/watch?v=NLhCHEwChzM "3DMark Night Raid Demo") | [![3DMark Wild Life Benchmark](http://img.youtube.com/vi/dfT5Glya4Yw/mqdefault.jpg)](https://www.youtube.com/watch?v=dfT5Glya4Yw "3DMark Wild Life Benchmark") | 277 | |------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| 278 | | [![USB Redirection](http://img.youtube.com/vi/_KP94X3J9n4/mqdefault.jpg)](https://www.youtube.com/watch?v=_KP94X3J9n4 "USB Redirection") | [![Video Playback](http://img.youtube.com/vi/5NDn_mNogNk/mqdefault.jpg)](https://www.youtube.com/watch?v=5NDn_mNogNk "Video Playback") | [![Unreal Tournament 2004](http://img.youtube.com/vi/q4QOEhNK-us/mqdefault.jpg)](https://www.youtube.com/watch?v=q4QOEhNK-us "Unreal Tournament 2004") | 279 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # show information about what is going on. 4 | echo "Generating build information using aclocal, autoheader, automake and autoconf" 5 | echo "This may take a while ..." 6 | 7 | # touch the timestamps on all the files since they can be messed up. 8 | directory=`dirname $0` 9 | touch $directory/configure.ac 10 | 11 | # regenerate configuration files. 12 | aclocal 13 | autoheader 14 | automake --foreign --add-missing --copy 15 | autoconf 16 | 17 | # show instructions what to do now. 18 | echo "Now you are ready to run ./configure" 19 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # the autoconf initilization. 2 | AC_INIT(vdi-stream-client, 0.3.0, [mbroemme@libmpq.org], [vdi-stream-client]) 3 | 4 | # detect the canonical target environment. 5 | AC_CANONICAL_TARGET 6 | 7 | # initialize autoconf and automake system. 8 | AM_INIT_AUTOMAKE([no-dependencies]) 9 | AC_CONFIG_HEADERS([config.h:config.h.in]) 10 | 11 | # create define for the package author. 12 | AC_DEFINE([AUTHOR], ["Maik Broemme "], [Define to the author of this package.]) 13 | 14 | # checking for programs. 15 | AC_PROG_CC 16 | 17 | # checking for pkg-config application. 18 | PKG_PROG_PKG_CONFIG 19 | 20 | # checking for libdl library. 21 | AC_CHECK_HEADER([dlfcn.h], [], [AC_MSG_ERROR([*** dlfcn.h is required, install glibc header files])]) 22 | AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_ERROR([*** dlopen is required, install glibc library files])]) 23 | 24 | # checking for libx11 library. 25 | PKG_CHECK_MODULES([X11], [x11]) 26 | 27 | # checking for libglvnd library. 28 | PKG_CHECK_MODULES([GL], [gl]) 29 | 30 | # checking for sdl2 library. 31 | PKG_CHECK_MODULES([SDL2], [sdl2 >= 2.0.5]) 32 | 33 | # checking for sdl2_ttf library. 34 | PKG_CHECK_MODULES([SDL2_TTF], [SDL2_ttf >= 2.0.5]) 35 | 36 | # checking for libusb library. 37 | PKG_CHECK_MODULES([USB], [libusb-1.0 >= 1.0.9]) 38 | 39 | # checking for usbredir library. 40 | PKG_CHECK_MODULES([USBREDIRHOST], [libusbredirhost >= 0.7.1]) 41 | PKG_CHECK_MODULES([USBREDIRPARSER], [libusbredirparser-0.5 >= 0.7.1]) 42 | 43 | # checking for internal parsec sdk. 44 | AC_CHECK_FILE([parsec-sdk/sdk/parsec.h], [AC_CHECK_FILE([parsec-sdk/sdk/linux/libparsec.so], [enable_internal_parsec_sdk="yes"])]) 45 | 46 | # checking for external parsec sdk usage. 47 | if test "x$enable_internal_parsec_sdk" != "xyes"; then 48 | 49 | # checking for external parsec sdk. 50 | AC_CHECK_HEADER([parsec/parsec.h], [], [AC_MSG_ERROR([*** parsec/parsec.h is required, install parsec-sdk header files])]) 51 | AC_CHECK_LIB([parsec], [ParsecInit], [], [AC_MSG_ERROR([*** ParsecInit is required, install parsec-sdk library files])]) 52 | AC_CHECK_MEMBER([struct ParsecCursor.hidden], [], [AC_MSG_ERROR([*** struct ParsecCursor.hidden is required, install parsec-sdk >= 6.0])], [[#include ]]) 53 | fi 54 | 55 | # condition for parsec sdk to usage. 56 | AM_CONDITIONAL([INTERNAL_PARSEC_SDK], [test "x$enable_internal_parsec_sdk" = "xyes"]) 57 | 58 | # creating files. 59 | AC_CONFIG_FILES([ 60 | Makefile 61 | src/Makefile 62 | docs/man1/Makefile 63 | ]) 64 | 65 | # perform configuration actions. 66 | AC_OUTPUT 67 | -------------------------------------------------------------------------------- /docs/man1/Makefile.am: -------------------------------------------------------------------------------- 1 | # manual page directory. 2 | EXTRA_DIST = $(man_MANS) 3 | 4 | # manual pages for the installed binaries. 5 | man_MANS = \ 6 | vdi-stream-client.1 7 | -------------------------------------------------------------------------------- /docs/man1/vdi-stream-client.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2021 Maik Broemme 2 | .\" 3 | .\" This program is free software: you can redistribute it and/or modify 4 | .\" it under the terms of the GNU General Public License as published by 5 | .\" the Free Software Foundation, either version 3 of the License, or 6 | .\" (at your option) any later version. 7 | .\" 8 | .\" This program is distributed in the hope that it will be useful, 9 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | .\" GNU General Public License for more details. 12 | .\" 13 | .\" You should have received a copy of the GNU General Public License 14 | .\" along with this program. If not, see . 15 | .TH VDI-STREAM-CLIENT 1 2021-01-26 "VDI Stream Client" "multimedia" 16 | .SH NAME 17 | vdi-stream-client \- a low latency desktop streaming client 18 | .SH SYNOPSIS 19 | .B vdi-stream-client 20 | [\fI\-\-session\fP ] [\fI\-\-peer\fP ] [\fIoptions\fP] 21 | .SH DESCRIPTION 22 | .PP 23 | VDI Stream Client is a tiny and low latency Linux client which connects 24 | to Parsec Host running on Windows. It allows to run fully GPU accelerated 25 | Windows desktop environment on a remote machine while streaming the 26 | content to a local Linux system which process keyboard and mouse input. 27 | The remote server can be a virtual machine running on-top of on-premise 28 | deployments of Virtuozzo Hybrid Server, KVM or Xen. It can also connect 29 | to public clouds like Amazon (EC2 G3 Accelerated) or Microsoft Azure 30 | (NV6). It uses Simple DirectMedia Layer (SDL2) for low-level access to 31 | audio, video, keyboard, mouse and clipboard. 32 | .SH OPTIONS 33 | Help options: 34 | .TP 8 35 | .B \-h|\-\-help 36 | .ti 15 37 | Print the usage message on the standard output. 38 | .TP 8 39 | .B \-v|\-\-version 40 | .ti 15 41 | Print the currently installed version on the standard output. 42 | .PP 43 | Parsec options: 44 | .TP 8 45 | .B \-\-session <\fIid\fP> 46 | .ti 15 47 | The session ID to connect to Parsec service. This option is mandatory. 48 | .TP 8 49 | .B \-\-peer <\fIid\fP> 50 | .ti 15 51 | The peer ID of the remote Parsec host. This option is mandatory. 52 | .TP 8 53 | .B \-\-timeout <\fIseconds\fP> 54 | .ti 15 55 | The connection timeout when first connection to host is established. 56 | There will be no reconnect in this case. The default timeout is 5 57 | seconds. 58 | .TP 8 59 | .B \-\-speed <\fIspeed\fP> 60 | .ti 15 61 | The mouse wheel snesitivity to use, supported range is between 0 62 | (disable mouse wheel completely) up to 500. The value is in pixel. The 63 | default value is 100. 64 | .TP 8 65 | .B \-\-width <\fIwidth\fP> 66 | .ti 15 67 | The host screen and window width to use. The host will change 68 | resolution either to specified value or - if not supported - to closest 69 | one which matches. If not used, the client will resize window to current 70 | configured host width. The value is in pixel. 71 | .TP 8 72 | .B \-\-height <\fIheight\fP> 73 | .ti 15 74 | The host screen and window height to use. The host will change 75 | resolution either to specified value or - if not supported - to closest 76 | one which matches. If not used, the client will resize window to current 77 | configured host height. The value is in pixel. 78 | .PP 79 | Parsec Warp options: 80 | .TP 8 81 | .B \-\-no\-subsampling 82 | .ti 15 83 | Disable compression and chroma subsampling. If disabled, host will 84 | compress video stream and apply chroma subsampling with mode 4:2:0 to 85 | reduce data transfers. If enabled, no chroma subsampling is applied and 86 | client will receive sharp and crisp stream with mode 4:4:4. Disabling is 87 | only available under commercial subscription Parsec Warp. It is enabled 88 | by default. 89 | .PP 90 | Client options: 91 | .TP 8 92 | .B \-\-no\-acceleration 93 | .ti 15 94 | Disable hardware accelerated client decoding. If disabled, client will 95 | decode frames in software on CPU. If enabled, client will decode frames 96 | acclerated with the help of GPU. In both cases frames are rendered with 97 | OpenGL. With software implementation it is almost impossible to reach 98 | smooth client rendering. It is enabled by default. 99 | .TP 8 100 | .B \-\-no\-upnp 101 | .ti 15 102 | Disable UPnP NAT traversal support. If disabled, client may not be 103 | able to connect to host. If enabled, client will use UPnP to assist 104 | NAT traversal. It is not recommended to turn it off due to UDP 105 | client listening. It is enabled by default. 106 | .TP 8 107 | .B \-\-no\-reconnect 108 | .ti 15 109 | Disable automatic reconnect in case of network or service failures. If 110 | disabled, client will immediately terminate on failures. If enabled a 111 | black window with text "Reconnecting..." is shown in case of failures. 112 | It is recommended to leave it enabled if you are on roaming or an 113 | unstable and slow network link. It is enabled by default. 114 | .TP 8 115 | .B \-\-no\-grab 116 | .ti 15 117 | Disable exclusive mouse grab. If disabled, the mouse is passive grabbed 118 | and can enter and leave the window when mouse is moved. If enabled, the 119 | first press of any mouse button will lock the mouse into the window. To 120 | release the mouse grab you need to press "Ctrl+Alt". If an application 121 | requests relative mode it is being grabbed regardless of this option, 122 | mostly the case for DirectX applications and during login of the Windows 123 | user. Without relative grabbing most games would behave unpredictable. 124 | A relative grabe can be released with "Ctrl+Alt". A relative grab can be 125 | noticed in the Window title and with an invisible the mouse cursor. 126 | .TP 8 127 | .B \-\-no\-screensaver 128 | .ti 15 129 | Disable screen saver and screen locker support on client machine (Linux 130 | X11). If disabled, configured X11 screen saver and lockers are ignored 131 | and X11 will never start them. This applies only to screen savers and 132 | lockers using the X11 API. If enabled, X11 screen saver and lockers will 133 | work as usual. It is enabled by default. 134 | .TP 8 135 | .B \-\-no\-clipboard 136 | .ti 15 137 | Disable clipboard sharing between client and host. If disabled, the 138 | clipboards of client and host are independent and never synchronized. It 139 | helps to avoid occasional leaks of sensitive information made by copy 140 | and paste mistakes. If enabled, both clipboards are always synchronized 141 | in bi-directional mode. It is enabled by default. 142 | .TP 8 143 | .B \-\-no\-audio 144 | .ti 15 145 | Disable audio streaming support. If disabled, no audio from host is 146 | streamed and played on client machine. If enabled, audio is streamed 147 | and played with default audio device used by SDL. It is enabled by 148 | default. 149 | .TP 8 150 | .B \-\-no\-hevc 151 | .ti 15 152 | Disable H.265 (HEVC) video codec. If disabled, client will use H.264 153 | (AVC) video codec. If enabled, client will use H.265 (HEVC) video codec. 154 | There is a trade-off between CPU performance and network latency and 155 | bandwidth consumption. When using H.265 (HEVC) - even in case of GPU 156 | decoding - CPU load and network latency is higher while network 157 | bandwidth is reduced. When using H.264 (AVC) the CPU load and network 158 | latency is lower while more network bandwidth is consumed. It is enabled 159 | by default. 160 | .PP 161 | USB options: 162 | .TP 8 163 | .B \-\-redirect <\fIvendorID\fP>:<\fIproductID\fP>@<\fIip\fP>#<\fIport\fP>,[...] 164 | .ti 15 165 | The USB devices to redirect to the host. The client will monitor the 166 | specified USB device with <\fIvendorID\fP> and <\fIproductID\fP> for 167 | hotplug events (attach and detach). To get a list of available USB devices 168 | you can use the "lsusb" command. If a USB device is connected to the 169 | client, it gets automatically redirected to the host with exclusive 170 | access. The client will connect to <\fIip\fP> and <\fIport\fP> to your 171 | virtualization host to redirect devices to the hypervisor. Multiple USB 172 | devices can be redirected if comma separated. You can redirect up to 8 173 | devices in total. Moreover, devices are reconnected to the host 174 | automatically when you unplug and plug them again to the USB port and if 175 | not connected during startup of the client, they are monitored and 176 | redirected as soon as they are attached. 177 | .SH KEYBOARD CONTROL 178 | During connection to the host, you can use certain key combinations to 179 | release keyboard grab or to switch into force grab mode. 180 | .TP 8 181 | .B Ctrl+Alt 182 | .ti 15 183 | Toggle mouse and keyboard grab if exclusive mouse grab is enabled. If any 184 | mouse button is pressed, the cursor will be locked into the window and all 185 | keys are passed. The Ctrl+Alt key combination will release the grab. 186 | See \-\-no\-grab option for more details. 187 | .TP 8 188 | .B Shift+F12 189 | .ti 15 190 | Toggle mouse and keyboard grab regardless if exclusive grab is enabled 191 | or disabled. If enabling forced grab, it will lock the cursor to the window 192 | and pass all keys, except Shift+F12 to the window. The client configured 193 | screen saver and screen locker is disabled and host must process locking. 194 | The Ctrl+Alt key combination will not release a forced grab. If disabling 195 | forced grab, it will release the mouse from the window, don't pass window 196 | manager key combinations anymore and re-enable screen saver and screen 197 | locker if necessary. 198 | .SH AUTHOR 199 | Written by Maik Broemme 200 | .SH REPORTING BUGS 201 | Report bugs to 202 | .SH COPYRIGHT 203 | VDI Stream Client is a very tiny and low latency desktop streaming 204 | client for remote Windows guests with GPU passthrough which supports 205 | Nvidia NVENC, AMD VCE, VCN and Intel Quick Sync Video. 206 | 207 | Copyright (C) 2020-2021 Maik Broemme 208 | 209 | This program is free software: you can redistribute it and/or modify 210 | it under the terms of the GNU General Public License as published by 211 | the Free Software Foundation, either version 3 of the License, or 212 | (at your option) any later version. 213 | 214 | This program is distributed in the hope that it will be useful, 215 | but WITHOUT ANY WARRANTY; without even the implied warranty of 216 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 217 | GNU General Public License for more details. 218 | 219 | You should have received a copy of the GNU General Public License 220 | along with this program. If not, see . 221 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # the main programs. 2 | bin_PROGRAMS = vdi-stream-client 3 | 4 | # sources for vdi-stream-client program. 5 | vdi_stream_client_SOURCES = client.c parsec.c redirect.c audio.c video.c 6 | vdi_stream_client_CFLAGS = $(USB_CFLAGS) $(USBREDIRHOST_CFLAGS) $(USBREDIRPARSER_CFLAGS) $(X11_CFLAGS) $(GL_CFLAGS) $(SDL2_CFLAGS) $(SDL2_TTF_CFLAGS) 7 | vdi_stream_client_LDADD = $(USB_LIBS) $(USBREDIRHOST_LIBS) $(USBREDIRPARSER_LIBS) $(X11_LIBS) $(GL_LIBS) $(SDL2_LIBS) $(SDL2_TTF_LIBS) 8 | 9 | # install libparsec for dso loading. 10 | if INTERNAL_PARSEC_SDK 11 | vdi_stream_client_LDFLAGS = -Wl,-rpath,$(libdir)/vdi-stream-client/plugins 12 | libparsecdir = $(libdir)/vdi-stream-client/plugins 13 | libparsec_DATA = ../parsec-sdk/sdk/linux/libparsec.so 14 | EXTRA_DIST = $(libparsec_DATA) 15 | endif 16 | -------------------------------------------------------------------------------- /src/audio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * audio.c -- audio rendering thread via sdl 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* internal includes. */ 21 | #include "client.h" 22 | #include "parsec.h" 23 | 24 | /* system includes. */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* parsec audio event. */ 31 | static void vdi_stream_client__audio(const Sint16 *pcm, Uint32 frames, void *opaque) { 32 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 33 | 34 | Uint32 size = SDL_GetQueuedAudioSize(parsec_context->audio); 35 | Uint32 queued_frames = size / (PARSEC_AUDIO_CHANNELS * sizeof(Sint16)); 36 | Uint32 queued_packets = queued_frames / PARSEC_AUDIO_FRAMES_PER_PACKET; 37 | 38 | if (parsec_context->playing == SDL_TRUE && queued_packets > parsec_context->max_buffer) { 39 | SDL_ClearQueuedAudio(parsec_context->audio); 40 | SDL_PauseAudioDevice(parsec_context->audio, 1); 41 | parsec_context->playing = SDL_FALSE; 42 | } else if (parsec_context->playing == SDL_FALSE && queued_packets >= parsec_context->min_buffer) { 43 | SDL_PauseAudioDevice(parsec_context->audio, 0); 44 | parsec_context->playing = SDL_TRUE; 45 | } 46 | 47 | SDL_QueueAudio(parsec_context->audio, pcm, frames * PARSEC_AUDIO_CHANNELS * sizeof(Sint16)); 48 | } 49 | 50 | /* sdl audio thread. */ 51 | Sint32 vdi_stream_client__audio_thread(void *opaque) { 52 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 53 | 54 | while (parsec_context->done == SDL_FALSE) { 55 | 56 | /* poll audio only if connected. */ 57 | if (parsec_context->connection == SDL_TRUE) { 58 | ParsecClientPollAudio(parsec_context->parsec, vdi_stream_client__audio, 100, parsec_context); 59 | } 60 | 61 | /* delay loop if in reconnect state. */ 62 | if (parsec_context->connection == SDL_FALSE) { 63 | 64 | /* clear queue and close audio device. */ 65 | if (parsec_context->playing == SDL_TRUE) { 66 | SDL_ClearQueuedAudio(parsec_context->audio); 67 | SDL_PauseAudioDevice(parsec_context->audio, 1); 68 | parsec_context->playing = SDL_FALSE; 69 | } 70 | SDL_Delay(parsec_context->timeout); 71 | } 72 | } 73 | 74 | return VDI_STREAM_CLIENT_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /src/audio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * audio.h -- audio rendering thread via sdl 3 | * 4 | * Copyright (c) 2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _AUDIO_H 21 | #define _AUDIO_H 22 | 23 | /* sdl includes. */ 24 | #define SDL_MAIN_HANDLED 25 | #include 26 | 27 | /* audio thread. */ 28 | Sint32 vdi_stream_client__audio_thread(void *opaque); 29 | 30 | #endif /* _AUDIO_H */ 31 | -------------------------------------------------------------------------------- /src/client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * client.c -- gpu accelerated streaming client 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* internal includes. */ 21 | #include "client.h" 22 | #include "parsec.h" 23 | 24 | /* system includes. */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* this function show the usage. */ 31 | Sint32 vdi_stream_client__usage(char *program_name) { 32 | 33 | /* show the help. */ 34 | printf("Usage: %s [session] [peer] (options)...\n", program_name); 35 | printf("GPU accelerated remote host graphical console\n"); 36 | printf("\n"); 37 | printf("Help Options:\n"); 38 | printf(" -h, --help show this help screen\n"); 39 | printf(" -v, --version show the version information\n"); 40 | printf("\n"); 41 | printf("Parsec Options:\n"); 42 | printf(" --session session id for connection (mandatory)\n"); 43 | printf(" --peer peer id for connection (mandatory)\n"); 44 | printf(" --timeout connection timeout (default: 5 seconds)\n"); 45 | printf(" --speed mouse wheel sensitivity: 0 to 500 (default: 100)\n"); 46 | printf(" --width horizontal resolution (default: host resolution)\n"); 47 | printf(" --height vertical resolution (default: host resolution)\n"); 48 | printf("\n"); 49 | printf("Parsec Warp Options:\n"); 50 | printf(" --no-subsampling disable compression with chroma subsampling\n"); 51 | printf("\n"); 52 | printf("Client Options:\n"); 53 | printf(" --no-acceleration disable hardware accelerated decoding\n"); 54 | printf(" --no-upnp disable upnp nat traversal\n"); 55 | printf(" --no-reconnect disable automatic reconnect in case of failures\n"); 56 | printf(" --no-grab disable exclusive mouse grab\n"); 57 | printf(" --no-screensaver disable screen saver and lockers\n"); 58 | printf(" --no-clipboard disable clipboard sharing\n"); 59 | printf(" --no-audio disable audio streaming\n"); 60 | printf(" --no-hevc disable H.265/HEVC video codec\n"); 61 | printf("\n"); 62 | printf("USB Options:\n"); 63 | printf(" --redirect :@
#,[...]\n"); 64 | printf(" redirect single or multiple local USB devices\n"); 65 | printf("\n"); 66 | printf("Please report bugs to the appropriate authors, which can be found in the\n"); 67 | printf("version information. All other things can be send to <%s>\n", PACKAGE_BUGREPORT); 68 | 69 | /* if no error was found, return zero. */ 70 | return VDI_STREAM_CLIENT_SUCCESS; 71 | } 72 | 73 | /* this function shows the version information. */ 74 | Sint32 vdi_stream_client__version(char *program_name) { 75 | 76 | /* show the version. */ 77 | printf("%s version %s Copyright (c) 2020 The VDI Stream developers\n", program_name, VERSION); 78 | printf("Written by %s\n", AUTHOR); 79 | printf("\n"); 80 | printf("This is free software; see the source for copying conditions. There is NO\n"); 81 | printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); 82 | 83 | /* if no error was found, return zero. */ 84 | return VDI_STREAM_CLIENT_SUCCESS; 85 | } 86 | 87 | /* main function to initialize structs and parse command line options. */ 88 | Sint32 main(Sint32 argc, char **argv) { 89 | 90 | /* variables. */ 91 | Sint32 option_index = 0; 92 | Sint32 opt; 93 | char *program_name; 94 | vdi_config_s *vdi_config = NULL; 95 | 96 | /* temp variables for command line parser. */ 97 | Sint32 device; 98 | Sint32 type; 99 | char *redirect; 100 | char *item; 101 | char *delim; 102 | char *endptr; 103 | Uint64 port; 104 | 105 | /* command line options. */ 106 | struct option long_options[] = { 107 | 108 | /* help options. */ 109 | {"help", no_argument, NULL, 'h'}, 110 | {"version", no_argument, NULL, 'v'}, 111 | 112 | /* parsec options. */ 113 | {"session", required_argument, NULL, 'x'}, 114 | {"peer", required_argument, NULL, 'y'}, 115 | {"timeout", required_argument, NULL, 't'}, 116 | {"speed", required_argument, NULL, 's'}, 117 | {"width", required_argument, NULL, 'w'}, 118 | {"height", required_argument, NULL, 'u'}, 119 | 120 | /* parsec warp options. */ 121 | {"no-subsampling", no_argument, NULL, 'm'}, 122 | 123 | /* client options. */ 124 | {"no-acceleration", no_argument, NULL, 'd'}, 125 | {"no-upnp", no_argument, NULL, 'b'}, 126 | {"no-reconnect", no_argument, NULL, 'r'}, 127 | {"no-grab", no_argument, NULL, 'g'}, 128 | {"no-screensaver", no_argument, NULL, 'z'}, 129 | {"no-clipboard", no_argument, NULL, 'p'}, 130 | {"no-audio", no_argument, NULL, 'a'}, 131 | {"no-hevc", no_argument, NULL, 'c'}, 132 | 133 | /* usb options. */ 134 | {"redirect", required_argument, NULL, 'f'}, 135 | 136 | /* end options. */ 137 | {0, 0, 0, 0}, 138 | }; 139 | 140 | /* default values. */ 141 | optind = 0; 142 | opterr = 0; 143 | 144 | /* allocate memory defaults. */ 145 | if ((vdi_config = calloc(1, sizeof(vdi_config_s))) == NULL) { 146 | goto error; 147 | } 148 | if ((vdi_config->session = calloc(0, sizeof(vdi_config->session))) == NULL || 149 | (vdi_config->peer = calloc(0, sizeof(vdi_config->peer))) == NULL) { 150 | goto error; 151 | } 152 | 153 | /* parsec defaults. */ 154 | vdi_config->timeout = 5000; 155 | vdi_config->speed = 100; 156 | 157 | /* parsec warp defaults. */ 158 | vdi_config->subsampling = 1; 159 | 160 | /* client defaults. */ 161 | vdi_config->acceleration = 1; 162 | vdi_config->upnp = 1; 163 | vdi_config->reconnect = 1; 164 | vdi_config->grab = 1; 165 | vdi_config->screensaver = 1; 166 | vdi_config->clipboard = 1; 167 | vdi_config->audio = 1; 168 | vdi_config->hevc = 1; 169 | 170 | program_name = argv[0]; 171 | if (program_name && strrchr(program_name, '/')) { 172 | program_name = strrchr(program_name, '/') + 1; 173 | } 174 | 175 | if (argc <= 1) { 176 | vdi_stream_client__usage(program_name); 177 | return VDI_STREAM_CLIENT_SUCCESS; 178 | } 179 | 180 | /* parse command line. */ 181 | while ((opt = getopt_long(argc, argv, ":hv", long_options, &option_index)) != -1) { 182 | 183 | /* check if all command line options are parsed. */ 184 | if (opt == -1) { 185 | break; 186 | } 187 | 188 | /* parse option. */ 189 | switch (opt) { 190 | 191 | /* help options. */ 192 | case 'h': 193 | vdi_stream_client__usage(program_name); 194 | return VDI_STREAM_CLIENT_SUCCESS; 195 | case 'v': 196 | vdi_stream_client__version(program_name); 197 | return VDI_STREAM_CLIENT_SUCCESS; 198 | 199 | /* parsec options. */ 200 | case 'x': 201 | vdi_config->session = strdup(argv[optind - 1]); 202 | continue; 203 | case 'y': 204 | vdi_config->peer = strdup(argv[optind - 1]); 205 | continue; 206 | case 't': 207 | vdi_config->timeout = strtol(argv[optind - 1], NULL, 10) * 1000; 208 | continue; 209 | case 's': 210 | vdi_config->speed = strtol(argv[optind - 1], NULL, 10); 211 | if (vdi_config->speed < 0) { 212 | vdi_config->speed = 0; 213 | } 214 | if (vdi_config->speed > 500) { 215 | vdi_config->speed = 500; 216 | } 217 | continue; 218 | case 'w': 219 | vdi_config->width = strtol(argv[optind - 1], NULL, 10); 220 | continue; 221 | case 'u': 222 | vdi_config->height = strtol(argv[optind - 1], NULL, 10); 223 | continue; 224 | 225 | /* parsec warp options. */ 226 | case 'm': 227 | vdi_config->subsampling = 0; 228 | continue; 229 | 230 | /* client options. */ 231 | case 'd': 232 | vdi_config->acceleration = 0; 233 | continue; 234 | case 'b': 235 | vdi_config->upnp = 0; 236 | continue; 237 | case 'r': 238 | vdi_config->reconnect = 0; 239 | continue; 240 | case 'g': 241 | vdi_config->grab = 0; 242 | continue; 243 | case 'z': 244 | vdi_config->screensaver = 0; 245 | continue; 246 | case 'p': 247 | vdi_config->clipboard = 0; 248 | continue; 249 | case 'a': 250 | vdi_config->audio = 0; 251 | continue; 252 | case 'c': 253 | vdi_config->hevc = 0; 254 | continue; 255 | 256 | /* usb options. */ 257 | case 'f': 258 | 259 | /* loop through multiple redirect configs. */ 260 | device = 0; 261 | while ((redirect = strsep(&argv[optind - 1], ",")) != NULL) { 262 | 263 | /* check if number of usb redirects are out of range. */ 264 | if (device >= USB_MAX) { 265 | fprintf(stderr, "%s: usb redirection limit of %d reached\n", program_name, USB_MAX); 266 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 267 | goto error; 268 | } 269 | 270 | /* initialize. */ 271 | memset(&vdi_config->server_addrs[device], 0, sizeof(vdi_config->server_addrs[device])); 272 | 273 | /* loop through redirect categroy. (usb vendor, product, address and port) */ 274 | type = 0; 275 | while ((item = strsep(&redirect, "@#")) != NULL) { 276 | 277 | /* usb device. */ 278 | if (type == 0) { 279 | 280 | /* check if usb vendor is out of range. */ 281 | vdi_config->usb_devices[device].vendor = strtol(item, &endptr, 16); 282 | if (vdi_config->usb_devices[device].vendor <= 0 || vdi_config->usb_devices[device].vendor > 0xffff) { 283 | fprintf(stderr, "%s: invalid vendor identifier in usb device: %s\n", program_name, item); 284 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 285 | goto error; 286 | } 287 | 288 | /* check if usb product is given. */ 289 | delim = strchr(item, ':'); 290 | if (*endptr != ':' || delim == NULL || strlen(delim) == 1) { 291 | fprintf(stderr, "%s: no product identifier in usb device\n", program_name); 292 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 293 | goto error; 294 | } 295 | 296 | /* check if usb product is out of range. (product id 0000 is valid) */ 297 | vdi_config->usb_devices[device].product = strtol(delim + 1, &endptr, 16); 298 | if (*endptr != '\0' || vdi_config->usb_devices[device].product < 0 || vdi_config->usb_devices[device].product > 0xffff) { 299 | fprintf(stderr, "%s: invalid product identifier in usb device: %s\n", program_name, item); 300 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 301 | goto error; 302 | } 303 | } 304 | 305 | /* address. */ 306 | if (type == 1) { 307 | 308 | /* check if empty ip address given. */ 309 | if (item[0] == '\0') { 310 | fprintf(stderr, "%s: no ip address in usb redirection\n", program_name); 311 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 312 | goto error; 313 | } 314 | 315 | /* check if ipv4 address. */ 316 | if (inet_pton(AF_INET, item, &vdi_config->server_addrs[device].v4.sin_addr) == 1) { 317 | vdi_config->server_addrs[device].v4.sin_family = AF_INET; 318 | } 319 | 320 | /* check if ipv6 address. */ 321 | if (inet_pton(AF_INET6, item, &vdi_config->server_addrs[device].v6.sin6_addr) == 1) { 322 | vdi_config->server_addrs[device].v6.sin6_family = AF_INET6; 323 | } 324 | 325 | /* check if bad formatted address. */ 326 | if (vdi_config->server_addrs[device].v4.sin_family != AF_INET && 327 | vdi_config->server_addrs[device].v6.sin6_family != AF_INET6) { 328 | fprintf(stderr, "%s: invalid address in usb redirection: %s\n", program_name, item); 329 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 330 | goto error; 331 | } 332 | } 333 | 334 | /* port. */ 335 | if (type == 2) { 336 | 337 | /* check if empty port given. */ 338 | if (item[0] == '\0') { 339 | fprintf(stderr, "%s: no port in usb redirection\n", program_name); 340 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 341 | goto error; 342 | } 343 | 344 | /* convert port string to integer. */ 345 | port = strtol(item, NULL, 10); 346 | 347 | /* check if port is out of range. */ 348 | if (port <= 0 || port >= 65536) { 349 | fprintf(stderr, "%s: invalid port in usb redirection: %s\n", program_name, item); 350 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 351 | goto error; 352 | } 353 | 354 | /* check if ipv4 address has been assigned previosuly. */ 355 | if (vdi_config->server_addrs[device].v4.sin_family != AF_INET) { 356 | vdi_config->server_addrs[device].v4.sin_port = htons(port); 357 | } 358 | 359 | /* check if ipv6 address has been assigned previosuly. */ 360 | if (vdi_config->server_addrs[device].v6.sin6_family != AF_INET6) { 361 | vdi_config->server_addrs[device].v6.sin6_port = htons(port); 362 | } 363 | } 364 | type++; 365 | } 366 | 367 | /* check if no ip address was given. */ 368 | if (type == 1) { 369 | fprintf(stderr, "%s: no ip address in usb redirection\n", program_name); 370 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 371 | goto error; 372 | } 373 | 374 | /* check if no port was given. */ 375 | if (type == 2) { 376 | fprintf(stderr, "%s: no port in usb redirection\n", program_name); 377 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 378 | goto error; 379 | } 380 | device++; 381 | } 382 | continue; 383 | 384 | /* missing arguments. */ 385 | case ':': 386 | fprintf(stderr, "%s: option `%s' requires an argument\n", program_name, argv[optind - 1]); 387 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 388 | goto error; 389 | 390 | /* unknown switches. */ 391 | case '?': 392 | fprintf(stderr, "%s: unrecognized option `%s'\n", program_name, argv[optind - 1]); 393 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 394 | goto error; 395 | } 396 | } 397 | 398 | /* mandatory arguments not given. */ 399 | if (strlen(vdi_config->session) == 0 || strlen(vdi_config->peer) == 0) { 400 | fprintf(stderr, "%s: mandatory arguments missing\n", program_name); 401 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 402 | goto error; 403 | } 404 | 405 | /* additional non-option arguments given. */ 406 | if (argc > optind) { 407 | fprintf(stderr, "%s: non-option argument `%s'\n", program_name, argv[optind]); 408 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); 409 | goto error; 410 | } 411 | 412 | /* main event loop. */ 413 | if (vdi_stream_client__event_loop(vdi_config) != 0) { 414 | goto error; 415 | } 416 | 417 | /* free allocated memory. */ 418 | free(vdi_config->session); 419 | free(vdi_config->peer); 420 | free(vdi_config); 421 | 422 | /* quit application. */ 423 | return VDI_STREAM_CLIENT_SUCCESS; 424 | 425 | error: 426 | 427 | /* free allocated memory. */ 428 | free(vdi_config->session); 429 | free(vdi_config->peer); 430 | free(vdi_config); 431 | 432 | /* quit application with error code. */ 433 | return VDI_STREAM_CLIENT_ERROR; 434 | } 435 | -------------------------------------------------------------------------------- /src/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * client.h -- default types and defines 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _CLIENT_H 21 | #define _CLIENT_H 22 | 23 | /* sdl includes. */ 24 | #define SDL_MAIN_HANDLED 25 | #include 26 | 27 | /* network includes. */ 28 | #include 29 | 30 | /* define return values. */ 31 | #define VDI_STREAM_CLIENT_SUCCESS 0 /* return value for all functions which success. */ 32 | #define VDI_STREAM_CLIENT_ERROR -1 /* generic error. */ 33 | 34 | /* define limits. */ 35 | #define USB_MAX 8 /* maximum number of usb redirects. */ 36 | 37 | /* define new print functions for logging. */ 38 | #define vdi_stream_client__log_info(...) printf(__VA_ARGS__); 39 | #define vdi_stream_client__log_error(...) fprintf(stderr, __VA_ARGS__); 40 | 41 | /* stored command line options. */ 42 | typedef struct { 43 | 44 | /* parsec options. */ 45 | char *session; /* session id for connection. */ 46 | char *peer; /* peer id for connection. */ 47 | Uint16 timeout; /* connection timeout in milliseconds. */ 48 | Uint16 speed; /* mouse wheel sensitivity. (0 - 255) */ 49 | Uint16 width; /* screen width in pixel. (host resolution is used if not specified) */ 50 | Uint16 height; /* screen height in pixel. (host resolution is used if not specified) */ 51 | 52 | /* parsec warp options. */ 53 | Uint16 subsampling; /* color mode to use. (0 = 4:4:4, 1 = 4:2:0) */ 54 | 55 | /* client options. */ 56 | Uint16 acceleration; /* client decoding type. (0 = software, 1 = hardware) */ 57 | Uint16 upnp; /* upnp nat traversal support. (0 = disable upnp, 1 = enable upnp) */ 58 | Uint16 reconnect; /* automatic reconnect support in case of failures. (0 = disable reconnect, 1 = enable reconnect). */ 59 | Uint16 grab; /* keyboard and mouse grabbing. (0 = grab only keyboard on mouse focus, 1 = grab keyboard and mouse) */ 60 | Uint16 screensaver; /* screen saver support. (0 = disable screen saver, 1 = enable screen saver) */ 61 | Uint16 clipboard; /* clipboard sharing support. (0 = disable clipboard sharing, 1 = enable clipboard sharing) */ 62 | Uint16 audio; /* audio support. (0 = disable audio streaming, 1 = enable audio streaming) */ 63 | Uint16 hevc; /* streaming codec to use. (0 = h264, 1 = h265) */ 64 | 65 | /* usb options. */ 66 | union { 67 | struct sockaddr_in v4; /* address (ipv4) to connect for usb redirection. */ 68 | struct sockaddr_in6 v6; /* address (ipv6) to connect for usb redirection. */ 69 | } server_addrs[USB_MAX]; 70 | struct { 71 | Sint32 vendor; /* vendor id of usb devices for redirection. */ 72 | Sint32 product; /* product id of usb devices for redirection. */ 73 | } usb_devices[USB_MAX]; 74 | } vdi_config_s; 75 | 76 | #endif /* _CLIENT_H */ 77 | -------------------------------------------------------------------------------- /src/parsec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * parsec.c -- desktop streaming with parsec sdk 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* internal includes. */ 21 | #include "audio.h" 22 | #include "client.h" 23 | #include "parsec.h" 24 | #include "redirect.h" 25 | #include "video.h" 26 | 27 | /* font include. */ 28 | #include "../include/font.h" 29 | 30 | /* system includes. */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /* sdl includes. */ 37 | #include 38 | 39 | /* parsec clipboard event. */ 40 | static void vdi_stream_client__clipboard(struct parsec_context_s *parsec_context, Uint32 id, Uint32 buffer_key) { 41 | char *msg = ParsecGetBuffer(parsec_context->parsec, buffer_key); 42 | 43 | if (msg && id == PARSEC_CLIPBOARD_MSG) { 44 | SDL_SetClipboardText(msg); 45 | } 46 | 47 | #ifdef HAVE_LIBPARSEC 48 | ParsecFree(msg); 49 | #else 50 | ParsecFree(parsec_context->parsec, msg); 51 | #endif 52 | } 53 | 54 | /* parsec cursor event. */ 55 | static void vdi_stream_client__cursor(struct parsec_context_s *parsec_context, ParsecCursor *cursor, Uint32 buffer_key, SDL_bool grab, SDL_bool grab_forced) { 56 | if (cursor->imageUpdate == SDL_TRUE) { 57 | Uint8 *image = ParsecGetBuffer(parsec_context->parsec, buffer_key); 58 | 59 | if (image != NULL) { 60 | SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(image, cursor->width, cursor->height, 61 | 32, cursor->width * 4, 0xff, 0xff00, 0xff0000, 0xff000000); 62 | SDL_Cursor *sdlCursor = SDL_CreateColorCursor(surface, cursor->hotX, cursor->hotY); 63 | SDL_SetCursor(sdlCursor); 64 | 65 | SDL_FreeCursor(parsec_context->cursor); 66 | parsec_context->cursor = sdlCursor; 67 | 68 | #ifdef HAVE_LIBPARSEC 69 | ParsecFree(image); 70 | #else 71 | ParsecFree(parsec_context->parsec, image); 72 | #endif 73 | } 74 | } 75 | 76 | if (cursor->relative == SDL_TRUE && cursor->hidden == SDL_TRUE) { 77 | SDL_ShowCursor(SDL_FALSE); 78 | SDL_SetRelativeMouseMode(SDL_TRUE); 79 | if (parsec_context->pressed == SDL_FALSE && grab_forced == SDL_FALSE) { 80 | SDL_SetWindowTitle(parsec_context->window, "VDI Stream Client (Press Ctrl+Alt to release grab)"); 81 | } 82 | parsec_context->relative = cursor->relative; 83 | } 84 | if (cursor->relative == SDL_FALSE && cursor->hidden == SDL_FALSE) { 85 | SDL_SetRelativeMouseMode(SDL_FALSE); 86 | SDL_ShowCursor(SDL_TRUE); 87 | SDL_WarpMouseInWindow(parsec_context->window, cursor->positionX, cursor->positionY); 88 | if (parsec_context->pressed == SDL_FALSE && grab == SDL_FALSE && grab_forced == SDL_FALSE) { 89 | SDL_SetWindowTitle(parsec_context->window, "VDI Stream Client"); 90 | } 91 | parsec_context->relative = cursor->relative; 92 | } 93 | } 94 | 95 | /* render text. */ 96 | Sint32 vdi_stream_client__render_text(void *opaque, char *text) { 97 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 98 | SDL_Color color = { 0x88, 0x88, 0x88, 0xFF }; 99 | GLfloat texture_coord[4]; 100 | GLenum gl_error; 101 | 102 | /* create the text surface. */ 103 | parsec_context->surface_ttf = TTF_RenderUTF8_Blended(parsec_context->font, text, color); 104 | if (parsec_context->surface_ttf == NULL) { 105 | vdi_stream_client__log_error("TTF surface creation failed: %s\n", TTF_GetError()); 106 | return VDI_STREAM_CLIENT_ERROR; 107 | } 108 | 109 | /* convert the text into an opengl texture. */ 110 | parsec_context->texture_ttf = vdi_stream_client__gl_load_texture(parsec_context->surface_ttf, texture_coord); 111 | if ((gl_error = glGetError()) != GL_NO_ERROR) { 112 | vdi_stream_client__log_error("TTF OpenGL texture creation failed: 0x%x\n", gl_error); 113 | return VDI_STREAM_CLIENT_ERROR; 114 | } 115 | 116 | /* make texture coordinates easy to understand. */ 117 | parsec_context->texture_min_x = texture_coord[0]; 118 | parsec_context->texture_min_y = texture_coord[1]; 119 | parsec_context->texture_max_x = texture_coord[2]; 120 | parsec_context->texture_max_y = texture_coord[3]; 121 | 122 | /* no error. */ 123 | return VDI_STREAM_CLIENT_SUCCESS; 124 | } 125 | 126 | /* parsec event loop. */ 127 | Sint32 vdi_stream_client__event_loop(vdi_config_s *vdi_config) { 128 | struct parsec_context_s parsec_context = {0}; 129 | struct redirect_context_s redirect_context[USB_MAX] = {0}; 130 | SDL_bool focus = SDL_FALSE; 131 | SDL_bool grab_forced = SDL_FALSE; 132 | Uint32 wait_time = 0; 133 | Uint32 last_time = 0; 134 | Sint32 error = 0; 135 | Sint32 x = 0; 136 | Sint32 y = 0; 137 | SDL_AudioSpec want = {0}; 138 | SDL_AudioSpec have = {0}; 139 | SDL_SysWMinfo wm_info; 140 | ParsecStatus e; 141 | ParsecConfig network_cfg = PARSEC_DEFAULTS; 142 | ParsecClientConfig cfg = PARSEC_CLIENT_DEFAULTS; 143 | Uint32 device; 144 | Uint32 count; 145 | SDL_Thread *video_thread = NULL; 146 | SDL_Thread *audio_thread = NULL; 147 | SDL_Thread *network_thread[USB_MAX] = {0}; 148 | 149 | /* default values. */ 150 | parsec_context.timeout = 100; 151 | 152 | /* sdl init. */ 153 | vdi_stream_client__log_info("Initialize SDL\n"); 154 | error = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); 155 | if (error != 0) { 156 | vdi_stream_client__log_error("Initialization failed: %s\n", SDL_GetError()); 157 | goto error; 158 | } 159 | SDL_VERSION(&wm_info.version); 160 | 161 | /* ttf init. */ 162 | vdi_stream_client__log_info("Initialize TTF\n"); 163 | error = TTF_Init(); 164 | if (error != 0) { 165 | vdi_stream_client__log_error("Initialization failed: %s\n", TTF_GetError()); 166 | goto error; 167 | } 168 | 169 | /* load font. */ 170 | parsec_context.font = TTF_OpenFontRW(SDL_RWFromMem(MorePerfectDOSVGA_ttf, MorePerfectDOSVGA_ttf_len), 1, 16); 171 | if (parsec_context.font == NULL) { 172 | vdi_stream_client__log_error("Loading font failed: %s\n", TTF_GetError()); 173 | goto error; 174 | } 175 | 176 | /* parsec init. */ 177 | vdi_stream_client__log_info("Initialize Parsec\n"); 178 | #ifdef HAVE_LIBPARSEC 179 | e = ParsecInit(PARSEC_VER, &network_cfg, NULL, &parsec_context.parsec); 180 | #else 181 | e = ParsecInit(NULL, &network_cfg, "libparsec.so", &parsec_context.parsec); 182 | #endif 183 | if (e != PARSEC_OK) { 184 | vdi_stream_client__log_error("Initialization failed with code: %d\n", e); 185 | goto error; 186 | } 187 | 188 | /* use client resolution if specified. */ 189 | if (vdi_config->width > 0 && vdi_config->height > 0) { 190 | vdi_stream_client__log_info("Override resolution %dx%d\n", vdi_config->width, vdi_config->height); 191 | cfg.video[DEFAULT_STREAM].resolutionX = vdi_config->width; 192 | cfg.video[DEFAULT_STREAM].resolutionY = vdi_config->height; 193 | } 194 | 195 | /* configure host video codec. */ 196 | if (vdi_config->hevc == 1) { 197 | cfg.video[DEFAULT_STREAM].decoderH265 = 1; 198 | } 199 | if (vdi_config->hevc == 0) { 200 | vdi_stream_client__log_info("Disable H.265 (HEVC) Video Codec\n"); 201 | cfg.video[DEFAULT_STREAM].decoderH265 = 0; 202 | } 203 | 204 | /* configure host color mode. */ 205 | if (vdi_config->subsampling == 1) { 206 | cfg.video[DEFAULT_STREAM].decoder444 = 1; 207 | } 208 | if (vdi_config->subsampling == 0) { 209 | vdi_stream_client__log_info("Disable Chroma Subsampling\n"); 210 | cfg.video[DEFAULT_STREAM].decoder444 = 0; 211 | 212 | /* TODO: parsec sdk bug. */ 213 | vdi_stream_client__log_info("WARNING: Parsec SDK bug and color mode 4:4:4 not working yet, details at:\n"); 214 | vdi_stream_client__log_info("WARNING: https://github.com/parsec-cloud/parsec-sdk/issues/36\n"); 215 | } 216 | 217 | /* configure client decoding acceleration. */ 218 | if (vdi_config->acceleration == 1) { 219 | cfg.video[DEFAULT_STREAM].decoderIndex = 1; 220 | } 221 | if (vdi_config->acceleration == 0) { 222 | vdi_stream_client__log_info("Disable Hardware Accelerated Video Decoding\n"); 223 | cfg.video[DEFAULT_STREAM].decoderIndex = 0; 224 | } 225 | 226 | /* configure upnp. */ 227 | if (vdi_config->upnp == 1) { 228 | network_cfg.upnp = 1; 229 | } 230 | if (vdi_config->upnp == 0) { 231 | vdi_stream_client__log_info("Disable UPnP\n"); 232 | network_cfg.upnp = 0; 233 | } 234 | 235 | /* check if reconnect should be disabled. */ 236 | if (vdi_config->reconnect == 0) { 237 | vdi_stream_client__log_info("Disable automatic reconnect\n"); 238 | } 239 | 240 | /* check if exclusive mouse grab should be disabled. */ 241 | if (vdi_config->grab == 0) { 242 | vdi_stream_client__log_info("Disable exclusive mouse grab\n"); 243 | } 244 | 245 | /* configure screen saver. */ 246 | if (vdi_config->screensaver == 1) { 247 | SDL_EnableScreenSaver(); 248 | } 249 | if (vdi_config->screensaver == 0) { 250 | vdi_stream_client__log_info("Disable screen saver\n"); 251 | SDL_DisableScreenSaver(); 252 | } 253 | 254 | /* check if clipboard should be disabled. */ 255 | if (vdi_config->clipboard == 0) { 256 | vdi_stream_client__log_info("Disable clipboard sharing\n"); 257 | } 258 | 259 | /* check if audio should be streamed. */ 260 | if (vdi_config->audio == 0) { 261 | vdi_stream_client__log_info("Disable audio streaming\n"); 262 | } 263 | 264 | /* parsec connect. */ 265 | vdi_stream_client__log_info("Connect to Parsec service\n"); 266 | e = ParsecClientConnect(parsec_context.parsec, &cfg, vdi_config->session, vdi_config->peer); 267 | if (e != PARSEC_OK) { 268 | vdi_stream_client__log_error("Connection failed with code: %d\n", e); 269 | goto error; 270 | } 271 | 272 | /* wait until connection is established. */ 273 | vdi_stream_client__log_info("Connect to Parsec host\n"); 274 | while (parsec_context.decoder == SDL_FALSE) { 275 | 276 | /* get client status. */ 277 | e = ParsecClientGetStatus(parsec_context.parsec, &parsec_context.client_status); 278 | 279 | /* connection established */ 280 | if (e == PARSEC_OK) { 281 | 282 | /* decoder not yet initialized. */ 283 | if (parsec_context.client_status.decoder->width == 0 && 284 | parsec_context.client_status.decoder->height == 0 && 285 | parsec_context.connection == SDL_FALSE) { 286 | vdi_stream_client__log_info("Initialize Video Decoder\n"); 287 | parsec_context.connection = SDL_TRUE; 288 | } 289 | 290 | /* decoder initialized. */ 291 | if (parsec_context.client_status.decoder->width > 0 && 292 | parsec_context.client_status.decoder->height > 0) { 293 | vdi_stream_client__log_info("Use resolution %dx%d\n", parsec_context.client_status.decoder->width, parsec_context.client_status.decoder->height); 294 | parsec_context.window_width = parsec_context.client_status.decoder->width; 295 | parsec_context.window_height = parsec_context.client_status.decoder->height; 296 | parsec_context.decoder = SDL_TRUE; 297 | } 298 | } 299 | 300 | /* unknown error. */ 301 | if (e != PARSEC_CONNECTING && e != PARSEC_OK) { 302 | break; 303 | } 304 | 305 | /* check if timeout reached. */ 306 | if (wait_time >= vdi_config->timeout) { 307 | break; 308 | } 309 | 310 | /* wait some time and re-check. */ 311 | SDL_Delay(250); 312 | wait_time = wait_time + 250; 313 | } 314 | 315 | /* check if connected and decoder initialized. */ 316 | if (parsec_context.connection == SDL_FALSE && 317 | parsec_context.decoder == SDL_FALSE) { 318 | vdi_stream_client__log_error("Connection failed with code: %d\n", e); 319 | goto error; 320 | } 321 | 322 | /* check if connected but decoder initialization failed. */ 323 | if (parsec_context.connection == SDL_TRUE && 324 | parsec_context.decoder == SDL_FALSE) { 325 | 326 | /* TODO: workaround if decoder initialization failed. (workaround for buggy parsec sdk) */ 327 | parsec_context.window_width = 640; 328 | parsec_context.window_height = 480; 329 | } 330 | 331 | parsec_context.window = SDL_CreateWindow("VDI Stream Client", 332 | SDL_WINDOWPOS_UNDEFINED, 333 | SDL_WINDOWPOS_UNDEFINED, 334 | parsec_context.window_width, 335 | parsec_context.window_height, 336 | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_INPUT_FOCUS 337 | ); 338 | if (parsec_context.window == NULL) { 339 | vdi_stream_client__log_error("Window creation failed: %s\n", SDL_GetError()); 340 | goto error; 341 | } 342 | 343 | parsec_context.gl = SDL_GL_CreateContext(parsec_context.window); 344 | if (parsec_context.gl == NULL) { 345 | vdi_stream_client__log_error("OpenGL context creation failed: %s\n", SDL_GetError()); 346 | goto error; 347 | } 348 | 349 | /* sdl video thread. */ 350 | video_thread = SDL_CreateThread(vdi_stream_client__video_thread, "vdi_stream_client__video_thread", &parsec_context); 351 | if (video_thread == NULL) { 352 | vdi_stream_client__log_error("Video thread creation failed: %s\n", SDL_GetError()); 353 | goto error; 354 | } 355 | 356 | /* check if audio should be streamed. */ 357 | if (vdi_config->audio == 1) { 358 | want.freq = PARSEC_AUDIO_SAMPLE_RATE; 359 | want.format = AUDIO_S16; 360 | want.channels = PARSEC_AUDIO_CHANNELS; 361 | want.samples = 2048; 362 | 363 | /* the number of audio packets (960 frames) to buffer before we begin playing. */ 364 | parsec_context.min_buffer = 1; 365 | 366 | /* the number of audio packets (960 frames) to buffer before overflow and clear. */ 367 | parsec_context.max_buffer = 6; 368 | 369 | /* sdl audio device. */ 370 | parsec_context.audio = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); 371 | if (parsec_context.audio == 0) { 372 | vdi_stream_client__log_error("Failed to open audio: %s\n", SDL_GetError()); 373 | goto error; 374 | } 375 | 376 | /* sdl audio thread. */ 377 | audio_thread = SDL_CreateThread(vdi_stream_client__audio_thread, "vdi_stream_client__audio_thread", &parsec_context); 378 | if (audio_thread == NULL) { 379 | vdi_stream_client__log_error("Audio thread creation failed: %s\n", SDL_GetError()); 380 | goto error; 381 | } 382 | } 383 | 384 | /* configure usb. */ 385 | if (vdi_config->usb_devices[0].vendor != 0) { 386 | vdi_stream_client__log_info("Initialize USB\n"); 387 | 388 | /* one thread per one usb device redirect. */ 389 | for (device = 0; vdi_config->usb_devices[device].vendor != 0 ; device++) { 390 | 391 | /* store main thread context in a pointer. */ 392 | redirect_context[device].parsec_context = &parsec_context; 393 | 394 | /* prepare data for network thread. */ 395 | redirect_context[device].server_addr.v4 = vdi_config->server_addrs[device].v4; 396 | redirect_context[device].server_addr.v6 = vdi_config->server_addrs[device].v6; 397 | redirect_context[device].usb_device.vendor = vdi_config->usb_devices[device].vendor; 398 | redirect_context[device].usb_device.product = vdi_config->usb_devices[device].product; 399 | 400 | /* sdl network thread. */ 401 | network_thread[device] = SDL_CreateThread(vdi_stream_client__network_thread, "vdi_stream_client__network_thread", &redirect_context[device]); 402 | if (network_thread[device] == NULL) { 403 | vdi_stream_client__log_error("Network thread creation failed: %s\n", SDL_GetError()); 404 | goto error; 405 | } 406 | } 407 | } 408 | 409 | SDL_GetWindowWMInfo(parsec_context.window, &wm_info); 410 | 411 | /* event loop. */ 412 | while (parsec_context.done == SDL_FALSE) { 413 | for (SDL_Event msg; SDL_PollEvent(&msg);) { 414 | ParsecMessage pmsg = {0}; 415 | 416 | switch (msg.type) { 417 | case SDL_QUIT: 418 | parsec_context.done = SDL_TRUE; 419 | 420 | /* render shutdown text. */ 421 | vdi_stream_client__render_text(&parsec_context, "Closing..."); 422 | break; 423 | case SDL_KEYUP: 424 | 425 | /* TODO: we need to re-grab keyboard later. (workaround for buggy x11 and sdl) */ 426 | focus = SDL_FALSE; 427 | 428 | pmsg.type = MESSAGE_KEYBOARD; 429 | pmsg.keyboard.code = (ParsecKeycode) msg.key.keysym.scancode; 430 | pmsg.keyboard.mod = msg.key.keysym.mod; 431 | pmsg.keyboard.pressed = SDL_FALSE; 432 | break; 433 | case SDL_KEYDOWN: 434 | 435 | /* check if we need to switch window grab state. */ 436 | if ((msg.key.keysym.mod & KMOD_LCTRL) != 0 && 437 | (msg.key.keysym.mod & KMOD_LALT) != 0) { 438 | 439 | /* check if no forced grab. */ 440 | if (grab_forced == SDL_FALSE) { 441 | 442 | /* check if no mouse button is hold down. */ 443 | if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_LMASK) == 0 && 444 | (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_MMASK) == 0 && 445 | (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON_RMASK) == 0) { 446 | 447 | /* check if we need to release mouse grab. */ 448 | if (vdi_config->grab == 1 && SDL_GetWindowGrab(parsec_context.window) == SDL_TRUE) { 449 | SDL_SetWindowGrab(parsec_context.window, SDL_FALSE); 450 | } 451 | 452 | /* check if we need to release relative grab. */ 453 | if (SDL_GetRelativeMouseMode() == SDL_TRUE) { 454 | SDL_SetRelativeMouseMode(SDL_FALSE); 455 | SDL_ShowCursor(SDL_TRUE); 456 | } 457 | 458 | /* remove grab information from window title. */ 459 | SDL_SetWindowTitle(parsec_context.window, "VDI Stream Client"); 460 | 461 | /* don't send hotkey to host and break execution. */ 462 | break; 463 | } 464 | } 465 | } 466 | 467 | /* check if we need to toggle runtime configuration. */ 468 | if ((msg.key.keysym.mod & KMOD_LSHIFT) != 0) { 469 | 470 | /* check if we need to toggle forced grab. */ 471 | if (msg.key.keysym.sym == SDLK_F12) { 472 | if (grab_forced == SDL_TRUE) { 473 | 474 | /* re-enable screensaver if leaving forced lock. */ 475 | if (vdi_config->screensaver == 1) { 476 | SDL_EnableScreenSaver(); 477 | } 478 | 479 | /* check if we need to release relative grab. */ 480 | if (SDL_GetRelativeMouseMode() == SDL_TRUE) { 481 | SDL_SetRelativeMouseMode(SDL_FALSE); 482 | SDL_ShowCursor(SDL_TRUE); 483 | } 484 | 485 | SDL_SetWindowGrab(parsec_context.window, SDL_FALSE); 486 | SDL_SetWindowTitle(parsec_context.window, "VDI Stream Client"); 487 | grab_forced = SDL_FALSE; 488 | } else { 489 | 490 | /* disable screensaver if entering forced lock. */ 491 | if (vdi_config->screensaver == 1) { 492 | SDL_DisableScreenSaver(); 493 | } 494 | 495 | /* check if we need to grab mouse in relative mode. */ 496 | if (parsec_context.relative == SDL_TRUE && SDL_GetRelativeMouseMode() == SDL_FALSE) { 497 | SDL_ShowCursor(SDL_FALSE); 498 | SDL_SetRelativeMouseMode(SDL_TRUE); 499 | } 500 | 501 | SDL_SetWindowGrab(parsec_context.window, SDL_TRUE); 502 | SDL_SetWindowTitle(parsec_context.window, "VDI Stream Client (Press Shift+F12 to release forced grab)"); 503 | grab_forced = SDL_TRUE; 504 | } 505 | 506 | /* don't send hotkey to host and break execution. */ 507 | break; 508 | } 509 | } 510 | 511 | pmsg.type = MESSAGE_KEYBOARD; 512 | pmsg.keyboard.code = (ParsecKeycode) msg.key.keysym.scancode; 513 | pmsg.keyboard.mod = msg.key.keysym.mod; 514 | pmsg.keyboard.pressed = SDL_TRUE; 515 | break; 516 | case SDL_MOUSEMOTION: 517 | 518 | /* check if we released relative mouse grab. */ 519 | if (parsec_context.relative == SDL_TRUE && SDL_GetRelativeMouseMode() == SDL_FALSE) { 520 | 521 | /* no mouse motion events should be forwarded. */ 522 | break; 523 | } 524 | 525 | pmsg.type = MESSAGE_MOUSE_MOTION; 526 | pmsg.mouseMotion.relative = SDL_GetRelativeMouseMode(); 527 | pmsg.mouseMotion.x = pmsg.mouseMotion.relative ? msg.motion.xrel : msg.motion.x + 1; 528 | pmsg.mouseMotion.y = pmsg.mouseMotion.relative ? msg.motion.yrel : msg.motion.y + 1; 529 | break; 530 | case SDL_MOUSEBUTTONUP: 531 | 532 | /* store mouse button state for use in cursor update. */ 533 | parsec_context.pressed = SDL_FALSE; 534 | 535 | pmsg.type = MESSAGE_MOUSE_BUTTON; 536 | pmsg.mouseButton.button = msg.button.button; 537 | pmsg.mouseButton.pressed = SDL_FALSE; 538 | break; 539 | case SDL_MOUSEBUTTONDOWN: 540 | 541 | /* check if no forced grab. */ 542 | if (grab_forced == SDL_FALSE) { 543 | 544 | /* check if we need to grab mouse. */ 545 | if (vdi_config->grab == 1 && SDL_GetWindowGrab(parsec_context.window) == SDL_FALSE) { 546 | SDL_SetWindowGrab(parsec_context.window, SDL_TRUE); 547 | SDL_SetWindowTitle(parsec_context.window, "VDI Stream Client (Press Ctrl+Alt to release grab)"); 548 | } 549 | 550 | /* check if we need to grab mouse in relative mode. */ 551 | if (parsec_context.relative == SDL_TRUE && SDL_GetRelativeMouseMode() == SDL_FALSE) { 552 | SDL_ShowCursor(SDL_FALSE); 553 | SDL_SetRelativeMouseMode(SDL_TRUE); 554 | SDL_SetWindowTitle(parsec_context.window, "VDI Stream Client (Press Ctrl+Alt to release grab)"); 555 | } 556 | } 557 | 558 | /* store mouse button state for use in cursor update. */ 559 | parsec_context.pressed = SDL_TRUE; 560 | 561 | pmsg.type = MESSAGE_MOUSE_BUTTON; 562 | pmsg.mouseButton.button = msg.button.button; 563 | pmsg.mouseButton.pressed = SDL_TRUE; 564 | break; 565 | case SDL_MOUSEWHEEL: 566 | pmsg.type = MESSAGE_MOUSE_WHEEL; 567 | pmsg.mouseWheel.x = msg.wheel.x * vdi_config->speed; 568 | pmsg.mouseWheel.y = msg.wheel.y * vdi_config->speed; 569 | break; 570 | case SDL_CLIPBOARDUPDATE: 571 | if (vdi_config->clipboard == 1) { 572 | ParsecClientSendUserData(parsec_context.parsec, PARSEC_CLIPBOARD_MSG, SDL_GetClipboardText()); 573 | } 574 | break; 575 | case SDL_WINDOWEVENT: 576 | switch (msg.window.event) { 577 | case SDL_WINDOWEVENT_FOCUS_GAINED: 578 | SDL_EventState(SDL_KEYDOWN, SDL_ENABLE); 579 | SDL_EventState(SDL_KEYUP, SDL_ENABLE); 580 | XGrabKeyboard(wm_info.info.x11.display, wm_info.info.x11.window, False, GrabModeAsync, GrabModeAsync, CurrentTime); 581 | 582 | /* TODO: copy client to host clipboard. (workaround for buggy x11 and sdl) */ 583 | if (vdi_config->clipboard == 1 && SDL_HasClipboardText() == SDL_TRUE) { 584 | ParsecClientSendUserData(parsec_context.parsec, PARSEC_CLIPBOARD_MSG, SDL_GetClipboardText()); 585 | } 586 | 587 | break; 588 | case SDL_WINDOWEVENT_FOCUS_LOST: 589 | SDL_EventState(SDL_KEYDOWN, SDL_DISABLE); 590 | SDL_EventState(SDL_KEYUP, SDL_DISABLE); 591 | XUngrabKeyboard(wm_info.info.x11.display, CurrentTime); 592 | break; 593 | case SDL_WINDOWEVENT_ENTER: 594 | parsec_context.focus = SDL_TRUE; 595 | break; 596 | case SDL_WINDOWEVENT_LEAVE: 597 | parsec_context.focus = SDL_FALSE; 598 | break; 599 | } 600 | break; 601 | } 602 | 603 | if (pmsg.type != 0) { 604 | ParsecClientSendMessage(parsec_context.parsec, &pmsg); 605 | } 606 | } 607 | 608 | /* check parsec connection status. */ 609 | e = ParsecClientGetStatus(parsec_context.parsec, &parsec_context.client_status); 610 | if (vdi_config->reconnect == 0 && e != PARSEC_CONNECTING && e != PARSEC_OK) { 611 | 612 | /* render shutdown text. */ 613 | vdi_stream_client__render_text(&parsec_context, "Closing..."); 614 | vdi_stream_client__log_error("Parsec disconnected\n"); 615 | parsec_context.done = SDL_TRUE; 616 | } 617 | if (vdi_config->reconnect == 1 && e != PARSEC_CONNECTING && e != PARSEC_OK && 618 | SDL_GetTicks() > last_time + vdi_config->timeout) { 619 | 620 | /* render reconnect text. */ 621 | vdi_stream_client__render_text(&parsec_context, "Reconnecting..."); 622 | ParsecClientDisconnect(parsec_context.parsec); 623 | ParsecClientConnect(parsec_context.parsec, &cfg, vdi_config->session, vdi_config->peer); 624 | parsec_context.connection = SDL_FALSE; 625 | last_time = SDL_GetTicks(); 626 | } 627 | 628 | /* check network connection status. */ 629 | if (vdi_config->reconnect == 0 && parsec_context.client_status.networkFailure == 1) { 630 | 631 | /* render shutdown text. */ 632 | vdi_stream_client__render_text(&parsec_context, "Closing..."); 633 | vdi_stream_client__log_error("Network disconnected\n"); 634 | parsec_context.done = SDL_TRUE; 635 | } 636 | if (vdi_config->reconnect == 1 && parsec_context.client_status.networkFailure == 1 && 637 | SDL_GetTicks() > last_time + vdi_config->timeout) { 638 | 639 | /* render reconnect text. */ 640 | vdi_stream_client__render_text(&parsec_context, "Reconnecting..."); 641 | ParsecClientDisconnect(parsec_context.parsec); 642 | ParsecClientConnect(parsec_context.parsec, &cfg, vdi_config->session, vdi_config->peer); 643 | parsec_context.connection = SDL_FALSE; 644 | last_time = SDL_GetTicks(); 645 | } 646 | 647 | /* set connection status if reconnected. */ 648 | if (vdi_config->reconnect == 1 && parsec_context.client_status.networkFailure == 0 && 649 | e == PARSEC_OK && parsec_context.connection == SDL_FALSE) { 650 | parsec_context.connection = SDL_TRUE; 651 | } 652 | 653 | for (ParsecClientEvent event; ParsecClientPollEvents(parsec_context.parsec, 0, &event);) { 654 | switch (event.type) { 655 | case CLIENT_EVENT_CURSOR: 656 | vdi_stream_client__cursor(&parsec_context, &event.cursor.cursor, event.cursor.key, vdi_config->grab, grab_forced); 657 | break; 658 | case CLIENT_EVENT_USER_DATA: 659 | if (vdi_config->clipboard == 1) { 660 | vdi_stream_client__clipboard(&parsec_context, event.userData.id, event.userData.key); 661 | } 662 | break; 663 | default: 664 | break; 665 | } 666 | 667 | /* TODO: we need to re-grab keyboard later. (workaround for buggy x11 and sdl) */ 668 | focus = SDL_FALSE; 669 | } 670 | 671 | /* TODO: check if we need to grab input to force decoder initialization. (workaround for buggy parsec sdk) */ 672 | if (vdi_config->grab == 0 && SDL_GetWindowGrab(parsec_context.window) == SDL_FALSE && 673 | parsec_context.decoder == SDL_FALSE && 674 | parsec_context.client_status.decoder->width == 0 && 675 | parsec_context.client_status.decoder->height == 0) { 676 | SDL_ShowCursor(SDL_FALSE); 677 | SDL_GetGlobalMouseState(&x, &y); 678 | SDL_SetWindowGrab(parsec_context.window, SDL_TRUE); 679 | } 680 | 681 | /* TODO: check if we need to ungrab input due to forced decoder initialization. (workaround for buggy parsec sdk) */ 682 | if (vdi_config->grab == 0 && SDL_GetWindowGrab(parsec_context.window) == SDL_TRUE && 683 | parsec_context.decoder == SDL_FALSE && 684 | parsec_context.client_status.decoder->width > 0 && 685 | parsec_context.client_status.decoder->height > 0) { 686 | vdi_stream_client__log_info("Use resolution %dx%d\n", 687 | parsec_context.client_status.decoder->width, 688 | parsec_context.client_status.decoder->height 689 | ); 690 | SDL_SetWindowGrab(parsec_context.window, SDL_FALSE); 691 | SDL_WarpMouseGlobal(x, y); 692 | SDL_ShowCursor(SDL_TRUE); 693 | SDL_SetWindowSize(parsec_context.window, parsec_context.client_status.decoder->width, parsec_context.client_status.decoder->height); 694 | parsec_context.window_width = parsec_context.client_status.decoder->width; 695 | parsec_context.window_height = parsec_context.client_status.decoder->height; 696 | parsec_context.decoder = SDL_TRUE; 697 | } 698 | 699 | /* check if we need to resize window due to client resolution change. */ 700 | if ((parsec_context.window_width != parsec_context.client_status.decoder->width || parsec_context.window_height != parsec_context.client_status.decoder->height) && 701 | parsec_context.client_status.decoder->width > 0 && 702 | parsec_context.client_status.decoder->height > 0) { 703 | vdi_stream_client__log_info("Change resolution from %dx%d to %dx%d\n", 704 | parsec_context.window_width, 705 | parsec_context.window_height, 706 | parsec_context.client_status.decoder->width, 707 | parsec_context.client_status.decoder->height 708 | ); 709 | SDL_SetWindowSize(parsec_context.window, parsec_context.client_status.decoder->width, parsec_context.client_status.decoder->height); 710 | parsec_context.window_width = parsec_context.client_status.decoder->width; 711 | parsec_context.window_height = parsec_context.client_status.decoder->height; 712 | } 713 | 714 | /* check if we need to regrab keyboard on modifier keypress. */ 715 | if (focus == SDL_FALSE && (SDL_GetWindowFlags(parsec_context.window) & SDL_WINDOW_INPUT_FOCUS) != 0) { 716 | XGrabKeyboard(wm_info.info.x11.display, wm_info.info.x11.window, False, GrabModeAsync, GrabModeAsync, CurrentTime); 717 | focus = SDL_TRUE; 718 | } 719 | 720 | SDL_Delay(1); 721 | } 722 | 723 | /* already release any grabbed keyboard because thread termination can take some time. */ 724 | XUngrabKeyboard(wm_info.info.x11.display, CurrentTime); 725 | 726 | /* stop network threads for usb redirection. */ 727 | if (vdi_config->usb_devices[0].vendor != 0) { 728 | vdi_stream_client__log_info("Stop Network Thread\n"); 729 | for (count = 0; count < USB_MAX ; count++) { 730 | if (network_thread[count] == NULL) { 731 | continue; 732 | } 733 | SDL_WaitThread(network_thread[count], NULL); 734 | } 735 | } 736 | 737 | /* stop audio thread. */ 738 | if (vdi_config->audio == 1) { 739 | vdi_stream_client__log_info("Stop Audio Thread\n"); 740 | SDL_WaitThread(audio_thread, NULL); 741 | } 742 | 743 | /* stop video thread. */ 744 | vdi_stream_client__log_info("Stop Video Thread\n"); 745 | SDL_WaitThread(video_thread, NULL); 746 | 747 | /* parsec destroy. */ 748 | ParsecDestroy(parsec_context.parsec); 749 | 750 | /* ttf destroy. */ 751 | TTF_CloseFont(parsec_context.font); 752 | TTF_Quit(); 753 | 754 | /* sdl destroy. */ 755 | if (vdi_config->audio == 1) { 756 | SDL_CloseAudioDevice(parsec_context.audio); 757 | } 758 | SDL_FreeSurface(parsec_context.surface_ttf); 759 | SDL_DestroyWindow(parsec_context.window); 760 | SDL_Quit(); 761 | 762 | /* terminate loop. */ 763 | return VDI_STREAM_CLIENT_SUCCESS; 764 | 765 | error: 766 | 767 | /* parsec destroy. */ 768 | ParsecDestroy(parsec_context.parsec); 769 | 770 | /* ttf destroy. */ 771 | TTF_CloseFont(parsec_context.font); 772 | TTF_Quit(); 773 | 774 | /* sdl destroy. */ 775 | if (vdi_config->audio == 1) { 776 | SDL_CloseAudioDevice(parsec_context.audio); 777 | } 778 | SDL_FreeSurface(parsec_context.surface_ttf); 779 | SDL_DestroyWindow(parsec_context.window); 780 | SDL_Quit(); 781 | 782 | /* return with error. */ 783 | return VDI_STREAM_CLIENT_ERROR; 784 | } 785 | -------------------------------------------------------------------------------- /src/parsec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parsec.h -- parsec default types and defines 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _PARSEC_H 21 | #define _PARSEC_H 22 | 23 | /* configuration includes. */ 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | /* parsec includes. */ 29 | #ifdef HAVE_LIBPARSEC 30 | #include 31 | #else 32 | #include "../parsec-sdk/sdk/parsec-dso.h" 33 | #endif 34 | 35 | /* sdl includes. */ 36 | #define SDL_MAIN_HANDLED 37 | #include 38 | #include 39 | 40 | /* opengl includes. */ 41 | #include 42 | 43 | /* network includes. */ 44 | #include 45 | 46 | /* define audio defaults. */ 47 | #define PARSEC_AUDIO_CHANNELS 2 48 | #define PARSEC_AUDIO_SAMPLE_RATE 48000 49 | #define PARSEC_AUDIO_FRAMES_PER_PACKET 960 50 | 51 | /* define parsec messages. */ 52 | #define PARSEC_CLIPBOARD_MSG 7 53 | 54 | /* parsec configuration. */ 55 | struct parsec_context_s { 56 | 57 | /* parsec. */ 58 | SDL_bool done; 59 | SDL_bool connection; 60 | SDL_bool decoder; 61 | SDL_bool focus; 62 | SDL_bool relative; 63 | SDL_bool pressed; 64 | #ifdef HAVE_LIBPARSEC 65 | Parsec *parsec; 66 | #else 67 | ParsecDSO *parsec; 68 | #endif 69 | ParsecClientStatus client_status; 70 | 71 | /* video. */ 72 | SDL_Window *window; 73 | SDL_GLContext *gl; 74 | SDL_Cursor *cursor; 75 | Sint32 window_width; 76 | Sint32 window_height; 77 | 78 | /* opengl texture for ttf rendering. */ 79 | SDL_Surface *surface_ttf; 80 | GLuint texture_ttf; 81 | GLfloat texture_min_x; 82 | GLfloat texture_min_y; 83 | GLfloat texture_max_x; 84 | GLfloat texture_max_y; 85 | TTF_Font *font; 86 | 87 | /* audio. */ 88 | SDL_AudioDeviceID audio; 89 | Sint32 playing; 90 | Uint32 min_buffer; 91 | Uint32 max_buffer; 92 | 93 | /* timeouts. */ 94 | Uint32 timeout; 95 | }; 96 | 97 | /* usb redirect. */ 98 | struct redirect_context_s { 99 | 100 | /* parsec context. */ 101 | struct parsec_context_s *parsec_context; 102 | 103 | /* network. */ 104 | union { 105 | struct sockaddr_in v4; 106 | struct sockaddr_in6 v6; 107 | } server_addr; 108 | 109 | /* usb. */ 110 | struct { 111 | Sint32 vendor; 112 | Sint32 product; 113 | } usb_device; 114 | }; 115 | 116 | /* parsec event loop. */ 117 | Sint32 vdi_stream_client__event_loop(vdi_config_s *vdi_config); 118 | 119 | #endif /* _PARSEC_H */ 120 | -------------------------------------------------------------------------------- /src/redirect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * redirect.c -- usb redirection via libusb 3 | * 4 | * Copyright (c) 2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* internal includes. */ 21 | #include "client.h" 22 | #include "parsec.h" 23 | 24 | /* system includes. */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | /* network includes. */ 33 | #include 34 | 35 | /* usb includes. */ 36 | #include 37 | #include 38 | 39 | /* thread specific variables. */ 40 | static __thread Sint32 server_fd = -1; 41 | static __thread libusb_device_handle *device_handle = NULL; 42 | static __thread struct usbredirhost *host = NULL; 43 | 44 | /* this must be defined, otherwise usbredir will crash. */ 45 | static void vdi_stream_client__usb_log(void *priv, Sint32 level, const char *msg) { } 46 | 47 | /* read data from client. */ 48 | static Sint32 vdi_stream_client__usb_read(void *priv, Uint8 *data, Sint32 count) { 49 | Sint32 r = read(server_fd, data, count); 50 | if (r < 0) { 51 | if (errno == EAGAIN) { 52 | return VDI_STREAM_CLIENT_SUCCESS; 53 | } 54 | return VDI_STREAM_CLIENT_ERROR; 55 | } 56 | 57 | /* client disconnected. */ 58 | if (r == 0) { 59 | close(server_fd); 60 | server_fd = -1; 61 | } 62 | return r; 63 | } 64 | 65 | /* write data to client. */ 66 | static Sint32 vdi_stream_client__usb_write(void *priv, Uint8 *data, Sint32 count) { 67 | Sint32 r = write(server_fd, data, count); 68 | if (r < 0) { 69 | if (errno == EAGAIN) { 70 | return VDI_STREAM_CLIENT_SUCCESS; 71 | } 72 | 73 | /* client disconnected. */ 74 | if (errno == EPIPE) { 75 | close(server_fd); 76 | server_fd = -1; 77 | return VDI_STREAM_CLIENT_SUCCESS; 78 | } 79 | return VDI_STREAM_CLIENT_ERROR; 80 | } 81 | return r; 82 | } 83 | 84 | /* usb hotplug event. */ 85 | static Sint32 vdi_stream_client__usb_remove(struct libusb_context *usb_context, struct libusb_device *device, libusb_hotplug_event event, void *user_data) { 86 | 87 | /* usb device removed. */ 88 | if (device_handle != NULL) { 89 | if (server_fd != -1) { 90 | close(server_fd); 91 | server_fd = -1; 92 | } 93 | } 94 | 95 | return VDI_STREAM_CLIENT_SUCCESS; 96 | } 97 | 98 | /* sdl network thread. */ 99 | Sint32 vdi_stream_client__network_thread(void *opaque) { 100 | struct redirect_context_s *redirect_context = (struct redirect_context_s *) opaque; 101 | struct libusb_device **devices; 102 | struct libusb_device *device; 103 | libusb_context *usb_context; 104 | libusb_hotplug_callback_handle callback_handle; 105 | struct libusb_device_descriptor desc; 106 | size_t count; 107 | Sint32 flag; 108 | 109 | /* variables for data processing loop. */ 110 | const struct libusb_pollfd **pollfds = NULL; 111 | fd_set readfds; 112 | fd_set writefds; 113 | Sint32 i; 114 | Sint32 n; 115 | Sint32 nfds; 116 | struct timeval timeout; 117 | 118 | /* initial values. */ 119 | Uint32 retry = 0; 120 | Uint32 delay = 1000; 121 | Sint32 option = 1; 122 | Sint32 error = 0; 123 | 124 | /* user output. */ 125 | vdi_stream_client__log_info("Start USB Redirect %04x:%04x\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product); 126 | 127 | /* usb init. */ 128 | error = libusb_init(&usb_context); 129 | if (error != 0) { 130 | vdi_stream_client__log_error("USB Device %04x:%04x redirect initialization failed: %s\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product, libusb_strerror(error)); 131 | goto error; 132 | } 133 | 134 | /* register events. */ 135 | error = libusb_hotplug_register_callback( 136 | usb_context, 137 | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 138 | 0, 139 | redirect_context->usb_device.vendor, 140 | redirect_context->usb_device.product, 141 | LIBUSB_HOTPLUG_MATCH_ANY, 142 | vdi_stream_client__usb_remove, 143 | NULL, 144 | &callback_handle 145 | ); 146 | if (error != 0) { 147 | vdi_stream_client__log_error("USB Device %04x:%04x redirect initialization failed: %s\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product, libusb_strerror(error)); 148 | goto error; 149 | } 150 | 151 | while (redirect_context->parsec_context->done == SDL_FALSE) { 152 | memset(&timeout, 0, sizeof(timeout)); 153 | timeout.tv_sec = 1; 154 | timeout.tv_usec = 0; 155 | 156 | /* try until connection established or application quits. */ 157 | while (server_fd == -1) { 158 | 159 | /* check if main thread is still running. */ 160 | if (redirect_context->parsec_context->done == SDL_TRUE) { 161 | break; 162 | } 163 | 164 | /* check if we reached reconnect retry timeout. */ 165 | if (retry > 0 && retry <= 10) { 166 | 167 | /* wait some time before reconnect. */ 168 | SDL_Delay(delay); 169 | retry++; 170 | continue; 171 | } 172 | 173 | /* check if we need to reset reconnect retry counter. */ 174 | if (retry > 10) { 175 | retry = 0; 176 | } 177 | 178 | /* set ipv4 or ipv6 socket. */ 179 | if (redirect_context->server_addr.v4.sin_family == AF_INET) { 180 | server_fd = socket(AF_INET, SOCK_STREAM, 0); 181 | } 182 | if (redirect_context->server_addr.v6.sin6_family == AF_INET6) { 183 | server_fd = socket(AF_INET6, SOCK_STREAM, 0); 184 | } 185 | 186 | /* set tcp options. */ 187 | flag = 1; 188 | setsockopt(server_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); 189 | setsockopt(server_fd, IPPROTO_TCP, TCP_QUICKACK, &flag, sizeof(flag)); 190 | 191 | /* set socket connection timeout. */ 192 | setsockopt(server_fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); 193 | 194 | /* connect to qemu usbredir guest service. */ 195 | if (connect(server_fd, (struct sockaddr *)&redirect_context->server_addr, sizeof(redirect_context->server_addr)) == -1) { 196 | close(server_fd); 197 | server_fd = -1; 198 | retry++; 199 | continue; 200 | } 201 | 202 | /* non-blocking client socket. */ 203 | fcntl(server_fd, F_SETFL, O_NONBLOCK); 204 | } 205 | 206 | /* try until usb device opened or disconnected or application quits. */ 207 | while (host == NULL) { 208 | 209 | /* check if main thread is still running. */ 210 | if (redirect_context->parsec_context->done == SDL_TRUE) { 211 | break; 212 | } 213 | 214 | /* get list of usb devices. */ 215 | libusb_get_device_list(usb_context, &devices); 216 | 217 | /* find device to open. */ 218 | count = 0; 219 | while ((device = devices[count++]) != NULL) { 220 | libusb_get_device_descriptor(device, &desc); 221 | if (desc.idVendor == redirect_context->usb_device.vendor && desc.idProduct == redirect_context->usb_device.product) { 222 | break; 223 | } 224 | } 225 | 226 | /* usb device not attached. */ 227 | if (device == NULL) { 228 | 229 | /* free list of usb devices after successful open. */ 230 | libusb_free_device_list(devices, 1); 231 | 232 | /* wait some time before rescan for usb device. */ 233 | SDL_Delay(delay); 234 | continue; 235 | } 236 | 237 | /* open usb device. */ 238 | error = libusb_open(device, &device_handle); 239 | if (error != 0) { 240 | 241 | /* check if permission denied. */ 242 | if (error == LIBUSB_ERROR_ACCESS) { 243 | vdi_stream_client__log_info("USB Device %04x:%04x redirect failed: %s\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product, libusb_strerror(error)); 244 | } 245 | 246 | /* free list of usb devices after successful open. */ 247 | libusb_free_device_list(devices, 1); 248 | 249 | /* wait some time before rescan for usb device. */ 250 | SDL_Delay(delay); 251 | continue; 252 | } 253 | 254 | /* free list of usb devices after successful open. */ 255 | libusb_free_device_list(devices, 1); 256 | 257 | /* setup host. */ 258 | host = usbredirhost_open(usb_context, device_handle, vdi_stream_client__usb_log, vdi_stream_client__usb_read, vdi_stream_client__usb_write, NULL, NULL, 0, 0); 259 | if (host == NULL) { 260 | 261 | /* wait some time before rescan for usb device. */ 262 | SDL_Delay(delay); 263 | continue; 264 | } 265 | } 266 | 267 | /* check if usb device is connected and redirected. */ 268 | if (host != NULL) { 269 | 270 | /* user output. */ 271 | vdi_stream_client__log_info("USB Device %04x:%04x connected\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product); 272 | } 273 | 274 | /* data processing loop. */ 275 | while (server_fd != -1) { 276 | 277 | /* check if main thread is still running. */ 278 | if (redirect_context->parsec_context->done == SDL_TRUE) { 279 | break; 280 | } 281 | 282 | /* remove all socket descriptors from set. */ 283 | FD_ZERO(&readfds); 284 | FD_ZERO(&writefds); 285 | 286 | /* adding client socket descriptor to set. */ 287 | FD_SET(server_fd, &readfds); 288 | if (usbredirhost_has_data_to_write(host)) { 289 | FD_SET(server_fd, &writefds); 290 | } 291 | nfds = server_fd + 1; 292 | 293 | /* free not cleared sockets. */ 294 | if (pollfds != NULL) { 295 | libusb_free_pollfds(pollfds); 296 | pollfds = NULL; 297 | } 298 | 299 | /* poll usb devices for data. */ 300 | pollfds = libusb_get_pollfds(usb_context); 301 | for (i = 0; pollfds && pollfds[i]; i++) { 302 | if (pollfds[i]->events & POLLIN) { 303 | FD_SET(pollfds[i]->fd, &readfds); 304 | } 305 | if (pollfds[i]->events & POLLOUT) { 306 | FD_SET(pollfds[i]->fd, &writefds); 307 | } 308 | if (pollfds[i]->fd >= nfds) { 309 | nfds = pollfds[i]->fd + 1; 310 | } 311 | } 312 | 313 | /* get next timeout. */ 314 | memset(&timeout, 0, sizeof(timeout)); 315 | if (libusb_get_next_timeout(usb_context, &timeout) == 0) { 316 | timeout.tv_sec = 1; 317 | timeout.tv_usec = 0; 318 | } 319 | 320 | /* select will wait for data to arrive until timeout. */ 321 | n = select(nfds, &readfds, &writefds, NULL, &timeout); 322 | if (n == -1) { 323 | if (errno == EINTR) { 324 | continue; 325 | } 326 | break; 327 | } 328 | 329 | /* wait for usb events and cleanup timeout structure for re-use. */ 330 | memset(&timeout, 0, sizeof(timeout)); 331 | if (n == 0) { 332 | libusb_handle_events_timeout(usb_context, &timeout); 333 | continue; 334 | } 335 | 336 | /* read data from usb device. */ 337 | if (FD_ISSET(server_fd, &readfds) != 0 && usbredirhost_read_guest_data(host) != 0) { 338 | break; 339 | } 340 | 341 | /* usbredirhost_read_guest_data may have detected client disconnect. */ 342 | if (server_fd == -1) { 343 | break; 344 | } 345 | 346 | /* write data to usb device. */ 347 | if (FD_ISSET(server_fd, &writefds) != 0 && usbredirhost_write_guest_data(host) != 0) { 348 | break; 349 | } 350 | 351 | /* wait until first timeout either for read or write happens. */ 352 | for (i = 0; pollfds && pollfds[i]; i++) { 353 | if (FD_ISSET(pollfds[i]->fd, &readfds) || 354 | FD_ISSET(pollfds[i]->fd, &writefds)) { 355 | libusb_handle_events_timeout(usb_context, &timeout); 356 | break; 357 | } 358 | } 359 | } 360 | 361 | /* loop terminated but socket still open. */ 362 | if (server_fd != -1) { 363 | close(server_fd); 364 | server_fd = -1; 365 | } 366 | 367 | /* free memory. */ 368 | if (pollfds != NULL) { 369 | libusb_free_pollfds(pollfds); 370 | pollfds = NULL; 371 | } 372 | 373 | /* usbredirhost_close() calls libusb_close() so no need to do it again. */ 374 | if (host != NULL) { 375 | 376 | /* user output. */ 377 | vdi_stream_client__log_info("USB Device %04x:%04x removed\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product); 378 | 379 | usbredirhost_close(host); 380 | device_handle = NULL; 381 | host = NULL; 382 | } 383 | } 384 | 385 | /* usb destroy. */ 386 | libusb_hotplug_deregister_callback(usb_context, callback_handle); 387 | libusb_exit(usb_context); 388 | 389 | /* user output. */ 390 | vdi_stream_client__log_info("Stop USB Redirect %04x:%04x\n", redirect_context->usb_device.vendor, redirect_context->usb_device.product); 391 | 392 | /* terminate loop. */ 393 | return VDI_STREAM_CLIENT_SUCCESS; 394 | 395 | error: 396 | 397 | /* stop main thread. */ 398 | redirect_context->parsec_context->done = SDL_TRUE; 399 | 400 | /* close client socket. */ 401 | if (server_fd != -1) { 402 | close(server_fd); 403 | } 404 | 405 | /* usb destroy. */ 406 | libusb_hotplug_deregister_callback(usb_context, callback_handle); 407 | libusb_exit(usb_context); 408 | 409 | /* return with error. */ 410 | return VDI_STREAM_CLIENT_ERROR; 411 | } 412 | -------------------------------------------------------------------------------- /src/redirect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * redirect.h -- usb redirection via libusb 3 | * 4 | * Copyright (c) 2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _REDIRECT_H 21 | #define _REDIRECT_H 22 | 23 | /* sdl includes. */ 24 | #define SDL_MAIN_HANDLED 25 | #include 26 | 27 | /* usb redirection thread. */ 28 | Sint32 vdi_stream_client__network_thread(void *opaque); 29 | 30 | #endif /* _REDIRECT_H */ 31 | -------------------------------------------------------------------------------- /src/video.c: -------------------------------------------------------------------------------- 1 | /* 2 | * video.c -- video rendering thread via sdl 3 | * 4 | * Copyright (c) 2020-2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* internal includes. */ 21 | #include "client.h" 22 | #include "parsec.h" 23 | 24 | /* system includes. */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* quick utility function for texture creation. */ 31 | static Sint32 vdi_stream_client__power_of_two(Sint32 input) { 32 | Sint32 value = 1; 33 | while (value < input) { 34 | value <<= 1; 35 | } 36 | return value; 37 | } 38 | 39 | /* convert text into opengl texture. */ 40 | GLuint vdi_stream_client__gl_load_texture(SDL_Surface *surface, GLfloat *texture_coord) { 41 | GLuint texture; 42 | Sint32 w, h; 43 | SDL_Surface *image; 44 | SDL_Rect area; 45 | Uint8 saved_alpha; 46 | SDL_BlendMode saved_mode; 47 | 48 | /* use the surface width and height expanded to powers of 2. */ 49 | w = vdi_stream_client__power_of_two(surface->w); 50 | h = vdi_stream_client__power_of_two(surface->h); 51 | texture_coord[0] = 0.0f; /* min x */ 52 | texture_coord[1] = 0.0f; /* min y */ 53 | texture_coord[2] = (GLfloat)surface->w / w; /* max x */ 54 | texture_coord[3] = (GLfloat)surface->h / h; /* max y */ 55 | 56 | image = SDL_CreateRGBSurface( 57 | SDL_SWSURFACE, 58 | w, h, 59 | 32, 60 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* opengl rgba masks. */ 61 | 0x000000FF, 62 | 0x0000FF00, 63 | 0x00FF0000, 64 | 0xFF000000 65 | #else 66 | 0xFF000000, 67 | 0x00FF0000, 68 | 0x0000FF00, 69 | 0x000000FF 70 | #endif 71 | ); 72 | if (image == NULL) { 73 | return VDI_STREAM_CLIENT_SUCCESS; 74 | } 75 | 76 | /* save the alpha blending attributes. */ 77 | SDL_GetSurfaceAlphaMod(surface, &saved_alpha); 78 | SDL_SetSurfaceAlphaMod(surface, 0xFF); 79 | SDL_GetSurfaceBlendMode(surface, &saved_mode); 80 | SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); 81 | 82 | /* copy the surface into the gl texture image. */ 83 | area.x = 0; 84 | area.y = 0; 85 | area.w = surface->w; 86 | area.h = surface->h; 87 | SDL_BlitSurface(surface, &area, image, &area); 88 | 89 | /* restore the alpha blending attributes. */ 90 | SDL_SetSurfaceAlphaMod(surface, saved_alpha); 91 | SDL_SetSurfaceBlendMode(surface, saved_mode); 92 | 93 | /* create an opengl texture for the image. */ 94 | glGenTextures(1, &texture); 95 | glBindTexture(GL_TEXTURE_2D, texture); 96 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 97 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 98 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); 99 | 100 | /* no longer needed. */ 101 | SDL_FreeSurface(image); 102 | 103 | return texture; 104 | } 105 | 106 | /* opengl frame text event. */ 107 | static void vdi_stream_client__frame_text(void *opaque) { 108 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 109 | Sint32 x, y, w, h; 110 | 111 | /* calculate position and size to center of window. */ 112 | x = (parsec_context->window_width - parsec_context->surface_ttf->w) / 2; 113 | y = (parsec_context->window_height - parsec_context->surface_ttf->h) / 2; 114 | w = parsec_context->surface_ttf->w; 115 | h = parsec_context->surface_ttf->h; 116 | 117 | /* reset drawable area. */ 118 | glViewport(0, 0, parsec_context->window_width, parsec_context->window_height); 119 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 120 | glClear(GL_COLOR_BUFFER_BIT); 121 | 122 | /* attributes. */ 123 | glPushAttrib(GL_ENABLE_BIT); 124 | glDisable(GL_DEPTH_TEST); 125 | glDisable(GL_CULL_FACE); 126 | glEnable(GL_TEXTURE_2D); 127 | 128 | /* this allows alpha blending of 2d textures with the scene. */ 129 | glEnable(GL_BLEND); 130 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 131 | 132 | glMatrixMode(GL_PROJECTION); 133 | glPushMatrix(); 134 | glLoadIdentity(); 135 | 136 | glOrtho(0.0, parsec_context->window_width, parsec_context->window_height, 0.0, 0.0, 1.0); 137 | 138 | glMatrixMode(GL_MODELVIEW); 139 | glPushMatrix(); 140 | glLoadIdentity(); 141 | 142 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 143 | 144 | /* show the text in center of window. */ 145 | glBindTexture(GL_TEXTURE_2D, parsec_context->texture_ttf); 146 | glBegin(GL_TRIANGLE_STRIP); 147 | glTexCoord2f(parsec_context->texture_min_x, parsec_context->texture_min_y); glVertex2i(x, y ); 148 | glTexCoord2f(parsec_context->texture_max_x, parsec_context->texture_min_y); glVertex2i(x + w, y ); 149 | glTexCoord2f(parsec_context->texture_min_x, parsec_context->texture_max_y); glVertex2i(x, y + h); 150 | glTexCoord2f(parsec_context->texture_max_x, parsec_context->texture_max_y); glVertex2i(x + w, y + h); 151 | glEnd(); 152 | 153 | /* stop text rendering. */ 154 | glMatrixMode(GL_MODELVIEW); 155 | glPopMatrix(); 156 | 157 | glMatrixMode(GL_PROJECTION); 158 | glPopMatrix(); 159 | 160 | /* remove attributes. */ 161 | glPopAttrib(); 162 | 163 | /* static text and no need to render it frequently. */ 164 | SDL_Delay(parsec_context->timeout); 165 | } 166 | 167 | /* opengl frame video event. */ 168 | static void vdi_stream_client__frame_video(void *opaque) { 169 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 170 | 171 | /* reset drawable area. */ 172 | glViewport(0, 0, parsec_context->window_width, parsec_context->window_height); 173 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 174 | glClear(GL_COLOR_BUFFER_BIT); 175 | 176 | ParsecClientSetDimensions(parsec_context->parsec, DEFAULT_STREAM, parsec_context->window_width, parsec_context->window_height, 1); 177 | ParsecClientGLRenderFrame(parsec_context->parsec, DEFAULT_STREAM, NULL, NULL, parsec_context->timeout); 178 | } 179 | 180 | /* sdl video thread. */ 181 | Sint32 vdi_stream_client__video_thread(void *opaque) { 182 | struct parsec_context_s *parsec_context = (struct parsec_context_s *) opaque; 183 | 184 | SDL_GL_MakeCurrent(parsec_context->window, parsec_context->gl); 185 | SDL_GL_SetSwapInterval(1); 186 | 187 | while (parsec_context->done == SDL_FALSE) { 188 | 189 | /* show parsec frame. */ 190 | if (parsec_context->connection == SDL_TRUE) { 191 | vdi_stream_client__frame_video(parsec_context); 192 | } 193 | 194 | /* show reconnecting text. */ 195 | if (parsec_context->connection == SDL_FALSE) { 196 | vdi_stream_client__frame_text(parsec_context); 197 | } 198 | 199 | SDL_GL_SwapWindow(parsec_context->window); 200 | } 201 | 202 | /* show closing text. */ 203 | vdi_stream_client__frame_text(parsec_context); 204 | SDL_GL_SwapWindow(parsec_context->window); 205 | 206 | ParsecClientGLDestroy(parsec_context->parsec, DEFAULT_STREAM); 207 | SDL_GL_DeleteContext(parsec_context->gl); 208 | 209 | return VDI_STREAM_CLIENT_SUCCESS; 210 | } 211 | -------------------------------------------------------------------------------- /src/video.h: -------------------------------------------------------------------------------- 1 | /* 2 | * video.h -- video rendering thread via sdl 3 | * 4 | * Copyright (c) 2021 Maik Broemme 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _VIDEO_H 21 | #define _VIDEO_H 22 | 23 | /* sdl includes. */ 24 | #define SDL_MAIN_HANDLED 25 | #include 26 | 27 | /* opengl includes. */ 28 | #include 29 | 30 | /* video thread. */ 31 | GLuint vdi_stream_client__gl_load_texture(SDL_Surface *surface, GLfloat *texture_coord); 32 | Sint32 vdi_stream_client__video_thread(void *opaque); 33 | 34 | #endif /* _VIDEO_H */ 35 | -------------------------------------------------------------------------------- /tools/parsec-login: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # parsec-login -- Parsec API tool to get session and list available peers. 4 | # 5 | # Copyright (c) 2021 Maik Broemme 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | # default config section. (this can be modified) 21 | export PARSEC_HOST="https://kessel-api.parsecgaming.com" 22 | 23 | # runtime config section. (don't edit) 24 | export PARSEC_PROCESS="${0##*/}" 25 | export PARSEC_VERSION="0.1.0" 26 | export PARSEC_AUTHOR="Maik Broemme" 27 | export PARSEC_EMAIL="mbroemme@libmpq.org" 28 | 29 | # global variables. 30 | declare -a GLOBAL__parameters=("${@}") 31 | 32 | # show help. 33 | function parsec_login__usage() { 34 | printf "Usage: %s [username] [password] (tfa)...\n" "${PARSEC_PROCESS}" 35 | printf "Parsec API tool to get session ID and peer IDs\n" 36 | printf "\n" 37 | printf "Help Options:\n" 38 | printf " -h, --help show this help screen\n" 39 | printf " -v, --version show the version information\n" 40 | printf "\n" 41 | printf "Parsec Options:\n" 42 | printf " -u, --username username for API login (mandatory)\n" 43 | printf " -p, --password password for API login (mandatory)\n" 44 | printf " -t, --tfa 2fa code for API login (optional)\n" 45 | printf "\n" 46 | printf "Please report bugs to the appropriate authors, which can be found in the\n" 47 | printf "version information. All other things can be send to <${PARSEC_EMAIL}>\n" 48 | 49 | # successful execution. 50 | return 0 51 | } 52 | 53 | # show version. 54 | function parsec_login__version() { 55 | printf "${PARSEC_PROCESS} version ${PARSEC_VERSION} Copyright (c) 2021 The VDI Stream developers\n" 56 | printf "Written by ${PARSEC_AUTHOR} <${PARSEC_EMAIL}>\n" 57 | printf "\n" 58 | printf "This is free software; see the source for copying conditions. There is NO\n" 59 | printf "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" 60 | 61 | # successful execution. 62 | return 0 63 | } 64 | 65 | # check if curl exist. 66 | [ -x "/bin/curl" ] || [ -x "/usr/bin/curl" ] || [ -x "/usr/local/bin/curl" ] || { 67 | printf "No curl found, please install it\n" 68 | exit 1 69 | } 70 | 71 | # check if jq exist. 72 | [ -x "/bin/jq" ] || [ -x "/usr/bin/jq" ] || [ -x "/usr/local/bin/jq" ] || { 73 | printf "No jq found, please install it\n" 74 | exit 1 75 | } 76 | 77 | # parse command line for switches. 78 | for LOOP__index in "${!GLOBAL__parameters[@]}" ; do 79 | case "${GLOBAL__parameters[${LOOP__index}]}" in 80 | -h|--help) 81 | parsec_login__usage 82 | exit 0 83 | ;; 84 | -v|--version) 85 | parsec_login__version 86 | exit 0 87 | ;; 88 | -u|--username) 89 | 90 | # check if we miss some parameter. 91 | [ -z "${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" ] && { 92 | 93 | # show the help for the missing parameter. 94 | printf "${PARSEC_PROCESS}: option \`${GLOBAL__parameters[${LOOP__index}]}' requires 1 argument\n" 95 | printf "Try \`${PARSEC_PROCESS} --help' for more information.\n" 96 | 97 | # exit if we missed some parameter. 98 | exit 1 99 | } 100 | 101 | # store username. 102 | declare -g GLOBAL__username="${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" 103 | 104 | # unset array items. 105 | unset GLOBAL__parameters[${LOOP__index}] 106 | unset GLOBAL__parameters[$(( ${LOOP__index} + 1 ))] 107 | ;; 108 | -p|--password) 109 | 110 | # check if we miss some parameter. 111 | [ -z "${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" ] && { 112 | 113 | # show the help for the missing parameter. 114 | printf "${PARSEC_PROCESS}: option \`${GLOBAL__parameters[${LOOP__index}]}' requires 1 argument\n" 115 | printf "Try \`${PARSEC_PROCESS} --help' for more information.\n" 116 | 117 | # exit if we missed some parameter. 118 | exit 1 119 | } 120 | 121 | # store password. 122 | declare -g GLOBAL__password="${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" 123 | 124 | # unset array items. 125 | unset GLOBAL__parameters[${LOOP__index}] 126 | unset GLOBAL__parameters[$(( ${LOOP__index} + 1 ))] 127 | ;; 128 | -t|--tfa) 129 | 130 | # check if we miss some parameter. 131 | [ -z "${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" ] && { 132 | 133 | # show the help for the missing parameter. 134 | printf "${PARSEC_PROCESS}: option \`${GLOBAL__parameters[${LOOP__index}]}' requires 1 argument\n" 135 | printf "Try \`${PARSEC_PROCESS} --help' for more information.\n" 136 | 137 | # exit if we missed some parameter. 138 | exit 1 139 | } 140 | 141 | # store password. 142 | declare -g GLOBAL__tfa="${GLOBAL__parameters[$(( ${LOOP__index} + 1 ))]}" 143 | 144 | # unset array items. 145 | unset GLOBAL__parameters[${LOOP__index}] 146 | unset GLOBAL__parameters[$(( ${LOOP__index} + 1 ))] 147 | ;; 148 | *) 149 | 150 | # store index of unknown parameter. 151 | [ -z "${GLOBAL__unknown}" ] && { 152 | declare -g GLOBAL__unknown="${GLOBAL__parameters[${LOOP__index}]}" 153 | } 154 | ;; 155 | esac 156 | done 157 | 158 | # check if unprocessed parameters are left. 159 | [ "${#GLOBAL__parameters[@]}" != "0" ] && { 160 | 161 | # show the help for an unknown option. 162 | printf "${PARSEC_PROCESS}: unrecognized option \`${GLOBAL__unknown}'\n" "OPTION" 163 | printf "Try \`${PARSEC_PROCESS} --help' for more information.\n" 164 | 165 | # exit if we found some unknown option. 166 | exit 1 167 | } 168 | 169 | # check if we need to ask for username. 170 | [ -z "${GLOBAL__username}" ] && { 171 | read -r -p "Username: " GLOBAL__username 172 | [ -z "${GLOBAL__username}" ] && { 173 | printf "Username cannot be empty\n" 174 | exit 1 175 | } 176 | } 177 | 178 | # check if we need to ask for password. 179 | [ -z "${GLOBAL__password}" ] && { 180 | read -r -p "Password: " -s GLOBAL__password 181 | printf "\n" 182 | [ -z "${GLOBAL__password}" ] && { 183 | printf "Password cannot be empty\n" 184 | exit 1 185 | } 186 | } 187 | 188 | # check if we need to ask for 2fa code. 189 | [ -z "${GLOBAL__tfa}" ] && { 190 | [ "$(/bin/curl --max-time 5 --silent --fail --request POST --write-out '{ "session_id":"%{http_code}" }' --header 'Content-Type: application/json' --data-binary '{ "email": "'"${GLOBAL__username}"'" , "password": "'"${GLOBAL__password}"'" }' "${PARSEC_HOST}/v1/auth" | /bin/jq --raw-output '.session_id')" == "403" ] && { 191 | 192 | # ask for 2fa code. 193 | read -r -p "2FA code: " GLOBAL__tfa 194 | [ -z "${GLOBAL__tfa}" ] && { 195 | printf "2FA code cannot be empty\n" 196 | exit 1 197 | } 198 | } 199 | } 200 | 201 | # show current step. 202 | printf "Retrieve Session ID: " 203 | 204 | # get session id. 205 | /bin/curl --max-time 5 --silent --fail --request POST --header 'Content-Type: application/json' --data-binary '{ "email": "'"${GLOBAL__username}"'" , "password": "'"${GLOBAL__password}"'" , "tfa": "'"${GLOBAL__tfa}"'" }' "${PARSEC_HOST}/v1/auth" | /bin/jq --raw-output '.session_id' | { 206 | while read LOCAL__line ; do 207 | declare -g GLOBAL__session_id="${LOCAL__line}" 208 | done 209 | 210 | # check if something failed. 211 | [ -z "${GLOBAL__session_id}" ] && { 212 | printf "failed\n" 213 | exit 1 214 | } 215 | 216 | printf "${GLOBAL__session_id}\n" 217 | printf "Retrieve Peer ID: " 218 | 219 | # get peer ids. 220 | /bin/curl --max-time 5 --silent --fail --request GET --header 'Content-Type: application/json' --header 'Authorization: Bearer '"${GLOBAL__session_id}"'' "${PARSEC_HOST}/v2/hosts?mode=desktop&public=false" | /bin/jq -r '.data[] | "\(.peer_id) (\(.name))"' | { 221 | while read LOCAL__line ; do 222 | 223 | # store result. 224 | [ -z "${GLOBAL__peer_ids}" ] && { 225 | GLOBAL__peer_ids="${LOCAL__line}" 226 | } || { 227 | GLOBAL__peer_ids="${GLOBAL__peer_ids}, ${LOCAL__line}" 228 | } 229 | done 230 | 231 | # check if something failed. 232 | [ -z "${GLOBAL__peer_ids}" ] && { 233 | printf "failed\n" 234 | exit 1 235 | } 236 | 237 | printf "${GLOBAL__peer_ids}\n" 238 | exit 0 239 | } || exit 1 240 | 241 | # all good. 242 | exit 0 243 | } || exit 1 244 | 245 | # no error found. 246 | exit 0 247 | --------------------------------------------------------------------------------