Instantly share code, notes, and snippets.

Embed
What would you like to do?
Opus-Tools patch to enable progress output in "opusdec" tool
diff --git a/src/opusdec.c b/src/opusdec.c
index 1dffbbc..3481c6c 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>
@@ -684,8 +685,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},
@@ -703,7 +707,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;
@@ -889,6 +893,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;
@@ -1100,18 +1105,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 6dd44ef..cc84ab5 100644
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -114,15 +114,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\nusing %s (%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)
@@ -360,6 +360,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;
@@ -435,6 +436,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);
@@ -481,10 +483,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;
@@ -721,7 +723,7 @@ int main(int argc, char **argv)
exit(0);
break;
case 'V':
- opustoolsversion(opus_version);
+ opustoolsversion(opus_version, ope_version);
exit(0);
break;
case '?':
@@ -908,7 +910,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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment