Search in sources :

Example 1 with PATSection

use of org.taktik.mpegts.PATSection in project alliance by codice.

the class MpegTsDecoderImpl method handleProgramAssociationTable.

private void handleProgramAssociationTable(MTSPacket mtsPacket) throws IOException {
    final ByteBuffer payload = mtsPacket.getPayload();
    final int pointer = payload.get() & BYTE_MASK;
    payload.position(payload.position() + pointer);
    final PATSection programAssociationTable = patSectionParser.parse(payload);
    programMapTablePacketIdDirectory.clear();
    programMapTablePacketIdDirectory.addAll(programAssociationTable.getPrograms().values());
    if (programMapTablePacketIdDirectory.isEmpty()) {
        throw new IOException("No programs found in transport stream.");
    }
}
Also used : IOException(java.io.IOException) PATSection(org.taktik.mpegts.PATSection) ByteBuffer(java.nio.ByteBuffer)

Example 2 with PATSection

use of org.taktik.mpegts.PATSection in project alliance by codice.

the class MpegTsDecoderTest method testRead.

@Test
public void testRead() {
    MTSUtils.StreamType streamType = MTSUtils.StreamType.VIDEO_H264;
    byte expectedByte1 = 0x01;
    byte expectedByte2 = 0x02;
    byte expectedByte3 = 0x03;
    byte expectedByte4 = 0x04;
    int programMapTableId = 1;
    int videoPacketId = 2;
    MpegTsDecoderImpl decoder = new MpegTsDecoderImpl();
    PATSection patSection = mock(PATSection.class);
    when(patSection.getPrograms()).thenReturn(Collections.singletonMap(1, programMapTableId));
    MpegTsDecoderImpl.PATSectionParser patSectionParser = mock(MpegTsDecoderImpl.PATSectionParser.class);
    when(patSectionParser.parse(any())).thenReturn(patSection);
    decoder.setPatSectionParser(patSectionParser);
    MTSPacket programAssociationTablePacket = mock(MTSPacket.class);
    when(programAssociationTablePacket.getPid()).thenReturn(Constants.PROGRAM_ASSOCIATION_TABLE_PID);
    when(programAssociationTablePacket.isPayloadUnitStartIndicator()).thenReturn(true);
    when(programAssociationTablePacket.getPayload()).thenReturn(ByteBuffer.wrap(new byte[] { 0x00 }));
    PMTSection.PMTStream pmtStream = mock(PMTSection.PMTStream.class);
    when(pmtStream.getStreamType()).thenReturn(streamType);
    when(pmtStream.getPid()).thenReturn(videoPacketId);
    PMTSection pmtSection = mock(PMTSection.class);
    when(pmtSection.getStreams()).thenReturn(new PMTSection.PMTStream[] { pmtStream });
    MpegTsDecoderImpl.PMTSectionParser pmtSectionParser = mock(MpegTsDecoderImpl.PMTSectionParser.class);
    when(pmtSectionParser.parse(any())).thenReturn(pmtSection);
    decoder.setPmtSectionParser(pmtSectionParser);
    MTSPacket programMapTablePacket = mock(MTSPacket.class);
    when(programMapTablePacket.getPid()).thenReturn(programMapTableId);
    when(programMapTablePacket.isPayloadUnitStartIndicator()).thenReturn(true);
    when(programMapTablePacket.getPayload()).thenReturn(ByteBuffer.wrap(new byte[] { 0x00 }));
    MTSPacket elementaryStreamPacket1 = createElementary(true, videoPacketId, expectedByte1);
    MTSPacket elementaryStreamPacket2 = createElementary(false, videoPacketId, expectedByte2);
    MTSPacket elementaryStreamPacket3 = createElementary(false, videoPacketId, expectedByte3);
    MTSPacket elementaryStreamPacket4 = createElementary(false, videoPacketId, expectedByte4);
    MTSPacket elementaryStreamPacket5 = createElementary(true, videoPacketId, (byte) 0x00);
    List<Object> outputList = new LinkedList<>();
    Stream.of(programAssociationTablePacket, programMapTablePacket, elementaryStreamPacket1, elementaryStreamPacket2, elementaryStreamPacket3, elementaryStreamPacket4, elementaryStreamPacket5).forEach(mtsPacket -> {
        try {
            decoder.read(mtsPacket, outputList::add);
        } catch (IOException e) {
            fail();
        }
    });
    assertThat(outputList, hasSize(1));
    assertThat(outputList.get(0), is(instanceOf(PESPacket.class)));
    PESPacket pesPacket = (PESPacket) outputList.get(0);
    assertThat(pesPacket.getPacketId(), is(videoPacketId));
    assertThat(pesPacket.getStreamType(), is(MpegStreamType.lookup(streamType)));
    assertThat(pesPacket.getPayload(), is(new byte[] { expectedByte1, expectedByte2, expectedByte3, expectedByte4 }));
}
Also used : MTSUtils(org.jcodec.containers.mps.MTSUtils) IOException(java.io.IOException) LinkedList(java.util.LinkedList) MTSPacket(org.taktik.mpegts.MTSPacket) PATSection(org.taktik.mpegts.PATSection) PMTSection(org.jcodec.containers.mps.psi.PMTSection) Test(org.junit.Test)

Example 3 with PATSection

use of org.taktik.mpegts.PATSection in project ddf by codice.

the class MpegTransportStreamMetadataExtractor method getProgramAssociationTable.

private void getProgramAssociationTable(final MTSPacket packet) throws JCodecException {
    final ByteBuffer payload = packet.getPayload();
    final int pointer = payload.get() & 0xff;
    payload.position(payload.position() + pointer);
    final PATSection programAssociationTable = PATSection.parse(payload);
    if (programAssociationTable == null) {
        throw new JCodecException("Program association table does not exist.");
    }
    programMapTablePacketIdDirectory.addAll(programAssociationTable.getPrograms().values());
    if (programMapTablePacketIdDirectory.isEmpty()) {
        throw new JCodecException("No programs found in transport stream.");
    }
}
Also used : JCodecException(org.jcodec.api.JCodecException) PATSection(org.taktik.mpegts.PATSection) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PATSection (org.taktik.mpegts.PATSection)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 LinkedList (java.util.LinkedList)1 JCodecException (org.jcodec.api.JCodecException)1 MTSUtils (org.jcodec.containers.mps.MTSUtils)1 PMTSection (org.jcodec.containers.mps.psi.PMTSection)1 Test (org.junit.Test)1 MTSPacket (org.taktik.mpegts.MTSPacket)1