| 1495 | int num_validcaptions = tbuffer_numvalid(); |
| 1496 | text_buflock.lock(); |
| 1497 | int prev_rtxt = (rtxt - 1 + MAXTBUFFER) % MAXTBUFFER; |
| 1498 | /* Check whether the reader appears to be waiting on a caption |
| 1499 | whose timestamp is too large. We can guess this is the case |
| 1500 | if we are adding a timestamp that is smaller than timestamp |
| 1501 | being waited on but larger than the timestamp before that. |
| 1502 | Note that even if the text buffer is full, the entry at index |
| 1503 | rtxt-1 should still be valid. |
| 1504 | */ |
| 1505 | if (num_validcaptions > 0 && |
| 1506 | txtbuffers[rtxt].timecode > timecode && |
| 1507 | timecode > txtbuffers[prev_rtxt].timecode) |
| 1508 | { |
| 1509 | /* If so, reset the timestamp that the reader is waiting on |
| 1510 | to a value reasonably close to the previously read |
| 1511 | timestamp. This will probably cause one or more captions |
| 1512 | to appear rapidly, but at least the captions won't |
| 1513 | appear to be stuck. |
| 1514 | */ |
| 1515 | VERBOSE(VB_VBI, |
| 1516 | QString("Writing caption timecode %1 but waiting on %2") |
| 1517 | .arg(timecode).arg(txtbuffers[rtxt].timecode)); |
| 1518 | txtbuffers[rtxt].timecode = txtbuffers[prev_rtxt].timecode + 500; |
| 1519 | } |
| 1520 | |