Skip to content

Commit

Permalink
Merge pull request #573 from bsmiles32/vcap
Browse files Browse the repository at this point in the history
Rework Video Capture backend to allow better isolation.
  • Loading branch information
richard42 authored Jul 29, 2018
2 parents 77a2f88 + 156b78a commit 2c66c25
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 183 deletions.
18 changes: 4 additions & 14 deletions projects/VisualStudio2013/mupen64plus-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
<ClCompile Include="..\..\src\api\debugger.c" />
<ClCompile Include="..\..\src\api\frontend.c" />
<ClCompile Include="..\..\src\api\vidext.c" />
<ClCompile Include="..\..\src\backends\api\video_capture_backend.c" />
<ClCompile Include="..\..\src\backends\plugins_compat\input_plugin_compat.c" />
<ClCompile Include="..\..\src\backends\plugins_compat\audio_plugin_compat.c" />
<ClCompile Include="..\..\src\backends\clock_ctime_plus_delta.c" />
<ClCompile Include="..\..\src\backends\dummy_video_capture.c" />
<ClCompile Include="..\..\src\backends\file_storage.c" />
<ClCompile Include="..\..\src\backends\opencv_video_backend.cpp">
<ClCompile Include="..\..\src\backends\opencv_video_capture.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Debug|Win32'">true</ExcludedFromBuild>
Expand All @@ -55,7 +57,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\backends\dummy_video_backend.c" />
<ClCompile Include="..\..\src\debugger\dbg_breakpoints.c" />
<ClCompile Include="..\..\src\debugger\dbg_debugger.c" />
<ClCompile Include="..\..\src\debugger\dbg_decoder.c" />
Expand Down Expand Up @@ -266,20 +267,9 @@
<ClInclude Include="..\..\src\backends\api\joybus.h" />
<ClInclude Include="..\..\src\backends\api\rumble_backend.h" />
<ClInclude Include="..\..\src\backends\api\storage_backend.h" />
<ClInclude Include="..\..\src\backends\api\video_backend.h" />
<ClInclude Include="..\..\src\backends\api\video_capture_backend.h" />
<ClInclude Include="..\..\src\backends\clock_ctime_plus_delta.h" />
<ClInclude Include="..\..\src\backends\file_storage.h" />
<ClInclude Include="..\..\src\backends\opencv_video_backend.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='New_Dynarec_Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\..\src\backends\dummy_video_backend.h" />
<ClInclude Include="..\..\src\backends\plugins_compat\plugins_compat.h" />
<ClInclude Include="..\..\src\api\vidext_sdl2_compat.h" />
<ClInclude Include="..\..\src\debugger\dbg_breakpoints.h" />
Expand Down
15 changes: 6 additions & 9 deletions projects/VisualStudio2013/mupen64plus-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@
<ClCompile Include="..\..\src\backends\clock_ctime_plus_delta.c">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\dummy_video_backend.c">
<ClCompile Include="..\..\src\backends\dummy_video_capture.c">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\opencv_video_backend.cpp">
<ClCompile Include="..\..\src\backends\opencv_video_capture.cpp">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\device\dd\dd_controller.c">
Expand Down Expand Up @@ -300,6 +300,9 @@
<ClCompile Include="..\..\src\device\pif\bootrom_hle.c">
<Filter>device\pif</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\api\video_capture_backend.c">
<Filter>backends</Filter>
</ClCompile>
<ClCompile Include="..\..\src\backends\plugins_compat\audio_plugin_compat.c">
<Filter>backends\plugins_compat</Filter>
</ClCompile>
Expand Down Expand Up @@ -494,12 +497,6 @@
<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 @@ -635,7 +632,7 @@
<ClInclude Include="..\..\src\backends\api\storage_backend.h">
<Filter>backends\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\api\video_backend.h">
<ClInclude Include="..\..\src\backends\api\video_capture_backend.h">
<Filter>backends\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\backends\plugins_compat\plugins_compat.h">
Expand Down
5 changes: 3 additions & 2 deletions projects/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,12 @@ SOURCE = \
$(SRCDIR)/api/debugger.c \
$(SRCDIR)/api/frontend.c \
$(SRCDIR)/api/vidext.c \
$(SRCDIR)/backends/api/video_capture_backend.c \
$(SRCDIR)/backends/plugins_compat/audio_plugin_compat.c \
$(SRCDIR)/backends/plugins_compat/input_plugin_compat.c \
$(SRCDIR)/backends/clock_ctime_plus_delta.c \
$(SRCDIR)/backends/dummy_video_capture.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 @@ -629,7 +630,7 @@ ifeq ($(DEBUGGER), 1)
endif

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - dummy_video_backend.c *
* Mupen64plus - video_capture_backend.c *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2018 Bobby Smiles *
* *
Expand All @@ -19,28 +19,38 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

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

#include "api/m64p_types.h"
#include <string.h>

static m64p_error dummy_video_open(void* vin, unsigned int width, unsigned int height)
{
return M64ERR_SUCCESS;
}
/* exported video capture backends */
extern const struct video_capture_backend_interface g_idummy_video_capture_backend;
#if defined(M64P_OPENCV)
extern const struct video_capture_backend_interface g_iopencv_video_capture_backend;
#endif

static void dummy_video_close(void* vin)
{
}

