pjs_frame_processor::pjs_frame_processor(pjs_global& global, unsigned capacity, unsigned samples_per_frame) : m_global(global), m_samples_per_frame(samples_per_frame) { m_started = false; m_thread = NULL; m_ready = false; m_exit = false; m_pool = pj_pool_create(m_global.get_pool_factory(), "pjs_frame_processor", 128, 128, NULL); m_lock = new PPJ_SemaphoreLock(m_pool, NULL, 1, 1); pj_status_t status = pjmedia_circ_buf_create(m_pool, capacity, &m_buffer); if (status == PJ_SUCCESS) { status = pj_thread_create(m_pool, "frame processor thread", (pj_thread_proc*) &s_thread_proc, this, PJ_THREAD_DEFAULT_STACK_SIZE, PJ_THREAD_SUSPENDED, &m_thread); if (status != PJ_SUCCESS) m_thread = NULL; else m_ready = true; } else m_buffer = NULL; }
PJ_DEF(pj_status_t) pjmedia_delay_buf_create( pj_pool_t *pool, const char *name, unsigned clock_rate, unsigned samples_per_frame, unsigned channel_count, unsigned max_delay, unsigned options, pjmedia_delay_buf **p_b) { pjmedia_delay_buf *b; pj_status_t status; PJ_ASSERT_RETURN(pool && samples_per_frame && clock_rate && channel_count && p_b, PJ_EINVAL); PJ_ASSERT_RETURN(options==0, PJ_EINVAL); PJ_UNUSED_ARG(options); if (!name) { name = "delaybuf"; } b = PJ_POOL_ZALLOC_T(pool, pjmedia_delay_buf); pj_ansi_strncpy(b->obj_name, name, PJ_MAX_OBJ_NAME-1); b->samples_per_frame = samples_per_frame; b->channel_count = channel_count; b->ptime = samples_per_frame * 1000 / clock_rate / channel_count; if (max_delay < b->ptime) max_delay = PJ_MAX(DEFAULT_MAX_DELAY, b->ptime); b->max_cnt = samples_per_frame * max_delay / b->ptime; b->eff_cnt = b->max_cnt >> 1; b->recalc_timer = RECALC_TIME; /* Create circular buffer */ status = pjmedia_circ_buf_create(pool, b->max_cnt, &b->circ_buf); if (status != PJ_SUCCESS) return status; /* Create WSOLA */ status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1, PJMEDIA_WSOLA_NO_FADING, &b->wsola); if (status != PJ_SUCCESS) return status; /* Finally, create mutex */ status = pj_lock_create_recursive_mutex(pool, b->obj_name, &b->lock); if (status != PJ_SUCCESS) return status; *p_b = b; TRACE__((b->obj_name,"Delay buffer created")); return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pjmedia_silence_port_create(pj_pool_t *pool, pjmedia_port *dn_port, unsigned buffer_size, pjmedia_port **p_port) { const pj_str_t silence = { "silence", 7 }; struct silence_port *sp; pj_status_t status; PJ_ASSERT_RETURN(pool && dn_port && p_port, PJ_EINVAL); /* Create the port itself */ sp = PJ_POOL_ZALLOC_T(pool, struct silence_port); pjmedia_port_info_init(&sp->base.info, &silence, SIGNATURE, dn_port->info.clock_rate, dn_port->info.channel_count, dn_port->info.bits_per_sample, dn_port->info.samples_per_frame); /* More init */ sp->dn_port = dn_port; sp->base.get_frame = &sp_get_frame; sp->base.put_frame = &sp_put_frame; sp->base.on_destroy = &sp_on_destroy; sp->frames = 0; sp->last_ts.u64 = 0; /* create circular buffer */ if (!buffer_size) buffer_size = dn_port->info.bits_per_sample * \ dn_port->info.samples_per_frame * 16; pjmedia_circ_buf_create (pool, buffer_size, &sp->buf); /* Done */ *p_port = &sp->base; return PJ_SUCCESS; }