Ejemplo n.º 1
0
/**
 * Deinitialize media endpoint.
 */
PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt)
{
    unsigned i;

    PJ_ASSERT_RETURN(endpt, PJ_EINVAL);

    endpt->quit_flag = 1;

    /* Destroy threads */
    for (i=0; i<endpt->thread_cnt; ++i) {
	if (endpt->thread[i]) {
	    pj_thread_join(endpt->thread[i]);
	    pj_thread_destroy(endpt->thread[i]);
	    endpt->thread[i] = NULL;
	}
    }

    /* Destroy internal ioqueue */
    if (endpt->ioqueue && endpt->own_ioqueue) {
	pj_ioqueue_destroy(endpt->ioqueue);
	endpt->ioqueue = NULL;
    }

    endpt->pf = NULL;

    pjmedia_aud_subsys_shutdown();
    pj_pool_release (endpt->pool);

    return PJ_SUCCESS;
}
Ejemplo n.º 2
0
/**
 * Deinitialize media endpoint.
 */
PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt)
{
    exit_cb *ecb;

    pjmedia_endpt_stop_threads(endpt);

    /* Destroy internal ioqueue */
    if (endpt->ioqueue && endpt->own_ioqueue) {
        pj_ioqueue_destroy(endpt->ioqueue);
        endpt->ioqueue = NULL;
    }

    endpt->pf = NULL;

    pjmedia_codec_mgr_destroy(&endpt->codec_mgr);
    pjmedia_aud_subsys_shutdown();

    /* Call all registered exit callbacks */
    ecb = endpt->exit_cb_list.next;
    while (ecb != &endpt->exit_cb_list) {
        (*ecb->func)(endpt);
        ecb = ecb->next;
    }

    pj_pool_release (endpt->pool);

    return PJ_SUCCESS;
}
Ejemplo n.º 3
0
/* Shutdown application */
static void app_fini()
{
    if (strm)
    	snd_stop();

    pjmedia_aud_subsys_shutdown();
    pjmedia_delay_buf_destroy(delaybuf);
    pj_pool_release(pool);
    pj_caching_pool_destroy(&cp);
    pj_shutdown();
}
Ejemplo n.º 4
0
void latency_checker::internal_clean()
{
	if(m_aud_stream)
	{
		pjmedia_aud_stream_stop(m_aud_stream);
		pjmedia_aud_stream_destroy(m_aud_stream);
		m_aud_stream = NULL;
	}
	if(m_pool)
		pjmedia_aud_subsys_shutdown();
	pj_logging_shutdown();
	pj_logging_destroy();
	if(m_lock)
	{
		delete m_lock;
		m_lock = NULL;
	}
	if(m_pool)
	{
		pj_pool_release(m_pool);
		m_pool = NULL;
	}
	if(m_caching_pool)
		pj_caching_pool_destroy(m_caching_pool);
	m_pool_factory = NULL;
	m_caching_pool = NULL;
	pj_shutdown();
	if(m_idle_freq1_det)
	{
		delete m_idle_freq1_det;
		m_idle_freq1_det = NULL;
	}
	if(m_idle_freq2_det)
	{
		delete m_idle_freq2_det;
		m_idle_freq2_det = NULL;
	}
	if(m_active_freq1_det)
	{
		delete m_active_freq1_det;
		m_active_freq1_det = NULL;
	}
	if(m_active_freq2_det)
	{
		delete m_active_freq2_det;
		m_active_freq2_det = NULL;
	}
	if(m_gain)
	{
		delete m_gain;
		m_gain = NULL;
	}
}
Ejemplo n.º 5
0
/**
* Deinitialize media endpoint.
*/
PJ_DEF(pj_status_t) pjmedia_endpt_destroy (pjmedia_endpt *endpt)
{
	exit_cb *ecb;
	unsigned i;

	PJ_ASSERT_RETURN(endpt, PJ_EINVAL);

	endpt->quit_flag = 1;

	/* Destroy threads */
	for (i=0; i<endpt->thread_cnt; ++i) {
		if (endpt->thread[i]) {
			pj_thread_join(endpt->thread[i]);
			pj_thread_destroy(endpt->thread[i]);
			endpt->thread[i] = NULL;
		}
	}

	/* Destroy internal ioqueue */
	if (endpt->ioqueue && endpt->own_ioqueue) {
		pj_ioqueue_destroy(endpt->ioqueue);
		endpt->ioqueue = NULL;
	}

	endpt->pf = NULL;

	pjmedia_codec_mgr_destroy(&endpt->codec_mgr);
	pjmedia_aud_subsys_shutdown();

	/* Call all registered exit callbacks */
	ecb = endpt->exit_cb_list.next;
	while (ecb != &endpt->exit_cb_list) {
		(*ecb->func)(endpt);
		ecb = ecb->next;
	}

	pj_pool_release (endpt->pool);

	return PJ_SUCCESS;
}
Ejemplo n.º 6
0
/**
 * Initialize and get the instance of media endpoint.
 */
