Java Code Examples for com.google.android.exoplayer2.util.NalUnitUtil#findNalUnit()
The following examples show how to use
com.google.android.exoplayer2.util.NalUnitUtil#findNalUnit() .
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: H264Reader.java From MediaSDK with Apache License 2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 2
Source File: H265Reader.java From MediaSDK with Apache License 2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }
Example 3
Source File: H264Reader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 4
Source File: H265Reader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }
Example 5
Source File: H264Reader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 6
Source File: H265Reader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }
Example 7
Source File: H262Reader.java From K-Sonic with MIT License | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); int searchOffset = offset; while (true) { int startCodeOffset = NalUnitUtil.findNalUnit(dataArray, searchOffset, limit, prefixFlags); if (startCodeOffset == limit) { // We've scanned to the end of the data without finding another start code. if (!hasOutputFormat) { csdBuffer.onData(dataArray, offset, limit); } return; } // We've found a start code with the following value. int startCodeValue = data.data[startCodeOffset + 3] & 0xFF; if (!hasOutputFormat) { // This is the number of bytes from the current offset to the start of the next start // code. It may be negative if the start code started in the previously consumed data. int lengthToStartCode = startCodeOffset - offset; if (lengthToStartCode > 0) { csdBuffer.onData(dataArray, offset, startCodeOffset); } // This is the number of bytes belonging to the next start code that have already been // passed to csdDataTargetBuffer. int bytesAlreadyPassed = lengthToStartCode < 0 ? -lengthToStartCode : 0; if (csdBuffer.onStartCode(startCodeValue, bytesAlreadyPassed)) { // The csd data is complete, so we can decode and output the media format. Pair<Format, Long> result = parseCsdBuffer(csdBuffer, formatId); output.format(result.first); frameDurationUs = result.second; hasOutputFormat = true; } } if (hasOutputFormat && (startCodeValue == START_GROUP || startCodeValue == START_PICTURE)) { int bytesWrittenPastStartCode = limit - startCodeOffset; if (foundFirstFrameInGroup) { @C.BufferFlags int flags = isKeyframe ? C.BUFFER_FLAG_KEY_FRAME : 0; int size = (int) (totalBytesWritten - framePosition) - bytesWrittenPastStartCode; output.sampleMetadata(frameTimeUs, flags, size, bytesWrittenPastStartCode, null); isKeyframe = false; } if (startCodeValue == START_GROUP) { foundFirstFrameInGroup = false; isKeyframe = true; } else /* startCodeValue == START_PICTURE */ { frameTimeUs = pesPtsUsAvailable ? pesTimeUs : (frameTimeUs + frameDurationUs); framePosition = totalBytesWritten - bytesWrittenPastStartCode; pesPtsUsAvailable = false; foundFirstFrameInGroup = true; } } offset = startCodeOffset; searchOffset = offset + 3; } }
Example 8
Source File: H264Reader.java From K-Sonic with MIT License | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 9
Source File: H265Reader.java From K-Sonic with MIT License | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }
Example 10
Source File: H264Reader.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 11
Source File: H265Reader.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }
Example 12
Source File: H264Reader.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (true) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getNalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } }
Example 13
Source File: H265Reader.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public void consume(ParsableByteArray data) { while (data.bytesLeft() > 0) { int offset = data.getPosition(); int limit = data.limit(); byte[] dataArray = data.data; // Append the data to the buffer. totalBytesWritten += data.bytesLeft(); output.sampleData(data, data.bytesLeft()); // Scan the appended data, processing NAL units as they are encountered while (offset < limit) { int nalUnitOffset = NalUnitUtil.findNalUnit(dataArray, offset, limit, prefixFlags); if (nalUnitOffset == limit) { // We've scanned to the end of the data without finding the start of another NAL unit. nalUnitData(dataArray, offset, limit); return; } // We've seen the start of a NAL unit of the following type. int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset); // This is the number of bytes from the current offset to the start of the next NAL unit. // It may be negative if the NAL unit started in the previously consumed data. int lengthToNalUnit = nalUnitOffset - offset; if (lengthToNalUnit > 0) { nalUnitData(dataArray, offset, nalUnitOffset); } int bytesWrittenPastPosition = limit - nalUnitOffset; long absolutePosition = totalBytesWritten - bytesWrittenPastPosition; // Indicate the end of the previous NAL unit. If the length to the start of the next unit // is negative then we wrote too many bytes to the NAL buffers. Discard the excess bytes // when notifying that the unit has ended. endNalUnit(absolutePosition, bytesWrittenPastPosition, lengthToNalUnit < 0 ? -lengthToNalUnit : 0, pesTimeUs); // Indicate the start of the next NAL unit. startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs); // Continue scanning the data. offset = nalUnitOffset + 3; } } }