Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #include <pjmedia/bidirectional.h> |
| 21 | #include <pj/pool.h> |
| 22 | |
| 23 | |
| 24 | #define THIS_FILE "bidirectional.c" |
| 25 | #define SIGNATURE PJMEDIA_SIG_PORT_BIDIR |
| 26 | |
| 27 | struct bidir_port |
| 28 | { |
| 29 | pjmedia_port base; |
| 30 | pjmedia_port *get_port; |
| 31 | pjmedia_port *put_port; |
| 32 | }; |
| 33 | |
| 34 | |
| 35 | static pj_status_t put_frame(pjmedia_port *this_port, |
| 36 | pjmedia_frame *frame) |
| 37 | { |
| 38 | struct bidir_port *p = (struct bidir_port*)this_port; |
| 39 | return pjmedia_port_put_frame(p->put_port, frame); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | static pj_status_t get_frame(pjmedia_port *this_port, |
| 44 | pjmedia_frame *frame) |
| 45 | { |
| 46 | struct bidir_port *p = (struct bidir_port*)this_port; |
| 47 | return pjmedia_port_get_frame(p->get_port, frame); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | PJ_DEF(pj_status_t) pjmedia_bidirectional_port_create( pj_pool_t *pool, |
| 52 | pjmedia_port *get_port, |
| 53 | pjmedia_port *put_port, |
| 54 | pjmedia_port **p_port ) |
| 55 | { |
| 56 | struct bidir_port *port; |
| 57 | const pjmedia_audio_format_detail *gafd; |
| 58 | |
| 59 | port = PJ_POOL_ZALLOC_T(pool, struct bidir_port); |
| 60 | gafd = pjmedia_format_get_audio_format_detail(&get_port->info.fmt, 1); |
| 61 | |
| 62 | pjmedia_port_info_init(&port->base.info, &get_port->info.name, SIGNATURE, |
| 63 | gafd->clock_rate, |
| 64 | gafd->channel_count, |
| 65 | gafd->bits_per_sample, |
| 66 | PJMEDIA_AFD_SPF(gafd)); |
| 67 | |
| 68 | port->get_port = get_port; |
| 69 | port->put_port = put_port; |
| 70 | |
| 71 | port->base.get_frame = &get_frame; |
| 72 | port->base.put_frame = &put_frame; |
| 73 | |
| 74 | *p_port = &port->base; |
| 75 | |
| 76 | return PJ_SUCCESS; |
| 77 | } |
| 78 | |