Commit 0e937ff9 by sheenachhabra Committed by Tofunmi Adigun-Hameed

Write metadata to Mp4Muxer in the release() method

Earlier metadata was written multiple times as it came.
With new changes, all the distinct metadata entries will
get collected and will be written at once in the end.

PiperOrigin-RevId: 534088401
(cherry picked from commit f88fde8b88c2422f096425b6568ee7ac8ebb2ade)
parent e755359e
......@@ -32,7 +32,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/** {@link Muxer} implementation that uses a {@link Mp4Muxer}. */
public final class InAppMuxer implements Muxer {
......@@ -83,12 +85,14 @@ public final class InAppMuxer implements Muxer {
private final long maxDelayBetweenSamplesMs;
private final List<TrackToken> trackTokenList;
private final BufferInfo bufferInfo;
private final Set<Metadata.Entry> metadataEntries;
private InAppMuxer(Mp4Muxer mp4Muxer, long maxDelayBetweenSamplesMs) {
this.mp4Muxer = mp4Muxer;
this.maxDelayBetweenSamplesMs = maxDelayBetweenSamplesMs;
trackTokenList = new ArrayList<>();
bufferInfo = new BufferInfo();
metadataEntries = new LinkedHashSet<>();
}
@Override
......@@ -131,15 +135,16 @@ public final class InAppMuxer implements Muxer {
public void addMetadata(Metadata metadata) {
for (int i = 0; i < metadata.length(); i++) {
Metadata.Entry entry = metadata.get(i);
// Keep only supported metadata.
if (entry instanceof Mp4LocationData) {
mp4Muxer.setLocation(
((Mp4LocationData) entry).latitude, ((Mp4LocationData) entry).longitude);
metadataEntries.add(entry);
}
}
}
@Override
public void release(boolean forCancellation) throws MuxerException {
writeMetadata();
try {
mp4Muxer.close();
} catch (IOException e) {
......@@ -151,4 +156,13 @@ public final class InAppMuxer implements Muxer {
public long getMaxDelayBetweenSamplesMs() {
return maxDelayBetweenSamplesMs;
}
private void writeMetadata() {
for (Metadata.Entry entry : metadataEntries) {
if (entry instanceof Mp4LocationData) {
mp4Muxer.setLocation(
((Mp4LocationData) entry).latitude, ((Mp4LocationData) entry).longitude);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment