Fix audio overlaps that could not be corrected with dejitter
| 1109 | |
| 1110 | // Fix audio overlaps that could not be corrected with dejitter |
| 1111 | static void fixAudioOverlap( sync_stream_t * stream ) |
| 1112 | { |
| 1113 | int drop = 0; |
| 1114 | int64_t overlap; |
| 1115 | hb_buffer_t * buf; |
| 1116 | |
| 1117 | if (!stream->first_frame) |
| 1118 | { |
| 1119 | // There are no overlaps if we haven't seen the first frame yet. |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | // If time goes backwards drop the frame. |
| 1124 | // Check if subsequent buffers also overlap. |
| 1125 | while ((buf = hb_list_item(stream->in_queue, 0)) != NULL) |
| 1126 | { |
| 1127 | overlap = stream->next_pts - buf->s.start; |
| 1128 | if (overlap > 90 * 20) |
| 1129 | { |
| 1130 | if (stream->drop == 0) |
| 1131 | { |
| 1132 | stream->drop_pts = buf->s.start; |
| 1133 | } |
| 1134 | // This is likely to generate a gap in audio timestamps |
| 1135 | // This will be subsequently handled by the call to |
| 1136 | // fix AudioGap in Synchronize(). Small gaps will be handled |
| 1137 | // by just shifting the timestamps and carrying the gap |
| 1138 | // along. |
| 1139 | hb_list_rem(stream->in_queue, buf); |
| 1140 | stream->drop_duration += buf->s.duration; |
| 1141 | stream->drop++; |
| 1142 | drop++; |
| 1143 | hb_buffer_close(&buf); |
| 1144 | } |
| 1145 | else |
| 1146 | { |
| 1147 | break; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | if (drop <= 0 && stream->drop > 0) |
| 1152 | { |
| 1153 | hb_log("sync: audio 0x%x time went backwards %d ms, dropped %d frames. " |
| 1154 | "PTS %"PRId64"", |
| 1155 | stream->audio.audio->id, (int)stream->drop_duration / 90, |
| 1156 | stream->drop, stream->drop_pts); |
| 1157 | stream->drop_duration = 0; |
| 1158 | stream->drop = 0; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | static void fixSubtitleOverlap( sync_stream_t * stream ) |
| 1163 | { |
no test coverage detected