diff mbox series

[FFmpeg-devel] ffmpeg_hw: Don't ignore key parameters when initializing a hw device

Message ID 20210811064405.7723-1-haihao.xiang@intel.com
State Accepted
Commit 51a80aacce1a7bd20823798dc9e5ec5f23a3b62d
Headers show
Series [FFmpeg-devel] ffmpeg_hw: Don't ignore key parameters when initializing a hw device | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Xiang, Haihao Aug. 11, 2021, 6:44 a.m. UTC
Currently user may use '-init_hw_device type=name' to initialize a hw
device, however the key parameter is ignored when use '-init_hw_device
type=name,key=value'. After applying this patch, user may set key
parameter if needed.
---
 fftools/ffmpeg_hw.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Soft Works Aug. 11, 2021, 7:42 p.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Haihao Xiang
> Sent: Wednesday, 11 August 2021 08:44
> To: ffmpeg-devel@ffmpeg.org
> Cc: Haihao Xiang <haihao.xiang@intel.com>
> Subject: [FFmpeg-devel] [PATCH] ffmpeg_hw: Don't ignore key
> parameters when initializing a hw device
> 
> Currently user may use '-init_hw_device type=name' to initialize a hw
> device, however the key parameter is ignored when use '-
> init_hw_device
> type=name,key=value'. After applying this patch, user may set key
> parameter if needed.
> ---
>  fftools/ffmpeg_hw.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 

This makes sense as it allows to further simplify hw initialization
command lines.

As an example, you can write 

-init_hw_device qsv=qd,child_device=1

Instead of

-init_hw_device qsv=qd:hw_any,child_device=1

So besides the former being shorter, it also saves the user from 
needing to remember 'hw_any' (or hw, hw2, hw3, hw4 matching the 
child_device param on Windows).

LGTM.

softworkz
James Almer Aug. 17, 2021, 1:10 p.m. UTC | #2
On 8/11/2021 4:42 PM, Soft Works wrote:
> 
> 
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
>> Haihao Xiang
>> Sent: Wednesday, 11 August 2021 08:44
>> To: ffmpeg-devel@ffmpeg.org
>> Cc: Haihao Xiang <haihao.xiang@intel.com>
>> Subject: [FFmpeg-devel] [PATCH] ffmpeg_hw: Don't ignore key
>> parameters when initializing a hw device
>>
>> Currently user may use '-init_hw_device type=name' to initialize a hw
>> device, however the key parameter is ignored when use '-
>> init_hw_device
>> type=name,key=value'. After applying this patch, user may set key
>> parameter if needed.
>> ---
>>   fftools/ffmpeg_hw.c | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
> 
> This makes sense as it allows to further simplify hw initialization
> command lines.
> 
> As an example, you can write
> 
> -init_hw_device qsv=qd,child_device=1
> 
> Instead of
> 
> -init_hw_device qsv=qd:hw_any,child_device=1
> 
> So besides the former being shorter, it also saves the user from
> needing to remember 'hw_any' (or hw, hw2, hw3, hw4 matching the
> child_device param on Windows).
> 
> LGTM.
> 
> softworkz

Pushed, thanks.
diff mbox series

Patch

diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index fc4a5d31d6..c55c459aa7 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -93,6 +93,8 @@  static char *hw_device_default_name(enum AVHWDeviceType type)
 
 int hw_device_init_from_string(const char *arg, HWDevice **dev_out)
 {
+    // "type=name"
+    // "type=name,key=value,key2=value2"
     // "type=name:device,key=value,key2=value2"
     // "type:device,key=value,key2=value2"
     // -> av_hwdevice_ctx_create()
@@ -124,7 +126,7 @@  int hw_device_init_from_string(const char *arg, HWDevice **dev_out)
     }
 
     if (*p == '=') {
-        k = strcspn(p + 1, ":@");
+        k = strcspn(p + 1, ":@,");
 
         name = av_strndup(p + 1, k);
         if (!name) {
@@ -190,6 +192,18 @@  int hw_device_init_from_string(const char *arg, HWDevice **dev_out)
                                              src->device_ref, 0);
         if (err < 0)
             goto fail;
+    } else if (*p == ',') {
+        err = av_dict_parse_string(&options, p + 1, "=", ",", 0);
+
+        if (err < 0) {
+            errmsg = "failed to parse options";
+            goto invalid;
+        }
+
+        err = av_hwdevice_ctx_create(&device_ref, type,
+                                     NULL, options, 0);
+        if (err < 0)
+            goto fail;
     } else {
         errmsg = "parse error";
         goto invalid;