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
767f5353
Commit
767f5353
authored
Mar 20, 2020
by
Timo Rothenpieler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nvdec: attach real hw_frames to post-processed frames
parent
33623307
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
18 deletions
+76
-18
nvdec.c
libavcodec/nvdec.c
+75
-17
version.h
libavcodec/version.h
+1
-1
No files found.
libavcodec/nvdec.c
View file @
767f5353
...
@@ -44,6 +44,7 @@ typedef struct NVDECDecoder {
...
@@ -44,6 +44,7 @@ typedef struct NVDECDecoder {
CUvideodecoder
decoder
;
CUvideodecoder
decoder
;
AVBufferRef
*
hw_device_ref
;
AVBufferRef
*
hw_device_ref
;
AVBufferRef
*
real_hw_frames_ref
;
CUcontext
cuda_ctx
;
CUcontext
cuda_ctx
;
CUstream
stream
;
CUstream
stream
;
...
@@ -163,6 +164,7 @@ static void nvdec_decoder_free(void *opaque, uint8_t *data)
...
@@ -163,6 +164,7 @@ static void nvdec_decoder_free(void *opaque, uint8_t *data)
CHECK_CU
(
decoder
->
cudl
->
cuCtxPopCurrent
(
&
dummy
));
CHECK_CU
(
decoder
->
cudl
->
cuCtxPopCurrent
(
&
dummy
));
}
}
av_buffer_unref
(
&
decoder
->
real_hw_frames_ref
);
av_buffer_unref
(
&
decoder
->
hw_device_ref
);
av_buffer_unref
(
&
decoder
->
hw_device_ref
);
cuvid_free_functions
(
&
decoder
->
cvdl
);
cuvid_free_functions
(
&
decoder
->
cvdl
);
...
@@ -269,10 +271,61 @@ int ff_nvdec_decode_uninit(AVCodecContext *avctx)
...
@@ -269,10 +271,61 @@ int ff_nvdec_decode_uninit(AVCodecContext *avctx)
return
0
;
return
0
;
}
}
static
void
nvdec_free_dummy
(
struct
AVHWFramesContext
*
ctx
)
{
av_buffer_pool_uninit
(
&
ctx
->
pool
);
}
static
AVBufferRef
*
nvdec_alloc_dummy
(
int
size
)
{
return
av_buffer_create
(
NULL
,
0
,
NULL
,
NULL
,
0
);
}
static
int
nvdec_init_hwframes
(
AVCodecContext
*
avctx
,
AVBufferRef
**
out_frames_ref
,
int
dummy
)
{
AVHWFramesContext
*
frames_ctx
;
int
ret
;
ret
=
avcodec_get_hw_frames_parameters
(
avctx
,
avctx
->
hw_device_ctx
,
avctx
->
hwaccel
->
pix_fmt
,
out_frames_ref
);
if
(
ret
<
0
)
return
ret
;
frames_ctx
=
(
AVHWFramesContext
*
)(
*
out_frames_ref
)
->
data
;
if
(
dummy
)
{
// Copied from ff_decode_get_hw_frames_ctx for compatibility
frames_ctx
->
initial_pool_size
+=
3
;
frames_ctx
->
free
=
nvdec_free_dummy
;
frames_ctx
->
pool
=
av_buffer_pool_init
(
0
,
nvdec_alloc_dummy
);
if
(
!
frames_ctx
->
pool
)
{
av_buffer_unref
(
out_frames_ref
);
return
AVERROR
(
ENOMEM
);
}
}
else
{
// This is normally not used to actually allocate frames from
frames_ctx
->
initial_pool_size
=
0
;
}
ret
=
av_hwframe_ctx_init
(
*
out_frames_ref
);
if
(
ret
<
0
)
{
av_buffer_unref
(
out_frames_ref
);
return
ret
;
}
return
0
;
}
int
ff_nvdec_decode_init
(
AVCodecContext
*
avctx
)
int
ff_nvdec_decode_init
(
AVCodecContext
*
avctx
)
{
{
NVDECContext
*
ctx
=
avctx
->
internal
->
hwaccel_priv_data
;
NVDECContext
*
ctx
=
avctx
->
internal
->
hwaccel_priv_data
;
NVDECDecoder
*
decoder
;
AVBufferRef
*
real_hw_frames_ref
;
NVDECFramePool
*
pool
;
NVDECFramePool
*
pool
;
AVHWFramesContext
*
frames_ctx
;
AVHWFramesContext
*
frames_ctx
;
const
AVPixFmtDescriptor
*
sw_desc
;
const
AVPixFmtDescriptor
*
sw_desc
;
...
@@ -301,9 +354,17 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
...
@@ -301,9 +354,17 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
chroma_444
=
ctx
->
supports_444
&&
cuvid_chroma_format
==
cudaVideoChromaFormat_444
;
chroma_444
=
ctx
->
supports_444
&&
cuvid_chroma_format
==
cudaVideoChromaFormat_444
;
if
(
!
avctx
->
hw_frames_ctx
)
{
if
(
!
avctx
->
hw_frames_ctx
)
{
ret
=
ff_decode_get_hw_frames_ctx
(
avctx
,
AV_HWDEVICE_TYPE_CUDA
);
ret
=
nvdec_init_hwframes
(
avctx
,
&
avctx
->
hw_frames_ctx
,
1
);
if
(
ret
<
0
)
return
ret
;
ret
=
nvdec_init_hwframes
(
avctx
,
&
real_hw_frames_ref
,
0
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
}
else
{
real_hw_frames_ref
=
av_buffer_ref
(
avctx
->
hw_frames_ctx
);
if
(
!
real_hw_frames_ref
)
return
AVERROR
(
ENOMEM
);
}
}
switch
(
sw_desc
->
comp
[
0
].
depth
)
{
switch
(
sw_desc
->
comp
[
0
].
depth
)
{
...
@@ -318,6 +379,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
...
@@ -318,6 +379,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
break
;
break
;
default:
default:
av_log
(
avctx
,
AV_LOG_ERROR
,
"Unsupported bit depth
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Unsupported bit depth
\n
"
);
av_buffer_unref
(
&
real_hw_frames_ref
);
return
AVERROR
(
ENOSYS
);
return
AVERROR
(
ENOSYS
);
}
}
...
@@ -342,9 +404,14 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
...
@@ -342,9 +404,14 @@ int ff_nvdec_decode_init(AVCodecContext *avctx)
av_log
(
avctx
,
AV_LOG_WARNING
,
"Try lowering the amount of threads. Using %d right now.
\n
"
,
av_log
(
avctx
,
AV_LOG_WARNING
,
"Try lowering the amount of threads. Using %d right now.
\n
"
,
avctx
->
thread_count
);
avctx
->
thread_count
);
}
}
av_buffer_unref
(
&
real_hw_frames_ref
);
return
ret
;
return
ret
;
}
}
decoder
=
(
NVDECDecoder
*
)
ctx
->
decoder_ref
->
data
;
decoder
->
real_hw_frames_ref
=
real_hw_frames_ref
;
real_hw_frames_ref
=
NULL
;
pool
=
av_mallocz
(
sizeof
(
*
pool
));
pool
=
av_mallocz
(
sizeof
(
*
pool
));
if
(
!
pool
)
{
if
(
!
pool
)
{
ret
=
AVERROR
(
ENOMEM
);
ret
=
AVERROR
(
ENOMEM
);
...
@@ -447,6 +514,13 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
...
@@ -447,6 +514,13 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
goto
copy_fail
;
goto
copy_fail
;
}
}
av_buffer_unref
(
&
frame
->
hw_frames_ctx
);
frame
->
hw_frames_ctx
=
av_buffer_ref
(
decoder
->
real_hw_frames_ref
);
if
(
!
frame
->
hw_frames_ctx
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
copy_fail
;
}
unmap_data
->
idx
=
cf
->
idx
;
unmap_data
->
idx
=
cf
->
idx
;
unmap_data
->
idx_ref
=
av_buffer_ref
(
cf
->
idx_ref
);
unmap_data
->
idx_ref
=
av_buffer_ref
(
cf
->
idx_ref
);
unmap_data
->
decoder_ref
=
av_buffer_ref
(
cf
->
decoder_ref
);
unmap_data
->
decoder_ref
=
av_buffer_ref
(
cf
->
decoder_ref
);
...
@@ -575,16 +649,6 @@ int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
...
@@ -575,16 +649,6 @@ int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
return
0
;
return
0
;
}
}
static
void
nvdec_free_dummy
(
struct
AVHWFramesContext
*
ctx
)
{
av_buffer_pool_uninit
(
&
ctx
->
pool
);
}
static
AVBufferRef
*
nvdec_alloc_dummy
(
int
size
)
{
return
av_buffer_create
(
NULL
,
0
,
NULL
,
NULL
,
0
);
}
int
ff_nvdec_frame_params
(
AVCodecContext
*
avctx
,
int
ff_nvdec_frame_params
(
AVCodecContext
*
avctx
,
AVBufferRef
*
hw_frames_ctx
,
AVBufferRef
*
hw_frames_ctx
,
int
dpb_size
,
int
dpb_size
,
...
@@ -620,12 +684,6 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
...
@@ -620,12 +684,6 @@ int ff_nvdec_frame_params(AVCodecContext *avctx,
*/
*/
frames_ctx
->
initial_pool_size
=
dpb_size
+
2
;
frames_ctx
->
initial_pool_size
=
dpb_size
+
2
;
frames_ctx
->
free
=
nvdec_free_dummy
;
frames_ctx
->
pool
=
av_buffer_pool_init
(
0
,
nvdec_alloc_dummy
);
if
(
!
frames_ctx
->
pool
)
return
AVERROR
(
ENOMEM
);
switch
(
sw_desc
->
comp
[
0
].
depth
)
{
switch
(
sw_desc
->
comp
[
0
].
depth
)
{
case
8
:
case
8
:
frames_ctx
->
sw_format
=
chroma_444
?
AV_PIX_FMT_YUV444P
:
AV_PIX_FMT_NV12
;
frames_ctx
->
sw_format
=
chroma_444
?
AV_PIX_FMT_YUV444P
:
AV_PIX_FMT_NV12
;
...
...
libavcodec/version.h
View file @
767f5353
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#define LIBAVCODEC_VERSION_MAJOR 58
#define LIBAVCODEC_VERSION_MAJOR 58
#define LIBAVCODEC_VERSION_MINOR 77
#define LIBAVCODEC_VERSION_MINOR 77
#define LIBAVCODEC_VERSION_MICRO 10
0
#define LIBAVCODEC_VERSION_MICRO 10
1
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
LIBAVCODEC_VERSION_MINOR, \
...
...
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