diff --git a/commands.go b/commands.go index a826461..cd5ee21 100644 --- a/commands.go +++ b/commands.go @@ -2,13 +2,14 @@ package gobaresip import ( "bytes" - "encoding/json" "fmt" "strconv" "strings" "sync/atomic" "time" "unicode" + + "github.com/goccy/go-json" ) /* diff --git a/go.mod b/go.mod index 6a044f2..b328219 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/negbie/go-baresip go 1.16 -require github.com/gorilla/websocket v1.4.2 +require ( + github.com/goccy/go-json v0.6.1 + github.com/gorilla/websocket v1.4.2 +) diff --git a/go.sum b/go.sum index 85efffd..d48fae7 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ +github.com/goccy/go-json v0.6.1 h1:O7xC9WR7B09imThbRIEMIWK4MVcxOsLzWtGe16cv5SU= +github.com/goccy/go-json v0.6.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= diff --git a/gobaresip.go b/gobaresip.go index 80e3614..d72b379 100644 --- a/gobaresip.go +++ b/gobaresip.go @@ -68,7 +68,6 @@ int mainLoop(){ import "C" import ( "bytes" - "encoding/json" "fmt" "log" "net" @@ -79,6 +78,8 @@ import ( "sync/atomic" "time" "unsafe" + + "github.com/goccy/go-json" ) //ResponseMsg @@ -221,7 +222,7 @@ func (b *Baresip) read() { b.eventChan <- e if b.wsAddr != "" { select { - case b.eventWsChan <- appendByte(e.RawJSON, []byte("\n")): + case b.eventWsChan <- e.RawJSON: default: } } @@ -271,7 +272,7 @@ func (b *Baresip) read() { b.responseChan <- r if b.wsAddr != "" { select { - case b.responseWsChan <- appendByte(r.RawJSON, []byte("\n")): + case b.responseWsChan <- r.RawJSON: default: } } @@ -279,13 +280,6 @@ func (b *Baresip) read() { } } -func appendByte(prefix []byte, suffix []byte) []byte { - b := make([]byte, len(prefix)+len(suffix)) - n := copy(b, prefix) - copy(b[n:], suffix) - return b -} - func findID(data []byte) string { if posA := bytes.Index(data, []byte("call id: ")); posA > 0 { if posB := bytes.Index(data[posA:], []byte("\n")); posB > 0 { diff --git a/libbaresip/baresip/include/baresip.h b/libbaresip/baresip/include/baresip.h index 4e457be..5e75ee9 100644 --- a/libbaresip/baresip/include/baresip.h +++ b/libbaresip/baresip/include/baresip.h @@ -129,6 +129,8 @@ const char *account_call_transfer(const struct account *acc); const char *account_extra(const struct account *acc); int account_uri_complete(const struct account *acc, struct mbuf *buf, const char *uri); +int account_answerdelay(const struct account *acc); +void account_set_answerdelay(struct account *acc, int adelay); bool account_sip_autoanswer(const struct account *acc); void account_set_sip_autoanswer(struct account *acc, bool allow); enum sipansbeep account_sipansbeep(const struct account *acc); diff --git a/libbaresip/baresip/libbaresip.a b/libbaresip/baresip/libbaresip.a index 47f1dd2..7b9315b 100644 Binary files a/libbaresip/baresip/libbaresip.a and b/libbaresip/baresip/libbaresip.a differ diff --git a/libbaresip/openssl/libcrypto.a b/libbaresip/openssl/libcrypto.a index cebfb73..80738f6 100644 Binary files a/libbaresip/openssl/libcrypto.a and b/libbaresip/openssl/libcrypto.a differ diff --git a/libbaresip/rem/include/rem_au.h b/libbaresip/rem/include/rem_au.h index 50355c8..1256647 100644 --- a/libbaresip/rem/include/rem_au.h +++ b/libbaresip/rem/include/rem_au.h @@ -12,6 +12,7 @@ enum aufmt { AUFMT_PCMU, /**< G.711 U-law */ AUFMT_FLOAT, /**< Float 32 bit (CPU endian) */ AUFMT_S24_3LE,/**< Signed 24bit Little Endian in 3bytes format */ + AUFMT_RAW, /**< RAW PCM */ }; size_t aufmt_sample_size(enum aufmt fmt); diff --git a/libbaresip/rem/include/rem_auframe.h b/libbaresip/rem/include/rem_auframe.h index e9f4f5f..ef1a8ee 100644 --- a/libbaresip/rem/include/rem_auframe.h +++ b/libbaresip/rem/include/rem_auframe.h @@ -6,7 +6,7 @@ * Defines a frame of audio samples */ struct auframe { - int fmt; /**< Sample format (enum aufmt) */ + enum aufmt fmt; /**< Sample format (enum aufmt) */ void *sampv; /**< Audio samples (must be mem_ref'd) */ size_t sampc; /**< Total number of audio samples */ uint64_t timestamp; /**< Timestamp in AUDIO_TIMEBASE units */ @@ -14,7 +14,7 @@ struct auframe { uint8_t ch; /**< Channels */ }; -void auframe_init(struct auframe *af, int fmt, void *sampv, size_t sampc, - uint32_t srate, uint8_t ch); +void auframe_init(struct auframe *af, enum aufmt fmt, void *sampv, + size_t sampc, uint32_t srate, uint8_t ch); size_t auframe_size(const struct auframe *af); void auframe_mute(struct auframe *af); diff --git a/libbaresip/rem/librem.a b/libbaresip/rem/librem.a index 491d0c5..4bd8455 100644 Binary files a/libbaresip/rem/librem.a and b/libbaresip/rem/librem.a differ diff --git a/ws.go b/ws.go index c402cc2..915ee1f 100644 --- a/ws.go +++ b/ws.go @@ -23,6 +23,10 @@ const ( maxMessageSize = 1024 ) +var ( + newline = []byte{'\n'} +) + var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, @@ -94,6 +98,7 @@ func (c *client) writePump() { // Add queued messages to the current websocket message. n := len(c.send) for i := 0; i < n; i++ { + w.Write(newline) w.Write(<-c.send) }