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; }
static pj_status_t stereo_get_frame(pjmedia_port *this_port, pjmedia_frame *frame) { struct stereo_port *sport = (struct stereo_port*) this_port; 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; } tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf; tmp_frame.size = sport->dn_port->info.bytes_per_frame; 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 (sport->base.info.channel_count == 1) { pjmedia_convert_channel_nto1((pj_int16_t*)frame->buf, (const pj_int16_t*)tmp_frame.buf, sport->dn_port->info.channel_count, sport->dn_port->info.samples_per_frame, (sport->options & PJMEDIA_STEREO_MIX), 0); } else { pjmedia_convert_channel_1ton((pj_int16_t*)frame->buf, (const pj_int16_t*)tmp_frame.buf, sport->base.info.channel_count, sport->dn_port->info.samples_per_frame, sport->options); } frame->size = sport->base.info.bytes_per_frame; frame->type = PJMEDIA_FRAME_TYPE_AUDIO; return PJ_SUCCESS; }
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 ); }
static pj_status_t stereo_put_frame(pjmedia_port *this_port, const pjmedia_frame *frame) { struct stereo_port *sport = (struct stereo_port*) this_port; pjmedia_frame tmp_frame; /* Return if we don't have downstream port. */ if (sport->dn_port == NULL) { return PJ_SUCCESS; } if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) { tmp_frame.buf = sport->put_buf; if (sport->dn_port->info.channel_count == 1) { pjmedia_convert_channel_nto1((pj_int16_t*)tmp_frame.buf, (const pj_int16_t*)frame->buf, sport->base.info.channel_count, sport->base.info.samples_per_frame, (sport->options & PJMEDIA_STEREO_MIX), 0); } else { pjmedia_convert_channel_1ton((pj_int16_t*)tmp_frame.buf, (const pj_int16_t*)frame->buf, sport->dn_port->info.channel_count, sport->base.info.samples_per_frame, sport->options); } tmp_frame.size = sport->dn_port->info.bytes_per_frame; } 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 ); }