diff mbox

[FFmpeg-devel,v2] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

Message ID 20181109031330.7310-1-linjie.fu@intel.com
State Superseded
Headers show

Commit Message

Fu, Linjie Nov. 9, 2018, 3:13 a.m. UTC
Currently ff_get_format will go through all usable choices if the chosen
format was not supported. It will fallback to software path if the hardware
init fails.

Provided an option "-fallback_forbid 1" in user-code to detect frame->format and
hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---

[v2] detect hardware init failures in get_buffer and modify in user-code

 fftools/ffmpeg.c     | 2 ++
 fftools/ffmpeg.h     | 1 +
 fftools/ffmpeg_opt.c | 3 +++
 3 files changed, 6 insertions(+)

Comments

Eoff, Ullysses A Nov. 9, 2018, 3:34 a.m. UTC | #1
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of Linjie Fu

> Sent: Thursday, November 08, 2018 7:14 PM

> To: ffmpeg-devel@ffmpeg.org

> Cc: Fu, Linjie <linjie.fu@intel.com>

> Subject: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to forbid the fallback to software path when hardware init fails

> 

> Currently ff_get_format will go through all usable choices if the chosen

> format was not supported. It will fallback to software path if the hardware

> init fails.

> 

> Provided an option "-fallback_forbid 1" in user-code to detect frame->format and

> hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.

> 


I'm not sure I like this option name ("-fallback_forbid").  How about "-disable_fallback",
"-hwaccel_or_die", "-require_hwaccel" or "-no_sw_fallback"?  I like the last two the most.
Or maybe someone has a better suggestion?

> Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> ---

> 

> [v2] detect hardware init failures in get_buffer and modify in user-code

> 

>  fftools/ffmpeg.c     | 2 ++

>  fftools/ffmpeg.h     | 1 +

>  fftools/ffmpeg_opt.c | 3 +++

>  3 files changed, 6 insertions(+)

> 

> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c

> index da4259a9a8..45694fef57 100644

> --- a/fftools/ffmpeg.c

> +++ b/fftools/ffmpeg.c

> @@ -2890,6 +2890,8 @@ static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)

> 

>      if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)

>          return ist->hwaccel_get_buffer(s, frame, flags);

> +    else if (ist->fallback_forbid)

> +        return AVERROR(EINVAL);

> 

>      return avcodec_default_get_buffer2(s, frame, flags);

>  }

> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h

> index eb1eaf6363..67ddaeaaee 100644

> --- a/fftools/ffmpeg.h

> +++ b/fftools/ffmpeg.h

> @@ -365,6 +365,7 @@ typedef struct InputStream {

>      enum AVHWDeviceType hwaccel_device_type;

>      char  *hwaccel_device;

>      enum AVPixelFormat hwaccel_output_format;

> +    int fallback_forbid;

> 

>      /* hwaccel context */

>      void  *hwaccel_ctx;

> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c

> index d4851a2cd8..314e25565c 100644

> --- a/fftools/ffmpeg_opt.c

> +++ b/fftools/ffmpeg_opt.c

> @@ -3600,6 +3600,9 @@ const OptionDef options[] = {

>      { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |

>                            OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(autorotate) },

>          "automatically insert correct rotate filters" },

> +    { "fallback_forbid",  HAS_ARG | OPT_BOOL | OPT_SPEC |

> +                          OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(fallback_forbid)},

> +      "forbid the fallback to default software path when hardware init fails"},

> 

>      /* audio options */

>      { "aframes",        OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_audio_frames },

> --

> 2.17.1

> 

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Fu, Linjie Nov. 9, 2018, 9 a.m. UTC | #2
> -----Original Message-----

> From: Eoff, Ullysses A

> Sent: Friday, November 9, 2018 11:34

> To: FFmpeg development discussions and patches <ffmpeg-

> devel@ffmpeg.org>

> Cc: Fu, Linjie <linjie.fu@intel.com>

> Subject: RE: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to

> forbid the fallback to software path when hardware init fails

> 

> > -----Original Message-----

> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On

> Behalf Of Linjie Fu

> > Sent: Thursday, November 08, 2018 7:14 PM

> > To: ffmpeg-devel@ffmpeg.org

> > Cc: Fu, Linjie <linjie.fu@intel.com>

> > Subject: [FFmpeg-devel] [PATCH v2] fftools/ffmpeg: add an option to

> forbid the fallback to software path when hardware init fails

> >

> > Currently ff_get_format will go through all usable choices if the chosen

> > format was not supported. It will fallback to software path if the hardware

> > init fails.

> >

> > Provided an option "-fallback_forbid 1" in user-code to detect frame-

> >format and

> > hwaccel_get_buffer in get_buffer. If hardware init fails, returns an error.

> >

> 

> I'm not sure I like this option name ("-fallback_forbid").  How about "-

> disable_fallback",

> "-hwaccel_or_die", "-require_hwaccel" or "-no_sw_fallback"?  I like the last

> two the most.

> Or maybe someone has a better suggestion?


Thanks, will change the option name to "-require_hwaccel"  temporary in [v3] and add an error message.
Also will add some missing codes.

> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> > ---

> >

> > [v2] detect hardware init failures in get_buffer and modify in user-code

> >
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index da4259a9a8..45694fef57 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2890,6 +2890,8 @@  static int get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
 
     if (ist->hwaccel_get_buffer && frame->format == ist->hwaccel_pix_fmt)
         return ist->hwaccel_get_buffer(s, frame, flags);
+    else if (ist->fallback_forbid)
+        return AVERROR(EINVAL);
 
     return avcodec_default_get_buffer2(s, frame, flags);
 }
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index eb1eaf6363..67ddaeaaee 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -365,6 +365,7 @@  typedef struct InputStream {
     enum AVHWDeviceType hwaccel_device_type;
     char  *hwaccel_device;
     enum AVPixelFormat hwaccel_output_format;
+    int fallback_forbid;
 
     /* hwaccel context */
     void  *hwaccel_ctx;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index d4851a2cd8..314e25565c 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -3600,6 +3600,9 @@  const OptionDef options[] = {
     { "autorotate",       HAS_ARG | OPT_BOOL | OPT_SPEC |
                           OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(autorotate) },
         "automatically insert correct rotate filters" },
+    { "fallback_forbid",  HAS_ARG | OPT_BOOL | OPT_SPEC |
+                          OPT_EXPERT | OPT_INPUT,                                { .off = OFFSET(fallback_forbid)},
+      "forbid the fallback to default software path when hardware init fails"},
 
     /* audio options */
     { "aframes",        OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_audio_frames },