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/null_port.h> |
| 21 | #include <pjmedia/errno.h> |
| 22 | #include <pj/assert.h> |
| 23 | #include <pj/pool.h> |
| 24 | #include <pj/string.h> |
| 25 | |
| 26 | |
| 27 | #define SIGNATURE PJMEDIA_SIG_PORT_NULL |
| 28 | |
| 29 | static pj_status_t null_get_frame(pjmedia_port *this_port, |
| 30 | pjmedia_frame *frame); |
| 31 | static pj_status_t null_put_frame(pjmedia_port *this_port, |
| 32 | pjmedia_frame *frame); |
| 33 | static pj_status_t null_on_destroy(pjmedia_port *this_port); |
| 34 | |
| 35 | |
| 36 | PJ_DEF(pj_status_t) pjmedia_null_port_create( pj_pool_t *pool, |
| 37 | unsigned sampling_rate, |
| 38 | unsigned channel_count, |
| 39 | unsigned samples_per_frame, |
| 40 | unsigned bits_per_sample, |
| 41 | pjmedia_port **p_port ) |
| 42 | { |
| 43 | pjmedia_port *port; |
| 44 | const pj_str_t name = pj_str("null-port"); |
| 45 | |
| 46 | PJ_ASSERT_RETURN(pool && p_port, PJ_EINVAL); |
| 47 | |
| 48 | port = PJ_POOL_ZALLOC_T(pool, pjmedia_port); |
| 49 | PJ_ASSERT_RETURN(port != NULL, PJ_ENOMEM); |
| 50 | |
| 51 | pjmedia_port_info_init(&port->info, &name, SIGNATURE, sampling_rate, |
| 52 | channel_count, bits_per_sample, samples_per_frame); |
| 53 | |
| 54 | port->get_frame = &null_get_frame; |
| 55 | port->put_frame = &null_put_frame; |
| 56 | port->on_destroy = &null_on_destroy; |
| 57 | |
| 58 | |
| 59 | *p_port = port; |
| 60 | |
| 61 | return PJ_SUCCESS; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | /* |
| 67 | * Put frame to file. |
| 68 | */ |
| 69 | static pj_status_t null_put_frame(pjmedia_port *this_port, |
| 70 | pjmedia_frame *frame) |
| 71 | { |
| 72 | PJ_UNUSED_ARG(this_port); |
| 73 | PJ_UNUSED_ARG(frame); |
| 74 | return PJ_SUCCESS; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * Get frame from file. |
| 80 | */ |
| 81 | static pj_status_t null_get_frame(pjmedia_port *this_port, |
| 82 | pjmedia_frame *frame) |
| 83 | { |
| 84 | frame->type = PJMEDIA_FRAME_TYPE_AUDIO; |
| 85 | frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info); |
| 86 | frame->timestamp.u32.lo += PJMEDIA_PIA_SPF(&this_port->info); |
| 87 | pjmedia_zero_samples((pj_int16_t*)frame->buf, |
| 88 | PJMEDIA_PIA_SPF(&this_port->info)); |
| 89 | |
| 90 | return PJ_SUCCESS; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /* |
| 95 | * Destroy port. |
| 96 | */ |
| 97 | static pj_status_t null_on_destroy(pjmedia_port *this_port) |
| 98 | { |
| 99 | PJ_UNUSED_ARG(this_port); |
| 100 | return PJ_SUCCESS; |
| 101 | } |