mirror of
https://github.com/androidx/media.git
synced 2025-05-04 14:10:40 +08:00
Extractor cleanup
- Align class summary Javadoc - Fix ErrorProne + Style warnings ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=177165593
This commit is contained in:
parent
7a03198028
commit
0e0300b802
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.flv;
|
package com.google.android.exoplayer2.extractor.flv;
|
||||||
|
|
||||||
|
import android.support.annotation.IntDef;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
import com.google.android.exoplayer2.extractor.Extractor;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||||
@ -25,9 +26,11 @@ import com.google.android.exoplayer2.extractor.SeekMap;
|
|||||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the FLV container format.
|
* Extracts data from the FLV container format.
|
||||||
*/
|
*/
|
||||||
public final class FlvExtractor implements Extractor, SeekMap {
|
public final class FlvExtractor implements Extractor, SeekMap {
|
||||||
|
|
||||||
@ -43,16 +46,22 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Header sizes.
|
/**
|
||||||
private static final int FLV_HEADER_SIZE = 9;
|
* Extractor states.
|
||||||
private static final int FLV_TAG_HEADER_SIZE = 11;
|
*/
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
// Parser states.
|
@IntDef({STATE_READING_FLV_HEADER, STATE_SKIPPING_TO_TAG_HEADER, STATE_READING_TAG_HEADER,
|
||||||
|
STATE_READING_TAG_DATA})
|
||||||
|
private @interface States {}
|
||||||
private static final int STATE_READING_FLV_HEADER = 1;
|
private static final int STATE_READING_FLV_HEADER = 1;
|
||||||
private static final int STATE_SKIPPING_TO_TAG_HEADER = 2;
|
private static final int STATE_SKIPPING_TO_TAG_HEADER = 2;
|
||||||
private static final int STATE_READING_TAG_HEADER = 3;
|
private static final int STATE_READING_TAG_HEADER = 3;
|
||||||
private static final int STATE_READING_TAG_DATA = 4;
|
private static final int STATE_READING_TAG_DATA = 4;
|
||||||
|
|
||||||
|
// Header sizes.
|
||||||
|
private static final int FLV_HEADER_SIZE = 9;
|
||||||
|
private static final int FLV_TAG_HEADER_SIZE = 11;
|
||||||
|
|
||||||
// Tag types.
|
// Tag types.
|
||||||
private static final int TAG_TYPE_AUDIO = 8;
|
private static final int TAG_TYPE_AUDIO = 8;
|
||||||
private static final int TAG_TYPE_VIDEO = 9;
|
private static final int TAG_TYPE_VIDEO = 9;
|
||||||
@ -71,11 +80,11 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
private ExtractorOutput extractorOutput;
|
private ExtractorOutput extractorOutput;
|
||||||
|
|
||||||
// State variables.
|
// State variables.
|
||||||
private int parserState;
|
private @States int state;
|
||||||
private int bytesToNextTagHeader;
|
private int bytesToNextTagHeader;
|
||||||
public int tagType;
|
private int tagType;
|
||||||
public int tagDataSize;
|
private int tagDataSize;
|
||||||
public long tagTimestampUs;
|
private long tagTimestampUs;
|
||||||
|
|
||||||
// Tags readers.
|
// Tags readers.
|
||||||
private AudioTagPayloadReader audioReader;
|
private AudioTagPayloadReader audioReader;
|
||||||
@ -87,7 +96,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
headerBuffer = new ParsableByteArray(FLV_HEADER_SIZE);
|
headerBuffer = new ParsableByteArray(FLV_HEADER_SIZE);
|
||||||
tagHeaderBuffer = new ParsableByteArray(FLV_TAG_HEADER_SIZE);
|
tagHeaderBuffer = new ParsableByteArray(FLV_TAG_HEADER_SIZE);
|
||||||
tagData = new ParsableByteArray();
|
tagData = new ParsableByteArray();
|
||||||
parserState = STATE_READING_FLV_HEADER;
|
state = STATE_READING_FLV_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -128,7 +137,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seek(long position, long timeUs) {
|
public void seek(long position, long timeUs) {
|
||||||
parserState = STATE_READING_FLV_HEADER;
|
state = STATE_READING_FLV_HEADER;
|
||||||
bytesToNextTagHeader = 0;
|
bytesToNextTagHeader = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +150,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
|
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (parserState) {
|
switch (state) {
|
||||||
case STATE_READING_FLV_HEADER:
|
case STATE_READING_FLV_HEADER:
|
||||||
if (!readFlvHeader(input)) {
|
if (!readFlvHeader(input)) {
|
||||||
return RESULT_END_OF_INPUT;
|
return RESULT_END_OF_INPUT;
|
||||||
@ -160,6 +169,9 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
return RESULT_CONTINUE;
|
return RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// Never happens.
|
||||||
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +211,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
|
|
||||||
// We need to skip any additional content in the FLV header, plus the 4 byte previous tag size.
|
// We need to skip any additional content in the FLV header, plus the 4 byte previous tag size.
|
||||||
bytesToNextTagHeader = headerBuffer.readInt() - FLV_HEADER_SIZE + 4;
|
bytesToNextTagHeader = headerBuffer.readInt() - FLV_HEADER_SIZE + 4;
|
||||||
parserState = STATE_SKIPPING_TO_TAG_HEADER;
|
state = STATE_SKIPPING_TO_TAG_HEADER;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +225,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
private void skipToTagHeader(ExtractorInput input) throws IOException, InterruptedException {
|
private void skipToTagHeader(ExtractorInput input) throws IOException, InterruptedException {
|
||||||
input.skipFully(bytesToNextTagHeader);
|
input.skipFully(bytesToNextTagHeader);
|
||||||
bytesToNextTagHeader = 0;
|
bytesToNextTagHeader = 0;
|
||||||
parserState = STATE_READING_TAG_HEADER;
|
state = STATE_READING_TAG_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,7 +248,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
tagTimestampUs = tagHeaderBuffer.readUnsignedInt24();
|
tagTimestampUs = tagHeaderBuffer.readUnsignedInt24();
|
||||||
tagTimestampUs = ((tagHeaderBuffer.readUnsignedByte() << 24) | tagTimestampUs) * 1000L;
|
tagTimestampUs = ((tagHeaderBuffer.readUnsignedByte() << 24) | tagTimestampUs) * 1000L;
|
||||||
tagHeaderBuffer.skipBytes(3); // streamId
|
tagHeaderBuffer.skipBytes(3); // streamId
|
||||||
parserState = STATE_READING_TAG_DATA;
|
state = STATE_READING_TAG_DATA;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +273,7 @@ public final class FlvExtractor implements Extractor, SeekMap {
|
|||||||
wasConsumed = false;
|
wasConsumed = false;
|
||||||
}
|
}
|
||||||
bytesToNextTagHeader = 4; // There's a 4 byte previous tag size before the next header.
|
bytesToNextTagHeader = 4; // There's a 4 byte previous tag size before the next header.
|
||||||
parserState = STATE_SKIPPING_TO_TAG_HEADER;
|
state = STATE_SKIPPING_TO_TAG_HEADER;
|
||||||
return wasConsumed;
|
return wasConsumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ import java.util.Locale;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts data from a Matroska or WebM file.
|
* Extracts data from the Matroska and WebM container formats.
|
||||||
*/
|
*/
|
||||||
public final class MatroskaExtractor implements Extractor {
|
public final class MatroskaExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts data from an MP3 file.
|
* Extracts data from the MP3 container format.
|
||||||
*/
|
*/
|
||||||
public final class Mp3Extractor implements Extractor {
|
public final class Mp3Extractor implements Extractor {
|
||||||
|
|
||||||
|
@ -113,12 +113,13 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
fx = 256f;
|
fx = 256f;
|
||||||
} else {
|
} else {
|
||||||
int a = (int) percent;
|
int a = (int) percent;
|
||||||
float fa, fb;
|
float fa;
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
fa = 0f;
|
fa = 0f;
|
||||||
} else {
|
} else {
|
||||||
fa = tableOfContents[a - 1];
|
fa = tableOfContents[a - 1];
|
||||||
}
|
}
|
||||||
|
float fb;
|
||||||
if (a < 99) {
|
if (a < 99) {
|
||||||
fb = tableOfContents[a];
|
fb = tableOfContents[a];
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,7 +53,7 @@ import java.util.Stack;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the fragmented mp4 container format.
|
* Extracts data from the FMP4 container format.
|
||||||
*/
|
*/
|
||||||
public final class FragmentedMp4Extractor implements Extractor {
|
public final class FragmentedMp4Extractor implements Extractor {
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ import java.util.List;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts data from an unfragmented MP4 file.
|
* Extracts data from the MP4 container format.
|
||||||
*/
|
*/
|
||||||
public final class Mp4Extractor implements Extractor, SeekMap {
|
public final class Mp4Extractor implements Extractor, SeekMap {
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ import java.io.IOException;
|
|||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
long offset = pageSize * (granuleDistance <= 0 ? 2 : 1);
|
long offset = pageSize * (granuleDistance <= 0 ? 2L : 1L);
|
||||||
long nextPosition = input.getPosition() - offset
|
long nextPosition = input.getPosition() - offset
|
||||||
+ (granuleDistance * (end - start) / (endGranule - startGranule));
|
+ (granuleDistance * (end - start) / (endGranule - startGranule));
|
||||||
|
|
||||||
|
@ -118,9 +118,10 @@ import java.util.List;
|
|||||||
case 14:
|
case 14:
|
||||||
case 15:
|
case 15:
|
||||||
return 256 << (blockSizeCode - 8);
|
return 256 << (blockSizeCode - 8);
|
||||||
}
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class FlacOggSeeker implements OggSeeker, SeekMap {
|
private class FlacOggSeeker implements OggSeeker, SeekMap {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ogg {@link Extractor}.
|
* Extracts data from the Ogg container format.
|
||||||
*/
|
*/
|
||||||
public class OggExtractor implements Extractor {
|
public class OggExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts CEA data from a RawCC file.
|
* Extracts data from the RawCC container format.
|
||||||
*/
|
*/
|
||||||
public final class RawCcExtractor implements Extractor {
|
public final class RawCcExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts samples from (E-)AC-3 bitstreams.
|
* Extracts data from (E-)AC-3 bitstreams.
|
||||||
*/
|
*/
|
||||||
public final class Ac3Extractor implements Extractor {
|
public final class Ac3Extractor implements Extractor {
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts samples from AAC bit streams with ADTS framing.
|
* Extracts data from AAC bit streams with ADTS framing.
|
||||||
*/
|
*/
|
||||||
public final class AdtsExtractor implements Extractor {
|
public final class AdtsExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import com.google.android.exoplayer2.util.TimestampAdjuster;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the MPEG-2 PS container format.
|
* Extracts data from the MPEG-2 PS container format.
|
||||||
*/
|
*/
|
||||||
public final class PsExtractor implements Extractor {
|
public final class PsExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the MPEG-2 TS container format.
|
* Extracts data from the MPEG-2 TS container format.
|
||||||
*/
|
*/
|
||||||
public final class TsExtractor implements Extractor {
|
public final class TsExtractor implements Extractor {
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ import com.google.android.exoplayer2.extractor.TrackOutput;
|
|||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/** {@link Extractor} to extract samples from a WAV byte stream. */
|
/**
|
||||||
|
* Extracts data from WAV byte streams.
|
||||||
|
*/
|
||||||
public final class WavExtractor implements Extractor, SeekMap {
|
public final class WavExtractor implements Extractor, SeekMap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user