Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- src/opusdec.c | 43 +++++++++++++++++++++++++++++++++----------
- src/opusenc.c | 18 ++++++++++--------
- 2 files changed, 43 insertions(+), 18 deletions(-)
- diff --git a/src/opusdec.c b/src/opusdec.c
- index 9f8ad2c..397b134 100644
- --- a/src/opusdec.c
- +++ b/src/opusdec.c
- @@ -41,6 +41,7 @@
- #include <limits.h>
- #include <string.h>
- #include <ctype.h> /*tolower()*/
- +#include <time.h>
- #include <opus.h>
- #include <opusfile.h>
- @@ -473,7 +474,7 @@ void usage(void)
- void version(void)
- {
- - printf("opusdec %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opus_get_version_string());
- + printf("opusdec %s %s\n using %s\n",PACKAGE_NAME,PACKAGE_VERSION,opus_get_version_string());
- printf("Copyright (C) 2008-2018 Xiph.Org Foundation\n");
- }
- @@ -680,8 +681,11 @@ int main(int argc, char **argv)
- int quiet = 0;
- int forcewav = 0;
- ogg_int64_t nb_read_total=0;
- + ogg_int64_t nb_total_length=0;
- ogg_int64_t link_read=0;
- ogg_int64_t link_out=0;
- + clock_t last_update=0;
- + double last_progress=0.0;
- struct option long_options[] =
- {
- {"help", no_argument, NULL, 0},
- @@ -699,7 +703,7 @@ int main(int argc, char **argv)
- {0, 0, 0, 0}
- };
- opus_int64 audio_size=0;
- - double last_coded_seconds=0;
- + double last_coded_seconds=0.0;
- float loss_percent=-1;
- float manual_gain=0;
- int force_rate=0;
- @@ -873,6 +877,7 @@ int main(int argc, char **argv)
- /*If we have a seekable file, we can make some intelligent decisions
- about how to decode.*/
- nlinks = op_link_count(st);
- + nb_total_length = op_pcm_total(st, -1);
- if (rate==0)
- {
- opus_uint32 initial_rate;
- @@ -1111,18 +1116,36 @@ int main(int argc, char **argv)
- {
- /*Display a progress spinner while decoding.*/
- static const char spinner[]="|/-\\";
- - double coded_seconds=nb_read_total/(double)rate;
- - if (coded_seconds>=last_coded_seconds+1 || li!=old_li)
- + int update_flag = 0;
- + const double coded_seconds=nb_read_total/(double)rate;
- + const clock_t clocks = clock();
- + if(nb_total_length > 0)
- {
- - fprintf(stderr,"\r[%c] %02d:%02d:%02d", spinner[last_spin&3],
- - (int)(coded_seconds/3600), (int)(coded_seconds/60)%60,
- - (int)(coded_seconds)%60);
- - fflush(stderr);
- + const double progress = (nb_read_total/(double)nb_total_length) * 100.0;
- + if ((update_flag = coded_seconds>=last_coded_seconds && clocks>=last_update && progress>=last_progress) || li != old_li)
- + {
- + fprintf(stderr, "\r[%c] %02d:%02d:%02d (%.1f%%)", spinner[last_spin & 3],
- + (int)(coded_seconds / 3600), (int)(coded_seconds / 60) % 60,
- + (int)(coded_seconds) % 60, progress);
- + fflush(stderr);
- + last_progress = progress + 1.0/3.0;
- + }
- + }
- + else
- + {
- + if ((update_flag = coded_seconds>=last_coded_seconds && clocks>=last_update) || li != old_li)
- + {
- + fprintf(stderr, "\r[%c] %02d:%02d:%02d", spinner[last_spin & 3],
- + (int)(coded_seconds / 3600), (int)(coded_seconds / 60) % 60,
- + (int)(coded_seconds) % 60);
- + fflush(stderr);
- + }
- }
- - if (coded_seconds>=last_coded_seconds+1)
- + if (update_flag)
- {
- last_spin++;
- - last_coded_seconds=coded_seconds;
- + last_coded_seconds = coded_seconds + 1.;
- + last_update = clocks + CLOCKS_PER_SEC/3;
- }
- }
- old_li=li;
- diff --git a/src/opusenc.c b/src/opusenc.c
- index 082ff3c..e14bbcc 100644
- --- a/src/opusenc.c
- +++ b/src/opusenc.c
- @@ -104,15 +104,15 @@ static void fatal(const char *format, ...)
- exit(1);
- }
- -static void opustoolsversion(const char *opusversion)
- +static void opustoolsversion(const char *opusversion, const char *opeversion)
- {
- - printf("opusenc %s %s (using %s)\n",PACKAGE_NAME,PACKAGE_VERSION,opusversion);
- + printf("opusenc %s %s\n using %s\n using %s\n",PACKAGE_NAME,PACKAGE_VERSION,opusversion,opeversion);
- printf("Copyright (C) 2008-2018 Xiph.Org Foundation\n");
- }
- -static void opustoolsversion_short(const char *opusversion)
- +static void opustoolsversion_short(const char *opusversion, const char *opeversion)
- {
- - opustoolsversion(opusversion);
- + opustoolsversion(opusversion, opeversion);
- }
- static void usage(void)
- @@ -401,6 +401,7 @@ int main(int argc, char **argv)
- OggOpusEnc *enc;
- EncData data;
- const char *opus_version;
- + const char *ope_version;
- float *input;
- /*I/O*/
- oe_enc_opt inopt;
- @@ -475,6 +476,7 @@ int main(int argc, char **argv)
- inopt.comments = ope_comments_create();
- if (inopt.comments == NULL) fatal("Error: failed to allocate memory for comments\n");
- opus_version=opus_get_version_string();
- + ope_version=ope_get_version_string();
- /*Vendor string should just be the encoder library,
- the ENCODER comment specifies the tool used.*/
- snprintf(ENCODER_string, sizeof(ENCODER_string), "opusenc from %s %s",PACKAGE_NAME,PACKAGE_VERSION);
- @@ -534,10 +536,10 @@ int main(int argc, char **argv)
- help_picture();
- exit(0);
- } else if (strcmp(optname, "version")==0) {
- - opustoolsversion(opus_version);
- + opustoolsversion(opus_version, ope_version);
- exit(0);
- } else if (strcmp(optname, "version-short")==0) {
- - opustoolsversion_short(opus_version);
- + opustoolsversion_short(opus_version, ope_version);
- exit(0);
- } else if (strcmp(optname, "ignorelength")==0) {
- inopt.ignorelength=1;
- @@ -781,7 +783,7 @@ int main(int argc, char **argv)
- exit(0);
- break;
- case 'V':
- - opustoolsversion(opus_version);
- + opustoolsversion(opus_version, ope_version);
- exit(0);
- break;
- case '?':
- @@ -987,7 +989,7 @@ int main(int argc, char **argv)
- if (!quiet) {
- int opus_app;
- - fprintf(stderr,"Encoding using %s",opus_version);
- + fprintf(stderr,"Encoding using %s (%s)",opus_version, ope_version);
- ret = ope_encoder_ctl(enc, OPUS_GET_APPLICATION(&opus_app));
- if (ret != OPE_OK) fprintf(stderr, "\n");
- else if (opus_app==OPUS_APPLICATION_VOIP) fprintf(stderr," (VoIP)\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement