Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.45 KB | None | 0 0
  1.  src/opusdec.c | 43 +++++++++++++++++++++++++++++++++----------
  2.  src/opusenc.c | 18 ++++++++++--------
  3.  2 files changed, 43 insertions(+), 18 deletions(-)
  4.  
  5. diff --git a/src/opusdec.c b/src/opusdec.c
  6. index 9f8ad2c..397b134 100644
  7. --- a/src/opusdec.c
  8. +++ b/src/opusdec.c
  9. @@ -41,6 +41,7 @@
  10.  #include <limits.h>
  11.  #include <string.h>
  12.  #include <ctype.h> /*tolower()*/
  13. +#include <time.h>
  14.  
  15.  #include <opus.h>
  16.  #include <opusfile.h>
  17. @@ -473,7 +474,7 @@ void usage(void)
  18.  
  19.  void version(void)
  20.  {
  21. -   printf("opusdec %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opus_get_version_string());
  22. +   printf("opusdec %s %s\n   using %s\n",PACKAGE_NAME,PACKAGE_VERSION,opus_get_version_string());
  23.     printf("Copyright (C) 2008-2018 Xiph.Org Foundation\n");
  24.  }
  25.  
  26. @@ -680,8 +681,11 @@ int main(int argc, char **argv)
  27.     int quiet = 0;
  28.     int forcewav = 0;
  29.     ogg_int64_t nb_read_total=0;
  30. +   ogg_int64_t nb_total_length=0;
  31.     ogg_int64_t link_read=0;
  32.     ogg_int64_t link_out=0;
  33. +   clock_t last_update=0;
  34. +   double last_progress=0.0;
  35.     struct option long_options[] =
  36.     {
  37.        {"help", no_argument, NULL, 0},
  38. @@ -699,7 +703,7 @@ int main(int argc, char **argv)
  39.        {0, 0, 0, 0}
  40.     };
  41.     opus_int64 audio_size=0;
  42. -   double last_coded_seconds=0;
  43. +   double last_coded_seconds=0.0;
  44.     float loss_percent=-1;
  45.     float manual_gain=0;
  46.     int force_rate=0;
  47. @@ -873,6 +877,7 @@ int main(int argc, char **argv)
  48.        /*If we have a seekable file, we can make some intelligent decisions
  49.          about how to decode.*/
  50.        nlinks = op_link_count(st);
  51. +      nb_total_length = op_pcm_total(st, -1);
  52.        if (rate==0)
  53.        {
  54.           opus_uint32 initial_rate;
  55. @@ -1111,18 +1116,36 @@ int main(int argc, char **argv)
  56.        {
  57.           /*Display a progress spinner while decoding.*/
  58.           static const char spinner[]="|/-\\";
  59. -         double coded_seconds=nb_read_total/(double)rate;
  60. -         if (coded_seconds>=last_coded_seconds+1 || li!=old_li)
  61. +         int update_flag = 0;
  62. +         const double coded_seconds=nb_read_total/(double)rate;
  63. +         const clock_t clocks = clock();
  64. +         if(nb_total_length > 0)
  65.           {
  66. -            fprintf(stderr,"\r[%c] %02d:%02d:%02d", spinner[last_spin&3],
  67. -             (int)(coded_seconds/3600), (int)(coded_seconds/60)%60,
  68. -             (int)(coded_seconds)%60);
  69. -            fflush(stderr);
  70. +            const double progress = (nb_read_total/(double)nb_total_length) * 100.0;
  71. +            if ((update_flag = coded_seconds>=last_coded_seconds && clocks>=last_update && progress>=last_progress) || li != old_li)
  72. +            {
  73. +               fprintf(stderr, "\r[%c] %02d:%02d:%02d (%.1f%%)", spinner[last_spin & 3],
  74. +                  (int)(coded_seconds / 3600), (int)(coded_seconds / 60) % 60,
  75. +                  (int)(coded_seconds) % 60, progress);
  76. +               fflush(stderr);
  77. +               last_progress = progress + 1.0/3.0;
  78. +            }
  79. +         }
  80. +         else
  81. +         {
  82. +            if ((update_flag = coded_seconds>=last_coded_seconds && clocks>=last_update) || li != old_li)
  83. +            {
  84. +               fprintf(stderr, "\r[%c] %02d:%02d:%02d", spinner[last_spin & 3],
  85. +                  (int)(coded_seconds / 3600), (int)(coded_seconds / 60) % 60,
  86. +                  (int)(coded_seconds) % 60);
  87. +               fflush(stderr);
  88. +            }
  89.           }
  90. -         if (coded_seconds>=last_coded_seconds+1)
  91. +         if (update_flag)
  92.           {
  93.              last_spin++;
  94. -            last_coded_seconds=coded_seconds;
  95. +            last_coded_seconds = coded_seconds + 1.;
  96. +            last_update = clocks + CLOCKS_PER_SEC/3;
  97.           }
  98.        }
  99.        old_li=li;
  100. diff --git a/src/opusenc.c b/src/opusenc.c
  101. index 082ff3c..e14bbcc 100644
  102. --- a/src/opusenc.c
  103. +++ b/src/opusenc.c
  104. @@ -104,15 +104,15 @@ static void fatal(const char *format, ...)
  105.    exit(1);
  106.  }
  107.  
  108. -static void opustoolsversion(const char *opusversion)
  109. +static void opustoolsversion(const char *opusversion, const char *opeversion)
  110.  {
  111. -  printf("opusenc %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opusversion);
  112. +  printf("opusenc %s %s\n   using %s\n   using %s\n",PACKAGE_NAME,PACKAGE_VERSION,opusversion,opeversion);
  113.    printf("Copyright (C) 2008-2018 Xiph.Org Foundation\n");
  114.  }
  115.  
  116. -static void opustoolsversion_short(const char *opusversion)
  117. +static void opustoolsversion_short(const char *opusversion, const char *opeversion)
  118.  {
  119. -  opustoolsversion(opusversion);
  120. +  opustoolsversion(opusversion, opeversion);
  121.  }
  122.  
  123.  static void usage(void)
  124. @@ -401,6 +401,7 @@ int main(int argc, char **argv)
  125.    OggOpusEnc         *enc;
  126.    EncData            data;
  127.    const char         *opus_version;
  128. +  const char         *ope_version;
  129.    float              *input;
  130.    /*I/O*/
  131.    oe_enc_opt         inopt;
  132. @@ -475,6 +476,7 @@ int main(int argc, char **argv)
  133.    inopt.comments = ope_comments_create();
  134.    if (inopt.comments == NULL) fatal("Error: failed to allocate memory for comments\n");
  135.    opus_version=opus_get_version_string();
  136. +  ope_version=ope_get_version_string();
  137.    /*Vendor string should just be the encoder library,
  138.      the ENCODER comment specifies the tool used.*/
  139.    snprintf(ENCODER_string, sizeof(ENCODER_string), "opusenc from %s %s",PACKAGE_NAME,PACKAGE_VERSION);
  140. @@ -534,10 +536,10 @@ int main(int argc, char **argv)
  141.            help_picture();
  142.            exit(0);
  143.          } else if (strcmp(optname, "version")==0) {
  144. -          opustoolsversion(opus_version);
  145. +          opustoolsversion(opus_version, ope_version);
  146.            exit(0);
  147.          } else if (strcmp(optname, "version-short")==0) {
  148. -          opustoolsversion_short(opus_version);
  149. +          opustoolsversion_short(opus_version, ope_version);
  150.            exit(0);
  151.          } else if (strcmp(optname, "ignorelength")==0) {
  152.            inopt.ignorelength=1;
  153. @@ -781,7 +783,7 @@ int main(int argc, char **argv)
  154.          exit(0);
  155.          break;
  156.        case 'V':
  157. -        opustoolsversion(opus_version);
  158. +        opustoolsversion(opus_version, ope_version);
  159.          exit(0);
  160.          break;
  161.        case '?':
  162. @@ -987,7 +989,7 @@ int main(int argc, char **argv)
  163.  
  164.    if (!quiet) {
  165.      int opus_app;
  166. -    fprintf(stderr,"Encoding using %s",opus_version);
  167. +    fprintf(stderr,"Encoding using %s (%s)",opus_version, ope_version);
  168.      ret = ope_encoder_ctl(enc, OPUS_GET_APPLICATION(&opus_app));
  169.      if (ret != OPE_OK) fprintf(stderr, "\n");
  170.      else if (opus_app==OPUS_APPLICATION_VOIP) fprintf(stderr," (VoIP)\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement