MP3: Make a defensive copy of the header in XingFrame constructor

This is currently set from `Mp3Extractor.synchronizedHeader` which
gets overwritten every time we read a new frame. It seems safer to make
this defensive copy (and there will be at most one `XingFrame` instance
per-playback, so this is not prohibitively expensive).

PiperOrigin-RevId: 636181038
This commit is contained in:
ibaker 2024-05-22 08:46:14 -07:00 committed by Copybara-Service
parent a74076f691
commit 8d515c8cdc
2 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,20 @@ public final class MpegAudioUtil {
/** Number of samples stored in the frame. */
public int samplesPerFrame;
/** Constructs an empty instance. */
public Header() {}
/** Constructs an instance with values from {@code header}. */
public Header(Header header) {
this.version = header.version;
this.mimeType = header.mimeType;
this.frameSize = header.frameSize;
this.sampleRate = header.sampleRate;
this.channels = header.channels;
this.bitrate = header.bitrate;
this.samplesPerFrame = header.samplesPerFrame;
}
/**
* Populates the fields in this instance to reflect the MPEG audio header in {@code headerData},
* returning whether the header was valid. If false, the values of the fields in this instance

View File

@ -60,7 +60,7 @@ import androidx.media3.extractor.MpegAudioUtil;
@Nullable long[] tableOfContents,
int encoderDelay,
int encoderPadding) {
this.header = header;
this.header = new MpegAudioUtil.Header(header);
this.frameCount = frameCount;
this.dataSize = dataSize;
this.tableOfContents = tableOfContents;