Skip to content

Commit

Permalink
Add DefaultMuxer forwarding to FrameworkMuxer
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
kim-vde authored and marcbaechinger committed Oct 20, 2022
1 parent 325e973 commit b4d7f06
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static final class Builder {
*/
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) -> {});
Expand Down Expand Up @@ -422,7 +422,7 @@ public Builder setDebugViewProvider(DebugViewProvider debugViewProvider) {
/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,24 +856,23 @@ private static String getDumpFileName(String originalFileName) {

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;
}

@Override
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;
}

Expand All @@ -885,7 +884,7 @@ public boolean supportsOutputMimeType(String mimeType) {
@Override
public ImmutableList<String> getSupportedSampleMimeTypes(
@C.TrackType int trackType, String containerMimeType) {
return frameworkMuxerFactory.getSupportedSampleMimeTypes(trackType, containerMimeType);
return defaultMuxerFactory.getSupportedSampleMimeTypes(trackType, containerMimeType);
}
}
}

0 comments on commit b4d7f06

Please sign in to comment.