Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
AudioInput::~AudioInput() {
	bRunning = false;
	wait();

#ifdef USE_OPUS
	if (opusState)
		opus_encoder_destroy(opusState);
#endif

	if (ceEncoder) {
		cCodec->celt_encoder_destroy(ceEncoder);
	}

	foreach(short *buf, qlEchoFrames)
		delete [] buf;

	if (sppPreprocess)
		speex_preprocess_state_destroy(sppPreprocess);
	if (sesEcho)
		speex_echo_state_destroy(sesEcho);

	if (srsMic)
		speex_resampler_destroy(srsMic);
	if (srsEcho)
		speex_resampler_destroy(srsEcho);

	delete [] psMic;
	delete [] psClean;
	delete [] psSpeaker;

	delete [] pfMicInput;
	delete [] pfEchoInput;
	delete [] pfOutput;
}
Exemplo n.º 4
0
long opus_create(const char* format_parameters, const char** format_parameters_out,
		 amci_codec_fmt_info_t** format_description) {
  opus_state_t* codec_inst;
  int error;

  unsigned int maxbandwidth = _OPUS_RATE;
  int useinbandfec = _OPUS_INBAND_FEC_;
  int stereo = 0;

  if (format_parameters) {
    DBG("OPUS params: >>%s<<.\n", format_parameters);
    decode_format_parameters(format_parameters, &maxbandwidth, &useinbandfec, &stereo);
  } 
    
  codec_inst = (opus_state_t*)malloc(sizeof(opus_state_t));

  if (!codec_inst) 
    return -1;

  DBG("OPUS: creating encoder with maxbandwidth=%u, stereo=%s, useinbandfec=%s\n",
      maxbandwidth, stereo?"true":"false", useinbandfec?"true":"false");

  codec_inst->opus_enc = opus_encoder_create(_OPUS_RATE,1,_OPUS_APPLICATION_,&error);
  if (error) {
    DBG("OPUS: error %d while creating encoder state.\n", error);
    return -1;
  }

  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_FORCE_CHANNELS(stereo ? 2:1));

  unsigned int opus_set_bw = _OPUS_RATE;
  if (maxbandwidth <= 8000) {
    opus_set_bw = OPUS_BANDWIDTH_NARROWBAND;
  } else if (maxbandwidth <= 12000) {
    opus_set_bw = OPUS_BANDWIDTH_MEDIUMBAND;
  } else if (maxbandwidth <= 16000) {
    opus_set_bw = OPUS_BANDWIDTH_WIDEBAND;
  } else if (maxbandwidth <= 24000) {
    opus_set_bw = OPUS_BANDWIDTH_SUPERWIDEBAND;
  } else {
    opus_set_bw = OPUS_BANDWIDTH_FULLBAND;
  }
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_MAX_BANDWIDTH(opus_set_bw));

  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_PACKET_LOSS_PERC(_OPUS_PKT_LOSS_PCT_));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_COMPLEXITY(_OPUS_COMPLEXITY_));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_INBAND_FEC(useinbandfec ? 1:0));
  opus_encoder_ctl(codec_inst->opus_enc, OPUS_SET_DTX(_OPUS_DTX_));

  codec_inst->opus_dec = opus_decoder_create(_OPUS_RATE,1,&error);
  if (error) {
    DBG("OPUS: error %d while creating decoder state.\n", error);
    opus_encoder_destroy(codec_inst->opus_enc);
    return -1;
  }

  *format_description = opus_fmt_description;

  return (long)codec_inst;
}
Exemplo n.º 5
0
static void destructor(void *arg)
{
	struct auenc_state *aes = arg;

	if (aes->enc)
		opus_encoder_destroy(aes->enc);
}
Exemplo n.º 6
0
Opus::~Opus()
{
    if (encoder_)
        opus_encoder_destroy(encoder_);
    if (decoder_)
        opus_decoder_destroy(decoder_);
}
Exemplo n.º 7
0
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");
}
Exemplo n.º 8
0
void cleanupRecorder() {
    if (_encoder) {
        opus_encoder_destroy(_encoder);
        _encoder = 0;
    }

    ogg_stream_clear(&os);

    if (_packet) {
        free(_packet);
        _packet = 0;
    }

    if (_fileOs) {
        fclose(_fileOs);
        _fileOs = 0;
    }

    _packetId = -1;
    bytes_written = 0;
    pages_out = 0;
    total_samples = 0;
    enc_granulepos = 0;
    size_segments = 0;
    last_segments = 0;
    last_granulepos = 0;
    memset(&os, 0, sizeof(ogg_stream_state));
    memset(&inopt, 0, sizeof(oe_enc_opt));
    memset(&header, 0, sizeof(OpusHeader));
    memset(&op, 0, sizeof(ogg_packet));
    memset(&og, 0, sizeof(ogg_page));
}
Exemplo n.º 9
0
static void audio_encoder_terminate()
{
    if (opus_enc) {
        opus_encoder_destroy(opus_enc);
        opus_enc = NULL;
    }
}
Exemplo n.º 10
0
	void Destroy(OpusEncoder* Encoder) const
	{
#if USE_UE4_MEM_ALLOC
		FMemory::Free(Encoder);
#else
		opus_encoder_destroy(Encoder);
#endif
	}
