diff mbox series

[FFmpeg-devel,v9,02/13] global: Move ass helper functions to avutil and extend ass dialog parsing

Message ID MN2PR04MB5981B3662987810D4D23FECFBAA49@MN2PR04MB5981.namprd04.prod.outlook.com
State Superseded, archived
Headers show
Series [FFmpeg-devel,v9,01/13] global: Prepare AVFrame for subtitle handling
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Soft Works Sept. 24, 2021, 12:30 a.m. UTC
Signed-off-by: softworkz <softworkz@hotmail.com>
---
 libavcodec/Makefile                   | 56 +++++++++++-----------
 libavcodec/ass_internal.h             | 68 +++++++++++++++++++++++++++
 libavcodec/assdec.c                   |  2 +-
 libavcodec/assenc.c                   |  2 +-
 libavcodec/ccaption_dec.c             | 15 +++---
 libavcodec/jacosubdec.c               |  2 +-
 libavcodec/microdvddec.c              |  7 +--
 libavcodec/movtextdec.c               |  3 +-
 libavcodec/movtextenc.c               |  4 +-
 libavcodec/mpl2dec.c                  |  2 +-
 libavcodec/realtextdec.c              |  2 +-
 libavcodec/samidec.c                  |  2 +-
 libavcodec/srtdec.c                   |  2 +-
 libavcodec/srtenc.c                   |  4 +-
 libavcodec/subviewerdec.c             |  2 +-
 libavcodec/textdec.c                  |  2 +-
 libavcodec/ttmlenc.c                  |  3 +-
 libavcodec/webvttdec.c                |  2 +-
 libavcodec/webvttenc.c                |  4 +-
 libavutil/Makefile                    |  4 ++
 {libavcodec => libavutil}/ass.c       | 63 ++++++++++++-------------
 {libavcodec => libavutil}/ass.h       | 64 ++++++++++++-------------
 {libavcodec => libavutil}/ass_split.c | 12 ++++-
 {libavcodec => libavutil}/ass_split.h |  8 ++--
 24 files changed, 206 insertions(+), 129 deletions(-)
 create mode 100644 libavcodec/ass_internal.h
 rename {libavcodec => libavutil}/ass.c (77%)
 rename {libavcodec => libavutil}/ass.h (71%)
 rename {libavcodec => libavutil}/ass_split.c (97%)
 rename {libavcodec => libavutil}/ass_split.h (96%)
diff mbox series

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 11873eecae..f1643e3845 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -209,10 +209,10 @@  OBJS-$(CONFIG_APNG_DECODER)            += png.o pngdec.o pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)            += png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)            += arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)            += argo.o
-OBJS-$(CONFIG_SSA_DECODER)             += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER)             += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER)             += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER)             += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER)             += assenc.o
+OBJS-$(CONFIG_ASS_DECODER)             += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER)             += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)            += asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)            += asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)            += asvdec.o asv.o mpeg12data.o
@@ -252,7 +252,7 @@  OBJS-$(CONFIG_BRENDER_PIX_DECODER)     += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER)             += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)            += cavs.o cavsdec.o cavsdsp.o \
                                           cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)        += ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)        += ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)      += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER)         += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)            += cdxl.o
@@ -423,7 +423,7 @@  OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER)             += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER)         += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER)         += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)        += j2kenc.o mqcenc.o mqc.o jpeg2000.o \
                                           jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)        += jpeg2000dec.o jpeg2000.o jpeg2000dsp.o \
@@ -445,7 +445,7 @@  OBJS-$(CONFIG_MAGICYUV_ENCODER)        += magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)            += mdec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_METASOUND_DECODER)       += metasound.o metasound_data.o \
                                           twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)        += microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)        += microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)           += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)           += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)       += qsvdec.o
@@ -460,8 +460,8 @@  OBJS-$(CONFIG_MLP_ENCODER)             += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER)         += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)        += mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)    += motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER)         += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCODER)         += movtextenc.o ass_split.o
+OBJS-$(CONFIG_MOVTEXT_DECODER)         += movtextdec.o
+OBJS-$(CONFIG_MOVTEXT_ENCODER)         += movtextenc.o
 OBJS-$(CONFIG_MP1_DECODER)             += mpegaudiodec_fixed.o
 OBJS-$(CONFIG_MP1FLOAT_DECODER)        += mpegaudiodec_float.o
 OBJS-$(CONFIG_MP2_DECODER)             += mpegaudiodec_fixed.o
