File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -357,8 +357,12 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
357
357
// / Defines the wait time in ms if the target output is full
358
358
virtual void setDelayIfOutputFull (int delayMs) { delay_if_full = delayMs; }
359
359
360
- // / Call this method in the loop.
361
360
virtual size_t copy () {
361
+ return copy (copier.bufferSize ());
362
+ }
363
+
364
+ // / Call this method in the loop.
365
+ virtual size_t copy (size_t bytes) {
362
366
size_t result = 0 ;
363
367
if (active) {
364
368
TRACED ();
@@ -371,7 +375,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
371
375
return 0 ;
372
376
}
373
377
// handle sound
374
- result = copier.copy ( );
378
+ result = copier.copyBytes (bytes );
375
379
if (result > 0 || timeout == 0 ) {
376
380
// reset timeout if we had any data
377
381
timeout = millis () + p_source->timeoutAutoNext ();
@@ -380,9 +384,10 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
380
384
moveToNextFileOnTimeout ();
381
385
382
386
// return silence when there was no data
383
- if (result == 0 && silence_on_inactive){
384
- writeSilence (1024 );
387
+ if (result < bytes && silence_on_inactive){
388
+ writeSilence (bytes - result );
385
389
}
390
+
386
391
} else {
387
392
// e.g. A2DP should still receive data to keep the connection open
388
393
if (silence_on_inactive) {
Original file line number Diff line number Diff line change @@ -89,8 +89,13 @@ class StreamCopyT {
89
89
}
90
90
91
91
// / copies the data from the source to the destination - the result is in bytes
92
- inline size_t copy (){
93
- LOGD (" copy %s" , log_name);
92
+ inline size_t copy () {
93
+ return copyBytes (buffer_size);
94
+ }
95
+
96
+ // / copies the inicated number of bytes from the source to the destination - the result is in bytes
97
+ inline size_t copyBytes (size_t bytes){
98
+ LOGD (" copy %d bytes %s" , bytes, log_name);
94
99
if (!active) return 0 ;
95
100
// if not initialized we do nothing
96
101
if (from==nullptr && to==nullptr ) return 0 ;
@@ -105,13 +110,19 @@ class StreamCopyT {
105
110
return 0 ;
106
111
}
107
112
113
+ // resize copy buffer if necessary
114
+ if (buffer.size () < bytes){
115
+ LOGI (" Resize to %d" , bytes);
116
+ buffer.resize (bytes);
117
+ }
118
+
108
119
size_t result = 0 ;
109
120
size_t delayCount = 0 ;
110
- size_t len = buffer_size ;
121
+ size_t len = bytes ;
111
122
if (check_available) {
112
123
len = available ();
113
124
}
114
- size_t bytes_to_read = buffer_size ;
125
+ size_t bytes_to_read = bytes ;
115
126
size_t bytes_read = 0 ;
116
127
117
128
if (len > 0 ){
You can’t perform that action at this time.
0 commit comments