summaryrefslogtreecommitdiffhomepage
path: root/video-ps3eye/PS3EYEDriver/sdl
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-05-05 12:34:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2019-05-06 03:42:13 +0200
commit6eda8a85b84c4e661a8763429ae1978f8da7f9dd (patch)
tree5169e1bf6779f7442235f36a206a91e224cda05d /video-ps3eye/PS3EYEDriver/sdl
parent12dfd6dcf60d9fefef7f8723fb9bc5a21fdb5b61 (diff)
video/ps3eye: WIP
Diffstat (limited to 'video-ps3eye/PS3EYEDriver/sdl')
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/CMakeLists.txt24
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/cmake/FindSDL2.cmake82
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/lang/nl_NL.ts4
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/lang/ru_RU.ts4
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/lang/stub.ts4
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/lang/zh_CN.ts4
-rw-r--r--video-ps3eye/PS3EYEDriver/sdl/main.cpp192
7 files changed, 247 insertions, 67 deletions
diff --git a/video-ps3eye/PS3EYEDriver/sdl/CMakeLists.txt b/video-ps3eye/PS3EYEDriver/sdl/CMakeLists.txt
new file mode 100644
index 00000000..5064b2d8
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(cmake-modules "${CMAKE_CURRENT_LIST_DIR}/cmake/")
+if(MSVC)
+ set(CMAKE_MODULE_PATH "${cmake-modules}" ${CMAKE_MODULE_PATH})
+else()
+ list(APPEND CMAKE_MODULE_PATH "${cmake-modules}")
+endif()
+
+find_package(SDL2 QUIET)
+if(SDL2_FOUND)
+ include_directories(${SDL2_INCLUDE_DIRS})
+ link_libraries(${SDL2_LIBRARIES})
+ link_libraries(opentrack-ps3eye)
+ otr_module(ps3eye-test EXECUTABLE NO-QT WIN32-CONSOLE)
+ if(WIN32)
+ foreach(k ${SDL2_LIBRARIES})
+ get_filename_component(path "${k}" PATH)
+ set(lib "${path}/SDL2.dll")
+ if(EXISTS "${lib}")
+ otr_install_lib("${lib}" "${opentrack-hier-pfx}")
+ break()
+ endif()
+ endforeach()
+ endif()
+endif()
diff --git a/video-ps3eye/PS3EYEDriver/sdl/cmake/FindSDL2.cmake b/video-ps3eye/PS3EYEDriver/sdl/cmake/FindSDL2.cmake
index 185d6e9e..e55e5849 100644
--- a/video-ps3eye/PS3EYEDriver/sdl/cmake/FindSDL2.cmake
+++ b/video-ps3eye/PS3EYEDriver/sdl/cmake/FindSDL2.cmake
@@ -1,8 +1,8 @@
# This module defines
-# SDL2_LIBRARY, the name of the library to link against
+# SDL2_LIBRARIES, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
-# SDL2_INCLUDE_DIR, where to find SDL.h
+# SDL2_INCLUDE_DIRS, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
@@ -76,12 +76,10 @@ SET(SDL2_SEARCH_PATHS
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
- ${SDL2_PATH}
+ ${SDL2_DIR}
)
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
- HINTS
- $ENV{SDL2DIR}
PATH_SUFFIXES include/SDL2 include
PATHS ${SDL2_SEARCH_PATHS}
)
@@ -89,10 +87,10 @@ FIND_PATH(SDL2_INCLUDE_DIR SDL.h
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PATH_SUFFIXES lib64 lib/x64 lib)
else()
- set(PATH_SUFFIXES lib/x86 lib)
+ set(PATH_SUFFIXES lib32 lib/x86 lib)
endif()
-FIND_LIBRARY(SDL2_LIBRARY_TEMP
+FIND_LIBRARY(SDL2_LIBRARY
NAMES SDL2
HINTS
$ENV{SDL2DIR}
@@ -100,44 +98,11 @@ FIND_LIBRARY(SDL2_LIBRARY_TEMP
PATHS ${SDL2_SEARCH_PATHS}
)
-IF(NOT SDL2_BUILDING_LIBRARY)
- IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
- # Non-OS X framework versions expect you to also dynamically link to
- # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
- # seem to provide SDL2main for compatibility even though they don't
- # necessarily need it.
- FIND_LIBRARY(SDL2MAIN_LIBRARY
- NAMES SDL2main
- HINTS
- $ENV{SDL2DIR}
- PATH_SUFFIXES ${PATH_SUFFIXES}
- PATHS ${SDL2_SEARCH_PATHS}
- )
- ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
-ENDIF(NOT SDL2_BUILDING_LIBRARY)
-
-# SDL2 may require threads on your system.
-# The Apple build may not need an explicit flag because one of the
-# frameworks may already provide it.
-# But for non-OSX systems, I will use the CMake Threads package.
-IF(NOT APPLE)
- FIND_PACKAGE(Threads)
-ENDIF(NOT APPLE)
-
-# MinGW needs an additional link flag, -mwindows
-# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
-IF(MINGW)
- SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
-ENDIF(MINGW)
-
-IF(SDL2_LIBRARY_TEMP)
- # For SDL2main
- IF(NOT SDL2_BUILDING_LIBRARY)
- IF(SDL2MAIN_LIBRARY)
- SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
- ENDIF(SDL2MAIN_LIBRARY)
- ENDIF(NOT SDL2_BUILDING_LIBRARY)
+if(SDL2_LIBRARY)
+ set(SDL2_LIBRARIES "${SDL2_LIBRARY}")
+endif()
+IF(SDL2_LIBRARIES)
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
@@ -145,30 +110,13 @@ IF(SDL2_LIBRARY_TEMP)
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
IF(APPLE)
- SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
+ list(APPEND SDL2_LIBRARIES "-framework Cocoa")
ENDIF(APPLE)
+ENDIF()
- # For threads, as mentioned Apple doesn't need this.
- # In fact, there seems to be a problem if I used the Threads package
- # and try using this line, so I'm just skipping it entirely for OS X.
- IF(NOT APPLE)
- SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
- ENDIF(NOT APPLE)
-
- # For MinGW library
- IF(MINGW)
- SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
- ENDIF(MINGW)
-
- # Set the final string here so the GUI reflects the final state.
- SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
- # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
- SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
-ENDIF(SDL2_LIBRARY_TEMP)
-
-# message("</FindSDL2.cmake>")
+if(SDL2_INCLUDE_DIR)
+ set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}")
+endif()
INCLUDE(FindPackageHandleStandardArgs)
-
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
-
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARIES SDL2_INCLUDE_DIRS)
diff --git a/video-ps3eye/PS3EYEDriver/sdl/lang/nl_NL.ts b/video-ps3eye/PS3EYEDriver/sdl/lang/nl_NL.ts
new file mode 100644
index 00000000..6401616d
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/lang/nl_NL.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1">
+</TS>
diff --git a/video-ps3eye/PS3EYEDriver/sdl/lang/ru_RU.ts b/video-ps3eye/PS3EYEDriver/sdl/lang/ru_RU.ts
new file mode 100644
index 00000000..6401616d
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/lang/ru_RU.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1">
+</TS>
diff --git a/video-ps3eye/PS3EYEDriver/sdl/lang/stub.ts b/video-ps3eye/PS3EYEDriver/sdl/lang/stub.ts
new file mode 100644
index 00000000..6401616d
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/lang/stub.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1">
+</TS>
diff --git a/video-ps3eye/PS3EYEDriver/sdl/lang/zh_CN.ts b/video-ps3eye/PS3EYEDriver/sdl/lang/zh_CN.ts
new file mode 100644
index 00000000..6401616d
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/lang/zh_CN.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1">
+</TS>
diff --git a/video-ps3eye/PS3EYEDriver/sdl/main.cpp b/video-ps3eye/PS3EYEDriver/sdl/main.cpp
new file mode 100644
index 00000000..6a5f3482
--- /dev/null
+++ b/video-ps3eye/PS3EYEDriver/sdl/main.cpp
@@ -0,0 +1,192 @@
+/**
+ * PS3EYEDriver Simple SDL 2 example, using OpenGL where available.
+ * Thomas Perl <m@thp.io>; 2014-01-10
+ * Joseph Howse <josephhowse@nummist.com>; 2014-12-26
+ **/
+
+#include "../ps3eye.hpp"
+#include "../log.hpp"
+
+#include <sstream>
+#include <iostream>
+
+#include <SDL.h>
+#undef main
+
+struct ps3eye_context {
+ ps3eye_context(int width, int height, int fps)
+ {
+ if (hasDevices())
+ {
+ eye = devices[0];
+ eye->init(width, height, (uint16_t)fps);
+ }
+ }
+
+ bool hasDevices() { return !devices.empty(); }
+
+ std::vector<ps3eye_camera::device> devices = ps3eye_camera::get_devices();
+ ps3eye_camera::device eye = nullptr;
+
+ bool running = true;
+ Uint32 last_ticks = 0;
+ Uint32 last_frames = 0;
+};
+
+void run_camera(int width, int height, int fps, Uint32 duration)
+{
+ ps3eye_context ctx(width, height, fps);
+ if (!ctx.hasDevices()) {
+ printf("No PS3 Eye ps3eye_camera connected\n");
+ return;
+ }
+ ctx.eye->set_flip(true); /* mirrored left-right */
+
+ char title[256];
+ sprintf(title, "%dx%d@%d\n", ctx.eye->getWidth(), ctx.eye->getHeight(), ctx.eye->getFrameRate());
+
+ SDL_Window *window = SDL_CreateWindow(
+ title, SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED, width, height, 0);
+ if (window == NULL) {
+ printf("Failed to create window: %s\n", SDL_GetError());
+ return;
+ }
+
+ SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
+ SDL_RENDERER_ACCELERATED);
+ if (renderer == NULL) {
+ printf("Failed to create renderer: %s\n", SDL_GetError());
+ SDL_DestroyWindow(window);
+ return;
+ }
+ SDL_RenderSetLogicalSize(renderer, ctx.eye->getWidth(), ctx.eye->getHeight());
+
+ SDL_Texture *video_tex = SDL_CreateTexture(
+ renderer, SDL_PIXELFORMAT_BGR24, SDL_TEXTUREACCESS_STREAMING,
+ ctx.eye->getWidth(), ctx.eye->getHeight());
+
+ if (video_tex == NULL)
+ {
+ printf("Failed to create video texture: %s\n", SDL_GetError());
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ return;
+ }
+
+ (void)ctx.eye->start();
+
+ printf("Camera mode: %dx%d@%d\n", ctx.eye->getWidth(), ctx.eye->getHeight(), ctx.eye->getFrameRate());
+
+ SDL_Event e;
+
+ Uint32 start_ticks = SDL_GetTicks();
+ while (ctx.running) {
+ if (duration != 0 && (SDL_GetTicks() - start_ticks) / 1000 >= duration)
+ break;
+
+ while (SDL_PollEvent(&e)) {
+ if (e.type == SDL_QUIT || (e.type == SDL_KEYUP && e.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) {
+ ctx.running = false;
+ }
+ }
+
+ {
+ Uint32 now_ticks = SDL_GetTicks();
+
+ ctx.last_frames++;
+
+ if (now_ticks - ctx.last_ticks > 1000)
+ {
+ printf("FPS: %.2f\n", 1000 * ctx.last_frames / (float(now_ticks - ctx.last_ticks)));
+ ctx.last_ticks = now_ticks;
+ ctx.last_frames = 0;
+ }
+ }
+
+ void *video_tex_pixels;
+ int pitch;
+ SDL_LockTexture(video_tex, NULL, &video_tex_pixels, &pitch);
+
+ if (!ctx.eye->get_frame((uint8_t*) video_tex_pixels))
+ ctx.running = false;
+
+ SDL_UnlockTexture(video_tex);
+
+ SDL_RenderCopy(renderer, video_tex, NULL, NULL);
+ SDL_RenderPresent(renderer);
+ }
+
+ ctx.eye->stop();
+
+ SDL_DestroyTexture(video_tex);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+}
+
+int main(int argc, char *argv[])
+{
+ bool mode_test = false;
+ int width = 640;
+ int height = 480;
+ int fps = 60;
+ if (argc > 1)
+ {
+ bool good_arg = false;
+ for (int arg_ix = 1; arg_ix < argc; ++arg_ix)
+ {
+ if (std::string(argv[arg_ix]) == "--qvga")
+ {
+ width = 320;
+ height = 240;
+ good_arg = true;
+ }
+
+ if ((std::string(argv[arg_ix]) == "--fps") && argc > arg_ix)
+ {
+ std::istringstream new_fps_ss( argv[arg_ix+1] );
+ if (new_fps_ss >> fps)
+ {
+ good_arg = true;
+ }
+ }
+
+ if (std::string(argv[arg_ix]) == "--mode_test")
+ {
+ mode_test = true;
+ good_arg = true;
+ }
+ }
+ if (!good_arg)
+ {
+ std::cerr << "Usage: " << argv[0] << " [--fps XX] [--qvga] [--mode_test]" << std::endl;
+ }
+ }
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ printf("Failed to initialize SDL: %s\n", SDL_GetError());
+ return EXIT_FAILURE;
+ }
+
+ if (mode_test)
+ {
+ int rates_qvga[] = { 2, 3, 5, 7, 10, 12, 15, 17, 30, 37, 40, 50, 60, 75, 90, 100, 125, 137, 150, 187 };
+ int num_rates_qvga = sizeof(rates_qvga) / sizeof(int);
+
+ int rates_vga[] = { 2, 3, 5, 8, 10, 15, 20, 25, 30, 40, 50, 60, 75 };
+ int num_rates_vga = sizeof(rates_vga) / sizeof(int);
+
+ for (int index = 0; index < num_rates_qvga; ++index)
+ run_camera(320, 240, rates_qvga[index], 5);
+
+ for (int index = 0; index < num_rates_vga; ++index)
+ run_camera(640, 480, rates_vga[index], 5);
+ }
+ else
+ {
+ run_camera(width, height, fps, 0);
+ }
+
+ return EXIT_SUCCESS;
+}
+