[libav-devel] [PATCH 1/2] avprobe: output proper INI format

Anton Khirnov anton at khirnov.net
Tue May 22 07:39:55 CEST 2012


On Mon, 21 May 2012 12:14:02 -0700, Luca Barbato <lu_zero at gentoo.org> wrote:
> On 21/05/12 10:23, Anton Khirnov wrote:
> > 
> > On Sat, 19 May 2012 11:46:04 -0700, Luca Barbato <lu_zero at gentoo.org> wrote:
> >> Make the output valid INI serialization.
> >> ---
> >>  avprobe.c |  507 ++++++++++++++++++++++++++++++++++++++++++++++---------------
> >>  1 files changed, 387 insertions(+), 120 deletions(-)
> >>
> >> diff --git a/avprobe.c b/avprobe.c
> >> index 6182875..543bf26 100644
> >> --- a/avprobe.c
> >> +++ b/avprobe.c
> >> @@ -64,6 +64,257 @@ void exit_program(int ret)
> >>      exit(ret);
> >>  }
> >>  
> >> +#define MAX_INDENT 4
> >> +
> >> +static int print_object_separator;
> >> +static int print_array_separator;
> >> +static int print_item_separator;
> >> +static int indent_level;
> >> +
> >> +AVIOContext *avp_out = NULL;
> > 
> > static?
> 
> Ok.
> 
> >> +
> >> +#define AVP_INDENT() avio_printf(avp_out, "%*c", indent_level * 2, ' ')
> >> +
> >> +/*
> >> + * Default format, INI
> >> + *
> >> + * - all key and values are utf8
> >> + * - '.' is the subgroup separator
> >> + * - newlines and the following characters are escaped
> >> + * - '\' is the escape character
> >> + * - '#' is the comment
> >> + * - '=' is the key/value separators
> >> + * - ':' is not used but usually parsed as key/value separator
> >> + */
> >> +
> >> +static void ini_print_header(void)
> >> +{
> >> +    avio_printf(avp_out, "# avprobe output\n\n");
> >> +}
> >> +static void ini_print_footer(void)
> >> +{
> >> +    avio_w8(avp_out, '\n');
> >> +}
> >> +
> >> +static void ini_escape_print(const char *s)
> >> +{
> >> +    int i = 0;
> >> +    char c = 0;
> >> +
> >> +    while (c = s[i++]) {
> >> +        switch (c) {
> >> +        case '\r': avio_printf(avp_out, "%s", "\\r"); break;
> >> +        case '\n': avio_printf(avp_out, "%s", "\\n"); break;
> >> +        case '\\': avio_printf(avp_out, "%s", "\\\\"); break;
> >> +        case '\f': avio_printf(avp_out, "%s", "\\f"); break;
> >> +        case '\b': avio_printf(avp_out, "%s", "\\b"); break;
> >> +        case '\t': avio_printf(avp_out, "%s", "\\t"); break;
> >> +        case '#':
> >> +        case '=':
> >> +        case ':': avio_w8(avp_out, '\\');
> >> +        default:
> >> +            if ((unsigned char)c < 32)
> >> +                avio_printf(avp_out, "\\x00%02x", c & 0xff);
> >> +            else
> >> +                avio_w8(avp_out, c);
> >> +        break;
> >> +        }
> >> +    }
> >> +}
> >> +
> >> +static char const **prefix;
> >> +static int group_index = -1;
> >> +static int in_object;
> > 
> > After the horror that avconv used to be, I would strongly prefer to
> > avoid this kind of globals. Please add some kind of writer-specific
> > private data and store those there.
> 
> If we do agree on the rest, (the output mostly).
> I'll add a context struct if that makes you feel more comfortable.
> 
> > Writer descriptions themselves might also be easier to follow if they
> > were put together in a struct.
> 
> The sanest thing would be split them in separate files, not sure if it
> worth it...
> 

AFAIK it's not possible without some nontrivial changes to the build
system

Otherwise I'd have split avconv long ago.

-- 
Anton Khirnov


More information about the libav-devel mailing list