Compare commits
2 commits
6cc027f24d
...
4421c708d1
Author | SHA1 | Date | |
---|---|---|---|
DataHoarder | 4421c708d1 | ||
DataHoarder | afe0cd7874 |
19
callbacks.c
19
callbacks.c
|
@ -11,6 +11,7 @@
|
|||
#include <opusfile.h>
|
||||
#include <opusenc.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Defined in Go. Uses the same signature as Go, no need for proxy function.
|
||||
int go_readcallback(void *p, unsigned char *buf, int nbytes);
|
||||
|
@ -65,6 +66,12 @@ bridge_encoder_set_dtx(OggOpusEnc *st, opus_int32 use_dtx)
|
|||
return ope_encoder_ctl(st, OPUS_SET_DTX(use_dtx));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_set_application(OggOpusEnc *st, opus_int32 application)
|
||||
{
|
||||
return ope_encoder_ctl(st, OPUS_SET_APPLICATION(application));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_get_dtx(OggOpusEnc *st, opus_int32 *dtx)
|
||||
{
|
||||
|
@ -78,6 +85,18 @@ bridge_encoder_get_sample_rate(OggOpusEnc *st, opus_int32 *sample_rate)
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
bridge_encoder_set_muxing_delay(OggOpusEnc *st, opus_int32 delay)
|
||||
{
|
||||
return ope_encoder_ctl(st, OPE_SET_MUXING_DELAY(delay));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_get_muxing_delay(OggOpusEnc *st, opus_int32 *delay)
|
||||
{
|
||||
return ope_encoder_ctl(st, OPE_GET_MUXING_DELAY(delay));
|
||||
}
|
||||
|
||||
int
|
||||
bridge_encoder_set_bitrate(OggOpusEnc *st, opus_int32 bitrate)
|
||||
{
|
||||
|
|
36
encoder.go
36
encoder.go
|
@ -5,9 +5,11 @@
|
|||
package opus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime/cgo"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -25,6 +27,11 @@ bridge_encoder_get_dtx(OggOpusEnc *st, opus_int32 *dtx);
|
|||
int
|
||||
bridge_encoder_get_sample_rate(OggOpusEnc *st, opus_int32 *sample_rate);
|
||||
|
||||
int
|
||||
bridge_encoder_set_muxing_delay(OggOpusEnc *st, opus_int32 delay);
|
||||
|
||||
int
|
||||
bridge_encoder_get_muxing_delay(OggOpusEnc *st, opus_int32 *delay);
|
||||
|
||||
int
|
||||
bridge_encoder_set_bitrate(OggOpusEnc *st, opus_int32 bitrate);
|
||||
|
@ -56,6 +63,8 @@ bridge_encoder_set_packet_loss_perc(OggOpusEnc *st, opus_int32 loss_perc);
|
|||
int
|
||||
bridge_encoder_get_packet_loss_perc(OggOpusEnc *st, opus_int32 *loss_perc);
|
||||
|
||||
int
|
||||
bridge_encoder_set_application(OggOpusEnc *st, opus_int32 application);
|
||||
|
||||
OpusEncCallbacks * my_write_callbacks();
|
||||
|
||||
|
@ -131,7 +140,9 @@ func (enc *Encoder) Init(sampleRate int, channels int, application Application,
|
|||
enc.handle = cgo.NewHandle(enc)
|
||||
|
||||
var errno C.int
|
||||
if channels > 2 {
|
||||
if channels > 8 {
|
||||
enc.p = C.ope_encoder_create_callbacks(C.my_write_callbacks(), unsafe.Pointer(&enc.handle), C.my_empty_comment(), C.opus_int32(sampleRate), C.int(channels), C.int(255), &errno)
|
||||
} else if channels > 2 {
|
||||
enc.p = C.ope_encoder_create_callbacks(C.my_write_callbacks(), unsafe.Pointer(&enc.handle), C.my_empty_comment(), C.opus_int32(sampleRate), C.int(channels), C.int(1), &errno)
|
||||
} else {
|
||||
enc.p = C.ope_encoder_create_callbacks(C.my_write_callbacks(), unsafe.Pointer(&enc.handle), C.my_empty_comment(), C.opus_int32(sampleRate), C.int(channels), C.int(0), &errno)
|
||||
|
@ -140,6 +151,7 @@ func (enc *Encoder) Init(sampleRate int, channels int, application Application,
|
|||
if errno != 0 {
|
||||
return Error(int(errno))
|
||||
}
|
||||
C.bridge_encoder_set_application(enc.p, C.int(application))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -280,6 +292,28 @@ func (enc *Encoder) Bitrate() (int, error) {
|
|||
return int(bitrate), nil
|
||||
}
|
||||
|
||||
// SetMuxingDelay sets maximum container delay
|
||||
func (enc *Encoder) SetMuxingDelay(delay time.Duration) error {
|
||||
if delay < 0 || delay > time.Millisecond*1000 {
|
||||
return errors.New("value must be between 0 to 1000 milliseconds")
|
||||
}
|
||||
res := C.bridge_encoder_set_muxing_delay(enc.p, C.opus_int32(delay.Milliseconds()*48))
|
||||
if res != C.OPUS_OK {
|
||||
return Error(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MuxingDelay returns the maximum container delay
|
||||
func (enc *Encoder) MuxingDelay() (time.Duration, error) {
|
||||
var delay C.opus_int32
|
||||
res := C.bridge_encoder_get_muxing_delay(enc.p, &delay)
|
||||
if res != C.OPUS_OK {
|
||||
return 0, Error(res)
|
||||
}
|
||||
return time.Millisecond * time.Duration(int(delay)/48), nil
|
||||
}
|
||||
|
||||
// SetComplexity sets the encoder's computational complexity
|
||||
func (enc *Encoder) SetComplexity(complexity int) error {
|
||||
res := C.bridge_encoder_set_complexity(enc.p, C.opus_int32(complexity))
|
||||
|
|
Loading…
Reference in a new issue