1
/* $Id: stream.h 3553 2011-05-05 06:14:19Z nanang $ */
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
#ifndef __PJMEDIA_STREAM_H__
21
#define __PJMEDIA_STREAM_H__
26
* @brief Media Stream.
29
#include <pjmedia/codec.h>
30
#include <pjmedia/endpoint.h>
31
#include <pjmedia/jbuf.h>
32
#include <pjmedia/port.h>
33
#include <pjmedia/rtcp.h>
34
#include <pjmedia/transport.h>
41
* @defgroup PJMED_STRM Streams
42
* @ingroup PJMEDIA_PORT
43
* @brief Communicating with remote peer via the network
46
* A media stream is a bidirectional multimedia communication between two
47
* endpoints. It corresponds to a media description (m= line) in SDP
50
* A media stream consists of two unidirectional channels:
51
* - encoding channel, which transmits unidirectional media to remote, and
52
* - decoding channel, which receives unidirectional media from remote.
54
* A media stream exports media port interface (see @ref PJMEDIA_PORT)
55
* and application normally uses this interface to interconnect the stream
56
* to other PJMEDIA components.
58
* A media stream internally manages the following objects:
59
* - an instance of media codec (see @ref PJMEDIA_CODEC),
60
* - an @ref PJMED_JBUF,
61
* - two instances of RTP sessions (#pjmedia_rtp_session, one for each
63
* - one instance of RTCP session (#pjmedia_rtcp_session),
64
* - and a reference to media transport to send and receive packets
65
* to/from the network (see @ref PJMEDIA_TRANSPORT).
67
* Streams are created by calling #pjmedia_stream_create(), specifying
68
* #pjmedia_stream_info structure in the parameter. Application can construct
69
* the #pjmedia_stream_info structure manually, or use
70
* #pjmedia_stream_info_from_sdp() or #pjmedia_session_info_from_sdp()
71
* functions to construct the #pjmedia_stream_info from local and remote
72
* SDP session descriptors.
74
* Application can also use @ref PJMEDIA_SESSION to indirectly create the
79
* Opaque declaration for media channel.
80
* Media channel is unidirectional flow of media from sender to
83
typedef struct pjmedia_channel pjmedia_channel;
86
* This structure describes media stream information. Each media stream
87
* corresponds to one "m=" line in SDP session descriptor, and it has
88
* its own RTP/RTCP socket pair.
90
struct pjmedia_stream_info
92
pjmedia_type type; /**< Media type (audio, video) */
93
pjmedia_tp_proto proto; /**< Transport protocol (RTP/AVP, etc.) */
94
pjmedia_dir dir; /**< Media direction. */
95
pj_sockaddr rem_addr; /**< Remote RTP address */
96
pj_sockaddr rem_rtcp; /**< Optional remote RTCP address. If
97
sin_family is zero, the RTP address
98
will be calculated from RTP. */
99
#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
100
pj_bool_t rtcp_xr_enabled;
101
/**< Specify whether RTCP XR is enabled.*/
102
pj_uint32_t rtcp_xr_interval; /**< RTCP XR interval. */
103
pj_sockaddr rtcp_xr_dest;/**<Additional remote RTCP XR address.
104
This is useful for third-party (e.g:
105
network monitor) to monitor the
106
stream. If sin_family is zero,
107
this will be ignored. */
109
pjmedia_codec_info fmt; /**< Incoming codec format info. */
110
pjmedia_codec_param *param; /**< Optional codec param. */
111
unsigned tx_pt; /**< Outgoing codec paylaod type. */
112
unsigned tx_maxptime;/**< Outgoing codec max ptime. */
113
int tx_event_pt;/**< Outgoing pt for telephone-events. */
114
int rx_event_pt;/**< Incoming pt for telephone-events. */
115
pj_uint32_t ssrc; /**< RTP SSRC. */
116
pj_uint32_t rtp_ts; /**< Initial RTP timestamp. */
117
pj_uint16_t rtp_seq; /**< Initial RTP sequence number. */
118
pj_uint8_t rtp_seq_ts_set;
119
/**< Bitmask flags if initial RTP sequence
120
and/or timestamp for sender are set.
121
bit 0/LSB : sequence flag
122
bit 1 : timestamp flag */
123
int jb_init; /**< Jitter buffer init delay in msec.
125
int jb_min_pre; /**< Jitter buffer minimum prefetch
126
delay in msec (-1 for default). */
127
int jb_max_pre; /**< Jitter buffer maximum prefetch
128
delay in msec (-1 for default). */
129
int jb_max; /**< Jitter buffer max delay in msec. */
131
#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
132
pj_bool_t use_ka; /**< Stream keep-alive and NAT hole punch
133
(see #PJMEDIA_STREAM_ENABLE_KA)
140
* @see pjmedia_stream_info.
142
typedef struct pjmedia_stream_info pjmedia_stream_info;
147
* Create a media stream based on the specified parameter. After the stream
148
* has been created, application normally would want to get the media port
149
* interface of the streams, by calling pjmedia_stream_get_port(). The
150
* media port interface exports put_frame() and get_frame() function, used
151
* to transmit and receive media frames from the stream.
153
* Without application calling put_frame() and get_frame(), there will be
154
* no media frames transmitted or received by the stream.
156
* @param endpt Media endpoint.
157
* @param pool Pool to allocate memory for the stream. A large
158
* number of memory may be needed because jitter
159
* buffer needs to preallocate some storage.
160
* @param info Stream information.
161
* @param tp Stream transport instance used to transmit
162
* and receive RTP/RTCP packets to/from the underlying
164
* @param user_data Arbitrary user data (for future callback feature).
165
* @param p_stream Pointer to receive the media stream.
167
* @return PJ_SUCCESS on success.
169
PJ_DECL(pj_status_t) pjmedia_stream_create(pjmedia_endpt *endpt,
171
const pjmedia_stream_info *info,
172
pjmedia_transport *tp,
174
pjmedia_stream **p_stream);
177
* Destroy the media stream.
179
* @param stream The media stream.
181
* @return PJ_SUCCESS on success.
183
PJ_DECL(pj_status_t) pjmedia_stream_destroy(pjmedia_stream *stream);
187
* Get the last frame type retreived from the jitter buffer.
189
* @param stream The media stream.
191
* @return Jitter buffer frame type.
193
PJ_DEF(char) pjmedia_stream_get_last_jb_frame_type(pjmedia_stream *stream);
197
* Get the media port interface of the stream. The media port interface
198
* declares put_frame() and get_frame() function, which is the only
199
* way for application to transmit and receive media frames from the
202
* @param stream The media stream.
203
* @param p_port Pointer to receive the port interface.
205
* @return PJ_SUCCESS on success.
207
PJ_DECL(pj_status_t) pjmedia_stream_get_port(pjmedia_stream *stream,
208
pjmedia_port **p_port );
212
* Get the media transport object associated with this stream.
214
* @param st The media stream.
216
* @return The transport object being used by the stream.
218
PJ_DECL(pjmedia_transport*) pjmedia_stream_get_transport(pjmedia_stream *st);
222
* Start the media stream. This will start the appropriate channels
223
* in the media stream, depending on the media direction that was set
224
* when the stream was created.
226
* @param stream The media stream.
228
* @return PJ_SUCCESS on success.
230
PJ_DECL(pj_status_t) pjmedia_stream_start(pjmedia_stream *stream);
234
* Get the stream statistics. See also
235
* #pjmedia_stream_get_stat_jbuf()
237
* @param stream The media stream.
238
* @param stat Media stream statistics.
240
* @return PJ_SUCCESS on success.
242
PJ_DECL(pj_status_t) pjmedia_stream_get_stat( const pjmedia_stream *stream,
243
pjmedia_rtcp_stat *stat);
247
* Reset the stream statistics.
249
* @param stream The media stream.
251
* @return PJ_SUCCESS on success.
253
PJ_DECL(pj_status_t) pjmedia_stream_reset_stat(pjmedia_stream *stream);
256
#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
258
* Get the stream extended report statistics (RTCP XR).
260
* @param stream The media stream.
261
* @param stat Media stream extended report statistics.
263
* @return PJ_SUCCESS on success.
265
PJ_DECL(pj_status_t) pjmedia_stream_get_stat_xr( const pjmedia_stream *stream,
266
pjmedia_rtcp_xr_stat *stat);
270
* Get current jitter buffer state. See also
271
* #pjmedia_stream_get_stat()
273
* @param stream The media stream.
274
* @param state Jitter buffer state.
276
* @return PJ_SUCCESS on success.
278
PJ_DECL(pj_status_t) pjmedia_stream_get_stat_jbuf(const pjmedia_stream *stream,
279
pjmedia_jb_state *state);
283
* Pause the individual channel in the stream.
285
* @param stream The media channel.
286
* @param dir Which direction to pause.
288
* @return PJ_SUCCESS on success.
290
PJ_DECL(pj_status_t) pjmedia_stream_pause( pjmedia_stream *stream,
294
* Resume the individual channel in the stream.
296
* @param stream The media channel.
297
* @param dir Which direction to resume.
299
* @return PJ_SUCCESS on success;
301
PJ_DECL(pj_status_t) pjmedia_stream_resume(pjmedia_stream *stream,
305
* Transmit DTMF to this stream. The DTMF will be transmitted uisng
306
* RTP telephone-events as described in RFC 2833. This operation is
307
* only valid for audio stream.
309
* @param stream The media stream.
310
* @param ascii_digit String containing digits to be sent to remote.
311
* Currently the maximum number of digits are 32.
313
* @return PJ_SUCCESS on success.
315
PJ_DECL(pj_status_t) pjmedia_stream_dial_dtmf(pjmedia_stream *stream,
316
const pj_str_t *ascii_digit);
320
* Check if the stream has incoming DTMF digits in the incoming DTMF
321
* queue. Incoming DTMF digits received via RFC 2833 mechanism are
322
* saved in the incoming digits queue.
324
* @param stream The media stream.
326
* @return Non-zero (PJ_TRUE) if the stream has received DTMF
329
PJ_DECL(pj_bool_t) pjmedia_stream_check_dtmf(pjmedia_stream *stream);
333
* Retrieve the incoming DTMF digits from the stream, and remove the digits
334
* from stream's DTMF buffer. Note that the digits buffer will not be NULL
337
* @param stream The media stream.
338
* @param ascii_digits Buffer to receive the digits. The length of this
339
* buffer is indicated in the "size" argument.
340
* @param size On input, contains the maximum digits to be copied
342
* On output, it contains the actual digits that has
343
* been copied to the buffer.
345
* @return Non-zero (PJ_TRUE) if the stream has received DTMF
348
PJ_DECL(pj_status_t) pjmedia_stream_get_dtmf( pjmedia_stream *stream,
354
* Set callback to be called upon receiving DTMF digits. If callback is
355
* registered, the stream will not buffer incoming DTMF but rather call
356
* the callback as soon as DTMF digit is received completely.
358
* @param stream The media stream.
359
* @param cb Callback to be called upon receiving DTMF digits.
360
* The DTMF digits will be given to the callback as
362
* @param user_data User data to be returned back when the callback
365
* @return PJ_SUCCESS on success.
368
pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream,
369
void (*cb)(pjmedia_stream*,
381
#endif /* __PJMEDIA_STREAM_H__ */