get one (position, timestamp) sample from a transport or program stream.
| 1557 | // get one (position, timestamp) sample from a transport or program |
| 1558 | // stream. |
| 1559 | static struct pts_pos hb_sample_pts(hb_stream_t *stream, uint64_t fpos) |
| 1560 | { |
| 1561 | struct pts_pos pp = { 0, 0 }; |
| 1562 | |
| 1563 | if ( stream->hb_stream_type == transport ) |
| 1564 | { |
| 1565 | const uint8_t *buf; |
| 1566 | int adapt_len; |
| 1567 | fseeko( stream->file_handle, fpos, SEEK_SET ); |
| 1568 | align_to_next_packet( stream ); |
| 1569 | int pid = stream->ts.list[ts_index_of_video(stream)].pid; |
| 1570 | buf = hb_ts_stream_getPEStype( stream, pid, &adapt_len ); |
| 1571 | if ( buf == NULL ) |
| 1572 | { |
| 1573 | hb_log("hb_sample_pts: couldn't find video packet near %"PRIu64, fpos); |
| 1574 | return pp; |
| 1575 | } |
| 1576 | const uint8_t *pes = buf + 4 + adapt_len; |
| 1577 | if ( ( pes[7] >> 7 ) != 1 ) |
| 1578 | { |
| 1579 | hb_log("hb_sample_pts: no PTS in video packet near %"PRIu64, fpos); |
| 1580 | return pp; |
| 1581 | } |
| 1582 | pp.pts = ((((uint64_t)pes[ 9] >> 1 ) & 7) << 30) | |
| 1583 | ( (uint64_t)pes[10] << 22) | |
| 1584 | ( ((uint64_t)pes[11] >> 1 ) << 15) | |
| 1585 | ( (uint64_t)pes[12] << 7 ) | |
| 1586 | ( (uint64_t)pes[13] >> 1 ); |
| 1587 | |
| 1588 | if ( ts_isIframe( stream, buf, adapt_len ) ) |
| 1589 | { |
| 1590 | if ( stream->has_IDRs < 255 ) |
| 1591 | { |
| 1592 | ++stream->has_IDRs; |
| 1593 | } |
| 1594 | } |
| 1595 | pp.pos = ftello(stream->file_handle); |
| 1596 | if ( !stream->has_IDRs ) |
| 1597 | { |
| 1598 | // Scan a little more to see if we will stumble upon one |
| 1599 | int ii; |
| 1600 | for ( ii = 0; ii < 10; ii++ ) |
| 1601 | { |
| 1602 | buf = hb_ts_stream_getPEStype( stream, pid, &adapt_len ); |
| 1603 | if ( buf == NULL ) |
| 1604 | break; |
| 1605 | if ( ts_isIframe( stream, buf, adapt_len ) ) |
| 1606 | { |
| 1607 | ++stream->has_IDRs; |
| 1608 | break; |
| 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | hb_buffer_t *buf; |
| 1616 | hb_pes_info_t pes_info; |
no test coverage detected