mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Add DefaultMuxer forwarding to FrameworkMuxer
- The naming DefaultMuxer is more consistent with the rest of Transformer codebase (e.g. DefaultEncoderFactory). - By hiding the implementation details of DefaultMuxer, the transition to in-app Muxer will be seamless for apps using DefaultMuxer. - The current plan is that DefaultMuxer will become the in-app muxer. PiperOrigin-RevId: 481838790
This commit is contained in:
parent
2625061ec0
commit
3399f4ecdf
3 changed files with 90 additions and 8 deletions
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2022 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 androidx.media3.transformer;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.Format;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** A default {@link Muxer} implementation. */
|
||||
@UnstableApi
|
||||
public final class DefaultMuxer implements Muxer {
|
||||
|
||||
/** A {@link Muxer.Factory} for {@link DefaultMuxer}. */
|
||||
public static final class Factory implements Muxer.Factory {
|
||||
private final Muxer.Factory muxerFactory;
|
||||
|
||||
public Factory() {
|
||||
this.muxerFactory = new FrameworkMuxer.Factory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Muxer create(String path, String outputMimeType) throws IOException {
|
||||
return new DefaultMuxer(muxerFactory.create(path, outputMimeType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Muxer create(ParcelFileDescriptor parcelFileDescriptor, String outputMimeType)
|
||||
throws IOException {
|
||||
return new DefaultMuxer(muxerFactory.create(parcelFileDescriptor, outputMimeType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsOutputMimeType(String mimeType) {
|
||||
return muxerFactory.supportsOutputMimeType(mimeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<String> getSupportedSampleMimeTypes(
|
||||
@C.TrackType int trackType, String containerMimeType) {
|
||||
return muxerFactory.getSupportedSampleMimeTypes(trackType, containerMimeType);
|
||||
}
|
||||
}
|
||||
|
||||
private final Muxer muxer;
|
||||
|
||||
private DefaultMuxer(Muxer muxer) {
|
||||
this.muxer = muxer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addTrack(Format format) throws MuxerException {
|
||||
return muxer.addTrack(format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSampleData(
|
||||
int trackIndex, ByteBuffer data, boolean isKeyFrame, long presentationTimeUs)
|
||||
throws MuxerException {
|
||||
muxer.writeSampleData(trackIndex, data, isKeyFrame, presentationTimeUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(boolean forCancellation) throws MuxerException {
|
||||
muxer.release(forCancellation);
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ public final class Transformer {
|
|||
*/
|
||||
public Builder(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
muxerFactory = new FrameworkMuxer.Factory();
|
||||
muxerFactory = new DefaultMuxer.Factory();
|
||||
looper = Util.getCurrentOrMainLooper();
|
||||
clock = Clock.DEFAULT;
|
||||
listeners = new ListenerSet<>(looper, clock, (listener, flags) -> {});
|
||||
|
|
@ -424,7 +424,7 @@ public final class Transformer {
|
|||
/**
|
||||
* Sets the factory for muxers that write the media container.
|
||||
*
|
||||
* <p>The default value is a {@link FrameworkMuxer.Factory}.
|
||||
* <p>The default value is a {@link DefaultMuxer.Factory}.
|
||||
*
|
||||
* @param muxerFactory A {@link Muxer.Factory}.
|
||||
* @return This builder.
|
||||
|
|
|
|||
|
|
@ -856,15 +856,15 @@ public final class TransformerEndToEndTest {
|
|||
|
||||
private final class TestMuxerFactory implements Muxer.Factory {
|
||||
|
||||
private final Muxer.Factory frameworkMuxerFactory;
|
||||
private final Muxer.Factory defaultMuxerFactory;
|
||||
|
||||
public TestMuxerFactory() {
|
||||
frameworkMuxerFactory = new FrameworkMuxer.Factory();
|
||||
defaultMuxerFactory = new DefaultMuxer.Factory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Muxer create(String path, String outputMimeType) throws IOException {
|
||||
testMuxer = new TestMuxer(path, outputMimeType, frameworkMuxerFactory);
|
||||
testMuxer = new TestMuxer(path, outputMimeType, defaultMuxerFactory);
|
||||
return testMuxer;
|
||||
}
|
||||
|
||||
|
|
@ -872,8 +872,7 @@ public final class TransformerEndToEndTest {
|
|||
public Muxer create(ParcelFileDescriptor parcelFileDescriptor, String outputMimeType)
|
||||
throws IOException {
|
||||
testMuxer =
|
||||
new TestMuxer(
|
||||
"FD:" + parcelFileDescriptor.getFd(), outputMimeType, frameworkMuxerFactory);
|
||||
new TestMuxer("FD:" + parcelFileDescriptor.getFd(), outputMimeType, defaultMuxerFactory);
|
||||
return testMuxer;
|
||||
}
|
||||
|
||||
|
|
@ -885,7 +884,7 @@ public final class TransformerEndToEndTest {
|
|||
@Override
|
||||
public ImmutableList<String> getSupportedSampleMimeTypes(
|
||||
@C.TrackType int trackType, String containerMimeType) {
|
||||
return frameworkMuxerFactory.getSupportedSampleMimeTypes(trackType, containerMimeType);
|
||||
return defaultMuxerFactory.getSupportedSampleMimeTypes(trackType, containerMimeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue