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

Function SortedQueueBuffer

libhb/sync.c:2003–2053  ·  view source on GitHub ↗

Handle broken timestamps that are out of order These are usually due to a broken decoder (e.g. QSV and libav AVI packed b-frame support). But sometimes can come from a severely broken or corrupted source file. We can pretty reliably fix out of order timestamps *if* every frame has a timestamp. But some container formats allow frames with no timestamp (e.g. TS and PS). When there is no timestam

Source from the content-addressed store, hash-verified

2001// vast majority of video is constant framerate, this will fix the above
2002// problem most of the time.
2003static void SortedQueueBuffer( sync_stream_t * stream, hb_buffer_t * buf )
2004{
2005 int64_t start;
2006 int ii, count;
2007
2008 start = buf->s.start;
2009 hb_list_add(stream->in_queue, buf);
2010
2011 // Search for the first earlier timestamp that is < this one.
2012 // Under normal circumstances where the timestamps are not broken,
2013 // this will only check the next to last buffer in the queue
2014 // before aborting.
2015 count = hb_list_count(stream->in_queue);
2016 for (ii = count - 2; ii >= 0; ii--)
2017 {
2018 buf = hb_list_item(stream->in_queue, ii);
2019 if (buf->s.start < start || start == AV_NOPTS_VALUE)
2020 {
2021 break;
2022 }
2023 }
2024 if (ii < count - 2)
2025 {
2026 hb_buffer_t * prev = NULL;
2027 int jj;
2028
2029 // The timestamp was out of order.
2030 // The timestamp belongs at position ii + 1
2031 // Every timestamp from ii + 2 to count - 1 needs to be shifted up.
2032 if (ii >= 0)
2033 {
2034 prev = hb_list_item(stream->in_queue, ii);
2035 }
2036 for (jj = ii + 1; jj < count; jj++)
2037 {
2038 int64_t tmp_start;
2039
2040 buf = hb_list_item(stream->in_queue, jj);
2041 tmp_start = buf->s.start;
2042 buf->s.start = start;
2043 start = tmp_start;
2044 if (stream->type == SYNC_TYPE_VIDEO && prev != NULL)
2045 {
2046 // recompute video buffer duration
2047 prev->s.duration = buf->s.start - prev->s.start;
2048 prev->s.stop = buf->s.start;
2049 }
2050 prev = buf;
2051 }
2052 }
2053}
2054
2055static void QueueBuffer( sync_stream_t * stream, hb_buffer_t * buf )
2056{

Callers 2

ProcessSCRDelayQueueFunction · 0.85
QueueBufferFunction · 0.85

Calls 3

hb_list_addFunction · 0.85
hb_list_countFunction · 0.85
hb_list_itemFunction · 0.85

Tested by

no test coverage detected