mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Use FlacLibrary.isAvailable in FlacExtractor selection
PiperOrigin-RevId: 288667790
This commit is contained in:
parent
bf9a61d62f
commit
7fe55cd468
3 changed files with 18 additions and 80 deletions
|
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2016 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.google.android.exoplayer2.ext.flac;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
|
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.amr.AmrExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.flv.FlvExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ogg.OggExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ts.Ac3Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ts.Ac4Extractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ts.AdtsExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ts.PsExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.ts.TsExtractor;
|
|
||||||
import com.google.android.exoplayer2.extractor.wav.WavExtractor;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
/** Unit test for {@link DefaultExtractorsFactory}. */
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public final class DefaultExtractorsFactoryTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreateExtractors_returnExpectedClasses() {
|
|
||||||
DefaultExtractorsFactory defaultExtractorsFactory = new DefaultExtractorsFactory();
|
|
||||||
|
|
||||||
Extractor[] extractors = defaultExtractorsFactory.createExtractors();
|
|
||||||
List<Class<?>> listCreatedExtractorClasses = new ArrayList<>();
|
|
||||||
for (Extractor extractor : extractors) {
|
|
||||||
listCreatedExtractorClasses.add(extractor.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?>[] expectedExtractorClassses =
|
|
||||||
new Class<?>[] {
|
|
||||||
MatroskaExtractor.class,
|
|
||||||
FragmentedMp4Extractor.class,
|
|
||||||
Mp4Extractor.class,
|
|
||||||
Mp3Extractor.class,
|
|
||||||
AdtsExtractor.class,
|
|
||||||
Ac3Extractor.class,
|
|
||||||
Ac4Extractor.class,
|
|
||||||
TsExtractor.class,
|
|
||||||
FlvExtractor.class,
|
|
||||||
OggExtractor.class,
|
|
||||||
PsExtractor.class,
|
|
||||||
WavExtractor.class,
|
|
||||||
AmrExtractor.class,
|
|
||||||
FlacExtractor.class
|
|
||||||
};
|
|
||||||
|
|
||||||
assertThat(listCreatedExtractorClasses).containsNoDuplicates();
|
|
||||||
assertThat(listCreatedExtractorClasses).containsExactlyElementsIn(expectedExtractorClassses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,6 +5,12 @@
|
||||||
public static android.net.Uri buildRawResourceUri(int);
|
public static android.net.Uri buildRawResourceUri(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Methods accessed via reflection in DefaultExtractorsFactory
|
||||||
|
-dontnote com.google.android.exoplayer2.ext.flac.FlacLibrary
|
||||||
|
-keepclassmembers class com.google.android.exoplayer2.ext.flac.FlacLibrary {
|
||||||
|
public static boolean isAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
# Some members of this class are being accessed from native methods. Keep them unobfuscated.
|
# Some members of this class are being accessed from native methods. Keep them unobfuscated.
|
||||||
-keep class com.google.android.exoplayer2.video.VideoDecoderOutputBuffer {
|
-keep class com.google.android.exoplayer2.video.VideoDecoderOutputBuffer {
|
||||||
*;
|
*;
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,18 @@ public final class DefaultExtractorsFactory implements ExtractorsFactory {
|
||||||
Constructor<? extends Extractor> flacExtensionExtractorConstructor = null;
|
Constructor<? extends Extractor> flacExtensionExtractorConstructor = null;
|
||||||
try {
|
try {
|
||||||
// LINT.IfChange
|
// LINT.IfChange
|
||||||
flacExtensionExtractorConstructor =
|
@SuppressWarnings("nullness:argument.type.incompatible")
|
||||||
Class.forName("com.google.android.exoplayer2.ext.flac.FlacExtractor")
|
boolean isFlacNativeLibraryAvailable =
|
||||||
.asSubclass(Extractor.class)
|
Boolean.TRUE.equals(
|
||||||
.getConstructor();
|
Class.forName("com.google.android.exoplayer2.ext.flac.FlacLibrary")
|
||||||
|
.getMethod("isAvailable")
|
||||||
|
.invoke(/* obj= */ null));
|
||||||
|
if (isFlacNativeLibraryAvailable) {
|
||||||
|
flacExtensionExtractorConstructor =
|
||||||
|
Class.forName("com.google.android.exoplayer2.ext.flac.FlacExtractor")
|
||||||
|
.asSubclass(Extractor.class)
|
||||||
|
.getConstructor();
|
||||||
|
}
|
||||||
// LINT.ThenChange(../../../../../../../../proguard-rules.txt)
|
// LINT.ThenChange(../../../../../../../../proguard-rules.txt)
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
// Expected if the app was built without the FLAC extension.
|
// Expected if the app was built without the FLAC extension.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue