summaryrefslogtreecommitdiff
path: root/pjmedia/include/pjmedia/port.h
blob: fbc5855267d7f18c48160151de2b7f12e540757b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* $Id$ */
/* 
 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
#ifndef __PJMEDIA_PORT_H__
#define __PJMEDIA_PORT_H__

/**
 * @file port.h
 * @brief Port interface declaration
 */
#include <pjmedia/types.h>
#include <pj/os.h>


PJ_BEGIN_DECL


/**
 * Port operation setting.
 */
enum pjmedia_port_op
{
    /** 
     * No change to the port TX or RX settings.
     */
    PJMEDIA_PORT_NO_CHANGE,

    /**
     * TX or RX is disabled from the port. It means get_frame() or
     * put_frame() WILL NOT be called for this port.
     */
    PJMEDIA_PORT_DISABLE,

    /**
     * TX or RX is muted, which means that get_frame() or put_frame()
     * will still be called, but the audio frame is discarded.
     */
    PJMEDIA_PORT_MUTE,

    /**
     * Enable TX and RX to/from this port.
     */
    PJMEDIA_PORT_ENABLE,
};


/**
 * @see pjmedia_port_op
 */
typedef enum pjmedia_port_op pjmedia_port_op;


/**
 * Port info.
 */
struct pjmedia_port_info
{
    pj_str_t	    name;		/**< Port name.			    */
    pj_uint32_t	    signature;		/**< Port signature.		    */
    pjmedia_type    type;		/**< Media type.		    */
    pj_bool_t	    has_info;		/**< Has info?			    */
    pj_bool_t	    need_info;		/**< Need info on connect?	    */
    unsigned	    pt;			/**< Payload type (can be dynamic). */
    pj_str_t	    encoding_name;	/**< Encoding name.		    */
    unsigned	    clock_rate;		/**< Sampling rate.		    */
    unsigned	    channel_count;	/**< Number of channels.	    */
    unsigned	    bits_per_sample;	/**< Bits/sample		    */
    unsigned	    samples_per_frame;	/**< No of samples per frame.	    */
    unsigned	    bytes_per_frame;	/**< No of samples per frame.	    */
};

/**
 * @see pjmedia_port_info
 */
typedef struct pjmedia_port_info pjmedia_port_info;


/** 
 * Types of media frame. 
 */
enum pjmedia_frame_type
{
    PJMEDIA_FRAME_TYPE_NONE,	    /**< No frame.		*/
    PJMEDIA_FRAME_TYPE_CNG,	    /**< Silence audio frame.	*/
    PJMEDIA_FRAME_TYPE_AUDIO,	    /**< Normal audio frame.	*/

};


/** 
 * @see pjmedia_frame_type
 */
typedef enum pjmedia_frame_type pjmedia_frame_type;


/** 
 * This structure describes a media frame. 
 */
struct pjmedia_frame
{
    pjmedia_frame_type	 type;	    /**< Frame type.		    */
    void		*buf;	    /**< Pointer to buffer.	    */
    pj_size_t		 size;	    /**< Frame size in bytes.	    */
    pj_timestamp	 timestamp; /**< Frame timestamp.	    */
};


/** 
 * @see pjmedia_frame
 */
typedef struct pjmedia_frame pjmedia_frame;


/**
 * For future graph.
 */
typedef struct pjmedia_graph pjmedia_graph;


/**
 * @see pjmedia_port
 */
typedef struct pjmedia_port pjmedia_port;

/**
 * Port interface.
 */
struct pjmedia_port
{
    pjmedia_port_info	 info;
    pjmedia_graph	*graph;
    pjmedia_port	*upstream_port;
    pjmedia_port	*downstream_port;
    void		*user_data;

    /**
     * Called when this port is connected to an upstream port.
     */
    pj_status_t (*on_upstream_connect)(pj_pool_t *pool,
				       pjmedia_port *this_port,
				       pjmedia_port *upstream);

    /**
     * Called when this port is connected to a downstream port.
     */
    pj_status_t (*on_downstream_connect)(pj_pool_t *pool,
					 pjmedia_port *this_port,
				         pjmedia_port *upstream);

    /**
     * Sink interface. 
     * This should only be called by #pjmedia_port_put_frame().
     */
    pj_status_t (*put_frame)(pjmedia_port *this_port, 
			     const pjmedia_frame *frame);

    /**
     * Source interface. 
     * This should only be called by #pjmedia_port_get_frame().
     */
    pj_status_t (*get_frame)(pjmedia_port *this_port, 
			     pjmedia_frame *frame);

    /**
     * Called to destroy this port.
     */
    pj_status_t (*on_destroy)(pjmedia_port *this_port);
};



/**
 * Connect two ports.
 */
PJ_DECL(pj_status_t) pjmedia_port_connect( pj_pool_t *pool,
					   pjmedia_port *upstream_port,
					   pjmedia_port *downstream_port);

/**
 * Disconnect ports.
 */
PJ_DECL(pj_status_t) pjmedia_port_disconnect( pjmedia_port *upstream_port,
					      pjmedia_port *downstream_port);


/**
 * Get a frame from the port (and subsequent downstream ports).
 */
PJ_DECL(pj_status_t) pjmedia_port_get_frame( pjmedia_port *port,
					     pjmedia_frame *frame );

/**
 * Put a frame to the port (and subsequent downstream ports).
 */
PJ_DECL(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
					     const pjmedia_frame *frame );


/**
 * Destroy port (and subsequent downstream ports)
 */
PJ_DECL(pj_status_t) pjmedia_port_destroy( pjmedia_port *port );



PJ_END_DECL


#endif	/* __PJMEDIA_PORT_H__ */