@@ -500,7 +500,7 @@  OBJS-$(CONFIG_MPEG4_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_MPEG4_OMX_ENCODER)       += omx.o
 OBJS-$(CONFIG_MPEG4_V4L2M2M_DECODER)   += v4l2_m2m_dec.o
 OBJS-$(CONFIG_MPEG4_V4L2M2M_ENCODER)   += v4l2_m2m_enc.o
-OBJS-$(CONFIG_MPL2_DECODER)            += mpl2dec.o ass.o
+OBJS-$(CONFIG_MPL2_DECODER)            += mpl2dec.o
 OBJS-$(CONFIG_MSA1_DECODER)            += mss3.o
 OBJS-$(CONFIG_MSCC_DECODER)            += mscc.o
 OBJS-$(CONFIG_MSMPEG4V1_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
@@ -553,7 +553,7 @@  OBJS-$(CONFIG_PGX_DECODER)             += pgxdec.o
 OBJS-$(CONFIG_PHOTOCD_DECODER)         += photocd.o
 OBJS-$(CONFIG_PICTOR_DECODER)          += pictordec.o cga_data.o
 OBJS-$(CONFIG_PIXLET_DECODER)          += pixlet.o
-OBJS-$(CONFIG_PJS_DECODER)             += textdec.o ass.o
+OBJS-$(CONFIG_PJS_DECODER)             += textdec.o
 OBJS-$(CONFIG_PNG_DECODER)             += png.o pngdec.o pngdsp.o
 OBJS-$(CONFIG_PNG_ENCODER)             += png.o pngenc.o
 OBJS-$(CONFIG_PPM_DECODER)             += pnmdec.o pnm.o
@@ -585,7 +585,7 @@  OBJS-$(CONFIG_RALF_DECODER)            += ralf.o
 OBJS-$(CONFIG_RASC_DECODER)            += rasc.o
 OBJS-$(CONFIG_RAWVIDEO_DECODER)        += rawdec.o
 OBJS-$(CONFIG_RAWVIDEO_ENCODER)        += rawenc.o
-OBJS-$(CONFIG_REALTEXT_DECODER)        += realtextdec.o ass.o
+OBJS-$(CONFIG_REALTEXT_DECODER)        += realtextdec.o
 OBJS-$(CONFIG_RL2_DECODER)             += rl2.o
 OBJS-$(CONFIG_ROQ_DECODER)             += roqvideodec.o roqvideo.o
 OBJS-$(CONFIG_ROQ_ENCODER)             += roqvideoenc.o roqvideo.o elbg.o
@@ -600,7 +600,7 @@  OBJS-$(CONFIG_RV20_DECODER)            += rv10.o
 OBJS-$(CONFIG_RV20_ENCODER)            += rv20enc.o
 OBJS-$(CONFIG_RV30_DECODER)            += rv30.o rv34.o rv30dsp.o
 OBJS-$(CONFIG_RV40_DECODER)            += rv40.o rv34.o rv40dsp.o
-OBJS-$(CONFIG_SAMI_DECODER)            += samidec.o ass.o htmlsubtitles.o
+OBJS-$(CONFIG_SAMI_DECODER)            += samidec.o htmlsubtitles.o
 OBJS-$(CONFIG_S302M_DECODER)           += s302m.o
 OBJS-$(CONFIG_S302M_ENCODER)           += s302menc.o
 OBJS-$(CONFIG_SANM_DECODER)            += sanm.o
@@ -634,13 +634,13 @@  OBJS-$(CONFIG_SPEEDHQ_DECODER)         += speedhq.o mpeg12.o mpeg12data.o simple
 OBJS-$(CONFIG_SPEEDHQ_ENCODER)         += speedhq.o mpeg12data.o mpeg12enc.o speedhqenc.o
 OBJS-$(CONFIG_SP5X_DECODER)            += sp5xdec.o
 OBJS-$(CONFIG_SRGC_DECODER)            += mscc.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 htmlsubtitles.o
-OBJS-$(CONFIG_SUBRIP_ENCODER)          += srtenc.o ass_split.o
-OBJS-$(CONFIG_SUBVIEWER1_DECODER)      += textdec.o ass.o
-OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o ass.o
+OBJS-$(CONFIG_SRT_DECODER)             += srtdec.o htmlsubtitles.o
+OBJS-$(CONFIG_SRT_ENCODER)             += srtenc.o
+OBJS-$(CONFIG_STL_DECODER)             += textdec.o
+OBJS-$(CONFIG_SUBRIP_DECODER)          += srtdec.o htmlsubtitles.o
+OBJS-$(CONFIG_SUBRIP_ENCODER)          += srtenc.o
+OBJS-$(CONFIG_SUBVIEWER1_DECODER)      += textdec.o
+OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o
 OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
 OBJS-$(CONFIG_LIBRSVG_DECODER)         += librsvgdec.o
@@ -650,8 +650,8 @@  OBJS-$(CONFIG_SVQ1_DECODER)            += svq1dec.o svq1.o h263data.o
 OBJS-$(CONFIG_SVQ1_ENCODER)            += svq1enc.o svq1.o  h263data.o  \
                                           h263.o ituh263enc.o
 OBJS-$(CONFIG_SVQ3_DECODER)            += svq3.o mpegutils.o h264data.o
-OBJS-$(CONFIG_TEXT_DECODER)            += textdec.o ass.o
-OBJS-$(CONFIG_TEXT_ENCODER)            += srtenc.o ass_split.o
+OBJS-$(CONFIG_TEXT_DECODER)            += textdec.o
+OBJS-$(CONFIG_TEXT_ENCODER)            += srtenc.o
 OBJS-$(CONFIG_TAK_DECODER)             += takdec.o tak.o takdsp.o
 OBJS-$(CONFIG_TARGA_DECODER)           += targa.o
 OBJS-$(CONFIG_TARGA_ENCODER)           += targaenc.o rle.o
@@ -671,7 +671,7 @@  OBJS-$(CONFIG_TSCC_DECODER)            += tscc.o msrledec.o
 OBJS-$(CONFIG_TSCC2_DECODER)           += tscc2.o
 OBJS-$(CONFIG_TTA_DECODER)             += tta.o ttadata.o ttadsp.o
 OBJS-$(CONFIG_TTA_ENCODER)             += ttaenc.o ttaencdsp.o ttadata.o
-OBJS-$(CONFIG_TTML_ENCODER)            += ttmlenc.o ass_split.o
+OBJS-$(CONFIG_TTML_ENCODER)            += ttmlenc.o
 OBJS-$(CONFIG_TWINVQ_DECODER)          += twinvqdec.o twinvq.o metasound_data.o
 OBJS-$(CONFIG_TXD_DECODER)             += txd.o
 OBJS-$(CONFIG_ULTI_DECODER)            += ulti.o
@@ -726,15 +726,15 @@  OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_VP9_RKMPP_DECODER)       += rkmppdec.o
 OBJS-$(CONFIG_VP9_VAAPI_ENCODER)       += vaapi_encode_vp9.o
 OBJS-$(CONFIG_VP9_QSV_ENCODER)         += qsvenc_vp9.o
