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

Function OutputBuffer

libhb/sync.c:1434–1751  ·  view source on GitHub ↗

OutputBuffer pulls buffers from the internal sync buffer queues in lowest PTS first order. It then processes the queue the buffer is pulled from for frame overlaps and gaps. If a queue reaches MAX depth, it is possible another queue is too low to achieve both goals of pulling lowest PTS first *and* perform timestamp correction. In this scenario, we forego lowest PTS and pull the next lowest PTS

Source from the content-addressed store, hash-verified

1432// the next lowest PTS that has enough buffers in the queue to perform
1433// timestamp correction.
1434static int OutputBuffer( sync_common_t * common )
1435{
1436 int ii, more;
1437 int64_t pts;
1438 sync_stream_t * out_stream;
1439 hb_buffer_t * buf;
1440 int out_count = 0;
1441
1442 do
1443 {
1444 more = 0;
1445 out_stream = NULL;
1446 pts = INT64_MAX;
1447
1448 // Find lowest PTS and output that buffer
1449 for (ii = 0; ii < common->stream_count; ii++)
1450 {
1451 sync_stream_t * stream = &common->streams[ii];
1452 int min = stream->min_len;
1453
1454 // Ignore minimum buffer requirements for video if we have
1455 // not yet found the PtoP start frame.
1456 if (!common->start_found && common->wait_for_frame &&
1457 stream->type == SYNC_TYPE_VIDEO)
1458 {
1459 min = 0;
1460 }
1461 // We need at least 2 buffers in the queue in order to fix
1462 // frame overlaps and inter-frame gaps. So if a queue is
1463 // low, do not do normal PTS interleaving with this queue.
1464 // Except for subtitles which are not processed for gaps
1465 // and overlaps.
1466 if ((common->flush && hb_list_count(stream->in_queue) > 0) ||
1467 hb_list_count(stream->in_queue) > min)
1468 {
1469 buf = hb_list_item(stream->in_queue, 0);
1470 if (buf->s.start < pts)
1471 {
1472 pts = buf->s.start;
1473 out_stream = stream;
1474 }
1475 }
1476 // But continue output of buffers as long as one of the queues
1477 // is above the maximum queue level.
1478 if ((common->flush && hb_list_count(stream->in_queue) > 0) ||
1479 hb_list_count(stream->in_queue) > stream->max_len)
1480 {
1481 more = 1;
1482 }
1483 }
1484 if (out_stream == NULL)
1485 {
1486 // This should only happen if all queues are below the
1487 // minimum queue level
1488 break;
1489 }
1490 if (out_stream->done)
1491 {

Callers 2

flushStreamsFunction · 0.85
SynchronizeFunction · 0.85

Calls 15

hb_list_countFunction · 0.85
hb_list_itemFunction · 0.85
hb_list_remFunction · 0.85
hb_buffer_closeFunction · 0.85
fixStreamTimestampsFunction · 0.85
UpdateSearchStateFunction · 0.85
shiftTSFunction · 0.85
alignStreamsFunction · 0.85
setNextPtsFunction · 0.85
hb_logFunction · 0.85
terminateSubtitleStreamsFunction · 0.85
flushStreamsFunction · 0.85

Tested by

no test coverage detected