Maxym Dmytrychenko
2018-07-13 14:24:41 UTC
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
Signed-off-by: Maxym Dmytrychenko <***@gmail.com>
---
libavutil/hwcontext_qsv.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..c540208f9 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
typedef struct QSVFramesContext {
mfxSession session_download;
+ int session_download_init;
mfxSession session_upload;
+ int session_upload_init;
AVBufferRef *child_frames_ref;
mfxFrameSurface1 *surfaces_internal;
@@ -535,14 +537,6 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
}
- ret = qsv_init_internal_session(ctx, &s->session_download, 0);
- if (ret < 0)
- return ret;
-
- ret = qsv_init_internal_session(ctx, &s->session_upload, 1);
- if (ret < 0)
- return ret;
-
return 0;
}
@@ -740,6 +734,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
mfxSyncPoint sync = NULL;
mfxStatus err;
+ int ret = -1;
+
+ if (!s->session_download_init) {
+ s->session_download_init = 1;
+ ret = qsv_init_internal_session(ctx, &s->session_download, 0);
+ if (ret < 0)
+ return ret;
+ }
if (!s->session_download) {
if (s->child_frames_ref)
@@ -787,6 +789,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
mfxSyncPoint sync = NULL;
mfxStatus err;
+ int ret = -1;
+
+ if (!s->session_upload_init) {
+ s->session_upload_init = 1;
+ ret = qsv_init_internal_session(ctx, &s->session_upload, 1);
+ if (ret < 0)
+ return ret;
+ }
if (!s->session_upload) {
if (s->child_frames_ref)
can increase CPU utilization and this patch fixes it.
Signed-off-by: Maxym Dmytrychenko <***@gmail.com>
---
libavutil/hwcontext_qsv.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..c540208f9 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
typedef struct QSVFramesContext {
mfxSession session_download;
+ int session_download_init;
mfxSession session_upload;
+ int session_upload_init;
AVBufferRef *child_frames_ref;
mfxFrameSurface1 *surfaces_internal;
@@ -535,14 +537,6 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
}
- ret = qsv_init_internal_session(ctx, &s->session_download, 0);
- if (ret < 0)
- return ret;
-
- ret = qsv_init_internal_session(ctx, &s->session_upload, 1);
- if (ret < 0)
- return ret;
-
return 0;
}
@@ -740,6 +734,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
mfxSyncPoint sync = NULL;
mfxStatus err;
+ int ret = -1;
+
+ if (!s->session_download_init) {
+ s->session_download_init = 1;
+ ret = qsv_init_internal_session(ctx, &s->session_download, 0);
+ if (ret < 0)
+ return ret;
+ }
if (!s->session_download) {
if (s->child_frames_ref)
@@ -787,6 +789,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
mfxSyncPoint sync = NULL;
mfxStatus err;
+ int ret = -1;
+
+ if (!s->session_upload_init) {
+ s->session_upload_init = 1;
+ ret = qsv_init_internal_session(ctx, &s->session_upload, 1);
+ if (ret < 0)
+ return ret;
+ }
if (!s->session_upload) {
if (s->child_frames_ref)
--
2.15.2 (Apple Git-101.1)
2.15.2 (Apple Git-101.1)