Use InAppMuxer in tests for API < 25

MediaMuxer doesn't support B-frame before API 25.

The fix is added only in those test which appeared in triage failure.
It can be added to other tests as they are discovered.

PiperOrigin-RevId: 670480966
This commit is contained in:
sheenachhabra 2024-09-03 03:15:01 -07:00 committed by Copybara-Service
parent ebb550a9f1
commit 95f69b649d
3 changed files with 14 additions and 1 deletions

View File

@ -57,6 +57,7 @@ import androidx.media3.effect.GlShaderProgram;
import androidx.media3.effect.PassthroughShaderProgram;
import androidx.media3.effect.ScaleAndRotateTransformation;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
import androidx.media3.muxer.Muxer;
import androidx.media3.test.utils.BitmapPixelTestUtil;
import androidx.media3.test.utils.VideoDecodingWrapper;
import com.google.common.base.Ascii;
@ -1200,6 +1201,12 @@ public final class AndroidTestUtil {
throw new AssumptionViolatedException(skipReason);
}
/** Returns a {@link Muxer.Factory} depending upon the API level. */
public static Muxer.Factory getMuxerFactoryBasedOnApi() {
// MediaMuxer supports B-frame from API > 24.
return SDK_INT > 24 ? new DefaultMuxer.Factory() : new InAppMuxer.Factory.Builder().build();
}
private static boolean canDecode(Format format) {
if (MimeTypes.isImage(format.sampleMimeType)) {
return Util.isBitmapFactorySupportedMimeType(format.sampleMimeType);

View File

@ -21,6 +21,7 @@ import static androidx.media3.transformer.AndroidTestUtil.JPG_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported;
import static androidx.media3.transformer.AndroidTestUtil.getMuxerFactoryBasedOnApi;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
@ -120,6 +121,7 @@ public final class ParameterizedItemExportAndroidTest {
assumeFormatsSupported(context, testId, itemConfig.format, itemConfig.outputFormat);
Transformer transformer =
new Transformer.Builder(context)
.setMuxerFactory(getMuxerFactoryBasedOnApi())
.setEncoderFactory(
new DefaultEncoderFactory.Builder(context).setEnableFallback(false).build())
.build();

View File

@ -33,6 +33,7 @@ import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported
import static androidx.media3.transformer.AndroidTestUtil.createFrameCountingEffect;
import static androidx.media3.transformer.AndroidTestUtil.createOpenGlObjects;
import static androidx.media3.transformer.AndroidTestUtil.generateTextureFromBitmap;
import static androidx.media3.transformer.AndroidTestUtil.getMuxerFactoryBasedOnApi;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_NA;
import static androidx.media3.transformer.ExportResult.CONVERSION_PROCESS_TRANSCODED;
@ -679,7 +680,10 @@ public class TransformerEndToEndTest {
/* outputFormat= */ MP4_ASSET_PHOTOS_TRIM_OPTIMIZATION_VIDEO.videoFormat);
Transformer transformer =
new Transformer.Builder(context).experimentalSetTrimOptimizationEnabled(true).build();
new Transformer.Builder(context)
.experimentalSetTrimOptimizationEnabled(true)
.setMuxerFactory(getMuxerFactoryBasedOnApi())
.build();
// The previous sample is at 1137 and the next sample (which is a sync sample) is at 1171.
long clippingStartMs = 1138;