1
/* $Id: port.c 3893 2011-12-01 10:49:07Z ming $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#include <pjmedia/port.h>
21
#include <pjmedia/errno.h>
22
#include <pj/assert.h>
26
#define THIS_FILE "port.c"
30
* This is an auxiliary function to initialize port info for
31
* ports which deal with PCM audio.
33
PJ_DEF(pj_status_t) pjmedia_port_info_init( pjmedia_port_info *info,
37
unsigned channel_count,
38
unsigned bits_per_sample,
39
unsigned samples_per_frame)
41
#define USEC_IN_SEC (pj_uint64_t)1000000
42
unsigned frame_time_usec, avg_bps;
44
pj_bzero(info, sizeof(*info));
46
info->signature = signature;
47
info->dir = PJMEDIA_DIR_ENCODING_DECODING;
50
frame_time_usec = (unsigned)(samples_per_frame * USEC_IN_SEC /
51
channel_count / clock_rate);
52
avg_bps = clock_rate * channel_count * bits_per_sample;
54
pjmedia_format_init_audio(&info->fmt, PJMEDIA_FORMAT_L16, clock_rate,
55
channel_count, bits_per_sample, frame_time_usec,
61
PJ_DEF(pj_status_t) pjmedia_port_info_init2( pjmedia_port_info *info,
65
const pjmedia_format *fmt)
67
pj_bzero(info, sizeof(*info));
68
info->signature = signature;
72
pjmedia_format_copy(&info->fmt, fmt);
78
* Get a clock source from the port.
80
PJ_DEF(pjmedia_clock_src *) pjmedia_port_get_clock_src( pjmedia_port *port,
83
if (port && port->get_clock_src)
84
return port->get_clock_src(port, dir);
90
* Get a frame from the port (and subsequent downstream ports).
92
PJ_DEF(pj_status_t) pjmedia_port_get_frame( pjmedia_port *port,
93
pjmedia_frame *frame )
95
PJ_ASSERT_RETURN(port && frame, PJ_EINVAL);
98
return port->get_frame(port, frame);
100
frame->type = PJMEDIA_FRAME_TYPE_NONE;
101
return PJ_EINVALIDOP;
107
* Put a frame to the port (and subsequent downstream ports).
109
PJ_DEF(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
110
pjmedia_frame *frame )
112
PJ_ASSERT_RETURN(port && frame, PJ_EINVAL);
115
return port->put_frame(port, frame);
117
return PJ_EINVALIDOP;
121
* Destroy port (and subsequent downstream ports)
123
PJ_DEF(pj_status_t) pjmedia_port_destroy( pjmedia_port *port )
127
PJ_ASSERT_RETURN(port, PJ_EINVAL);
129
if (port->on_destroy)
130
status = port->on_destroy(port);