/*
#cgo pkg-config: opus
#include <opus/opus.h>
+
+int bridge_set_dtx(OpusEncoder *st, int use_dtx) {
+ return opus_encoder_ctl(st, OPUS_SET_DTX(use_dtx));
+}
+
+int bridge_get_dtx(OpusEncoder *st) {
+ int dtx = 0;
+ opus_encoder_ctl(st, OPUS_GET_DTX(&dtx));
+ return dtx;
+}
*/
import "C"
}
return n, nil
}
+
+// Configures the encoder's use of discontinuous transmission (DTX).
+func (enc *Encoder) UseDTX(use bool) {
+ dtx := 0
+ if use {
+ dtx = 1
+ }
+ C.bridge_set_dtx(enc.p, C.int(dtx))
+}
+
+func (enc *Encoder) GetDTX() bool {
+ dtx := C.bridge_get_dtx(enc.p)
+ return dtx != 0
+}
--- /dev/null
+// Copyright © 2015, 2016 Hraban Luyat <hraban@0brg.net>
+//
+// License for use of this code is detailed in the LICENSE file
+
+package opus
+
+import "testing"
+
+func TestUseDTX(t *testing.T) {
+ enc, err := NewEncoder(8000, 1, APPLICATION_VOIP)
+ if err != nil || enc == nil {
+ t.Errorf("Error creating new encoder: %v", err)
+ }
+ vals := []bool{true, false}
+ for _, dtx := range vals {
+ enc.UseDTX(dtx)
+ gotv := enc.GetDTX()
+ if gotv != dtx {
+ t.Errorf("Error set dtx: expect dtx=%v, got dtx=%v", dtx, gotv)
+ }
+ }
+}