Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
2b21bb4a
Commit
2b21bb4a
authored
Aug 27, 2019
by
Aman Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/v4l2_buffers: split out AVFrame generation into helper method
Signed-off-by:
Aman Gupta
<
aman@tmm1.net
>
parent
b3b958c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
31 deletions
+45
-31
v4l2_buffers.c
libavcodec/v4l2_buffers.c
+45
-31
No files found.
libavcodec/v4l2_buffers.c
View file @
2b21bb4a
...
...
@@ -281,6 +281,47 @@ static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, i
return
0
;
}
static
int
v4l2_buffer_buf_to_swframe
(
AVFrame
*
frame
,
V4L2Buffer
*
avbuf
)
{
int
i
,
ret
;
frame
->
format
=
avbuf
->
context
->
av_pix_fmt
;
for
(
i
=
0
;
i
<
avbuf
->
num_planes
;
i
++
)
{
ret
=
v4l2_buf_to_bufref
(
avbuf
,
i
,
&
frame
->
buf
[
i
]);
if
(
ret
)
return
ret
;
frame
->
linesize
[
i
]
=
avbuf
->
plane_info
[
i
].
bytesperline
;
frame
->
data
[
i
]
=
frame
->
buf
[
i
]
->
data
;
}
/* fixup special cases */
switch
(
avbuf
->
context
->
av_pix_fmt
)
{
case
AV_PIX_FMT_NV12
:
case
AV_PIX_FMT_NV21
:
if
(
avbuf
->
num_planes
>
1
)
break
;
frame
->
linesize
[
1
]
=
avbuf
->
plane_info
[
0
].
bytesperline
;
frame
->
data
[
1
]
=
frame
->
buf
[
0
]
->
data
+
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
;
break
;
case
AV_PIX_FMT_YUV420P
:
if
(
avbuf
->
num_planes
>
1
)
break
;
frame
->
linesize
[
1
]
=
avbuf
->
plane_info
[
0
].
bytesperline
>>
1
;
frame
->
linesize
[
2
]
=
avbuf
->
plane_info
[
0
].
bytesperline
>>
1
;
frame
->
data
[
1
]
=
frame
->
buf
[
0
]
->
data
+
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
;
frame
->
data
[
2
]
=
frame
->
data
[
1
]
+
((
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
)
>>
2
);
break
;
default:
break
;
}
return
0
;
}
/******************************************************************************
*
* V4L2Buffer interface
...
...
@@ -349,44 +390,17 @@ int ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out)
int
ff_v4l2_buffer_buf_to_avframe
(
AVFrame
*
frame
,
V4L2Buffer
*
avbuf
)
{
V4L2m2mContext
*
s
=
buf_to_m2mctx
(
avbuf
);
int
i
,
ret
;
int
ret
;
av_frame_unref
(
frame
);
/* 1. get references to the actual data */
for
(
i
=
0
;
i
<
avbuf
->
num_planes
;
i
++
)
{
ret
=
v4l2_buf_to_bufref
(
avbuf
,
i
,
&
frame
->
buf
[
i
]);
if
(
ret
)
return
ret
;
frame
->
linesize
[
i
]
=
avbuf
->
plane_info
[
i
].
bytesperline
;
frame
->
data
[
i
]
=
frame
->
buf
[
i
]
->
data
;
}
/* 1.1 fixup special cases */
switch
(
avbuf
->
context
->
av_pix_fmt
)
{
case
AV_PIX_FMT_NV12
:
case
AV_PIX_FMT_NV21
:
if
(
avbuf
->
num_planes
>
1
)
break
;
frame
->
linesize
[
1
]
=
avbuf
->
plane_info
[
0
].
bytesperline
;
frame
->
data
[
1
]
=
frame
->
buf
[
0
]
->
data
+
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
;
break
;
case
AV_PIX_FMT_YUV420P
:
if
(
avbuf
->
num_planes
>
1
)
break
;
frame
->
linesize
[
1
]
=
avbuf
->
plane_info
[
0
].
bytesperline
>>
1
;
frame
->
linesize
[
2
]
=
avbuf
->
plane_info
[
0
].
bytesperline
>>
1
;
frame
->
data
[
1
]
=
frame
->
buf
[
0
]
->
data
+
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
;
frame
->
data
[
2
]
=
frame
->
data
[
1
]
+
((
avbuf
->
plane_info
[
0
].
bytesperline
*
avbuf
->
context
->
format
.
fmt
.
pix_mp
.
height
)
>>
2
);
break
;
default:
break
;
}
ret
=
v4l2_buffer_buf_to_swframe
(
frame
,
avbuf
);
if
(
ret
)
return
ret
;
/* 2. get frame information */
frame
->
key_frame
=
!!
(
avbuf
->
buf
.
flags
&
V4L2_BUF_FLAG_KEYFRAME
);
frame
->
format
=
avbuf
->
context
->
av_pix_fmt
;
frame
->
color_primaries
=
v4l2_get_color_primaries
(
avbuf
);
frame
->
colorspace
=
v4l2_get_color_space
(
avbuf
);
frame
->
color_range
=
v4l2_get_color_range
(
avbuf
);
...
...
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