linux-v4l2.c 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>

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, see <http://www.gnu.org/licenses/>.
*/
#include <obs-module.h>
18
#include <util/platform.h>
19 20

OBS_DECLARE_MODULE()
J
jp9000 已提交
21
OBS_MODULE_USE_DEFAULT_LOCALE("linux-v4l2", "en-US")
22 23
MODULE_EXPORT const char *obs_module_description(void)
{
24
	return "Video4Linux2(V4L2) sources/virtual camera";
25
}
26 27

extern struct obs_source_info v4l2_input;
28 29 30 31 32 33
extern struct obs_output_info virtualcam_info;

static bool v4l2loopback_installed()
{
	bool loaded = false;

34
	int ret = system("modinfo v4l2loopback >/dev/null 2>&1");
35 36 37 38 39 40

	if (ret == 0)
		loaded = true;

	return loaded;
}
41

42
bool obs_module_load(void)
43 44
{
	obs_register_source(&v4l2_input);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

	obs_data_t *obs_settings = obs_data_create();

	if (v4l2loopback_installed()) {
		obs_register_output(&virtualcam_info);
		obs_data_set_bool(obs_settings, "vcamEnabled", true);
	} else {
		obs_data_set_bool(obs_settings, "vcamEnabled", false);
		blog(LOG_WARNING,
		     "v4l2loopback not installed, virtual camera disabled");
	}

	obs_apply_private_data(obs_settings);
	obs_data_release(obs_settings);

60 61
	return true;
}