X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fass_split.c;h=beaba7eb7c565399c8b875fb6fe53c4668389226;hb=db44b599805fdd96940cf2e5a336f872648bbda1;hp=f84a686b032df0c34ea67ec89baaf5eb2e8fdd4b;hpb=3f462fcf76bb99bc2cb14575eaa7a020595ca277;p=ffmpeg diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index f84a686b032..beaba7eb7c5 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -409,6 +409,55 @@ ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, return dialog; } +void ff_ass_free_dialog(ASSDialog **dialogp) +{ + ASSDialog *dialog = *dialogp; + if (!dialog) + return; + av_freep(&dialog->style); + av_freep(&dialog->name); + av_freep(&dialog->effect); + av_freep(&dialog->text); + av_freep(dialogp); +} + +ASSDialog *ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf) +{ + int i; + static const ASSFields fields[] = { + {"ReadOrder", ASS_INT, offsetof(ASSDialog, readorder)}, + {"Layer", ASS_INT, offsetof(ASSDialog, layer) }, + {"Style", ASS_STR, offsetof(ASSDialog, style) }, + {"Name", ASS_STR, offsetof(ASSDialog, name) }, + {"MarginL", ASS_INT, offsetof(ASSDialog, margin_l) }, + {"MarginR", ASS_INT, offsetof(ASSDialog, margin_r) }, + {"MarginV", ASS_INT, offsetof(ASSDialog, margin_v) }, + {"Effect", ASS_STR, offsetof(ASSDialog, effect) }, + {"Text", ASS_STR, offsetof(ASSDialog, text) }, + }; + + ASSDialog *dialog = av_mallocz(sizeof(*dialog)); + if (!dialog) + return NULL; + + for (i = 0; i < FF_ARRAY_ELEMS(fields); i++) { + size_t len; + const int last = i == FF_ARRAY_ELEMS(fields) - 1; + const ASSFieldType type = fields[i].type; + uint8_t *ptr = (uint8_t *)dialog + fields[i].offset; + buf = skip_space(buf); + len = last ? strlen(buf) : strcspn(buf, ","); + if (len >= INT_MAX) { + ff_ass_free_dialog(&dialog); + return NULL; + } + convert_func[type](ptr, buf, len); + buf += len; + if (*buf) buf++; + } + return dialog; +} + void ff_ass_split_free(ASSSplitContext *ctx) { if (ctx) {