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
|
id = null
|
||||||
containerMimeType = null
|
containerMimeType = null
|
||||||
sampleMimeType = audio/vorbis
|
sampleMimeType = audio/vorbis
|
||||||
maxInputSize = 65025
|
maxInputSize = -1
|
||||||
width = -1
|
width = -1
|
||||||
height = -1
|
height = -1
|
||||||
frameRate = -1.0
|
frameRate = -1.0
|
||||||
|
@ -9,7 +9,7 @@ track 0:
|
|||||||
id = null
|
id = null
|
||||||
containerMimeType = null
|
containerMimeType = null
|
||||||
sampleMimeType = audio/vorbis
|
sampleMimeType = audio/vorbis
|
||||||
maxInputSize = 65025
|
maxInputSize = -1
|
||||||
width = -1
|
width = -1
|
||||||
height = -1
|
height = -1
|
||||||
frameRate = -1.0
|
frameRate = -1.0
|
||||||
|
@ -9,7 +9,7 @@ track 0:
|
|||||||
id = null
|
id = null
|
||||||
containerMimeType = null
|
containerMimeType = null
|
||||||
sampleMimeType = audio/vorbis
|
sampleMimeType = audio/vorbis
|
||||||
maxInputSize = 65025
|
maxInputSize = -1
|
||||||
width = -1
|
width = -1
|
||||||
height = -1
|
height = -1
|
||||||
frameRate = -1.0
|
frameRate = -1.0
|
||||||
|
@ -9,7 +9,7 @@ track 0:
|
|||||||
id = null
|
id = null
|
||||||
containerMimeType = null
|
containerMimeType = null
|
||||||
sampleMimeType = audio/vorbis
|
sampleMimeType = audio/vorbis
|
||||||
maxInputSize = 65025
|
maxInputSize = -1
|
||||||
width = -1
|
width = -1
|
||||||
height = -1
|
height = -1
|
||||||
frameRate = -1.0
|
frameRate = -1.0
|
||||||
|
@ -9,7 +9,7 @@ track 0:
|
|||||||
id = null
|
id = null
|
||||||
containerMimeType = null
|
containerMimeType = null
|
||||||
sampleMimeType = audio/vorbis
|
sampleMimeType = audio/vorbis
|
||||||
maxInputSize = 65025
|
maxInputSize = -1
|
||||||
width = -1
|
width = -1
|
||||||
height = -1
|
height = -1
|
||||||
frameRate = -1.0
|
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.Assertions;
|
||||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OGG packet class.
|
* OGG packet class.
|
||||||
@ -27,8 +28,8 @@ import java.io.IOException;
|
|||||||
/* package */ final class OggPacket {
|
/* package */ final class OggPacket {
|
||||||
|
|
||||||
private final OggPageHeader pageHeader = new OggPageHeader();
|
private final OggPageHeader pageHeader = new OggPageHeader();
|
||||||
private final ParsableByteArray packetArray =
|
private final ParsableByteArray packetArray = new ParsableByteArray(
|
||||||
new ParsableByteArray(new byte[OggPageHeader.MAX_PAGE_PAYLOAD], 0);
|
new byte[OggPageHeader.MAX_PAGE_PAYLOAD], 0);
|
||||||
|
|
||||||
private int currentSegmentIndex = C.INDEX_UNSET;
|
private int currentSegmentIndex = C.INDEX_UNSET;
|
||||||
private int segmentCount;
|
private int segmentCount;
|
||||||
@ -85,6 +86,9 @@ import java.io.IOException;
|
|||||||
int size = calculatePacketSize(currentSegmentIndex);
|
int size = calculatePacketSize(currentSegmentIndex);
|
||||||
int segmentIndex = currentSegmentIndex + segmentCount;
|
int segmentIndex = currentSegmentIndex + segmentCount;
|
||||||
if (size > 0) {
|
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);
|
input.readFully(packetArray.data, packetArray.limit(), size);
|
||||||
packetArray.setLimit(packetArray.limit() + size);
|
packetArray.setLimit(packetArray.limit() + size);
|
||||||
populated = pageHeader.laces[segmentIndex - 1] != 255;
|
populated = pageHeader.laces[segmentIndex - 1] != 255;
|
||||||
@ -118,6 +122,17 @@ import java.io.IOException;
|
|||||||
return packetArray;
|
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}.
|
* Calculates the size of the packet starting from {@code startSegmentIndex}.
|
||||||
*
|
*
|
||||||
|
@ -103,15 +103,12 @@ import java.io.IOException;
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_READ_HEADERS:
|
case STATE_READ_HEADERS:
|
||||||
return readHeaders(input);
|
return readHeaders(input);
|
||||||
|
|
||||||
case STATE_SKIP_HEADERS:
|
case STATE_SKIP_HEADERS:
|
||||||
input.skipFully((int) payloadStartPosition);
|
input.skipFully((int) payloadStartPosition);
|
||||||
state = STATE_READ_PAYLOAD;
|
state = STATE_READ_PAYLOAD;
|
||||||
return Extractor.RESULT_CONTINUE;
|
return Extractor.RESULT_CONTINUE;
|
||||||
|
|
||||||
case STATE_READ_PAYLOAD:
|
case STATE_READ_PAYLOAD:
|
||||||
return readPayload(input, seekPosition);
|
return readPayload(input, seekPosition);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Never happens.
|
// Never happens.
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@ -152,6 +149,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
setupData = null;
|
setupData = null;
|
||||||
state = STATE_READ_PAYLOAD;
|
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;
|
return Extractor.RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ import java.util.ArrayList;
|
|||||||
codecInitialisationData.add(vorbisSetup.setupHeaderData);
|
codecInitialisationData.add(vorbisSetup.setupHeaderData);
|
||||||
|
|
||||||
setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_VORBIS, null,
|
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,
|
this.vorbisSetup.idHeader.channels, (int) this.vorbisSetup.idHeader.sampleRate,
|
||||||
codecInitialisationData, null, 0, null);
|
codecInitialisationData, null, 0, null);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user