TEST_F(Voe, enc_dec_alloc)
{
	struct aucodec_param prm;
	struct auenc_state *aesp = NULL;
	struct audec_state *adsp = NULL;
	struct media_ctx *mctxp = NULL;
	const struct aucodec *ac;
	int pt = 96;
	int srate = 48000;
	int err;
    
	memset(&prm, 0, sizeof(prm));

    	ac = aucodec_find(&aucodecl, "opus", 48000, 2);
    
	if (ac->enc_alloc){
		err = ac->enc_alloc(&aesp, &mctxp, ac, NULL, &prm,
                      NULL, NULL, NULL, NULL, NULL);
		ASSERT_EQ(0, err);
	}

	if (ac->dec_alloc){
		err = ac->dec_alloc(&adsp, &mctxp, ac, NULL, &prm,
                            NULL, NULL, NULL);
		ASSERT_EQ(0, err);
	}
    
	mem_deref(aesp);
	mem_deref(adsp);
}
Esempio n. 2
0
static void start_codec(struct audio_loop *al, const char *name)
{
	struct auenc_param prm = {PTIME};
	int err;

	al->ac = aucodec_find(name,
			      configv[al->index].srate,
			      configv[al->index].ch);
	if (!al->ac) {
		warning("auloop: could not find codec: %s\n", name);
		return;
	}

	if (al->ac->encupdh) {
		err = al->ac->encupdh(&al->enc, al->ac, &prm, NULL);
		if (err) {
			warning("auloop: encoder update failed: %m\n", err);
		}
	}

	if (al->ac->decupdh) {
		err = al->ac->decupdh(&al->dec, al->ac, NULL);
		if (err) {
			warning("auloop: decoder update failed: %m\n", err);
		}
	}
}
TEST_F(Voe, unmute_after_call)
{
	int err;
	struct aucodec_param prm;
	struct auenc_state *aesp = NULL;
	struct audec_state *adsp = NULL;
	struct media_ctx *mctxp = NULL;
	const struct aucodec *ac;
	int pt = 96;
	int srate = 48000;
	bool muted;
    
	memset(&prm, 0, sizeof(prm));

	ac = aucodec_find(&aucodecl, "opus", 48000, 2);
    
	if (ac->enc_alloc){
		err = ac->enc_alloc(&aesp, &mctxp, ac, NULL, &prm,
                            NULL, NULL, NULL, NULL, NULL);
		ASSERT_EQ(0, err);
	}
    
	if (ac->dec_alloc){
		err = ac->dec_alloc(&adsp, &mctxp, ac, NULL, &prm,
                            NULL, NULL, NULL);
		ASSERT_EQ(0, err);
	}
    
	err = voe_get_mute(&muted);
	ASSERT_EQ(err, 0);
	ASSERT_EQ(muted, false);

	err = voe_set_mute(true);
	ASSERT_EQ(err, 0);
    
	err = voe_get_mute(&muted);
	ASSERT_EQ(err, 0);
	ASSERT_EQ(muted, true);
    
	mem_deref(aesp);
	mem_deref(adsp);

	err = voe_get_mute(&muted);
	ASSERT_EQ(err, 0);
	ASSERT_EQ(muted, false);
}
TEST(voe, enc_dec_alloc_start_stop_interrupt)
{
    struct list aucodecl = LIST_INIT;
    int err;
    struct auenc_state *aesp = NULL;
    struct audec_state *adsp = NULL;
    struct media_ctx *mctxp = NULL;
    const struct aucodec *ac;
    int pt = 96;
    int srate = 48000;
    webrtc::fake_audiodevice ad(true);
    struct sync_state ss;
    init_sync_state(&ss);
    struct aucodec_param prm;
    memset(&prm, 0, sizeof(prm));
    prm.local_ssrc = 0x12345678;
    prm.pt = 96;
    prm.srate = 48000;
    prm.ch = 2;
    
    err = voe_init(&aucodecl);
    ASSERT_EQ(0, err);
    
    err = re_thread_init();
    
    struct mqueue *mq;
    err = mqueue_alloc(&mq, mqueue_handler, NULL);
    if(err){
        printf("Could not allocate mqueue \n");
    }
    
    voe_register_adm((void*)&ad);
    
    ac = aucodec_find(&aucodecl, "opus", 48000, 2);
    ss.ac = ac;
    
    if (ac->enc_alloc){
        err = ac->enc_alloc(&aesp, &mctxp, ac, NULL, &prm,
                            send_rtp, NULL, NULL, NULL, &ss);
        ASSERT_EQ(0, err);
    }
    
    if (ac->dec_alloc){
        err = ac->dec_alloc(&adsp, &mctxp, ac, NULL, &prm,
                            NULL, NULL, NULL);
        ASSERT_EQ(0, err);
    }
    ss.adsp = adsp;
    
    if (ac->enc_start){
        ac->enc_start(aesp);
    }
    
    if (ac->dec_start){
        ac->dec_start(adsp);
    }
    
    wait_for_event(&ss);
    
    wait_for_event(&ss);
    pthread_mutex_lock(&ss.mutex);
    if (mqueue_push(mq, 0, (void*)&ss) != 0) {
        error("mediamgr_set_sound_mode failed \n");
    }
    pthread_mutex_unlock(&ss.mutex);
    
    for(int i = 0; i < 200; i++){
            wait_for_event(&ss);
    }
    
    
    //sleep(3);
    
    if (ac->enc_stop){
        ac->enc_stop(aesp);
    }
    
    if (ac->dec_stop){
        ac->dec_stop(adsp);
    }
    
    mem_deref(aesp);
    mem_deref(adsp);
    
    voe_deregister_adm();
    
    voe_close();
}
TEST(voe, packet_size_40)
{
    struct list aucodecl = LIST_INIT;
    int err;
    struct auenc_state *aesp = NULL;
    struct audec_state *adsp = NULL;
    struct media_ctx *mctxp = NULL;
    const struct aucodec *ac;
    int pt = 96;
    int srate = 48000;
    webrtc::fake_audiodevice ad;
    struct sync_state ss;
    init_sync_state(&ss);
    struct aucodec_param prm;
    memset(&prm, 0, sizeof(prm));
    prm.local_ssrc = 0x12345678;
    prm.pt = 96;
    prm.srate = 48000;
    prm.ch = 2;
    
    err = voe_init(&aucodecl);
    ASSERT_EQ(0, err);
    
    voe_register_adm((void*)&ad);
    
    ac = aucodec_find(&aucodecl, "opus", 48000, 2);
    if (ac->enc_alloc){
        err = ac->enc_alloc(&aesp, &mctxp, ac, NULL, &prm,
                            send_rtp, NULL, NULL, NULL, &ss);
        ASSERT_EQ(0, err);
    }
    
    if (ac->dec_alloc){
        err = ac->dec_alloc(&adsp, &mctxp, ac, NULL, &prm,
                            NULL, NULL, NULL);
        ASSERT_EQ(0, err);
    }
    
    if (ac->enc_start){
        ac->enc_start(aesp);
    }
    
    if (ac->dec_start){
        ac->dec_start(adsp);
    }
    
    voe_set_packet_size(40);
    
    wait_for_event(&ss);
    //ASSERT_EQ(pt, ss.pt); // for some reason the first packet has wrong pt ??
    
    wait_for_event(&ss);
    ASSERT_EQ(pt, ss.pt);
    ASSERT_EQ(prm.local_ssrc, ss.ssrc);
    ASSERT_EQ(1, ss.seq_diff);
    ASSERT_EQ(2*960, ss.timestamp_diff);
    
    if (ac->enc_stop){
        ac->enc_stop(aesp);
    }
    
    if (ac->dec_stop){
        ac->dec_stop(adsp);
    }
    
    mem_deref(aesp);
    mem_deref(adsp);
    
    voe_deregister_adm();
    
    voe_close();
}