summaryrefslogtreecommitdiff
path: root/player
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-01-21 15:21:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-01-21 15:21:59 (GMT)
commit5c8b3b98ca2c8b7709f062b45abf73f480caf351 (patch)
tree52ec3dd4c86841fa1e74b551548814c650472a7e /player
parent7cd335cf3e0a2f7a1df167e7bcc28d696541a8cf (diff)
implemented meter callbacks
Diffstat (limited to 'player')
-rw-r--r--player/player.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/player/player.go b/player/player.go
index 6ee0317..cb613d4 100644
--- a/player/player.go
+++ b/player/player.go
@@ -84,8 +84,8 @@ type addUpdateHandlerRequest struct {
}
type MeterChannel struct {
- peak float64
- decay float64
+ Peak float64
+ Decay float64
}
type Meter []MeterChannel
type updateData struct {
@@ -94,6 +94,10 @@ type updateData struct {
meter Meter
}
type UpdateCB func(len time.Duration, pos time.Duration, meter Meter, userdata interface{}) bool
+type pUpdateCB struct {
+ cb UpdateCB
+ userdata interface{}
+}
type State int
@@ -119,6 +123,7 @@ type Player struct {
stopChan chan stopRequest
updateChan chan updateData
addUpdateHandlerChan chan addUpdateHandlerRequest
+ updateCBs []*pUpdateCB
}
func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) {
@@ -153,7 +158,7 @@ func (p *Player) onMessage(bus *gst.Bus, msg *gst.Message) {
meter := make([]MeterChannel, len(peak))
for i := 0; i < len(peak); i++ {
- meter[i] = MeterChannel{peak: peak[i].(float64), decay: decay[i].(float64)}
+ meter[i] = MeterChannel{Peak: peak[i].(float64), Decay: decay[i].(float64)}
}
pos := time.Duration(s.Data["stream-time"].(uint64))
p.updateChan <- updateData{len: p.len, pos: pos, meter: meter}
@@ -228,13 +233,18 @@ func (p *Player) stop() (resp stopResult) {
}
func (p *Player) addUpdateHandler(callback UpdateCB, userdata interface{}) (resp addUpdateHandlerResult) {
- resp.err = fmt.Errorf("not yet implemented!") // TODO: implement this
+ p.updateCBs = append(p.updateCBs, &pUpdateCB{callback, userdata})
return
}
func (p *Player) sendUpdate(len time.Duration, pos time.Duration, meter Meter) {
- p.dbglog.Printf("player update: len: %s, pos: %s, meter: %+v", len.String(), pos.String(), meter)
- // TODO: send this to all subscribed handler
+ for _, cb := range p.updateCBs {
+ if cb.cb != nil {
+ if keep := cb.cb(len, pos, meter, cb.userdata); !keep {
+ cb.cb = nil
+ }
+ }
+ }
return
}
@@ -276,6 +286,7 @@ func (p *Player) createPipeline() (err error) {
return
}
p.level.SetProperty("message", true)
+ p.level.SetProperty("interval", 25000000)
p.level.SetProperty("peak-ttl", 300000000)
p.level.SetProperty("peak-falloff", 25)
if conv2, err = gst.ElementFactoryMake("audioconvert", "conv2"); err != nil {