* Read the SRT file and put the entries into the subtitle fifo for all to read */
| 213 | * Read the SRT file and put the entries into the subtitle fifo for all to read |
| 214 | */ |
| 215 | static hb_buffer_t *srt_read( hb_work_private_t *pv ) |
| 216 | { |
| 217 | char line_buffer[1024]; |
| 218 | int reprocess = 0, resync = 0; |
| 219 | |
| 220 | if (!pv->file) |
| 221 | { |
| 222 | return hb_buffer_eof_init(); |
| 223 | } |
| 224 | |
| 225 | if (pv->job->reader_pts_offset == AV_NOPTS_VALUE) |
| 226 | { |
| 227 | // We need to wait for reader to initialize it's pts offset so that |
| 228 | // we know where to start reading SRTs. |
| 229 | return NULL; |
| 230 | } |
| 231 | if (pv->start_time == AV_NOPTS_VALUE) |
| 232 | { |
| 233 | pv->start_time = pv->job->reader_pts_offset; |
| 234 | if (pv->job->pts_to_stop > 0) |
| 235 | { |
| 236 | pv->stop_time = pv->job->pts_to_start + pv->job->pts_to_stop; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | while( reprocess || get_line( pv, line_buffer, sizeof( line_buffer ) ) ) |
| 241 | { |
| 242 | reprocess = 0; |
| 243 | switch (pv->current_state) |
| 244 | { |
| 245 | case k_state_timecode: |
| 246 | { |
| 247 | struct start_and_end timing; |
| 248 | int result; |
| 249 | |
| 250 | result = read_time_from_string( line_buffer, &timing ); |
| 251 | if (!result) |
| 252 | { |
| 253 | resync = 1; |
| 254 | pv->current_state = k_state_potential_new_entry; |
| 255 | continue; |
| 256 | } |
| 257 | pv->current_entry.duration = timing.end - timing.start; |
| 258 | pv->current_entry.offset = timing.start - pv->current_time; |
| 259 | |
| 260 | pv->current_time = timing.end; |
| 261 | |
| 262 | pv->current_entry.start = timing.start; |
| 263 | pv->current_entry.stop = timing.end; |
| 264 | |
| 265 | pv->current_state = k_state_inEntry; |
| 266 | continue; |
| 267 | } |
| 268 | |
| 269 | case k_state_inEntry_or_new: |
| 270 | { |
| 271 | char *endpoint; |
| 272 | /* |
no test coverage detected