Пример #1
0
static pj_status_t stereo_get_frame(pjmedia_port *this_port, 
				    pjmedia_frame *frame)
{
    struct stereo_port *sport = (struct stereo_port*) this_port;
    const pjmedia_audio_format_detail *s_afd, *dn_afd;
    pjmedia_frame tmp_frame;
    pj_status_t status;

    /* Return silence if we don't have downstream port */
    if (sport->dn_port == NULL) {
	pj_bzero(frame->buf, frame->size);
	return PJ_SUCCESS;
    }

    s_afd = pjmedia_format_get_audio_format_detail(&this_port->info.fmt, 1);
    dn_afd = pjmedia_format_get_audio_format_detail(&sport->dn_port->info.fmt,
						    1);

    tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf;
    tmp_frame.size = PJMEDIA_PIA_AVG_FSZ(&sport->dn_port->info);
    tmp_frame.timestamp.u64 = frame->timestamp.u64;
    tmp_frame.type = PJMEDIA_FRAME_TYPE_AUDIO;

    status = pjmedia_port_get_frame( sport->dn_port, &tmp_frame);
    if (status != PJ_SUCCESS)
	return status;

    if (tmp_frame.type != PJMEDIA_FRAME_TYPE_AUDIO) {
	frame->type = tmp_frame.type;
	frame->timestamp = tmp_frame.timestamp;
	frame->size = tmp_frame.size;
	if (tmp_frame.size && tmp_frame.buf == sport->get_buf)
	    pj_memcpy(frame->buf, tmp_frame.buf, tmp_frame.size);
	return PJ_SUCCESS;
    }

    if (s_afd->channel_count == 1) {
	pjmedia_convert_channel_nto1((pj_int16_t*)frame->buf, 
				     (const pj_int16_t*)tmp_frame.buf,
				     dn_afd->channel_count,
				     PJMEDIA_AFD_SPF(s_afd),
				     (sport->options & PJMEDIA_STEREO_MIX), 0);
    } else {
	pjmedia_convert_channel_1ton((pj_int16_t*)frame->buf, 
				     (const pj_int16_t*)tmp_frame.buf,
				     s_afd->channel_count,
				     PJMEDIA_AFD_SPF(dn_afd),
				     sport->options);
    }

    frame->size = PJMEDIA_AFD_AVG_FSZ(s_afd);
    frame->type = PJMEDIA_FRAME_TYPE_AUDIO;

    return PJ_SUCCESS;
}
Пример #2
0
/*
 * Connect a port.
 */
