Example #1
0
  /**
   * Creates a new, empty SessionDescription. The session is set as follows:
   *
   * <p>v=0
   *
   * <p>o=this.createOrigin ("user", InetAddress.getLocalHost().toString());
   *
   * <p>s=-
   *
   * <p>t=0 0
   *
   * @throws SdpException SdpException, - if there is a problem constructing the SessionDescription.
   * @return a new, empty SessionDescription.
   */
  public SessionDescription createSessionDescription() throws SdpException {
    SessionDescriptionImpl sessionDescriptionImpl = new SessionDescriptionImpl();

    ProtoVersionField ProtoVersionField = new ProtoVersionField();
    ProtoVersionField.setVersion(0);
    sessionDescriptionImpl.setVersion(ProtoVersionField);

    OriginField originImpl = null;
    try {
      originImpl =
          (OriginField) this.createOrigin("user", InetAddress.getLocalHost().getHostAddress());
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
    sessionDescriptionImpl.setOrigin(originImpl);

    SessionNameField sessionNameImpl = new SessionNameField();
    sessionNameImpl.setValue("-");
    sessionDescriptionImpl.setSessionName(sessionNameImpl);

    TimeDescriptionImpl timeDescriptionImpl = new TimeDescriptionImpl();
    TimeField timeImpl = new TimeField();
    timeImpl.setZero();
    timeDescriptionImpl.setTime(timeImpl);
    Vector times = new Vector();
    times.addElement(timeDescriptionImpl);
    sessionDescriptionImpl.setTimeDescriptions(times);

    sessionDescriptionsList.addElement(sessionDescriptionImpl);
    return sessionDescriptionImpl;
  }
Example #2
0
  public static void main(String[] args) throws SdpParseException, SdpException {
    String sdpFields =
        "v=0\r\n"
            + "o=4855 13760799956958020 13760799956958020 IN IP4 166.35.224.216\r\n"
            + "s=nortelnetworks\r\n"
            + "p=+1 972 684 1000\r\n"
            + "c=IN IP4 166.35.224.216\r\n"
            + "t=0 0\r\n"
            + "m=audio 50006 RTP/AVP 0 8 4 18\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n"
            + "a=rtpmap:8 PCMA/8000\r\n"
            + "a=rtpmap:4 G723/8000\r\n"
            + "a=rtpmap:18 G729A/8000\r\n"
            + "a=ptime:30\r\n";
    SdpFactory sdpFactory = new SdpFactory();
    SessionDescription sessionDescription = sdpFactory.createSessionDescription(sdpFields);

    System.out.println("sessionDescription = " + sessionDescription);
    Vector mediaDescriptions = sessionDescription.getMediaDescriptions(true);
    for (int i = 0; i < mediaDescriptions.size(); i++) {
      MediaDescription m = (MediaDescription) mediaDescriptions.elementAt(i);
      System.out.println("m = " + m.toString());
      Media media = m.getMedia();
      Vector formats = media.getMediaFormats(false);
      System.out.println("formats = " + formats);
    }
  }
Example #3
0
  /**
   * Returns MediaDescription object with the specified properties. The returned object will respond
   * to Media.getMediaFormats(boolean) with a Vector of String objects specified by the 'formats
   * argument.
   *
   * @param media the media type, eg "audio"
   * @param port port number on which to receive media
   * @param numPorts number of ports used for this media stream
   * @param transport transport type, eg "RTP/AVP"
   * @param formats list of formats which should be specified by the returned MediaDescription
   * @return MediaDescription
   */
  public MediaDescription createMediaDescription(
      String media, int port, int numPorts, String transport, String[] formats) {
    MediaDescriptionImpl mediaDescriptionImpl = new MediaDescriptionImpl();
    try {

      MediaField mediaImpl = new MediaField();
      mediaImpl.setMediaType(media);
      mediaImpl.setMediaPort(port);
      mediaImpl.setPortCount(numPorts);
      mediaImpl.setProtocol(transport);

      Vector formatsV = new Vector(formats.length);
      for (int i = 0; i < formats.length; i++) formatsV.add(formats[i]);
      mediaImpl.setMediaFormats(formatsV);
      mediaDescriptionImpl.setMedia(mediaImpl);
    } catch (SdpException s) {
      s.printStackTrace();
    }
    return mediaDescriptionImpl;
  }