1. 25 Mar, 2013 2 commits
    • Timothy B. Terriberry's avatar
      Reset dither state when API path changes. · f8222c99
      Timothy B. Terriberry authored
      The caller can switch between the fixed/float APIs and the
       stereo/multichannel APIs on every call.
      Detect this and reset the dither state to avoid potentially
       injecting noise from a very out-of-date state when switching from
       fixed to float back to fixed, or from the wrong channels when
       switching between stereo and multichannel.
      Normal applications won't do this stuff, but we should be
       well-behaved if they do.
      f8222c99
    • Timothy B. Terriberry's avatar
      Fix a buffer overflow in op_read_stereo(). · 81002442
      Timothy B. Terriberry authored
      For multichannel files, this potentially caused writes beyond the
       end of the output buffer provided by the user.
      81002442
  2. 01 Mar, 2013 1 commit
  3. 12 Feb, 2013 1 commit
  4. 10 Feb, 2013 1 commit
    • Timothy B. Terriberry's avatar
      Allow decoding forward instead of seeking. · 3cc27477
      Timothy B. Terriberry authored
      This lets us seek forward by small amounts (currently less than
       90 ms) by decoding forward instead of actually seeking.
      This is often a good idea, since we would have to decode at least
       80 ms of pre-roll anyway.
      This optimization also handles the case of seeking to what is
       already the current position cheaply.
      
      This became relatively easy after we dropped op_pcm_seek_page()
       from the public API.
      However, because others may look to libopusfile's seeking code as a
       model, we've added an OP_SMALL_FOOTPRINT #define to cordon off
       some of these complex sections of code that are deeply specific to
       libopusfile's design, ancillary to the main seeking algorithm,
       and relatively unimportant to overall seeking performance.
      3cc27477
  5. 04 Dec, 2012 1 commit
  6. 19 Nov, 2012 1 commit
  7. 13 Nov, 2012 2 commits
    • Timothy B. Terriberry's avatar
      Check for end_offset < data_offset. · 15193c53
      Timothy B. Terriberry authored
      I don't think it actually breaks anything if we don't (seeking will
       fail, but it will fail cleanly).
      However, it _is_ an indication that the file data changed out from
       under us (or of another library bug), so we should fail fast.
      15193c53
    • Timothy B. Terriberry's avatar
      Add op_get_last_page() for calculating duration. · 4dcf9b0d
      Timothy B. Terriberry authored
      Using op_get_prev_page_serial() meant if there were valid pages
       from another stream, we would re-scan them all repeatedly until we
       managed to back up, a page at a time, to a chunk with a page from
       the preferred stream with a valid granule position.
      Breaking this case into its own function means we can guarantee we
       only scan each page once, and that we can stop as soon as we hit a
       page from a different link (in the unlikely event that the stream
       has no pages with valid timestamps).
      4dcf9b0d
  8. 11 Nov, 2012 1 commit
  9. 24 Oct, 2012 1 commit
    • Timothy B. Terriberry's avatar
      Replace return code checks with OP_ALWAYS_TRUE(). · 4b70af03
      Timothy B. Terriberry authored
      Instead of assigning the return code to a local variable and then
       using OP_ASSERT(), define a new OP_ALWAYS_TRUE() macro that still
       evaluates its argument when assertions are disabled.
      This avoids -Wunused-but-set-variable warnings from clang and
       useless scan-build reports (if scan-build is run without
       assertions enabled).
      4b70af03
  10. 23 Oct, 2012 5 commits
  11. 22 Oct, 2012 2 commits
    • Timothy B. Terriberry's avatar
      Bias the offsets in op_predict_link_start(). · 498fc0bd
      Timothy B. Terriberry authored
      We apply a positive bias when the previous bisection point was
       inside the current link, causing us to scan forward a bit instead
       of seeking to a new location.
      This knocks up to 18% off the number of seeks required to open very
       large files with lots of links.
      498fc0bd
    • Timothy B. Terriberry's avatar
      Fix a few minor nits. · 21f72850
      Timothy B. Terriberry authored
      - The DIGIT character sets shouldn't need to list "0" twice.
      - Avoid a lookup for the port number in getaddrinfo().
      - Resolve the OPUS_SET_GAIN TODO (by refusing to implement a fallback).
      - A few more minor things.
      21f72850
  12. 20 Oct, 2012 3 commits
    • Timothy B. Terriberry's avatar
      Re-do abstract stream reader API. · e2d7b266
      Timothy B. Terriberry authored
      This changes op_read_func to
      a) Take a single byte count to read instead of an "item" count
          (which the http backend couldn't properly support anyway).
      b) Use integers for buffer sizes to avoid having to worry about
          sign differences and whether size_t is larger or smaller than
          opus_int64, etc.
      c) Return an explicit error code (instead of using errno like
          fread).
         We had already eliminated the use of errno, but we did it by
          treating read errors and EOF identically in all cases.
         This was preventing us from reporting SSL truncation attacks
          from the https backend.
         The https backend now properly reports such errors.
      
      This commit also fixes a bug introduced in 9b57b0c2, where we
       accidentally started passing absolute offsets to the _boundary
       parameter of op_get_next_page() instead of relative offsets.
      We now use absolute offsets in all places, as it is the simpler
       choice.
      This matters now, because the error reported when encountering EOF
       before hitting the _boundary is no longer suppressed (but instead
       reported as OP_EBADLINK).
      
      Finally, it removes the op_page_seek() function.
      Except for the time needed to decode forward after seeking, this
       function was identical in performance to op_pcm_seek(), and Opus
       requires decoding 80 ms of data after seek anyway, so the relative
       benefit is much smaller than with Vorbis.
      A survey of open-source code using libvorbisfile showed that the
       only usages of ov_page_seek() in the wild were calling it to seek
       to the start of the stream, for which op_pcm_seek() already has a
       special case that makes it just as fast.
      
      The documentation was also updated to describe all of these chanes.
      
      This is an incompatible API change.
      e2d7b266
    • Timothy B. Terriberry's avatar
      Make the URL API more extensible. · 800be8c0
      Timothy B. Terriberry authored
      Right now we have no way to add any more parameters beyond a set of
       basic binary flags.
      This unifies op_url_stream_create() and
       op_url_stream_create_with_proxy() into a single function that
       takes a variable-length list of arguments, which can be extended
       in the future to include more options of any type.
      
      This is an incompatible API change.
      800be8c0
    • Timothy B. Terriberry's avatar
      Documentation revisions and a leak fix. · 2ffd8cb7
      Timothy B. Terriberry authored
      Thanks to Jean-Marc Valin for providing documentation feedback.
      This also changes op_tags() to allow the tags to be queried on a
       partially-open file (because they've already been read and are
       available), and fixes a leak when a partially open file is freed
       instead of being fully opened.
      2ffd8cb7
  13. 09 Oct, 2012 1 commit
  14. 01 Oct, 2012 4 commits
    • Timothy B. Terriberry's avatar
      Multiple small fixes. · 6c56a973
      Timothy B. Terriberry authored
      * Tags were being freed even if not initialized if
         op_fetch_headers() failed on the first link.
        The logic for handling completely empty links would leak, also.
      * Ignore fragment identifiers in http URLs instead of rejecting
         them.
      * Get the current link in seeking_example's verify_seek when
         op_read_native() fails to return it for us.
      6c56a973
    • Timothy B. Terriberry's avatar
      Fix scan_build static analysis reports. · 737cbf57
      Timothy B. Terriberry authored
      Most of these were dead code left around from rewriting things and
       things llvm doesn't have enough global information to prove by
       itself.
      The one real error was the missing NULL check in
       opus_tags_parse_impl().
      737cbf57
    • Timothy B. Terriberry's avatar
      Fix an uninitialized warning from cf594de6. · 1f2f0bc4
      Timothy B. Terriberry authored
      The warning was correct, as far as it goes, but the use was
       actually harmless.
      1f2f0bc4
    • Timothy B. Terriberry's avatar
      Clean up page seeking a bit. · cf594de6
      Timothy B. Terriberry authored
      * Guarantee pcm_start and pcm_end stay in range (not just move in
         the right direction).
      * When we fail to find a page in the interval, back up by increasing
         chunk sizes just like op_get_prev_page_serial().
      * Eliminate the special case for the last page in the interval.
      * Force a straight bisection if we're backing up, but not decreasing
         the interval size rapidly enough, to limit the worst-case.
        This is guaranteed not to affect the first two iterations, so it
         has minimal impact on seeking in the normal case.
      cf594de6
  15. 29 Sep, 2012 2 commits
    • Timothy B. Terriberry's avatar
      Fix handling of holes. · e7661191
      Timothy B. Terriberry authored
      We have to call op_collect_audio_packets() again to drain any
       buffered packets from the page.
      e7661191
    • Timothy B. Terriberry's avatar
      Clean-up for alternate configurations. · 21322357
      Timothy B. Terriberry authored
      * s/op_read_stereo_float/op_read_float_stereo/ for the fixed-point
         API.
      * Fix compiler warnings exposed when optimizations are enabled.
      * Fix opusfile_example to work with --enable-fixed-point
         --disable-float
      * Fix seeking_example to not re-define OP_FIXED_POINT if it's
         already been defined.
      21322357
  16. 24 Sep, 2012 1 commit
  17. 23 Sep, 2012 9 commits
    • Timothy B. Terriberry's avatar
      Documentation clean-up and updates. · 7be86aca
      Timothy B. Terriberry authored
      Splits the documentation into sections and provides an overview.
      Also explicitly document which functions can and cannot be called on
       partially-open streams, and fix-up a few things to behave as
       documented.
      7be86aca
    • Timothy B. Terriberry's avatar
      Abstract position indicator tracking slightly. · 620ae47d
      Timothy B. Terriberry authored
      There are now a couple of places where we need to know the actual
       stream position indicator, not just the offset of the data we've
       read out of the ogg_sync_state.
      Make a function to compute this, document it, and use it.
      620ae47d
    • Timothy B. Terriberry's avatar
      Fix end_offset tracking bug from 007ec4e4. · bcbd60b8
      Timothy B. Terriberry authored
      end_offset should be the _start_ of the last Opus page in a link,
       to guarantee we seek before it to have enough information to do
       end-trimming.
      After the changes in 007ec4e4, it would be set to the start of the
       next link if we cached the last page granule position.
      
      Also add more comments.
      bcbd60b8
    • Timothy B. Terriberry's avatar
      Minor 16-bit int fix. · d0ce8564
      Timothy B. Terriberry authored
      d0ce8564
    • Timothy B. Terriberry's avatar
      More link enumeration improvements. · 007ec4e4
      Timothy B. Terriberry authored
      1) Remember the granule position of the last page we've seen from
          the current link and save the first page of the next link as
          long as we're scanning forward.
         This knocks almost 10% off the number of seeks for large links.
         For smaller links the improvement is much larger.
      2) Only use pairs of close-by serial numbers to estimate link
          start locations (assuming they're above our start threshold).
         This gives a minor (<2%) improvement, which might be in the
          noise, but as it doesn't appear to hurt and is faster, might as
          well.
      3) Eliminate a redundant check in op_pcm_seek_page_impl().
      007ec4e4
    • Timothy B. Terriberry's avatar
      Further reduce seeks per bisection search. · 9ed9fa49
      Timothy B. Terriberry authored
      If we encounter the first page after the target while scanning
       forward, we no longer seek back and read it again after we exit the
       bisection search, but just hold on to the copy we already have.
      9ed9fa49
    • Timothy B. Terriberry's avatar
      Estimate http connection latency and bandwidth. · e4f32131
      Timothy B. Terriberry authored
      This gives us a better idea when to re-use a connection.
      e4f32131
    • Timothy B. Terriberry's avatar
      Extrapolate in op_bisect_forward_serialno(). · 3774672b
      Timothy B. Terriberry authored
      This uses two sightings of a valid granule position from the same
       future stream to extrapolate where the start of that stream is
       during link enumeration.
      This can cut out more than 20% of the seeks required to open large
       files with lots of long links.
      3774672b
    • Timothy B. Terriberry's avatar
      Save more stream state on seekable open. · 28dce6b3
      Timothy B. Terriberry authored
      2df5f786 did not quite save enough.
      The ogg_stream_state and initial ogg_packet list also need to be
       saved, and the starting granule position and pre-skip need to be
       restored.
      Otherwise, if the stream has more than one link, the first packets
       decoded will come from the wrong one.
      28dce6b3
  18. 22 Sep, 2012 2 commits
    • Timothy B. Terriberry's avatar
      Save initial stream state on seekable open. · 2df5f786
      Timothy B. Terriberry authored
      This means that in the normal case, after identifying the chain
       boundaries, we will seek back exactly where we were before.
      With the http backend, that gives us a good chance of re-using our
       initial connection to continue reading the stream.
      Currently the LRU connection expiration algorithm means that is
       unlikely with lots of links, however.
      2df5f786
    • Timothy B. Terriberry's avatar
      Small speed-up to op_bisect_forward_serialno(). · 167822cf
      Timothy B. Terriberry authored
      Try to guess that the next link will be approximately the average
       size of all previous links, for files with many links.
      This cuts off 6-17% of the seeks.
      
      Also remove a variable that was left unused after 5e36109d.
      167822cf