static int jacosub_probe(AVProbeData *p) { const char *ptr = p->buf; const char *ptr_end = p->buf + p->buf_size; if (AV_RB24(ptr) == 0xEFBBBF) ptr += 3; /* skip UTF-8 BOM */ while (ptr < ptr_end) { while (jss_whitespace(*ptr)) ptr++; if (*ptr != '#' && *ptr != '\n') { if (timed_line(ptr)) return AVPROBE_SCORE_MAX/2 + 1; return 0; } ptr += strcspn(ptr, "\n") + 1; } return 0; }
static int jacosub_probe(AVProbeData *p) { const char *ptr = p->buf; const char *ptr_end = p->buf + p->buf_size; if (AV_RB24(ptr) == 0xEFBBBF) ptr += 3; /* skip UTF-8 BOM */ while (ptr < ptr_end) { while (jss_whitespace(*ptr)) ptr++; if (*ptr != '#' && *ptr != '\n') { if (timed_line(ptr)) return AVPROBE_SCORE_EXTENSION + 1; return 0; } ptr += ff_subtitles_next_line(ptr); } return 0; }
static void jacosub_to_ass(AVCodecContext *avctx, AVBPrint *dst, const char *src) { int i, valign = 0, halign = 0; char c = av_toupper(*src); char directives[128] = {0}; /* extract the optional directives */ if ((c >= 'A' && c <= 'Z') || c == '[') { char *p = directives; char *pend = directives + sizeof(directives) - 1; do *p++ = av_toupper(*src++); while (*src && !jss_whitespace(*src) && p < pend); *p = 0; src = jss_skip_whitespace(src); } /* handle directives (TODO: handle more of them, and more reliably) */ if (strstr(directives, "VB")) valign = ALIGN_VB; else if (strstr(directives, "VM")) valign = ALIGN_VM; else if (strstr(directives, "VT")) valign = ALIGN_VT; if (strstr(directives, "JC")) halign = ALIGN_JC; else if (strstr(directives, "JL")) halign = ALIGN_JL; else if (strstr(directives, "JR")) halign = ALIGN_JR; if (valign || halign) { if (!valign) valign = ALIGN_VB; if (!halign) halign = ALIGN_JC; switch (valign | halign) { case ALIGN_VB | ALIGN_JL: av_bprintf(dst, "{\\an1}"); break; // bottom left case ALIGN_VB | ALIGN_JC: av_bprintf(dst, "{\\an2}"); break; // bottom center case ALIGN_VB | ALIGN_JR: av_bprintf(dst, "{\\an3}"); break; // bottom right case ALIGN_VM | ALIGN_JL: av_bprintf(dst, "{\\an4}"); break; // middle left case ALIGN_VM | ALIGN_JC: av_bprintf(dst, "{\\an5}"); break; // middle center case ALIGN_VM | ALIGN_JR: av_bprintf(dst, "{\\an6}"); break; // middle right case ALIGN_VT | ALIGN_JL: av_bprintf(dst, "{\\an7}"); break; // top left case ALIGN_VT | ALIGN_JC: av_bprintf(dst, "{\\an8}"); break; // top center case ALIGN_VT | ALIGN_JR: av_bprintf(dst, "{\\an9}"); break; // top right } } /* process timed line */ while (*src && *src != '\n') { /* text continue on the next line */ if (src[0] == '\\' && src[1] == '\n') { src += 2; while (jss_whitespace(*src)) src++; continue; } /* special character codes */ for (i = 0; i < FF_ARRAY_ELEMS(ass_codes_map); i++) { const char *from = ass_codes_map[i].from; const char *arg = ass_codes_map[i].arg; size_t codemap_len = strlen(from); if (!strncmp(src, from, codemap_len)) { src += codemap_len; src += ass_codes_map[i].func(dst, src, arg); break; } } /* simple char copy */ if (i == FF_ARRAY_ELEMS(ass_codes_map)) av_bprintf(dst, "%c", *src++); } av_bprintf(dst, "\r\n"); }