* [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function
@ 2022-08-12 12:55 Fei Wang
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Fei Wang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Fei Wang @ 2022-08-12 12:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Fei Wang, Linjie Fu
From: Linjie Fu <linjie.fu@intel.com>
Wrap the procedure of getting the hardware config from a pixel format
into a function.
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
libavcodec/decode.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75373989c6..d66d5a4160 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1156,6 +1156,26 @@ static void hwaccel_uninit(AVCodecContext *avctx)
av_buffer_unref(&avctx->hw_frames_ctx);
}
+static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum AVPixelFormat fmt)
+{
+ const AVCodecHWConfigInternal *hw_config;
+ int i;
+
+ if (ffcodec(avctx->codec)->hw_configs) {
+ for (i = 0;; i++) {
+ hw_config = ffcodec(avctx->codec)->hw_configs[i];
+ if (!hw_config)
+ break;
+ if (hw_config->public.pix_fmt == fmt)
+ break;
+ }
+ } else {
+ hw_config = NULL;
+ }
+
+ return hw_config;
+}
+
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
{
const AVPixFmtDescriptor *desc;
@@ -1213,18 +1233,7 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
break;
}
- if (ffcodec(avctx->codec)->hw_configs) {
- for (i = 0;; i++) {
- hw_config = ffcodec(avctx->codec)->hw_configs[i];
- if (!hw_config)
- break;
- if (hw_config->public.pix_fmt == user_choice)
- break;
- }
- } else {
- hw_config = NULL;
- }
-
+ hw_config = get_hw_config(avctx, user_choice);
if (!hw_config) {
// No config available, so no extra setup required.
ret = user_choice;
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel
2022-08-12 12:55 [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Fei Wang
@ 2022-08-12 12:55 ` Fei Wang
2022-08-16 11:26 ` Anton Khirnov
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 3/3] lavc/vaapi_vp9: add surface internal re-allocation capability Fei Wang
2022-08-16 11:22 ` [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Anton Khirnov
2 siblings, 1 reply; 6+ messages in thread
From: Fei Wang @ 2022-08-12 12:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Fei Wang, Linjie Fu
From: Linjie Fu <linjie.fu@intel.com>
Add HWACCEL_CAP_INTERNAL_ALLOC flag to indicate hwaccels are able to
re-allocate surface internally through ff_decode_get_hw_frames_ctx.
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++
libavcodec/hwconfig.h | 1 +
2 files changed, 37 insertions(+)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index d66d5a4160..00c9141d91 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1176,6 +1176,33 @@ static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum
return hw_config;
}
+static int hwaccel_realloc_surface(AVCodecContext *avctx)
+{
+ const AVCodecHWConfigInternal *hw_config;
+ int ret;
+
+ if (avctx->hw_frames_ctx)
+ av_buffer_unref(&avctx->hw_frames_ctx);
+
+ hw_config = get_hw_config(avctx, avctx->pix_fmt);
+ if (!hw_config)
+ return AV_PIX_FMT_NONE;
+
+ if (avctx->hw_device_ctx &&
+ hw_config->public.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
+ const AVHWDeviceContext *device_ctx =
+ (AVHWDeviceContext*)avctx->hw_device_ctx->data;
+ ret = ff_decode_get_hw_frames_ctx(avctx, device_ctx->type);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_WARNING, "Failed to re-allocate hwaccel surface internally.\n");
+ return AV_PIX_FMT_NONE;
+ }
+ } else
+ return AV_PIX_FMT_NONE;
+
+ return hw_config->public.pix_fmt;
+}
+
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
{
const AVPixFmtDescriptor *desc;
@@ -1202,6 +1229,15 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
return AV_PIX_FMT_NONE;
for (;;) {
+ if (avctx->internal->hwaccel_priv_data &&
+ avctx->hwaccel->caps_internal & HWACCEL_CAP_INTERNAL_ALLOC) {
+ err = hwaccel_realloc_surface(avctx);
+ if (err < 0)
+ av_log(avctx, AV_LOG_WARNING, "Try to re-initialize all.\n");
+ else
+ return err;
+ }
+
// Remove the previous hwaccel, if there was one.
hwaccel_uninit(avctx);
diff --git a/libavcodec/hwconfig.h b/libavcodec/hwconfig.h
index 721424912c..7405c66c07 100644
--- a/libavcodec/hwconfig.h
+++ b/libavcodec/hwconfig.h
@@ -24,6 +24,7 @@
#define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
+#define HWACCEL_CAP_INTERNAL_ALLOC (1 << 1)
typedef struct AVCodecHWConfigInternal {
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH v1 3/3] lavc/vaapi_vp9: add surface internal re-allocation capability
2022-08-12 12:55 [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Fei Wang
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Fei Wang
@ 2022-08-12 12:55 ` Fei Wang
2022-08-16 11:22 ` [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Anton Khirnov
2 siblings, 0 replies; 6+ messages in thread
From: Fei Wang @ 2022-08-12 12:55 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Fei Wang, Linjie Fu
From: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
libavcodec/vaapi_vp9.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/vaapi_vp9.c b/libavcodec/vaapi_vp9.c
index 776382f683..fc6ff0a0f2 100644
--- a/libavcodec/vaapi_vp9.c
+++ b/libavcodec/vaapi_vp9.c
@@ -181,5 +181,5 @@ const AVHWAccel ff_vp9_vaapi_hwaccel = {
.uninit = ff_vaapi_decode_uninit,
.frame_params = ff_vaapi_common_frame_params,
.priv_data_size = sizeof(VAAPIDecodeContext),
- .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_INTERNAL_ALLOC,
};
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function
2022-08-12 12:55 [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Fei Wang
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Fei Wang
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 3/3] lavc/vaapi_vp9: add surface internal re-allocation capability Fei Wang
@ 2022-08-16 11:22 ` Anton Khirnov
2022-08-18 2:34 ` Wang, Fei W
2 siblings, 1 reply; 6+ messages in thread
From: Anton Khirnov @ 2022-08-16 11:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Fei Wang, Linjie Fu
The commit message is misleading - you are not adding code, you are
moving code.
Quoting Fei Wang (2022-08-12 14:55:43)
> From: Linjie Fu <linjie.fu@intel.com>
>
> Wrap the procedure of getting the hardware config from a pixel format
> into a function.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
> libavcodec/decode.c | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 75373989c6..d66d5a4160 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1156,6 +1156,26 @@ static void hwaccel_uninit(AVCodecContext *avctx)
> av_buffer_unref(&avctx->hw_frames_ctx);
> }
>
> +static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum AVPixelFormat fmt)
> +{
> + const AVCodecHWConfigInternal *hw_config;
> + int i;
Should be declared in the loop
> + if (ffcodec(avctx->codec)->hw_configs) {
> + for (i = 0;; i++) {
> + hw_config = ffcodec(avctx->codec)->hw_configs[i];
> + if (!hw_config)
> + break;
return NULL;
> + if (hw_config->public.pix_fmt == fmt)
> + break;
return hw_config;
> + }
> + } else {
> + hw_config = NULL;
> + }
You can save one level of indentation by starting with
if (!ffcodec(avctx->codec)->hw_configs)
return NULL;
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Fei Wang
@ 2022-08-16 11:26 ` Anton Khirnov
0 siblings, 0 replies; 6+ messages in thread
From: Anton Khirnov @ 2022-08-16 11:26 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Fei Wang, Linjie Fu
Quoting Fei Wang (2022-08-12 14:55:44)
> From: Linjie Fu <linjie.fu@intel.com>
>
> Add HWACCEL_CAP_INTERNAL_ALLOC flag to indicate hwaccels are able to
> re-allocate surface internally through ff_decode_get_hw_frames_ctx.
>
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
The commit message should explain what problem is this trying to solve.
It is very much not obvious to me.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function
2022-08-16 11:22 ` [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Anton Khirnov
@ 2022-08-18 2:34 ` Wang, Fei W
0 siblings, 0 replies; 6+ messages in thread
From: Wang, Fei W @ 2022-08-18 2:34 UTC (permalink / raw)
To: anton, ffmpeg-devel; +Cc: linjie.fu
On Tue, 2022-08-16 at 13:22 +0200, Anton Khirnov wrote:
> The commit message is misleading - you are not adding code, you are
> moving code.
>
> Quoting Fei Wang (2022-08-12 14:55:43)
> > From: Linjie Fu <linjie.fu@intel.com>
> >
> > Wrap the procedure of getting the hardware config from a pixel
> > format
> > into a function.
> >
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> > ---
> > libavcodec/decode.c | 33 +++++++++++++++++++++------------
> > 1 file changed, 21 insertions(+), 12 deletions(-)
> >
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75373989c6..d66d5a4160 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1156,6 +1156,26 @@ static void hwaccel_uninit(AVCodecContext
> > *avctx)
> > av_buffer_unref(&avctx->hw_frames_ctx);
> > }
> >
> > +static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext
> > *avctx, enum AVPixelFormat fmt)
> > +{
> > + const AVCodecHWConfigInternal *hw_config;
> > + int i;
>
> Should be declared in the loop
>
> > + if (ffcodec(avctx->codec)->hw_configs) {
> > + for (i = 0;; i++) {
> > + hw_config = ffcodec(avctx->codec)->hw_configs[i];
> > + if (!hw_config)
> > + break;
>
> return NULL;
>
> > + if (hw_config->public.pix_fmt == fmt)
> > + break;
>
> return hw_config;
>
> > + }
> > + } else {
> > + hw_config = NULL;
> > + }
>
> You can save one level of indentation by starting with
>
> if (!ffcodec(avctx->codec)->hw_configs)
> return NULL;
Fix in V2.
Thanks
Fei
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-08-18 2:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-12 12:55 [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Fei Wang
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 2/3] lavc/decode: Add internal surface re-allocate method for hwaccel Fei Wang
2022-08-16 11:26 ` Anton Khirnov
2022-08-12 12:55 ` [FFmpeg-devel] [PATCH v1 3/3] lavc/vaapi_vp9: add surface internal re-allocation capability Fei Wang
2022-08-16 11:22 ` [FFmpeg-devel] [PATCH v1 1/3] lavc/decode: Add get_hw_config function Anton Khirnov
2022-08-18 2:34 ` Wang, Fei W
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git