@Override
    public String toString() {
        StringBuffer buf = new StringBuffer();
        buf.append(RFC4566.TYPE_MEDIA).append(RFC4566.SEPARATOR);
        buf.append(type).append(" ").append(port);
        buf.append(" RTP/AVP");
        for (Codec codec: codecs) {
            buf.append(" ");
            buf.append(codec.getPayloadType());
        }
        buf.append("\r\n");
        if (ipAddress != null) {
            int ipVersion;
            if (ipAddress instanceof Inet4Address) {
                ipVersion = 4;
            } else if (ipAddress instanceof Inet6Address) {
                ipVersion = 6;
            } else {
                throw new RuntimeException("unknown ip version: " + ipAddress);
            }
            buf.append(RFC4566.TYPE_CONNECTION).append(RFC4566.SEPARATOR);
            buf.append("IN IP").append(ipVersion).append(" ");
            buf.append(ipAddress.getHostAddress()).append("\r\n");
        }
        for (Codec codec: codecs) {
            buf.append(codec.toString());
        }
        if (attributes != null) {
            for (String attributeName: attributes.keySet()) {
                buf.append(RFC4566.TYPE_ATTRIBUTE).append(RFC4566.SEPARATOR);
                buf.append(attributeName);
                String attributeValue = attributes.get(attributeName);
                if (attributeValue != null && !"".equals(attributeValue.trim())) {
                    buf.append(":").append(attributeValue);
                }
                buf.append("\r\n");
            }
        }
        return buf.toString();
    }