[
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 2.8)\n\nproject(wds CXX)\n\nset(WDS_VERSION_MAJOR 1)\nset(WDS_VERSION_MINOR 1)\nset(WDS_VERSION_PATCH 0)\n\nenable_testing()\n\noption(WDS_INSTALL_TESTS \"Install test programs\" off)\n\ninclude(GNUInstallDirs)\n\nadd_subdirectory(data)\nadd_subdirectory(libwds/rtsp)\nadd_subdirectory(libwds/rtsp/tests)\nadd_subdirectory(libwds/common)\nadd_subdirectory(libwds/source)\nadd_subdirectory(libwds/sink)\nadd_subdirectory(libwds)\nadd_subdirectory(p2p)\nadd_subdirectory(mirac_network)\nadd_subdirectory(sink)\nadd_subdirectory(desktop_source)\n"
  },
  {
    "path": "COPYING",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\n                  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n\n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n                            NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n\n"
  },
  {
    "path": "README.md",
    "content": "DISCONTINUATION OF PROJECT.\n\nThis project will no longer be maintained by Intel.\n\nIntel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. \n\nIntel no longer accepts patches to this project.\n\nIf you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. \n## Wireless Display Software For Linux OS (WDS)\n\nWDS is a set of libraries for developers who want to build Wi-Fi Display applications on linux.\n\nWDS consists of:\n * libwds: Main library implements a Wi-Fi Display dialect of RTSP that includes the parser, actual negotiation logic for sink and source, and the related data structures. It is not tied to any specific connection manager, media framework or main loop. This Library is also compatible with MSVC.\n * network: Supports integration with GLib main loop and GStreamer\n * p2p: Supports integration with Connman Wifi P2P features\n\n\nThe source code includes example implementations:\n * _sink:_ Wi-Fi Display sink that depends on Gstreamer, Connman and GLib mainloop\n * _desktop_source:_ Wi-Fi Display source that depends on Gstreamer, Connman and GLib mainloop\n\nMore information can be found on the [mailing list](https://lists.01.org/mailman/listinfo/wysiwidi-dev) and the [wiki](https://github.com/01org/wds/wiki).\n\n### Requirements:\n\nWDS test executables have runtime dependencies on just a few things (mostly GStreamer and GLib), but for successful Wi-Fi Display sessions the following are adviced:\n * Wifi adapter from Intel 7260-family or Atheros ath9k\n * [wpa_supplicant](http://w1.fi/wpa_supplicant/): version 2.4 or later, built with\t`CONFIG_P2P=y`, `CONFIG_WIFI_DISPLAY=y` and `CONFIG_CTRL_IFACE_DBUS_NEW=y`\n * [connman](https://01.org/connman): version 1.28 (released Feb 1st 2015) or later.\n * gstreamer: either master branch more recent than Feb 3rd 2015 (commit d0a50be2), or 1.4 branch more recent than \nFeb 3rd 2005 (commit 1ce3260a638d or release 1.4.6 or later).\n\nTest results with other Wifi adapters are very welcome but be warned that in many cases Wifi-P2P has not had the testing it needs on linux: you may run into problems in surprising places.\n\n### Building WDS from git:\n\n```\ncmake .\nmake\n```\n\n### Testing WDS\n\n#### Pre-requisites\n\nMake sure wpa_supplicant & connmand are running. Running both of them uninstalled is possible (but in that case make sure the system wpa_supplicant and system connection manager are _not_ running):\n\n```\n$ sudo hostap/wpa_supplicant/wpa_supplicant -ddt -u\n\n$ sudo connman/src/connmand -n -d\n```\n\nUse connmanctl to enable Wi-Fi and Wi-Fi P2P:\n\n```\n$ connman/client/connmanctl\nconnmanctl> enable wifi\nEnabled wifi\nconnmanctl> enable p2p\nEnabled p2p\n```\n\nCheck that Peer-to-peer functionality is working:\n\n```\nconnmanctl> scan p2p\nScan completed for p2p\nconnmanctl> peers\nNexus 5 (jku) idle peer_0c8bfd5f12fc_8ac9d0c0da67\nPush2TV 75AEB2-PTV3000 idle peer_0c8bfd5f12fc_22e52a75aeb2\n\n```\n\nEnable agent:\n\n```\nconnmanctl> agent on\nAgent registered\n```\n\n#### Testing WDS sink with an Android device (e.g. Nexus 5):\n\n* start sink: `sink/sink-test`\n* Android: select the sink from the list in \"Settings > Display > Cast Screen\"\n* connmanctl: when agent asks, accept the connection\n\nIn a few seconds, a window should open and a audio/video stream should start playing.\n\n#### Testing WDS source with another sink:\n\n* start source: `desktop_source/desktop_source`\n* Initial scan will be automatic, but `scan` command will re-scan.\n* After getting scan results, connect with `connect N` (where N is number from scan result)\n* connmanctl: when agent asks, accept the connection\n\nIn a few seconds, the sink should start showing a stream mirroring your desktop.\n\n"
  },
  {
    "path": "TODO",
    "content": "GOAL: Make a release with the proper librarization by the time all dependencies are released, namely\n\ta. wpa_supplicant, past 2.3 (likely 2.4)\n\tb. connman, past 1.28\t(likely 1.29)\n\tc. gst_plugins_bad past 1.4.5+ (likely 1.4.6) \n\n\nBig tasks (see issue tracker for the rest)\n==========================================\n\nInspect and beautify P2P API\n\nCreate an installable library from the current source tree\n\nCreate C/gobject interface to the library so that language bindings can be done easliy\n\t\nCreate API for HDCP plugin implementation\n\nImplement UIBC \n\nUse accelerated encoders/decoders for demo apps\n\n\n"
  },
  {
    "path": "data/CMakeLists.txt",
    "content": "configure_file(wds.pc.in wds.pc @ONLY)\ninstall(FILES ${CMAKE_CURRENT_BINARY_DIR}/wds.pc\n        DESTINATION lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig)\n"
  },
  {
    "path": "data/wds.pc.in",
    "content": "prefix=@CMAKE_INSTALL_PREFIX@\nexec_prefix=${prefix}\nlibdir=${prefix}/@CMAKE_INSTALL_LIBDIR@\nincludedir=${exec_prefix}/include\n \nName: @CMAKE_PROJECT_NAME@\nDescription: Library to build WiFi Display applications\nVersion: @WDS_VERSION_MAJOR@.@WDS_VERSION_MINOR@.@WDS_VERSION_PATCH@\nLibs: -L${libdir} -lwds\nCflags: -I${includedir}/wds\n"
  },
  {
    "path": "datadumps/gstreamer-pipelines.txt",
    "content": "WFD source:\n\n Only video:\n gst-launch-1.0 videotestsrc ! x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=5000\n\n Only audio:\n gst-launch-1.0 audiotestsrc ! avenc_ac3 ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=5000\n\n Both:\n gst-launch-1.0 videotestsrc ! x264enc ! muxer.  audiotestsrc ! avenc_ac3 ! muxer.  mpegtsmux name=muxer ! rtpmp2tpay ! udpsink host=127.0.0.1 port=5000\n\nWFD sink:\n\n Only audio:\n gst-launch-1.0 udpsrc port=5000 caps=\"application/x-rtp\" ! rtpmp2tdepay ! decodebin ! autoaudiosink\n\n Only video:\n gst-launch-1.0 udpsrc port=5000 caps=\"application/x-rtp\" ! rtpmp2tdepay ! decodebin ! autovideosink\n\n Both:\n gst-launch-1.0 udpsrc port=5000 caps=\"application/x-rtp\" ! rtpmp2tdepay ! decodebin name=decoder ! autoaudiosink  decoder. ! autovideosink\n\n"
  },
  {
    "path": "datadumps/rtsp-capture-win8.txt",
    "content": "OPTIONS * RTSP/1.0\nCSeq: 1\nRequire: org.wfa.wfd1.0\nUser-Agent: WiDiApp/4.5.35.0 RDS/1.0.0\n\nRTSP/1.0 200 OK\nCSeq: 1\nDate: Thu Jan  1 00:05:42 1970\nPublic: org.wfa.wfd1.0, GET_PARAMETER, SET_PARAMETER\n\nOPTIONS * RTSP/1.0\nCSeq: 1\nRequire: org.wfa.wfd1.0\nUser-Agent: SEC-WDH/ME29\n\nRTSP/1.0 200 OK\nCSeq: 1\nDate: Tue, Aug 05 2014 18:56:28 GMT\nPublic: org.wfa.wfd1.0, GET_PARAMETER, PAUSE, PLAY, SETUP, SET_PARAMETER, TEARDOWN\n\nGET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 2\nContent-Type: text/parameters\nContent-Length: 325\n\nwfd_client_rtp_ports\nwfd_audio_codecs\nwfd_video_formats\nwfd_3d_video_formats\nwfd_coupled_sink\nwfd_display_edid\nwfd_connector_type\nwfd_uibc_capability\nwfd_standby_resume_capability\nwfd_content_protection\nintel_sink_version\nintel_sink_information\nintel_lower_bandwidth\nintel_interactivity_mode\nintel_fast_cursor\nRTSP/1.0 200 OK\nCSeq: 2\nContent-Type: text/parameters\nContent-Length: 1187\n\nwfd_audio_codecs: LPCM 00000003 00, AAC 00000001 00\nwfd_video_formats: 40 00 02 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 none none, 01 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 none none\nwfd_3d_video_formats: 80 00 03 0F 0000000000000005 00 0001 1401 13 none none\nwfd_content_protection: HDCP2.1 port=1189\nwfd_display_edid: 0002 00ffffffffffff004c2dde07000000002f14010380834a780aee91a3544c99260f5054bdef80714f8100814081809500950fb300a940023a801871382d40582c4500a05a0000001e662150b051001b3040703600a05a0000001e000000fd00184b1a5117000a202020202020000000fc0053414d53554e470a202020202001fd02032ef14b901f0413051403122021222309070783010000e2000f72030c004000b82d20d0080140073f405090a0023a80d072382d40102c4580a05a0000001e011d00bc52d01e20b8285540a05a0000001e011d80d0721c1620102c2580a05a0000009e00000000000000000000000000000000000000000000000000000078\nwfd_coupled_sink: none\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\nwfd_uibc_capability: none\nwfd_connector_type: 05\nwfd_standby_resume_capability: supported\nintel_sink_version: product_ID=widicesdk hw_version=02.00.00.0000 sw_version=02.04.46.0000\nintel_lower_bandwidth: none\nintel_interactivity_mode: HIGH\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 3\nContent-Type: text/parameters\nContent-Length: 248\n\nwfd_audio_codecs: AAC 00000001 00\nwfd_video_formats: 00 00 02 04 00000020 00000000 00000000 00 0000 0000 11 none none\nwfd_presentation_URL: rtsp://192.168.173.1/wfd1.0/streamid=0 none\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\nRTSP/1.0 200 OK\nCSeq: 3\n\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 4\nContent-Type: text/parameters\nContent-Length: 146\n\nintel_overscan_comp: x=0, y=0\nintel_sigma_pipeline_params: PlaybackDelay=50; PositiveMaxStcPCR=25; NegativeMaxStcPCR=50;\nintel_topology: CLONE\nRTSP/1.0 200 OK\nCSeq: 4\n\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 5\nContent-Type: text/parameters\nContent-Length: 27\n\nwfd_trigger_method: SETUP\nRTSP/1.0 200 OK\nCSeq: 5\n\nSETUP rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 2\nUser-Agent: SEC-WDH/ME29\nTransport: RTP/AVP/UDP;unicast;client_port=19000\n\nRTSP/1.0 200 OK\nCSeq: 2\nSession: VaMkltjy;timeout=60\nTransport: RTP/AVP/UDP;unicast;client_port=19000;server_port=53151-53153\n\nPLAY rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 3\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\n\nRTSP/1.0 200 OK\nCSeq: 3\nSession: VaMkltjy\nDate: Tue, Aug 05 2014 18:56:29 GMT\n\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 6\nContent-Type: text/parameters\nContent-Length: 31\nSession: VaMkltjy\n\nintel_enable_widi_rtcp: 53153\nRTSP/1.0 200 OK\nCSeq: 6\n\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 7\nContent-Type: text/parameters\nContent-Length: 172\nSession: VaMkltjy\n\nwfd_audio_codecs: AAC 00000001 00\nwfd_video_formats: 00 00 02 04 00000000 00001000 00000000 00 0000 0000 11 none none\nwfd_av_format_change_timing: 00000bb800 000005dc00\nRTSP/1.0 200 OK\nCSeq: 7\n\nSET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 8\nContent-Type: text/parameters\nContent-Length: 150\nSession: VaMkltjy\n\nintel_sigma_pipeline_params: PlaybackDelay=50; PositiveMaxStcPCR=25; NegativeMaxStcPCR=50;\nintel_interactivity_mode: DEFAULT\nintel_topology: LOCAL\nRTSP/1.0 200 OK\nCSeq: 8\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 4\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 4\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 5\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 5\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 6\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 6\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 7\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 7\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 8\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 8\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 9\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 9\nSession: VaMkltjy\n\nSET_PARAMETER rtsp://192.168.173.1/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 10\nSession: VaMkltjy\nUser-Agent: SEC-WDH/ME29\nContent-Type: text/parameters\nContent-Length: 17\n\nwfd_idr_request\nRTSP/1.0 200 OK\nCSeq: 10\nSession: VaMkltjy\n\n\n"
  },
  {
    "path": "desktop_source/CMakeLists.txt",
    "content": "#FIXME in the future: with cmake 2.8.12 and up it's better\n#to use target_compile_options or add_compile_options\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wall -pthread -std=c++11\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/libwds/public\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/libwds/parser\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/p2p\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/mirac_network\")\n\nfind_package(PkgConfig REQUIRED)\n\npkg_check_modules (GLIB2 REQUIRED glib-2.0)\ninclude_directories(${GLIB2_INCLUDE_DIRS})\n\npkg_check_modules (GIO REQUIRED gio-2.0)\ninclude_directories(${GIO_INCLUDE_DIRS})\n\npkg_check_modules (GST REQUIRED gstreamer-1.0)\ninclude_directories(${GST_INCLUDE_DIRS})\n\nadd_executable(desktop-source-test main.cpp source-app.cpp mirac_broker_source.cpp desktop_media_manager.cpp)\ntarget_link_libraries (desktop-source-test  mirac wds p2p ${GIO_LIBRARIES} ${GST_LIBRARIES})\n\nif (WDS_INSTALL_TESTS)\n  install(PROGRAMS desktop-source-test DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})\nendif()\n"
  },
  {
    "path": "desktop_source/desktop_media_manager.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n#include \"desktop_media_manager.h\"\n#include \"mirac-glib-logging.hpp\"\n#include <cassert>\n\nDesktopMediaManager::DesktopMediaManager(const std::string& hostname)\n  : hostname_(hostname),\n    format_() {\n}\n\nvoid DesktopMediaManager::Play() {\n  assert(gst_pipeline_);\n  gst_pipeline_->SetState(GST_STATE_PLAYING);\n}\n\nvoid DesktopMediaManager::Pause() {\n  assert(gst_pipeline_);\n  gst_pipeline_->SetState(GST_STATE_PAUSED);\n}\n\nvoid DesktopMediaManager::Teardown() {\n  if (gst_pipeline_)\n    gst_pipeline_->SetState(GST_STATE_READY);\n}\n\nbool DesktopMediaManager::IsPaused() const {\n  return (gst_pipeline_->GetState() != GST_STATE_PLAYING);\n}\n\nstd::string DesktopMediaManager::GetSessionId() const {\n  return \"abcdefg123456\";\n}\n\nwds::SessionType DesktopMediaManager::GetSessionType() const {\n  return wds::VideoSession;\n}\n\nvoid DesktopMediaManager::SetSinkRtpPorts(int port1, int port2) {\n  sink_port1_ = port1;\n  sink_port2_ = port2;\n  gst_pipeline_.reset(new MiracGstTestSource(WFD_DESKTOP, hostname_, port1));\n  gst_pipeline_->SetState(GST_STATE_READY);\n}\n\nstd::pair<int, int> DesktopMediaManager::GetSinkRtpPorts() const {\n  return std::pair<int, int>(sink_port1_, sink_port2_);\n}\n\nint DesktopMediaManager::GetLocalRtpPort() const {\n  return gst_pipeline_->UdpSourcePort();\n}\n\nnamespace {\n\nstd::vector<wds::H264VideoCodec> GetH264VideoCodecs() {\n  static std::vector<wds::H264VideoCodec> codecs;\n  if (codecs.empty()) {\n    wds::RateAndResolutionsBitmap cea_rr;\n    wds::RateAndResolutionsBitmap vesa_rr;\n    wds::RateAndResolutionsBitmap hh_rr;\n    wds::RateAndResolution i;\n    // declare that we support all resolutions, CHP and level 4.2\n    // gstreamer should handle all of it :)\n    for (i = wds::CEA640x480p60; i <= wds::CEA1920x1080p24; ++i)\n      cea_rr.set(i);\n    for (i = wds::VESA800x600p30; i <= wds::VESA1920x1200p30; ++i)\n      vesa_rr.set(i);\n    for (i = wds::HH800x480p30; i <= wds::HH848x480p60; ++i)\n      hh_rr.set(i);\n\n    wds::H264VideoCodec codec(wds::CHP, wds::k4_2, cea_rr, vesa_rr, hh_rr);\n    codecs.push_back(codec);\n  }\n\n  return codecs;\n}\n\n}\n\nbool DesktopMediaManager::InitOptimalVideoFormat(\n    const wds::NativeVideoFormat& sink_native_format,\n    const std::vector<wds::H264VideoCodec>& sink_supported_codecs) {\n\n  format_ = wds::FindOptimalVideoFormat(sink_native_format,\n                                        GetH264VideoCodecs(),\n                                        sink_supported_codecs);\n  return true;\n}\n\nwds::H264VideoFormat DesktopMediaManager::GetOptimalVideoFormat() const {\n  return format_;\n}\n\nbool DesktopMediaManager::InitOptimalAudioFormat(const std::vector<wds::AudioCodec>& sink_codecs) {\n  for (const auto& codec : sink_codecs) {\n     if (codec.format == wds::AAC && codec.modes.test(wds::AAC_48K_16B_2CH))\n       return true;\n  }\n  return false;\n}\n\nwds::AudioCodec DesktopMediaManager::GetOptimalAudioFormat() const {\n  wds::AudioModes audio_modes;\n  audio_modes.set(wds::AAC_48K_16B_2CH);\n\n  return wds::AudioCodec(wds::AAC, audio_modes, 0);\n}\n\nvoid DesktopMediaManager::SendIDRPicture() {\n  WDS_WARNING(\"Unimplemented IDR picture request\");\n}\n"
  },
  {
    "path": "desktop_source/desktop_media_manager.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n#ifndef DESKTOP_MEDIA_MANAGER_H_\n#define DESKTOP_MEDIA_MANAGER_H_\n\n#include <memory>\n\n#include \"libwds/public/media_manager.h\"\n#include \"mirac-gst-test-source.hpp\"\n\nclass DesktopMediaManager : public wds::SourceMediaManager {\n public:\n  explicit DesktopMediaManager(const std::string& hostname);\n  void Play() override;\n  void Pause() override;\n  void Teardown() override;\n  bool IsPaused() const override;\n  std::string GetSessionId() const override;\n  void SetSinkRtpPorts(int port1, int port2) override;\n  std::pair<int,int> GetSinkRtpPorts() const override;\n  int GetLocalRtpPort() const override;\n  wds::SessionType GetSessionType() const override;\n\n  bool InitOptimalVideoFormat(const wds::NativeVideoFormat& sink_native_format,\n      const std::vector<wds::H264VideoCodec>& sink_supported_codecs) override;\n  wds::H264VideoFormat GetOptimalVideoFormat() const override;\n  bool InitOptimalAudioFormat(const std::vector<wds::AudioCodec>& sink_supported_codecs) override;\n  wds::AudioCodec GetOptimalAudioFormat() const override;\n  void SendIDRPicture() override;\n\n private:\n  std::string hostname_;\n  std::unique_ptr<MiracGstTestSource> gst_pipeline_;\n  int sink_port1_;\n  int sink_port2_;\n  wds::H264VideoFormat format_;\n};\n\n#endif // DESKTOP_MEDIA_MANAGER_H_\n"
  },
  {
    "path": "desktop_source/main.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <glib.h>\n#include <glib-unix.h>\n#include <gst/gst.h>\n#include <iostream>\n\n#include \"source-app.h\"\n#include \"mirac_broker_source.h\"\n#include \"mirac-glib-logging.hpp\"\n\n#include \"libwds/public/source.h\"\n\nstatic gboolean _sig_handler (gpointer data_ptr)\n{\n    GMainLoop *main_loop = (GMainLoop *) data_ptr;\n\n    g_main_loop_quit(main_loop);\n\n    return G_SOURCE_CONTINUE;\n}\n\nstatic void parse_input_and_call_source(\n    const std::string& command, SourceApp *app) {\n\n    auto source = app->source()->wfd_source();\n    bool status = true;\n\n    if (command == \"scan\\n\") {\n        app->scan();\n    } else if (command.find(\"connect \") == 0) {\n        app->connect(std::stoi(command.substr(8)));\n    } else if (command == \"teardown\\n\") {\n        status = source && source->Teardown();\n    } else if (command == \"pause\\n\") {\n        status = source && source->Pause();\n    } else if (command == \"play\\n\") {\n        status = source && source->Play();\n    } else {\n        std::cout << \"Received unknown command: \" << command << std::endl;\n    }\n\n    if (!status)\n        std::cout << \"This command cannot be executed now.\" << std::endl;\n}\n\nstatic gboolean _user_input_handler (\n    GIOChannel* channel, GIOCondition /*condition*/, gpointer data_ptr)\n{\n    GError* error = NULL;\n    char* str = NULL;\n    size_t len;\n    SourceApp* app = static_cast<SourceApp*>(data_ptr);\n\n    switch (g_io_channel_read_line(channel, &str, &len, NULL, &error)) {\n    case G_IO_STATUS_NORMAL:\n        parse_input_and_call_source(str, app);\n        g_free(str);\n        return true;\n    case G_IO_STATUS_ERROR:\n        std::cout << \"User input error: \" << error->message << std::endl;\n        g_error_free(error);\n        return false;\n    case G_IO_STATUS_EOF:\n    case G_IO_STATUS_AGAIN:\n        return true;\n    default:\n        return false;\n    }\n    return false;\n}\n\nint main (int argc, char *argv[])\n{\n    InitGlibLogging();\n    int port = 7236;\n\n    GOptionEntry main_entries[] =\n    {\n        { \"rtsp_port\", 0, 0, G_OPTION_ARG_INT, &(port), \"Specify optional RTSP port number, 7236 by default\", \"rtsp_port\"},\n        { NULL }\n    };\n\n    GOptionContext* context = g_option_context_new (\"- WFD desktop source demo application\\n\");\n    g_option_context_add_main_entries (context, main_entries, NULL);\n    g_option_context_add_group (context, gst_init_get_option_group ());\n\n    GError* error = NULL;\n    if (!g_option_context_parse (context, &argc, &argv, &error)) {\n        WDS_ERROR (\"option parsing failed: %s\", error->message);\n        g_option_context_free(context);\n        exit (1);\n    }\n    g_option_context_free(context);\n\n    SourceApp app(port);\n\n    GMainLoop *main_loop =  g_main_loop_new(NULL, TRUE);\n    g_unix_signal_add(SIGINT, _sig_handler, main_loop);\n    g_unix_signal_add(SIGTERM, _sig_handler, main_loop);\n\n    GIOChannel* io_channel = g_io_channel_unix_new (STDIN_FILENO);\n    g_io_add_watch(io_channel, G_IO_IN, _user_input_handler, &app);\n    g_io_channel_unref(io_channel);\n\n\n    g_main_loop_run (main_loop);\n\n    g_main_loop_unref (main_loop);\n\n    return 0;\n}\n\n"
  },
  {
    "path": "desktop_source/mirac_broker_source.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n\n#include \"desktop_media_manager.h\"\n#include \"mirac_broker_source.h\"\n\n#include \"libwds/public/source.h\"\n\nMiracBrokerSource::MiracBrokerSource(int rtsp_port)\n  : MiracBroker(std::to_string(rtsp_port)) {\n}\n\nMiracBrokerSource::~MiracBrokerSource() {}\n\nvoid MiracBrokerSource::got_message(const std::string& message) {\n  wfd_source_->RTSPDataReceived(message);\n}\n\nvoid MiracBrokerSource::on_connected() {\n  media_manager_.reset(new DesktopMediaManager(get_peer_address()));\n  wfd_source_.reset(wds::Source::Create(this, media_manager_.get()));\n  wfd_source_->Start();\n}\n\nvoid MiracBrokerSource::on_connection_failure(ConnectionFailure failure) {\n  switch (failure) {\n      case CONNECTION_LOST:\n          std::cout << \"* RTSP connection lost\" << std::endl;\n          break;\n      case CONNECTION_TIMEOUT:\n          std::cout << \"* RTSP connection failed: timeout\" << std::endl;\n          break;\n      default:\n          std::cout << \"* RTSP connection failure\" << std::endl;\n  }\n}\n\nwds::Peer* MiracBrokerSource::Peer() const {\n  return wfd_source_.get();\n}\n"
  },
  {
    "path": "desktop_source/mirac_broker_source.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef MIRAC_BROKER_SOURCE_H_\n#define MIRAC_BROKER_SOURCE_H_\n\n#include <memory>\n\n#include \"mirac-broker.hpp\"\n\nnamespace wds {\nclass SourceMediaManager;\nclass Source;\n}\n\nclass MiracBrokerSource : public MiracBroker {\n public:\n  explicit MiracBrokerSource(int rtsp_port);\n  ~MiracBrokerSource();\n\n  wds::Source* wfd_source() { return wfd_source_.get(); }\n\n private:\n  virtual void got_message(const std::string& message) override;\n  virtual void on_connected() override;\n  void on_connection_failure(ConnectionFailure failure) override;\n  virtual wds::Peer* Peer() const override;\n\n  std::unique_ptr<wds::SourceMediaManager> media_manager_;\n  std::unique_ptr<wds::Source> wfd_source_;\n};\n\n#endif // MIRAC_BROKER_SOURCE_H_\n"
  },
  {
    "path": "desktop_source/source-app.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n#include <netinet/in.h> // htons()\n\n#include \"source-app.h\"\n\nvoid SourceApp::on_availability_changed(P2P::Client *client)\n{\n    if (client->is_available())\n        scan();\n}\n\nvoid SourceApp::on_peer_added(P2P::Client *client, std::shared_ptr<P2P::Peer> peer)\n{\n    if (peer->device_type() == P2P::PRIMARY_SINK) {\n        peer->set_observer(this);\n    }\n}\n\nvoid SourceApp::on_peer_removed(P2P::Client *client, std::shared_ptr<P2P::Peer> peer)\n{\n    for (auto it = peers_.begin(); it != peers_.end();) {\n        if (it->second == peer.get()) {\n            peers_.erase (it++);\n            return;\n        } else {\n            ++it;\n        }\n    }\n}\n\nvoid SourceApp::on_initialized(P2P::Peer *peer)\n{\n    peers_[peer_index_] = peer;\n    std::cout << \"  \"<< peer_index_ << \" : \" << peer->name() << std::endl;\n    peer_index_++;\n}\n\nvoid SourceApp::scan()\n{\n    std::cout << \"* Now scanning for peers...\" << std::endl;\n    p2p_client_->scan();\n}\n\nbool SourceApp::connect(uint peer_index)\n{\n    auto it = peers_.find (peer_index);\n    if (it == peers_.end()) {\n        std::cout << \"No such peer\" << std::endl;\n        return false;\n    }\n\n    it->second->connect ();\n    return true;\n}\n\nvoid SourceApp::on_availability_changed(P2P::Peer *peer)\n{\n    if (!peer->is_available())\n        return;\n\n    std::cout << \"* Connected to \" << peer->remote_host()  << std::endl;\n}\n\nSourceApp::SourceApp(int port) :\n    peer_index_(0)\n{\n    // Create a information element for a simple WFD Source\n    P2P::InformationElement ie;\n    auto sub_element = P2P::new_subelement(P2P::DEVICE_INFORMATION);\n    auto dev_info = (P2P::DeviceInformationSubelement*)sub_element;\n\n    // TODO InformationElement could have constructors for this stuff...\n    dev_info->session_management_control_port = htons(port);\n    dev_info->maximum_throughput = htons(50);\n    dev_info->field1.device_type = P2P::SOURCE;\n    dev_info->field1.session_availability = true;\n    ie.add_subelement(sub_element);\n\n    std::cout << \"* Registering Wi-Fi Display Source with IE \" << ie.to_string() <<  std::endl;\n\n    // register the P2P service with connman\n    auto array = ie.serialize ();\n    p2p_client_.reset(new P2P::Client(array, this));\n\n    source_.reset(new MiracBrokerSource(port));\n}\n\nSourceApp::~SourceApp()\n{\n}\n"
  },
  {
    "path": "desktop_source/source-app.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef SOURCE_APP_H\n#define SOURCE_APP_H\n\n#include <memory>\n\n#include \"source.h\"\n#include \"connman-client.h\"\n#include \"mirac_broker_source.h\"\n\nclass SourceApp: public P2P::Client::Observer, public P2P::Peer::Observer {\n  public:\n    SourceApp(int port);\n    ~SourceApp();\n\n    MiracBrokerSource* source() { return source_.get(); }\n\n    void on_peer_added(P2P::Client *client, std::shared_ptr<P2P::Peer> peer) override;\n    void on_peer_removed(P2P::Client *client, std::shared_ptr<P2P::Peer> peer) override;\n    void on_availability_changed(P2P::Client *client) override;\n\n    void on_availability_changed(P2P::Peer *peer) override;\n    void on_initialized(P2P::Peer *peer) override;\n\n    void scan();\n    bool connect(uint peer_index);\n\n  private:\n    std::unique_ptr<P2P::Client> p2p_client_;\n    std::unique_ptr<MiracBrokerSource> source_;\n    std::map<uint, P2P::Peer*>peers_;\n    uint peer_index_;\n};\n\n#endif // SOURCE_APP_H\n"
  },
  {
    "path": "libwds/CMakeLists.txt",
    "content": "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\n\nadd_library(wds\n    SHARED $<TARGET_OBJECTS:wdsrtsp>\n           $<TARGET_OBJECTS:wdscommon>\n           $<TARGET_OBJECTS:wdssink>\n           $<TARGET_OBJECTS:wdssource>)\nset_target_properties(wds PROPERTIES\n    VERSION ${WDS_VERSION_MAJOR}.${WDS_VERSION_MINOR}.${WDS_VERSION_PATCH}\n    SOVERSION ${WDS_VERSION_MAJOR})\n\ninstall(TARGETS wds LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})\n\nset(PUBLIC_HEADERS\n    public/connector_type.h\n    public/peer.h\n    public/video_format.h\n    public/sink.h\n    public/wds_export.h\n    public/audio_codec.h\n    public/media_manager.h\n    public/source.h\n    public/logging.h)\n\ninstall(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/wds)\n"
  },
  {
    "path": "libwds/common/CMakeLists.txt",
    "content": "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden -fPIC\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\" \"${PROJECT_SOURCE_DIR}/libwds/rtsp/gen\")\n\nadd_library(wdscommon OBJECT\n    logging.cpp message_handler.cpp rtsp_input_handler.cpp video_format.cpp)\nadd_dependencies(wdscommon wdsrtsp)\n"
  },
  {
    "path": "libwds/common/logging.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2016 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/public/logging.h\"\n\nnamespace wds {\n\nstatic void Dummy(const char*, ...) {}\nLogSystem::LogFunction LogSystem::log_func_ = &Dummy;\nLogSystem::LogFunction LogSystem::vlog_func_ = &Dummy;\nLogSystem::LogFunction LogSystem::warning_func_ = &Dummy;\nLogSystem::LogFunction LogSystem::error_func_ = &Dummy;\n\nvoid LogSystem::set_log_func(LogFunction func) {\n  log_func_ = func;\n}\n\nLogSystem::LogFunction LogSystem::log_func() {\n  return log_func_;\n}\n\nvoid LogSystem::set_vlog_func(LogFunction func) {\n  vlog_func_ = func;\n}\n\nLogSystem::LogFunction LogSystem::vlog_func() {\n  return vlog_func_;\n}\n\nvoid LogSystem::set_warning_func(LogFunction func) {\n  warning_func_ = func;\n}\n\nLogSystem::LogFunction LogSystem::warning_func() {\n  return warning_func_;\n}\n\nvoid LogSystem::set_error_func(LogFunction func) {\n  error_func_ = func;\n}\n\nLogSystem::LogFunction LogSystem::error_func() {\n  return error_func_;\n}\n\n}  // namespace wds\n"
  },
  {
    "path": "libwds/common/message_handler.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <algorithm>\n\n#include \"libwds/common/message_handler.h\"\n#include \"libwds/public/media_manager.h\"\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nbool MessageHandler::HandleTimeoutEvent(unsigned timer_id) const {\n  return false;\n}\n\nMessageHandler::~MessageHandler() {}\n\nMessageSequenceHandler::MessageSequenceHandler(const InitParams& init_params)\n  : MessageHandler(init_params),\n    current_handler_(nullptr) {\n}\n\nMessageSequenceHandler::~MessageSequenceHandler() {\n}\n\nvoid MessageSequenceHandler::Start() {\n  if (current_handler_) {\n    return;\n  }\n  current_handler_ = handlers_.front();\n  current_handler_->Start();\n}\n\nvoid MessageSequenceHandler::Reset() {\n  if (current_handler_) {\n    current_handler_->Reset();\n    current_handler_ = nullptr;\n  }\n}\n\nbool MessageSequenceHandler::CanSend(Message* message) const {\n  return current_handler_ && current_handler_->CanSend(message);\n}\n\nvoid MessageSequenceHandler::Send(std::unique_ptr<Message> message) {\n  assert(current_handler_);\n  current_handler_->Send(std::move(message));\n}\n\nbool MessageSequenceHandler::CanHandle(Message* message) const {\n  return current_handler_ && current_handler_->CanHandle(message);\n}\n\nvoid MessageSequenceHandler::Handle(std::unique_ptr<Message> message) {\n  assert(current_handler_);\n  current_handler_->Handle(std::move(message));\n}\n\nvoid MessageSequenceHandler::AddSequencedHandler(MessageHandlerPtr handler) {\n  assert(!current_handler_); // We are not started\n  assert(handler);\n  assert(handlers_.end() == std::find(\n      handlers_.begin(), handlers_.end(), handler));\n  handlers_.push_back(handler);\n  handler->set_observer(this);\n}\n\nvoid MessageSequenceHandler::OnCompleted(MessageHandlerPtr handler) {\n  assert(handler == current_handler_);\n  current_handler_->Reset();\n\n  auto it = std::find(handlers_.begin(), handlers_.end(), handler);\n  assert(handlers_.end() != it);\n  if (++it == handlers_.end()) {\n    observer_->OnCompleted(shared_from_this());\n    return;\n  }\n\n  current_handler_ = *it;\n  current_handler_->Start();\n}\n\nvoid MessageSequenceHandler::OnError(MessageHandlerPtr handler) {\n  assert(handler == current_handler_);\n  handler->Reset();\n  observer_->OnError(shared_from_this());\n}\n\nbool MessageSequenceHandler::HandleTimeoutEvent(unsigned timer_id) const {\n  return current_handler_->HandleTimeoutEvent(timer_id);\n}\n\nMessageSequenceWithOptionalSetHandler::MessageSequenceWithOptionalSetHandler(\n    const InitParams& init_params)\n  : MessageSequenceHandler(init_params) {\n}\n\nMessageSequenceWithOptionalSetHandler::~MessageSequenceWithOptionalSetHandler() {\n}\n\nvoid MessageSequenceWithOptionalSetHandler::Start() {\n  MessageSequenceHandler::Start();\n  for (MessageHandlerPtr handler : optional_handlers_)\n    handler->Start();\n}\n\nvoid MessageSequenceWithOptionalSetHandler::Reset() {\n  MessageSequenceHandler::Reset();\n  for (MessageHandlerPtr handler : optional_handlers_)\n    handler->Reset();\n}\n\nbool MessageSequenceWithOptionalSetHandler::CanSend(Message* message) const {\n  for (MessageHandlerPtr handler : optional_handlers_)\n    if (handler->CanSend(message))\n      return true;\n\n  if (MessageSequenceHandler::CanSend(message))\n    return true;\n\n  return false;\n}\n\nvoid MessageSequenceWithOptionalSetHandler::Send(std::unique_ptr<Message> message) {\n  for (MessageHandlerPtr handler : optional_handlers_) {\n    if (handler->CanSend(message.get())) {\n      handler->Send(std::move(message));\n      return;\n    }\n  }\n\n  if (MessageSequenceHandler::CanSend(message.get())) {\n    MessageSequenceHandler::Send(std::move(message));\n    return;\n  }\n\n  observer_->OnError(shared_from_this());\n}\n\nbool MessageSequenceWithOptionalSetHandler::CanHandle(Message* message) const {\n  if (MessageSequenceHandler::CanHandle(message))\n    return true;\n\n  for (MessageHandlerPtr handler : optional_handlers_)\n    if (handler->CanHandle(message))\n      return true;\n\n  return false;\n}\n\nvoid MessageSequenceWithOptionalSetHandler::Handle(std::unique_ptr<Message> message) {\n  if (MessageSequenceHandler::CanHandle(message.get())) {\n     MessageSequenceHandler::Handle(std::move(message));\n     return;\n  }\n\n  for (MessageHandlerPtr handler : optional_handlers_) {\n    if (handler->CanHandle(message.get())) {\n      handler->Handle(std::move(message));\n      return;\n    }\n  }\n\n  observer_->OnError(shared_from_this());\n}\n\nvoid MessageSequenceWithOptionalSetHandler::AddOptionalHandler(\n    MessageHandlerPtr handler) {\n  assert(handler);\n  assert(optional_handlers_.end() == std::find(\n      optional_handlers_.begin(), optional_handlers_.end(), handler));\n  optional_handlers_.push_back(handler);\n  handler->set_observer(this);\n}\n\nvoid MessageSequenceWithOptionalSetHandler::OnCompleted(MessageHandlerPtr handler) {\n  auto it = std::find(\n      optional_handlers_.begin(), optional_handlers_.end(), handler);\n  if (it != optional_handlers_.end()) {\n    handler->Reset();\n    handler->Start();\n    return;\n  }\n  MessageSequenceHandler::OnCompleted(handler);\n}\n\nvoid MessageSequenceWithOptionalSetHandler::OnError(MessageHandlerPtr handler) {\n  handler->Reset();\n  observer_->OnError(shared_from_this());\n}\n\nbool MessageSequenceWithOptionalSetHandler::HandleTimeoutEvent(unsigned timer_id) const {\n  for (MessageHandlerPtr handler : optional_handlers_)\n    if (handler->HandleTimeoutEvent(timer_id))\n      return true;\n  return MessageSequenceHandler::HandleTimeoutEvent(timer_id);\n}\n\n// MessageReceiverBase\nMessageReceiverBase::MessageReceiverBase(const InitParams& init_params)\n  : MessageHandler(init_params),\n    wait_for_message_(false) {}\n\nMessageReceiverBase::~MessageReceiverBase() {}\n\nbool MessageReceiverBase::CanHandle(Message* message) const {\n  assert(message);\n  return wait_for_message_;\n}\n\nvoid MessageReceiverBase::Start() { wait_for_message_ = true; }\nvoid MessageReceiverBase::Reset() { wait_for_message_ = false; }\nbool MessageReceiverBase::CanSend(Message* message) const { return false; }\nvoid MessageReceiverBase::Send(std::unique_ptr<Message> message) {}\nvoid MessageReceiverBase::Handle(std::unique_ptr<Message> message) {\n  assert(message);\n  if (!CanHandle(message.get())) {\n    observer_->OnError(shared_from_this());\n    return;\n  }\n  wait_for_message_ = false;\n  std::unique_ptr<Reply> reply = HandleMessage(message.get());\n  if (!reply) {\n    observer_->OnError(shared_from_this());\n    return;\n  }\n  reply->header().set_cseq(message->cseq());\n  sender_->SendRTSPData(reply->ToString());\n  observer_->OnCompleted(shared_from_this());\n}\n\nMessageSenderBase::MessageSenderBase(const InitParams& init_params)\n  : MessageHandler(init_params) {\n}\n\nMessageSenderBase::~MessageSenderBase() {\n  for (const ParcelData& data : parcel_queue_)\n    sender_->ReleaseTimer(data.timer_id);\n}\n\nvoid MessageSenderBase::Reset() {\n  while (!parcel_queue_.empty()) {\n    sender_->ReleaseTimer(parcel_queue_.front().timer_id);\n    parcel_queue_.pop_front();\n  }\n}\n\nvoid MessageSenderBase::Send(std::unique_ptr<Message> message) {\n  assert(message);\n  if (!CanSend(message.get())) {\n    observer_->OnError(shared_from_this());\n    return;\n  }\n  parcel_queue_.push_back(\n      {message->cseq(), sender_->CreateTimer(GetResponseTimeout())});\n  sender_->SendRTSPData(message->ToString());\n}\n\nbool MessageSenderBase::CanHandle(Message* message) const {\n  assert(message);\n  return message->is_reply() && !parcel_queue_.empty() &&\n         (message->cseq() == parcel_queue_.front().cseq);\n}\n\nvoid MessageSenderBase::Handle(std::unique_ptr<Message> message) {\n  assert(message);\n  if (!CanHandle(message.get())) {\n    observer_->OnError(shared_from_this());\n    return;\n  }\n  sender_->ReleaseTimer(parcel_queue_.front().timer_id);\n  parcel_queue_.pop_front();\n\n  if (!HandleReply(static_cast<Reply*>(message.get()))) {\n    observer_->OnError(shared_from_this());\n    return;\n  }\n\n  if (parcel_queue_.empty()) {\n    observer_->OnCompleted(shared_from_this());\n  }\n}\n\nbool MessageSenderBase::HandleTimeoutEvent(unsigned timer_id) const {\n  for (const ParcelData& data : parcel_queue_)\n    if (data.timer_id == timer_id)\n      return true;\n\n  return false;\n}\n\nint MessageSenderBase::GetResponseTimeout() const {\n  return kDefaultTimeoutValue;\n}\n\nSequencedMessageSender::SequencedMessageSender(const InitParams& init_params)\n  : MessageSenderBase(init_params),\n    to_be_send_(nullptr) {\n}\n\nSequencedMessageSender::~SequencedMessageSender() {\n}\n\nvoid SequencedMessageSender::Start() {\n  auto message = CreateMessage();\n  to_be_send_ = message.get();\n  Send(std::move(message));\n}\n\nvoid SequencedMessageSender::Reset() {\n  to_be_send_ = nullptr;\n  MessageSenderBase::Reset();\n}\n\nbool SequencedMessageSender::CanSend(Message* message) const {\n  return message && (message == to_be_send_);\n}\n\n}\n"
  },
  {
    "path": "libwds/common/message_handler.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_COMMON_MESSAGE_HANDLER_H_\n#define LIBWDS_COMMON_MESSAGE_HANDLER_H_\n\n#include <cassert>\n#include <list>\n#include <vector>\n#include <memory>\n#include <utility>\n\n#include \"libwds/rtsp/message.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/public/logging.h\"\n#include \"libwds/public/peer.h\"\n\nnamespace wds {\n\n// Default keep-alive timer is 60 seconds\nconst int kDefaultKeepAliveTimeout = 60;\n// Default timeout for RTSP message exchange\nconst int kDefaultTimeoutValue = 5;\n\nclass MediaManager;\n\nclass MessageHandler;\nusing MessageHandlerPtr = std::shared_ptr<MessageHandler>;\n\ninline MessageHandlerPtr make_ptr(MessageHandler* handler) {\n  return MessageHandlerPtr(handler);\n}\n\nclass MessageHandler : public std::enable_shared_from_this<MessageHandler> {\n public:\n  class Observer {\n   public:\n    virtual void OnCompleted(MessageHandlerPtr handler) {}\n    virtual void OnError(MessageHandlerPtr handler) {}\n\n   protected:\n    virtual ~Observer() {}\n  };\n\n  struct InitParams {\n    Peer::Delegate* sender;\n    MediaManager* manager;\n    Observer* observer;\n  };\n\n  virtual ~MessageHandler();\n\n  virtual void Start() = 0;\n  virtual void Reset() = 0;\n\n  virtual bool CanSend(rtsp::Message* message) const = 0;\n  virtual void Send(std::unique_ptr<rtsp::Message> message) = 0;\n\n  virtual bool CanHandle(rtsp::Message* message) const = 0;\n  virtual void Handle(std::unique_ptr<rtsp::Message> message) = 0;\n\n  // For handlers that require timeout\n  virtual bool HandleTimeoutEvent(unsigned timer_id) const;\n\n  void set_observer(Observer* observer) {\n    assert(observer);\n    observer_ = observer;\n  }\n\nprotected:\n  explicit MessageHandler(const InitParams& init_params)\n    : sender_(init_params.sender),\n      manager_(init_params.manager),\n      observer_(init_params.observer) {\n    assert(sender_);\n    assert(manager_);\n    assert(observer_);\n  }\n\n  Peer::Delegate* sender_;\n  MediaManager* manager_;\n  Observer* observer_;\n};\n\nclass MessageSequenceHandler : public MessageHandler,\n                               public MessageHandler::Observer {\n public:\n  explicit MessageSequenceHandler(const InitParams& init_params);\n  ~MessageSequenceHandler() override;\n  void Start() override;\n  void Reset() override;\n\n  bool CanSend(rtsp::Message* message) const override;\n  void Send(std::unique_ptr<rtsp::Message> message) override;\n\n  bool CanHandle(rtsp::Message* message) const override;\n  void Handle(std::unique_ptr<rtsp::Message> message) override;\n\n  bool HandleTimeoutEvent(unsigned timer_id) const override;\n\n protected:\n  void AddSequencedHandler(MessageHandlerPtr handler);\n  // MessageHandler::Observer implementation.\n  void OnCompleted(MessageHandlerPtr handler) override;\n  void OnError(MessageHandlerPtr handler) override;\n\n  std::vector<MessageHandlerPtr> handlers_;\n  MessageHandlerPtr current_handler_;\n};\n\nclass MessageSequenceWithOptionalSetHandler : public MessageSequenceHandler {\n public:\n  explicit MessageSequenceWithOptionalSetHandler(const InitParams& init_params);\n  ~MessageSequenceWithOptionalSetHandler() override;\n  void Start() override;\n  void Reset() override;\n  bool CanSend(rtsp::Message* message) const override;\n  void Send(std::unique_ptr<rtsp::Message> message) override;\n  bool CanHandle(rtsp::Message* message) const override;\n  void Handle(std::unique_ptr<rtsp::Message> message) override;\n\n  bool HandleTimeoutEvent(unsigned timer_id) const override;\n\n protected:\n  void AddOptionalHandler(MessageHandlerPtr handler);\n  // MessageHandler::Observer implementation.\n  void OnCompleted(MessageHandlerPtr handler) override;\n  void OnError(MessageHandlerPtr handler) override;\n\n  std::vector<MessageHandlerPtr> optional_handlers_;\n};\n\n// This is aux classes to handle single message.\n// There are two common scenarious:\n// 1. We send a message and wait for reply\n// class Handler : public MessageSender\n//\n// 2. We wait for the message and reply ourselves.\n// class Handler : public MessageReceiver<type of the message\n// we're waiting for>\nclass MessageReceiverBase : public MessageHandler {\n public:\n  explicit MessageReceiverBase(const InitParams& init_params);\n  ~MessageReceiverBase() override;\n\n protected:\n  virtual std::unique_ptr<wds::rtsp::Reply> HandleMessage(rtsp::Message* message) = 0;\n  bool CanHandle(rtsp::Message* message) const override;\n  void Handle(std::unique_ptr<rtsp::Message> message) override;\n\n private:\n  void Start() override;\n  void Reset() override;\n  bool CanSend(rtsp::Message* message) const override;\n  void Send(std::unique_ptr<rtsp::Message> message) override;\n\n  bool wait_for_message_;\n};\n\ntemplate <rtsp::Request::ID id>\nclass MessageReceiver : public MessageReceiverBase {\n public:\n  using MessageReceiverBase::MessageReceiverBase;\n\n protected:\n  bool CanHandle(rtsp::Message* message) const override {\n    return MessageReceiverBase::CanHandle(message) && message->is_request() &&\n           id == ToRequest(message)->id();\n  }\n};\n\nclass MessageSenderBase : public MessageHandler {\n public:\n  explicit MessageSenderBase(const InitParams& init_params);\n  ~MessageSenderBase() override;\n\n protected:\n  virtual bool HandleReply(rtsp::Reply* reply) = 0;\n  void Send(std::unique_ptr<rtsp::Message> message) override;\n  void Reset() override;\n  bool HandleTimeoutEvent(unsigned timer_id) const override;\n\n\n private:\n  bool CanHandle(rtsp::Message* message) const override;\n  void Handle(std::unique_ptr<rtsp::Message> message) override;\n\n  virtual int GetResponseTimeout() const;\n\n  struct ParcelData {\n    int cseq;\n    unsigned timer_id;\n  };\n  std::list<ParcelData> parcel_queue_;\n};\n\n// To be used for optional senders.\ntemplate <rtsp::Request::ID id>\nclass OptionalMessageSender : public MessageSenderBase {\n public:\n  using MessageSenderBase::MessageSenderBase;\n\n protected:\n  bool CanSend(rtsp::Message* message) const override {\n    assert(message);\n    return message->is_request() && ToRequest(message)->id() == id;\n  }\n\n private:\n  void Start() override {}\n};\n\n// To be used for sequensed senders.\nclass SequencedMessageSender : public MessageSenderBase {\n public:\n  explicit SequencedMessageSender(const InitParams& init_params);\n  ~SequencedMessageSender() override;\n\n protected:\n  virtual std::unique_ptr<rtsp::Message> CreateMessage() = 0;\n\n private:\n  void Start() override;\n  void Reset() override;\n  bool CanSend(rtsp::Message* message) const override;\n\n  rtsp::Message* to_be_send_;\n};\n\n}  // namespace wds\n#endif // LIBWDS_COMMON_MESSAGE_HANDLER_H_\n"
  },
  {
    "path": "libwds/common/rtsp_input_handler.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"rtsp_input_handler.h\"\n\n#include \"libwds/rtsp/driver.h\"\n#include \"libwds/rtsp/message.h\"\n\n#include <cassert>\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Driver;\n\nRTSPInputHandler::~RTSPInputHandler() {\n}\n\nvoid RTSPInputHandler::AddInput(const std::string& input) {\n  rtsp_input_buffer_ += input;\n\n  // First trying to get payload for the message obtained\n  // from the previous input.\n  if (message_ && !ParsePayload())\n    return;\n\n  while (ParseHeader()) {\n    if (!ParsePayload())\n      break;\n  }\n}\n\nbool RTSPInputHandler::ParseHeader() {\n  assert(!message_);\n  static const char delimiter[] = \"\\r\\n\\r\\n\";\n  static const int delimiter_length = 4;\n  size_t eom = rtsp_input_buffer_.find(delimiter);\n  if (eom == std::string::npos) {\n    return false;\n  }\n\n  const std::string& header = rtsp_input_buffer_.substr(0, eom + delimiter_length);\n  rtsp_input_buffer_.erase(0, eom + delimiter_length);\n  return Parse(header);\n}\n\nbool RTSPInputHandler::ParsePayload() {\n  assert(message_);\n  unsigned content_length = message_->header().content_length();\n  if (content_length == 0) {\n    MessageParsed(std::move(message_));\n    return true;\n  }\n\n  if (rtsp_input_buffer_.size() < content_length)\n    return false;\n\n  const std::string& payload = rtsp_input_buffer_.substr(0, content_length);\n  rtsp_input_buffer_.erase(0, content_length);\n  if (!Parse(payload))\n    return false;\n\n  MessageParsed(std::move(message_));\n  return true;\n}\n\nbool RTSPInputHandler::Parse(const std::string& input) {\n  Driver::Parse(input, message_);\n  if (!message_) {\n    ParserErrorOccurred(rtsp_input_buffer_);\n    rtsp_input_buffer_.clear();\n    return false;\n  }\n\n  return true;\n}\n\n}  // namespace wds\n"
  },
  {
    "path": "libwds/common/rtsp_input_handler.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_COMMON_RTSP_INPUT_HANDLER_H_\n#define LIBWDS_COMMON_RTSP_INPUT_HANDLER_H_\n\n#include <memory>\n#include <string>\n\nnamespace wds {\n\nnamespace rtsp {\nclass Message;\n}  // namespace rtsp\n\n// An aux class used to obtain Message object from the given raw input.\nclass RTSPInputHandler {\n protected:\n  RTSPInputHandler() = default;\n  virtual ~RTSPInputHandler();\n\n  void AddInput(const std::string& input);\n\n  // To be overridden.\n  virtual void MessageParsed(std::unique_ptr<rtsp::Message> message) = 0;\n  virtual void ParserErrorOccurred(const std::string& invalid_input) {}\n\n private:\n  bool ParseHeader();\n  bool ParsePayload();\n  bool Parse(const std::string& input);\n\n  std::string rtsp_input_buffer_;\n  std::unique_ptr<rtsp::Message> message_;\n};\n\n}\n\n#endif // LIBWDS_COMMON_RTSP_INPUT_HANDLER_H_\n"
  },
  {
    "path": "libwds/common/video_format.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/public/media_manager.h\"\n\n#include <assert.h>\n\n#include <algorithm>\n\n#include \"libwds/public/logging.h\"\n\nnamespace wds {\n\nnamespace {\n// Quality weight is calculated using following formula:\n// width * height * fps * 2 for progressive or 1 for interlaced frames\nstruct QualityInfo {\n  unsigned width;\n  unsigned height;\n  unsigned weight;\n};\n\nconst QualityInfo cea_info_table[] = {\n  {640, 480, 640*480*60*2},     // CEA640x480p60\n  {720, 480, 720*480*60*2},     // CEA720x480p60\n  {720, 480, 720*480*60},       // CEA720x480i60\n  {720, 576, 720*576*50*2},     // CEA720x576p50\n  {720, 576, 720*576*50},       // CEA720x576i50\n  {1280, 720, 1280*720*30*2},   // CEA1280x720p30\n  {1280, 720, 1280*720*60*2},   // CEA1280x720p60\n  {1920, 1080, 1920*1080*30*2}, // CEA1920x1080p30\n  {1920, 1080, 1920*1080*60*2}, // CEA1920x1080p60\n  {1920, 1080, 1920*1080*60},   // CEA1920x1080i60\n  {1280, 720, 1280*720*25*2},   // CEA1280x720p25\n  {1280, 720, 1280*720*50*2},   // CEA1280x720p50\n  {1920, 1080, 1920*1080*25*2}, // CEA1920x1080p25\n  {1920, 1080, 1920*1080*50*2}, // CEA1920x1080p50\n  {1920, 1080, 1920*1080*50},   // CEA1920x1080i50\n  {1280, 720, 1280*720*24*2},   // CEA1280x720p24\n  {1920, 1080, 1920*1080*24*2}  // CEA1920x1080p24\n};\n\n#define CEA_TABLE_LENGTH  sizeof(cea_info_table) / sizeof(QualityInfo)\n\nconst QualityInfo vesa_info_table[] = {\n  {800, 600, 800*600*30*2},        // VESA800x600p30\n  {800, 600, 800*600*60*2},        // VESA800x600p60\n  {1024, 768, 1024*768*30*2},      // VESA1024x768p30\n  {1024, 768, 1024*768*60*2},      // VESA1024x768p60\n  {1152, 864, 1152*864*30*2},      // VESA1152x864p30\n  {1152, 864, 1152*864*60*2},      // VESA1152x864p60\n  {1280, 768, 1280*768*30*2},      // VESA1280x768p30\n  {1280, 768, 1280*768*60*2},      // VESA1280x768p60\n  {1280, 800, 1280*800*30*2},      // VESA1280x800p30\n  {1280, 800, 1280*800*60*2},      // VESA1280x800p60\n  {1360, 768, 1360*768*30*2},      // VESA1360x768p30\n  {1360, 768, 1360*768*60*2},      // VESA1360x768p60\n  {1366, 768, 1366*768*30*2},      // VESA1366x768p30\n  {1366, 768, 1366*768*60*2},      // VESA1366x768p60\n  {1280, 1024, 1280*1024*30*2},    // VESA1280x1024p30\n  {1280, 1024, 1280*1024*60*2},    // VESA1280x1024p60\n  {1400, 1050, 1400*1050*30*2},    // VESA1400x1050p30\n  {1400, 1050, 1400*1050*60*2},    // VESA1400x1050p60\n  {1440, 900, 1440*900*30*2},      // VESA1440x900p30\n  {1440, 900, 1440*900*60*2},      // VESA1440x900p60\n  {1600, 900, 1600*900*30*2},      // VESA1600x900p30\n  {1600, 900, 1600*900*60*2},      // VESA1600x900p60\n  {1600, 1200, 1600*1200*30*2},    // VESA1600x1200p30\n  {1600, 1200, 1600*1200*60*2},    // VESA1600x1200p60\n  {1680, 1024, 1680*1024*30*2},    // VESA1680x1024p30\n  {1680, 1024, 1680*1024*60*2},    // VESA1680x1024p60\n  {1680, 1050, 1680*1050*30*2},    // VESA1680x1050p30\n  {1680, 1050, 1680*1050*60*2},    // VESA1680x1050p60\n  {1920, 1200, 1920*1200*30*2}     // VESA1920x1200p30\n};\n\n#define VESA_TABLE_LENGTH  sizeof(vesa_info_table) / sizeof(QualityInfo)\n\nconst QualityInfo hh_info_table[] = {\n  {800, 480, 800*480*30*2},         // HH800x480p30\n  {800, 480, 800*480*60*2},         // HH800x480p60\n  {854, 480, 854*480*30*2},         // HH854x480p30\n  {854, 480, 854*480*60*2},         // HH854x480p60\n  {864, 480, 864*480*30*2},         // HH864x480p30\n  {864, 480, 864*480*60*2},         // HH864x480p60\n  {640, 360, 640*360*30*2},         // HH640x360p30\n  {640, 360, 640*360*60*2},         // HH640x360p60\n  {960, 540, 960*540*30*2},         // HH960x540p30\n  {960, 540, 960*540*60*2},         // HH960x540p60\n  {848, 480, 848*480*30*2},         // HH848x480p30\n  {848, 480, 848*480*60*2}          // HH848x480p60\n};\n\n#define HH_TABLE_LENGTH  sizeof(hh_info_table) / sizeof(QualityInfo)\n\nQualityInfo get_cea_info(const H264VideoFormat& format) {\n  assert(format.rate_resolution < CEA_TABLE_LENGTH);\n  return cea_info_table[format.rate_resolution];\n}\n\nQualityInfo get_vesa_info(const H264VideoFormat& format) {\n  assert(format.rate_resolution < VESA_TABLE_LENGTH);\n  return vesa_info_table[format.rate_resolution];\n}\n\nQualityInfo get_hh_info(const H264VideoFormat& format) {\n  assert(format.rate_resolution < HH_TABLE_LENGTH);\n  return hh_info_table[format.rate_resolution];\n}\n\nQualityInfo get_quality_info(const H264VideoFormat& format) {\n  QualityInfo info;\n  switch (format.type) {\n  case CEA:\n    info = get_cea_info(format);\n    break;\n  case VESA:\n    info = get_vesa_info(format);\n    break;\n  case HH:\n    info = get_hh_info(format);\n    break;\n  default:\n    assert(false);\n    break;\n  }\n  return info;\n}\n\nstd::pair<unsigned, unsigned> get_resolution(const H264VideoFormat& format) {\n  QualityInfo info = get_quality_info(format);\n  return std::pair<unsigned, unsigned>(info.width, info.height);\n}\n\nbool video_format_sort_func(const H264VideoFormat& a, const H264VideoFormat& b) {\n  if (get_quality_info(a).weight != get_quality_info(b).weight)\n    return get_quality_info(a).weight < get_quality_info(b).weight;\n  if (a.profile != b.profile)\n    return a.profile < b.profile;\n  return a.level < b.level;\n}\n\ntemplate <typename RREnum>\nvoid PopulateVideoFormatList(\n    H264Profile profile,\n    H264Level level,\n    const RateAndResolutionsBitmap& bitmap,\n    RREnum max_value,\n    std::vector<H264VideoFormat>& formats) {\n  if (bitmap.none())\n    return;\n\n  for (RateAndResolution rr = 0; rr <= static_cast<RateAndResolution>(max_value); ++rr) {\n    if (bitmap.test(rr))\n      formats.push_back(H264VideoFormat(profile, level, static_cast<RREnum>(rr)));\n  }\n}\n\n}  // namespace\n\nvoid PopulateVideoFormatList(\n    const H264VideoCodec& codec, std::vector<H264VideoFormat>& formats) {\n  PopulateVideoFormatList<CEARatesAndResolutions>(\n      codec.profile, codec.level, codec.cea_rr, CEA1920x1080p24, formats);\n  PopulateVideoFormatList<VESARatesAndResolutions>(\n      codec.profile, codec.level, codec.vesa_rr, VESA1920x1200p30, formats);\n  PopulateVideoFormatList<HHRatesAndResolutions>(\n      codec.profile, codec.level, codec.hh_rr, HH848x480p60, formats);\n}\n\nH264VideoFormat FindOptimalVideoFormat(\n    const NativeVideoFormat& native,\n    const std::vector<H264VideoCodec>& local_codecs,\n    const std::vector<H264VideoCodec>& remote_codecs,\n    bool* success) {\n  std::vector<H264VideoFormat> local_formats, remote_formats;\n  for (const auto& codec : local_codecs)\n    PopulateVideoFormatList(codec, local_formats);\n  for (const auto& codec : remote_codecs)\n    PopulateVideoFormatList(codec, remote_formats);\n\n  std::sort(local_formats.begin(), local_formats.end(),\n      video_format_sort_func);\n  std::sort(remote_formats.begin(), remote_formats.end(),\n      video_format_sort_func);\n\n  auto it = local_formats.begin();\n  auto end = local_formats.end();\n\n  H264VideoFormat format;\n\n  while(it != end) {\n    auto match = std::find_if(\n        remote_formats.begin(),\n        remote_formats.end(),\n        [&it] (const H264VideoFormat& format) {\n            return ((*it).type == format.type) &&\n                   (get_resolution(*it) == get_resolution(format));\n        });\n\n    if (match != remote_formats.end()) {\n      format = *match;\n      break;\n    }\n    ++it;\n  }\n\n  // Should not happen, 640x480p60 should be always supported!\n  if (it == end) {\n    WDS_ERROR(\"Failed to find compatible video format.\");\n    if (success)\n      *success = false;\n    return format;\n  }\n\n  // if remote device supports higher codec profile / level\n  // downgrade them to what we support locally.\n  if (format.profile > (*it).profile)\n    format.profile = (*it).profile;\n  if (format.level > (*it).level)\n    format.level = (*it).level;\n  if (success)\n    *success = true;\n  return format;\n}\n\n}  // namespace wds\n"
  },
  {
    "path": "libwds/public/audio_codec.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_AUDIO_CODEC_H_\n#define LIBWDS_PUBLIC_AUDIO_CODEC_H_\n\n#include <bitset>\n\nnamespace wds {\n\nenum AudioFormats {\n  LPCM,\n  AAC,\n  AC3\n};\n\nenum LPCMModes {\n  LPCM_44_1K_16B_2CH,\n  LPCM_48K_16B_2CH\n};\n\nenum AACModes {\n  AAC_48K_16B_2CH,\n  AAC_48K_16B_4CH,\n  AAC_48K_16B_6CH,\n  AAC_48K_16B_8CH\n};\n\nenum AC3Modes {\n  AC3_48K_16B_2CH,\n  AC3_48K_16B_4CH,\n  AC3_48K_16B_6CH\n};\n\nusing AudioModes = std::bitset<32>;\n\n/**\n * @brief The AudioCodec struct\n *\n * Repersents a <audio-format, modes, latency> tuple used in 'wfd-audio-codecs'.\n */\nstruct AudioCodec {\n  AudioCodec()\n  : format(LPCM), modes(AudioModes().set(LPCM_48K_16B_2CH)), latency(0) {}\n  AudioCodec(AudioFormats format, const AudioModes& modes, unsigned latency)\n  : format(format), modes(modes), latency(latency) {}\n\n  AudioFormats format;\n  AudioModes modes;\n  unsigned latency;\n};\n\n}  // namespace wds\n\n#endif  // LIBWDS_PUBLIC_AUDIO_CODEC_H_\n"
  },
  {
    "path": "libwds/public/connector_type.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_CONNECTOR_TYPE_H_\n#define LIBWDS_PUBLIC_CONNECTOR_TYPE_H_\n\nnamespace wds {\n\nenum ConnectorType {\n  ConnectorTypeVGA = 0,\n  // TODO : Add the rest of connector types.\n  ConnectorTypeUndefined = 255,\n  ConnectorTypeNone\n};\n\n}  // namespace wds\n\n#endif  // LIBWDS_PUBLIC_CONNECTOR_TYPE_H_\n"
  },
  {
    "path": "libwds/public/logging.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_LOGGING_H_\n#define LIBWDS_PUBLIC_LOGGING_H_\n\n#include <cstdarg>\n\n#include \"wds_export.h\"\n\nnamespace wds {\n\n/**\n * WFD logging subsystem.\n */\nclass WDS_EXPORT LogSystem {\n public:\n  typedef void (*LogFunction)(const char*, ...);\n\n  /**\n   * Sets a function to log a normal message.\n   * @param function to log a normal message\n   */\n  static void set_log_func(LogFunction func);\n  /**\n   * Gets a function to log a normal message @see set_log_func\n   * @return function to log a normal message\n   */\n  static LogFunction log_func();\n\n  /**\n   * Sets a function to log a verbose message.\n   * @param function to log a verbose message\n   */\n  static void set_vlog_func(LogFunction func);\n  /**\n   * Gets a function to log a verbose message @see set_vlog_func\n   * @return function to log a verbose message\n   */\n  static LogFunction vlog_func();\n\n  /**\n   * Sets a function to log a warning message.\n   * @param function to log a warning message\n   */\n  static void set_warning_func(LogFunction func);\n  /**\n   * Gets a function to log a warning message @see set_warning_func\n   * @return function to log a warning message\n   */\n  static LogFunction warning_func();\n\n  /**\n   * Sets a function to log an error message.\n   * @param function to log an error message\n   */\n  static void set_error_func(LogFunction func);\n  /**\n   * Gets a function to log an error message @see set_error_func\n   * @return function to log an error message\n   */\n  static LogFunction error_func();\n\n private:\n  static LogFunction log_func_;\n  static LogFunction vlog_func_;\n  static LogFunction warning_func_;\n  static LogFunction error_func_;\n\n private:\n  LogSystem() = delete;\n};\n\n}\n\n#define WDS_LOG(...) (*wds::LogSystem::log_func())(__VA_ARGS__);\n#define WDS_VLOG(...) (*wds::LogSystem::vlog_func())(__VA_ARGS__);\n#define WDS_WARNING(...) (*wds::LogSystem::warning_func())(__VA_ARGS__);\n#define WDS_ERROR(...) (*wds::LogSystem::error_func())(__VA_ARGS__);\n\n#endif // LIBWDS_PUBLIC_LOGGING_H_\n"
  },
  {
    "path": "libwds/public/media_manager.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_MEDIA_MANAGER_H_\n#define LIBWDS_PUBLIC_MEDIA_MANAGER_H_\n\n#include <string>\n#include <vector>\n#include \"audio_codec.h\"\n#include \"connector_type.h\"\n#include \"video_format.h\"\n#include \"wds_export.h\"\n\nnamespace wds {\n\nenum SessionType {\n  AudioSession = 1,  // Audio only session\n  VideoSession = 1 << 1,  // Video only session\n  AudioVideoSession = AudioSession | VideoSession  // Audio/video session\n};\n\n/**\n * MediaManager interface.\n *\n * MediaManager instance is used by the state machine to control media stream\n * during WFD session.\n *\n * MediaManager contains the common methods for both WFD sink and WFD source.\n * The client applications are not supposed to implement it directly, they should\n * rather implement either @c SinkMediaManager or @c SourceMediaManager.\n * @see SinkMediaManager, SourceMediaManager\n */\nclass MediaManager {\n public:\n  virtual ~MediaManager() {}\n\n  /**\n   * Triggers playback of the media stream.\n   */\n  virtual void Play() = 0;\n\n  /**\n   * Pauses playback of the media stream.\n   */\n  virtual void Pause() = 0;\n\n  /**\n   * Destroys media stream.\n   */\n  virtual void Teardown() = 0;\n\n  /**\n   * Queries whether media stream is paused.\n   * @return true if media stream is paused, false otherwise.\n   */\n  virtual bool IsPaused() const = 0;\n\n  /**\n   * Returns unique WFD session id.\n   *\n   * The session Id is generated by WFD source.\n   *\n   * @return unique id for WFD session\n   */\n  virtual std::string GetSessionId() const = 0;\n};\n\n/**\n * SinkMediaManager interface.\n *\n * Extends the common @c MediaManager interface with WFD sink specific methods.\n * @see MediaManager\n */\nclass SinkMediaManager : public MediaManager {\n public:\n   ~SinkMediaManager() override { }\n\n  /**\n   * Returns RTP listening ports that are used by WFD sink to receive media streams.\n   *\n   * In case of coupled sink configuration video and audio data could be sent\n   * to different RTP ports.\n   *\n   * @return pair of RTP ports, port0 and port1\n   */\n  virtual std::pair<int,int> GetLocalRtpPorts() const = 0;\n\n  /**\n   * Sets presentation URL for media stream.\n   * Presentation URL can be referred in order to control media stream resource\n   * within WFD session.\n   *\n   * The implementation must store the given value and return it at GetPresentationUrl.\n   *\n   * @param presentation URL that represents video / audio stream\n   */\n  virtual void SetPresentationUrl(const std::string& url) = 0;\n\n  /**\n   * Returns presentation URL for managed media resource.\n   * @see SetPresentationUrl\n   * @return presentation URL\n   */\n  virtual std::string GetPresentationUrl() const = 0;\n\n  /**\n   * Sets unique ID for WFD session.\n   *\n   * The implementation must store the given value and return it at GetSessionId.\n   *\n   * @param string that uniquely identifies WFD session\n   */\n  virtual void SetSessionId(const std::string& session) = 0;\n\n  /**\n   * Returns list of supported H264 video formats\n   * @return vector of supported H264 video formats\n   */\n  virtual std::vector<H264VideoCodec> GetSupportedH264VideoCodecs() const = 0;\n\n  /**\n   * Returns native video format of a device\n   * @return native video format\n   */\n  virtual NativeVideoFormat GetNativeVideoFormat() const = 0;\n\n  /**\n   * Sets optimal H264 format that would be used to send / receive video stream\n   *\n   * @param optimal H264 format\n   * @return true if format can be used by media manager, false otherwise\n   */\n  virtual bool SetOptimalVideoFormat(const H264VideoFormat& optimal_format) = 0;\n\n  /**\n   * Returns active connector type of a device\n   * @return connector type. @see ConnectorType\n   */\n  virtual ConnectorType GetConnectorType() const = 0;\n};\n\n/**\n * SourceMediaManager interface.\n *\n * Extends the common @c MediaManager interface with WFD source specific methods.\n * @see MediaManager\n */\nclass SourceMediaManager : public MediaManager {\n public:\n   ~SourceMediaManager() override { }\n\n   /**\n    * Returns media type for the current session.\n    * @see MediaType\n    * @return media time.\n    */\n   virtual SessionType GetSessionType() const = 0;\n\n  /**\n   * Sets RTP ports used by WFD sink to receive media streams.\n   *\n   * In case of coupled sink configuration video and audio data could be sent\n   * to different RTP ports.\n   *\n   * WFD source must use these RTP ports for outgoing UDP connection.\n   *\n   * The implementation must store the given values and return them at GetSinkRtpPorts.\n   *\n   * @param port0 RTP port for video / audio stream\n   * @param port1 RTP port that could be used to send audio stream\n   */\n  virtual void SetSinkRtpPorts(int port1, int port2) = 0;\n\n  /**\n   * Returns RTP ports that are used by WFD sink to receive media streams.\n   * @see SetRtpPorts\n   * @return pair of RTP ports, port0 and port1\n   */\n  virtual std::pair<int,int> GetSinkRtpPorts() const = 0;\n\n  /**\n   * Returns the local WFD source RTP port transmitting the media stream.\n   * @return RTP port\n   */\n  virtual int GetLocalRtpPort() const = 0;\n\n  /**\n   * Initializes optimal video format\n   * The optimal video format will be returned by GetOptimalVideoFormat\n   *\n   * @param sink_native_format format of the sink device\n   * @param sink_supported_formats of H264 formats that are supported by the sink device\n   * @return true if optimal video format is successfully initialized, false otherwise\n   */\n  virtual bool InitOptimalVideoFormat(\n      const NativeVideoFormat& sink_native_format,\n      const std::vector<H264VideoCodec>& sink_supported_codecs) = 0;\n\n  /**\n   * Gets optimal H264 format @see InitOptimalVideoFormat\n   *\n   * @return optimal H264 format\n   */\n  virtual H264VideoFormat GetOptimalVideoFormat() const = 0;\n\n  /**\n   * Initializes optimal audio codec\n   * The optimal audio codec will be returned by GetOptimalAudioFormat\n   *\n   * @param sink_supported_codecs list of the codecs supported by sink\n   * @return true if optimal audio codec is successfully initialized, false otherwise\n   */\n  virtual bool InitOptimalAudioFormat(const std::vector<AudioCodec>& sink_supported_codecs) = 0;\n\n  /**\n   * Gets optimal audio codec @see InitOptimalAudioFormat\n   *\n   * @return optimal audio codec\n   */\n  virtual AudioCodec GetOptimalAudioFormat() const = 0;\n\n  /**\n   * Sends of H.264 instantaneous decoding refresh (IDR) picture\n   * to recover the content streaming.\n   */\n  virtual void SendIDRPicture() = 0;\n};\n\ninline SourceMediaManager* ToSourceMediaManager(MediaManager* mng) {\n  return static_cast<SourceMediaManager*>(mng);\n}\n\ninline SinkMediaManager* ToSinkMediaManager(MediaManager* mng) {\n  return static_cast<SinkMediaManager*>(mng);\n}\n\n}  // namespace wds\n\n#endif // LIBWDS_PUBLIC_MEDIA_MANAGER_H_\n\n"
  },
  {
    "path": "libwds/public/peer.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_PEER_H_\n#define LIBWDS_PUBLIC_PEER_H_\n\n#include <string>\n\n#include \"wds_export.h\"\n\nnamespace wds {\n\nenum ErrorType {\n  /// Arrived message cannot be handled by the state machine at the time.\n  UnexpectedMessageError,\n  /// RTSP message cannot be created form the given input.\n  MessageParseError,\n  /// The connected peer became unresponsive.\n  TimeoutError\n};\n\n\n/**\n * Peer interface.\n *\n * Peer is a base class for sink and source state machines.\n */\nclass WDS_EXPORT Peer {\n public:\n  /**\n   * Delegate interface.\n   *\n   * Implementation of Delegate interface is used by the state machine\n   * to obtain necessary context from the client.\n   */\n  class Delegate {\n   public:\n    /**\n     * The implementation should send the RTSP data over the network\n     * @param data data to be send\n     */\n    virtual void SendRTSPData(const std::string& data) = 0;\n    /**\n     * Returns the local IP address\n     * @return IP address\n     */\n    virtual std::string GetLocalIPAddress() const = 0;\n    /**\n     * The implementation should start a timer to be used by the state machine.\n     * @param seconds the time interval in seconds\n     * @return unique timer id within the session\n     */\n    virtual unsigned CreateTimer(int seconds) = 0;\n    /**\n     * The implementation should release timer by the given id.\n     * @param timer_id id of the timer to be released.\n     */\n    virtual void ReleaseTimer(unsigned timer_id) = 0;\n\n    /**\n     * Returns the sequence number for the following RTSP request-response pair\n     * @param initial_peer_cseq is provided for the WFD sink implementation at\n     * the first method's call during the WFD session and it contains the\n     * initial request sequence number obtained from the WFD source (the initial\n     * sequence numbers of connected peers may not be identical).\n     */\n    virtual int GetNextCSeq(int* initial_peer_cseq = nullptr) const = 0;\n\n   protected:\n    virtual ~Delegate() {}\n  };\n\n  /**\n   * Observer interface.\n   *\n   * This interface can be used by the client in order to get notifications\n   * from the state machine.\n   */\n  class Observer {\n   public:\n    /**\n     * This method is called by the state machine if an error has occurred.\n     * State machine is not reset.\n     *\n     * @param error type of the error\n     *\n     * @see ErrorType\n     */\n    virtual void ErrorOccurred(ErrorType error) {}\n    /**\n     * This method is called by the state machine if the session has been\n     * completed normally (with 'teardown' message).\n     * State machine is not reset.\n     */\n    virtual void SessionCompleted() {}\n\n   protected:\n    virtual ~Observer() {}\n  };\n\n  virtual ~Peer() {}\n\n  /**\n   * Starts wds state machine (source or sink)\n   */\n  virtual void Start() = 0;\n\n  /**\n   * Reset wds state machine (source or sink) to the initial state.\n   */\n  virtual void Reset() = 0;\n\n  /**\n   * Whenever RTSP data is received, this method should be called, so that\n   * the state machine could take action based on current state.\n   */\n  virtual void RTSPDataReceived(const std::string& data) = 0;\n\n  // Following methods:\n  // @see Teardown()\n  // @see Play()\n  // @see Pause()\n  // send M5 wfd_trigger_method messages for Peers that implement\n  // Source functionality or M7, M8 and M9 for Sink implementations\n\n  /**\n   * Sends RTSP teardown request.\n   * @return true if request can be sent, false otherwise.\n   */\n  virtual bool Teardown() = 0;\n\n  /**\n   * Sends RTSP play request.\n   * @return true if request can be sent, false otherwise.\n   */\n  virtual bool Play() = 0;\n\n  /**\n   * Sends RTSP pause request.\n   * @return true if request can be sent, false otherwise.\n   */\n  virtual bool Pause() = 0;\n\n  /**\n   * This method should be called by the client to notify the state\n   * machine about the timer events.\n   * @param timer_id id of the timer\n   * @return true if request can be sent, false otherwise.\n   *\n   * @see Delegate::CreateTimer()\n   */\n  virtual void OnTimerEvent(unsigned timer_id) = 0;\n};\n\n}\n\n#endif // LIBWDS_PUBLIC_PEER_H_\n"
  },
  {
    "path": "libwds/public/sink.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_SINK_H_\n#define LIBWDS_PUBLIC_SINK_H_\n\n#include \"peer.h\"\n\nnamespace wds {\n\nclass SinkMediaManager;\n\n/**\n * Sink state machine implementation\n */\nclass WDS_EXPORT Sink : public Peer {\n public:\n  virtual ~Sink() {}\n\n  /**\n   * Factory method that creates Sink state machine.\n   * @param delegate that is used for networking\n   * @param media manger that is used for media stream management\n   * @return newly created Sink instance\n   */\n  static Sink* Create(Peer::Delegate* delegate, SinkMediaManager* mng);\n};\n\n}\n\n#endif // LIBWDS_PUBLIC_SINK_H_\n"
  },
  {
    "path": "libwds/public/source.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_SOURCE_H_\n#define LIBWDS_PUBLIC_SOURCE_H_\n\n#include \"peer.h\"\n\nnamespace wds {\n\nclass SourceMediaManager;\n\n/**\n * Source state machine implementation\n */\nclass WDS_EXPORT Source : public Peer {\n public:\n  /**\n   * Factory method that creates Source state machine.\n   * @param delegate that is used for networking\n   * @param media manger that is used for media stream management\n   * @param observer\n   * @return newly created Source instance\n   */\n  static Source* Create(Peer::Delegate* delegate,\n                        SourceMediaManager* mng,\n                        Peer::Observer* observer = nullptr);\n};\n\n}\n\n#endif // LIBWDS_PUBLIC_SOURCE_H_\n"
  },
  {
    "path": "libwds/public/video_format.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_VIDEO_FORMAT_H_\n#define LIBWDS_PUBLIC_VIDEO_FORMAT_H_\n\n#include <bitset>\n#include <vector>\n\n#include \"wds_export.h\"\n\nnamespace wds {\n\nusing RateAndResolution = unsigned;\nusing RateAndResolutionsBitmap = std::bitset<32>;\n\n// NOTE : Do not change the elements order in the following enums!\n\nenum ResolutionType {\n  CEA,\n  VESA,\n  HH\n};\n\nenum CEARatesAndResolutions {\n  CEA640x480p60,\n  CEA720x480p60,\n  CEA720x480i60,\n  CEA720x576p50,\n  CEA720x576i50,\n  CEA1280x720p30,\n  CEA1280x720p60,\n  CEA1920x1080p30,\n  CEA1920x1080p60,\n  CEA1920x1080i60,\n  CEA1280x720p25,\n  CEA1280x720p50,\n  CEA1920x1080p25,\n  CEA1920x1080p50,\n  CEA1920x1080i50,\n  CEA1280x720p24,\n  CEA1920x1080p24\n};\n\nenum VESARatesAndResolutions {\n  VESA800x600p30,\n  VESA800x600p60,\n  VESA1024x768p30,\n  VESA1024x768p60,\n  VESA1152x864p30,\n  VESA1152x864p60,\n  VESA1280x768p30,\n  VESA1280x768p60,\n  VESA1280x800p30,\n  VESA1280x800p60,\n  VESA1360x768p30,\n  VESA1360x768p60,\n  VESA1366x768p30,\n  VESA1366x768p60,\n  VESA1280x1024p30,\n  VESA1280x1024p60,\n  VESA1400x1050p30,\n  VESA1400x1050p60,\n  VESA1440x900p30,\n  VESA1440x900p60,\n  VESA1600x900p30,\n  VESA1600x900p60,\n  VESA1600x1200p30,\n  VESA1600x1200p60,\n  VESA1680x1024p30,\n  VESA1680x1024p60,\n  VESA1680x1050p30,\n  VESA1680x1050p60,\n  VESA1920x1200p30\n};\n\nenum HHRatesAndResolutions {\n  HH800x480p30,\n  HH800x480p60,\n  HH854x480p30,\n  HH854x480p60,\n  HH864x480p30,\n  HH864x480p60,\n  HH640x360p30,\n  HH640x360p60,\n  HH960x540p30,\n  HH960x540p60,\n  HH848x480p30,\n  HH848x480p60\n};\n\nenum H264Profile {\n  CBP,\n  CHP\n};\n\nenum H264Level {\n  k3_1,\n  k3_2,\n  k4,\n  k4_1,\n  k4_2\n};\n\n\nstruct NativeVideoFormat {\n  NativeVideoFormat()\n  : type(CEA), rate_resolution(CEA640x480p60) {}\n  NativeVideoFormat(CEARatesAndResolutions rr)\n  : type(CEA), rate_resolution(rr) {}\n  NativeVideoFormat(VESARatesAndResolutions rr)\n  : type(VESA), rate_resolution(rr) {}\n  NativeVideoFormat(HHRatesAndResolutions rr)\n  : type(HH), rate_resolution(rr) {}\n\n  ResolutionType type;\n  RateAndResolution rate_resolution;\n};\n\n/**\n * A single video format that the source selects for streaming.\n *\n * H264VideoFormat is a H264 profile, H264 level, and a single CEA,\n * VESA or HH resolution. Sources are choosing the video format by matching what they\n * support to what the sink supports, and then they communicate the chosen format back\n * to the sink.\n */\nstruct H264VideoFormat {\n  H264VideoFormat()\n  : profile(CBP), level(k3_1), type(CEA), rate_resolution(CEA640x480p60) {}\n\n  H264VideoFormat(H264Profile profile, H264Level level, CEARatesAndResolutions rr)\n  : profile(profile), level(level), type(CEA), rate_resolution(rr) {}\n\n  H264VideoFormat(H264Profile profile, H264Level level, VESARatesAndResolutions rr)\n  : profile(profile), level(level), type(VESA), rate_resolution(rr) {}\n\n  H264VideoFormat(H264Profile profile, H264Level level, HHRatesAndResolutions rr)\n  : profile(profile), level(level), type(HH), rate_resolution(rr) {}\n\n  H264Profile profile;\n  H264Level level;\n  ResolutionType type;\n  RateAndResolution rate_resolution;\n};\n\n/**\n * Represents <profile, level, misc-params, max-hres, max-vres> tuple used in 'wfd-video-formats'.\n *\n * H264VideoCodec is a H264 profile, H264 level, and three sets of\n * CEA, VESA and HH resolutions. Sinks send one or several H264VideoCodec\n * to sources (for example because supported resolutions might\n * be different for CBP and CHP).\n */\nstruct H264VideoCodec {\n  H264VideoCodec()\n  : profile(CBP), level(k3_1), cea_rr(RateAndResolutionsBitmap().set(CEA640x480p60)) {}\n\n  H264VideoCodec(H264Profile profile, H264Level level,\n                  const RateAndResolutionsBitmap& cea,\n                  const RateAndResolutionsBitmap& vesa,\n                  const RateAndResolutionsBitmap& hh)\n  : profile(profile), level(level), cea_rr(cea), vesa_rr(vesa), hh_rr(hh) {}\n\n  H264Profile profile;\n  H264Level level;\n  RateAndResolutionsBitmap cea_rr;\n  RateAndResolutionsBitmap vesa_rr;\n  RateAndResolutionsBitmap hh_rr;\n};\n\n/**\n * An auxiliary function which populates list of @c H264VideoFormat\n * items from the given @c H264VideoCodec instance.\n *\n * @param codec the given @c H264VideoCodec instance.\n * @param formats resulting list of @c H264VideoFormat items\n */\nWDS_EXPORT void PopulateVideoFormatList(\n    const H264VideoCodec& codec,\n    std::vector<H264VideoFormat>& formats);\n\n/**\n * An auxiliary function to find the optimal format for streaming.\n * The quality selection algorithm will pick codec with higher bandwidth.\n *\n * @param native format of a remote device\n * @param local_codecs list of H264 codecs that are supported by local device\n * @param remote_codecs list of H264 codecs that are supported by remote device\n * @return optimal H264 video format\n */\nWDS_EXPORT H264VideoFormat FindOptimalVideoFormat(\n    const NativeVideoFormat& remote_native_format,\n    const std::vector<H264VideoCodec>& local_codecs,\n    const std::vector<H264VideoCodec>& remote_codecs,\n    bool* success = nullptr);\n\n}  // namespace wds\n\n#endif  // LIBWDS_PUBLIC_VIDEO_FORMAT_H_\n"
  },
  {
    "path": "libwds/public/wds_export.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_PUBLIC_WDS_EXPORT_H_\n#define LIBWDS_PUBLIC_WDS_EXPORT_H_\n\n#if defined _WIN32 || defined _WIN64\n  #define WDS_EXPORT __declspec(dllexport)\n#else\n  #define WDS_EXPORT __attribute__((visibility(\"default\")))\n#endif\n\n\n#endif  // LIBWDS_PUBLIC_WDS_EXPORT_H_\n"
  },
  {
    "path": "libwds/rtsp/CMakeLists.txt",
    "content": "#FIXME in the future: with cmake 2.8.12 and up it's better\n#to use target_compile_options or add_compile_options\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden -fPIC\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\n# Make directory for generated parser files\nset(PARSER_GEN_DIR \"${CMAKE_CURRENT_SOURCE_DIR}/gen\")\nfile(MAKE_DIRECTORY ${PARSER_GEN_DIR})\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\" \"${PARSER_GEN_DIR}\" )\n\nif (CMAKE_BUILD_TYPE STREQUAL \"Debug\")\n  set(PARSER_DEBUG_OPTIONS \"--debug -v\")\nendif (CMAKE_BUILD_TYPE STREQUAL \"Debug\")\n\nfind_package(BISON REQUIRED)\nBISON_TARGET(Parser parser.ypp ${PARSER_GEN_DIR}/parser.cpp COMPILE_FLAGS \"-l -p wds_ ${PARSER_DEBUG_OPTIONS}\")\n\nfind_package(FLEX REQUIRED)\nFLEX_TARGET(MessageLexer messagelexer.l ${PARSER_GEN_DIR}/messagescanner.cpp COMPILE_FLAGS \"-L -P message_ ${PARSER_DEBUG_OPTIONS}\")\nADD_FLEX_BISON_DEPENDENCY(MessageLexer Parser)\nFLEX_TARGET(HeaderLexer headerlexer.l ${PARSER_GEN_DIR}/headerscanner.cpp COMPILE_FLAGS \"-L -P header_ ${PARSER_DEBUG_OPTIONS}\")\nADD_FLEX_BISON_DEPENDENCY(HeaderLexer Parser)\nFLEX_TARGET(ErrorLexer errorlexer.l ${PARSER_GEN_DIR}/errorscanner.cpp COMPILE_FLAGS \"-L -P error_ ${PARSER_DEBUG_OPTIONS}\")\nADD_FLEX_BISON_DEPENDENCY(ErrorLexer Parser)\n\nadd_library(wdsrtsp OBJECT\n    ${BISON_Parser_OUTPUT_SOURCE}\n    ${FLEX_MessageLexer_OUTPUTS}\n    ${FLEX_ErrorLexer_OUTPUTS}\n    ${FLEX_HeaderLexer_OUTPUTS}\n    driver.cpp message.cpp header.cpp transportheader.cpp payload.cpp\n    options.cpp reply.cpp getparameter.cpp setparameter.cpp play.cpp\n    pause.cpp teardown.cpp setup.cpp property.cpp genericproperty.cpp\n    formats3d.cpp audiocodecs.cpp clientrtpports.cpp\n    contentprotection.cpp coupledsink.cpp displayedid.cpp\n    presentationurl.cpp route.cpp triggermethod.cpp\n    videoformats.cpp i2c.cpp avformatchangetiming.cpp uibcsetting.cpp\n    standbyresumecapability.cpp standby.cpp idrrequest.cpp connectortype.cpp\n    preferreddisplaymode.cpp uibccapability.cpp propertyerrors.cpp\n)\n"
  },
  {
    "path": "libwds/rtsp/audiocodecs.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/audiocodecs.h\"\n\n#include <assert.h>\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n\nstd::string ToString(const wds::AudioCodec& codec) {\n  MAKE_HEX_STRING_8(audio_modes_str,\n      static_cast<unsigned int>(codec.modes.to_ulong()));\n  MAKE_HEX_STRING_2(latency_str, codec.latency);\n  const char* const name[] = {\"LPCM\", \"AAC\", \"AC3\"};\n  std::string ret = name[codec.format]\n    + std::string(SPACE) + audio_modes_str\n    + std::string(SPACE) + latency_str;\n  return ret;\n}\n\n}\n\nAudioCodecs::AudioCodecs()\n  : Property(AudioCodecsPropertyType, true) {\n}\n\nAudioCodecs::AudioCodecs(const std::vector<wds::AudioCodec>& audio_codecs)\n  : Property(AudioCodecsPropertyType),\n    audio_codecs_(audio_codecs) {\n}\n\nAudioCodecs::~AudioCodecs() {\n}\n\nstd::string AudioCodecs::ToString() const {\n  std::string ret = PropertyName::wfd_audio_codecs + std::string(SEMICOLON)\n    + std::string(SPACE);\n\n  if (audio_codecs_.empty())\n    return ret + NONE;\n\n  auto it = audio_codecs_.begin();\n  auto end = audio_codecs_.end();\n  while (it != end) {\n    ret += wds::rtsp::ToString(*it);\n    ++it;\n    if (it != end)\n      ret += \", \";\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/audiocodecs.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_AUDIOCODECS_H_\n#define LIBWDS_RTSP_AUDIOCODECS_H_\n\n#include <vector>\n\n#include \"libwds/public/audio_codec.h\"\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass AudioCodecs: public Property {\n public:\n  AudioCodecs();\n  AudioCodecs(const std::vector<wds::AudioCodec>& audio_codecs);\n  ~AudioCodecs() override;\n\n  const std::vector<wds::AudioCodec>& audio_codecs() const { return audio_codecs_; }\n  std::string ToString() const override;\n\n private:\n  std::vector<AudioCodec> audio_codecs_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_AUDIOCODECS_H_\n"
  },
  {
    "path": "libwds/rtsp/avformatchangetiming.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/avformatchangetiming.h\"\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nAVFormatChangeTiming::AVFormatChangeTiming(unsigned long long int pts,\n    unsigned long long int dts)\n  : Property(AVFormatChangeTimingPropertyType),\n    pts_(pts),\n    dts_(dts) {\n\n}\n\nAVFormatChangeTiming::~AVFormatChangeTiming() {\n}\n\nstd::string AVFormatChangeTiming::ToString() const {\n  MAKE_HEX_STRING_10(pts, pts_);\n  MAKE_HEX_STRING_10(dts, dts_);\n  std::string ret =\n      PropertyName::wfd_av_format_change_timing + std::string(SEMICOLON)\n     + std::string(SPACE) + pts\n     + std::string(SPACE) + dts;\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/avformatchangetiming.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_AVFORMATCHANGETIMING_H_\n#define LIBWDS_RTSP_AVFORMATCHANGETIMING_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass AVFormatChangeTiming: public Property {\npublic:\n  AVFormatChangeTiming(unsigned long long int pts, unsigned long long int dts);\n  ~AVFormatChangeTiming() override;\n\n  unsigned long long int pts() const { return pts_; }\n  unsigned long long int dts() const { return dts_; }\n\n  std::string ToString() const override;\n\n private:\n  unsigned long long int pts_;\n  unsigned long long int dts_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_AVFORMATCHANGETIMING_H_\n"
  },
  {
    "path": "libwds/rtsp/clientrtpports.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/clientrtpports.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\nconst char profile[] = \"RTP/AVP/UDP;unicast\";\nconst char mode[] = \"mode=play\";\n}\n\nClientRtpPorts::ClientRtpPorts(unsigned short rtp_port_0,\n    unsigned short rtp_port_1)\n  : Property(ClientRTPPortsPropertyType),\n    rtp_port_0_(rtp_port_0),\n    rtp_port_1_(rtp_port_1) {\n}\n\nClientRtpPorts::~ClientRtpPorts() {\n}\n\nstd::string ClientRtpPorts::ToString() const {\n  return PropertyName::wfd_client_rtp_ports + std::string(SEMICOLON)\n    + std::string(SPACE) + profile\n    + std::string(SPACE) + std::to_string(rtp_port_0_)\n    + std::string(SPACE) + std::to_string(rtp_port_1_)\n    + std::string(SPACE) + mode;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/clientrtpports.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_CLIENTRTPPORTS_H_\n#define LIBWDS_RTSP_CLIENTRTPPORTS_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass ClientRtpPorts: public Property {\n public:\n  ClientRtpPorts(unsigned short rtp_port_0, unsigned short rtp_port_1);\n  ~ClientRtpPorts() override;\n\n  unsigned short rtp_port_0() const { return rtp_port_0_; }\n  unsigned short rtp_port_1() const { return rtp_port_1_; }\n  std::string ToString() const override;\n\n private:\n  unsigned short rtp_port_0_;\n  unsigned short rtp_port_1_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_CLIENTRTPPORTS_H_\n"
  },
  {
    "path": "libwds/rtsp/connectortype.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/connectortype.h\"\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nConnectorType::ConnectorType()\n  : Property(ConnectorTypePropertyType, true),\n    connector_type_() {\n}\n\nConnectorType::ConnectorType(unsigned char connector_type)\n  : Property(ConnectorTypePropertyType),\n    connector_type_(connector_type) {\n}\n\nConnectorType::ConnectorType(wds::ConnectorType connector_type)\n  : Property(ConnectorTypePropertyType, connector_type == wds::ConnectorTypeNone) {\n  connector_type_ = is_none() ? 0  // Ignored.\n                              : static_cast<unsigned char>(connector_type);\n}\n\nConnectorType::~ConnectorType() {\n}\n\nstd::string ConnectorType::ToString() const {\n  std::string ret = PropertyName::wfd_connector_type + std::string(SEMICOLON)\n    + std::string(SPACE);\n\n  if (is_none()) {\n    ret += NONE;\n  } else {\n    MAKE_HEX_STRING_2(connector_type, connector_type_);\n    ret += connector_type;\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/connectortype.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_CONNECTORTYPE_H_\n#define LIBWDS_RTSP_CONNECTORTYPE_H_\n\n#include \"libwds/public/connector_type.h\"\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass ConnectorType: public Property {\n public:\n  ConnectorType();\n  explicit ConnectorType(unsigned char connector_type);\n  explicit ConnectorType(wds::ConnectorType connector_type);\n  ~ConnectorType() override;\n\n  unsigned char connector_type() const { return connector_type_; }\n  std::string ToString() const override;\n\n private:\n  unsigned char connector_type_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n#endif  // LIBWDS_RTSP_CONNECTORTYPE_H_\n"
  },
  {
    "path": "libwds/rtsp/constants.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_CONSTANTS_H_\n#define LIBWDS_RTSP_CONSTANTS_H_\n\nnamespace wds {\nnamespace rtsp {\n\nconst char SEMICOLON[] = \":\";\nconst char SPACE[] = \" \";\nconst char NONE[] = \"none\";\nconst char CRLF[] = \"\\r\\n\";\nconst char RTSP_END[] = \"RTSP/1.0\";\n\nenum PropertyType {\n  AVFormatChangeTimingPropertyType,\n  AudioCodecsPropertyType,\n  ClientRTPPortsPropertyType,\n  ConnectorTypePropertyType,\n  ContentProtectionPropertyType,\n  CoupledSinkPropertyType,\n  DisplayEdidPropertyType,\n  GenericPropertyType,\n  I2CPropertyType,\n  IDRRequestPropertyType,\n  PreferredDisplayModePropertyType,\n  PresentationURLPropertyType,\n  RoutePropertyType,\n  StandbyPropertyType,\n  StandbyResumeCapabilityPropertyType,\n  TriggerMethodPropertyType,\n  UIBCCapabilityPropertyType,\n  UIBCSettingPropertyType,\n  Video3DFormatsPropertyType,\n  VideoFormatsPropertyType\n};\n\nnamespace PropertyName {\n  const char wfd_audio_codecs[] = \"wfd_audio_codecs\";\n  const char wfd_video_formats[] = \"wfd_video_formats\";\n  const char wfd_3d_video_formats[] = \"wfd_3d_video_formats\";\n  const char wfd_content_protection[] = \"wfd_content_protection\";\n  const char wfd_display_edid[] = \"wfd_display_edid\";\n  const char wfd_coupled_sink[] = \"wfd_coupled_sink\";\n  const char wfd_trigger_method[] = \"wfd_trigger_method\";\n  const char wfd_presentation_url[] = \"wfd_presentation_URL\";\n  const char wfd_client_rtp_ports[] = \"wfd_client_rtp_ports\";\n  const char wfd_route[] = \"wfd_route\";\n  const char wfd_I2C[] = \"wfd_I2C\";\n  const char wfd_av_format_change_timing[] = \"wfd_av_format_change_timing\";\n  const char wfd_preferred_display_mode[] = \"wfd_preferred_display_mode\";\n  const char wfd_uibc_capability[] = \"wfd_uibc_capability\";\n  const char wfd_uibc_setting[] = \"wfd_uibc_setting\";\n  const char wfd_standby_resume_capability[] = \"wfd_standby_resume_capability\";\n  const char wfd_standby[] = \"wfd_standby\";\n  const char wfd_connector_type[] = \"wfd_connector_type\";\n  const char wfd_idr_request[] = \"wfd_idr_request\";\n}  // namespace PropertyName\n\nenum Method {\n  OPTIONS,\n  SET_PARAMETER,\n  GET_PARAMETER,\n  SETUP,\n  PLAY,\n  TEARDOWN,\n  PAUSE,\n  ORG_WFA_WFD_1_0\n};\n\nnamespace MethodName {\n  const char OPTIONS[] = \"OPTIONS\";\n  const char SET_PARAMETER[] = \"SET_PARAMETER\";\n  const char GET_PARAMETER[] = \"GET_PARAMETER\";\n  const char SETUP[] = \"SETUP\";\n  const char PLAY[] = \"PLAY\";\n  const char TEARDOWN[] = \"TEARDOWN\";\n  const char PAUSE[] = \"PAUSE\";\n  const char ORG_WFA_WFD1_0[] = \"org.wfa.wfd1.0\";\n\n  const char* const name[] = { OPTIONS,\n                              SET_PARAMETER,\n                              GET_PARAMETER,\n                              SETUP,\n                              PLAY,\n                              TEARDOWN,\n                              PAUSE,\n                              ORG_WFA_WFD1_0 };\n}\n\nenum RTSPStatusCode {\n  STATUS_OK = 200,\n  STATUS_SeeOther = 303,\n  STATUS_NotAcceptable = 406,\n  STATUS_UnsupportedMediaType = 415,\n  STATUS_NotImplemented = 501\n};\n\n} // namespace rtsp\n} // namespace wds\n\n#endif // LIBWDS_RTSP_CONSTANTS_H_\n"
  },
  {
    "path": "libwds/rtsp/contentprotection.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/contentprotection.h\"\n\n#include <assert.h>\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n  const char* name[] = {\"HDCP2.0\", \"HDCP2.1\"};\n  const char port_prefix[] = \"port=\";\n}\n\nContentProtection::ContentProtection(HDCPSpec hdcp_spec, unsigned int port)\n  : Property (ContentProtectionPropertyType),\n    hdcp_spec_(hdcp_spec),\n    port_(port) {\n}\n\nContentProtection::ContentProtection(): Property (ContentProtectionPropertyType, true) {\n}\n\nContentProtection::~ContentProtection() {\n}\n\nContentProtection::HDCPSpec ContentProtection::hdcp_spec() const {\n  assert(hdcp_spec_ != HDCP_SPEC_2_0\n      || hdcp_spec_ != HDCP_SPEC_2_1);\n  return hdcp_spec_;\n}\n\nstd::string ContentProtection::ToString() const {\n  std::string ret =\n      PropertyName::wfd_content_protection\n    + std::string(SEMICOLON) + std::string(SPACE);\n\n  if (is_none())\n    ret += NONE;\n  else\n    ret += name[hdcp_spec()] + std::string(SPACE)\n        + port_prefix + std::to_string(port_);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/contentprotection.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_CONTENTPROTECTION_H_\n#define LIBWDS_RTSP_CONTENTPROTECTION_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass ContentProtection: public Property {\n public:\n  enum HDCPSpec {\n    HDCP_SPEC_2_0,\n    HDCP_SPEC_2_1\n  };\n\n public:\n  ContentProtection();\n  ContentProtection(HDCPSpec hdcp_spec, unsigned int port);\n  ~ContentProtection() override;\n\n  HDCPSpec hdcp_spec() const;\n  unsigned int port() const { return port_; }\n  std::string ToString() const override;\n\n private:\n  HDCPSpec hdcp_spec_;\n  unsigned int port_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_CONTENTPROTECTION_H_\n"
  },
  {
    "path": "libwds/rtsp/coupledsink.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/coupledsink.h\"\n\n#include <climits>\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nCoupledSink::CoupledSink(unsigned char status,\n    unsigned long long int sink_address)\n    : Property(CoupledSinkPropertyType),\n      status_(status),\n      sink_address_(sink_address) {\n}\n\nCoupledSink::CoupledSink(): Property(CoupledSinkPropertyType, true){\n}\n\nCoupledSink::~CoupledSink(){\n}\n\nstd::string CoupledSink::ToString() const {\n  std::string ret =\n      PropertyName::wfd_coupled_sink + std::string(SEMICOLON)\n    + std::string(SPACE);\n\n  if (is_none()) {\n    ret += NONE;\n  } else {\n    MAKE_HEX_STRING_2(status, status_);\n    ret += status + std::string(SPACE);\n\n    if (sink_address_ != ULLONG_MAX) {\n      MAKE_HEX_STRING_12(sink_address, sink_address_);\n      ret += sink_address;\n    } else {\n      ret += NONE;\n    }\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/coupledsink.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_COUPLEDSINK_H_\n#define LIBWDS_RTSP_COUPLEDSINK_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass CoupledSink: public Property {\n public:\n  CoupledSink();\n  CoupledSink(unsigned char status, unsigned long long int sink_address);\n  ~CoupledSink() override;\n\n  unsigned char status() const { return status_; }\n  unsigned long long int sink_address() const { return sink_address_; }\n  std::string ToString() const override;\n\n private:\n  unsigned short status_;\n  unsigned long long int sink_address_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_COUPLEDSINK_H_\n"
  },
  {
    "path": "libwds/rtsp/displayedid.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/displayedid.h\"\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nDisplayEdid::DisplayEdid(): Property(DisplayEdidPropertyType, true) {\n}\n\nDisplayEdid::DisplayEdid(unsigned short edid_block_count,\n    const std::string& edid_payload)\n  : Property(DisplayEdidPropertyType),\n    edid_block_count_(edid_block_count),\n    edid_payload_(edid_payload.length() ? edid_payload : NONE) {\n}\n\nDisplayEdid::~DisplayEdid() {\n}\n\nstd::string DisplayEdid::ToString() const {\n\n  std::string ret =\n      PropertyName::wfd_display_edid + std::string(SEMICOLON)\n    + std::string(SPACE);\n\n  if (is_none()) {\n    ret += NONE;\n  } else {\n    MAKE_HEX_STRING_2(edid_block_count, edid_block_count_);\n    ret += edid_block_count + std::string(SPACE) + edid_payload_;\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/displayedid.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_DISPLAYEDID_H_\n#define LIBWDS_RTSP_DISPLAYEDID_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass DisplayEdid: public Property {\n public:\n  DisplayEdid();\n  DisplayEdid(unsigned short edid_block_count, const std::string& edid_payload);\n  ~DisplayEdid() override;\n\n  unsigned short block_count() const { return edid_block_count_; }\n  const std::string& payload() const { return edid_payload_; }\n  std::string ToString() const override;\n\n private:\n  unsigned short edid_block_count_;\n  std::string edid_payload_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_DISPLAYEDID_H_\n"
  },
  {
    "path": "libwds/rtsp/driver.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/driver.h\"\n\n#include <cctype>\n#include <sstream>\n\n#include \"libwds/public/logging.h\"\n#include \"libwds/rtsp/message.h\"\n#include \"libwds/rtsp/reply.h\"\n\n#include \"errorscanner.h\"\n#include \"headerscanner.h\"\n#include \"messagescanner.h\"\n\nint wds_lex(YYSTYPE* yylval, void* scanner,\n    std::unique_ptr<wds::rtsp::Message>& message) {\n  if (!message) {\n    return header_lex(yylval, scanner);\n  } else if (message->is_reply()) {\n    wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n    if (reply->response_code() == wds::rtsp::STATUS_SeeOther)\n      return error_lex(yylval, scanner);\n\n    return message_lex(yylval, scanner);\n  }\n\n  return message_lex(yylval, scanner);\n}\n\nvoid wds_error(void* scanner, std::unique_ptr<wds::rtsp::Message>& message,\n    const char* error_message) {\n  WDS_ERROR(\"Parser error: %s\", error_message);\n  message.reset(nullptr);\n}\n\nnamespace wds {\nnamespace rtsp {\n\nvoid Driver::Parse(const std::string& input, std::unique_ptr<Message>& message) {\n  void* scanner = nullptr;\n#if YYDEBUG\n  bool enable_debug = true;\n  wds_debug = 1;\n#else\n  bool enable_debug = false;\n#endif\n\n  if (!message) {\n    header_lex_init(&scanner);\n    header_set_debug(enable_debug, scanner);\n    header__scan_string(input.c_str(), scanner);\n    wds_parse(scanner, message);\n    header_lex_destroy(scanner);\n  } else if (message->is_reply()) {\n    Reply* reply = static_cast<Reply*>(message.get());\n    if (reply->response_code() == STATUS_SeeOther) {\n      error_lex_init(&scanner);\n      error_set_debug(enable_debug, scanner);\n      error__scan_string(input.c_str(), scanner);\n      wds_parse(scanner, message);\n      error_lex_destroy(scanner);\n    } else {\n      message_lex_init(&scanner);\n      message_set_debug(enable_debug, scanner);\n      message_set_extra(message->is_reply(), scanner);\n      message__scan_string(input.c_str(), scanner);\n      wds_parse(scanner, message);\n      message_lex_destroy(scanner);\n    }\n  } else {\n    message_lex_init(&scanner);\n    message_set_debug(enable_debug, scanner);\n    message__scan_string(input.c_str(), scanner);\n    wds_parse(scanner, message);\n    message_lex_destroy(scanner);\n  }\n}\n\n} // namespace rtsp\n} // namespace wds\n\n"
  },
  {
    "path": "libwds/rtsp/driver.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_DRIVER_H_\n#define LIBWDS_RTSP_DRIVER_H_\n\n#include <string>\n#include <memory>\n\n#include \"parser.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Message;\n\nclass Driver {\n public:\n  static void Parse(const std::string& input, std::unique_ptr<Message>& message /*out*/);\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n// Required by bison.\nint wds_lex(YYSTYPE* yylval, void* scanner, std::unique_ptr<wds::rtsp::Message>& message);\nvoid wds_error (void* scanner, std::unique_ptr<wds::rtsp::Message>& message, const char* error_message);\n\n#endif  // LIBWDS_RTSP_DRIVER_H_\n"
  },
  {
    "path": "libwds/rtsp/errorlexer.l",
    "content": "%option nodefault nounput nomain\n%option bison-bridge reentrant noyywrap\n%option never-interactive\n%option warn stack noyy_top_state noyy_pop_state noyy_push_state\n%option case-insensitive\n%option extra-type=\"bool\"\n%option outfile=\"gen/errorscanner.cpp\" header-file=\"gen/errorscanner.h\"\n\n%top{\n/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <stdint.h>\n\n#define YY_NO_UNISTD_H 1\n}\n\n%{\n#include <string>\n\n#include \"parser.h\"\n\n#define yyterminate() return(END)\n%}\n\nDIGITS [0-9]+\nSP [ \\t]\nCR [\\r]\nLF [\\n]\nCRLF {CR}{LF}\n\n%%\n  /* skip these */\n{CRLF} { }\n{LF} { }\n{CR} { }\n\n /* Convert these */\n\",\"  { return ','; }\n\":\"  { return ':'; }\n\n{SP}+ return WFD_SP;\n\n^\"wfd_audio_codecs\" {\n    return WFD_AUDIO_CODECS_ERROR;\n  }\n\n^\"wfd_video_formats\" {\n    return WFD_VIDEO_FORMATS_ERROR;\n  }\n\n^\"wfd_3d_video_formats\" {\n    return WFD_3D_FORMATS_ERROR;\n  }\n\n^\"wfd_content_protection\" {\n    return WFD_CONTENT_PROTECTION_ERROR;\n  }\n\n^\"wfd_display_edid\" {\n    return WFD_DISPLAY_EDID_ERROR;\n  }\n\n^\"wfd_coupled_sink\" {\n    return WFD_COUPLED_SINK_ERROR;\n  }\n\n^\"wfd_trigger_method\" {\n    return WFD_TRIGGER_METHOD_ERROR;\n  }\n\n^\"wfd_presentation_url\" {\n    return WFD_PRESENTATION_URL_ERROR;\n  }\n\n^\"wfd_client_rtp_ports\" {\n    return WFD_CLIENT_RTP_PORTS_ERROR;\n  }\n\n^\"wfd_route\" {\n    return WFD_ROUTE_ERROR;\n  }\n\n^\"wfd_I2C\" {\n    return WFD_I2C_ERROR;\n  }\n\n^\"wfd_av_format_change_timing\" {\n    return WFD_AV_FORMAT_CHANGE_TIMING_ERROR;\n  }\n\n^\"wfd_preferred_display_mode\" {\n    return WFD_PREFERRED_DISPLAY_MODE_ERROR;\n  }\n\n^\"wfd_uibc_capability\" {\n    return WFD_UIBC_CAPABILITY_ERROR;\n  }\n\n^\"wfd_uibc_setting\" {\n    return WFD_UIBC_SETTING_ERROR;\n  }\n\n^\"wfd_standby_resume_capability\" {\n    return WFD_STANDBY_RESUME_CAPABILITY_ERROR;\n  }\n\n^\"wfd_standby\" {\n    return WFD_STANDBY_ERROR;\n  }\n\n^\"wfd_connector_type\" {\n    return WFD_CONNECTOR_TYPE_ERROR;\n  }\n\n^\"wfd_idr_request\" {\n    return WFD_IDR_REQUEST_ERROR;\n  }\n\n^[[:alpha:]][[:alnum:]\\-\\_]* {\n    yylval->sval = new std::string(yytext, yyleng);\n    return WFD_GENERIC_PROPERTY_ERROR;\n  }\n\n{DIGITS} {\n    std::string str(yytext, yyleng);\n    str += '\\0';\n    errno = 0;\n    yylval->nval = strtoull(str.c_str(), NULL, 10);\n    if (errno)\n      yyterminate();\n    return WFD_NUM;\n  }\n\n /* all unmatched */\n<*>. {}\n%%\n"
  },
  {
    "path": "libwds/rtsp/formats3d.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/formats3d.h\"\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nFormats3d::Formats3d() : Property(Video3DFormatsPropertyType, true) {\n}\n\nFormats3d::Formats3d(unsigned char native,\n    unsigned char preferred_display_mode,\n    const H264Codecs3d& h264_codecs_3d)\n  : Property(Video3DFormatsPropertyType),\n    native_(native),\n    preferred_display_mode_(preferred_display_mode),\n    h264_codecs_3d_(h264_codecs_3d) {\n}\n\nFormats3d::~Formats3d() {\n  // TODO Auto-generated destructor stub\n}\n\nstd::string H264Codec3d::ToString() const {\n  std::string ret;\n  MAKE_HEX_STRING_2(profile, profile_);\n  MAKE_HEX_STRING_2(level, level_);\n  MAKE_HEX_STRING_16(video_capability_3d, video_capability_3d_);\n  MAKE_HEX_STRING_2(latency,latency_);\n  MAKE_HEX_STRING_4(min_slice_size, min_slice_size_);\n  MAKE_HEX_STRING_4(slice_enc_params, slice_enc_params_);\n  MAKE_HEX_STRING_2(frame_rate_control_support, frame_rate_control_support_);\n\n  ret = profile + std::string(SPACE)\n      + level + std::string(SPACE)\n      + video_capability_3d + std::string(SPACE)\n      + latency + std::string(SPACE)\n      + min_slice_size + std::string(SPACE)\n      + slice_enc_params + std::string(SPACE)\n      + frame_rate_control_support + std::string(SPACE);\n\n  if (max_hres_ > 0) {\n    MAKE_HEX_STRING_4(max_hres, max_hres_);\n    ret += max_hres;\n  } else {\n    ret += NONE;\n  }\n  ret += std::string(SPACE);\n\n  if (max_vres_ > 0) {\n    MAKE_HEX_STRING_4(max_vres, max_vres_);\n    ret += max_vres;\n  } else {\n    ret += NONE;\n  }\n\n  return ret;\n}\n\nstd::string Formats3d::ToString() const {\n  std::string ret;\n\n  ret = PropertyName::wfd_3d_video_formats\n      + std::string(SEMICOLON)+ std::string(SPACE);\n\n  if (is_none())\n    return ret + NONE;\n\n  MAKE_HEX_STRING_2(native, native_);\n  MAKE_HEX_STRING_2(preferred_display_mode, preferred_display_mode_);\n\n  ret += native + std::string(SPACE)\n      + preferred_display_mode + std::string(SPACE);\n\n  auto it = h264_codecs_3d_.begin();\n  auto end = h264_codecs_3d_.end();\n  while(it != end) {\n    ret += (*it).ToString();\n    ++it;\n    if (it != end)\n      ret += \", \";\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/formats3d.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_FORMATS3D_H_\n#define LIBWDS_RTSP_FORMATS3D_H_\n\n#include \"libwds/rtsp/property.h\"\n\n#include <vector>\n\nnamespace wds {\nnamespace rtsp {\n\n// todo(shalamov): refactor, looks almost similar to VideoFormats\n\nstruct H264Codec3d {\n public:\n  H264Codec3d(unsigned char profile, unsigned char level,\n      unsigned long long int video_capability_3d, unsigned char latency,\n      unsigned short min_slice_size, unsigned short slice_enc_params,\n      unsigned char frame_rate_control_support,\n      unsigned short max_hres, unsigned short max_vres)\n    : profile_(profile),\n      level_(level),\n      video_capability_3d_(video_capability_3d),\n      latency_(latency),\n      min_slice_size_(min_slice_size),\n      slice_enc_params_(slice_enc_params),\n      frame_rate_control_support_(frame_rate_control_support),\n      max_hres_(max_hres),\n      max_vres_(max_vres) {}\n\n  std::string ToString() const;\n\n  unsigned char profile_;\n  unsigned char level_;\n  unsigned long long int video_capability_3d_;\n  unsigned char latency_;\n  unsigned short min_slice_size_;\n  unsigned short slice_enc_params_;\n  unsigned char frame_rate_control_support_;\n  unsigned short max_hres_;\n  unsigned short max_vres_;\n};\n\ntypedef std::vector<H264Codec3d> H264Codecs3d;\n\nclass Formats3d: public Property {\n public:\n  Formats3d();\n  Formats3d(unsigned char native,\n            unsigned char preferred_display_mode,\n            const H264Codecs3d& h264_codecs_3d);\n  ~Formats3d() override;\n\n  unsigned char native_resolution() const { return native_; }\n  unsigned char preferred_display_mode() const { return preferred_display_mode_;}\n  const H264Codecs3d& codecs() const { return h264_codecs_3d_; }\n\n  std::string ToString() const override;\n\n private:\n  unsigned char native_;\n  unsigned char preferred_display_mode_;\n  H264Codecs3d h264_codecs_3d_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_FORMATS3D_H_\n"
  },
  {
    "path": "libwds/rtsp/genericproperty.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include <string>\n\n#include \"libwds/rtsp/genericproperty.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nGenericProperty::GenericProperty() : Property(GenericPropertyType) {\n}\n\nGenericProperty::GenericProperty(const std::string& key, const std::string& value)\n  : Property(GenericPropertyType),\n    key_(key),\n    value_(value) {\n}\n\nGenericProperty::~GenericProperty() {\n}\n\nstd::string GenericProperty::ToString() const {\n  return key_ + \": \" + value_;\n}\n\nstd::string GenericProperty::GetName() const {\n  return key_;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/genericproperty.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_GENERIC_PROPERTY_H_\n#define LIBWDS_RTSP_GENERIC_PROPERTY_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass GenericProperty: public Property {\n public:\n  GenericProperty();\n  GenericProperty(const std::string& key, const std::string& value);\n\n  ~GenericProperty() override;\n\n  const std::string& key() const { return key_; }\n  const std::string& value() const { return value_; }\n\n  std::string ToString() const override;\n  std::string GetName() const override;\n\n private:\n  std::string key_;\n  std::string value_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_GENERIC_PROPERTY_H_\n"
  },
  {
    "path": "libwds/rtsp/getparameter.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/getparameter.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nGetParameter::GetParameter(const std::string& request_uri)\n : Request(Request::MethodGetParameter, request_uri) {\n}\n\nGetParameter::~GetParameter() {\n}\n\nstd::string GetParameter::ToString() const {\n  std::string ret = MethodName::GET_PARAMETER\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/getparameter.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_GETPARAMETER_H_\n#define LIBWDS_RTSP_GETPARAMETER_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass GetParameter : public Request {\n public:\n    explicit GetParameter(const std::string& request_uri);\n    ~GetParameter() override;\n    std::string ToString() const override;\n};\n\n} // namespace rtsp\n} // namespace wds\n\n#endif // LIBWDS_RTSP_GETPARAMETER_H_\n"
  },
  {
    "path": "libwds/rtsp/header.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/header.h\"\n\n#include <algorithm>\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n  const char kContentLenght[] = \"Content-Length: \";\n  const char kContentType[] = \"Content-Type: \";\n  const char kContentLength[] = \"Content-Length: \";\n  const char kCSeq[] = \"CSeq: \";\n  const char kSession[] = \"Session: \";\n  const char kTimeout[] = \";timeout=\";\n  const char kPublic[] = \"Public: \";\n  const char kRequire[] = \"Require: org.wfa.wfd1.0\";\n}\n\nHeader::Header() :\n    cseq_(0),\n    content_length_(0),\n    timeout_(0),\n    require_wfd_support_(false) {\n}\n\nHeader::~Header() {\n}\n\nint Header::cseq() const {\n  return cseq_;\n}\n\nvoid Header::set_cseq(int cseq) {\n  cseq_ = cseq;\n}\n\nint Header::content_length() const {\n  return content_length_;\n}\n\nvoid Header::set_content_length(int content_length) {\n  content_length_ = content_length;\n}\n\nconst std::string& Header::content_type() const {\n  return content_type_;\n}\n\nvoid Header::set_content_type(const std::string& content_type) {\n  content_type_ = content_type;\n}\n\nconst std::string& Header::session() const {\n    return session_;\n}\n\nvoid Header::set_session(const std::string& session) {\n    session_ = session;\n}\n\nunsigned int Header::timeout() const {\n    return timeout_;\n}\n\nvoid Header::set_timeout(int timeout) {\n    timeout_ = timeout;\n}\n\nTransportHeader& Header::transport() const {\n    if (!transport_)\n        transport_.reset(new TransportHeader());\n    return *transport_;\n}\n\nvoid Header::set_transport(TransportHeader* transport) {\n    transport_.reset(transport);\n}\n\nbool Header::require_wfd_support() const {\n  return require_wfd_support_;\n}\n\nvoid Header::set_require_wfd_support(bool require_wfd_support) {\n  require_wfd_support_ = require_wfd_support;\n}\n\nconst std::vector<Method>& Header::supported_methods() const {\n  return supported_methods_;\n}\n\nvoid Header::add_generic_header(const std::string& key ,const std::string& value) {\n    generic_headers_[key] = value;\n}\n\nconst GenericHeaderMap& Header::generic_headers() const {\n    return generic_headers_;\n}\n\nvoid Header::set_supported_methods(\n    const std::vector<Method>& supported_methods) {\n  supported_methods_ = supported_methods;\n}\n\nbool Header::has_method(const Method& method) const {\n  return std::find (supported_methods_.begin(),\n      supported_methods_.end(),\n      method) != supported_methods_.end();\n}\n\nstd::string Header::ToString() const {\n  std::string ret;\n\n  ret += kCSeq + std::to_string(cseq_) + CRLF;\n\n  if (!session_.empty()) {\n      if (timeout_ > 0)\n          ret += kSession + session_\n            + kTimeout + std::to_string(timeout_) + CRLF;\n      else\n          ret += kSession + session_ + CRLF;\n  }\n\n  if (content_type_.length())\n    ret += kContentType + content_type_ + CRLF;\n\n  if (content_length_)\n    ret += kContentLenght + std::to_string(content_length_) + CRLF;\n\n  ret += transport().ToString();\n\n  if (supported_methods_.size()) {\n    auto i = supported_methods_.begin();\n    auto end = supported_methods_.end();\n    ret += kPublic;\n    while (i != end) {\n      ret += MethodName::name[*i];\n      if (i != --supported_methods_.end()) {\n        ret += \", \";\n      }\n      ++i;\n    }\n    ret += CRLF;\n  }\n\n  if (require_wfd_support_)\n    ret += std::string(kRequire) + CRLF;\n\n  for (auto it = generic_headers_.begin(); it != generic_headers_.end(); it++)\n    ret += (*it).first + \": \" + (*it).second + CRLF;\n\n  return ret + CRLF;\n}\n\n} // namespace rtsp\n} // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/header.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_HEADER_H_\n#define LIBWDS_RTSP_HEADER_H_\n\n#include <string>\n#include <vector>\n#include <map>\n#include <memory>\n\n#include \"libwds/rtsp/constants.h\"\n#include \"libwds/rtsp/transportheader.h\"\n\ntypedef std::map<std::string, std::string> GenericHeaderMap;\n\nnamespace wds {\nnamespace rtsp {\n\nclass Header {\n  public:\n    Header();\n    virtual ~Header();\n\n    int cseq() const;\n    void set_cseq(int cseq);\n\n    int content_length() const;\n    void set_content_length(int content_length);\n\n    const std::string& content_type() const;\n    void set_content_type(const std::string& content_type);\n\n    const std::string& session() const;\n    void set_session(const std::string& session);\n\n    unsigned int timeout() const;\n    void set_timeout(int timeout);\n\n    TransportHeader& transport() const;\n    void set_transport(TransportHeader* transport);\n\n    bool require_wfd_support() const;\n    void set_require_wfd_support(bool require_wfd_support);\n\n    const std::vector<Method>& supported_methods() const;\n    void set_supported_methods(const std::vector<Method>& supported_methods);\n    bool has_method(const Method& method) const;\n\n    void add_generic_header(const std::string& key ,const std::string& value);\n    const GenericHeaderMap& generic_headers () const;\n\n    std::string ToString() const;\n\n private:\n    int cseq_;\n    int content_length_;\n    unsigned int timeout_;\n    std::string session_;\n    mutable std::unique_ptr<TransportHeader> transport_;\n    std::string content_type_;\n    bool require_wfd_support_;\n    std::vector<Method> supported_methods_;\n    GenericHeaderMap generic_headers_;\n};\n\n} // namespace rtsp\n} // namespace wds\n\n#endif // LIBWDS_RTSP_HEADER_H_\n"
  },
  {
    "path": "libwds/rtsp/headerlexer.l",
    "content": "%option nodefault nounput nomain\n%option bison-bridge reentrant noyywrap\n%option never-interactive\n%option warn stack noyy_top_state noyy_pop_state noyy_push_state\n%option case-insensitive\n%option extra-type=\"bool\"\n%option outfile=\"gen/headerscanner.cpp\" header-file=\"gen/headerscanner.h\"\n\n%top{\n/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <stdint.h>\n\n#define YY_NO_UNISTD_H 1\n}\n\n%{\n#include <string>\n\n#include \"parser.h\"\n#define yyterminate() return(END)\n%}\n\n%x MATCH_STRING_STATE\n%x MATCH_RESPONSE_CODE_STATE\n\n%s SUPPORTED_METHODS_STATE\n%s CONTENT_TYPE_STATE\n%s SESSION_STATE\n\nDIGIT [0-9]\nDIGITS [0-9]+\nHEXDIG [0-9a-fA-F]\nHEXDIGITS [0-9a-fA-F]+\nSP [ \\t]\nCR [\\r]\nLF [\\n]\nCRLF {CR}{LF}\n\n%%\n\n<*>{CRLF} { BEGIN(INITIAL); }\n<*>{LF} { BEGIN(INITIAL); }\n<*>{CR} { BEGIN(INITIAL); }\n\n /* Convert these */\n\"=\"  { return '='; }\n\"-\"  { return '-'; }\n\",\"  { return ','; }\n\"\\*\" { return '*'; }\n\";\"  { return ';'; }\n\":\"  { return ':'; }\n\"/\"  { return '/'; }\n\n{SP}+ return WFD_SP;\n\n\";timeout=\" return WFD_TIMEOUT;\n\";server_port=\" return WFD_SERVER_PORT;\n\n^(?-i:\"OPTIONS\") {\n    BEGIN(INITIAL);\n    return WFD_OPTIONS;\n  }\n\n^(?-i:\"SET_PARAMETER\") {\n    BEGIN(INITIAL);\n    return WFD_SET_PARAMETER;\n  }\n\n^(?-i:\"GET_PARAMETER\") {\n    BEGIN(INITIAL);\n    return WFD_GET_PARAMETER;\n  }\n\n^(?-i:\"SETUP\") {\n    BEGIN(INITIAL);\n    return WFD_SETUP;\n  }\n\n^(?-i:\"PLAY\") {\n    BEGIN(INITIAL);\n    return WFD_PLAY;\n  }\n\n^(?-i:\"TEARDOWN\") {\n    BEGIN(INITIAL);\n    return WFD_TEARDOWN;\n  }\n\n^(?-i:\"PAUSE\") {\n    BEGIN(INITIAL);\n    return WFD_PAUSE;\n  }\n\n  /* RTSP response, get reply code, RTSP/1.0 200 OK */\n^\"RTSP/\"{DIGIT}\".\"{DIGIT}{SP}+ {\n    BEGIN(MATCH_RESPONSE_CODE_STATE);\n    return WFD_RESPONSE;\n  }\n\n  /* CSeq: i */\n^\"CSeq:\" {\n    BEGIN(INITIAL);\n    return WFD_CSEQ;\n  }\n\n^\"Public:\" {\n    BEGIN(SUPPORTED_METHODS_STATE);\n    return WFD_RESPONSE_METHODS;\n  }\n\n^\"Require: org.wfa.wfd1.0\" {\n    return WFD_SUPPORT_CHECK;\n  }\n\n^\"Content-Type:\" {\n    BEGIN(CONTENT_TYPE_STATE);\n    return WFD_CONTENT_TYPE;\n  }\n\n^\"Content-Length:\" {\n    BEGIN(INITIAL);\n    return WFD_CONTENT_LENGTH;\n  }\n\n^\"Session:\" {\n    BEGIN(SESSION_STATE);\n    return WFD_SESSION;\n  }\n\n^\"Transport: RTP/AVP/UDP;unicast;client_port=\" {\n    return WFD_TRANSPORT;\n  }\n\n^[[:alpha:]][[:alnum:]\\-\\_]*\":\" {\n    BEGIN(MATCH_STRING_STATE);\n    yylval->sval = new std::string(yytext, yyleng - 1);\n    return WFD_HEADER;\n  }\n\n<SESSION_STATE>[^ ;\\t\\r\\n]+ {\n    BEGIN(INITIAL);\n    yylval->sval = new std::string(yytext, yyleng);\n    return WFD_SESSION_ID;\n  }\n\n<MATCH_RESPONSE_CODE_STATE>{DIGITS} {\n    BEGIN(MATCH_STRING_STATE);\n    yylval->nval = atoi(yytext);\n    return WFD_RESPONSE_CODE;\n  }\n\n<MATCH_STRING_STATE>[^ \\r\\n][^\\r\\n]+/\"\\r\\n\" {\n    BEGIN(INITIAL);\n    yylval->sval = new std::string(yytext);\n    return WFD_STRING;\n  }\n\n<SUPPORTED_METHODS_STATE>\"OPTIONS\" {\n    return WFD_OPTIONS;\n  }\n\n<SUPPORTED_METHODS_STATE>\"SET_PARAMETER\" {\n    return WFD_SET_PARAMETER;\n  }\n\n<SUPPORTED_METHODS_STATE>\"GET_PARAMETER\" {\n    return WFD_GET_PARAMETER;\n  }\n\n<SUPPORTED_METHODS_STATE>\"SETUP\" {\n    return WFD_SETUP;\n  }\n\n<SUPPORTED_METHODS_STATE>\"PLAY\" {\n    return WFD_PLAY;\n  }\n\n<SUPPORTED_METHODS_STATE>\"TEARDOWN\" {\n    return WFD_TEARDOWN;\n  }\n\n<SUPPORTED_METHODS_STATE>\"PAUSE\" {\n    return WFD_PAUSE;\n  }\n\n<SUPPORTED_METHODS_STATE>\"org.wfa.wfd1.0\" {\n  return WFD_TAG;\n  }\n\n<CONTENT_TYPE_STATE>[-[:alnum:]]+\\/[-[:alnum:]]+ {\n    BEGIN(INITIAL);\n    yylval->sval = new std::string(yytext);\n    return WFD_MIME;\n  }\n\n{DIGITS} {\n    std::string str(yytext, yyleng);\n    str += '\\0';\n    errno = 0;\n    yylval->nval = strtoull(str.c_str(), NULL, 10);\n    if (errno)\n      yyterminate();\n    return WFD_NUM;\n  }\n\n  /* RTSP request rule,  e.g., OPTIONS * RTSP/1.0 */\n\"RTSP/\"{DIGIT}\".\"{DIGIT} {\n    return WFD_END;\n  }\n\n  /* GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0 */\n\"rtsp://\"[^ \\t\\n]+ {\n    yylval->sval = new std::string(yytext);\n    return WFD_REQUEST_URI;\n  }\n\n /* all unmatched */\n<*>. {}\n%%\n"
  },
  {
    "path": "libwds/rtsp/i2c.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/i2c.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nI2C::I2C(int port) : Property(I2CPropertyType), port_(port) {\n}\n\nI2C::~I2C() {\n}\n\nstd::string I2C::ToString() const {\n  std::string ret = PropertyName::wfd_I2C + std::string(SEMICOLON)\n    + std::string(SPACE) + (is_supported() ? std::to_string(port()) : NONE);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/i2c.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_I2C_H_\n#define LIBWDS_RTSP_I2C_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass I2C: public Property {\n public:\n  explicit I2C(int port);\n  ~I2C() override;\n\n  bool is_supported() const { return port_ > 0; }\n  int port() const { return port_; }\n  std::string ToString() const override;\n\n private:\n  int port_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_I2C_H_\n"
  },
  {
    "path": "libwds/rtsp/idrrequest.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/idrrequest.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nIDRRequest::IDRRequest() : Property(IDRRequestPropertyType) {\n}\n\nIDRRequest::~IDRRequest() {\n}\n\nstd::string IDRRequest::ToString() const {\n  return std::string(\"wfd_idr_request\");\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/idrrequest.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_IDRREQUEST_H_\n#define LIBWDS_RTSP_IDRREQUEST_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass IDRRequest: public Property {\npublic:\n  IDRRequest();\n  ~IDRRequest() override;\n\n  std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_IDRREQUEST_H_\n"
  },
  {
    "path": "libwds/rtsp/macros.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_MACROS_H_\n#define LIBWDS_RTSP_MACROS_H_\n\n#include <stdio.h>\n\n#define MAKE_HEX_STRING_2(NAME, PROPERTY) \\\n  char NAME[3]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%02X\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_4(NAME, PROPERTY) \\\n  char NAME[5]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%04X\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_6(NAME, PROPERTY) \\\n  char NAME[7]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%06X\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_8(NAME, PROPERTY) \\\n  char NAME[9]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%08X\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_10(NAME, PROPERTY) \\\n  char NAME[11]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%010llX\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_12(NAME, PROPERTY) \\\n  char NAME[13]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%012llX\", PROPERTY) \\\n\n#define MAKE_HEX_STRING_16(NAME, PROPERTY) \\\n  char NAME[17]; \\\n  std::snprintf(NAME, sizeof(NAME), \"%016llX\", PROPERTY) \\\n\n#endif  // LIBWDS_RTSP_MACROS_H_\n\n"
  },
  {
    "path": "libwds/rtsp/message.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/message.h\"\n\n#include <cassert>\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n  const char kDefaultContentType[] = \"text/parameters\";\n}\n\nMessage::Message(Type type)\n  : type_(type) {\n}\n\nMessage::~Message() {\n}\n\nint Message::cseq() const {\n  assert(header_);\n  return header_->cseq();\n}\n\nHeader& Message::header() {\n  if (!header_)\n    header_.reset(new Header());\n  return *header_;\n}\n\nstd::string Message::ToString() const {\n  std::string ret;\n  if (payload_)\n    ret = payload_->ToString();\n\n  if (header_) {\n    header_->set_content_length (ret.length());\n    if(ret.length() > 0 && header_->content_type().length() == 0)\n        header_->set_content_type (kDefaultContentType);\n    ret = header_->ToString() + ret;\n  }\n\n  return ret;\n}\n\nRequest::Request(RTSPMethod method, const std::string& request_uri)\n  : Message(REQUEST),\n    id_(UNKNOWN),\n    method_(method),\n    request_uri_(request_uri) {\n}\n\nRequest::~Request() {\n}\n\n} // namespace rtsp\n} // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/message.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_MESSAGE_H_\n#define LIBWDS_RTSP_MESSAGE_H_\n\n#include <memory>\n\n#include \"libwds/rtsp/header.h\"\n#include \"libwds/rtsp/payload.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Message {\n public:\n  enum Type {\n    REQUEST,\n    REPLY\n  };\n\n  explicit Message(Type type);\n  virtual ~Message();\n\n  bool is_reply() const { return type_ == REPLY; }\n  bool is_request() const { return type_ == REQUEST; }\n\n  int cseq() const;\n\n  void set_header(std::unique_ptr<Header> header) {\n    header_ = std::move(header);\n  }\n\n  Header& header();\n\n  void set_payload(std::unique_ptr<Payload> payload) {\n    payload_ = std::move(payload);\n  }\n\n  Payload* payload() { return payload_.get(); }\n\n  virtual std::string ToString() const;\n\n protected:\n  std::unique_ptr<Header> header_;\n  std::unique_ptr<Payload> payload_;\n\n private:\n  Type type_;\n};\n\nclass Request : public Message {\n public:\n  enum ID {\n    UNKNOWN, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14,\n    M15, M16\n  };\n\n  enum RTSPMethod {\n    MethodOptions = 1,\n    MethodSetParameter,\n    MethodGetParameter,\n    MethodSetup,\n    MethodPlay,\n    MethodTeardown,\n    MethodPause\n  };\n\n  Request(RTSPMethod method, const std::string& request_uri = std::string());\n  ~Request() override;\n\n  const std::string& request_uri() const { return request_uri_; }\n  void set_request_uri(const std::string& request_uri) {\n    request_uri_ = request_uri;\n  }\n\n  ID id() const { return id_; }\n  void set_id(ID id) { id_ = id; }\n\n  RTSPMethod method() const { return method_; }\n  void set_method(RTSPMethod method) { method_ = method; }\n\n private:\n  ID id_;\n  RTSPMethod method_;\n  std::string request_uri_;\n};\n\ninline Request* ToRequest(Message* message) {\n  return static_cast<Request*>(message);\n}\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_MESSAGE_H_\n"
  },
  {
    "path": "libwds/rtsp/messagelexer.l",
    "content": "%option nodefault nounput nomain\n%option bison-bridge reentrant noyywrap\n%option never-interactive\n%option warn stack noyy_top_state noyy_pop_state noyy_push_state\n%option case-insensitive\n%option extra-type=\"bool\"\n%option outfile=\"gen/messagescanner.cpp\" header-file=\"gen/messagescanner.h\"\n\n%top{\n/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <stdint.h>\n\n#define YY_NO_UNISTD_H 1\n}\n\n%{\n#include <string>\n\n#include \"parser.h\"\n#define yyterminate() return(END)\n%}\n\n%x MATCH_STRING_STATE\n%x MATCH_RESPONSE_CODE_STATE\n\n%s SUPPORTED_METHODS_STATE\n%s CONTENT_TYPE_STATE\n%s SESSION_STATE\n%s MATCH_PRESENTATION_URL\n%s NUM_AS_HEX_MODE\n%s MATCH_EDID_STATE\n\nDIGIT [0-9]\nDIGITS [0-9]+\nHEXDIG [0-9a-fA-F]\nHEXDIGITS [0-9a-fA-F]+\nSP [ \\t]\nCR [\\r]\nLF [\\n]\nCRLF {CR}{LF}\nIPADDRESS (([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\nIPPORT [:]({DIGIT}){1,5}\n\n%%\n\n<*>{CRLF} { BEGIN(INITIAL); }\n<*>{LF} { BEGIN(INITIAL); }\n<*>{CR} { BEGIN(INITIAL); }\n\n /* Convert these */\n\"=\"  { return '='; }\n\"-\"  { return '-'; }\n\",\"  { return ','; }\n\"\\*\" { return '*'; }\n\";\"  { return ';'; }\n\":\"  { return ':'; }\n\"/\"  { return '/'; }\n\n{SP}+ return WFD_SP;\n\n\"none\" return WFD_NONE;\n\"LPCM\" return WFD_AUDIO_CODEC_LPCM;\n\"AAC\" return WFD_AUDIO_CODEC_AAC;\n\"AC3\" return WFD_AUDIO_CODEC_AC3;\n\"HDCP2.0\" return WFD_HDCP_SPEC_2_0;\n\"HDCP2.1\" return WFD_HDCP_SPEC_2_1;\n\"port=\" return WFD_IP_PORT;\n\"RTP/AVP/UDP;unicast\" return WFD_STREAM_PROFILE;\n\"mode=play\" return WFD_MODE_PLAY;\n\"primary\" return WFD_ROUTE_PRIMARY;\n\"secondary\" return WFD_ROUTE_SECONDARY;\n\"input_category_list=\" return WFD_INPUT_CATEGORY_LIST;\n\"GENERIC\" return WFD_INPUT_CATEGORY_GENERIC;\n\"HIDC\" return WFD_INPUT_CATEGORY_HIDC;\n\"generic_cap_list=\" return WFD_GENERIC_CAP_LIST;\n\"Keyboard\" return WFD_INPUT_TYPE_KEYBOARD;\n\"Mouse\" return WFD_INPUT_TYPE_MOUSE;\n\"SingleTouch\" return WFD_INPUT_TYPE_SINGLE_TOUCH;\n\"MultiTouch\" return WFD_INPUT_TYPE_MULTI_TOUCH;\n\"Joystick\" return WFD_INPUT_TYPE_JOYSTICK;\n\"Camera\" return WFD_INPUT_TYPE_CAMERA;\n\"Gesture\" return WFD_INPUT_TYPE_GESTURE;\n\"RemoteControl\" return WFD_INPUT_TYPE_REMOTE_CONTROL;\n\"hidc_cap_list=\" return WFD_HIDC_CAP_LIST;\n\"Infrared\" return WFD_INPUT_PATH_INFRARED;\n\"USB\" return WFD_INPUT_PATH_USB;\n\"BT\" return WFD_INPUT_PATH_BT;\n\"Wi-Fi\" return WFD_INPUT_PATH_WIFI;\n\"Zigbee\" return WFD_INPUT_PATH_ZIGBEE;\n\"No-SP\" return WFD_INPUT_PATH_NOSP;\n\"disable\" return WFD_UIBC_SETTING_DISABLE;\n\"enable\" return WFD_UIBC_SETTING_ENABLE;\n\"supported\" return WFD_SUPPORTED;\n\n<NUM_AS_HEX_MODE>{DIGITS} {\n    std::string str(yytext, yyleng);\n    str += '\\0';\n    errno = 0;\n    yylval->nval = strtoull(str.c_str(), NULL, 16);\n    if (errno)\n      yyterminate();\n    return WFD_NUM;\n  }\n\n<NUM_AS_HEX_MODE>{HEXDIGITS} {\n    std::string str(yytext, yyleng);\n    str += '\\0';\n    errno = 0;\n    yylval->nval = strtoull(str.c_str(), NULL, 16);\n    if (errno)\n      yyterminate();\n    return WFD_NUM;\n  }\n\n<MATCH_EDID_STATE>{DIGITS} {\n    yylval->sval = new std::string(yytext);\n    return WFD_STRING;\n  }\n\n<MATCH_EDID_STATE>{HEXDIGITS} {\n    yylval->sval = new std::string(yytext);\n    return WFD_STRING;\n  }\n\n^\"wfd_audio_codecs\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_AUDIO_CODECS;\n  }\n\n^\"wfd_video_formats\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_VIDEO_FORMATS;\n  }\n\n^\"wfd_3d_video_formats\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_3D_FORMATS;\n  }\n\n^\"wfd_content_protection\" {\n    return WFD_CONTENT_PROTECTION;\n  }\n\n^\"wfd_display_edid\" {\n    BEGIN(MATCH_EDID_STATE);\n    return WFD_DISPLAY_EDID;\n  }\n\n^\"wfd_coupled_sink\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_COUPLED_SINK;\n  }\n\n^\"wfd_trigger_method\" {\n    BEGIN(SUPPORTED_METHODS_STATE);\n    return WFD_TRIGGER_METHOD;\n  }\n\n^\"wfd_presentation_url\" {\n    BEGIN(MATCH_PRESENTATION_URL);\n    return WFD_PRESENTATION_URL;\n  }\n\n^\"wfd_client_rtp_ports\" {\n    return WFD_CLIENT_RTP_PORTS;\n  }\n\n^\"wfd_route\" {\n    return WFD_ROUTE;\n  }\n\n^\"wfd_I2C\" {\n    return WFD_I2C;\n  }\n\n^\"wfd_av_format_change_timing\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_AV_FORMAT_CHANGE_TIMING;\n  }\n\n^\"wfd_preferred_display_mode\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_PREFERRED_DISPLAY_MODE;\n  }\n\n^\"wfd_uibc_capability\" {\n    return WFD_UIBC_CAPABILITY;\n  }\n\n^\"wfd_uibc_setting\" {\n    return WFD_UIBC_SETTING;\n  }\n\n^\"wfd_standby_resume_capability\" {\n    return WFD_STANDBY_RESUME_CAPABILITY;\n  }\n\n^\"wfd_standby\" {\n    if (yyextra)  // Is reply.\n      return WFD_STANDBY_IN_RESPONSE;\n    return WFD_STANDBY_IN_REQUEST;\n  }\n\n^\"wfd_connector_type\" {\n    BEGIN(NUM_AS_HEX_MODE);\n    return WFD_CONNECTOR_TYPE;\n  }\n\n^\"wfd_idr_request\" {\n    return WFD_IDR_REQUEST;\n  }\n\n^[[:alpha:]][[:alnum:]\\-\\_]* {\n    BEGIN(MATCH_STRING_STATE);\n    yylval->sval = new std::string(yytext, yyleng);\n    return WFD_GENERIC_PROPERTY;\n  }\n\n{DIGITS} {\n    std::string str(yytext, yyleng);\n    str += '\\0';\n    errno = 0;\n    yylval->nval = strtoull(str.c_str(), NULL, 10);\n    if (errno)\n      yyterminate();\n    return WFD_NUM;\n  }\n\n<MATCH_STRING_STATE>[^ :\\r\\n][^\\r\\n]+/\"\\r\\n\" {\n    BEGIN(INITIAL);\n    yylval->sval = new std::string(yytext);\n    return WFD_STRING;\n  }\n\n<SUPPORTED_METHODS_STATE>\"OPTIONS\" {\n    return WFD_OPTIONS;\n  }\n\n<SUPPORTED_METHODS_STATE>\"SET_PARAMETER\" {\n    return WFD_SET_PARAMETER;\n  }\n\n<SUPPORTED_METHODS_STATE>\"GET_PARAMETER\" {\n    return WFD_GET_PARAMETER;\n  }\n\n<SUPPORTED_METHODS_STATE>\"SETUP\" {\n    return WFD_SETUP;\n  }\n\n<SUPPORTED_METHODS_STATE>\"PLAY\" {\n    return WFD_PLAY;\n  }\n\n<SUPPORTED_METHODS_STATE>\"TEARDOWN\" {\n    return WFD_TEARDOWN;\n  }\n\n<SUPPORTED_METHODS_STATE>\"PAUSE\" {\n    return WFD_PAUSE;\n  }\n     \n<SUPPORTED_METHODS_STATE>\"org.wfa.wfd1.0\" {\n  return WFD_TAG;\n  }\n\n<MATCH_PRESENTATION_URL>\"rtsp://\"{IPADDRESS}{IPPORT}?\"/wfd1.0/streamid=0\" {\n    yylval->sval = new std::string(yytext);\n    return WFD_PRESENTATION_URL_0;\n  }\n\n<MATCH_PRESENTATION_URL>\"rtsp://\"{IPADDRESS}{IPPORT}?\"/wfd1.0/streamid=1\" {\n    yylval->sval = new std::string(yytext);\n    return WFD_PRESENTATION_URL_1;\n  }\n\n /* all unmatched */\n<*>. {}\n%%\n"
  },
  {
    "path": "libwds/rtsp/messages_rules.txt",
    "content": "Rules and lexer\n\nDIGIT = %x30-39\nHEXDIG = DIGIT / %x41-46\nSP = %x20\nCR = %x0D\nLF = %x0A\nCRLF = CR LF\nIPADDRESS = 1*3(DIGIT) “.” 1*3(DIGIT) “.” 1*3(DIGIT) “.” 1*3(DIGIT)\nIPPORT = 1*5(DIGIT)\n\nRULE wfd-audio-codecs\n\nwfd-audio-codecs = “wfd_audio_codecs:” SP sink-audio-cap CRLF\nsink-audio-cap = “none” / sink-audio-list; “none” if not supported at a\nsink-audio-list = audio-format SP modes SP latency *(“,” SP sink-audio-list)\naudio-format = “LPCM” / “AAC” / “AC3”\nmodes = 8*8HEXDIG; see Table 5-21, Table 5-22 and Table 5-23\nlatency = 2*2HEXDIG; decoder latency in units of 5 msecs, see LPCM decoder latency field for LPCM, see AAC decoder latency field for AAC and see AC3 decoder latency field in Table 5-20 for more detail\n\nRULE wfd-video-formats\n\nwfd-video-formats = “wfd_video_formats:” SP sink-video-list CRLF\nsink-video-list = “none” / (native SP preferred-display-mode-supported SP H.264-codec);the Secondary Sink shall return “none”\nnative = 2*2HEXDIG; see Table 5-13\npreferred-display-mode-supported = 2*2HEXDIG; 0-not supported, 1-supported, 2-255 reserved\nH.264-codec = profile SP level SP misc-params SP max-hres SP max-vres *(“,” SP H.264-codec)\nprofile = 2*2HEXDIG; see Table 5-14, only one bit set\nlevel = 2*2HEXDIG; see Table 5-15, only one bit set\nmax-hres = “none” / (4*4HEXDIG); in M3 response and if preferred-display mode-supported is 0, then “none”. in M3 response and if preferred-display-mode- supported is 1, specifies the maximum horizontal resolution that the H.264 decoder supports in pixels. in M4 request, it is “none” and the recipient shall ignore this subparameter\nmax-vres = “none” / (4*4HEXDIG); in M3 response and if preferred-display mode-supported is 0, then “none”. in M3 response and if preferred-display-mode- supported is 1, specifies the maximum vertical resolution that the H.264 decoder supports in pixels. in M4 request, it is “none” and the recipient shall ignore this subparameter\nmisc-params = SP VESA-Support SP HH-Support SP latency SP min-slice-size SP slice-enc-params SP frame-rate-control-support CEA-Support\nCEA-Support = 8*8HEXDIG; see Table 5-10. when used inside preferred display mode in M4 request, this subfield should be set to 0x00000000 and the recipient shall ignore this subfield.\nVESA-Support = 8*8HEXDIG; see Table 5-11. when used inside preferred display mode in M4 request, this subfield should be set to 0x00000000 and the recipient shall ignore this subfield.\nHH-Support = 8*8HEXDIG; see Table 5-12. when used inside preferred display mode in M4 request, this subfield should be set to 0x00000000 and the recipient shall ignore this subfield.\nlatency = 2*2HEXDIG; decoder latency in units of 5 msecs, see latency field in Table 5-9 for more detail\nmin-slice-size = 4*4HEXDIG; number of macroblocks\nslice-enc-params = 4*4HEXDIG; see Table 5-16\nframe-rate-control-support = 2*2HEXDIG; see Table 5-17\n\nRULE wfd-3d-formats\n \nwfd-3d-formats = “wfd_3d_video_formats:” SP 3d-cap CRLF\n3d-cap = “none” / 3d-cap-list; if not supported then “none”\n3d-cap-list = native SP preferred-display-mode-supported SP H.264-codec\nnative = 2*2HEXDIG; see Table 5-13 preferred-display-mode-supported = 2*2HEXDIG; 0-not supported, 1-supported, 2-255 reserved\nH.264-codec = profile SP level SP misc-params SP max-hres SP max-vres * (“,” SP H.264-codec)\nprofile = 2*2HEXDIG; see Table 5-14, only one bit set\nlevel = 2*2HEXDIG; see Table 5-15, only one bit set\nmax-hres = “none” / (4*4HEXDIG); in M3 response and if preferred-display mode-supported is 0, then “none”. in M3 response and if preferred-display-mode-supported is 1, specifies the maximum horizontal resolution that the H.264 decoder supports in pixels. in M4 request, it is “none” and the recipient shall ignore this subparameter\nmax-vres = “none” / (4*4HEXDIG); in M3 response and if preferred-display mode-supported is 0, then “none”. in M3 response and if preferred-display-mode-supported is 1, specifies the maximum vertical resolution that the H.264 decoder supports in pixels. in M4 request, it is “none” and the recipient shall ignore this subparameter\nmisc-params = 3d-video-capability SP latency SP min-slice-size SP slice-enc-params SP frame-rate-control-support\n3d-video-capability= 16*16HEXDIG; see Table 5-19.\nlatency = 2*2HEXDIG; decoder latency in units of 5 msecs, see latency field in Table 5-9 for more detail\nmin-slice-size = 4*4HEXDIG; number of macroblocks\nslice-enc-params = 4*4HEXDIG; see Table 5-16\nframe-rate-control-support = 2*2HEXDIG; see Table 5-17\n\nRULE wfd-content-protection\n\nwfd-content-protection = “wfd_content_protection:” SP cp-spec CRLF\ncp-spec = “none” / hdcp2-spec\nhdcp2-spec = (“HDCP2.0” / “HDCP2.1”) SP “port=” IPPORT ;TCP port\n\nRULE wfd-display-edid\n\nwfd-display-edid = “wfd_display_edid:” SP edid CRLF\nedid = “none” / (edid-block-count SP edid-payload)\nedid-block-count = 4*4HEXDIG; 0: if EDID is not available at the time that the WFD Sink responses to the parameter request. 1-256: number of 128-byte EDID blocks in edid-payload Other values: reserved\nedid-payload = “none” / 256*65536HEXDIG; “none” if edid-block-count is 0. Otherwise, edid-payload contains the entire EDID data structure available from the display device. Length of edid-payload shall be a multiple of 128 bytes. (length of edid-payload = edid-block-count * 128-byte)\n\nRULE wfd-coupled-sink\n\nwfd-coupled-sink = “wfd_coupled_sink:” SP coupled-sink-cap CRLF\ncoupled-sink-cap = “none” /(status SP sink-address); “none” if Coupled Sink Operation is not supported\nstatus = 2*2HEXDIG; see Table 5-8\nsink-address = “none” / (12*12HEXDIG); WFD Sink’s MAC address if status is Coupled otherwise “none”.\n\nRULE wfd-trigger-method\n\nwfd-trigger-method = “wfd_trigger_method:” SP (“SETUP” / “PAUSE” / “TEARDOWN” / “PLAY”) CRLF\n\nRULE wfd-presentation-url\n\nwfd-presentation-url = “wfd_presentation_URL:” SP wfd-url0 SP wfd-url1 CRLF\nwfd-url0 = “none” / (“rtsp://” source-ip-address“/wfd1.0/streamid=0”)\nwfd-url1 = “none” / (“rtsp://” source-ip-address“/wfd1.0/streamid=1”)\nsource-ip-address = IPADDRESS\n\nRULE wfd-client-rtp-ports\n\nwfd-client-rtp-ports = “wfd_client_rtp_ports:” SP profile SP rtp-port0 SP rtp-port1 SP mode CRLF\nprofile = “RTP/AVP/UDP;unicast”\nrtp-port0 = IPPORT ; UDP port\nrtp-port1 = IPPORT ; UDP port\nmode = “mode=play”\n\nRULE wfd-route\n\nwfd-route = “wfd_route:” SP destination CRLF\ndestination = “primary” / “secondary”\n\nRULE wfd-I2C\n\nwfd-I2C = “wfd_I2C:” SP I2C-port CRLF\nI2C-port = “none” / IPPORT; port where the device listens for I2C commands, “none” if not supported\n\nRULE wfd-av-format-change-timing\n\nwfd-av-format-change-timing = “wfd_av_format_change_timing:” SP PTS SP DTS CRLF\nPTS = 10*10HEXDIG; most-significant 33 bits indicating PTS value\nDTS = 10*10HEXDIG; most-significant 33 bits indicating DTS value\n\nRULE wfd-preferred-display-mode\n\nwfd-preferred-display-mode = “wfd_preferred_display_mode:” SP dinfo CRLF\ndinfo = p-clock SP H SP HB SP HSPOL-HSOFF SP HSW SP V SP VB SP VSPOL-VSOFF SP VSW SP VBS3D SP 2d-s3d-modes SP p-depth SP H.264-codec\np-clock = 6*6HEXDIG; pixel clock in 10kHz units\nH = 4*4HEXDIG; horizontal active resolution in units of pixels\nHB = 4*4HEXDIG; horizontal blanking period in units of pixels\nHSPOL-HSOFF = 4*4HEXDIG; b15: horizontal sync polarity (0 negative, 1 positive) b14:b0 horizontal sync offset in units of pixels\nHSW = 4*4HEXDIG; horizontal sync width in units of pixels\nV = 4*4HEXDIG; vertical active resolution in units of lines\nVB = 4*4HEXDIG; vertical blanking period in units of lines\nVSPOL-VSOFF = 4*4HEXDIG; b15: vertical sync polarity (0 negative, 1 positive) b14:b0 vertical sync offset in units of lines\nVSW = 4*4HEXDIG; vertical sync width in units of lines\nVBS3D = 2*2HEXDIG; vertical blanking interval in units of lines (only used in stereoscopic 3D Frame Packing mode)\n2d-s3d-modes = 2*2HEXDIG; 2D/Stereoscopic 3D Modes (refer to Table 6-4)\nP-depth = 2*2HEXDIG; pixel depth (refer to Table 6-5). This is the pixel depth of the display output which is different from the codec pixel depth.\nH.264-codec = ; see section 6.1.3\n\nRULE wfd-uibc-capability\n\nwfd-uibc-capability = “wfd_uibc_capability:” SP (“none” / (input-category-val “;” generic-cap-val “;” hidc-cap-val “;” tcp-port)) CRLF; “none” if not supported\ninput-category-val = “input_category_list=” (“none” / input-category-list)\ninput-category-list = input-cat * (“,” SP input-category-list)\ninput-cat = “GENERIC” / “HIDC”\ngeneric-cap-val = “generic_cap_list=” (“none” / generic-cap-list)\ngeneric-cap-list = inp-type *(“,” SP generic-cap-list)\ninp-type = “Keyboard” / “Mouse” / “SingleTouch” / “MultiTouch” / “Joystick” / “Camera” / “Gesture” / “RemoteControl”\nhidc-cap-val = “hidc_cap_list=” (“none” / hidc-cap-list)\nhidc-cap-list = detailed-cap *(“,” SP hidc-cap-list)\ndetailed-cap = inp-type “/” inp-path\ninp-path = “Infrared” / “USB” / “BT” / “Zigbee” / “Wi-Fi” / “No-SP”\ntcp-port = “port=” (“none” / IPPORT)\n\nRULE wfd-uibc-setting\n\nwfd-uibc-setting = “wfd_uibc_setting:” SP uibc-setting CRLF\nuibc-setting = “disable” / “enable”\n\nRULE wfd-standby-resume-capability\n\nwfd-standby-resume-capability = “wfd_standby_resume_capability:” SP standby-resume-cap CRLF\nstandby-resume-cap = “none” / “supported”; “none” if not supported\n\nRULE wfd-standby\n\nwfd-standby = “wfd_standby” CRLF\n\nRULE wfd-connector-type\nwfd-connector-type = “wfd_connector_type:” SP connector-type CRLF\nconnector-type = “none” / (2*2HEXDIG); specifies the active display connector type (see Table 6-6), “none” if the WFD Sink dongle that is not acting as a WFD Sink with an integrated display is not connected to an external display\n\nRULE wfd-idr-request\nwfd-idr-request = “wfd_idr_request” CRLF\n\nRTSP Methods\nOPTIONS \norg.wfa.wfd1.0 \nSET_PARAMETER \nGET_PARAMETER \nSETUP \nPLAY \nTEARDOWN \nPAUSE  \n\nRULE RTSP SETUP\n\nTransport = “Transport:” SP profile port-numbers CRLF\nprofile = “RTP/AVP/UDP;unicast;”\nport-numbers = client-port [“;” server-port]; client-port only at M6 request message, (client-port “;” server- port) at M6 response message.\nclient-port = “client_port=” (rtp-port0 / rtp-port1) [“-” IPPORT]; rtp-port0 from a Primary Sink, rtp-port1 from a Secondary Sink. IPPORT here is rtp-port0 (or rtp-port1) plus 1 to be used for RTCP. [“-” IPPORT] can only appear in M6 request if the WFD Sink wants to use optional RTCP. [“-” IPPORT] can only appear in M6 response if the WFD Source accepts to use optional RTCP.\nserver-port = “server_port=” IPPORT [“-” IPPORT]; server’s UDP port number for RTP. Optional IPPORT is server’s UDP port number for RTP plus 1 to be used for optional RTCP. [“-” IPPORT] can only appear in M6 response if the WFD Source accepts to use optional RTCP.\n\n\n///////////////////////////////////////////////////////////////////////////////\n// Payload\n///////////////////////////////////////////////////////////////////////////////\n\nwfd-audio-codecs\nwfd-video-formats\nwfd-3d-formats\nwfd-content-protection\nwfd-display-edid\nwfd-coupled-sink\nwfd-trigger-method\nwfd-presentation-url\nwfd-client-rtp-ports\nwfd-route\n\nwfd-I2C\nwfd-av-format-change-timing\nwfd-preferred-display-mode\nwfd-uibc-capability\nwfd-uibc-setting\nwfd-standby-resume-capability\nwfd-standby\nwfd-connector-type\nwfd-idr-request\n\n///////////////////////////////////////////////////////////////////////////////\n// Messages\n///////////////////////////////////////////////////////////////////////////////\n\nM1 Request (src->snk)\n\nOPTIONS * RTSP/1.0\nCSeq: i\nRequire: org.wfa.wfd1.0\n\nM1 Response (snk->src)\n\nRTSP/1.0 200 OK\nCSeq: i\nDate: Sun, Aug 21 2011 04:20:53 GMT\nPublic: org.wfa.wfd1.0, GET_PARAMETER, SET_PARAMETER\n\n-------------------------------------------------------------------------------\n\nM2 Request (src->snk)\n\nOPTIONS * RTSP/1.0\nCSeq: j\nRequire: org.wfa.wfd1.0\n\nM2 Response (snk->src)\n\nRTSP/1.0 200 OK\nCSeq: j\nDate: Sun, Aug 21 2011 04:20:53 GMT\nPublic: org.wfa.wfd1.0, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\n\n-------------------------------------------------------------------------------\n\nM3 Request (src->snk)\n\nGET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: i+1\nContent-Type: text/parameters\nContent-Length: 141\n\nwfd_video_formats\nwfd_audio_codecs\nwfd_3d_video_formats\nwfd_content_protection\nwfd_display_edid\nwfd_coupled_sink\nwfd_client_rtp_ports\n\nM3 Response (snk->src)\n\nRTSP/1.0 200 OK\nCSeq: i+1\nContent-Length: 290\nContent-Type: text/parameters\n\nwfd_video_formats: 00 00 00 01 01 00000001 00000000 00000000 000000 0000 00 none none\nwfd_audio_codecs: LPCM 00000003 00\nwfd_3d_video_formats: none\nwfd_content_protection: none\nwfd_display_edid: none\nwfd_coupled_sink: none\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 1028 0 mode=play\n\n-------------------------------------------------------------------------------\n\nM4\n\n-------------------------------------------------------------------------------\n\nM5\n\n-------------------------------------------------------------------------------\n\nM6\n"
  },
  {
    "path": "libwds/rtsp/options.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/options.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nOptions::Options(const std::string& request_uri)\n  : Request(Request::MethodOptions, request_uri) {\n}\n\nOptions::~Options() {\n}\n\nstd::string Options::ToString() const {\n  std::string ret = MethodName::OPTIONS\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/options.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_OPTIONS_H_\n#define LIBWDS_RTSP_OPTIONS_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Options: public Request {\n  public:\n    explicit Options(const std::string& request_uri);\n    ~Options() override;\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_OPTIONS_H_\n"
  },
  {
    "path": "libwds/rtsp/parser.ypp",
    "content": "%pure-parser\n%no-lines\n%output \"gen/parser.cpp\"\n%defines \"gen/parser.h\"\n\n%code requires {\n/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n   #include <map>\n   #include <memory>\n   #include \"libwds/rtsp/audiocodecs.h\"\n   #include \"libwds/rtsp/contentprotection.h\"\n   #include \"libwds/rtsp/triggermethod.h\"\n   #include \"libwds/rtsp/route.h\"\n   #include \"libwds/rtsp/uibcsetting.h\"\n   #include \"libwds/rtsp/uibccapability.h\"\n   \n   #define YYLEX_PARAM scanner\n   \n   namespace wds {\n      struct AudioCodec;\n   namespace rtsp {\n      class Driver;\n      class Scanner;\n      class Message;\n      class Header;\n      class TransportHeader;\n      class Property;\n      class PropertyErrors;\n      class Payload;\n      class VideoFormats;\n      struct H264Codec;\n      struct H264Codec3d;\n   }\n   }\n}\n\n%lex-param {void* scanner} { std::unique_ptr<wds::rtsp::Message>& message }\n%parse-param {void* scanner} { std::unique_ptr<wds::rtsp::Message>& message }\n\n%code {\n#include <iostream>\n#include <cstdlib>\n#include <string>\n#include <vector>\n#include <map>\n\n#include \"libwds/rtsp/driver.h\"\n#include \"libwds/rtsp/message.h\"\n#include \"libwds/rtsp/header.h\"\n#include \"libwds/rtsp/transportheader.h\"\n#include \"libwds/rtsp/payload.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/options.h\"\n#include \"libwds/rtsp/getparameter.h\"\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/play.h\"\n#include \"libwds/rtsp/teardown.h\"\n#include \"libwds/rtsp/pause.h\"\n#include \"libwds/rtsp/setup.h\"\n#include \"libwds/rtsp/audiocodecs.h\"\n#include \"libwds/rtsp/videoformats.h\"\n#include \"libwds/rtsp/formats3d.h\"\n#include \"libwds/rtsp/contentprotection.h\"\n#include \"libwds/rtsp/displayedid.h\"\n#include \"libwds/rtsp/coupledsink.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/rtsp/clientrtpports.h\"\n#include \"libwds/rtsp/i2c.h\"\n#include \"libwds/rtsp/avformatchangetiming.h\"\n#include \"libwds/rtsp/standbyresumecapability.h\"\n#include \"libwds/rtsp/standby.h\"\n#include \"libwds/rtsp/idrrequest.h\"\n#include \"libwds/rtsp/connectortype.h\"\n#include \"libwds/rtsp/preferreddisplaymode.h\"\n#include \"libwds/rtsp/presentationurl.h\"\n#include \"libwds/rtsp/uibccapability.h\"\n\n#define UNUSED_TOKEN(T) (void)T\n#define DELETE_TOKEN(T) \\\n    delete T;           \\\n    T = nullptr\n}\n\n%union {\n   std::string* sval;\n   unsigned long long int nval;\n   bool bool_val;\n   std::vector<std::string>* vsval;\n   wds::rtsp::Message* message;\n   wds::rtsp::Header* header;\n   wds::rtsp::Payload* mpayload;\n   wds::AudioFormats audio_format;\n   wds::rtsp::Property* property;\n   std::vector<unsigned short>* error_list;\n   wds::rtsp::PropertyErrors* property_errors;\n   std::map<wds::rtsp::PropertyType, std::shared_ptr<wds::rtsp::PropertyErrors>>* property_error_map;\n   std::vector<wds::rtsp::H264Codec>* codecs;\n   wds::rtsp::H264Codec* codec;\n   std::vector<wds::rtsp::H264Codec3d>* codecs_3d;\n   wds::rtsp::H264Codec3d* codec_3d;\n   wds::rtsp::ContentProtection::HDCPSpec hdcp_spec;\n   wds::rtsp::TriggerMethod::Method trigger_method;\n   wds::rtsp::Route::Destination route_destination;\n   bool uibc_setting;\n   std::vector<wds::rtsp::UIBCCapability::InputCategory>* input_category_list;\n   std::vector<wds::rtsp::UIBCCapability::InputType>* generic_cap_list;\n   std::vector<wds::rtsp::UIBCCapability::DetailedCapability>* hidc_cap_list;\n   wds::rtsp::UIBCCapability::InputCategory input_category_list_value;\n   wds::rtsp::UIBCCapability::InputType generic_cap_list_value;\n   wds::rtsp::UIBCCapability::DetailedCapability* hidc_cap_list_value;\n   wds::rtsp::UIBCCapability::InputPath input_path;\n   wds::rtsp::Method method;\n   std::vector<wds::rtsp::Method>* methods;\n   wds::rtsp::PropertyType parameter;\n   std::vector<wds::rtsp::PropertyType>* parameters;\n   std::vector<wds::AudioCodec>* audio_codecs;\n   wds::AudioCodec* audio_codec;\n   std::pair<std::string, unsigned int>* session_info;\n   wds::rtsp::TransportHeader* transport;\n}\n\n%token END 0\n%token WFD_SP\n%token <nval> WFD_NUM\n%token WFD_OPTIONS\n%token WFD_SET_PARAMETER\n%token WFD_GET_PARAMETER\n%token WFD_SETUP\n%token WFD_PLAY\n%token WFD_TEARDOWN\n%token WFD_PAUSE\n%token WFD_END\n%token WFD_RESPONSE\n%token <nval> WFD_RESPONSE_CODE\n%token <sval> WFD_STRING\n%token <sval> WFD_GENERIC_PROPERTY\n%token <sval> WFD_HEADER\n%token WFD_CSEQ\n%token WFD_RESPONSE_METHODS\n%token WFD_TAG\n%token WFD_SUPPORT_CHECK\n%token <sval> WFD_REQUEST_URI\n%token WFD_CONTENT_TYPE\n%token <sval> WFD_MIME\n%token WFD_CONTENT_LENGTH\n%token WFD_AUDIO_CODECS\n%token WFD_VIDEO_FORMATS\n%token WFD_3D_FORMATS\n%token WFD_CONTENT_PROTECTION\n%token WFD_DISPLAY_EDID\n%token WFD_COUPLED_SINK\n%token WFD_TRIGGER_METHOD\n%token WFD_PRESENTATION_URL\n%token WFD_CLIENT_RTP_PORTS\n%token WFD_ROUTE\n%token WFD_I2C\n%token WFD_AV_FORMAT_CHANGE_TIMING\n%token WFD_PREFERRED_DISPLAY_MODE\n%token WFD_UIBC_CAPABILITY\n%token WFD_UIBC_SETTING\n%token WFD_STANDBY_RESUME_CAPABILITY\n%token WFD_STANDBY_IN_REQUEST\n%token WFD_STANDBY_IN_RESPONSE\n%token WFD_CONNECTOR_TYPE\n%token WFD_IDR_REQUEST\n%token WFD_AUDIO_CODECS_ERROR\n%token WFD_VIDEO_FORMATS_ERROR\n%token WFD_3D_FORMATS_ERROR\n%token WFD_CONTENT_PROTECTION_ERROR\n%token WFD_DISPLAY_EDID_ERROR\n%token WFD_COUPLED_SINK_ERROR\n%token WFD_TRIGGER_METHOD_ERROR\n%token WFD_PRESENTATION_URL_ERROR\n%token WFD_CLIENT_RTP_PORTS_ERROR\n%token WFD_ROUTE_ERROR\n%token WFD_I2C_ERROR\n%token WFD_AV_FORMAT_CHANGE_TIMING_ERROR\n%token WFD_PREFERRED_DISPLAY_MODE_ERROR\n%token WFD_UIBC_CAPABILITY_ERROR\n%token WFD_UIBC_SETTING_ERROR\n%token WFD_STANDBY_RESUME_CAPABILITY_ERROR\n%token WFD_STANDBY_ERROR\n%token WFD_CONNECTOR_TYPE_ERROR\n%token WFD_IDR_REQUEST_ERROR\n%token <sval> WFD_GENERIC_PROPERTY_ERROR\n%token WFD_NONE\n%token WFD_AUDIO_CODEC_LPCM\n%token WFD_AUDIO_CODEC_AAC\n%token WFD_AUDIO_CODEC_AC3\n%token WFD_HDCP_SPEC_2_0\n%token WFD_HDCP_SPEC_2_1\n%token <nval> WFD_IP_PORT\n%token <sval> WFD_PRESENTATION_URL_0\n%token <sval> WFD_PRESENTATION_URL_1\n%token WFD_STREAM_PROFILE\n%token WFD_MODE_PLAY\n%token WFD_ROUTE_PRIMARY\n%token WFD_ROUTE_SECONDARY\n%token WFD_INPUT_CATEGORY_LIST\n%token WFD_INPUT_CATEGORY_GENERIC\n%token WFD_INPUT_CATEGORY_HIDC\n%token WFD_GENERIC_CAP_LIST\n%token WFD_INPUT_TYPE_KEYBOARD\n%token WFD_INPUT_TYPE_MOUSE\n%token WFD_INPUT_TYPE_SINGLE_TOUCH\n%token WFD_INPUT_TYPE_MULTI_TOUCH\n%token WFD_INPUT_TYPE_JOYSTICK\n%token WFD_INPUT_TYPE_CAMERA\n%token WFD_INPUT_TYPE_GESTURE\n%token WFD_INPUT_TYPE_REMOTE_CONTROL\n%token WFD_HIDC_CAP_LIST\n%token WFD_INPUT_PATH_INFRARED\n%token WFD_INPUT_PATH_USB\n%token WFD_INPUT_PATH_BT\n%token WFD_INPUT_PATH_WIFI\n%token WFD_INPUT_PATH_ZIGBEE\n%token WFD_INPUT_PATH_NOSP\n%token WFD_UIBC_SETTING_ENABLE\n%token WFD_UIBC_SETTING_DISABLE\n%token WFD_SUPPORTED\n%token WFD_SESSION\n%token <sval> WFD_SESSION_ID\n%token WFD_TIMEOUT\n%token WFD_TRANSPORT\n%token WFD_SERVER_PORT\n\n%type <message> options set_parameter get_parameter setup play teardown pause\n%type <message> wfd_reply command\n%type <header> headers\n\n%type <sval> wfd_content_type\n%type <session_info> wfd_session\n%type <method> wfd_method\n%type <methods> wfd_methods wfd_supported_methods\n%type <nval> wfd_content_length\n%type <nval> wfd_cseq\n%type <audio_format> wfd_audio_codec_type\n%type <property> wfd_property wfd_property_audio_codecs\n%type <property> wfd_property_video_formats \n%type <property> wfd_property_3d_formats\n%type <property> wfd_content_protection\n%type <property> wfd_display_edid\n%type <property> wfd_coupled_sink\n%type <property> wfd_trigger_method\n%type <property> wfd_presentation_url\n%type <property> wfd_client_rtp_ports\n%type <property> wfd_route\n%type <property> wfd_I2C\n%type <property> wfd_av_format_change_timing\n%type <property> wfd_preferred_display_mode\n%type <property> wfd_uibc_capability\n%type <property> wfd_uibc_setting\n%type <property> wfd_standby_resume_capability\n%type <property> wfd_connector_type\n%type <mpayload> wdf_property_map\n%type <mpayload> wfd_property_error_map\n%type <property_errors> wfd_property_errors\n%type <error_list> wfd_error_list\n%type <mpayload> payload\n%type <codecs> wfd_h264_codecs\n%type <codec> wfd_h264_codec\n%type <nval> wfd_max_hres\n%type <nval> wfd_max_vres\n%type <codecs_3d> wfd_h264_codecs_3d\n%type <codec_3d> wfd_h264_codec_3d\n%type <hdcp_spec> hdcp2_spec\n%type <sval> wfd_edid_payload\n%type <nval> wfd_sink_address\n%type <trigger_method> wfd_supported_trigger_methods\n%type <route_destination> wfd_route_destination\n%type <nval> wfd_port\n%type <uibc_setting> wfd_uibc_setting_value\n%type <bool_val> wfd_standby_resume_capability_value\n%type <sval> wfd_presentation_url0 wfd_presentation_url1\n%type <input_category_list> wfd_input_category_list wfd_input_category_list_values\n%type <generic_cap_list> wfd_generic_cap_list wfd_generic_cap_list_values\n%type <hidc_cap_list> wfd_hidc_cap_list wfd_hidc_cap_list_values\n%type <input_category_list_value> wfd_input_category_list_value\n%type <generic_cap_list_value> wfd_generic_cap_list_value\n%type <hidc_cap_list_value> wfd_hidc_cap_list_value\n%type <input_path> wfd_input_path\n%type <parameter> wfd_parameter\n%type <mpayload> wfd_parameter_list\n%type <audio_codecs> wfd_audio_codec_list\n%type <audio_codec> wfd_audio_codec\n%type <transport> wfd_transport\n\n%destructor { DELETE_TOKEN($$); } WFD_STRING WFD_REQUEST_URI WFD_MIME WFD_GENERIC_PROPERTY\n%destructor { DELETE_TOKEN($$); } wfd_methods wfd_supported_methods\n%destructor { DELETE_TOKEN($$); } wfd_h264_codec wfd_h264_codecs\n%destructor { DELETE_TOKEN($$); } wfd_h264_codec_3d wfd_h264_codecs_3d\n%destructor { DELETE_TOKEN($$); } wfd_edid_payload\n%destructor { DELETE_TOKEN($$); } wfd_hidc_cap_list_value\n%destructor { DELETE_TOKEN($$); } wfd_parameter_list\n%destructor { DELETE_TOKEN($$); } wfd_audio_codec wfd_audio_codec_list\n\n%%\n\nstart: message\n  ;\n\nmessage:\n    command headers {\n      message.reset($1);\n      $1->set_header(std::unique_ptr<wds::rtsp::Header>($2));\n    }\n  | payload {\n      if (message && $1)\n        message->set_payload(std::unique_ptr<wds::rtsp::Payload>($1));\n      else\n        YYERROR;\n    }\n  | error {\n      message.reset();\n      std::cerr << \"Unknown message\" << std::endl;\n      YYABORT;\n    }\n  ;\n\ncommand:\n    options\n  | set_parameter\n  | get_parameter\n  | setup\n  | play\n  | teardown\n  | pause\n  | wfd_reply\n  ;\n\noptions:\n    WFD_OPTIONS WFD_SP '*' WFD_SP WFD_END {\n      $$ = new wds::rtsp::Options(\"*\");\n    }\n  | WFD_OPTIONS WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::Options(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nset_parameter:\n    WFD_SET_PARAMETER WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::SetParameter(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nget_parameter:\n    WFD_GET_PARAMETER WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::GetParameter(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nsetup:\n    WFD_SETUP WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::Setup(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nplay:\n    WFD_PLAY WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::Play(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nteardown:\n    WFD_TEARDOWN WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::Teardown(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\npause:\n    WFD_PAUSE WFD_SP WFD_REQUEST_URI WFD_SP WFD_END {\n      $$ = new wds::rtsp::Pause(*$3);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nwfd_reply:\n    WFD_RESPONSE WFD_RESPONSE_CODE WFD_STRING {\n      DELETE_TOKEN($3);\n      $$ = new wds::rtsp::Reply($2);\n    }\n  ;\n\nheaders:\n    {\n      $$ = new wds::rtsp::Header();\n    }\n  | headers wfd_cseq { $1->set_cseq($2); }\n  | headers WFD_SUPPORT_CHECK { $1->set_require_wfd_support(true); }\n  | headers wfd_content_type {\n          $1->set_content_type(*$2);\n          DELETE_TOKEN($2);\n      }\n  | headers wfd_content_length { $1->set_content_length($2); }\n  | headers wfd_supported_methods {\n          $1->set_supported_methods(*$2);\n          DELETE_TOKEN($2);\n      }\n  | headers wfd_session {\n      $1->set_session((*$2).first);\n      $1->set_timeout((*$2).second);\n      DELETE_TOKEN($2);\n    }\n  | headers wfd_transport { $1->set_transport ($2); }\n  | headers WFD_HEADER wfd_ows WFD_STRING {\n          $1->add_generic_header(*$2, *$4);\n          DELETE_TOKEN($2);\n          DELETE_TOKEN($4);\n      }\n  ;\n  \nwfd_cseq: \n    WFD_CSEQ wfd_ows WFD_NUM {\n      $$ = $3;\n    }\n  ;\n\nwfd_content_type:\n    WFD_CONTENT_TYPE wfd_ows WFD_MIME {\n      $$ = $3;\n    }\n  ;\n  \nwfd_content_length:\n    WFD_CONTENT_LENGTH wfd_ows WFD_NUM {\n      $$ = $3;\n    }\n  ;\n\nwfd_session:\n    WFD_SESSION WFD_SP WFD_SESSION_ID {\n      $$ = new std::pair<std::string, unsigned int>(*$3, 0);\n      DELETE_TOKEN($3);\n    }\n  | WFD_SESSION WFD_SP WFD_SESSION_ID WFD_TIMEOUT WFD_NUM {\n      $$ = new std::pair<std::string, unsigned int>(*$3, $5);\n      DELETE_TOKEN($3);\n    }\n  ;\n\nwfd_transport:\n    WFD_TRANSPORT WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n    }\n  | WFD_TRANSPORT WFD_NUM '-' WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n      $$->set_client_supports_rtcp (true);\n    }\n  | WFD_TRANSPORT WFD_NUM WFD_SERVER_PORT WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n      $$->set_server_port ($4);\n    }\n  | WFD_TRANSPORT WFD_NUM '-' WFD_NUM WFD_SERVER_PORT WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n      $$->set_client_supports_rtcp (true);\n      $$->set_server_port ($6);\n    }\n  | WFD_TRANSPORT WFD_NUM WFD_SERVER_PORT WFD_NUM '-' WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n      $$->set_server_port ($4);\n      $$->set_server_supports_rtcp (true);\n    }\n  | WFD_TRANSPORT WFD_NUM '-' WFD_NUM WFD_SERVER_PORT WFD_NUM '-' WFD_NUM {\n      $$ = new wds::rtsp::TransportHeader();\n      $$->set_client_port ($2);\n      $$->set_client_supports_rtcp (true);\n      $$->set_server_port ($6);\n      $$->set_server_supports_rtcp (true);\n    }\n  ;\n\nwfd_supported_methods:\n    WFD_RESPONSE_METHODS wfd_ows wfd_methods {\n     $$ = $3;\n    }\n  ;\n\nwfd_methods:\n    wfd_method {\n      $$ = new std::vector<wds::rtsp::Method>();\n      $$->push_back($1);\n    }\n  | wfd_methods wfd_ows ',' wfd_ows wfd_method {\n      UNUSED_TOKEN($$);\n      $1->push_back($5);\n    }\n  ;\n\nwfd_method: \n    WFD_OPTIONS { $$ = wds::rtsp::OPTIONS; }\n  | WFD_SET_PARAMETER { $$ = wds::rtsp::SET_PARAMETER; }\n  | WFD_GET_PARAMETER { $$ = wds::rtsp::GET_PARAMETER; }\n  | WFD_SETUP { $$ = wds::rtsp::SETUP; }\n  | WFD_PLAY { $$ = wds::rtsp::PLAY; }\n  | WFD_TEARDOWN { $$ = wds::rtsp::TEARDOWN; }\n  | WFD_PAUSE { $$ = wds::rtsp::PAUSE; }\n  | WFD_TAG { $$ = wds::rtsp::ORG_WFA_WFD_1_0; }\n  ;\n  \nwfd_ows: \n    /*blank*/\n  | WFD_SP\n  ;\n  \npayload: {\n    $$ = 0;\n    }\n  | wfd_parameter_list\n  | wdf_property_map\n  | wfd_property_error_map\n  ;\n\n  /* used for GET_PARAMETER method */\nwfd_parameter_list:\n    wfd_parameter_list wfd_parameter {\n      UNUSED_TOKEN($$);\n      if (auto payload = ToGetParameterPayload($1))\n        payload->AddRequestProperty($2);\n      else\n        YYERROR;\n    }\n  | wfd_parameter {\n      $$ = new wds::rtsp::GetParameterPayload();\n      wds::rtsp::ToGetParameterPayload($$)->AddRequestProperty($1);\n    }\n  | wfd_parameter_list WFD_GENERIC_PROPERTY {\n      UNUSED_TOKEN($$);\n      if (auto payload = ToGetParameterPayload($1))\n        payload->AddRequestProperty(*$2);\n      else\n        YYERROR;\n      DELETE_TOKEN($2);\n    }\n  | WFD_GENERIC_PROPERTY {\n      $$ = new wds::rtsp::GetParameterPayload();\n      wds::rtsp::ToGetParameterPayload($$)->AddRequestProperty(*$1);\n      DELETE_TOKEN($1);\n    }\n  ;\n\nwfd_parameter:\n    WFD_AUDIO_CODECS { $$ = wds::rtsp::AudioCodecsPropertyType; }\n  | WFD_VIDEO_FORMATS { $$ = wds::rtsp::VideoFormatsPropertyType; }\n  | WFD_3D_FORMATS { $$ = wds::rtsp::Video3DFormatsPropertyType; }\n  | WFD_CONTENT_PROTECTION { $$ = wds::rtsp::ContentProtectionPropertyType; }\n  | WFD_DISPLAY_EDID { $$ = wds::rtsp::DisplayEdidPropertyType; }\n  | WFD_COUPLED_SINK { $$ = wds::rtsp::CoupledSinkPropertyType; }\n  | WFD_TRIGGER_METHOD { $$ = wds::rtsp::TriggerMethodPropertyType; }\n  | WFD_PRESENTATION_URL { $$ = wds::rtsp::PresentationURLPropertyType; }\n  | WFD_CLIENT_RTP_PORTS { $$ = wds::rtsp::ClientRTPPortsPropertyType; }\n  | WFD_ROUTE { $$ = wds::rtsp::RoutePropertyType; }\n  | WFD_I2C { $$ = wds::rtsp::I2CPropertyType; }\n  | WFD_AV_FORMAT_CHANGE_TIMING { $$ = wds::rtsp::AVFormatChangeTimingPropertyType; }\n  | WFD_PREFERRED_DISPLAY_MODE { $$ = wds::rtsp::PreferredDisplayModePropertyType; }\n  | WFD_UIBC_CAPABILITY { $$ = wds::rtsp::UIBCCapabilityPropertyType; }\n  | WFD_UIBC_SETTING { $$ = wds::rtsp::UIBCSettingPropertyType; }\n  | WFD_STANDBY_RESUME_CAPABILITY { $$ = wds::rtsp::StandbyResumeCapabilityPropertyType; }\n  | WFD_STANDBY_IN_REQUEST { $$ = wds::rtsp::StandbyPropertyType; }\n  | WFD_CONNECTOR_TYPE { $$ = wds::rtsp::ConnectorTypePropertyType; }\n  ;\n\nwfd_error_list:\n    WFD_NUM {\n      $$ = new std::vector<unsigned short>();\n      $$->push_back($1);\n    }\n  | wfd_error_list ',' WFD_SP WFD_NUM {\n      $1->push_back($4);\n    }\n\nwfd_property_errors:\n    WFD_AUDIO_CODECS_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::AudioCodecsPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_VIDEO_FORMATS_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::VideoFormatsPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_3D_FORMATS_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::Video3DFormatsPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_CONTENT_PROTECTION_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::ContentProtectionPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_DISPLAY_EDID_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::DisplayEdidPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_COUPLED_SINK_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::CoupledSinkPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_TRIGGER_METHOD_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::TriggerMethodPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_PRESENTATION_URL_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::PresentationURLPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_CLIENT_RTP_PORTS_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::ClientRTPPortsPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_ROUTE_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::RoutePropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_I2C_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::I2CPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_AV_FORMAT_CHANGE_TIMING_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::AVFormatChangeTimingPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_PREFERRED_DISPLAY_MODE_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::PreferredDisplayModePropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_UIBC_CAPABILITY_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::UIBCCapabilityPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_UIBC_SETTING_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::UIBCSettingPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_STANDBY_RESUME_CAPABILITY_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::StandbyResumeCapabilityPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_CONNECTOR_TYPE_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::ConnectorTypePropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_IDR_REQUEST_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(wds::rtsp::IDRRequestPropertyType, *$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_GENERIC_PROPERTY_ERROR ':' WFD_SP wfd_error_list {\n      $$ = new wds::rtsp::PropertyErrors(*$1, *$4);\n      DELETE_TOKEN($1);\n      DELETE_TOKEN($4);\n    }\n  ;\n\nwfd_property_error_map:\n    wfd_property_errors {\n      $$ = new wds::rtsp::PropertyErrorPayload();\n      ToPropertyErrorPayload($$)->AddPropertyError(std::shared_ptr<wds::rtsp::PropertyErrors>($1));\n    }\n  | wfd_property_error_map wfd_property_errors {\n      if (auto payload = ToPropertyErrorPayload($1))\n        payload->AddPropertyError(std::shared_ptr<wds::rtsp::PropertyErrors>($2));\n      else\n        YYERROR;\n    }\n  ;\n\nwdf_property_map:\n    wfd_property {\n      $$ = new wds::rtsp::PropertyMapPayload();\n      ToPropertyMapPayload($$)->AddProperty(std::shared_ptr<wds::rtsp::Property>($1));\n    }\n  | wdf_property_map wfd_property {\n      if (auto payload = ToPropertyMapPayload($1))\n        payload->AddProperty(std::shared_ptr<wds::rtsp::Property>($2));\n      else\n        YYERROR;\n    } \n  ;\n\nwfd_property:\n    wfd_property_audio_codecs\n  | wfd_property_video_formats \n  | wfd_property_3d_formats\n  | wfd_content_protection\n  | wfd_display_edid\n  | wfd_coupled_sink\n  | wfd_trigger_method\n  | wfd_presentation_url\n  | wfd_client_rtp_ports\n  | wfd_route\n  | wfd_I2C\n  | wfd_av_format_change_timing\n  | wfd_preferred_display_mode\n  | wfd_uibc_capability\n  | wfd_uibc_setting\n  | wfd_standby_resume_capability\n  | wfd_connector_type\n  | WFD_STANDBY_IN_RESPONSE {\n      $$ = new wds::rtsp::Standby();\n    }\n  | WFD_IDR_REQUEST {\n      $$ = new wds::rtsp::IDRRequest();\n    }\n  | WFD_GENERIC_PROPERTY WFD_STRING {\n      $$ = new wds::rtsp::GenericProperty(*$1, *$2);\n      DELETE_TOKEN($1);\n      DELETE_TOKEN($2);\n    }\n  ;\n\nwfd_property_audio_codecs:\n    WFD_AUDIO_CODECS ':' WFD_SP wfd_audio_codec_list  {\n      $$ = new wds::rtsp::AudioCodecs(*$4);\n      DELETE_TOKEN($4);\n    }\n  | WFD_AUDIO_CODECS ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::AudioCodecs();\n    }\n  ;\n\nwfd_audio_codec_list:\n    wfd_audio_codec {\n      $$ = new std::vector<wds::AudioCodec>();\n      $$->push_back(*$1);\n      DELETE_TOKEN($1);\n    }\n  | wfd_audio_codec_list ',' WFD_SP wfd_audio_codec {\n      UNUSED_TOKEN($$);\n      $1->push_back(*$4);\n      DELETE_TOKEN($4);\n    }\n  ;\n\nwfd_audio_codec:\n  wfd_audio_codec_type WFD_SP WFD_NUM WFD_SP WFD_NUM {\n    $$ = new wds::AudioCodec($1, $3, $5);\n  }\n  ;\n\nwfd_audio_codec_type:\n    WFD_AUDIO_CODEC_LPCM { $$ = wds::LPCM; }\n  | WFD_AUDIO_CODEC_AAC { $$ = wds::AAC; }\n  | WFD_AUDIO_CODEC_AC3 { $$ = wds::AC3; }\n  ;\n\nwfd_property_video_formats:\n    WFD_VIDEO_FORMATS ':' wfd_ows WFD_NONE {\n      $$ = new wds::rtsp::VideoFormats();\n    }\n    /* native, preferred-display-mode-supported, H.264-codecs */\n  | WFD_VIDEO_FORMATS ':' wfd_ows WFD_NUM WFD_SP WFD_NUM WFD_SP wfd_h264_codecs {\n      $$ = new wds::rtsp::VideoFormats($4, $6, *$8);\n      DELETE_TOKEN($8);\n    }\n  ;\n\nwfd_h264_codecs:\n    wfd_h264_codec {\n      $$ = new wds::rtsp::H264Codecs();\n      $$->push_back(*$1);\n      DELETE_TOKEN($1);\n    }\n  | wfd_h264_codecs wfd_ows ',' wfd_ows wfd_h264_codec {\n      UNUSED_TOKEN($$);\n      $1->push_back(*$5);\n      DELETE_TOKEN($5);\n    }\n  ;\n\nwfd_h264_codec:\n    /* profile, level, misc-params , max-hres, max-vres */\n    WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP wfd_max_hres WFD_SP wfd_max_vres {\n      $$ = new wds::rtsp::H264Codec($1, $3, $5, $7, $9, $11, $13, $15, $17, $19, $21);\n    }\n\n\nwfd_h264_codecs_3d:\n    wfd_h264_codec_3d {\n      $$ = new wds::rtsp::H264Codecs3d();\n      $$->push_back(*$1);\n      DELETE_TOKEN($1);\n    }\n  | wfd_h264_codecs_3d wfd_ows ',' wfd_ows wfd_h264_codec_3d {\n      UNUSED_TOKEN($$);\n      $1->push_back(*$5);\n      DELETE_TOKEN($5);\n    }\n  ;\n\nwfd_h264_codec_3d:\n    WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP  wfd_max_hres WFD_SP wfd_max_vres {\n      $$ = new wds::rtsp::H264Codec3d($1, $3, $5, $7, $9, $11, $13, $15, $17);\n    }\n  ;\n\nwfd_max_hres:\n    WFD_NONE {\n      $$ = 0;\n    }\n  | WFD_NUM\n  ;\n  \nwfd_max_vres:\n    WFD_NONE {\n      $$ = 0;\n    }\n  | WFD_NUM\n  ;\n\nwfd_property_3d_formats:\n    /* native, preferred-display-mode-supported, H.264-codecs */\n    WFD_3D_FORMATS ':' WFD_SP  WFD_NUM WFD_SP WFD_NUM WFD_SP wfd_h264_codecs_3d {\n      $$ = new wds::rtsp::Formats3d($4, $6, *$8);\n      DELETE_TOKEN($8);\n    }\n  | WFD_3D_FORMATS ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::Formats3d();\n    }\n  ;\n\nwfd_content_protection:\n    WFD_CONTENT_PROTECTION ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::ContentProtection();\n    }\n  | WFD_CONTENT_PROTECTION ':' WFD_SP hdcp2_spec WFD_SP WFD_IP_PORT WFD_NUM {\n      $$ = new wds::rtsp::ContentProtection($4, $7);\n    }\n  ;\n\nhdcp2_spec:\n    WFD_HDCP_SPEC_2_0 {\n      $$ = wds::rtsp::ContentProtection::HDCP_SPEC_2_0;\n    }\n  | WFD_HDCP_SPEC_2_1 {\n      $$ = wds::rtsp::ContentProtection::HDCP_SPEC_2_1;\n    }\n  ;\n\nwfd_display_edid:\n    WFD_DISPLAY_EDID ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::DisplayEdid();\n    }\n  | WFD_DISPLAY_EDID ':' WFD_SP WFD_NUM WFD_SP wfd_edid_payload {\n      $$ = new wds::rtsp::DisplayEdid($4, $6 ? *$6 : \"\");\n      DELETE_TOKEN($6);\n    }\n  ;\n\nwfd_edid_payload:\n    WFD_NONE {\n      $$ = 0;\n    }\n  | WFD_STRING\n  ;\n  \nwfd_coupled_sink:\n    WFD_COUPLED_SINK ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::CoupledSink();\n    }\n  | WFD_COUPLED_SINK ':' WFD_SP WFD_NUM WFD_SP wfd_sink_address {\n      $$ = new wds::rtsp::CoupledSink($4, $6);\n    }\n  ;\n\nwfd_sink_address:\n    WFD_NONE {\n     $$ = -1;\n    }\n  | WFD_NUM\n  ; \n\nwfd_trigger_method:\n    WFD_TRIGGER_METHOD ':' WFD_SP wfd_supported_trigger_methods {\n      $$ = new wds::rtsp::TriggerMethod($4);\n    }\n  ;\n\nwfd_supported_trigger_methods:\n    WFD_SETUP {\n      $$ = wds::rtsp::TriggerMethod::SETUP;\n    }\n  | WFD_PAUSE{\n      $$ = wds::rtsp::TriggerMethod::PAUSE;\n    }\n  | WFD_TEARDOWN {\n      $$ = wds::rtsp::TriggerMethod::TEARDOWN;\n    }\n  | WFD_PLAY {\n      $$ = wds::rtsp::TriggerMethod::PLAY;\n    }\n  ;\n\nwfd_presentation_url:\n    WFD_PRESENTATION_URL ':' WFD_SP wfd_presentation_url0 WFD_SP wfd_presentation_url1 {\n      $$ = new wds::rtsp::PresentationUrl($4 ? *$4 : \"\", $6 ? *$6 : \"\");\n      DELETE_TOKEN($4);\n      DELETE_TOKEN($6);\n    }\n  ;\n \nwfd_presentation_url0:\n    WFD_NONE {\n      $$ = 0;\n    }\n  | WFD_PRESENTATION_URL_0\n  ;\n\nwfd_presentation_url1:\n    WFD_NONE {\n      $$ = 0;\n    }\n  | WFD_PRESENTATION_URL_1\n  ;\n\nwfd_client_rtp_ports:\n    WFD_CLIENT_RTP_PORTS ':' WFD_SP WFD_STREAM_PROFILE WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_MODE_PLAY {\n      $$ = new wds::rtsp::ClientRtpPorts($6, $8);\n  }\n\nwfd_route:\n    WFD_ROUTE ':' WFD_SP wfd_route_destination {\n      $$ = new wds::rtsp::Route($4);\n    }\n  ;\n\nwfd_route_destination:\n    WFD_ROUTE_PRIMARY {\n      $$ = wds::rtsp::Route::PRIMARY;\n    }\n  | WFD_ROUTE_SECONDARY {\n      $$ = wds::rtsp::Route::SECONDARY;\n    }\n  ;\n\nwfd_I2C:\n    WFD_I2C ':' WFD_SP wfd_port {\n      $$ = new wds::rtsp::I2C($4);\n    }\n  ;\n\nwfd_port:\n    WFD_NONE {\n      $$ = -1;\n    }\n  | WFD_NUM\n  ;\n\nwfd_av_format_change_timing:\n    WFD_AV_FORMAT_CHANGE_TIMING ':' WFD_SP WFD_NUM WFD_SP WFD_NUM {\n      $$ = new wds::rtsp::AVFormatChangeTiming($4, $6);\n    }\n  ;\n\nwfd_preferred_display_mode:\n    /* p-clock SP H SP HB SP HSPOL-HSOFF SP HSW SP V SP VB SP VSPOL-VSOFF SP VSW SP VBS3D SP 2d-s3d-modes SP p-depth SP H.264-codec */\n    WFD_PREFERRED_DISPLAY_MODE ':' WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP WFD_NUM WFD_SP wfd_h264_codec {\n      $$ = new wds::rtsp::PreferredDisplayMode($4, $6, $8, $10, $12, $14, $16, $18, $20, $22, $24, $26, *$28);\n      DELETE_TOKEN($28);\n    }\n  ;\n\nwfd_uibc_capability:\n    WFD_UIBC_CAPABILITY ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::UIBCCapability();\n    }\n  | WFD_UIBC_CAPABILITY ':' WFD_SP wfd_input_category_list ';' wfd_generic_cap_list ';' wfd_hidc_cap_list ';' WFD_IP_PORT wfd_port {\n      $$ = new wds::rtsp::UIBCCapability(*$4, *$6, *$8, $11);\n      DELETE_TOKEN($4);\n      DELETE_TOKEN($6);\n      DELETE_TOKEN($8);\n    }\n  ;\n\nwfd_input_category_list:\n    WFD_INPUT_CATEGORY_LIST wfd_input_category_list_values {\n      $$ = $2;\n    }\n  ;\n\nwfd_input_category_list_values:\n    WFD_NONE {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::InputCategory>();\n    }\n  | wfd_input_category_list_value {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::InputCategory>();\n      $$->push_back($1);\n    }\n  | wfd_input_category_list_values ',' WFD_SP wfd_input_category_list_value {\n      $1->push_back($4);\n    }\n  ; \n\nwfd_input_category_list_value:\n    WFD_INPUT_CATEGORY_GENERIC {\n      $$ = wds::rtsp::UIBCCapability::GENERIC;\n    }\n  | WFD_INPUT_CATEGORY_HIDC {\n      $$ = wds::rtsp::UIBCCapability::HIDC;\n    }\n  ;\n\nwfd_generic_cap_list:\n    WFD_GENERIC_CAP_LIST wfd_generic_cap_list_values {\n      $$ = $2;\n    }\n  ;\n  \nwfd_generic_cap_list_values:\n    WFD_NONE {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::InputType>();\n    }\n  | wfd_generic_cap_list_value {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::InputType>();\n      $$->push_back($1);\n    }\n  | wfd_generic_cap_list_values ',' WFD_SP wfd_generic_cap_list_value {\n      $1->push_back($4);\n    }\n  ;\n\nwfd_generic_cap_list_value:\n    WFD_INPUT_TYPE_KEYBOARD {\n      $$ = wds::rtsp::UIBCCapability::KEYBOARD;\n    }\n  | WFD_INPUT_TYPE_MOUSE {\n      $$ = wds::rtsp::UIBCCapability::MOUSE;\n    }\n  | WFD_INPUT_TYPE_SINGLE_TOUCH {\n      $$ = wds::rtsp::UIBCCapability::SINGLE_TOUCH;\n    }\n  | WFD_INPUT_TYPE_MULTI_TOUCH {\n      $$ = wds::rtsp::UIBCCapability::MULTI_TOUCH;\n    }\n  | WFD_INPUT_TYPE_JOYSTICK {\n      $$ = wds::rtsp::UIBCCapability::JOYSTICK;\n    }\n  | WFD_INPUT_TYPE_CAMERA {\n      $$ = wds::rtsp::UIBCCapability::CAMERA;\n    }\n  | WFD_INPUT_TYPE_GESTURE {\n      $$ = wds::rtsp::UIBCCapability::GESTURE;\n    }\n  | WFD_INPUT_TYPE_REMOTE_CONTROL {\n      $$ = wds::rtsp::UIBCCapability::REMOTE_CONTROL;\n    }\n  ;\n\nwfd_hidc_cap_list:\n    WFD_HIDC_CAP_LIST wfd_hidc_cap_list_values {\n      $$ = $2;\n    }\n  ;\n  \nwfd_hidc_cap_list_values:\n    WFD_NONE {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::DetailedCapability>();\n    }\n  | wfd_hidc_cap_list_value {\n      $$ = new std::vector<wds::rtsp::UIBCCapability::DetailedCapability>();\n      $$->push_back(*$1);\n      DELETE_TOKEN($1);\n    }\n  | wfd_hidc_cap_list_values ',' WFD_SP wfd_hidc_cap_list_value {\n      $1->push_back(*$4);\n      DELETE_TOKEN($4);\n    }\n  ;\n\nwfd_hidc_cap_list_value:\n    wfd_generic_cap_list_value '/' wfd_input_path {\n      $$ = new wds::rtsp::UIBCCapability::DetailedCapability($1, $3);\n    }\n  ;\n\n\nwfd_input_path:\n    WFD_INPUT_PATH_INFRARED {\n      $$ = wds::rtsp::UIBCCapability::INFRARED;\n    }\n  | WFD_INPUT_PATH_USB {\n      $$ = wds::rtsp::UIBCCapability::USB;\n    }\n  | WFD_INPUT_PATH_BT {\n      $$ = wds::rtsp::UIBCCapability::BT;\n    }\n  | WFD_INPUT_PATH_ZIGBEE {\n      $$ = wds::rtsp::UIBCCapability::ZIGBEE;\n    }\n  | WFD_INPUT_PATH_WIFI {\n      $$ = wds::rtsp::UIBCCapability::WI_FI;\n    }\n  | WFD_INPUT_PATH_NOSP {\n      $$ = wds::rtsp::UIBCCapability::NO_SP;\n    }\n  ;\n  \nwfd_uibc_setting:\n    WFD_UIBC_SETTING ':' WFD_SP wfd_uibc_setting_value {\n      $$ = new wds::rtsp::UIBCSetting($4);\n    }\n  ;\n\nwfd_uibc_setting_value:\n    WFD_UIBC_SETTING_ENABLE {\n      $$ = true;\n    }\n  | WFD_UIBC_SETTING_DISABLE {\n      $$ = false;\n    }\n  ;\n\nwfd_standby_resume_capability:\n    WFD_STANDBY_RESUME_CAPABILITY ':' WFD_SP wfd_standby_resume_capability_value {\n      $$ = new wds::rtsp::StandbyResumeCapability($4);\n    }\n  ;\n  \nwfd_standby_resume_capability_value:\n    WFD_NONE {\n      $$ = false;\n    }\n  | WFD_SUPPORTED {\n      $$ = true;\n    }\n  ;\n  \nwfd_connector_type:\n    WFD_CONNECTOR_TYPE ':' WFD_SP WFD_NUM {\n      $$ = new wds::rtsp::ConnectorType($4);\n    }\n  | WFD_CONNECTOR_TYPE ':' WFD_SP WFD_NONE {\n      $$ = new wds::rtsp::ConnectorType();\n    }\n  ;\n\n%%\n"
  },
  {
    "path": "libwds/rtsp/pause.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/pause.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nPause::Pause(const std::string& request_uri)\n : Request(Request::MethodPause, request_uri) {\n}\n\nPause::~Pause() {\n}\n\nstd::string Pause::ToString() const {\n  std::string ret = MethodName::PAUSE\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/pause.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PAUSE_H_\n#define LIBWDS_RTSP_PAUSE_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Pause : public Request {\n public:\n    explicit Pause(const std::string& request_uri);\n    ~Pause() override;\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_PAUSE_H_\n"
  },
  {
    "path": "libwds/rtsp/payload.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/payload.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nPayload::~Payload() {\n}\n\nPropertyMapPayload::~PropertyMapPayload() {\n}\n\nstd::shared_ptr<Property> PropertyMapPayload::GetProperty(\n    const std::string& name) const {\n  auto property = properties_.find(name);\n  if (property != properties_.end())\n    return property->second;\n  return nullptr;\n}\n\nstd::shared_ptr<Property> PropertyMapPayload::GetProperty(\n    PropertyType type) const {\n  if (type == GenericPropertyType)\n    return nullptr;\n\n  return GetProperty(GetPropertyName(type));\n}\n\nbool PropertyMapPayload::HasProperty(PropertyType type) const {\n  return properties_.find(GetPropertyName(type)) != properties_.end();\n}\n\nvoid PropertyMapPayload::AddProperty(\n    const std::shared_ptr<Property>& property) {\n  properties_[property->GetName()] = property;\n}\n\nstd::string PropertyMapPayload::ToString() const {\n  std::string ret;\n  for (auto it : properties_) {\n    if (auto property = it.second) {\n      ret += property->ToString();\n      ret += \"\\r\\n\";\n    }\n  }\n\n  return ret;\n}\n\nGetParameterPayload::GetParameterPayload(const std::vector<std::string>& properties)\n   : Payload(Payload::Requests),\n     properties_(properties) {\n}\n\nGetParameterPayload::~GetParameterPayload() {\n}\n\nvoid GetParameterPayload::AddRequestProperty(const PropertyType& type) {\n  properties_.push_back(GetPropertyName(type));\n}\n\nvoid GetParameterPayload::AddRequestProperty(\n    const std::string& generic_property) {\n  properties_.push_back(generic_property);\n}\n\nstd::string GetParameterPayload::ToString() const {\n  std::string ret;\n  for (const std::string& property : properties_) {\n    ret += property;\n    ret += \"\\r\\n\";\n  }\n\n  return ret;\n}\n\nPropertyErrorPayload::~PropertyErrorPayload() {\n}\n\nstd::shared_ptr<PropertyErrors> PropertyErrorPayload::GetPropertyError(\n    const std::string& name) const {\n  auto property = property_errors_.find(name);\n  if (property != property_errors_.end())\n    return property->second;\n  return nullptr;\n}\n\nstd::shared_ptr<PropertyErrors> PropertyErrorPayload::GetPropertyError(\n    PropertyType type) const {\n  if (type == GenericPropertyType)\n    return nullptr;\n  return GetPropertyError(GetPropertyName(type));\n}\n\nvoid PropertyErrorPayload::AddPropertyError(const std::shared_ptr<PropertyErrors>& errors) {\n  if (errors->type() == GenericPropertyType) {\n    property_errors_[errors->generic_property_name()] = errors;\n  } else {\n    property_errors_[GetPropertyName(errors->type())] = errors;\n  }\n}\n\nstd::string PropertyErrorPayload::ToString() const {\n  std::string ret;\n  for (auto it = property_errors_.rbegin();\n       it != property_errors_.rend(); ++it) {\n    ret += it->second->ToString();\n    ret += \"\\r\\n\";\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/payload.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PAYLOAD_H_\n#define LIBWDS_RTSP_PAYLOAD_H_\n\n#include <map>\n#include <memory>\n#include <string>\n#include <vector>\n\n#include \"libwds/public/logging.h\"\n\n#include \"libwds/rtsp/property.h\"\n#include \"libwds/rtsp/genericproperty.h\"\n#include \"libwds/rtsp/propertyerrors.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nusing PropertyMap = std::map<std::string, std::shared_ptr<Property>>;\nusing PropertyErrorMap = std::map<std::string, std::shared_ptr<PropertyErrors>>;\n\nclass Payload {\n public:\n  enum Type {\n    Properties,\n    Requests,\n    Errors\n  };\n\n  virtual ~Payload();\n  virtual std::string ToString() const = 0;\n\n  Type type() const { return type_; }\n\n protected:\n  explicit Payload(Type type) : type_(type) {}\n  Type type_;\n};\n\nclass PropertyMapPayload : public Payload {\n public:\n  PropertyMapPayload() : Payload(Payload::Properties) {}\n\n  ~PropertyMapPayload() override;\n\n  std::shared_ptr<Property> GetProperty(const std::string& name) const;\n  std::shared_ptr<Property> GetProperty(PropertyType type) const;\n  bool HasProperty(PropertyType type) const;\n  void AddProperty(const std::shared_ptr<Property>& property);\n  const PropertyMap& properties() const { return properties_; }\n\n  std::string ToString() const override;\n\n private:\n  PropertyMap properties_;\n};\n\ninline PropertyMapPayload* ToPropertyMapPayload(Payload* payload) {\n  if (!payload)\n     return nullptr;\n  if (payload->type() == Payload::Properties)\n    return static_cast<PropertyMapPayload*>(payload);\n  WDS_ERROR(\"Inappropriate payload type\");\n  return nullptr;\n}\n\nclass GetParameterPayload : public Payload {\n public:\n  GetParameterPayload() : Payload(Payload::Requests) {}\n  explicit GetParameterPayload(\n      const std::vector<std::string>& properties);\n  ~GetParameterPayload() override;\n\n  void AddRequestProperty(const PropertyType& property);\n  void AddRequestProperty(const std::string& generic_property);\n  const std::vector<std::string>& properties() const {\n    return properties_;\n  }\n\n  std::string ToString() const override;\n\n private:\n  std::vector<std::string> properties_;\n};\n\ninline GetParameterPayload* ToGetParameterPayload(Payload* payload) {\n  if (!payload)\n    return nullptr;\n  if (payload->type() == Payload::Requests)\n    return static_cast<GetParameterPayload*>(payload);\n  WDS_ERROR(\"Inappropriate payload type\");\n  return nullptr;\n}\n\nclass PropertyErrorPayload : public Payload {\n public:\n  PropertyErrorPayload() : Payload(Payload::Errors) {}\n  ~PropertyErrorPayload() override;\n\n  std::shared_ptr<PropertyErrors> GetPropertyError(const std::string& name) const;\n  std::shared_ptr<PropertyErrors> GetPropertyError(PropertyType type) const;\n  void AddPropertyError(const std::shared_ptr<PropertyErrors>& error);\n  const PropertyErrorMap& property_errors() const { return property_errors_; }\n  std::string ToString() const override;\n\n private:\n  PropertyErrorMap property_errors_;\n};\n\ninline PropertyErrorPayload* ToPropertyErrorPayload(Payload* payload) {\n  if (!payload)\n     return nullptr;\n  if (payload->type() == Payload::Errors)\n    return static_cast<PropertyErrorPayload*>(payload);\n  WDS_ERROR(\"Inappropriate payload type\");\n  return nullptr;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_PAYLOAD_H_\n"
  },
  {
    "path": "libwds/rtsp/play.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/play.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nPlay::Play(const std::string& request_uri)\n : Request(Request::MethodPlay, request_uri) {\n}\n\nstd::string Play::ToString() const {\n  std::string ret = MethodName::PLAY\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/play.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PLAY_H_\n#define LIBWDS_RTSP_PLAY_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Play : public Request {\n public:\n    explicit Play(const std::string& request_uri);\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_PLAY_H_\n"
  },
  {
    "path": "libwds/rtsp/preferreddisplaymode.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/preferreddisplaymode.h\"\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nPreferredDisplayMode::PreferredDisplayMode(\n    unsigned int p_clock,unsigned short h,\n    unsigned short hb, unsigned short hspol_hsoff, unsigned short hsw,\n    unsigned short v, unsigned short vb, unsigned short vspol_vsoff,\n    unsigned short vsw, unsigned char vbs3d, unsigned char modes_2d_s3d,\n    unsigned char p_depth, const H264Codec& h264_codec)\n  : Property(PreferredDisplayModePropertyType),\n    p_clock_(p_clock),\n    h_(h),\n    hb_(hb),\n    hspol_hsoff_(hspol_hsoff),\n    hsw_(hsw),\n    v_(v),\n    vb_(vb),\n    vspol_vsoff_(vspol_vsoff),\n    vsw_(vsw),\n    vbs3d_(vbs3d),\n    modes_2d_s3d_(modes_2d_s3d),\n    p_depth_(p_depth),\n    h264_codec_(h264_codec) {\n}\n\nstd::string PreferredDisplayMode::ToString() const {\n  MAKE_HEX_STRING_6(p_clock, p_clock_);\n  MAKE_HEX_STRING_4(h, h_);\n  MAKE_HEX_STRING_4(hb, hb_);\n  MAKE_HEX_STRING_4(hspol_hsoff, hspol_hsoff_);\n  MAKE_HEX_STRING_4(hsw, hsw_);\n  MAKE_HEX_STRING_4(v, v_);\n  MAKE_HEX_STRING_4(vb, vb_);\n  MAKE_HEX_STRING_4(vspol_vsoff, vspol_vsoff_);\n  MAKE_HEX_STRING_4(vsw, vsw_);\n  MAKE_HEX_STRING_2(vbs3d, vbs3d_);\n  MAKE_HEX_STRING_2(modes_2d_s3d, modes_2d_s3d_);\n  MAKE_HEX_STRING_2(p_depth, p_depth_);\n\n  std::string ret =\n      PropertyName::wfd_preferred_display_mode + std::string(SEMICOLON)\n  + std::string(SPACE) + p_clock\n  + std::string(SPACE) + h\n  + std::string(SPACE) + hb\n  + std::string(SPACE) + hspol_hsoff\n  + std::string(SPACE) + hsw\n  + std::string(SPACE) + v\n  + std::string(SPACE) + vb\n  + std::string(SPACE) + vspol_vsoff\n  + std::string(SPACE) + vsw\n  + std::string(SPACE) + vbs3d\n  + std::string(SPACE) + modes_2d_s3d\n  + std::string(SPACE) + p_depth\n  + std::string(SPACE) + h264_codec_.ToString();\n  return ret;\n}\n\nPreferredDisplayMode::~PreferredDisplayMode() {\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/preferreddisplaymode.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PREFERREDDISPLAYMODE_H_\n#define LIBWDS_RTSP_PREFERREDDISPLAYMODE_H_\n\n#include \"libwds/rtsp/property.h\"\n\n#include \"libwds/rtsp/videoformats.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass PreferredDisplayMode: public Property {\n public:\n  PreferredDisplayMode(unsigned int p_clock, unsigned short h,\n      unsigned short hb, unsigned short hspol_hsoff, unsigned short hsw,\n      unsigned short v, unsigned short vb, unsigned short vspol_vsoff,\n      unsigned short vsw, unsigned char vbs3d, unsigned char modes_2d_s3d,\n      unsigned char p_depth, const H264Codec& h264_codec);\n\n  ~PreferredDisplayMode() override;\n\n  unsigned int p_clock() const { return p_clock_; }\n  unsigned short h() const { return h_; }\n  unsigned short hb() const { return hb_; }\n  unsigned short hspol_hsoff() const { return hspol_hsoff_; }\n  unsigned short hsw() const { return hsw_; }\n  unsigned short v() const { return v_; }\n  unsigned short vb() const { return vb_; }\n  unsigned short vspol_vsoff() const { return vspol_vsoff_; }\n  unsigned short vsw() const { return vsw_; }\n  unsigned char vbs3d() const { return vbs3d_; }\n  unsigned char modes_2d_s3d() const { return modes_2d_s3d_; }\n  unsigned char p_depth() const { return p_depth_; }\n  const H264Codec& h264_codec() const { return h264_codec_; }\n\n  std::string ToString() const override;\n\n private:\n  unsigned int p_clock_;\n  unsigned short h_;\n  unsigned short hb_;\n  unsigned short hspol_hsoff_;\n  unsigned short hsw_;\n  unsigned short v_;\n  unsigned short vb_;\n  unsigned short vspol_vsoff_;\n  unsigned short vsw_;\n  unsigned char vbs3d_;\n  unsigned char modes_2d_s3d_;\n  unsigned char p_depth_;\n  H264Codec h264_codec_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_PREFERREDDISPLAYMODE_H_\n"
  },
  {
    "path": "libwds/rtsp/presentationurl.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/presentationurl.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nPresentationUrl::PresentationUrl(const std::string& presentation_url_1,\n    const std::string presentation_url_2)\n  : Property(PresentationURLPropertyType),\n    presentation_url_1_(presentation_url_1),\n    presentation_url_2_(presentation_url_2) {\n}\n\nPresentationUrl::~PresentationUrl() {\n}\n\nstd::string PresentationUrl::ToString() const {\n  std::string ret =\n      PropertyName::wfd_presentation_url + std::string(SEMICOLON)\n    + std::string(SPACE)\n    + (presentation_url_1_.length() ? presentation_url_1_ : NONE)\n    + std::string(SPACE)\n    + (presentation_url_2_.length() ? presentation_url_2_ : NONE);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/presentationurl.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PRESENTATIONURL_H_\n#define LIBWDS_RTSP_PRESENTATIONURL_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass PresentationUrl: public Property {\n public:\n  PresentationUrl(const std::string& presentation_url_1,\n      const std::string presentation_url_2);\n  ~PresentationUrl() override;\n\n  const std::string& presentation_url_1() const { return presentation_url_1_; }\n  const std::string& presentation_url_2() const { return presentation_url_2_; }\n  std::string ToString() const override;\n\n private:\n  std::string presentation_url_1_;\n  std::string presentation_url_2_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_PRESENTATIONURL_H_\n"
  },
  {
    "path": "libwds/rtsp/property.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/rtsp/property.h\"\n\n#include \"libwds/public/logging.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nProperty::Property(PropertyType type)\n    : type_(type),\n      is_none_(false) {\n}\n\nProperty::Property(PropertyType type, bool is_none)\n    : type_(type),\n      is_none_(is_none) {\n}\n\nProperty::~Property() {\n}\n\nstd::string Property::ToString() const {\n  return std::string();\n}\n\nstd::string Property::GetName() const {\n  if (type_ == GenericPropertyType)\n    return std::string();\n  return GetPropertyName(type_);\n}\n\nstd::string GetPropertyName(PropertyType type) {\n  switch(type) {\n    case AVFormatChangeTimingPropertyType:\n      return PropertyName::wfd_av_format_change_timing;\n    case AudioCodecsPropertyType:\n      return PropertyName::wfd_audio_codecs;\n    case ClientRTPPortsPropertyType:\n      return PropertyName::wfd_client_rtp_ports;\n    case ConnectorTypePropertyType:\n      return PropertyName::wfd_connector_type;\n    case ContentProtectionPropertyType:\n      return PropertyName::wfd_content_protection;\n    case CoupledSinkPropertyType:\n      return PropertyName::wfd_coupled_sink;\n    case DisplayEdidPropertyType:\n      return PropertyName::wfd_display_edid;\n    case GenericPropertyType:\n      WDS_ERROR(\"Generic property does not have a defined name\");\n      return std::string();\n    case I2CPropertyType:\n      return PropertyName::wfd_I2C;\n    case IDRRequestPropertyType:\n      return PropertyName::wfd_idr_request;\n    case PreferredDisplayModePropertyType:\n      return PropertyName::wfd_preferred_display_mode;\n    case PresentationURLPropertyType:\n      return PropertyName::wfd_presentation_url;\n    case RoutePropertyType:\n      return PropertyName::wfd_route;\n    case StandbyPropertyType:\n      return PropertyName::wfd_standby;\n    case StandbyResumeCapabilityPropertyType:\n      return PropertyName::wfd_standby_resume_capability;\n    case TriggerMethodPropertyType:\n      return PropertyName::wfd_trigger_method;\n    case UIBCCapabilityPropertyType:\n      return PropertyName::wfd_uibc_capability;\n    case UIBCSettingPropertyType:\n      return PropertyName::wfd_uibc_setting;\n    case Video3DFormatsPropertyType:\n      return PropertyName::wfd_3d_video_formats;\n    case VideoFormatsPropertyType:\n      return PropertyName::wfd_video_formats;\n    default:\n      WDS_ERROR(\"Unknown property type %d\", type);\n      return std::string();\n  }\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/property.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PROPERTY_H_\n#define LIBWDS_RTSP_PROPERTY_H_\n\n#include <string>\n#include <map>\n\n#include \"libwds/rtsp/constants.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Property {\n public:\n  explicit Property(PropertyType type);\n  virtual ~Property();\n  virtual std::string ToString() const;\n\n  PropertyType type() { return type_; }\n  bool is_none() const { return is_none_; }\n\n  virtual std::string GetName() const;\n\n protected:\n  Property(PropertyType type, bool is_none_);\n\n private:\n  PropertyType type_;\n  bool is_none_;\n};\n\nstd::string GetPropertyName(PropertyType type);\n\n}  // namespace wds\n}  // namespace rtsp\n\n#endif  // LIBWDS_RTSP_PROPERTY_H_\n"
  },
  {
    "path": "libwds/rtsp/propertyerrors.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/propertyerrors.h\"\n#include \"libwds/rtsp/property.h\"\n\n#include <assert.h>\n\nnamespace wds {\nnamespace rtsp {\n\nPropertyErrors::PropertyErrors(PropertyType type,\n                               const std::vector<unsigned short>& error_codes)\n    : type_(type),\n      error_codes_(error_codes) {\n}\n\nPropertyErrors::PropertyErrors(const std::string& generic_property_name,\n                               const std::vector<unsigned short>& error_codes)\n    : type_(GenericPropertyType),\n      generic_property_name_(generic_property_name),\n      error_codes_(error_codes) {\n}\n\nPropertyErrors::~PropertyErrors() {\n}\n\nstd::string PropertyErrors::ToString() const {\n  std::string ret;\n\n  if (type_ == GenericPropertyType)\n    ret += generic_property_name_;\n  else\n    ret += GetPropertyName(type_);\n\n  ret += std::string(SEMICOLON) + std::string(SPACE);\n\n  auto it = error_codes_.begin();\n  while (it != error_codes_.end()) {\n    ret += std::to_string(*it);\n    it++;\n    if (it != error_codes_.end())\n      ret += \", \";\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/propertyerrors.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_PROPERTYERRORS_H_\n#define LIBWDS_RTSP_PROPERTYERRORS_H_\n\n#include <string>\n#include <vector>\n#include \"libwds/rtsp/constants.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass PropertyErrors {\n public:\n  PropertyErrors(PropertyType type, const std::vector<unsigned short>& error_codes);\n  PropertyErrors(const std::string& generic_property_name, const std::vector<unsigned short>& error_codes);\n  ~PropertyErrors();\n\n  PropertyType type() const { return type_; }\n  const std::vector<unsigned short>& error_codes() const { return error_codes_; }\n  const std::string& generic_property_name() const { return generic_property_name_; }\n\n  std::string ToString() const;\n\n private:\n  PropertyType type_;\n  std::string generic_property_name_;\n  std::vector<unsigned short> error_codes_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_PROPERTYERRORS_H_\n"
  },
  {
    "path": "libwds/rtsp/reply.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/reply.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n  const char kRTSPHeader[] = \"RTSP/1.0 \";\n  const char kOK[] = \"OK\";\n}\n\nReply::Reply(int response_code)\n  : Message(Message::REPLY),\n    response_code_(response_code) {\n}\n\nReply::~Reply() {\n}\n\nstd::string Reply::ToString() const {\n  std::string ret;\n  ret += kRTSPHeader + std::to_string(response_code_)\n       + std::string(SPACE) + kOK + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/reply.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_REPLY_H_\n#define LIBWDS_RTSP_REPLY_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Reply: public Message {\n public:\n  explicit Reply(int response_code = STATUS_OK);\n  ~Reply() override;\n\n  int response_code() const { return response_code_; }\n  void set_response_code(int response_code) { response_code_ = response_code; }\n\n  std::string ToString() const override;\n\n private:\n  int response_code_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_REPLY_H_\n"
  },
  {
    "path": "libwds/rtsp/route.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/route.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\nconst char primary[] = \"primary\";\nconst char secondary[] = \"secondary\";\n}\n\nRoute::Route(const Route::Destination& destination)\n  : Property(RoutePropertyType), destination_(destination) {\n\n}\n\nRoute::~Route() {\n}\n\nstd::string Route::ToString() const {\n  std::string ret = PropertyName::wfd_route+ std::string(SEMICOLON)\n    + std::string(SPACE) + (destination() == PRIMARY ? primary : secondary);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/route.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_ROUTE_H_\n#define LIBWDS_RTSP_ROUTE_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Route: public Property {\n public:\n  enum Destination {\n    PRIMARY,\n    SECONDARY\n  };\n\n public:\n  explicit Route(const Route::Destination& destination);\n  ~Route() override;\n\n  Route::Destination destination() const { return destination_; }\n  std::string ToString() const override;\n\n private:\n  Route::Destination destination_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_ROUTE_H_\n"
  },
  {
    "path": "libwds/rtsp/setparameter.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nSetParameter::SetParameter(const std::string& request_uri)\n : Request(Request::MethodSetParameter, request_uri) {\n}\n\nstd::string SetParameter::ToString() const {\n  std::string ret = MethodName::SET_PARAMETER\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/setparameter.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_SETPARAMETER_H_\n#define LIBWDS_RTSP_SETPARAMETER_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass SetParameter : public Request {\n public:\n    explicit SetParameter(const std::string& request_uri);\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_SETPARAMETER_H_\n"
  },
  {
    "path": "libwds/rtsp/setup.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/setup.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nSetup::Setup(const std::string& request_uri)\n : Request(Request::MethodSetup, request_uri) {\n}\n\nSetup::~Setup() {\n}\n\nstd::string Setup::ToString() const {\n  std::string ret = MethodName::SETUP\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/setup.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_SETUP_H_\n#define LIBWDS_RTSP_SETUP_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Setup : public Request {\n public:\n    explicit Setup(const std::string& request_uri);\n    ~Setup() override;\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_SETUP_H_\n"
  },
  {
    "path": "libwds/rtsp/standby.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/standby.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nStandby::Standby() : Property(StandbyPropertyType) {\n}\n\nStandby::~Standby() {\n}\n\nstd::string Standby::ToString() const {\n  return std::string(\"wfd_standby\");\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/standby.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_STANDBY_H_\n#define LIBWDS_RTSP_STANDBY_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Standby: public Property {\npublic:\n  Standby();\n  ~Standby() override;\n  std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_STANDBY_H_\n"
  },
  {
    "path": "libwds/rtsp/standbyresumecapability.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/standbyresumecapability.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\nconst char supported[] = \"supported\";\n}\n\nStandbyResumeCapability::StandbyResumeCapability(bool is_supported)\n  : Property(StandbyResumeCapabilityPropertyType, !is_supported) {\n}\n\nStandbyResumeCapability::~StandbyResumeCapability() {\n}\n\nstd::string StandbyResumeCapability::ToString() const {\n  std::string ret =\n      PropertyName::wfd_standby_resume_capability + std::string(SEMICOLON)\n     + std::string(SPACE) + (is_none() ? NONE : supported);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/standbyresumecapability.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_STANDBYRESUMECAPABILITY_H_\n#define LIBWDS_RTSP_STANDBYRESUMECAPABILITY_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass StandbyResumeCapability: public Property {\npublic:\n  explicit StandbyResumeCapability(bool is_supported);\n  ~StandbyResumeCapability() override;\n\n  std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_STANDBYRESUMECAPABILITY_H_\n"
  },
  {
    "path": "libwds/rtsp/teardown.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/teardown.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nTeardown::Teardown(const std::string& request_uri)\n : Request(Request::MethodTeardown, request_uri) {\n}\n\nTeardown::~Teardown() {\n}\n\nstd::string Teardown::ToString() const {\n  std::string ret = MethodName::TEARDOWN\n      + std::string(SPACE) + request_uri()\n      + std::string(SPACE) + std::string(RTSP_END) + std::string(CRLF);\n  return ret + Message::ToString();\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/teardown.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_TEARDOWN_H_\n#define LIBWDS_RTSP_TEARDOWN_H_\n\n#include \"libwds/rtsp/message.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass Teardown : public Request {\n public:\n    explicit Teardown(const std::string& request_uri);\n    ~Teardown() override;\n    std::string ToString() const override;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_TEARDOWN_H_\n"
  },
  {
    "path": "libwds/rtsp/tests/CMakeLists.txt",
    "content": "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden -fPIC\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\" \"../gen\")\n\nadd_executable(test-wds tests.cpp $<TARGET_OBJECTS:wdsrtsp> $<TARGET_OBJECTS:wdscommon>)\nset(LINK_FLAGS ${LINK_FLAGS} \"-Wl,-whole-archive\")\ntarget_link_libraries (test-wds)\n\nadd_test(WfdTest test-wds)\n\nif (WDS_INSTALL_TESTS)\n  install(PROGRAMS test-wds DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})\nendif()\n\nOPTION(WDS_FUZZER \"Binary that is used for fuzzer tests.\" OFF)\nIF(WDS_FUZZER)\nadd_executable(wdsfuzzer wdsfuzzer.cpp $<TARGET_OBJECTS:wdsrtsp> $<TARGET_OBJECTS:wdscommon>)\nset(LINK_FLAGS ${LINK_FLAGS} \"-Wl,-whole-archive\")\ntarget_link_libraries (wdsfuzzer)\nENDIF(WDS_FUZZER)"
  },
  {
    "path": "libwds/rtsp/tests/README",
    "content": "=======================\nHow to fuzz WDS parser\n=======================\n\n1) Get afl-fuzz from http://lcamtuf.coredump.cx/afl/ and follow\n   \"QuickStartGuide\" http://lcamtuf.coredump.cx/afl/QuickStartGuide.txt\n\n2) Build WDS with WDS_FUZZER support. Provide full path to afl-gcc / afl-g++\n   or add path containing afl-* binaries to your PATH environment variable.\n   CC=afl-gcc CXX=afl-g++ cmake -DWDS_FUZZER=ON --disable-shared .\n\n3) Run run_afl_fuzzer.sh script which is located under libwds/rtsp/tests folder\n   ./libwds/rtsp/tests/run_afl_fuzzer.sh PATH_TO_AFL_FUZZ TEST_RESULT_PATH\n   e.g. ./libwds/rtsp/tests/run_afl_fuzzer.sh afl-fuzz test_results\n   Four fuzzer jobs will be started (header, payload_request, payload_reply\n   and payload_error), each testing independent lexing / parsing code paths.\n\n4) Observe progress in separate xterm terminal or use afl-whatsup to get status\n   of fuzzing job with afl-whatsup.\n\n5) For more information check http://lcamtuf.coredump.cx/afl/README.txt or docs\n   folder under afl-fuzz source tree."
  },
  {
    "path": "libwds/rtsp/tests/dict/wfd_header.dict",
    "content": "# This file is part of Wireless Display Software for Linux OS\n#\n# Copyright (C) 2016 Intel Corporation.\n#\n# This library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n#\n# This library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this library; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n# 02110-1301 USA\n\n# WiFi Display RTSP dictionary for request / response headers\n\nmethod_OPTIONS=\"OPTIONS\"\nmethod_WFD=\"org.wfa.wfd1.0\"\nmethod_SET_PARAMETER=\"SET_PARAMETER\"\nmethod_GET_PARAMETER=\"GET_PARAMETER\"\nmethod_SETUP=\"SETUP\"\nmethod_PLAY=\"PLAY\"\nmethod_TEARDOWN=\"TEARDOWN\"\nmethod_PAUSE=\"PAUSE\"\n\nheader_RESPONSE=\"RTSP/1.0\"\nheader_CSeq=\"CSeq:\"\nheader_SupportedMethods=\"Public:\"\nheader_Require=\"Require:\"\nheader_ContentType=\"Content-Type:\"\nheader_ContentLength=\"Content-Length:\"\nheader_Session=\"Session:\"\nheader_Transport=\"Transport:\"\nheader_star=\"*\"\nheader_status\"OK\"\nheader_date=\"Date:\"\n\ntoken_Timeout=\"timeout=\"\ntoken_ServerPort=\"server_port=\"\ntoken_ServerPort=\"client_port=\"\ntoken_RTPUDP=\"RTP/AVP/UDP\"\ntoken_unicast=\"unicast\"\n\ndata_url=\"rtsp://localhost/wfd1.0\"\ndata_url_ip=\"rtsp://192.168.0.101/wfd1.0\"\ndata_error_code=\"200\""
  },
  {
    "path": "libwds/rtsp/tests/dict/wfd_payload_error.dict",
    "content": "# This file is part of Wireless Display Software for Linux OS\n#\n# Copyright (C) 2016 Intel Corporation.\n#\n# This library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n#\n# This library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this library; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n# 02110-1301 USA\n\n# WiFi Display RTSP dictionary for payload with response error\n\npayload_wfd_audio_codecs=\"wfd-audio-codecs:\"\npayload_wfd_video_formats=\"wfd-video-formats:\"\npayload_wfd_3d_formats=\"wfd-3d-formats:\"\npayload_wfd_content_protection=\"wfd-content-protection:\"\npayload_wfd_display_edid=\"wfd-display-edid:\"\npayload_wfd_coupled_sink=\"wfd-coupled-sink:\"\npayload_wfd_trigger_method=\"wfd-trigger-method:\"\npayload_wfd_presentation_url=\"wfd-presentation-url:\"\npayload_wfd_client_rtp_ports=\"wfd-client-rtp-ports:\"\npayload_wfd_route=\"wfd-route:\"\npayload_wfd_I2C=\"wfd-I2C:\"\npayload_wfd_av_format_change_timing=\"wfd-av-format-change-timing:\"\npayload_wfd_preferred_display_mode=\"wfd-preferred-display-mode:\"\npayload_wfd_uibc_capability=\"wfd-uibc-capability:\"\npayload_wfd_uibc_setting=\"wfd-uibc-setting:\"\npayload_wfd_standby_resume_capability=\"wfd-standby-resume-capability:\"\npayload_wfd_standby=\"wfd-standby:\"\npayload_wfd_connector_type=\"wfd-connector-type:\"\npayload_wfd_idr_request=\"wfd-idr-request:\"\n\ntoken_SEPARATOR=\", \""
  },
  {
    "path": "libwds/rtsp/tests/dict/wfd_payload_reply.dict",
    "content": "# This file is part of Wireless Display Software for Linux OS\n#\n# Copyright (C) 2016 Intel Corporation.\n#\n# This library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n#\n# This library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this library; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n# 02110-1301 USA\n\n# WiFi Display RTSP dictionary payload response\n\npayload_wfd_audio_codecs=\"wfd-audio-codecs:\"\npayload_wfd_video_formats=\"wfd-video-formats:\"\npayload_wfd_3d_formats=\"wfd-3d-formats:\"\npayload_wfd_content_protection=\"wfd-content-protection:\"\npayload_wfd_display_edid=\"wfd-display-edid:\"\npayload_wfd_coupled_sink=\"wfd-coupled-sink:\"\npayload_wfd_trigger_method=\"wfd-trigger-method:\"\npayload_wfd_presentation_url=\"wfd-presentation-url:\"\npayload_wfd_client_rtp_ports=\"wfd-client-rtp-ports:\"\npayload_wfd_route=\"wfd-route:\"\npayload_wfd_I2C=\"wfd-I2C:\"\npayload_wfd_av_format_change_timing=\"wfd-av-format-change-timing:\"\npayload_wfd_preferred_display_mode=\"wfd-preferred-display-mode:\"\npayload_wfd_uibc_capability=\"wfd-uibc-capability:\"\npayload_wfd_uibc_setting=\"wfd-uibc-setting:\"\npayload_wfd_standby_resume_capability=\"wfd-standby-resume-capability:\"\npayload_wfd_standby=\"wfd-standby:\"\npayload_wfd_connector_type=\"wfd-connector-type:\"\npayload_wfd_idr_request=\"wfd-idr-request:\"\n\ntoken_none=\"none\"\ntoken_LPCM=\"LPCM\"\ntoken_AAC=\"AAC\"\ntoken_AC3=\"AC3\"\ntoken_HDCP20=\"HDCP2.0\"\ntoken_HDCP21=\"HDCP2.1\"\ntoken_port=\"port=\"\ntoken_RTP=\"RTP/AVP/UDP;unicast\"\ntoken_mode_play=\"mode=play\"\ntoken_primary=\"primary\"\ntoken_secondary=\"secondary\"\ntoken_input_category_list==\"input_category_list=\"\ntoken_GENERIC=\"GENERIC\"\ntoken_HIDC=\"HIDC\"\ntoken_generic_cap_list==\"generic_cap_list=\"\ntoken_Keyboard=\"Keyboard\"\ntoken_Mouse=\"Mouse\"\ntoken_SingleTouch=\"SingleTouch\"\ntoken_MultiTouch=\"MultiTouch\"\ntoken_Joystick=\"Joystick\"\ntoken_Camera=\"Camera\"\ntoken_Gesture=\"Gesture\"\ntoken_RemoteControl=\"RemoteControl\"\ntoken_hidc_cap_list==\"hidc_cap_list=\"\ntoken_Infrared=\"Infrared\"\ntoken_USB=\"USB\"\ntoken_BT=\"BT\"\ntoken_WiFi=\"Wi-Fi\"\ntoken_Zigbee=\"Zigbee\"\ntoken_NoSP=\"No-SP\"\ntoken_disable=\"disable\"\ntoken_enable=\"enable\"\ntoken_supported=\"supported\""
  },
  {
    "path": "libwds/rtsp/tests/dict/wfd_payload_request.dict",
    "content": "# This file is part of Wireless Display Software for Linux OS\n#\n# Copyright (C) 2016 Intel Corporation.\n#\n# This library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n#\n# This library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this library; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n# 02110-1301 USA\n\n# WiFi Display RTSP dictionary for GET_PARAMETER request messages\n\npayload_wfd_audio_codecs=\"wfd-audio-codecs\"\npayload_wfd_video_formats=\"wfd-video-formats\"\npayload_wfd_3d_formats=\"wfd-3d-formats\"\npayload_wfd_content_protection=\"wfd-content-protection\"\npayload_wfd_display_edid=\"wfd-display-edid\"\npayload_wfd_coupled_sink=\"wfd-coupled-sink\"\npayload_wfd_trigger_method=\"wfd-trigger-method\"\npayload_wfd_presentation_url=\"wfd-presentation-url\"\npayload_wfd_client_rtp_ports=\"wfd-client-rtp-ports\"\npayload_wfd_route=\"wfd-route\"\npayload_wfd_I2C=\"wfd-I2C\"\npayload_wfd_av_format_change_timing=\"wfd-av-format-change-timing\"\npayload_wfd_preferred_display_mode=\"wfd-preferred-display-mode\"\npayload_wfd_uibc_capability=\"wfd-uibc-capability\"\npayload_wfd_uibc_setting=\"wfd-uibc-setting\"\npayload_wfd_standby_resume_capability=\"wfd-standby-resume-capability\"\npayload_wfd_standby=\"wfd-standby\"\npayload_wfd_connector_type=\"wfd-connector-type\"\npayload_wfd_idr_request=\"wfd-idr-request\"\ntoken_newline=\"0x0d0x0a\""
  },
  {
    "path": "libwds/rtsp/tests/run_afl_fuzzer.sh",
    "content": "#!/bin/bash\n\n# This file is part of Wireless Display Software for Linux OS\n#\n# Copyright (C) 2016 Intel Corporation.\n#\n# This library is free software; you can redistribute it and/or\n# modify it under the terms of the GNU Lesser General Public\n# License as published by the Free Software Foundation; either\n# version 2.1 of the License, or (at your option) any later version.\n#\n# This library is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n# Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this library; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n# 02110-1301 USA\n\nBASEDIR=$(dirname $0)\n\nxterm -geometry 80x25 -e \"$1 -i $BASEDIR/seed/header/ -x $BASEDIR/dict/wfd_header.dict -o $2_header -T header $BASEDIR/wdsfuzzer --num-lines 6 --header\" &\nxterm -geometry 80x25 -e \"$1 -i $BASEDIR/seed/payload_reply/ -x $BASEDIR/dict/wfd_payload_reply.dict -o $2_payload_reply -T payload_reply $BASEDIR/wdsfuzzer --num-lines 8 --payload-reply\" &\nxterm -geometry 80x25 -e \"$1 -i $BASEDIR/seed/payload_request/ -x $BASEDIR/dict/wfd_payload_request.dict -o $2_payload_request -T payload_request $BASEDIR/wdsfuzzer --num-lines 8 --payload-request\" &\nxterm -geometry 80x25 -e \"$1 -i $BASEDIR/seed/payload_error/ -x $BASEDIR/dict/wfd_payload_error.dict -o $2_payload_error -T payload_error $BASEDIR/wdsfuzzer --num-lines 8 --payload-error\" &\n"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/error.txt",
    "content": "RTSP/1.0 303 OK\nCSeq: 0\nContent-Type: text/parameters\nContent-Length: 55"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/get_parameter.txt",
    "content": "GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 2\nContent-Type: text/parameters\nContent-Length: 141"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/options.txt",
    "content": "OPTIONS * RTSP/1.0\nCSeq: 1\nRequire: org.wfa.wfd1.0"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/pause.txt",
    "content": "PAUSE rtsp://10.82.24.140/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 6\nSession: 6B8B4567"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/play.txt",
    "content": "PLAY rtsp://10.82.24.140/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 5\nSession: 6B8B4567"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/reply.txt",
    "content": "RTSP/1.0 200 OK\nCSeq: 4\nDate: Sun, Aug 21 2011 04:20:53 GMT\nPublic: org.wfa.wfd1.0, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/set_parameter.txt",
    "content": "SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\nCSeq: 3\nContent-Type: text/parameters\nContent-Length: 302"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/setup.txt",
    "content": "SETUP rtsp://10.82.24.140/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 4\nTransport: RTP/AVP/UDP;unicast;client_port=1028"
  },
  {
    "path": "libwds/rtsp/tests/seed/header/teardown.txt",
    "content": "TEARDOWN rtsp://10.82.24.140/wfd1.0/streamid=0 RTSP/1.0\nCSeq: 8\nSession: 6B8B4567"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_error/payload_error01.txt",
    "content": "wfd_3d_video_formats: 415, 457\nwfd_I2C: 404\nwfd_audio_codecs: 415, 457\nwfd_client_rtp_ports: 415, 457\nwfd_connector_type: 415, 457\nwfd_content_protection: 404\nwfd_coupled_sink: 404\nwfd_display_edid: 503\nwfd_standby_resume_capability: 415, 457\nwfd_uibc_capability: 494\nwfd_video_formats: 415, 457"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_error/payload_error02.txt",
    "content": "wfd-audio-codecs: 415, 457\nwfd-video-formats: 415, 457\nwfd-3d-formats: 415, 457\nwfd-content-protection: 404\nwfd-display-edid: 415, 457\nwfd-coupled-sink: 465\nwfd-trigger-method: 457\nwfd-presentation-url: 401\nwfd-client-rtp-ports: 401\nwfd-route: 404\nwfd-I2C: 404\nwfd-av-format-change-timing: 451\nwfd-preferred-display-mode: 401\nwfd-uibc-capability: 404\nwfd-uibc-setting: 401\nwfd-standby-resume-capability: 415\nwfd-standby: 465\nwfd-connector-type: 503\nwfd-idr-request: 303"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_reply/payload_reply01.txt",
    "content": "wfd_I2C: 404\nwfd_audio_codecs: LPCM 00000003 00, AAC 00000001 00\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\nwfd_connector_type: 05\nwfd_content_protection: HDCP2.1 port=1189\nwfd_coupled_sink: none\nwfd_display_edid: none\nwfd_standby_resume_capability: supported\nwfd_uibc_capability: none\nwfd_video_formats: 40 01 02 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 0400 0300, 01 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 0400 0300\nwfd_3d_video_formats: 80 00 03 0F 0000000000000005 00 0001 1401 13 none none"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_reply/payload_reply02.txt",
    "content": "wfd_audio_codecs: LPCM 00000003 00\nwfd_3d_video_formats: none\nwfd_content_protection: none\nwfd_display_edid: none\nwfd_coupled_sink: none\nwfd_client_rtp_ports: RTP/AVP/UDP;unicast 1028 0 mode=play\nwfd_presentation_URL: rtsp://192.168.173.1:3921/wfd1.0/streamid=0 rtsp://192.168.173.1:3922/wfd1.0/streamid=1\nwfd_trigger_method: TEARDOWN"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_request/payload_request01.txt",
    "content": "wfd_video_formats\nwfd_audio_codecs\nwfd_client_rtp_ports"
  },
  {
    "path": "libwds/rtsp/tests/seed/payload_request/payload_request02.txt",
    "content": "wfd-audio-codecs\nwfd-video-formats\nwfd-3d-formats\nwfd-content-protection\nwfd-display-edid\nwfd-coupled-sink\nwfd-trigger-method\nwfd-presentation-url\nwfd-client-rtp-ports\nwfd-route\nwfd-I2C\nwfd-av-format-change-timing\nwfd-preferred-display-mode\nwfd-uibc-capability\nwfd-uibc-setting\nwfd-standby-resume-capability\nwfd-standby\nwfd-connector-type\nwfd-idr-request"
  },
  {
    "path": "libwds/rtsp/tests/tests.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include <algorithm>\n#include <iostream>\n#include <list>\n\n#include \"libwds/rtsp/audiocodecs.h\"\n#include \"libwds/rtsp/avformatchangetiming.h\"\n#include \"libwds/rtsp/clientrtpports.h\"\n#include \"libwds/rtsp/connectortype.h\"\n#include \"libwds/rtsp/constants.h\"\n#include \"libwds/rtsp/contentprotection.h\"\n#include \"libwds/rtsp/displayedid.h\"\n#include \"libwds/rtsp/driver.h\"\n#include \"libwds/rtsp/formats3d.h\"\n#include \"libwds/rtsp/i2c.h\"\n#include \"libwds/rtsp/presentationurl.h\"\n#include \"libwds/rtsp/propertyerrors.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/route.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/rtsp/uibcsetting.h\"\n#include \"libwds/rtsp/videoformats.h\"\n\nusing wds::rtsp::Driver;\n\ntypedef bool (*TestFunc)(void);\n\n#define ASSERT_EQUAL(value, expected) \\\n  if ((value) != (expected)) { \\\n    std::cout << __func__ << \" (\" << __FILE__ << \":\" << __LINE__ << \"): \" \\\n              << #value << \": \" \\\n              << \"expected '\" << (expected) \\\n              << \"', got '\" << (value) << \"'\" \\\n              << std::endl; \\\n    return 0; \\\n  }\n\n#define ASSERT(assertion) \\\n  if (!(assertion)) { \\\n    std::cout << __func__ << \" (\" << __FILE__ << \":\" << __LINE__ << \"): \" \\\n              << \"assertion failed: \" << #assertion \\\n              << std::endl; \\\n    return 0; \\\n  }\n\n#define ASSERT_NO_EXCEPTION(method_call) \\\n  try { \\\n    method_call; \\\n  } catch (std::exception &x) { \\\n    std::cout << __func__ << \" (\" << __FILE__ << \":\" << __LINE__ << \"): \" \\\n              << \"unexpected exception: \" << #method_call << \": \" \\\n              << x.what() << std::endl; \\\n    return false; \\\n  }\n\n#define ASSERT_EXCEPTION(method_call) \\\n  try { \\\n    method_call; \\\n    std::cout << __func__ << \" (\" << __FILE__ << \":\" << __LINE__ << \"): \" \\\n              << \"expected exception: \" << #method_call << std::endl; \\\n    return false; \\\n  } catch (std::exception &x) { \\\n    ; \\\n  }\n\nstatic bool property_type_exists (std::vector<std::string> properties,\n                                  wds::rtsp::PropertyType type)\n{\n  return std::find (properties.begin(),\n                    properties.end(),\n                    wds::rtsp::GetPropertyName(type)) != properties.end();\n}\n\nstatic bool test_audio_codec (wds::AudioCodec codec, wds::AudioFormats format,\n                              unsigned long int modes, unsigned char latency)\n{\n  ASSERT_EQUAL(codec.format, format);\n  ASSERT_EQUAL(codec.modes.to_ulong(), modes);\n  ASSERT_EQUAL(codec.latency, latency);\n\n  return true;\n}\n\nstatic bool test_h264_codec_3d (wds::rtsp::H264Codec3d codec,\n                                unsigned char profile, unsigned char level,\n                                unsigned long long int video_capability_3d, unsigned char latency,\n                                unsigned short min_slice_size, unsigned short slice_enc_params,\n                                unsigned char frame_rate_control_support, int max_hres,\n                                int max_vres)\n{\n  ASSERT_EQUAL(codec.profile_, profile);\n  ASSERT_EQUAL(codec.level_, level);\n  ASSERT_EQUAL(codec.video_capability_3d_, video_capability_3d);\n  ASSERT_EQUAL(codec.latency_, latency);\n  ASSERT_EQUAL(codec.min_slice_size_, min_slice_size);\n  ASSERT_EQUAL(codec.slice_enc_params_, slice_enc_params);\n  ASSERT_EQUAL(codec.frame_rate_control_support_, frame_rate_control_support);\n\n  return true;\n}\n\nstatic bool test_valid_options ()\n{\n  std::string header(\"OPTIONS * RTSP/1.0\\r\\n\"\n                     \"CSeq: 0\\r\\n\"\n                     \"Require: org.wfa.wfd1.0\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodOptions);\n  ASSERT_EQUAL(request->header().cseq(), 0);\n  ASSERT_EQUAL(request->header().content_length(), 0);\n  ASSERT_EQUAL(request->header().require_wfd_support(), true);\n  ASSERT_EQUAL (request->ToString(), header);\n\n  return true;\n}\n\nstatic bool test_valid_options_reply ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 1\\r\\n\"\n                     \"Public: org.wfa.wfd1.0, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n  ASSERT(reply != NULL);\n  ASSERT_EQUAL(reply->response_code(), 200);\n  ASSERT_EQUAL(reply->header().cseq(), 1);\n  ASSERT_EQUAL(reply->header().content_length(), 0);\n\n  std::vector<wds::rtsp::Method> methods = message->header().supported_methods();\n  static const wds::rtsp::Method expected[] = { wds::rtsp::Method::ORG_WFA_WFD_1_0,\n                                                wds::rtsp::Method::SETUP,\n                                                wds::rtsp::Method::TEARDOWN,\n                                                wds::rtsp::Method::PLAY,\n                                                wds::rtsp::Method::PAUSE,\n                                                wds::rtsp::Method::GET_PARAMETER,\n                                                wds::rtsp::Method::SET_PARAMETER };\n\n  ASSERT_EQUAL(methods.size(), 7);\n  for (int i = 0; i < 7; i++) {\n    std::vector<wds::rtsp::Method>::iterator method = std::find(methods.begin(), methods.end(), expected[i]);\n    ASSERT(method != methods.end());\n  }\n\n  ASSERT_EQUAL (reply->ToString(), header);\n\n  return true;\n}\n\nstatic bool test_valid_extra_properties ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 72\\r\\n\"\n                     \"My-Header: 123 testing testing\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  GenericHeaderMap gen_headers = message->header().generic_headers();\n  auto extra_header_it = gen_headers.find(\"My-Header\");\n  ASSERT(extra_header_it != gen_headers.end())\n  ASSERT_EQUAL(extra_header_it->second, \"123 testing testing\");\n  ASSERT_EQUAL(message->header().content_length(), 72);\n\n  std::string payload_buffer(\"nonstandard_property: 1!!1! non standard value\\r\\n\"\n                      \"wfd_audio_codecs: none\\r\\n\");\n  Driver::Parse(payload_buffer, message);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> property;\n\n  ASSERT_NO_EXCEPTION (property =\n      payload->GetProperty(wds::rtsp::AudioCodecsPropertyType));\n  ASSERT(property->is_none());\n\n  ASSERT_NO_EXCEPTION (property =\n      payload->GetProperty(\"nonstandard_property\"));\n  auto extra_property = std::static_pointer_cast<wds::rtsp::GenericProperty>(property);\n  ASSERT_EQUAL(extra_property->value(), \"1!!1! non standard value\");\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_extra_errors ()\n{\n  std::string header(\"RTSP/1.0 303 OK\\r\\n\"\n                     \"CSeq: 0\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 55\\r\\n\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  std::string payload_buffer(\"wfd_audio_codecs: 103\\r\\n\"\n                      \"nonstandard_property: 101, 102\\r\\n\");\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n\n  auto payload = ToPropertyErrorPayload(message->payload());\n  ASSERT(payload);\n\n  std::shared_ptr<wds::rtsp::PropertyErrors> error;\n\n  ASSERT_EQUAL(payload->property_errors().size(), 2);\n\n  ASSERT_NO_EXCEPTION(error =\n      payload->GetPropertyError(wds::rtsp::AudioCodecsPropertyType));\n  ASSERT_EQUAL(error->error_codes().size(), 1);\n  ASSERT_EQUAL(error->error_codes()[0], 103);\n\n  ASSERT_NO_EXCEPTION(error =\n      payload->GetPropertyError(\"nonstandard_property\"));\n  ASSERT_EQUAL(error->error_codes().size(), 2);\n  ASSERT_EQUAL(error->error_codes()[0], 101);\n  ASSERT_EQUAL(error->error_codes()[1], 102);\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_extra_properties_in_get ()\n{\n  std::string header(\"GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 40\\r\\n\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodGetParameter);\n\n  std::string payload_buffer(\"nonstandard_property\\r\\n\"\n                             \"wfd_audio_codecs\\r\\n\");\n  Driver::Parse(payload_buffer, message);\n  auto payload = ToGetParameterPayload(message->payload());\n  ASSERT(payload);\n  auto properties = payload->properties();\n  ASSERT(property_type_exists (properties, wds::rtsp::AudioCodecsPropertyType));\n  ASSERT_EQUAL(properties.size(), 2);\n  ASSERT_EQUAL(properties[0], \"nonstandard_property\");\n  ASSERT_EQUAL(properties[1], \"wfd_audio_codecs\");\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_get_parameter ()\n{\n  std::string header(\"GET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 213\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_client_rtp_ports\\r\\n\"\n                      \"wfd_audio_codecs\\r\\n\"\n                      \"wfd_video_formats\\r\\n\"\n                      \"wfd_3d_video_formats\\r\\n\"\n                      \"wfd_coupled_sink\\r\\n\"\n                      \"wfd_display_edid\\r\\n\"\n                      \"wfd_connector_type\\r\\n\"\n                      \"wfd_uibc_capability\\r\\n\"\n                      \"wfd_standby_resume_capability\\r\\n\"\n                      \"wfd_content_protection\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodGetParameter);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://localhost/wfd1.0\");\n  ASSERT_EQUAL(message->header().cseq(), 2);\n  ASSERT_EQUAL(message->header().content_length(), 213);\n  ASSERT_EQUAL(message->header().content_type(), \"text/parameters\");\n  ASSERT_EQUAL(message->header().require_wfd_support(), false);\n  auto payload = ToGetParameterPayload(message->payload());\n  ASSERT(payload);\n  std::vector<std::string> properties = payload->properties();\n  ASSERT(property_type_exists (properties, wds::rtsp::ClientRTPPortsPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::ClientRTPPortsPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::AudioCodecsPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::VideoFormatsPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::Video3DFormatsPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::CoupledSinkPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::DisplayEdidPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::ConnectorTypePropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::UIBCCapabilityPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::StandbyResumeCapabilityPropertyType));\n  ASSERT(property_type_exists (properties, wds::rtsp::ContentProtectionPropertyType));\n\n  ASSERT_EQUAL (message->ToString(), header + payload_buffer)\n\n  return true;\n}\n\nstatic bool test_valid_get_parameter_reply_with_all_none ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 483\\r\\n\\r\\n\");\n  // not a real-world message, just a collection of all properties\n  std::string payload_buffer(\"wfd_3d_video_formats: none\\r\\n\"\n                      \"wfd_I2C: none\\r\\n\"\n                      \"wfd_audio_codecs: none\\r\\n\"\n                      \"wfd_av_format_change_timing: 000000000F 00000000FF\\r\\n\"\n                      \"wfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\\r\\n\"\n                      \"wfd_connector_type: none\\r\\n\"\n                      \"wfd_content_protection: none\\r\\n\"\n                      \"wfd_coupled_sink: none\\r\\n\"\n                      \"wfd_display_edid: none\\r\\n\"\n                      \"wfd_presentation_URL: none none\\r\\n\"\n                      \"wfd_route: primary\\r\\n\"\n                      \"wfd_standby_resume_capability: none\\r\\n\"\n                      \"wfd_trigger_method: TEARDOWN\\r\\n\"\n                      \"wfd_uibc_capability: none\\r\\n\"\n                      \"wfd_uibc_setting: disable\\r\\n\"\n                      \"wfd_video_formats: none\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n\n  wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n  ASSERT(reply != NULL);\n  ASSERT_EQUAL(reply->response_code(), 200);\n  ASSERT_EQUAL(reply->header().cseq(), 2);\n  ASSERT_EQUAL(reply->header().content_length(), 483);\n  ASSERT_EQUAL(reply->header().content_type(), \"text/parameters\");\n  ASSERT_EQUAL(reply->header().supported_methods().size(), 0);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::AudioCodecsPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::VideoFormatsPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::Video3DFormatsPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ContentProtectionPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::DisplayEdidPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::CoupledSinkPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::UIBCCapabilityPropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ConnectorTypePropertyType));\n  ASSERT(prop->is_none());\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::StandbyResumeCapabilityPropertyType));\n  ASSERT(prop->is_none());\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::AVFormatChangeTimingPropertyType));\n  auto av_format_change_timing = std::static_pointer_cast<wds::rtsp::AVFormatChangeTiming> (prop);\n  ASSERT_EQUAL(av_format_change_timing->pts(), 0x000000000F);\n  ASSERT_EQUAL(av_format_change_timing->dts(), 0x00000000FF);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ClientRTPPortsPropertyType));\n  auto client_rtp_ports = std::static_pointer_cast<wds::rtsp::ClientRtpPorts> (prop);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_0(), 19000);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_1(), 0);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::TriggerMethodPropertyType));\n  auto trigger_method = std::static_pointer_cast<wds::rtsp::TriggerMethod> (prop);\n  ASSERT_EQUAL(trigger_method->method(), wds::rtsp::TriggerMethod::TEARDOWN);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::PresentationURLPropertyType));\n  auto presentation_url = std::static_pointer_cast<wds::rtsp::PresentationUrl> (prop);\n  ASSERT_EQUAL(presentation_url->presentation_url_1(), \"\");\n  ASSERT_EQUAL(presentation_url->presentation_url_2(), \"\");\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::RoutePropertyType));\n  auto route = std::static_pointer_cast<wds::rtsp::Route> (prop);\n  ASSERT_EQUAL(route->destination(), wds::rtsp::Route::PRIMARY);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::I2CPropertyType));\n  auto i2c = std::static_pointer_cast<wds::rtsp::I2C> (prop);\n  ASSERT_EQUAL(i2c->is_supported(), false);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::UIBCSettingPropertyType));\n  auto uibc_setting = std::static_pointer_cast<wds::rtsp::UIBCSetting> (prop);\n  ASSERT_EQUAL(uibc_setting->is_enabled(), false);\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_get_parameter_reply ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 535\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_3d_video_formats: 80 00 03 0F 0000000000000005 00 0001 1401 13 none none\\r\\n\"\n                      \"wfd_I2C: 404\\r\\n\"\n                      \"wfd_audio_codecs: LPCM 00000003 00, AAC 00000001 00\\r\\n\"\n                      \"wfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\\r\\n\"\n                      \"wfd_connector_type: 05\\r\\n\"\n                      \"wfd_content_protection: HDCP2.1 port=1189\\r\\n\"\n                      \"wfd_coupled_sink: none\\r\\n\"\n                      \"wfd_display_edid: none\\r\\n\"\n                      \"wfd_standby_resume_capability: supported\\r\\n\"\n                      \"wfd_uibc_capability: none\\r\\n\"\n                      \"wfd_video_formats: 40 01 02 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 0400 0300, 01 04 0001DEFF 053C7FFF 00000FFF 00 0000 0000 11 0400 0300\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n\n  wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n  ASSERT(reply != NULL);\n  ASSERT_EQUAL(reply->response_code(), 200);\n  ASSERT_EQUAL(reply->header().cseq(), 2);\n  ASSERT_EQUAL(reply->header().content_length(), 535);\n  ASSERT_EQUAL(reply->header().content_type(), \"text/parameters\");\n  ASSERT_EQUAL(reply->header().supported_methods().size(), 0);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::AudioCodecsPropertyType));\n\n  // Test that all properties exist\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::AudioCodecsPropertyType));\n  std::shared_ptr<wds::rtsp::AudioCodecs> audio_codecs = std::static_pointer_cast<wds::rtsp::AudioCodecs> (prop);\n  ASSERT_EQUAL(audio_codecs->audio_codecs().size(), 2);\n  ASSERT(test_audio_codec (audio_codecs->audio_codecs()[0],\n                           wds::LPCM, 3, 0));\n  ASSERT(test_audio_codec (audio_codecs->audio_codecs()[1],\n                           wds::AAC, 1, 0));\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::VideoFormatsPropertyType));\n  std::shared_ptr<wds::rtsp::VideoFormats> video_formats = std::static_pointer_cast<wds::rtsp::VideoFormats> (prop);\n  ASSERT_EQUAL(video_formats->GetNativeFormat().rate_resolution, 8);\n  ASSERT_EQUAL(video_formats->GetNativeFormat().type, 0);\n  ASSERT_EQUAL(video_formats->GetH264Formats().size(), 96);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::Video3DFormatsPropertyType));\n  std::shared_ptr<wds::rtsp::Formats3d> formats_3d = std::static_pointer_cast<wds::rtsp::Formats3d> (prop);\n\n  ASSERT_EQUAL(formats_3d->native_resolution(), 0x80);\n  ASSERT_EQUAL(formats_3d->preferred_display_mode(), 0);\n  ASSERT_EQUAL(formats_3d->codecs().size(), 1);\n  ASSERT(test_h264_codec_3d (formats_3d->codecs()[0],\n                             0x03, 0x0F, 0x0000000000000005, 0, 0x0001, 0x1401, 0x13, 0, 0));\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ContentProtectionPropertyType));\n  std::shared_ptr<wds::rtsp::ContentProtection> content_protection = std::static_pointer_cast<wds::rtsp::ContentProtection> (prop);\n  ASSERT_EQUAL(content_protection->hdcp_spec(), wds::rtsp::ContentProtection::HDCP_SPEC_2_1);\n  ASSERT_EQUAL(content_protection->port(), 1189);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::DisplayEdidPropertyType));\n  ASSERT(prop->is_none());\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::CoupledSinkPropertyType));\n  ASSERT(prop->is_none());\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ClientRTPPortsPropertyType));\n  std::shared_ptr<wds::rtsp::ClientRtpPorts> client_rtp_ports = std::static_pointer_cast<wds::rtsp::ClientRtpPorts> (prop);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_0(), 19000);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_1(), 0);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::UIBCCapabilityPropertyType));\n  ASSERT(prop->is_none());\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ConnectorTypePropertyType));\n  std::shared_ptr<wds::rtsp::ConnectorType> connector_type = std::static_pointer_cast<wds::rtsp::ConnectorType> (prop);\n  ASSERT_EQUAL(connector_type->connector_type(), 5);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::I2CPropertyType));\n  auto i2c = std::static_pointer_cast<wds::rtsp::I2C> (prop);\n  ASSERT_EQUAL(i2c->is_supported(), true);\n  ASSERT_EQUAL(i2c->port(), 404);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::StandbyResumeCapabilityPropertyType));\n  ASSERT(!prop->is_none());\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_invalid_property_value ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 1187\\r\\n\");\n  std::string payload_buffer(\"wfd_uibc_capability: none and something completely different\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message == NULL);\n\n  return true;\n}\n\nstatic bool test_case_insensitivity ()\n{\n  std::string invalid_header(\"OptionS * RTSP/1.0\\r\\n\"\n                             \"CSeq: 0\\r\\n\"\n                             \"Require: org.wfa.wfd1.0\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(invalid_header, message);\n  ASSERT(message == NULL);\n\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSEQ: 2\\r\\n\"\n                     \"Content-Type: tEXT/parameters\\r\\n\"\n                     \"Content-LENGTH: 1187\\r\\n\");\n  std::string payload_buffer(\"wfd_uibc_capABILITY: noNE\\r\\n\\r\\n\");\n\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n\n  ASSERT_EQUAL(message->header().cseq(), 2);\n  ASSERT_EQUAL(message->header().content_type(), \"tEXT/parameters\");\n  ASSERT_EQUAL(message->header().content_length(), 1187);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::UIBCCapabilityPropertyType));\n  ASSERT(prop->is_none());\n\n  // TODO test insensitivity of triggers and method list\n\n  return true;\n}\n\nstatic bool test_valid_get_parameter_reply_with_errors ()\n{\n  std::string header(\"RTSP/1.0 303 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 42\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_audio_codecs: 415, 457\\r\\n\"\n                      \"wfd_I2C: 404\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n\n  wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n  ASSERT(reply != NULL);\n  ASSERT_EQUAL(reply->response_code(), 303);\n\n  auto payload = ToPropertyErrorPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::PropertyErrors> error;\n  ASSERT_EQUAL (payload->property_errors().size(), 2);\n  ASSERT_NO_EXCEPTION(error =\n      payload->GetPropertyError(wds::rtsp::AudioCodecsPropertyType));\n  ASSERT_EQUAL(error->error_codes().size(), 2);\n  ASSERT_EQUAL(error->error_codes()[0], 415);\n  ASSERT_EQUAL(error->error_codes()[1], 457);\n\n  ASSERT_NO_EXCEPTION(error =\n      payload->GetPropertyError(wds::rtsp::I2CPropertyType));\n  ASSERT_EQUAL(error->error_codes().size(), 1);\n  ASSERT_EQUAL(error->error_codes()[0], 404);\n\n  ASSERT_EQUAL(message->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_set_parameter ()\n{\n  std::string header(\"SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 3\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 275\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_audio_codecs: AAC 00000001 00\\r\\n\"\n                      \"wfd_client_rtp_ports: RTP/AVP/UDP;unicast 19000 0 mode=play\\r\\n\"\n                      \"wfd_presentation_URL: rtsp://192.168.173.1/wfd1.0/streamid=0 none\\r\\n\"\n                      \"wfd_trigger_method: SETUP\\r\\n\"\n                      \"wfd_video_formats: 5A 00 02 04 00000020 00000000 00000000 00 0000 0000 11 none none\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodSetParameter);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://localhost/wfd1.0\");\n  ASSERT_EQUAL(request->header().cseq(), 3);\n  ASSERT_EQUAL(request->header().content_length(), 275);\n  ASSERT_EQUAL(request->header().require_wfd_support(), false);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::AudioCodecsPropertyType));\n  std::shared_ptr<wds::rtsp::AudioCodecs> audio_codecs = std::static_pointer_cast<wds::rtsp::AudioCodecs> (prop);\n  ASSERT_EQUAL(audio_codecs->audio_codecs().size(), 1);\n  ASSERT(test_audio_codec (audio_codecs->audio_codecs()[0],\n                           wds::AAC, 1, 0));\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::VideoFormatsPropertyType));\n  std::shared_ptr<wds::rtsp::VideoFormats> video_formats = std::static_pointer_cast<wds::rtsp::VideoFormats> (prop);\n  ASSERT_EQUAL(video_formats->GetNativeFormat().rate_resolution, 11);\n  ASSERT_EQUAL(video_formats->GetNativeFormat().type, 2);\n  ASSERT_EQUAL(video_formats->GetH264Formats().size(), 1);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::ClientRTPPortsPropertyType));\n  std::shared_ptr<wds::rtsp::ClientRtpPorts> client_rtp_ports = std::static_pointer_cast<wds::rtsp::ClientRtpPorts> (prop);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_0(), 19000);\n  ASSERT_EQUAL(client_rtp_ports->rtp_port_1(), 0);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::TriggerMethodPropertyType));\n  std::shared_ptr<wds::rtsp::TriggerMethod> trigger_method = std::static_pointer_cast<wds::rtsp::TriggerMethod> (prop);\n  ASSERT_EQUAL(trigger_method->method(), wds::rtsp::TriggerMethod::SETUP);\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::PresentationURLPropertyType));\n\n  ASSERT_EQUAL(request->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_set_parameter_url_with_port ()\n{\n  std::string header(\"SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 3\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 111\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_presentation_URL: rtsp://192.168.173.1:3921/wfd1.0/streamid=0 rtsp://192.168.173.1:3922/wfd1.0/streamid=1\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodSetParameter);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://localhost/wfd1.0\");\n  ASSERT_EQUAL(request->header().cseq(), 3);\n  ASSERT_EQUAL(request->header().content_length(), 111);\n  ASSERT_EQUAL(request->header().require_wfd_support(), false);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::PresentationURLPropertyType));\n\n  ASSERT_EQUAL(request->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_set_parameter_with_all_ipv4_url ()\n{\n  std::string header(\"SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 3\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 61\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_presentation_URL: rtsp://0.0.0.0/wfd1.0/streamid=0 none\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message != NULL);\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodSetParameter);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://localhost/wfd1.0\");\n  ASSERT_EQUAL(request->header().cseq(), 3);\n  ASSERT_EQUAL(request->header().content_length(), 61);\n  ASSERT_EQUAL(request->header().require_wfd_support(), false);\n\n  auto payload = ToPropertyMapPayload(message->payload());\n  ASSERT(payload);\n  std::shared_ptr<wds::rtsp::Property> prop;\n\n  ASSERT_NO_EXCEPTION (prop =\n      payload->GetProperty(wds::rtsp::PresentationURLPropertyType));\n\n  std::shared_ptr<wds::rtsp::PresentationUrl> presentation_url =\n      std::static_pointer_cast<wds::rtsp::PresentationUrl> (prop);\n\n  ASSERT_EQUAL(presentation_url->presentation_url_1(), \"rtsp://0.0.0.0/wfd1.0/streamid=0\");\n\n  ASSERT_EQUAL(request->ToString(), header + payload_buffer);\n\n  return true;\n}\n\nstatic bool test_valid_setup ()\n{\n  std::string header(\"SETUP rtsp://10.82.24.140/wfd1.0/streamid=0 RTSP/1.0\\r\\n\"\n                      \"CSeq: 4\\r\\n\"\n                      \"Transport: RTP/AVP/UDP;unicast;client_port=19000\\r\\n\"\n                      \"User-Agent: SEC-WDH/ME29\\r\\n\"\n                      \"\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodSetup);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://10.82.24.140/wfd1.0/streamid=0\");\n  ASSERT_EQUAL(request->header().cseq(), 4);\n  ASSERT_EQUAL(request->header().content_length(), 0);\n  ASSERT_EQUAL(request->header().require_wfd_support(), false);\n\n  ASSERT_EQUAL(request->header().transport().client_port(), 19000);\n  ASSERT_EQUAL(request->header().transport().client_supports_rtcp(), false);\n  ASSERT_EQUAL(request->header().transport().server_port(), 0);\n  ASSERT_EQUAL(request->header().transport().server_supports_rtcp(), false);\n\n  ASSERT_EQUAL(request->ToString(), header);\n\n  return true;\n}\n\nstatic bool test_valid_setup_reply ()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 4\\r\\n\"\n                     \"Session: 6B8B4567;timeout=30\\r\\n\"\n                     \"Transport: RTP/AVP/UDP;unicast;client_port=19000;server_port=5000-5001\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  wds::rtsp::Reply* reply = static_cast<wds::rtsp::Reply*>(message.get());\n  ASSERT(reply != NULL);\n\n  ASSERT_EQUAL(reply->response_code(), 200);\n  ASSERT_EQUAL(reply->header().cseq(), 4);\n  ASSERT_EQUAL(reply->header().content_length(), 0);\n  ASSERT_EQUAL(reply->header().session(), \"6B8B4567\");\n  ASSERT_EQUAL(reply->header().timeout(), 30);\n\n  ASSERT_EQUAL(reply->header().transport().client_port(), 19000);\n  ASSERT_EQUAL(reply->header().transport().client_supports_rtcp(), false);\n  ASSERT_EQUAL(reply->header().transport().server_port(), 5000);\n  ASSERT_EQUAL(reply->header().transport().server_supports_rtcp(), true);\n\n  ASSERT_EQUAL(reply->ToString(), header);\n\n  return true;\n}\n\nstatic bool test_valid_play ()\n{\n  std::string header(\"PLAY rtsp://localhost/wfd1.0 RTSP/1.0\\r\\n\"\n                     \"CSeq: 5\\r\\n\"\n                     \"Session: 6B8B4567\\r\\n\"\n                     \"User-Agent: SEC-WDH/ME29\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_request());\n  wds::rtsp::Request* request = wds::rtsp::ToRequest(message.get());\n  ASSERT_EQUAL(request->method(), wds::rtsp::Request::MethodPlay);\n  ASSERT_EQUAL(request->request_uri(), \"rtsp://localhost/wfd1.0\");\n  ASSERT_EQUAL(request->header().cseq(), 5);\n  ASSERT_EQUAL(request->header().content_length(), 0);\n  ASSERT_EQUAL(request->header().require_wfd_support(), false);\n  ASSERT_EQUAL(request->header().session(), \"6B8B4567\");\n\n  ASSERT_EQUAL(request->ToString(), header);\n\n  return true;\n}\n\nstatic bool test_number_conversion_header()\n{\n  std::string header(\"OPTIONS * RTSP/1.0\\r\\n\"\n                     \"CSeq: 92233720368547758079223372036854775807\\r\\n\"\n                     \"Require: org.wfa.wfd1.0\\r\\n\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message == NULL);\n  return true;\n}\n\nstatic bool test_number_conversion_body()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 101\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_client_rtp_ports: RTP/AVP/UDP;unicast 92233720368547758079223372036854775807 0 mode=play\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message == NULL);\n\n  return true;\n}\n\nstatic bool test_hex_number_conversion_body()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 101\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_audio_codecs: AAC 92233720368547758079223372036854775807 00\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message == NULL);\n\n  return true;\n}\n\nstatic bool test_hex_number_conversion_body_2()\n{\n  std::string header(\"RTSP/1.0 200 OK\\r\\n\"\n                     \"CSeq: 2\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 101\\r\\n\\r\\n\");\n  std::string payload_buffer(\"wfd_audio_codecs: AAC FFFFFFFFFFFFFFFFF 00\\r\\n\");\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message == NULL);\n\n  return true;\n}\n\nstatic bool test_number_conversion_in_errors ()\n{\n  std::string header(\"RTSP/1.0 303 OK\\r\\n\"\n                     \"CSeq: 0\\r\\n\"\n                     \"Content-Type: text/parameters\\r\\n\"\n                     \"Content-Length: 55\\r\\n\\r\\n\");\n\n  std::unique_ptr<wds::rtsp::Message> message;\n  Driver::Parse(header, message);\n  ASSERT(message != NULL);\n  ASSERT(message->is_reply());\n\n  std::string payload_buffer(\"wfd_audio_codecs: 92233720368547758079223372036854775807\\r\\n\");\n  Driver::Parse(payload_buffer, message);\n  ASSERT(message == NULL);\n\n  return true;\n}\n\nint main(const int argc, const char **argv)\n{\n  std::list<TestFunc> tests;\n  int failures = 0;\n\n  // Add tests\n  tests.push_back(test_valid_options);\n  tests.push_back(test_valid_options_reply);\n  tests.push_back(test_valid_get_parameter);\n  tests.push_back(test_valid_get_parameter_reply);\n  tests.push_back(test_valid_get_parameter_reply_with_all_none);\n  tests.push_back(test_valid_get_parameter_reply_with_errors);\n  tests.push_back(test_valid_setup_reply);\n  tests.push_back(test_valid_set_parameter);\n  tests.push_back(test_valid_set_parameter_url_with_port);\n  tests.push_back(test_valid_set_parameter_with_all_ipv4_url);\n  tests.push_back(test_valid_setup);\n  tests.push_back(test_valid_play);\n  tests.push_back(test_invalid_property_value);\n  tests.push_back(test_case_insensitivity);\n  tests.push_back(test_valid_extra_properties);\n  tests.push_back(test_valid_extra_errors);\n  tests.push_back(test_valid_extra_properties_in_get);\n  tests.push_back(test_number_conversion_header);\n  tests.push_back(test_number_conversion_body);\n  tests.push_back(test_hex_number_conversion_body);\n  tests.push_back(test_hex_number_conversion_body_2);\n  tests.push_back(test_number_conversion_in_errors);\n\n  // Run tests\n  for (std::list<TestFunc>::iterator it=tests.begin(); it!=tests.end(); ++it) {\n    TestFunc test = *it;\n    if (!test())\n      failures++;\n  }\n\n  if (failures > 0) {\n    std::cout << std::endl << \"Failed \" << failures\n              << \" out of \" << tests.size() << \" tests\" << std::endl;\n    return 1;\n  }\n\n  std::cout << \"Passed all \" << tests.size() << \" tests\" << std::endl;\n  return 0;\n}\n"
  },
  {
    "path": "libwds/rtsp/tests/wdsfuzzer.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2016 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <string.h>\n#include <iostream>\n#include <fstream>\n\n#include \"libwds/rtsp/driver.h\"\n#include \"libwds/rtsp/message.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/getparameter.h\"\n\nusing wds::rtsp::Driver;\n\nnamespace {\nconst char kTestHeaderCommand[] = \"--header\";\nconst char kTestPayloadRequestCommand[] = \"--payload-request\";\nconst char kTestPayloadReplyCommand[] = \"--payload-reply\";\nconst char kTestPayloadErrorCommand[] = \"--payload-error\";\nconst char kTestNumLinesCommand[] = \"--num-lines\";\nconst char kTestTestCaseCommand[] = \"--test-case\";\n\nint PrintError(const char* program) {\n  std::cerr << \"Usage: \" << program << \" [--num-lines NUM | --test-case ABSOLUTE_PATH_FILE] [--header | --payload-request | --payload-reply | --payload-error]\" << std::endl;\n  std::cerr << \"Example: \" << program << \" --num-lines 6 --header\" << std::endl;\n  std::cerr << \"Example: \" << program << \" --test-case test-options-request.txt --header\" << std::endl;\n  return 1;\n}\n\nstd::string GetBufferFromStdin(int num_lines) {\n  std::string buffer, input;\n  while(num_lines--) {\n    getline(std::cin, input);\n    buffer += input;\n    if (num_lines)\n      buffer += \"\\r\\n\";\n  }\n  return buffer;\n}\n\nstd::string GetBufferFromFile(const std::string& file) {\n  std::string line, buffer;\n  std::ifstream input_stream(file);\n  if (input_stream.is_open()) {\n    while (getline(input_stream, line))\n      buffer += line;\n    input_stream.close();\n  }\n  return buffer;\n}\n\n}  // namespace\n\nint main(const int argc, const char **argv)\n{\n  // Program name, number of lines to be read, type of message\n  if (argc < 4)\n    return PrintError(argv[0]);\n\n  std::string buffer;\n  if (strncmp(argv[1], kTestNumLinesCommand, strlen(kTestNumLinesCommand)) == 0)\n    buffer = GetBufferFromStdin(atoi(argv[2])) + \"\\r\\n\\r\\n\";\n  else if (strncmp(argv[1], kTestTestCaseCommand, strlen(kTestTestCaseCommand)) == 0)\n    buffer = GetBufferFromFile(argv[2]);\n  else\n    return PrintError(argv[0]);\n\n  std::unique_ptr<wds::rtsp::Message> message;\n\n  if (strcmp(argv[3], kTestHeaderCommand) == 0) {\n    Driver::Parse(buffer, message);\n  } else if (strcmp(argv[3], kTestPayloadReplyCommand) == 0) {\n    message.reset(new wds::rtsp::Reply());\n    Driver::Parse(buffer, message);\n  } else if (strcmp(argv[3], kTestPayloadRequestCommand) == 0) {\n    message.reset(new wds::rtsp::GetParameter(\"rtsp://localhost/wfd1.0\"));\n    Driver::Parse(buffer, message);\n  } else if (strcmp(argv[3], kTestPayloadErrorCommand) == 0) {\n    message.reset(new wds::rtsp::Reply(303));\n    Driver::Parse(buffer, message);\n  } else {\n    return PrintError(argv[0]);\n  }\n\n  return 0;\n}\n"
  },
  {
    "path": "libwds/rtsp/transportheader.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/transportheader.h\"\n#include \"libwds/rtsp/constants.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n  const char kTransport[] = \"Transport: RTP/AVP/UDP;unicast;client_port=\";\n  const char kServerPort[] = \";server_port=\";\n}\n\nTransportHeader::TransportHeader() :\n  client_port_(0),\n  server_port_(0),\n  client_supports_rtcp_(false),\n  server_supports_rtcp_(false) {\n\n}\n\nTransportHeader::~TransportHeader() {\n}\n\nunsigned int TransportHeader::client_port() const {\n  return client_port_;\n}\n\nvoid TransportHeader::set_client_port(unsigned int client_port) {\n  client_port_ = client_port;\n}\n\nunsigned int TransportHeader::server_port() const {\n  return server_port_;\n}\n\nvoid TransportHeader::set_server_port(unsigned int server_port) {\n  server_port_ = server_port;\n}\n\nbool TransportHeader::client_supports_rtcp() const {\n  return client_supports_rtcp_;\n}\n\nvoid TransportHeader::set_client_supports_rtcp(bool client_supports_rtcp) {\n  client_supports_rtcp_ = client_supports_rtcp;\n}\n\nbool TransportHeader::server_supports_rtcp() const {\n  return server_supports_rtcp_;\n}\n\nvoid TransportHeader::set_server_supports_rtcp(bool server_supports_rtcp) {\n  server_supports_rtcp_ = server_supports_rtcp;\n}\n\nstd::string TransportHeader::ToString() const {\n  std::string ret;\n\n  if (client_port_ > 0) {\n    ret += kTransport + std::to_string(client_port_);\n    if (client_supports_rtcp_)\n      ret += \"-\" + std::to_string(client_port_ + 1);\n\n    if (server_port_ > 0) {\n      ret += kServerPort + std::to_string(server_port_);\n      if (server_supports_rtcp_)\n        ret += \"-\" + std::to_string(server_port_ + 1);\n    }\n\n    ret += CRLF;\n  }\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/transportheader.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_TRANSPORT_HEADER_H_\n#define LIBWDS_RTSP_TRANSPORT_HEADER_H_\n\n#include <string>\n\nnamespace wds {\nnamespace rtsp {\n\nclass TransportHeader {\n  public:\n    TransportHeader();\n    virtual ~TransportHeader();\n\n    unsigned int client_port() const;\n    void set_client_port(unsigned int client_port);\n\n    unsigned int server_port() const;\n    void set_server_port(unsigned int server_port);\n\n    bool client_supports_rtcp() const;\n    void set_client_supports_rtcp(bool client_supports_rtcp);\n\n    bool server_supports_rtcp() const;\n    void set_server_supports_rtcp(bool server_supports_rtcp);\n\n    std::string ToString() const;\n\n private:\n    unsigned int client_port_;\n    unsigned int server_port_;\n    bool client_supports_rtcp_;\n    bool server_supports_rtcp_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif // LIBWDS_RTSP_TRANSPORT_HEADER_H_\n"
  },
  {
    "path": "libwds/rtsp/triggermethod.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/triggermethod.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\nconst char* name[] = {MethodName::SETUP, MethodName::PAUSE,\n    MethodName::TEARDOWN, MethodName::PLAY};\n}\n\nTriggerMethod::TriggerMethod(TriggerMethod::Method method)\n: Property(TriggerMethodPropertyType),\n  method_(method) {\n}\n\nTriggerMethod::~TriggerMethod() {\n}\n\nstd::string TriggerMethod::ToString() const {\n  std::string ret =\n      PropertyName::wfd_trigger_method + std::string(SEMICOLON)\n    + std::string(SPACE) + name[method()];\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/triggermethod.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_TRIGGERMETHOD_H_\n#define LIBWDS_RTSP_TRIGGERMETHOD_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass TriggerMethod : public Property {\n public:\n  enum Method {\n    SETUP,\n    PAUSE,\n    TEARDOWN,\n    PLAY\n  };\n\n public:\n  explicit TriggerMethod(TriggerMethod::Method method);\n  ~TriggerMethod() override;\n\n  TriggerMethod::Method method() const { return method_; }\n  std::string ToString() const override;\n\n private:\n  TriggerMethod::Method method_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_TRIGGERMETHOD_H_\n"
  },
  {
    "path": "libwds/rtsp/uibccapability.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/uibccapability.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\n\nconst char kInputCategoryGeneric[] = \"GENERIC\";\nconst char kInputCategoryHIDC[] = \"HIDC\";\nconst char kInputCategoryList[] = \"input_category_list=\";\nconst char* kInputCategories[] = { kInputCategoryGeneric, kInputCategoryHIDC };\n\nconst char kInputTypeKeyboard[] = \"Keyboard\";\nconst char kInputTypeMouse[] = \"Mouse\";\nconst char kInputTypeSingleTouch[] = \"SingleTouch\";\nconst char kInputTypeMultiTouch[] = \"MultiTouch\";\nconst char kInputTypeJoystick[] = \"Joystick\";\nconst char kInputTypeCamera[] = \"Camera\";\nconst char kInputTypeGesture[] = \"Gesture\";\nconst char kInputTypeRemoteControl[] = \"RemoteControl\";\nconst char kInputGenericCapabilityList[] = \"generic_cap_list=\";\n\nconst char* kInputTypes[] =\n  { kInputTypeKeyboard,\n    kInputTypeMouse,\n    kInputTypeSingleTouch,\n    kInputTypeMultiTouch,\n    kInputTypeJoystick,\n    kInputTypeCamera,\n    kInputTypeGesture,\n    kInputTypeRemoteControl\n  };\n\nconst char kInputPathInfrared[] = \"Infrared\";\nconst char kInputPathUSB[] = \"USB\";\nconst char kInputPathBT[] = \"BT\";\nconst char kInputPathZigbee[] = \"Zigbee\";\nconst char kInputPathWiFi[] = \"Wi-Fi\";\nconst char kInputPathNoSP[] = \"No-SP\";\nconst char kHIDCCapabilityList[] = \"hidc_cap_list=\";\n\nconst char* kInputPaths[] =\n  { kInputPathInfrared,\n    kInputPathUSB,\n    kInputPathBT,\n    kInputPathZigbee,\n    kInputPathWiFi,\n    kInputPathNoSP\n  };\n\n}\n\nUIBCCapability::UIBCCapability()\n  : Property(UIBCCapabilityPropertyType, true) {\n}\n\nUIBCCapability::UIBCCapability(\n    const std::vector<InputCategory>& input_categories,\n    const std::vector<InputType>& generic_capabilities,\n    const std::vector<DetailedCapability> hidc_capabilities,\n    int tcp_port)\n  : Property(UIBCCapabilityPropertyType),\n    input_categories_(input_categories),\n    generic_capabilities_(generic_capabilities),\n    hidc_capabilities_(hidc_capabilities),\n    tcp_port_(tcp_port) {\n}\n\nUIBCCapability::~UIBCCapability() {\n}\n\nstd::string UIBCCapability::ToString() const {\n  std::string ret;\n  ret = PropertyName::wfd_uibc_capability + std::string(SEMICOLON)\n  + std::string(SPACE);\n\n  if (is_none())\n    return ret + NONE;\n\n  ret += kInputCategoryList;\n  auto inp_cat_i = input_categories_.begin();\n  auto inp_cat_end = input_categories_.end();\n\n  if (input_categories_.empty())\n    ret += NONE;\n\n  while (inp_cat_i != inp_cat_end) {\n    ret += kInputCategories[*inp_cat_i];\n\n    if(inp_cat_i != --input_categories_.end())\n      ret += std::string(\",\") + std::string(SPACE);\n    else\n      ret += std::string(\";\");\n\n    ++inp_cat_i;\n  }\n\n  ret += kInputGenericCapabilityList;\n  auto gen_cap_i = generic_capabilities_.begin();\n  auto gen_cap_end = generic_capabilities_.end();\n\n  if (generic_capabilities_.empty())\n    ret += NONE;\n\n  while (gen_cap_i != gen_cap_end) {\n    ret += kInputTypes[*gen_cap_i];\n\n    if(gen_cap_i != --generic_capabilities_.end())\n      ret += std::string(\",\") + std::string(SPACE);\n    else\n      ret += std::string(\";\");\n\n    ++gen_cap_i;\n  }\n\n  ret += kHIDCCapabilityList;\n  auto hidc_cap_i = hidc_capabilities_.begin();\n  auto hidc_cap_end = hidc_capabilities_.end();\n\n  if (hidc_capabilities_.empty())\n    ret += NONE;\n\n  while (hidc_cap_i != hidc_cap_end) {\n    ret += kInputTypes[(*hidc_cap_i).first]\n         + std::string(\"/\") + kInputPaths[(*hidc_cap_i).second];\n\n    if(hidc_cap_i != --hidc_capabilities_.end())\n      ret += std::string(\",\") + std::string(SPACE);\n    else\n      ret += std::string(\";\");\n\n    ++hidc_cap_i;\n  }\n\n  ret += tcp_port_ > 0 ? std::string(\"port=\") + std::to_string(tcp_port_)\n                       : NONE;\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/uibccapability.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_UIBCCAPABILITY_H_\n#define LIBWDS_RTSP_UIBCCAPABILITY_H_\n\n#include \"libwds/rtsp/property.h\"\n\n#include <vector>\n#include <utility>\n\nnamespace wds {\nnamespace rtsp {\n\nclass UIBCCapability: public Property {\n public:\n  enum InputCategory {\n    GENERIC,\n    HIDC\n  };\n\n  enum InputType {\n    KEYBOARD,\n    MOUSE,\n    SINGLE_TOUCH,\n    MULTI_TOUCH,\n    JOYSTICK,\n    CAMERA,\n    GESTURE,\n    REMOTE_CONTROL\n  };\n\n  enum InputPath {\n    INFRARED,\n    USB,\n    BT,\n    ZIGBEE,\n    WI_FI,\n    NO_SP\n  };\n\n typedef std::pair<InputType, InputPath> DetailedCapability;\n\n public:\n  UIBCCapability();\n  UIBCCapability(const std::vector<InputCategory>& input_categories,\n      const std::vector<InputType>& generic_capabilities,\n      const std::vector<DetailedCapability> hidc_capabilities,\n      int tcp_port);\n  ~UIBCCapability() override;\n\n  std::string ToString() const override;\n\n private:\n\n  std::vector<InputCategory> input_categories_;\n  std::vector<InputType> generic_capabilities_;\n  std::vector<DetailedCapability> hidc_capabilities_;\n  int tcp_port_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_UIBCCAPABILITY_H_\n"
  },
  {
    "path": "libwds/rtsp/uibcsetting.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include \"libwds/rtsp/uibcsetting.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\nconst char enable[] = \"enable\";\nconst char disable[] = \"disable\";\n}\n\nUIBCSetting::UIBCSetting(bool is_enabled)\n  : Property(UIBCSettingPropertyType),\n    is_enabled_(is_enabled) {\n\n}\n\nUIBCSetting::~UIBCSetting() {\n}\n\nstd::string UIBCSetting::ToString() const {\n  std::string ret =\n      PropertyName::wfd_uibc_setting + std::string(SEMICOLON)\n     + std::string(SPACE) + (is_enabled() ? enable : disable);\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/uibcsetting.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_UIBCSETTING_H_\n#define LIBWDS_RTSP_UIBCSETTING_H_\n\n#include \"libwds/rtsp/property.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nclass UIBCSetting : public Property {\n public:\n  explicit UIBCSetting(bool is_enabled);\n  ~UIBCSetting() override;\n\n  bool is_enabled() const { return is_enabled_; }\n  std::string ToString() const override;\n\n private:\n  bool is_enabled_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n#endif  // LIBWDS_RTSP_UIBCSETTING_H_\n"
  },
  {
    "path": "libwds/rtsp/videoformats.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/rtsp/videoformats.h\"\n\n#include <cassert>\n\n#include \"libwds/rtsp/macros.h\"\n\nnamespace wds {\nnamespace rtsp {\n\nnamespace {\ntemplate <typename EnumType>\nunsigned int EnumListToMask(const std::vector<EnumType>& from) {\n  unsigned int result = 0;\n\n  for (auto item : from) {\n    result = result | (1 << item);\n  }\n\n  return result;\n}\n} //namespace\n\nusing wds::H264VideoFormat;\nusing wds::H264VideoCodec;\n\nH264Codec::H264Codec(unsigned char profile, unsigned char level,\n    unsigned int cea_support, unsigned int vesa_support,\n    unsigned int hh_support, unsigned char latency,\n    unsigned short min_slice_size, unsigned short slice_enc_params,\n    unsigned char frame_rate_control_support,\n    unsigned short max_hres, unsigned short max_vres)\n  : profile(profile),\n    level(level),\n    cea_support(cea_support),\n    vesa_support(vesa_support),\n    hh_support(hh_support),\n    latency(latency),\n    min_slice_size(min_slice_size),\n    slice_enc_params(slice_enc_params),\n    frame_rate_control_support(frame_rate_control_support),\n    max_hres(max_hres),\n    max_vres(max_vres) {}\n\nH264Codec::H264Codec(const H264VideoFormat& format)\n  : profile(1 << format.profile),\n    level(1 << format.level),\n    cea_support((format.type == CEA) ? 1 << format.rate_resolution : 0),\n    vesa_support((format.type == VESA) ? 1 << format.rate_resolution : 0),\n    hh_support((format.type == HH) ? 1 << format.rate_resolution : 0),\n    latency(0),\n    min_slice_size(0),\n    slice_enc_params(0),\n    frame_rate_control_support(0),\n    max_hres(0),\n    max_vres(0) {\n\n}\n\nH264Codec::H264Codec(const H264VideoCodec& format)\n  : profile(1 << format.profile),\n    level(1 << format.level),\n    cea_support(format.cea_rr.to_ulong()),\n    vesa_support(format.vesa_rr.to_ulong()),\n    hh_support(format.hh_rr.to_ulong()),\n    latency(0),\n    min_slice_size(0),\n    slice_enc_params(0),\n    frame_rate_control_support(0),\n    max_hres(0),\n    max_vres(0) {\n\n}\n\n\nstd::string H264Codec::ToString() const {\n  std::string ret;\n  MAKE_HEX_STRING_2(profile_str, profile);\n  MAKE_HEX_STRING_2(level_str, level);\n  MAKE_HEX_STRING_8(cea_support_str, cea_support);\n  MAKE_HEX_STRING_8(vesa_support_str, vesa_support);\n  MAKE_HEX_STRING_8(hh_support_str, hh_support);\n  MAKE_HEX_STRING_2(latency_str, latency);\n  MAKE_HEX_STRING_4(min_slice_size_str, min_slice_size);\n  MAKE_HEX_STRING_4(slice_enc_params_str, slice_enc_params);\n  MAKE_HEX_STRING_2(frame_rate_control_support_str, frame_rate_control_support);\n\n  ret = profile_str + std::string(SPACE)\n      + level_str + std::string(SPACE)\n      + cea_support_str + std::string(SPACE)\n      + vesa_support_str + std::string(SPACE)\n      + hh_support_str + std::string(SPACE)\n      + latency_str + std::string(SPACE)\n      + min_slice_size_str + std::string(SPACE)\n      + slice_enc_params_str + std::string(SPACE)\n      + frame_rate_control_support_str + std::string(SPACE);\n\n  if (max_hres > 0) {\n    MAKE_HEX_STRING_4(max_hres_str, max_hres);\n    ret += max_hres_str;\n  } else {\n    ret += NONE;\n  }\n  ret += std::string(SPACE);\n\n  if (max_vres > 0) {\n    MAKE_HEX_STRING_4(max_vres_str, max_vres);\n    ret += max_vres_str;\n  } else {\n    ret += NONE;\n  }\n\n  return ret;\n}\n\nnamespace {\n\ntemplate <typename EnumType, typename ArgType>\nEnumType MaskToEnum(ArgType from, EnumType biggest_value) {\n  assert(from != 0);\n  ArgType copy = from;\n  unsigned result = 0;\n  while ((copy & 1) == 0 && copy != 0) {\n    copy = copy >> 1;\n    ++result;\n  }\n  if (result > static_cast<unsigned>(biggest_value)) {\n    assert(false);\n    return biggest_value;\n  }\n  return static_cast<EnumType>(result);\n}\n\ntemplate <typename EnumType, typename ArgType>\nstd::vector<EnumType> MaskToEnumList(ArgType from, EnumType biggest_value) {\n  assert(from != 0);\n  ArgType copy = from;\n  unsigned enum_value = 0;\n  std::vector<EnumType> result;\n\n  while (copy != 0) {\n    if ((copy & 1) != 0) {\n      if (enum_value > static_cast<unsigned>(biggest_value))\n        break;\n\n      result.push_back(static_cast<EnumType>(enum_value));\n    }\n    copy = copy >> 1;\n    ++enum_value;\n  }\n\n  return result;\n}\n\ninline H264Profile ToH264Profile(unsigned char profile) {\n  return MaskToEnum<H264Profile>(profile, CHP);\n}\n\ninline H264Level ToH264Level(unsigned char level) {\n  return MaskToEnum<H264Level>(level, k4_2);\n}\n\n}  // namespace\n\nH264VideoCodec H264Codec::ToH264VideoCodec() const {\n  H264VideoCodec result;\n  result.profile = ToH264Profile(profile);\n  result.level = ToH264Level(level);\n  result.cea_rr = RateAndResolutionsBitmap(cea_support);\n  result.vesa_rr = RateAndResolutionsBitmap(vesa_support);\n  result.hh_rr = RateAndResolutionsBitmap(hh_support);\n  return result;\n}\n\nVideoFormats::VideoFormats() : Property(VideoFormatsPropertyType, true) {\n}\n\nVideoFormats::VideoFormats(NativeVideoFormat format,\n    bool preferred_display_mode,\n    const std::vector<H264VideoFormat>& h264_formats)\n  : Property(VideoFormatsPropertyType),\n    preferred_display_mode_(preferred_display_mode ? 1 : 0) {\n  native_ = (format.rate_resolution << 3) | format.type;\n  for(auto h264_format : h264_formats)\n    h264_codecs_.push_back(H264Codec(h264_format));\n}\n\nVideoFormats::VideoFormats(NativeVideoFormat format,\n    bool preferred_display_mode,\n    const std::vector<H264VideoCodec>& h264_formats)\n  : Property(VideoFormatsPropertyType),\n    preferred_display_mode_(preferred_display_mode ? 1 : 0) {\n  native_ = (format.rate_resolution << 3) | format.type;\n  for(auto h264_format : h264_formats)\n    h264_codecs_.push_back(H264Codec(h264_format));\n}\n\nVideoFormats::VideoFormats(unsigned char native,\n    unsigned char preferred_display_mode,\n    const H264Codecs& h264_codecs)\n  : Property(VideoFormatsPropertyType),\n    native_(native),\n    preferred_display_mode_(preferred_display_mode),\n    h264_codecs_(h264_codecs) {\n}\n\nVideoFormats::~VideoFormats() {\n}\n\nnamespace {\n\ntemplate <typename EnumType>\nNativeVideoFormat GetFormatFromIndex(unsigned index, EnumType biggest_value) {\n  if (index <= static_cast<unsigned>(biggest_value))\n    return NativeVideoFormat(static_cast<EnumType>(index));\n  assert(false);\n  return NativeVideoFormat(biggest_value);\n}\n\n}\n\nNativeVideoFormat VideoFormats::GetNativeFormat() const {\n  unsigned index  = native_ >> 3;\n  unsigned selection_bits = native_ & 7;\n  switch (selection_bits) {\n  case 0: // 0b000 CEA\n    return GetFormatFromIndex<CEARatesAndResolutions>(index, CEA1920x1080p24);\n  case 1: // 0b001 VESA\n    return GetFormatFromIndex<VESARatesAndResolutions>(index, VESA1920x1200p30);\n  case 2: // 0b010 HH\n    return GetFormatFromIndex<HHRatesAndResolutions>(index, HH848x480p60);\n  default:\n    assert(false);\n    break;\n  }\n  return NativeVideoFormat(CEA640x480p60);\n}\n\nstd::vector<H264VideoFormat> VideoFormats::GetH264Formats() const {\n  std::vector<H264VideoFormat> result;\n  for (const auto& codec : h264_codecs_)\n    PopulateVideoFormatList(codec.ToH264VideoCodec(), result);\n  return result;\n}\n\nstd::vector<H264VideoCodec> VideoFormats::GetH264VideoCodecs() const {\n  std::vector<H264VideoCodec> result;\n  for (const auto& codec : h264_codecs_)\n    result.push_back(codec.ToH264VideoCodec());\n  return result;\n}\n\nstd::string VideoFormats::ToString() const {\n  std::string ret;\n\n  ret = PropertyName::wfd_video_formats\n      + std::string(SEMICOLON)+ std::string(SPACE);\n\n  if (is_none())\n    return ret + NONE;\n\n  MAKE_HEX_STRING_2(native, native_);\n  MAKE_HEX_STRING_2(preferred_display_mode, preferred_display_mode_);\n\n  ret += native + std::string(SPACE)\n      + preferred_display_mode + std::string(SPACE);\n\n  auto it = h264_codecs_.begin();\n  auto end = h264_codecs_.end();\n  while(it != end) {\n    ret += (*it).ToString();\n    ++it;\n    if (it != end)\n      ret += \", \";\n  }\n\n  return ret;\n}\n\n}  // namespace rtsp\n}  // namespace wds\n"
  },
  {
    "path": "libwds/rtsp/videoformats.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef LIBWDS_RTSP_VIDEOFORMATS_H_\n#define LIBWDS_RTSP_VIDEOFORMATS_H_\n\n#include \"libwds/rtsp/property.h\"\n#include \"libwds/public/video_format.h\"\n\n#include <vector>\n\nnamespace wds {\nnamespace rtsp {\n\nstruct H264Codec {\n public:\n  H264Codec(unsigned char profile, unsigned char level,\n      unsigned int cea_support, unsigned int vesa_support,\n      unsigned int hh_support, unsigned char latency,\n      unsigned short min_slice_size, unsigned short slice_enc_params,\n      unsigned char frame_rate_control_support,\n      unsigned short max_hres, unsigned short max_vres);\n\n  H264Codec(const H264VideoFormat& format);\n  H264Codec(const H264VideoCodec& format);\n\n  H264VideoCodec ToH264VideoCodec() const;\n\n  std::string ToString() const;\n\n  unsigned char profile;\n  unsigned char level;\n  unsigned int cea_support;\n  unsigned int vesa_support;\n  unsigned int hh_support;\n  unsigned char latency;\n  unsigned short min_slice_size;\n  unsigned short slice_enc_params;\n  unsigned char frame_rate_control_support;\n  unsigned short max_hres;\n  unsigned short max_vres;\n};\n\nusing H264Codecs = std::vector<H264Codec>;\n\nclass VideoFormats: public Property {\n public:\n  VideoFormats();\n  VideoFormats(NativeVideoFormat format,\n               bool preferred_display_mode,\n               const std::vector<H264VideoFormat>& h264_formats);\n  VideoFormats(NativeVideoFormat format,\n               bool preferred_display_mode,\n               const std::vector<H264VideoCodec>& h264_formats);\n  VideoFormats(unsigned char native,\n               unsigned char preferred_display_mode,\n               const H264Codecs& h264_codecs);\n  ~VideoFormats() override;\n\n  NativeVideoFormat GetNativeFormat() const;\n\n  std::vector<H264VideoFormat> GetH264Formats() const;\n  std::vector<H264VideoCodec> GetH264VideoCodecs() const;\n\n  std::string ToString() const override;\n\n private:\n  unsigned char native_;\n  unsigned char preferred_display_mode_;\n  H264Codecs h264_codecs_;\n};\n\n}  // namespace rtsp\n}  // namespace wds\n\n#endif  // LIBWDS_RTSP_VIDEOFORMATS_H_\n"
  },
  {
    "path": "libwds/sink/CMakeLists.txt",
    "content": "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden -fPIC\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\")\n\nadd_library(wdssink OBJECT\n    sink.cpp cap_negotiation_state.cpp init_state.cpp\n    session_state.cpp streaming_state.cpp\n)\nadd_dependencies(wdssink wdsrtsp)\n"
  },
  {
    "path": "libwds/sink/cap_negotiation_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/sink/cap_negotiation_state.h\"\n\n#include <iostream>\n\n#include \"libwds/public/media_manager.h\"\n#include \"libwds/rtsp/audiocodecs.h\"\n#include \"libwds/rtsp/clientrtpports.h\"\n#include \"libwds/rtsp/connectortype.h\"\n#include \"libwds/rtsp/contentprotection.h\"\n#include \"libwds/rtsp/coupledsink.h\"\n#include \"libwds/rtsp/displayedid.h\"\n#include \"libwds/rtsp/getparameter.h\"\n#include \"libwds/rtsp/formats3d.h\"\n#include \"libwds/rtsp/i2c.h\"\n#include \"libwds/rtsp/payload.h\"\n#include \"libwds/rtsp/presentationurl.h\"\n#include \"libwds/rtsp/propertyerrors.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/standbyresumecapability.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/rtsp/uibccapability.h\"\n#include \"libwds/rtsp/videoformats.h\"\n\nnamespace wds {\nusing rtsp::Message;\nusing rtsp::Payload;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace sink {\n\nM3Handler::M3Handler(const InitParams& init_params)\n  : MessageReceiver<Request::M3>(init_params) {\n}\n\nstd::unique_ptr<Reply> M3Handler::HandleMessage(Message* message) {\n  // FIXME : resolve clashes between wds exported and internal rtsp type names.\n  //using namespace rtsp;\n  auto received_payload = ToGetParameterPayload(message->payload());\n  if (!received_payload)\n    return nullptr;\n\n  auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n  auto reply_payload = new rtsp::PropertyMapPayload();\n  for (const std::string& property : received_payload->properties()) {\n      std::shared_ptr<rtsp::Property> new_prop;\n      if (property == GetPropertyName(rtsp::AudioCodecsPropertyType)){\n          // FIXME: declare that we support absolutely every audio codec/format,\n          // but there should be a MediaManager API for it\n          auto codec_lpcm = AudioCodec(LPCM, AudioModes(3), 0);\n          auto codec_aac = AudioCodec(AAC, AudioModes(15), 0);\n          auto codec_ac3 = AudioCodec(AC3, AudioModes(7), 0);\n          std::vector<AudioCodec> codec_list;\n          codec_list.push_back(codec_lpcm);\n          codec_list.push_back(codec_aac);\n          codec_list.push_back(codec_ac3);\n          new_prop.reset(new rtsp::AudioCodecs(codec_list));\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::VideoFormatsPropertyType)){\n          new_prop.reset(new rtsp::VideoFormats(ToSinkMediaManager(manager_)->GetNativeVideoFormat(),\n              false,\n              ToSinkMediaManager(manager_)->GetSupportedH264VideoCodecs()));\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::Video3DFormatsPropertyType)){\n          new_prop.reset(new rtsp::Formats3d());\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::ContentProtectionPropertyType)){\n          new_prop.reset(new rtsp::ContentProtection());\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::DisplayEdidPropertyType)){\n          new_prop.reset(new rtsp::DisplayEdid());\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::CoupledSinkPropertyType)){\n          new_prop.reset(new rtsp::CoupledSink());\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::ClientRTPPortsPropertyType)){\n          new_prop.reset(new rtsp::ClientRtpPorts(\n              ToSinkMediaManager(manager_)->GetLocalRtpPorts().first,\n              ToSinkMediaManager(manager_)->GetLocalRtpPorts().second));\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::I2CPropertyType)){\n          new_prop.reset(new rtsp::I2C(0));\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::UIBCCapabilityPropertyType)){\n          new_prop.reset(new rtsp::UIBCCapability());\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::ConnectorTypePropertyType)){\n          new_prop.reset(new rtsp::ConnectorType(ToSinkMediaManager(manager_)->GetConnectorType()));\n          reply_payload->AddProperty(new_prop);\n      } else if (property == GetPropertyName(rtsp::StandbyResumeCapabilityPropertyType)){\n          new_prop.reset(new rtsp::StandbyResumeCapability(false));\n          reply_payload->AddProperty(new_prop);\n      } else {\n          WDS_WARNING(\"** GET_PARAMETER: Ignoring unsupported property '%s'.\", property.c_str());\n      }\n  }\n  reply->set_payload(std::unique_ptr<Payload>(reply_payload));\n\n  return reply;\n}\n\n\nM4Handler::M4Handler(const InitParams& init_params)\n  : MessageReceiver<Request::M4>(init_params) {\n}\n\nstd::unique_ptr<Reply> M4Handler::HandleMessage(Message* message) {\n  SinkMediaManager* sink_media_manager = ToSinkMediaManager(manager_);\n  auto payload = ToPropertyMapPayload(message->payload());\n  if (!payload) {\n    WDS_ERROR(\"Failed to obtain payload in M4 handler.\");\n    return nullptr;\n  }\n\n  auto presentation_url =\n      static_cast<rtsp::PresentationUrl*>(payload->GetProperty(rtsp::PresentationURLPropertyType).get());\n  if (presentation_url) {\n    sink_media_manager->SetPresentationUrl(presentation_url->presentation_url_1());\n  }\n\n  auto video_formats =\n      static_cast<rtsp::VideoFormats*>(payload->GetProperty(rtsp::VideoFormatsPropertyType).get());\n\n  if (!video_formats) {\n    WDS_ERROR(\"Failed to obtain 'wfd-video-formats' in M4 handler.\");\n    return nullptr;\n  }\n\n  const auto& selected_formats = video_formats->GetH264Formats();\n  if (selected_formats.size() != 1) {\n    WDS_ERROR(\"Failed to obtain optimal video format from 'wfd-video-formats' in M4 handler.\");\n    return nullptr;\n  }\n\n  if (!sink_media_manager->SetOptimalVideoFormat(selected_formats[0])) {\n    auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_SeeOther));\n    auto payload = new rtsp::PropertyErrorPayload();\n    std::vector<unsigned short> error_codes = {rtsp::STATUS_UnsupportedMediaType};\n    auto property_errors =\n        std::make_shared<rtsp::PropertyErrors>(rtsp::VideoFormatsPropertyType, error_codes);\n    payload->AddPropertyError(property_errors);\n    reply->set_payload(std::unique_ptr<rtsp::Payload>(payload));\n    return reply;\n  }\n\n  return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n}\n\nclass M5Handler final : public MessageReceiver<Request::M5> {\n public:\n  M5Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M5>(init_params) {\n  }\n  std::unique_ptr<Reply> HandleMessage(Message* message) override {\n    auto payload = ToPropertyMapPayload(message->payload());\n    if (!payload) {\n      WDS_ERROR(\"Failed to obtain payload in M5 handler.\");\n      return nullptr;\n    }\n    auto property =\n        static_cast<rtsp::TriggerMethod*>(payload->GetProperty(rtsp::TriggerMethodPropertyType).get());\n\n    auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n    reply->header().set_cseq(message->cseq());\n    if (property->method() != rtsp::TriggerMethod::SETUP) {\n      reply->set_response_code(rtsp::STATUS_SeeOther);\n    }\n\n    return reply;\n  }\n};\n\nCapNegotiationState::CapNegotiationState(const InitParams &init_params)\n  : MessageSequenceWithOptionalSetHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M3Handler(init_params)));\n  AddSequencedHandler(make_ptr(new M4Handler(init_params)));\n  AddSequencedHandler(make_ptr(new M5Handler(init_params)));\n\n  AddOptionalHandler(make_ptr(new M3Handler(init_params)));\n  AddOptionalHandler(make_ptr(new M4Handler(init_params)));\n}\n\n}  // sink\n}  // wds\n"
  },
  {
    "path": "libwds/sink/cap_negotiation_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SINK_CAP_NEGOTIATION_STATE_H_\n#define LIBWDS_SINK_CAP_NEGOTIATION_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace sink {\n\n// Capability negotiation state for RTSP sink.\n// Includes M3 and M4 messages handling\nclass CapNegotiationState : public MessageSequenceWithOptionalSetHandler {\n public:\n  CapNegotiationState(const InitParams& init_params);\n};\n\nclass M4Handler final : public MessageReceiver<rtsp::Request::M4> {\n public:\n  M4Handler(const InitParams& init_params);\n  std::unique_ptr<rtsp::Reply> HandleMessage(rtsp::Message* message) override;\n};\n\nclass M3Handler final : public MessageReceiver<rtsp::Request::M3> {\n public:\n  M3Handler(const InitParams& init_params);\n  std::unique_ptr<rtsp::Reply> HandleMessage(rtsp::Message* message) override;\n};\n\n}  // namespace sink\n}  // namespace wds\n\n#endif // LIBWDS_SINK_CAP_NEGOTIATION_STATE_H_\n"
  },
  {
    "path": "libwds/sink/init_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/sink/init_state.h\"\n\n#include \"libwds/rtsp/options.h\"\n#include \"libwds/rtsp/reply.h\"\n\nnamespace wds {\nnamespace sink {\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nclass M1Handler final : public MessageReceiver<Request::M1> {\n public:\n  M1Handler(const InitParams& init_params, int& source_init_cseq)\n    : MessageReceiver<Request::M1>(init_params),\n      source_init_cseq_(source_init_cseq) {\n  }\n  virtual std::unique_ptr<Reply> HandleMessage(Message* message) override {\n    source_init_cseq_ = message->cseq();\n    auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n    std::vector<rtsp::Method> supported_methods;\n    supported_methods.push_back(rtsp::ORG_WFA_WFD_1_0);\n    supported_methods.push_back(rtsp::GET_PARAMETER);\n    supported_methods.push_back(rtsp::SET_PARAMETER);\n    reply->header().set_supported_methods(supported_methods);\n    return reply;\n  }\n\n private:\n  int& source_init_cseq_;\n};\n\nclass M2Handler final : public SequencedMessageSender {\n public:\n  M2Handler(const InitParams& init_params, int& source_init_cseq)\n    : SequencedMessageSender(init_params),\n      source_init_cseq_(source_init_cseq) {\n  }\n private:\n  virtual std::unique_ptr<Message> CreateMessage() override {\n    auto options = new rtsp::Options(\"*\");\n    options->header().set_cseq(sender_->GetNextCSeq(&source_init_cseq_));\n    options->header().set_require_wfd_support(true);\n    return std::unique_ptr<Message>(options);\n  }\n\n  virtual bool HandleReply(Reply* reply) override {\n    const rtsp::Header& header = reply->header();\n\n    if (reply->response_code() == rtsp::STATUS_OK\n        && header.has_method(rtsp::Method::ORG_WFA_WFD_1_0)\n        && header.has_method(rtsp::Method::GET_PARAMETER)\n        && header.has_method(rtsp::Method::SET_PARAMETER)\n        && header.has_method(rtsp::Method::SETUP)\n        && header.has_method(rtsp::Method::PLAY)\n        && header.has_method(rtsp::Method::TEARDOWN)\n        && header.has_method(rtsp::Method::PAUSE)) {\n      return true;\n    }\n\n    return false;\n  }\n  int& source_init_cseq_;\n};\n\nInitState::InitState(const InitParams& init_params)\n  : MessageSequenceHandler(init_params),\n    source_init_cseq_(0) {\n  AddSequencedHandler(make_ptr(new M1Handler(init_params, source_init_cseq_)));\n  AddSequencedHandler(make_ptr(new M2Handler(init_params, source_init_cseq_)));\n}\n\n}  // sink\n}  // wds\n"
  },
  {
    "path": "libwds/sink/init_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SINK_INIT_STATE_H_\n#define LIBWDS_SINK_INIT_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace sink {\n\n// Inital state for RTSP sink.\n// Includes M1 and M2 messages handling\nclass InitState : public MessageSequenceHandler {\n public:\n  InitState(const InitParams& init_params);\n\n private:\n  int source_init_cseq_;\n};\n\n}  // sink\n}  // wds\n\n#endif // LIBWDS_SINK_INIT_STATE_H_\n"
  },
  {
    "path": "libwds/sink/session_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/sink/session_state.h\"\n\n#include \"libwds/public/media_manager.h\"\n\n#include \"libwds/rtsp/play.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/setup.h\"\n#include \"libwds/rtsp/transportheader.h\"\n#include \"libwds/sink/cap_negotiation_state.h\"\n#include \"libwds/sink/streaming_state.h\"\n\nnamespace wds {\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace sink {\n\nM16Handler::M16Handler(const InitParams& init_params, unsigned& keep_alive_timer)\n  : MessageReceiver<Request::M16>(init_params),\n    keep_alive_timer_(keep_alive_timer) { }\n\nbool M16Handler::HandleTimeoutEvent(unsigned timer_id) const {\n  return timer_id == keep_alive_timer_;\n}\n\nstd::unique_ptr<Reply> M16Handler::HandleMessage(Message* message) {\n  // Reset keep alive timer;\n  sender_->ReleaseTimer(keep_alive_timer_);\n  keep_alive_timer_ = sender_->CreateTimer(60);\n\n  return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n}\n\nM6Handler::M6Handler(const InitParams& init_params, unsigned& keep_alive_timer)\n  : SequencedMessageSender(init_params),\n    keep_alive_timer_(keep_alive_timer) {}\n\nstd::unique_ptr<Message> M6Handler::CreateMessage() {\n  auto setup = new rtsp::Setup(ToSinkMediaManager(manager_)->GetPresentationUrl());\n  auto transport = new rtsp::TransportHeader();\n  // we assume here that there is no coupled secondary sink\n  transport->set_client_port(ToSinkMediaManager(manager_)->GetLocalRtpPorts().first);\n  setup->header().set_transport(transport);\n  setup->header().set_cseq(sender_->GetNextCSeq());\n  setup->header().set_require_wfd_support(true);\n\n  return std::unique_ptr<Message>(setup);\n}\n\nbool M6Handler::HandleReply(Reply* reply) {\n  const std::string& session_id = reply->header().session();\n  if(reply->response_code() == rtsp::STATUS_OK && !session_id.empty()) {\n    ToSinkMediaManager(manager_)->SetSessionId(session_id);\n    // FIXME : take timeout value from session.\n    keep_alive_timer_ = sender_->CreateTimer(60);\n    return true;\n  }\n\n  return false;\n}\n\nclass M7Handler final : public SequencedMessageSender {\n public:\n    using SequencedMessageSender::SequencedMessageSender;\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::Play* play = new rtsp::Play(ToSinkMediaManager(manager_)->GetPresentationUrl());\n    play->header().set_session(manager_->GetSessionId());\n    play->header().set_cseq(sender_->GetNextCSeq());\n    play->header().set_require_wfd_support(true);\n\n    return std::unique_ptr<Message>(play);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    return (reply->response_code() == rtsp::STATUS_OK);\n  }\n};\n\nSessionState::SessionState(const InitParams& init_params, MessageHandlerPtr m6_handler, MessageHandlerPtr m16_handler)\n  : MessageSequenceWithOptionalSetHandler(init_params) {\n  AddSequencedHandler(m6_handler);\n  AddSequencedHandler(make_ptr(new M7Handler(init_params)));\n\n  AddOptionalHandler(make_ptr(new M3Handler(init_params)));\n  AddOptionalHandler(make_ptr(new M4Handler(init_params)));\n  AddOptionalHandler(make_ptr(new TeardownHandler(init_params)));\n  AddOptionalHandler(m16_handler);\n}\n\n}  // namespace sink\n}  // namespace wds\n"
  },
  {
    "path": "libwds/sink/session_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SINK_SESSION_STATE_H_\n#define LIBWDS_SINK_SESSION_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace sink {\n\nclass M6Handler final : public SequencedMessageSender {\n public:\n  M6Handler(const InitParams& init_params, unsigned& keep_alive_timer);\n\n private:\n  std::unique_ptr<rtsp::Message> CreateMessage() override;\n  bool HandleReply(rtsp::Reply* reply) override;\n\n  unsigned& keep_alive_timer_;\n};\n\nclass M16Handler final : public MessageReceiver<rtsp::Request::M16> {\n public:\n  M16Handler(const InitParams& init_params, unsigned& keep_alive_timer);\n\n private:\n  bool HandleTimeoutEvent(unsigned timer_id) const override;\n  std::unique_ptr<rtsp::Reply> HandleMessage(rtsp::Message* message) override;\n\n  unsigned& keep_alive_timer_;\n};\n\n// WFD session state for RTSP sink.\n// Includes M6, M7, M8 messages handling and optionally can handle M3, M4, M16\nclass SessionState : public MessageSequenceWithOptionalSetHandler {\n public:\n  SessionState(const InitParams& init_params, MessageHandlerPtr m6_handler, MessageHandlerPtr m16_handler);\n};\n\n}  // sink\n}  // wds\n\n#endif // LIBWDS_SINK_SESSION_STATE_H_\n"
  },
  {
    "path": "libwds/sink/sink.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/public/sink.h\"\n\n#include \"libwds/common/message_handler.h\"\n#include \"libwds/common/rtsp_input_handler.h\"\n#include \"libwds/public/wds_export.h\"\n#include \"libwds/rtsp/pause.h\"\n#include \"libwds/rtsp/play.h\"\n#include \"libwds/rtsp/teardown.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/public/media_manager.h\"\n#include \"libwds/sink/cap_negotiation_state.h\"\n#include \"libwds/sink/init_state.h\"\n#include \"libwds/sink/session_state.h\"\n#include \"libwds/sink/streaming_state.h\"\n\nnamespace wds {\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace {\n\n// todo: check mandatory parameters for each message\nbool InitializeRequestId(Request* request) {\n  Request::ID id = Request::UNKNOWN;\n  switch(request->method()) {\n  case Request::MethodOptions:\n    id = Request::M1;\n    break;\n  case Request::MethodGetParameter:\n    if (auto payload = rtsp::ToGetParameterPayload(request->payload())) {\n      if (!payload->properties().empty())\n        id = Request::M3;\n    } else {\n      id = Request::M16;\n    }\n    break;\n  case Request::MethodSetParameter:\n    if (auto payload = rtsp::ToPropertyMapPayload(request->payload())) {\n      if (payload->HasProperty(rtsp::PresentationURLPropertyType))\n        id = Request::M4;\n      else if (payload->HasProperty(rtsp::AVFormatChangeTimingPropertyType))\n        id = Request::M4;\n      else if (payload->HasProperty(rtsp::TriggerMethodPropertyType))\n        id = Request::M5;\n      break;\n    }\n  default:\n    WDS_ERROR(\"Failed to identify the received message\");\n    return false;\n  }\n\n  request->set_id(id);\n  return true;\n}\n\n}\n\nclass SinkStateMachine : public MessageSequenceHandler {\n public:\n   SinkStateMachine(const InitParams& init_params)\n     : MessageSequenceHandler(init_params),\n       keep_alive_timer_(0) {\n     auto m6_handler = make_ptr(new sink::M6Handler(init_params, keep_alive_timer_));\n     auto m16_handler = make_ptr(new sink::M16Handler(init_params, keep_alive_timer_));\n     AddSequencedHandler(make_ptr(new sink::InitState(init_params)));\n     AddSequencedHandler(make_ptr(new sink::CapNegotiationState(init_params)));\n     AddSequencedHandler(make_ptr(new sink::SessionState(init_params, m6_handler, m16_handler)));\n     AddSequencedHandler(make_ptr(new sink::StreamingState(init_params, m16_handler)));\n   }\n\n   SinkStateMachine(Peer::Delegate* sender, SinkMediaManager* mng)\n     : SinkStateMachine({sender, mng, this}) {}\n\n private:\n   unsigned keep_alive_timer_;\n};\n\nclass SinkImpl final : public Sink, public RTSPInputHandler, public MessageHandler::Observer {\n public:\n  SinkImpl(Delegate* delegate, SinkMediaManager* mng);\n\n private:\n  // Sink implementation.\n  void Start() override;\n  void Reset() override;\n  void RTSPDataReceived(const std::string& message) override;\n  bool Teardown() override;\n  bool Play() override;\n  bool Pause() override;\n\n  // RTSPInputHandler\n  void MessageParsed(std::unique_ptr<Message> message) override;\n\n  // public MessageHandler::Observer\n  void OnCompleted(MessageHandlerPtr handler) override;\n  void OnError(MessageHandlerPtr handler) override;\n  void OnTimerEvent(unsigned timer_id) override;\n\n  bool HandleCommand(std::unique_ptr<Message> command);\n\n  template <class WfdMessage, Request::ID id>\n  std::unique_ptr<Message> CreateCommand();\n\n  void ResetAndTeardownMedia();\n\n  std::shared_ptr<SinkStateMachine> state_machine_;\n  Delegate* delegate_;\n  SinkMediaManager* manager_;\n};\n\nSinkImpl::SinkImpl(Delegate* delegate, SinkMediaManager* mng)\n  : state_machine_(new SinkStateMachine({delegate, mng, this})),\n    delegate_(delegate),\n    manager_(mng) {\n}\n\nvoid SinkImpl::Start() {\n  state_machine_->Start();\n}\n\nvoid SinkImpl::Reset() {\n  state_machine_->Reset();\n}\n\nvoid SinkImpl::RTSPDataReceived(const std::string& message) {\n  AddInput(message);\n}\n\ntemplate <class WfdMessage, Request::ID id>\nstd::unique_ptr<Message> SinkImpl::CreateCommand() {\n  auto message = new WfdMessage(manager_->GetPresentationUrl());\n  message->header().set_session(manager_->GetSessionId());\n  message->header().set_cseq(delegate_->GetNextCSeq());\n  message->set_id(id);\n  return std::unique_ptr<Message>(message);\n}\n\nbool SinkImpl::HandleCommand(std::unique_ptr<Message> command) {\n  if (manager_->GetSessionId().empty() ||\n      manager_->GetPresentationUrl().empty())\n    return false;\n\n  if (!state_machine_->CanSend(command.get()))\n    return false;\n  state_machine_->Send(std::move(command));\n  return true;\n}\n\nbool SinkImpl::Teardown() {\n  return HandleCommand(CreateCommand<rtsp::Teardown, Request::M8>());\n}\n\nbool SinkImpl::Play() {\n  return HandleCommand(CreateCommand<rtsp::Play, Request::M7>());\n}\n\nbool SinkImpl::Pause() {\n  return HandleCommand(CreateCommand<rtsp::Pause, Request::M9>());\n}\n\nvoid SinkImpl::MessageParsed(std::unique_ptr<Message> message) {\n  if (message->is_request() && !InitializeRequestId(ToRequest(message.get()))) {\n    WDS_ERROR(\"Cannot identify the received message\");\n    return;\n  }\n  if (!state_machine_->CanHandle(message.get())) {\n    WDS_ERROR(\"Cannot handle the received message with Id: %d\", ToRequest(message.get())->id());\n    return;\n  }\n  state_machine_->Handle(std::move(message));\n}\n\nvoid SinkImpl::ResetAndTeardownMedia() {\n  manager_->Teardown();\n  state_machine_->Reset();\n}\n\nvoid SinkImpl::OnCompleted(MessageHandlerPtr handler) {\n  assert(handler == state_machine_);\n  ResetAndTeardownMedia();\n}\n\nvoid SinkImpl::OnError(MessageHandlerPtr handler) {\n   assert(handler == state_machine_);\n   ResetAndTeardownMedia();\n}\n\nvoid SinkImpl::OnTimerEvent(unsigned timer_id) {\n  if (state_machine_->HandleTimeoutEvent(timer_id))\n    state_machine_->Reset();\n}\n\nSink* Sink::Create(Delegate* delegate, SinkMediaManager* mng) {\n  return new SinkImpl(delegate, mng);\n}\n\n}  // namespace wds\n"
  },
  {
    "path": "libwds/sink/streaming_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/sink/streaming_state.h\"\n\n#include \"libwds/public/media_manager.h\"\n\n#include \"libwds/rtsp/pause.h\"\n#include \"libwds/rtsp/play.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/teardown.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/sink/cap_negotiation_state.h\"\n#include \"libwds/sink/session_state.h\"\n\nnamespace wds {\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\nusing rtsp::TriggerMethod;\n\nnamespace sink {\n\ntemplate <TriggerMethod::Method method>\nclass M5Handler final : public MessageReceiver<Request::M5> {\n public:\n  explicit M5Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M5>(init_params) {\n  }\n\n  bool CanHandle(Message* message) const override {\n    if (!MessageReceiver<Request::M5>::CanHandle(message))\n      return false;\n    auto payload = ToPropertyMapPayload(message->payload());\n    if (!payload) {\n      WDS_ERROR(\"Failed to obtain payload in M5 handler.\");\n      return false;\n    }\n    auto property =\n        static_cast<TriggerMethod*>(\n            payload->GetProperty(rtsp::TriggerMethodPropertyType).get());\n    return method == property->method();\n  }\n\n  std::unique_ptr<Reply> HandleMessage(Message* message) override {\n    return std::unique_ptr<Reply>(new Reply());\n  }\n};\n\nclass M7Sender final : public SequencedMessageSender {\n public:\n    using SequencedMessageSender::SequencedMessageSender;\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::Play* play = new rtsp::Play(ToSinkMediaManager(manager_)->GetPresentationUrl());\n    play->header().set_session(manager_->GetSessionId());\n    play->header().set_cseq (sender_->GetNextCSeq());\n    return std::unique_ptr<Message>(play);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    if (reply->response_code() == rtsp::STATUS_OK) {\n      manager_->Play();\n      return true;\n    }\n    return false;\n  }\n};\n\nclass PlayHandler : public MessageSequenceHandler {\n public:\n  explicit PlayHandler(const InitParams& init_params)\n  : MessageSequenceHandler(init_params) {\n    AddSequencedHandler(make_ptr(new M5Handler<TriggerMethod::PLAY>(init_params)));\n    AddSequencedHandler(make_ptr(new M7Sender(init_params)));\n  }\n};\n\nclass M8Sender final : public SequencedMessageSender {\n public:\n  using SequencedMessageSender::SequencedMessageSender;\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::Teardown* teardown = new rtsp::Teardown(ToSinkMediaManager(manager_)->GetPresentationUrl());\n    teardown->header().set_session(manager_->GetSessionId());\n    teardown->header().set_cseq(sender_->GetNextCSeq());\n    return std::unique_ptr<Message>(teardown);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    if (!manager_->GetSessionId().empty() &&\n        (reply->response_code() == rtsp::STATUS_OK)) {\n      manager_->Teardown();\n      return true;\n    }\n    return false;\n  }\n};\n\nTeardownHandler::TeardownHandler(const InitParams& init_params)\n  : MessageSequenceHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M5Handler<TriggerMethod::TEARDOWN>(init_params)));\n  AddSequencedHandler(make_ptr(new M8Sender(init_params)));\n}\n\nclass M9Sender final : public SequencedMessageSender {\n public:\n    using SequencedMessageSender::SequencedMessageSender;\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::Pause* pause = new rtsp::Pause(ToSinkMediaManager(manager_)->GetPresentationUrl());\n    pause->header().set_session(manager_->GetSessionId());\n    pause->header().set_cseq(sender_->GetNextCSeq());\n    return std::unique_ptr<Message>(pause);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    if (reply->response_code() == rtsp::STATUS_OK) {\n      manager_->Pause();\n      return true;\n    }\n    return false;\n  }\n};\n\nclass PauseHandler : public MessageSequenceHandler {\n public:\n  explicit PauseHandler(const InitParams& init_params)\n  : MessageSequenceHandler(init_params) {\n    AddSequencedHandler(make_ptr(new M5Handler<TriggerMethod::PAUSE>(init_params)));\n    AddSequencedHandler(make_ptr(new M9Sender(init_params)));\n  }\n};\n\nclass M7SenderOptional final : public OptionalMessageSender<Request::M7> {\n public:\n  M7SenderOptional(const InitParams& init_params)\n    : OptionalMessageSender<Request::M7>(init_params) {\n  }\n private:\n  bool HandleReply(Reply* reply) override {\n    if (reply->response_code() == rtsp::STATUS_OK) {\n      manager_->Play();\n      return true;\n    }\n    return false;\n  }\n\n  bool CanSend(Message* message) const override {\n    if (OptionalMessageSender<Request::M7>::CanSend(message)\n        && manager_->IsPaused())\n      return true;\n    return false;\n  }\n};\n\nclass M8SenderOptional final : public OptionalMessageSender<Request::M8> {\n public:\n  M8SenderOptional(const InitParams& init_params)\n    : OptionalMessageSender<Request::M8>(init_params) {\n  }\n private:\n  bool HandleReply(Reply* reply) override {\n    // todo: if successfull, switch to init state\n    if (reply->response_code() == rtsp::STATUS_OK) {\n      manager_->Teardown();\n      return true;\n    }\n\n    return false;\n  }\n};\n\nclass M9SenderOptional final : public OptionalMessageSender<Request::M9> {\n public:\n  M9SenderOptional(const InitParams& init_params)\n    : OptionalMessageSender<Request::M9>(init_params) {\n  }\n private:\n  bool HandleReply(Reply* reply) override {\n    if (reply->response_code() == rtsp::STATUS_OK) {\n      manager_->Pause();\n      return true;\n    }\n    return false;\n  }\n\n  bool CanSend(Message* message) const override {\n    if (OptionalMessageSender<Request::M9>::CanSend(message)\n        && !manager_->IsPaused())\n      return true;\n    return false;\n  }\n};\n\nStreamingState::StreamingState(const InitParams& init_params, MessageHandlerPtr m16_handler)\n  : MessageSequenceWithOptionalSetHandler(init_params) {\n  AddSequencedHandler(make_ptr(new TeardownHandler(init_params)));\n  AddOptionalHandler(make_ptr(new PlayHandler(init_params)));\n  AddOptionalHandler(make_ptr(new PauseHandler(init_params)));\n  AddOptionalHandler(make_ptr(new M3Handler(init_params)));\n  AddOptionalHandler(make_ptr(new M4Handler(init_params)));\n\n  // optional senders that handle sending play, pause and teardown\n  AddOptionalHandler(make_ptr(new M7SenderOptional(init_params)));\n  AddOptionalHandler(make_ptr(new M8SenderOptional(init_params)));\n  AddOptionalHandler(make_ptr(new M9SenderOptional(init_params)));\n  AddOptionalHandler(m16_handler);\n}\n\n}  // sink\n}  // wds\n"
  },
  {
    "path": "libwds/sink/streaming_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SINK_STREAMING_STATE_H_\n#define LIBWDS_SINK_STREAMING_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace sink {\n\n// Streaming state for RTSP sink.\n// Includes M8 message handling and optionally can handle M3, M4, M7 and M9\nclass StreamingState : public MessageSequenceWithOptionalSetHandler {\n public:\n  StreamingState(const InitParams& init_params, MessageHandlerPtr m16_handler);\n};\n\nclass TeardownHandler : public MessageSequenceHandler {\n public:\n  explicit TeardownHandler(const InitParams& init_params);\n};\n\n}  // sink\n}  // wds\n\n#endif // LIBWDS_SINK_STREAMING_STATE_H_\n"
  },
  {
    "path": "libwds/source/CMakeLists.txt",
    "content": "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fvisibility=hidden -fPIC\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -std=c99 -Wall\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\")\n\nadd_library(wdssource OBJECT\n    source.cpp cap_negotiation_state.cpp init_state.cpp\n    session_state.cpp streaming_state.cpp)\nadd_dependencies(wdssource wdsrtsp)\n"
  },
  {
    "path": "libwds/source/cap_negotiation_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/source/cap_negotiation_state.h\"\n\n#include \"libwds/rtsp/audiocodecs.h\"\n#include \"libwds/rtsp/clientrtpports.h\"\n#include \"libwds/rtsp/getparameter.h\"\n#include \"libwds/rtsp/payload.h\"\n#include \"libwds/rtsp/presentationurl.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/videoformats.h\"\n#include \"libwds/public/media_manager.h\"\n\nnamespace wds {\n\nusing rtsp::AudioCodecs;\nusing rtsp::ClientRtpPorts;\nusing rtsp::GetParameter;\nusing rtsp::Message;\nusing rtsp::Payload;\nusing rtsp::Property;\nusing rtsp::Request;\nusing rtsp::Reply;\nusing rtsp::SetParameter;\nusing rtsp::VideoFormats;\n\nnamespace source {\n\nclass M3Handler final : public SequencedMessageSender {\n public:\n  using SequencedMessageSender::SequencedMessageSender;\n\n private:\n  std::unique_ptr<Message> CreateMessage() override;\n  bool HandleReply(Reply* reply) override;\n};\n\nclass M4Handler final : public SequencedMessageSender {\n public:\n  using SequencedMessageSender::SequencedMessageSender;\n\n private:\n  std::unique_ptr<Message> CreateMessage() override;\n  bool HandleReply(Reply* reply) override;\n};\n\nstd::unique_ptr<Message> M3Handler::CreateMessage() {\n  GetParameter* get_param = new GetParameter(\"rtsp://localhost/wfd1.0\");\n  get_param->header().set_cseq(sender_->GetNextCSeq());\n  std::vector<std::string> props;\n\n  SessionType media_type = ToSourceMediaManager(manager_)->GetSessionType();\n  if (media_type & VideoSession)\n    props.push_back(\"wfd_video_formats\");\n  if (media_type & AudioSession)\n    props.push_back(\"wfd_audio_codecs\");\n\n  props.push_back(\"wfd_client_rtp_ports\");\n  get_param->set_payload(\n      std::unique_ptr<Payload>(new rtsp::GetParameterPayload(props)));\n  return std::unique_ptr<Message>(get_param);\n}\n\nbool M3Handler::HandleReply(Reply* reply) {\n  if (reply->response_code() != rtsp::STATUS_OK)\n    return false;\n\n  SourceMediaManager* source_manager = ToSourceMediaManager(manager_);\n  auto payload = ToPropertyMapPayload(reply->payload());\n  if (!payload){\n    WDS_ERROR(\"Failed to obtain payload from reply.\");\n    return false;\n  }\n  auto property = payload->GetProperty(rtsp::ClientRTPPortsPropertyType);\n  auto ports = static_cast<ClientRtpPorts*>(property.get());\n  if (!ports){\n    WDS_ERROR(\"Failed to obtain RTP ports from source.\");\n    return false;\n  }\n  source_manager->SetSinkRtpPorts(ports->rtp_port_0(), ports->rtp_port_1());\n\n  auto video_formats = static_cast<VideoFormats*>(\n      payload->GetProperty(rtsp::VideoFormatsPropertyType).get());\n\n  auto audio_codecs = static_cast<AudioCodecs*>(\n      payload->GetProperty(rtsp::AudioCodecsPropertyType).get());\n\n  if (!video_formats && (source_manager->GetSessionType() & VideoSession)) {\n    WDS_ERROR(\"Failed to obtain WFD_VIDEO_FORMATS property\");\n    return false;\n  }\n\n  if (!audio_codecs && (source_manager->GetSessionType() & AudioSession)) {\n    WDS_ERROR(\"Failed to obtain WFD_AUDIO_CODECS property\");\n    return false;\n  }\n\n  if (video_formats && !source_manager->InitOptimalVideoFormat(\n      video_formats->GetNativeFormat(),\n      video_formats->GetH264VideoCodecs())) {\n    WDS_ERROR(\"Cannot initalize optimal video format from the supported by sink.\");\n    return false;\n  }\n\n  if (audio_codecs && !source_manager->InitOptimalAudioFormat(\n      audio_codecs->audio_codecs())) {\n    WDS_ERROR(\"Cannot initalize optimal audio format from the supported by sink.\");\n    return false;\n  }\n\n  return true;\n}\n\nstd::unique_ptr<Message> M4Handler::CreateMessage() {\n  SetParameter* set_param = new SetParameter(\"rtsp://localhost/wfd1.0\");\n  set_param->header().set_cseq(sender_->GetNextCSeq());\n  SourceMediaManager* source_manager = ToSourceMediaManager(manager_);\n  const auto& ports = source_manager->GetSinkRtpPorts();\n  auto payload = new rtsp::PropertyMapPayload();\n\n  payload->AddProperty(\n      std::shared_ptr<Property>(new ClientRtpPorts(ports.first, ports.second)));\n  std::string presentation_Url_1 = \"rtsp://\" + sender_->GetLocalIPAddress() + \"/wfd1.0/streamid=0\";\n  payload->AddProperty(\n      std::shared_ptr<Property>(new rtsp::PresentationUrl(presentation_Url_1, \"\")));\n\n  if (source_manager->GetSessionType() & VideoSession) {\n    payload->AddProperty(\n        std::shared_ptr<VideoFormats>(new VideoFormats(\n            NativeVideoFormat(),  // Should be all zeros.\n            false,\n            {source_manager->GetOptimalVideoFormat()})));\n  }\n\n  if (source_manager->GetSessionType() & AudioSession) {\n    payload->AddProperty(\n        std::shared_ptr<AudioCodecs>(new AudioCodecs({source_manager->GetOptimalAudioFormat()})));\n  }\n\n  set_param->set_payload(std::unique_ptr<Payload>(payload));\n\n  return std::unique_ptr<Message>(set_param);\n}\n\nbool M4Handler::HandleReply(Reply* reply) {\n  return (reply->response_code() == rtsp::STATUS_OK);\n}\n\nCapNegotiationState::CapNegotiationState(const InitParams &init_params)\n  : MessageSequenceHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M3Handler(init_params)));\n  AddSequencedHandler(make_ptr(new M4Handler(init_params)));\n}\n\nCapNegotiationState::~CapNegotiationState() {\n}\n\n}  // namespace source\n}  // namespace wds\n"
  },
  {
    "path": "libwds/source/cap_negotiation_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SOURCE_CAP_NEGOTIATION_STATE_H_\n#define LIBWDS_SOURCE_CAP_NEGOTIATION_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace source {\n\n// Capability negotiation state for RTSP source.\n// Includes M3 and M4 messages handling\nclass CapNegotiationState : public MessageSequenceHandler {\n public:\n  CapNegotiationState(const InitParams& init_params);\n  ~CapNegotiationState() override;\n};\n\n}  // source\n}  // wds\n\n#endif // LIBWDS_SOURCE_CAP_NEGOTIATION_STATE_H_\n"
  },
  {
    "path": "libwds/source/init_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/source/init_state.h\"\n\n#include \"libwds/rtsp/options.h\"\n#include \"libwds/rtsp/reply.h\"\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace source {\n\nclass M1Handler final : public SequencedMessageSender {\n public:\n  using SequencedMessageSender::SequencedMessageSender;\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::Options* options = new rtsp::Options(\"*\");\n    options->header().set_cseq(sender_->GetNextCSeq());\n    options->header().set_require_wfd_support(true);\n    return std::unique_ptr<Message>(options);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    return (reply->response_code() == rtsp::STATUS_OK);\n  }\n\n};\n\nclass M2Handler final : public MessageReceiver<Request::M2> {\n public:\n  M2Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M2>(init_params) {\n  }\n  std::unique_ptr<Reply> HandleMessage(\n      Message* message) override {\n    auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n    std::vector<rtsp::Method> supported_methods;\n    supported_methods.push_back(rtsp::ORG_WFA_WFD_1_0);\n    supported_methods.push_back(rtsp::GET_PARAMETER);\n    supported_methods.push_back(rtsp::SET_PARAMETER);\n    supported_methods.push_back(rtsp::PLAY);\n    supported_methods.push_back(rtsp::PAUSE);\n    supported_methods.push_back(rtsp::SETUP);\n    supported_methods.push_back(rtsp::TEARDOWN);\n    reply->header().set_supported_methods(supported_methods);\n    return reply;\n  }\n};\n\nInitState::InitState(const InitParams& init_params)\n  : MessageSequenceHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M1Handler(init_params)));\n  AddSequencedHandler(make_ptr(new M2Handler(init_params)));\n}\n\nInitState::~InitState() {\n}\n\n}  // source\n}  // wds\n"
  },
  {
    "path": "libwds/source/init_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SOURCE_INIT_STATE_H_\n#define LIBWDS_SOURCE_INIT_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace source {\n\n// Inital state for RTSP source.\n// Includes M1 and M2 messages handling\nclass InitState : public MessageSequenceHandler {\n public:\n  InitState(const InitParams& init_params);\n  ~InitState() override;\n};\n\n}  // source\n}  // wds\n\n#endif // LIBWDS_SOURCE_INIT_STATE_H_\n"
  },
  {
    "path": "libwds/source/session_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/source/session_state.h\"\n\n#include \"libwds/public/media_manager.h\"\n#include \"libwds/source/cap_negotiation_state.h\"\n#include \"libwds/rtsp/reply.h\"\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Payload;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace source {\n\nclass M5Handler final : public SequencedMessageSender {\n public:\n  using SequencedMessageSender::SequencedMessageSender;\n\n private:\n  std::unique_ptr<Message> CreateMessage() override {\n    rtsp::SetParameter* set_param = new rtsp::SetParameter(\"rtsp://localhost/wfd1.0\");\n    set_param->header().set_cseq(sender_->GetNextCSeq());\n    auto payload = new rtsp::PropertyMapPayload();\n    payload->AddProperty(\n        std::shared_ptr<rtsp::Property>(new rtsp::TriggerMethod(rtsp::TriggerMethod::SETUP)));\n    set_param->set_payload(std::unique_ptr<Payload>(payload));\n    return std::unique_ptr<Message>(set_param);\n  }\n\n  bool HandleReply(Reply* reply) override {\n    return (reply->response_code() == rtsp::STATUS_OK);\n  }\n\n};\n\nclass M6Handler final : public MessageReceiver<Request::M6> {\n public:\n  M6Handler(const InitParams& init_params, unsigned& timer_id)\n    : MessageReceiver<Request::M6>(init_params),\n      keep_alive_timer_(timer_id) {\n  }\n\n  std::unique_ptr<Reply> HandleMessage(\n      Message* message) override {\n    auto reply = std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n    reply->header().set_session(manager_->GetSessionId());\n    reply->header().set_timeout(kDefaultKeepAliveTimeout);\n\n    auto transport = new rtsp::TransportHeader();\n    // we assume here that there is no coupled secondary sink\n    transport->set_client_port(ToSourceMediaManager(manager_)->GetSinkRtpPorts().first);\n    transport->set_server_port(ToSourceMediaManager(manager_)->GetLocalRtpPort());\n    reply->header().set_transport(transport);\n\n    return reply;\n  }\n\n  void Handle(std::unique_ptr<Message> message) override {\n    MessageReceiver<Request::M6>::Handle(std::move(message));\n    keep_alive_timer_ =\n        sender_->CreateTimer(kDefaultTimeoutValue);\n  }\n\n  unsigned& keep_alive_timer_;\n};\n\nM7Handler::M7Handler(const InitParams& init_params)\n  : MessageReceiver<Request::M7>(init_params) {\n}\n\nstd::unique_ptr<Reply> M7Handler::HandleMessage(\n    Message* message) {\n  if (!manager_->IsPaused())\n    return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_NotAcceptable));\n  manager_->Play();\n  return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n}\n\nM16Sender::M16Sender(const InitParams& init_params)\n  : OptionalMessageSender<Request::M16>(init_params) {\n}\n\nbool M16Sender::HandleReply(Reply* reply) {\n  return (reply->response_code() == rtsp::STATUS_OK);\n}\n\nSessionState::SessionState(const InitParams& init_params, unsigned& timer_id,\n    MessageHandlerPtr& m16_sender)\n  : MessageSequenceWithOptionalSetHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M5Handler(init_params)));\n  AddSequencedHandler(make_ptr(new M6Handler(init_params, timer_id)));\n  AddSequencedHandler(make_ptr(new M7Handler(init_params)));\n\n  AddOptionalHandler(m16_sender);\n}\n\nSessionState::~SessionState() {\n}\n\n}  // source\n}  // wds\n"
  },
  {
    "path": "libwds/source/session_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SOURCE_SESSION_STATE_H_\n#define LIBWDS_SOURCE_SESSION_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace source {\n\n// WFD session state for RTSP source.\n// Includes M5, M6, M7 messages handling and optionally can handle M3, M4, M8\nclass SessionState : public MessageSequenceWithOptionalSetHandler {\n public:\n  SessionState(const InitParams& init_params, unsigned& timer_id,\n      MessageHandlerPtr& m16_sender);\n  ~SessionState() override;\n};\n\nclass M7Handler final : public MessageReceiver<rtsp::Request::M7> {\n public:\n  M7Handler(const InitParams& init_params);\n\n private:\n  std::unique_ptr<rtsp::Reply> HandleMessage(\n      rtsp::Message* message) override;\n};\n\nclass M16Sender final : public OptionalMessageSender<rtsp::Request::M16> {\n public:\n  M16Sender(const InitParams& init_params);\n\n private:\n  bool HandleReply(rtsp::Reply* reply) override;\n};\n\n}  // source\n}  // wds\n\n#endif // LIBWDS_SOURCE_SESSION_STATE_H_\n"
  },
  {
    "path": "libwds/source/source.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/public/source.h\"\n\n#include \"libwds/source/cap_negotiation_state.h\"\n#include \"libwds/source/init_state.h\"\n#include \"libwds/source/streaming_state.h\"\n#include \"libwds/source/session_state.h\"\n#include \"libwds/common/message_handler.h\"\n#include \"libwds/common/rtsp_input_handler.h\"\n#include \"libwds/public/wds_export.h\"\n#include \"libwds/rtsp/getparameter.h\"\n#include \"libwds/rtsp/setparameter.h\"\n#include \"libwds/rtsp/triggermethod.h\"\n#include \"libwds/public/media_manager.h\"\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace {\n\nbool InitializeRequestId(Request* request) {\n  Request::ID id = Request::UNKNOWN;\n  switch(request->method()) {\n  case Request::MethodOptions:\n    id = Request::M2;\n    break;\n  case Request::MethodSetup:\n    id = Request::M6;\n    break;\n  case Request::MethodPlay:\n    id = Request::M7;\n    break;\n  case Request::MethodTeardown:\n    id = Request::M8;\n    break;\n  case Request::MethodPause:\n    id = Request::M9;\n    break;\n  case Request::MethodSetParameter:\n    if (auto payload = rtsp::ToPropertyMapPayload(request->payload())) {\n      if (payload->HasProperty(rtsp::RoutePropertyType))\n        id = Request::M10;\n      else if (payload->HasProperty(rtsp::ConnectorTypePropertyType))\n        id = Request::M11;\n      else if (payload->HasProperty(rtsp::StandbyPropertyType))\n        id = Request::M12;\n      else if (payload->HasProperty(rtsp::IDRRequestPropertyType))\n        id = Request::M13;\n      else if (payload->HasProperty(rtsp::UIBCCapabilityPropertyType))\n        id = Request::M14;\n      else if (payload->HasProperty(rtsp::UIBCSettingPropertyType))\n        id = Request::M15;\n      break;\n    }\n  default:\n    WDS_ERROR(\"Failed to identify the received message\");\n    return false;\n  }\n\n  request->set_id(id);\n  return true;\n}\n\n}\n\nclass SourceStateMachine : public MessageSequenceHandler {\n public:\n   SourceStateMachine(const InitParams& init_params, unsigned& timer_id)\n     : MessageSequenceHandler(init_params) {\n     MessageHandlerPtr m16_sender = make_ptr(new source::M16Sender(init_params));\n     AddSequencedHandler(make_ptr(new source::InitState(init_params)));\n     AddSequencedHandler(make_ptr(new source::CapNegotiationState(init_params)));\n     AddSequencedHandler(make_ptr(new source::SessionState(init_params, timer_id, m16_sender)));\n     AddSequencedHandler(make_ptr(new source::StreamingState(init_params, m16_sender)));\n   }\n};\n\nclass SourceImpl final : public Source, public RTSPInputHandler, public MessageHandler::Observer {\n public:\n  SourceImpl(Delegate* delegate, SourceMediaManager* mng, Peer::Observer* observer);\n\n private:\n  // Source implementation.\n  void Start() override;\n  void Reset() override;\n  void RTSPDataReceived(const std::string& message) override;\n  bool Teardown() override;\n  bool Play() override;\n  bool Pause() override;\n\n  // public MessageHandler::Observer\n  void OnCompleted(MessageHandlerPtr handler) override;\n  void OnError(MessageHandlerPtr handler) override;\n\n  void OnTimerEvent(unsigned timer_id) override;\n\n  // RTSPInputHandler\n  void MessageParsed(std::unique_ptr<Message> message) override;\n  void ParserErrorOccurred(const std::string& invalid_input) override;\n\n  // Keep-alive function\n  void SendKeepAlive();\n  void ResetAndTeardownMedia();\n\n  unsigned keep_alive_timer_;\n  std::shared_ptr<SourceStateMachine> state_machine_;\n  Delegate* delegate_;\n  SourceMediaManager* media_manager_;\n  Peer::Observer* observer_;\n};\n\nSourceImpl::SourceImpl(Delegate* delegate, SourceMediaManager* mng, Peer::Observer* observer)\n  : keep_alive_timer_(0),\n    state_machine_(new SourceStateMachine({delegate, mng, this}, keep_alive_timer_)),\n    delegate_(delegate),\n    media_manager_(mng),\n    observer_(observer) {\n}\n\nvoid SourceImpl::Start() {\n  state_machine_->Start();\n}\n\nvoid SourceImpl::Reset() {\n  state_machine_->Reset();\n  delegate_->ReleaseTimer(keep_alive_timer_);\n}\n\nvoid SourceImpl::RTSPDataReceived(const std::string& message) {\n  AddInput(message);\n}\n\nvoid SourceImpl::OnTimerEvent(unsigned timer_id) {\n  if (keep_alive_timer_ == timer_id)\n    SendKeepAlive();\n  else if (state_machine_->HandleTimeoutEvent(timer_id) && observer_)\n    observer_->ErrorOccurred(TimeoutError);\n}\n\nvoid SourceImpl::SendKeepAlive() {\n  delegate_->ReleaseTimer(keep_alive_timer_);\n  auto get_param = std::unique_ptr<Request>(\n      new rtsp::GetParameter(\"rtsp://localhost/wfd1.0\"));\n  get_param->header().set_cseq(delegate_->GetNextCSeq());\n  get_param->set_id(Request::M16);\n\n  assert(state_machine_->CanSend(get_param.get()));\n  state_machine_->Send(std::move(get_param));\n  keep_alive_timer_ =\n      delegate_->CreateTimer(kDefaultKeepAliveTimeout - kDefaultTimeoutValue);\n  assert(keep_alive_timer_);\n}\n\nnamespace  {\n\nstd::unique_ptr<Message> CreateM5(int send_cseq, rtsp::TriggerMethod::Method method) {\n  auto set_param = std::unique_ptr<Request>(\n      new rtsp::SetParameter(\"rtsp://localhost/wfd1.0\"));\n  set_param->header().set_cseq(send_cseq);\n  auto payload = new rtsp::PropertyMapPayload();\n  payload->AddProperty(\n      std::shared_ptr<rtsp::Property>(new rtsp::TriggerMethod(method)));\n  set_param->set_payload(std::unique_ptr<rtsp::Payload>(payload));\n  set_param->set_id(Request::M5);\n  return std::move(set_param);\n}\n\n}\n\nbool SourceImpl::Teardown() {\n  auto m5 = CreateM5(delegate_->GetNextCSeq(),\n                     rtsp::TriggerMethod::TEARDOWN);\n\n  if (!state_machine_->CanSend(m5.get()))\n    return false;\n  state_machine_->Send(std::move(m5));\n  return true;\n}\n\nbool SourceImpl::Play() {\n  auto m5 = CreateM5(delegate_->GetNextCSeq(),\n                     rtsp::TriggerMethod::PLAY);\n\n  if (!state_machine_->CanSend(m5.get()))\n    return false;\n  state_machine_->Send(std::move(m5));\n  return true;\n}\n\nbool SourceImpl::Pause() {\n  auto m5 = CreateM5(delegate_->GetNextCSeq(),\n                     rtsp::TriggerMethod::PAUSE);\n\n  if (!state_machine_->CanSend(m5.get()))\n    return false;\n  state_machine_->Send(std::move(m5));\n  return true;\n}\n\nvoid SourceImpl::OnCompleted(MessageHandlerPtr handler) {\n  assert(handler == state_machine_);\n  if (observer_)\n    observer_->SessionCompleted();\n}\n\nvoid SourceImpl::OnError(MessageHandlerPtr handler) {\n  assert(handler == state_machine_);\n  if (observer_)\n    observer_->ErrorOccurred(UnexpectedMessageError);\n}\n\nvoid SourceImpl::MessageParsed(std::unique_ptr<Message> message) {\n  if (message->is_request() && !InitializeRequestId(ToRequest(message.get()))) {\n    WDS_ERROR(\"Cannot identify the received message\");\n    if (observer_)\n      observer_->ErrorOccurred(UnexpectedMessageError);\n    return;\n  }\n  if (!state_machine_->CanHandle(message.get())) {\n    WDS_ERROR(\"Cannot handle the received message with Id: %d\", ToRequest(message.get())->id());\n    if (observer_)\n      observer_->ErrorOccurred(UnexpectedMessageError);\n    return;\n  }\n  state_machine_->Handle(std::move(message));\n}\n\nvoid SourceImpl::ParserErrorOccurred(const std::string& invalid_input) {\n  WDS_ERROR(\"Failed to parse: %s\", invalid_input.c_str());\n  if (observer_)\n    observer_->ErrorOccurred(MessageParseError);\n}\n\nSource* Source::Create(Delegate* delegate, SourceMediaManager* mng, Peer::Observer* observer) {\n  return new SourceImpl(delegate, mng, observer);\n}\n\n}  // namespace wds\n"
  },
  {
    "path": "libwds/source/streaming_state.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"libwds/source/streaming_state.h\"\n\n#include \"libwds/public/media_manager.h\"\n#include \"libwds/source/cap_negotiation_state.h\"\n#include \"libwds/source/session_state.h\"\n#include \"libwds/rtsp/reply.h\"\n\nnamespace wds {\n\nusing rtsp::Message;\nusing rtsp::Request;\nusing rtsp::Reply;\n\nnamespace source {\n\nclass M8Handler final : public MessageReceiver<rtsp::Request::M8> {\n public:\n  M8Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M8>(init_params) {\n  }\n\n private:\n  std::unique_ptr<rtsp::Reply> HandleMessage(\n      rtsp::Message* message) override {\n    manager_->Teardown();\n    return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n  }\n};\n\nclass M9Handler final : public MessageReceiver<Request::M9> {\n public:\n  M9Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M9>(init_params) {\n  }\n\n  std::unique_ptr<Reply> HandleMessage(\n      Message* message) override {\n    int response_code = rtsp::STATUS_NotAcceptable;\n    if (!manager_->IsPaused()) {\n      manager_->Pause();\n      response_code = rtsp::STATUS_OK;\n    }\n    return std::unique_ptr<Reply>(new Reply(response_code));\n  }\n};\n\nclass M5Sender final : public OptionalMessageSender<Request::M5> {\n public:\n  M5Sender(const InitParams& init_params)\n    : OptionalMessageSender<Request::M5>(init_params) {\n  }\n  bool HandleReply(Reply* reply) override {\n    return (reply->response_code() == rtsp::STATUS_OK);\n  }\n};\n\nclass M13Handler final : public MessageReceiver<Request::M13> {\n public:\n  M13Handler(const InitParams& init_params)\n    : MessageReceiver<Request::M13>(init_params) {\n  }\n\n  std::unique_ptr<Reply> HandleMessage(\n      Message* message) override {\n    ToSourceMediaManager(manager_)->SendIDRPicture();\n    return std::unique_ptr<Reply>(new Reply(rtsp::STATUS_OK));\n  }\n};\n\nStreamingState::StreamingState(const InitParams& init_params,\n    MessageHandlerPtr m16_sender)\n  : MessageSequenceWithOptionalSetHandler(init_params) {\n  AddSequencedHandler(make_ptr(new M8Handler(init_params)));\n\n  AddOptionalHandler(make_ptr(new M5Sender(init_params)));\n  AddOptionalHandler(make_ptr(new M7Handler(init_params)));\n  AddOptionalHandler(make_ptr(new M9Handler(init_params)));\n  AddOptionalHandler(make_ptr(new M13Handler(init_params)));\n  AddOptionalHandler(m16_sender);\n}\n\nStreamingState::~StreamingState() {\n}\n\n}  // source\n}  // wds\n"
  },
  {
    "path": "libwds/source/streaming_state.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef LIBWDS_SOURCE_STREAMING_STATE_H_\n#define LIBWDS_SOURCE_STREAMING_STATE_H_\n\n#include \"libwds/common/message_handler.h\"\n\nnamespace wds {\nnamespace source {\n\n// Streaming state for RTSP source.\n// Includes M8 message handling and optionally can handle M3, M4, M7, M9-M15\nclass StreamingState : public MessageSequenceWithOptionalSetHandler {\n public:\n  StreamingState(const InitParams& init_params, MessageHandlerPtr m16_sender);\n  ~StreamingState() override;\n};\n\n}  // source\n}  // wds\n\n#endif // LIBWDS_SOURCE_STREAMING_STATE_H_\n"
  },
  {
    "path": "mirac_network/CMakeLists.txt",
    "content": "#FIXME in the future: with cmake 2.8.12 and up it's better\n#to use target_compile_options or add_compile_options\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wall -pthread -std=c++11\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\" )\ninclude_directories (\"${PROJECT_SOURCE_DIR}/include\" )\ninclude_directories (\"${PROJECT_SOURCE_DIR}/libwds/rtsp\" )\ninclude_directories (\"${PROJECT_SOURCE_DIR}/libwds/public\" )\n\nfind_package(PkgConfig REQUIRED)\npkg_check_modules (GLIB2 REQUIRED glib-2.0)\ninclude_directories(${GLIB2_INCLUDE_DIRS})\n\npkg_check_modules (GIO REQUIRED gio-2.0)\ninclude_directories(${GIO_INCLUDE_DIRS})\n\npkg_check_modules (GST REQUIRED gstreamer-1.0)\ninclude_directories(${GST_INCLUDE_DIRS})\n\nadd_library(mirac STATIC mirac-network.cpp mirac-gst-sink.cpp mirac-gst-test-source.cpp mirac-broker.cpp mirac-glib-logging.cpp mirac-gst-bus-handler.cpp)\n\nadd_executable(network-test network-test.cpp)\ntarget_link_libraries (network-test ${GLIB2_LIBRARIES} mirac)\n\nadd_executable(gst-test gst-test.cpp)\ntarget_link_libraries (gst-test mirac wds ${GLIB2_LIBRARIES} ${GIO_LIBRARIES} ${GST_LIBRARIES})\n\nif (WDS_INSTALL_TESTS)\n  install(PROGRAMS network-test gst-test DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})\nendif()\n"
  },
  {
    "path": "mirac_network/gst-test.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Alexander Kanavin <alex.kanavin@gmail.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include <glib.h>\n#include <iostream>\n#include <memory>\n\n#include <glib-unix.h>\n\n#include \"mirac-gst-test-source.hpp\"\n#include \"mirac-gst-sink.hpp\"\n#include \"mirac-glib-logging.hpp\"\n\nstatic gboolean _sig_handler (gpointer data_ptr)\n{\n    GMainLoop *ml = (GMainLoop *) data_ptr;\n\n    g_main_loop_quit(ml);\n\n    return G_SOURCE_CONTINUE;\n}\n\n\nint main (int argc, char *argv[])\n{\n    InitGlibLogging();\n\n    GError *error = NULL;\n    GOptionContext *context;\n    GMainLoop* ml = NULL;\n    \n    gchar* wfd_device_option = NULL;\n    gchar* wfd_stream_option = NULL;\n    gchar* hostname_option = NULL;\n    gint port = 0;\n    \n    GOptionEntry main_entries[] =\n    {\n        { \"device\", 0, 0, G_OPTION_ARG_STRING, &wfd_device_option, \"Specify WFD device type: testsource or sink\", \"(testsource|sink)\"},\n        { \"stream\", 0, 0, G_OPTION_ARG_STRING, &wfd_stream_option, \"Specify WFD stream type for testsource: audio, video, both or desktop capture\", \"(audio|video|both|desktop)\"},\n        { \"hostname\", 0, 0, G_OPTION_ARG_STRING, &hostname_option, \"Specify optional hostname or ip address to stream to or listen on\", \"host\"},\n        { \"port\", 0, 0, G_OPTION_ARG_INT, &port, \"Specify optional UDP port number to stream to or listen on\", \"port\"},\n        { NULL }\n    };\n\n    context = g_option_context_new (\"- WFD source/sink demo application\\n\\nExample:\\ngst-test --device=testsource --stream=both --hostname=127.0.0.1 --port=5000\\ngst-test --device=sink --port=5000\");\n    g_option_context_add_main_entries (context, main_entries, NULL);\n    \n   if (!g_option_context_parse (context, &argc, &argv, &error)) {\n        WDS_ERROR (\"option parsing failed: %s\", error->message);\n        g_option_context_free(context);\n        exit (1);\n    }\n    g_option_context_free(context);\n\n    wfd_test_stream_t wfd_stream = WFD_UNKNOWN_STREAM;\n    if (g_strcmp0(wfd_stream_option, \"audio\") == 0)\n        wfd_stream = WFD_TEST_AUDIO;\n    else if (g_strcmp0(wfd_stream_option, \"video\") == 0)\n        wfd_stream = WFD_TEST_VIDEO;\n    else if (g_strcmp0(wfd_stream_option, \"both\") == 0)\n        wfd_stream = WFD_TEST_BOTH;\n    else if (g_strcmp0(wfd_stream_option, \"desktop\") == 0)\n        wfd_stream = WFD_DESKTOP;\n\n    std::string hostname;\n    if (hostname_option)\n        hostname = hostname_option;\n\n    g_free(wfd_stream_option);\n    g_free(hostname_option);\n\n    gst_init (&argc, &argv);\n\n    std::unique_ptr<MiracGstSink> sink_pipeline;\n    std::unique_ptr<MiracGstTestSource> source_pipeline;\n\n    if (g_strcmp0(wfd_device_option, \"testsource\") == 0) {\n        source_pipeline.reset(new MiracGstTestSource(wfd_stream, hostname, port));\n        source_pipeline->SetState(GST_STATE_PLAYING);\n        WDS_LOG(\"Source UDP port: %d\", source_pipeline->UdpSourcePort());\n    } else if (g_strcmp0(wfd_device_option, \"sink\") == 0) {\n        sink_pipeline.reset(new MiracGstSink(hostname, port));\n        WDS_LOG(\"Listening on port %d\", sink_pipeline->sink_udp_port());\n    }\n\n    g_free(wfd_device_option);\n\n    ml = g_main_loop_new(NULL, TRUE);\n    g_unix_signal_add(SIGINT, _sig_handler, ml);\n    g_unix_signal_add(SIGTERM, _sig_handler, ml);\n\n    g_main_loop_run(ml);\n\n    g_main_loop_unref(ml);\n    \n    return 0;\n}\n\n  "
  },
  {
    "path": "mirac_network/mirac-broker.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <glib-unix.h>\n#include <algorithm>\n\n#include \"mirac-broker.hpp\"\n#include \"mirac-glib-logging.hpp\"\n\nstruct TimerCallbackData {\n  TimerCallbackData(MiracBroker* delegate)\n    : delegate_(delegate), timer_id_(0) {}\n  MiracBroker* delegate_;\n  uint timer_id_;\n};\n\n/* static C callback wrapper */\ngboolean MiracBroker::send_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    auto broker = static_cast<MiracBroker**> (data_ptr);\n    return (*broker)->send_cb(fd, condition);\n}\n\n/* static C callback wrapper */\ngboolean MiracBroker::receive_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    auto broker = static_cast<MiracBroker**> (data_ptr);\n    return (*broker)->receive_cb(fd, condition);\n}\n\n/* static C callback wrapper */\ngboolean MiracBroker::listen_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    auto broker = static_cast<MiracBroker**> (data_ptr);\n    return (*broker)->listen_cb(fd, condition);\n}\n\n/* static C callback wrapper */\ngboolean MiracBroker::connect_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    auto broker = static_cast<MiracBroker**> (data_ptr);\n    return (*broker)->connect_cb(fd, condition);\n}\n\n/* static C callback wrapper */\ngboolean MiracBroker::try_connect (gpointer data_ptr)\n{\n    auto broker = static_cast<MiracBroker*> (data_ptr);\n    broker->try_connect();\n    return false;\n}\n\ngboolean MiracBroker::send_cb (gint fd, GIOCondition condition)\n{\n    try {\n        if (!connection_->Send())\n            return G_SOURCE_CONTINUE;\n    } catch (const MiracConnectionLostException &exception) {\n        on_connection_failure(CONNECTION_LOST);\n    } catch (const std::exception &x) {\n        WDS_WARNING(\"exception: %s\", x.what());\n    }\n    return G_SOURCE_REMOVE;\n}\n\n\ngboolean MiracBroker::receive_cb (gint fd, GIOCondition condition)\n{\n    std::string msg;\n    try {\n        if (connection_->Receive(msg)) {\n            WDS_VLOG(\"Received RTSP message:\\n%s\", msg.c_str());\n            got_message (msg);\n        }\n    } catch (const MiracConnectionLostException &exception) {\n        on_connection_failure(CONNECTION_LOST);\n        return G_SOURCE_REMOVE;\n    }\n    return G_SOURCE_CONTINUE;\n}\n\ngboolean MiracBroker::listen_cb (gint fd, GIOCondition condition)\n{\n    try {\n        connection(network_->Accept());\n        WDS_LOG(\"connection from: %s\", connection_->GetPeerAddress().c_str());\n        on_connected();\n    } catch (const std::exception &x) {\n        WDS_WARNING(\"exception: %s\", x.what());\n    }\n\n    return G_SOURCE_CONTINUE;\n}\n\ngboolean MiracBroker::connect_cb (gint fd, GIOCondition condition)\n{\n    try {\n        if (!network_->Connect(NULL, NULL))\n            return G_SOURCE_CONTINUE;\n        WDS_LOG(\"connection success to: %s\", network_->GetPeerAddress().c_str());\n        connection(network_.release());\n\n        /* make sure any network event sources are removed */\n        network(NULL);\n\n        on_connected();\n    } catch (const std::exception &x) {\n        gdouble elapsed = 1000 * g_timer_elapsed(connect_timer_, NULL);\n        if (elapsed + connect_wait_ > connect_timeout_) {\n            on_connection_failure(CONNECTION_TIMEOUT);\n        } else {\n            connect_wait_id_ = g_timeout_add (connect_wait_, try_connect, this);\n        }\n    }\n    return G_SOURCE_REMOVE;\n}\n\nvoid MiracBroker::network(MiracNetwork *connection)\n{\n    while (g_source_remove_by_user_data(&network_source_ptr_))\n        ;\n    network_.reset(connection);\n}\n\nvoid MiracBroker::connection(MiracNetwork *connection)\n{\n    while (g_source_remove_by_user_data(&connection_source_ptr_))\n        ;\n    connection_.reset(connection);\n\n    if (connection_)\n        g_unix_fd_add(connection_->GetHandle(), G_IO_IN,\n                      receive_cb, &connection_source_ptr_);\n}\n\nvoid MiracBroker::try_connect()\n{\n    WDS_LOG(\"Trying to connect...\");\n\n    connect_wait_id_ = 0;\n    network(new MiracNetwork());\n\n    if (network_->Connect(peer_address_.c_str(), peer_port_.c_str())) {\n        g_unix_fd_add(network_->GetHandle(), G_IO_OUT,\n                      MiracBroker::send_cb, &network_source_ptr_);\n    } else {\n        g_unix_fd_add(network_->GetHandle(), G_IO_OUT,\n                      MiracBroker::connect_cb, &network_source_ptr_);\n    }\n}\n\nunsigned short MiracBroker::get_host_port() const\n{\n    return network_->GetHostPort();\n}\n\nstd::string MiracBroker::get_peer_address() const\n{\n    return connection_->GetPeerAddress();\n}\n\nMiracBroker::MiracBroker (const std::string& listen_port):\n    connect_timer_(NULL)\n{\n    network_source_ptr_ = this;\n    connection_source_ptr_ = this;\n\n    network(new MiracNetwork());\n\n    network_->Bind(NULL, listen_port.c_str());\n    g_unix_fd_add(network_->GetHandle(), G_IO_IN,\n                  MiracBroker::listen_cb, &network_source_ptr_);\n}\n\nMiracBroker::MiracBroker(const std::string& peer_address, const std::string& peer_port, uint timeout):\n    peer_address_(peer_address),\n    peer_port_(peer_port),\n    connect_timeout_(timeout)\n{\n    network_source_ptr_ = this;\n    connection_source_ptr_ = this;\n    connect_timer_ = g_timer_new();\n    try_connect();\n}\n\nMiracBroker::~MiracBroker ()\n{\n    network(NULL);\n    connection(NULL);\n\n    if (connect_timer_) {\n        g_timer_destroy(connect_timer_);\n        connect_timer_ = NULL;\n    }\n\n    if (connect_wait_id_ > 0) {\n        g_source_remove(connect_wait_id_);\n        connect_wait_id_ = 0;\n    }\n    while (!timers_.empty())\n        g_source_remove(timers_.front());\n}\n\nvoid MiracBroker::SendRTSPData(const std::string& data) {\n  WDS_VLOG(\"Sending RTSP message:\\n%s\", data.c_str());\n\n  if (connection_ && !connection_->Send(data))\n      g_unix_fd_add(connection_->GetHandle(), G_IO_OUT,\n                    send_cb, &connection_source_ptr_);\n}\n\nstd::string MiracBroker::GetLocalIPAddress() const {\n  return \"127.0.0.1\";  // FIXME : return the actual local IP address.\n}\n\nvoid MiracBroker::on_timeout_remove(gpointer user_data) {\n  TimerCallbackData* data = static_cast<TimerCallbackData*>(user_data);\n  auto& timers = data->delegate_->timers_;\n  auto it = std::find(timers.begin(), timers.end(), data->timer_id_);\n  if (it != timers.end())\n    timers.erase(it);\n  delete data;\n}\n\nstatic gboolean on_timeout(gpointer user_data) {\n  TimerCallbackData* data = static_cast<TimerCallbackData*>(user_data);\n  data->delegate_->OnTimeout(data->timer_id_);\n  return FALSE;\n}\n\nvoid MiracBroker::OnTimeout(uint timer_id) {\n  Peer()->OnTimerEvent(timer_id);\n}\n\nuint MiracBroker::CreateTimer(int seconds) {\n  TimerCallbackData* data = new TimerCallbackData(this);\n  uint timer_id = g_timeout_add_seconds_full(\n                        G_PRIORITY_DEFAULT,\n                        seconds,\n                        on_timeout,\n                        data,\n                        on_timeout_remove);\n  if (timer_id > 0) {\n    data->timer_id_ = timer_id;\n    timers_.push_back(timer_id);\n  } else {\n    delete data;\n  }\n\n  return timer_id;\n}\n\nvoid MiracBroker::ReleaseTimer(uint timer_id) {\n  if (timer_id > 0) {\n    auto it = std::find(timers_.begin(), timers_.end(), timer_id);\n    if (it != timers_.end() )\n      g_source_remove(*it);\n  }\n}\n\nint MiracBroker::GetNextCSeq(int* initial_peer_cseq) const {\n  static int send_cseq_;\n  ++send_cseq_;\n  if (initial_peer_cseq && send_cseq_ == *initial_peer_cseq)\n    send_cseq_ *= 2;\n\n  return send_cseq_;\n}\n\n"
  },
  {
    "path": "mirac_network/mirac-broker.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef MIRAC_BROKER_HPP\n#define MIRAC_BROKER_HPP\n\n#include <glib.h>\n#include <memory>\n#include <map>\n#include <vector>\n\n#include \"libwds/public/peer.h\"\n#include \"mirac-network.hpp\"\n\nclass MiracBroker : public wds::Peer::Delegate\n{\n    public:\n        MiracBroker (const std::string& listen_port);\n        MiracBroker(const std::string& peer_address, const std::string& peer_port, uint timeout = 3000);\n        virtual ~MiracBroker ();\n        unsigned short get_host_port() const;\n        std::string get_peer_address() const;\n        virtual wds::Peer* Peer() const = 0;\n        void OnTimeout(uint timer_id);\n\n    protected:\n        enum ConnectionFailure {\n            CONNECTION_TIMEOUT,\n            CONNECTION_LOST,\n        };\n\n        // wds::Peer::Delegate\n        void SendRTSPData(const std::string& data) override;\n        std::string GetLocalIPAddress() const override;\n        uint CreateTimer(int seconds) override;\n        void ReleaseTimer(uint timer_id) override;\n        int GetNextCSeq(int* initial_peer_cseq = nullptr) const override;\n\n        virtual void got_message(const std::string& data) {}\n        virtual void on_connected() {};\n        virtual void on_connection_failure(ConnectionFailure failure) {};\n\n    private:\n        static gboolean send_cb (gint fd, GIOCondition condition, gpointer data_ptr);\n        static gboolean receive_cb (gint fd, GIOCondition condition, gpointer data_ptr);\n        static gboolean listen_cb (gint fd, GIOCondition condition, gpointer data_ptr);\n        static gboolean connect_cb (gint fd, GIOCondition condition, gpointer data_ptr);\n        static gboolean try_connect(gpointer data_ptr);\n        static void on_timeout_remove(gpointer user_data);\n\n        gboolean send_cb (gint fd, GIOCondition condition);\n        gboolean receive_cb (gint fd, GIOCondition condition);\n        gboolean listen_cb (gint fd, GIOCondition condition);\n        gboolean connect_cb (gint fd, GIOCondition condition);\n        void try_connect();\n\n        void handle_body(const std::string msg);\n        void handle_header(const std::string msg);\n\n        void network(MiracNetwork* connection);\n        std::unique_ptr<MiracNetwork> network_;\n        MiracBroker *network_source_ptr_;\n\n        void connection(MiracNetwork* connection);\n        std::unique_ptr<MiracNetwork> connection_;\n        MiracBroker *connection_source_ptr_;\n\n        std::vector<uint> timers_;\n\n        std::string peer_address_;\n        std::string peer_port_;\n\n        GTimer *connect_timer_;\n        uint connect_wait_id_;\n        uint connect_timeout_;\n        static const uint connect_wait_ = 200;\n};\n\n\n#endif  /* MIRAC_BROKER_HPP */\n\n"
  },
  {
    "path": "mirac_network/mirac-exception.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Jussi Laako <jussi.laako@linux.intel.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef MIRAC_EXCEPTION_HPP\n#define MIRAC_EXCEPTION_HPP\n\n#include <cstring>\n#include <exception>\n\nclass MiracException : public std::exception\n{\n    public:\n        MiracException () throw ()\n            { }\n        MiracException (int error_code, const char *function = NULL) throw ()\n            {\n                ec = error_code;\n                msg = strerror(ec);\n                add_func(function);\n            }\n        MiracException (const char *error_msg, const char *function = NULL) throw ()\n            {\n                msg = error_msg;\n                add_func(function);\n            }\n        MiracException (int error_code, const char *error_msg, const char *function = NULL) throw ()\n            {\n                ec = error_code;\n                msg = std::string(error_msg) + std::string(\": \") +\n                    std::string(strerror(ec));\n                add_func(function);\n            }\n        virtual ~MiracException () throw ()\n            { }\n\n        virtual const char * what () const throw ()\n            { return msg.c_str(); }\n        virtual operator int () const throw ()\n            { return ec; }\n        virtual operator std::string () const throw ()\n            { return msg; }\n\n    protected:\n        int ec;\n        std::string msg;\n        void add_func (const char *function) throw ()\n            {\n                if (function)\n                    msg = std::string(function) + std::string(\"(): \") + msg;\n            }\n};\n\n\n#endif  // MIRAC_EXCEPTION_HPP\n\n"
  },
  {
    "path": "mirac_network/mirac-glib-logging.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"mirac-glib-logging.hpp\"\n\n#include <glib.h>\n\nnamespace {\n\nvoid MiracGlibLog(const char* format, ...) {\n    va_list va;\n    va_start(va, format);\n    g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, va);\n    va_end(va);\n}\n\nvoid MiracGlibVLog(const char* format, ...) {\n    va_list va;\n    va_start(va, format);\n    g_logv(\"rtsp\", G_LOG_LEVEL_DEBUG, format, va);\n    va_end(va);\n}\n\nvoid MiracGlibWarning(const char* format, ...) {\n    va_list va;\n    va_start(va, format);\n    g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, va);\n    va_end(va);\n}\n\nvoid MiracGlibError(const char* format, ...) {\n    va_list va;\n    va_start(va, format);\n    g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, va);\n    va_end(va);\n}\n\n}  // namespace\n\nvoid InitGlibLogging() {\n    wds::LogSystem::set_log_func(&MiracGlibLog);\n    wds::LogSystem::set_vlog_func(&MiracGlibVLog);\n    wds::LogSystem::set_warning_func(&MiracGlibWarning);\n    wds::LogSystem::set_error_func(&MiracGlibError);\n}\n\n"
  },
  {
    "path": "mirac_network/mirac-glib-logging.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef MIRAC_LOGGING_HPP\n#define MIRAC_LOGGING_HPP\n\n#include \"libwds/public/logging.h\"\n\nvoid InitGlibLogging();\n\n#endif  // MIRAC_LOGGING_HPP\n\n"
  },
  {
    "path": "mirac_network/mirac-gst-bus-handler.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <gst/gst.h>\n#include \"libwds/public/logging.h\"\n\n\ngboolean\nmirac_gstbus_callback (GstBus     *bus,\n                 GstMessage *message,\n                 gpointer    data)\n{\n    GError *err = NULL;\n    gchar *debug = NULL;\n\n    switch (GST_MESSAGE_TYPE (message)) {\n    case GST_MESSAGE_ERROR:\n        gst_message_parse_error (message, &err, &debug);\n        WDS_VLOG (debug);\n        WDS_ERROR (\"[%s] %s\", g_quark_to_string(err->domain), err->message);\n        g_error_free (err);\n        g_free (debug);\n        break;\n    case GST_MESSAGE_WARNING:\n        gst_message_parse_warning (message, &err, &debug);\n        WDS_VLOG (debug);\n        WDS_WARNING (\"[%s] %s\", g_quark_to_string(err->domain), err->message);\n        g_error_free (err);\n        g_free (debug);\n        break;\n    case GST_MESSAGE_INFO:\n        gst_message_parse_info (message, &err, &debug);\n        WDS_VLOG (debug);\n        WDS_LOG (\"[%s] %s\", g_quark_to_string(err->domain), err->message);\n        g_error_free (err);\n        g_free (debug);\n        break;\n    default:\n        /* unhandled message */\n        break;\n    }\n\n    return TRUE;\n}\n"
  },
  {
    "path": "mirac_network/mirac-gst-bus-handler.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2015 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef MIRAC_GST_BUS_HANDLER_HPP\n#define MIRAC_GST_BUS_HANDLER_HPP\n\ngboolean\nmirac_gstbus_callback (GstBus     *bus,\n                     GstMessage *message,\n                     gpointer    data);\n\n#endif"
  },
  {
    "path": "mirac_network/mirac-gst-sink.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"mirac-gst-sink.hpp\"\n#include \"mirac-gst-bus-handler.hpp\"\n#include \"libwds/public/logging.h\"\n\n#include <cassert>\n\nvoid _set_udp_caps(GstElement *playbin, GstElement *source, gpointer    user_data)\n{\n    GstCaps* caps = gst_caps_new_simple (\"application/x-rtp\",\n        \"media\", G_TYPE_STRING, \"video\",\n        \"clock-rate\", G_TYPE_INT, 1,\n        \"encoding-name\", G_TYPE_STRING, \"MP2T\",\n        NULL);\n\n    g_object_set(source, \"caps\", caps, NULL);\n    gst_caps_unref(caps);\n}\n\nMiracGstSink::MiracGstSink (std::string hostname, int port) {\n  // todo (shalamov): move out pipeline initialization\n  // from constructor, otherwise we can't check error conditions\n  std::string gst_pipeline;\n\n  std::string url =  \"udp://\" + (!hostname.empty() ? hostname  : \"::\") + (port > 0 ? \":\" + std::to_string(port) : \":\");\n  gst_pipeline = \"playbin uri=\" + url;\n\n  GError *err = NULL;\n  gst_elem = gst_parse_launch(gst_pipeline.c_str(), &err);\n  if (err != NULL) {\n      WDS_ERROR(\"Cannot initialize gstreamer pipeline: [%s] %s\", g_quark_to_string(err->domain), err->message);\n  }\n\n  if (gst_elem) {\n      GstBus* bus = gst_pipeline_get_bus (GST_PIPELINE (gst_elem));\n      bus_watch_id = gst_bus_add_watch (bus, mirac_gstbus_callback, this);\n      gst_object_unref (bus);\n\n      g_signal_connect(gst_elem, \"source-setup\", G_CALLBACK(_set_udp_caps), NULL);\n      gst_element_set_state (gst_elem, GST_STATE_PLAYING);\n  }\n}\n\nint MiracGstSink::sink_udp_port() {\n    if (gst_elem == NULL)\n        return 0;\n\n    GstElement* source = NULL;\n    g_object_get(gst_elem, \"source\", &source, NULL);\n\n    if (source == NULL)\n        return 0;\n\n    gint port = 0;\n    g_object_get(source, \"port\", &port, NULL);\n    return port;\n}\n\nvoid MiracGstSink::Play() {\n  assert(gst_elem);\n  if(!IsInState(GST_STATE_PLAYING)) {\n    gst_element_set_state(gst_elem, GST_STATE_PLAYING);\n    IsInState(GST_STATE_PLAYING);\n  }\n}\n\nvoid MiracGstSink::Pause() {\n  assert(gst_elem);\n  if(!IsPaused()) {\n    gst_element_set_state(gst_elem, GST_STATE_PAUSED);\n    IsPaused();\n  }\n}\n\nvoid MiracGstSink::Teardown() {\n  assert(gst_elem);\n  if(!IsInState(GST_STATE_READY)) {\n    gst_element_set_state(gst_elem, GST_STATE_READY);\n    IsInState(GST_STATE_READY);\n  }\n}\n\nbool MiracGstSink::IsPaused() const {\n  return IsInState(GST_STATE_PAUSED);\n}\n\nbool MiracGstSink::IsInState(GstState state) const {\n  assert(gst_elem);\n  GstState current_state;\n  gst_element_get_state(gst_elem, &current_state, NULL, GST_CLOCK_TIME_NONE);\n  return current_state == state;\n}\n\nMiracGstSink::~MiracGstSink () {\n  if (gst_elem) {\n    gst_element_set_state (gst_elem, GST_STATE_NULL);\n    g_source_remove (bus_watch_id);\n    gst_object_unref (GST_OBJECT (gst_elem));\n  }\n}\n"
  },
  {
    "path": "mirac_network/mirac-gst-sink.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef MIRAC_GST_SINK_HPP\n#define MIRAC_GST_SINK_HPP\n\n#include <gst/gst.h>\n#include <string>\n\nclass MiracGstSink\n{\npublic:\n    MiracGstSink(std::string hostname, int port);\n    ~MiracGstSink ();\n\n    void Play();\n    void Pause();\n    bool IsPaused() const;\n    void Teardown();\n\n    int sink_udp_port();\n\nprivate:\n    bool IsInState(GstState state) const;\n    GstElement* gst_elem;\n    guint bus_watch_id;\n};\n\n#endif\n"
  },
  {
    "path": "mirac_network/mirac-gst-test-source.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Alexander Kanavin <alex.kanavin@gmail.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n#include <gio/gio.h>\n\n#include \"mirac-gst-test-source.hpp\"\n#include \"mirac-gst-bus-handler.hpp\"\n#include \"libwds/public/logging.h\"\n\nMiracGstTestSource::MiracGstTestSource (wfd_test_stream_t wfd_stream_type, std::string hostname, int port)\n{\n    std::string gst_pipeline;\n\n    std::string hostname_port = (!hostname.empty() ? \"host=\" + hostname + \" \": \" \") + (port > 0 ? \"port=\" + std::to_string(port) : \"\");\n\n    if (wfd_stream_type == WFD_TEST_BOTH) {\n        gst_pipeline = \"videotestsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc ! muxer.  audiotestsrc ! avenc_ac3 ! muxer.  mpegtsmux name=muxer ! rtpmp2tpay ! udpsink name=sink \" +\n            hostname_port;\n    } else if (wfd_stream_type == WFD_TEST_AUDIO) {\n        gst_pipeline = \"audiotestsrc ! avenc_ac3 ! mpegtsmux ! rtpmp2tpay ! udpsink name=sink \" + hostname_port;\n    } else if (wfd_stream_type == WFD_TEST_VIDEO) {\n        gst_pipeline = \"videotestsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink name=sink \" + hostname_port;\n    } else if (wfd_stream_type == WFD_DESKTOP) {\n        gst_pipeline = \"ximagesrc ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency ! mpegtsmux ! rtpmp2tpay ! udpsink name=sink \" + hostname_port;\n    }\n\n    GError *err = NULL;\n    gst_elem = gst_parse_launch(gst_pipeline.c_str(), &err);\n    if (err != NULL) {\n        WDS_ERROR(\"Cannot initialize gstreamer pipeline: [%s] %s\", g_quark_to_string(err->domain), err->message);\n    }\n\n    if (gst_elem) {\n        GstBus* bus = gst_pipeline_get_bus (GST_PIPELINE (gst_elem));\n        bus_watch_id = gst_bus_add_watch (bus, mirac_gstbus_callback, this);\n        gst_object_unref (bus);\n    }\n}\n\nvoid MiracGstTestSource::SetState(GstState state)\n{\n    if (gst_elem) {\n        gst_element_set_state (gst_elem, state);\n    }\n}\n\nGstState MiracGstTestSource::GetState() const\n{\n    if (!gst_elem)\n        return GST_STATE_NULL;\n    GstState result;\n    gst_element_get_state (gst_elem, &result, NULL, GST_CLOCK_TIME_NONE);\n    return result;\n}\n\nint MiracGstTestSource::UdpSourcePort()\n{\n    if (gst_elem == NULL)\n        return 0;\n\n    GstElement* sink = NULL;\n    sink = gst_bin_get_by_name(GST_BIN(gst_elem), \"sink\");\n\n    if (sink == NULL)\n        return 0;\n\n    GSocket* socket = NULL;\n    g_object_get(sink, \"used-socket\", &socket, NULL);\n    if (socket == NULL)\n        return 0;\n\n    guint16 port = g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(g_socket_get_local_address(socket, NULL)));\n\n    return port;\n}\n\nMiracGstTestSource::~MiracGstTestSource ()\n{\n    if (gst_elem) {\n        gst_element_set_state (gst_elem, GST_STATE_NULL);\n        g_source_remove (bus_watch_id);\n        gst_object_unref (GST_OBJECT (gst_elem));\n    }\n}\n"
  },
  {
    "path": "mirac_network/mirac-gst-test-source.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Alexander Kanavin <alex.kanavin@gmail.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef MIRAC_GST_TEST_SOURCE_HPP\n#define MIRAC_GST_TEST_SOURCE_HPP\n\n#include <gst/gst.h>\n\nenum wfd_test_stream_t {WFD_TEST_AUDIO, WFD_TEST_VIDEO, WFD_TEST_BOTH, WFD_DESKTOP, WFD_UNKNOWN_STREAM};\n\n\nclass MiracGstTestSource\n{\npublic:\n    MiracGstTestSource(wfd_test_stream_t wfd_stream, std::string hostname, int port);\n    ~MiracGstTestSource ();\n\n    void SetState(GstState state);\n    GstState GetState() const;\n\n    int UdpSourcePort();\n\nprivate:\n    GstElement* gst_elem;\n    guint bus_watch_id;\n};\n\n#endif\n"
  },
  {
    "path": "mirac_network/mirac-network.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Jussi Laako <jussi.laako@linux.intel.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include <cstddef>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <cerrno>\n#include <algorithm>\n#include <memory>\n\n#include <unistd.h>\n#include <netdb.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <sys/ioctl.h>\n#include <netinet/in.h>\n#include <netinet/tcp.h>\n#include <arpa/inet.h>\n\n#include \"mirac-network.hpp\"\n\n\n#define MIRAC_MAX_NAMELEN       255\n\n\nMiracNetwork::MiracNetwork ()\n{\n    Init();\n}\n\n\nMiracNetwork::MiracNetwork (int conn_handle)\n{\n    Init();\n    handle = conn_handle;\n}\n\n\n\nMiracNetwork::~MiracNetwork ()\n{\n    Close();\n}\n\n\nvoid MiracNetwork::Init ()\n{\n    long ps;\n\n    handle = -1;\n\n    ps = sysconf(_SC_PAGESIZE);\n    page_size = (ps <= 0) ? 4096 : static_cast<size_t> (ps);\n\n    conn_ares = NULL;\n}\n\n\nvoid MiracNetwork::Close ()\n{\n    if (handle >= 0)\n        close(handle);\n    handle = -1;\n\n    if (conn_ares)\n    {\n        freeaddrinfo(reinterpret_cast<struct addrinfo *> (conn_ares));\n        conn_ares = NULL;\n    }\n}\n\n\nvoid MiracNetwork::Bind (const char *address, const char *service)\n{\n    int ec;\n    int reuse = 1;\n    struct addrinfo *addr_res = NULL;\n    struct addrinfo *bind_addr;\n    struct addrinfo addr_hint;\n\n    Close();\n\n    memset(&addr_hint, 0x00, sizeof(addr_hint));\n    addr_hint.ai_flags = AI_PASSIVE;\n    ec = getaddrinfo(address, service, &addr_hint, &addr_res);\n    if (ec)\n        throw MiracException(gai_strerror(ec), __FUNCTION__);\n    bind_addr = addr_res;\n    while (bind_addr)\n    {\n        /* note, the SOCK_NONBLOCK is specific to Linux 2.6.27+,\n         * on other platforms use either fcntl() or ioctl(h, FIONBIO, 1) */\n        handle = socket(addr_res->ai_family,\n            addr_res->ai_socktype | SOCK_NONBLOCK, addr_res->ai_protocol);\n        if (handle < 0)\n            throw MiracException(errno, \"socket()\", __FUNCTION__);\n        if (setsockopt(handle, SOL_SOCKET, SO_REUSEADDR,\n            &reuse, sizeof(reuse)))\n            throw MiracException(errno, \"setsockopt()\", __FUNCTION__);\n\tif (bind(handle, bind_addr->ai_addr, bind_addr->ai_addrlen) == 0)\n           break;\n        else if (!bind_addr->ai_next)\n            throw MiracException(errno, \"bind()\", __FUNCTION__);\n        close(handle);\n\tbind_addr = bind_addr->ai_next;\n    }\n    freeaddrinfo(addr_res);\n\n    if (listen(handle, 1))\n        throw MiracException(errno, \"listen()\", __FUNCTION__);\n}\n\n\nMiracNetwork * MiracNetwork::Accept ()\n{\n    int ch;\n    int nonblock = 1;\n\n    ch = accept(handle, NULL, NULL);\n    if (ch < 0)\n        throw MiracException(errno, \"accept()\", __FUNCTION__);\n    if (ioctl(ch, FIONBIO, &nonblock))\n        throw MiracException(errno, \"ioctl(FIONBIO)\", __FUNCTION__);\n    return new MiracNetwork(ch);\n}\n\n\nbool MiracNetwork::Connect (const char *address, const char *service)\n{\n    int ec = 0;\n\n    if (address && service)\n    {\n        Close();\n\n        struct addrinfo addr_hint;\n        memset(&addr_hint, 0x00, sizeof(addr_hint));\n        addr_hint.ai_socktype = SOCK_STREAM;\n        ec = getaddrinfo(address, service, &addr_hint,\n            reinterpret_cast<struct addrinfo **> (&conn_ares));\n        if (ec)\n            throw MiracException(gai_strerror(ec), __FUNCTION__);\n        conn_aptr = conn_ares;\n    }\n    else\n    {\n        socklen_t optlen = sizeof(ec);\n        if (getsockopt(handle, SOL_SOCKET, SO_ERROR, &ec, &optlen))\n            throw MiracException(errno, \"getsockopt()\", __FUNCTION__);\n        if (!ec)\n            return true;\n        conn_aptr = reinterpret_cast<struct addrinfo *> (conn_aptr)->ai_next;\n    }\n\n    struct addrinfo *addr = reinterpret_cast<struct addrinfo *> (conn_aptr);\n    if (!addr)\n        throw MiracException(\"peer unavailable\", __FUNCTION__);\n    /* note, the SOCK_NONBLOCK is specific to Linux 2.6.27+,\n     * on other platforms use either fcntl() or ioctl(h, FIONBIO, 1) */\n    handle = socket(addr->ai_family,\n        addr->ai_socktype | SOCK_NONBLOCK, addr->ai_protocol);\n    if (handle < 0)\n        throw MiracException(errno, \"socket()\", __FUNCTION__);\n    if (connect(handle, addr->ai_addr, addr->ai_addrlen))\n    {\n        if (errno == EINPROGRESS)\n            return false;\n        throw MiracException(errno, \"connect()\", __FUNCTION__);\n    }\n    return true;\n}\n\n\nstd::string MiracNetwork::GetPeerAddress ()\n{\n    int ec;\n    socklen_t addrsize = std::max(sizeof(sockaddr_in), sizeof(sockaddr_in6));\n    std::unique_ptr<uint8_t []> addrbuf(new uint8_t[addrsize]);\n    std::unique_ptr<char []> namebuf(new char [MIRAC_MAX_NAMELEN + 1]);\n    std::unique_ptr<char []> servbuf(new char [MIRAC_MAX_NAMELEN + 1]);\n\n    if (getpeername(handle,\n        reinterpret_cast<struct sockaddr *> (addrbuf.get()), &addrsize))\n        throw MiracException(errno, \"getpeername()\", __FUNCTION__);\n    ec = getnameinfo(\n        reinterpret_cast<struct sockaddr *> (addrbuf.get()), addrsize,\n        namebuf.get(), MIRAC_MAX_NAMELEN,\n        servbuf.get(), MIRAC_MAX_NAMELEN,\n        NI_NOFQDN|NI_NUMERICHOST|NI_NUMERICSERV);\n    if (ec)\n        throw MiracException(gai_strerror(ec), __FUNCTION__);\n    return std::string(namebuf.get());\n}\n\n\nunsigned short MiracNetwork::GetHostPort ()\n{\n    socklen_t addrsize = std::max(sizeof(sockaddr_in), sizeof(sockaddr_in6));\n    std::unique_ptr<uint8_t []> addrbuf(new uint8_t[addrsize]);\n\n    if (getsockname(handle,\n        reinterpret_cast<struct sockaddr *> (addrbuf.get()), &addrsize))\n        throw MiracException(errno, \"getsockname()\", __FUNCTION__);\n\n    struct sockaddr *saddr =\n        reinterpret_cast<struct sockaddr *> (addrbuf.get());\n    if (saddr->sa_family == AF_INET)\n    {\n        struct sockaddr_in *ip4addr =\n            reinterpret_cast<struct sockaddr_in *> (saddr);\n        return ntohs(ip4addr->sin_port);\n    }\n    else if (saddr->sa_family == AF_INET6)\n    {\n        struct sockaddr_in6 *ip6addr =\n            reinterpret_cast<struct sockaddr_in6 *> (saddr);\n        return ntohs(ip6addr->sin6_port);\n    }\n    return 0;\n}\n\n\nbool MiracNetwork::Receive (std::string &message)\n{\n    int ec;\n    char nb[page_size];\n\n    do {\n        ec = recv(handle, nb, page_size, 0);\n        if (ec > 0)\n            message.append(nb, ec);\n        else if (ec < 0)\n        {\n            if (errno == EAGAIN || errno == EWOULDBLOCK)\n                break;\n            if (errno == ECONNRESET)\n                throw MiracConnectionLostException( __FUNCTION__);\n            throw MiracException(errno, \"recv()\", __FUNCTION__);\n        }\n        else  // ec == 0\n            throw MiracConnectionLostException( __FUNCTION__);\n    } while (ec > 0);\n\n    return true;\n}\n\n\nbool MiracNetwork::Receive (std::string &message, size_t length)\n{\n    int ec;\n    char nb[page_size];\n\n    do {\n        ec = recv(handle, nb, page_size, 0);\n        if (ec > 0)\n            recv_buf.append(nb, ec);\n        else if (ec < 0)\n        {\n            if (errno == EAGAIN || errno == EWOULDBLOCK)\n                break;\n            if (errno == ECONNRESET)\n                throw MiracConnectionLostException( __FUNCTION__);\n            throw MiracException(errno, \"recv()\", __FUNCTION__);\n        }\n        else  // ec == 0\n            throw MiracConnectionLostException( __FUNCTION__);\n    } while (ec > 0);\n\n    if (recv_buf.size() < length)\n        return false;\n\n    message = recv_buf.substr(0, length);\n    recv_buf.erase(0, length);\n    return true;\n}\n\n\nbool MiracNetwork::Send (const std::string &message)\n{\n    int ec;\n\n    if (!message.empty())\n        send_buf.append(message);\n    do {\n        ec = send(handle, send_buf.c_str(), send_buf.size(), MSG_NOSIGNAL);\n        if (ec > 0)\n            send_buf.erase(0, ec);\n        else\n        {\n            if (errno == EAGAIN || errno == EWOULDBLOCK)\n                return false;\n            if (errno == EPIPE || errno == ENOTCONN)\n                throw MiracConnectionLostException(__FUNCTION__);\n            throw MiracException(errno, \"send()\", __FUNCTION__);\n        }\n    } while (send_buf.size() > 0);\n\n    return true;\n}\n\n"
  },
  {
    "path": "mirac_network/mirac-network.hpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Jussi Laako <jussi.laako@linux.intel.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#ifndef MIRAC_NETWORK_HPP\n#define MIRAC_NETWORK_HPP\n\n#include <cstring>\n#include <string>\n\n#include \"mirac-exception.hpp\"\n\n\nclass MiracConnectionLostException : public MiracException\n{\n    public:\n        MiracConnectionLostException (const char *function = NULL) throw ()\n            {\n                msg = std::string(\"Connection lost\");\n                add_func(function);\n            }\n        virtual ~MiracConnectionLostException () throw ()\n            { }\n};\n\n\n\nclass MiracNetwork\n{\n    public:\n        MiracNetwork ();\n        MiracNetwork (int conn_handle);\n        virtual ~MiracNetwork ();\n        void Bind (const char *address, const char *service);\n        MiracNetwork * Accept ();\n        bool Connect (const char *address, const char *service);\n        int GetHandle () const\n            { return handle; }\n        std::string GetPeerAddress ();\n        unsigned short GetHostPort ();\n        bool Receive (std::string &message);\n        bool Receive (std::string &message, size_t length);\n        bool Send (const std::string &message = std::string());\n\n    protected:\n        int handle;\n        size_t page_size;\n        std::string recv_buf;\n        std::string send_buf;\n\n        void Init ();\n        void Close ();\n\n    private:\n        void *conn_ares;\n        void *conn_aptr;\n};\n\n\n#endif  /* MIRAC_NETWORK_HPP */\n\n"
  },
  {
    "path": "mirac_network/network-test.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * Contact: Jussi Laako <jussi.laako@linux.intel.com>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n\n#include <glib.h>\n#include <glib-unix.h>\n\n#include <memory>\n\n#include \"mirac-network.hpp\"\n\n\nstatic gboolean _sig_handler (gpointer data_ptr)\n{\n    GMainLoop *ml = (GMainLoop *) data_ptr;\n\n    g_main_loop_quit(ml);\n\n    return G_SOURCE_CONTINUE;\n}\n\n\nstatic gboolean _send_cb (gint fd, GIOCondition condition,\n    gpointer data_ptr)\n{\n    MiracNetwork *ctx = reinterpret_cast<MiracNetwork *> (data_ptr);\n\n    try\n    {\n        return ctx->Send() ? G_SOURCE_REMOVE : G_SOURCE_CONTINUE;\n    }\n    catch (std::exception &x)\n    {\n        g_warning(\"exception: %s\", x.what());\n        delete ctx;\n    }\n    return G_SOURCE_REMOVE;\n}\n\n\nstatic gboolean _receive_cb (gint fd, GIOCondition condition,\n    gpointer data_ptr)\n{\n    MiracNetwork *ctx = reinterpret_cast<MiracNetwork *> (data_ptr);\n\n    try\n    {\n        std::string msg;\n        if (ctx->Receive(msg))\n        {\n            g_message(\"message: %s\", msg.c_str());\n            if (!ctx->Send(msg))\n                g_unix_fd_add(ctx->GetHandle(), G_IO_OUT, _send_cb, ctx);\n        }\n    }\n    catch (std::exception &x)\n    {\n        g_warning(\"exception: %s\", x.what());\n        delete ctx;\n        return G_SOURCE_REMOVE;\n    }\n    return G_SOURCE_CONTINUE;\n}\n\n\nstatic gboolean _listen_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    try\n    {\n        MiracNetwork *listener = reinterpret_cast<MiracNetwork *> (data_ptr);\n        MiracNetwork *ctx;\n\n        ctx = listener->Accept();\n        g_message(\"connection from: %s\", ctx->GetPeerAddress().c_str());\n        g_unix_fd_add(ctx->GetHandle(), G_IO_IN, _receive_cb, ctx);\n    }\n    catch (std::exception &x)\n    {\n        g_warning(\"exception: %s\", x.what());\n    }\n    return G_SOURCE_CONTINUE;\n}\n\n\nstatic gboolean _sendmsg_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    try\n    {\n        MiracNetwork *ctx = reinterpret_cast<MiracNetwork *> (data_ptr);\n\n        if (!ctx->Send (std::string(\"Hello world!\\r\\n\\r\\n\")))\n            g_unix_fd_add(ctx->GetHandle(), G_IO_OUT, _send_cb, ctx);\n\n    }\n    catch (std::exception &x)\n    {\n        g_warning(\"exception %s\", x.what());\n    }\n    return G_SOURCE_REMOVE;\n}\n\n\nstatic gboolean _connect_cb (gint fd, GIOCondition condition, gpointer data_ptr)\n{\n    try\n    {\n        MiracNetwork *ctx = reinterpret_cast<MiracNetwork *> (data_ptr);\n\n        if (!ctx->Connect(NULL, NULL))\n            return G_SOURCE_CONTINUE;\n        g_message(\"connection success to: %s\", ctx->GetPeerAddress().c_str());\n        g_unix_fd_add(ctx->GetHandle(), G_IO_OUT, _sendmsg_cb, ctx);\n    }\n    catch (std::exception &x)\n    {\n        g_warning(\"exception: %s\", x.what());\n    }\n    return G_SOURCE_REMOVE;\n}\n\n\nint main (int argc, char *argv[])\n{\n    GMainLoop *ml = NULL;\n\n    try\n    {\n        ml = g_main_loop_new(NULL, TRUE);\n        g_unix_signal_add(SIGINT, _sig_handler, ml);\n        g_unix_signal_add(SIGTERM, _sig_handler, ml);\n\n        std::unique_ptr<MiracNetwork> net_listen(new MiracNetwork);\n        std::unique_ptr<MiracNetwork> net_conn(new MiracNetwork);\n\n        net_listen->Bind(\"127.0.0.1\", \"8080\");\n        g_message(\"bound to port %hu\", net_listen->GetHostPort());\n        g_unix_fd_add(net_listen->GetHandle(), G_IO_IN, _listen_cb,\n            net_listen.get());\n\n        if (net_conn->Connect(\"127.0.0.1\", \"8080\"))\n            g_unix_fd_add(net_conn->GetHandle(), G_IO_OUT, _sendmsg_cb,\n                net_conn.get());\n        else\n            g_unix_fd_add(net_conn->GetHandle(), G_IO_OUT, _connect_cb,\n                net_conn.get());\n\n        g_main_loop_run(ml);\n    }\n    catch (std::exception &x)\n    {\n        g_error(\"exception: %s\", x.what());\n    }\n\n    if (ml)\n        g_main_loop_unref(ml);\n\n    return 0;\n}\n\n"
  },
  {
    "path": "p2p/CMakeLists.txt",
    "content": "#FIXME in the future: with cmake 2.8.12 and up it's better\n#to use target_compile_options or add_compile_options\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -O0 -std=c++11 -ggdb3 -Wall\")\nset(CMAKE_C_FLAGS \"${CMAKE_CXX_FLAGS} -O0 -std=c99 -ggdb3 -Wall\")\n\nfind_package(PkgConfig REQUIRED)\npkg_check_modules (GIO REQUIRED gio-2.0)\ninclude_directories(${GIO_INCLUDE_DIRS})\n\nadd_library(p2p STATIC\n    connman-peer.cpp connman-client.cpp information-element.cpp\n)\n\nadd_executable(register-peer-service main.cpp)\ntarget_link_libraries (register-peer-service p2p ${GIO_LIBRARIES})\n\nadd_executable(test-ie test-ie.cpp)\ntarget_link_libraries (test-ie p2p ${GIO_LIBRARIES})\n\nadd_test(InformationElementTest test-ie)\n\nif (WDS_INSTALL_TESTS)\n  install(PROGRAMS test-ie DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})\nendif()\n"
  },
  {
    "path": "p2p/connman-client.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n#include <gio/gio.h>\n#include <memory>\n\n#include \"connman-client.h\"\n\nnamespace P2P {\n\nvoid Client::connman_appeared_cb(GDBusConnection *connection, const char *name, const char *owner, gpointer data_ptr)\n{\n    g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,\n                              G_DBUS_PROXY_FLAGS_NONE,\n                              NULL,\n                              \"net.connman\",\n                              \"/\",\n                              \"net.connman.Manager\",\n                              NULL,\n                              Client::proxy_cb,\n                              data_ptr);\n\n    /* TODO should get the p2p object path\n     * by watching Manager.TechnologyAdded/TechnologyRemoved */\n    g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,\n                              G_DBUS_PROXY_FLAGS_NONE,\n                              NULL,\n                              \"net.connman\",\n                              \"/net/connman/technology/p2p\",\n                              \"net.connman.Technology\",\n                              NULL,\n                              Client::technology_proxy_cb,\n                              data_ptr);\n}\n\nvoid Client::connman_disappeared_cb(GDBusConnection *connection, const char *name, gpointer data_ptr)\n{\n    auto client = static_cast<Client*> (data_ptr);\n    client->connman_disappeared ();\n}\n\n/* static C callback */\nvoid Client::proxy_signal_cb (GDBusProxy *proxy, const char *sender, const char *signal, GVariant *params, gpointer data_ptr)\n{\n    if (g_strcmp0(signal, \"PeersChanged\") != 0)\n        return;\n\n    auto client = static_cast<Client*> (data_ptr);\n    client->peers_changed (params);\n}\n\nvoid Client::get_technologies_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY (object);\n    char *object_path;\n    bool p2p_found = false;\n    GVariant *params;\n    GVariantIter *iter;\n\n    params = g_dbus_proxy_call_finish (proxy, res, &error);\n    if (error) {\n        std::cout << \"GetTechnologies error \" << error->message << std::endl;\n        g_clear_error (&error);\n    }\n\n    g_variant_get (params, \"(a(oa{sv}))\", &iter);\n    while (g_variant_iter_loop (iter, \"(oa{sv})\", &object_path, NULL)) {\n        /* TODO: warn if P2P is not enabled. Also, don't set\n         * the client available before P2P is enabled */\n        if (g_strcmp0(object_path, \"/net/connman/technology/p2p\") == 0) {\n            p2p_found = true;\n            break;\n        }\n    }\n    g_variant_unref(params);\n    g_variant_iter_free (iter);\n\n    if (!p2p_found)\n        std::cout << \"Warning: P2P not found in Connman technologies.\" << std::endl;\n}\n\nvoid Client::register_peer_service_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY (object);\n\n    g_dbus_proxy_call_finish (proxy, res, &error);\n    if (error) {\n        std::cout << \"register error \" << error->message << std::endl;\n        g_clear_error (&error);\n        return;\n    }\n}\n\nvoid Client::get_peers_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY(object);\n    GVariantIter *peer_iter;\n    GVariant *params;\n\n    params = g_dbus_proxy_call_finish(proxy, res, &error);\n    if (error) {\n        std::cout << \"GetPeers error \" << error->message << std::endl;\n        g_clear_error(&error);\n        return;\n    }\n\n    g_variant_get(params, \"(a(oa{sv}))\", &peer_iter);\n    auto client = static_cast<Client*>(data_ptr);\n    client->handle_new_peers(peer_iter);\n\n    g_variant_unref(params);\n    g_variant_iter_free(peer_iter);\n}\n\n/* static C callback */\nvoid Client::scan_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY (object);\n\n    g_dbus_proxy_call_finish (proxy, res, &error);\n    if (error) {\n        std::cout << \"scan error \" << error->message << std::endl;\n        g_clear_error (&error);\n        return;\n    }\n\n    std::cout << \"* scan complete\"<< std::endl;\n}\n\n/* static C callback */\nvoid Client::proxy_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    auto client = static_cast<Client*> (data_ptr);\n    client->proxy_cb (res);\n}\n\n/* static C callback */\nvoid Client::technology_proxy_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    auto client = static_cast<Client*> (data_ptr);\n    client->technology_proxy_cb (res);\n}\n\n\nvoid Client::connman_disappeared()\n{\n    bool was_available = is_available();\n\n    if (proxy_)\n        g_clear_object (&proxy_);\n    if (technology_proxy_)\n        g_clear_object (&technology_proxy_);\n\n    if (observer_ && was_available)\n        observer_->on_availability_changed(this);\n}\n\nvoid Client::handle_new_peers (GVariantIter *added)\n{\n    GVariantIter *props;\n    const char *path;\n\n    while (g_variant_iter_loop(added, \"(oa{sv})\", &path, &props)) {\n        try {\n            peers_[path] = std::make_shared<P2P::Peer>(path, props);\n            if (observer_)\n                observer_->on_peer_added(this, peers_[path]);\n        } catch (std::invalid_argument &x) {\n            /* Not a miracast peer */\n        }\n    }\n}\n\nvoid Client::peers_changed (GVariant *params)\n{\n    GVariantIter *added, *removed;\n    const char *path;\n\n    g_variant_get(params, \"(a(oa{sv})ao)\", &added, &removed);\n\n    handle_new_peers(added);\n\n    while (g_variant_iter_loop (removed, \"o\", &path)) {\n        auto it = peers_.find(path);\n        if (it == peers_.end())\n            return;\n\n        if (observer_)\n            observer_->on_peer_removed(this, it->second);\n\n        peers_.erase(it);\n    }\n\n    g_variant_iter_free (added);\n    g_variant_iter_free (removed);\n}\n\nvoid Client::register_peer_service ()\n{\n    GVariantBuilder builder;\n\n    /* HACK: Connman should figure out the \"master\" boolean on its own but it does not.\n     * We need to do it here with InformationElement for now... */\n    P2P::InformationElement ie(array_);\n    bool is_master = (ie.get_device_type() != P2P::SOURCE);\n\n    g_variant_builder_init (&builder, G_VARIANT_TYPE(\"a{sv}\"));\n    g_variant_builder_add (&builder, \"{sv}\",\n                           \"WiFiDisplayIEs\",\n                           g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,\n                                                      array_->bytes,\n                                                      array_->length,\n                                                      1));\n\n    g_dbus_proxy_call (proxy_,\n                       \"RegisterPeerService\",\n                       g_variant_new (\"(a{sv}b)\", &builder, is_master),\n                       G_DBUS_CALL_FLAGS_NONE,\n                       -1,\n                       NULL,\n                       Client::register_peer_service_cb,\n                       this);\n}\n\nvoid Client::unregister_peer_service ()\n{\n    GVariantBuilder builder;\n    g_variant_builder_init (&builder, G_VARIANT_TYPE(\"a{sv}\"));\n    g_variant_builder_add (&builder, \"{sv}\",\n                           \"WiFiDisplayIEs\",\n                           g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,\n                                                      array_->bytes,\n                                                      array_->length,\n                                                      1));\n\n    g_dbus_proxy_call (proxy_,\n                       \"UnregisterPeerService\",\n                       g_variant_new (\"(a{sv}b)\", &builder, TRUE),\n                       G_DBUS_CALL_FLAGS_NONE,\n                       -1,\n                       NULL,\n                       Client::register_peer_service_cb,\n                       this);\n}\n\nvoid Client::initialize_peers ()\n{\n    g_dbus_proxy_call(proxy_,\n                      \"GetPeers\",\n                      NULL,\n                      G_DBUS_CALL_FLAGS_NONE,\n                      -1,\n                      NULL,\n                      Client::get_peers_cb,\n                      this);\n}\n\n\nvoid Client::proxy_cb (GAsyncResult *result)\n{\n    GError *error = NULL;\n\n    proxy_ = g_dbus_proxy_new_for_bus_finish(result, &error);\n    if (error) {\n        std::cout << \"proxy error \"<< std::endl;\n        g_clear_error (&error);\n        return;\n    }\n\n    g_signal_connect(proxy_, \"g-signal\",\n                     G_CALLBACK (Client::proxy_signal_cb), this);\n\n    g_dbus_proxy_call(proxy_,\n                      \"GetTechnologies\",\n                      NULL,\n                      G_DBUS_CALL_FLAGS_NONE,\n                      -1,\n                      NULL,\n                      Client::get_technologies_cb,\n                      this);\n\n    initialize_peers();\n    register_peer_service();\n\n    if(observer_ && is_available())\n        observer_->on_availability_changed(this);\n}\n\nvoid Client::technology_proxy_cb (GAsyncResult *result)\n{\n    GError *error = NULL;\n\n    technology_proxy_ = g_dbus_proxy_new_for_bus_finish(result, &error);\n    if (error) {\n        std::cout << \"tech proxy error \"<< std::endl;\n        g_clear_error (&error);\n    }\n\n    if(observer_ && is_available())\n        observer_->on_availability_changed(this);\n}\n\nClient::Client(std::unique_ptr<P2P::InformationElementArray> &take_array, Observer *observer):\n    proxy_(NULL),\n    technology_proxy_(NULL),\n    observer_(observer),\n    array_(std::move(take_array))\n{\n    connman_watcher_ = g_bus_watch_name (G_BUS_TYPE_SYSTEM,\n                                         \"net.connman\",\n                                         G_BUS_NAME_WATCHER_FLAGS_NONE,\n                                         Client::connman_appeared_cb,\n                                         Client::connman_disappeared_cb,\n                                         this, NULL);\n}\n\nClient::~Client()\n{\n    if (connman_watcher_ != 0) {\n        g_bus_unwatch_name (connman_watcher_);\n        connman_watcher_ = 0;\n    }\n    if (proxy_)\n        g_clear_object (&proxy_);\n    if (technology_proxy_)\n        g_clear_object (&technology_proxy_);\n}\n\nvoid Client::set_information_element(std::unique_ptr<P2P::InformationElementArray> &take_array)\n{\n    g_return_if_fail (is_available());\n\n    unregister_peer_service();\n    array_ = std::move (take_array);\n    register_peer_service();\n}\n\nbool Client::is_available() const\n{\n    return proxy_ && technology_proxy_;\n}\n\nvoid Client::scan()\n{\n    g_return_if_fail (is_available());\n\n    g_dbus_proxy_call (technology_proxy_,\n                       \"Scan\",\n                       NULL,\n                       G_DBUS_CALL_FLAGS_NONE,\n                       60 * 1000,\n                       NULL,\n                       Client::scan_cb,\n                       this);\n}\n\n}\n"
  },
  {
    "path": "p2p/connman-client.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef CONNMAN_CLIENT_H_\n#define CONNMAN_CLIENT_H_\n\n#include <memory>\n#include <gio/gio.h>\n\n#include \"information-element.h\"\n#include \"connman-peer.h\"\n\nnamespace P2P {\n\nclass Client {\n    public:\n        class Observer {\n            public:\n                virtual void on_peer_added(Client *client, std::shared_ptr<P2P::Peer> peer) {}\n                virtual void on_peer_removed(Client *client, std::shared_ptr<P2P::Peer> peer) {}\n                virtual void on_availability_changed(Client *client) {}\n\n            protected:\n                virtual ~Observer() {}\n        };\n\n        Client(std::unique_ptr<P2P::InformationElementArray> &take_array, Observer *observer = NULL);\n        virtual ~Client();\n\n        void set_information_element(std::unique_ptr<P2P::InformationElementArray> &take_array);\n        void set_observer(Observer* observer) {\n            observer_ = observer;\n        }\n\n        bool is_available() const;\n        /* TODO error / finished handling */\n        void scan();\n\n    private:\n        static void connman_appeared_cb(GDBusConnection *connection, const char *name, const char *owner, gpointer data_ptr);\n        static void connman_disappeared_cb(GDBusConnection *connection, const char *name, gpointer data_ptr);\n        static void proxy_signal_cb (GDBusProxy *proxy, const char *sender, const char *signal, GVariant *params, gpointer data_ptr);\n        static void proxy_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void technology_proxy_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void get_technologies_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void register_peer_service_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void scan_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void get_peers_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n\n        void connman_disappeared();\n        void peers_changed (GVariant *params);\n        void proxy_cb(GAsyncResult *res);\n        void technology_proxy_cb(GAsyncResult *res);\n        void handle_new_peers(GVariantIter *added);\n\n        void initialize_peers();\n        void register_peer_service();\n        void unregister_peer_service();\n\n        uint connman_watcher_;\n        GDBusProxy *proxy_;\n        GDBusProxy *technology_proxy_;\n\n        Observer* observer_;\n        std::unique_ptr<P2P::InformationElementArray>array_;\n        std::map<std::string, std::shared_ptr<P2P::Peer>> peers_;\n};\n\n}\n#endif // CONNMAN_CLIENT_H_\n"
  },
  {
    "path": "p2p/connman-peer.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n#include <stdexcept>\n#include <gio/gio.h>\n\n#include \"connman-peer.h\"\n\nnamespace P2P {\n\n/* static C callback */\nvoid Peer::proxy_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    auto client = static_cast<Peer*> (data_ptr);\n    client->proxy_cb (res);\n}\n\n/* static C callback */\nvoid Peer::proxy_signal_cb (GDBusProxy *proxy, const char *sender, const char *signal, GVariant *params, gpointer data_ptr)\n{\n    GVariant *property;\n    char *name;\n    auto peer = static_cast<Peer*> (data_ptr);\n\n    if (g_strcmp0(signal, \"PropertyChanged\") != 0)\n        return;\n\n    g_variant_get (params, \"(sv)\", &name, &property);\n\n    peer->handle_property_change (name, property);\n}\n\nvoid Peer::handle_property_change (const char *name, GVariant *property)\n{\n    if (g_strcmp0(name, \"State\") == 0) {\n        state_changed (g_variant_get_string (property, NULL));\n    } else if (g_strcmp0(name, \"Name\") == 0) {\n        name_changed (g_variant_get_string (property, NULL));\n    } else if (g_strcmp0(name, \"Services\") == 0) {\n        GVariantIter *service_array, *services;\n        GVariant *spec_val;\n\n        g_variant_get (property, \"a(a{sv})\", &service_array);\n        while (g_variant_iter_loop (service_array, \"(a{sv})\", &services)) {\n            const char *service_name;\n            while (g_variant_iter_loop (services, \"{sv}\", &service_name, &spec_val)) {\n                if (g_strcmp0 (service_name, \"WiFiDisplayIEs\") == 0) {\n                    uint8_t *bytes;\n                    gsize length;\n\n                    bytes = (uint8_t*)g_variant_get_fixed_array (spec_val, &length, 1);\n                    std::unique_ptr<P2P::InformationElementArray> array\n                            (new P2P::InformationElementArray(length, bytes));\n                    ie_.reset(new P2P::InformationElement (array));\n                }\n            }\n        }\n        g_variant_iter_free (service_array);\n    } else if (g_strcmp0(name, \"IPv4\") == 0) {\n        GVariantIter *ips;\n        GVariant *spec_val;\n        char *name;\n        const char *remote = \"\";\n        const char *local = \"\";\n\n        g_variant_get (property, \"a{sv}\", &ips);\n        while (g_variant_iter_loop (ips, \"{sv}\", &name, &spec_val)) {\n            if (g_strcmp0 (name, \"Remote\") == 0) {\n                remote = g_variant_get_string (spec_val, NULL);\n            } else if (g_strcmp0 (name, \"Local\") == 0) {\n                local = g_variant_get_string (spec_val, NULL);\n            }\n        }\n        ips_changed (remote, local);\n\n        g_variant_iter_free (ips);\n    }\n}\n\n/* static C callback */\nvoid Peer::connect_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY (object);\n\n    g_dbus_proxy_call_finish (proxy, res, &error);\n    if (error) {\n        std::cout << \"connect error \" << error->message << std::endl;\n        g_clear_error (&error);\n        return;\n    }\n\n    std::cout << \"* connected \"<< std::endl;\n}\n\n/* static C callback */\nvoid Peer::disconnect_cb (GObject *object, GAsyncResult *res, gpointer data_ptr)\n{\n    GError *error = NULL;\n    GDBusProxy *proxy = G_DBUS_PROXY (object);\n\n    g_dbus_proxy_call_finish (proxy, res, &error);\n    if (error) {\n        std::cout << \"disconnect error \" << error->message << std::endl;\n        g_clear_error (&error);\n        return;\n    }\n\n    std::cout << \"* disconnected \"<< std::endl;\n}\n\nvoid Peer::proxy_cb (GAsyncResult *result)\n{\n    GError *error = NULL;\n\n    proxy_ = g_dbus_proxy_new_for_bus_finish(result, &error);\n    if (error) {\n        std::cout << \"Peer proxy error \"<< std::endl;\n        g_clear_error (&error);\n        return;\n    }\n\n    g_signal_connect (proxy_, \"g-signal\",\n                      G_CALLBACK (Peer::proxy_signal_cb), this);\n\n    /* TODO check the ip address in case it's up to date already */\n\n    if (observer_)\n        observer_->on_initialized(this);\n}\n\nvoid Peer::ips_changed (const char *remote, const char *local)\n{\n    if (g_strcmp0 (remote, remote_host_.c_str()) == 0 &&\n        g_strcmp0 (local, local_host_.c_str()) == 0)\n        return;\n\n    auto was_available = is_available();\n\n    if (g_strcmp0 (remote, \"0.0.0.0\") == 0)\n        remote_host_.clear();\n    else\n        remote_host_ = std::string(remote);\n\n    if (g_strcmp0 (local, \"0.0.0.0\") == 0)\n        local_host_.clear();\n    else\n        local_host_ = std::string(local);\n\n    if (!observer_)\n        return;\n\n    if (was_available != is_available())\n        observer_->on_availability_changed(this);\n}\n\nvoid Peer::state_changed (const char *state)\n{\n    bool ready = (g_strcmp0 (state, \"ready\") == 0);\n\n    if (ready_ == ready)\n        return;\n    \n    auto was_available = is_available();\n    ready_ = ready;\n\n    if (!observer_)\n        return;\n\n    if (was_available != is_available())\n        observer_->on_availability_changed(this);\n}\n\nvoid Peer::name_changed (const char *name)\n{\n    if (g_strcmp0 (name, name_.c_str()) == 0)\n        return;\n\n    name_ = std::string (name);\n}\n\n\nPeer::Peer(const char *object_path, GVariantIter *props):\n    observer_(NULL)\n{\n    GVariant *val;\n    const char *prop_name;\n\n    while (g_variant_iter_loop (props, \"{&sv}\", &prop_name, &val)) {\n        handle_property_change (prop_name, val);\n    }\n\n    if (!ie_)\n        throw std::invalid_argument(\"WiFiDisplayIEs is a required property\");\n\n    g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,\n                              G_DBUS_PROXY_FLAGS_NONE,\n                              NULL,\n                              \"net.connman\",\n                              object_path,\n                              \"net.connman.Peer\",\n                              NULL,\n                              Peer::proxy_cb,\n                              this);\n}\n\nvoid Peer::connect()\n{\n    g_dbus_proxy_call (proxy_,\n                       \"Connect\",\n                       NULL,\n                       G_DBUS_CALL_FLAGS_NONE,\n                       60 * 1000, // is 1 minute too long?\n                       NULL,\n                       Peer::connect_cb,\n                       this);\n}\n\nvoid Peer::disconnect()\n{\n    g_dbus_proxy_call (proxy_,\n                       \"Disconnect\",\n                       NULL,\n                       G_DBUS_CALL_FLAGS_NONE,\n                       -1,\n                       NULL,\n                       Peer::disconnect_cb,\n                       this);\n}\n\n\nPeer::~Peer()\n{\n    if (proxy_)\n        g_clear_object (&proxy_);\n}\n\n}\n"
  },
  {
    "path": "p2p/connman-peer.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <gio/gio.h>\n#include \"information-element.h\"\n\n#ifndef CONNMAN_PEER_H_\n#define CONNMAN_PEER_H_\n\nnamespace P2P {\n\nclass Peer {\n    public:\n        class Observer {\n            public:\n                virtual void on_availability_changed(Peer *peer) {}\n                virtual void on_initialized(Peer *peer) {}\n\n            protected:\n                virtual ~Observer() {}\n        };\n\n        Peer(const char *object_path, GVariantIter *property_iterator);\n        virtual ~Peer();\n\n        void set_observer(Observer* observer) {\n            observer_ = observer;\n        }\n\n        /* TODO add error handling for these -- maybe through observer.on_error? */\n        void connect();\n        void disconnect();\n\n        const P2P::DeviceType device_type() const { return ie_->get_device_type(); }\n        const std::string& name() const { return name_; }\n        const std::string& remote_host() const {return remote_host_; }\n        const int remote_port() const { return ie_->get_rtsp_port(); }\n        const std::string& local_host() const {return local_host_; }\n        bool is_available() const { return ready_ && !remote_host_.empty() && !local_host_.empty(); }\n\n    private:\n        static void proxy_signal_cb (GDBusProxy *proxy, const char *sender, const char *signal, GVariant *params, gpointer data_ptr);\n        static void proxy_cb(GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void connect_cb (GObject *object, GAsyncResult *res, gpointer data_ptr);\n        static void disconnect_cb (GObject *object, GAsyncResult *res, gpointer data_ptr);\n\n        void ips_changed (const char *remote, const char *local);\n        void state_changed (const char *state);\n        void name_changed (const char *name);\n        void proxy_cb (GAsyncResult *res);\n        void handle_property_change (const char *name, GVariant *property);\n\n        Observer *observer_;\n        std::string name_;\n        std::string remote_host_;\n        std::string local_host_;\n        bool ready_;\n        GDBusProxy *proxy_;\n        std::shared_ptr<P2P::InformationElement> ie_;\n};\n\n}\n#endif // CONNMAN_PEER_H_\n"
  },
  {
    "path": "p2p/information-element.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <assert.h> \n#include <iostream>\n#include <string.h>\n#include <netinet/in.h> // htons()\n\n#include \"information-element.h\"\n\nnamespace P2P {\n\nSubelement* new_subelement (SubelementId id)\n{\n    Subelement* element;\n    switch (id) {\n        case DEVICE_INFORMATION:\n            element = (Subelement*)new DeviceInformationSubelement;\n            break;\n        case ASSOCIATED_BSSID:\n            element = (Subelement*)new AssociatedBSSIDSubelement;\n            break;\n        case COUPLED_SINK_INFORMATION:\n            element = (Subelement*)new CoupledSinkInformationSubelement;\n            break;\n        default:\n            element = NULL;\n            break;\n    }\n\n    if (element) {\n        /* Fill in the common values */\n        memset(element, 0, SubelementSize[id]);\n        element->id = id;\n        element->length = htons(SubelementSize[id] - 3);\n    }\n\n    return element;\n}\n\nvoid delete_subelement (Subelement *element)\n{\n    switch (element->id) {\n        case DEVICE_INFORMATION:\n            delete ((DeviceInformationSubelement*)element);\n            break;\n        case ASSOCIATED_BSSID:\n            delete ((AssociatedBSSIDSubelement*)element);\n            break;\n        case COUPLED_SINK_INFORMATION:\n            delete ((CoupledSinkInformationSubelement*)element);\n            break;\n        default:\n            assert(false);\n    }\n}\n\nInformationElement::InformationElement(): length_(0) {}\n\nInformationElement::InformationElement(const std::unique_ptr<InformationElementArray> &array)\n{\n    uint pos = 0;\n    length_ = array->length;\n\n    while (length_ >= pos + 2) {\n        SubelementId id = (SubelementId)array->bytes[pos];\n        size_t subelement_size = SubelementSize[id];\n\n        Subelement *element = new_subelement(id);\n        if (element) {\n            memcpy (element, array->bytes + pos, subelement_size);\n            subelements_[id] = element;\n        }\n        pos += subelement_size;\n    }\n}\n\nInformationElement::~InformationElement()\n{\n    for (auto it = subelements_.begin(); it != subelements_.end(); it++){\n        P2P::delete_subelement ((*it).second);\n    }\n    subelements_.clear();\n}\n\nvoid InformationElement::add_subelement(P2P::Subelement* subelement)\n{\n    SubelementId id = (SubelementId)subelement->id;\n    Subelement* old = subelements_[id];\n    if (old){\n        P2P::delete_subelement (old);\n    } else {\n        length_ += SubelementSize[id];\n    }\n    subelements_[id] = subelement;\n}\n\nconst DeviceType InformationElement::get_device_type() const\n{\n    auto it = subelements_.find (DEVICE_INFORMATION);\n    if (it == subelements_.end()) {\n        /* FIXME : exception ? */\n        return DUAL_ROLE;\n    }\n\n    auto dev_info = (P2P::DeviceInformationSubelement*)(*it).second;\n    return (DeviceType)dev_info->field1.device_type;\n}\n\nconst int InformationElement::get_rtsp_port() const\n{\n    auto it = subelements_.find (DEVICE_INFORMATION);\n    if (it == subelements_.end()) {\n       /* FIXME : exception ? */\n       return -1;\n    }\n\n    auto dev_info = (P2P::DeviceInformationSubelement*)(*it).second;\n    return dev_info->session_management_control_port;\n}\n\nstd::unique_ptr<InformationElementArray> InformationElement::serialize () const\n{\n    uint8_t pos = 0;\n    std::unique_ptr<InformationElementArray> array\n            (new InformationElementArray(length_));\n\n    for (auto it = subelements_.begin(); it != subelements_.end(); it++) {\n        Subelement* element = (*it).second;\n        memcpy (array->bytes + pos, element, P2P::SubelementSize[element->id]);\n        pos += P2P::SubelementSize[element->id];\n    }\n\n    return array;\n}\n\nstd::string InformationElement::to_string() const\n{\n    std::string ret;\n\n    auto array = serialize ();\n\n    for (size_t i = 0; i < array->length; i++) {\n        char hex[3];\n        sprintf(hex,\"%02X\", array->bytes[i]);\n        ret += hex;\n    }\n\n    return ret;\n}\n\n} // namespace P2P\n\n"
  },
  {
    "path": "p2p/information-element.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef INFORMATION_ELEMENT_H_\n#define INFORMATION_ELEMENT_H_\n\n#include <cstring>\n#include <map>\n#include <memory>\n#include <string>\n#include <stdint.h>\n\n\nnamespace P2P {\n\nenum DeviceType {\n    SOURCE,\n    PRIMARY_SINK,\n    SECONDARY_SINK,\n    DUAL_ROLE\n};\n\nenum SubelementId {\n    DEVICE_INFORMATION,\n    ASSOCIATED_BSSID,\n    AUDIO_FORMATS,\n    VIDEO_FORMATS,\n    FORMATS_3D,\n    CONTENT_PROTECTION,\n    COUPLED_SINK_INFORMATION,\n    EXTENDED_CAPABILITY,\n    LOCAL_IP_ADDRESS,\n    SESSION_INFORMATION,\n    ALTERNATIVE_MAC,\n};\n\n// SubelementSize == subelement.length - 3\nconst uint16_t SubelementSize[] = {\n    9,\n    9,\n    18,\n    24,\n    20,\n    4,\n    10,\n    5,\n    11,\n    3, // variable: 3 + N*24, where N is number of devices connected to GO\n    9,\n};\n\nstruct __attribute__ ((packed)) Subelement {\n    uint8_t id;\n    uint16_t length;\n};\n\nstruct __attribute__ ((packed)) DeviceinformationBits1 {\n    unsigned device_type : 2; // DeviceType\n    unsigned coupled_sink_support_at_source : 1;\n    unsigned coupled_sink_support_at_sink : 1;\n    unsigned session_availability : 1;\n    unsigned reserved : 1;\n    unsigned service_discovery_support : 1;\n    unsigned preferred_connectivity : 1;\n};\n\nstruct __attribute__ ((packed)) DeviceinformationBits2 {\n    unsigned hdcp_support : 1;\n    unsigned time_synchronization_support : 1;\n    unsigned audio_unsupport_at_primary_sink : 1;\n    unsigned audio_only_support_at_source : 1;\n    unsigned tdls_persistent_group : 1;\n    unsigned tdls_persistent_group_reinvoke : 1;\n    unsigned reserved2 : 2;\n};\n\nstruct __attribute__ ((packed)) DeviceInformationSubelement {\n    uint8_t id;\n    uint16_t length;\n    DeviceinformationBits2 field2;\n    DeviceinformationBits1 field1;\n    uint16_t session_management_control_port;\n    uint16_t maximum_throughput;\n};\n\nstruct __attribute__ ((packed)) AssociatedBSSIDSubelement {\n    uint8_t id;\n    uint16_t length;\n    uint8_t bssid[6];\n};\n\nstruct __attribute__ ((packed)) CoupledSinkStatus {\n    unsigned status : 2;\n    unsigned reserved : 6; \n};\n\nstruct __attribute__ ((packed)) CoupledSinkInformationSubelement {\n    uint8_t id;\n    uint16_t length;\n    CoupledSinkStatus status;\n    uint8_t mac_address[6];\n};\n\nstruct InformationElementArray {\n    uint8_t *bytes;\n    uint length;\n\n    InformationElementArray(uint len) : length(len) {\n        bytes = new uint8_t[length];\n    }\n\n    InformationElementArray(uint len, uint8_t* in_bytes) :\n        length(len) {\n        bytes = new uint8_t[length];\n        memcpy (bytes, in_bytes, length);\n\n    }\n\n    ~InformationElementArray() {\n        delete[] bytes;\n    }\n};\n\nSubelement* new_subelement (SubelementId id);\n\nclass InformationElement {\n  public:\n    InformationElement();\n    InformationElement(const std::unique_ptr<InformationElementArray> &array);\n    virtual ~InformationElement();\n\n    void add_subelement(P2P::Subelement* subelement);\n    const DeviceType get_device_type() const;\n    const int get_rtsp_port() const;\n\n    std::unique_ptr<InformationElementArray> serialize () const;\n    std::string to_string() const;\n\n  private:\n    void delete_subelement(P2P::Subelement* subelement);\n\n    uint length_;\n    std::map<SubelementId, P2P::Subelement*> subelements_;\n};\n\n} // namespace P2P\n\n#endif // INFORMATION_ELEMENT_H_\n"
  },
  {
    "path": "p2p/main.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <assert.h> \n#include <iostream>\n#include <string.h>\n#include <netinet/in.h> // htons()\n\n#include \"connman-client.h\"\n#include \"information-element.h\"\n\nint main (int argc, const char **argv)\n{\n    GMainLoop *main_loop = g_main_loop_new(NULL, TRUE);\n\n    // check that packing works\n    assert (sizeof(P2P::DeviceInformationSubelement) ==\n            P2P::SubelementSize[P2P::DEVICE_INFORMATION]);\n    assert (sizeof(P2P::AssociatedBSSIDSubelement) ==\n            P2P::SubelementSize[P2P::ASSOCIATED_BSSID]);\n    assert (sizeof(P2P::CoupledSinkInformationSubelement) ==\n            P2P::SubelementSize[P2P::COUPLED_SINK_INFORMATION]);\n\n    // Create a information element for a simple WFD Sink\n    P2P::InformationElement ie;\n    auto sub_element = P2P::new_subelement(P2P::DEVICE_INFORMATION);\n    auto dev_info = (P2P::DeviceInformationSubelement*)sub_element;\n    dev_info->session_management_control_port =  htons(8080);\n    dev_info->maximum_throughput = htons(50);\n    dev_info->field1.device_type = P2P::PRIMARY_SINK;\n    dev_info->field1.session_availability = true;\n    ie.add_subelement (sub_element);\n\n    std::cout << \"Registering \" << ie.to_string() <<  std::endl;\n\n    // register the P2P service with connman\n    auto array = ie.serialize ();\n    P2P::Client p2p_client (array);\n\n    g_main_loop_run (main_loop);\n    g_main_loop_unref (main_loop);\n\n    return 0;\n}\n"
  },
  {
    "path": "p2p/test-ie.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <assert.h> \n#include <iostream>\n#include <string.h>\n#include <netinet/in.h> // htons()\n\n#include \"connman-client.h\"\n#include \"information-element.h\"\n\nint main (int argc, const char **argv)\n{\n    // check that packing works\n    if (sizeof(P2P::DeviceInformationSubelement) !=\n        P2P::SubelementSize[P2P::DEVICE_INFORMATION] ||\n        sizeof(P2P::AssociatedBSSIDSubelement) !=\n        P2P::SubelementSize[P2P::ASSOCIATED_BSSID] ||\n        sizeof(P2P::CoupledSinkInformationSubelement) !=\n        P2P::SubelementSize[P2P::COUPLED_SINK_INFORMATION]) {\n        std::cout << \"Subelement struct size checks failed\"<< std::endl;\n        return 1;\n    }\n\n    P2P::InformationElement ie;\n    auto sub_element = P2P::new_subelement(P2P::DEVICE_INFORMATION);\n    auto dev_info = (P2P::DeviceInformationSubelement*)sub_element;\n    dev_info->session_management_control_port =  htons(8080);\n    dev_info->maximum_throughput = htons(50);\n    dev_info->field1.device_type = P2P::PRIMARY_SINK;\n    dev_info->field1.session_availability = true;\n\n    ie.add_subelement (sub_element);\n    ie.add_subelement (P2P::new_subelement(P2P::COUPLED_SINK_INFORMATION));\n    ie.add_subelement (P2P::new_subelement(P2P::ASSOCIATED_BSSID));\n\n    auto array = ie.serialize ();\n    P2P::InformationElement ie2(array);\n    auto array1 = ie.to_string();\n    auto array2 = ie2.to_string();\n    if (array1 != array2) {\n        std::cout << \"Expected byte array '\" << array1\n                  << \"', got '\" << array2 << \"'\" << std::endl;\n        return 1;\n    }\n\n    \n    return 0;\n}\n"
  },
  {
    "path": "rtsp-message-exchanges.txt",
    "content": "\n**************************************************\n* RTSP messages during WFD session establishment *\n**************************************************\n\n\nThere are five different states:\n   1. capability negotiation A\n   2. capability negotiation B\n   3. RTSP session establishment\n   4. WFD session establishment\n   5. WFD session\n\nI'm listing the possible exchanges below, per state (except for the\nlast state: that's a lot more work and mostly not required for POC).\n  *   = message\n  ***  = message, valid start point for a message exchange in this state\n\n\nSOURCE                                   SINK\nMESSAGES                                 MESSAGES\n-------------------------------------------------------------\n\n\nSTATE 1 capability negotiation A\n-------------------------------------------------------------\n*** M1 OPTIONS           -------->\n                                        if M1 response == 200\n                                        send M2\n\n\n                         <--------      * M2 OPTIONS\nif M2 response = 200\nsend M3\n\n\n* M3 GET_PARAMETER       -------->\nif M3 response == 200\nmove to state 2, send M4\n\n\nSTATE 2 capability negotiation B\n-------------------------------------------------------------\n\n*** M3 GET_PARAMETER     -------->\n\n* M4 SET_PARAMETER     -------->\n(mandatory and optional parameters below)\nif M4 response == 200\nsend M5\n\n\nSTATE 3 RTSP session establishment\n-------------------------------------------------------------\n\n*** M3 GET_PARAMETER     -------->\n\n\n*** M4 SET_PARAMETER     -------->\n\n\n* M5 SET_PARAMETER       -------->\n(trigger SETUP)                         if M5 response == 200 \n                                        send M6\n\n\n                         <--------      * M6 SETUP\n                                        if M6 response == 200\n                                        move to state 4, send M7\n\n\nSTATE 4 WFD session establishment\n-------------------------------------------------------------\n\n*** M3 GET_PARAMETER     -------->\n\n\n*** M5 SET_PARAMETER     -------->\n(trigger TEARDOWN)                      if M5 response = 200\n                                        send M8\n\n\n*** M5 SET_PARAMETER     -------->\n(trigger PLAY)                          if M5 response == 200\n                                        send M7\n\n\n                         <--------      * M7 PLAY\nif M7 response == 200\nmove to state 5, start streaming\n\n\n                                        *** M8 TEARDOWN\nif M8 response == 200\nmove to state 1\n\n\n\n\nSTATE 5 WFD Session\n---------------------------------------------------------------\nTODO ...\n\n\n\n\n\n*****************************\n* GET/SET Method parameters *\n*****************************\n\n\n    M = mandatory\n    O = optional\n\nThese rules apply _before_ the WFD sessions is established\n(in other words states 1-4): \n\n                    request                reply\n* M3 GET_PARAMETER \n-----------------------------------------------------------------\naudio-codecs        M                      M\nvideo-formats       M                      M\n3d-video-formats    O                      M (if in request)\ncontent-protection  O                      M (if in request)\ndisplay-edid        O                      M (if in request)\ncoupled-sink        O                      M (if in request)\nclient-rtp-ports    M                      M\nI2C                 O                      M (if in request)\nuibc-capability     O                      M (if in request)\nconnector-type      O                      M (if in request)\nstandby-resume--    O                      M (if in request)\n\n\n* M4 SET_PARAMETER\naudio-codecs        M (if stream contains audio) \nvideo-formats       M (if no preferred-display and stream contains video)\n3d-video-formats    M (if no preferred-display and stream includes 3d)\npresentation-url    M \nclient-rtp-ports    M\npreferred-display-- O                        (spec error on p 111?)\nuibc-capability     O\nuibc-setting        O\n\n\n* M5 SET_PARAMETER \ntrigger-method      M\n\n"
  },
  {
    "path": "sink/CMakeLists.txt",
    "content": "#FIXME in the future: with cmake 2.8.12 and up it's better\n#to use target_compile_options or add_compile_options\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wall -pthread -std=c++11\")\n\ninclude_directories (\"${PROJECT_SOURCE_DIR}\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/include\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/p2p\")\ninclude_directories (\"${PROJECT_SOURCE_DIR}/mirac_network\")\n\nfind_package(PkgConfig REQUIRED)\n\npkg_check_modules (GLIB2 REQUIRED glib-2.0)\ninclude_directories(${GLIB2_INCLUDE_DIRS})\n\npkg_check_modules (GIO REQUIRED gio-2.0)\ninclude_directories(${GIO_INCLUDE_DIRS})\n\npkg_check_modules (GST REQUIRED gstreamer-1.0)\ninclude_directories(${GST_INCLUDE_DIRS})\n\nadd_executable(sink-test main.cpp sink-app.cpp sink.cpp gst_sink_media_manager.cpp)\ntarget_link_libraries (sink-test mirac wds p2p ${GIO_LIBRARIES} ${GST_LIBRARIES})\n\nif (WDS_INSTALL_TESTS)\n  install(PROGRAMS sink-test DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})\nendif()\n"
  },
  {
    "path": "sink/gst_sink_media_manager.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include \"gst_sink_media_manager.h\"\n\nGstSinkMediaManager::GstSinkMediaManager(const std::string& hostname)\n  : gst_pipeline_(new MiracGstSink(hostname, 0)) {\n}\n\nvoid GstSinkMediaManager::Play() {\n  gst_pipeline_->Play();\n}\n\nvoid GstSinkMediaManager::Pause() {\n  gst_pipeline_->Pause();\n}\n\nvoid GstSinkMediaManager::Teardown() {\n  gst_pipeline_->Teardown();\n}\n\nbool GstSinkMediaManager::IsPaused() const {\n  return gst_pipeline_->IsPaused();\n}\n\nstd::pair<int,int> GstSinkMediaManager::GetLocalRtpPorts() const {\n  return std::pair<int,int>(gst_pipeline_->sink_udp_port(), 0);\n}\n\nvoid GstSinkMediaManager::SetPresentationUrl(const std::string& url) {\n  presentation_url_ = url;\n}\n\nstd::string GstSinkMediaManager::GetPresentationUrl() const {\n  return presentation_url_;\n}\n\nvoid GstSinkMediaManager::SetSessionId(const std::string& session) {\n  session_ = session;\n}\n\nstd::string GstSinkMediaManager::GetSessionId() const {\n  return session_;\n}\n\nstd::vector<wds::H264VideoCodec>\nGstSinkMediaManager::GetSupportedH264VideoCodecs() const {\n  wds::RateAndResolutionsBitmap cea_rr;\n  wds::RateAndResolutionsBitmap vesa_rr;\n  wds::RateAndResolutionsBitmap hh_rr;\n  wds::RateAndResolution i;\n  // declare that we support all resolutions, CHP and level 4.2\n  // gstreamer should handle all of it :)\n  for (i = wds::CEA640x480p60; i <= wds::CEA1920x1080p24; ++i)\n    cea_rr.set(i);\n  for (i = wds::VESA800x600p30; i <= wds::VESA1920x1200p30; ++i)\n    vesa_rr.set(i);\n  for (i = wds::HH800x480p30; i <= wds::HH848x480p60; ++i)\n    hh_rr.set(i);\n  return {wds::H264VideoCodec(wds::CHP, wds::k4_2, cea_rr, vesa_rr, hh_rr),\n          wds::H264VideoCodec(wds::CBP, wds::k4_2, cea_rr, vesa_rr, hh_rr)};\n}\n\nwds::NativeVideoFormat GstSinkMediaManager::GetNativeVideoFormat() const {\n  // pick the maximum possible resolution, let gstreamer deal with it\n  // TODO: get the actual screen size of the system\n  return wds::NativeVideoFormat(wds::CEA1920x1080p60);\n}\n\nbool GstSinkMediaManager::SetOptimalVideoFormat(const wds::H264VideoFormat& optimal_format) {\n  return true;\n}\n\nwds::ConnectorType GstSinkMediaManager::GetConnectorType() const {\n  return wds::ConnectorTypeNone;\n}\n"
  },
  {
    "path": "sink/gst_sink_media_manager.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef GST_SINK_MEDIA_MANAGER_H_\n#define GST_SINK_MEDIA_MANAGER_H_\n\n#include <memory>\n\n#include \"libwds/public/media_manager.h\"\n#include \"mirac-gst-sink.hpp\"\n\nclass GstSinkMediaManager : public wds::SinkMediaManager {\n public:\n  explicit GstSinkMediaManager(const std::string& hostname);\n\n  void Play() override;\n  void Pause() override;\n  void Teardown() override;\n  bool IsPaused() const override;\n  std::pair<int,int> GetLocalRtpPorts() const override;\n  void SetPresentationUrl(const std::string& url) override;\n  std::string GetPresentationUrl() const override;\n  void SetSessionId(const std::string& session) override;\n  std::string GetSessionId() const override;\n\n  std::vector<wds::H264VideoCodec> GetSupportedH264VideoCodecs() const override;\n  wds::NativeVideoFormat GetNativeVideoFormat() const override;\n  bool SetOptimalVideoFormat(const wds::H264VideoFormat& optimal_format) override;\n  wds::ConnectorType GetConnectorType() const override;\n\n private:\n  std::string hostname_;\n  std::string presentation_url_;\n  std::string session_;\n  std::unique_ptr<MiracGstSink> gst_pipeline_;\n};\n\n#endif // GST_SINK_MEDIA_MANAGER_H_\n"
  },
  {
    "path": "sink/main.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <glib.h>\n#include <glib-unix.h>\n#include <gst/gst.h>\n\n#include <iostream>\n\n#include \"mirac-glib-logging.hpp\"\n\n#include \"sink-app.h\"\n#include \"sink.h\"\n\n\nstatic gboolean _sig_handler (gpointer data_ptr)\n{\n    GMainLoop *main_loop = (GMainLoop *) data_ptr;\n\n    g_main_loop_quit(main_loop);\n\n    return G_SOURCE_CONTINUE;\n}\n\nstatic void parse_input_and_call_sink(\n    const std::string& command, Sink *sink) {\n    if (command == \"teardown\\n\") {\n        sink->Teardown();\n        return;\n    }\n    if (command == \"pause\\n\") {\n        sink->Pause();\n        return;\n    }\n    if (command == \"play\\n\") {\n        sink->Play();\n        return;\n    }\n    std::cout << \"Received unknown command: \" << command << std::endl;\n}\n\nstatic gboolean _user_input_handler (\n    GIOChannel* channel, GIOCondition /*condition*/, gpointer data_ptr)\n{\n    GError* error = NULL;\n    char* str = NULL;\n    size_t len;\n    SinkApp* app = static_cast<SinkApp*>(data_ptr);\n\n    switch (g_io_channel_read_line(channel, &str, &len, NULL, &error)) {\n    case G_IO_STATUS_NORMAL:\n        parse_input_and_call_sink(str, &app->sink());\n        g_free(str);\n        return true;\n    case G_IO_STATUS_ERROR:\n        std::cout << \"User input error: \" << error->message << std::endl;\n        g_error_free(error);\n        return false;\n    case G_IO_STATUS_EOF:\n    case G_IO_STATUS_AGAIN:\n        return true;\n    default:\n        return false;\n    }\n    return false;\n}\n\nint main (int argc, char *argv[])\n{\n    InitGlibLogging();\n    char* hostname = NULL;\n    int port = 7236;\n    std::unique_ptr<SinkApp> app;\n\n    GOptionEntry main_entries[] = {\n        { \"hostname\", 0, 0, G_OPTION_ARG_STRING, &hostname, \"Specify remote hostname (for debugging purposes)\", \"host\"},\n        { \"rtsp_port\", 0, 0, G_OPTION_ARG_INT, &port, \"Specify remote RTSP port number (for debugging purposes), 7236 by default\", \"rtsp_port\"},\n        { NULL }\n    };\n\n    GOptionContext* context = g_option_context_new (\"- WFD sink demo application\\n\");\n    g_option_context_add_main_entries (context, main_entries, NULL);\n    g_option_context_add_group (context, gst_init_get_option_group ());\n\n    GError* error = NULL;\n    if (!g_option_context_parse (context, &argc, &argv, &error)) {\n        WDS_ERROR (\"option parsing failed: %s\", error->message);\n        g_option_context_free(context);\n        exit (1);\n    }\n    g_option_context_free(context);\n\n    if (hostname) {\n        app.reset(new SinkApp(std::string(hostname), port));\n        g_free (hostname);\n    } else {\n        app.reset(new SinkApp());\n    }\n\n    GMainLoop *main_loop =  g_main_loop_new(NULL, TRUE);\n    g_unix_signal_add(SIGINT, _sig_handler, main_loop);\n    g_unix_signal_add(SIGTERM, _sig_handler, main_loop);\n\n    GIOChannel* io_channel = g_io_channel_unix_new (STDIN_FILENO);\n    g_io_add_watch(io_channel, G_IO_IN, _user_input_handler, app.get());\n    g_io_channel_unref(io_channel);\n\n    g_main_loop_run (main_loop);\n\n    g_main_loop_unref (main_loop);\n\n    return 0;\n}\n\n"
  },
  {
    "path": "sink/sink-app.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n#include <netinet/in.h> // htons()\n\n#include \"sink-app.h\"\n#include \"sink.h\"\n#include \"connman-client.h\"\n\nvoid SinkApp::on_peer_added(P2P::Client *client, std::shared_ptr<P2P::Peer> peer)\n{\n    std::cout << \"* New peer: \" << peer->name() << std::endl;\n    peer->set_observer (this);\n}\n\nvoid SinkApp::on_peer_removed(P2P::Client *client, std::shared_ptr<P2P::Peer> peer)\n{\n    std::cout << \"* Peer removed: \" << peer->name() << std::endl;\n    if (peer.get() == peer_) {\n        sink_.reset(NULL);\n        peer_ = NULL;\n    }\n}\n\nvoid SinkApp::on_availability_changed(P2P::Peer *peer)\n{\n    if (!sink_ && peer->is_available() && peer->device_type() == P2P::SOURCE) {\n        std::cout << \"* Connecting to source at \" << peer->remote_host() << \":\" << ntohs(peer->remote_port()) << std::endl;\n\n        sink_.reset(new Sink (peer->remote_host(), ntohs(peer->remote_port()), peer->local_host()));\n        peer_ = peer;\n    } else if (sink_ && !peer->is_available() && peer == peer_) {\n        std::cout << \"* Source unavailable\" << std::endl;\n\n        sink_.reset(NULL);\n        peer_ = NULL;\n    }\n}\n\nSinkApp::SinkApp(){\n    // Create a information element for a simple WFD Sink\n    P2P::InformationElement ie;\n    auto sub_element = P2P::new_subelement(P2P::DEVICE_INFORMATION);\n    auto dev_info = (P2P::DeviceInformationSubelement*)sub_element;\n\n    // TODO port number is a lie -- we should start the sink first, then \n    // use the port from there (and sink should probably default to 7236)\n\n    // TODO InformationElement could have constructors for this stuff...\n    dev_info->session_management_control_port = htons(7236);\n    dev_info->maximum_throughput = htons(50);\n    dev_info->field1.device_type = P2P::PRIMARY_SINK;\n    dev_info->field1.session_availability = true;\n    ie.add_subelement (sub_element);\n\n    std::cout << \"* Registering Wifi Display with IE \" << ie.to_string() <<  std::endl;\n\n    // register the P2P service with connman\n    auto array = ie.serialize ();\n    p2p_client_.reset(new P2P::Client(array, this));\n}\n\nSinkApp::SinkApp(const std::string& hostname, int port)\n{\n    std::cout << \"* Connecting to peer at \" << hostname << \":\" << port << std::endl;\n\n    sink_.reset(new Sink (hostname, port, \"\"));\n}\n\nSinkApp::~SinkApp() {\n}\n"
  },
  {
    "path": "sink/sink-app.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef SINK_APP_H\n#define SINK_APP_H\n\n#include <memory>\n\n#include \"sink.h\"\n#include \"connman-client.h\"\n\nclass SinkApp: public P2P::Client::Observer, public P2P::Peer::Observer {\n public:\n  SinkApp();\n  SinkApp(const std::string& hostname, int port);\n  ~SinkApp();\n\n  Sink& sink() { return *sink_; }\n\n  void on_peer_added(P2P::Client *client, std::shared_ptr<P2P::Peer> peer) override;\n  void on_peer_removed(P2P::Client *client, std::shared_ptr<P2P::Peer> peer) override;\n  void on_availability_changed(P2P::Client *client) override {};\n\n  void on_availability_changed(P2P::Peer *peer) override;\n  void on_initialized(P2P::Peer *peer) override {};\n\n private:\n  std::unique_ptr<P2P::Client> p2p_client_;\n  std::unique_ptr<Sink> sink_;\n  P2P::Peer *peer_;\n};\n\n#endif // SINK_APP_H\n"
  },
  {
    "path": "sink/sink.cpp",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#include <iostream>\n\n#include \"sink.h\"\n#include \"gst_sink_media_manager.h\"\n\nSink::Sink(const std::string& remote_host, int remote_rtsp_port, const std::string& local_host)\n  : MiracBroker(remote_host, std::to_string(remote_rtsp_port)),\n    local_host_(local_host) {\n}\n\nSink::~Sink() {}\n\nvoid Sink::got_message(const std::string& message) {\n  wfd_sink_->RTSPDataReceived(message);\n}\n\nvoid Sink::on_connected() {\n  media_manager_.reset(new GstSinkMediaManager(local_host_));\n  wfd_sink_.reset(wds::Sink::Create(this, media_manager_.get()));\n  wfd_sink_->Start();\n}\n\nvoid Sink::on_connection_failure(ConnectionFailure failure) {\n  switch (failure) {\n      case CONNECTION_LOST:\n          std::cout << \"* RTSP connection lost\" << std::endl;\n      case CONNECTION_TIMEOUT:\n          ;\n  }\n}\n\nvoid Sink::Play() {\n  wfd_sink_->Play();\n}\n\nvoid Sink::Pause() {\n  wfd_sink_->Pause();\n}\n\nvoid Sink::Teardown() {\n  wfd_sink_->Teardown();\n}\n\nwds::Peer* Sink::Peer() const {\n  return wfd_sink_.get();\n}\n\n"
  },
  {
    "path": "sink/sink.h",
    "content": "/*\n * This file is part of Wireless Display Software for Linux OS\n *\n * Copyright (C) 2014 Intel Corporation.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA\n */\n\n#ifndef SINK_H\n#define SINK_H\n\n#include <memory>\n\n#include \"libwds/public/media_manager.h\"\n#include \"libwds/public/sink.h\"\n\n#include \"mirac-broker.hpp\"\n\nclass Sink : public MiracBroker {\n public:\n  explicit Sink(const std::string& remote_host, int remote_rtsp_port, const std::string& local_host);\n  ~Sink();\n\n  void Play();\n  void Pause();\n  void Teardown();\n\n protected:\n  virtual wds::Peer* Peer() const override;\n\n private:\n  virtual void got_message(const std::string& message) override;\n  virtual void on_connected() override;\n  void on_connection_failure(ConnectionFailure failure) override;\n\n  std::unique_ptr<wds::SinkMediaManager> media_manager_;\n  std::unique_ptr<wds::Sink> wfd_sink_;\n  std::string local_host_;\n};\n\n#endif // SINK_H\n"
  }
]