MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / dejitterAudio

Function dejitterAudio

libhb/sync.c:1007–1046  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1005// timestamps. libav creates this type of problem sometimes with it's
1006// timestamp guessing code.
1007static 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
1049static void fixAudioGap( sync_stream_t * stream )

Callers 1

fixStreamTimestampsFunction · 0.85

Calls 3

hb_list_countFunction · 0.85
hb_list_itemFunction · 0.85
removeAudioJitterFunction · 0.85

Tested by

no test coverage detected