Skip to content

Commit

Permalink
Add support for GameBoy Camera
Browse files Browse the repository at this point in the history
All the reverse-engineering work comes from AntonioND [1].
A new video backend API has been added to grab video images.
By default, a dummy backend is provided.
However, an OpenCV based backend is also provided (if enabled at
compile-time with OPENCV=1).
Other implementation should be possible (GStreamer for instance ?) in
the future.

With the OpenCV backend, the video device selection can be done using
the Core parameter:

[Core]
GbCameraVideoDevice=<my_device>

Where <my_device> can be either an integer which represent the device
number (0 for default) or a string which specify the video device path.

Tested with 64DD Mario Talent Studio (Japan), a transfer pak plugged
in the first controller with a Japanese GameBoy camera. Also since the
core currently requires a cart ROM (even if should strictly be required)
I used Perfect Dark (Japan) to allow using the Transfer Pak. This is a
core/ui limitation not related to this PR.

[1] https://github.com/AntonioND/gbcam-rev-engineer
  • Loading branch information
bsmiles32 committed May 15, 2018
1 parent 462a40a commit 5f6f53a
Show file tree
Hide file tree
Showing 15 changed files with 812 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ addons:
- liblircclient-dev
- binutils-dev
- nasm
- libopencv-dev
env:
- OSD=0
- OSD=1
Expand Down Expand Up @@ -51,6 +52,7 @@ matrix:
- mxe-i686-w64-mingw32.shared-freetype
- mxe-i686-w64-mingw32.shared-libpng
- mxe-i686-w64-mingw32.shared-zlib
- mxe-i686-w64-mingw32.shared-opencv
- mxe-i686-w64-mingw32.shared-pkgconf
- nasm
script:
Expand All @@ -72,6 +74,7 @@ matrix:
- mxe-x86-64-w64-mingw32.shared-freetype
- mxe-x86-64-w64-mingw32.shared-libpng
- mxe-x86-64-w64-mingw32.shared-zlib
- mxe-x86-64-w64-mingw32.shared-opencv
- mxe-i686-w64-mingw32.shared-pkgconf
- nasm
script:
Expand Down
53 changes: 29 additions & 24 deletions projects/VisualStudio2013/mupen64plus-core.vcxproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions projects/VisualStudio2013/mupen64plus-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
<ClCompile Include="..\..\src\backends\clock_ctime_plus_delta.c">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\dummy_video_backend.c">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\opencv_video_backend.cpp">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\device\dd\dd_controller.c">
<Filter>device\dd</Filter>
</ClCompile>
Expand Down Expand Up @@ -485,6 +491,12 @@
<ClInclude Include="..\..\src\backends\clock_ctime_plus_delta.h">
<Filter>backends</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\dummy_video_backend.h">
<Filter>backends</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\opencv_video_backend.h">
<Filter>backends</Filter>
</ClInclude>
<ClInclude Include="..\..\src\device\dd\dd_controller.h">
<Filter>device\dd</Filter>
</ClInclude>
Expand Down Expand Up @@ -620,6 +632,9 @@
<ClInclude Include="..\..\src\backends\api\storage_backend.h">
<Filter>backends\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\api\video_backend.h">
<Filter>backends\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\plugins_compat\plugins_compat.h">
<Filter>backends\plugins_compat</Filter>
</ClInclude>
Expand Down
22 changes: 21 additions & 1 deletion projects/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ endif
CFLAGS += $(LIBPNG_CFLAGS)
LDLIBS += $(LIBPNG_LDLIBS)

ifeq ($(OPENCV), 1)
# OpenCV lib
ifeq ($(origin OPENCV_CFLAGS) $(origin OPENCV_LDLIBS), undefined undefined)
ifeq ($(shell $(PKG_CONFIG) --modversion opencv 2>/dev/null),)
$(error No OpenCV development libraries found!)
endif
OPENCV_CFLAGS += $(shell $(PKG_CONFIG) --cflags opencv)
OPENCV_LDLIBS += $(shell $(PKG_CONFIG) --libs opencv)
endif
CFLAGS += $(OPENCV_CFLAGS)
LDLIBS += $(OPENCV_LDLIBS)
endif

