@@ -129,11 +129,7 @@ public static class Builder {
129
129
@ NonNull
130
130
@ SuppressWarnings ("WeakerAccess" )
131
131
public Builder addDataSource (@ NonNull DataSource dataSource ) {
132
- if (dataSource .getTrackFormat (TrackType .AUDIO ) == null && dataSource .getTrackFormat (TrackType .VIDEO ) != null ) {
133
- audioDataSources .add (new MutedAudioDataSource (dataSource .getDurationUs ()));
134
- } else {
135
- audioDataSources .add (dataSource );
136
- }
132
+ audioDataSources .add (dataSource );
137
133
videoDataSources .add (dataSource );
138
134
return this ;
139
135
}
@@ -322,6 +318,43 @@ public Builder setAudioResampler(@NonNull AudioResampler audioResampler) {
322
318
return this ;
323
319
}
324
320
321
+ /**
322
+ * Generates muted audio data sources if needed
323
+ * @return The list of audio data sources including the muted sources
324
+ */
325
+ private List <DataSource > buildAudioDataSources ()
326
+ {
327
+ // Check if we have a mix of empty and non-empty data sources
328
+ // This would cause an error in Engine::computeTrackStatus
329
+ boolean hasMissingAudioDataSources = false ;
330
+ boolean hasAudioDataSources = false ;
331
+ boolean hasValidAudioDataSources = true ;
332
+ for (DataSource dataSource : audioDataSources ) {
333
+ if (dataSource .getTrackFormat (TrackType .AUDIO ) == null ) {
334
+ hasMissingAudioDataSources = true ;
335
+ } else {
336
+ hasAudioDataSources = true ;
337
+ }
338
+ if (hasAudioDataSources && hasMissingAudioDataSources ) {
339
+ hasValidAudioDataSources = false ;
340
+ break ;
341
+ }
342
+ }
343
+ if (hasValidAudioDataSources ) {
344
+ return audioDataSources ;
345
+ }
346
+ // Fix the audioDataSources by replacing the empty data source by muted data source
347
+ List <DataSource > result = new ArrayList <>();
348
+ for (DataSource dataSource : audioDataSources ) {
349
+ if (dataSource .getTrackFormat (TrackType .AUDIO ) != null ) {
350
+ result .add (dataSource );
351
+ } else {
352
+ result .add (new MutedAudioDataSource (dataSource .getDurationUs ()));
353
+ }
354
+ }
355
+ return result ;
356
+ }
357
+
325
358
@ NonNull
326
359
public TranscoderOptions build () {
327
360
if (listener == null ) {
@@ -358,7 +391,7 @@ public TranscoderOptions build() {
358
391
}
359
392
TranscoderOptions options = new TranscoderOptions ();
360
393
options .listener = listener ;
361
- options .audioDataSources = audioDataSources ;
394
+ options .audioDataSources = buildAudioDataSources () ;
362
395
options .videoDataSources = videoDataSources ;
363
396
options .dataSink = dataSink ;
364
397
options .listenerHandler = listenerHandler ;
0 commit comments