From 23090d2bd51ee8ba077fc563297efcaacef5eaff Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Thu, 15 Oct 2020 16:15:38 +0200 Subject: [PATCH] Added owner information --- src/zutil/parser/sdp/SDPParser.java | 17 ++++++- src/zutil/parser/sdp/SessionDescription.java | 33 +++++++------- test/zutil/parser/URLDecoderTest.java | 4 +- test/zutil/parser/sdp/SDPParserTest.java | 12 +++++ .../parser/sdp/SessionDescriptionTest.java | 45 ++++++++++++++----- 5 files changed, 79 insertions(+), 32 deletions(-) diff --git a/src/zutil/parser/sdp/SDPParser.java b/src/zutil/parser/sdp/SDPParser.java index 51b022a..b94ddd8 100644 --- a/src/zutil/parser/sdp/SDPParser.java +++ b/src/zutil/parser/sdp/SDPParser.java @@ -88,10 +88,10 @@ public class SDPParser { public List parse() throws IOException { List sessions = new ArrayList<>(); - String line; SessionDescription currentSession = null; TimingDescription currentTiming = null; MediaDescription currentMedia = null; + String line; String[] tmpArr; while ((line=IOUtil.readLine(in)) != null) { @@ -115,7 +115,20 @@ public class SDPParser { currentSession.protocolVersion = Integer.parseInt(getValue(line)); break; - // TODO: o=
+ // o=
+ case 'o': + if (currentSession == null) throw new RuntimeException("Received session owner before session definition: '" + line + "'"); + + tmpArr = getValueArray(line); + if (tmpArr.length != 6) throw new RuntimeException("Incorrect owner definition found: '" + line + "'"); + + currentSession.sessionOwner = tmpArr[0]; + currentSession.sessionId = Long.parseLong(tmpArr[1]); + currentSession.sessionAnnouncementVersion = Long.parseLong(tmpArr[2]); + currentSession.ownerNetworkType = tmpArr[3]; + currentSession.ownerAddressType = tmpArr[4]; + currentSession.ownerAddress = tmpArr[5]; + break; // s= case 's': diff --git a/src/zutil/parser/sdp/SessionDescription.java b/src/zutil/parser/sdp/SessionDescription.java index c092397..ae82359 100644 --- a/src/zutil/parser/sdp/SessionDescription.java +++ b/src/zutil/parser/sdp/SessionDescription.java @@ -12,11 +12,11 @@ public class SessionDescription { protected int protocolVersion; protected String sessionOwner; - protected String sessionId; - protected String sessionVersion; - protected String networkType; - protected String addressType; - protected String address; + protected long sessionId; + protected long sessionAnnouncementVersion; + protected String ownerNetworkType = "IN"; + protected String ownerAddressType = "IP4"; // IP4 or IP6 + protected String ownerAddress; protected String sessionTitle; protected String sessionDescription; @@ -40,24 +40,24 @@ public class SessionDescription { return sessionOwner; } - public String getSessionId() { + public long getSessionId() { return sessionId; } - public String getSessionVersion() { - return sessionVersion; + public long getAnnouncementVersion() { + return sessionAnnouncementVersion; } - public String getNetworkType() { - return networkType; + public String getOwnerNetworkType() { + return ownerNetworkType; } - public String getAddressType() { - return addressType; + public String getOwnerAddressType() { + return ownerAddressType; } - public String getAddress() { - return address; + public String getOwnerAddress() { + return ownerAddress; } public String getSessionTitle() { @@ -93,8 +93,9 @@ public class SessionDescription { StringBuffer output = new StringBuffer(); output.append("v=").append(protocolVersion).append('\n'); - // TODO: o=
- output.append("s=").append(sessionTitle).append('\n');; + output.append("o=").append(sessionOwner).append(' ').append(sessionId).append(' ').append(sessionAnnouncementVersion) + .append(' ').append(ownerNetworkType).append(' ').append(ownerAddressType).append(' ').append(ownerAddress).append('\n'); + output.append("s=").append(sessionTitle).append('\n'); if (sessionDescription != null) output.append("i=").append(sessionDescription).append('\n'); if (sessionURI != null) output.append("u=").append(sessionURI).append('\n'); diff --git a/test/zutil/parser/URLDecoderTest.java b/test/zutil/parser/URLDecoderTest.java index 7d81ee2..653530b 100755 --- a/test/zutil/parser/URLDecoderTest.java +++ b/test/zutil/parser/URLDecoderTest.java @@ -56,7 +56,7 @@ public class URLDecoderTest { @Test public void percentMultibyteTest() throws UnsupportedEncodingException { - assertEquals("Ängen", java.net.URLDecoder.decode("%C3%84ngen", "UTF-8")); - assertEquals("Ängen", URLDecoder.decode("%C3%84ngen")); + assertEquals("Ängen", java.net.URLDecoder.decode("%C3%84ngen", "UTF-8")); + assertEquals("Ängen", URLDecoder.decode("%C3%84ngen")); } } diff --git a/test/zutil/parser/sdp/SDPParserTest.java b/test/zutil/parser/sdp/SDPParserTest.java index 68931a9..2969bd2 100644 --- a/test/zutil/parser/sdp/SDPParserTest.java +++ b/test/zutil/parser/sdp/SDPParserTest.java @@ -66,10 +66,22 @@ public class SDPParserTest { assertEquals(1, sessions.size()); SessionDescription session = sessions.get(0); + // v= assertEquals(0, session.getProtocolVersion()); + // o= + assertEquals("mhandley", session.getSessionOwner()); + assertEquals(2890844526l, session.getSessionId()); + assertEquals(2890842807l, session.getAnnouncementVersion()); + assertEquals("IN", session.getOwnerNetworkType()); + assertEquals("IP4", session.getOwnerAddressType()); + assertEquals("126.16.64.4", session.getOwnerAddress()); + // s= assertEquals("SDP Seminar", session.getSessionTitle()); + // i= assertEquals("A Seminar on the session description protocol", session.getSessionDescription()); + // u= assertEquals("http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps", session.getSessionURI()); + // e= assertEquals("mjh@isi.edu (Mark Handley)", session.getOrganizerEmail()); } diff --git a/test/zutil/parser/sdp/SessionDescriptionTest.java b/test/zutil/parser/sdp/SessionDescriptionTest.java index d38362e..d3c64aa 100644 --- a/test/zutil/parser/sdp/SessionDescriptionTest.java +++ b/test/zutil/parser/sdp/SessionDescriptionTest.java @@ -26,7 +26,7 @@ package zutil.parser.sdp; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class SessionDescriptionTest { @@ -46,9 +46,7 @@ public class SessionDescriptionTest { // TODO: [optional] k=: // Encryption information // TODO: [optional] a=: - // -------------------------------------- - // Media description - // -------------------------------------- + @Test public void basicSession() { @@ -56,8 +54,28 @@ public class SessionDescriptionTest { session.protocolVersion = 0; session.sessionTitle = "SDP Seminar"; - assertEquals(session.toString(), "v=0\n" + - "s=SDP Seminar" + assertEquals("v=0\n" + + "o=null 0 0 IN IP4 null\n" + + "s=SDP Seminar", + session.toString() + ); + } + + @Test + public void basicOwner() { + SessionDescription session = new SessionDescription(); + session.protocolVersion = 0; + session.sessionTitle = "SDP Seminar"; + + session.sessionOwner = "mhandley"; + session.sessionId = 2890844526l; + session.sessionAnnouncementVersion = 2890842807l; + session.ownerAddress = "126.16.64.4"; + + assertEquals("v=0\n" + + "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\n" + + "s=SDP Seminar", + session.toString() ); } @@ -72,9 +90,11 @@ public class SessionDescriptionTest { session.sessionTitle = "SDP Seminar"; session.timings.add(timing); - assertEquals(session.toString(), "v=0\n" + - "s=SDP Seminar\n" + - "t=2873397496 2873404696" + assertEquals("v=0\n" + + "o=null 0 0 IN IP4 null\n" + + "s=SDP Seminar\n" + + "t=2873397496 2873404696", + session.toString() ); } @@ -91,11 +111,12 @@ public class SessionDescriptionTest { session.sessionTitle = "SDP Seminar"; session.media.add(media); - assertEquals(session.toString(), "v=0\n" + + assertEquals("v=0\n" + + "o=null 0 0 IN IP4 null\n" + "s=SDP Seminar\n" + "m=video 51372 RTP/AVP\n" + - "i=main video feed" + "i=main video feed", + session.toString() ); } - } \ No newline at end of file