Skip to content
Snippets Groups Projects
Commit 2f7945b3 authored by ale's avatar ale
Browse files

prober: Add "-t mp3" to decode mp3 streams

parent 3dd20fbb
Branches
No related tags found
No related merge requests found
......@@ -21,8 +21,13 @@ type decoder struct {
cmd *exec.Cmd
}
func newDecoder(r io.Reader) (*decoder, error) {
cmd := exec.Command("sox", "-", "-r", analysisSampleRate, "-c", analysisChannels, "-b", "64", "-e", "float", "--endian", "little", "-t", "raw", "-")
func newDecoder(r io.Reader, ext string) (*decoder, error) {
var args []string
if ext == ".mp3" {
args = append(args, "-t", "mp3")
}
args = append(args, "-", "-r", analysisSampleRate, "-c", analysisChannels, "-b", "64", "-e", "float", "--endian", "little", "-t", "raw", "-")
cmd := exec.Command("sox", args...)
cmd.Stdin = r
cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
......
......@@ -5,6 +5,7 @@ import (
"log"
"net/http"
"net/url"
"path/filepath"
"time"
"github.com/prometheus/client_golang/prometheus"
......@@ -119,7 +120,7 @@ func (p *Prober) stream(deadline time.Time) {
// Instrument the raw bytes transfered, before decoding happens.
r := newInstrumentedReader(resp.Body, bytesReceived.WithLabelValues(p.streamName))
dec, err := newDecoder(r)
dec, err := newDecoder(r, filepath.Ext(p.streamURL))
if err != nil {
log.Printf("decoder error: %v", err)
connections.WithLabelValues(p.streamName, "decoder_error").Inc()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment