[FFmpeg-devel] [PATCH 1/2] refactored srtdec
Clément Bœsch
u at pkh.me
Fri Apr 10 11:09:03 CEST 2015
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] refactored srtdec
"avcodec/subrip: factor out HTML parsing code"
On Thu, Apr 09, 2015 at 11:54:22PM -0700, Yayoi wrote:
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/htmlsubtitles.c | 179 +++++++++++++++++++++++++++++++++++++++++++++
> libavcodec/htmlsubtitles.h | 45 ++++++++++++
> libavcodec/srtdec.c | 149 +------------------------------------
> 4 files changed, 227 insertions(+), 148 deletions(-)
> create mode 100644 libavcodec/htmlsubtitles.c
> create mode 100644 libavcodec/htmlsubtitles.h
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b01ecd6..8384458 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -446,7 +446,7 @@ OBJS-$(CONFIG_SONIC_DECODER) += sonic.o
> OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o
> OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o
> OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o
> -OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o
> +OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o htmlsubtitles.o
> OBJS-$(CONFIG_SRT_ENCODER) += srtenc.o ass_split.o
> OBJS-$(CONFIG_STL_DECODER) += textdec.o ass.o
> OBJS-$(CONFIG_SUBRIP_DECODER) += srtdec.o ass.o
> diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c
> new file mode 100644
> index 0000000..7eeec98
> --- /dev/null
> +++ b/libavcodec/htmlsubtitles.c
> @@ -0,0 +1,179 @@
> +/*
> + * SubRip subtitle decoder
This file is meant to be shared and not SubRip specific, so you can remove
that line.
> + * Copyright (c) 2010 Aurelien Jacobs <aurel at gnuage.org>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/avstring.h"
> +#include "libavutil/common.h"
> +#include "libavutil/intreadwrite.h"
Do you need this?
> +#include "libavutil/parseutils.h"
> +#include "avcodec.h"
> +#include "ass.h"
> +#include "htmlsubtitles.h"
> +
> +static int html_color_parse(AVCodecContext *avctx, const char *str)
> +{
> + uint8_t rgba[4];
> + if (av_parse_color(rgba, str, strcspn(str, "\" >"), avctx) < 0)
> + return -1;
> + return rgba[0] | rgba[1] << 8 | rgba[2] << 16;
> +}
> +
> +enum {
> + PARAM_UNKNOWN = -1,
> + PARAM_SIZE,
> + PARAM_COLOR,
> + PARAM_FACE,
> + PARAM_NUMBER
> +};
> +
> + typedef struct SrtStack {
You added a space where there wasn't any
> + char tag[128];
> + char param[PARAM_NUMBER][128];
> +} SrtStack;
> +
> +static void rstrip_spaces_buf(AVBPrint *buf)
> +{
> + while (buf->len > 0 && buf->str[buf->len - 1] == ' ')
> + buf->str[--buf->len] = 0;
> +}
> +
> +void ff_htmlmarkup_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *in)
> +{
[...]
> +}
All of this probably OK if straight copy from the subrip decoder.
One note though: AVCodecContext is probably only necessary as a logging
context, so you can probably use a void* here, and avoid the avcodec.h
include.
> \ No newline at end of file
Please fix that warning
> diff --git a/libavcodec/htmlsubtitles.h b/libavcodec/htmlsubtitles.h
> new file mode 100644
> index 0000000..4f21205
> --- /dev/null
> +++ b/libavcodec/htmlsubtitles.h
> @@ -0,0 +1,45 @@
> +/*
> + * SSA/ASS common functions
Not really
> + * Copyright (c) 2010 Aurelien Jacobs <aurel at gnuage.org>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVCODEC_HTMLSUBTITLES_H
> +#define AVCODEC_HTMLSUBTITLES_H
> +
> +#include "avcodec.h"
> +#include "libavutil/bprint.h"
> +
> +/**
> + * @name Default values for ASS style
> + * @{
> + */
> +#define ASS_DEFAULT_FONT "Arial"
> +#define ASS_DEFAULT_FONT_SIZE 16
> +#define ASS_DEFAULT_COLOR 0xffffff
> +#define ASS_DEFAULT_BACK_COLOR 0
> +#define ASS_DEFAULT_BOLD 0
> +#define ASS_DEFAULT_ITALIC 0
> +#define ASS_DEFAULT_UNDERLINE 0
> +#define ASS_DEFAULT_ALIGNMENT 2
> +/** @} */
> +
As already pointed out, this doesn't belong here.
> +void ff_htmlmarkup_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *in);
> +
> +
> +#endif /* AVCODEC_HTMLSUBTITLES_H */
[...]
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150410/70352215/attachment.asc>
More information about the ffmpeg-devel
mailing list