static m64p_error dummy_grab_image(void* vin, void* data)
const struct video_capture_backend_interface* g_video_capture_backend_interfaces[] =
{
return M64ERR_UNSUPPORTED;
}
#if defined(M64P_OPENCV)
&g_iopencv_video_capture_backend,
#endif
&g_idummy_video_capture_backend,
NULL /* sentinel - must be last element */
};

const struct video_input_backend_interface g_idummy_video_input_backend =

const struct video_capture_backend_interface* get_video_capture_backend(const char* name)
{
dummy_video_open,
dummy_video_close,
dummy_grab_image
};
const struct video_capture_backend_interface** i;

/* passing NULL or empty string gives the dummy video input backend interface */
if (!name || strlen(name) == 0) { return &g_idummy_video_capture_backend; }

/* iterate through interfaces to find matching name */
for (i = g_video_capture_backend_interfaces; (*i) != NULL; ++i) {
if (strcmp((*i)->name, name) == 0) { return (*i); }
}

return NULL;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - video_backend.h *
* Mupen64plus - video_capture_backend.h *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2017 Bobby Smiles *
* *
Expand All @@ -19,13 +19,43 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_BACKENDS_API_VIDEO_BACKEND_H
#define M64P_BACKENDS_API_VIDEO_BACKEND_H
#ifndef M64P_BACKENDS_API_VIDEO_CAPTURE_BACKEND_H
#define M64P_BACKENDS_API_VIDEO_CAPTURE_BACKEND_H

#include "api/m64p_types.h"

struct video_input_backend_interface
/* Define default video capture backend
* if not defined by Makefile/msvc
*/
#if !defined(DEFAULT_VIDEO_CAPTURE_BACKEND)
#if defined(M64P_OPENCV)
#define DEFAULT_VIDEO_CAPTURE_BACKEND "opencv"
#else
#define DEFAULT_VIDEO_CAPTURE_BACKEND ""
#endif
#endif


struct video_capture_backend_interface
{
/* Backend class name.
* Must be unique.
*/
const char* name;

/* Initialize backend instance (*vin)
* using (when provided) parameters from config section.
*
* Returns M64ERR_SUCCESS on success.
*
* You must call corresponding release method to release any allocated resources.
*/
m64p_error (*init)(void** vin, const char* section);

/* Release backend instance and any associated resouces.
*/
void (*release)(void* vin);

/* Open a video stream with following properties (width, height)
* Returns M64ERR_SUCCESS on success.
*/
Expand All @@ -41,4 +71,10 @@ struct video_input_backend_interface
m64p_error (*grab_image)(void* vin, void* data);
};

/* collection of available video capture backends */
extern const struct video_capture_backend_interface* g_video_capture_backend_interfaces[];

/* helper function which find backend by name (or dummy when NULL/empty) */
const struct video_capture_backend_interface* get_video_capture_backend(const char* name);

#endif
29 changes: 0 additions & 29 deletions src/backends/dummy_video_backend.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus - opencv_video_backend.h *
* Mupen64plus - dummy_video_capture.c *
* Mupen64Plus homepage: https://mupen64plus.org/ *
* Copyright (C) 2017 Bobby Smiles *
* *
Expand All @@ -19,33 +19,66 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef M64P_BACKENDS_OPENCV_VIDEO_BACKEND_H
#define M64P_BACKENDS_OPENCV_VIDEO_BACKEND_H
#include "backends/api/video_capture_backend.h"

#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <string.h>

#include "backends/api/video_backend.h"
/* Dummy video capture backend
*
* Returns a black frame
*/
struct dummy_video_capture
{
/* BGR frame size (no stride) */
size_t size;
};

struct opencv_video_backend
static m64p_error dummy_init(void** vcap, const char* config)
{
char* device;
unsigned int width;
unsigned int height;
struct dummy_video_capture* dummy = malloc(sizeof(*dummy));
if (dummy == NULL) {
*vcap = NULL;
return M64ERR_NO_MEMORY;
}

/* using void* to avoid leaking C++ stuff in this header */
void* cap;
};
memset(dummy, 0, sizeof(*dummy));

#if 0
void cv_imshow(const char* name, unsigned int width, unsigned int height, int channels, void* data);
#endif
*vcap = dummy;
return M64ERR_SUCCESS;
}

extern const struct video_input_backend_interface g_iopencv_video_input_backend;
static void dummy_release(void* vcap)
{
free(vcap);
}

#ifdef __cplusplus
static m64p_error dummy_open(void* vcap, unsigned int width, unsigned int height)
{
struct dummy_video_capture* dummy = (struct dummy_video_capture*)vcap;
dummy->size = 3 * width * height;
return M64ERR_SUCCESS;
}
#endif

#endif
static void dummy_close(void* vcap)
{
struct dummy_video_capture* dummy = (struct dummy_video_capture*)vcap;
dummy->size = 0;
}

static m64p_error dummy_grab_image(void* vcap, void* data)
{
struct dummy_video_capture* dummy = (struct dummy_video_capture*)vcap;
memset(data, 0, dummy->size);
return M64ERR_SUCCESS;
}

const struct video_capture_backend_interface g_idummy_video_capture_backend =
{
"dummy",
dummy_init,
dummy_release,
dummy_open,
dummy_close,
dummy_grab_image
};
Loading

0 comments on commit 2c66c25

Please sign in to comment.