Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
obs-studio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yunxiang Li
obs-studio
Commits
dcd395f7
Commit
dcd395f7
authored
10 years ago
by
fryshorts
Browse files
Options
Downloads
Patches
Plain Diff
Use helper function to set framerate in v4l2 input.
parent
6c8216c6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugins/linux-v4l2/v4l2-helpers.c
+30
-0
30 additions, 0 deletions
plugins/linux-v4l2/v4l2-helpers.c
plugins/linux-v4l2/v4l2-helpers.h
+12
-0
12 additions, 0 deletions
plugins/linux-v4l2/v4l2-helpers.h
plugins/linux-v4l2/v4l2-input.c
+4
-10
4 additions, 10 deletions
plugins/linux-v4l2/v4l2-input.c
with
46 additions
and
10 deletions
plugins/linux-v4l2/v4l2-helpers.c
+
30
−
0
View file @
dcd395f7
...
@@ -169,3 +169,33 @@ int_fast32_t v4l2_set_format(int_fast32_t dev, int *resolution,
...
@@ -169,3 +169,33 @@ int_fast32_t v4l2_set_format(int_fast32_t dev, int *resolution,
*
bytesperline
=
fmt
.
fmt
.
pix
.
bytesperline
;
*
bytesperline
=
fmt
.
fmt
.
pix
.
bytesperline
;
return
0
;
return
0
;
}
}
int_fast32_t
v4l2_set_framerate
(
int_fast32_t
dev
,
int
*
framerate
)
{
bool
set
=
false
;
int
num
,
denom
;
struct
v4l2_streamparm
par
;
if
(
!
dev
||
!
framerate
)
return
-
1
;
/* We need to set the type in order to query the stream settings */
par
.
type
=
V4L2_BUF_TYPE_VIDEO_CAPTURE
;
if
(
v4l2_ioctl
(
dev
,
VIDIOC_G_PARM
,
&
par
)
<
0
)
return
-
1
;
if
(
*
framerate
!=
-
1
)
{
v4l2_unpack_tuple
(
&
num
,
&
denom
,
*
framerate
);
par
.
parm
.
capture
.
timeperframe
.
numerator
=
num
;
par
.
parm
.
capture
.
timeperframe
.
denominator
=
denom
;
set
=
true
;
}
if
(
set
&&
(
v4l2_ioctl
(
dev
,
VIDIOC_S_PARM
,
&
par
)
<
0
))
return
-
1
;
*
framerate
=
v4l2_pack_tuple
(
par
.
parm
.
capture
.
timeperframe
.
numerator
,
par
.
parm
.
capture
.
timeperframe
.
denominator
);
return
0
;
}
This diff is collapsed.
Click to expand it.
plugins/linux-v4l2/v4l2-helpers.h
+
12
−
0
View file @
dcd395f7
...
@@ -235,6 +235,18 @@ int_fast32_t v4l2_set_input(int_fast32_t dev, int *input);
...
@@ -235,6 +235,18 @@ int_fast32_t v4l2_set_input(int_fast32_t dev, int *input);
int_fast32_t
v4l2_set_format
(
int_fast32_t
dev
,
int
*
resolution
,
int_fast32_t
v4l2_set_format
(
int_fast32_t
dev
,
int
*
resolution
,
int
*
pixelformat
,
int
*
bytesperline
);
int
*
pixelformat
,
int
*
bytesperline
);
/**
* Set the framerate on the device.
*
* If the action succeeds framerate is set to the used value.
*
* @param dev handle to the v4l2 device
* @param framerate packed value of the framerate or -1 to leave as is
*
* @return negative on failure
*/
int_fast32_t
v4l2_set_framerate
(
int_fast32_t
dev
,
int
*
framerate
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
This diff is collapsed.
Click to expand it.
plugins/linux-v4l2/v4l2-input.c
+
4
−
10
View file @
dcd395f7
...
@@ -64,7 +64,7 @@ struct v4l2_data {
...
@@ -64,7 +64,7 @@ struct v4l2_data {
int
set_input
;
int
set_input
;
int
set_pixfmt
;
int
set_pixfmt
;
int
set_res
;
int
set_res
;
int
_fast32_t
set_fps
;
int
set_fps
;
/* data used within the capture thread */
/* data used within the capture thread */
int_fast32_t
dev
;
int_fast32_t
dev
;
...
@@ -582,7 +582,6 @@ static void v4l2_destroy(void *vptr)
...
@@ -582,7 +582,6 @@ static void v4l2_destroy(void *vptr)
*/
*/
static
void
v4l2_init
(
struct
v4l2_data
*
data
)
static
void
v4l2_init
(
struct
v4l2_data
*
data
)
{
{
struct
v4l2_streamparm
par
;
struct
dstr
fps
;
struct
dstr
fps
;
int
fps_num
,
fps_denom
;
int
fps_num
,
fps_denom
;
...
@@ -614,18 +613,13 @@ static void v4l2_init(struct v4l2_data *data)
...
@@ -614,18 +613,13 @@ static void v4l2_init(struct v4l2_data *data)
blog
(
LOG_INFO
,
"Linesize: %d Bytes"
,
data
->
linesize
);
blog
(
LOG_INFO
,
"Linesize: %d Bytes"
,
data
->
linesize
);
/* set framerate */
/* set framerate */
v4l2_unpack_tuple
(
&
fps_num
,
&
fps_denom
,
data
->
set_fps
);
if
(
v4l2_set_framerate
(
data
->
dev
,
&
data
->
set_fps
)
<
0
)
{
par
.
type
=
V4L2_BUF_TYPE_VIDEO_CAPTURE
;
par
.
parm
.
capture
.
timeperframe
.
numerator
=
fps_num
;
par
.
parm
.
capture
.
timeperframe
.
denominator
=
fps_denom
;
if
(
v4l2_ioctl
(
data
->
dev
,
VIDIOC_S_PARM
,
&
par
)
<
0
)
{
blog
(
LOG_ERROR
,
"Unable to set framerate"
);
blog
(
LOG_ERROR
,
"Unable to set framerate"
);
goto
fail
;
goto
fail
;
}
}
v4l2_unpack_tuple
(
&
fps_num
,
&
fps_denom
,
data
->
set_fps
);
dstr_init
(
&
fps
);
dstr_init
(
&
fps
);
dstr_printf
(
&
fps
,
"%.2f"
,
dstr_printf
(
&
fps
,
"%.2f"
,
(
float
)
fps_denom
/
fps_num
);
(
float
)
par
.
parm
.
capture
.
timeperframe
.
denominator
/
par
.
parm
.
capture
.
timeperframe
.
numerator
);
blog
(
LOG_INFO
,
"Framerate: %s fps"
,
fps
.
array
);
blog
(
LOG_INFO
,
"Framerate: %s fps"
,
fps
.
array
);
dstr_free
(
&
fps
);
dstr_free
(
&
fps
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment