given an array of (position, time) samples, compute a max-likelihood estimate of the average rate by computing the rate between all pairs of samples then taking the median of those rates.
| 1677 | // estimate of the average rate by computing the rate between all pairs |
| 1678 | // of samples then taking the median of those rates. |
| 1679 | static double compute_stream_rate( struct pts_pos *pp, int n ) |
| 1680 | { |
| 1681 | int i, j; |
| 1682 | double rates[NDURSAMPLES * NDURSAMPLES / 8]; |
| 1683 | double *rp = rates; |
| 1684 | |
| 1685 | // the following nested loops compute the rates between all pairs. |
| 1686 | *rp = 0; |
| 1687 | for ( i = 0; i < n-1; ++i ) |
| 1688 | { |
| 1689 | // Bias the median filter by not including pairs that are "far" |
| 1690 | // from one another. This is to handle cases where the file is |
| 1691 | // made of roughly equal size pieces where a symmetric choice of |
| 1692 | // pairs results in having the same number of intra-piece & |
| 1693 | // inter-piece rate estimates. This would mean that the median |
| 1694 | // could easily fall in the inter-piece part of the data which |
| 1695 | // would give a bogus estimate. The 'ns' index creates an |
| 1696 | // asymmetry that favors locality. |
| 1697 | int ns = i + ( n >> 3 ); |
| 1698 | if ( ns > n ) |
| 1699 | ns = n; |
| 1700 | for ( j = i+1; j < ns; ++j ) |
| 1701 | { |
| 1702 | if ( (uint64_t)(pp[j].pts - pp[i].pts) > 90000LL*3600*6 ) |
| 1703 | break; |
| 1704 | if ( pp[j].pts != pp[i].pts && pp[j].pos > pp[i].pos ) |
| 1705 | { |
| 1706 | *rp = ((double)( pp[j].pts - pp[i].pts )) / |
| 1707 | ((double)( pp[j].pos - pp[i].pos )); |
| 1708 | ++rp; |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | // now compute and return the median of all the (n*n/2) rates we computed |
| 1713 | // above. |
| 1714 | int nrates = rp - rates; |
| 1715 | qsort( rates, nrates, sizeof (rates[0] ), dur_compare ); |
| 1716 | return rates[nrates >> 1]; |
| 1717 | } |
| 1718 | |
| 1719 | static void hb_stream_duration(hb_stream_t *stream, hb_title_t *inTitle) |
| 1720 | { |
no outgoing calls
no test coverage detected