alexballas / go2tv

Cast media files to UPnP/DLNA Media Renderers and Smart TVs.
MIT License
468 stars 45 forks source link

http: server closed idle connection #69

Closed mostcute closed 1 year ago

mostcute commented 1 year ago

im trying to write a simple demo with this lib, and i call the playAction first,then call stopAction. when i call playAction again, i met err

{"level":"error","Method":"AVTransportActionSoapCall","Action":"Do POST","error":"Post \"http://192.168.123.7:49494/upnp/control/rendertransport1\": http: server closed idle connection","time":"2023-06-03T22:16:56+08:00"}

mostcute commented 1 year ago

found the solution,seems the soapcalls.DMRextractor(context.Background(), res.Device) must call before every palyAction,can not be reused

mostcute commented 1 year ago

try many times, seems call soapcalls.DMRextractor(context.Background(), res.Device) ervery time is not the proper solution

mostcute commented 1 year ago

some log

{"level":"debug","Method":"GetProtocolInfo","Action":"Request","Headers":{"Connection":["close"],"SOAPAction":["\"urn:schemas-upnp-org:service:ConnectionManager:1#GetProtocolInfo\""],"charset":["utf-8"],"content-type":["text/xml"]},"time":"2023-06-04T00:46:32+08:00","message":"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:GetProtocolInfo xmlns:u=\"urn:schemas-upnp-org:service:ConnectionManager:1\"></u:GetProtocolInfo></s:Body></s:Envelope>"}
{"level":"debug","Method":"GetProtocolInfo","Action":"Response","Status Code":"200","Headers":{"Content-Length":["308"],"Content-Type":["text/xml; charset=\"utf-8\""],"Date":["Sat, 03 Jun 2023 16:46:31 GMT"],"Ext":[""],"Server":["Linux/4.4.25, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"],"X-User-Agent":["redsonic"]},"time":"2023-06-04T00:46:32+08:00","message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:GetProtocolInfoResponse xmlns:u=\"urn:schemas-upnp-org:service:ConnectionManager:1\">\r\n<Source></Source>\r\n<Sink></Sink>\r\n</u:GetProtocolInfoResponse>\r\n</s:Body> </s:Envelope>"}
{"level":"debug","Method":"SubscribeSoapCall","Action":"Subscribe Request","Headers":{"CALLBACK":["\u003chttp://192.168.123.35:3500/BDB280991FB953EDDECADCA46977BF95\u003e"],"Connection":["close"],"NT":["upnp:event"],"TIMEOUT":["Second-300"],"USER-AGENT":["linux  UPnP/1.1 Go2TV"]},"time":"2023-06-04T00:46:32+08:00"}
{"level":"debug","Method":"SubscribeSoapCall","Action":"Subscribe Response","Status Code":"200","Headers":{"Content-Length":["0"],"Date":["Sat, 03 Jun 2023 16:46:31 GMT"],"Server":["Linux/4.4.25, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"],"Sid":["uuid:31874410-1dd2-11b2-8292-91ee0d1b0ea5"],"Timeout":["Second-300"],"X-User-Agent":["redsonic"]},"time":"2023-06-04T00:46:32+08:00"}
{"level":"debug","Method":"setAVTransportSoapCall","Action":"Request","Headers":{"Connection":["close"],"SOAPAction":["\"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\""],"charset":["utf-8"],"content-type":["text/xml"]},"time":"2023-06-04T00:46:32+08:00","message":"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><CurrentURI>http://192.168.123.35:3500/37.mp4</CurrentURI><CurrentURIMetaData>&lt;DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:sec=\"http://www.sec.co.kr/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\"&gt;&lt;item id=\"1\" parentID=\"0\" restricted=\"1\"&gt;&lt;dc:title&gt;37.mp4&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;res protocolInfo=\"http-get:*:video/mp4:DLNA.ORG_PN=AVC_MP4_MP_SD_AAC_MULT5;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000\"&gt;http://192.168.123.35:3500/37.mp4&lt;/res&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>"}
{"level":"debug","Method":"GetTransportInfo","Action":"Request","Headers":{"Connection":["close"],"SOAPAction":["\"urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo\""],"charset":["utf-8"],"content-type":["text/xml"]},"time":"2023-06-04T00:46:34+08:00","message":"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:GetTransportInfo xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetTransportInfo></s:Body></s:Envelope>"}
{"level":"debug","Method":"setAVTransportSoapCall","Action":"Response","Status Code":"200","Headers":{"Content-Length":["270"],"Content-Type":["text/xml; charset=\"utf-8\""],"Date":["Sat, 03 Jun 2023 16:46:33 GMT"],"Ext":[""],"Server":["Linux/4.4.25, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"],"X-User-Agent":["redsonic"]},"time":"2023-06-04T00:46:34+08:00","message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:SetAVTransportURIResponse xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"></u:SetAVTransportURIResponse>\r\n</s:Body> </s:Envelope>"}
{"level":"debug","Method":"AVTransportActionSoapCall","Action":"Play Request","Headers":{"Connection":["close"],"SOAPAction":["\"urn:schemas-upnp-org:service:AVTransport:1#Play\""],"charset":["utf-8"],"content-type":["text/xml"]},"time":"2023-06-04T00:46:34+08:00","message":"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>"}
{"level":"debug","Method":"GetTransportInfo","Action":"Response","Status Code":"200","Headers":{"Content-Length":["411"],"Content-Type":["text/xml; charset=\"utf-8\""],"Date":["Sat, 03 Jun 2023 16:46:33 GMT"],"Ext":[""],"Server":["Linux/4.4.25, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"],"X-User-Agent":["redsonic"]},"time":"2023-06-04T00:46:34+08:00","message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:GetTransportInfoResponse xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">\r\n<CurrentTransportState>STOPPED</CurrentTransportState>\r\n<CurrentTransportStatus>OK</CurrentTransportStatus>\r\n<CurrentSpeed>1</CurrentSpeed>\r\n</u:GetTransportInfoResponse>\r\n</s:Body> </s:Envelope>"}
{"level":"error","Method":"AVTransportActionSoapCall","Action":"Do POST","error":"Post \"http://192.168.123.7:49494/upnp/control/rendertransport1\": http: server closed idle connection","time":"2023-06-04T00:46:34+08:00"}
fsm.go:253: SendtoTV Play/Stop/Pause action error: AVTransportActionSoapCall Do POST error: Post "http://192.168.123.7:49494/upnp/control/rendertransport1": http: server closed idle connection
{"level":"debug","Method":"AVTransportActionSoapCall","Action":"Stop Request","Headers":{"Connection":["close"],"SOAPAction":["\"urn:schemas-upnp-org:service:AVTransport:1#Stop\""],"charset":["utf-8"],"content-type":["text/xml"]},"time":"2023-06-04T00:46:34+08:00","message":"<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:Stop xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID><Speed>1</Speed></u:Stop></s:Body></s:Envelope>"}
{"level":"debug","Method":"AVTransportActionSoapCall","Action":"Stop Response","Status Code":"200","Headers":{"Content-Length":["244"],"Content-Type":["text/xml; charset=\"utf-8\""],"Date":["Sat, 03 Jun 2023 16:46:33 GMT"],"Ext":[""],"Server":["Linux/4.4.25, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"],"X-User-Agent":["redsonic"]},"time":"2023-06-04T00:46:34+08:00","message":"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>\n<u:StopResponse xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"></u:StopResponse>\r\n</s:Body> </s:Envelope>"}
alexballas commented 1 year ago

Hello, can you please share a working code example that demonstrates this issue?

mostcute commented 1 year ago

a workong example is like this

                Globalscreen.SecletedDevice = Globalscreen.getdevice(res.Device)
                // must be called before play
                t, err := soapcalls.DMRextractor(context.Background(), Globalscreen.SecletedDevice.URL)
                if err == nil {
                    Globalscreen.controlURL = t.AvtransportControlURL
                    Globalscreen.eventlURL = t.AvtransportEventSubURL
                    Globalscreen.renderingControlURL = t.RenderingControlURL
                    Globalscreen.connectionManagerURL = t.ConnectionManagerURL
                    if Globalscreen.tvdata != nil {
                        Globalscreen.tvdata.RenderingControlURL = Globalscreen.renderingControlURL
                    }
                }
                Globalscreen.mediafile = res.Media

                playAction(Globalscreen)
                time.Sleep(time.Second * 30)
                stopAction(Globalscreen)
                time.Sleep(time.Second * 10)
                playAction(Globalscreen)
                time.Sleep(time.Second * 30)
                stopAction(Globalscreen)
                time.Sleep(time.Second * 10)
                playAction(Globalscreen)
                time.Sleep(time.Second * 30)
                stopAction(Globalscreen)
                time.Sleep(time.Second * 10)
                playAction(Globalscreen)

            }
        }

i tested many times on different device,

1 . i cast a mp4 file to my Projector ,worked well

  1. i cast a mp3 file to my speaker,worked well

  2. i cast a mp4 file to my speaker, it can work,play the sound,but when play and stop again and again, the error will appear,maybe at the second play time or third play time,a little random.

so maybe is the devices problem when cast media that didn't quite match the type?

alexballas commented 1 year ago

Although it's still not clear to me what playAction is doing, I would expect that this intermittent failure is indeed coming from the device. This "http: server closed idle connection" is basically your device sending EOF.

src/net/http/transport.go
 738         if err == errServerClosedIdle {                                                                                                                                                                
 739                 // The server replied with io.EOF while we were trying to
 740                 // read the response. Probably an unfortunately keep-alive
 741                 // timeout, just as the client was writing a request.
 742                 return true
 743         }

So not much we can do here.