--- libmpdemux/demux_mkv.cpp 27 Aug 2003 13:08:40 -0000 1.28 +++ libmpdemux/demux_mkv.cpp 9 Sep 2003 09:04:39 -0000 @@ -185,6 +185,7 @@ uint64_t clear_subs_at; subtitle subs; + int subtitle_ssa; EbmlStream *es; EbmlElement *saved_l1, *saved_l2; @@ -391,6 +392,45 @@ s2 = mkv_d->subs.text[0]; mkv_d->subs.lines = 1; state = 0; + + if (mkv_d->subtitle_ssa == 1) { + /* Matroska's SSA format does not have timecodes embedded into the SAA line. + Timescodes are encoded into the blocks timecode and duration. */ + + /* Find last comma. */ + s1 = buffer; + s1 = s1 + len - 1; + while (*s1 != ',') { + s1--; + } + s1++; + + /* Load text. */ + while ((unsigned int)(s1 - buffer) != data.Size()) { + if (*s1 == '{') { + /* Newline */ + if (*(s1 + 1) == '\\' && (*(s1 + 2) == 'N' || *(s1 + 2) == 'n')) { + mkv_d->subs.lines++; + *s2 = 0; + s2 = mkv_d->subs.text[mkv_d->subs.lines - 1]; + } + state = 1; + } else if (*s1 == '}' && state == 1) { + state = 2; + } + + if (state == 0) { + *s2 = *s1; + s2++; + } + s1++; + + if (state == 2) { + state = 0; + } + } + *s2 = 0; + } else { while ((unsigned int)(s1 - buffer) != data.Size()) { if ((*s1 == '\n') || (*s1 == '\r')) { if (state == 0) { // normal char --> newline @@ -416,6 +456,7 @@ } *s2 = 0; + } #ifdef USE_ICONV subcp_recode1(&mkv_d->subs); @@ -1761,7 +1802,8 @@ track = find_track_by_language(mkv_d, dvdsub_lang, NULL); if (track) { if (strcmp(track->codec_id, MKV_S_TEXTASCII) && - strcmp(track->codec_id, MKV_S_TEXTUTF8)) + strcmp(track->codec_id, MKV_S_TEXTUTF8) && + strcmp(track->codec_id, MKV_S_TEXTSSA)) mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Subtitle type '%s' is not " "supported. Track will not be displayed.\n", track->codec_id); else { @@ -1774,6 +1816,10 @@ if (!strcmp(track->codec_id, MKV_S_TEXTUTF8)) sub_utf8 = 1; // Force UTF-8 conversion. + if (!strcmp(track->codec_id, MKV_S_TEXTSSA)) + mkv_d->subtitle_ssa = 1; + else + mkv_d->subtitle_ssa = 0; } else mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] File does not contain a " "subtitle track with the id %u.\n", demuxer->sub->id);