APT_DECLARE(apt_consumer_task_t*) apt_consumer_task_create( void *obj, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_consumer_task_t *consumer_task = apr_palloc(pool,sizeof(apt_consumer_task_t)); consumer_task->obj = obj; consumer_task->msg_queue = NULL; if(apr_queue_create(&consumer_task->msg_queue,1024,pool) != APR_SUCCESS) { return NULL; } consumer_task->base = apt_task_create(consumer_task,msg_pool,pool); if(!consumer_task->base) { return NULL; } vtable = apt_task_vtable_get(consumer_task->base); if(vtable) { vtable->run = apt_consumer_task_run; vtable->signal_msg = apt_consumer_task_msg_signal; } #if APR_HAS_QUEUE_TIMEOUT consumer_task->timer_queue = apt_timer_queue_create(pool); #endif return consumer_task; }
/** Create poller task */ APT_DECLARE(apt_poller_task_t*) apt_poller_task_create( apr_size_t max_pollset_size, apt_poll_signal_f signal_handler, void *obj, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_poller_task_t *task; if(!signal_handler) { return NULL; } task = apr_palloc(pool,sizeof(apt_poller_task_t)); task->pool = pool; task->obj = obj; task->pollset = NULL; task->signal_handler = signal_handler; task->pollset = apt_pollset_create((apr_uint32_t)max_pollset_size,pool); if(!task->pollset) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset"); return NULL; } task->base = apt_task_create(task,msg_pool,pool); if(!task->base) { apt_pollset_destroy(task->pollset); return NULL; } vtable = apt_task_vtable_get(task->base); if(vtable) { vtable->run = apt_poller_task_run; vtable->destroy = apt_poller_task_on_destroy; vtable->signal_msg = apt_poller_task_msg_signal; } apt_task_auto_ready_set(task->base,FALSE); task->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&task->guard,APR_THREAD_MUTEX_UNNESTED,pool); task->timer_queue = apt_timer_queue_create(pool); return task; }
MPF_DECLARE(mpf_engine_t*) mpf_engine_create(const char *id, apr_pool_t *pool) { apt_task_vtable_t *vtable; apt_task_msg_pool_t *msg_pool; mpf_engine_t *engine = apr_palloc(pool,sizeof(mpf_engine_t)); engine->pool = pool; engine->request_queue = NULL; engine->context_factory = NULL; engine->codec_manager = NULL; msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mpf_message_container_t),pool); apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Media Engine [%s]",id); engine->task = apt_task_create(engine,msg_pool,pool); if(!engine->task) { return NULL; } apt_task_name_set(engine->task,id); vtable = apt_task_vtable_get(engine->task); if(vtable) { vtable->destroy = mpf_engine_destroy; vtable->start = mpf_engine_start; vtable->terminate = mpf_engine_terminate; vtable->signal_msg = mpf_engine_msg_signal; vtable->process_msg = mpf_engine_msg_process; } engine->task_msg_type = TASK_MSG_USER; engine->context_factory = mpf_context_factory_create(engine->pool); engine->request_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE); apr_thread_mutex_create(&engine->request_queue_guard,APR_THREAD_MUTEX_UNNESTED,engine->pool); engine->scheduler = mpf_scheduler_create(engine->pool); mpf_scheduler_media_clock_set(engine->scheduler,CODEC_FRAME_TIME_BASE,mpf_engine_main,engine); engine->timer_queue = apt_timer_queue_create(engine->pool); mpf_scheduler_timer_clock_set(engine->scheduler,MPF_TIMER_RESOLUTION,mpf_engine_timer_proc,engine); return engine; }