-OBJS-$(CONFIG_VPLAYER_DECODER)         += textdec.o ass.o
+OBJS-$(CONFIG_VPLAYER_DECODER)         += textdec.o
 OBJS-$(CONFIG_VP9_V4L2M2M_DECODER)     += v4l2_m2m_dec.o
 OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
 OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o wavpackdata.o dsd.o
 OBJS-$(CONFIG_WAVPACK_ENCODER)         += wavpackdata.o wavpackenc.o
 OBJS-$(CONFIG_WCMV_DECODER)            += wcmv.o
 OBJS-$(CONFIG_WEBP_DECODER)            += webp.o
-OBJS-$(CONFIG_WEBVTT_DECODER)          += webvttdec.o ass.o
-OBJS-$(CONFIG_WEBVTT_ENCODER)          += webvttenc.o ass_split.o
+OBJS-$(CONFIG_WEBVTT_DECODER)          += webvttdec.o
+OBJS-$(CONFIG_WEBVTT_ENCODER)          += webvttenc.o
 OBJS-$(CONFIG_WMALOSSLESS_DECODER)     += wmalosslessdec.o wma_common.o
 OBJS-$(CONFIG_WMAPRO_DECODER)          += wmaprodec.o wma.o wma_common.o
 OBJS-$(CONFIG_WMAV1_DECODER)           += wmadec.o wma.o wma_common.o aactab.o
@@ -1019,7 +1019,7 @@  OBJS-$(CONFIG_PCM_ALAW_AT_ENCODER)        += audiotoolboxenc.o
 OBJS-$(CONFIG_PCM_MULAW_AT_ENCODER)       += audiotoolboxenc.o
 OBJS-$(CONFIG_LIBAOM_AV1_DECODER)         += libaomdec.o
 OBJS-$(CONFIG_LIBAOM_AV1_ENCODER)         += libaomenc.o
-OBJS-$(CONFIG_LIBARIBB24_DECODER)         += libaribb24.o ass.o
+OBJS-$(CONFIG_LIBARIBB24_DECODER)         += libaribb24.o
 OBJS-$(CONFIG_LIBCELT_DECODER)            += libcelt_dec.o
 OBJS-$(CONFIG_LIBCODEC2_DECODER)          += libcodec2.o
 OBJS-$(CONFIG_LIBCODEC2_ENCODER)          += libcodec2.o
