MCPcopy Create free account
hub / github.com/78/tenbox / Open

Method Open

src/daemon/opus_audio_encoder.cpp:19–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19bool OpusAudioEncoder::Open(uint32_t sample_rate, uint32_t channels, std::string* error) {
20 Close();
21 if (sample_rate != 48000 || channels == 0 || channels > 2) {
22 if (error) *error = "only 48kHz mono/stereo PCM is supported for Opus encoding";
23 return false;
24 }
25
26 int opus_error = OPUS_OK;
27 OpusEncoder* encoder = opus_encoder_create(
28 static_cast<opus_int32>(sample_rate),
29 static_cast<int>(channels),
30 OPUS_APPLICATION_RESTRICTED_LOWDELAY,
31 &opus_error);
32 if (!encoder || opus_error != OPUS_OK) {
33 if (error) *error = opus_strerror(opus_error);
34 if (encoder) opus_encoder_destroy(encoder);
35 return false;
36 }
37
38 opus_encoder_ctl(encoder, OPUS_SET_BITRATE(64000));
39 opus_encoder_ctl(encoder, OPUS_SET_VBR(1));
40 opus_encoder_ctl(encoder, OPUS_SET_VBR_CONSTRAINT(0));
41 opus_encoder_ctl(encoder, OPUS_SET_COMPLEXITY(5));
42 opus_encoder_ctl(encoder, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
43 opus_encoder_ctl(encoder, OPUS_SET_INBAND_FEC(0));
44 opus_encoder_ctl(encoder, OPUS_SET_DTX(1));
45
46 impl_ = std::make_unique<Impl>();
47 impl_->encoder = encoder;
48 impl_->sample_rate = sample_rate;
49 impl_->channels = channels;
50 encoded_.resize(4096);
51 return true;
52}
53
54bool OpusAudioEncoder::Encode(const AudioChunk& chunk, EncodedAudioFrame* output, std::string* error) {
55 if (!impl_ || !impl_->encoder) {

Callers 4

ProbeH264EncoderFunction · 0.45
HandleRuntimeMessageMethod · 0.45
AudioPumpMainMethod · 0.45
VideoPumpMainMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected