Added packet loss and inband fec encoder ctls
This commit is contained in:
parent
ffc1be2bfb
commit
01412cbea5
64
encoder.go
64
encoder.go
|
@ -68,6 +68,30 @@ bridge_encoder_get_max_bandwidth(OpusEncoder *st, opus_int32 *max_bw)
|
|||
return opus_encoder_ctl(st, OPUS_GET_MAX_BANDWIDTH(max_bw));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_set_inband_fec(OpusEncoder *st, opus_int32 fec)
|
||||
{
|
||||
return opus_encoder_ctl(st, OPUS_SET_INBAND_FEC(fec));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_get_inband_fec(OpusEncoder *st, opus_int32 *fec)
|
||||
{
|
||||
return opus_encoder_ctl(st, OPUS_GET_INBAND_FEC(fec));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_set_packet_loss_perc(OpusEncoder *st, opus_int32 loss_perc)
|
||||
{
|
||||
return opus_encoder_ctl(st, OPUS_SET_PACKET_LOSS_PERC(loss_perc));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_get_packet_loss_perc(OpusEncoder *st, opus_int32 *loss_perc)
|
||||
{
|
||||
return opus_encoder_ctl(st, OPUS_GET_PACKET_LOSS_PERC(loss_perc));
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
@ -301,3 +325,43 @@ func (enc *Encoder) MaxBandwidth() (Bandwidth, error) {
|
|||
}
|
||||
return Bandwidth(maxBw), nil
|
||||
}
|
||||
|
||||
|
||||
// SetInBandFEC configures the encoder's use of inband forward error
|
||||
// correction (FEC)
|
||||
func (enc *Encoder) SetInBandFEC(fec int) error {
|
||||
res := C.bridge_encoder_set_inband_fec(enc.p, C.opus_int32(fec))
|
||||
if res != C.OPUS_OK {
|
||||
return Error(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InBandFEC gets the encoder's configured inband forward error correction (FEC)
|
||||
func (enc *Encoder) InBandFEC() (int, error) {
|
||||
var fec C.opus_int32
|
||||
res := C.bridge_encoder_get_inband_fec(enc.p, &fec)
|
||||
if res != C.OPUS_OK {
|
||||
return 0, Error(res)
|
||||
}
|
||||
return int(fec), nil
|
||||
}
|
||||
|
||||
// SetPacketLossPerc configures the encoder's expected packet loss percentage.
|
||||
func (enc *Encoder) SetPacketLossPerc(lossPerc int) error {
|
||||
res := C.bridge_encoder_set_packet_loss_perc(enc.p, C.opus_int32(lossPerc))
|
||||
if res != C.OPUS_OK {
|
||||
return Error(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PacketLossPerc gets the encoder's configured packet loss percentage.
|
||||
func (enc *Encoder) PacketLossPerc() (int, error) {
|
||||
var lossPerc C.opus_int32
|
||||
res := C.bridge_encoder_get_packet_loss_perc(enc.p, &lossPerc)
|
||||
if res != C.OPUS_OK {
|
||||
return 0, Error(res)
|
||||
}
|
||||
return int(lossPerc), nil
|
||||
}
|
||||
|
|
|
@ -259,3 +259,57 @@ func TestEncoder_SetGetMaxBandwidth(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoder_SetGetInBandFEC(t *testing.T) {
|
||||
enc, err := NewEncoder(8000, 1, AppVoIP)
|
||||
if err != nil || enc == nil {
|
||||
t.Errorf("Error creating new encoder: %v", err)
|
||||
}
|
||||
|
||||
|
||||
if err := enc.SetInBandFEC(1); err != nil {
|
||||
t.Error("Error setting fec:", err)
|
||||
}
|
||||
|
||||
fec, err := enc.InBandFEC()
|
||||
if err != nil {
|
||||
t.Error("Error getting fec", err)
|
||||
}
|
||||
if fec !=1{
|
||||
t.Error("Wrong fec value ")
|
||||
}
|
||||
|
||||
if err := enc.SetInBandFEC(0); err != nil {
|
||||
t.Error("Error setting fec:", err)
|
||||
}
|
||||
|
||||
fec, err = enc.InBandFEC()
|
||||
if err != nil {
|
||||
t.Error("Error getting fec", err)
|
||||
}
|
||||
if fec !=0{
|
||||
t.Error("Wrong fec value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncoder_SetGetPacketLossPerc(t *testing.T) {
|
||||
enc, err := NewEncoder(8000, 1, AppVoIP)
|
||||
if err != nil || enc == nil {
|
||||
t.Errorf("Error creating new encoder: %v", err)
|
||||
}
|
||||
vals := []int{0, 5, 10, 20}
|
||||
for _, lossPerc := range vals {
|
||||
err := enc.SetPacketLossPerc(lossPerc)
|
||||
if err != nil {
|
||||
t.Error("Error setting loss percentage value:", err)
|
||||
}
|
||||
lp, err := enc.PacketLossPerc()
|
||||
if err != nil {
|
||||
t.Error("Error getting loss percentage value", err)
|
||||
}
|
||||
if lp != lossPerc {
|
||||
t.Errorf("Unexpected encoder loss percentage value. Got %d, but expected %d",
|
||||
lp, lossPerc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue