emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.63k stars 3.29k forks source link

Porting v4l2 #19894

Open mjaafa opened 1 year ago

mjaafa commented 1 year ago

Please include the following in your bug report:

Version of emscripten/emsdk: master

Failing command line in full: cmake_minimum_required (VERSION 3.10) project (smart_opengl)

find_package(PkgConfig) if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") set(USE_FLAGS "--bind -s WASM=1 -s USE_SDL=2 -s USE_FREETYPE=1 ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}") set(CMAKE_EXECUTABLE_SUFFIX .html) else() pkg_check_modules(PC_SDL REQUIRED sdl2) pkg_check_modules(PC_CGAL REQUIRED libv4l2) pkg_check_modules(PC_OPENGL REQUIRED opengl) pkg_check_modules(PC_SDL REQUIRED glut)

endif()

pkg_check_modules(PC_CGAL REQUIRED gl1-mesa)

pkg_check_modules(OPENGL REQUIRED opengl)

pkg_check_modules(GL REQUIRED gl)

find_package(CGAL REQUIRED)

find_package(Threads REQUIRED)

set(CMAKE_CXX_COMPILER "em++")

set(EMSCRIPTEN_PATH "/home/momo/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" CACHE PATH "Path to Emscripten toolchain file") set(EMCC_DEBUG 1)

set (SMART_OPENGL_VERSION_MAJOR 0) set (SMART_OPENGL_VERSION_MINOR 1) set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fsanitize=address,undefined -Wformat -Werror=format-security -Werror=array-bounds -D_FORTIFY_SOURCE=2 -fstack-protector-all -fstack-protector-strong -D_REENTRANT")

add_compile_options("-D_REENTRANT -g -fpermissive") link_libraries("-D_REENTRANT")

configure_file ( "${PROJECT_SOURCE_DIR}/smart_opengl.h.in" "${PROJECT_BINARY_DIR}/smart_opengl.h" )

MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} " PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PC_PTHREAD_INCLUDE_DIRS} ${PC_SDL_INCLUDE_DIRS} ${PC_CGAL_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ${GL_INCLUDE_DIRS})

add_executable(smart_sdl camera.cpp) #test.image.cpp) #PixelPusher.cpp) target_link_libraries(smart_sdl -lSDL2)

