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

Function UpdateSCR

libhb/sync.c:1887–1982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1885}
1886
1887static int UpdateSCR( sync_stream_t * stream, hb_buffer_t * buf )
1888{
1889 int hash = buf->s.scr_sequence & SCR_HASH_MASK;
1890 sync_common_t * common = stream->common;
1891 double last_scr_pts, last_duration;
1892 int64_t scr_offset = 0;
1893
1894 if (buf->s.scr_sequence < stream->last_scr_sequence)
1895 {
1896 // In decoder error conditions, the decoder can send us out of
1897 // order frames. Often the stream error will also trigger a
1898 // discontinuity detection. An out of order frame will
1899 // cause an incorrect SCR offset, so drop such frames.
1900 hb_deep_log(3, "SCR sequence went backwards %d -> %d",
1901 stream->last_scr_sequence, buf->s.scr_sequence);
1902 hb_buffer_close(&buf);
1903 return 0;
1904 }
1905 if (buf->s.scr_sequence >= 0)
1906 {
1907 if (buf->s.scr_sequence != common->scr[hash].scr_sequence)
1908 {
1909 if (stream->type == SYNC_TYPE_SUBTITLE ||
1910 (stream->last_scr_pts == (int64_t)AV_NOPTS_VALUE &&
1911 common->first_scr))
1912 {
1913 // We got a new scr, but we have no last_scr_pts to base it
1914 // off of. Delay till we can compute the scr offset from a
1915 // different stream.
1916 hb_list_add(stream->scr_delay_queue, buf);
1917 return 0;
1918 }
1919 if (buf->s.start != AV_NOPTS_VALUE)
1920 {
1921 last_scr_pts = stream->last_scr_pts;
1922 last_duration = stream->last_duration;
1923 if (last_scr_pts == (int64_t)AV_NOPTS_VALUE)
1924 {
1925 last_scr_pts = 0.;
1926 last_duration = 0.;
1927 common->first_scr = 1;
1928 }
1929 // New SCR. Compute SCR offset
1930 common->scr[hash].scr_sequence = buf->s.scr_sequence;
1931 common->scr[hash].scr_offset = buf->s.start -
1932 (last_scr_pts + last_duration);
1933 hb_deep_log(4,
1934 "New SCR: type %8s id %x scr seq %d scr offset %"PRId64" "
1935 "start %"PRId64" last %f dur %f",
1936 getStreamType(stream), getStreamId(stream),
1937 buf->s.scr_sequence, common->scr[hash].scr_offset,
1938 buf->s.start, last_scr_pts, last_duration);
1939 ProcessSCRDelayQueue(common);
1940 }
1941 }
1942 scr_offset = common->scr[hash].scr_offset;
1943 }
1944

Callers 2

computeInitialTSFunction · 0.85
QueueBufferFunction · 0.85

Calls 6

hb_deep_logFunction · 0.85
hb_buffer_closeFunction · 0.85
hb_list_addFunction · 0.85
getStreamTypeFunction · 0.85
getStreamIdFunction · 0.85
ProcessSCRDelayQueueFunction · 0.85

Tested by

no test coverage detected