diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-06-16 19:13:42 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-06-17 00:38:08 +0200 |
commit | 5422a4a7c5c6c71367937422e753a0d65a60ae21 (patch) | |
tree | 3cc2a2b42cd90a9cc7da8becd25e1d58dbb2a814 /libavformat/sccdec.c | |
parent | 9887bcc6c63c1f525a3e7e7b004189e79e4f1eba (diff) | |
download | ffmpeg-5422a4a7c5c6c71367937422e753a0d65a60ae21.tar.gz |
avformat/sccdec: simplify demuxer a little
Diffstat (limited to 'libavformat/sccdec.c')
-rw-r--r-- | libavformat/sccdec.c | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/libavformat/sccdec.c b/libavformat/sccdec.c index fa2a5c223a..4d94743c81 100644 --- a/libavformat/sccdec.c +++ b/libavformat/sccdec.c @@ -63,11 +63,10 @@ static int scc_read_header(AVFormatContext *s) { SCCContext *scc = s->priv_data; AVStream *st = avformat_new_stream(s, NULL); - char line[4096], line2[4096]; - int64_t current_pos, next_pos; - int64_t ts_start, ts_end; - int count = 0, ret = 0; - ptrdiff_t len2, len; + char line2[4096], line[4096]; + int64_t pos, ts, next_ts = AV_NOPTS_VALUE; + int ret = 0; + ptrdiff_t len; uint8_t out[4096]; FFTextReader tr; @@ -79,41 +78,49 @@ static int scc_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_EIA_608; - while (!ff_text_eof(&tr)) { + while (!ff_text_eof(&tr) || next_ts == AV_NOPTS_VALUE || line2[0]) { char *saveptr = NULL, *lline; - int hh1, mm1, ss1, fs1, i; - int hh2, mm2, ss2, fs2; + int hh, mm, ss, fs, i; AVPacket *sub; - if (count == 0) { - current_pos = ff_text_pos(&tr); + if (next_ts == AV_NOPTS_VALUE) { while (!ff_text_eof(&tr)) { len = ff_subtitles_read_line(&tr, line, sizeof(line)); - if (len > 13) + if (len <= 13) + continue; + if (!strncmp(line, "Scenarist_SCC V1.0", 18)) + continue; + if (av_sscanf(line, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4) break; } - } - if (!strncmp(line, "Scenarist_SCC V1.0", 18)) - continue; - if (av_sscanf(line, "%d:%d:%d%*[:;]%d", &hh1, &mm1, &ss1, &fs1) != 4) - continue; + ts = (hh * 3600LL + mm * 60LL + ss) * 1000LL + fs * 33; - ts_start = (hh1 * 3600LL + mm1 * 60LL + ss1) * 1000LL + fs1 * 33; + while (!ff_text_eof(&tr)) { + len = ff_subtitles_read_line(&tr, line2, sizeof(line2)); + if (len <= 13) + continue; - next_pos = ff_text_pos(&tr); - while (!ff_text_eof(&tr)) { - len2 = ff_subtitles_read_line(&tr, line2, sizeof(line2)); - if (len2 > 13) - break; + if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4) + break; + } + } else { + memmove(line, line2, sizeof(line)); + line2[0] = 0; + + while (!ff_text_eof(&tr)) { + len = ff_subtitles_read_line(&tr, line2, sizeof(line2)); + if (len <= 13) + continue; + + if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh, &mm, &ss, &fs) == 4) + break; + } } - if (av_sscanf(line2, "%d:%d:%d%*[:;]%d", &hh2, &mm2, &ss2, &fs2) != 4) - continue; - ts_end = (hh2 * 3600LL + mm2 * 60LL + ss2) * 1000LL + fs2 * 33; - count++; + next_ts = (hh * 3600LL + mm * 60LL + ss) * 1000LL + fs * 33; -try_again: + pos = ff_text_pos(&tr); lline = (char *)&line; lline += 12; @@ -134,20 +141,18 @@ try_again: if (i > 12 && o1 == 0x94 && o2 == 0x20 && saveptr && (av_strncasecmp(saveptr, "942f", 4) || !av_strncasecmp(saveptr, "942c", 4))) { - int64_t duration; out[i] = 0; - duration = i * 11; sub = ff_subtitles_queue_insert(&scc->q, out, i, 0); if (!sub) goto fail; - sub->pos = current_pos; - current_pos += i; - sub->pts = ts_start; - sub->duration = duration; - ts_start += duration; + sub->pos = pos; + pos += i; + sub->pts = ts; + sub->duration = i * 11; + ts += sub->duration; i = 0; } @@ -162,18 +167,10 @@ try_again: if (!sub) goto fail; - sub->pos = current_pos; - sub->pts = ts_start; - sub->duration = ts_end - ts_start; - memmove(line, line2, sizeof(line)); - current_pos = next_pos; - line2[0] = 0; - } - - if (line[0]) { - ts_start = ts_end; - ts_end += 1200; - goto try_again; + sub->pos = pos; + sub->pts = ts; + sub->duration = next_ts - ts; + ts = next_ts; } ff_subtitles_queue_finalize(s, &scc->q); |