int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) { int error_l; int error_r; OpusDecInst* state; // Create Opus decoder memory. state = (OpusDecInst*) calloc(1, sizeof(OpusDecInst)); if (state == NULL) { return -1; } // Create new memory for left and right channel, always at 48000 Hz. state->decoder_left = opus_decoder_create(48000, channels, &error_l); state->decoder_right = opus_decoder_create(48000, channels, &error_r); if (error_l == OPUS_OK && error_r == OPUS_OK && state->decoder_left != NULL && state->decoder_right != NULL) { // Creation of memory all ok. state->channels = channels; *inst = state; return 0; } // If memory allocation was unsuccessful, free the entire state. if (state->decoder_left) { opus_decoder_destroy(state->decoder_left); } if (state->decoder_right) { opus_decoder_destroy(state->decoder_right); } free(state); state = NULL; return -1; }
void cs_kill(CSSession *cs) { if (!cs) return; /* queue_message will not be called since it's unregistered before cs_kill is called */ pthread_mutex_destroy(cs->queue_mutex); if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); if ( cs->audio_decoder ) opus_decoder_destroy(cs->audio_decoder); if ( cs->capabilities & cs_VideoDecoding ) vpx_codec_destroy(&cs->v_decoder); if ( cs->capabilities & cs_VideoEncoding ) vpx_codec_destroy(&cs->v_encoder); jbuf_free(cs->j_buf); buffer_free(cs->vbuf_raw); free(cs->frame_buf); LOGGER_DEBUG("Terminated codec state: %p", cs); free(cs); }
static void gst_opus_dec_reset (GstOpusDec * dec) { gst_segment_init (&dec->segment, GST_FORMAT_UNDEFINED); dec->granulepos = -1; dec->packetno = 0; dec->frame_size = 0; dec->frame_samples = 960; dec->frame_duration = 0; if (dec->state) { opus_decoder_destroy (dec->state); dec->state = NULL; } #if 0 if (dec->mode) { opus_mode_destroy (dec->mode); dec->mode = NULL; } #endif gst_buffer_replace (&dec->streamheader, NULL); gst_buffer_replace (&dec->vorbiscomment, NULL); g_list_foreach (dec->extra_headers, (GFunc) gst_mini_object_unref, NULL); g_list_free (dec->extra_headers); dec->extra_headers = NULL; #if 0 memset (&dec->header, 0, sizeof (dec->header)); #endif }
SoundOpusData::~SoundOpusData() { delete _opusData; delete _samples; foreach(dec, decoders) opus_decoder_destroy(dec->decoder); }
void Opus::setOptimalFormat(uint32_t sample_rate, uint8_t channels) { // Use a SR higher or equal to sample_rate. // Typical case: 44.1kHz => 48kHz. unsigned i = 0; while (i < VALID_SAMPLING_RATE_NUM - 1 and VALID_SAMPLING_RATE[i] < sample_rate) i++; sample_rate = VALID_SAMPLING_RATE[i]; // Opus supports 1 or 2 channels. channels = std::max(std::min(channels, (uint8_t) 2), (uint8_t) 1); if (not (!encoder_ || !decoder_ || sample_rate != clockRateCur_ || channels != channelsCur_)) return; clockRateCur_ = sample_rate; channelsCur_ = channels; int err; if (encoder_) opus_encoder_destroy(encoder_); encoder_ = opus_encoder_create(sample_rate, channels, OPUS_APPLICATION_VOIP, &err); if (err) throw std::runtime_error("opus: could not create encoder"); if (decoder_) opus_decoder_destroy(decoder_); lastDecodedFrameSize_ = 0; decoder_ = opus_decoder_create(sample_rate, channels, &err); if (err) throw std::runtime_error("opus: could not create decoder"); }
Opus::~Opus() { if (encoder_) opus_encoder_destroy(encoder_); if (decoder_) opus_decoder_destroy(decoder_); }
bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels) { if (sampling_rate != ac->ld_sample_rate || channels != ac->ld_channel_count) { if (current_time_monotonic() - ac->ldrts < 500) { return false; } int status; OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status); if (status != OPUS_OK) { LOGGER_ERROR(ac->log, "Error while starting audio decoder(%d %d): %s", sampling_rate, channels, opus_strerror(status)); return false; } ac->ld_sample_rate = sampling_rate; ac->ld_channel_count = channels; ac->ldrts = current_time_monotonic(); opus_decoder_destroy(ac->decoder); ac->decoder = new_dec; LOGGER_DEBUG(ac->log, "Reconfigured audio decoder sr: %d cc: %d", sampling_rate, channels); } return true; }
static void ms_opus_dec_postprocess(MSFilter *f) { OpusDecData *d = (OpusDecData *)f->data; ms_message("opus decoder stats: fec %d packets - plc %d packets.", d->statsfec, d->statsplc); opus_decoder_destroy(d->state); d->state = NULL; ms_concealer_context_destroy(d->concealer); d->concealer=NULL; }
OpusDecode::~OpusDecode() { if (!initialized) return; /*Destroy the encoder state*/ opus_decoder_destroy(decoder); }
irforeach(i, decoders) { if( ++ decoders[i].unusedCount >= 5) { opus_decoder_destroy(decoders[i].decoder); decoders.erase(i); } }
CODEC_API int PLG_FREE_V1(opus_48000)(void* opaqueCodecContext, int isDecoder) { int status = RPLG_INVALID_ARGUMENT; assert(opaqueCodecContext); if(opaqueCodecContext) { struct MpCodecOpusCodecState* codecContext = (struct MpCodecOpusCodecState*) opaqueCodecContext; if(isDecoder) { assert(codecContext->mCodecType == CODEC_DECODE); assert(codecContext->mpDecoderContext); if(codecContext->mpDecoderContext) { opus_encoder_destroy(codecContext->mpDecoderContext); status = RPLG_BAD_HANDLE; codecContext->mpDecoderContext = NULL; } else { status = RPLG_BAD_HANDLE; } } else { assert(codecContext->mCodecType == CODEC_ENCODE); assert(codecContext->mpEncoderContext); if(codecContext->mpEncoderContext) { opus_decoder_destroy(codecContext->mpEncoderContext); status = RPLG_BAD_HANDLE; codecContext->mpEncoderContext = NULL; } else { status = RPLG_BAD_HANDLE; } } if(codecContext->mFmtp) { free(codecContext->mFmtp); codecContext->mFmtp = NULL; } free(codecContext); codecContext = NULL; opaqueCodecContext = NULL; } return(status); }
static void ms_opus_dec_uninit(MSFilter *f) { OpusDecData *d = (OpusDecData *)f->data; if (d == NULL) return; if (d->state) { opus_decoder_destroy(d->state); d->state = NULL; } ms_free(d); }
static void audio_renderer_cleanup() { if (decoder != NULL) opus_decoder_destroy(decoder); if (handle != NULL) { snd_pcm_drain(handle); snd_pcm_close(handle); } }
void FVoiceDecoderOpus::Destroy() { #if USE_UE4_MEM_ALLOC FMemory::Free(Decoder); #else opus_decoder_destroy(Decoder); #endif Decoder = NULL; }
void opus_destroy(long h_inst) { opus_state_t* codec_inst; if (h_inst) { codec_inst = (opus_state_t*)h_inst; opus_encoder_destroy(codec_inst->opus_enc); opus_decoder_destroy(codec_inst->opus_dec); free(codec_inst); } }
static void destructor(void *arg) { struct aucodec_st *st = arg; if (st->enc) opus_encoder_destroy(st->enc); if (st->dec) opus_decoder_destroy(st->dec); mem_deref(st->ac); }
OpusDecoderClass::~OpusDecoderClass() { if (m_initialized) { m_initialized = false; /*Destroy the encoder state*/ opus_decoder_destroy(m_decoder); } STOP_THREAD }
static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) { Group_Peer_AV *peer_av = peer_object; if (!peer_av) return; if (peer_av->audio_decoder) opus_decoder_destroy(peer_av->audio_decoder); terminate_queue(peer_av->buffer); free(peer_object); }
void pa_transcode_free(pa_transcode *transcode) { switch(transcode->encoding) { #ifdef HAVE_OPUS case PA_ENCODING_OPUS: opus_decoder_destroy(transcode->decoder); break; #endif default: transcode->decoder = NULL; } }
void ac_kill(ACSession *ac) { if (!ac) return; opus_encoder_destroy(ac->encoder); opus_decoder_destroy(ac->decoder); jbuf_free(ac->j_buf); pthread_mutex_destroy(ac->queue_mutex); LOGGER_DEBUG("Terminated audio handler: %p", ac); free(ac); }
static void opustolin_destroy(struct ast_trans_pvt *arg) { struct opus_coder_pvt *opvt = arg->pvt; if (!opvt || !opvt->opus) { return; } opus_decoder_destroy(opvt->opus); opvt->opus = NULL; ast_atomic_fetchadd_int(&usage.decoders, -1); ast_debug(3, "Destroyed decoder #%d (opus->%d)\n", opvt->id, opvt->sampling_rate); }
void ac_kill(ACSession *ac) { if (!ac) { return; } opus_encoder_destroy(ac->encoder); opus_decoder_destroy(ac->decoder); jbuf_free((struct JitterBuffer *)ac->j_buf); pthread_mutex_destroy(ac->queue_mutex); LOGGER_DEBUG(ac->log, "Terminated audio handler: %p", ac); free(ac); }
/* destructor */ static tsk_object_t* tdav_codec_opus_dtor(tsk_object_t * self) { tdav_codec_opus_t *opus = self; if(opus) { /* deinit base */ tmedia_codec_audio_deinit(opus); /* deinit self */ if(opus->decoder.inst) { opus_decoder_destroy(opus->decoder.inst), opus->decoder.inst = tsk_null; } if(opus->encoder.inst) { opus_encoder_destroy(opus->encoder.inst), opus->encoder.inst = tsk_null; } } return self; }
void codec_terminate_session ( CodecState *cs ) { if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); if ( cs->audio_decoder ) opus_decoder_destroy(cs->audio_decoder); /* TODO: Terminate video * Do what??? */ if ( cs->supported_actions & v_decoding ) vpx_codec_destroy(&cs->v_decoder); if ( cs->supported_actions & v_encoding ) vpx_codec_destroy(&cs->v_encoder); }
void codec_terminate_session ( CodecState *cs ) { if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); if ( cs->audio_decoder ) opus_decoder_destroy(cs->audio_decoder); /* TODO: Terminate video * Do what? */ if ( cs->capabilities & v_decoding ) vpx_codec_destroy(&cs->v_decoder); if ( cs->capabilities & v_encoding ) vpx_codec_destroy(&cs->v_encoder); }
static switch_status_t switch_opus_destroy(switch_codec_t *codec) { struct opus_context *context = codec->private_info; if (context) { if (context->decoder_object) { opus_decoder_destroy(context->decoder_object); context->decoder_object = NULL; } if (context->encoder_object) { opus_encoder_destroy(context->encoder_object); context->encoder_object = NULL; } } codec->private_info = NULL; return SWITCH_STATUS_SUCCESS; }
JNIEXPORT void JNICALL Java_aopus_OpusLibrary_decoderDestroy (JNIEnv *env, jobject obj, jlong state) { Decoder *decoder = (Decoder *)state; if (decoder->dec) { opus_decoder_destroy(decoder->dec); decoder->dec = NULL; } if (decoder->buffer) { free(decoder->buffer); decoder->buffer = NULL; } free(decoder); }
bool CAudioCodecOpus::FiniCodec() { if (AM_LIKELY(mEncoder)) { opus_encoder_destroy(mEncoder); mEncoder = NULL; } if (AM_LIKELY(mDecoder)) { opus_decoder_destroy(mDecoder); mDecoder = NULL; } if (AM_LIKELY(mRepacketizer)) { opus_repacketizer_destroy(mRepacketizer); mRepacketizer = NULL; } mIsInitialized = false; return true; }
void codec_terminate_session ( CodecState *cs ) { if (!cs) return; if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); if ( cs->audio_decoder ) opus_decoder_destroy(cs->audio_decoder); if ( cs->capabilities & v_decoding ) vpx_codec_destroy(&cs->v_decoder); if ( cs->capabilities & v_encoding ) vpx_codec_destroy(&cs->v_encoder); LOGGER_DEBUG("Terminated codec state: %p", cs); free(cs); }
void _v3_coder_destroy(v3_handle v3h, v3_coder *coder) { _v3_enter(v3h, __func__); if (coder->state) { _v3_debug(v3h, V3_DBG_MEMORY, "releasing %scoder state", (coder->encoder) ? "en" : "de"); switch (coder->index) { #ifdef HAVE_GSM case 0: gsm_destroy(coder->state); _v3_debug(v3h, V3_DBG_MEMORY, "released gsm state"); break; #endif #ifdef HAVE_OPUS case 1: case 2: if (coder->encoder) { opus_encoder_destroy(coder->state); } else { opus_decoder_destroy(coder->state); } _v3_debug(v3h, V3_DBG_MEMORY, "released opus state"); break; #endif #ifdef HAVE_SPEEX case 3: if (coder->encoder) { speex_encoder_destroy(coder->state); } else { speex_decoder_destroy(coder->state); } _v3_debug(v3h, V3_DBG_MEMORY, "released speex state"); break; #endif default: break; } coder->state = NULL; } _v3_leave(v3h, __func__); }