mirror of
https://github.com/androidx/media.git
synced 2025-05-15 19:49:50 +08:00
Add parameterized tests for generating silence.
Covers all permutations&combinations of: * AV asset. * AV asset with effects. * AV asset with silence. * AV asset with silence and effects. Note that the video is not relevant (therefore transmuxed), but is needed for silence generation. PiperOrigin-RevId: 558734593
This commit is contained in:
parent
e0d3cad8bb
commit
352916b182
@ -34,6 +34,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@ -48,26 +49,73 @@ import org.robolectric.ParameterizedRobolectricTestRunner.Parameters;
|
|||||||
@RunWith(ParameterizedRobolectricTestRunner.class)
|
@RunWith(ParameterizedRobolectricTestRunner.class)
|
||||||
public final class ParameterizedAudioExportTest {
|
public final class ParameterizedAudioExportTest {
|
||||||
public static final String AUDIO_44100_MONO = ASSET_URI_PREFIX + FILE_AUDIO_RAW;
|
public static final String AUDIO_44100_MONO = ASSET_URI_PREFIX + FILE_AUDIO_RAW;
|
||||||
public static final String AUDIO_48000_STEREO = ASSET_URI_PREFIX + FILE_AUDIO_RAW_VIDEO;
|
public static final String AUDIO_48000_STEREO_VIDEO = ASSET_URI_PREFIX + FILE_AUDIO_RAW_VIDEO;
|
||||||
public static final ImmutableSet<ItemConfig> EDITED_MEDIA_ITEMS =
|
|
||||||
ImmutableSet.of(
|
|
||||||
new ItemConfig(AUDIO_44100_MONO, /* withEffects= */ false),
|
|
||||||
new ItemConfig(AUDIO_44100_MONO, /* withEffects= */ true),
|
|
||||||
new ItemConfig(AUDIO_48000_STEREO, /* withEffects= */ false),
|
|
||||||
new ItemConfig(AUDIO_48000_STEREO, /* withEffects= */ true));
|
|
||||||
|
|
||||||
@Parameters(name = "{0}")
|
@Parameters(name = "{0}")
|
||||||
public static List<SequenceConfig> params() {
|
public static List<SequenceConfig> params() {
|
||||||
// All permutations of all combinations.
|
return new ImmutableList.Builder<SequenceConfig>()
|
||||||
return Sets.powerSet(EDITED_MEDIA_ITEMS).stream()
|
.addAll(getAllPermutationsOfAllCombinations(AUDIO_ITEMS))
|
||||||
|
.addAll(getAllPermutationsOfAllCombinations(AUDIO_VIDEO_ITEMS))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<SequenceConfig> getAllPermutationsOfAllCombinations(Set<ItemConfig> items) {
|
||||||
|
return Sets.powerSet(items).stream()
|
||||||
.filter(s -> !s.isEmpty())
|
.filter(s -> !s.isEmpty())
|
||||||
.flatMap(s -> Collections2.permutations(s).stream())
|
.flatMap(s -> Collections2.permutations(s).stream())
|
||||||
.map(SequenceConfig::new)
|
.map(SequenceConfig::new)
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final ImmutableSet<ItemConfig> AUDIO_ITEMS =
|
||||||
|
ImmutableSet.of(
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_44100_MONO,
|
||||||
|
/* audioEffects= */ false,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ true),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_44100_MONO,
|
||||||
|
/* audioEffects= */ true,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ true),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ false,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ true),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ true,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ true));
|
||||||
|
|
||||||
|
private static final ImmutableSet<ItemConfig> AUDIO_VIDEO_ITEMS =
|
||||||
|
ImmutableSet.of(
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ false,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ false),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ true,
|
||||||
|
/* withSilentAudio= */ false,
|
||||||
|
/* removeVideo= */ false),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ false,
|
||||||
|
/* withSilentAudio= */ true,
|
||||||
|
/* removeVideo= */ false),
|
||||||
|
new ItemConfig(
|
||||||
|
AUDIO_48000_STEREO_VIDEO,
|
||||||
|
/* audioEffects= */ true,
|
||||||
|
/* withSilentAudio= */ true,
|
||||||
|
/* removeVideo= */ false));
|
||||||
|
|
||||||
@Rule public final TemporaryFolder outputDir = new TemporaryFolder();
|
@Rule public final TemporaryFolder outputDir = new TemporaryFolder();
|
||||||
@Parameter public SequenceConfig sequence;
|
@Parameter public SequenceConfig sequence;
|
||||||
|
|
||||||
private final CapturingMuxer.Factory muxerFactory = new CapturingMuxer.Factory();
|
private final CapturingMuxer.Factory muxerFactory = new CapturingMuxer.Factory();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -105,7 +153,10 @@ public final class ParameterizedAudioExportTest {
|
|||||||
items.add(itemConfig.asItem());
|
items.add(itemConfig.asItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Composition.Builder(new EditedMediaItemSequence(items.build())).build();
|
return new Composition.Builder(new EditedMediaItemSequence(items.build()))
|
||||||
|
.setTransmuxVideo(true)
|
||||||
|
.experimentalSetForceAudioTrack(true)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
@ -126,17 +177,24 @@ public final class ParameterizedAudioExportTest {
|
|||||||
|
|
||||||
private static class ItemConfig {
|
private static class ItemConfig {
|
||||||
private final String uri;
|
private final String uri;
|
||||||
private final boolean withEffects;
|
private final boolean audioEffects;
|
||||||
|
private final boolean withSilentAudio;
|
||||||
|
private final boolean removeVideo;
|
||||||
|
|
||||||
public ItemConfig(String uri, boolean withEffects) {
|
public ItemConfig(
|
||||||
|
String uri, boolean audioEffects, boolean withSilentAudio, boolean removeVideo) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.withEffects = withEffects;
|
this.audioEffects = audioEffects;
|
||||||
|
this.withSilentAudio = withSilentAudio;
|
||||||
|
this.removeVideo = removeVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditedMediaItem asItem() {
|
public EditedMediaItem asItem() {
|
||||||
EditedMediaItem.Builder editedMediaItem =
|
EditedMediaItem.Builder editedMediaItem =
|
||||||
new EditedMediaItem.Builder(MediaItem.fromUri(uri)).setRemoveVideo(true);
|
new EditedMediaItem.Builder(MediaItem.fromUri(uri))
|
||||||
if (withEffects) {
|
.setRemoveAudio(withSilentAudio)
|
||||||
|
.setRemoveVideo(removeVideo);
|
||||||
|
if (audioEffects) {
|
||||||
editedMediaItem.setEffects(
|
editedMediaItem.setEffects(
|
||||||
new Effects(
|
new Effects(
|
||||||
ImmutableList.of(createPitchChangingAudioProcessor(0.6f)), ImmutableList.of()));
|
ImmutableList.of(createPitchChangingAudioProcessor(0.6f)), ImmutableList.of()));
|
||||||
@ -147,14 +205,20 @@ public final class ParameterizedAudioExportTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String itemName = uri;
|
String itemName = "audio(";
|
||||||
if (uri.equals(AUDIO_44100_MONO)) {
|
if (withSilentAudio) {
|
||||||
itemName = "mono_44.1kHz";
|
itemName += "silence";
|
||||||
} else if (uri.equals(AUDIO_48000_STEREO)) {
|
} else if (uri.equals(AUDIO_44100_MONO)) {
|
||||||
itemName = "stereo_48kHz";
|
itemName += "mono_44.1kHz";
|
||||||
|
} else if (uri.equals(AUDIO_48000_STEREO_VIDEO)) {
|
||||||
|
itemName += "stereo_48kHz";
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
itemName += audioEffects ? "+effects" : "";
|
||||||
|
itemName += !removeVideo ? ")_video(transmux)" : ")";
|
||||||
|
|
||||||
return itemName + (withEffects ? "_effects" : "");
|
return itemName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user