Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
尘离序散
obs-studio
提交
73e62a21
O
obs-studio
项目概览
尘离序散
/
obs-studio
与 Fork 源项目一致
从无法访问的项目Fork
通知
30
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
obs-studio
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
73e62a21
编写于
12月 18, 2019
作者:
J
Jim
提交者:
GitHub
12月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1815 from grimmy/v4l-controls
linux-v4l2: add support for controls
上级
2a1a76b3
cbe17913
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
198 addition
and
0 deletion
+198
-0
plugins/linux-v4l2/CMakeLists.txt
plugins/linux-v4l2/CMakeLists.txt
+1
-0
plugins/linux-v4l2/v4l2-controls.c
plugins/linux-v4l2/v4l2-controls.c
+155
-0
plugins/linux-v4l2/v4l2-controls.h
plugins/linux-v4l2/v4l2-controls.h
+40
-0
plugins/linux-v4l2/v4l2-input.c
plugins/linux-v4l2/v4l2-input.c
+2
-0
未找到文件。
plugins/linux-v4l2/CMakeLists.txt
浏览文件 @
73e62a21
...
...
@@ -31,6 +31,7 @@ include_directories(
set
(
linux-v4l2_SOURCES
linux-v4l2.c
v4l2-controls.c
v4l2-input.c
v4l2-helpers.c
${
linux-v4l2-udev_SOURCES
}
...
...
plugins/linux-v4l2/v4l2-controls.c
0 → 100644
浏览文件 @
73e62a21
/*
Copyright (C) 2019 by Gary Kramlich <grim@reaperworld.com>
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 <fcntl.h>
#include <linux/videodev2.h>
#include <libv4l2.h>
#include "v4l2-controls.h"
#define blog(level, msg, ...) blog(level, "v4l2-controls: " msg, ##__VA_ARGS__)
#if defined(__i386__)
#define UINT_TO_POINTER(val) ((void *)(unsigned int)(val))
#define POINTER_TO_UINT(p) ((unsigned int)(unsigned int)(p))
#elif defined(__x86_64__)
#define UINT_TO_POINTER(val) ((void *)(unsigned long)(val))
#define POINTER_TO_UINT(p) ((unsigned int)(unsigned long)(p))
#else
#error "unknown platform, this code won't work"
#endif
static
bool
v4l2_control_changed
(
void
*
data
,
obs_properties_t
*
props
,
obs_property_t
*
prop
,
obs_data_t
*
settings
)
{
int
dev
=
v4l2_open
(
obs_data_get_string
(
settings
,
"device_id"
),
O_RDWR
|
O_NONBLOCK
);
bool
ret
=
false
;
(
void
)
props
;
if
(
dev
==
-
1
)
return
false
;
struct
v4l2_control
control
;
control
.
id
=
POINTER_TO_UINT
(
data
);
control
.
value
=
obs_data_get_int
(
settings
,
obs_property_name
(
prop
));
if
(
0
!=
v4l2_ioctl
(
dev
,
VIDIOC_S_CTRL
,
&
control
))
{
ret
=
true
;
}
v4l2_close
(
dev
);
return
ret
;
}
static
int_fast32_t
v4l2_update_controls_menu
(
int_fast32_t
dev
,
obs_properties_t
*
props
,
struct
v4l2_queryctrl
*
qctrl
)
{
obs_property_t
*
prop
;
struct
v4l2_querymenu
qmenu
;
prop
=
obs_properties_add_list
(
props
,
(
char
*
)
qctrl
->
name
,
(
char
*
)
qctrl
->
name
,
OBS_COMBO_TYPE_LIST
,
OBS_COMBO_FORMAT_INT
);
obs_property_set_modified_callback2
(
prop
,
v4l2_control_changed
,
UINT_TO_POINTER
(
qctrl
->
id
));
memset
(
&
qmenu
,
0
,
sizeof
(
qmenu
));
qmenu
.
id
=
qctrl
->
id
;
for
(
qmenu
.
index
=
qctrl
->
minimum
;
qmenu
.
index
<=
(
uint32_t
)
qctrl
->
maximum
;
qmenu
.
index
+=
qctrl
->
step
)
{
if
(
0
==
v4l2_ioctl
(
dev
,
VIDIOC_QUERYMENU
,
&
qmenu
))
{
obs_property_list_add_int
(
prop
,
(
char
*
)
qmenu
.
name
,
qmenu
.
value
);
}
}
return
0
;
}
int_fast32_t
v4l2_update_controls
(
int_fast32_t
dev
,
obs_properties_t
*
props
,
obs_data_t
*
settings
)
{
struct
v4l2_queryctrl
qctrl
;
obs_property_t
*
prop
=
NULL
;
if
(
!
dev
||
!
props
)
return
-
1
;
memset
(
&
qctrl
,
0
,
sizeof
(
qctrl
));
qctrl
.
id
=
V4L2_CTRL_FLAG_NEXT_CTRL
;
while
(
0
==
v4l2_ioctl
(
dev
,
VIDIOC_QUERYCTRL
,
&
qctrl
))
{
if
(
qctrl
.
flags
&
V4L2_CTRL_FLAG_DISABLED
)
{
blog
(
LOG_INFO
,
"found control %s but it is disabled"
,
qctrl
.
name
);
continue
;
}
if
(
qctrl
.
flags
&
V4L2_CTRL_FLAG_READ_ONLY
)
{
blog
(
LOG_INFO
,
"found control %s but it is readonly"
,
qctrl
.
name
);
continue
;
}
if
(
qctrl
.
flags
&
V4L2_CTRL_FLAG_VOLATILE
)
{
blog
(
LOG_INFO
,
"found control %s but it is volatile"
,
qctrl
.
name
);
continue
;
}
switch
(
qctrl
.
type
)
{
case
V4L2_CTRL_TYPE_INTEGER
:
prop
=
obs_properties_add_int_slider
(
props
,
(
char
*
)
qctrl
.
name
,
(
char
*
)
qctrl
.
name
,
qctrl
.
minimum
,
qctrl
.
maximum
,
qctrl
.
step
);
obs_data_set_default_int
(
settings
,
(
char
*
)
qctrl
.
name
,
qctrl
.
default_value
);
obs_property_set_modified_callback2
(
prop
,
v4l2_control_changed
,
UINT_TO_POINTER
(
qctrl
.
id
));
break
;
case
V4L2_CTRL_TYPE_BOOLEAN
:
prop
=
obs_properties_add_bool
(
props
,
(
char
*
)
qctrl
.
name
,
(
char
*
)
qctrl
.
name
);
obs_data_set_default_bool
(
settings
,
(
char
*
)
qctrl
.
name
,
qctrl
.
default_value
);
obs_property_set_modified_callback2
(
prop
,
v4l2_control_changed
,
UINT_TO_POINTER
(
qctrl
.
id
));
break
;
case
V4L2_CTRL_TYPE_MENU
:
case
V4L2_CTRL_TYPE_INTEGER_MENU
:
v4l2_update_controls_menu
(
dev
,
props
,
&
qctrl
);
obs_data_set_default_int
(
settings
,
(
char
*
)
qctrl
.
name
,
qctrl
.
default_value
);
blog
(
LOG_INFO
,
"setting default for %s to %d"
,
(
char
*
)
qctrl
.
name
,
qctrl
.
default_value
);
break
;
}
qctrl
.
id
|=
V4L2_CTRL_FLAG_NEXT_CTRL
;
}
return
0
;
}
plugins/linux-v4l2/v4l2-controls.h
0 → 100644
浏览文件 @
73e62a21
/*
Copyright (C) 2019 by Gary Kramlich <grim@reaperworld.com>
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/>.
*/
#pragma once
#include <obs-module.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* Update a devices properties to include all v4l controls that it supports.
*
* @param dev handle to the v4l2 device
* @param props properties for the device
* @param data the settings for the source
*
* @return negative on failure
*/
int_fast32_t
v4l2_update_controls
(
int_fast32_t
dev
,
obs_properties_t
*
props
,
obs_data_t
*
settings
);
#ifdef __cplusplus
}
#endif
plugins/linux-v4l2/v4l2-input.c
浏览文件 @
73e62a21
...
...
@@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <util/platform.h>
#include <obs-module.h>
#include "v4l2-controls.h"
#include "v4l2-helpers.h"
#if HAVE_UDEV
...
...
@@ -579,6 +580,7 @@ static bool device_selected(obs_properties_t *props, obs_property_t *p,
obs_property_t
*
prop
=
obs_properties_get
(
props
,
"input"
);
v4l2_input_list
(
dev
,
prop
);
v4l2_update_controls
(
dev
,
props
,
settings
);
v4l2_close
(
dev
);
obs_property_modified
(
prop
,
settings
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录