Image transcoding: Add support for heic/heif image formats

PiperOrigin-RevId: 530578549
This commit is contained in:
tofunmi 2023-05-09 12:13:24 +00:00 committed by Tofunmi Adigun-Hameed
parent 99dac0be0f
commit 477994461d
2 changed files with 17 additions and 2 deletions

View File

@ -16,6 +16,7 @@
package androidx.media3.effect; package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import static java.lang.Math.round; import static java.lang.Math.round;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -27,6 +28,7 @@ import androidx.media3.common.GlTextureInfo;
import androidx.media3.common.VideoFrameProcessingException; import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -39,6 +41,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
*/ */
@UnstableApi @UnstableApi
/* package */ final class BitmapTextureManager implements TextureManager { /* package */ final class BitmapTextureManager implements TextureManager {
private static final String UNSUPPORTED_IMAGE_CONFIGURATION =
"Unsupported Image Configuration: No more than 8 bits of precision should be used for each"
+ " RGB channel.";
private final GlShaderProgram shaderProgram; private final GlShaderProgram shaderProgram;
private final VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor; private final VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor;
// The queue holds all bitmaps with one or more frames pending to be sent downstream. // The queue holds all bitmaps with one or more frames pending to be sent downstream.
@ -125,6 +130,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private void setupBitmap( private void setupBitmap(
Bitmap bitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) Bitmap bitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
if (Util.SDK_INT >= 26) {
checkState(
!bitmap.getConfig().equals(Bitmap.Config.RGBA_F16), UNSUPPORTED_IMAGE_CONFIGURATION);
}
if (Util.SDK_INT >= 33) {
checkState(
!bitmap.getConfig().equals(Bitmap.Config.RGBA_1010102), UNSUPPORTED_IMAGE_CONFIGURATION);
}
this.useHdr = useHdr; this.useHdr = useHdr;
int framesToAdd = round(frameRate * (durationUs / (float) C.MICROS_PER_SECOND)); int framesToAdd = round(frameRate * (durationUs / (float) C.MICROS_PER_SECOND));
double frameDurationUs = C.MICROS_PER_SECOND / frameRate; double frameDurationUs = C.MICROS_PER_SECOND / frameRate;

View File

@ -26,6 +26,7 @@ import androidx.media3.common.util.Clock;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.source.MediaSource; import androidx.media3.exoplayer.source.MediaSource;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** The default {@link AssetLoader.Factory} implementation. */ /** The default {@link AssetLoader.Factory} implementation. */
@ -114,13 +115,14 @@ public final class DefaultAssetLoaderFactory implements AssetLoader.Factory {
if (localConfiguration == null) { if (localConfiguration == null) {
return false; return false;
} }
ImmutableList<String> supportedImageTypes = ImmutableList.of(".png", ".webp", ".jpg", ".jpeg"); ImmutableList<String> supportedImageTypes =
ImmutableList.of(".png", ".webp", ".jpg", ".jpeg", ".heic", ".heif");
String uriPath = checkNotNull(localConfiguration.uri.getPath()); String uriPath = checkNotNull(localConfiguration.uri.getPath());
int fileExtensionStart = uriPath.lastIndexOf("."); int fileExtensionStart = uriPath.lastIndexOf(".");
if (fileExtensionStart < 0) { if (fileExtensionStart < 0) {
return false; return false;
} }
String extension = uriPath.substring(fileExtensionStart); String extension = uriPath.substring(fileExtensionStart).toLowerCase(Locale.ENGLISH);
return supportedImageTypes.contains(extension); return supportedImageTypes.contains(extension);
} }
} }