@@ -711,6 +711,7 @@ class MeasuringStream : public ModifyingStream {
711
711
712
712
// / Provides the data from all streams mixed together
713
713
size_t readBytes (uint8_t * data, size_t len) override {
714
+ total_bytes_since_begin += len;
714
715
return measure (p_stream->readBytes (data, len));
715
716
}
716
717
@@ -720,6 +721,7 @@ class MeasuringStream : public ModifyingStream {
720
721
721
722
// / Writes raw PCM audio data, which will be the input for the volume control
722
723
virtual size_t write (const uint8_t *data, size_t len) override {
724
+ total_bytes_since_begin += len;
723
725
return measure (p_print->write (data, len));
724
726
}
725
727
@@ -744,12 +746,14 @@ class MeasuringStream : public ModifyingStream {
744
746
}
745
747
746
748
bool begin (){
749
+ total_bytes_since_begin = 0 ;
750
+ ms_at_begin = millis ();
747
751
return AudioStream::begin ();
748
752
}
749
753
750
754
bool begin (AudioInfo info){
751
755
setAudioInfo (info);
752
- return true ;
756
+ return begin () ;
753
757
}
754
758
755
759
// / Trigger reporting in frames (=samples) per second
@@ -766,6 +770,28 @@ class MeasuringStream : public ModifyingStream {
766
770
this ->name = name;
767
771
}
768
772
773
+ // / Provides the time in ms since the last call of begin()
774
+ uint32_t timeSinceBegin () {
775
+ return millis () - ms_at_begin;
776
+ }
777
+
778
+ // / Provides the total processed bytes since the last call of begin()
779
+ uint32_t bytesSinceBegin () {
780
+ return total_bytes_since_begin;
781
+ }
782
+
783
+ // / Provides the estimated runtime in milliseconds for the indicated total
784
+ uint32_t estimatedTotalTimeFor (uint32_t totalBytes) {
785
+ if (bytesSinceBegin ()==0 ) return 0 ;
786
+ return timeSinceBegin () / bytesSinceBegin () * totalBytes;
787
+ }
788
+
789
+ // / Provides the estimated time from now to the end in ms
790
+ uint32_t estimatedOpenTimeFor (uint32_t totalBytes) {
791
+ if (bytesSinceBegin ()==0 ) return 0 ;
792
+ return estimatedTotalTimeFor (totalBytes) -timeSinceBegin ();
793
+ }
794
+
769
795
protected:
770
796
int max_count=0 ;
771
797
int count=0 ;
@@ -779,6 +805,8 @@ class MeasuringStream : public ModifyingStream {
779
805
Print *p_logout=nullptr ;
780
806
bool report_bytes = false ;
781
807
const char * name = " " ;
808
+ uint32_t ms_at_begin = 0 ;
809
+ uint32_t total_bytes_since_begin = 0 ;
782
810
783
811
size_t measure (size_t len) {
784
812
count--;
0 commit comments