| 127 | } |
| 128 | |
| 129 | static int srt_read_header(AVFormatContext *s) |
| 130 | { |
| 131 | SRTContext *srt = s->priv_data; |
| 132 | AVBPrint buf; |
| 133 | AVStream *st = avformat_new_stream(s, NULL); |
| 134 | int res = 0; |
| 135 | char line[4096], line_cache[4096]; |
| 136 | int has_event_info = 0; |
| 137 | struct event_info ei; |
| 138 | FFTextReader tr; |
| 139 | ff_text_init_avio(s, &tr, s->pb); |
| 140 | |
| 141 | if (!st) |
| 142 | return AVERROR(ENOMEM); |
| 143 | avpriv_set_pts_info(st, 64, 1, 1000); |
| 144 | st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; |
| 145 | st->codecpar->codec_id = AV_CODEC_ID_SUBRIP; |
| 146 | |
| 147 | av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 148 | |
| 149 | line_cache[0] = 0; |
| 150 | |
| 151 | while (!ff_text_eof(&tr)) { |
| 152 | struct event_info tmp_ei; |
| 153 | const int64_t pos = ff_text_pos(&tr); |
| 154 | ptrdiff_t len = ff_subtitles_read_line(&tr, line, sizeof(line)); |
| 155 | |
| 156 | if (len < 0) |
| 157 | break; |
| 158 | |
| 159 | if (!len || !line[0]) |
| 160 | continue; |
| 161 | |
| 162 | if (get_event_info(line, &tmp_ei) < 0) { |
| 163 | char *pline; |
| 164 | |
| 165 | if (!has_event_info) |
| 166 | continue; |
| 167 | |
| 168 | if (line_cache[0]) { |
| 169 | /* We got some cache and a new line so we assume the cached |
| 170 | * line was actually part of the payload */ |
| 171 | av_bprintf(&buf, "%s\n", line_cache); |
| 172 | line_cache[0] = 0; |
| 173 | } |
| 174 | |
| 175 | /* If the line doesn't start with a number, we assume it's part of |
| 176 | * the payload, otherwise is likely an event number preceding the |
| 177 | * timing information... but we can't be sure of this yet, so we |
| 178 | * cache it */ |
| 179 | if (strtol(line, &pline, 10) < 0 || line == pline) |
| 180 | av_bprintf(&buf, "%s\n", line); |
| 181 | else |
| 182 | strcpy(line_cache, line); |
| 183 | } else { |
| 184 | if (has_event_info) { |
| 185 | /* We have the information of previous event, append it to the |
| 186 | * queue. We insert the cached line if and only if the payload |
nothing calls this directly
no test coverage detected