@Override public boolean sniff(ExtractorInput input) throws IOException, InterruptedException { scratch.peek(input, 2); int packetType = scratch.getU16(); return (packetType == Connection.XVDR_STREAM_CHANGE || packetType == Connection.XVDR_STREAM_MUXPKT); }
@Override public synchronized int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException { // read packet header // messageId uint16 2 bytes // frameType uint16 2 bytes // length uint32 4 bytes scratch.read(input, 4); int messageId = scratch.getU16(); int frameType = scratch.getU16(); // check for format packet if (messageId == Connection.XVDR_STREAM_CHANGE) { Log.d(TAG, "stream change packet received"); scratch.peek(input, 512); updateStreamReaders(scratch); int bytesRead = scratch.position(); Log.d(TAG, "skipping " + bytesRead + " bytes (stream change packet)"); input.skipFully(bytesRead); // reset position reference position.reset(); return RESULT_CONTINUE; } // exit if we didn't receive a stream packet if (messageId != Connection.XVDR_STREAM_MUXPKT) { Log.d(TAG, "unknown message id: " + messageId); return RESULT_CONTINUE; } // read stream packet header // pid uint16 2 bytes // pts int64 8 bytes // dts int64 8 bytes // duration uint32 4 bytes // length uint32 4 bytes scratch.read(input, 26); int pid = scratch.getU16(); long pts = scratch.getS64(); long dts = scratch.getS64(); scratch.getU32(); int size = (int) scratch.getU32(); // size of encapsulated stream data StreamReader reader = streamManager.get(pid); // unknown stream ? if (reader == null) { input.skipFully(size); input.skipFully(8); return RESULT_CONTINUE; } // convert TS -> timeUs long timeUs = position.adjustTimestamp(pts); // consume stream data reader.consume(input, size, timeUs, C.BUFFER_FLAG_KEY_FRAME); // get current position // position uint64 8 bytes scratch.read(input, 8); long pos = scratch.getU64(); // sanity check if position is within the range if (position.getStartPosition() < pos && pos < position.getEndPosition()) { position.set(timeUs, pos); } return RESULT_CONTINUE; }