MediaDescription.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. This file is part of Peers, a java SIP softphone.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. Copyright 2007, 2008, 2009, 2010 Yohann Martineau
  14. */
  15. package com.genersoft.iot.vmp.gb28181.sdp;
  16. import java.net.Inet4Address;
  17. import java.net.Inet6Address;
  18. import java.net.InetAddress;
  19. import java.util.Hashtable;
  20. import java.util.List;
  21. public class MediaDescription {
  22. private String type;
  23. private InetAddress ipAddress;
  24. // attributes not codec-related
  25. private Hashtable<String, String> attributes;
  26. private int port;
  27. private List<Codec> codecs;
  28. public String getType() {
  29. return type;
  30. }
  31. public void setType(String type) {
  32. this.type = type;
  33. }
  34. public Hashtable<String, String> getAttributes() {
  35. return attributes;
  36. }
  37. public void setAttributes(Hashtable<String, String> attributes) {
  38. this.attributes = attributes;
  39. }
  40. public InetAddress getIpAddress() {
  41. return ipAddress;
  42. }
  43. public void setIpAddress(InetAddress ipAddress) {
  44. this.ipAddress = ipAddress;
  45. }
  46. public int getPort() {
  47. return port;
  48. }
  49. public void setPort(int port) {
  50. this.port = port;
  51. }
  52. public List<Codec> getCodecs() {
  53. return codecs;
  54. }
  55. public void setCodecs(List<Codec> codecs) {
  56. this.codecs = codecs;
  57. }
  58. @Override
  59. public String toString() {
  60. StringBuffer buf = new StringBuffer();
  61. buf.append(RFC4566_28181.TYPE_MEDIA).append(RFC4566_28181.SEPARATOR);
  62. buf.append(type).append(" ").append(port);
  63. buf.append(" RTP/AVP");
  64. if (codecs != null) {
  65. for (Codec codec: codecs) {
  66. buf.append(" ");
  67. buf.append(codec.getPayloadType());
  68. }
  69. buf.append("\r\n");
  70. }
  71. if (ipAddress != null) {
  72. int ipVersion;
  73. if (ipAddress instanceof Inet4Address) {
  74. ipVersion = 4;
  75. } else if (ipAddress instanceof Inet6Address) {
  76. ipVersion = 6;
  77. } else {
  78. throw new RuntimeException("unknown ip version: " + ipAddress);
  79. }
  80. buf.append(RFC4566_28181.TYPE_CONNECTION).append(RFC4566_28181.SEPARATOR);
  81. buf.append("IN IP").append(ipVersion).append(" ");
  82. buf.append(ipAddress.getHostAddress()).append("\r\n");
  83. }
  84. if (codecs != null) {
  85. for (Codec codec: codecs) {
  86. buf.append(codec.toString());
  87. }
  88. }
  89. if (attributes != null) {
  90. for (String attributeName: attributes.keySet()) {
  91. buf.append(RFC4566_28181.TYPE_ATTRIBUTE).append(RFC4566_28181.SEPARATOR);
  92. buf.append(attributeName);
  93. String attributeValue = attributes.get(attributeName);
  94. if (attributeValue != null && !"".equals(attributeValue.trim())) {
  95. buf.append(":").append(attributeValue);
  96. }
  97. buf.append("\r\n");
  98. }
  99. }
  100. return buf.toString();
  101. }
  102. }