-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since the public class has already been split into `Mp4Muxer` and `FragmentedMp4Muxer`, there is no need for having common interface for internal implementation. In the follow up CL `BasicMp4Writer` will be renamed to `Mp4Writer` which is more appropriate and aligns with public class names. PiperOrigin-RevId: 619486876
- Loading branch information
1 parent
5a318de
commit 66547cc
Showing
4 changed files
with
123 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 0 additions & 129 deletions
129
libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Writer.java
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
libraries/muxer/src/main/java/androidx/media3/muxer/Track.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* 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.muxer; | ||
|
||
import static androidx.media3.common.util.Assertions.checkArgument; | ||
|
||
import android.media.MediaCodec; | ||
import android.media.MediaCodec.BufferInfo; | ||
import androidx.media3.common.C; | ||
import androidx.media3.common.Format; | ||
import androidx.media3.common.MimeTypes; | ||
import androidx.media3.muxer.Muxer.TrackToken; | ||
import com.google.common.collect.ImmutableList; | ||
import java.nio.ByteBuffer; | ||
import java.util.ArrayDeque; | ||
import java.util.ArrayList; | ||
import java.util.Deque; | ||
import java.util.List; | ||
|
||
/** Represents a single track (audio, video, metadata etc.). */ | ||
/* package */ final class Track implements TrackToken, Mp4MoovStructure.TrackMetadataProvider { | ||
public final Format format; | ||
public final int sortKey; | ||
public final List<BufferInfo> writtenSamples; | ||
public final List<Long> writtenChunkOffsets; | ||
public final List<Integer> writtenChunkSampleCounts; | ||
public final Deque<BufferInfo> pendingSamplesBufferInfo; | ||
public final Deque<ByteBuffer> pendingSamplesByteBuffer; | ||
public boolean hadKeyframe; | ||
|
||
private long lastSamplePresentationTimeUs; | ||
|
||
/** Creates an instance with {@code sortKey} set to 1. */ | ||
public Track(Format format) { | ||
this(format, /* sortKey= */ 1); | ||
} | ||
|
||
/** | ||
* Creates an instance. | ||
* | ||
* @param format The {@link Format} for the track. | ||
* @param sortKey The key used for sorting the track list. | ||
*/ | ||
public Track(Format format, int sortKey) { | ||
this.format = format; | ||
this.sortKey = sortKey; | ||
writtenSamples = new ArrayList<>(); | ||
writtenChunkOffsets = new ArrayList<>(); | ||
writtenChunkSampleCounts = new ArrayList<>(); | ||
pendingSamplesBufferInfo = new ArrayDeque<>(); | ||
pendingSamplesByteBuffer = new ArrayDeque<>(); | ||
lastSamplePresentationTimeUs = C.TIME_UNSET; | ||
} | ||
|
||
public void writeSampleData(ByteBuffer byteBuffer, BufferInfo bufferInfo) { | ||
checkArgument( | ||
bufferInfo.presentationTimeUs > lastSamplePresentationTimeUs, | ||
"Out of order B-frames are not supported"); | ||
// TODO: b/279931840 - Confirm whether muxer should throw when writing empty samples. | ||
// Skip empty samples. | ||
if (bufferInfo.size == 0 || byteBuffer.remaining() == 0) { | ||
return; | ||
} | ||
|
||
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) > 0) { | ||
hadKeyframe = true; | ||
} | ||
|
||
// The video track must start with a key frame. | ||
if (!hadKeyframe && MimeTypes.isVideo(format.sampleMimeType)) { | ||
return; | ||
} | ||
|
||
pendingSamplesBufferInfo.addLast(bufferInfo); | ||
pendingSamplesByteBuffer.addLast(byteBuffer); | ||
lastSamplePresentationTimeUs = bufferInfo.presentationTimeUs; | ||
} | ||
|
||
@Override | ||
public int videoUnitTimebase() { | ||
return MimeTypes.isAudio(format.sampleMimeType) | ||
? 48_000 // TODO: b/270583563 - Update these with actual values from mediaFormat. | ||
: 90_000; | ||
} | ||
|
||
@Override | ||
public ImmutableList<BufferInfo> writtenSamples() { | ||
return ImmutableList.copyOf(writtenSamples); | ||
} | ||
|
||
@Override | ||
public ImmutableList<Long> writtenChunkOffsets() { | ||
return ImmutableList.copyOf(writtenChunkOffsets); | ||
} | ||
|
||
@Override | ||
public ImmutableList<Integer> writtenChunkSampleCounts() { | ||
return ImmutableList.copyOf(writtenChunkSampleCounts); | ||
} | ||
|
||
@Override | ||
public Format format() { | ||
return format; | ||
} | ||
} |