Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
70611d7f
Commit
70611d7f
authored
Jan 10, 2022
by
Anton Khirnov
Committed by
Andreas Rheinhardt
Feb 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavc/amfenc: switch to new FIFO API
parent
37e70d48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
30 deletions
+15
-30
amfenc.c
libavcodec/amfenc.c
+14
-29
amfenc.h
libavcodec/amfenc.h
+1
-1
No files found.
libavcodec/amfenc.c
View file @
70611d7f
...
...
@@ -117,8 +117,9 @@ static int amf_load_library(AVCodecContext *avctx)
if
(
!
ctx
->
delayed_frame
)
{
return
AVERROR
(
ENOMEM
);
}
// hardcoded to current HW queue size - will realloc in timestamp_queue_enqueue() if too small
ctx
->
timestamp_list
=
av_fifo_alloc
((
avctx
->
max_b_frames
+
16
)
*
sizeof
(
int64_t
));
// hardcoded to current HW queue size - will auto-realloc if too small
ctx
->
timestamp_list
=
av_fifo_alloc2
(
avctx
->
max_b_frames
+
16
,
sizeof
(
int64_t
),
AV_FIFO_FLAG_AUTO_GROW
);
if
(
!
ctx
->
timestamp_list
)
{
return
AVERROR
(
ENOMEM
);
}
...
...
@@ -403,7 +404,7 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx)
ctx
->
version
=
0
;
ctx
->
delayed_drain
=
0
;
av_frame_free
(
&
ctx
->
delayed_frame
);
av_fifo_freep
(
&
ctx
->
timestamp_list
);
av_fifo_freep
2
(
&
ctx
->
timestamp_list
);
return
0
;
}
...
...
@@ -432,18 +433,6 @@ static int amf_copy_surface(AVCodecContext *avctx, const AVFrame *frame,
return
0
;
}
static
inline
int
timestamp_queue_enqueue
(
AVCodecContext
*
avctx
,
int64_t
timestamp
)
{
AmfContext
*
ctx
=
avctx
->
priv_data
;
if
(
av_fifo_space
(
ctx
->
timestamp_list
)
<
sizeof
(
timestamp
))
{
if
(
av_fifo_grow
(
ctx
->
timestamp_list
,
sizeof
(
timestamp
))
<
0
)
{
return
AVERROR
(
ENOMEM
);
}
}
av_fifo_generic_write
(
ctx
->
timestamp_list
,
&
timestamp
,
sizeof
(
timestamp
),
NULL
);
return
0
;
}
static
int
amf_copy_buffer
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
,
AMFBuffer
*
buffer
)
{
AmfContext
*
ctx
=
avctx
->
priv_data
;
...
...
@@ -479,21 +468,17 @@ static int amf_copy_buffer(AVCodecContext *avctx, AVPacket *pkt, AMFBuffer *buff
pkt
->
pts
=
var
.
int64Value
;
// original pts
AMF_RETURN_IF_FALSE
(
ctx
,
av_fifo_size
(
ctx
->
timestamp_list
)
>
0
,
AVERROR_UNKNOWN
,
"timestamp_list is empty
\n
"
);
av_fifo_generic_read
(
ctx
->
timestamp_list
,
&
timestamp
,
sizeof
(
timestamp
),
NULL
);
AMF_RETURN_IF_FALSE
(
ctx
,
av_fifo_read
(
ctx
->
timestamp_list
,
&
timestamp
,
1
)
>=
0
,
AVERROR_UNKNOWN
,
"timestamp_list is empty
\n
"
);
// calc dts shift if max_b_frames > 0
if
(
avctx
->
max_b_frames
>
0
&&
ctx
->
dts_delay
==
0
)
{
int64_t
timestamp_last
=
AV_NOPTS_VALUE
;
AMF_RETURN_IF_FALSE
(
ctx
,
av_fifo_size
(
ctx
->
timestamp_list
)
>
0
,
AVERROR_UNKNOWN
,
size_t
can_read
=
av_fifo_can_read
(
ctx
->
timestamp_list
);
AMF_RETURN_IF_FALSE
(
ctx
,
can_read
>
0
,
AVERROR_UNKNOWN
,
"timestamp_list is empty while max_b_frames = %d
\n
"
,
avctx
->
max_b_frames
);
av_fifo_generic_peek_at
(
ctx
->
timestamp_list
,
&
timestamp_last
,
(
av_fifo_size
(
ctx
->
timestamp_list
)
/
sizeof
(
timestamp
)
-
1
)
*
sizeof
(
timestamp_last
),
sizeof
(
timestamp_last
),
NULL
);
av_fifo_peek
(
ctx
->
timestamp_list
,
&
timestamp_last
,
1
,
can_read
-
1
);
if
(
timestamp
<
0
||
timestamp_last
<
AV_NOPTS_VALUE
)
{
return
AVERROR
(
ERANGE
);
}
...
...
@@ -710,9 +695,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
AMF_RETURN_IF_FALSE
(
ctx
,
res
==
AMF_OK
,
AVERROR_UNKNOWN
,
"SubmitInput() failed with error %d
\n
"
,
res
);
av_frame_unref
(
frame
);
if
((
ret
=
timestamp_queue_enqueue
(
avctx
,
pts
))
<
0
)
{
ret
=
av_fifo_write
(
ctx
->
timestamp_list
,
&
pts
,
1
);
if
(
ret
<
0
)
return
ret
;
}
}
}
...
...
@@ -751,9 +736,9 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
av_frame_unref
(
ctx
->
delayed_frame
);
AMF_RETURN_IF_FALSE
(
ctx
,
res
==
AMF_OK
,
AVERROR_UNKNOWN
,
"Repeated SubmitInput() failed with error %d
\n
"
,
res
);
if
((
ret
=
timestamp_queue_enqueue
(
avctx
,
pts
))
<
0
)
{
ret
=
av_fifo_write
(
ctx
->
timestamp_list
,
&
pts
,
1
);
if
(
ret
<
0
)
return
ret
;
}
}
else
{
av_log
(
avctx
,
AV_LOG_WARNING
,
"Data acquired but delayed frame submission got AMF_INPUT_FULL- should not happen
\n
"
);
}
...
...
libavcodec/amfenc.h
View file @
70611d7f
...
...
@@ -72,7 +72,7 @@ typedef struct AmfContext {
AVFrame
*
delayed_frame
;
// shift dts back by max_b_frames in timing
AVFifo
Buffer
*
timestamp_list
;
AVFifo
*
timestamp_list
;
int64_t
dts_delay
;
// common encoder option options
...
...
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