Enlarge size of data array of parsable packetArray if ogg packet size exceeds
the current size. https://github.com/google/ExoPlayer/issues/2782 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=156018137
This commit is contained in:
parent
3dd2f4af57
commit
f335fb936d
@ -9,7 +9,7 @@ track 0:
|
||||
id = null
|
||||
containerMimeType = null
|
||||
sampleMimeType = audio/vorbis
|
||||
maxInputSize = 65025
|
||||
maxInputSize = -1
|
||||
width = -1
|
||||
height = -1
|
||||
frameRate = -1.0
|
||||
|
@ -9,7 +9,7 @@ track 0:
|
||||
id = null
|
||||
containerMimeType = null
|
||||
sampleMimeType = audio/vorbis
|
||||
maxInputSize = 65025
|
||||
maxInputSize = -1
|
||||
width = -1
|
||||
height = -1
|
||||
frameRate = -1.0
|
||||
|
@ -9,7 +9,7 @@ track 0:
|
||||
id = null
|
||||
containerMimeType = null
|
||||
sampleMimeType = audio/vorbis
|
||||
maxInputSize = 65025
|
||||
maxInputSize = -1
|
||||
width = -1
|
||||
height = -1
|
||||
frameRate = -1.0
|
||||
|
@ -9,7 +9,7 @@ track 0:
|
||||
id = null
|
||||
containerMimeType = null
|
||||
sampleMimeType = audio/vorbis
|
||||
maxInputSize = 65025
|
||||
maxInputSize = -1
|
||||
width = -1
|
||||
height = -1
|
||||
frameRate = -1.0
|
||||
|
@ -9,7 +9,7 @@ track 0:
|
||||
id = null
|
||||
containerMimeType = null
|
||||
sampleMimeType = audio/vorbis
|
||||
maxInputSize = 65025
|
||||
maxInputSize = -1
|
||||
width = -1
|
||||
height = -1
|
||||
frameRate = -1.0
|
||||
|
@ -20,6 +20,7 @@ import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* OGG packet class.
|
||||
@ -27,8 +28,8 @@ import java.io.IOException;
|
||||
/* package */ final class OggPacket {
|
||||
|
||||
private final OggPageHeader pageHeader = new OggPageHeader();
|
||||
private final ParsableByteArray packetArray =
|
||||
new ParsableByteArray(new byte[OggPageHeader.MAX_PAGE_PAYLOAD], 0);
|
||||
private final ParsableByteArray packetArray = new ParsableByteArray(
|
||||
new byte[OggPageHeader.MAX_PAGE_PAYLOAD], 0);
|
||||
|
||||
private int currentSegmentIndex = C.INDEX_UNSET;
|
||||
private int segmentCount;
|
||||
@ -85,6 +86,9 @@ import java.io.IOException;
|
||||
int size = calculatePacketSize(currentSegmentIndex);
|
||||
int segmentIndex = currentSegmentIndex + segmentCount;
|
||||
if (size > 0) {
|
||||
if (packetArray.capacity() < packetArray.limit() + size) {
|
||||
packetArray.data = Arrays.copyOf(packetArray.data, packetArray.limit() + size);
|
||||
}
|
||||
input.readFully(packetArray.data, packetArray.limit(), size);
|
||||
packetArray.setLimit(packetArray.limit() + size);
|
||||
populated = pageHeader.laces[segmentIndex - 1] != 255;
|
||||
@ -118,6 +122,17 @@ import java.io.IOException;
|
||||
return packetArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the packet data array.
|
||||
*/
|
||||
public void trimPayload() {
|
||||
if (packetArray.data.length == OggPageHeader.MAX_PAGE_PAYLOAD) {
|
||||
return;
|
||||
}
|
||||
packetArray.data = Arrays.copyOf(packetArray.data, Math.max(OggPageHeader.MAX_PAGE_PAYLOAD,
|
||||
packetArray.limit()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the size of the packet starting from {@code startSegmentIndex}.
|
||||
*
|
||||
|
@ -103,15 +103,12 @@ import java.io.IOException;
|
||||
switch (state) {
|
||||
case STATE_READ_HEADERS:
|
||||
return readHeaders(input);
|
||||
|
||||
case STATE_SKIP_HEADERS:
|
||||
input.skipFully((int) payloadStartPosition);
|
||||
state = STATE_READ_PAYLOAD;
|
||||
return Extractor.RESULT_CONTINUE;
|
||||
|
||||
case STATE_READ_PAYLOAD:
|
||||
return readPayload(input, seekPosition);
|
||||
|
||||
default:
|
||||
// Never happens.
|
||||
throw new IllegalStateException();
|
||||
@ -152,6 +149,8 @@ import java.io.IOException;
|
||||
|
||||
setupData = null;
|
||||
state = STATE_READ_PAYLOAD;
|
||||
// First payload packet. Trim the payload array of the ogg packet after headers have been read.
|
||||
oggPacket.trimPayload();
|
||||
return Extractor.RESULT_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ import java.util.ArrayList;
|
||||
codecInitialisationData.add(vorbisSetup.setupHeaderData);
|
||||
|
||||
setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_VORBIS, null,
|
||||
this.vorbisSetup.idHeader.bitrateNominal, OggPageHeader.MAX_PAGE_PAYLOAD,
|
||||
this.vorbisSetup.idHeader.bitrateNominal, Format.NO_VALUE,
|
||||
this.vorbisSetup.idHeader.channels, (int) this.vorbisSetup.idHeader.sampleRate,
|
||||
codecInitialisationData, null, 0, null);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user