Use ProcessStop boolean to detect stopped state
This commit is contained in:
@@ -135,14 +135,13 @@ func (s *HTTPserver) callbackHandler(tv *soapcalls.TVPayload, screen Screen) htt
|
|||||||
// Apparently we should ignore the first message
|
// Apparently we should ignore the first message
|
||||||
// On some media renderers we receive a STOPPED message
|
// On some media renderers we receive a STOPPED message
|
||||||
// even before we start streaming.
|
// even before we start streaming.
|
||||||
seq, err := tv.GetSequence(uuid)
|
processStop, err := tv.GetProcessStop(uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.NotFound(w, req)
|
http.NotFound(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if seq == 0 && newstate == "STOPPED" {
|
if processStop && newstate == "STOPPED" {
|
||||||
tv.IncreaseSequence(uuid)
|
|
||||||
fmt.Fprintf(w, "OK\n")
|
fmt.Fprintf(w, "OK\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -154,10 +153,12 @@ func (s *HTTPserver) callbackHandler(tv *soapcalls.TVPayload, screen Screen) htt
|
|||||||
|
|
||||||
switch newstate {
|
switch newstate {
|
||||||
case "PLAYING":
|
case "PLAYING":
|
||||||
|
tv.SetProcessStopFalse(uuid)
|
||||||
screen.EmitMsg("Playing")
|
screen.EmitMsg("Playing")
|
||||||
case "PAUSED_PLAYBACK":
|
case "PAUSED_PLAYBACK":
|
||||||
screen.EmitMsg("Paused")
|
screen.EmitMsg("Paused")
|
||||||
case "STOPPED":
|
case "STOPPED":
|
||||||
|
tv.SetProcessStopTrue(uuid)
|
||||||
screen.EmitMsg("Stopped")
|
screen.EmitMsg("Stopped")
|
||||||
_ = tv.UnsubscribeSoapCall(uuid)
|
_ = tv.UnsubscribeSoapCall(uuid)
|
||||||
screen.Fini()
|
screen.Fini()
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
type States struct {
|
type States struct {
|
||||||
PreviousState string
|
PreviousState string
|
||||||
NewState string
|
NewState string
|
||||||
Sequence int
|
ProcessStop bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// TVPayload this is the heart of Go2TV. We pass that type to the
|
// 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] {
|
if p.InitialMediaRenderersStates[uuid] {
|
||||||
p.MediaRenderersStates[uuid].PreviousState = previous
|
p.MediaRenderersStates[uuid].PreviousState = previous
|
||||||
p.MediaRenderersStates[uuid].NewState = new
|
p.MediaRenderersStates[uuid].NewState = new
|
||||||
p.MediaRenderersStates[uuid].Sequence++
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,7 +548,7 @@ func (p *TVPayload) CreateMRstate(uuid string) {
|
|||||||
p.MediaRenderersStates[uuid] = &States{
|
p.MediaRenderersStates[uuid] = &States{
|
||||||
PreviousState: "",
|
PreviousState: "",
|
||||||
NewState: "",
|
NewState: "",
|
||||||
Sequence: 0,
|
ProcessStop: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,20 +560,27 @@ func (p *TVPayload) DeleteMRstate(uuid string) {
|
|||||||
delete(p.MediaRenderersStates, uuid)
|
delete(p.MediaRenderersStates, uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncreaseSequence increases the sequence value of the specific UUID by 1.
|
// SetProcessStopTrue set the stop process to true
|
||||||
func (p *TVPayload) IncreaseSequence(uuid string) {
|
func (p *TVPayload) SetProcessStopTrue(uuid string) {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
p.MediaRenderersStates[uuid].Sequence++
|
p.MediaRenderersStates[uuid].ProcessStop = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSequence returns the sequence value of the specific UUID.
|
// SetProcessStopFalse set the stop process to false
|
||||||
func (p *TVPayload) GetSequence(uuid string) (int, error) {
|
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()
|
p.RLock()
|
||||||
defer p.RUnlock()
|
defer p.RUnlock()
|
||||||
if p.InitialMediaRenderersStates[uuid] {
|
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")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user