emiago / diago

Short of Dialog + GO. Library/Framework for building VOIP solutions in GO
Mozilla Public License 2.0
87 stars 9 forks source link

segfault in playback #14

Open mcondie-addsalt opened 3 weeks ago

mcondie-addsalt commented 3 weeks ago

I'm getting a segfault when attempting a basic wav file playback. Are there dependencies that need to be installed on a debian/ubuntu server to support audio processing?


Oct 11 18:05:40.294518 INF New dialog request id=ybgS~v40xA__1f0e7e5d-5ae2-4c71-b1de-abb01d4754d5__LTmpfzxC1
Oct 11 18:05:50.297288 INF Playing a file file=echo-done.wav
Oct 11 18:05:50.297458 INF Dialog finished id=ybgS~v40xA__1f0e7e5d-5ae2-4c71-b1de-abb01d4754d5__LTmpfzxC1
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x49ee07]

goroutine 21 [running]:
io.ReadAtLeast({0x0, 0x0}, {0xc0001ae998, 0x4, 0x4}, 0x4)
    /home/matt/.asdf/installs/golang/1.23.2/go/src/io/io.go:335 +0x67
io.ReadFull(...)
    /home/matt/.asdf/installs/golang/1.23.2/go/src/io/io.go:354
encoding/binary.Read({0x0, 0x0}, {0x81aef0, 0xa29dc0}, {0x6ca6a0, 0xc0001b7808})
    /home/matt/.asdf/installs/golang/1.23.2/go/src/encoding/binary/binary.go:268 +0x35d
github.com/go-audio/riff.(*Parser).IDnSize(0xc0001b7938)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/go-audio/riff@v1.0.0/parser.go:155 +0x58
github.com/go-audio/riff.(*Parser).ParseHeaders(0xc0001b7938)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/go-audio/riff@v1.0.0/parser.go:78 +0x1c
github.com/emiago/diago/audio.(*WavReader).readHeaders(0xc0001b7938)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/diago@v0.4.0/audio/wav_reader.go:34 +0x1a
github.com/emiago/diago/audio.(*WavReader).ReadHeaders(0xc0001b7938)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/diago@v0.4.0/audio/wav_reader.go:26 +0x18
github.com/emiago/diago.(*AudioPlayback).streamWav(0xc0001b7b60, {0x0?, 0x0?}, {0x817080, 0xc00019e620})
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/diago@v0.4.0/playback.go:105 +0x17d
github.com/emiago/diago.(*AudioPlayback).Play(0xc0001b7b60, {0x0?, 0x0?}, {0x7304bd?, 0xd?})
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/diago@v0.4.0/playback.go:63 +0xfb
main.Playback(0xc0001c6900)
    /home/matt/repos/heimdall/main.go:76 +0x299
main.start.func1(0xc0001c6900)
    /home/matt/repos/heimdall/main.go:60 +0xcf
github.com/emiago/diago.NewDiago.func2(0xc0001a68c0, {0x819a60, 0xc0001e0160})
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/diago@v0.4.0/diago.go:192 +0x284
github.com/emiago/sipgo.(*Server).handleRequest(0xc0001a2180, 0xc0001a68c0, {0x819a60, 0xc0001e0160})
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/sipgo@v0.24.2-0.20241009194434-f8762ab672dc/server.go:271 +0xcf
github.com/emiago/sipgo.(*Server).onRequest(...)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/sipgo@v0.24.2-0.20241009194434-f8762ab672dc/server.go:262
github.com/emiago/sipgo/sip.(*TransactionLayer).handleRequest(0xc0001a00a0, 0xc0001a68c0)
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/sipgo@v0.24.2-0.20241009194434-f8762ab672dc/sip/transaction_layer.go:139 +0x584
created by github.com/emiago/sipgo/sip.(*TransactionLayer).handleMessage in goroutine 1
    /home/matt/.asdf/installs/golang/1.23.2/packages/pkg/mod/github.com/emiago/sipgo@v0.24.2-0.20241009194434-f8762ab672dc/sip/transaction_layer.go:67 +0x9c
exit status 2```
emiago commented 3 weeks ago

@mcondie-addsalt no, audio package has no external dependencies. Seems like your wav reader is nil, Check did you handle all your errors. If all ok send me full code then

mcondie-addsalt commented 1 week ago

Here's the entire code file.

// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024, Emir Aganovic

package main

import (
    "context"
    "os"
    "os/signal"
    "time"

    "github.com/emiago/diago"
    "github.com/emiago/diago/media"
    "github.com/emiago/diago/testdata"
    "github.com/emiago/sipgo"
    "github.com/emiago/sipgo/sip"
    "github.com/rs/zerolog"
    "github.com/rs/zerolog/log"
)

// Dial this app with
// gophone dial -media=speaker "sip:123@127.0.0.1"

func main() {
    ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
    defer cancel()

    lev, err := zerolog.ParseLevel(os.Getenv("LOG_LEVEL"))
    if err != nil || lev == zerolog.NoLevel {
        lev = zerolog.InfoLevel
    }

    zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMicro
    log.Logger = zerolog.New(zerolog.ConsoleWriter{
        Out:        os.Stdout,
        TimeFormat: time.StampMicro,
    }).With().Timestamp().Logger().Level(lev)

    sip.SIPDebug = os.Getenv("SIP_DEBUG") == "true"
    media.RTCPDebug = os.Getenv("RTCP_DEBUG") == "true"

    err = start(ctx)
    if err != nil {
        log.Fatal().Err(err).Msg("PBX finished with error")
    }
}

func start(ctx context.Context) error {
    ua, _ := sipgo.NewUA()
    transportTCP := diago.Transport{
        Transport: "udp",
        BindHost:  "0.0.0.0",
        BindPort:  5060,
    }
    tu := diago.NewDiago(ua,
        diago.WithTransport(transportTCP),
    )

    return tu.Serve(ctx, func(inDialog *diago.DialogServerSession) {
        log.Info().Str("id", inDialog.ID).Msg("New dialog request")
        defer log.Info().Str("id", inDialog.ID).Msg("Dialog finished")
        Playback(inDialog)
    })
}

func Playback(inDialog *diago.DialogServerSession) error {
    inDialog.Progress() // Progress -> 100 Trying
    inDialog.Ringing()  // Ringing -> 180 Response
    inDialog.Answer()   // Answer -> 200 Response

    playfile, _ := testdata.OpenFile("echo-test.wav")
    log.Info().Str("file", "echo-test.wav").Msg("Playing a file")

    pb, err := inDialog.PlaybackCreate()
    if err != nil {
        return err
    }
    _, err = pb.Play(playfile, "audio/wav")
    return err
}
mcondie-addsalt commented 1 week ago

I've tried this on a plain GCP vm as well as running in an ubuntu vm (v24) locally and I get the same result.