package net.sf.fmj.media.rtp.util;

import java.io.*;

public class RTPPacketParser
{
    public RTPPacket parse(Packet packet) throws BadFormatException
    {
        RTPPacket rtppacket = new RTPPacket(packet);
        DataInputStream datainputstream = new DataInputStream(
                new ByteArrayInputStream(((Packet) (rtppacket)).data,
                        ((Packet) (rtppacket)).offset,
                        ((Packet) (rtppacket)).length));
        try
        {
            int firstByte = datainputstream.readUnsignedByte();
            if ((firstByte & 0xc0) != 128)
                throw new BadFormatException();
            if ((firstByte & 0x10) != 0)
                rtppacket.extensionPresent = true;
            int paddingLength = 0;
            if ((firstByte & 0x20) != 0)
                paddingLength = ((Packet) (rtppacket)).data[(((Packet) (rtppacket)).offset + ((Packet) (rtppacket)).length) - 1] & 0xff;
            firstByte &= 0xf;
            rtppacket.payloadType = datainputstream.readUnsignedByte();
            rtppacket.marker = rtppacket.payloadType >> 7;
            rtppacket.payloadType &= 0x7f;
            rtppacket.seqnum = datainputstream.readUnsignedShort();
            rtppacket.timestamp = datainputstream.readInt() & 0xffffffffL;
            rtppacket.ssrc = datainputstream.readInt();
            int offset = 0;
            rtppacket.csrc = new int[firstByte];
            for (int i1 = 0; i1 < rtppacket.csrc.length; i1++)
                rtppacket.csrc[i1] = datainputstream.readInt();

            offset += 12 + (rtppacket.csrc.length << 2);
            if (rtppacket.extensionPresent)
            {
                rtppacket.extensionType = datainputstream.readUnsignedShort();
                int l = datainputstream.readUnsignedShort();
                l <<= 2;
                rtppacket.extension = new byte[l];
                datainputstream.readFully(rtppacket.extension);
                offset += l + 4;
            }
            rtppacket.payloadlength = ((Packet) (rtppacket)).length - (offset + paddingLength);
            if (rtppacket.payloadlength < 0)
                throw new BadFormatException();
            rtppacket.payloadoffset = offset + ((Packet) (rtppacket)).offset;
        } catch (EOFException eofexception)
        {
            throw new BadFormatException("Unexpected end of RTP packet");
        } catch (IOException ioexception)
        {
            throw new IllegalArgumentException("Impossible Exception");
        }
        return rtppacket;
    }
}

@@ -309,27 +309,16 @@
 utStream
-(((Packet) 
 (rtppack
@@ -315,26 +315,24 @@
 am(rtppacket
-))
 .data,%0A     
@@ -346,35 +346,24 @@
             
-((Packet) (
 rtppacket)).
@@ -355,26 +355,24 @@
    rtppacket
-))
 .offset,%0A   
@@ -392,27 +392,16 @@
         
-((Packet) (
 rtppacke
@@ -393,34 +393,32 @@
        rtppacket
-))
 .length));%0A     
@@ -785,35 +785,24 @@
 ingLength = 
-((Packet) (
 rtppacket)).
@@ -802,28 +802,14 @@
 cket
-))
 .data%5B
-(((Packet) (
 rtpp
@@ -809,26 +809,24 @@
 ta%5Brtppacket
-))
 .offset + ((
@@ -819,35 +819,24 @@
 et.offset + 
-((Packet) (
 rtppacket)).
@@ -836,18 +836,15 @@
 cket
-))
 .length
-)
  - 1
@@ -1941,27 +1941,16 @@
 ength = 
-((Packet) (
 rtppacke
@@ -1950,18 +1950,16 @@
 tppacket
-))
 .length 
@@ -2130,19 +2130,8 @@
 t + 
-((Packet) (
 rtpp
@@ -2135,18 +2135,16 @@
 tppacket
-))
 .offset;

Simplifies source code.