target_link_libraries(smart_sdl ${PC_PTHREAD_LIBRARY} ${PC_GLFW_LIBRARY} ${PC_CGAL_LIBRARY} ${OPENGL_LIBRARY_DIRS} ${GL_LIBRARY_DIRS} -lpng -lGL -lGLU -lglfw -lX11 -ldl -lglut) if( ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") set_target_properties(smart_sdl PROPERTIES SUFFIX ".html" LINK_FLAGS "-s NO_EXIT_RUNTIME=1 -s OFFSCREEN_FRAMEBUFFER=1 -s USE_GLFW=3 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=[\"png\"] -s EXPORTED_RUNTIME_METHODS=\"['cwrap', 'ccall']\" -s USE_SDL=2 -s USE_SDL_MIXER=2 -s USE_SDL_TTF=2 -s ALLOW_MEMORY_GROWTH=1 --std=c++17 --no-check-features" ) endif() install (TARGETS smart_sdl DESTINATION bin) install (FILES ${PROJECT_BINARY_DIR}/smart_opengl.h DESTINATION include)

Full link command and output with -v appended: /usr/bin/cmake -S/media/momo/UFDRecovery/cam-v4l2 -B/media/momo/UFDRecovery/cam-v4l2/build --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /media/momo/UFDRecovery/cam-v4l2/build/CMakeFiles /media/momo/UFDRecovery/cam-v4l2/build//CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/media/momo/UFDRecovery/cam-v4l2/build' make -f CMakeFiles/smart_sdl.dir/build.make CMakeFiles/smart_sdl.dir/depend make[2]: Entering directory '/media/momo/UFDRecovery/cam-v4l2/build' cd /media/momo/UFDRecovery/cam-v4l2/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /media/momo/UFDRecovery/cam-v4l2 /media/momo/UFDRecovery/cam-v4l2 /media/momo/UFDRecovery/cam-v4l2/build /media/momo/UFDRecovery/cam-v4l2/build /media/momo/UFDRecovery/cam-v4l2/build/CMakeFiles/smart_sdl.dir/DependInfo.cmake --color= make[2]: Leaving directory '/media/momo/UFDRecovery/cam-v4l2/build' make -f CMakeFiles/smart_sdl.dir/build.make CMakeFiles/smart_sdl.dir/build make[2]: Entering directory '/media/momo/UFDRecovery/cam-v4l2/build' [ 50%] Building CXX object CMakeFiles/smart_sdl.dir/camera.cpp.o /home/momo/emsdk/upstream/emscripten/em++ @CMakeFiles/smart_sdl.dir/includes_CXX.rsp --bind -s WASM=1 -s USE_SDL=2 -s USE_FREETYPE=1 "-D_REENTRANT -g -fpermissive" -MD -MT CMakeFiles/smart_sdl.dir/camera.cpp.o -MF CMakeFiles/smart_sdl.dir/camera.cpp.o.d -o CMakeFiles/smart_sdl.dir/camera.cpp.o -c /media/momo/UFDRecovery/cam-v4l2/camera.cpp em++: warning: linker setting ignored during compilation: 'WASM' [-Wunused-command-line-argument] em++: warning: linker flag ignored during compilation: '--bind' [-Wunused-command-line-argument] /media/momo/UFDRecovery/cam-v4l2/camera.cpp:47:10: fatal error: 'linux/videodev2.h' file not found 47 | #include <linux/videodev2.h> | ^~~~~~~ 1 error generated. em++: error: '/home/momo/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -I/home/momo/emsdk/upstream/emscripten/cache/sysroot/include/SDL2 -I/home/momo/emsdk/upstream/emscripten/cache/sysroot/include/freetype2 --sysroot=/home/momo/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I/media/momo/UFDRecovery/cam-v4l2/build -I/media/momo/UFDRecovery/cam-v4l2 "-D_REENTRANT -g -fpermissive" -MD -MT CMakeFiles/smart_sdl.dir/camera.cpp.o -MF CMakeFiles/smart_sdl.dir/camera.cpp.o.d -c /media/momo/UFDRecovery/cam-v4l2/camera.cpp -o CMakeFiles/smart_sdl.dir/camera.cpp.o' failed (returned 1) make[2]: [CMakeFiles/smart_sdl.dir/build.make:80: CMakeFiles/smart_sdl.dir/camera.cpp.o] Error 1 make[2]: Leaving directory '/media/momo/UFDRecovery/cam-v4l2/build' make[1]: [CMakeFiles/Makefile2:86: CMakeFiles/smart_sdl.dir/all] Error 2 make[1]: Leaving directory '/media/momo/UFDRecovery/cam-v4l2/build' make: *** [Makefile:139: all] Error 2

sbc100 commented 1 year ago

linux/videodev2.h looks like a very linux-specific header file that doesn't exist under emscripten. You need to find some way to avoid the dependency on that header, or provide some kind of dummy version of it.

mjaafa commented 1 year ago

If it s the case to provide a dummy version. It would make just a cork not working and doing the job. The problem I guess is that there is no interface for the moment is there a way to compile a library containing v4l2 then link with wasm

sbc100 commented 1 year ago

Yes, its seems extremely unlikely that v4l would work on emscripten since the whole point of v4l (IIRC) is that it uses some kind of underlying kernel/hardware features and will not run inside the WebAssembly sandbox.

Assuming that answers you question perhaps this issue can now be closed?

mjaafa commented 1 year ago

The opengl and specifically EGL has kernel hardware feature. It s useful to have v4l2 supported

sbc100 commented 1 year ago

But unlike opengl and EGL I don't think there is any kind of open standard for v4l. Its linux-specific. I suppose it might be possible to create an implementation based on WebCodecs or some other existing web platform feature, but its sounds like large project. At the same time I'm not sure how much code bases there are out there that would benefit from such an implementation. If you would like to take a stab at it I suggest you take a look at WebCodecs and see if it looks like it might be a good fit: https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API

mjaafa commented 1 year ago

V4l2 is away to handle the camera hardware and make it easy to grap frames. Thank you for the link. But it s better for me to have a support for v4l2 and make it easy to have mapped memory from kernel.

sbc100 commented 1 year ago

I'm afraid such things are not really feasible given the WebAssembly sandbox or the Web Platform. There is no access to mapped pages in WebAssembly and also no access or OS-specific features like this.