]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'refs/heads/t/ogg_afh'
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 28 Feb 2020 17:13:50 +0000 (18:13 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 28 Feb 2020 17:16:00 +0000 (18:16 +0100)
A patch which teaches the ogg/* audio format handlers to report the
correct length for files with holes. A bug was found in that patch
after the branch had been merged to next, so there's a fixup commit
on top.

The second patch in this series fixes an issue with
ogg_page_granulepos() that can result in incorrect estimates for the
duration of files that use the ogg container format.

Cooking for a year.

* refs/heads/t/ogg_afh:
  ogg_afh_common.c: Check return value of ogg_page_granulepos().
  ogg_afh_common: Fix signedness issue.
  ogg: Detect missing ogg pages.

NEWS.md
ogg_afh_common.c

diff --git a/NEWS.md b/NEWS.md
index fd587fab054dea33124918870b24351b20586fc6..3775b21c27e32426a11dd47758182ffd99bfeeff 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -22,6 +22,9 @@ NEWS
 - para_client now supports RFC4716 private keys as generated with
   ssh-keygen -m RFC4716. In fact, this key format has been made the
   default, and the former PEM keys will be depreciated at some point.
+- The ogg audio format handlers learned to detect holes and now report
+  the correct duration also if ogg pages are missing in the file. This
+  affects ogg/vorbis ogg/speex and ogg/opus.
 
 --------------------------------------
 0.6.2 (2018-06-30) "elastic diversity"
index 62cde3d465ab7c86a23d6c539b8a2b447d465f78..3e36bdd5b1e9d3615695f975541bf69c0cc05093 100644 (file)
@@ -124,8 +124,9 @@ int oac_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        ogg_sync_state oss;
        ogg_page op;
        char *buf;
-       int ret, i, j, frames_per_chunk, ct_size;
-       long long unsigned num_frames = 0;
+       int ret, i, j, frames_per_chunk, ct_size, prev_pageno = 0;
+       long long unsigned granule_skip = 0, num_frames = 0;
+       int64_t granule = 0, prev_granule = 0;
 
        ogg_sync_init(&oss);
        ret = -E_OGG_SYNC;
@@ -145,8 +146,17 @@ int oac_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        oss.returned = 0;
        oss.fill = numbytes;
        /* count ogg pages and get duration of the file */
-       for (i = 0; ogg_sync_pageseek(&oss, &op) > 0; i++)
-               num_frames = ogg_page_granulepos(&op);
+       for (i = 0; ogg_sync_pageseek(&oss, &op) > 0; i++) {
+               int this_pageno = ogg_page_pageno(&op);
+               int64_t this_granule = ogg_page_granulepos(&op);
+               if (this_granule >= 0)
+                       granule = this_granule;
+               if (i > 0 && this_pageno != prev_pageno + 1) /* hole */
+                       granule_skip += granule - prev_granule;
+               prev_pageno = this_pageno;
+               prev_granule = granule;
+       }
+       num_frames = granule - granule_skip;
        PARA_INFO_LOG("%d pages, %llu frames\n", i, num_frames);
        ret = -E_OGG_EMPTY;
        if (i == 0)
@@ -163,7 +173,7 @@ int oac_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        oss.returned = afhi->header_len;
        oss.fill = numbytes;
        for (j = 1; ogg_sync_pageseek(&oss, &op) > 0; /* nothing */) {
-               int granule = ogg_page_granulepos(&op);
+               granule = ogg_page_granulepos(&op);
 
                while (granule >= (j + 1) * frames_per_chunk) {
                        j++;