PJ_DEF(pj_status_t) pjmedia_snd_port_connect( pjmedia_snd_port *snd_port,
					      pjmedia_port *port)
{
    pjmedia_audio_format_detail *afd;

    PJ_ASSERT_RETURN(snd_port && port, PJ_EINVAL);

    afd = pjmedia_format_get_audio_format_detail(&port->info.fmt, PJ_TRUE);

    /* Check that port has the same configuration as the sound device
     * port.
     */
    if (afd->clock_rate != snd_port->clock_rate)
	return PJMEDIA_ENCCLOCKRATE;

    if (PJMEDIA_AFD_SPF(afd) != snd_port->samples_per_frame)
	return PJMEDIA_ENCSAMPLESPFRAME;

    if (afd->channel_count != snd_port->channel_count)
	return PJMEDIA_ENCCHANNEL;

    if (afd->bits_per_sample != snd_port->bits_per_sample)
	return PJMEDIA_ENCBITS;

    /* Port is okay. */
    snd_port->port = port;
    return PJ_SUCCESS;
}
Пример #3
0
PJ_DEF(pj_status_t) pjmedia_bidirectional_port_create( pj_pool_t *pool,
						       pjmedia_port *get_port,
						       pjmedia_port *put_port,
						       pjmedia_port **p_port )
{
    struct bidir_port *port;
    const pjmedia_audio_format_detail *gafd;

    port = PJ_POOL_ZALLOC_T(pool, struct bidir_port);
    gafd = pjmedia_format_get_audio_format_detail(&get_port->info.fmt, 1);

    pjmedia_port_info_init(&port->base.info, &get_port->info.name, SIGNATURE,
			   gafd->clock_rate,
			   gafd->channel_count,
			   gafd->bits_per_sample,
			   PJMEDIA_AFD_SPF(gafd));

    port->get_port = get_port;
    port->put_port = put_port;

    port->base.get_frame = &get_frame;
    port->base.put_frame = &put_frame;

    *p_port = &port->base;

    return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pjmedia_echo_port_create(pj_pool_t *pool,
					     pjmedia_port *dn_port,
					     unsigned tail_ms,
					     unsigned latency_ms,
					     unsigned options,
					     pjmedia_port **p_port )
{
    const pj_str_t AEC = { "EC", 2 };
    pjmedia_audio_format_detail *afd;
    struct ec *ec;
    pj_status_t status;

    PJ_ASSERT_RETURN(pool && dn_port && p_port, PJ_EINVAL);

    afd = pjmedia_format_get_audio_format_detail(&dn_port->info.fmt, PJ_TRUE);

    PJ_ASSERT_RETURN(afd->bits_per_sample==16 && tail_ms,
		     PJ_EINVAL);

    /* Create the port and the AEC itself */
    ec = PJ_POOL_ZALLOC_T(pool, struct ec);
    
    pjmedia_port_info_init(&ec->base.info, &AEC, SIGNATURE,
			   afd->clock_rate,
			   afd->channel_count,
			   afd->bits_per_sample,
			   PJMEDIA_AFD_SPF(afd));

    status = pjmedia_echo_create2(pool, afd->clock_rate,
				  afd->channel_count,
				  PJMEDIA_AFD_SPF(afd),
				  tail_ms, latency_ms, options, &ec->ec);
    if (status != PJ_SUCCESS)
	return status;

    /* More init */
    ec->dn_port = dn_port;
    ec->base.get_frame = &ec_get_frame;
    ec->base.put_frame = &ec_put_frame;
    ec->base.on_destroy = &ec_on_destroy;

    /* Done */
    *p_port = &ec->base;

    return PJ_SUCCESS;
}
Пример #5
0
static pj_status_t stereo_put_frame(pjmedia_port *this_port,
				    pjmedia_frame *frame)
{
    struct stereo_port *sport = (struct stereo_port*) this_port;
    const pjmedia_audio_format_detail *s_afd, *dn_afd;
    pjmedia_frame tmp_frame;

    /* Return if we don't have downstream port. */
    if (sport->dn_port == NULL) {
	return PJ_SUCCESS;
    }

    s_afd = pjmedia_format_get_audio_format_detail(&this_port->info.fmt, 1);
    dn_afd = pjmedia_format_get_audio_format_detail(&sport->dn_port->info.fmt,
						    1);

    if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) {
	tmp_frame.buf = sport->put_buf;
	if (dn_afd->channel_count == 1) {
	    pjmedia_convert_channel_nto1((pj_int16_t*)tmp_frame.buf, 
					 (const pj_int16_t*)frame->buf,
					 s_afd->channel_count,
					 PJMEDIA_AFD_SPF(s_afd),
					 (sport->options & PJMEDIA_STEREO_MIX),
					 0);
	} else {
	    pjmedia_convert_channel_1ton((pj_int16_t*)tmp_frame.buf, 
					 (const pj_int16_t*)frame->buf,
					 dn_afd->channel_count,
					 PJMEDIA_AFD_SPF(s_afd),
					 sport->options);
	}
	tmp_frame.size = PJMEDIA_AFD_AVG_FSZ(dn_afd);
    } else {
	tmp_frame.buf = frame->buf;
	tmp_frame.size = frame->size;
    }

    tmp_frame.type = frame->type;
    tmp_frame.timestamp.u64 = frame->timestamp.u64;

    return pjmedia_port_put_frame( sport->dn_port, &tmp_frame );
}