2017-05-18 14 views
0

현재 연결을 설정하기 위해 SDP 메시지를 사용하는 응용 프로그램에서 작업 중입니다. 필자가해야 할 일은 SDP 메시지의 문자열 표현을위한 파서 (parser)를 생성하고 정보를 나타내는 일종의 구조를 생성하고 기존 구조에서 그러한 메시지를 생성하는 것입니다. RFC 4566에서 Java에서 SDP 메시지 문자열 구문 분석

:

v=0 
    o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5 
    s=SDP Seminar 
    i=A Seminar on the session description protocol 
    u=http://www.example.com/seminars/sdp.pdf 
    [email protected] (Jane Doe) 
    c=IN IP4 224.2.17.12/127 
    t=2873397496 2873404696 
    a=recvonly 
    m=audio 49170 RTP/AVP 0 
    m=video 51372 RTP/AVP 99 
    a=rtpmap:99 h263-1998/90000 

내 질문은 : 는 메시지를 구문 분석하는 자바 도구의 모든 빌드가 있습니까? github에 대한 몇 가지 예를 보았습니다. 그러나 주제에 익숙하지 않아서 어떤 솔루션이 그러한 작업에 가장 적합한 지 결정할 수 없습니다.

답변

1

예, Java에는 Jain SIP라는 기본 제공 SIP 기능이 있습니다. 그것은 미디어 부분에 매우 약하며 (좋은 코덱 지원이 없음) 신호 처리를 위해서는 사용자의 요구를 충족시켜야합니다.

예 :

import javax.sdp.*; 
import javax.sip.*; 

ContentTypeHeader contentType = (ContentTypeHeader) msg.getHeader(ContentTypeHeader.NAME); 
ContentLengthHeader contentLen = (ContentLengthHeader) msg.getHeader(ContentLengthHeader.NAME); 

if (contentLen.getContentLength() > 0 && contentType.getContentSubType().equals("sdp")){ 
    String charset = null; 

    if (contentType != null) 
     charset = contentType.getParameter("charset"); 
    if (charset == null) 
     charset = "UTF-8"; // RFC 3261 

    //Save the SDP content in a String 
    byte[] rawContent = msg.getRawContent(); 
    String sdpContent = new String(rawContent, charset); 

    //Use the static method of SdpFactory to parse the content 
    SdpFactory sdpFactory = SdpFactory.getInstance(); 
    SessionDescription sessionDescription = sdpFactory.createSessionDescription(sdpContent); 
    Origin origin = sessionDescription.getOrigin(); 

    System.out.println("A Session ID is " + origin.getSessionId()); 
} else { 
    System.out.println("It is not a SDP content"); 
} 

이 마음에 들지 않으면, 바로 그러한 jain sip 또는 jsdp 같은 오픈 소스 SDP 파서를 사용합니다.

또한 SDP 구문 분석은 RFC 4566에 따라 손쉽게 수행 할 수 있습니다. SDP 구문 분석은 실제로 간단하며 작은 문자열 조작으로 수행 할 수 있습니다.

+0

답장을 보내 주셔서 감사합니다. 내가 걱정하는 것은 내가 좋은 미디어 지원이 필요하다는 것입니다. 내가 SIP를 사용하지 않기 때문에 SDP만이 관심을 가지며, 당신이 언급 한 라이브러리는 몇 년 (상당히 오래되었습니다)입니다. 그것이 문제가 될 것이라고 생각합니까? –

+1

좋은 미디어 지원을 찾으려면 [this java sip client] (https://www.mizu-voip.com/Software/Softphones/JVoIP.aspx)를보십시오. SIP 클라이언트를 사용할 준비가되었지만 보내거나받은 메시지 (SDP 포함)를 조작하거나 SDP에 더 많은 액세스가 필요한 경우 개발자에게 요청할 수 있습니다. –