com.google.android.exoplayer2.metadata.id3.Id3Decoder Java Examples
The following examples show how to use
com.google.android.exoplayer2.metadata.id3.Id3Decoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetadataDecoderFactory.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public MetadataDecoder createDecoder(Format format) { @Nullable String mimeType = format.sampleMimeType; if (mimeType != null) { switch (mimeType) { case MimeTypes.APPLICATION_ID3: return new Id3Decoder(); case MimeTypes.APPLICATION_EMSG: return new EventMessageDecoder(); case MimeTypes.APPLICATION_SCTE35: return new SpliceInfoDecoder(); case MimeTypes.APPLICATION_ICY: return new IcyDecoder(); default: break; } } throw new IllegalArgumentException( "Attempted to create decoder for unsupported MIME type: " + mimeType); }
Example #2
Source File: MetadataDecoderFactory.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public MetadataDecoder createDecoder(Format format) { switch (format.sampleMimeType) { case MimeTypes.APPLICATION_ID3: return new Id3Decoder(); case MimeTypes.APPLICATION_EMSG: return new EventMessageDecoder(); case MimeTypes.APPLICATION_SCTE35: return new SpliceInfoDecoder(); case MimeTypes.APPLICATION_ICY: return new IcyDecoder(); default: throw new IllegalArgumentException( "Attempted to create decoder for unsupported format"); } }
Example #3
Source File: MetadataDecoderFactory.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public MetadataDecoder createDecoder(Format format) { switch (format.sampleMimeType) { case MimeTypes.APPLICATION_ID3: return new Id3Decoder(); case MimeTypes.APPLICATION_EMSG: return new EventMessageDecoder(); case MimeTypes.APPLICATION_SCTE35: return new SpliceInfoDecoder(); case MimeTypes.APPLICATION_ICY: return new IcyDecoder(); default: throw new IllegalArgumentException( "Attempted to create decoder for unsupported format"); } }
Example #4
Source File: Mp3Extractor.java From K-Sonic with MIT License | 5 votes |
/** * Peeks ID3 data from the input, including gapless playback information. * * @param input The {@link ExtractorInput} from which data should be peeked. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ private void peekId3Data(ExtractorInput input) throws IOException, InterruptedException { int peekedId3Bytes = 0; while (true) { input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH); scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); // We need to parse enough ID3 metadata to retrieve any gapless playback information even // if ID3 metadata parsing is disabled. Id3Decoder.FramePredicate id3FramePredicate = (flags & FLAG_DISABLE_ID3_METADATA) != 0 ? GaplessInfoHolder.GAPLESS_INFO_ID3_FRAME_PREDICATE : null; metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); if (metadata != null) { gaplessInfoHolder.setFromMetadata(metadata); } } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); }
Example #5
Source File: FlacExtractor.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 tag data at the beginning of the input. * * @return The first ID3 tag {@link Metadata}, or null if an ID3 tag is not present in the input. */ @Nullable private Metadata peekId3Data(ExtractorInput input) throws IOException, InterruptedException { input.resetPeekPosition(); Id3Decoder.FramePredicate id3FramePredicate = id3MetadataDisabled ? Id3Decoder.NO_FRAMES_PREDICATE : null; return id3Peeker.peekId3Data(input, id3FramePredicate); }
Example #6
Source File: Id3Peeker.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 data from the input and parses the first ID3 tag. * * @param input The {@link ExtractorInput} from which data should be peeked. * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all * frames. * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ @Nullable public Metadata peekId3Data( ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException, InterruptedException { int peekedId3Bytes = 0; Metadata metadata = null; while (true) { try { input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH); } catch (EOFException e) { // If input has less than ID3_HEADER_LENGTH, ignore the rest. break; } scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); return metadata; }
Example #7
Source File: FlacExtractor.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 tag data at the beginning of the input. * * @return The first ID3 tag {@link Metadata}, or null if an ID3 tag is not present in the input. */ @Nullable private Metadata peekId3Data(ExtractorInput input) throws IOException, InterruptedException { input.resetPeekPosition(); Id3Decoder.FramePredicate id3FramePredicate = id3MetadataDisabled ? Id3Decoder.NO_FRAMES_PREDICATE : null; return id3Peeker.peekId3Data(input, id3FramePredicate); }
Example #8
Source File: Id3Peeker.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 data from the input and parses the first ID3 tag. * * @param input The {@link ExtractorInput} from which data should be peeked. * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all * frames. * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ @Nullable public Metadata peekId3Data( ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException, InterruptedException { int peekedId3Bytes = 0; Metadata metadata = null; while (true) { try { input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH); } catch (EOFException e) { // If input has less than ID3_HEADER_LENGTH, ignore the rest. break; } scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); return metadata; }
Example #9
Source File: HlsMediaChunk.java From K-Sonic with MIT License | 5 votes |
/** * @param dataSource The source from which the data should be loaded. * @param dataSpec Defines the data to be loaded. * @param initDataSpec Defines the initialization data to be fed to new extractors. May be null. * @param hlsUrl The url of the playlist from which this chunk was obtained. * @param muxedCaptionFormats List of muxed caption {@link Format}s. * @param trackSelectionReason See {@link #trackSelectionReason}. * @param trackSelectionData See {@link #trackSelectionData}. * @param startTimeUs The start time of the chunk in microseconds. * @param endTimeUs The end time of the chunk in microseconds. * @param chunkIndex The media sequence number of the chunk. * @param discontinuitySequenceNumber The discontinuity sequence number of the chunk. * @param isMasterTimestampSource True if the chunk can initialize the timestamp adjuster. * @param timestampAdjuster Adjuster corresponding to the provided discontinuity sequence number. * @param previousChunk The {@link HlsMediaChunk} that preceded this one. May be null. * @param encryptionKey For AES encryption chunks, the encryption key. * @param encryptionIv For AES encryption chunks, the encryption initialization vector. */ public HlsMediaChunk(DataSource dataSource, DataSpec dataSpec, DataSpec initDataSpec, HlsUrl hlsUrl, List<Format> muxedCaptionFormats, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs, int chunkIndex, int discontinuitySequenceNumber, boolean isMasterTimestampSource, TimestampAdjuster timestampAdjuster, HlsMediaChunk previousChunk, byte[] encryptionKey, byte[] encryptionIv) { super(buildDataSource(dataSource, encryptionKey, encryptionIv), dataSpec, hlsUrl.format, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkIndex); this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.initDataSpec = initDataSpec; this.hlsUrl = hlsUrl; this.muxedCaptionFormats = muxedCaptionFormats; this.isMasterTimestampSource = isMasterTimestampSource; this.timestampAdjuster = timestampAdjuster; // Note: this.dataSource and dataSource may be different. this.isEncrypted = this.dataSource instanceof Aes128DataSource; lastPathSegment = dataSpec.uri.getLastPathSegment(); isPackedAudio = lastPathSegment.endsWith(AAC_FILE_EXTENSION) || lastPathSegment.endsWith(AC3_FILE_EXTENSION) || lastPathSegment.endsWith(EC3_FILE_EXTENSION) || lastPathSegment.endsWith(MP3_FILE_EXTENSION); if (previousChunk != null) { id3Decoder = previousChunk.id3Decoder; id3Data = previousChunk.id3Data; previousExtractor = previousChunk.extractor; shouldSpliceIn = previousChunk.hlsUrl != hlsUrl; needNewExtractor = previousChunk.discontinuitySequenceNumber != discontinuitySequenceNumber || shouldSpliceIn; } else { id3Decoder = isPackedAudio ? new Id3Decoder() : null; id3Data = isPackedAudio ? new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH) : null; previousExtractor = null; shouldSpliceIn = false; needNewExtractor = true; } initDataSource = dataSource; uid = UID_SOURCE.getAndIncrement(); }
Example #10
Source File: FlacExtractor.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 tag data (if present) at the beginning of the input. * * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. */ @Nullable private Metadata peekId3Data(ExtractorInput input) throws IOException, InterruptedException { input.resetPeekPosition(); Id3Decoder.FramePredicate id3FramePredicate = isId3MetadataDisabled ? Id3Decoder.NO_FRAMES_PREDICATE : null; return id3Peeker.peekId3Data(input, id3FramePredicate); }
Example #11
Source File: MetadataDecoderFactory.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public MetadataDecoder createDecoder(Format format) { switch (format.sampleMimeType) { case MimeTypes.APPLICATION_ID3: return new Id3Decoder(); case MimeTypes.APPLICATION_EMSG: return new EventMessageDecoder(); case MimeTypes.APPLICATION_SCTE35: return new SpliceInfoDecoder(); default: throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); } }
Example #12
Source File: Id3Peeker.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 data from the input and parses the first ID3 tag. * * @param input The {@link ExtractorInput} from which data should be peeked. * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all * frames. * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ @Nullable public Metadata peekId3Data( ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException, InterruptedException { int peekedId3Bytes = 0; Metadata metadata = null; while (true) { try { input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH); } catch (EOFException e) { // If input has less than ID3_HEADER_LENGTH, ignore the rest. break; } scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); return metadata; }
Example #13
Source File: Id3Peeker.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Peeks ID3 data from the input and parses the first ID3 tag. * * @param input The {@link ExtractorInput} from which data should be peeked. * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all * frames. * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ @Nullable public Metadata peekId3Data( ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException, InterruptedException { int peekedId3Bytes = 0; Metadata metadata = null; while (true) { try { input.peekFully(scratch.data, /* offset= */ 0, Id3Decoder.ID3_HEADER_LENGTH); } catch (EOFException e) { // If input has less than ID3_HEADER_LENGTH, ignore the rest. break; } scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); return metadata; }
Example #14
Source File: Id3Peeker.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 data from the input and parses the first ID3 tag. * * @param input The {@link ExtractorInput} from which data should be peeked. * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all * frames. * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. * @throws IOException If an error occurred peeking from the input. * @throws InterruptedException If the thread was interrupted. */ @Nullable public Metadata peekId3Data( ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate) throws IOException, InterruptedException { int peekedId3Bytes = 0; Metadata metadata = null; while (true) { try { input.peekFully(scratch.data, 0, Id3Decoder.ID3_HEADER_LENGTH); } catch (EOFException e) { // If input has less than ID3_HEADER_LENGTH, ignore the rest. break; } scratch.setPosition(0); if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) { // Not an ID3 tag. break; } scratch.skipBytes(3); // Skip major version, minor version and flags. int framesLength = scratch.readSynchSafeInt(); int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength; if (metadata == null) { byte[] id3Data = new byte[tagLength]; System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH); input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength); metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength); } else { input.advancePeekPosition(framesLength); } peekedId3Bytes += tagLength; } input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes); return metadata; }
Example #15
Source File: MetadataDecoderFactory.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public MetadataDecoder createDecoder(Format format) { switch (format.sampleMimeType) { case MimeTypes.APPLICATION_ID3: return new Id3Decoder(); case MimeTypes.APPLICATION_EMSG: return new EventMessageDecoder(); case MimeTypes.APPLICATION_SCTE35: return new SpliceInfoDecoder(); default: throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); } }
Example #16
Source File: FlacExtractor.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Peeks ID3 tag data (if present) at the beginning of the input. * * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not * present in the input. */ @Nullable private Metadata peekId3Data(ExtractorInput input) throws IOException, InterruptedException { input.resetPeekPosition(); Id3Decoder.FramePredicate id3FramePredicate = isId3MetadataDisabled ? Id3Decoder.NO_FRAMES_PREDICATE : null; return id3Peeker.peekId3Data(input, id3FramePredicate); }
Example #17
Source File: Mp3Extractor.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private boolean synchronize(ExtractorInput input, boolean sniffing) throws IOException, InterruptedException { int validFrameCount = 0; int candidateSynchronizedHeaderData = 0; int peekedId3Bytes = 0; int searchedBytes = 0; int searchLimitBytes = sniffing ? MAX_SNIFF_BYTES : MAX_SYNC_BYTES; input.resetPeekPosition(); if (input.getPosition() == 0) { // We need to parse enough ID3 metadata to retrieve any gapless/seeking playback information // even if ID3 metadata parsing is disabled. boolean parseAllId3Frames = (flags & FLAG_DISABLE_ID3_METADATA) == 0; Id3Decoder.FramePredicate id3FramePredicate = parseAllId3Frames ? null : REQUIRED_ID3_FRAME_PREDICATE; metadata = id3Peeker.peekId3Data(input, id3FramePredicate); if (metadata != null) { gaplessInfoHolder.setFromMetadata(metadata); } peekedId3Bytes = (int) input.getPeekPosition(); if (!sniffing) { input.skipFully(peekedId3Bytes); } } while (true) { if (peekEndOfStreamOrHeader(input)) { if (validFrameCount > 0) { // We reached the end of the stream but found at least one valid frame. break; } throw new EOFException(); } scratch.setPosition(0); int headerData = scratch.readInt(); int frameSize; if ((candidateSynchronizedHeaderData != 0 && !headersMatch(headerData, candidateSynchronizedHeaderData)) || (frameSize = MpegAudioHeader.getFrameSize(headerData)) == C.LENGTH_UNSET) { // The header doesn't match the candidate header or is invalid. Try the next byte offset. if (searchedBytes++ == searchLimitBytes) { if (!sniffing) { throw new ParserException("Searched too many bytes."); } return false; } validFrameCount = 0; candidateSynchronizedHeaderData = 0; if (sniffing) { input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes + searchedBytes); } else { input.skipFully(1); } } else { // The header matches the candidate header and/or is valid. validFrameCount++; if (validFrameCount == 1) { MpegAudioHeader.populateHeader(headerData, synchronizedHeader); candidateSynchronizedHeaderData = headerData; } else if (validFrameCount == 4) { break; } input.advancePeekPosition(frameSize - 4); } } // Prepare to read the synchronized frame. if (sniffing) { input.skipFully(peekedId3Bytes + searchedBytes); } else { input.resetPeekPosition(); } synchronizedHeaderData = candidateSynchronizedHeaderData; return true; }
Example #18
Source File: Id3Peeker.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public Id3Peeker() { scratch = new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); }
Example #19
Source File: Id3Peeker.java From MediaSDK with Apache License 2.0 | 4 votes |
public Id3Peeker() { scratch = new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); }
Example #20
Source File: Mp3Extractor.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean synchronize(ExtractorInput input, boolean sniffing) throws IOException, InterruptedException { int validFrameCount = 0; int candidateSynchronizedHeaderData = 0; int peekedId3Bytes = 0; int searchedBytes = 0; int searchLimitBytes = sniffing ? MAX_SNIFF_BYTES : MAX_SYNC_BYTES; input.resetPeekPosition(); if (input.getPosition() == 0) { // We need to parse enough ID3 metadata to retrieve any gapless playback information even // if ID3 metadata parsing is disabled. boolean onlyDecodeGaplessInfoFrames = (flags & FLAG_DISABLE_ID3_METADATA) != 0; Id3Decoder.FramePredicate id3FramePredicate = onlyDecodeGaplessInfoFrames ? GaplessInfoHolder.GAPLESS_INFO_ID3_FRAME_PREDICATE : null; metadata = id3Peeker.peekId3Data(input, id3FramePredicate); if (metadata != null) { gaplessInfoHolder.setFromMetadata(metadata); } peekedId3Bytes = (int) input.getPeekPosition(); if (!sniffing) { input.skipFully(peekedId3Bytes); } } while (true) { if (!input.peekFully(scratch.data, 0, 4, validFrameCount > 0)) { // We reached the end of the stream but found at least one valid frame. break; } scratch.setPosition(0); int headerData = scratch.readInt(); int frameSize; if ((candidateSynchronizedHeaderData != 0 && !headersMatch(headerData, candidateSynchronizedHeaderData)) || (frameSize = MpegAudioHeader.getFrameSize(headerData)) == C.LENGTH_UNSET) { // The header doesn't match the candidate header or is invalid. Try the next byte offset. if (searchedBytes++ == searchLimitBytes) { if (!sniffing) { throw new ParserException("Searched too many bytes."); } return false; } validFrameCount = 0; candidateSynchronizedHeaderData = 0; if (sniffing) { input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes + searchedBytes); } else { input.skipFully(1); } } else { // The header matches the candidate header and/or is valid. validFrameCount++; if (validFrameCount == 1) { MpegAudioHeader.populateHeader(headerData, synchronizedHeader); candidateSynchronizedHeaderData = headerData; } else if (validFrameCount == 4) { break; } input.advancePeekPosition(frameSize - 4); } } // Prepare to read the synchronized frame. if (sniffing) { input.skipFully(peekedId3Bytes + searchedBytes); } else { input.resetPeekPosition(); } synchronizedHeaderData = candidateSynchronizedHeaderData; return true; }
Example #21
Source File: HlsMediaChunk.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private HlsMediaChunk( HlsExtractorFactory extractorFactory, DataSource mediaDataSource, DataSpec dataSpec, Format format, boolean mediaSegmentEncrypted, DataSource initDataSource, @Nullable DataSpec initDataSpec, boolean initSegmentEncrypted, Uri playlistUrl, @Nullable List<Format> muxedCaptionFormats, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs, long chunkMediaSequence, int discontinuitySequenceNumber, boolean hasGapTag, boolean isMasterTimestampSource, TimestampAdjuster timestampAdjuster, @Nullable DrmInitData drmInitData, @Nullable Extractor previousExtractor, Id3Decoder id3Decoder, ParsableByteArray scratchId3Data, boolean shouldSpliceIn) { super( mediaDataSource, dataSpec, format, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkMediaSequence); this.mediaSegmentEncrypted = mediaSegmentEncrypted; this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.initDataSource = initDataSource; this.initDataSpec = initDataSpec; this.initSegmentEncrypted = initSegmentEncrypted; this.playlistUrl = playlistUrl; this.isMasterTimestampSource = isMasterTimestampSource; this.timestampAdjuster = timestampAdjuster; this.hasGapTag = hasGapTag; this.extractorFactory = extractorFactory; this.muxedCaptionFormats = muxedCaptionFormats; this.drmInitData = drmInitData; this.previousExtractor = previousExtractor; this.id3Decoder = id3Decoder; this.scratchId3Data = scratchId3Data; this.shouldSpliceIn = shouldSpliceIn; initDataLoadRequired = initDataSpec != null; uid = uidSource.getAndIncrement(); }
Example #22
Source File: Id3Peeker.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public Id3Peeker() { scratch = new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); }
Example #23
Source File: Mp3Extractor.java From Telegram with GNU General Public License v2.0 | 4 votes |
private boolean synchronize(ExtractorInput input, boolean sniffing) throws IOException, InterruptedException { int validFrameCount = 0; int candidateSynchronizedHeaderData = 0; int peekedId3Bytes = 0; int searchedBytes = 0; int searchLimitBytes = sniffing ? MAX_SNIFF_BYTES : MAX_SYNC_BYTES; input.resetPeekPosition(); if (input.getPosition() == 0) { // We need to parse enough ID3 metadata to retrieve any gapless/seeking playback information // even if ID3 metadata parsing is disabled. boolean parseAllId3Frames = (flags & FLAG_DISABLE_ID3_METADATA) == 0; Id3Decoder.FramePredicate id3FramePredicate = parseAllId3Frames ? null : REQUIRED_ID3_FRAME_PREDICATE; metadata = id3Peeker.peekId3Data(input, id3FramePredicate); if (metadata != null) { gaplessInfoHolder.setFromMetadata(metadata); } peekedId3Bytes = (int) input.getPeekPosition(); if (!sniffing) { input.skipFully(peekedId3Bytes); } } while (true) { if (peekEndOfStreamOrHeader(input)) { if (validFrameCount > 0) { // We reached the end of the stream but found at least one valid frame. break; } throw new EOFException(); } scratch.setPosition(0); int headerData = scratch.readInt(); int frameSize; if ((candidateSynchronizedHeaderData != 0 && !headersMatch(headerData, candidateSynchronizedHeaderData)) || (frameSize = MpegAudioHeader.getFrameSize(headerData)) == C.LENGTH_UNSET) { // The header doesn't match the candidate header or is invalid. Try the next byte offset. if (searchedBytes++ == searchLimitBytes) { if (!sniffing) { throw new ParserException("Searched too many bytes."); } return false; } validFrameCount = 0; candidateSynchronizedHeaderData = 0; if (sniffing) { input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes + searchedBytes); } else { input.skipFully(1); } } else { // The header matches the candidate header and/or is valid. validFrameCount++; if (validFrameCount == 1) { MpegAudioHeader.populateHeader(headerData, synchronizedHeader); candidateSynchronizedHeaderData = headerData; } else if (validFrameCount == 4) { break; } input.advancePeekPosition(frameSize - 4); } } // Prepare to read the synchronized frame. if (sniffing) { input.skipFully(peekedId3Bytes + searchedBytes); } else { input.resetPeekPosition(); } synchronizedHeaderData = candidateSynchronizedHeaderData; return true; }
Example #24
Source File: Id3Peeker.java From Telegram with GNU General Public License v2.0 | 4 votes |
public Id3Peeker() { scratch = new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); }
Example #25
Source File: Mp3Extractor.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean synchronize(ExtractorInput input, boolean sniffing) throws IOException, InterruptedException { int validFrameCount = 0; int candidateSynchronizedHeaderData = 0; int peekedId3Bytes = 0; int searchedBytes = 0; int searchLimitBytes = sniffing ? MAX_SNIFF_BYTES : MAX_SYNC_BYTES; input.resetPeekPosition(); if (input.getPosition() == 0) { // We need to parse enough ID3 metadata to retrieve any gapless playback information even // if ID3 metadata parsing is disabled. boolean onlyDecodeGaplessInfoFrames = (flags & FLAG_DISABLE_ID3_METADATA) != 0; Id3Decoder.FramePredicate id3FramePredicate = onlyDecodeGaplessInfoFrames ? GaplessInfoHolder.GAPLESS_INFO_ID3_FRAME_PREDICATE : null; metadata = id3Peeker.peekId3Data(input, id3FramePredicate); if (metadata != null) { gaplessInfoHolder.setFromMetadata(metadata); } peekedId3Bytes = (int) input.getPeekPosition(); if (!sniffing) { input.skipFully(peekedId3Bytes); } } while (true) { if (!input.peekFully(scratch.data, 0, 4, validFrameCount > 0)) { // We reached the end of the stream but found at least one valid frame. break; } scratch.setPosition(0); int headerData = scratch.readInt(); int frameSize; if ((candidateSynchronizedHeaderData != 0 && !headersMatch(headerData, candidateSynchronizedHeaderData)) || (frameSize = MpegAudioHeader.getFrameSize(headerData)) == C.LENGTH_UNSET) { // The header doesn't match the candidate header or is invalid. Try the next byte offset. if (searchedBytes++ == searchLimitBytes) { if (!sniffing) { throw new ParserException("Searched too many bytes."); } return false; } validFrameCount = 0; candidateSynchronizedHeaderData = 0; if (sniffing) { input.resetPeekPosition(); input.advancePeekPosition(peekedId3Bytes + searchedBytes); } else { input.skipFully(1); } } else { // The header matches the candidate header and/or is valid. validFrameCount++; if (validFrameCount == 1) { MpegAudioHeader.populateHeader(headerData, synchronizedHeader); candidateSynchronizedHeaderData = headerData; } else if (validFrameCount == 4) { break; } input.advancePeekPosition(frameSize - 4); } } // Prepare to read the synchronized frame. if (sniffing) { input.skipFully(peekedId3Bytes + searchedBytes); } else { input.resetPeekPosition(); } synchronizedHeaderData = candidateSynchronizedHeaderData; return true; }
Example #26
Source File: HlsMediaChunk.java From MediaSDK with Apache License 2.0 | 4 votes |
private HlsMediaChunk( HlsExtractorFactory extractorFactory, DataSource mediaDataSource, DataSpec dataSpec, Format format, boolean mediaSegmentEncrypted, @Nullable DataSource initDataSource, @Nullable DataSpec initDataSpec, boolean initSegmentEncrypted, Uri playlistUrl, @Nullable List<Format> muxedCaptionFormats, int trackSelectionReason, @Nullable Object trackSelectionData, long startTimeUs, long endTimeUs, long chunkMediaSequence, int discontinuitySequenceNumber, boolean hasGapTag, boolean isMasterTimestampSource, TimestampAdjuster timestampAdjuster, @Nullable DrmInitData drmInitData, @Nullable Extractor previousExtractor, Id3Decoder id3Decoder, ParsableByteArray scratchId3Data, boolean shouldSpliceIn) { super( mediaDataSource, dataSpec, format, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkMediaSequence); this.mediaSegmentEncrypted = mediaSegmentEncrypted; this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.initDataSpec = initDataSpec; this.initDataSource = initDataSource; this.initDataLoadRequired = initDataSpec != null; this.initSegmentEncrypted = initSegmentEncrypted; this.playlistUrl = playlistUrl; this.isMasterTimestampSource = isMasterTimestampSource; this.timestampAdjuster = timestampAdjuster; this.hasGapTag = hasGapTag; this.extractorFactory = extractorFactory; this.muxedCaptionFormats = muxedCaptionFormats; this.drmInitData = drmInitData; this.previousExtractor = previousExtractor; this.id3Decoder = id3Decoder; this.scratchId3Data = scratchId3Data; this.shouldSpliceIn = shouldSpliceIn; uid = uidSource.getAndIncrement(); }
Example #27
Source File: HlsMediaChunk.java From Telegram with GNU General Public License v2.0 | 4 votes |
private HlsMediaChunk( HlsExtractorFactory extractorFactory, DataSource mediaDataSource, DataSpec dataSpec, Format format, boolean mediaSegmentEncrypted, DataSource initDataSource, @Nullable DataSpec initDataSpec, boolean initSegmentEncrypted, Uri playlistUrl, @Nullable List<Format> muxedCaptionFormats, int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs, long chunkMediaSequence, int discontinuitySequenceNumber, boolean hasGapTag, boolean isMasterTimestampSource, TimestampAdjuster timestampAdjuster, @Nullable DrmInitData drmInitData, @Nullable Extractor previousExtractor, Id3Decoder id3Decoder, ParsableByteArray scratchId3Data, boolean shouldSpliceIn) { super( mediaDataSource, dataSpec, format, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, chunkMediaSequence); this.mediaSegmentEncrypted = mediaSegmentEncrypted; this.discontinuitySequenceNumber = discontinuitySequenceNumber; this.initDataSource = initDataSource; this.initDataSpec = initDataSpec; this.initSegmentEncrypted = initSegmentEncrypted; this.playlistUrl = playlistUrl; this.isMasterTimestampSource = isMasterTimestampSource; this.timestampAdjuster = timestampAdjuster; this.hasGapTag = hasGapTag; this.extractorFactory = extractorFactory; this.muxedCaptionFormats = muxedCaptionFormats; this.drmInitData = drmInitData; this.previousExtractor = previousExtractor; this.id3Decoder = id3Decoder; this.scratchId3Data = scratchId3Data; this.shouldSpliceIn = shouldSpliceIn; initDataLoadRequired = initDataSpec != null; uid = uidSource.getAndIncrement(); }
Example #28
Source File: Id3Peeker.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public Id3Peeker() { scratch = new ParsableByteArray(Id3Decoder.ID3_HEADER_LENGTH); }