# test for presence of SDL
ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
SDL_CONFIG = $(CROSS_COMPILE)sdl2-config
Expand Down Expand Up @@ -446,6 +459,7 @@ SOURCE = \
$(SRCDIR)/backends/plugins_compat/input_plugin_compat.c \
$(SRCDIR)/backends/clock_ctime_plus_delta.c \
$(SRCDIR)/backends/file_storage.c \
$(SRCDIR)/backends/dummy_video_backend.c \
$(SRCDIR)/device/cart/cart.c \
$(SRCDIR)/device/cart/af_rtc.c \
$(SRCDIR)/device/cart/cart_rom.c \
Expand Down Expand Up @@ -613,6 +627,12 @@ ifeq ($(DEBUGGER), 1)
endif
endif

ifeq ($(OPENCV), 1)
SOURCE += $(SRCDIR)/backends/opencv_video_backend.cpp
CFLAGS += -DM64P_OPENCV
endif


# generate a list of object files to build, make a temporary directory for them
OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(filter %.c, $(SOURCE)))
OBJECTS += $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRCDIR)/asm_defines/asm_defines.c)
Expand Down Expand Up @@ -646,7 +666,7 @@ targets:
@echo " WARNFLAGS=flag == compiler warning levels (default: -Wall)"
@echo " PIC=(1|0) == Force enable/disable of position independent code"
@echo " OSD=(1|0) == Enable/disable build of OpenGL On-screen display"
@echo " NEW_DYNAREC=1 == Replace dynamic recompiler with Ari64's experimental dynarec"
@echo " OPENCV=1 == Enable OpenCV support"
@echo " POSTFIX=name == String added to the name of the the build (default: '')"
@echo " Install Options:"
@echo " PREFIX=path == install/uninstall prefix (default: /usr/local/)"
Expand Down
44 changes: 44 additions & 0 deletions src/backends/api/video_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - video_backend.h *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2017 Bobby Smiles *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_BACKENDS_API_VIDEO_BACKEND_H
#define M64P_BACKENDS_API_VIDEO_BACKEND_H

#include "api/m64p_types.h"

struct video_input_backend_interface
{
/* Open a video stream with following properties (width, height)
* Returns M64ERR_SUCCESS on success.
*/
m64p_error (*open)(void* vin, unsigned int width, unsigned int height);

/* Close a previsouly opened video stream.
*/
void (*close)(void* vin);

/* Grab a BGR image on an open stream
* Returns M64ERR_SUCCESS on success.
*/
m64p_error (*grab_image)(void* vin, void* data);
};

#endif
46 changes: 46 additions & 0 deletions src/backends/dummy_video_backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - dummy_video_backend.c *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2018 Bobby Smiles *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "backends/dummy_video_backend.h"
#include "backends/api/video_backend.h"

#include "api/m64p_types.h"

static m64p_error dummy_video_open(void* vin, unsigned int width, unsigned int height)
{
return M64ERR_SUCCESS;
}

static void dummy_video_close(void* vin)
{
}

static m64p_error dummy_grab_image(void* vin, void* data)
{
return M64ERR_UNSUPPORTED;
}

const struct video_input_backend_interface g_idummy_video_input_backend =
{
dummy_video_open,
dummy_video_close,
dummy_grab_image
};
29 changes: 29 additions & 0 deletions src/backends/dummy_video_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - dummy_video_backend.h *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2018 Bobby Smiles *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_BACKENDS_DUMMY_VIDEO_BACKEND_H
#define M64P_BACKENDS_DUMMY_VIDEO_BACKEND_H

#include "api/video_backend.h"

extern const struct video_input_backend_interface g_idummy_video_input_backend;

#endif
Loading

0 comments on commit 5f6f53a

Please sign in to comment.