Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
0efd48df
Commit
0efd48df
authored
Jan 05, 2012
by
Luca Barbato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v4l2: poll the file descriptor
Instead of busy waiting use poll();
parent
b8c310cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
v4l2.c
libavdevice/v4l2.c
+15
-0
No files found.
libavdevice/v4l2.c
View file @
0efd48df
...
...
@@ -36,6 +36,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <poll.h>
#if HAVE_SYS_VIDEOIO_H
#include <sys/videoio.h>
#else
...
...
@@ -48,6 +49,7 @@
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avstring.h"
#include "libavutil/mathematics.h"
static
const
int
desired_video_buffers
=
256
;
...
...
@@ -61,6 +63,7 @@ struct video_data {
int
frame_format
;
/* V4L2_PIX_FMT_* */
int
width
,
height
;
int
frame_size
;
int
timeout
;
int
interlaced
;
int
top_field_first
;
...
...
@@ -436,12 +439,20 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
struct
video_data
*
s
=
ctx
->
priv_data
;
struct
v4l2_buffer
buf
;
struct
buff_data
*
buf_descriptor
;
struct
pollfd
p
=
{
.
fd
=
s
->
fd
,
.
events
=
POLLIN
};
int
res
;
memset
(
&
buf
,
0
,
sizeof
(
struct
v4l2_buffer
));
buf
.
type
=
V4L2_BUF_TYPE_VIDEO_CAPTURE
;
buf
.
memory
=
V4L2_MEMORY_MMAP
;
res
=
poll
(
&
p
,
1
,
s
->
timeout
);
if
(
res
<
0
)
return
AVERROR
(
errno
);
if
(
!
(
p
.
revents
&
(
POLLIN
|
POLLERR
|
POLLHUP
)))
return
AVERROR
(
EAGAIN
);
/* FIXME: Some special treatment might be needed in case of loss of signal... */
while
((
res
=
ioctl
(
s
->
fd
,
VIDIOC_DQBUF
,
&
buf
))
<
0
&&
(
errno
==
EINTR
));
if
(
res
<
0
)
{
...
...
@@ -635,6 +646,10 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
s1
->
streams
[
0
]
->
codec
->
time_base
.
den
=
tpf
->
denominator
;
s1
->
streams
[
0
]
->
codec
->
time_base
.
num
=
tpf
->
numerator
;
s
->
timeout
=
100
+
av_rescale_q
(
1
,
s1
->
streams
[
0
]
->
codec
->
time_base
,
(
AVRational
){
1
,
1000
});
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment