Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdp file parsing failed #44

Closed
autoexpect opened this issue Mar 24, 2020 · 7 comments · Fixed by #46
Closed

sdp file parsing failed #44

autoexpect opened this issue Mar 24, 2020 · 7 comments · Fixed by #46

Comments

@autoexpect
Copy link

What did you do?

Hi~
I took a sdp file from a webcam, but it failed to parse
[
v=0
o=NVR 1585015269 1585015269 IN IP4 0.0.0.0
s=3GPP Unicast SDP
c=IN IP4 0.0.0.0
t=0 0
a=range:npt=0-
a=control:*
m=video 0 RTP/AVP 96
a=control:video_0
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42002a;sprop-parameter-sets=Z0IAKp2oHgCJ+WbgICAgQA==,aM48gA==;packetization-mode=0
m=audio 0 RTP/AVP 8
a=control:audio_0
a=rtpmap:8 PCMA/8000

]

@at-wat
Copy link
Member

at-wat commented Mar 24, 2020

The SDP looks be able to be parsed by the following code:

package main

import (
  "fmt"

  "github.com/pion/sdp/v2"
)

func main() {
  s := &sdp.SessionDescription{}
  err := s.Unmarshal([]byte(`v=0
o=NVR 1585015269 1585015269 IN IP4 0.0.0.0
s=3GPP Unicast SDP
c=IN IP4 0.0.0.0
t=0 0
a=range:npt=0-
a=control:*
m=video 0 RTP/AVP 96
a=control:video_0
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42002a;sprop-parameter-sets=Z0IAKp2oHgCJ+WbgICAgQA==,aM48gA==;packetization-mode=0
m=audio 0 RTP/AVP 8
a=control:audio_0
a=rtpmap:8 PCMA/8000`))
  if err != nil {
    panic(err)
  }
  fmt.Printf("parsed:\n%+#v\n\n", s)
  
  b, err := s.Marshal()
  fmt.Printf("roundtrip:\n%s\n", b)
} 

output:

parsed:
&sdp.SessionDescription{Version:0, Origin:sdp.Origin{Username:"NVR", SessionID:0x5e7969e5, SessionVersion:0x5e7969e5, NetworkType:"IN", AddressType:"IP4", UnicastAddress:"0.0.0.0"}, SessionName:"3GPP Unicast SDP", SessionInformation:(*sdp.Information)(nil), URI:(*url.URL)(nil), EmailAddress:(*sdp.EmailAddress)(nil), PhoneNumber:(*sdp.PhoneNumber)(nil), ConnectionInformation:(*sdp.ConnectionInformation)(0xc0001100c0), Bandwidth:[]sdp.Bandwidth(nil), TimeDescriptions:[]sdp.TimeDescription{sdp.TimeDescription{Timing:sdp.Timing{StartTime:0x0, StopTime:0x0}, RepeatTimes:[]sdp.RepeatTime(nil)}}, TimeZones:[]sdp.TimeZone(nil), EncryptionKey:(*sdp.EncryptionKey)(nil), Attributes:[]sdp.Attribute{sdp.Attribute{Key:"range", Value:"npt=0-"}, sdp.Attribute{Key:"control", Value:"*"}}, MediaDescriptions:[]*sdp.MediaDescription{(*sdp.MediaDescription)(0xc000120000), (*sdp.MediaDescription)(0xc0001200a0)}}

roundtrip:
v=0
o=NVR 1585015269 1585015269 IN IP4 0.0.0.0
s=3GPP Unicast SDP
c=IN IP4 0.0.0.0
t=0 0
a=range:npt=0-
a=control:*
m=video 0 RTP/AVP 96
a=control:video_0
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42002a;sprop-parameter-sets=Z0IAKp2oHgCJ+WbgICAgQA==,aM48gA==;packetization-mode=0
m=audio 0 RTP/AVP 8
a=control:audio_0
a=rtpmap:8 PCMA/8000

Could you post your code and error log?

@autoexpect
Copy link
Author

code:

package main

import (
  "fmt"

  "github.com/pion/sdp/v2"
)

func main() {
  s := &sdp.SessionDescription{}
  err := s.Unmarshal([]byte(`v=0
o=NVR 1585043154 1585043154 IN IP4 0.0.0.0
s=3GPP Unicast SDP
c=IN IP4 0.0.0.0
t=0 0
a=range:npt=0-
a=control:*
m=video 0 RTP/AVP 96
a=control:video_0
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42002a;sprop-parameter-sets=Z0IAKp2oHgCJ+WbgICAgQA==,aM48gA==;packetization-mode=0
m=audio 0 RTP/AVP 8
a=control:audio_0
a=rtpmap:8 PCMA/8000

`))
  if err != nil {
    panic(err)
  }
  fmt.Printf("parsed:\n%+#v\n\n", s)

  b, err := s.Marshal()
  fmt.Printf("roundtrip:\n%s\n", b)
}

output:

go run main.go
panic: EOF

goroutine 1 [running]:
main.main()
	/Users/harry/Downloads/test/main.go:28 +0x1d4
exit status 2

there are several newline bytes after sdp..

@at-wat
Copy link
Member

at-wat commented Mar 24, 2020

I'm not very sure SDP allows empty lines.
I'll check the RFC and BNF definition of SDP.

@at-wat
Copy link
Member

at-wat commented Mar 26, 2020

In my understanding, extra newlines in SDP is not fully adapting the specification. (I'm not 100% sure.)
But other SDP parsers, for example one in VLC media player, allow to have extra newlines.

#46 will fix the issue.

@autoexpect
Copy link
Author

OK thanks!

@at-wat
Copy link
Member

at-wat commented Mar 27, 2020

@umbrellary the master branch support SDP with extra newlines now. Please check it out!

@autoexpect
Copy link
Author

it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants