├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── docs └── property-window.png ├── external └── FindLibObs.cmake ├── locale ├── de-DE.ini ├── en-US.ini ├── es-ES.ini ├── it_IT.ini ├── zh-CN.ini └── zh-TW.ini └── src ├── v4l2sink.cpp ├── v4l2sink.h ├── v4l2sinkproperties.cpp ├── v4l2sinkproperties.h └── v4l2sinkproperties.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | build/ 3 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(obs-v4l2sink) 3 | include(GNUInstallDirs) 4 | 5 | 6 | include(external/FindLibObs.cmake) 7 | find_package(LibObs REQUIRED) 8 | 9 | set (CMAKE_CXX_STANDARD 11) 10 | set(CMAKE_PREFIX_PATH "${QTDIR}") 11 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 12 | set(CMAKE_AUTOMOC ON) 13 | set(CMAKE_AUTOUIC ON) 14 | 15 | find_package(Qt5Core REQUIRED) 16 | find_package(Qt5Widgets REQUIRED) 17 | 18 | 19 | set(virtualoutput_SOURCES 20 | src/v4l2sink.cpp 21 | src/v4l2sinkproperties.cpp) 22 | 23 | set(virtualoutput_HEADERS 24 | src/v4l2sink.h 25 | src/v4l2sinkproperties.h) 26 | 27 | include_directories( 28 | "${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api") 29 | 30 | add_library(v4l2sink MODULE 31 | ${virtualoutput_SOURCES} 32 | ${virtualoutput_HEADERS}) 33 | 34 | target_link_libraries(v4l2sink 35 | libobs 36 | Qt5::Core 37 | Qt5::Widgets) 38 | 39 | if(ARCH EQUAL 64) 40 | set(ARCH_NAME "x86_64") 41 | else() 42 | set(ARCH_NAME "i686") 43 | endif() 44 | 45 | set_target_properties(v4l2sink PROPERTIES PREFIX "") 46 | 47 | install(TARGETS v4l2sink 48 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/obs-plugins) 49 | 50 | install(DIRECTORY locale/ 51 | DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-plugins/v4l2sink/locale") 52 | 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # obs-v4l2sink 2 | 3 | **Notice: [OBS Studio 26.1](https://github.com/obsproject/obs-studio/releases/tag/26.1.0) 4 | officially provides virtual cam support, and can be used without installing this plugin. 5 | See [issue (#56)](https://github.com/CatxFish/obs-v4l2sink/issues/56#issuecomment-753191690) 6 | for more information.** 7 | 8 | An [OBS Studio][obs-proj] plugin that provides output capabilities to a 9 | Video4Linux2 device. It is basically a Linux version of [obs-virtual-cam][vcam], 10 | but only contains the video sink part. You can use it with 11 | [v4l2loopback][v4l2loopback] to achieve cross-program video transfer between OBS 12 | Studio and third party software supporting Video4Linux2, e.g. to present an OBS 13 | session in proprietary browser-based conferencing systems by selecting the OBS 14 | session as a webcam. 15 | 16 | The idea for this plugin originated from the discussions around [obs-virtual-cam 17 | issue #17][vcam#17]. 18 | 19 | [obs-proj]: https://obsproject.com/ 20 | [vcam]: https://github.com/CatxFish/obs-virtual-cam 21 | [v4l2loopback]: https://github.com/umlaeute/v4l2loopback 22 | [vcam#17]: https://github.com/CatxFish/obs-virtual-cam/issues/17 23 | 24 | ## Usage with v4l2loopback 25 | 26 | - Make sure to [load the v4l2loopback module][run-v4l2loopback] and check the Device Path. 27 | - If using Chrome or Chromium you must use the option `exclusive_caps=1`. 28 | - Open OBS and select the menu entry `Tools > V4L2 Video Output`. 29 | - Fill in the Device Path and select the appropriate video format. 30 | - Click the `Start` button. 31 | 32 | ![Property Window](docs/property-window.png) 33 | 34 | [run-v4l2loopback]: https://github.com/umlaeute/v4l2loopback#run 35 | 36 | ## Build 37 | 38 | - Install QT 39 | 40 | ``` 41 | sudo apt install qtbase5-dev 42 | ``` 43 | 44 | - Install LibObs 45 | 46 | ``` 47 | sudo apt install libobs-dev 48 | ``` 49 | 50 | - Get obs-studio source code 51 | 52 | ``` 53 | git clone --recursive https://github.com/obsproject/obs-studio.git 54 | ``` 55 | 56 | - Build plugins 57 | 58 | ``` 59 | git clone https://github.com/CatxFish/obs-v4l2sink.git 60 | cd obs-v4l2sink 61 | mkdir build && cd build 62 | cmake -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" -DCMAKE_INSTALL_PREFIX=/usr .. 63 | make -j4 64 | sudo make install 65 | ``` 66 | -------------------------------------------------------------------------------- /docs/property-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CatxFish/obs-v4l2sink/09878f7721bbbe0c3a8b9fdfbd46504fe35032fe/docs/property-window.png -------------------------------------------------------------------------------- /external/FindLibObs.cmake: -------------------------------------------------------------------------------- 1 | # This module can be copied and used by external plugins for OBS 2 | # 3 | # Once done these will be defined: 4 | # 5 | # LIBOBS_FOUND 6 | # LIBOBS_INCLUDE_DIRS 7 | # LIBOBS_LIBRARIES 8 | 9 | find_package(PkgConfig QUIET) 10 | if (PKG_CONFIG_FOUND) 11 | pkg_check_modules(_OBS QUIET obs libobs) 12 | endif() 13 | 14 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 15 | set(_lib_suffix 64) 16 | else() 17 | set(_lib_suffix 32) 18 | endif() 19 | 20 | if(DEFINED CMAKE_BUILD_TYPE) 21 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 22 | set(_build_type_base "debug") 23 | else() 24 | set(_build_type_base "release") 25 | endif() 26 | endif() 27 | 28 | find_path(LIBOBS_INCLUDE_DIR 29 | NAMES obs.h 30 | HINTS 31 | ENV obsPath${_lib_suffix} 32 | ENV obsPath 33 | ${obsPath} 34 | PATHS 35 | /usr/include /usr/local/include /opt/local/include /sw/include 36 | PATH_SUFFIXES 37 | libobs 38 | ) 39 | 40 | function(find_obs_lib base_name repo_build_path lib_name) 41 | string(TOUPPER "${base_name}" base_name_u) 42 | 43 | if(DEFINED _build_type_base) 44 | set(_build_type_${repo_build_path} "${_build_type_base}/${repo_build_path}") 45 | set(_build_type_${repo_build_path}${_lib_suffix} "${_build_type_base}${_lib_suffix}/${repo_build_path}") 46 | endif() 47 | 48 | find_library(${base_name_u}_LIB 49 | NAMES ${_${base_name_u}_LIBRARIES} ${lib_name} lib${lib_name} 50 | HINTS 51 | ENV obsPath${_lib_suffix} 52 | ENV obsPath 53 | ${obsPath} 54 | ${_${base_name_u}_LIBRARY_DIRS} 55 | PATHS 56 | /usr/lib /usr/local/lib /opt/local/lib /sw/lib 57 | PATH_SUFFIXES 58 | lib${_lib_suffix} lib 59 | libs${_lib_suffix} libs 60 | bin${_lib_suffix} bin 61 | ../lib${_lib_suffix} ../lib 62 | ../libs${_lib_suffix} ../libs 63 | ../bin${_lib_suffix} ../bin 64 | # base repo non-msvc-specific search paths 65 | ${_build_type_${repo_build_path}} 66 | ${_build_type_${repo_build_path}${_lib_suffix}} 67 | build/${repo_build_path} 68 | build${_lib_suffix}/${repo_build_path} 69 | # base repo msvc-specific search paths on windows 70 | build${_lib_suffix}/${repo_build_path}/Debug 71 | build${_lib_suffix}/${repo_build_path}/RelWithDebInfo 72 | build/${repo_build_path}/Debug 73 | build/${repo_build_path}/RelWithDebInfo 74 | ) 75 | endfunction() 76 | 77 | find_obs_lib(LIBOBS libobs obs) 78 | 79 | if(MSVC) 80 | find_obs_lib(W32_PTHREADS deps/w32-pthreads w32-pthreads) 81 | endif() 82 | 83 | include(FindPackageHandleStandardArgs) 84 | find_package_handle_standard_args(Libobs DEFAULT_MSG LIBOBS_LIB LIBOBS_INCLUDE_DIR) 85 | mark_as_advanced(LIBOBS_INCLUDE_DIR LIBOBS_LIB) 86 | 87 | if(LIBOBS_FOUND) 88 | if(MSVC) 89 | if (NOT DEFINED W32_PTHREADS_LIB) 90 | message(FATAL_ERROR "Could not find the w32-pthreads library" ) 91 | endif() 92 | 93 | set(W32_PTHREADS_INCLUDE_DIR ${LIBOBS_INCLUDE_DIR}/../deps/w32-pthreads) 94 | endif() 95 | 96 | set(LIBOBS_INCLUDE_DIRS ${LIBOBS_INCLUDE_DIR} ${W32_PTHREADS_INCLUDE_DIR}) 97 | set(LIBOBS_LIBRARIES ${LIBOBS_LIB} ${W32_PTHREADS_LIB}) 98 | include(${LIBOBS_INCLUDE_DIR}/../cmake/external/ObsPluginHelpers.cmake) 99 | 100 | # allows external plugins to easily use/share common dependencies that are often included with libobs (such as FFmpeg) 101 | if(NOT DEFINED INCLUDED_LIBOBS_CMAKE_MODULES) 102 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LIBOBS_INCLUDE_DIR}/../cmake/Modules/") 103 | set(INCLUDED_LIBOBS_CMAKE_MODULES true) 104 | endif() 105 | else() 106 | message(FATAL_ERROR "Could not find the libobs library" ) 107 | endif() 108 | -------------------------------------------------------------------------------- /locale/de-DE.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="V4L2 Videoausgabe" 2 | AutoStart="Automatisch starten" 3 | Device="Pfad zum V4L2-Gerät" 4 | Format="Videoformat" 5 | -------------------------------------------------------------------------------- /locale/en-US.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="V4L2 Video Output" 2 | AutoStart="Auto Start" 3 | Device="Path to V4L2 Device" 4 | Format="Video Format" 5 | -------------------------------------------------------------------------------- /locale/es-ES.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="Salida de video a V4L2" 2 | AutoStart="Comenzar automáticamente" 3 | Device="Ruta al dispositivo V4L2" 4 | Format="Formato de video" 5 | -------------------------------------------------------------------------------- /locale/it_IT.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="Uscita video V4L2" 2 | AutoStart="Avvio Automatico" 3 | Device="Percorso al dispositivo V4L2" 4 | Format="Formato Video" 5 | -------------------------------------------------------------------------------- /locale/zh-CN.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="V4L2输出" 2 | AutoStart="自动运行" 3 | Device="设备路径" 4 | Format="视频格式" 5 | -------------------------------------------------------------------------------- /locale/zh-TW.ini: -------------------------------------------------------------------------------- 1 | V4l2sink="V4L2輸出" 2 | AutoStart="自動開始" 3 | Device="裝置路徑" 4 | Format="影像格式" 5 | -------------------------------------------------------------------------------- /src/v4l2sink.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | obs-v4l2sink 3 | Copyright (C) 2018 by CatxFish 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | ******************************************************************************/ 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "v4l2sink.h" 27 | #include "v4l2sinkproperties.h" 28 | 29 | #define V4L2SINK_SUCCESS_OPEN 0 30 | #define V4L2SINK_ERROR_OPEN 1 31 | #define V4L2SINK_ERROR_FORMAT 2 32 | #define V4L2SINK_ERROR_OTHER 3 33 | 34 | struct v4l2sink_data{ 35 | obs_output_t *output = nullptr; 36 | bool active = false; 37 | int v4l2_fd = 0; 38 | int width = 0; 39 | int height = 0; 40 | int frame_size = 0; 41 | uint32_t format = V4L2_PIX_FMT_YUYV; 42 | }; 43 | 44 | static inline enum video_format v4l2_to_obs_video_format(uint_fast32_t format) 45 | { 46 | switch (format) { 47 | case V4L2_PIX_FMT_YVYU: return VIDEO_FORMAT_YVYU; 48 | case V4L2_PIX_FMT_YUYV: return VIDEO_FORMAT_YUY2; 49 | case V4L2_PIX_FMT_UYVY: return VIDEO_FORMAT_UYVY; 50 | case V4L2_PIX_FMT_NV12: return VIDEO_FORMAT_NV12; 51 | case V4L2_PIX_FMT_YUV420: return VIDEO_FORMAT_I420; 52 | case V4L2_PIX_FMT_YVU420: return VIDEO_FORMAT_I420; 53 | #ifdef V4L2_PIX_FMT_XBGR32 54 | case V4L2_PIX_FMT_XBGR32: return VIDEO_FORMAT_BGRX; 55 | #endif 56 | case V4L2_PIX_FMT_BGR32: return VIDEO_FORMAT_BGRA; 57 | #ifdef V4L2_PIX_FMT_ABGR32 58 | case V4L2_PIX_FMT_ABGR32: return VIDEO_FORMAT_BGRA; 59 | #endif 60 | default: return VIDEO_FORMAT_NONE; 61 | } 62 | } 63 | 64 | static inline uint32_t string_to_v4l2_format(const char* format) 65 | { 66 | if(strcmp(format, V4L2SINK_NV12)==0) 67 | return V4L2_PIX_FMT_NV12; 68 | else if(strcmp(format, V4L2SINK_YUV420)==0) 69 | return V4L2_PIX_FMT_YUV420; 70 | else if (strcmp(format, V4L2SINK_RGB32)==0) 71 | return V4L2_PIX_FMT_BGR32; 72 | else 73 | return V4L2_PIX_FMT_YUYV; 74 | } 75 | 76 | V4l2sinkProperties* prop; 77 | obs_output_t* v4l2_out; 78 | 79 | void v4l2sink_signal_init(const char *signal) 80 | { 81 | signal_handler_t *handler = v4l2sink_get_signal_handler(); 82 | signal_handler_add(handler,signal); 83 | } 84 | 85 | void v4l2sink_signal_stop(const char *msg, bool opening) 86 | { 87 | struct calldata call_data; 88 | calldata_init(&call_data); 89 | calldata_set_string(&call_data, "msg", msg); 90 | calldata_set_bool(&call_data,"opening",opening); 91 | signal_handler_t *handler = v4l2sink_get_signal_handler(); 92 | signal_handler_signal(handler, "v4l2close", &call_data); 93 | calldata_free(&call_data); 94 | } 95 | 96 | bool v4l2device_set_format(void *data,struct v4l2_format *format) 97 | { 98 | v4l2sink_data *out_data = (v4l2sink_data*)data; 99 | format->fmt.pix.width = out_data->width; 100 | format->fmt.pix.height = out_data->height; 101 | format->fmt.pix.pixelformat = out_data->format; 102 | format->fmt.pix.sizeimage = out_data->frame_size; 103 | return true; 104 | } 105 | 106 | int v4l2device_framesize(void *data) 107 | { 108 | v4l2sink_data *out_data = (v4l2sink_data*)data; 109 | switch(out_data->format){ 110 | 111 | case V4L2_PIX_FMT_YVYU: 112 | case V4L2_PIX_FMT_YUYV: 113 | case V4L2_PIX_FMT_UYVY: 114 | return out_data->width * out_data->height * 2; 115 | case V4L2_PIX_FMT_YUV420: 116 | case V4L2_PIX_FMT_YVU420: 117 | return out_data->width * out_data->height * 3 / 2; 118 | #ifdef V4L2_PIX_FMT_XBGR32 119 | case V4L2_PIX_FMT_XBGR32: 120 | #endif 121 | #ifdef V4L2_PIX_FMT_ABGR32 122 | case V4L2_PIX_FMT_ABGR32: 123 | #endif 124 | case V4L2_PIX_FMT_BGR32: 125 | return out_data->width * out_data->height * 4; 126 | } 127 | return 0; 128 | } 129 | 130 | int v4l2device_open(void *data) 131 | { 132 | v4l2sink_data *out_data = (v4l2sink_data*)data; 133 | struct v4l2_format v4l2_fmt; 134 | int width,height,ret = 0; 135 | struct v4l2_capability capability; 136 | enum video_format format; 137 | video_t *video = obs_output_video(out_data->output); 138 | 139 | obs_data_t *settings = obs_output_get_settings(out_data->output); 140 | out_data->v4l2_fd = open(obs_data_get_string(settings, "device_name") 141 | , O_RDWR); 142 | out_data->format = string_to_v4l2_format( 143 | obs_data_get_string(settings, "format")); 144 | out_data->frame_size = v4l2device_framesize(data); 145 | obs_data_release(settings); 146 | 147 | if(out_data->v4l2_fd < 0){ 148 | printf("v4l2 device open fail\n"); 149 | return V4L2SINK_ERROR_OPEN; 150 | } 151 | 152 | if (ioctl(out_data->v4l2_fd, VIDIOC_QUERYCAP, &capability) < 0){ 153 | printf("v4l2 device qureycap fail\n"); 154 | return V4L2SINK_ERROR_FORMAT; 155 | } 156 | 157 | v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 158 | ret = ioctl(out_data->v4l2_fd, VIDIOC_G_FMT, &v4l2_fmt); 159 | 160 | if(ret<0){ 161 | printf("v4l2 device getformat fail\n"); 162 | return V4L2SINK_ERROR_FORMAT; 163 | } 164 | 165 | v4l2device_set_format(data,&v4l2_fmt); 166 | ret = ioctl(out_data->v4l2_fd, VIDIOC_S_FMT, &v4l2_fmt); 167 | 168 | if(ret<0){ 169 | printf("v4l2 device setformat fail\n"); 170 | return V4L2SINK_ERROR_FORMAT; 171 | } 172 | 173 | ret = ioctl(out_data->v4l2_fd, VIDIOC_G_FMT, &v4l2_fmt); 174 | 175 | if(ret<0){ 176 | printf("v4l2 device getformat fail\n"); 177 | return V4L2SINK_ERROR_FORMAT; 178 | } 179 | 180 | if(out_data->format != v4l2_fmt.fmt.pix.pixelformat){ 181 | printf("v4l2 format not support\n"); 182 | return V4L2SINK_ERROR_FORMAT; 183 | } 184 | 185 | 186 | width = (int32_t)obs_output_get_width(out_data->output); 187 | height = (int32_t)obs_output_get_height(out_data->output); 188 | format = v4l2_to_obs_video_format(v4l2_fmt.fmt.pix.pixelformat); 189 | 190 | if(format == VIDEO_FORMAT_NONE){ 191 | printf("v4l2 conversion format not support\n"); 192 | return V4L2SINK_ERROR_FORMAT; 193 | } 194 | 195 | if(width!= v4l2_fmt.fmt.pix.width || 196 | height!= v4l2_fmt.fmt.pix.height || 197 | format!= video_output_get_format(video)){ 198 | struct video_scale_info conv; 199 | conv.format = format; 200 | conv.width = v4l2_fmt.fmt.pix.width; 201 | conv.height = v4l2_fmt.fmt.pix.height; 202 | out_data->frame_size = v4l2_fmt.fmt.pix.sizeimage; 203 | obs_output_set_video_conversion(out_data->output,&conv); 204 | } 205 | else 206 | obs_output_set_video_conversion(out_data->output,NULL); 207 | 208 | return V4L2SINK_SUCCESS_OPEN; 209 | } 210 | 211 | 212 | 213 | static void v4l2device_close(void *data) 214 | { 215 | v4l2sink_data *out_data = (v4l2sink_data*)data; 216 | close(out_data->v4l2_fd); 217 | } 218 | 219 | static const char *v4l2sink_getname(void *unused) 220 | { 221 | UNUSED_PARAMETER(unused); 222 | return obs_module_text("V4l2sink"); 223 | } 224 | 225 | static void v4l2sink_destroy(void *data) 226 | { 227 | v4l2sink_data *out_data = (v4l2sink_data*)data; 228 | if (out_data){ 229 | bfree(out_data); 230 | } 231 | } 232 | static void *v4l2sink_create(obs_data_t *settings, obs_output_t *output) 233 | { 234 | v4l2sink_data *data = (v4l2sink_data *)bzalloc(sizeof( 235 | struct v4l2sink_data)); 236 | data->output = output; 237 | UNUSED_PARAMETER(settings); 238 | return data; 239 | } 240 | 241 | static bool v4l2sink_start(void *data) 242 | { 243 | v4l2sink_data *out_data = (v4l2sink_data*)data; 244 | out_data->width = (int32_t)obs_output_get_width(out_data->output); 245 | out_data->height = (int32_t)obs_output_get_height(out_data->output); 246 | int ret = v4l2device_open(data); 247 | 248 | if(ret!= V4L2SINK_SUCCESS_OPEN){ 249 | switch (ret) { 250 | case V4L2SINK_ERROR_OPEN: 251 | v4l2sink_signal_stop("device open failed", true); 252 | break; 253 | case V4L2SINK_ERROR_FORMAT: 254 | v4l2sink_signal_stop("format not support", true); 255 | break; 256 | default: 257 | v4l2sink_signal_stop("device open failed", true); 258 | } 259 | return false; 260 | } 261 | 262 | if(!obs_output_can_begin_data_capture(out_data->output,0)){ 263 | v4l2sink_signal_stop("start failed", true); 264 | return false; 265 | } 266 | 267 | out_data->active = true; 268 | return obs_output_begin_data_capture(out_data->output, 0); 269 | } 270 | 271 | static void v4l2sink_stop(void *data, uint64_t ts) 272 | { 273 | v4l2sink_data *out_data = (v4l2sink_data*)data; 274 | 275 | if(out_data->active){ 276 | out_data->active = false; 277 | obs_output_end_data_capture(out_data->output); 278 | v4l2device_close(data); 279 | v4l2sink_signal_stop("stop", false); 280 | } 281 | 282 | } 283 | 284 | obs_properties_t* v4l2sink_getproperties(void *data) 285 | { 286 | UNUSED_PARAMETER(data); 287 | 288 | obs_properties_t* props = obs_properties_create(); 289 | obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE); 290 | 291 | obs_properties_add_text(props, "v4l2sink_name", 292 | obs_module_text("V4l2sink.name"), OBS_TEXT_DEFAULT); 293 | return props; 294 | } 295 | 296 | static void v4l2sink_videotick(void *param, struct video_data *frame) 297 | { 298 | v4l2sink_data *out_data = (v4l2sink_data*)param; 299 | if(out_data->active){ 300 | size_t bytes = write(out_data->v4l2_fd, frame->data[0], 301 | out_data->frame_size); 302 | } 303 | } 304 | 305 | struct obs_output_info create_output_info() 306 | { 307 | struct obs_output_info output_info = {}; 308 | output_info.id = "v4l2sink"; 309 | output_info.flags = OBS_OUTPUT_VIDEO; 310 | output_info.get_name = v4l2sink_getname; 311 | output_info.create = v4l2sink_create; 312 | output_info.destroy = v4l2sink_destroy; 313 | output_info.start = v4l2sink_start; 314 | output_info.stop = v4l2sink_stop; 315 | output_info.raw_video = v4l2sink_videotick; 316 | output_info.get_properties = v4l2sink_getproperties; 317 | return output_info; 318 | } 319 | 320 | OBS_DECLARE_MODULE() 321 | OBS_MODULE_USE_DEFAULT_LOCALE("v4l2sink", "en-US") 322 | 323 | bool obs_module_load(void) 324 | { 325 | obs_output_info v4l2sink_info = create_output_info(); 326 | obs_register_output(&v4l2sink_info); 327 | obs_data_t *settings = obs_data_create(); 328 | v4l2_out = obs_output_create("v4l2sink", "V4l2sink",settings, NULL); 329 | obs_data_release(settings); 330 | v4l2sink_signal_init("void v4l2close(string msg, bool opening)"); 331 | 332 | QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window(); 333 | QAction *action = (QAction*)obs_frontend_add_tools_menu_qaction( 334 | obs_module_text("V4l2sink")); 335 | 336 | obs_frontend_push_ui_translation(obs_module_get_string); 337 | prop = new V4l2sinkProperties(main_window); 338 | obs_frontend_pop_ui_translation(); 339 | 340 | auto menu_cb = [] 341 | { 342 | prop->setVisible(!prop->isVisible()); 343 | }; 344 | 345 | action->connect(action, &QAction::triggered, menu_cb); 346 | 347 | return true; 348 | } 349 | 350 | void obs_module_unload() 351 | { 352 | } 353 | 354 | void v4l2sink_release() 355 | { 356 | obs_output_stop(v4l2_out); 357 | obs_output_release(v4l2_out); 358 | } 359 | 360 | void v4l2sink_enable(const char *dev_name, const char *format) 361 | { 362 | obs_data_t *settings = obs_output_get_settings(v4l2_out); 363 | obs_data_set_string(settings, "device_name", dev_name); 364 | obs_data_set_string(settings, "format", format); 365 | obs_output_update(v4l2_out,settings); 366 | obs_data_release(settings); 367 | obs_output_start(v4l2_out); 368 | } 369 | 370 | void v4l2sink_disable() 371 | { 372 | obs_output_stop(v4l2_out); 373 | } 374 | 375 | signal_handler_t* v4l2sink_get_signal_handler() 376 | { 377 | return obs_output_get_signal_handler(v4l2_out); 378 | } 379 | -------------------------------------------------------------------------------- /src/v4l2sink.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | obs-v4l2sink 3 | Copyright (C) 2018 by CatxFish 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | ******************************************************************************/ 15 | 16 | #ifndef V4L2SINK_H 17 | #define V4L2SINK_H 18 | #include 19 | void v4l2sink_enable(const char *dev_name, const char *format); 20 | void v4l2sink_disable(); 21 | void v4l2sink_release(); 22 | signal_handler_t* v4l2sink_get_signal_handler(); 23 | #endif // V4L2SINK_H 24 | -------------------------------------------------------------------------------- /src/v4l2sinkproperties.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | obs-v4l2sink 3 | Copyright (C) 2018 by CatxFish 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | ******************************************************************************/ 15 | 16 | #include "v4l2sinkproperties.h" 17 | #include "ui_v4l2sinkproperties.h" 18 | #include 19 | #include 20 | 21 | V4l2sinkProperties::V4l2sinkProperties(QWidget *parent) : 22 | QDialog(parent), 23 | ui(new Ui::V4l2sinkProperties) 24 | { 25 | ui->setupUi(this); 26 | connect(ui->pushButton_start,SIGNAL(clicked(bool)), this, SLOT(onStart())); 27 | connect(ui->pushButton_stop,SIGNAL(clicked(bool)), this, SLOT(onStop())); 28 | 29 | config_t* config = obs_frontend_get_global_config(); 30 | config_set_default_bool(config, "V4l2sink", "AutoStart", false); 31 | config_set_default_string(config, "V4l2sink", "DevicePath", "/dev/video0"); 32 | config_set_default_string(config, "V4l2sink", "Format", V4L2SINK_YUV420); 33 | 34 | bool autostart = config_get_bool(config, "V4l2sink", "AutoStart"); 35 | const char* device = config_get_string(config, "V4l2sink", "DevicePath"); 36 | const char* format = config_get_string(config, "V4l2sink", "Format"); 37 | 38 | ui->checkBox_auto->setChecked(autostart); 39 | ui->lineEdit_dev->setText(device); 40 | 41 | ui->comboBox_format->addItem(V4L2SINK_YUV420, V4L2SINK_YUV420); 42 | ui->comboBox_format->addItem(V4L2SINK_NV12, V4L2SINK_NV12); 43 | ui->comboBox_format->addItem(V4L2SINK_YUY2, V4L2SINK_YUY2); 44 | ui->comboBox_format->addItem(V4L2SINK_RGB32, V4L2SINK_RGB32); 45 | ui->comboBox_format->setCurrentIndex( 46 | ui->comboBox_format->findText(format)); 47 | 48 | ui->label_warning->setStyleSheet("QLabel { color : red; }"); 49 | enableStart(true); 50 | 51 | if(autostart) 52 | onStart(); 53 | 54 | } 55 | 56 | V4l2sinkProperties::~V4l2sinkProperties() 57 | { 58 | saveSettings(); 59 | v4l2sink_release(); 60 | delete ui; 61 | } 62 | 63 | void V4l2sinkProperties::closeEvent(QCloseEvent *event) 64 | { 65 | saveSettings(); 66 | } 67 | 68 | void V4l2sinkProperties::saveSettings() 69 | { 70 | bool autostart = ui->checkBox_auto->isChecked(); 71 | QByteArray ba_dev_name = ui->lineEdit_dev->text().toUtf8(); 72 | QByteArray ba_format = ui->comboBox_format->currentData().toString(). 73 | toUtf8(); 74 | config_t* config = obs_frontend_get_global_config(); 75 | if(config){ 76 | config_set_bool(config, "V4l2sink", "AutoStart", autostart); 77 | config_set_string(config, "V4l2sink", "DevicePath", 78 | ba_dev_name.constData()); 79 | config_set_string(config, "V4l2sink", "Format", 80 | ba_format.constData()); 81 | } 82 | 83 | } 84 | void V4l2sinkProperties::onStart() 85 | { 86 | QByteArray ba_format = ui->comboBox_format->currentData().toString() 87 | .toUtf8(); 88 | QByteArray ba_dev_name = ui->lineEdit_dev->text().toUtf8(); 89 | signal_handler_t *handler = v4l2sink_get_signal_handler(); 90 | signal_handler_connect(handler, "v4l2close", output_stopped , this); 91 | enableStart(false); 92 | setWarningText(""); 93 | saveSettings(); 94 | v4l2sink_enable(ba_dev_name.constData(), ba_format.constData()); 95 | } 96 | 97 | void V4l2sinkProperties::onStop() 98 | { 99 | v4l2sink_disable(); 100 | } 101 | 102 | void V4l2sinkProperties::enableStart(bool enable) 103 | { 104 | ui->pushButton_start->setEnabled(enable); 105 | ui->pushButton_stop->setEnabled(!enable); 106 | } 107 | 108 | void V4l2sinkProperties::setWarningText(const char *msg) 109 | { 110 | ui->label_warning->setText(msg); 111 | } 112 | 113 | static void output_stopped(void *data, calldata_t *cd) 114 | { 115 | auto page = (V4l2sinkProperties*) data; 116 | auto output = (obs_output_t*) calldata_ptr(cd, "output"); 117 | bool opening = calldata_bool(cd, "opening"); 118 | const char* msg = calldata_string(cd, "msg"); 119 | 120 | if (opening) 121 | page->setWarningText(msg); 122 | 123 | signal_handler_t *handler = obs_output_get_signal_handler(output); 124 | page->enableStart(true); 125 | signal_handler_disconnect(handler, "v4l2close", output_stopped , page); 126 | } 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/v4l2sinkproperties.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | obs-v4l2sink 3 | Copyright (C) 2018 by CatxFish 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program. If not, see . 14 | ******************************************************************************/ 15 | 16 | #ifndef V4L2SINKPROPERTIES_H 17 | #define V4L2SINKPROPERTIES_H 18 | 19 | #include 20 | #include "v4l2sink.h" 21 | 22 | #define V4L2SINK_NV12 "NV12" 23 | #define V4L2SINK_YUV420 "YUV420" 24 | #define V4L2SINK_YUY2 "YUY2" 25 | #define V4L2SINK_RGB32 "RGB32" 26 | 27 | 28 | namespace Ui { 29 | class V4l2sinkProperties; 30 | } 31 | 32 | class V4l2sinkProperties : public QDialog 33 | { 34 | Q_OBJECT 35 | 36 | public: 37 | explicit V4l2sinkProperties(QWidget *parent = 0); 38 | ~V4l2sinkProperties(); 39 | void enableStart(bool enable); 40 | void setWarningText(const char *msg); 41 | void closeEvent(QCloseEvent *event); 42 | void saveSettings(); 43 | 44 | private Q_SLOTS: 45 | void onStart(); 46 | void onStop(); 47 | 48 | private: 49 | Ui::V4l2sinkProperties *ui; 50 | }; 51 | 52 | static void output_started(void *data, calldata_t *cd); 53 | static void output_stopped(void *data, calldata_t *cd); 54 | 55 | 56 | #endif // V4L2SINKPROPERTIES_H 57 | -------------------------------------------------------------------------------- /src/v4l2sinkproperties.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | V4l2sinkProperties 4 | 5 | 6 | 7 | 0 8 | 0 9 | 455 10 | 227 11 | 12 | 13 | 14 | V4l2sinkProperties 15 | 16 | 17 | 18 | 19 | 230 20 | 180 21 | 89 22 | 25 23 | 24 | 25 | 26 | Start 27 | 28 | 29 | 30 | 31 | 32 | 330 33 | 180 34 | 89 35 | 25 36 | 37 | 38 | 39 | Stop 40 | 41 | 42 | 43 | 44 | 45 | 42 46 | 43 47 | 381 48 | 114 49 | 50 | 51 | 52 | 53 | 54 | 55 | AutoStart 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Device 67 | 68 | 69 | 70 | 71 | 72 | 73 | Format 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | /dev/video0 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | --------------------------------------------------------------------------------