1
/* $Id: vid_stream.h 4043 2012-04-12 13:41:50Z nanang $ */
3
* Copyright (C) 2011 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#ifndef __PJMEDIA_VID_STREAM_H__
20
#define __PJMEDIA_VID_STREAM_H__
25
* @brief Video Stream.
28
#include <pjmedia/endpoint.h>
29
#include <pjmedia/jbuf.h>
30
#include <pjmedia/port.h>
31
#include <pjmedia/rtcp.h>
32
#include <pjmedia/transport.h>
33
#include <pjmedia/vid_codec.h>
40
* @defgroup PJMED_VID_STRM Video streams
41
* @ingroup PJMEDIA_PORT
42
* @brief Video communication via the network
45
* A video stream is a bidirectional video communication between two
46
* endpoints. It corresponds to a video media description ("m=video" line)
47
* in SDP session descriptor.
49
* A video stream consists of two unidirectional channels:
50
* - encoding channel, which transmits unidirectional video to remote, and
51
* - decoding channel, which receives unidirectional media from remote.
53
* A video stream exports two media port interface (see @ref PJMEDIA_PORT),
54
* one for each direction, and application normally uses this interface to
55
* interconnect the stream to other PJMEDIA components, e.g: the video
56
* capture port supplies frames to the encoding port and video renderer
57
* consumes frames from the decoding port.
59
* A video stream internally manages the following objects:
60
* - an instance of video codec (see @ref PJMEDIA_VID_CODEC),
61
* - an @ref PJMED_JBUF,
62
* - two instances of RTP sessions (#pjmedia_rtp_session, one for each
64
* - one instance of RTCP session (#pjmedia_rtcp_session),
65
* - and a reference to video transport to send and receive packets
66
* to/from the network (see @ref PJMEDIA_TRANSPORT).
68
* Video streams are created by calling #pjmedia_vid_stream_create(),
69
* specifying #pjmedia_stream_info structure in the parameter. Application
70
* can construct the #pjmedia_vid_stream_info structure manually, or use
71
* #pjmedia_vid_stream_info_from_sdp() function to construct the
72
* #pjmedia_vid stream_info from local and remote SDP session descriptors.
77
* Enumeration of video stream sending rate control.
79
typedef enum pjmedia_vid_stream_rc_method
82
* No sending rate control. All outgoing RTP packets will be transmitted
83
* immediately right after encoding process is done.
85
PJMEDIA_VID_STREAM_RC_NONE = 0,
88
* Simple blocking. Each outgoing RTP packet transmission may be delayed
89
* to avoid peak bandwidth that is much higher than specified. The thread
90
* invoking the video stream put_frame(), e.g: video capture device thread,
91
* will be blocked whenever transmission delay takes place.
93
PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING = 1
95
} pjmedia_vid_stream_rc_method;
99
* Structure of configuration settings for video stream sending rate control.
101
typedef struct pjmedia_vid_stream_rc_config
104
* Rate control method.
106
* Default: PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING.
108
pjmedia_vid_stream_rc_method method;
111
* Upstream/outgoing bandwidth. If this is set to zero, the video stream
112
* will use codec maximum bitrate setting.
114
* Default: 0 (follow codec maximum bitrate).
118
} pjmedia_vid_stream_rc_config;
122
* This structure describes video stream information. Each video stream
123
* corresponds to one "m=" line in SDP session descriptor, and it has
124
* its own RTP/RTCP socket pair.
126
typedef struct pjmedia_vid_stream_info
128
pjmedia_type type; /**< Media type (audio, video) */
129
pjmedia_tp_proto proto; /**< Transport protocol (RTP/AVP, etc.) */
130
pjmedia_dir dir; /**< Media direction. */
131
pj_sockaddr rem_addr; /**< Remote RTP address */
132
pj_sockaddr rem_rtcp; /**< Optional remote RTCP address. If
133
sin_family is zero, the RTP address
134
will be calculated from RTP. */
135
unsigned tx_pt; /**< Outgoing codec paylaod type. */
136
unsigned rx_pt; /**< Incoming codec paylaod type. */
137
pj_uint32_t ssrc; /**< RTP SSRC. */
138
pj_uint32_t rtp_ts; /**< Initial RTP timestamp. */
139
pj_uint16_t rtp_seq; /**< Initial RTP sequence number. */
140
pj_uint8_t rtp_seq_ts_set;
141
/**< Bitmask flags if initial RTP sequence
142
and/or timestamp for sender are set.
143
bit 0/LSB : sequence flag
144
bit 1 : timestamp flag */
145
int jb_init; /**< Jitter buffer init delay in msec.
147
int jb_min_pre; /**< Jitter buffer minimum prefetch
148
delay in msec (-1 for default). */
149
int jb_max_pre; /**< Jitter buffer maximum prefetch
150
delay in msec (-1 for default). */
151
int jb_max; /**< Jitter buffer max delay in msec. */
153
#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
154
pj_bool_t use_ka; /**< Stream keep-alive and NAT hole punch
155
(see #PJMEDIA_STREAM_ENABLE_KA)
159
pjmedia_vid_codec_info codec_info; /**< Incoming codec format info. */
160
pjmedia_vid_codec_param *codec_param; /**< Optional codec param. */
162
pj_bool_t rtcp_sdes_bye_disabled;
163
/**< Disable automatic sending of RTCP
166
pjmedia_vid_stream_rc_config rc_cfg;
167
/**< Stream send rate control settings. */
168
} pjmedia_vid_stream_info;
172
* This function will initialize the video stream info based on information
173
* in both SDP session descriptors for the specified stream index.
174
* The remaining information will be taken from default codec parameters.
175
* If socket info array is specified, the socket will be copied to the
176
* session info as well.
178
* @param si Stream info structure to be initialized.
179
* @param pool Pool to allocate memory.
180
* @param endpt PJMEDIA endpoint instance.
181
* @param local Local SDP session descriptor.
182
* @param remote Remote SDP session descriptor.
183
* @param stream_idx Media stream index in the session descriptor.
185
* @return PJ_SUCCESS if stream info is successfully initialized.
188
pjmedia_vid_stream_info_from_sdp(pjmedia_vid_stream_info *si,
190
pjmedia_endpt *endpt,
191
const pjmedia_sdp_session *local,
192
const pjmedia_sdp_session *remote,
193
unsigned stream_idx);
197
* Initialize the video stream rate control with default settings.
199
* @param cfg Video stream rate control structure to be initialized.
202
pjmedia_vid_stream_rc_config_default(pjmedia_vid_stream_rc_config *cfg);
206
* Opaque declaration for video stream.
208
typedef struct pjmedia_vid_stream pjmedia_vid_stream;
212
* Create a video stream based on the specified parameter. After the video
213
* stream has been created, application normally would want to get the media
214
* port interface of the stream, by calling pjmedia_vid_stream_get_port().
215
* The media port interface exports put_frame() and get_frame() function,
216
* used to transmit and receive media frames from the stream.
218
* Without application calling put_frame() and get_frame(), there will be
219
* no media frames transmitted or received by the stream.
221
* @param endpt Media endpoint.
222
* @param pool Optional pool to allocate memory for the stream. If
223
* this is not specified, one will be created internally.
224
* A large number of memory may be needed because jitter
225
* buffer needs to preallocate some storage.
226
* @param info Stream information to create the stream. Upon return,
227
* this info will be updated with the information from
228
* the instantiated codec. Note that if the "pool"
229
* argument is NULL, some fields in this "info" parameter
230
* will be allocated from the internal pool of the
231
* stream, which means that they will only remain valid
232
* as long as the stream is not destroyed.
233
* @param tp Media transport instance used to transmit and receive
234
* RTP/RTCP packets to/from the underlying network.
235
* @param user_data Arbitrary user data (for future callback feature).
236
* @param p_stream Pointer to receive the video stream.
238
* @return PJ_SUCCESS on success.
240
PJ_DECL(pj_status_t) pjmedia_vid_stream_create(
241
pjmedia_endpt *endpt,
243
pjmedia_vid_stream_info *info,
244
pjmedia_transport *tp,
246
pjmedia_vid_stream **p_stream);
249
* Destroy the video stream.
251
* @param stream The video stream.
253
* @return PJ_SUCCESS on success.
255
PJ_DECL(pj_status_t) pjmedia_vid_stream_destroy(pjmedia_vid_stream *stream);
259
* Get the media port interface of the stream. The media port interface
260
* declares put_frame() and get_frame() function, which is the only
261
* way for application to transmit and receive media frames from the
262
* stream. As bidirectional video streaming may have different video
263
* formats in the encoding and decoding direction, there are two media
264
* ports exported by the video stream, one for each direction.
266
* @param stream The video stream.
267
* @param dir The video direction.
268
* @param p_port Pointer to receive the port interface.
270
* @return PJ_SUCCESS on success.
272
PJ_DECL(pj_status_t) pjmedia_vid_stream_get_port(
273
pjmedia_vid_stream *stream,
275
pjmedia_port **p_port);
279
* Get the media transport object associated with this stream.
281
* @param st The video stream.
283
* @return The transport object being used by the stream.
285
PJ_DECL(pjmedia_transport*) pjmedia_vid_stream_get_transport(
286
pjmedia_vid_stream *st);
290
* Get the stream statistics. See also #pjmedia_stream_get_stat_jbuf()
292
* @param stream The video stream.
293
* @param stat Media stream statistics.
295
* @return PJ_SUCCESS on success.
297
PJ_DECL(pj_status_t) pjmedia_vid_stream_get_stat(
298
const pjmedia_vid_stream *stream,
299
pjmedia_rtcp_stat *stat);
302
* Reset the video stream statistics.
304
* @param stream The video stream.
306
* @return PJ_SUCCESS on success.
308
PJ_DECL(pj_status_t) pjmedia_vid_stream_reset_stat(pjmedia_vid_stream *stream);
312
* Get current jitter buffer state. See also #pjmedia_stream_get_stat()
314
* @param stream The video stream.
315
* @param state Jitter buffer state.
317
* @return PJ_SUCCESS on success.
319
PJ_DECL(pj_status_t) pjmedia_vid_stream_get_stat_jbuf(
320
const pjmedia_vid_stream *stream,
321
pjmedia_jb_state *state);
325
* Get the stream info.
327
* @param stream The video stream.
328
* @param info Video stream info.
330
* @return PJ_SUCCESS on success.
332
PJ_DECL(pj_status_t) pjmedia_vid_stream_get_info(
333
const pjmedia_vid_stream *stream,
334
pjmedia_vid_stream_info *info);
338
* Start the video stream. This will start the appropriate channels
339
* in the video stream, depending on the video direction that was set
340
* when the stream was created.
342
* @param stream The video stream.
344
* @return PJ_SUCCESS on success.
346
PJ_DECL(pj_status_t) pjmedia_vid_stream_start(pjmedia_vid_stream *stream);
350
* Query if the stream is started on the specified direction.
352
* @param stream The video stream.
353
* @param dir The direction to be checked.
355
* @return PJ_TRUE if stream is started.
357
PJ_DECL(pj_bool_t) pjmedia_vid_stream_is_running(pjmedia_vid_stream *stream,
361
* Pause stream channels.
363
* @param stream The video stream.
364
* @param dir Which channel direction to pause.
366
* @return PJ_SUCCESS on success.
368
PJ_DECL(pj_status_t) pjmedia_vid_stream_pause(pjmedia_vid_stream *stream,
372
* Resume stream channels.
374
* @param stream The video stream.
375
* @param dir Which channel direction to resume.
377
* @return PJ_SUCCESS on success;
379
PJ_DECL(pj_status_t) pjmedia_vid_stream_resume(pjmedia_vid_stream *stream,
384
* Force stream to send video keyframe on the next transmission.
386
* @param stream The video stream.
388
* @return PJ_SUCCESS on success;
390
PJ_DECL(pj_status_t) pjmedia_vid_stream_send_keyframe(
391
pjmedia_vid_stream *stream);
395
* Send RTCP SDES for the media stream.
397
* @param stream The media stream.
399
* @return PJ_SUCCESS on success.
401
PJ_DECL(pj_status_t) pjmedia_vid_stream_send_rtcp_sdes(
402
pjmedia_vid_stream *stream);
406
* Send RTCP BYE for the media stream.
408
* @param stream The media stream.
410
* @return PJ_SUCCESS on success.
412
PJ_DECL(pj_status_t) pjmedia_vid_stream_send_rtcp_bye(
413
pjmedia_vid_stream *stream);
423
#endif /* __PJMEDIA_VID_STREAM_H__ */