Fix audio gaps that could not be corrected with dejitter
| 1047 | |
| 1048 | // Fix audio gaps that could not be corrected with dejitter |
| 1049 | static void fixAudioGap( sync_stream_t * stream ) |
| 1050 | { |
| 1051 | int64_t gap; |
| 1052 | hb_buffer_t * buf; |
| 1053 | |
| 1054 | if (hb_list_count(stream->in_queue) < 1 || !stream->first_frame) |
| 1055 | { |
| 1056 | // Can't find gaps with < 1 buffers |
| 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | buf = hb_list_item(stream->in_queue, 0); |
| 1061 | gap = buf->s.start - stream->next_pts; |
| 1062 | |
| 1063 | // If there's a gap of more than a minute between the last |
| 1064 | // frame and this, assume we got a corrupted timestamp. |
| 1065 | if (gap > 90 * 20 && gap < 90000LL * 60) |
| 1066 | { |
| 1067 | if (stream->gap_duration <= 0) |
| 1068 | { |
| 1069 | stream->gap_pts = buf->s.start; |
| 1070 | } |
| 1071 | buf = CreateSilenceBuf(stream, gap, stream->next_pts); |
| 1072 | if (buf != NULL) |
| 1073 | { |
| 1074 | hb_buffer_t * next; |
| 1075 | int pos; |
| 1076 | for (pos = 0; buf != NULL; buf = next, pos++) |
| 1077 | { |
| 1078 | next = buf->next; |
| 1079 | buf->next = NULL; |
| 1080 | hb_list_insert(stream->in_queue, pos, buf); |
| 1081 | } |
| 1082 | } |
| 1083 | else |
| 1084 | { |
| 1085 | addDelta(stream->common, stream->next_pts, gap); |
| 1086 | applyDeltas(stream->common); |
| 1087 | } |
| 1088 | stream->gap_duration += gap; |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | // If not fixing the gap, carry to the next frame |
| 1093 | // so they do not accumulate. Do not carry negative gaps. |
| 1094 | // Those are overlaps and are handled by fixAudioOverlap. |
| 1095 | if (gap >= 90000LL * 60) |
| 1096 | { |
| 1097 | // Fix "corrupted" timestamp |
| 1098 | buf->s.start = stream->next_pts; |
| 1099 | } |
| 1100 | if (stream->gap_duration > 0) |
| 1101 | { |
| 1102 | hb_deep_log(3, "sync: audio 0x%x time gap %d ms. PTS %"PRId64"", |
| 1103 | stream->audio.audio->id, (int)stream->gap_duration / 90, |
| 1104 | stream->gap_pts); |
| 1105 | stream->gap_duration = 0; |
| 1106 | } |
no test coverage detected