Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 1 | From 78a97c1ec35ada76d83fc67d0549ba56c74d8875 Mon Sep 17 00:00:00 2001 |
| 2 | From: Seungha Yang <seungha@centricular.com> |
| 3 | Date: Thu, 7 Jul 2022 22:16:30 +0900 |
| 4 | Subject: [PATCH] libav: Fix for APNG encoder property registration |
| 5 | |
| 6 | The AVClass name of Animated PNG in FFmpeg 5.x is "(A)PNG" |
| 7 | and it will be converted to "-a-png" through |
| 8 | g_ascii_strdown() and g_strcanon(). But GLib disallow leading '-' |
| 9 | character for a GType name. Strip leading '-' to workaround it. |
| 10 | |
| 11 | Upstream-Status: Backport [https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2724] |
| 12 | |
| 13 | Seungha Yangs patch was imported without modifications. |
| 14 | |
| 15 | Signed-off-by: Claus Stovgaard <claus.stovgaard@gmail.com> |
| 16 | --- |
| 17 | ext/libav/gstavcfg.c | 29 +++++++++++++++++++++++------ |
| 18 | 1 file changed, 23 insertions(+), 6 deletions(-) |
| 19 | |
| 20 | diff --git a/ext/libav/gstavcfg.c b/ext/libav/gstavcfg.c |
| 21 | index c736920..a8635a7 100644 |
| 22 | --- a/ext/libav/gstavcfg.c |
| 23 | +++ b/ext/libav/gstavcfg.c |
| 24 | @@ -91,10 +91,19 @@ register_enum (const AVClass ** obj, const AVOption * top_opt) |
| 25 | gchar *lower_obj_name = g_ascii_strdown ((*obj)->class_name, -1); |
| 26 | gchar *enum_name = g_strdup_printf ("%s-%s", lower_obj_name, top_opt->unit); |
| 27 | gboolean none_default = TRUE; |
| 28 | + const gchar *enum_name_strip; |
| 29 | |
| 30 | g_strcanon (enum_name, G_CSET_a_2_z G_CSET_DIGITS, '-'); |
| 31 | |
| 32 | - if ((res = g_type_from_name (enum_name))) |
| 33 | + /* strip leading '-'s */ |
| 34 | + enum_name_strip = enum_name; |
| 35 | + while (enum_name_strip[0] == '-') |
| 36 | + enum_name_strip++; |
| 37 | + |
| 38 | + if (enum_name_strip[0] == '\0') |
| 39 | + goto done; |
| 40 | + |
| 41 | + if ((res = g_type_from_name (enum_name_strip))) |
| 42 | goto done; |
| 43 | |
| 44 | while ((opt = av_opt_next (obj, opt))) { |
| 45 | @@ -150,9 +159,8 @@ register_enum (const AVClass ** obj, const AVOption * top_opt) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | - res = |
| 50 | - g_enum_register_static (enum_name, &g_array_index (values, GEnumValue, |
| 51 | - 0)); |
| 52 | + res = g_enum_register_static (enum_name_strip, |
| 53 | + &g_array_index (values, GEnumValue, 0)); |
| 54 | |
| 55 | gst_type_mark_as_plugin_api (res, 0); |
| 56 | } |
| 57 | @@ -177,10 +185,19 @@ register_flags (const AVClass ** obj, const AVOption * top_opt) |
| 58 | GArray *values = g_array_new (TRUE, TRUE, sizeof (GEnumValue)); |
| 59 | gchar *lower_obj_name = g_ascii_strdown ((*obj)->class_name, -1); |
| 60 | gchar *flags_name = g_strdup_printf ("%s-%s", lower_obj_name, top_opt->unit); |
| 61 | + const gchar *flags_name_strip; |
| 62 | |
| 63 | g_strcanon (flags_name, G_CSET_a_2_z G_CSET_DIGITS, '-'); |
| 64 | |
| 65 | - if ((res = g_type_from_name (flags_name))) |
| 66 | + /* strip leading '-'s */ |
| 67 | + flags_name_strip = flags_name; |
| 68 | + while (flags_name_strip[0] == '-') |
| 69 | + flags_name_strip++; |
| 70 | + |
| 71 | + if (flags_name_strip[0] == '\0') |
| 72 | + goto done; |
| 73 | + |
| 74 | + if ((res = g_type_from_name (flags_name_strip))) |
| 75 | goto done; |
| 76 | |
| 77 | while ((opt = av_opt_next (obj, opt))) { |
| 78 | @@ -211,7 +228,7 @@ register_flags (const AVClass ** obj, const AVOption * top_opt) |
| 79 | g_array_sort (values, (GCompareFunc) cmp_flags_value); |
| 80 | |
| 81 | res = |
| 82 | - g_flags_register_static (flags_name, &g_array_index (values, |
| 83 | + g_flags_register_static (flags_name_strip, &g_array_index (values, |
| 84 | GFlagsValue, 0)); |
| 85 | |
| 86 | gst_type_mark_as_plugin_api (res, 0); |