Skip to content

Fix the usage of the MutedAudioDataSource in the TranscoderOptions bu… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ public static class Builder {
@NonNull
@SuppressWarnings("WeakerAccess")
public Builder addDataSource(@NonNull DataSource dataSource) {
if (dataSource.getTrackFormat(TrackType.AUDIO) == null && dataSource.getTrackFormat(TrackType.VIDEO) != null) {
audioDataSources.add(new MutedAudioDataSource(dataSource.getDurationUs()));
} else {
audioDataSources.add(dataSource);
}
audioDataSources.add(dataSource);
videoDataSources.add(dataSource);
return this;
}
Expand Down Expand Up @@ -322,6 +318,43 @@ public Builder setAudioResampler(@NonNull AudioResampler audioResampler) {
return this;
}

/**
* Generates muted audio data sources if needed
* @return The list of audio data sources including the muted sources
*/
private List<DataSource> buildAudioDataSources()
{
// Check if we have a mix of empty and non-empty data sources
// This would cause an error in Engine::computeTrackStatus
boolean hasMissingAudioDataSources = false;
boolean hasAudioDataSources = false;
boolean hasValidAudioDataSources = true;
for (DataSource dataSource : audioDataSources) {
if (dataSource.getTrackFormat(TrackType.AUDIO) == null) {
hasMissingAudioDataSources = true;
} else {
hasAudioDataSources = true;
}
if (hasAudioDataSources && hasMissingAudioDataSources) {
hasValidAudioDataSources = false;
break;
}
}
if (hasValidAudioDataSources) {
return audioDataSources;
}
// Fix the audioDataSources by replacing the empty data source by muted data source
List<DataSource> result = new ArrayList<>();
for (DataSource dataSource : audioDataSources) {
if (dataSource.getTrackFormat(TrackType.AUDIO) != null) {
result.add(dataSource);
} else {
result.add(new MutedAudioDataSource(dataSource.getDurationUs()));
}
}
return result;
}

@NonNull
public TranscoderOptions build() {
if (listener == null) {
Expand Down Expand Up @@ -358,7 +391,7 @@ public TranscoderOptions build() {
}
TranscoderOptions options = new TranscoderOptions();
options.listener = listener;
options.audioDataSources = audioDataSources;
options.audioDataSources = buildAudioDataSources();
options.videoDataSources = videoDataSources;
options.dataSink = dataSink;
options.listenerHandler = listenerHandler;
Expand Down