pax_global_header00006660000000000000000000000064132440206070014510gustar00rootroot0000000000000052 comment=0c29003c55fb2e48cdd37607af0adab1a5d7f2d2 dablin-1.8.0/000077500000000000000000000000001324402060700127475ustar00rootroot00000000000000dablin-1.8.0/.gitignore000066400000000000000000000001001324402060700147260ustar00rootroot00000000000000*~ /.idea/ /cmake-build-debug/ /.cproject /.project /.settings/ dablin-1.8.0/.travis.yml000066400000000000000000000011331324402060700150560ustar00rootroot00000000000000language: c++ sudo: required dist: trusty addons: &addons apt: sources: &sources - ubuntu-toolchain-r-test packages: &packages - libfaad-dev - libfdk-aac-dev - libmpg123-dev - libsdl2-dev - libgtkmm-3.0-dev - g++-6 script: - | mkdir build_faad pushd build_faad cmake -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6 .. make sudo make install popd - | mkdir build_fdkaac pushd build_fdkaac cmake -DUSE_FDK-AAC=1 -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6 .. make sudo make install popd dablin-1.8.0/CMakeLists.txt000066400000000000000000000122311324402060700155060ustar00rootroot00000000000000######################################################################## # Project setup ######################################################################## cmake_minimum_required(VERSION 2.8) project(dablin C CXX) # Select the release build type by default to get optimization flags if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") message(STATUS "Build type not specified: defaulting to release.") endif(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) enable_testing() ######################################################################## # Build the FEC library before setting up DABlin application builds. ######################################################################## add_subdirectory(fec) ######################################################################## # Version information ######################################################################## # version derived from git (if possible) execute_process( COMMAND git describe --dirty OUTPUT_VARIABLE VERSION_FROM_GIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) if(VERSION_FROM_GIT) add_definitions(-DDABLIN_VERSION="${VERSION_FROM_GIT}") set(VERSION_OUTPUT ${VERSION_FROM_GIT}) else() set(VERSION_OUTPUT "[see src/version.h]") endif() ######################################################################## # Compiler specific setup ######################################################################## if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_CLANGXX 1) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) add_definitions(-std=c++0x) add_definitions(-Wall) add_definitions(-Wextra) elseif(MSVC) # TODO endif() ######################################################################## # Find build dependencies ######################################################################## find_package(PkgConfig) find_package(Threads REQUIRED) # SDL2 if(NOT DISABLE_SDL) pkg_check_modules(SDL2 sdl2 REQUIRED) if(NOT SDL2_FOUND) message(FATAL_ERROR "SDL2 required to compile dablin\n") endif() include_directories(${SDL2_INCLUDE_DIRS}) link_directories(${SDL2_LIBRARY_DIRS}) list(APPEND dablin_sources sdl_output.cpp) else() add_definitions(-DDABLIN_DISABLE_SDL) endif() # libmpg123 pkg_check_modules(MPG123 libmpg123 REQUIRED) if(NOT MPG123_FOUND) message(FATAL_ERROR "libmpg123 required to compile dablin\n") endif() include_directories(${MPG123_INCLUDE_DIRS}) link_directories(${MPG123_LIBRARY_DIRS}) # gtkmm 3.0 pkg_check_modules(GTKMM gtkmm-3.0) if(GTKMM_FOUND) include_directories(${GTKMM_INCLUDE_DIRS}) link_directories(${GTKMM_LIBRARY_DIRS}) endif() # libfaad2 find_package(FAAD) # fdk-aac pkg_check_modules(FDKAAC fdk-aac) # fdk-aac-dabplus pkg_check_modules(FDKAAC-DABPLUS fdk-aac-dabplus) if(USE_FDK-AAC) if(NOT(FDKAAC_FOUND OR FDKAAC-DABPLUS_FOUND)) message(FATAL_ERROR "fdk-aac or fdk-aac-dabplus required to compile dablin with USE_FDK-AAC\n") endif() if(FDKAAC-DABPLUS_FOUND) include_directories(${FDKAAC-DABPLUS_INCLUDE_DIRS}) link_directories(${FDKAAC-DABPLUS_LIBRARY_DIRS}) list(APPEND AAC_LIB ${FDKAAC-DABPLUS_LIBRARIES}) else() include_directories(${FDKAAC_INCLUDE_DIRS}) link_directories(${FDKAAC_LIBRARY_DIRS}) list(APPEND AAC_LIB ${FDKAAC_LIBRARIES}) endif() add_definitions(-DDABLIN_AAC_FDKAAC) else() if(NOT FAAD_FOUND) message(FATAL_ERROR "libfaad required to compile dablin\n") endif() include_directories(${FAAD_INCLUDE_DIRS}) link_directories(${FAAD_LIBRARY_DIRS}) list(APPEND AAC_LIB ${FAAD_LIBRARIES}) add_definitions(-DDABLIN_AAC_FAAD2) endif() # iconv find_package(ICONV REQUIRED) if(NOT ICONV_FOUND) message(FATAL_ERROR "iconv required to compile dablin\n") endif() include_directories(${ICONV_INCLUDE_DIRS}) link_directories(${ICONV_LIBRARY_DIRS}) ######################################################################## # Setup DABlin application build ######################################################################## add_subdirectory(src) add_subdirectory(doc) ######################################################################## # Print Summary ######################################################################## message(STATUS "") message(STATUS "##########################################################") message(STATUS "## Building version: ${VERSION_OUTPUT}") message(STATUS "## Using install prefix: ${CMAKE_INSTALL_PREFIX}") if(NOT GTKMM_FOUND) message(STATUS "## gtkmm not found, thus do not build dablin_gtk") endif() message(STATUS "##########################################################") message(STATUS "") ######################################################################## # Create uninstall target ######################################################################## configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) dablin-1.8.0/COPYING000066400000000000000000001045131324402060700140060ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . dablin-1.8.0/README.md000066400000000000000000000272711324402060700142370ustar00rootroot00000000000000# DABlin – capital DAB experience DABlin plays a DAB/DAB+ audio service – either from a received live transmission or from a stored ensemble recording (frame-aligned ETI-NI). Both DAB (MP2) and DAB+ (AAC-LC, HE-AAC, HE-AAC v2) services are supported. The GTK GUI version in addition supports the data applications Dynamic Label and MOT Slideshow (if used by the selected service). ## Screenshots ### GTK GUI version ![Screenshot of the GTK GUI version](https://basicmaster.de/dab/DABlin.png) ### Console version ![Screenshot of the console version](https://basicmaster.de/dab/DABlin_console.png) ## Requirements ### General Besides Git a C/C++ compiler (with C++11 support) and CMake are required to build DABlin. On Debian or Ubuntu, the respective packages (with GCC as C/C++ compiler) can be installed using aptitude or apt-get, for example: ``` sudo apt-get install git gcc g++ cmake ``` ### Libraries The following libraries are required: * mpg123 (1.14.0 or higher) * FAAD2 * SDL2 The GTK GUI version in addition requires: * gtkmm Usually the `glibc` implementation of `iconv` is available. If this is not the case, in addition `libiconv` is required. On Debian or Ubuntu, mpg123, FAAD2, SDL2 and gtkmm are packaged and installed with: ``` sudo apt-get install libmpg123-dev libfaad-dev libsdl2-dev libgtkmm-3.0-dev ``` On Fedora, mpg123, SDL2, and gtkmm are all packaged and can be installed thus: ``` sudo dnf install mpg123-devel SDL2-devel gtkmm30-devel ``` FAAD2 is not packaged in the main Fedora repository, but it is available in [RPM Fusion repository](https://rpmfusion.org/). Once you have added RPM Fusion to the repositories, FAAD2 may be installed by: ``` sudo dnf install faad2-devel ``` If you do not wish to, or cannot, add the RPM Fusion repositories, you will have to download FAAD2, perhaps from [here](http://www.audiocoding.com/faad2.html), and build and install manually. ### Alternative DAB+ decoder Instead of using FAAD2, DAB+ channels can be decoded with [FDK-AAC](https://github.com/mstorsjo/fdk-aac). You can also use [OpenDigitalradio's fork](https://github.com/Opendigitalradio/fdk-aac), if already installed. On Debian and Ubuntu, you can install FDK-AAC with: ``` sudo apt-get install libfdk-aac-dev ``` On Fedora, RPM Fusion is again needed and, if used, you can: ``` sudo dnf install fdk-aac-devel ``` When the alternative AAC decoder is used, the FAAD2 library mentioned above is no longer required. After installing the library, to use FDK-AAC instead of FAAD2, you have to have `-DUSE_FDK-AAC=1` as part of the `cmake` command. ### Audio output The SDL2 library is used for audio output, but you can instead choose to output the decoded audio in plain PCM for further processing (e.g. for forwarding to a streaming server). In case you only want PCM output, you can disable SDL output and therefore omit the SDL2 library prerequisite. You then also have to have `-DDISABLE_SDL=1` as part of the `cmake` command. ### Surround sound Services with surround sound are only decoded from their Mono/Stereo core, as unfortunately there is no FOSS AAC decoder which supports the required Spatial Audio Coding (SAC) extension of MPEG Surround at the moment. ## Precompiled packages and source-based Linux distributions Official precompiled packages are available for the following Linux distributions (kindly maintained by Gürkan Myczko): * [Debian](https://packages.debian.org/dablin) * [Ubuntu](https://launchpad.net/ubuntu/+source/dablin) Some users kindly provide precompiled packages on their own: * [openSUSE](https://build.opensuse.org/package/show/home:mnhauke:ODR-mmbTools/dablin) (by Martin Hauke) * [CentOS](https://build.opensuse.org/package/show/home:radiorabe:dab/dablin) (by [Radio Bern RaBe 95.6](http://rabe.ch)); [more info](https://github.com/radiorabe/centos-rpm-dablin) For other distributions you may also want to check the [Repology page](https://repology.org/metapackage/dablin). Source-based Linux distributions: * [Gentoo](https://github.com/paraenggu/delicious-absurdities-overlay/tree/master/media-sound/dablin) (by Christian Affolter, as part of his [delicious-absurdities-overlay](https://github.com/paraenggu/delicious-absurdities-overlay)) ## Compilation If the gtkmm library is available both the console and GTK GUI executables will be built. If the gtkmm library is not available only the console executable will be built. To fetch the DABlin source code, execute the following commmands: ``` git clone https://github.com/Opendigitalradio/dablin.git cd dablin ``` Note that by default the `master` branch is cloned which contains the current stable version. The development takes place in the `next` branch which can instead be cloned by appending `-b next` to the end of the above `git clone` command line. You can use, for example, the following command sequence in order to compile and install DABlin: ``` mkdir build cd build cmake .. make sudo make install ``` ## Usage The console executable is called `dablin`, the GTK GUI executable `dablin_gtk`. Use `-h` to get an overview of all available options. (Currently no desktop files are installed so it is not easy to start DABlin directly from GNOME Shell. For now, at least, start DABlin from a console.) DABlin processes frame-aligned DAB ETI-NI recordings. If no filename is specified, `stdin` is used for input. You just should specify the service ID (SID) of the desired service using `-s` - otherwise initially no service is played. The GUI version of course does not necessarily need this. You can replay an existing ETI-NI recording as follows: ``` dablin -s 0xd911 mux.eti ``` In this case a progress indicator and the current position is displayed. With the console version, instead of the desired service it is also possible to directly request a specific sub-channel by using `-r` (for DAB) or `-R` (for DAB+). In addition to the respective button, the GTK GUI version also allows the keyboard shortcut `m` to toggle muting the audio. ### DAB live reception If you want to play a live station, you can use `dab2eti` from [dabtools](https://github.com/Opendigitalradio/dabtools) (ODR maintained fork) and transfer the ETI live stream via pipe, e.g.: ``` dab2eti 216928000 | dablin_gtk ``` It is possible to let DABlin invoke `dab2eti` or any other DAB live source that outputs ETI-NI. The respective binary is then called with the necessary parameters, including the frequency and an optional gain value. You therefore just have to specify the path to the `dab2eti` binary and the desired channel. ``` dablin -d ~/bin/dab2eti -c 11D -s 0xd911 ``` Using `dab2eti` the E4000 tuner is recommended as auto gain is supported with it. If you want/have to use a gain value you can specify it using `-g`. Instead of `dab2eti` the tool `eti-cmdline` by Jan van Katwijk can be used, as it has more sensitive reception (however the CPU load is higher compared to `dab2eti`) and does not require a E4000 tuner for auto gain. It is part of his [eti-stuff](https://github.com/JvanKatwijk/eti-stuff). In addition to specifying the path to the respective binary you also have to change the DAB live source type accordingly by using `-D`. ``` dablin -d ~/bin/eti-cmdline-rtlsdr -D eti-cmdline -c 11D -s 0xd911 ``` In case of the GTK GUI version the desired channel may not be specified. To avoid the huge channel list containing all possible DAB channels, one can also state the desired channels (separated by comma) which shall be displayed within the channel list. Hereby the specified (default) gain value can also be overwritten for a channel by adding the desired value after a colon, e.g. `5C:-54`. ``` dablin_gtk -d ~/bin/dab2eti -c 11D -C 5C,7B,11A,11C,11D -s 0xd911 ``` ### Secondary component audio services Some ensembles may contain audio services that consist of additional "sub services" called secondary components, in addition to the primary component. That secondary components can initially be selected by using `-x` in addition to `-s`. In the GTK version in the service list such components are shown prefixed with `» ` (e.g. `» BBC R5LiveSportX`). Meanwhile the related primary component is suffixed with ` »` (e.g. `BBC Radio 5 Live »`). ## Status output While playback a number of status messages may appear. Some are quite common (enclosed with round brackets) e.g. due to bad reception, while others are rather unlikely to occur (enclosed with square brackets). ### Common During (re-)synchronisation status messages are shown. Also dropped Superframes or AU are mentioned. If the Reed Solomon FEC was used to correct bytes of a Superframe, this is mentioned by messages of the format `(3+)` in cyan color. This shorter format is used as those messages occure several times with borderline reception. The digit refers to the number of corrected bytes within the Superframe while a plus (if present) indicates that at least one byte was incorrectable. When a FIB is discarded (due to failed CRC check), this is indicated by a `(FIB)` message in yellow color. MP2 frames with invalid CRC (MP2's CRC only - not DAB's ScF-CRC) are discarded, which is indicated by a `(CRC)` message in red color. Audio Units (AUs) with invalid CRC are mentioned with short format messages like `(AU #2)` in red color, indicating that the CRC check on AU No. 2 failed and hence the AU was dismissed. When the decoding of an AU nevertheless fails, this is indicated by an `(AAC)` message in magenta color. However in that case the AAC decoder may output audio samples anyway. ### Uncommon If the announced X-PAD length of a DAB+ service does not match the available X-PAD length i.e. if it falls below, a red `[X-PAD len]` message is shown and the X-PAD is discarded. However not all X-PADs may be affected and hence it may happen that the Dynamic Label can be processed but the MOT Slideshow cannot. To anyhow process affected X-PADs, a loose mode can be enabled by using `-L`. Thus the mentioned message will be shown in yellow then. ## Standards DABlin implements (at least partly) the following DAB standards: ### General * ETSI EN 300 401 (DAB system) * ETSI TS 101 756 (Registered tables) * ETSI TS 103 466 (DAB audio) * ETSI TS 102 563 (DAB+ audio) * ETSI ETS 300 799 (ETI) ### Data applications * ETSI EN 301 234 (MOT) * ETSI TS 101 499 (MOT Slideshow) ## TODO At the moment, DABlin is kind of a rudimentary tool for the playback of DAB/DAB+ services. It is planned to add support for further Program Aided Data (PAD) features. ### Slideshow The GTK GUI version supports the MOT Slideshow. If Slideshow is enabled and the current service signals to transmit a Slideshow, the Slideshow window is displayed. It shows a slide after it has been received completely and without errors. Currently the following limitations apply: * slideshows in a separate sub-channel are not supported (just X-PAD); * the TriggerTime field does not support values other than Now ## License This software is licensed under the GNU General Public License Version 3 (please see the file COPYING for further details). ![GPLv3 Image](https://www.gnu.org/graphics/gplv3-88x31.png) *Please note that the included FEC lib by KA9Q has a separate license!* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . dablin-1.8.0/cmake/000077500000000000000000000000001324402060700140275ustar00rootroot00000000000000dablin-1.8.0/cmake/Modules/000077500000000000000000000000001324402060700154375ustar00rootroot00000000000000dablin-1.8.0/cmake/Modules/FindFAAD.cmake000066400000000000000000000017051324402060700177400ustar00rootroot00000000000000# - Try to find libfaad # Once done this will define # FAAD_FOUND - System has libfaad # FAAD_INCLUDE_DIRS - The libfaad include directories # FAAD_LIBRARIES - The libraries needed to use libfaad # FAAD_DEFINITIONS - Compiler switches required for using libfaad #find_package(PkgConfig) #pkg_check_modules(PC_FAAD QUIET libfaad) #set(FAAD_DEFINITIONS ${PC_FAAD_CFLAGS_OTHER}) find_path(FAAD_INCLUDE_DIR faad.h HINTS ${PC_FAAD_INCLUDEDIR} ${PC_FAAD_INCLUDE_DIRS} ) find_library(FAAD_LIBRARY NAMES faad HINTS ${PC_FAAD_LIBDIR} ${PC_FAAD_LIBRARY_DIRS} ) set(FAAD_LIBRARIES ${FAAD_LIBRARY}) set(FAAD_INCLUDE_DIRS ${FAAD_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set FAAD_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(FAAD DEFAULT_MSG FAAD_LIBRARY FAAD_INCLUDE_DIR) mark_as_advanced(FAAD_INCLUDE_DIR FAAD_LIBRARY) dablin-1.8.0/cmake/Modules/FindFEC.cmake000066400000000000000000000016431324402060700176430ustar00rootroot00000000000000# - Try to find libfec # Once done this will define # FEC_FOUND - System has libfec # FEC_INCLUDE_DIRS - The libfec include directories # FEC_LIBRARIES - The libraries needed to use libfec # FEC_DEFINITIONS - Compiler switches required for using libfec find_package(PkgConfig) pkg_check_modules(PC_FEC QUIET libfec) set(FEC_DEFINITIONS ${PC_FEC_CFLAGS_OTHER}) find_path(FEC_INCLUDE_DIR fec.h HINTS ${PC_FEC_INCLUDEDIR} ${PC_FEC_INCLUDE_DIRS} ) find_library(FEC_LIBRARY NAMES fec HINTS ${PC_FEC_LIBDIR} ${PC_FEC_LIBRARY_DIRS} ) set(FEC_LIBRARIES ${FEC_LIBRARY}) set(FEC_INCLUDE_DIRS ${FEC_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set FEC_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(FEC DEFAULT_MSG FEC_LIBRARY FEC_INCLUDE_DIR) mark_as_advanced(FEC_INCLUDE_DIR FEC_LIBRARY) dablin-1.8.0/cmake/Modules/FindICONV.cmake000066400000000000000000000020141324402060700201150ustar00rootroot00000000000000# - Try to find libiconv (or libc instead) # Once done this will define # ICONV_FOUND - System has libiconv # ICONV_INCLUDE_DIRS - The libiconv include directories # ICONV_LIBRARIES - The libraries needed to use libiconv # ICONV_DEFINITIONS - Compiler switches required for using libiconv #find_package(PkgConfig) #pkg_check_modules(PC_ICONV QUIET libiconv) #set(ICONV_DEFINITIONS ${PC_ICONV_CFLAGS_OTHER}) find_path(ICONV_INCLUDE_DIR iconv.h HINTS ${PC_ICONV_INCLUDEDIR} ${PC_ICONV_INCLUDE_DIRS} ) find_library(ICONV_LIBRARY NAMES libiconv_a iconv libiconv c HINTS ${PC_ICONV_LIBDIR} ${PC_ICONV_LIBRARY_DIRS} ) set(ICONV_LIBRARIES ${ICONV_LIBRARY}) set(ICONV_INCLUDE_DIRS ${ICONV_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set ICONV_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(ICONV DEFAULT_MSG ICONV_LIBRARY ICONV_INCLUDE_DIR) mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARY) dablin-1.8.0/cmake/cmake_uninstall.cmake.in000066400000000000000000000020131324402060700206030ustar00rootroot00000000000000if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach(file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if(NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif(NOT "${rm_retval}" STREQUAL 0) else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach(file) dablin-1.8.0/doc/000077500000000000000000000000001324402060700135145ustar00rootroot00000000000000dablin-1.8.0/doc/CMakeLists.txt000066400000000000000000000006441324402060700162600ustar00rootroot00000000000000######################################################################## # Add docs install rules. ######################################################################## if(NOT MAN_INSTALL_DIR) set(MAN_INSTALL_DIR "share/man") endif() # dablin install(FILES dablin.1 DESTINATION ${MAN_INSTALL_DIR}/man1/) # dablin_gtk if(GTKMM_FOUND) install(FILES dablin_gtk.1 DESTINATION ${MAN_INSTALL_DIR}/man1/) endif() dablin-1.8.0/doc/dablin.1000066400000000000000000000027211324402060700150310ustar00rootroot00000000000000.TH DABLIN 1 "2018-02-22" .\"------------------------------------------------------------------------ .SH NAME dablin \- CLI DAB/DAB+ receiver for Linux .\"------------------------------------------------------------------------ .SH SYNOPSIS .B dablin .RI ( options ) .RI [ file ] .\"------------------------------------------------------------------------ .SH DESCRIPTION .B DABlin plays a DAB/DAB+ audio service – either from a received live transmission or from a stored ensemble recording (frame-aligned ETI-NI). Both DAB (MP2) and DAB+ (AAC-LC, HE-AAC, HE-AAC v2) services are supported. .\"------------------------------------------------------------------------ .SH OPTIONS .TP .B \-h Show summary of options .TP .B \-d Use DAB live source (using the mentioned binary) .TP .B \-D DAB live source type: "dab2eti" (default), "eti-cmdline" .TP .B \-c Channel to be played (requires DAB live source) .TP .B \-s ID of the service to be played .TP .B \-x ID of the service component to be played (requires service ID) .TP .B \-r ID of the sub-channel (DAB) to be played .TP .B \-R ID of the sub-channel (DAB+) to be played .TP .B \-g USB stick gain to pass to DAB live source (auto gain is default) .TP .B \-p Output PCM to stdout instead of using SDL .TP .B file Input file to be played (stdin, if not specified) .\"------------------------------------------------------------------------ .SH "SEE ALSO" .BR dablin_gtk (1) dablin-1.8.0/doc/dablin_gtk.1000066400000000000000000000033171324402060700157000ustar00rootroot00000000000000.TH DABLIN_GTK 1 "2018-02-22" .\"------------------------------------------------------------------------ .SH NAME dablin_gtk \- GTK DAB/DAB+ receiver for Linux .\"------------------------------------------------------------------------ .SH SYNOPSIS .B dablin_gtk .RI ( options ) .RI [ file ] .\"------------------------------------------------------------------------ .SH DESCRIPTION .B DABlin plays a DAB/DAB+ audio service – either from a received live transmission or from a stored ensemble recording (frame-aligned ETI-NI). Both DAB (MP2) and DAB+ (AAC-LC, HE-AAC, HE-AAC v2) services are supported. .PP The GTK GUI version in addition supports the data applications Dynamic Label and MOT Slideshow (if used by the selected service). .\"------------------------------------------------------------------------ .SH OPTIONS .TP .B \-h Show summary of options .TP .B \-d Use DAB live source (using the mentioned binary) .TP .B \-D DAB live source type: "dab2eti" (default), "eti-cmdline" .TP .B \-C ,... Channels to be listed (comma separated; requires DAB live source; an optional gain can also be specified, e.g. "5C:-54") .TP .B \-c Channel to be played (requires DAB live source) .TP .B \-s ID of the service to be played .TP .B \-x ID of the service component to be played (requires service ID) .TP .B \-g USB stick gain to pass to DAB live source (auto gain is default) .TP .B \-p Output PCM to stdout instead of using SDL .TP .B \-S Initially disable slideshow .TP .B \-L Enable loose behaviour (e.g. PAD conformance) .TP .B file Input file to be played (stdin, if not specified) .\"------------------------------------------------------------------------ .SH "SEE ALSO" .BR dablin (1) dablin-1.8.0/fec/000077500000000000000000000000001324402060700135045ustar00rootroot00000000000000dablin-1.8.0/fec/CMakeLists.txt000066400000000000000000000057371324402060700162600ustar00rootroot00000000000000######################################################################## # Project setup ######################################################################## project(libfec ASM C) ######################################################################## # Compiler specific setup ######################################################################## if((CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 4)) set(TARGET_ARCH "x86") elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) set(TARGET_ARCH "x64") elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "i386") AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (APPLE)) # Mac is weird like that. set(TARGET_ARCH "x64") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") set(TARGET_ARCH "ARM") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le") set(TARGET_ARCH "ppc64" "ppc64le") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64") set(TARGET_ARCH "ppc64" "ppc") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") set(TARGET_ARCH "ppc") endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANGCC) add_definitions(-Wall) add_definitions(-Wno-unused) if(TARGET_ARCH MATCHES "x64") add_definitions(-fPIC) add_definitions(-msse2) elseif(TARGET_ARCH MATCHES "x86") add_definitions(-mmmx) add_definitions(-msse) add_definitions(-msse2) elseif(TARGET_ARCH MATCHES "ppc|ppc64") add_definitions(-fno-common) add_definitions(-faltivec) endif() endif() ######################################################################## # Find build dependencies ######################################################################## find_library(M_LIB m REQUIRED) ######################################################################## # Checks for features. ######################################################################## include(CheckIncludeFile) check_include_file("stdio.h" HAVE_STDIO_H) check_include_file("stdlib.h" HAVE_STDLIB_H) check_include_file("string.h" HAVE_STRING_H) include(CheckFunctionExists) check_function_exists("memset" HAVE_MEMSET) check_function_exists("memmove" HAVE_MEMMOVE) ######################################################################## # Setup apps ######################################################################## set(libfec_sources encode_rs_char.c decode_rs_char.c init_rs_char.c ) ######################################################################## # Setup libraries ######################################################################## add_library(fec STATIC ${libfec_sources}) set_target_properties(fec PROPERTIES LINKER_LANGUAGE C) target_link_libraries(fec ${M_LIB}) ######################################################################## # Build the tests ######################################################################## add_subdirectory(test) dablin-1.8.0/fec/LICENSE000066400000000000000000000635061324402060700145230ustar00rootroot00000000000000GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. (This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.) Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. {signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice That's all there is to it! dablin-1.8.0/fec/README.md000066400000000000000000000006331324402060700147650ustar00rootroot00000000000000FEC routines from KA9Q's libfec =============================== This folder contains part of the libfec library by KA9Q. Only the char-sized Reed-Solomon encoder and decoder is here. The files have been copied from the libfec fork at https://github.com/Opendigitalradio/ka9q-fec Original code is at http://www.ka9q.net/code/fec/ All files in this folder are licenced under the LGPL v2.1, please see LICENCE dablin-1.8.0/fec/char.h000066400000000000000000000010321324402060700145660ustar00rootroot00000000000000/* Stuff specific to the 8-bit symbol version of the general purpose RS codecs * * Copyright 2003, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ typedef unsigned char data_t; #define MODNN(x) modnn(rs,x) #define MM (rs->mm) #define NN (rs->nn) #define ALPHA_TO (rs->alpha_to) #define INDEX_OF (rs->index_of) #define GENPOLY (rs->genpoly) #define NROOTS (rs->nroots) #define FCR (rs->fcr) #define PRIM (rs->prim) #define IPRIM (rs->iprim) #define PAD (rs->pad) #define A0 (NN) dablin-1.8.0/fec/decode_rs.h000066400000000000000000000204631324402060700156110ustar00rootroot00000000000000/* The guts of the Reed-Solomon decoder, meant to be #included * into a function body with the following typedefs, macros and variables supplied * according to the code parameters: * data_t - a typedef for the data symbol * data_t data[] - array of NN data and parity symbols to be corrected in place * retval - an integer lvalue into which the decoder's return code is written * NROOTS - the number of roots in the RS code generator polynomial, * which is the same as the number of parity symbols in a block. Integer variable or literal. * NN - the total number of symbols in a RS block. Integer variable or literal. * PAD - the number of pad symbols in a block. Integer variable or literal. * ALPHA_TO - The address of an array of NN elements to convert Galois field * elements in index (log) form to polynomial form. Read only. * INDEX_OF - The address of an array of NN elements to convert Galois field * elements in polynomial form to index (log) form. Read only. * MODNN - a function to reduce its argument modulo NN. May be inline or a macro. * FCR - An integer literal or variable specifying the first consecutive root of the * Reed-Solomon generator polynomial. Integer variable or literal. * PRIM - The primitive root of the generator poly. Integer variable or literal. * DEBUG - If set to 1 or more, do various internal consistency checking. Leave this * undefined for production code * The memset(), memmove(), and memcpy() functions are used. The appropriate header * file declaring these functions (usually ) must be included by the calling * program. */ #if !defined(NROOTS) #error "NROOTS not defined" #endif #if !defined(NN) #error "NN not defined" #endif #if !defined(PAD) #error "PAD not defined" #endif #if !defined(ALPHA_TO) #error "ALPHA_TO not defined" #endif #if !defined(INDEX_OF) #error "INDEX_OF not defined" #endif #if !defined(MODNN) #error "MODNN not defined" #endif #if !defined(FCR) #error "FCR not defined" #endif #if !defined(PRIM) #error "PRIM not defined" #endif #if !defined(NULL) #define NULL ((void *)0) #endif #undef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) #undef A0 #define A0 (NN) { int deg_lambda, el, deg_omega; int i, j, r,k; data_t u,q,tmp,num1,num2,den,discr_r; data_t lambda[NROOTS+1], s[NROOTS]; /* Err+Eras Locator poly * and syndrome poly */ data_t b[NROOTS+1], t[NROOTS+1], omega[NROOTS+1]; data_t root[NROOTS], reg[NROOTS+1], loc[NROOTS]; int syn_error, count; /* form the syndromes; i.e., evaluate data(x) at roots of g(x) */ for(i=0;i 0) { /* Init lambda to be the erasure locator polynomial */ lambda[1] = ALPHA_TO[MODNN(PRIM*(NN-1-eras_pos[0]))]; for (i = 1; i < no_eras; i++) { u = MODNN(PRIM*(NN-1-eras_pos[i])); for (j = i+1; j > 0; j--) { tmp = INDEX_OF[lambda[j - 1]]; if(tmp != A0) lambda[j] ^= ALPHA_TO[MODNN(u + tmp)]; } } #if DEBUG >= 1 /* Test code that verifies the erasure locator polynomial just constructed Needed only for decoder debugging. */ /* find roots of the erasure location polynomial */ for(i=1;i<=no_eras;i++) reg[i] = INDEX_OF[lambda[i]]; count = 0; for (i = 1,k=IPRIM-1; i <= NN; i++,k = MODNN(k+IPRIM)) { q = 1; for (j = 1; j <= no_eras; j++) if (reg[j] != A0) { reg[j] = MODNN(reg[j] + j); q ^= ALPHA_TO[reg[j]]; } if (q != 0) continue; /* store root and error location number indices */ root[count] = i; loc[count] = k; count++; } if (count != no_eras) { fprintf(stderr, "count = %d no_eras = %d\n lambda(x) is WRONG\n",count,no_eras); count = -1; goto finish; } #if DEBUG >= 2 fprintf(stderr, "\n Erasure positions as determined by roots of Eras Loc Poly:\n"); for (i = 0; i < count; i++) fprintf(stderr, "%d ", loc[i]); fprintf(stderr, "\n"); #endif #endif } for(i=0;i 0; j--){ if (reg[j] != A0) { reg[j] = MODNN(reg[j] + j); q ^= ALPHA_TO[reg[j]]; } } if (q != 0) continue; /* Not a root */ /* store root (index-form) and error location number */ #if DEBUG>=2 fprintf(stderr, "count %d root %d loc %d\n",count,i,k); #endif root[count] = i; loc[count] = k; /* If we've already found max possible roots, * abort the search to save time */ if(++count == deg_lambda) break; } if (deg_lambda != count) { /* * deg(lambda) unequal to number of roots => uncorrectable * error detected */ count = -1; goto finish; } /* * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo * x**NROOTS). in index form. Also find deg(omega). */ deg_omega = deg_lambda-1; for (i = 0; i <= deg_omega;i++){ tmp = 0; for(j=i;j >= 0; j--){ if ((s[i - j] != A0) && (lambda[j] != A0)) tmp ^= ALPHA_TO[MODNN(s[i - j] + lambda[j])]; } omega[i] = INDEX_OF[tmp]; } /* * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = * inv(X(l))**(FCR-1) and den = lambda_pr(inv(X(l))) all in poly-form */ for (j = count-1; j >=0; j--) { num1 = 0; for (i = deg_omega; i >= 0; i--) { if (omega[i] != A0) num1 ^= ALPHA_TO[MODNN(omega[i] + i * root[j])]; } num2 = ALPHA_TO[MODNN(root[j] * (FCR - 1) + NN)]; den = 0; /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ for (i = MIN(deg_lambda,NROOTS-1) & ~1; i >= 0; i -=2) { if(lambda[i+1] != A0) den ^= ALPHA_TO[MODNN(lambda[i+1] + i * root[j])]; } #if DEBUG >= 1 if (den == 0) { fprintf(stderr, "\n ERROR: denominator = 0\n"); count = -1; goto finish; } #endif /* Apply error to data */ if (num1 != 0 && loc[j] >= PAD) { data[loc[j]-PAD] ^= ALPHA_TO[MODNN(INDEX_OF[num1] + INDEX_OF[num2] + NN - INDEX_OF[den])]; } } finish: if(eras_pos != NULL){ for(i=0;i #endif #include #include "char.h" #include "rs-common.h" int decode_rs_char(void *p, data_t *data, int *eras_pos, int no_eras){ int retval; struct rs *rs = (struct rs *)p; #include "decode_rs.h" return retval; } dablin-1.8.0/fec/encode_rs.h000066400000000000000000000044511324402060700156220ustar00rootroot00000000000000/* The guts of the Reed-Solomon encoder, meant to be #included * into a function body with the following typedefs, macros and variables supplied * according to the code parameters: * data_t - a typedef for the data symbol * data_t data[] - array of NN-NROOTS-PAD and type data_t to be encoded * data_t parity[] - an array of NROOTS and type data_t to be written with parity symbols * NROOTS - the number of roots in the RS code generator polynomial, * which is the same as the number of parity symbols in a block. Integer variable or literal. * * NN - the total number of symbols in a RS block. Integer variable or literal. * PAD - the number of pad symbols in a block. Integer variable or literal. * ALPHA_TO - The address of an array of NN elements to convert Galois field * elements in index (log) form to polynomial form. Read only. * INDEX_OF - The address of an array of NN elements to convert Galois field * elements in polynomial form to index (log) form. Read only. * MODNN - a function to reduce its argument modulo NN. May be inline or a macro. * GENPOLY - an array of NROOTS+1 elements containing the generator polynomial in index form * The memset() and memmove() functions are used. The appropriate header * file declaring these functions (usually ) must be included by the calling * program. * Copyright 2004, Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ #undef A0 #define A0 (NN) /* Special reserved value encoding zero in index form */ { int i, j; data_t feedback; memset(parity,0,NROOTS*sizeof(data_t)); for(i=0;i #include "char.h" #include "rs-common.h" void encode_rs_char(void *p,data_t *data, data_t *parity){ struct rs *rs = (struct rs *)p; #include "encode_rs.h" } dablin-1.8.0/fec/fec.h000066400000000000000000000015451324402060700144170ustar00rootroot00000000000000/* Main header for reduced libfec. * * The FEC code in this folder is * Copyright 2003 Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ #pragma once #include #include "char.h" #include "rs-common.h" /* Initialize a Reed-Solomon codec * symsize = symbol size, bits * gfpoly = Field generator polynomial coefficients * fcr = first root of RS code generator polynomial, index form * prim = primitive element to generate polynomial roots * nroots = RS code generator polynomial degree (number of roots) * pad = padding bytes at front of shortened block */ void *init_rs_char(int symsize,int gfpoly,int fcr,int prim,int nroots,int pad); int decode_rs_char(void *p, data_t *data, int *eras_pos, int no_eras); void encode_rs_char(void *p,data_t *data, data_t *parity); void free_rs_char(void *p); dablin-1.8.0/fec/init_rs.h000066400000000000000000000051461324402060700153320ustar00rootroot00000000000000/* Common code for intializing a Reed-Solomon control block (char or int symbols) * Copyright 2004 Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ { int i, j, sr,root,iprim; rs = NULL; /* Check parameter ranges */ if(symsize < 0 || symsize > 8*sizeof(data_t)){ goto done; } if(fcr < 0 || fcr >= (1<= (1<= (1<= ((1<mm = symsize; rs->nn = (1<pad = pad; rs->alpha_to = (data_t *)malloc(sizeof(data_t)*(rs->nn+1)); if(rs->alpha_to == NULL){ free(rs); rs = NULL; goto done; } rs->index_of = (data_t *)malloc(sizeof(data_t)*(rs->nn+1)); if(rs->index_of == NULL){ free(rs->alpha_to); free(rs); rs = NULL; goto done; } /* Generate Galois field lookup tables */ rs->index_of[0] = A0; /* log(zero) = -inf */ rs->alpha_to[A0] = 0; /* alpha**-inf = 0 */ sr = 1; for(i=0;inn;i++){ rs->index_of[sr] = i; rs->alpha_to[i] = sr; sr <<= 1; if(sr & (1<nn; } if(sr != 1){ /* field generator polynomial is not primitive! */ free(rs->alpha_to); free(rs->index_of); free(rs); rs = NULL; goto done; } /* Form RS code generator polynomial from its roots */ rs->genpoly = (data_t *)malloc(sizeof(data_t)*(nroots+1)); if(rs->genpoly == NULL){ free(rs->alpha_to); free(rs->index_of); free(rs); rs = NULL; goto done; } rs->fcr = fcr; rs->prim = prim; rs->nroots = nroots; /* Find prim-th root of 1, used in decoding */ for(iprim=1;(iprim % prim) != 0;iprim += rs->nn) ; rs->iprim = iprim / prim; rs->genpoly[0] = 1; for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) { rs->genpoly[i+1] = 1; /* Multiply rs->genpoly[] by @**(root + x) */ for (j = i; j > 0; j--){ if (rs->genpoly[j] != 0) rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)]; else rs->genpoly[j] = rs->genpoly[j-1]; } /* rs->genpoly[0] can never be zero */ rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)]; } /* convert rs->genpoly[] to index form for quicker encoding */ for (i = 0; i <= nroots; i++) rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; done:; } dablin-1.8.0/fec/init_rs_char.c000066400000000000000000000015201324402060700163120ustar00rootroot00000000000000/* Initialize a RS codec * * Copyright 2002 Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ #include #include "char.h" #include "rs-common.h" void free_rs_char(void *p){ struct rs *rs = (struct rs *)p; free(rs->alpha_to); free(rs->index_of); free(rs->genpoly); free(rs); } /* Initialize a Reed-Solomon codec * symsize = symbol size, bits * gfpoly = Field generator polynomial coefficients * fcr = first root of RS code generator polynomial, index form * prim = primitive element to generate polynomial roots * nroots = RS code generator polynomial degree (number of roots) * pad = padding bytes at front of shortened block */ void *init_rs_char(int symsize,int gfpoly,int fcr,int prim, int nroots,int pad){ struct rs *rs; #include "init_rs.h" return rs; } dablin-1.8.0/fec/rs-common.h000066400000000000000000000016471324402060700155770ustar00rootroot00000000000000/* Stuff common to all the general-purpose Reed-Solomon codecs * Copyright 2004 Phil Karn, KA9Q * May be used under the terms of the GNU Lesser General Public License (LGPL) */ /* Reed-Solomon codec control block */ struct rs { int mm; /* Bits per symbol */ int nn; /* Symbols per block (= (1<= rs->nn) { x -= rs->nn; x = (x >> rs->mm) + (x & rs->nn); } return x; } dablin-1.8.0/fec/test/000077500000000000000000000000001324402060700144635ustar00rootroot00000000000000dablin-1.8.0/fec/test/CMakeLists.txt000066400000000000000000000016711324402060700172300ustar00rootroot00000000000000######################################################################## # Checks for features. ######################################################################## include(CheckIncludeFile) check_include_file("stdio.h" HAVE_STDIO_H) check_include_file("stdlib.h" HAVE_STDLIB_H) check_include_file("memory.h" HAVE_MEMORY_H) check_include_file("time.h" HAVE_TIME_H) include(CheckFunctionExists) check_function_exists("memset" HAVE_MEMSET) ######################################################################## # Build the executables and set up the tests ######################################################################## include_directories(.. ${CMAKE_CURRENT_BINARY_DIR}) add_executable(rs_speedtest rs_speedtest.c) target_link_libraries(rs_speedtest fec) add_test(rs_speedtest rs_speedtest) add_executable(rstest rstest.c) target_link_libraries(rstest fec) add_test(rstest rstest) dablin-1.8.0/fec/test/rs_speedtest.c000066400000000000000000000016471324402060700173430ustar00rootroot00000000000000#include #include #include #include #include #include #include "fec.h" int main(){ unsigned char block[255]; int i; void *rs; struct rusage start,finish; double extime; int trials = 10000; for(i=0;i<223;i++) block[i] = 0x01; rs = init_rs_char(8,0x187,112,11,32,0); encode_rs_char(rs,block,&block[223]); getrusage(RUSAGE_SELF,&start); for(i=0;i #include #include #include #include "fec.h" struct etab { int symsize; int genpoly; int fcs; int prim; int nroots; int ntrials; } Tab[] = { {2, 0x7, 1, 1, 1, 10 }, {3, 0xb, 1, 1, 2, 10 }, {4, 0x13, 1, 1, 4, 10 }, {5, 0x25, 1, 1, 6, 10 }, {6, 0x43, 1, 1, 8, 10 }, {7, 0x89, 1, 1, 10, 10 }, {8, 0x11d, 1, 1, 32, 10 }, {8, 0x187, 112,11, 32, 10 }, /* Duplicates CCSDS codec */ {0, 0, 0, 0, 0}, }; int exercise_char(struct etab *e); int main(){ int i; srandom(time(NULL)); for(i=0;Tab[i].symsize != 0;i++){ int nn,kk; nn = (1<symsize) - 1; unsigned char block[nn],tblock[nn]; int errlocs[nn],derrlocs[nn]; int i; int errors; int derrors,kk; int errval,errloc; int erasures; int decoder_errors = 0; void *rs; if(e->symsize > 8) return -1; /* Compute code parameters */ kk = nn - e->nroots; rs = init_rs_char(e->symsize,e->genpoly,e->fcs,e->prim,e->nroots,0); if(rs == NULL){ printf("init_rs_char failed!\n"); return -1; } /* Test up to the error correction capacity of the code */ for(errors=0;errors <= e->nroots/2;errors++){ /* Load block with random data and encode */ for(i=0;i. */ #ifndef AUDIO_OUTPUT_H_ #define AUDIO_OUTPUT_H_ #include // --- AudioOutput ----------------------------------------------------------------- class AudioOutput { public: virtual ~AudioOutput() {} virtual void StartAudio(int /*samplerate*/, int /*channels*/, bool /*float32*/) = 0; virtual void PutAudio(const uint8_t* /*data*/, size_t /*len*/) = 0; virtual void SetAudioMute(bool /*audio_mute*/) = 0; virtual void SetAudioVolume(double /*audio_volume*/) = 0; virtual bool HasAudioVolumeControl() = 0; }; #endif /* AUDIO_OUTPUT_H_ */ dablin-1.8.0/src/dab_decoder.cpp000066400000000000000000000217651324402060700164700ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "dab_decoder.h" // --- MP2Decoder ----------------------------------------------------------------- // from ETSI TS 103 466, table 4 (= ISO/IEC 11172-3, table B.2a): const int MP2Decoder::table_nbal_48a[] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2 }; // from ETSI TS 103 466, table 5 (= ISO/IEC 11172-3, table B.2c): const int MP2Decoder::table_nbal_48b[] = { 4, 4, 3, 3, 3, 3, 3, 3 }; // from ETSI TS 103 466, table 6 (= ISO/IEC 13818-3, table B.1): const int MP2Decoder::table_nbal_24[] = { 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; const int* MP2Decoder::tables_nbal[] = { table_nbal_48a, table_nbal_48b, table_nbal_24 }; const int MP2Decoder::sblimits[] = { sizeof(table_nbal_48a) / sizeof(int), sizeof(table_nbal_48b) / sizeof(int), sizeof(table_nbal_24) / sizeof(int), }; MP2Decoder::MP2Decoder(SubchannelSinkObserver* observer) : SubchannelSink(observer) { scf_crc_len = -1; int mpg_result; // init mpg_result = mpg123_init(); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_init: " + std::string(mpg123_plain_strerror(mpg_result))); // ensure features if(!mpg123_feature(MPG123_FEATURE_OUTPUT_32BIT)) throw std::runtime_error("MP2Decoder: no 32bit output support!"); if(!mpg123_feature(MPG123_FEATURE_DECODE_LAYER2)) throw std::runtime_error("MP2Decoder: no Layer II decode support!"); handle = mpg123_new(nullptr, &mpg_result); if(!handle) throw std::runtime_error("MP2Decoder: error while mpg123_new: " + std::string(mpg123_plain_strerror(mpg_result))); fprintf(stderr, "MP2Decoder: using decoder '%s'.\n", mpg123_current_decoder(handle)); // set allowed formats mpg_result = mpg123_format_none(handle); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_format_none: " + std::string(mpg123_plain_strerror(mpg_result))); mpg_result = mpg123_format(handle, 48000, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_format #1: " + std::string(mpg123_plain_strerror(mpg_result))); mpg_result = mpg123_format(handle, 24000, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_format #2: " + std::string(mpg123_plain_strerror(mpg_result))); // disable resync limit mpg_result = mpg123_param(handle, MPG123_RESYNC_LIMIT, -1, 0); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_param: " + std::string(mpg123_plain_strerror(mpg_result))); mpg_result = mpg123_open_feed(handle); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_open_feed: " + std::string(mpg123_plain_strerror(mpg_result))); } MP2Decoder::~MP2Decoder() { if(handle) { int mpg_result = mpg123_close(handle); if(mpg_result != MPG123_OK) fprintf(stderr, "MP2Decoder: error while mpg123_close: %s\n", mpg123_plain_strerror(mpg_result)); } mpg123_delete(handle); mpg123_exit(); } void MP2Decoder::Feed(const uint8_t *data, size_t len) { int mpg_result = mpg123_feed(handle, data, len); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_feed: " + std::string(mpg123_plain_strerror(mpg_result))); do { // go to next frame mpg_result = mpg123_framebyframe_next(handle); switch(mpg_result) { case MPG123_NEED_MORE: break; // loop left below case MPG123_NEW_FORMAT: ProcessFormat(); // fall through - as MPG123_NEW_FORMAT implies MPG123_OK case MPG123_OK: { // forward decoded frame, if applicable uint8_t *frame_data; size_t frame_len = DecodeFrame(&frame_data); if(frame_len) observer->PutAudio(frame_data, frame_len); break; } default: throw std::runtime_error("MP2Decoder: error while mpg123_framebyframe_next: " + std::string(mpg123_plain_strerror(mpg_result))); } } while (mpg_result != MPG123_NEED_MORE); } size_t MP2Decoder::DecodeFrame(uint8_t **data) { int mpg_result; if(scf_crc_len == -1) throw std::runtime_error("MP2Decoder: ScF-CRC len not yet set at PAD extraction!"); // derive PAD data from frame unsigned long header; uint8_t *body_data; size_t body_bytes; mpg_result = mpg123_framedata(handle, &header, &body_data, &body_bytes); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_framedata: " + std::string(mpg123_plain_strerror(mpg_result))); // forwarding the whole frame (except ScF-CRC + F-PAD) as X-PAD, as we don't know the X-PAD len here observer->ProcessPAD(body_data, body_bytes - FPAD_LEN - scf_crc_len, false, body_data + body_bytes - FPAD_LEN); // check CRC (MP2's CRC only - not DAB's ScF-CRC) if(!CheckCRC(header, body_data, body_bytes)) { fprintf(stderr, "\x1B[31m" "(CRC)" "\x1B[0m" " "); // no PAD reset, as not covered by CRC return 0; } size_t frame_len; mpg_result = mpg123_framebyframe_decode(handle, nullptr, data, &frame_len); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_framebyframe_decode: " + std::string(mpg123_plain_strerror(mpg_result))); return frame_len; } bool MP2Decoder::CheckCRC(const unsigned long& header, const uint8_t *body_data, const size_t& body_bytes) { mpg123_frameinfo info; int mpg_result = mpg123_info(handle, &info); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_info: " + std::string(mpg123_plain_strerror(mpg_result))); // abort, if no CRC present (though required by DAB) if(!(info.flags & MPG123_CRC)) return false; // select matching nbal table int nch = info.mode == MPG123_M_MONO ? 1 : 2; int table_index = info.version == MPG123_1_0 ? ((info.bitrate / nch) >= 56 ? 0 : 1) : 2; const int* table_nbal = tables_nbal[table_index]; // count body bits covered by CRC (= allocation + ScFSI) BitReader br(body_data + CalcCRC::CRCLen, body_bytes - CalcCRC::CRCLen); size_t body_crc_len = 0; int sblimit = sblimits[table_index]; int bound = info.mode == MPG123_M_JOINT ? (info.mode_ext + 1) * 4 : sblimit; for(int sb = 0; sb < bound; sb++) { for(int ch = 0; ch < nch; ch++) { int nbal = table_nbal[sb]; body_crc_len += nbal; int index; if(!br.GetBits(index, nbal)) return false; if(index) body_crc_len += 2; } } for(int sb = bound; sb < sblimit; sb++) { int nbal = table_nbal[sb]; body_crc_len += nbal; int index; if(!br.GetBits(index, nbal)) return false; for(int ch = 0; ch < nch; ch++) { if(index) body_crc_len += 2; } } // calc CRC uint16_t crc_stored = (body_data[0] << 8) + body_data[1]; uint16_t crc_calced; CalcCRC::CalcCRC_CRC16_IBM.Initialize(crc_calced); CalcCRC::CalcCRC_CRC16_IBM.ProcessByte(crc_calced, (header & 0x0000FF00) >> 8); CalcCRC::CalcCRC_CRC16_IBM.ProcessByte(crc_calced, header & 0x000000FF); CalcCRC::CalcCRC_CRC16_IBM.ProcessBits(crc_calced, body_data + CalcCRC::CRCLen, body_crc_len); CalcCRC::CalcCRC_CRC16_IBM.Finalize(crc_calced); return crc_stored == crc_calced; } void MP2Decoder::ProcessFormat() { mpg123_frameinfo info; int mpg_result = mpg123_info(handle, &info); if(mpg_result != MPG123_OK) throw std::runtime_error("MP2Decoder: error while mpg123_info: " + std::string(mpg123_plain_strerror(mpg_result))); scf_crc_len = (info.version == MPG123_1_0 && info.bitrate < (info.mode == MPG123_M_MONO ? 56 : 112)) ? 2 : 4; // output format const char* version = "unknown"; switch(info.version) { case MPG123_1_0: version = "1.0"; break; case MPG123_2_0: version = "2.0"; break; case MPG123_2_5: version = "2.5"; break; } const char* layer = "unknown"; switch(info.layer) { case 1: layer = "I"; break; case 2: layer = "II"; break; case 3: layer = "III"; break; } const char* mode = "unknown"; switch(info.mode) { case MPG123_M_STEREO: mode = "Stereo"; break; case MPG123_M_JOINT: mode = "Joint Stereo"; break; case MPG123_M_DUAL: mode = "Dual Channel"; break; case MPG123_M_MONO: mode = "Mono"; break; } std::stringstream ss; ss << "MPEG " << version << " Layer " << layer << ", "; ss << (info.rate / 1000) << " kHz "; ss << mode << " "; ss << "@ " << info.bitrate << " kbit/s"; observer->FormatChange(ss.str()); observer->StartAudio(info.rate, info.mode != MPG123_M_MONO ? 2 : 1, true); } dablin-1.8.0/src/dab_decoder.h000066400000000000000000000033201324402060700161200ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DAB_DECODER_H_ #define DAB_DECODER_H_ #include #include #include #include #include #include #include "mpg123.h" #if MPG123_API_VERSION < 36 # error "At least version 1.14.0 (API version 36) of mpg123 is required!" #endif #include "subchannel_sink.h" #include "tools.h" // --- MP2Decoder ----------------------------------------------------------------- class MP2Decoder : public SubchannelSink { private: mpg123_handle *handle; int scf_crc_len; void ProcessFormat(); size_t DecodeFrame(uint8_t **data); bool CheckCRC(const unsigned long& header, const uint8_t *body_data, const size_t& body_bytes); static const int table_nbal_48a[]; static const int table_nbal_48b[]; static const int table_nbal_24[]; static const int* tables_nbal[]; static const int sblimits[]; public: MP2Decoder(SubchannelSinkObserver* observer); ~MP2Decoder(); void Feed(const uint8_t *data, size_t len); }; #endif /* DAB_DECODER_H_ */ dablin-1.8.0/src/dablin.cpp000066400000000000000000000164301324402060700154770ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "dablin.h" static DABlinText *dablin = nullptr; static void break_handler(int) { fprintf(stderr, "...DABlin exits...\n"); if(dablin) dablin->DoExit(); } static void usage(const char* exe) { fprint_dablin_banner(stderr); fprintf(stderr, "Usage: %s [OPTIONS] [file]\n", exe); fprintf(stderr, " -h Show this help\n" " -d Use DAB live source (using the mentioned binary)\n" " -D DAB live source type: \"%s\" (default), \"%s\"\n" " -c Channel to be played (requires DAB live source)\n" " -s ID of the service to be played\n" " -x ID of the service component to be played (requires service ID)\n" " -r ID of the sub-channel (DAB) to be played\n" " -R ID of the sub-channel (DAB+) to be played\n" " -g USB stick gain to pass to DAB live source (auto gain is default)\n" " -p Output PCM to stdout instead of using SDL\n" " file Input file to be played (stdin, if not specified)\n", DABLiveETISource::TYPE_DAB2ETI.c_str(), DABLiveETISource::TYPE_ETI_CMDLINE.c_str() ); exit(1); } int main(int argc, char **argv) { // handle signals if(signal(SIGINT, break_handler) == SIG_ERR) { perror("DABlin: error while setting SIGINT handler"); return 1; } if(signal(SIGTERM, break_handler) == SIG_ERR) { perror("DABlin: error while setting SIGTERM handler"); return 1; } DABlinTextOptions options; int id_param_count = 0; // option args int c; while((c = getopt(argc, argv, "hc:d:D:g:s:x:pr:R:")) != -1) { switch(c) { case 'h': usage(argv[0]); break; case 'd': options.dab_live_source_binary = optarg; break; case 'D': options.dab_live_source_type = optarg; break; case 'c': options.initial_channel = optarg; break; case 's': options.initial_sid = strtol(optarg, nullptr, 0); id_param_count++; break; case 'x': options.initial_scids = strtol(optarg, nullptr, 0); break; case 'r': options.initial_subchid_dab = strtol(optarg, nullptr, 0); id_param_count++; break; case 'R': options.initial_subchid_dab_plus = strtol(optarg, nullptr, 0); id_param_count++; break; case 'g': options.gain = strtol(optarg, nullptr, 0); break; case 'p': options.pcm_output = true; break; case '?': default: usage(argv[0]); } } // non-option args switch(argc - optind) { case 0: break; case 1: options.filename = argv[optind]; break; default: usage(argv[0]); } // ensure valid options if(options.dab_live_source_binary.empty()) { if(!options.initial_channel.empty()) { fprintf(stderr, "If a channel is selected, DAB live source must be used!\n"); usage(argv[0]); } } else { if(!options.filename.empty()) { fprintf(stderr, "Both a file and DAB live source cannot be used as source!\n"); usage(argv[0]); } if(options.initial_channel.empty()) { fprintf(stderr, "If DAB live source is used, a channel must be selected!\n"); usage(argv[0]); } if(dab_channels.find(options.initial_channel) == dab_channels.end()) { fprintf(stderr, "The channel '%s' is not supported!\n", options.initial_channel.c_str()); usage(argv[0]); } if(options.dab_live_source_type != DABLiveETISource::TYPE_DAB2ETI && options.dab_live_source_type != DABLiveETISource::TYPE_ETI_CMDLINE) { fprintf(stderr, "The DAB live source type '%s' is not supported!\n", options.dab_live_source_type.c_str()); usage(argv[0]); } } if(options.initial_scids != LISTED_SERVICE::scids_none && options.initial_sid == LISTED_SERVICE::sid_none) { fprintf(stderr, "The service component ID requires the service ID to be specified!\n"); usage(argv[0]); } #ifdef DABLIN_DISABLE_SDL if(!options.pcm_output) { fprintf(stderr, "SDL output was disabled, so PCM output must be selected!\n"); usage(argv[0]); } #endif // at most one SId/SubChId needed! if(id_param_count > 1) { fprintf(stderr, "At most one SId or SubChId shall be specified!\n"); usage(argv[0]); } fprint_dablin_banner(stderr); dablin = new DABlinText(options); int result = dablin->Main(); delete dablin; return result; } // --- DABlinText ----------------------------------------------------------------- DABlinText::DABlinText(DABlinTextOptions options) { this->options = options; // set XTerm window title to version string fprintf(stderr, "\x1B]0;" "DABlin v" DABLIN_VERSION "\a"); eti_player = new ETIPlayer(options.pcm_output, this); // set initial sub-channel, if desired if(options.initial_subchid_dab != AUDIO_SERVICE::subchid_none) { eti_player->SetAudioService(AUDIO_SERVICE(options.initial_subchid_dab, false)); // set XTerm window title to sub-channel number fprintf(stderr, "\x1B]0;" "Sub-channel %d (DAB) - DABlin" "\a", options.initial_subchid_dab); } if(options.initial_subchid_dab_plus != AUDIO_SERVICE::subchid_none) { eti_player->SetAudioService(AUDIO_SERVICE(options.initial_subchid_dab_plus, true)); // set XTerm window title to sub-channel number fprintf(stderr, "\x1B]0;" "Sub-channel %d (DAB+) - DABlin" "\a", options.initial_subchid_dab_plus); } if(options.dab_live_source_binary.empty()) { eti_source = new ETISource(options.filename, this); } else { DAB_LIVE_SOURCE_CHANNEL channel(options.initial_channel, dab_channels.at(options.initial_channel), options.gain); if(options.dab_live_source_type == DABLiveETISource::TYPE_ETI_CMDLINE) eti_source = new EtiCmdlineETISource(options.dab_live_source_binary, channel, this); else eti_source = new DAB2ETIETISource(options.dab_live_source_binary, channel, this); } fic_decoder = new FICDecoder(this); } DABlinText::~DABlinText() { DoExit(); delete eti_source; delete eti_player; delete fic_decoder; } void DABlinText::ETIUpdateProgress(const ETI_PROGRESS progress) { // compensate cursor movement std::string format = "\x1B[34m" "%s" "\x1B[0m"; format.append(progress.text.length(), '\b'); fprintf(stderr, format.c_str(), progress.text.c_str()); } void DABlinText::FICChangeService(const LISTED_SERVICE& service) { // fprintf(stderr, "### FICChangeService\n"); // abort, if no/not initial service if(options.initial_sid == LISTED_SERVICE::sid_none || service.sid != options.initial_sid || service.scids != options.initial_scids) return; // if the audio service changed, switch if(!eti_player->IsSameAudioService(service.audio_service)) eti_player->SetAudioService(service.audio_service); // set XTerm window title to service name std::string label = FICDecoder::ConvertLabelToUTF8(service.label); fprintf(stderr, "\x1B]0;" "%s - DABlin" "\a", label.c_str()); } dablin-1.8.0/src/dablin.h000066400000000000000000000044701324402060700151450ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DABLIN_H_ #define DABLIN_H_ #include #include #include "eti_source.h" #include "eti_player.h" #include "fic_decoder.h" #include "tools.h" #include "version.h" // --- DABlinTextOptions ----------------------------------------------------------------- struct DABlinTextOptions { std::string filename; int initial_sid; int initial_scids; int initial_subchid_dab; int initial_subchid_dab_plus; std::string dab_live_source_binary; std::string dab_live_source_type; std::string initial_channel; bool pcm_output; int gain; DABlinTextOptions() : initial_sid(LISTED_SERVICE::sid_none), initial_scids(LISTED_SERVICE::scids_none), initial_subchid_dab(AUDIO_SERVICE::subchid_none), initial_subchid_dab_plus(AUDIO_SERVICE::subchid_none), dab_live_source_type(DABLiveETISource::TYPE_DAB2ETI), pcm_output(false), gain(DAB_LIVE_SOURCE_CHANNEL::auto_gain) {} }; // --- DABlinText ----------------------------------------------------------------- class DABlinText : ETISourceObserver, ETIPlayerObserver, FICDecoderObserver { private: DABlinTextOptions options; ETISource *eti_source; ETIPlayer *eti_player; FICDecoder *fic_decoder; void ETIProcessFrame(const uint8_t *data) {eti_player->ProcessFrame(data);}; void ETIUpdateProgress(const ETI_PROGRESS progress); void ETIProcessFIC(const uint8_t *data, size_t len) {fic_decoder->Process(data, len);} void FICChangeService(const LISTED_SERVICE& service); public: DABlinText(DABlinTextOptions options); ~DABlinText(); void DoExit() {eti_source->DoExit();} int Main() {return eti_source->Main();} }; #endif /* DABLIN_H_ */ dablin-1.8.0/src/dablin_gtk.cpp000066400000000000000000000606321324402060700163470ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "dablin_gtk.h" static DABlinGTK *dablin = nullptr; static void break_handler(int) { fprintf(stderr, "...DABlin exits...\n"); if(dablin) dablin->hide(); } static void usage(const char* exe) { fprint_dablin_banner(stderr); fprintf(stderr, "Usage: %s [OPTIONS] [file]\n", exe); fprintf(stderr, " -h Show this help\n" " -d Use DAB live source (using the mentioned binary)\n" " -D DAB live source type: \"%s\" (default), \"%s\"\n" " -C ,... Channels to be listed (comma separated; requires DAB live source;\n" " an optional gain can also be specified, e.g. \"5C:-54\")\n" " -c Channel to be played (requires DAB live source)\n" " -s ID of the service to be played\n" " -x ID of the service component to be played (requires service ID)\n" " -g USB stick gain to pass to DAB live source (auto gain is default)\n" " -p Output PCM to stdout instead of using SDL\n" " -S Initially disable slideshow\n" " -L Enable loose behaviour (e.g. PAD conformance)\n" " file Input file to be played (stdin, if not specified)\n", DABLiveETISource::TYPE_DAB2ETI.c_str(), DABLiveETISource::TYPE_ETI_CMDLINE.c_str() ); exit(1); } int main(int argc, char **argv) { // handle signals if(signal(SIGINT, break_handler) == SIG_ERR) { perror("DABlin: error while setting SIGINT handler"); return 1; } if(signal(SIGTERM, break_handler) == SIG_ERR) { perror("DABlin: error while setting SIGTERM handler"); return 1; } DABlinGTKOptions options; // option args int c; while((c = getopt(argc, argv, "hd:D:C:c:g:s:x:pSL")) != -1) { switch(c) { case 'h': usage(argv[0]); break; case 'd': options.dab_live_source_binary = optarg; break; case 'D': options.dab_live_source_type = optarg; break; case 'C': options.displayed_channels = optarg; break; case 'c': options.initial_channel = optarg; break; case 's': options.initial_sid = strtol(optarg, nullptr, 0); break; case 'x': options.initial_scids = strtol(optarg, nullptr, 0); break; case 'g': options.gain = strtol(optarg, nullptr, 0); break; case 'p': options.pcm_output = true; break; case 'S': options.initially_disable_slideshow = true; break; case 'L': options.loose = true; break; case '?': default: usage(argv[0]); } } // non-option args switch(argc - optind) { case 0: break; case 1: options.filename = argv[optind]; break; default: usage(argv[0]); } // ensure valid options if(options.dab_live_source_binary.empty()) { if(!options.displayed_channels.empty()) { fprintf(stderr, "If displayed channels are selected, DAB live source must be used!\n"); usage(argv[0]); } if(!options.initial_channel.empty()) { fprintf(stderr, "If a channel is selected, DAB live source must be used!\n"); usage(argv[0]); } } else { if(!options.filename.empty()) { fprintf(stderr, "Both a file and DAB live source cannot be used as source!\n"); usage(argv[0]); } if(!options.initial_channel.empty() && dab_channels.find(options.initial_channel) == dab_channels.end()) { fprintf(stderr, "The channel '%s' is not supported!\n", options.initial_channel.c_str()); usage(argv[0]); } if(options.dab_live_source_type != DABLiveETISource::TYPE_DAB2ETI && options.dab_live_source_type != DABLiveETISource::TYPE_ETI_CMDLINE) { fprintf(stderr, "The DAB live source type '%s' is not supported!\n", options.dab_live_source_type.c_str()); usage(argv[0]); } } if(options.initial_scids != LISTED_SERVICE::scids_none && options.initial_sid == LISTED_SERVICE::sid_none) { fprintf(stderr, "The service component ID requires the service ID to be specified!\n"); usage(argv[0]); } #ifdef DABLIN_DISABLE_SDL if(!options.pcm_output) { fprintf(stderr, "SDL output was disabled, so PCM output must be selected!\n"); usage(argv[0]); } #endif fprint_dablin_banner(stderr); int myargc = 1; Glib::RefPtr app = Gtk::Application::create(myargc, argv, ""); dablin = new DABlinGTK(options); int result = app->run(*dablin); delete dablin; return result; } // --- DABlinGTK ----------------------------------------------------------------- DABlinGTK::DABlinGTK(DABlinGTKOptions options) { this->options = options; initial_channel_appended = false; slideshow_window.set_transient_for(*this); eti_update_progress.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::ETIUpdateProgressEmitted)); eti_change_format.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::ETIChangeFormatEmitted)); fic_change_ensemble.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::FICChangeEnsembleEmitted)); fic_change_service.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::FICChangeServiceEmitted)); pad_change_dynamic_label.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::PADChangeDynamicLabelEmitted)); pad_change_slide.GetDispatcher().connect(sigc::mem_fun(*this, &DABlinGTK::PADChangeSlideEmitted)); eti_player = new ETIPlayer(options.pcm_output, this); if(!options.dab_live_source_binary.empty()) { eti_source = nullptr; } else { eti_source = new ETISource(options.filename, this); eti_source_thread = std::thread(&ETISource::Main, eti_source); } fic_decoder = new FICDecoder(this); pad_decoder = new PADDecoder(this, options.loose); set_title("DABlin v" + std::string(DABLIN_VERSION)); set_default_icon_name("media-playback-start"); InitWidgets(); set_border_width(2 * WIDGET_SPACE); // combobox first must be visible if(combo_channels_liststore->iter_is_valid(initial_channel_it)) combo_channels.set_active(initial_channel_it); initial_channel_appended = true; ConnectKeyPressEventHandler(*this); ConnectKeyPressEventHandler(slideshow_window); // add window config event handler (before default handler) signal_configure_event().connect(sigc::mem_fun(*this, &DABlinGTK::HandleConfigureEvent), false); add_events(Gdk::STRUCTURE_MASK); } DABlinGTK::~DABlinGTK() { if(eti_source) { eti_source->DoExit(); eti_source_thread.join(); delete eti_source; } delete eti_player; delete pad_decoder; delete fic_decoder; } int DABlinGTK::ComboChannelsSlotCompare(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b) { const DAB_LIVE_SOURCE_CHANNEL& ch_a = (DAB_LIVE_SOURCE_CHANNEL) (*a)[combo_channels_cols.col_channel]; const DAB_LIVE_SOURCE_CHANNEL& ch_b = (DAB_LIVE_SOURCE_CHANNEL) (*b)[combo_channels_cols.col_channel]; if(ch_a < ch_b) return -1; if(ch_b < ch_a) return 1; return 0; } int DABlinGTK::ComboServicesSlotCompare(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b) { const LISTED_SERVICE& service_a = (LISTED_SERVICE) (*a)[combo_services_cols.col_service]; const LISTED_SERVICE& service_b = (LISTED_SERVICE) (*b)[combo_services_cols.col_service]; if(service_a < service_b) return -1; if(service_b < service_a) return 1; return 0; } void DABlinGTK::InitWidgets() { // init widgets frame_combo_channels.set_label("Channel"); frame_combo_channels.set_size_request(75, -1); frame_combo_channels.add(combo_channels); combo_channels_liststore = Gtk::ListStore::create(combo_channels_cols); combo_channels_liststore->set_default_sort_func(sigc::mem_fun(*this, &DABlinGTK::ComboChannelsSlotCompare)); combo_channels_liststore->set_sort_column(Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID, Gtk::SORT_ASCENDING); combo_channels.signal_changed().connect(sigc::mem_fun(*this, &DABlinGTK::on_combo_channels)); combo_channels.set_model(combo_channels_liststore); combo_channels.pack_start(combo_channels_cols.col_string); if(!options.dab_live_source_binary.empty()) AddChannels(); else frame_combo_channels.set_sensitive(false); frame_label_ensemble.set_label("Ensemble"); frame_label_ensemble.set_size_request(150, -1); frame_label_ensemble.add(label_ensemble); label_ensemble.set_halign(Gtk::ALIGN_START); label_ensemble.set_padding(WIDGET_SPACE, WIDGET_SPACE); frame_combo_services.set_label("Service"); frame_combo_services.set_size_request(170, -1); frame_combo_services.add(combo_services); combo_services_liststore = Gtk::ListStore::create(combo_services_cols); combo_services_liststore->set_default_sort_func(sigc::mem_fun(*this, &DABlinGTK::ComboServicesSlotCompare)); combo_services_liststore->set_sort_column(Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID, Gtk::SORT_ASCENDING); combo_services.signal_changed().connect(sigc::mem_fun(*this, &DABlinGTK::on_combo_services)); combo_services.set_model(combo_services_liststore); combo_services.pack_start(combo_services_cols.col_string); frame_label_format.set_label("Format"); frame_label_format.set_size_request(250, -1); frame_label_format.set_hexpand(true); frame_label_format.add(label_format); label_format.set_halign(Gtk::ALIGN_START); label_format.set_padding(WIDGET_SPACE, WIDGET_SPACE); tglbtn_mute.set_label("Mute"); tglbtn_mute.signal_clicked().connect(sigc::mem_fun(*this, &DABlinGTK::on_tglbtn_mute)); vlmbtn.set_value(1.0); vlmbtn.set_sensitive(eti_player->HasAudioVolumeControl()); vlmbtn.signal_value_changed().connect(sigc::mem_fun(*this, &DABlinGTK::on_vlmbtn)); tglbtn_slideshow.set_label("Slideshow"); tglbtn_slideshow.set_active(!options.initially_disable_slideshow); tglbtn_slideshow.signal_clicked().connect(sigc::mem_fun(*this, &DABlinGTK::on_tglbtn_slideshow)); frame_label_dl.set_label("Dynamic Label"); frame_label_dl.set_size_request(750, 50); frame_label_dl.set_sensitive(false); frame_label_dl.set_hexpand(true); frame_label_dl.set_vexpand(true); frame_label_dl.add(label_dl); label_dl.set_halign(Gtk::ALIGN_START); label_dl.set_valign(Gtk::ALIGN_START); label_dl.set_padding(WIDGET_SPACE, WIDGET_SPACE); progress_position.set_show_text(); top_grid.set_column_spacing(WIDGET_SPACE); top_grid.set_row_spacing(WIDGET_SPACE); // add widgets add(top_grid); top_grid.attach(frame_combo_channels, 0, 0, 1, 2); top_grid.attach_next_to(frame_label_ensemble, frame_combo_channels, Gtk::POS_RIGHT, 1, 2); top_grid.attach_next_to(frame_combo_services, frame_label_ensemble, Gtk::POS_RIGHT, 1, 2); top_grid.attach_next_to(frame_label_format, frame_combo_services, Gtk::POS_RIGHT, 1, 2); top_grid.attach_next_to(tglbtn_mute, frame_label_format, Gtk::POS_RIGHT, 1, 1); top_grid.attach_next_to(vlmbtn, tglbtn_mute, Gtk::POS_RIGHT, 1, 1); top_grid.attach_next_to(tglbtn_slideshow, tglbtn_mute, Gtk::POS_BOTTOM, 2, 1); top_grid.attach_next_to(frame_label_dl, frame_combo_channels, Gtk::POS_BOTTOM, 6, 1); top_grid.attach_next_to(progress_position, frame_label_dl, Gtk::POS_BOTTOM, 6, 1); show_all_children(); progress_position.hide(); // invisible until progress updated } void DABlinGTK::AddChannels() { if(options.displayed_channels.empty()) { // add all channels for(dab_channels_t::const_iterator it = dab_channels.cbegin(); it != dab_channels.cend(); it++) AddChannel(it, options.gain); } else { // add specific channels string_vector_t channels = MiscTools::SplitString(options.displayed_channels, ','); for(string_vector_t::const_iterator ch_it = channels.cbegin(); ch_it != channels.cend(); ch_it++) { int gain = options.gain; string_vector_t parts = MiscTools::SplitString(*ch_it, ':'); switch(parts.size()) { case 2: gain = strtol(parts[1].c_str(), nullptr, 0); // fall through case 1: { dab_channels_t::const_iterator it = dab_channels.find(parts[0]); if(it != dab_channels.cend()) AddChannel(it, gain); else fprintf(stderr, "DABlinGTK: The channel '%s' is not supported; ignoring!\n", parts[0].c_str()); break; } default: fprintf(stderr, "DABlinGTK: The format of channel '%s' is not supported; ignoring!\n", ch_it->c_str()); continue; } } } } void DABlinGTK::AddChannel(dab_channels_t::const_iterator &it, int gain) { Gtk::ListStore::iterator row_it = combo_channels_liststore->append(); Gtk::TreeModel::Row row = *row_it; row[combo_channels_cols.col_string] = it->first; row[combo_channels_cols.col_channel] = DAB_LIVE_SOURCE_CHANNEL(it->first, it->second, gain); if(it->first == options.initial_channel) initial_channel_it = row_it; } void DABlinGTK::SetService(const LISTED_SERVICE& service) { // (re)set labels/tooltips if(!service.IsNone()) { char sid_string[7]; snprintf(sid_string, sizeof(sid_string), "0x%04X", service.sid); Glib::ustring label = FICDecoder::ConvertLabelToUTF8(service.label); set_title(label + " - DABlin"); frame_combo_services.set_tooltip_text( "Short label: \"" + DeriveShortLabel(label, service.label.short_label_mask) + "\"\n" "SId: " + sid_string + (!service.IsPrimary() ? " (SCIdS: " + std::to_string(service.scids) + ")" : "") + "\n" "SubChId: " + std::to_string(service.audio_service.subchid) + "\n" "Audio type: " + (service.audio_service.dab_plus ? "DAB+" : "DAB") ); if(!service.subchannel.IsNone()) { std::string tooltip_text; if(!service.subchannel.pl.empty()) { tooltip_text += "Sub-channel start: " + std::to_string(service.subchannel.start) + " CUs\n" "Sub-channel size: " + std::to_string(service.subchannel.size) + " CUs\n" "Protection level: " + service.subchannel.pl + "\n" "Bit rate: " + std::to_string(service.subchannel.bitrate) + " kBit/s"; } if(service.subchannel.language != FIC_SUBCHANNEL::language_none) { if(!tooltip_text.empty()) tooltip_text += "\n"; tooltip_text += "Language: " + FICDecoder::ConvertLanguageToString(service.subchannel.language); } frame_label_format.set_tooltip_text(tooltip_text); } } else { set_title("DABlin"); frame_combo_services.set_tooltip_text(""); frame_label_format.set_tooltip_text(""); } // if the audio service changed, reset format/DL/slide + switch if(!eti_player->IsSameAudioService(service.audio_service)) { // stop playback of old service eti_player->SetAudioService(AUDIO_SERVICE()); pad_decoder->Reset(); label_format.set_label(""); frame_label_dl.set_sensitive(false); label_dl.set_label(""); frame_label_dl.set_tooltip_text(""); if(!service.HasSLS()) { slideshow_window.hide(); slideshow_window.ClearSlide(); } // start playback of new service eti_player->SetAudioService(service.audio_service); } if(service.HasSLS()) { slideshow_window.AwaitSlide(); if(tglbtn_slideshow.get_active()) slideshow_window.TryToShow(); pad_decoder->SetMOTAppType(service.sls_app_type); } } void DABlinGTK::on_tglbtn_mute() { eti_player->SetAudioMute(tglbtn_mute.get_active()); } void DABlinGTK::on_vlmbtn(double value) { eti_player->SetAudioVolume(value); // disable mute, if needed if(tglbtn_mute.get_active()) tglbtn_mute.clicked(); } void DABlinGTK::on_tglbtn_slideshow() { if(tglbtn_slideshow.get_active()) slideshow_window.TryToShow(); else slideshow_window.hide(); } void DABlinGTK::ConnectKeyPressEventHandler(Gtk::Widget& widget) { widget.signal_key_press_event().connect(sigc::mem_fun(*this, &DABlinGTK::HandleKeyPressEvent)); widget.add_events(Gdk::KEY_PRESS_MASK); } bool DABlinGTK::HandleKeyPressEvent(GdkEventKey* key_event) { // consider only events without Shift/Control/Alt if((key_event->state & (Gdk::SHIFT_MASK | Gdk::CONTROL_MASK | Gdk::MOD1_MASK)) == 0) { switch(key_event->keyval) { case GDK_KEY_m: case GDK_KEY_M: // toggle mute tglbtn_mute.clicked(); return true; } } return false; } bool DABlinGTK::HandleConfigureEvent(GdkEventConfigure* /*configure_event*/) { // move together with slideshow window if(slideshow_window.get_visible()) slideshow_window.AlignToParent(); return false; } void DABlinGTK::ETIUpdateProgressEmitted() { // fprintf(stderr, "### ETIUpdateProgressEmitted\n"); ETI_PROGRESS progress = eti_update_progress.Pop(); progress_position.set_fraction(progress.value); progress_position.set_text(progress.text); if(!progress_position.get_visible()) progress_position.show(); } void DABlinGTK::ETIChangeFormatEmitted() { // fprintf(stderr, "### ETIChangeFormatEmitted\n"); label_format.set_label(eti_change_format.Pop()); } void DABlinGTK::FICChangeEnsembleEmitted() { // fprintf(stderr, "### FICChangeEnsembleEmitted\n"); FIC_ENSEMBLE new_ensemble = fic_change_ensemble.Pop(); char eid_string[7]; snprintf(eid_string, sizeof(eid_string), "0x%04X", new_ensemble.eid); Glib::ustring label = FICDecoder::ConvertLabelToUTF8(new_ensemble.label); label_ensemble.set_label(label); frame_label_ensemble.set_tooltip_text( "Short label: \"" + DeriveShortLabel(label, new_ensemble.label.short_label_mask) + "\"\n" "EId: " + eid_string); } void DABlinGTK::FICChangeServiceEmitted() { // fprintf(stderr, "### FICChangeServiceEmitted\n"); LISTED_SERVICE new_service = fic_change_service.Pop(); Glib::ustring label = FICDecoder::ConvertLabelToUTF8(new_service.label); if(new_service.multi_comps) label = (!new_service.IsPrimary() ? "» " : "") + label + (new_service.IsPrimary() ? " »" : ""); // get row (add new one, if needed) Gtk::ListStore::Children children = combo_services_liststore->children(); Gtk::ListStore::iterator row_it = std::find_if( children.begin(), children.end(), [&](const Gtk::TreeModel::Row& row)->bool { const LISTED_SERVICE& ls = (LISTED_SERVICE) row[combo_services_cols.col_service]; return ls.sid == new_service.sid && ls.scids == new_service.scids; } ); bool add_new_row = row_it == children.end(); if(add_new_row) row_it = combo_services_liststore->append(); Gtk::TreeModel::Row row = *row_it; row[combo_services_cols.col_string] = label; row[combo_services_cols.col_service] = new_service; if(add_new_row) { // set (initial) service if(new_service.sid == options.initial_sid && new_service.scids == options.initial_scids) combo_services.set_active(row_it); } else { // set (updated) service Gtk::ListStore::iterator current_it = combo_services.get_active(); if(current_it && current_it == row_it) SetService(new_service); } } void DABlinGTK::on_combo_channels() { Gtk::TreeModel::Row row = *combo_channels.get_active(); DAB_LIVE_SOURCE_CHANNEL channel = row[combo_channels_cols.col_channel]; // cleanup if(eti_source) { eti_source->DoExit(); eti_source_thread.join(); delete eti_source; } ETIResetFIC(); combo_services_liststore->clear(); // TODO: prevent on_combo_services() being called for each deleted row label_ensemble.set_label(""); frame_label_ensemble.set_tooltip_text(""); frame_combo_channels.set_tooltip_text( "Center frequency: " + std::to_string(channel.freq) + " kHz\n" "Gain: " + channel.GainToString() ); // prevent re-use of initial SID if(initial_channel_appended) { options.initial_sid = LISTED_SERVICE::sid_none; options.initial_scids = LISTED_SERVICE::scids_none; } // append if(options.dab_live_source_type == DABLiveETISource::TYPE_ETI_CMDLINE) eti_source = new EtiCmdlineETISource(options.dab_live_source_binary, channel, this); else eti_source = new DAB2ETIETISource(options.dab_live_source_binary, channel, this); eti_source_thread = std::thread(&ETISource::Main, eti_source); } void DABlinGTK::on_combo_services() { LISTED_SERVICE service; // default: none Gtk::TreeModel::iterator row_it = combo_services.get_active(); if(combo_services_liststore->iter_is_valid(row_it)) { Gtk::TreeModel::Row row = *row_it; service = row[combo_services_cols.col_service]; } SetService(service); } void DABlinGTK::PADChangeDynamicLabelEmitted() { // fprintf(stderr, "### PADChangeDynamicLabelEmitted\n"); DL_STATE dl = pad_change_dynamic_label.Pop(); // consider clear display command if(dl.charset != -1) { std::string charset_name; Glib::ustring label = FICDecoder::ConvertTextToUTF8(&dl.raw[0], dl.raw.size(), dl.charset, false, &charset_name); // skip unsupported charsets if(!charset_name.empty()) { frame_label_dl.set_sensitive(true); label_dl.set_label(label); frame_label_dl.set_tooltip_text("Charset: " + charset_name); } } else { frame_label_dl.set_sensitive(true); label_dl.set_label(""); frame_label_dl.set_tooltip_text(""); } } void DABlinGTK::PADChangeSlideEmitted() { // fprintf(stderr, "### PADChangeSlideEmitted\n"); slideshow_window.UpdateSlide(pad_change_slide.Pop()); if(tglbtn_slideshow.get_active()) slideshow_window.TryToShow(); } Glib::ustring DABlinGTK::DeriveShortLabel(Glib::ustring long_label, uint16_t short_label_mask) { Glib::ustring short_label; for(int i = 0; i < 16; i++) if(short_label_mask & (0x8000 >> i)) short_label += long_label[i]; return short_label; } // --- DABlinGTKSlideshowWindow ----------------------------------------------------------------- DABlinGTKSlideshowWindow::DABlinGTKSlideshowWindow() { pixbuf_waiting = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, false, 8, 320, 240); // default slide size pixbuf_waiting->fill(0x003000FF); // align to the right of parent offset_x = 20; // add some horizontal padding for WM decoration offset_y = 0; set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY); set_resizable(false); set_deletable(false); add(top_grid); top_grid.attach(image, 0, 0, 1, 1); top_grid.attach_next_to(link_button, image, Gtk::POS_BOTTOM, 1, 1); show_all_children(); // add window config event handler (before default handler) signal_configure_event().connect(sigc::mem_fun(*this, &DABlinGTKSlideshowWindow::HandleConfigureEvent), false); add_events(Gdk::STRUCTURE_MASK); } void DABlinGTKSlideshowWindow::TryToShow() { // if already visible or no slide (awaiting), abort if(get_visible() || image.get_storage_type() == Gtk::ImageType::IMAGE_EMPTY) return; AlignToParent(); show(); } void DABlinGTKSlideshowWindow::AlignToParent() { int x, y, w, h; get_transient_for()->get_position(x, y); get_transient_for()->get_size(w, h); // TODO: fix multi head issue move(x + w + offset_x, y + offset_y); } bool DABlinGTKSlideshowWindow::HandleConfigureEvent(GdkEventConfigure* /*configure_event*/) { // update window offset, if visible if(get_visible()) { int x, y, w, h, sls_x, sls_y; get_transient_for()->get_position(x, y); get_transient_for()->get_size(w, h); get_position(sls_x, sls_y); // event position doesn't work! offset_x = sls_x - w - x; offset_y = sls_y - y; } return false; } void DABlinGTKSlideshowWindow::AwaitSlide() { set_title("Slideshow..."); image.set(pixbuf_waiting); image.set_tooltip_text("Waiting for slide..."); link_button.hide(); } void DABlinGTKSlideshowWindow::UpdateSlide(const MOT_FILE& slide) { std::string type_mime = ""; std::string type_display = "unknown"; switch(slide.content_sub_type) { case MOT_FILE::CONTENT_SUB_TYPE_JFIF: type_mime = "image/jpeg"; type_display = "JPEG"; break; case MOT_FILE::CONTENT_SUB_TYPE_PNG: type_mime = "image/png"; type_display = "PNG"; break; } Glib::RefPtr pixbuf_loader = Gdk::PixbufLoader::create(type_mime, true); pixbuf_loader->write(&slide.data[0], slide.data.size()); pixbuf_loader->close(); Glib::RefPtr pixbuf = pixbuf_loader->get_pixbuf(); if(!pixbuf) return; // update title std::string title = "Slideshow"; if(!slide.category_title.empty()) title = slide.category_title + " - " + title; set_title(title); // update image image.set(pixbuf); image.set_tooltip_text( "Resolution: " + std::to_string(pixbuf->get_width()) + "x" + std::to_string(pixbuf->get_height()) + " pixels\n" + "Size: " + std::to_string(slide.data.size()) + " bytes\n" + "Format: " + type_display + "\n" + "Content name: " + slide.content_name); // update ClickThroughURL link if(!slide.click_through_url.empty()) { link_button.set_label(slide.click_through_url); link_button.set_tooltip_text(slide.click_through_url); link_button.set_uri(slide.click_through_url); // ensure that the label (created/replaced by set_label) does not extend the slide Gtk::Label* l = (Gtk::Label*) link_button.get_child(); l->set_max_width_chars(1); l->set_ellipsize(Pango::ELLIPSIZE_END); link_button.show(); } else { link_button.hide(); } } dablin-1.8.0/src/dablin_gtk.h000066400000000000000000000157461324402060700160220ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DABLIN_GTK_H_ #define DABLIN_GTK_H_ #include #include #include #include #include #include #include #include "eti_source.h" #include "eti_player.h" #include "fic_decoder.h" #include "pad_decoder.h" #include "tools.h" #include "version.h" #define WIDGET_SPACE 5 // --- DABlinGTKSlideshowWindow ----------------------------------------------------------------- class DABlinGTKSlideshowWindow : public Gtk::Window { private: Gtk::Grid top_grid; Gtk::Image image; Gtk::LinkButton link_button; Glib::RefPtr pixbuf_waiting; std::atomic offset_x; std::atomic offset_y; bool HandleConfigureEvent(GdkEventConfigure* configure_event); public: DABlinGTKSlideshowWindow(); void TryToShow(); void AlignToParent(); void AwaitSlide(); void UpdateSlide(const MOT_FILE& slide); void ClearSlide() {image.clear();} }; // --- DABlinGTKChannelColumns ----------------------------------------------------------------- class DABlinGTKChannelColumns : public Gtk::TreeModelColumnRecord { public: Gtk::TreeModelColumn col_string; Gtk::TreeModelColumn col_channel; DABlinGTKChannelColumns() { add(col_string); add(col_channel); } }; // --- DABlinGTKServiceColumns ----------------------------------------------------------------- class DABlinGTKServiceColumns : public Gtk::TreeModelColumnRecord { public: Gtk::TreeModelColumn col_string; Gtk::TreeModelColumn col_service; DABlinGTKServiceColumns() { add(col_string); add(col_service); } }; // --- DABlinGTKOptions ----------------------------------------------------------------- struct DABlinGTKOptions { std::string filename; int initial_sid; int initial_scids; std::string dab_live_source_binary; std::string dab_live_source_type; std::string displayed_channels; std::string initial_channel; bool pcm_output; int gain; bool initially_disable_slideshow; bool loose; DABlinGTKOptions() : initial_sid(LISTED_SERVICE::sid_none), initial_scids(LISTED_SERVICE::scids_none), dab_live_source_type(DABLiveETISource::TYPE_DAB2ETI), pcm_output(false), gain(DAB_LIVE_SOURCE_CHANNEL::auto_gain), initially_disable_slideshow(false), loose(false) {} }; // --- GTKDispatcherQueue ----------------------------------------------------------------- template class GTKDispatcherQueue { private: Glib::Dispatcher dispatcher; std::mutex mutex; std::queue values; public: Glib::Dispatcher& GetDispatcher() {return dispatcher;} void PushAndEmit(T value) { { std::lock_guard lock(mutex); values.push(value); } dispatcher.emit(); } T Pop() { std::lock_guard lock(mutex); T value = values.front(); values.pop(); return value; } }; // --- DABlinGTK ----------------------------------------------------------------- class DABlinGTK : public Gtk::Window, ETISourceObserver, ETIPlayerObserver, FICDecoderObserver, PADDecoderObserver { private: DABlinGTKOptions options; Gtk::ListStore::iterator initial_channel_it; bool initial_channel_appended; DABlinGTKSlideshowWindow slideshow_window; ETISource *eti_source; std::thread eti_source_thread; ETIPlayer *eti_player; FICDecoder *fic_decoder; PADDecoder *pad_decoder; // ETI data change GTKDispatcherQueue eti_update_progress; void ETIProcessFrame(const uint8_t *data) {eti_player->ProcessFrame(data);}; void ETIUpdateProgress(const ETI_PROGRESS progress) {eti_update_progress.PushAndEmit(progress);}; void ETIUpdateProgressEmitted(); GTKDispatcherQueue eti_change_format; void ETIChangeFormat(const std::string& format) {eti_change_format.PushAndEmit(format);} void ETIChangeFormatEmitted(); void ETIProcessFIC(const uint8_t *data, size_t len) {fic_decoder->Process(data, len);} void ETIResetFIC() {fic_decoder->Reset();}; void ETIProcessPAD(const uint8_t *xpad_data, size_t xpad_len, bool exact_xpad_len, const uint8_t* fpad_data) {pad_decoder->Process(xpad_data, xpad_len, exact_xpad_len, fpad_data);} Gtk::Grid top_grid; Gtk::Frame frame_combo_channels; DABlinGTKChannelColumns combo_channels_cols; Glib::RefPtr combo_channels_liststore; Gtk::ComboBox combo_channels; int ComboChannelsSlotCompare(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b); Gtk::Frame frame_label_ensemble; Gtk::Label label_ensemble; Gtk::Frame frame_combo_services; DABlinGTKServiceColumns combo_services_cols; Glib::RefPtr combo_services_liststore; Gtk::ComboBox combo_services; int ComboServicesSlotCompare(const Gtk::TreeModel::iterator& a, const Gtk::TreeModel::iterator& b); Gtk::Frame frame_label_format; Gtk::Label label_format; Gtk::ToggleButton tglbtn_mute; Gtk::VolumeButton vlmbtn; Gtk::ToggleButton tglbtn_slideshow; Gtk::Frame frame_label_dl; Gtk::Label label_dl; Gtk::ProgressBar progress_position; void InitWidgets(); void AddChannels(); void AddChannel(dab_channels_t::const_iterator &it, int gain); void SetService(const LISTED_SERVICE& service); void on_tglbtn_mute(); void on_vlmbtn(double value); void on_tglbtn_slideshow(); void on_combo_channels(); void on_combo_services(); void ConnectKeyPressEventHandler(Gtk::Widget& widget); bool HandleKeyPressEvent(GdkEventKey* key_event); bool HandleConfigureEvent(GdkEventConfigure* configure_event); // FIC data change GTKDispatcherQueue fic_change_ensemble; void FICChangeEnsemble(const FIC_ENSEMBLE& ensemble) {fic_change_ensemble.PushAndEmit(ensemble);} void FICChangeEnsembleEmitted(); GTKDispatcherQueue fic_change_service; void FICChangeService(const LISTED_SERVICE& service) {fic_change_service.PushAndEmit(service);} void FICChangeServiceEmitted(); // PAD data change GTKDispatcherQueue pad_change_dynamic_label; void PADChangeDynamicLabel(const DL_STATE& dl) {pad_change_dynamic_label.PushAndEmit(dl);} void PADChangeDynamicLabelEmitted(); GTKDispatcherQueue pad_change_slide; void PADChangeSlide(const MOT_FILE& slide) {pad_change_slide.PushAndEmit(slide);} void PADChangeSlideEmitted(); Glib::ustring DeriveShortLabel(Glib::ustring long_label, uint16_t short_label_mask); public: DABlinGTK(DABlinGTKOptions options); ~DABlinGTK(); }; #endif /* DABLIN_GTK_H_ */ dablin-1.8.0/src/dabplus_decoder.cpp000066400000000000000000000343171324402060700173710ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "dabplus_decoder.h" // --- SuperframeFilter ----------------------------------------------------------------- SuperframeFilter::SuperframeFilter(SubchannelSinkObserver* observer) : SubchannelSink(observer) { aac_dec = nullptr; frame_len = 0; frame_count = 0; sync_frames = 0; sf_raw = nullptr; sf = nullptr; sf_len = 0; sf_format_set = false; sf_format_raw = 0; num_aus = 0; } SuperframeFilter::~SuperframeFilter() { delete[] sf_raw; delete[] sf; delete aac_dec; } void SuperframeFilter::Feed(const uint8_t *data, size_t len) { // check frame len if(frame_len) { if(frame_len != len) { fprintf(stderr, "SuperframeFilter: different frame len %zu (should be: %zu) - frame ignored!\n", len, frame_len); return; } } else { if(len < 10) { fprintf(stderr, "SuperframeFilter: frame len %zu too short - frame ignored!\n", len); return; } if((5 * len) % 120) { fprintf(stderr, "SuperframeFilter: resulting Superframe len of len %zu not divisible by 120 - frame ignored!\n", len); return; } frame_len = len; sf_len = 5 * frame_len; sf_raw = new uint8_t[sf_len]; sf = new uint8_t[sf_len]; } if(frame_count == 5) { // shift previous frames for(int i = 0; i < 4; i++) memcpy(sf_raw + i * frame_len, sf_raw + (i + 1) * frame_len, frame_len); } else { frame_count++; } // copy frame memcpy(sf_raw + (frame_count - 1) * frame_len, data, frame_len); if(frame_count < 5) return; // append RS coding on copy memcpy(sf, sf_raw, sf_len); rs_dec.DecodeSuperframe(sf, sf_len); if(!CheckSync()) { if(sync_frames == 0) fprintf(stderr, "SuperframeFilter: Superframe sync started...\n"); sync_frames++; return; } if(sync_frames) { fprintf(stderr, "SuperframeFilter: Superframe sync succeeded after %d frame(s)\n", sync_frames); sync_frames = 0; ResetPAD(); } // check announced format if(!sf_format_set || sf_format_raw != sf[2]) { sf_format_raw = sf[2]; sf_format_set = true; ProcessFormat(); } // decode frames for(int i = 0; i < num_aus; i++) { uint8_t *au_data = sf + au_start[i]; size_t au_len = au_start[i+1] - au_start[i]; uint16_t au_crc_stored = au_data[au_len-2] << 8 | au_data[au_len-1]; uint16_t au_crc_calced = CalcCRC::CalcCRC_CRC16_CCITT.Calc(au_data, au_len - 2); if(au_crc_stored != au_crc_calced) { fprintf(stderr, "\x1B[31m" "(AU #%d)" "\x1B[0m" " ", i); ResetPAD(); continue; } au_len -= 2; aac_dec->DecodeFrame(au_data, au_len); CheckForPAD(au_data, au_len); } // ensure getting a complete new Superframe frame_count = 0; } void SuperframeFilter::CheckForPAD(const uint8_t *data, size_t len) { bool present = false; // check for PAD (embedded into Data Stream Element) if(len >= 3 && (data[0] >> 5) == 4) { size_t pad_start = 2; size_t pad_len = data[1]; if(pad_len == 255) { pad_len += data[2]; pad_start++; } if(pad_len >= 2 && len >= pad_start + pad_len) { observer->ProcessPAD(data + pad_start, pad_len - FPAD_LEN, true, data + pad_start + pad_len - FPAD_LEN); present = true; } } if(!present) ResetPAD(); } void SuperframeFilter::ResetPAD() { // required to reset internal state of PAD parser (in case of omitted CI list) uint8_t zero_fpad[FPAD_LEN] = {0x00}; observer->ProcessPAD(nullptr, 0, true, zero_fpad); } bool SuperframeFilter::CheckSync() { // abort, if au_start is kind of zero (prevent sync on complete zero array) if(sf[3] == 0x00 && sf[4] == 0x00) return false; // TODO: use fire code for error correction // try to sync on fire code uint16_t crc_stored = sf[0] << 8 | sf[1]; uint16_t crc_calced = CalcCRC::CalcCRC_FIRE_CODE.Calc(sf + 2, 9); if(crc_stored != crc_calced) return false; // handle format sf_format.dac_rate = sf[2] & 0x40; sf_format.sbr_flag = sf[2] & 0x20; sf_format.aac_channel_mode = sf[2] & 0x10; sf_format.ps_flag = sf[2] & 0x08; sf_format.mpeg_surround_config = sf[2] & 0x07; // determine number/start of AUs num_aus = sf_format.dac_rate ? (sf_format.sbr_flag ? 3 : 6) : (sf_format.sbr_flag ? 2 : 4); au_start[0] = sf_format.dac_rate ? (sf_format.sbr_flag ? 6 : 11) : (sf_format.sbr_flag ? 5 : 8); au_start[num_aus] = sf_len / 120 * 110; // pseudo-next AU (w/o RS coding) au_start[1] = sf[3] << 4 | sf[4] >> 4; if(num_aus >= 3) au_start[2] = (sf[4] & 0x0F) << 8 | sf[5]; if(num_aus >= 4) au_start[3] = sf[6] << 4 | sf[7] >> 4; if(num_aus == 6) { au_start[4] = (sf[7] & 0x0F) << 8 | sf[8]; au_start[5] = sf[9] << 4 | sf[10] >> 4; } // simple plausi check for correct order of start offsets for(int i = 0; i < num_aus; i++) if(au_start[i] >= au_start[i+1]) return false; return true; } void SuperframeFilter::ProcessFormat() { // output format const char *stereo_mode = (sf_format.aac_channel_mode || sf_format.ps_flag) ? "Stereo" : "Mono"; const char *surround_mode; switch(sf_format.mpeg_surround_config) { case 0: surround_mode = nullptr; break; case 1: surround_mode = "Surround 5.1"; break; case 2: surround_mode = "Surround 7.1"; break; default: surround_mode = "Surround (unknown)"; break; } int bitrate = sf_len / 120 * 8; std::stringstream ss; ss << (sf_format.sbr_flag ? (sf_format.ps_flag ? "HE-AAC v2" : "HE-AAC") : "AAC-LC") << ", "; ss << (sf_format.dac_rate ? 48 : 32) << " kHz "; if(surround_mode) ss << surround_mode << " (" << stereo_mode << " core) "; else ss << stereo_mode << " "; ss << "@ " << bitrate << " kBit/s"; observer->FormatChange(ss.str()); if(aac_dec) delete aac_dec; #ifdef DABLIN_AAC_FAAD2 aac_dec = new AACDecoderFAAD2(observer, sf_format); #endif #ifdef DABLIN_AAC_FDKAAC aac_dec = new AACDecoderFDKAAC(observer, sf_format); #endif } // --- RSDecoder ----------------------------------------------------------------- RSDecoder::RSDecoder() { rs_handle = init_rs_char(8, 0x11D, 0, 1, 10, 135); if(!rs_handle) throw std::runtime_error("RSDecoder: error while init_rs_char"); } RSDecoder::~RSDecoder() { free_rs_char(rs_handle); } void RSDecoder::DecodeSuperframe(uint8_t *sf, size_t sf_len) { // // insert errors for test // sf[0] ^= 0xFF; // sf[10] ^= 0xFF; // sf[20] ^= 0xFF; int subch_index = sf_len / 120; int total_corr_count = 0; bool uncorr_errors = false; // process all RS packets for(int i = 0; i < subch_index; i++) { for(int pos = 0; pos < 120; pos++) rs_packet[pos] = sf[pos * subch_index + i]; // detect errors int corr_count = decode_rs_char(rs_handle, rs_packet, corr_pos, 0); if(corr_count == -1) uncorr_errors = true; else total_corr_count += corr_count; // correct errors for(int j = 0; j < corr_count; j++) { int pos = corr_pos[j] - 135; if(pos < 0) continue; // fprintf(stderr, "j: %d, pos: %d, sf-index: %d\n", j, pos, pos * subch_index + i); sf[pos * subch_index + i] = rs_packet[pos]; } } // output statistics if errors present (using ANSI coloring) if(total_corr_count || uncorr_errors) fprintf(stderr, "\x1B[36m" "(%d%s)" "\x1B[0m" " ", total_corr_count, uncorr_errors ? "+" : ""); } // --- AACDecoder ----------------------------------------------------------------- AACDecoder::AACDecoder(std::string decoder_name, SubchannelSinkObserver* observer, SuperframeFormat sf_format) { fprintf(stderr, "AACDecoder: using decoder '%s'\n", decoder_name.c_str()); this->observer = observer; /* AudioSpecificConfig structure (the only way to select 960 transform here!) * * 00010 = AudioObjectType 2 (AAC LC) * xxxx = (core) sample rate index * xxxx = (core) channel config * 100 = GASpecificConfig with 960 transform * * SBR: explicit signaling (backwards-compatible), adding: * 01010110111 = sync extension for SBR * 00101 = AudioObjectType 5 (SBR) * 1 = SBR present flag * xxxx = extension sample rate index * * PS: explicit signaling (backwards-compatible), adding: * 10101001000 = sync extension for PS * 1 = PS present flag * * Note: * libfaad2 does not support non backwards-compatible PS signaling (AOT 29); * it detects PS only by implicit signaling. */ // AAC LC asc_len = 0; asc[asc_len++] = 0b00010 << 3 | sf_format.GetCoreSrIndex() >> 1; asc[asc_len++] = (sf_format.GetCoreSrIndex() & 0x01) << 7 | sf_format.GetCoreChConfig() << 3 | 0b100; if(sf_format.sbr_flag) { // add SBR asc[asc_len++] = 0x56; asc[asc_len++] = 0xE5; asc[asc_len++] = 0x80 | (sf_format.GetExtensionSrIndex() << 3); if(sf_format.ps_flag) { // add PS asc[asc_len - 1] |= 0x05; asc[asc_len++] = 0x48; asc[asc_len++] = 0x80; } } } #ifdef DABLIN_AAC_FAAD2 // --- AACDecoderFAAD2 ----------------------------------------------------------------- AACDecoderFAAD2::AACDecoderFAAD2(SubchannelSinkObserver* observer, SuperframeFormat sf_format) : AACDecoder("FAAD2", observer, sf_format) { // ensure features unsigned long cap = NeAACDecGetCapabilities(); if(!(cap & LC_DEC_CAP)) throw std::runtime_error("AACDecoderFAAD2: no LC decoding support!"); handle = NeAACDecOpen(); if(!handle) throw std::runtime_error("AACDecoderFAAD2: error while NeAACDecOpen"); // set general config NeAACDecConfigurationPtr config = NeAACDecGetCurrentConfiguration(handle); if(!config) throw std::runtime_error("AACDecoderFAAD2: error while NeAACDecGetCurrentConfiguration"); config->outputFormat = FAAD_FMT_FLOAT; config->dontUpSampleImplicitSBR = 0; if(NeAACDecSetConfiguration(handle, config) != 1) throw std::runtime_error("AACDecoderFAAD2: error while NeAACDecSetConfiguration"); // init decoder unsigned long output_sr; unsigned char output_ch; long int init_result = NeAACDecInit2(handle, asc, asc_len, &output_sr, &output_ch); if(init_result != 0) throw std::runtime_error("AACDecoderFAAD2: error while NeAACDecInit2: " + std::string(NeAACDecGetErrorMessage(-init_result))); observer->StartAudio(output_sr, output_ch, true); } AACDecoderFAAD2::~AACDecoderFAAD2() { NeAACDecClose(handle); } void AACDecoderFAAD2::DecodeFrame(uint8_t *data, size_t len) { // decode audio uint8_t* output_frame = (uint8_t*) NeAACDecDecode(handle, &dec_frameinfo, data, len); if(dec_frameinfo.error) fprintf(stderr, "\x1B[35m" "(AAC)" "\x1B[0m" " "); // abort, if no output at all if(dec_frameinfo.bytesconsumed == 0 && dec_frameinfo.samples == 0) return; if(dec_frameinfo.bytesconsumed != len) throw std::runtime_error("AACDecoderFAAD2: NeAACDecDecode did not consume all bytes"); observer->PutAudio(output_frame, dec_frameinfo.samples * 4); } #endif #ifdef DABLIN_AAC_FDKAAC // --- AACDecoderFDKAAC ----------------------------------------------------------------- AACDecoderFDKAAC::AACDecoderFDKAAC(SubchannelSinkObserver* observer, SuperframeFormat sf_format) : AACDecoder("FDK-AAC", observer, sf_format) { handle = aacDecoder_Open(TT_MP4_RAW, 1); if(!handle) throw std::runtime_error("AACDecoderFDKAAC: error while aacDecoder_Open"); int channels = sf_format.aac_channel_mode || sf_format.ps_flag ? 2 : 1; AAC_DECODER_ERROR init_result; /* Restrict output channel count to actual input channel count. * * Just using the parameter value -1 (no up-/downmix) does not work, as with * SBR and Mono the lib assumes possibly present PS and then outputs Stereo! * * Note: * Older lib versions use a combined parameter for the output channel count. * As the headers of these didn't define the version, branch accordingly. */ #if !defined(AACDECODER_LIB_VL0) && !defined(AACDECODER_LIB_VL1) && !defined(AACDECODER_LIB_VL2) init_result = aacDecoder_SetParam(handle, AAC_PCM_OUTPUT_CHANNELS, channels); if(init_result != AAC_DEC_OK) throw std::runtime_error("AACDecoderFDKAAC: error while setting parameter AAC_PCM_OUTPUT_CHANNELS: " + std::to_string(init_result)); #else init_result = aacDecoder_SetParam(handle, AAC_PCM_MIN_OUTPUT_CHANNELS, channels); if(init_result != AAC_DEC_OK) throw std::runtime_error("AACDecoderFDKAAC: error while setting parameter AAC_PCM_MIN_OUTPUT_CHANNELS: " + std::to_string(init_result)); init_result = aacDecoder_SetParam(handle, AAC_PCM_MAX_OUTPUT_CHANNELS, channels); if(init_result != AAC_DEC_OK) throw std::runtime_error("AACDecoderFDKAAC: error while setting parameter AAC_PCM_MAX_OUTPUT_CHANNELS: " + std::to_string(init_result)); #endif uint8_t* asc_array[1] {asc}; const unsigned int asc_sizeof_array[1] {(unsigned int) asc_len}; init_result = aacDecoder_ConfigRaw(handle, asc_array, asc_sizeof_array); if(init_result != AAC_DEC_OK) throw std::runtime_error("AACDecoderFDKAAC: error while aacDecoder_ConfigRaw: " + std::to_string(init_result)); output_frame_len = 960 * 2 * channels * (sf_format.sbr_flag ? 2 : 1); output_frame = new uint8_t[output_frame_len]; observer->StartAudio(sf_format.dac_rate ? 48000 : 32000, channels, false); } AACDecoderFDKAAC::~AACDecoderFDKAAC() { aacDecoder_Close(handle); delete[] output_frame; } void AACDecoderFDKAAC::DecodeFrame(uint8_t *data, size_t len) { uint8_t* input_buffer[1] {data}; const unsigned int input_buffer_size[1] {(unsigned int) len}; unsigned int bytes_valid = len; // fill internal input buffer AAC_DECODER_ERROR result = aacDecoder_Fill(handle, input_buffer, input_buffer_size, &bytes_valid); if(result != AAC_DEC_OK) throw std::runtime_error("AACDecoderFDKAAC: error while aacDecoder_Fill: " + std::to_string(result)); if(bytes_valid) throw std::runtime_error("AACDecoderFDKAAC: aacDecoder_Fill did not consume all bytes"); // decode audio result = aacDecoder_DecodeFrame(handle, (short int*) output_frame, output_frame_len / 2, 0); if(result != AAC_DEC_OK) fprintf(stderr, "\x1B[35m" "(AAC)" "\x1B[0m" " "); if(!IS_OUTPUT_VALID(result)) return; observer->PutAudio(output_frame, output_frame_len); } #endif dablin-1.8.0/src/dabplus_decoder.h000066400000000000000000000073621324402060700170360ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef DABPLUS_DECODER_H_ #define DABPLUS_DECODER_H_ #include #include #include #include #include #include #if !(defined(DABLIN_AAC_FAAD2) ^ defined(DABLIN_AAC_FDKAAC)) #error "You must select a AAC decoder by defining either DABLIN_AAC_FAAD2 or DABLIN_AAC_FDKAAC!" #endif #ifdef DABLIN_AAC_FAAD2 #include #endif #ifdef DABLIN_AAC_FDKAAC #include #endif extern "C" { #include } #include "subchannel_sink.h" #include "tools.h" struct SuperframeFormat { bool dac_rate; bool sbr_flag; bool aac_channel_mode; bool ps_flag; int mpeg_surround_config; int GetCoreSrIndex() { return dac_rate ? (sbr_flag ? 6 : 3) : (sbr_flag ? 8 : 5); // 24/48/16/32 kHz } int GetCoreChConfig() { return aac_channel_mode ? 2 : 1; } int GetExtensionSrIndex() { return dac_rate ? 3 : 5; // 48/32 kHz } }; // --- RSDecoder ----------------------------------------------------------------- class RSDecoder { private: void *rs_handle; uint8_t rs_packet[120]; int corr_pos[10]; public: RSDecoder(); ~RSDecoder(); void DecodeSuperframe(uint8_t *sf, size_t sf_len); }; // --- AACDecoder ----------------------------------------------------------------- class AACDecoder { protected: SubchannelSinkObserver* observer; uint8_t asc[7]; size_t asc_len; public: AACDecoder(std::string decoder_name, SubchannelSinkObserver* observer, SuperframeFormat sf_format); virtual ~AACDecoder() {} virtual void DecodeFrame(uint8_t *data, size_t len) = 0; }; #ifdef DABLIN_AAC_FAAD2 // --- AACDecoderFAAD2 ----------------------------------------------------------------- class AACDecoderFAAD2 : public AACDecoder { private: NeAACDecHandle handle; NeAACDecFrameInfo dec_frameinfo; public: AACDecoderFAAD2(SubchannelSinkObserver* observer, SuperframeFormat sf_format); ~AACDecoderFAAD2(); void DecodeFrame(uint8_t *data, size_t len); }; #endif #ifdef DABLIN_AAC_FDKAAC // --- AACDecoderFDKAAC ----------------------------------------------------------------- class AACDecoderFDKAAC : public AACDecoder { private: HANDLE_AACDECODER handle; uint8_t *output_frame; size_t output_frame_len; public: AACDecoderFDKAAC(SubchannelSinkObserver* observer, SuperframeFormat sf_format); ~AACDecoderFDKAAC(); void DecodeFrame(uint8_t *data, size_t len); }; #endif // --- SuperframeFilter ----------------------------------------------------------------- class SuperframeFilter : public SubchannelSink { private: RSDecoder rs_dec; AACDecoder *aac_dec; size_t frame_len; int frame_count; int sync_frames; uint8_t *sf_raw; uint8_t *sf; size_t sf_len; bool sf_format_set; uint8_t sf_format_raw; SuperframeFormat sf_format; int num_aus; int au_start[6+1]; // +1 for end of last AU bool CheckSync(); void ProcessFormat(); void CheckForPAD(const uint8_t *data, size_t len); void ResetPAD(); public: SuperframeFilter(SubchannelSinkObserver* observer); ~SuperframeFilter(); void Feed(const uint8_t *data, size_t len); }; #endif /* DABPLUS_DECODER_H_ */ dablin-1.8.0/src/eti_player.cpp000066400000000000000000000123071324402060700164020ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "eti_player.h" // --- ETIPlayer ----------------------------------------------------------------- ETIPlayer::ETIPlayer(bool pcm_output, ETIPlayerObserver *observer) { this->observer = observer; next_frame_time = std::chrono::steady_clock::now(); dec = nullptr; #ifndef DABLIN_DISABLE_SDL if(!pcm_output) out = new SDLOutput; else #endif out = new PCMOutput; } ETIPlayer::~ETIPlayer() { delete dec; delete out; } bool ETIPlayer::IsSameAudioService(const AUDIO_SERVICE& audio_service) { std::lock_guard lock(audio_service_mutex); // check, if already the same service return this->audio_service == audio_service; } void ETIPlayer::SetAudioService(const AUDIO_SERVICE& audio_service) { std::lock_guard lock(audio_service_mutex); // abort, if already the same service if(this->audio_service == audio_service) return; // cleanup if(dec) { // out->StopAudio(); delete dec; dec = nullptr; } if(audio_service.IsNone()) fprintf(stderr, "ETIPlayer: playing nothing\n"); else fprintf(stderr, "ETIPlayer: playing sub-channel %d (%s)\n", audio_service.subchid, audio_service.dab_plus ? "DAB+" : "DAB"); // append if(!audio_service.IsNone()) { if(audio_service.dab_plus) dec = new SuperframeFilter(this); else dec = new MP2Decoder(this); } this->audio_service = audio_service; } void ETIPlayer::ProcessFrame(const uint8_t *data) { // flow control std::this_thread::sleep_until(next_frame_time); next_frame_time += std::chrono::milliseconds(24); DecodeFrame(data); } void ETIPlayer::DecodeFrame(const uint8_t *eti_frame) { std::lock_guard lock(audio_service_mutex); // ERR if(eti_frame[0] != 0xFF) { fprintf(stderr, "ETIPlayer: ignored ETI frame with ERR = 0x%02X\n", eti_frame[0]); return; } uint32_t fsync = eti_frame[1] << 16 | eti_frame[2] << 8 | eti_frame[3]; if(fsync != 0x073AB6 && fsync != 0xF8C549) { fprintf(stderr, "ETIPlayer: ignored ETI frame with FSYNC = 0x%06X\n", fsync); return; } if(eti_frame[4] == 0xFF && eti_frame[5] == 0xFF && eti_frame[6] == 0xFF && eti_frame[7] == 0xFF) { fprintf(stderr, "ETIPlayer: ignored ETI frame with null transmission\n"); return; } bool ficf = eti_frame[5] & 0x80; int nst = eti_frame[5] & 0x7F; int mid = (eti_frame[6] & 0x18) >> 3; int fl = (eti_frame[6] & 0x07) << 8 | eti_frame[7]; // check header CRC size_t header_crc_data_len = 4 + nst * 4 + 2; uint16_t header_crc_stored = eti_frame[4 + header_crc_data_len] << 8 | eti_frame[4 + header_crc_data_len + 1]; uint16_t header_crc_calced = CalcCRC::CalcCRC_CRC16_CCITT.Calc(eti_frame + 4, header_crc_data_len); if(header_crc_stored != header_crc_calced) { fprintf(stderr, "ETIPlayer: ignored ETI frame due to wrong header CRC\n"); return; } int ficl = ficf ? (mid == 3 ? 32 : 24) : 0; int subch_bytes = 0; int subch_offset = 4 + 4 + nst * 4 + 4; // check (MST) CRC size_t mst_crc_data_len = (fl - nst - 1) * 4; uint16_t mst_crc_stored = eti_frame[subch_offset + mst_crc_data_len] << 8 | eti_frame[subch_offset + mst_crc_data_len + 1]; uint16_t mst_crc_calced = CalcCRC::CalcCRC_CRC16_CCITT.Calc(eti_frame + subch_offset, mst_crc_data_len); if(mst_crc_stored != mst_crc_calced) { fprintf(stderr, "ETIPlayer: ignored ETI frame due to wrong (MST) CRC\n"); return; } if(ficl) { ProcessFIC(eti_frame + subch_offset, ficl * 4); subch_offset += ficl * 4; } // abort here, if ATM no sub-channel selected if(audio_service.IsNone()) return; for(int i = 0; i < nst; i++) { int scid = (eti_frame[8 + i*4] & 0xFC) >> 2; int stl = (eti_frame[8 + i*4 + 2] & 0x03) << 8 | eti_frame[8 + i*4 + 3]; if(scid == audio_service.subchid) { subch_bytes = stl * 8; break; } else { subch_offset += stl * 8; } } if(subch_bytes == 0) { fprintf(stderr, "ETIPlayer: ignored ETI frame without sub-channel %d\n", audio_service.subchid); return; } dec->Feed(eti_frame + subch_offset, subch_bytes); } void ETIPlayer::FormatChange(const std::string& format) { fprintf(stderr, "ETIPlayer: format: %s\n", format.c_str()); if(observer) observer->ETIChangeFormat(format); } void ETIPlayer::ProcessFIC(const uint8_t *data, size_t len) { // fprintf(stderr, "Received %zu bytes FIC\n", len); if(observer) observer->ETIProcessFIC(data, len); } void ETIPlayer::ProcessPAD(const uint8_t *xpad_data, size_t xpad_len, bool exact_xpad_len, const uint8_t *fpad_data) { // fprintf(stderr, "Received %zu bytes X-PAD\n", xpad_len); if(observer) observer->ETIProcessPAD(xpad_data, xpad_len, exact_xpad_len, fpad_data); } dablin-1.8.0/src/eti_player.h000066400000000000000000000053211324402060700160450ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef ETI_PLAYER_H_ #define ETI_PLAYER_H_ #include #include #include #include #include #include "subchannel_sink.h" #include "dab_decoder.h" #include "dabplus_decoder.h" #include "pcm_output.h" #include "tools.h" #ifndef DABLIN_DISABLE_SDL #include "sdl_output.h" #endif // --- ETIPlayerObserver ----------------------------------------------------------------- class ETIPlayerObserver { public: virtual ~ETIPlayerObserver() {}; virtual void ETIChangeFormat(const std::string& /*format*/) {}; virtual void ETIProcessFIC(const uint8_t* /*data*/, size_t /*len*/) {}; virtual void ETIProcessPAD(const uint8_t* /*xpad_data*/, size_t /*xpad_len*/, bool /*exact_xpad_len*/, const uint8_t* /*fpad_data*/) {} }; // --- ETIPlayer ----------------------------------------------------------------- class ETIPlayer : SubchannelSinkObserver { private: ETIPlayerObserver *observer; std::chrono::steady_clock::time_point next_frame_time; std::mutex audio_service_mutex; AUDIO_SERVICE audio_service; SubchannelSink *dec; AudioOutput *out; void DecodeFrame(const uint8_t *eti_frame); void FormatChange(const std::string& format); void StartAudio(int samplerate, int channels, bool float32) {out->StartAudio(samplerate, channels, float32);} void PutAudio(const uint8_t *data, size_t len) {out->PutAudio(data, len);} void ProcessFIC(const uint8_t *data, size_t len); void ProcessPAD(const uint8_t *xpad_data, size_t xpad_len, bool exact_xpad_len, const uint8_t *fpad_data); public: ETIPlayer(bool pcm_output, ETIPlayerObserver *observer); ~ETIPlayer(); void ProcessFrame(const uint8_t *data); bool IsSameAudioService(const AUDIO_SERVICE& audio_service); void SetAudioService(const AUDIO_SERVICE& audio_service); void SetAudioMute(bool audio_mute) {out->SetAudioMute(audio_mute);} void SetAudioVolume(double audio_volume) {out->SetAudioVolume(audio_volume);} bool HasAudioVolumeControl() {return out->HasAudioVolumeControl();} }; #endif /* ETI_PLAYER_H_ */ dablin-1.8.0/src/eti_source.cpp000066400000000000000000000152021324402060700164030ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "eti_source.h" // --- ETISource ----------------------------------------------------------------- ETISource::ETISource(std::string filename, ETISourceObserver *observer) { this->filename = filename; this->observer = observer; input_file = nullptr; eti_frame_count = 0; eti_frame_total = 0; eti_progress_next_ms = 0; do_exit = false; } ETISource::~ETISource() { // cleanup if(input_file && input_file != stdin) fclose(input_file); } void ETISource::PrintSource() { fprintf(stderr, "ETISource: reading from '%s'\n", filename.c_str()); } bool ETISource::OpenFile() { if(filename.empty()) { input_file = stdin; filename = "stdin"; } else { input_file = fopen(filename.c_str(), "rb"); if(!input_file) { perror("ETISource: error opening input file"); return false; } } // init total frames return UpdateTotalFrames(); } bool ETISource::UpdateTotalFrames() { // if file size available, calc total frame count off_t old_offset = ftello(input_file); if(old_offset == -1) { // ignore non-seekable files (like usually stdin) if(errno == ESPIPE) return true; perror("ETISource: error getting file offset"); return false; } if(fseeko(input_file, 0, SEEK_END)) { perror("ETISource: error seeking to end"); return false; } off_t len = ftello(input_file); if(len == -1) { perror("ETISource: error getting file size"); return false; } if(fseeko(input_file, old_offset, SEEK_SET)) { perror("ETISource: error seeking to offset"); return false; } eti_frame_total = (len / sizeof(eti_frame)) - 1; return true; } int ETISource::Main() { Init(); if(!input_file) { if(!OpenFile()) return 1; } PrintSource(); int file_no = fileno(input_file); // set non-blocking mode int old_flags = fcntl(file_no, F_GETFL); if(old_flags == -1) { perror("ETISource: error getting socket flags"); return 1; } if(fcntl(file_no, F_SETFL, (old_flags == -1 ? 0 : old_flags) | O_NONBLOCK)) { perror("ETISource: error setting socket flags"); return 1; } fd_set fds; timeval select_timeval; size_t filled = 0; while(!do_exit) { FD_ZERO(&fds); FD_SET(file_no, &fds); select_timeval.tv_sec = 0; select_timeval.tv_usec = 100 * 1000; int ready_fds = select(file_no + 1, &fds, nullptr, nullptr, &select_timeval); if(ready_fds == -1) { // ignore break request, as handled above if(errno != EINTR) perror("ETISource: error while select"); continue; } if(!(ready_fds && FD_ISSET(file_no, &fds))) continue; size_t bytes = fread(eti_frame + filled, 1, sizeof(eti_frame) - filled, input_file); if(bytes > 0) filled += bytes; if(bytes == 0) { if(feof(input_file)) { fprintf(stderr, "ETISource: EOF reached!\n"); break; } perror("ETISource: error while fread"); return 1; } if(filled < sizeof(eti_frame)) continue; // if present, update progress every 500ms or at file end if(eti_frame_total && (eti_frame_count * 24 >= eti_progress_next_ms || eti_frame_count == eti_frame_total)) { // update total frames if(!UpdateTotalFrames()) return 1; ETI_PROGRESS progress; progress.value = (double) eti_frame_count / (double) eti_frame_total; progress.text = FramecountToTimecode(eti_frame_count) + " / " + FramecountToTimecode(eti_frame_total); observer->ETIUpdateProgress(progress); eti_progress_next_ms += 500; } observer->ETIProcessFrame(eti_frame); eti_frame_count++; filled = 0; } return 0; } std::string ETISource::FramecountToTimecode(size_t value) { // frame count -> time code long int tc_s = value * 24 / 1000; // split int h = tc_s / 3600; tc_s -= h * 3600; int m = tc_s / 60; tc_s -= m * 60; int s = tc_s; // generate output char digits[3]; std::string result = std::to_string(h); snprintf(digits, sizeof(digits), "%02d", m); result += ":" + std::string(digits); snprintf(digits, sizeof(digits), "%02d", s); result += ":" + std::string(digits); return result; } // --- DABLiveETISource ----------------------------------------------------------------- const std::string DABLiveETISource::TYPE_DAB2ETI = "dab2eti"; const std::string DABLiveETISource::TYPE_ETI_CMDLINE = "eti-cmdline"; DABLiveETISource::DABLiveETISource(std::string binary, DAB_LIVE_SOURCE_CHANNEL channel, ETISourceObserver *observer, std::string source_name) : ETISource("", observer) { this->channel = channel; this->binary = binary; this->source_name = source_name; // it doesn't matter whether there is a prefixed path or not binary_name = binary.substr(binary.find_last_of('/') + 1); } void DABLiveETISource::Init() { std::string cmdline = binary + " " + GetParams(); input_file = popen(cmdline.c_str(), "r"); if(!input_file) perror("ETISource: error starting DAB live source"); } void DABLiveETISource::PrintSource() { fprintf(stderr, "ETISource: playing from channel %s (%u kHz) via %s (gain: %s)\n", channel.block.c_str(), channel.freq, source_name.c_str(), channel.GainToString().c_str()); } DABLiveETISource::~DABLiveETISource() { // TODO: replace bad style temporary solution (here possible, because dab2eti allows only one concurrent session) std::string cmd_killall = "killall " + binary_name; int result = system(cmd_killall.c_str()); if(result != 0) fprintf(stderr, "ETISource: error killing %s\n", source_name.c_str()); pclose(input_file); input_file = nullptr; } // --- DAB2ETIETISource ----------------------------------------------------------------- std::string DAB2ETIETISource::GetParams() { std::string result = std::to_string(channel.freq * 1000); if(!channel.HasAutoGain()) result += " " + std::to_string(channel.gain); return result; } // --- EtiCmdlineETISource ----------------------------------------------------------------- std::string EtiCmdlineETISource::GetParams() { std::string cmdline = "-C " + channel.block + " -S -B " + (channel.freq < 1000000 ? "BAND_III" : "L_BAND"); if(channel.HasAutoGain()) cmdline += " -Q"; else cmdline += " -G " + std::to_string(channel.gain); return cmdline; } dablin-1.8.0/src/eti_source.h000066400000000000000000000073661324402060700160640ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef ETI_SOURCE_H_ #define ETI_SOURCE_H_ // support 2GB+ files on 32bit systems #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include #include struct ETI_PROGRESS { double value; std::string text; }; struct DAB_LIVE_SOURCE_CHANNEL { std::string block; uint32_t freq; int gain; static const int auto_gain = -10000; bool HasAutoGain() const {return gain == auto_gain;} std::string GainToString() {return HasAutoGain() ? "auto" : std::to_string(gain);} DAB_LIVE_SOURCE_CHANNEL() : freq(-1), gain(auto_gain) {} DAB_LIVE_SOURCE_CHANNEL(std::string block, uint32_t freq, int gain) : block(block), freq(freq), gain(gain) {} bool operator<(const DAB_LIVE_SOURCE_CHANNEL & ch) const { return freq < ch.freq; } }; // --- ETISourceObserver ----------------------------------------------------------------- class ETISourceObserver { public: virtual ~ETISourceObserver() {}; virtual void ETIProcessFrame(const uint8_t* /*data*/) {}; virtual void ETIUpdateProgress(const ETI_PROGRESS /*progress*/) {}; }; // --- ETISource ----------------------------------------------------------------- class ETISource { protected: std::string filename; ETISourceObserver *observer; std::atomic do_exit; FILE *input_file; uint8_t eti_frame[6144]; size_t eti_frame_count; size_t eti_frame_total; unsigned long int eti_progress_next_ms; bool OpenFile(); bool UpdateTotalFrames(); virtual void Init() {} virtual void PrintSource(); static std::string FramecountToTimecode(size_t value); public: ETISource(std::string filename, ETISourceObserver *observer); virtual ~ETISource(); int Main(); void DoExit() {do_exit = true;} }; // --- DABLiveETISource ----------------------------------------------------------------- class DABLiveETISource : public ETISource { protected: DAB_LIVE_SOURCE_CHANNEL channel; std::string binary; std::string binary_name; std::string source_name; void Init(); void PrintSource(); virtual std::string GetParams() = 0; public: DABLiveETISource(std::string binary, DAB_LIVE_SOURCE_CHANNEL channel, ETISourceObserver *observer, std::string source_name); ~DABLiveETISource(); static const std::string TYPE_DAB2ETI; static const std::string TYPE_ETI_CMDLINE; }; // --- DAB2ETIETISource ----------------------------------------------------------------- class DAB2ETIETISource : public DABLiveETISource { protected: std::string GetParams(); public: DAB2ETIETISource(std::string binary, DAB_LIVE_SOURCE_CHANNEL channel, ETISourceObserver *observer) : DABLiveETISource(binary, channel, observer, "dab2eti") {} }; // --- EtiCmdlineETISource ----------------------------------------------------------------- class EtiCmdlineETISource : public DABLiveETISource { protected: std::string GetParams(); public: EtiCmdlineETISource(std::string binary, DAB_LIVE_SOURCE_CHANNEL channel, ETISourceObserver *observer) : DABLiveETISource(binary, channel, observer, "eti-cmdline") {} }; #endif /* ETI_SOURCE_H_ */ dablin-1.8.0/src/fic_decoder.cpp000066400000000000000000000552431324402060700165010ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "fic_decoder.h" // --- FICDecoder ----------------------------------------------------------------- void FICDecoder::Reset() { ensemble = FIC_ENSEMBLE(); services.clear(); subchannels.clear(); } void FICDecoder::Process(const uint8_t *data, size_t len) { // check for integer FIB count if(len % 32) { fprintf(stderr, "FICDecoder: Ignoring non-integer FIB count FIC data with %zu bytes\n", len); return; } for(size_t i = 0; i < len; i += 32) ProcessFIB(data + i); } void FICDecoder::ProcessFIB(const uint8_t *data) { // check CRC uint16_t crc_stored = data[30] << 8 | data[31]; uint16_t crc_calced = CalcCRC::CalcCRC_CRC16_CCITT.Calc(data, 30); if(crc_stored != crc_calced) { fprintf(stderr, "\x1B[33m" "(FIB)" "\x1B[0m" " "); return; } // iterate over all FIGs for(size_t offset = 0; offset < 30 && data[offset] != 0xFF;) { int type = data[offset] >> 5; size_t len = data[offset] & 0x1F; offset++; switch(type) { case 0: ProcessFIG0(data + offset, len); break; case 1: ProcessFIG1(data + offset, len); break; // default: // fprintf(stderr, "FICDecoder: received unsupported FIG %d with %zu bytes\n", type, len); } offset += len; } } void FICDecoder::ProcessFIG0(const uint8_t *data, size_t len) { if(len < 1) { fprintf(stderr, "FICDecoder: received empty FIG 0\n"); return; } // read/skip FIG 0 header FIG0_HEADER header(data[0]); data++; len--; // ignore next config/other ensembles/data services if(header.cn || header.oe || header.pd) return; // handle extension switch(header.extension) { case 1: ProcessFIG0_1(data, len); break; case 2: ProcessFIG0_2(data, len); break; case 5: ProcessFIG0_5(data, len); break; case 8: ProcessFIG0_8(data, len); break; case 13: ProcessFIG0_13(data, len); break; // default: // fprintf(stderr, "FICDecoder: received unsupported FIG 0/%d with %zu field bytes\n", header.extension, len); } } void FICDecoder::ProcessFIG0_1(const uint8_t *data, size_t len) { // FIG 0/1 - Basic sub-channel organization // iterate through all sub-channels for(size_t offset = 0; offset < len;) { int subchid = data[offset] >> 2; size_t start_address = (data[offset] & 0x03) << 8 | data[offset + 1]; offset += 2; FIC_SUBCHANNEL sc; sc.start = start_address; bool short_long_form = data[offset] & 0x80; if(short_long_form) { // long form int option = (data[offset] & 0x70) >> 4; int pl = (data[offset] & 0x0C) >> 2; size_t subch_size = (data[offset] & 0x03) << 8 | data[offset + 1]; switch(option) { case 0b000: sc.size = subch_size; sc.pl = "EEP " + std::to_string(pl + 1) + "-A"; sc.bitrate = subch_size / eep_a_size_factors[pl] * 8; break; case 0b001: sc.size = subch_size; sc.pl = "EEP " + std::to_string(pl + 1) + "-B"; sc.bitrate = subch_size / eep_b_size_factors[pl] * 32; break; } offset += 2; } else { // short form bool table_switch = data[offset] & 0x40; if(!table_switch) { int table_index = data[offset] & 0x3F; sc.size = uep_sizes[table_index]; sc.pl = "UEP " + std::to_string(uep_pls[table_index]); sc.bitrate = uep_bitrates[table_index]; } offset++; } if(!sc.IsNone()) { FIC_SUBCHANNEL& current_sc = GetSubchannel(subchid); sc.language = current_sc.language; // ignored for comparison if(current_sc != sc) { current_sc = sc; fprintf(stderr, "FICDecoder: SubChId %2d: start %3zu CUs, size %3zu CUs, PL %-7s = %3d kBit/s\n", subchid, sc.start, sc.size, sc.pl.c_str(), sc.bitrate); UpdateSubchannel(subchid); } } } } void FICDecoder::ProcessFIG0_2(const uint8_t *data, size_t len) { // FIG 0/2 - Basic service and service component definition // programme services only // iterate through all services for(size_t offset = 0; offset < len;) { uint16_t sid = data[offset] << 8 | data[offset + 1]; offset += 2; size_t num_service_comps = data[offset++] & 0x0F; // iterate through all service components for(size_t comp = 0; comp < num_service_comps; comp++) { int tmid = data[offset] >> 6; switch(tmid) { case 0b00: // MSC stream audio int ascty = data[offset] & 0x3F; int subchid = data[offset + 1] >> 2; bool ps = data[offset + 1] & 0x02; bool ca = data[offset + 1] & 0x01; if(!ca) { switch(ascty) { case 0: // DAB case 63: // DAB+ bool dab_plus = ascty == 63; AUDIO_SERVICE audio_service(subchid, dab_plus); FIC_SERVICE& service = GetService(sid); AUDIO_SERVICE& current_audio_service = service.audio_comps[subchid]; if(current_audio_service != audio_service || ps != (service.pri_comp_subchid == subchid)) { current_audio_service = audio_service; if(ps) service.pri_comp_subchid = subchid; fprintf(stderr, "FICDecoder: SId 0x%04X: audio service (SubChId %2d, %-4s, %s)\n", sid, subchid, dab_plus ? "DAB+" : "DAB", ps ? "primary" : "secondary"); UpdateService(service); } break; } } } offset += 2; } } } void FICDecoder::ProcessFIG0_5(const uint8_t *data, size_t len) { // FIG 0/5 - Service component language // programme services only // iterate through all components for(size_t offset = 0; offset < len;) { bool ls_flag = data[offset] & 0x80; if(ls_flag) { // long form - skipped, as not relevant offset += 3; } else { // short form bool msc_fic_flag = data[offset] & 0x40; // handle only MSC components if(!msc_fic_flag) { int subchid = data[offset] & 0x3F; int language = data[offset + 1]; FIC_SUBCHANNEL& current_sc = GetSubchannel(subchid); if(current_sc.language != language) { current_sc.language = language; fprintf(stderr, "FICDecoder: SubChId %2d: language '%s'\n", subchid, ConvertLanguageToString(language).c_str()); UpdateSubchannel(subchid); } } offset += 2; } } } void FICDecoder::ProcessFIG0_8(const uint8_t *data, size_t len) { // FIG 0/8 - Service component global definition // programme services only // iterate through all service components for(size_t offset = 0; offset < len;) { uint16_t sid = data[offset] << 8 | data[offset + 1]; offset += 2; bool ext_flag = data[offset] & 0x80; int scids = data[offset] & 0x0F; offset++; bool ls_flag = data[offset] & 0x80; if(ls_flag) { // long form - skipped, as not relevant offset += 2; } else { // short form bool msc_fic_flag = data[offset] & 0x40; // handle only MSC components if(!msc_fic_flag) { int subchid = data[offset] & 0x3F; FIC_SERVICE& service = GetService(sid); bool new_comp = service.comp_defs.find(scids) == service.comp_defs.end(); int& current_subchid = service.comp_defs[scids]; if(new_comp || current_subchid != subchid) { current_subchid = subchid; fprintf(stderr, "FICDecoder: SId 0x%04X, SCIdS %2d: MSC service component (SubChId %2d)\n", sid, scids, subchid); UpdateService(service); } } offset++; } // skip Rfa field, if needed if(ext_flag) offset++; } } void FICDecoder::ProcessFIG0_13(const uint8_t *data, size_t len) { // FIG 0/13 - User application information // programme services only // iterate through all service components for(size_t offset = 0; offset < len;) { uint16_t sid = data[offset] << 8 | data[offset + 1]; offset += 2; int scids = data[offset] >> 4; size_t num_scids_uas = data[offset] & 0x0F; offset++; // iterate through all user applications for(size_t scids_ua = 0; scids_ua < num_scids_uas; scids_ua++) { int ua_type = data[offset] << 3 | data[offset + 1] >> 5; size_t ua_data_length = data[offset + 1] & 0x1F; offset += 2; // handle only Slideshow if(ua_type == 0x002) { FIC_SERVICE& service = GetService(sid); if(service.comp_sls_uas.find(scids) == service.comp_sls_uas.end()) { ua_data_t& sls_ua_data = service.comp_sls_uas[scids]; sls_ua_data.resize(ua_data_length); if(ua_data_length) memcpy(&sls_ua_data[0], data + offset, ua_data_length); fprintf(stderr, "FICDecoder: SId 0x%04X, SCIdS %2d: Slideshow (%zu bytes UA data)\n", sid, scids, ua_data_length); UpdateService(service); } } offset += ua_data_length; } } } void FICDecoder::ProcessFIG1(const uint8_t *data, size_t len) { if(len < 1) { fprintf(stderr, "FICDecoder: received empty FIG 1\n"); return; } // read/skip FIG 1 header FIG1_HEADER header(data[0]); data++; len--; // ignore other ensembles if(header.oe) return; // check for (un)supported extension + set ID field len size_t len_id = -1; switch(header.extension) { case 0: // ensemble case 1: // programme service len_id = 2; break; case 4: // service component // programme services only (P/D = 0) if(data[0] & 0x80) return; len_id = 3; break; default: // fprintf(stderr, "FICDecoder: received unsupported FIG 1/%d with %zu field bytes\n", header.extension, len); return; } // check length size_t len_calced = len_id + 16 + 2; if(len != len_calced) { fprintf(stderr, "FICDecoder: received FIG 1/%d having %zu field bytes (expected: %zu)\n", header.extension, len, len_calced); return; } // parse actual label data FIC_LABEL label; label.charset = header.charset; memcpy(label.label, data + len_id, 16); label.short_label_mask = data[len_id + 16] << 8 | data[len_id + 17]; // handle extension switch(header.extension) { case 0: { // ensemble uint16_t eid = data[0] << 8 | data[1]; ProcessFIG1_0(eid, label); break; } case 1: { // programme service uint16_t sid = data[0] << 8 | data[1]; ProcessFIG1_1(sid, label); break; } case 4: { // service component int scids = data[0] & 0x0F; uint16_t sid = data[1] << 8 | data[2]; ProcessFIG1_4(sid, scids, label); break; } } } void FICDecoder::ProcessFIG1_0(uint16_t eid, const FIC_LABEL& label) { if(ensemble.eid != eid || ensemble.label != label) { ensemble.eid = eid; ensemble.label = label; std::string label_str = ConvertLabelToUTF8(label); fprintf(stderr, "FICDecoder: EId 0x%04X: ensemble label '%s'\n", eid, label_str.c_str()); observer->FICChangeEnsemble(ensemble); } } void FICDecoder::ProcessFIG1_1(uint16_t sid, const FIC_LABEL& label) { FIC_SERVICE& service = GetService(sid); if(service.label != label) { service.label = label; std::string label_str = ConvertLabelToUTF8(label); fprintf(stderr, "FICDecoder: SId 0x%04X: programme service label '%s'\n", sid, label_str.c_str()); UpdateService(service); } } void FICDecoder::ProcessFIG1_4(uint16_t sid, int scids, const FIC_LABEL& label) { // programme services only FIC_SERVICE& service = GetService(sid); FIC_LABEL& comp_label = service.comp_labels[scids]; if(comp_label != label) { comp_label = label; std::string label_str = ConvertLabelToUTF8(label); fprintf(stderr, "FICDecoder: SId 0x%04X, SCIdS %2d: service component label '%s'\n", sid, scids, label_str.c_str()); UpdateService(service); } } FIC_SUBCHANNEL& FICDecoder::GetSubchannel(int subchid) { // created automatically, if not yet existing return subchannels[subchid]; } void FICDecoder::UpdateSubchannel(int subchid) { // update services that consist of this sub-channel for(fic_services_t::const_iterator it = services.cbegin(); it != services.cend(); it++) { const FIC_SERVICE& s = it->second; if(s.audio_comps.find(subchid) != s.audio_comps.end()) UpdateService(s); } } FIC_SERVICE& FICDecoder::GetService(uint16_t sid) { FIC_SERVICE& result = services[sid]; // created, if not yet existing // if new service, set SID if(result.IsNone()) result.sid = sid; return result; } void FICDecoder::UpdateService(const FIC_SERVICE& service) { // abort update, if primary component or label not yet present if(service.HasNoPriCompSubchid() || service.label.IsNone()) return; // secondary components (if both component and definition are present) bool multi_comps = false; for(comp_defs_t::const_iterator it = service.comp_defs.cbegin(); it != service.comp_defs.cend(); it++) { if(it->second == service.pri_comp_subchid || service.audio_comps.find(it->second) == service.audio_comps.end()) continue; UpdateListedService(service, it->first, true); multi_comps = true; } // primary component UpdateListedService(service, LISTED_SERVICE::scids_none, multi_comps); } void FICDecoder::UpdateListedService(const FIC_SERVICE& service, int scids, bool multi_comps) { // assemble listed service LISTED_SERVICE ls; ls.sid = service.sid; ls.scids = scids; ls.label = service.label; ls.pri_comp_subchid = service.pri_comp_subchid; ls.multi_comps = multi_comps; if(scids == LISTED_SERVICE::scids_none) { // primary component ls.audio_service = service.audio_comps.at(service.pri_comp_subchid); } else { // secondary component ls.audio_service = service.audio_comps.at(service.comp_defs.at(scids)); // use component label, if available comp_labels_t::const_iterator cl_it = service.comp_labels.find(scids); if(cl_it != service.comp_labels.end()) ls.label = cl_it->second; } // use sub-channel information, if available fic_subchannels_t::const_iterator sc_it = subchannels.find(ls.audio_service.subchid); if(sc_it != subchannels.end()) ls.subchannel = sc_it->second; /* check (for) Slideshow; currently only supported in X-PAD * - derive the required SCIdS (if not yet known) * - derive app type from UA data (if present) */ int sls_scids = scids; if(sls_scids == LISTED_SERVICE::scids_none) { for(comp_defs_t::const_iterator it = service.comp_defs.cbegin(); it != service.comp_defs.cend(); it++) { if(it->second == ls.audio_service.subchid) { sls_scids = it->first; break; } } } if(sls_scids != LISTED_SERVICE::scids_none && service.comp_sls_uas.find(sls_scids) != service.comp_sls_uas.end()) ls.sls_app_type = GetSLSAppType(service.comp_sls_uas.at(sls_scids)); // forward to observer observer->FICChangeService(ls); } int FICDecoder::GetSLSAppType(const ua_data_t& ua_data) { // default values, if no UA data present bool ca_flag = false; int xpad_app_type = 12; bool dg_flag = false; int dscty = 60; // MOT // if UA data present, parse X-PAD data if(ua_data.size() >= 2) { ca_flag = ua_data[0] & 0x80; xpad_app_type = ua_data[0] & 0x1F; dg_flag = ua_data[1] & 0x80; dscty = ua_data[1] & 0x3F; } // if no CA is used, but DGs and MOT, enable Slideshow if(!ca_flag && !dg_flag && dscty == 60) return xpad_app_type; else return LISTED_SERVICE::sls_app_type_none; } std::string FICDecoder::ConvertLabelToUTF8(const FIC_LABEL& label) { std::string result = ConvertTextToUTF8(label.label, sizeof(label.label), label.charset, false, nullptr); // discard trailing spaces size_t last_pos = result.find_last_not_of(' '); if(last_pos != std::string::npos) result.resize(last_pos + 1); return result; } std::string FICDecoder::ConvertTextToUTF8(const uint8_t *data, size_t len, int charset, bool mot, std::string* charset_name) { // remove undesired chars std::vector cleaned_data; for(size_t i = 0; i < len; i++) { switch(data[i]) { case 0x00: // NULL case 0x0A: // PLB case 0x0B: // EoH case 0x1F: // PWB continue; default: cleaned_data.push_back(data[i]); } } // convert characters if(charset == 0b0000) { // EBU Latin based if(charset_name) *charset_name = "EBU Latin based"; std::string result; for(size_t i = 0; i < cleaned_data.size(); i++) result += ConvertCharEBUToUTF8(cleaned_data[i]); return result; } if(charset == 0b0100 && mot) // ISO/IEC-8859-1 (MOT only) return ConvertStringIconvToUTF8(cleaned_data, charset_name, "ISO-8859-1"); if(charset == 0b0110 && !mot) // UCS-2 BE (DAB only) return ConvertStringIconvToUTF8(cleaned_data, charset_name, "UCS-2BE"); if(charset == 0b1111) { // UTF-8 if(charset_name) *charset_name = "UTF-8"; return std::string((char*) &cleaned_data[0], cleaned_data.size()); } // ignore unsupported charset fprintf(stderr, "FICDecoder: The %s charset %d is not supported; ignoring!\n", mot ? "MOT" : "DAB", charset); return ""; } std::string FICDecoder::ConvertStringIconvToUTF8(const std::vector& cleaned_data, std::string* charset_name, const std::string& src_charset) { // prepare iconv_t conv = iconv_open("UTF-8", src_charset.c_str()); if(conv == (iconv_t) -1) { perror("FICDecoder: error while iconv_open"); return ""; } size_t input_len = cleaned_data.size(); char input_bytes[input_len]; char* input = input_bytes; memcpy(input_bytes, &cleaned_data[0], cleaned_data.size()); size_t output_len = input_len * 4; // theoretical worst case size_t output_len_orig = output_len; char output_bytes[output_len]; char* output = output_bytes; // convert size_t count = iconv(conv, &input, &input_len, &output, &output_len); if(count == (size_t) -1) { perror("FICDecoder: error while iconv"); return ""; } if(input_len) { fprintf(stderr, "FICDecoder: Could not convert all chars to %s!\n", src_charset.c_str()); return ""; } if(iconv_close(conv)) { perror("FICDecoder: error while iconv_close"); return ""; } if(charset_name) *charset_name = src_charset; return std::string(output_bytes, output_len_orig - output_len); } const char* FICDecoder::no_char = ""; const char* FICDecoder::ebu_values_0x00_to_0x1F[] = { no_char , "\u0118", "\u012E", "\u0172", "\u0102", "\u0116", "\u010E", "\u0218", "\u021A", "\u010A", no_char , no_char , "\u0120", "\u0139" , "\u017B", "\u0143", "\u0105", "\u0119", "\u012F", "\u0173", "\u0103", "\u0117", "\u010F", "\u0219", "\u021B", "\u010B", "\u0147", "\u011A", "\u0121", "\u013A", "\u017C", no_char }; const char* FICDecoder::ebu_values_0x7B_to_0xFF[] = { /* starting some chars earlier than 0x80 -----> */ "\u00AB", "\u016F", "\u00BB", "\u013D", "\u0126", "\u00E1", "\u00E0", "\u00E9", "\u00E8", "\u00ED", "\u00EC", "\u00F3", "\u00F2", "\u00FA", "\u00F9", "\u00D1", "\u00C7", "\u015E", "\u00DF", "\u00A1", "\u0178", "\u00E2", "\u00E4", "\u00EA", "\u00EB", "\u00EE", "\u00EF", "\u00F4", "\u00F6", "\u00FB", "\u00FC", "\u00F1", "\u00E7", "\u015F", "\u011F", "\u0131", "\u00FF", "\u0136", "\u0145", "\u00A9", "\u0122", "\u011E", "\u011B", "\u0148", "\u0151", "\u0150", "\u20AC", "\u00A3", "\u0024", "\u0100", "\u0112", "\u012A", "\u016A", "\u0137", "\u0146", "\u013B", "\u0123", "\u013C", "\u0130", "\u0144", "\u0171", "\u0170", "\u00BF", "\u013E", "\u00B0", "\u0101", "\u0113", "\u012B", "\u016B", "\u00C1", "\u00C0", "\u00C9", "\u00C8", "\u00CD", "\u00CC", "\u00D3", "\u00D2", "\u00DA", "\u00D9", "\u0158", "\u010C", "\u0160", "\u017D", "\u00D0", "\u013F", "\u00C2", "\u00C4", "\u00CA", "\u00CB", "\u00CE", "\u00CF", "\u00D4", "\u00D6", "\u00DB", "\u00DC", "\u0159", "\u010D", "\u0161", "\u017E", "\u0111", "\u0140", "\u00C3", "\u00C5", "\u00C6", "\u0152", "\u0177", "\u00DD", "\u00D5", "\u00D8", "\u00DE", "\u014A", "\u0154", "\u0106", "\u015A", "\u0179", "\u0164", "\u00F0", "\u00E3", "\u00E5", "\u00E6", "\u0153", "\u0175", "\u00FD", "\u00F5", "\u00F8", "\u00FE", "\u014B", "\u0155", "\u0107", "\u015B", "\u017A", "\u0165", "\u0127" }; const size_t FICDecoder::uep_sizes[] = { 16, 21, 24, 29, 35, 24, 29, 35, 42, 52, 29, 35, 42, 52, 32, 42, 48, 58, 70, 40, 52, 58, 70, 84, 48, 58, 70, 84, 104, 58, 70, 84, 104, 64, 84, 96, 116, 140, 80, 104, 116, 140, 168, 96, 116, 140, 168, 208, 116, 140, 168, 208, 232, 128, 168, 192, 232, 280, 160, 208, 280, 192, 280, 416 }; const int FICDecoder::uep_pls[] = { 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 2, 5, 3, 1 }; const int FICDecoder::uep_bitrates[] = { 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 56, 56, 56, 56, 64, 64, 64, 64, 64, 80, 80, 80, 80, 80, 96, 96, 96, 96, 96, 112, 112, 112, 112, 128, 128, 128, 128, 128, 160, 160, 160, 160, 160, 192, 192, 192, 192, 192, 224, 224, 224, 224, 224, 256, 256, 256, 256, 256, 320, 320, 320, 384, 384, 384 }; const int FICDecoder::eep_a_size_factors[] = {12, 8, 6, 4}; const int FICDecoder::eep_b_size_factors[] = {27, 21, 18, 15}; const char* FICDecoder::languages_0x00_to_0x2B[] = { "unknown/not applicable", "Albanian", "Breton", "Catalan", "Croatian", "Welsh", "Czech", "Danish", "German", "English", "Spanish", "Esperanto", "Estonian", "Basque", "Faroese", "French", "Frisian", "Irish", "Gaelic", "Galician", "Icelandic", "Italian", "Sami", "Latin", "Latvian", "Luxembourgian", "Lithuanian", "Hungarian", "Maltese", "Dutch", "Norwegian", "Occitan", "Polish", "Portuguese", "Romanian", "Romansh", "Serbian", "Slovak", "Slovene", "Finnish", "Swedish", "Turkish", "Flemish", "Walloon" }; const char* FICDecoder::languages_0x7F_downto_0x45[] = { "Amharic", "Arabic", "Armenian", "Assamese", "Azerbaijani", "Bambora", "Belorussian", "Bengali", "Bulgarian", "Burmese", "Chinese", "Chuvash", "Dari", "Fulani", "Georgian", "Greek", "Gujurati", "Gurani", "Hausa", "Hebrew", "Hindi", "Indonesian", "Japanese", "Kannada", "Kazakh", "Khmer", "Korean", "Laotian", "Macedonian", "Malagasay", "Malaysian", "Moldavian", "Marathi", "Ndebele", "Nepali", "Oriya", "Papiamento", "Persian", "Punjabi", "Pushtu", "Quechua", "Russian", "Rusyn", "Serbo-Croat", "Shona", "Sinhalese", "Somali", "Sranan Tongo", "Swahili", "Tadzhik", "Tamil", "Tatar", "Telugu", "Thai", "Ukranian", "Urdu", "Uzbek", "Vietnamese", "Zulu" }; std::string FICDecoder::ConvertCharEBUToUTF8(const uint8_t value) { // convert via LUT if(value <= 0x1F) return ebu_values_0x00_to_0x1F[value]; if(value >= 0x7B) return ebu_values_0x7B_to_0xFF[value - 0x7B]; // convert by hand (avoiding a LUT with mostly 1:1 mapping) switch(value) { case 0x24: return "\u0142"; case 0x5C: return "\u016E"; case 0x5E: return "\u0141"; case 0x60: return "\u0104"; } // leave untouched return std::string((char*) &value, 1); } std::string FICDecoder::ConvertLanguageToString(const int value) { if(value >= 0x00 && value <= 0x2B) return languages_0x00_to_0x2B[value]; if(value == 0x40) return "background sound/clean feed"; if(value >= 0x45 && value <= 0x7F) return languages_0x7F_downto_0x45[0x7F - value]; return "unknown (" + std::to_string(value) + ")"; } dablin-1.8.0/src/fic_decoder.h000066400000000000000000000161721324402060700161440ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef FIC_DECODER_H_ #define FIC_DECODER_H_ #include #include #include #include #include #include #include #include "tools.h" struct FIG0_HEADER { bool cn; bool oe; bool pd; int extension; FIG0_HEADER(uint8_t data) : cn(data & 0x80), oe(data & 0x40), pd(data & 0x20), extension(data & 0x1F) {} }; struct FIG1_HEADER { int charset; bool oe; int extension; FIG1_HEADER(uint8_t data) : charset(data >> 4), oe(data & 0x08), extension(data & 0x07) {} }; struct FIC_LABEL { int charset; uint8_t label[16]; uint16_t short_label_mask; static const int charset_none = -1; bool IsNone() const {return charset == charset_none;} FIC_LABEL() : charset(charset_none), short_label_mask(0x0000) { memset(label, 0x00, sizeof(label)); } bool operator==(const FIC_LABEL & fic_label) const { return charset == fic_label.charset && !memcmp(label, fic_label.label, sizeof(label)) && short_label_mask == fic_label.short_label_mask; } bool operator!=(const FIC_LABEL & fic_label) const { return !(*this == fic_label); } }; struct FIC_SUBCHANNEL { size_t start; size_t size; std::string pl; int bitrate; int language; static const int language_none = -1; bool IsNone() const {return pl.empty() && language == language_none;} FIC_SUBCHANNEL() : start(0), size(0), bitrate(-1), language(language_none) {} bool operator==(const FIC_SUBCHANNEL & fic_subchannel) const { return start == fic_subchannel.start && size == fic_subchannel.size && pl == fic_subchannel.pl && bitrate == fic_subchannel.bitrate && language == fic_subchannel.language; } bool operator!=(const FIC_SUBCHANNEL & fic_subchannel) const { return !(*this == fic_subchannel); } }; struct FIC_ENSEMBLE { int eid; FIC_LABEL label; static const int eid_none = -1; bool IsNone() const {return eid == eid_none;} FIC_ENSEMBLE() : eid(eid_none) {} bool operator==(const FIC_ENSEMBLE & ensemble) const { return eid == ensemble.eid && label == ensemble.label; } bool operator!=(const FIC_ENSEMBLE & ensemble) const { return !(*this == ensemble); } }; typedef std::map audio_comps_t; typedef std::map comp_defs_t; typedef std::map comp_labels_t; typedef std::vector ua_data_t; typedef std::map comp_sls_uas_t; struct FIC_SERVICE { int sid; int pri_comp_subchid; FIC_LABEL label; // components audio_comps_t audio_comps; // from FIG 0/2 : SubChId -> AUDIO_SERVICE comp_defs_t comp_defs; // from FIG 0/8 : SCIdS -> SubChId comp_labels_t comp_labels; // from FIG 1/4 : SCIdS -> FIC_LABEL comp_sls_uas_t comp_sls_uas; // from FIG 0/13: SCIdS -> UA data static const int sid_none = -1; bool IsNone() const {return sid == sid_none;} static const int pri_comp_subchid_none = -1; bool HasNoPriCompSubchid() const {return pri_comp_subchid == pri_comp_subchid_none;} FIC_SERVICE() : sid(sid_none), pri_comp_subchid(pri_comp_subchid_none) {} }; struct LISTED_SERVICE { int sid; int scids; FIC_SUBCHANNEL subchannel; AUDIO_SERVICE audio_service; FIC_LABEL label; int sls_app_type; int pri_comp_subchid; // only used for sorting bool multi_comps; static const int sid_none = -1; bool IsNone() const {return sid == sid_none;} static const int scids_none = -1; bool IsPrimary() const {return scids == scids_none;} static const int sls_app_type_none = -1; bool HasSLS() const {return sls_app_type != sls_app_type_none;} LISTED_SERVICE() : sid(sid_none), scids(scids_none), sls_app_type(sls_app_type_none), pri_comp_subchid(AUDIO_SERVICE::subchid_none), multi_comps(false) {} bool operator<(const LISTED_SERVICE & service) const { if(pri_comp_subchid != service.pri_comp_subchid) return pri_comp_subchid < service.pri_comp_subchid; if(sid != service.sid) return sid < service.sid; return scids < service.scids; } }; typedef std::map fic_services_t; typedef std::map fic_subchannels_t; // --- FICDecoderObserver ----------------------------------------------------------------- class FICDecoderObserver { public: virtual ~FICDecoderObserver() {}; virtual void FICChangeEnsemble(const FIC_ENSEMBLE& /*ensemble*/) {}; virtual void FICChangeService(const LISTED_SERVICE& /*service*/) {}; }; // --- FICDecoder ----------------------------------------------------------------- class FICDecoder { private: FICDecoderObserver *observer; void ProcessFIB(const uint8_t *data); void ProcessFIG0(const uint8_t *data, size_t len); void ProcessFIG0_1(const uint8_t *data, size_t len); void ProcessFIG0_2(const uint8_t *data, size_t len); void ProcessFIG0_5(const uint8_t *data, size_t len); void ProcessFIG0_8(const uint8_t *data, size_t len); void ProcessFIG0_13(const uint8_t *data, size_t len); void ProcessFIG1(const uint8_t *data, size_t len); void ProcessFIG1_0(uint16_t eid, const FIC_LABEL& label); void ProcessFIG1_1(uint16_t sid, const FIC_LABEL& label); void ProcessFIG1_4(uint16_t sid, int scids, const FIC_LABEL& label); FIC_SUBCHANNEL& GetSubchannel(int subchid); void UpdateSubchannel(int subchid); FIC_SERVICE& GetService(uint16_t sid); void UpdateService(const FIC_SERVICE& service); void UpdateListedService(const FIC_SERVICE& service, int scids, bool multi_comps); int GetSLSAppType(const ua_data_t& ua_data); FIC_ENSEMBLE ensemble; fic_services_t services; fic_subchannels_t subchannels; // from FIG 0/1: SubChId -> FIC_SUBCHANNEL static const char* no_char; static const char* ebu_values_0x00_to_0x1F[]; static const char* ebu_values_0x7B_to_0xFF[]; static std::string ConvertCharEBUToUTF8(const uint8_t value); static std::string ConvertStringIconvToUTF8(const std::vector& cleaned_data, std::string* charset_name, const std::string& src_charset); static const size_t uep_sizes[]; static const int uep_pls[]; static const int uep_bitrates[]; static const int eep_a_size_factors[]; static const int eep_b_size_factors[]; static const char* languages_0x00_to_0x2B[]; static const char* languages_0x7F_downto_0x45[]; public: FICDecoder(FICDecoderObserver *observer) : observer(observer) {} void Process(const uint8_t *data, size_t len); void Reset(); static std::string ConvertTextToUTF8(const uint8_t *data, size_t len, int charset, bool mot, std::string* charset_name); static std::string ConvertLabelToUTF8(const FIC_LABEL& label); static std::string ConvertLanguageToString(const int value); }; #endif /* FIC_DECODER_H_ */ dablin-1.8.0/src/mot_manager.cpp000066400000000000000000000207711324402060700165420ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2016-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "mot_manager.h" // --- MOTEntity ----------------------------------------------------------------- void MOTEntity::AddSeg(int seg_number, bool last_seg, const uint8_t* data, size_t len) { if(last_seg) last_seg_number = seg_number; if(segs.find(seg_number) != segs.end()) return; // copy data segs[seg_number] = seg_t(len); memcpy(&segs[seg_number][0], data, len); size += len; } bool MOTEntity::IsFinished() { if(last_seg_number == -1) return false; // check if all segments are available for(int i = 0; i <= last_seg_number; i++) if(segs.find(i) == segs.end()) return false; return true; } std::vector MOTEntity::GetData() { std::vector result(size); size_t offset = 0; // concatenate all segments for(int i = 0; i <= last_seg_number; i++) { seg_t& seg = segs[i]; memcpy(&result[offset], &seg[0], seg.size()); offset += seg.size(); } return result; } // --- MOTObject ----------------------------------------------------------------- void MOTObject::AddSeg(bool dg_type_header, int seg_number, bool last_seg, const uint8_t* data, size_t len) { (dg_type_header ? header : body).AddSeg(seg_number, last_seg, data, len); } bool MOTObject::ParseCheckHeader(MOT_FILE& target_file) { MOT_FILE file = target_file; std::vector data = header.GetData(); // parse/check header core if(data.size() < 7) return false; size_t body_size = (data[0] << 20) | (data[1] << 12) | (data[2] << 4) | (data[3] >> 4); size_t header_size = ((data[3] & 0x0F) << 9) | (data[4] << 1) | (data[5] >> 7); int content_type = (data[5] & 0x7F) >> 1; int content_sub_type = ((data[5] & 0x01) << 8) | data[6]; // fprintf(stderr, "body_size: %5zu, header_size: %3zu, content_type: 0x%02X, content_sub_type: 0x%03X\n", // body_size, header_size, content_type, content_sub_type); if(header_size != header.GetSize()) return false; bool header_update = content_type == MOT_FILE::CONTENT_TYPE_MOT_TRANSPORT && content_sub_type == MOT_FILE::CONTENT_SUB_TYPE_HEADER_UPDATE; // abort, if neither none nor both conditions (header received/update) apply if(header_received != header_update) return false; if(!header_update) { // store core info file.body_size = body_size; file.content_type = content_type; file.content_sub_type = content_sub_type; } std::string old_content_name = file.content_name; std::string new_content_name; // parse/check header extension for(size_t offset = 7; offset < data.size();) { int pli = data[offset] >> 6; int param_id = data[offset] & 0x3F; offset++; // get parameter len size_t data_len; switch(pli) { case 0b00: data_len = 0; break; case 0b01: data_len = 1; break; case 0b10: data_len = 4; break; case 0b11: if(offset >= data.size()) return false; bool ext = data[offset] & 0x80; data_len = data[offset] & 0x7F; offset++; if(ext) { if(offset >= data.size()) return false; data_len = (data_len << 8) + data[offset]; offset++; } break; } if(offset + data_len - 1 >= data.size()) return false; // process parameter switch(param_id) { case 0x05: // TriggerTime if(data_len < 4) return false; // TODO: not only distinguish between Now or not file.trigger_time_now = !(data[offset] & 0x80); // fprintf(stderr, "TriggerTime: %s\n", file.trigger_time_now ? "Now" : "(not Now)"); break; case 0x0C: // ContentName if(data_len == 0) return false; file.content_name = FICDecoder::ConvertTextToUTF8(&data[offset + 1], data_len - 1, data[offset] >> 4, true, nullptr); new_content_name = file.content_name; // fprintf(stderr, "ContentName: '%s'\n", file.content_name.c_str()); break; case 0x26: // CategoryTitle file.category_title = std::string((char*) &data[offset], data_len); // already UTF-8 // fprintf(stderr, "CategoryTitle: '%s'\n", file.category_title.c_str()); break; case 0x27: // ClickThroughURL file.click_through_url = std::string((char*) &data[offset], data_len); // already UTF-8 // fprintf(stderr, "ClickThroughURL: '%s'\n", file.click_through_url.c_str()); break; } offset += data_len; } if(!header_update) { // ensure actual header is processed only once header_received = true; } else { // ensure matching content name if(new_content_name != old_content_name) return false; } target_file = file; return true; } bool MOTObject::IsToBeShown() { // abort, if already shown if(shown) return false; // try to process finished header if(header.IsFinished()) { // parse/check MOT header bool result = ParseCheckHeader(result_file); header.Reset(); // allow for header updates if(!result) return false; } // abort, if incomplete/not yet triggered if(!header_received) return false; if(!body.IsFinished() || result_file.body_size != body.GetSize()) return false; if(!result_file.trigger_time_now) return false; // add body data result_file.data = body.GetData(); shown = true; return true; } // --- MOTManager ----------------------------------------------------------------- MOTManager::MOTManager() { Reset(); } void MOTManager::Reset() { object = MOTObject(); current_transport_id = -1; } bool MOTManager::ParseCheckDataGroupHeader(const std::vector& dg, size_t& offset, int& dg_type) { // parse/check Data Group header if(dg.size() < (offset + 2)) return false; bool extension_flag = dg[offset] & 0x80; bool crc_flag = dg[offset] & 0x40; bool segment_flag = dg[offset] & 0x20; bool user_access_flag = dg[offset] & 0x10; dg_type = dg[offset] & 0x0F; offset += 2 + (extension_flag ? 2 : 0); if(!crc_flag) return false; if(!segment_flag) return false; if(!user_access_flag) return false; if(dg_type != 3 && dg_type != 4) // only accept MOT header/body return false; return true; } bool MOTManager::ParseCheckSessionHeader(const std::vector& dg, size_t& offset, bool& last_seg, int& seg_number, int& transport_id) { // parse/check session header if(dg.size() < (offset + 3)) return false; last_seg = dg[offset] & 0x80; seg_number = ((dg[offset] & 0x7F) << 8) | dg[offset + 1]; bool transport_id_flag = dg[offset + 2] & 0x10; size_t len_indicator = dg[offset + 2] & 0x0F; offset += 3; if(!transport_id_flag) return false; if(len_indicator < 2) return false; // handle transport ID if(dg.size() < (offset + len_indicator)) return false; transport_id = (dg[offset] << 8) | dg[offset + 1]; offset += len_indicator; return true; } bool MOTManager::ParseCheckSegmentationHeader(const std::vector& dg, size_t& offset, size_t& seg_size) { // parse/check segmentation header (MOT) if(dg.size() < (offset + 2)) return false; seg_size = ((dg[offset] & 0x1F) << 8) | dg[offset + 1]; offset += 2; // compare announced/actual segment size if(seg_size != dg.size() - offset - CalcCRC::CRCLen) return false; return true; } bool MOTManager::HandleMOTDataGroup(const std::vector& dg) { size_t offset = 0; // parse/check headers int dg_type; bool last_seg; int seg_number; int transport_id; size_t seg_size; if(!ParseCheckDataGroupHeader(dg, offset, dg_type)) return false; if(!ParseCheckSessionHeader(dg, offset, last_seg, seg_number, transport_id)) return false; if(!ParseCheckSegmentationHeader(dg, offset, seg_size)) return false; // add segment to MOT object (reset if necessary) if(current_transport_id != transport_id) { current_transport_id = transport_id; object = MOTObject(); } object.AddSeg(dg_type == 3, seg_number, last_seg, &dg[offset], seg_size); // check if object shall be shown bool display = object.IsToBeShown(); // fprintf(stderr, "dg_type: %d, seg_number: %2d%s, transport_id: %5d, size: %4zu; display: %s\n", // dg_type, seg_number, last_seg ? " (LAST)" : "", transport_id, seg_size, display ? "true" : "false"); // if object shall be shown, update it return display; } dablin-1.8.0/src/mot_manager.h000066400000000000000000000063671324402060700162140ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2016-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef MOT_MANAGER_H_ #define MOT_MANAGER_H_ #include #include #include #include #include #include #include "fic_decoder.h" #include "tools.h" // --- MOT_FILE ----------------------------------------------------------------- struct MOT_FILE { std::vector data; // from header core size_t body_size; int content_type; int content_sub_type; // from header extension std::string content_name; std::string category_title; std::string click_through_url; bool trigger_time_now; static const int CONTENT_TYPE_IMAGE = 0x02; static const int CONTENT_TYPE_MOT_TRANSPORT = 0x05; static const int CONTENT_SUB_TYPE_JFIF = 0x001; static const int CONTENT_SUB_TYPE_PNG = 0x003; static const int CONTENT_SUB_TYPE_HEADER_UPDATE = 0x000; MOT_FILE() : body_size(-1), content_type(-1), content_sub_type(-1), trigger_time_now(false) {} }; typedef std::vector seg_t; typedef std::map segs_t; // --- MOTEntity ----------------------------------------------------------------- class MOTEntity { private: segs_t segs; int last_seg_number; size_t size; public: MOTEntity() {Reset();} void Reset() { segs.clear(); last_seg_number = -1; size = 0; } void AddSeg(int seg_number, bool last_seg, const uint8_t* data, size_t len); bool IsFinished(); size_t GetSize() {return size;} std::vector GetData(); }; // --- MOTObject ----------------------------------------------------------------- class MOTObject { private: MOTEntity header; MOTEntity body; bool header_received; bool shown; MOT_FILE result_file; bool ParseCheckHeader(MOT_FILE& target_file); public: MOTObject(): header_received(false), shown(false) {} void AddSeg(bool dg_type_header, int seg_number, bool last_seg, const uint8_t* data, size_t len); bool IsToBeShown(); MOT_FILE GetFile() {return result_file;} }; // --- MOTManager ----------------------------------------------------------------- class MOTManager { private: MOTObject object; int current_transport_id; bool ParseCheckDataGroupHeader(const std::vector& dg, size_t& offset, int& dg_type); bool ParseCheckSessionHeader(const std::vector& dg, size_t& offset, bool& last_seg, int& seg_number, int& transport_id); bool ParseCheckSegmentationHeader(const std::vector& dg, size_t& offset, size_t& seg_size); public: MOTManager(); void Reset(); bool HandleMOTDataGroup(const std::vector& dg); MOT_FILE GetFile() {return object.GetFile();} }; #endif /* MOT_MANAGER_H_ */ dablin-1.8.0/src/pad_decoder.cpp000066400000000000000000000252321324402060700164770ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "pad_decoder.h" // --- XPAD_CI ----------------------------------------------------------------- const size_t XPAD_CI::lens[] = {4, 6, 8, 12, 16, 24, 32, 48}; // --- PADDecoder ----------------------------------------------------------------- void PADDecoder::Reset() { mot_app_type = -1; last_xpad_ci.Reset(); dl_decoder.Reset(); dgli_decoder.Reset(); mot_decoder.Reset(); mot_manager.Reset(); } void PADDecoder::Process(const uint8_t *xpad_data, size_t xpad_len, bool exact_xpad_len, const uint8_t* fpad_data) { // undo reversed byte order + trim long MP2 frames size_t used_xpad_len = std::min(xpad_len, sizeof(xpad)); for(size_t i = 0; i < used_xpad_len; i++) xpad[i] = xpad_data[xpad_len - 1 - i]; xpad_cis_t xpad_cis; size_t xpad_cis_len = -1; int fpad_type = fpad_data[0] >> 6; int xpad_ind = (fpad_data[0] & 0x30) >> 4; bool ci_flag = fpad_data[1] & 0x02; XPAD_CI prev_xpad_ci = last_xpad_ci; last_xpad_ci.Reset(); // build CI list if(fpad_type == 0b00) { if(ci_flag) { switch(xpad_ind) { case 0b01: { // short X-PAD if(xpad_len < 1) return; int type = xpad[0] & 0x1F; // skip end marker if(type != 0x00) { xpad_cis_len = 1; xpad_cis.push_back(XPAD_CI(3, type)); } break; } case 0b10: // variable size X-PAD xpad_cis_len = 0; for(size_t i = 0; i < 4; i++) { if(xpad_len < i + 1) return; uint8_t ci_raw = xpad[i]; xpad_cis_len++; // break on end marker if((ci_raw & 0x1F) == 0x00) break; xpad_cis.push_back(XPAD_CI(ci_raw)); } break; } } else { switch(xpad_ind) { case 0b01: // short X-PAD case 0b10: // variable size X-PAD // if there is a previous CI, append it if(prev_xpad_ci.type != -1) { xpad_cis_len = 0; xpad_cis.push_back(prev_xpad_ci); } break; } } } // fprintf(stderr, "PADDecoder: -----\n"); if(xpad_cis.empty()) return; size_t announced_xpad_len = xpad_cis_len; for(xpad_cis_t::const_iterator it = xpad_cis.cbegin(); it != xpad_cis.cend(); it++) announced_xpad_len += it->len; // abort, if the announced X-PAD len exceeds the available one if(announced_xpad_len > xpad_len) return; if(exact_xpad_len && announced_xpad_len < xpad_len) { /* If the announced X-PAD len falls below the available one (which can * only happen with DAB+), a decoder shall discard the X-PAD (see §5.4.3 * in ETSI TS 102 563). * This behaviour can be disabled in order to process the X-PAD anyhow. */ if(loose) { fprintf(stderr, "\x1B[33m" "[X-PAD len]" "\x1B[0m" " "); } else { fprintf(stderr, "\x1B[31m" "[X-PAD len]" "\x1B[0m" " "); return; } } // process CIs size_t xpad_offset = xpad_cis_len; int xpad_ci_type_continued = -1; for(xpad_cis_t::const_iterator it = xpad_cis.cbegin(); it != xpad_cis.cend(); it++) { // len only valid for the *immediate* next data group after the DGLI! size_t dgli_len = dgli_decoder.GetDGLILen(); // handle Data Subfield switch(it->type) { case 1: // Data Group Length Indicator dgli_decoder.ProcessDataSubfield(ci_flag, xpad + xpad_offset, it->len); xpad_ci_type_continued = 1; break; case 2: // Dynamic Label segment (start) case 3: // Dynamic Label segment (continuation) // if new label available, append it if(dl_decoder.ProcessDataSubfield(it->type == 2, xpad + xpad_offset, it->len)) observer->PADChangeDynamicLabel(dl_decoder.GetLabel()); xpad_ci_type_continued = 3; break; default: // MOT, X-PAD data group (start/continuation) if(mot_app_type != -1 && (it->type == mot_app_type || it->type == mot_app_type + 1)) { bool start = it->type == mot_app_type; if(start) mot_decoder.SetLen(dgli_len); // if new Data Group available, append it if(mot_decoder.ProcessDataSubfield(start, xpad + xpad_offset, it->len)) { // if new slide available, show it if(mot_manager.HandleMOTDataGroup(mot_decoder.GetMOTDataGroup())) { const MOT_FILE new_slide = mot_manager.GetFile(); // check file type bool show_slide = true; if(new_slide.content_type != MOT_FILE::CONTENT_TYPE_IMAGE) show_slide = false; switch(new_slide.content_sub_type) { case MOT_FILE::CONTENT_SUB_TYPE_JFIF: case MOT_FILE::CONTENT_SUB_TYPE_PNG: break; default: show_slide = false; } if(show_slide) observer->PADChangeSlide(new_slide); } } xpad_ci_type_continued = mot_app_type + 1; } break; } // fprintf(stderr, "PADDecoder: Data Subfield: type: %2d, len: %2zu\n", it->type, it->len); xpad_offset += it->len; } // set last CI last_xpad_ci.len = xpad_offset; last_xpad_ci.type = xpad_ci_type_continued; } // --- DataGroup ----------------------------------------------------------------- DataGroup::DataGroup(size_t dg_size_max) { dg_raw.resize(dg_size_max); Reset(); } void DataGroup::Reset() { dg_size = 0; dg_size_needed = GetInitialNeededSize(); } bool DataGroup::ProcessDataSubfield(bool start, const uint8_t *data, size_t len) { if(start) { Reset(); } else { // ignore Data Group continuation without previous start if(dg_size == 0) return false; } // abort, if needed size already reached (except needed size not yet set) if(dg_size >= dg_size_needed) return false; // abort, if maximum size already reached if(dg_size == dg_raw.size()) return false; // append Data Subfield size_t copy_len = dg_raw.size() - dg_size; if(len < copy_len) copy_len = len; memcpy(&dg_raw[dg_size], data, copy_len); dg_size += copy_len; // abort, if needed size not yet reached if(dg_size < dg_size_needed) return false; return DecodeDataGroup(); } bool DataGroup::EnsureDataGroupSize(size_t desired_dg_size) { dg_size_needed = desired_dg_size; return dg_size >= dg_size_needed; } bool DataGroup::CheckCRC(size_t len) { // ensure needed size reached if(dg_size < len + CalcCRC::CRCLen) return false; uint16_t crc_stored = dg_raw[len] << 8 | dg_raw[len + 1]; uint16_t crc_calced = CalcCRC::CalcCRC_CRC16_CCITT.Calc(&dg_raw[0], len); return crc_stored == crc_calced; } // --- DGLIDecoder ----------------------------------------------------------------- void DGLIDecoder::Reset() { DataGroup::Reset(); dgli_len = 0; } bool DGLIDecoder::DecodeDataGroup() { // abort on invalid CRC if(!CheckCRC(2)) { DataGroup::Reset(); return false; } dgli_len = (dg_raw[0] & 0x3F) << 8 | dg_raw[1]; DataGroup::Reset(); // fprintf(stderr, "DGLIDecoder: dgli_len: %5zu\n", dgli_len); return true; } size_t DGLIDecoder::GetDGLILen() { size_t result = dgli_len; dgli_len = 0; return result; } // --- DynamicLabelDecoder ----------------------------------------------------------------- void DynamicLabelDecoder::Reset() { DataGroup::Reset(); dl_sr.Reset(); label.Reset(); } bool DynamicLabelDecoder::DecodeDataGroup() { bool command = dg_raw[0] & 0x10; size_t field_len = 0; bool cmd_remove_label = false; // handle command/segment if(command) { switch(dg_raw[0] & 0x0F) { case DL_CMD_REMOVE_LABEL: cmd_remove_label = true; break; default: // ignore command DataGroup::Reset(); return false; } } else { field_len = (dg_raw[0] & 0x0F) + 1; } size_t real_len = 2 + field_len; if(!EnsureDataGroupSize(real_len + CalcCRC::CRCLen)) return false; // abort on invalid CRC if(!CheckCRC(real_len)) { DataGroup::Reset(); return false; } // on Remove Label command, display empty label if(cmd_remove_label) { label.Reset(); return true; } // create new segment DL_SEG dl_seg; memcpy(dl_seg.prefix, &dg_raw[0], 2); dl_seg.chars.insert(dl_seg.chars.begin(), dg_raw.begin() + 2, dg_raw.begin() + 2 + field_len); DataGroup::Reset(); // fprintf(stderr, "DynamicLabelDecoder: segnum %d, toggle: %s, chars_len: %2d%s\n", dl_seg.SegNum(), dl_seg.Toggle() ? "Y" : "N", dl_seg.chars.size(), dl_seg.Last() ? " [LAST]" : ""); // try to add segment if(!dl_sr.AddSegment(dl_seg)) return false; // append new label label.raw = dl_sr.label_raw; label.charset = dl_sr.dl_segs[0].prefix[1] >> 4; return true; } // --- DL_SEG_REASSEMBLER ----------------------------------------------------------------- void DL_SEG_REASSEMBLER::Reset() { dl_segs.clear(); label_raw.clear(); } bool DL_SEG_REASSEMBLER::AddSegment(DL_SEG &dl_seg) { dl_segs_t::const_iterator it; // if there are already segments with other toggle value in cache, first clear it it = dl_segs.cbegin(); if(it != dl_segs.cend() && it->second.Toggle() != dl_seg.Toggle()) dl_segs.clear(); // if the segment is already there, abort it = dl_segs.find(dl_seg.SegNum()); if(it != dl_segs.cend()) return false; // add segment dl_segs[dl_seg.SegNum()] = dl_seg; // check for complete label return CheckForCompleteLabel(); } bool DL_SEG_REASSEMBLER::CheckForCompleteLabel() { dl_segs_t::const_iterator it; // check if all segments are in cache int segs = 0; for(int i = 0; i < 8; i++) { it = dl_segs.find(i); if(it == dl_segs.cend()) return false; segs++; if(it->second.Last()) break; if(i == 7) return false; } // append complete label label_raw.clear(); for(int i = 0; i < segs; i++) label_raw.insert(label_raw.end(), dl_segs[i].chars.begin(), dl_segs[i].chars.end()); // std::string label((const char*) &label_raw[0], label_raw.size()); // fprintf(stderr, "DL_SEG_REASSEMBLER: new label: '%s'\n", label.c_str()); return true; } // --- MOTDecoder ----------------------------------------------------------------- void MOTDecoder::Reset() { DataGroup::Reset(); mot_len = 0; } bool MOTDecoder::DecodeDataGroup() { // ignore too short lens if(mot_len < CalcCRC::CRCLen) return false; // only DGs with CRC are supported here! // abort on invalid CRC if(!CheckCRC(mot_len - CalcCRC::CRCLen)) { DataGroup::Reset(); return false; } DataGroup::Reset(); // fprintf(stderr, "MOTDecoder: mot_len: %5zu\n", mot_len); return true; } std::vector MOTDecoder::GetMOTDataGroup() { std::vector result(mot_len); memcpy(&result[0], &dg_raw[0], mot_len); return result; } dablin-1.8.0/src/pad_decoder.h000066400000000000000000000117061324402060700161450ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PAD_DECODER_H_ #define PAD_DECODER_H_ #include #include #include #include #include #include #include #include "mot_manager.h" #include "tools.h" #define DL_MAX_LEN 128 #define DL_CMD_REMOVE_LABEL 0x01 // --- DL_SEG ----------------------------------------------------------------- struct DL_SEG { uint8_t prefix[2]; std::vector chars; bool Toggle() const {return prefix[0] & 0x80;} bool First() const {return prefix[0] & 0x40;} bool Last() const {return prefix[0] & 0x20;} int SegNum() const {return First() ? 0 : ((prefix[1] & 0x70) >> 4);} }; // --- DataGroup ----------------------------------------------------------------- class DataGroup { protected: std::vector dg_raw; size_t dg_size; size_t dg_size_needed; virtual size_t GetInitialNeededSize() {return 0;}; virtual bool DecodeDataGroup() = 0; bool EnsureDataGroupSize(size_t desired_dg_size); bool CheckCRC(size_t len); void Reset(); public: DataGroup(size_t dg_size_max); virtual ~DataGroup() {} bool ProcessDataSubfield(bool start, const uint8_t *data, size_t len); }; // --- DGLIDecoder ----------------------------------------------------------------- class DGLIDecoder : public DataGroup { private: size_t dgli_len; size_t GetInitialNeededSize() {return 2 + CalcCRC::CRCLen;} // DG len + CRC bool DecodeDataGroup(); public: DGLIDecoder() : DataGroup(2 + CalcCRC::CRCLen) {Reset();} void Reset(); size_t GetDGLILen(); }; typedef std::map dl_segs_t; // --- DL_SEG_REASSEMBLER ----------------------------------------------------------------- struct DL_SEG_REASSEMBLER { dl_segs_t dl_segs; std::vector label_raw; bool AddSegment(DL_SEG &dl_seg); bool CheckForCompleteLabel(); void Reset(); }; // --- DL_STATE ----------------------------------------------------------------- struct DL_STATE { std::vector raw; int charset; DL_STATE() {Reset();} void Reset() { raw.clear(); charset = -1; } }; // --- DynamicLabelDecoder ----------------------------------------------------------------- class DynamicLabelDecoder : public DataGroup { private: DL_SEG_REASSEMBLER dl_sr; DL_STATE label; size_t GetInitialNeededSize() {return 2 + CalcCRC::CRCLen;} // at least prefix + CRC bool DecodeDataGroup(); public: DynamicLabelDecoder() : DataGroup(2 + 16 + CalcCRC::CRCLen) {Reset();} void Reset(); DL_STATE GetLabel() {return label;} }; // --- MOTDecoder ----------------------------------------------------------------- class MOTDecoder : public DataGroup { private: size_t mot_len; size_t GetInitialNeededSize() {return mot_len;} // MOT len + CRC (or zero!) bool DecodeDataGroup(); public: MOTDecoder() : DataGroup(16384) {Reset();} // = 2^14 void Reset(); void SetLen(size_t mot_len) {this->mot_len = mot_len;} std::vector GetMOTDataGroup(); }; // --- XPAD_CI ----------------------------------------------------------------- struct XPAD_CI { size_t len; int type; static const size_t lens[]; XPAD_CI() {Reset();} XPAD_CI(uint8_t ci_raw) { len = lens[ci_raw >> 5]; type = ci_raw & 0x1F; } XPAD_CI(size_t len, int type) : len(len), type(type) {} void Reset() { len = 0; type = -1; } }; typedef std::list xpad_cis_t; // --- PADDecoderObserver ----------------------------------------------------------------- class PADDecoderObserver { public: virtual ~PADDecoderObserver() {}; virtual void PADChangeDynamicLabel(const DL_STATE& /*dl*/) {}; virtual void PADChangeSlide(const MOT_FILE& /*slide*/) {}; }; // --- PADDecoder ----------------------------------------------------------------- class PADDecoder { private: PADDecoderObserver *observer; bool loose; std::atomic mot_app_type; uint8_t xpad[196]; // longest possible X-PAD XPAD_CI last_xpad_ci; DynamicLabelDecoder dl_decoder; DGLIDecoder dgli_decoder; MOTDecoder mot_decoder; MOTManager mot_manager; public: PADDecoder(PADDecoderObserver *observer, bool loose) : observer(observer), loose(loose), mot_app_type(-1) {} void SetMOTAppType(int mot_app_type) {this-> mot_app_type = mot_app_type;} void Process(const uint8_t *xpad_data, size_t xpad_len, bool exact_xpad_len, const uint8_t* fpad_data); void Reset(); }; #endif /* PAD_DECODER_H_ */ dablin-1.8.0/src/pcm_output.cpp000066400000000000000000000027731324402060700164520ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2016 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "pcm_output.h" // --- PCMOutput ----------------------------------------------------------------- PCMOutput::PCMOutput() : AudioOutput() { samplerate = 0; channels = 0; float32 = false; audio_mute = false; } void PCMOutput::StartAudio(int samplerate, int channels, bool float32) { // if no change, return if(this->samplerate == samplerate && this->channels == channels && this->float32 == float32) return; this->samplerate = samplerate; this->channels = channels; this->float32 = float32; fprintf(stderr, "PCMOutput: format set; samplerate: %d, channels: %d, output: %s\n", samplerate, channels, float32 ? "32bit float" : "16bit integer"); } void PCMOutput::PutAudio(const uint8_t *data, size_t len) { if(!audio_mute) fwrite(data, len, 1, stdout); } dablin-1.8.0/src/pcm_output.h000066400000000000000000000026271324402060700161150ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PCM_OUTPUT_H_ #define PCM_OUTPUT_H_ #include #include #include #include #include "audio_output.h" // --- PCMOutput ----------------------------------------------------------------- class PCMOutput : public AudioOutput { private: int samplerate; int channels; bool float32; std::atomic audio_mute; public: PCMOutput(); ~PCMOutput() {} void StartAudio(int samplerate, int channels, bool float32); void PutAudio(const uint8_t *data, size_t len); void SetAudioMute(bool audio_mute) {this->audio_mute = audio_mute;}; void SetAudioVolume(double) {} bool HasAudioVolumeControl() {return false;} }; #endif /* PCM_OUTPUT_H_ */ dablin-1.8.0/src/sdl_output.cpp000066400000000000000000000126541324402060700164540ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "sdl_output.h" static void sdl_audio_callback(void *userdata, Uint8 *stream, int len) { AudioSource* audio_source = (AudioSource*) userdata; audio_source->AudioCallback(stream, len); } // --- SDLOutput ----------------------------------------------------------------- SDLOutput::SDLOutput() : AudioOutput() { audio_device = 0; silence_len = 0; samplerate = 0; channels = 0; float32 = false; audio_buffer = nullptr; audio_start_buffer_size = 0; audio_mute = false; audio_volume = 1.0; // init SDL if(SDL_Init(SDL_INIT_AUDIO)) throw std::runtime_error("SDLOutput: error while SDL_Init: " + std::string(SDL_GetError())); SDL_version sdl_version; SDL_GetVersion(&sdl_version); fprintf(stderr, "SDLOutput: using SDL version '%u.%u.%u'\n", sdl_version.major, sdl_version.minor, sdl_version.patch); } SDLOutput::~SDLOutput() { StopAudio(); SDL_Quit(); delete audio_buffer; } void SDLOutput::StopAudio() { if(audio_device) { SDL_CloseAudioDevice(audio_device); fprintf(stderr, "SDLOutput: audio closed\n"); audio_device = 0; } } void SDLOutput::StartAudio(int samplerate, int channels, bool float32) { // if no change, do quick restart if(audio_device && this->samplerate == samplerate && this->channels == channels && this->float32 == float32) { std::lock_guard lock(audio_buffer_mutex); audio_buffer->Clear(); SetAudioStartBufferSize(); return; } this->samplerate = samplerate; this->channels = channels; this->float32 = float32; StopAudio(); // (re)init buffer { std::lock_guard lock(audio_buffer_mutex); if(audio_buffer) delete audio_buffer; // use 500ms buffer size_t buffersize = samplerate / 2 * channels * (float32 ? 4 : 2); fprintf(stderr, "SDLOutput: using audio buffer of %zu bytes\n", buffersize); audio_buffer = new CircularBuffer(buffersize); SetAudioStartBufferSize(); } // init audio SDL_AudioSpec desired; SDL_AudioSpec obtained; desired.freq = samplerate; desired.format = float32 ? AUDIO_F32SYS : AUDIO_S16SYS; desired.channels = channels; desired.samples = 0; desired.callback = sdl_audio_callback; desired.userdata = (AudioSource*) this; audio_device = SDL_OpenAudioDevice(nullptr, 0, &desired, &obtained, 0); if(!audio_device) throw std::runtime_error("SDLOutput: error while SDL_OpenAudioDevice: " + std::string(SDL_GetError())); fprintf(stderr, "SDLOutput: audio opened; driver name: %s, freq: %d, channels: %d, size: %d, samples: %d, silence: 0x%02X, output: %s\n", SDL_GetCurrentAudioDriver(), obtained.freq, obtained.channels, obtained.size, obtained.samples, obtained.silence, float32 ? "32bit float" : "16bit integer"); audio_spec = obtained; SDL_PauseAudioDevice(audio_device, 0); } void SDLOutput::SetAudioStartBufferSize() { // start audio when 1/2 filled audio_start_buffer_size = audio_buffer->Capacity() / 2; } void SDLOutput::PutAudio(const uint8_t *data, size_t len) { std::lock_guard lock(audio_buffer_mutex); size_t capa = audio_buffer->Capacity() - audio_buffer->Size(); // if(capa < len) { // fprintf(stderr, "SDLOutput: audio buffer overflow, therefore cleaning buffer!\n"); // audio_buffer->Clear(); // capa = audio_buffer->capacity(); // } if(len > capa) fprintf(stderr, "SDLOutput: audio buffer overflow: %zu > %zu\n", len, capa); audio_buffer->Write(data, len); // fprintf(stderr, "Buffer: %zu / %zu\n", audio_buffer->Size(), audio_buffer->Capacity()); } void SDLOutput::AudioCallback(Uint8* stream, int len) { // audio int filled = GetAudio(stream, len); if(filled && silence_len) { fprintf(stderr, "SDLOutput: silence ended (%d bytes)\n", silence_len); silence_len = 0; } // silence, if needed if(filled < len) { int bytes = len - filled; memset(stream + filled, audio_spec.silence, bytes); if(silence_len == 0) fprintf(stderr, "SDLOutput: silence started...\n"); silence_len += bytes; } } size_t SDLOutput::GetAudio(uint8_t *data, size_t len) { std::lock_guard lock(audio_buffer_mutex); if(audio_start_buffer_size && audio_buffer->Size() >= audio_start_buffer_size) audio_start_buffer_size = 0; // output silence, if needed if(audio_volume == 0.0 || audio_mute || audio_start_buffer_size) { if(audio_start_buffer_size == 0) audio_buffer->Read(nullptr, len); memset(data, audio_spec.silence, len); return len; } // output buffer, if full volume if(audio_volume == 1.0) return audio_buffer->Read(data, len); // output buffer after volume adjustment audio_mix_buffer.resize(len); size_t got_len = audio_buffer->Read(&audio_mix_buffer[0], len); memset(data, audio_spec.silence, got_len); SDL_MixAudioFormat(data, &audio_mix_buffer[0], audio_spec.format, got_len, SDL_MIX_MAXVOLUME * audio_volume); return got_len; } dablin-1.8.0/src/sdl_output.h000066400000000000000000000041661324402060700161200ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SDL_OUTPUT_H_ #define SDL_OUTPUT_H_ #include #include #include #include #include #include #include "SDL.h" #include "audio_output.h" #include "tools.h" // --- AudioSource ----------------------------------------------------------------- class AudioSource { public: virtual ~AudioSource() {}; virtual void AudioCallback(Uint8* /*stream*/, int /*len*/) = 0; }; // --- SDLOutput ----------------------------------------------------------------- class SDLOutput : public AudioOutput, AudioSource { private: SDL_AudioDeviceID audio_device; SDL_AudioSpec audio_spec; int silence_len; int samplerate; int channels; bool float32; std::mutex audio_buffer_mutex; CircularBuffer *audio_buffer; size_t audio_start_buffer_size; std::vector audio_mix_buffer; std::atomic audio_mute; std::atomic audio_volume; void AudioCallback(Uint8* stream, int len); size_t GetAudio(uint8_t *data, size_t len); void StopAudio(); void SetAudioStartBufferSize(); public: SDLOutput(); ~SDLOutput(); void StartAudio(int samplerate, int channels, bool float32); void PutAudio(const uint8_t *data, size_t len); void SetAudioMute(bool audio_mute) {this->audio_mute = audio_mute;} void SetAudioVolume(double audio_volume) {this->audio_volume = audio_volume;} bool HasAudioVolumeControl() {return true;} }; #endif /* SDL_OUTPUT_H_ */ dablin-1.8.0/src/subchannel_sink.h000066400000000000000000000033211324402060700170540ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SUBCHANNEL_SINK_H_ #define SUBCHANNEL_SINK_H_ #include #include #define FPAD_LEN 2 // --- SubchannelSinkObserver ----------------------------------------------------------------- class SubchannelSinkObserver { public: virtual ~SubchannelSinkObserver() {}; virtual void FormatChange(const std::string& /*format*/) {} virtual void StartAudio(int /*samplerate*/, int /*channels*/, bool /*float32*/) {} virtual void PutAudio(const uint8_t* /*data*/, size_t /*len*/) {} virtual void ProcessPAD(const uint8_t* /*xpad_data*/, size_t /*xpad_len*/, bool /*exact_xpad_len*/, const uint8_t* /*fpad_data*/) {} }; // --- SubchannelSink ----------------------------------------------------------------- class SubchannelSink { protected: SubchannelSinkObserver* observer; public: SubchannelSink(SubchannelSinkObserver* observer) : observer(observer) {} virtual ~SubchannelSink() {}; virtual void Feed(const uint8_t *data, size_t len) = 0; }; #endif /* SUBCHANNEL_SINK_H_ */ dablin-1.8.0/src/tools.cpp000066400000000000000000000126211324402060700154040ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "tools.h" // --- MiscTools ----------------------------------------------------------------- string_vector_t MiscTools::SplitString(const std::string &s, const char delimiter) { string_vector_t result; std::stringstream ss(s); std::string part; while(std::getline(ss, part, delimiter)) result.push_back(part); return result; } // --- CalcCRC ----------------------------------------------------------------- CalcCRC CalcCRC::CalcCRC_CRC16_CCITT(true, true, 0x1021); // 0001 0000 0010 0001 (16, 12, 5, 0) CalcCRC CalcCRC::CalcCRC_CRC16_IBM(true, false, 0x8005); // 1000 0000 0000 0101 (16, 15, 2, 0) CalcCRC CalcCRC::CalcCRC_FIRE_CODE(false, false, 0x782F); // 0111 1000 0010 1111 (16, 14, 13, 12, 11, 5, 3, 2, 1, 0) size_t CalcCRC::CRCLen = 2; CalcCRC::CalcCRC(bool initial_invert, bool final_invert, uint16_t gen_polynom) { this->initial_invert = initial_invert; this->final_invert = final_invert; this->gen_polynom = gen_polynom; FillLUT(); } void CalcCRC::FillLUT() { for(int value = 0; value < 256; value++) { uint16_t crc = value << 8; for(int i = 0; i < 8; i++) { if(crc & 0x8000) crc = (crc << 1) ^ gen_polynom; else crc = crc << 1; } crc_lut[value] = crc; } } uint16_t CalcCRC::Calc(const uint8_t *data, size_t len) { uint16_t crc; Initialize(crc); for(size_t offset = 0; offset < len; offset++) ProcessByte(crc, data[offset]); Finalize(crc); return crc; } void CalcCRC::ProcessBits(uint16_t& crc, const uint8_t *data, size_t len) { // byte-aligned start only size_t bytes = len / 8; size_t bits = len % 8; for(size_t offset = 0; offset < bytes; offset++) ProcessByte(crc, data[offset]); for(size_t bit = 0; bit < bits; bit++) ProcessBit(crc, data[bytes] & (0x80 >> bit)); } // --- CircularBuffer ----------------------------------------------------------------- CircularBuffer::CircularBuffer(size_t capacity) { buffer = new uint8_t[capacity]; this->capacity = capacity; Clear(); } CircularBuffer::~CircularBuffer() { delete[] buffer; } size_t CircularBuffer::Write(const uint8_t *data, size_t bytes) { size_t real_bytes = std::min(bytes, capacity - size); // split task on index rollover if(real_bytes <= capacity - index_end) { memcpy(buffer + index_end, data, real_bytes); } else { size_t first_bytes = capacity - index_end; memcpy(buffer + index_end, data, first_bytes); memcpy(buffer, data + first_bytes, real_bytes - first_bytes); } index_end = (index_end + real_bytes) % capacity; size += real_bytes; return real_bytes; } size_t CircularBuffer::Read(uint8_t *data, size_t bytes) { size_t real_bytes = std::min(bytes, size); if(data) { // split task on index rollover if(real_bytes <= capacity - index_start) { memcpy(data, buffer + index_start, real_bytes); } else { size_t first_bytes = capacity - index_start; memcpy(data, buffer + index_start, first_bytes); memcpy(data + first_bytes, buffer, real_bytes - first_bytes); } } index_start = (index_start + real_bytes) % capacity; size -= real_bytes; return real_bytes; } // --- BitReader ----------------------------------------------------------------- bool BitReader::GetBits(int& result, size_t count) { int result_value = 0; while(count) { if(data_bytes == 0) return false; size_t copy_bits = std::min(count, 8 - data_bits); result_value <<= copy_bits; result_value |= (*data & (0xFF >> data_bits)) >> (8 - data_bits - copy_bits); data_bits += copy_bits; count -= copy_bits; // switch to next byte if(data_bits == 8) { data++; data_bytes--; data_bits = 0; } } result = result_value; return true; } const dab_channels_t dab_channels { { "5A", 174928}, { "5B", 176640}, { "5C", 178352}, { "5D", 180064}, { "6A", 181936}, { "6B", 183648}, { "6C", 185360}, { "6D", 187072}, { "7A", 188928}, { "7B", 190640}, { "7C", 192352}, { "7D", 194064}, { "8A", 195936}, { "8B", 197648}, { "8C", 199360}, { "8D", 201072}, { "9A", 202928}, { "9B", 204640}, { "9C", 206352}, { "9D", 208064}, {"10A", 209936}, {"10N", 210096}, {"10B", 211648}, {"10C", 213360}, {"10D", 215072}, {"11A", 216928}, {"11N", 217088}, {"11B", 218640}, {"11C", 220352}, {"11D", 222064}, {"12A", 223936}, {"12N", 224096}, {"12B", 225648}, {"12C", 227360}, {"12D", 229072}, {"13A", 230784}, {"13B", 232496}, {"13C", 234208}, {"13D", 235776}, {"13E", 237488}, {"13F", 239200}, { "LA", 1452960}, { "LB", 1454672}, { "LC", 1456384}, { "LD", 1458096}, { "LE", 1459808}, { "LF", 1461520}, { "LG", 1463232}, { "LH", 1464944}, { "LI", 1466656}, { "LJ", 1468368}, { "LK", 1470080}, { "LL", 1471792}, { "LM", 1473504}, { "LN", 1475216}, { "LO", 1476928}, { "LP", 1478640}, }; dablin-1.8.0/src/tools.h000066400000000000000000000074461324402060700150620ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2015-2017 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef TOOLS_H_ #define TOOLS_H_ #include #include #include #include #include #include #include typedef std::vector string_vector_t; // --- MiscTools ----------------------------------------------------------------- class MiscTools { public: static string_vector_t SplitString(const std::string &s, const char delimiter); }; // --- CalcCRC ----------------------------------------------------------------- class CalcCRC { private: bool initial_invert; bool final_invert; uint16_t gen_polynom; uint16_t crc_lut[256]; void FillLUT(); public: CalcCRC(bool initial_invert, bool final_invert, uint16_t gen_polynom); virtual ~CalcCRC() {} // simple API uint16_t Calc(const uint8_t *data, size_t len); // modular API void Initialize(uint16_t& crc); void ProcessByte(uint16_t& crc, const uint8_t data); void ProcessBit(uint16_t& crc, const bool data); void ProcessBits(uint16_t& crc, const uint8_t *data, size_t len); void Finalize(uint16_t& crc); static CalcCRC CalcCRC_CRC16_CCITT; static CalcCRC CalcCRC_CRC16_IBM; static CalcCRC CalcCRC_FIRE_CODE; static size_t CRCLen; }; inline void CalcCRC::Initialize(uint16_t& crc) { crc = initial_invert ? 0xFFFF : 0x0000; } inline void CalcCRC::ProcessByte(uint16_t& crc, const uint8_t data) { // use LUT crc = (crc << 8) ^ crc_lut[(crc >> 8) ^ data]; } inline void CalcCRC::ProcessBit(uint16_t& crc, const bool data) { if(data ^ (bool) (crc & 0x8000)) crc = (crc << 1) ^ gen_polynom; else crc = crc << 1; } inline void CalcCRC::Finalize(uint16_t& crc) { if(final_invert) crc = ~crc; } // --- CircularBuffer ----------------------------------------------------------------- class CircularBuffer { private: uint8_t *buffer; size_t capacity; size_t size; size_t index_start; size_t index_end; public: CircularBuffer(size_t capacity); ~CircularBuffer(); size_t Capacity() {return capacity;} size_t Size() {return size;} size_t Write(const uint8_t *data, size_t bytes); size_t Read(uint8_t *data, size_t bytes); void Clear() {size = index_start = index_end = 0;} }; // --- BitReader ----------------------------------------------------------------- class BitReader { private: const uint8_t *data; size_t data_bytes; size_t data_bits; public: BitReader(const uint8_t *data, size_t data_bytes) : data(data), data_bytes(data_bytes), data_bits(0) {} bool GetBits(int& result, size_t count); }; typedef std::map dab_channels_t; extern const dab_channels_t dab_channels; struct AUDIO_SERVICE { int subchid; bool dab_plus; static const int subchid_none = -1; bool IsNone() const {return subchid == subchid_none;} AUDIO_SERVICE() : AUDIO_SERVICE(subchid_none, false) {} AUDIO_SERVICE(int subchid, bool dab_plus) : subchid(subchid), dab_plus(dab_plus) {} bool operator==(const AUDIO_SERVICE & audio_service) const { return subchid == audio_service.subchid && dab_plus == audio_service.dab_plus; } bool operator!=(const AUDIO_SERVICE & audio_service) const { return !(*this == audio_service); } }; #endif /* TOOLS_H_ */ dablin-1.8.0/src/version.cpp000066400000000000000000000020121324402060700157220ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2016 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "version.h" void fprint_dablin_banner(FILE *f) { fprintf(f, "DABlin v%s - capital DAB experience\n", DABLIN_VERSION); fprintf(f, "Plays a DAB/DAB+ audio service from a frame-aligned ETI-NI stream.\n"); fprintf(f, " https://github.com/Opendigitalradio/dablin\n"); fprintf(f, "\n"); } dablin-1.8.0/src/version.h000066400000000000000000000017031324402060700153750ustar00rootroot00000000000000/* DABlin - capital DAB experience Copyright (C) 2016-2018 Stefan Pöschel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef VERSION_H_ #define VERSION_H_ #include // usually externally derived from git #ifndef DABLIN_VERSION #define DABLIN_VERSION "1.8.0" #endif void fprint_dablin_banner(FILE *f); #endif /* VERSION_H_ */