-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+) Enable vaapi hw acceleration for h264 and HEVC
+) Add ffmpeg patches for invalid reference frames in vaapi hevc/ h264
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
ffmpeg/ffmpeg-lavc-vaapi_h264-Fixup-invalid-references.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
From 9d4b9b0b963f5375317636f4f527a203e21e89b9 Mon Sep 17 00:00:00 2001 | ||
From: David Rosca <nowrep@gmail.com> | ||
Date: Mon, 8 Jan 2024 12:44:20 +0100 | ||
Subject: [PATCH] lavc/vaapi_h264: Fixup invalid references | ||
|
||
--- | ||
libavcodec/vaapi_h264.c | 20 +++++++++++++++++++- | ||
1 file changed, 19 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c | ||
index 55cf5a05ee..c935c88bad 100644 | ||
--- a/libavcodec/vaapi_h264.c | ||
+++ b/libavcodec/vaapi_h264.c | ||
@@ -128,6 +128,8 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param, | ||
DPB dpb; | ||
int i; | ||
|
||
+ const H264Picture *pic_good = NULL; | ||
+ | ||
dpb.size = 0; | ||
dpb.max_size = FF_ARRAY_ELEMS(pic_param->ReferenceFrames); | ||
dpb.va_pics = pic_param->ReferenceFrames; | ||
@@ -136,7 +138,23 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param, | ||
|
||
for (i = 0; i < h->short_ref_count; i++) { | ||
const H264Picture *pic = h->short_ref[i]; | ||
- if (pic && pic->reference && dpb_add(&dpb, pic) < 0) | ||
+ if (!pic || !pic->reference) | ||
+ continue; | ||
+ if (pic->recovered) { | ||
+ pic_good = pic; | ||
+ } else { | ||
+ if (pic_good) { | ||
+ pic = pic_good; | ||
+ } else { | ||
+ for (int i = 0; i < h->short_ref_count; i++) { | ||
+ if (h->short_ref[i] && h->short_ref[i]->reference && h->short_ref[i]->recovered) { | ||
+ pic = h->short_ref[i]; | ||
+ break; | ||
+ } | ||
+ } | ||
+ } | ||
+ } | ||
+ if (dpb_add(&dpb, pic) < 0) | ||
return -1; | ||
} | ||
|
||
-- | ||
2.43.0 | ||
|
48 changes: 48 additions & 0 deletions
48
ffmpeg/ffmpeg-lavc-vaapi_hevc-Fixup-invalid-references.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
From 1b516ca017fa45888d4962ebf97a78987e696209 Mon Sep 17 00:00:00 2001 | ||
From: David Rosca <nowrep@gmail.com> | ||
Date: Sun, 10 Dec 2023 10:00:28 +0100 | ||
Subject: [PATCH] lavc/vaapi_hevc: Fixup invalid references | ||
|
||
--- | ||
libavcodec/vaapi_hevc.c | 18 ++++++++++++++++++ | ||
1 file changed, 18 insertions(+) | ||
|
||
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c | ||
index 3bdd2dd1b8..d08fb50e37 100644 | ||
--- a/libavcodec/vaapi_hevc.c | ||
+++ b/libavcodec/vaapi_hevc.c | ||
@@ -100,6 +100,8 @@ static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameter | ||
const HEVCFrame *current_picture = h->ref; | ||
int i, j, rps_type; | ||
|
||
+ const HEVCFrame *frame_good = NULL; | ||
+ | ||
for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); i++) { | ||
const HEVCFrame *frame = NULL; | ||
|
||
@@ -113,6 +115,22 @@ static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameter | ||
init_vaapi_pic(&pp->ReferenceFrames[i]); | ||
|
||
if (frame) { | ||
+ if (frame->sequence != HEVC_SEQUENCE_COUNTER_INVALID) { | ||
+ frame_good = frame; | ||
+ } else { | ||
+ if (frame_good) { | ||
+ frame = frame_good; | ||
+ } else { | ||
+ for (int k = 0; k < FF_ARRAY_ELEMS(h->DPB); k++) { | ||
+ if ((&h->DPB[k] != current_picture || h->ps.pps->pps_curr_pic_ref_enabled_flag) && | ||
+ (h->DPB[k].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)) && | ||
+ h->DPB[k].sequence != HEVC_SEQUENCE_COUNTER_INVALID) { | ||
+ frame = &h->DPB[k]; | ||
+ break; | ||
+ } | ||
+ } | ||
+ } | ||
+ } | ||
rps_type = find_frame_rps_type(h, frame); | ||
fill_vaapi_pic(&pp->ReferenceFrames[i], frame, rps_type); | ||
} | ||
-- | ||
2.43.0 | ||
|