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

Panic on connecting client (vlc and ffplay) #43

Closed
QuantumEntangledAndy opened this issue Jul 20, 2020 · 7 comments
Closed

Panic on connecting client (vlc and ffplay) #43

QuantumEntangledAndy opened this issue Jul 20, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@QuantumEntangledAndy
Copy link

Which version are you using?

v0.9.3

Describe the problem

After your bug fix in #41 I am able to connect the publishing client (an ios app). When attempting to play the stream the following error occurs.

2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] connected
2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] OPTIONS
2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] DESCRIBE
2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] SETUP
2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] SETUP
2020/07/20 11:52:55 [2/1/0] [client 127.0.0.1:53142] PLAY
2020/07/20 11:52:55 [2/1/1] [client 127.0.0.1:53142] is receiving on path 'test', 2 tracks via udp
panic: runtime error: slice bounds out of range [:12846] with capacity 2048

goroutine 8 [running]:
main.(*serverUdpListener).write(...)
	/s/server-udpl.go:96
main.(*program).forwardFrame(0xc00022a070, 0xc000292158, 0x4, 0x0, 0x0, 0xc000300000, 0x322e, 0x80000)
	/s/main.go:525 +0x8e4
main.(*program).run(0xc00022a070)
	/s/main.go:408 +0x1e8
created by main.newProgram
	/s/main.go:264 +0xbb1

Please let me know if you need further debugging information

@QuantumEntangledAndy
Copy link
Author

QuantumEntangledAndy commented Jul 20, 2020

This happens on both TCP and UDP

(this is the TCP error message)

panic: runtime error: slice bounds out of range [:12903] with capacity 2048

goroutine 22 [running]:
main.(*program).forwardFrame(0xc000115ce0, 0xc00021a158, 0x4, 0x0, 0x0, 0xc000280000, 0x3267, 0x80000)
	/s/main.go:546 +0x88a
main.(*program).run(0xc000115ce0)
	/s/main.go:408 +0x1e8
created by main.newProgram
	/s/main.go:264 +0xbb1

@QuantumEntangledAndy
Copy link
Author

QuantumEntangledAndy commented Jul 20, 2020

So looking into this..

You have the client double buffer fixed at 2048

server-client.go:790

if c.streamProtocol == gortsplib.StreamProtocolTcp {
		c.writeBuf = newDoubleBuffer(2048)
		c.events = make(chan serverClientEvent)
}

The size of the frames are larger than this.

If I send only the first 2048 bytes of each frame (obviously this means the frame is not complete and only a portion of the picture is sent) it will work

main.go:526

buf := client.writeBuf.swap()
len_frame := 2048 // Edited to fixed size for this test
buf = buf[:len_frame]
copy(buf, frame)

I don't know enough about the details of the code to know if I should up the buffer size or send the frame over multiple buffers but I hope that this helps with the debugging.

@QuantumEntangledAndy
Copy link
Author

QuantumEntangledAndy commented Jul 20, 2020

I tried chunking the data but that did not work as I expected, so instead I bumped up the buffer size to 20480 (since the largest frame was 19999 bytes) c.writeBuf = newDoubleBuffer(20480) and everything is working.

@QuantumEntangledAndy
Copy link
Author

QuantumEntangledAndy commented Jul 20, 2020

This increasing of the buffer size only works with the TCP since the UDP uses another method hmm. Or at least the buffer is defined elsewhere. Anyway I will stop tinkering.

@aler9 aler9 added the bug Something isn't working label Jul 20, 2020
@aler9
Copy link
Member

aler9 commented Jul 20, 2020

Hello, this happens because you're publishing via TCP (read buffer size = 512*1028) and reading via TCP (write buffer size = 2048) and UDP (write buffer size = 2048). The buffer sizes have been adjusted to the following values to avoid memory leaks:

  • TCP read buffer size (for publishing) = 128 * 1024
  • UDP read buffer size (for publishing) = 2048
  • TCP write buffer size (for reading) = 128 * 1024
  • UDP write buffer size (for reading) = 128 * 1024
    Please try again with v0.9.4 and let me know if it works.

@QuantumEntangledAndy
Copy link
Author

I can confirm that this is working. Thanks for your efforts :)

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2023

This issue is being locked automatically because it has been closed for more than 6 months.
Please open a new issue in case you encounter a similar problem.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants