decrease memory usage

This commit is contained in:
aler9 2020-10-31 12:16:53 +01:00
parent 282a15ebba
commit 42ba83245b
3 changed files with 16 additions and 0 deletions

View file

@ -832,6 +832,8 @@ func (c *Client) handleRequest(req *base.Request) error {
func (c *Client) runInitial() bool {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
req, err := c.conn.ReadRequest()
if err != nil {
@ -959,6 +961,8 @@ func (c *Client) runPlay() bool {
func (c *Client) runPlayUDP() {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
req, err := c.conn.ReadRequest()
if err != nil {
@ -998,6 +1002,8 @@ func (c *Client) runPlayTCP() {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
recv, err := c.conn.ReadFrameTCPOrRequest(false)
if err != nil {
@ -1026,6 +1032,7 @@ func (c *Client) runPlayTCP() {
// responses must be written in the same routine of frames
case req := <-readRequest:
req.res <- c.handleRequest(req.req)
close(req.res)
case err := <-readDone:
c.conn.Close()
@ -1143,6 +1150,8 @@ func (c *Client) runRecord() bool {
func (c *Client) runRecordUDP() {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
req, err := c.conn.ReadRequest()
if err != nil {
@ -1217,6 +1226,8 @@ func (c *Client) runRecordTCP() {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
recv, err := c.conn.ReadFrameTCPOrRequest(true)
if err != nil {

View file

@ -270,6 +270,8 @@ func (s *Source) runInnerInner() bool {
readDone := make(chan error)
go func() {
defer close(readDone)
for {
pkt, err := conn.ReadPacket()
if err != nil {

View file

@ -253,6 +253,7 @@ func (s *Source) runUDP(u *url.URL, conn *gortsplib.ConnClient, tracks gortsplib
tcpConnDone := make(chan error)
go func() {
defer close(tcpConnDone)
tcpConnDone <- conn.LoopUDP()
}()
@ -304,6 +305,8 @@ func (s *Source) runTCP(u *url.URL, conn *gortsplib.ConnClient, tracks gortsplib
tcpConnDone := make(chan error)
go func() {
defer close(tcpConnDone)
for {
trackId, streamType, content, err := conn.ReadFrameTCP()
if err != nil {