diff options
-rw-r--r-- | player/player.go | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/player/player.go b/player/player.go index 5ab8f72..13b1304 100644 --- a/player/player.go +++ b/player/player.go @@ -80,7 +80,9 @@ const ( ) type Player struct { - pipe *gst.Element + pipe *gst.Pipeline + src *gst.Element + volume *gst.Element bus *gst.Bus basepath string stdlog *log.Logger @@ -92,7 +94,7 @@ type Player struct { stopChan chan stopRequest } -func (p *Player) onMessage(msg *gst.Message) { +func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) { switch msg.GetType() { case gst.MESSAGE_EOS: p.pipe.SetState(gst.STATE_NULL) @@ -142,7 +144,7 @@ func (p *Player) load(cart, cut uint) (resp loadResult) { p.pipe.SetState(gst.STATE_NULL) p.state = IDLE } - p.pipe.SetProperty("uri", "file://"+filename) + p.src.SetProperty("uri", "file://"+filename) p.pipe.SetState(gst.STATE_PAUSED) p.state = PAUSED return @@ -184,9 +186,8 @@ func (p *Player) stop() (resp stopResult) { } func (p *Player) dispatchRequests() { - msgChan := make(chan gst.Message) p.bus.AddSignalWatch() - p.bus.Connect("message", func(bus *gst.Bus, msg *gst.Message) { msgChan <- *msg }) + p.bus.Connect("message", func(bus *gst.Bus, msg *gst.Message) { p.onMessage(bus, msg) }) for { select { @@ -198,8 +199,6 @@ func (p *Player) dispatchRequests() { req.response <- p.pause() case req := <-p.stopChan: req.response <- p.stop() - case msg := <-msgChan: - p.onMessage(&msg) } } } @@ -277,13 +276,47 @@ func (p *Player) GetInterface() *PlayerChan { return ch } +func (p *Player) createPipeline() (err error) { + if p.pipe, err = gst.PipelineNew("rhlibrary"); err != nil { + return + } + + // var conv1, conv2, sink *gst.Element + if p.src, err = gst.ElementFactoryMake("playbin", "source"); err != nil { + return + } + // if conv1, err = gst.ElementFactoryMake("audioconvert", "conv1"); err != nil { + // return + // } + // if p.volume, err = gst.ElementFactoryMake("volume", "meter"); err != nil { + // return + // } + // if conv2, err = gst.ElementFactoryMake("audioconvert", "conv2"); err != nil { + // return + // } + // if sink, err = gst.ElementFactoryMake("autoaudiosink", "sink"); err != nil { + // return + // } + + p.pipe.Add(p.src) + // p.pipe.Add(conv1) + // p.pipe.Add(p.volume) + // p.pipe.Add(conv2) + // p.pipe.Add(sink) + + if p.bus, err = p.pipe.GetBus(); err != nil { + return + } + return +} + func NewPlayer(basepath string, stdlog *log.Logger, dbglog *log.Logger) (p *Player, err error) { p = &Player{} p.basepath = path.Clean(basepath) if stdlog != nil { p.stdlog = stdlog } else { - p.stdlog = log.New(ioutil.Discard, "rhrd-go.player", log.LstdFlags) + p.stdlog = log.New(ioutil.Discard, "autoplayrhrd-go.player", log.LstdFlags) } if dbglog != nil { p.dbglog = dbglog @@ -295,10 +328,7 @@ func NewPlayer(basepath string, stdlog *log.Logger, dbglog *log.Logger) (p *Play p.pauseChan = make(chan pauseRequest) p.stopChan = make(chan stopRequest) - if p.pipe, err = gst.ElementFactoryMake("playbin", "autoplay"); err != nil { - return - } - if p.bus, err = p.pipe.GetBus(); err != nil { + if err = p.createPipeline(); err != nil { return } |