Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/libavformat/stldec.c b/libavformat/stldec.c
- index 24ae5bd..d841e1e 100644
- --- a/libavformat/stldec.c
- +++ b/libavformat/stldec.c
- @@ -1,7 +1,6 @@
- #include "avformat.h"
- #include "internal.h"
- #include "subtitles.h"
- -#include "libavutil/bprint.h"
- #include "libavutil/intreadwrite.h"
- typedef struct {
- @@ -10,97 +9,35 @@ typedef struct {
- static int stl_probe(AVProbeData *p)
- {
- - char c;
- +
- const unsigned char *ptr = p->buf;
- - if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,", &c) == 1)
- + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,") == 1)
- return AVPROBE_SCORE_MAX;
- return 0;
- }
- -static int64_t get_pts(const char **buf, int *duration,
- - int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2)
- +static int64_t get_pts(char **buf, int *duration)
- {
- int hh1, mm1, ss1, ms1;
- int hh2, mm2, ss2, ms2;
- - if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , ",
- + int len;
- + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
- &hh1, &mm1, &ss1, &ms1,
- - &hh2, &mm2, &ss2, &ms2) >= 6) {
- + &hh2, &mm2, &ss2, &ms2, &len) >= 6) {
- +
- int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
- int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
- *duration = end - start;
- - *buf += ff_subtitles_next_line(*buf);
- + *buf+=len;
- return start;
- - }
- - *buf += ff_subtitles_next_line(*buf);
- -
- - return AV_NOPTS_VALUE;
- + }
- + return AV_NOPTS_VALUE;
- }
- static int stl_read_header(AVFormatContext *s)
- {
- STLContext *stl = s->priv_data;
- - AVBPrint buf;
- AVStream *st = avformat_new_stream(s, NULL);
- - int res = 0;
- - FFTextReader tr;
- - ff_text_init_avio(&tr, s->pb);
- -
- - if (!st)
- - return AVERROR(ENOMEM);
- - avpriv_set_pts_info(st, 64, 1, 100);
- - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
- - st->codec->codec_id = AV_CODEC_ID_TEXT;
- -
- - av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
- -
- - while (!ff_text_eof(&tr)) {
- - ff_subtitles_read_text_chunk(&tr, &buf);
- -
- - if (buf.len) {
- - int64_t pos = ff_text_pos(&tr);
- - int64_t pts;
- - int duration;
- - const char *ptr = buf.str;
- - int32_t x1 = -1, y1 = -1, x2 = -1, y2 = -1;
- - AVPacket *sub;
- - pts = get_pts(&ptr, &duration, &x1, &y1, &x2, &y2);
- - if (pts != AV_NOPTS_VALUE) {
- - int len = buf.len - (ptr - buf.str);
- - if (len <= 0)
- - continue;
- - sub = ff_subtitles_queue_insert(&stl->q, ptr, len, 0);
- - if (!sub) {
- - res = AVERROR(ENOMEM);
- - goto end;
- - }
- - sub->pos = pos;
- - sub->pts = pts;
- - sub->duration = duration;
- - if (x1 != -1) {
- - uint8_t *p = av_packet_new_side_data(sub, AV_PKT_DATA_SUBTITLE_POSITION, 16);
- - if (p) {
- - AV_WL32(p, x1);
- - AV_WL32(p + 4, y1);
- - AV_WL32(p + 8, x2);
- - AV_WL32(p + 12, y2);
- - }
- - }
- - }
- - }
- - }
- -
- - ff_subtitles_queue_finalize(&stl->q);
- -
- -end:
- - av_bprint_finalize(&buf, NULL);
- - return res;
- -}
- -
- -/*static int stl_read_header(AVFormatContext *s)
- -{
- - STLContext *stl = s->priv_data;
- - AVStream *st = avformat_new_stream(s, NULL);
- -
- if (!st)
- return AVERROR(ENOMEM);
- avpriv_set_pts_info(st, 64, 1, 100);
- @@ -110,17 +47,16 @@ end:
- while (!avio_feof(s->pb)) {
- char line[4096];
- char *p = line;
- -
- const int64_t pos = avio_tell(s->pb);
- int len = ff_get_line(s->pb, line, sizeof(line));
- int64_t pts_start;
- -
- + int duration;
- if (!len)
- break;
- line[strcspn(line, "\r\n")] = 0;
- - pts_start = read_ts(&p);
- + pts_start = get_pts(&p , &duration);
- if (pts_start != AV_NOPTS_VALUE) {
- AVPacket *sub;
- @@ -129,14 +65,14 @@ end:
- return AVERROR(ENOMEM);
- sub->pos = pos;
- sub->pts = pts_start;
- - sub->duration = -1;
- + sub->duration = duration;
- }
- }
- ff_subtitles_queue_finalize(&stl->q);
- return 0;
- +
- }
- -*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement