public static PayloadTypePacketExtension formatToPayloadType(
MediaFormat format,
DynamicPayloadTypeRegistry ptRegistry,
int payloadId)
{
PayloadTypePacketExtension ptExt = new PayloadTypePacketExtension();
int payloadType = format.getRTPPayloadType();
if (payloadType == MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN) {
if( payloadId != MediaFormat.RTP_PAYLOAD_TYPE_UNKNOWN )
payloadType = payloadId;
else
payloadType = ptRegistry.obtainPayloadTypeNumber(format);
}
ptExt.setId(payloadType);
ptExt.setName(format.getEncoding());
if(format instanceof AudioMediaFormat)
ptExt.setChannels(((AudioMediaFormat)format).getChannels());
ptExt.setClockrate((int)format.getClockRate());
/*
* Add the format parameters and the advanced attributes (as parameter
* packet extensions).
*/
for(Map.Entry<String, String> entry :
format.getFormatParameters().entrySet())
{
ParameterPacketExtension ext = new ParameterPacketExtension();
ext.setName(entry.getKey());
ext.setValue(entry.getValue());
ptExt.addParameter(ext);
}
for(Map.Entry<String, String> entry :
format.getAdvancedAttributes().entrySet())
{
ParameterPacketExtension ext = new ParameterPacketExtension();
ext.setName(entry.getKey());
ext.setValue(entry.getValue());
ptExt.addParameter(ext);
}
return ptExt;
}