notedit / media-server-go-demo

webrtc media server go demo
MIT License
212 stars 64 forks source link

Panic runtime error with VP8 #26

Closed tomberek closed 4 years ago

tomberek commented 4 years ago

Starting to explore the media-server-go examples and got it working nicely with H264. Then I tried to adapt it to use VP8, (perhaps eventually to support both several incoming offered formats) and came across this panic during a buffer conversion.

Code below, note the "continue" on line 151 that skips the OnMediaFrame callback registration. It seems that this code allows one to loopback VP8, but as soon as you may want to register something on frames, likely to feed it to a modified gstreamer pipeline, the OnMediaFrame call fails. The gstreamer/HLS portions of the gist can be removed with the same result.

[0x7f7dacff9700][1585316205.235][LOG]-SRTPSession::AddStream() | [ssrc:91865768,OK]
[0x7f7dacff9700][1585316205.235][LOG]-DTLSICETransport::SetRemoteCryptoSDES() | [suite:AES_CM_128_HMAC_SHA1_80]
[0x7f7dacff9700][1585316205.235][LOG]-SRTPSession::AddStream() | [ssrc:1521937445,OK]
[0x7f7dacff9700][1585316205.235][LOG]-SRTPSession::AddStream() | [ssrc:1450984025,OK]
[0x7f7dacff9700][1585316205.235][LOG]-SRTPSession::AddStream() | [ssrc:91865768,OK]
OnDTLSStateChange 2
panic: runtime error: slice bounds out of range [:1354170525] with capacity 2862

goroutine 17 [running, locked to thread]:
github.com/notedit/media-server-go.annexbConvert(0xc000055800, 0xb32, 0xb32, 0xb32, 0xb32, 0x7f7dc4e5a428, 0x0, 0x8)
        /home/tom/go/src/github.com/notedit/media-server-go/util.go:59 +0x30b
github.com/notedit/media-server-go.(*overwrittenMediaFrameListener).OnMediaFrame(0xc000453280, 0xe11cc0, 0xc0002d0f10)
        /home/tom/go/src/github.com/notedit/media-server-go/mediaframemultiplexer.go:44 +0xe1
github.com/notedit/media-server-go/wrapper.(*_swig_DirectorMediaFrameListener).OnMediaFrame(0xc0004532c0, 0xe11cc0, 0xc0002d0f10)
        /home/tom/go/src/github.com/notedit/media-server-go/wrapper/native.go:5095 +0x77
github.com/notedit/media-server-go/wrapper.Swig_DirectorMediaFrameListener_callback_onMediaFrame_native_4b7afac4175a7297(0x5, 0x7f7d9000fe10)
        /home/tom/go/src/github.com/notedit/media-server-go/wrapper/native.go:5110 +0x7c
github.com/notedit/media-server-go/wrapper._cgoexpwrap_6c6c43463922_Swig_DirectorMediaFrameListener_callback_onMediaFrame_native_4b7afac4175a7297(0x5, 0x7f7d9000fe10)
        _cgo_gotypes.go:6875 +0x35
exit status 2

https://gist.github.com/tomberek/c5dcdb1199e08c33ca2be46d5da08a3f

The OnMediaFrame call seems to work without any problems when using H264.

Sidenote: I've created a Nix expression that handles creating and installing media-server-go-native. With some cleanup and making it more idiomatic, this may be useful for any Nix users. https://gist.github.com/tomberek/f0b56c0754b55b20e7c881f98ab872b7

tomberek commented 4 years ago

I've tracked this down to this check: https://github.com/notedit/media-server-go/blob/master/mediaframemultiplexer.go#L43

This seems to assume H264, or doesn't really check it correctly. Removing the annexbConvert (or adjusting the if condition to be false) makes VP8/9 work correctly. Is there another way to make that condition go the other way?

notedit commented 4 years ago

you can check your sdp.