Look for a sequence of packets whose duration as measure by packet durations closely matches the duration as measured by timestamp differences. When close matches are found, smooth the timestamps. This fixes issues where there are false overlaps and gaps in audio timestamps. libav creates this type of problem sometimes with it's timestamp guessing code.
| 1005 | // timestamps. libav creates this type of problem sometimes with it's |
| 1006 | // timestamp guessing code. |
| 1007 | static void dejitterAudio( sync_stream_t * stream ) |
| 1008 | { |
| 1009 | int ii, count, jitter_stop; |
| 1010 | double duration; |
| 1011 | hb_buffer_t * buf, * buf0, * buf1; |
| 1012 | |
| 1013 | count = hb_list_count(stream->in_queue); |
| 1014 | if (count < 4) |
| 1015 | { |
| 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | // Look for start of jitter sequence |
| 1020 | jitter_stop = 0; |
| 1021 | buf0 = hb_list_item(stream->in_queue, 0); |
| 1022 | buf1 = hb_list_item(stream->in_queue, 1); |
| 1023 | if (ABS(buf0->s.duration - (buf1->s.start - stream->next_pts)) < 1.1) |
| 1024 | { |
| 1025 | // Ignore very small jitter |
| 1026 | return; |
| 1027 | } |
| 1028 | buf = hb_list_item(stream->in_queue, 0); |
| 1029 | duration = buf->s.duration; |
| 1030 | |
| 1031 | // Look for end of jitter sequence |
| 1032 | for (ii = 1; ii < count; ii++) |
| 1033 | { |
| 1034 | buf = hb_list_item(stream->in_queue, ii); |
| 1035 | if (ABS(duration - (buf->s.start - stream->next_pts)) < (90 * 40)) |
| 1036 | { |
| 1037 | // Finds the largest span that has low jitter |
| 1038 | jitter_stop = ii; |
| 1039 | } |
| 1040 | duration += buf->s.duration; |
| 1041 | } |
| 1042 | if (jitter_stop >= 4) |
| 1043 | { |
| 1044 | removeAudioJitter(stream, jitter_stop); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | // Fix audio gaps that could not be corrected with dejitter |
| 1049 | static void fixAudioGap( sync_stream_t * stream ) |
no test coverage detected