Use ProcessStop boolean to detect stopped state

This commit is contained in:
Corentin Mors
2022-06-11 10:52:46 +02:00
parent 22dc238ac1
commit 87c327dd88
2 changed files with 20 additions and 13 deletions

View File

@@ -135,14 +135,13 @@ func (s *HTTPserver) callbackHandler(tv *soapcalls.TVPayload, screen Screen) htt
// Apparently we should ignore the first message
// On some media renderers we receive a STOPPED message
// even before we start streaming.
seq, err := tv.GetSequence(uuid)
processStop, err := tv.GetProcessStop(uuid)
if err != nil {
http.NotFound(w, req)
return
}
if seq == 0 && newstate == "STOPPED" {
tv.IncreaseSequence(uuid)
if processStop && newstate == "STOPPED" {
fmt.Fprintf(w, "OK\n")
return
}
@@ -154,10 +153,12 @@ func (s *HTTPserver) callbackHandler(tv *soapcalls.TVPayload, screen Screen) htt
switch newstate {
case "PLAYING":
tv.SetProcessStopFalse(uuid)
screen.EmitMsg("Playing")
case "PAUSED_PLAYBACK":
screen.EmitMsg("Paused")
case "STOPPED":
tv.SetProcessStopTrue(uuid)
screen.EmitMsg("Stopped")
_ = tv.UnsubscribeSoapCall(uuid)
screen.Fini()

View File

@@ -19,7 +19,7 @@ import (
type States struct {
PreviousState string
NewState string
Sequence int
ProcessStop bool
}
// TVPayload this is the heart of Go2TV. We pass that type to the
@@ -534,7 +534,6 @@ func (p *TVPayload) UpdateMRstate(previous, new, uuid string) bool {
if p.InitialMediaRenderersStates[uuid] {
p.MediaRenderersStates[uuid].PreviousState = previous
p.MediaRenderersStates[uuid].NewState = new
p.MediaRenderersStates[uuid].Sequence++
return true
}
@@ -549,7 +548,7 @@ func (p *TVPayload) CreateMRstate(uuid string) {
p.MediaRenderersStates[uuid] = &States{
PreviousState: "",
NewState: "",
Sequence: 0,
ProcessStop: true,
}
}
@@ -561,20 +560,27 @@ func (p *TVPayload) DeleteMRstate(uuid string) {
delete(p.MediaRenderersStates, uuid)
}
// IncreaseSequence increases the sequence value of the specific UUID by 1.
func (p *TVPayload) IncreaseSequence(uuid string) {
// SetProcessStopTrue set the stop process to true
func (p *TVPayload) SetProcessStopTrue(uuid string) {
p.Lock()
defer p.Unlock()
p.MediaRenderersStates[uuid].Sequence++
p.MediaRenderersStates[uuid].ProcessStop = true
}
// GetSequence returns the sequence value of the specific UUID.
func (p *TVPayload) GetSequence(uuid string) (int, error) {
// SetProcessStopFalse set the stop process to false
func (p *TVPayload) SetProcessStopFalse(uuid string) {
p.Lock()
defer p.Unlock()
p.MediaRenderersStates[uuid].ProcessStop = false
}
// GetProcessStop returns the processStop value of the specific UUID.
func (p *TVPayload) GetProcessStop(uuid string) (bool, error) {
p.RLock()
defer p.RUnlock()
if p.InitialMediaRenderersStates[uuid] {
return p.MediaRenderersStates[uuid].Sequence, nil
return p.MediaRenderersStates[uuid].ProcessStop, nil
}
return -1, errors.New("zombie callbacks, we should ignore those")
return true, errors.New("zombie callbacks, we should ignore those")
}