Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clpi_lookup_spn(CLPI_CL *cl, uint32_t timestamp, int before, uint8_t stc_id)
- {
- CLPI_EP_MAP_ENTRY *entry;
- CLPI_CPI *cpi = &cl->cpi;
- int ii, jj;
- uint32_t coarse_pts, pts; // 45khz timestamps
- uint32_t spn, coarse_spn, stc_spn;
- int start, end;
- int ref;
- if (cpi->num_stream_pid < 1 || !cpi->entry) {
- if (before) {
- return 0;
- }
- return cl->clip.num_source_packets;
- }
- // Assumes that there is only one pid of interest
- entry = &cpi->entry[0];
- // Use sequence info to find spn_stc_start before doing
- // PTS search. The spn_stc_start defines the point in
- // the EP map to start searching.
- stc_spn = _find_stc_spn(cl, stc_id);
- for (ii = 0; ii < entry->num_ep_coarse; ii++) {
- ref = entry->coarse[ii].ref_ep_fine_id;
- if (entry->coarse[ii].spn_ep >= stc_spn) {
- // The desired starting point is either after this point
- // or in the middle of the previous coarse entry
- break;
- }
- }
- if (ii >= entry->num_ep_coarse) {
- return cl->clip.num_source_packets;
- }
- pts = ((uint64_t)(entry->coarse[ii].pts_ep & ~0x01) << 18) +
- ((uint64_t)entry->fine[ref].pts_ep << 8);
- if (pts > timestamp && ii) {
- // The starting point and desired PTS is in the previous coarse entry
- ii--;
- coarse_pts = (uint32_t)(entry->coarse[ii].pts_ep & ~0x01) << 18;
- coarse_spn = entry->coarse[ii].spn_ep;
- start = entry->coarse[ii].ref_ep_fine_id;
- end = entry->coarse[ii+1].ref_ep_fine_id;
- // Find a fine entry that has bothe spn > stc_spn and ptc > timestamp
- for (jj = start; jj < end; jj++) {
- pts = coarse_pts + ((uint32_t)entry->fine[jj].pts_ep << 8);
- spn = (coarse_spn & ~0x1FFFF) + entry->fine[jj].spn_ep;
- if (stc_spn >= spn && pts > timestamp)
- break;
- }
- goto done;
- }
- // If we've gotten this far, the desired timestamp is somewhere
- // after the coarse entry we found the stc_spn in.
- start = ii;
- for (ii = start; ii < entry->num_ep_coarse; ii++) {
- ref = entry->coarse[ii].ref_ep_fine_id;
- pts = ((uint64_t)(entry->coarse[ii].pts_ep & ~0x01) << 18) +
- ((uint64_t)entry->fine[ref].pts_ep << 8);
- if (pts > timestamp) {
- break;
- }
- }
- // If the timestamp is before the first entry, then return
- // the beginning of the clip
- if (ii == 0) {
- return 0;
- }
- ii--;
- coarse_pts = (uint32_t)(entry->coarse[ii].pts_ep & ~0x01) << 18;
- start = entry->coarse[ii].ref_ep_fine_id;
- if (ii < entry->num_ep_coarse - 1) {
- end = entry->coarse[ii+1].ref_ep_fine_id;
- } else {
- end = entry->num_ep_fine;
- }
- for (jj = start; jj < end; jj++) {
- pts = coarse_pts + ((uint32_t)entry->fine[jj].pts_ep << 8);
- if (pts > timestamp)
- break;
- }
- done:
- if (before) {
- jj--;
- }
- if (jj == end) {
- ii++;
- if (ii >= entry->num_ep_coarse) {
- // End of file
- return cl->clip.num_source_packets;
- }
- jj = entry->coarse[ii].ref_ep_fine_id;
- }
- spn = (entry->coarse[ii].spn_ep & ~0x1FFFF) + entry->fine[jj].spn_ep;
- return spn;
- }
Add Comment
Please, Sign In to add comment