Exemplo n.º 11
0
static void kill_group_av(Group_AV *group_av)
{
    if (group_av->audio_encoder) {
        opus_encoder_destroy(group_av->audio_encoder);
    }

    free(group_av);
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
void FVoiceEncoderOpus::Destroy()
{
#if USE_UE4_MEM_ALLOC
	FMemory::Free(Encoder);
#else
	opus_encoder_destroy(Encoder);
#endif
	Encoder = NULL;
}
Exemplo n.º 14
0
OpusTrackEncoder::~OpusTrackEncoder()
{
  if (mEncoder) {
    opus_encoder_destroy(mEncoder);
  }
  if (mResampler) {
    speex_resampler_destroy(mResampler);
    mResampler = nullptr;
  }
}
Exemplo n.º 15
0
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);
  }
}
Exemplo n.º 16
0
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);
}
Exemplo n.º 17
0
static void ms_opus_enc_uninit(MSFilter *f) {
	OpusEncData *d = (OpusEncData *)f->data;
	if (d == NULL) return;
	if (d->state) {
		opus_encoder_destroy(d->state);
		d->state = NULL;
	}
	ms_bufferizer_destroy(d->bufferizer);
	d->bufferizer = NULL;
	ms_free(d);
}
Exemplo n.º 18
0
OpusSM* sm_destroy(OpusSM* sm) {
	if (sm == NULL) {
		return NULL;
	}


	if (sm->opus_enc != NULL) {
		opus_encoder_destroy(sm->opus_enc);
	}
	free(sm);
	sm = NULL;
	return sm;
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
static int recreate_encoder(Group_AV *group_av)
{
    if (group_av->audio_encoder) {
        opus_encoder_destroy(group_av->audio_encoder);
        group_av->audio_encoder = NULL;
    }

    int rc = OPUS_OK;
    group_av->audio_encoder = opus_encoder_create(group_av->audio_sample_rate, group_av->audio_channels,
                              OPUS_APPLICATION_AUDIO, &rc);

    if (rc != OPUS_OK) {
        LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc));
        group_av->audio_encoder = NULL;
        return -1;
    }

    rc = opus_encoder_ctl(group_av->audio_encoder, OPUS_SET_BITRATE(group_av->audio_bitrate));

    if (rc != OPUS_OK) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        opus_encoder_destroy(group_av->audio_encoder);
        group_av->audio_encoder = NULL;
        return -1;
    }

    rc = opus_encoder_ctl(group_av->audio_encoder, OPUS_SET_COMPLEXITY(10));

    if (rc != OPUS_OK) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        opus_encoder_destroy(group_av->audio_encoder);
        group_av->audio_encoder = NULL;
        return -1;
    }

    return 0;
}
Exemplo n.º 22
0
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);
}
Exemplo n.º 23
0
static void lintoopus_destroy(struct ast_trans_pvt *arg)
{
	struct opus_coder_pvt *opvt = arg->pvt;

	if (!opvt || !opvt->opus) {
		return;
	}

	opus_encoder_destroy(opvt->opus);
	opvt->opus = NULL;

	ast_atomic_fetchadd_int(&usage.encoders, -1);

	ast_debug(3, "Destroyed encoder #%d (%d->opus)\n", opvt->id, opvt->sampling_rate);
}
Exemplo n.º 24
0
void opus_enc_close(opus_enc *opus)
{

	if (opus->buffer != NULL) {
		ogg_stream_clear (&opus->os);
		opus_encoder_destroy (opus->encoder);

		free (opus->header_data);
		free (opus->header);
		free (opus->tags);
		free (opus->buffer);
		opus->buffer = NULL;
	}
	//printf("Opus Encoder Destroyed\n");

}
Exemplo n.º 25
0
/* 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;
}
Exemplo n.º 26
0
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);
}
Exemplo n.º 27
0
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;
}
Exemplo n.º 28
0
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);
}
Exemplo n.º 29
0
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;
}
Exemplo n.º 30
0
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);
}