本文整理汇总了C++中opus_encoder_ctl函数的典型用法代码示例。如果您正苦于以下问题:C++ opus_encoder_ctl函数的具体用法?C++ opus_encoder_ctl怎么用?C++ opus_encoder_ctl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了opus_encoder_ctl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tdav_codec_opus_open
static int tdav_codec_opus_open(tmedia_codec_t* self)
{
tdav_codec_opus_t* opus = (tdav_codec_opus_t*)self;
int opus_err;
if(!opus) {
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
// Initialize the decoder
if(!opus->decoder.inst) {
TSK_DEBUG_INFO("[OPUS] Open decoder: rate=%d, channels=%d", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels);
if(!(opus->decoder.inst = opus_decoder_create((opus_int32)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, &opus_err)) || opus_err != OPUS_OK) {
TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->in.rate, (int)TMEDIA_CODEC_AUDIO(self)->in.channels, opus_err);
return -2;
}
}
opus->decoder.last_seq = 0;
// Initialize the encoder
if(!opus->encoder.inst) {
TSK_DEBUG_INFO("[OPUS] Open encoder: rate=%d, channels=%d", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels);
if(!(opus->encoder.inst = opus_encoder_create((opus_int32)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, OPUS_APPLICATION_VOIP, &opus_err)) || opus_err != OPUS_OK) {
TSK_DEBUG_ERROR("Failed to create Opus decoder(rate=%d, channels=%d) instance with error code=%d.", (int)self->out.rate, (int)TMEDIA_CODEC_AUDIO(self)->out.channels, opus_err);
return -2;
}
}
#if TDAV_UNDER_MOBILE /* iOS, Android and WP8 */
opus_encoder_ctl(opus->encoder.inst, OPUS_SET_COMPLEXITY(3));
#endif
opus_encoder_ctl(opus->encoder.inst, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
return 0;
}
示例2: init_audio_encoder
static int init_audio_encoder(CSSession *cs)
{
int rc = OPUS_OK;
cs->audio_encoder = opus_encoder_create(cs->audio_encoder_sample_rate,
cs->audio_encoder_channels, OPUS_APPLICATION_AUDIO, &rc);
if ( rc != OPUS_OK ) {
LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc));
return -1;
}
rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_encoder_bitrate));
if ( rc != OPUS_OK ) {
LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
return -1;
}
rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));
if ( rc != OPUS_OK ) {
LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
return -1;
}
return 0;
}
示例3: apply_max_bitrate
static void apply_max_bitrate(OpusEncData *d) {
ms_message("Setting opus codec bitrate to [%i] from network bitrate [%i] with ptime [%i]", d->bitrate, d->max_network_bitrate, d->ptime);
/* give the bitrate to the encoder if exists*/
if (d->state) {
opus_int32 maxBandwidth=0;
/*tell the target bitrate, opus will choose internally the bandwidth to use*/
int error = opus_encoder_ctl(d->state, OPUS_SET_BITRATE(d->bitrate));
if (error != OPUS_OK) {
ms_error("could not set bit rate to opus encoder: %s", opus_strerror(error));
}
/* implement maxplaybackrate parameter, which is constraint on top of bitrate */
if (d->maxplaybackrate <= 8000) {
maxBandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (d->maxplaybackrate <= 12000) {
maxBandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
} else if (d->maxplaybackrate <= 16000) {
maxBandwidth = OPUS_BANDWIDTH_WIDEBAND;
} else if (d->maxplaybackrate <= 24000) {
maxBandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
} else {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
}
if (maxBandwidth!=0){
error = opus_encoder_ctl(d->state, OPUS_SET_MAX_BANDWIDTH(maxBandwidth));
if (error != OPUS_OK) {
ms_error("could not set max bandwidth to opus encoder: %s", opus_strerror(error));
}
}
}
}
示例4: init_audio_encoder
int init_audio_encoder(CodecState *cs, uint32_t audio_channels)
{
int err = OPUS_OK;
cs->audio_encoder = opus_encoder_create(cs->audio_sample_rate, audio_channels, OPUS_APPLICATION_AUDIO, &err);
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_bitrate));
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));
return err == OPUS_OK ? 0 : -1;
}
示例5: opus_encoder_create
EncodeManager::EncodeManager()
{
_enc = opus_encoder_create(SAMPLE_RATE, 2, OPUS_APPLICATION_VOIP, &_err);
_dec = opus_decoder_create(SAMPLE_RATE, 2, &_err);
opus_encoder_ctl(this->_enc, OPUS_GET_BANDWIDTH(&this->_len));
this->_len = FRAMES_PER_BUFFER;
}
示例6: WebRtcOpus_EncoderInit
WebRtc_Word16 WebRtcOpus_EncoderInit(OPUS_encinst_t* encInst,
WebRtc_Word16 samplFreq,
WebRtc_Word16 mode,
WebRtc_Word16 vbrFlag){
opus_encoder_ctl(((OPUS_Enc_Inst_t*)encInst)->enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
return (0);
}
示例7: opus_enc_init
int opus_enc_init(opus_enc *opus)
{
int err;
err = 0;
opus->header = (OpusHeader *)calloc(1, sizeof(OpusHeader));
opus->header_data = (unsigned char *)calloc (1, 1024);
opus->tags = (unsigned char *)calloc (1, 1024);
opus->buffer = (unsigned char *)calloc (1, 4 * 4096);
srand(time(NULL));
ogg_stream_init(&opus->os, rand());
opus->header->gain = 0;
opus->header->channels = opus->channel;
if ((opus->bitrate < 8000) || (opus->bitrate > 320000)) {
opus->bitrate = DEFAULT_OPUS_BITRATE;
}
opus->header->input_sample_rate = 48000;
opus->encoder = opus_encoder_create (opus->header->input_sample_rate, opus->channel, OPUS_APPLICATION_AUDIO, &err);
opus_encoder_ctl (opus->encoder, OPUS_SET_BITRATE(opus->bitrate));
if (opus->encoder == NULL) {
printf("Opus Encoder creation error: %s\n", opus_strerror (err));
return 1;
}
opus->last_bitrate = opus->bitrate;
opus_encoder_ctl (opus->encoder, OPUS_GET_LOOKAHEAD (&opus->header->preskip));
opus->header_size = opus_header_to_packet (opus->header, opus->header_data, 100);
opus->tags_size =
8 + 4 + strlen (opus_get_version_string ()) + 4 + 4 + strlen ("ENCODER=") + strlen (VERSION);
memcpy (opus->tags, "OpusTags", 8);
opus->tags[8] = strlen (opus_get_version_string ());
memcpy (opus->tags + 12, opus_get_version_string (), strlen (opus_get_version_string ()));
opus->tags[12 + strlen (opus_get_version_string ())] = 1;
opus->tags[12 + strlen (opus_get_version_string ()) + 4] = strlen ("ENCODER=") + strlen (VERSION);
memcpy (opus->tags + 12 + strlen (opus_get_version_string ()) + 4 + 4, "ENCODER=", strlen ("ENCODER="));
memcpy (opus->tags + 12 + strlen (opus_get_version_string ()) + 4 + 4 + strlen ("ENCODER="),
VERSION,
strlen (VERSION));
//printf("Opus Encoder Created\n");
return 0;
}
示例8: opus_encoder_create
OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
{
int status = OPUS_OK;
OpusEncoder *rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_VOIP, &status);
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status));
return NULL;
}
status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate));
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
goto FAILURE;
}
/* Enable in-band forward error correction in codec */
status = opus_encoder_ctl(rc, OPUS_SET_INBAND_FEC(1));
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
goto FAILURE;
}
/* Make codec resistant to up to 10% packet loss
* NOTE This could also be adjusted on the fly, rather than hard-coded,
* with feedback from the receiving client.
*/
status = opus_encoder_ctl(rc, OPUS_SET_PACKET_LOSS_PERC(10));
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
goto FAILURE;
}
/* Set algorithm to the highest complexity, maximizing compression */
status = opus_encoder_ctl(rc, OPUS_SET_COMPLEXITY(10));
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
goto FAILURE;
}
return rc;
FAILURE:
opus_encoder_destroy(rc);
return NULL;
}
示例9: opus_encoder_ctl
int AudioInput::encodeOpusFrame(short *source, int size, EncodingOutputBuffer& buffer) {
int len = 0;
#ifdef USE_OPUS
if (!bPreviousVoice)
opus_encoder_ctl(opusState, OPUS_RESET_STATE, NULL);
opus_encoder_ctl(opusState, OPUS_SET_BITRATE(iAudioQuality));
len = opus_encode(opusState, source, size, &buffer[0], buffer.size());
const int tenMsFrameCount = (size / iFrameSize);
iBitrate = (len * 100 * 8) / tenMsFrameCount;
#endif
return len;
}
示例10: UE_LOG
bool FVoiceEncoderOpus::Init(int32 InSampleRate, int32 InNumChannels)
{
UE_LOG(LogVoiceEncode, Display, TEXT("EncoderVersion: %s"), ANSI_TO_TCHAR(opus_get_version_string()));
SampleRate = InSampleRate;
NumChannels = InNumChannels;
// 20ms frame sizes are a good choice for most applications (1000ms / 20ms = 50)
FrameSize = SampleRate / NUM_OPUS_FRAMES_PER_SEC;
//MaxFrameSize = FrameSize * MAX_OPUS_FRAMES;
int32 EncError = 0;
#if USE_UE4_MEM_ALLOC
int32 EncSize = opus_encoder_get_size(NumChannels);
Encoder = (OpusEncoder*)FMemory::Malloc(EncSize);
EncError = opus_encoder_init(Encoder, SampleRate, NumChannels, OPUS_APPLICATION_VOIP);
#else
Encoder = opus_encoder_create(SampleRate, NumChannels, OPUS_APPLICATION_VOIP, &EncError);
#endif
if (EncError != OPUS_OK)
{
UE_LOG(LogVoiceEncode, Warning, TEXT("Failed to init Opus Encoder: %s"), ANSI_TO_TCHAR(opus_strerror(EncError)));
Destroy();
}
// Turn on variable bit rate encoding
int32 UseVbr = 1;
opus_encoder_ctl(Encoder, OPUS_SET_VBR(UseVbr));
// Turn off constrained VBR
int32 UseCVbr = 0;
opus_encoder_ctl(Encoder, OPUS_SET_VBR_CONSTRAINT(UseCVbr));
// Complexity (1-10)
int32 Complexity = 1;
opus_encoder_ctl(Encoder, OPUS_SET_COMPLEXITY(Complexity));
// Forward error correction
int32 InbandFEC = 0;
opus_encoder_ctl(Encoder, OPUS_SET_INBAND_FEC(InbandFEC));
#if DEBUG_OPUS
DebugEncoderInfo(Encoder);
#endif // DEBUG_OPUS
return EncError == OPUS_OK;
}
示例11: apply_max_bitrate
static void apply_max_bitrate(OpusEncData *d) {
ms_message("Setting opus codec bitrate to [%i] from network bitrate [%i] with ptime [%i]", d->bitrate, d->max_network_bitrate, d->ptime);
/* give the bitrate to the encoder if exists*/
if (d->state) {
opus_int32 maxBandwidth;
int error = opus_encoder_ctl(d->state, OPUS_SET_BITRATE(d->bitrate));
if (error != OPUS_OK) {
ms_error("could not set bit rate to opus encoder: %s", opus_strerror(error));
}
/* set output sampling rate according to bitrate and RFC section 3.1.1 */
if (d->bitrate<12000) {
maxBandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (d->bitrate<20000) {
maxBandwidth = OPUS_BANDWIDTH_WIDEBAND;
} else if (d->bitrate<40000) {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
} else if (d->bitrate<64000) {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
} else {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
}
/* check if selected maxBandwidth is compatible with the maxplaybackrate parameter */
if (d->maxplaybackrate < 12000) {
maxBandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (d->maxplaybackrate < 16000) {
if (maxBandwidth != OPUS_BANDWIDTH_NARROWBAND) {
maxBandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
}
} else if (d->maxplaybackrate < 24000) {
if (maxBandwidth != OPUS_BANDWIDTH_NARROWBAND) {
maxBandwidth = OPUS_BANDWIDTH_WIDEBAND;
}
} else if (d->maxplaybackrate < 48000) {
if (maxBandwidth == OPUS_BANDWIDTH_FULLBAND) {
maxBandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
}
}
error = opus_encoder_ctl(d->state, OPUS_SET_MAX_BANDWIDTH(maxBandwidth));
if (error != OPUS_OK) {
ms_error("could not set max bandwidth to opus encoder: %s", opus_strerror(error));
}
}
}
示例12: reconfigure_audio_encoder
bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch,
int32_t *old_br, int32_t *old_sr, int32_t *old_ch)
{
/* Values are checked in toxav.c */
if (*old_sr != new_sr || *old_ch != new_ch) {
OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch);
if (new_encoder == NULL) {
return false;
}
opus_encoder_destroy(*e);
*e = new_encoder;
} else if (*old_br == new_br) {
return true; /* Nothing changed */
}
int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br));
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
return false;
}
*old_br = new_br;
*old_sr = new_sr;
*old_ch = new_ch;
LOGGER_DEBUG(log, "Reconfigured audio encoder br: %d sr: %d cc:%d", new_br, new_sr, new_ch);
return true;
}
示例13: opus_encoder_ctl
int AudioInput::encodeOpusFrame(short *source, int size, EncodingOutputBuffer& buffer) {
int len = 0;
#ifdef USE_OPUS
if (bResetEncoder) {
opus_encoder_ctl(opusState, OPUS_RESET_STATE, NULL);
bResetEncoder = false;
}
opus_encoder_ctl(opusState, OPUS_SET_BITRATE(iAudioQuality));
len = opus_encode(opusState, source, size, &buffer[0], static_cast<opus_int32>(buffer.size()));
const int tenMsFrameCount = (size / iFrameSize);
iBitrate = (len * 100 * 8) / tenMsFrameCount;
#endif
return len;
}
示例14: opus_enc_write_header
//This function needs to be called before
//every connection
void opus_enc_write_header(opus_enc *opus)
{
ogg_packet op;
ogg_stream_clear (&opus->os);
ogg_stream_init(&opus->os, rand());
opus_encoder_ctl (opus->encoder, OPUS_RESET_STATE);
opus->packetno = 0;
opus->granulepos = 0;
op.b_o_s = 1;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = opus->packetno++;
op.packet = opus->header_data;
op.bytes = opus->header_size;
ogg_stream_packetin (&opus->os, &op);
op.b_o_s = 0;
op.e_o_s = 0;
op.granulepos = 0;
op.packetno = opus->packetno++;
op.packet = opus->tags;
op.bytes = opus->tags_size;
ogg_stream_packetin (&opus->os, &op);
}
示例15: ms_opus_enc_preprocess
static void ms_opus_enc_preprocess(MSFilter *f) {
int error;
OpusEncData *d = (OpusEncData *)f->data;
/* create the encoder */
d->state = opus_encoder_create(d->samplerate, d->channels, d->application, &error);
if (error != OPUS_OK) {
ms_error("Opus encoder creation failed: %s", opus_strerror(error));
return;
}
/* set complexity to 0 for single processor arm devices */
#if defined(__arm__) || defined(_M_ARM)
if (ms_factory_get_cpu_count(f->factory)==1){
opus_encoder_ctl(d->state, OPUS_SET_COMPLEXITY(0));
}else{
opus_encoder_ctl(d->state, OPUS_SET_COMPLEXITY(5));
}
#endif
error = opus_encoder_ctl(d->state, OPUS_SET_PACKET_LOSS_PERC(10));
if (error != OPUS_OK) {
ms_error("Could not set default loss percentage to opus encoder: %s", opus_strerror(error));
}
/* set the encoder parameters: VBR, IN_BAND_FEC, DTX and bitrate settings */
ms_opus_enc_set_vbr(f);
ms_opus_enc_set_inbandfec(f);
ms_opus_enc_set_dtx(f);
/* if decoder prefers mono signal, force encoder to output mono signal */
if (d->stereo == 0) {
error = opus_encoder_ctl(d->state, OPUS_SET_FORCE_CHANNELS(1));
if (error != OPUS_OK) {
ms_error("could not force mono channel to opus encoder: %s", opus_strerror(error));
}
if (d->channels == 2) ms_message("Opus encoder configured to encode mono despite it is feed with stereo.");
}else if (d->channels == 2){
ms_message("Opus encoder configured to encode stereo.");
}
ms_filter_lock(f);
// set bitrate wasn't call, compute it with the default network bitrate (36000)
if (d->bitrate==-1) {
compute_max_bitrate(d, 0);
}
apply_max_bitrate(d);
ms_filter_unlock(f);
}