Make minor improvements for IAMF decoder module

- Create `LibiamfAudioRenderer` with `DefaultRenderersFactory` in `ExoPlayerModuleProguard`.
- Remove redundant library availability check from `IamfModuleProguard`.
- Move `proguard-rules.txt` to the root folder.
- Removed unused `cryptoType` parameter from `setLibraries()` method in `IamfLibrary`.
- Added log when `LibiamfAudioRenderer` is loaded in `DefaultRenderersFactory`.
- Annotated missing classes with `@UnstableApi`.
- Check for library availability and throw exception in `IamfDecoder` constructor.

#cherrypick

PiperOrigin-RevId: 689330016
This commit is contained in:
rohks 2024-10-24 04:42:48 -07:00 committed by Copybara-Service
parent 4a406be1bf
commit 5f99955f31
6 changed files with 11 additions and 6 deletions

View File

@ -56,6 +56,9 @@ public final class IamfDecoder
public IamfDecoder(List<byte[]> initializationData, boolean spatializationSupported) public IamfDecoder(List<byte[]> initializationData, boolean spatializationSupported)
throws IamfDecoderException { throws IamfDecoderException {
super(new DecoderInputBuffer[1], new SimpleDecoderOutputBuffer[1]); super(new DecoderInputBuffer[1], new SimpleDecoderOutputBuffer[1]);
if (!IamfLibrary.isAvailable()) {
throw new IamfDecoderException("Failed to load decoder native libraries.");
}
if (initializationData.size() != 1) { if (initializationData.size() != 1) {
throw new IamfDecoderException("Initialization data must contain a single element."); throw new IamfDecoderException("Initialization data must contain a single element.");
} }

View File

@ -15,10 +15,12 @@
*/ */
package androidx.media3.decoder.iamf; package androidx.media3.decoder.iamf;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.decoder.DecoderException; import androidx.media3.decoder.DecoderException;
/** Thrown when an IAMF decoder error occurs. */ /** Thrown when an IAMF decoder error occurs. */
final class IamfDecoderException extends DecoderException { @UnstableApi
public final class IamfDecoderException extends DecoderException {
/* package */ IamfDecoderException(String message) { /* package */ IamfDecoderException(String message) {
super(message); super(message);

View File

@ -15,7 +15,6 @@
*/ */
package androidx.media3.decoder.iamf; package androidx.media3.decoder.iamf;
import androidx.media3.common.C;
import androidx.media3.common.MediaLibraryInfo; import androidx.media3.common.MediaLibraryInfo;
import androidx.media3.common.util.LibraryLoader; import androidx.media3.common.util.LibraryLoader;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
@ -43,12 +42,9 @@ public final class IamfLibrary {
* it must do so before calling any other method defined by this class, and before instantiating a * it must do so before calling any other method defined by this class, and before instantiating a
* {@link LibiamfAudioRenderer} instance. * {@link LibiamfAudioRenderer} instance.
* *
* @param cryptoType The {@link C.CryptoType} for which the decoder library supports decrypting
* protected content, or {@link C#CRYPTO_TYPE_UNSUPPORTED} if the library does not support
* decryption.
* @param libraries The names of the IAMF native libraries. * @param libraries The names of the IAMF native libraries.
*/ */
public static void setLibraries(@C.CryptoType int cryptoType, String... libraries) { public static void setLibraries(String... libraries) {
LOADER.setLibraries(libraries); LOADER.setLibraries(libraries);
} }

View File

@ -27,6 +27,7 @@ import androidx.media3.common.C;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.TraceUtil; import androidx.media3.common.util.TraceUtil;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.decoder.CryptoConfig; import androidx.media3.decoder.CryptoConfig;
import androidx.media3.decoder.DecoderException; import androidx.media3.decoder.DecoderException;
@ -36,6 +37,7 @@ import androidx.media3.exoplayer.audio.DecoderAudioRenderer;
import java.util.Objects; import java.util.Objects;
/** Decodes and renders audio using the native IAMF decoder. */ /** Decodes and renders audio using the native IAMF decoder. */
@UnstableApi
public class LibiamfAudioRenderer extends DecoderAudioRenderer<IamfDecoder> { public class LibiamfAudioRenderer extends DecoderAudioRenderer<IamfDecoder> {
private final Context context; private final Context context;

View File

@ -547,6 +547,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
// The extension is present, but instantiation failed. // The extension is present, but instantiation failed.
throw new IllegalStateException("Error instantiating FFmpeg extension", e); throw new IllegalStateException("Error instantiating FFmpeg extension", e);
} }
try { try {
// Full class names used for constructor args so the LINT rule triggers if any of them move. // Full class names used for constructor args so the LINT rule triggers if any of them move.
Class<?> clazz = Class.forName("androidx.media3.decoder.iamf.LibiamfAudioRenderer"); Class<?> clazz = Class.forName("androidx.media3.decoder.iamf.LibiamfAudioRenderer");
@ -559,6 +560,7 @@ public class DefaultRenderersFactory implements RenderersFactory {
Renderer renderer = Renderer renderer =
(Renderer) constructor.newInstance(context, eventHandler, eventListener, audioSink); (Renderer) constructor.newInstance(context, eventHandler, eventListener, audioSink);
out.add(extensionRendererIndex++, renderer); out.add(extensionRendererIndex++, renderer);
Log.i(TAG, "Loaded LibiamfAudioRenderer.");
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// Expected if the app was built without the extension. // Expected if the app was built without the extension.
} catch (Exception e) { } catch (Exception e) {