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 (cherry picked from commit b4d7f066dd31cce1e3d7ab14cc47d3b7be364a88)
This commit is contained in:
parent
7cc3f119b1
commit
1c6cea80eb
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 com.google.android.exoplayer2.transformer;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** A default {@link Muxer} implementation. */
|
||||
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);
|
||||
}
|
||||
}
|
@ -124,7 +124,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) -> {});
|
||||
@ -422,7 +422,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…
x
Reference in New Issue
Block a user