summaryrefslogtreecommitdiff
path: root/player
diff options
context:
space:
mode:
Diffstat (limited to 'player')
-rw-r--r--player/player.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/player/player.go b/player/player.go
index 8951813..b3dc761 100644
--- a/player/player.go
+++ b/player/player.go
@@ -49,6 +49,14 @@ type loadRequest struct {
response chan<- loadResult
}
+type unloadResult struct {
+ err error
+}
+
+type unloadRequest struct {
+ response chan<- unloadResult
+}
+
type playResult struct {
err error
}
@@ -151,6 +159,7 @@ type Player struct {
state State
duration time.Duration
loadChan chan loadRequest
+ unloadChan chan unloadRequest
playChan chan playRequest
pauseChan chan pauseRequest
playPauseChan chan playPauseRequest
@@ -167,6 +176,9 @@ type Player struct {
func (p *Player) changeState(new State) {
p.state = new
p.stateChangeChan <- new
+ if new == IDLE {
+ p.updateChan <- updateData{}
+ }
}
func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) {
@@ -252,6 +264,12 @@ func (p *Player) load(cart, cut uint) (resp loadResult) {
return
}
+func (p *Player) unload() (resp unloadResult) {
+ p.pipe.SetState(gst.STATE_NULL)
+ p.changeState(IDLE)
+ return
+}
+
func (p *Player) play() (resp playResult) {
if p.state != PAUSED {
resp.err = fmt.Errorf("player: no file loaded")
@@ -352,6 +370,8 @@ func (p *Player) dispatchRequests() {
select {
case req := <-p.loadChan:
req.response <- p.load(req.cart, req.cut)
+ case req := <-p.unloadChan:
+ req.response <- p.unload()
case req := <-p.playChan:
req.response <- p.play()
case req := <-p.pauseChan:
@@ -431,6 +451,7 @@ func (p *Player) createPipeline() (err error) {
type PlayerChan struct {
load chan<- loadRequest
+ unload chan<- unloadRequest
play chan<- playRequest
playPause chan<- playPauseRequest
pause chan<- pauseRequest
@@ -455,6 +476,19 @@ func (p *PlayerChan) Load(cart, cut uint) error {
return nil
}
+func (p *PlayerChan) Unload() error {
+ resCh := make(chan unloadResult)
+ req := unloadRequest{}
+ req.response = resCh
+ p.unload <- req
+
+ res := <-resCh
+ if res.err != nil {
+ return res.err
+ }
+ return nil
+}
+
func (p *PlayerChan) Play() error {
resCh := make(chan playResult)
req := playRequest{}
@@ -554,6 +588,7 @@ func (p *PlayerChan) AddStateChangeHandler(callback StateChangeCB, userdata inte
func (p *Player) GetInterface() *PlayerChan {
ch := &PlayerChan{}
ch.load = p.loadChan
+ ch.unload = p.unloadChan
ch.play = p.playChan
ch.pause = p.pauseChan
ch.playPause = p.playPauseChan
@@ -580,6 +615,7 @@ func NewPlayer(basepath string, stdlog *log.Logger, dbglog *log.Logger) (p *Play
p.dbglog = log.New(ioutil.Discard, "rhrd-go.player-dbg", log.LstdFlags)
}
p.loadChan = make(chan loadRequest)
+ p.unloadChan = make(chan unloadRequest)
p.playChan = make(chan playRequest)
p.pauseChan = make(chan pauseRequest)
p.playPauseChan = make(chan playPauseRequest)