PJ_DEF(pj_status_t) pjmedia_endpt_create(pj_pool_factory *pf,
					 pj_ioqueue_t *ioqueue,
					 unsigned worker_cnt,
					 pjmedia_endpt **p_endpt)
{
    pj_pool_t *pool;
    pjmedia_endpt *endpt;
    unsigned i;
    pj_status_t status;

    if (!error_subsys_registered) {
	pj_register_strerror(PJMEDIA_ERRNO_START, PJ_ERRNO_SPACE_SIZE, 
			     &pjmedia_strerror);
	error_subsys_registered = 1;
    }

    PJ_ASSERT_RETURN(pf && p_endpt, PJ_EINVAL);
    PJ_ASSERT_RETURN(worker_cnt <= MAX_THREADS, PJ_EINVAL);

    pool = pj_pool_create(pf, "med-ept", 512, 512, NULL);
    if (!pool)
	return PJ_ENOMEM;

    endpt = PJ_POOL_ZALLOC_T(pool, struct pjmedia_endpt);
    endpt->pool = pool;
    endpt->pf = pf;
    endpt->ioqueue = ioqueue;
    endpt->thread_cnt = worker_cnt;

    /* Sound */
    status = pjmedia_aud_subsys_init(pf);
    if (status != PJ_SUCCESS)
	goto on_error;

    /* Init codec manager. */
    status = pjmedia_codec_mgr_init(&endpt->codec_mgr);
    if (status != PJ_SUCCESS)
	goto on_error;

    /* Create ioqueue if none is specified. */
    if (endpt->ioqueue == NULL) {
	
	endpt->own_ioqueue = PJ_TRUE;

	status = pj_ioqueue_create( endpt->pool, PJ_IOQUEUE_MAX_HANDLES,
				    &endpt->ioqueue);
	if (status != PJ_SUCCESS)
	    goto on_error;

	if (worker_cnt == 0) {
	    PJ_LOG(4,(THIS_FILE, "Warning: no worker thread is created in"  
				 "media endpoint for internal ioqueue"));
	}
    }

    /* Create worker threads if asked. */
    for (i=0; i<worker_cnt; ++i) {
	status = pj_thread_create( endpt->pool, "media", &worker_proc,
				   endpt, 0, 0, &endpt->thread[i]);
	if (status != PJ_SUCCESS)
	    goto on_error;
    }


    *p_endpt = endpt;
    return PJ_SUCCESS;

on_error:

    /* Destroy threads */
    for (i=0; i<endpt->thread_cnt; ++i) {
	if (endpt->thread[i]) {
	    pj_thread_destroy(endpt->thread[i]);
	}
    }

    /* Destroy internal ioqueue */
    if (endpt->ioqueue && endpt->own_ioqueue)
	pj_ioqueue_destroy(endpt->ioqueue);

    pjmedia_aud_subsys_shutdown();
    pj_pool_release(pool);
    return status;
}
Ejemplo n.º 7
0
static int main_func(int argc, char *argv[])
{
    pj_caching_pool cp;
    pj_pool_t *pool;
    int rc = 0;
    pj_status_t status = PJ_SUCCESS;

    if (argc != 2) {
        puts("Error: filename required");
        puts(desc);
        return 1;
    }


    /* Must init PJLIB first: */
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);

    /* Create memory pool for our file player */
    pool = pj_pool_create( &cp.factory,	    /* pool factory	    */
                           "AVI",	    /* pool name.	    */
                           4000,	    /* init size	    */
                           4000,	    /* increment size	    */
                           NULL		    /* callback on error    */
                         );

    pjmedia_video_format_mgr_create(pool, 64, 0, NULL);
    pjmedia_converter_mgr_create(pool, NULL);
    pjmedia_event_mgr_create(pool, 0, NULL);
    pjmedia_vid_codec_mgr_create(pool, NULL);

    status = pjmedia_vid_dev_subsys_init(&cp.factory);
    if (status != PJ_SUCCESS)
        goto on_return;

    status = pjmedia_aud_subsys_init(&cp.factory);
    if (status != PJ_SUCCESS) {
        goto on_return;
    }

#if PJMEDIA_HAS_FFMPEG_VID_CODEC
    status = pjmedia_codec_ffmpeg_vid_init(NULL, &cp.factory);
    if (status != PJ_SUCCESS)
        goto on_return;
#endif

    rc = aviplay(pool, argv[1]);

    /*
     * File should be playing and looping now
     */

    /* Without this sleep, Windows/DirectSound will repeteadly
     * play the last frame during destroy.
     */
    pj_thread_sleep(100);

on_return:
#if PJMEDIA_HAS_FFMPEG_VID_CODEC
    pjmedia_codec_ffmpeg_vid_deinit();
#endif
    pjmedia_aud_subsys_shutdown();
    pjmedia_vid_dev_subsys_shutdown();

    pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr_instance());
    pjmedia_converter_mgr_destroy(pjmedia_converter_mgr_instance());
    pjmedia_event_mgr_destroy(pjmedia_event_mgr_instance());
    pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr_instance());

    /* Release application pool */
    pj_pool_release( pool );

    /* Destroy pool factory */
    pj_caching_pool_destroy( &cp );

    /* Shutdown PJLIB */
    pj_shutdown();

    /* Done. */
    return 0;
}
Ejemplo n.º 8
0
PJ_DEF(pj_status_t) pjmedia_snd_deinit(void)
{
    return pjmedia_aud_subsys_shutdown();
}