@@ -1070,7 +1070,7 @@  OBJS-$(CONFIG_LIBX265_ENCODER)            += libx265.o
 OBJS-$(CONFIG_LIBXAVS_ENCODER)            += libxavs.o
 OBJS-$(CONFIG_LIBXAVS2_ENCODER)           += libxavs2.o
 OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvid.o
-OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER)   += libzvbi-teletextdec.o ass.o
+OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER)   += libzvbi-teletextdec.o
 
 # parsers
 OBJS-$(CONFIG_AAC_LATM_PARSER)         += latm_parser.o
diff --git a/libavcodec/ass_internal.h b/libavcodec/ass_internal.h
new file mode 100644
index 0000000000..44cc9f5ff1
--- /dev/null
+++ b/libavcodec/ass_internal.h
@@ -0,0 +1,68 @@ 
+/*
+ * Copyright (c) 2021 The FFmpeg Project
+ *
+ * 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_ASS_INTERNAL_H
+#define AVCODEC_ASS_INTERNAL_H
+
+#include "avcodec.h"
+#include "libavutil/ass.h"
+
+typedef struct FFASSDecoderContext {
+    int readorder;
+} FFASSDecoderContext;
+
+static inline int ff_ass_subtitle_header_full(AVCodecContext *avctx,
+                                int play_res_x, int play_res_y,
+                                const char *font, int font_size,
+                                int primary_color, int secondary_color,
+                                int outline_color, int back_color,
+                                int bold, int italic, int underline,
+                                int border_style, int alignment)
+{
+    avctx->subtitle_header = (uint8_t *)av_ass_get_subtitle_header_full(
+                                play_res_x, play_res_y, font, font_size,
+                                primary_color, secondary_color, outline_color, 
+                                back_color, bold,italic,underline,border_style,alignment,
+                                !(avctx->flags & AV_CODEC_FLAG_BITEXACT));
+
+    if (!avctx->subtitle_header)
+        return AVERROR(ENOMEM);
+    avctx->subtitle_header_size = strlen((char *)avctx->subtitle_header);
+    return 0;
+}
+
+static inline int ff_ass_subtitle_header_default(AVCodecContext *avctx)
+{
+    avctx->subtitle_header = (uint8_t *)av_ass_get_subtitle_header_default(!(avctx->flags & AV_CODEC_FLAG_BITEXACT));
+
+    if (!avctx->subtitle_header)
+        return AVERROR(ENOMEM);
+    avctx->subtitle_header_size = strlen((char *)avctx->subtitle_header);
+    return 0;
+}
+
+static inline void ff_ass_decoder_flush(AVCodecContext *avctx)
+{
+    FFASSDecoderContext *s = avctx->priv_data;
+    if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
+        s->readorder = 0;
+}
+
+#endif /* AVCODEC_ASS_INTERNAL_H */
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 319279490c..4e319740cb 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -22,7 +22,7 @@ 
 #include <string.h>
 
 #include "avcodec.h"
-#include "ass.h"
+#include "libavutil/ass.h"
 #include "internal.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index a6d107ded2..9b79807bae 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -22,7 +22,7 @@ 
 #include <string.h>
 
 #include "avcodec.h"
-#include "ass.h"
+#include "libavutil/ass.h"
 #include "internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/internal.h"
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 27c61527f6..d75e9cd01e 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -20,7 +20,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/opt.h"
 
@@ -272,15 +272,12 @@  static av_cold int init_decoder(AVCodecContext *avctx)
     ctx->bg_color = CCCOL_BLACK;
     ctx->rollup = 2;
     ctx->cursor_row = 10;
-    ret = ff_ass_subtitle_header(avctx, "Monospace",
+    ret = ff_ass_subtitle_header_full(avctx, ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY, "Monospace",
                                  ASS_DEFAULT_FONT_SIZE,
-                                 ASS_DEFAULT_COLOR,
-                                 ASS_DEFAULT_BACK_COLOR,
-                                 ASS_DEFAULT_BOLD,
-                                 ASS_DEFAULT_ITALIC,
-                                 ASS_DEFAULT_UNDERLINE,
-                                 3,
-                                 ASS_DEFAULT_ALIGNMENT);
+                                 ASS_DEFAULT_COLOR, ASS_DEFAULT_COLOR,
+                                 ASS_DEFAULT_BACK_COLOR, ASS_DEFAULT_BACK_COLOR,
+                                 ASS_DEFAULT_BOLD, ASS_DEFAULT_ITALIC, ASS_DEFAULT_UNDERLINE,
+                                 3, ASS_DEFAULT_ALIGNMENT);
     if (ret < 0) {
         return ret;
     }
diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index 698895a86b..d56d45ebbe 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -25,7 +25,7 @@ 
  */
 
 #include <time.h>
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "jacosub.h"
 #include "libavutil/avstring.h"
diff --git a/libavcodec/microdvddec.c b/libavcodec/microdvddec.c
index c45fe043bf..2f5c56ffde 100644
--- a/libavcodec/microdvddec.c
+++ b/libavcodec/microdvddec.c
@@ -30,7 +30,7 @@ 
 #include "libavutil/parseutils.h"
 #include "libavutil/bprint.h"
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 
 static int indexof(const char *s, int c)
@@ -363,8 +363,9 @@  static int microdvd_init(AVCodecContext *avctx)
             }
         }
     }
-    return ff_ass_subtitle_header(avctx, font_buf.str, font_size, color,
-                                  ASS_DEFAULT_BACK_COLOR, bold, italic,
+    return ff_ass_subtitle_header_full(avctx, ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY,
+                                  font_buf.str, font_size, color, color,
+                                  ASS_DEFAULT_BACK_COLOR, ASS_DEFAULT_BACK_COLOR, bold, italic,
                                   underline, ASS_DEFAULT_BORDERSTYLE,
                                   alignment);
 }
diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 4e14ae5900..c518d6af54 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -20,9 +20,8 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "libavutil/opt.h"
-#include "libavutil/avstring.h"
 #include "libavutil/common.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index 2ae5a9bf0b..865eddc2c5 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -26,8 +26,8 @@ 
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
 #include "libavutil/common.h"
-#include "ass_split.h"
-#include "ass.h"
+#include "libavutil/ass_split.h"
+#include "libavutil/ass.h"
 #include "bytestream.h"
 #include "internal.h"
 
diff --git a/libavcodec/mpl2dec.c b/libavcodec/mpl2dec.c
index 61e47050ec..31a6e2b89b 100644
--- a/libavcodec/mpl2dec.c
+++ b/libavcodec/mpl2dec.c
@@ -26,7 +26,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/bprint.h"
 
diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c
index 11b586d493..52c5555eb3 100644
--- a/libavcodec/realtextdec.c
+++ b/libavcodec/realtextdec.c
@@ -25,7 +25,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c
index 32d07447b4..e58b1ea318 100644
--- a/libavcodec/samidec.c
+++ b/libavcodec/samidec.c
@@ -24,7 +24,7 @@ 
  * @see http://msdn.microsoft.com/en-us/library/ms971327.aspx
  */
 
-#include "ass.h"
+#include "ass_internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "htmlsubtitles.h"
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 4f16226b83..19bbd670b7 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -24,7 +24,7 @@ 
 #include "libavutil/intreadwrite.h"
 #include "libavutil/parseutils.h"
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "htmlsubtitles.h"
 #include "internal.h"
 
diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c
index 2e3ac55770..cb8f0724df 100644
--- a/libavcodec/srtenc.c
+++ b/libavcodec/srtenc.c
@@ -23,8 +23,8 @@ 
 #include "avcodec.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
-#include "ass_split.h"
-#include "ass.h"
+#include "libavutil/ass_split.h"
+#include "libavutil/ass.h"
 #include "internal.h"
 
 
diff --git a/libavcodec/subviewerdec.c b/libavcodec/subviewerdec.c
index 5c650d0cde..bb2c2d76fd 100644
--- a/libavcodec/subviewerdec.c
+++ b/libavcodec/subviewerdec.c
@@ -25,7 +25,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/bprint.h"
 
diff --git a/libavcodec/textdec.c b/libavcodec/textdec.c
index 308553660a..0781f195e0 100644
--- a/libavcodec/textdec.c
+++ b/libavcodec/textdec.c
@@ -24,7 +24,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/bprint.h"
 #include "libavutil/opt.h"
diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index ad2eddfdd5..34c7e8e9f8 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -32,8 +32,7 @@ 
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/internal.h"
-#include "ass_split.h"
-#include "ass.h"
+#include "libavutil/ass_split.h"
 #include "ttmlenc.h"
 
 typedef struct {
diff --git a/libavcodec/webvttdec.c b/libavcodec/webvttdec.c
index 0093f328fa..5de4167c51 100644
--- a/libavcodec/webvttdec.c
+++ b/libavcodec/webvttdec.c
@@ -26,7 +26,7 @@ 
  */
 
 #include "avcodec.h"
-#include "ass.h"
+#include "ass_internal.h"
 #include "internal.h"
 #include "libavutil/bprint.h"
 
diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index 89b49e42bf..325019956f 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -24,8 +24,8 @@ 
 #include "avcodec.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
-#include "ass_split.h"
-#include "ass.h"
+#include "libavutil/ass_split.h"
+#include "libavutil/ass.h"
 #include "internal.h"
 
 #define WEBVTT_STACK_SIZE 64
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 04e1101bf3..65e65746f1 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -4,6 +4,8 @@  DESC = FFmpeg utility library
 HEADERS = adler32.h                                                     \
           aes.h                                                         \
           aes_ctr.h                                                     \
+          ass.h                                                         \
+          ass_split.h                                                   \
           attributes.h                                                  \
           audio_fifo.h                                                  \
           avassert.h                                                    \
@@ -101,6 +103,8 @@  BUILT_HEADERS = avconfig.h                                              \
 OBJS = adler32.o                                                        \
        aes.o                                                            \
        aes_ctr.o                                                        \
+       ass.o                                                            \
+       ass_split.o                                                      \
        audio_fifo.o                                                     \
        avstring.o                                                       \
        avsscanf.o                                                       \
diff --git a/libavcodec/ass.c b/libavutil/ass.c
similarity index 77%
rename from libavcodec/ass.c
rename to libavutil/ass.c
index 907e2d7b88..2b2eaaf4d8 100644
--- a/libavcodec/ass.c
+++ b/libavutil/ass.c
@@ -19,21 +19,22 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "avcodec.h"
 #include "ass.h"
+
+#include "subfmt.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/common.h"
 
-int ff_ass_subtitle_header_full(AVCodecContext *avctx,
-                                int play_res_x, int play_res_y,
-                                const char *font, int font_size,
-                                int primary_color, int secondary_color,
-                                int outline_color, int back_color,
-                                int bold, int italic, int underline,
-                                int border_style, int alignment)
+char* av_ass_get_subtitle_header_full(int play_res_x, int play_res_y,
+                                    const char *font, int font_size,
+                                    int primary_color, int secondary_color,
+                                    int outline_color, int back_color,
+                                    int bold, int italic, int underline,
+                                    int border_style, int alignment,
+                                    int print_av_version)
 {
-    avctx->subtitle_header = av_asprintf(
+    char* header = av_asprintf(
              "[Script Info]\r\n"
              "; Script generated by FFmpeg/Lavc%s\r\n"
              "ScriptType: v4.00+\r\n"
@@ -68,34 +69,31 @@  int ff_ass_subtitle_header_full(AVCodecContext *avctx,
              "\r\n"
              "[Events]\r\n"
              "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n",
-             !(avctx->flags & AV_CODEC_FLAG_BITEXACT) ? AV_STRINGIFY(LIBAVCODEC_VERSION) : "",
+             print_av_version ? AV_STRINGIFY(LIBAVCODEC_VERSION) : "",
              play_res_x, play_res_y, font, font_size,
              primary_color, secondary_color, outline_color, back_color,
              -bold, -italic, -underline, border_style, alignment);
 
-    if (!avctx->subtitle_header)
-        return AVERROR(ENOMEM);
-    avctx->subtitle_header_size = strlen(avctx->subtitle_header);
-    return 0;
+    return header;
 }
 
-int ff_ass_subtitle_header(AVCodecContext *avctx,
-                           const char *font, int font_size,
+char* av_ass_get_subtitle_header(const char *font, int font_size,
                            int color, int back_color,
                            int bold, int italic, int underline,
-                           int border_style, int alignment)
+                           int border_style, int alignment,
+                           int print_av_version)
 {
-    return ff_ass_subtitle_header_full(avctx,
-                               ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY,
-                               font, font_size, color, color,
-                               back_color, back_color,
-                               bold, italic, underline,
-                               border_style, alignment);
+    return av_ass_get_subtitle_header_full(ASS_DEFAULT_PLAYRESX, ASS_DEFAULT_PLAYRESY,
+                                       font, font_size, color, color,
+                                       back_color, back_color,
+                                       bold, italic, underline,
+                                       border_style, alignment,
+                                       print_av_version);
 }
 
-int ff_ass_subtitle_header_default(AVCodecContext *avctx)
+char* av_ass_get_subtitle_header_default(int print_av_version)
 {
-    return ff_ass_subtitle_header(avctx, ASS_DEFAULT_FONT,
+    return av_ass_get_subtitle_header(ASS_DEFAULT_FONT,
                                ASS_DEFAULT_FONT_SIZE,
                                ASS_DEFAULT_COLOR,
                                ASS_DEFAULT_BACK_COLOR,
@@ -103,7 +101,8 @@  int ff_ass_subtitle_header_default(AVCodecContext *avctx)
                                ASS_DEFAULT_ITALIC,
                                ASS_DEFAULT_UNDERLINE,
                                ASS_DEFAULT_BORDERSTYLE,
-                               ASS_DEFAULT_ALIGNMENT);
+                               ASS_DEFAULT_ALIGNMENT,
+                               print_av_version);
 }
 
 char *ff_ass_get_dialog(int readorder, int layer, const char *style,
@@ -137,12 +136,12 @@  int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
     return 0;
 }
 
-void ff_ass_decoder_flush(AVCodecContext *avctx)
-{
-    FFASSDecoderContext *s = avctx->priv_data;
-    if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
-        s->readorder = 0;
-}
+////void ff_ass_decoder_flush(AVCodecContext *avctx)
+////{
+////    FFASSDecoderContext *s = avctx->priv_data;
+////    if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP))
+////        s->readorder = 0;
+////}
 
 void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size,
                              const char *linebreaks, int keep_ass_markup)
diff --git a/libavcodec/ass.h b/libavutil/ass.h
similarity index 71%
rename from libavcodec/ass.h
rename to libavutil/ass.h
index 2c260e4e78..a54164cb56 100644
--- a/libavcodec/ass.h
+++ b/libavutil/ass.h
@@ -19,10 +19,10 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_ASS_H
-#define AVCODEC_ASS_H
+#ifndef AVUTIL_ASS_H
+#define AVUTIL_ASS_H
 
-#include "avcodec.h"
+#include "subfmt.h"
 #include "libavutil/bprint.h"
 
 #define ASS_DEFAULT_PLAYRESX 384
@@ -43,15 +43,10 @@ 
 #define ASS_DEFAULT_BORDERSTYLE 1
 /** @} */
 
-typedef struct FFASSDecoderContext {
-    int readorder;
-} FFASSDecoderContext;
-
 /**
  * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
  * Can specify all fields explicitly
  *
- * @param avctx pointer to the AVCodecContext
  * @param play_res_x subtitle frame width
  * @param play_res_y subtitle frame height
  * @param font name of the default font face to use
@@ -66,19 +61,20 @@  typedef struct FFASSDecoderContext {
  * @param border_style 1 for outline, 3 for opaque box
  * @param alignment position of the text (left, center, top...), defined after
  *                  the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top)
- * @return >= 0 on success otherwise an error code <0
+ * @param print_av_version include library version in header
+ * @return a string containing the subtitle header that needs
+ *         to be released via av_free()
  */
-int ff_ass_subtitle_header_full(AVCodecContext *avctx,
-                                int play_res_x, int play_res_y,
-                                const char *font, int font_size,
-                                int primary_color, int secondary_color,
-                                int outline_color, int back_color,
-                                int bold, int italic, int underline,
-                                int border_style, int alignment);
+char* av_ass_get_subtitle_header_full(int play_res_x, int play_res_y,
+                                  const char *font, int font_size,
+                                  int primary_color, int secondary_color,
+                                  int outline_color, int back_color,
+                                  int bold, int italic, int underline,
+                                  int border_style, int alignment,
+                                  int print_av_version);
 /**
  * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
  *
- * @param avctx pointer to the AVCodecContext
  * @param font name of the default font face to use
  * @param font_size default font size to use
  * @param color default text color to use (ABGR)
@@ -86,24 +82,28 @@  int ff_ass_subtitle_header_full(AVCodecContext *avctx,
  * @param bold 1 for bold text, 0 for normal text
  * @param italic 1 for italic text, 0 for normal text
  * @param underline 1 for underline text, 0 for normal text
+ * @param border_style 1 for outline, 3 for opaque box
  * @param alignment position of the text (left, center, top...), defined after
  *                  the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top)
- * @return >= 0 on success otherwise an error code <0
+ * @param print_av_version include library version in header
+ * @return a string containing the subtitle header that needs
+ *         to be released via av_free()
  */
-int ff_ass_subtitle_header(AVCodecContext *avctx,
-                           const char *font, int font_size,
-                           int color, int back_color,
-                           int bold, int italic, int underline,
-                           int border_style, int alignment);
+char* av_ass_get_subtitle_header(const char *font, int font_size,
+                                int color, int back_color,
+                                int bold, int italic, int underline,
+                                int border_style, int alignment,
+                                int print_av_version);
 
 /**
  * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS
  * with default style.
  *
- * @param avctx pointer to the AVCodecContext
- * @return >= 0 on success otherwise an error code <0
+ * @param print_av_version include library version in header
+ * @return a string containing the subtitle header that needs
+ *         to be released via av_free()
  */
-int ff_ass_subtitle_header_default(AVCodecContext *avctx);
+char* av_ass_get_subtitle_header_default(int print_av_version);
 
 /**
  * Craft an ASS dialog string.
@@ -118,11 +118,11 @@  int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
                     int readorder, int layer, const char *style,
                     const char *speaker);
 
-/**
- * Helper to flush a text subtitles decoder making use of the
- * FFASSDecoderContext.
- */
-void ff_ass_decoder_flush(AVCodecContext *avctx);
+/////**
+//// * Helper to flush a text subtitles decoder making use of the
+//// * FFASSDecoderContext.
+//// */
+////void ff_ass_decoder_flush(AVCodecContext *avctx);
 
 /**
  * Escape a text subtitle using ASS syntax into an AVBPrint buffer.
@@ -136,4 +136,4 @@  void ff_ass_decoder_flush(AVCodecContext *avctx);
  */
 void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size,
                              const char *linebreaks, int keep_ass_markup);
-#endif /* AVCODEC_ASS_H */
+#endif /* AVUTIL_ASS_H */
diff --git a/libavcodec/ass_split.c b/libavutil/ass_split.c
similarity index 97%
rename from libavcodec/ass_split.c
rename to libavutil/ass_split.c
index 05c5453e53..e58585d3da 100644
--- a/libavcodec/ass_split.c
+++ b/libavutil/ass_split.c
@@ -497,8 +497,8 @@  int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
             while (*buf == '\\') {
                 char style[2], c[2], sep[2], c_num[2] = "0", tmp[128] = {0};
                 unsigned int color = 0xFFFFFFFF;
-                int len, size = -1, an = -1, alpha = -1;
-                int x1, y1, x2, y2, t1 = -1, t2 = -1;
+                int len, size = -1, an = -1, alpha = -1, scale = 0;
+                int x1, y1, x2, y2, t1 = -1, t2 = -1, accel = 1;
                 if (sscanf(buf, "\\%1[bisu]%1[01\\}]%n", style, c, &len) > 1) {
                     int close = c[0] == '0' ? 1 : c[0] == '1' ? 0 : -1;
                     len += close != -1;
@@ -546,6 +546,14 @@  int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
                 } else if (sscanf(buf, "\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) {
                     if (callbacks->origin)
                         callbacks->origin(priv, x1, y1);
+                } else if (sscanf(buf, "\\t(%d,%d,%1[\\}]%n", &t1, &t2, sep, &len) > 2 ||
+                           sscanf(buf, "\\t(%d,%d,%d,%1[\\}]%n", &t1, &t2, &accel, sep, &len) > 3) {
+                    if (callbacks->animate)
+                        callbacks->animate(priv, t1, t2, accel, tmp);
+                } else if (sscanf(buf, "\\p%1[\\}]%n", sep, &len) > 0 ||
+                           sscanf(buf, "\\p%u%1[\\}]%n", &scale, sep, &len) > 1) {
+                    if (callbacks->drawing_mode)
+                        callbacks->drawing_mode(priv, scale);
                 } else {
                     len = strcspn(buf+1, "\\}") + 2;  /* skip unknown code */
                 }
diff --git a/libavcodec/ass_split.h b/libavutil/ass_split.h
similarity index 96%
rename from libavcodec/ass_split.h
rename to libavutil/ass_split.h
index a45fb9b8a1..a918f5c773 100644
--- a/libavcodec/ass_split.h
+++ b/libavutil/ass_split.h
@@ -19,8 +19,8 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_ASS_SPLIT_H
-#define AVCODEC_ASS_SPLIT_H
+#ifndef AVUTIL_ASS_SPLIT_H
+#define AVUTIL_ASS_SPLIT_H
 
 /**
  * fields extracted from the [Script Info] section
@@ -156,7 +156,9 @@  typedef struct {
      * @{
      */
     void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2);
+    void (*animate)(void *priv, int t1, int t2, int accel, char *style);
     void (*origin)(void *priv, int x, int y);
+    void (*drawing_mode)(void *priv, int scale);
     /** @} */
 
     /**
@@ -188,4 +190,4 @@  int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv,
  */
 ASSStyle *ff_ass_style_get(ASSSplitContext *ctx, const char *style);
 
-#endif /* AVCODEC_ASS_SPLIT_H */
+#endif /* AVUTIL_ASS_SPLIT_H */