Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ffmpeg
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Luma Media Server
ffmpeg
Commits
ece068a7
Commit
ece068a7
authored
6 years ago
by
Timo Rothenpieler
Browse files
Options
Downloads
Patches
Plain Diff
avutil/hwcontext_cuda: use generic size and pointer assignment functions
parent
41a18982
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavutil/hwcontext_cuda.c
+15
-67
15 additions, 67 deletions
libavutil/hwcontext_cuda.c
with
15 additions
and
67 deletions
libavutil/hwcontext_cuda.c
+
15
−
67
View file @
ece068a7
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include
"mem.h"
#include
"mem.h"
#include
"pixdesc.h"
#include
"pixdesc.h"
#include
"pixfmt.h"
#include
"pixfmt.h"
#include
"imgutils.h"
#define CUDA_FRAME_ALIGNMENT 256
#define CUDA_FRAME_ALIGNMENT 256
...
@@ -117,7 +118,6 @@ fail:
...
@@ -117,7 +118,6 @@ fail:
static
int
cuda_frames_init
(
AVHWFramesContext
*
ctx
)
static
int
cuda_frames_init
(
AVHWFramesContext
*
ctx
)
{
{
CUDAFramesContext
*
priv
=
ctx
->
internal
->
priv
;
CUDAFramesContext
*
priv
=
ctx
->
internal
->
priv
;
int
aligned_width
=
FFALIGN
(
ctx
->
width
,
CUDA_FRAME_ALIGNMENT
);
int
i
;
int
i
;
for
(
i
=
0
;
i
<
FF_ARRAY_ELEMS
(
supported_formats
);
i
++
)
{
for
(
i
=
0
;
i
<
FF_ARRAY_ELEMS
(
supported_formats
);
i
++
)
{
...
@@ -133,29 +133,9 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
...
@@ -133,29 +133,9 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
av_pix_fmt_get_chroma_sub_sample
(
ctx
->
sw_format
,
&
priv
->
shift_width
,
&
priv
->
shift_height
);
av_pix_fmt_get_chroma_sub_sample
(
ctx
->
sw_format
,
&
priv
->
shift_width
,
&
priv
->
shift_height
);
if
(
!
ctx
->
pool
)
{
if
(
!
ctx
->
pool
)
{
int
size
;
int
size
=
av_image_get_buffer_size
(
ctx
->
sw_format
,
ctx
->
width
,
ctx
->
height
,
CUDA_FRAME_ALIGNMENT
);
if
(
size
<
0
)
switch
(
ctx
->
sw_format
)
{
return
size
;
case
AV_PIX_FMT_NV12
:
case
AV_PIX_FMT_YUV420P
:
size
=
aligned_width
*
ctx
->
height
*
3
/
2
;
break
;
case
AV_PIX_FMT_YUV444P
:
case
AV_PIX_FMT_P010
:
case
AV_PIX_FMT_P016
:
size
=
aligned_width
*
ctx
->
height
*
3
;
break
;
case
AV_PIX_FMT_YUV444P16
:
size
=
aligned_width
*
ctx
->
height
*
6
;
break
;
case
AV_PIX_FMT_0RGB32
:
case
AV_PIX_FMT_0BGR32
:
size
=
aligned_width
*
ctx
->
height
*
4
;
break
;
default:
av_log
(
ctx
,
AV_LOG_ERROR
,
"BUG: Pixel format missing from size calculation."
);
return
AVERROR_BUG
;
}
ctx
->
internal
->
pool_internal
=
av_buffer_pool_init2
(
size
,
ctx
,
cuda_pool_alloc
,
NULL
);
ctx
->
internal
->
pool_internal
=
av_buffer_pool_init2
(
size
,
ctx
,
cuda_pool_alloc
,
NULL
);
if
(
!
ctx
->
internal
->
pool_internal
)
if
(
!
ctx
->
internal
->
pool_internal
)
...
@@ -167,54 +147,22 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
...
@@ -167,54 +147,22 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
static
int
cuda_get_buffer
(
AVHWFramesContext
*
ctx
,
AVFrame
*
frame
)
static
int
cuda_get_buffer
(
AVHWFramesContext
*
ctx
,
AVFrame
*
frame
)
{
{
int
aligned_width
;
int
res
;
int
width_in_bytes
=
ctx
->
width
;
if
(
ctx
->
sw_format
==
AV_PIX_FMT_P010
||
ctx
->
sw_format
==
AV_PIX_FMT_P016
||
ctx
->
sw_format
==
AV_PIX_FMT_YUV444P16
)
{
width_in_bytes
*=
2
;
}
aligned_width
=
FFALIGN
(
width_in_bytes
,
CUDA_FRAME_ALIGNMENT
);
frame
->
buf
[
0
]
=
av_buffer_pool_get
(
ctx
->
pool
);
frame
->
buf
[
0
]
=
av_buffer_pool_get
(
ctx
->
pool
);
if
(
!
frame
->
buf
[
0
])
if
(
!
frame
->
buf
[
0
])
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
switch
(
ctx
->
sw_format
)
{
res
=
av_image_fill_arrays
(
frame
->
data
,
frame
->
linesize
,
frame
->
buf
[
0
]
->
data
,
case
AV_PIX_FMT_NV12
:
ctx
->
sw_format
,
ctx
->
width
,
ctx
->
height
,
CUDA_FRAME_ALIGNMENT
);
case
AV_PIX_FMT_P010
:
if
(
res
<
0
)
case
AV_PIX_FMT_P016
:
return
res
;
frame
->
data
[
0
]
=
frame
->
buf
[
0
]
->
data
;
frame
->
data
[
1
]
=
frame
->
data
[
0
]
+
aligned_width
*
ctx
->
height
;
// YUV420P is a special case.
frame
->
linesize
[
0
]
=
aligned_width
;
// Nvenc expects the U/V planes in swapped order from how ffmpeg expects them.
frame
->
linesize
[
1
]
=
aligned_width
;
if
(
ctx
->
sw_format
==
AV_PIX_FMT_YUV420P
)
{
break
;
FFSWAP
(
uint8_t
*
,
frame
->
data
[
1
],
frame
->
data
[
2
]);
case
AV_PIX_FMT_YUV420P
:
FFSWAP
(
int
,
frame
->
linesize
[
1
],
frame
->
linesize
[
2
]);
frame
->
data
[
0
]
=
frame
->
buf
[
0
]
->
data
;
frame
->
data
[
2
]
=
frame
->
data
[
0
]
+
aligned_width
*
ctx
->
height
;
frame
->
data
[
1
]
=
frame
->
data
[
2
]
+
aligned_width
*
ctx
->
height
/
4
;
frame
->
linesize
[
0
]
=
aligned_width
;
frame
->
linesize
[
1
]
=
aligned_width
/
2
;
frame
->
linesize
[
2
]
=
aligned_width
/
2
;
break
;
case
AV_PIX_FMT_YUV444P
:
case
AV_PIX_FMT_YUV444P16
:
frame
->
data
[
0
]
=
frame
->
buf
[
0
]
->
data
;
frame
->
data
[
1
]
=
frame
->
data
[
0
]
+
aligned_width
*
ctx
->
height
;
frame
->
data
[
2
]
=
frame
->
data
[
1
]
+
aligned_width
*
ctx
->
height
;
frame
->
linesize
[
0
]
=
aligned_width
;
frame
->
linesize
[
1
]
=
aligned_width
;
frame
->
linesize
[
2
]
=
aligned_width
;
break
;
case
AV_PIX_FMT_0BGR32
:
case
AV_PIX_FMT_0RGB32
:
frame
->
data
[
0
]
=
frame
->
buf
[
0
]
->
data
;
frame
->
linesize
[
0
]
=
aligned_width
*
4
;
break
;
default:
av_frame_unref
(
frame
);
return
AVERROR_BUG
;
}
}
frame
->
format
=
AV_PIX_FMT_CUDA
;
frame
->
format
=
AV_PIX_FMT_CUDA
;
...
...
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