From 5c43708955177778cac44eb56d98e16cbbecf438 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 18 Jan 2006 23:12:57 +0000 Subject: Compiled cleanly first time for the new pjlib git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@121 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia.h | 32 ++++ pjmedia/include/pjmedia/codec.h | 353 +++++++++++++++++++++++++++++++++++++ pjmedia/include/pjmedia/config.h | 27 +++ pjmedia/include/pjmedia/jbuf.h | 142 +++++++++++++++ pjmedia/include/pjmedia/mediamgr.h | 100 +++++++++++ pjmedia/include/pjmedia/rtcp.h | 192 ++++++++++++++++++++ pjmedia/include/pjmedia/rtp.h | 256 +++++++++++++++++++++++++++ pjmedia/include/pjmedia/sdp.h | 332 ++++++++++++++++++++++++++++++++++ pjmedia/include/pjmedia/session.h | 152 ++++++++++++++++ pjmedia/include/pjmedia/sound.h | 201 +++++++++++++++++++++ pjmedia/include/pjmedia/stream.h | 99 +++++++++++ 11 files changed, 1886 insertions(+) create mode 100644 pjmedia/include/pjmedia.h create mode 100644 pjmedia/include/pjmedia/codec.h create mode 100644 pjmedia/include/pjmedia/config.h create mode 100644 pjmedia/include/pjmedia/jbuf.h create mode 100644 pjmedia/include/pjmedia/mediamgr.h create mode 100644 pjmedia/include/pjmedia/rtcp.h create mode 100644 pjmedia/include/pjmedia/rtp.h create mode 100644 pjmedia/include/pjmedia/sdp.h create mode 100644 pjmedia/include/pjmedia/session.h create mode 100644 pjmedia/include/pjmedia/sound.h create mode 100644 pjmedia/include/pjmedia/stream.h (limited to 'pjmedia/include') diff --git a/pjmedia/include/pjmedia.h b/pjmedia/include/pjmedia.h new file mode 100644 index 00000000..b0310f24 --- /dev/null +++ b/pjmedia/include/pjmedia.h @@ -0,0 +1,32 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_H__ +#define __PJMEDIA_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* __PJMEDIA_H__ */ + diff --git a/pjmedia/include/pjmedia/codec.h b/pjmedia/include/pjmedia/codec.h new file mode 100644 index 00000000..3069f31c --- /dev/null +++ b/pjmedia/include/pjmedia/codec.h @@ -0,0 +1,353 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_CODEC_H__ +#define __PJMEDIA_CODEC_H__ + + +/** + * @file codec.h + * @brief Codec framework. + */ + +#include + +PJ_BEGIN_DECL + + +/** + * @defgroup PJMED_CODEC Codec framework. + * @ingroup PJMEDIA + * @{ + */ + +/** Top most media type. */ +typedef enum pj_media_type +{ + /** No type. */ + PJ_MEDIA_TYPE_NONE = 0, + + /** The media is audio */ + PJ_MEDIA_TYPE_AUDIO = 1, + + /** The media is video. */ + PJ_MEDIA_TYPE_VIDEO = 2, + + /** Unknown media type, in this case the name will be specified in + * encoding_name. + */ + PJ_MEDIA_TYPE_UNKNOWN = 3, + +} pj_media_type; + + +/** Media direction. */ +typedef enum pj_media_dir_t +{ + /** None */ + PJ_MEDIA_DIR_NONE = 0, + + /** Encoding (outgoing to network) stream */ + PJ_MEDIA_DIR_ENCODING = 1, + + /** Decoding (incoming from network) stream. */ + PJ_MEDIA_DIR_DECODING = 2, + + /** Incoming and outgoing stream. */ + PJ_MEDIA_DIR_ENCODING_DECODING = 3, + +} pj_media_dir_t; + + +/** Standard RTP paylist types. */ +typedef enum pj_rtp_pt +{ + PJ_RTP_PT_PCMU = 0, /* audio PCMU */ + PJ_RTP_PT_GSM = 3, /* audio GSM */ + PJ_RTP_PT_G723 = 4, /* audio G723 */ + PJ_RTP_PT_DVI4_8K = 5, /* audio DVI4 8KHz */ + PJ_RTP_PT_DVI4_16K = 6, /* audio DVI4 16Khz */ + PJ_RTP_PT_LPC = 7, /* audio LPC */ + PJ_RTP_PT_PCMA = 8, /* audio PCMA */ + PJ_RTP_PT_G722 = 9, /* audio G722 */ + PJ_RTP_PT_L16_2 = 10, /* audio 16bit linear 44.1KHz stereo */ + PJ_RTP_PT_L16_1 = 11, /* audio 16bit linear 44.1KHz mono */ + PJ_RTP_PT_QCELP = 12, /* audio QCELP */ + PJ_RTP_PT_CN = 13, /* audio Comfort Noise */ + PJ_RTP_PT_MPA = 14, /* audio MPEG1 or MPEG2 as elementary streams */ + PJ_RTP_PT_G728 = 15, /* audio G728 */ + PJ_RTP_PT_DVI4_11K = 16, /* audio DVI4 11.025KHz mono */ + PJ_RTP_PT_DVI4_22K = 17, /* audio DVI4 22.050KHz mono */ + PJ_RTP_PT_G729 = 18, /* audio G729 */ + PJ_RTP_PT_CELB = 25, /* video/comb Cell-B by Sun Microsystems (RFC 2029) */ + PJ_RTP_PT_JPEG = 26, /* video JPEG */ + PJ_RTP_PT_NV = 28, /* video NV implemented by nv program by Xerox */ + PJ_RTP_PT_H261 = 31, /* video H261 */ + PJ_RTP_PT_MPV = 32, /* video MPEG1 or MPEG2 elementary streams */ + PJ_RTP_PT_MP2T = 33, /* video MPEG2 transport */ + PJ_RTP_PT_H263 = 34, /* video H263 */ + + PJ_RTP_PT_DYNAMIC = 96, /* start of dynamic RTP payload */ +} pj_rtp_pt; + + +/** Identification used to search for codec factory that supports specific + * codec specification. + */ +typedef struct pj_codec_id +{ + /** Media type. */ + pj_media_type type; + + /** Payload type (can be dynamic). */ + unsigned pt; + + /** Encoding name, must be present if the payload type is dynamic. */ + pj_str_t encoding_name; + + /** Sampling rate. */ + unsigned sample_rate; +} pj_codec_id; + + +/** Detailed codec attributes used both to configure a codec and to query + * the capability of codec factories. + */ +typedef struct pj_codec_attr +{ + pj_uint32_t sample_rate; /* Sampling rate in Hz */ + pj_uint32_t avg_bps; /* Average bandwidth in bits per second */ + + pj_uint8_t pcm_bits_per_sample;/* Bits per sample in the PCM side */ + pj_uint16_t ptime; /* Packet time in miliseconds */ + + unsigned pt:8; /* Payload type. */ + unsigned vad_enabled:1; /* Voice Activity Detector. */ + unsigned cng_enabled:1; /* Comfort Noise Generator. */ + unsigned lpf_enabled:1; /* Low pass filter */ + unsigned hpf_enabled:1; /* High pass filter */ + unsigned penh_enabled:1; /* Perceptual Enhancement */ + unsigned concl_enabled:1; /* Packet loss concealment */ + unsigned reserved_bit:1; + +} pj_codec_attr; + +/** Types of audio frame. */ +typedef enum pj_audio_frame_type +{ + /** The frame is a silence audio frame. */ + PJ_AUDIO_FRAME_SILENCE, + + /** The frame is a non-silence audio frame. */ + PJ_AUDIO_FRAME_AUDIO, + +} pj_audio_frame_type; + +typedef struct pj_codec pj_codec; +typedef struct pj_codec_factory pj_codec_factory; + + +/** This structure describes an audio frame. */ +struct pj_audio_frame +{ + /** Type: silence or non-silence. */ + pj_audio_frame_type type; + + /** Pointer to buffer. */ + void *buf; + + /** Frame size in bytes. */ + unsigned size; +}; + +/** + * Operations that must be supported by the codec. + */ +typedef struct pj_codec_op +{ + /** Get default attributes. */ + pj_status_t (*default_attr) (pj_codec *codec, pj_codec_attr *attr); + + /** Open and initialize codec using the specified attribute. + * @return zero on success. + */ + pj_status_t (*init)( pj_codec *codec, pj_pool_t *pool ); + + /** Close and shutdown codec. + */ + pj_status_t (*open)( pj_codec *codec, pj_codec_attr *attr ); + + /** Close and shutdown codec. + */ + pj_status_t (*close)( pj_codec *codec ); + + /** Encode frame. + */ + pj_status_t (*encode)( pj_codec *codec, const struct pj_audio_frame *input, + unsigned output_buf_len, struct pj_audio_frame *output); + + /** Decode frame. + */ + pj_status_t (*decode)( pj_codec *codec, const struct pj_audio_frame *input, + unsigned output_buf_len, struct pj_audio_frame *output); + +} pj_codec_op; + +/** + * A codec describes an instance to encode or decode media frames. + */ +struct pj_codec +{ + /** Entries to put this codec instance in codec factory's list. */ + PJ_DECL_LIST_MEMBER(struct pj_codec); + + /** Codec's private data. */ + void *codec_data; + + /** Codec factory where this codec was allocated. */ + pj_codec_factory *factory; + + /** Operations to codec. */ + pj_codec_op *op; +}; + +/** + * This structure describes operations that must be supported by codec factories. + */ +typedef struct pj_codec_factory_op +{ + /** Check whether the factory can create codec with the specified ID. + * @param factory The codec factory. + * @param id The codec ID. + * @return zero it matches. + */ + pj_status_t (*match_id)( pj_codec_factory *factory, const pj_codec_id *id ); + + /** Create default attributes for the specified codec ID. This function can + * be called by application to get the capability of the codec. + * @param factory The codec factory. + * @param id The codec ID. + * @param attr The attribute to be initialized. + * @return zero if success. + */ + pj_status_t (*default_attr)( pj_codec_factory *factory, const pj_codec_id *id, + pj_codec_attr *attr ); + + /** Enumerate supported codecs. + * @param factory The codec factory. + * @param count Number of entries in the array. + * @param codecs The codec array. + * @return the total number of supported codecs, which can be less or + * greater than requested. + */ + unsigned (*enum_codecs) (pj_codec_factory *factory, unsigned count, pj_codec_id codecs[]); + + /** This function is called by codec manager to instantiate one codec + * instance. + * @param factory The codec factory. + * @param id The codec ID. + * @return the instance of the codec, or NULL if codec can not be created. + */ + pj_codec* (*alloc_codec)( pj_codec_factory *factory, const pj_codec_id *id); + + /** This function is called by codec manager to return a particular instance + * of codec back to the codec factory. + * @param factory The codec factory. + * @param codec The codec instance to be returned. + */ + void (*dealloc_codec)( pj_codec_factory *factory, pj_codec *codec ); + +} pj_codec_factory_op; + +/** + * Codec factory describes a module that is able to create codec with specific + * capabilities. These capabilities can be queried by codec manager to create + * instances of codec. + */ +struct pj_codec_factory +{ + /** Entries to put this structure in the codec manager list. */ + PJ_DECL_LIST_MEMBER(struct pj_codec_factory); + + /** The factory's private data. */ + void *factory_data; + + /** Operations to the factory. */ + pj_codec_factory_op *op; + +}; + +/** + * Declare maximum codecs + */ +#define PJ_CODEC_MGR_MAX_CODECS 32 + +/** + * Codec manager maintains codec factory etc. + */ +typedef struct pj_codec_mgr +{ + pj_codec_factory factory_list; + unsigned codec_cnt; + pj_codec_id codecs[PJ_CODEC_MGR_MAX_CODECS]; +} pj_codec_mgr; + +/** + * Init codec manager. + */ +PJ_DECL(pj_status_t) +pj_codec_mgr_init (pj_codec_mgr *mgr); + +/** + * Register codec to codec manager. + */ +PJ_DECL(pj_status_t) +pj_codec_mgr_register_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); + +/** + * Unregister codec. + */ +PJ_DECL(void) +pj_codec_mgr_unregister_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); + +/** + * Enumerate codecs. + */ +PJ_DECL(unsigned) +pj_codec_mgr_enum_codecs (pj_codec_mgr *mgr, unsigned count, const pj_codec_id *codecs[]); + +/** + * Open codec. + */ +PJ_DECL(pj_codec*) +pj_codec_mgr_alloc_codec (pj_codec_mgr *mgr, const struct pj_codec_id *id); + +/** + * Close codec. + */ +PJ_DECL(void) +pj_codec_mgr_dealloc_codec (pj_codec_mgr *mgr, pj_codec *codec); + +/** + * @} + */ + +PJ_END_DECL + + +#endif /* __PJMEDIA_CODEC_H__ */ diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h new file mode 100644 index 00000000..489d5b31 --- /dev/null +++ b/pjmedia/include/pjmedia/config.h @@ -0,0 +1,27 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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 __PJMED_CONFIG_H__ +#define __PJMED_CONFIG_H__ + +/** + * @defgroup PJMEDIA Media Stack + */ + + +#endif /* __PJMED_CONFIG_H__ */ diff --git a/pjmedia/include/pjmedia/jbuf.h b/pjmedia/include/pjmedia/jbuf.h new file mode 100644 index 00000000..8ad89f38 --- /dev/null +++ b/pjmedia/include/pjmedia/jbuf.h @@ -0,0 +1,142 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_JBUF_H__ +#define __PJMEDIA_JBUF_H__ + + +/** + * @file jbuf.h + * @brief Adaptive jitter buffer implementation. + */ +/** + * @defgroup PJMED_JBUF Adaptive jitter buffer + * @ingroup PJMEDIA + * @{ + */ + +#include + + +PJ_BEGIN_DECL + + +/** + * Opaque declaration of internal frame type used by jitter buffer. + */ +struct pj_jbframe; + + +/** + * Miscelaneous operation result/status. + */ +typedef enum jb_op_status +{ + PJ_JB_STATUS_TOO_OLD = -2, /** The packet is too old. */ + PJ_JB_STATUS_TOO_SOON = -3, /** The packet is too soon. */ + PJ_JB_STATUS_FRAME_NULL = -4, /** No packet can be retrieved */ + PJ_JB_STATUS_FRAME_MISSING = -5, /** The specified packet is missing/lost */ +} jb_op_status; + + +/* + * Frame list, container abstraction for ordered list with fixed maximum + * size. It is used internally by the jitter buffer. + */ +typedef struct pj_jbframelist +{ + unsigned head, count, maxcount; + struct pj_jbframe *frames; +} pj_jbframelist; + + +/** + * Jitter buffer implementation. + */ +typedef struct pj_jitter_buffer +{ + pj_jbframelist lst; /** The frame list. */ + int level; /** Current, real-time jitter level. */ + int max_level; /** Maximum level for the period. */ + unsigned prefetch; /** Prefetch count currently used. */ + unsigned get_cnt; /** Number of get operation during prefetch state. */ + unsigned min; /** Minimum jitter size, in packets. */ + unsigned max; /** Maximum jitter size, in packets. */ + pj_uint32_t lastseq; /** Last sequence number put to jitter buffer. */ + unsigned upd_count; /** Internal counter to manage update interval. */ + int state; /** Jitter buffer state (1==operational) */ + int last_op; /** Last jitter buffer operation. */ +} pj_jitter_buffer; + + +/** + * Initialize jitter buffer with the specified parameters. + * This function will allocate internal frame buffer from the specified pool. + * @param jb The jitter buffer to be initialized. + * @param pool Pool where memory will be allocated for the frame buffer. + * @param min The minimum value of jitter buffer, in packets. + * @param max The maximum value of jitter buffer, in packets. + * @param maxcount The maximum number of delay, in packets, which must be + * greater than max. + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pj_jb_init(pj_jitter_buffer *jb, pj_pool_t *pool, + unsigned min, unsigned max, unsigned maxcount); + +/** + * Reset jitter buffer according to the parameters specified when the jitter + * buffer was initialized. Any packets currently in the buffer will be + * discarded. + */ +PJ_DECL(void) pj_jb_reset(pj_jitter_buffer *jb); + +/** + * Put a pointer to the buffer with the specified sequence number. The pointer + * normally points to a buffer held by application, and this pointer will be + * returned later on when pj_jb_get() is called. The jitter buffer will not try + * to interpret the content of this pointer. + * @return: + * - PJ_SUCCESS on success. + * - PJ_JB_STATUS_TOO_OLD when the packet is too old. + * - PJ_JB_STATUS_TOO_SOON when the packet is too soon. + */ +PJ_DECL(pj_status_t) pj_jb_put( pj_jitter_buffer *jb, pj_uint32_t extseq, void *buf ); + +/** + * Get the earliest data from the jitter buffer. ONLY when the operation succeeds, + * the function returns both sequence number and a pointer in the parameters. + * This returned data corresponds to sequence number and pointer that were + * given to jitter buffer in the previous pj_jb_put operation. + * @return + * - PJ_SUCCESS on success + * - PJ_JB_STATUS_FRAME_NULL when there is no frames to be returned. + * - PJ_JB_STATUS_FRAME_MISSING if the jitter buffer detects that the packet + * is lost. Application may run packet concealment algorithm when it + * receives this status. + */ +PJ_DECL(pj_status_t) pj_jb_get( pj_jitter_buffer *jb, pj_uint32_t *extseq, void **buf ); + + + +PJ_END_DECL + +/** + * @} + */ + +#endif /* __PJMEDIA_JBUF_H__ */ diff --git a/pjmedia/include/pjmedia/mediamgr.h b/pjmedia/include/pjmedia/mediamgr.h new file mode 100644 index 00000000..148038ec --- /dev/null +++ b/pjmedia/include/pjmedia/mediamgr.h @@ -0,0 +1,100 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_MEDIAMGR_H__ +#define __PJMEDIA_MEDIAMGR_H__ + + +/** + * @file mediamgr.h + * @brief Media Manager. + */ +/** + * @defgroup PJMED_MGR Media Manager + * @ingroup PJMEDIA + * @{ + * + * The media manager acts as placeholder for endpoint capabilities. Each + * media manager will have a codec manager to manage list of codecs installed + * in the endpoint and a sound device factory. + * + * A reference to media manager instance is required when application wants + * to create a media session (#pj_media_session_create or + * #pj_media_session_create_from_sdp). + */ + +#include +#include + + +PJ_BEGIN_DECL + + +/** Opague declaration of media manager. */ +typedef struct pj_med_mgr_t pj_med_mgr_t; + +/** + * Create an instance of media manager. + * + * @param pf Pool factory. + * @param conn_addr Connection address to be used by this media manager. + * + * @return A new instance of media manager, or NULL if failed. + */ +PJ_DECL(pj_med_mgr_t*) pj_med_mgr_create (pj_pool_factory *pf); + +/** + * Destroy media manager instance. + * + * @param mgr Media manager instance. + * + * @return zero on success. + */ +PJ_DECL(pj_status_t) pj_med_mgr_destroy (pj_med_mgr_t *mgr); + +/** + * Get pool factory of the media manager as specified when the media + * manager was created. + * + * @param mgr The media manager instance. + * + * @return Pool factory instance of the media manager. + */ +PJ_DECL(pj_pool_factory*) pj_med_mgr_get_pool_factory (pj_med_mgr_t *mgr); + +/** + * Get the codec manager instance. + * + * @param mgr The media manager instance. + * + * @return The instance of codec manager. + */ +PJ_DECL(pj_codec_mgr*) pj_med_mgr_get_codec_mgr (pj_med_mgr_t *mgr); + + + +PJ_END_DECL + + +/** + * @} + */ + + + +#endif /* __PJMEDIA_MEDIAMGR_H__ */ diff --git a/pjmedia/include/pjmedia/rtcp.h b/pjmedia/include/pjmedia/rtcp.h new file mode 100644 index 00000000..8a8f8909 --- /dev/null +++ b/pjmedia/include/pjmedia/rtcp.h @@ -0,0 +1,192 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_RTCP_H__ +#define __PJMEDIA_RTCP_H__ + +/** + * @file rtcp.h + * @brief RTCP implementation. + */ + +#include +#include + +PJ_BEGIN_DECL + + +/** + * @defgroup PJMED_RTCP RTCP + * @ingroup PJMEDIA + * @{ + */ + +/** + * RTCP sender report. + */ +struct pj_rtcp_sr +{ + pj_uint32_t ssrc; + pj_uint32_t ntp_sec; + pj_uint32_t ntp_frac; + pj_uint32_t rtp_ts; + pj_uint32_t sender_pcount; + pj_uint32_t sender_bcount; +}; + +typedef struct pj_rtcp_sr pj_rtcp_sr; + +/** + * RTCP receiver report. + */ +struct pj_rtcp_rr +{ + pj_uint32_t ssrc; +#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 + pj_uint32_t fract_lost:8; + pj_uint32_t total_lost_2:8; + pj_uint32_t total_lost_1:8; + pj_uint32_t total_lost_0:8; +#else + pj_uint32_t fract_lost:8; + pj_uint32_t total_lost_0:8; + pj_uint32_t total_lost_1:8; + pj_uint32_t total_lost_2:8; +#endif + pj_uint32_t last_seq; + pj_uint32_t jitter; + pj_uint32_t lsr; + pj_uint32_t dlsr; +}; + +typedef struct pj_rtcp_rr pj_rtcp_rr; + +/** + * RTCP common header. + */ +struct pj_rtcp_common +{ +#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 + unsigned version:2; /* packet type */ + unsigned p:1; /* padding flag */ + unsigned count:5; /* varies by payload type */ + unsigned pt:8; /* payload type */ +#else + unsigned count:5; /* varies by payload type */ + unsigned p:1; /* padding flag */ + unsigned version:2; /* packet type */ + unsigned pt:8; /* payload type */ +#endif + pj_uint16_t length; /* packet length */ +}; + +typedef struct pj_rtcp_common pj_rtcp_common; + +/** + * RTCP packet. + */ +struct pj_rtcp_pkt +{ + pj_rtcp_common common; + pj_rtcp_sr sr; + pj_rtcp_rr rr; /* variable-length list */ +}; + +typedef struct pj_rtcp_pkt pj_rtcp_pkt; + +/** + * NTP time representation. + */ +struct pj_rtcp_ntp_rec +{ + pj_uint32_t hi; + pj_uint32_t lo; +}; + +typedef struct pj_rtcp_ntp_rec pj_rtcp_ntp_rec; + +/** + * RTCP session. + */ +struct pj_rtcp_session +{ + pj_rtcp_pkt rtcp_pkt; + + pj_rtp_seq_session seq_ctrl; + + pj_uint32_t received; /* packets received */ + pj_uint32_t expected_prior; /* packet expected at last interval */ + pj_uint32_t received_prior; /* packet received at last interval */ + pj_int32_t transit; /* relative trans time for prev pkt */ + pj_uint32_t jitter; /* estimated jitter */ + + pj_rtcp_ntp_rec rtcp_lsr; /* NTP timestamp in last sender report received */ + unsigned rtcp_lsr_time; /* Time when last RTCP SR is received. */ + unsigned peer_ssrc; /* Peer SSRC */ + +}; + +typedef struct pj_rtcp_session pj_rtcp_session; + +/** + * Init RTCP session. + * @param session The session + * @param ssrc The SSRC used in to identify the session. + */ +PJ_DECL(void) pj_rtcp_init( pj_rtcp_session *session, pj_uint32_t ssrc ); + +/** + * Deinit RTCP session. + * @param session The session. + */ +PJ_DECL(void) pj_rtcp_fini( pj_rtcp_session *session); + +/** + * Call this function everytime an RTP packet is received to let the RTCP + * session do its internal calculations. + * @param session The session. + * @param seq The RTP packet sequence number, in host byte order. + * @param ts The RTP packet timestamp, in host byte order. + */ +PJ_DECL(void) pj_rtcp_rx_rtp( pj_rtcp_session *session, pj_uint16_t seq, pj_uint32_t ts ); + +/** + * Call this function everytime an RTP packet is sent to let the RTCP session + * do its internal calculations. + * @param session The session. + * @param bytes_payload_size The payload size of the RTP packet (ie packet minus + * RTP header). + */ +PJ_DECL(void) pj_rtcp_tx_rtp( pj_rtcp_session *session, pj_uint16_t bytes_payload_size ); + +/** + * Build a RTCP SR/RR packet to be transmitted to remote RTP peer. + * @param session The session. + * @param rtcp_pkt [output] Upon return, it will contain pointer to the RTCP packet. + * @param len [output] Upon return, it will indicate the size of the RTCP packet. + */ +PJ_DECL(void) pj_rtcp_build_rtcp( pj_rtcp_session *session, pj_rtcp_pkt **rtcp_pkt, int *len ); + +/** + * @} + */ + +PJ_END_DECL + + +#endif /* __PJMEDIA_RTCP_H__ */ diff --git a/pjmedia/include/pjmedia/rtp.h b/pjmedia/include/pjmedia/rtp.h new file mode 100644 index 00000000..54c1e32e --- /dev/null +++ b/pjmedia/include/pjmedia/rtp.h @@ -0,0 +1,256 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_RTP_H__ +#define __PJMEDIA_RTP_H__ + +#include + +/** + * @file rtp.h + * @brief RTP implementation. + */ + +PJ_BEGIN_DECL + + +/** + * @defgroup PJMED_RTP RTP + * @ingroup PJMEDIA + * @{ + * + * The RTP module is designed to be dependent only to PJLIB, it does not depend + * on any other parts of PJMEDIA library. The RTP module does not even depend + * on any transports (sockets), to promote even more use. + * + * An RTCP implementation is also separated from this module. + * + * The functions that are provided by this module: + * - creating RTP header for each outgoing packet. + * - decoding RTP packet into RTP header and payload. + * - provide simple RTP session management (sequence number, etc.) + * + * The RTP module does not use any dynamic memory at all. + * + * \section P1 How to Use the RTP Module + * + * First application must call #pj_rtp_session_init to initialize the RTP + * session. + * + * When application wants to send RTP packet, it needs to call + * #pj_rtp_encode_rtp to build the RTP header. Note that this WILL NOT build + * the complete RTP packet, but instead only the header. Application can + * then either concatenate the header with the payload, or send the two + * fragments (the header and the payload) using scatter-gather transport API + * (e.g. \a sendv()). + * + * When application receives an RTP packet, first it should call + * #pj_rtp_decode_rtp to decode RTP header and payload, then it should call + * #pj_rtp_session_update to check whether we can process the RTP payload, + * and to let the RTP session updates its internal status. The decode function + * is guaranteed to point the payload to the correct position regardless of + * any options present in the RTP packet. + * + */ + + +#ifdef _MSC_VER +# pragma warning ( disable : 4214 ) +#endif + + +/** + * Error codes. + */ +enum pj_rtp_error_t +{ + PJ_RTP_ERR_RTP_PACKING, /**< Invalid RTP packet. */ + PJ_RTP_ERR_INVALID_VERSION, /**< Invalid RTP version. */ + PJ_RTP_ERR_INVALID_SSRC, /**< Invalid SSRC. */ + PJ_RTP_ERR_INVALID_PT, /**< Invalid payload type. */ + PJ_RTP_ERR_INVALID_PACKET, /**< Invalid packet. */ + PJ_RTP_ERR_SESSION_RESTARTED, /**< Session has just been restarted. */ + PJ_RTP_ERR_SESSION_PROBATION, /**< Session in probation. */ + PJ_RTP_ERR_BAD_SEQUENCE, /**< Bad RTP sequence number. */ +}; + +#pragma pack(1) +/** + * RTP packet header. + */ +struct pj_rtp_hdr +{ +#if defined(PJ_IS_BIG_ENDIAN) && (PJ_IS_BIG_ENDIAN!=0) + pj_uint16_t v:2; /**< packet type/version */ + pj_uint16_t p:1; /**< padding flag */ + pj_uint16_t x:1; /**< extension flag */ + pj_uint16_t cc:4; /**< CSRC count */ + pj_uint16_t m:1; /**< marker bit */ + pj_uint16_t pt:7; /**< payload type */ +#else + pj_uint16_t cc:4; /**< CSRC count */ + pj_uint16_t x:1; /**< header extension flag */ + pj_uint16_t p:1; /**< padding flag */ + pj_uint16_t v:2; /**< packet type/version */ + pj_uint16_t pt:7; /**< payload type */ + pj_uint16_t m:1; /**< marker bit */ +#endif + pj_uint16_t seq; /**< sequence number */ + pj_uint32_t ts; /**< timestamp */ + pj_uint32_t ssrc; /**< synchronization source */ +}; +#pragma pack() + +typedef struct pj_rtp_hdr pj_rtp_hdr; + +/** + * RTP extendsion header. + */ +struct pj_rtp_ext_hdr +{ + pj_uint16_t profile_data; + pj_uint16_t length; +}; + +typedef struct pj_rtp_ext_hdr pj_rtp_ext_hdr; + +/** + * A generic sequence number management, used by both RTP and RTCP. + */ +struct pj_rtp_seq_session +{ + pj_uint16_t max_seq; /**< highest sequence number heard */ + pj_uint32_t cycles; /**< shifted count of seq. number cycles */ + pj_uint32_t base_seq; /**< base seq number */ + pj_uint32_t bad_seq; /**< last 'bad' seq number + 1 */ + pj_uint32_t probation; /**< sequ. packets till source is valid */ +}; + +typedef struct pj_rtp_seq_session pj_rtp_seq_session; + +/** + * RTP session descriptor. + */ +struct pj_rtp_session +{ + pj_rtp_hdr out_hdr; /**< Saved header for outgoing packets. */ + pj_rtp_seq_session seq_ctrl; /**< Sequence number management. */ + pj_uint16_t out_pt; /**< Default outgoing payload type. */ + pj_uint32_t out_extseq; /**< Outgoing extended sequence number. */ + pj_uint32_t peer_ssrc; /**< Peer SSRC. */ + pj_uint32_t received; /**< Number of received packets. */ +}; + +typedef struct pj_rtp_session pj_rtp_session; + +/** + * \brief Initialize RTP session. + * This function will initialize the RTP session according to given parameters. + * + * @param ses The session. + * @param default_pt Default payload type. + * @param sender_ssrc SSRC used for outgoing packets. + * + * @return zero if successfull. + */ +PJ_DECL(pj_status_t) pj_rtp_session_init( pj_rtp_session *ses, + int default_pt, pj_uint32_t sender_ssrc ); + +/** + * \brief Encode outgoing RTP packet header. + * Create the RTP header based on arguments and current state of the RTP + * session. + * + * @param ses The session. + * @param pt Payload type. + * @param m Marker flag. + * @param payload_len Payload length in bytes. + * @param ts_len Timestamp length. + * @param rtphdr Upon return will point to RTP packet header. + * @param hdrlen Upon return will indicate the size of RTP packet header + * + * @return zero if successfull. + */ +PJ_DECL(pj_status_t) pj_rtp_encode_rtp( pj_rtp_session *ses, int pt, int m, + int payload_len, int ts_len, + const void **rtphdr, int *hdrlen ); + +/** + * \brief Decode an incoming RTP packet. + * This function will decode incoming packet into RTP header and payload. + * The decode function is guaranteed to point the payload to the correct + * position regardless of any options present in the RTP packet. + * + * @param ses The session. + * @param pkt The received RTP packet. + * @param pkt_len The length of the packet. + * @param hdr Upon return will point to the location of the RTP header + * inside the packet. + * @param payload Upon return will point to the location of the + * payload inside the packet. + * @param payloadlen Upon return will indicate the size of the payload. + * + * @return zero if successfull. + */ +PJ_DECL(pj_status_t) pj_rtp_decode_rtp( pj_rtp_session *ses, + const void *pkt, int pkt_len, + const pj_rtp_hdr **hdr, + const void **payload, + unsigned *payloadlen); + +/** + * \brief Update RTP session with an incoming RTP packet. + * Call this function everytime + * an RTP packet is received to check whether the packet can be received and to + * let the RTP session performs its internal calculations. + * + * @param ses The session. + * @param hdr The RTP header of the incoming packet. + * + * @return zero if the packet is valid and can be processed, otherwise will + * return one of the error in #pj_rtp_error_t. + */ +PJ_DECL(pj_status_t) pj_rtp_session_update( pj_rtp_session *ses, + const pj_rtp_hdr *hdr); + +/** +* \brief Internal. + * Internal function for sequence control, shared by RTCP implementation. + */ +void pj_rtp_seq_init(pj_rtp_seq_session *seq_ctrl, pj_uint16_t seq); + +/** +* \brief Internal. + * Internal function for sequence control, shared by RTCP implementation. + */ +void pj_rtp_seq_restart(pj_rtp_seq_session *seq_ctrl, pj_uint16_t seq); + +/** +* \brief Internal. + * Internal function for sequence control, shared by RTCP implementation. + */ +int pj_rtp_seq_update(pj_rtp_seq_session *seq_ctrl, pj_uint16_t seq); + +/** + * @} + */ + +PJ_END_DECL + + +#endif /* __PJMEDIA_RTP_H__ */ diff --git a/pjmedia/include/pjmedia/sdp.h b/pjmedia/include/pjmedia/sdp.h new file mode 100644 index 00000000..1b45744c --- /dev/null +++ b/pjmedia/include/pjmedia/sdp.h @@ -0,0 +1,332 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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 __PJSDP_SDP_H__ +#define __PJSDP_SDP_H__ + +/** + * @defgroup PJSDP SDP Library + */ +/** + * @file sdp.h + * @brief SDP header file. + */ +/** + * @defgroup PJ_SDP_H SDP stack. + * @ingroup PJSDP + * @{ + * + * This SDP module consists of SDP parser, SDP structure, and function to + * print back the structure as SDP message. + */ + +#include + +PJ_BEGIN_DECL + +#define PJSDP_MAX_FMT 32 +#define PJSDP_MAX_ATTR 32 +#define PJSDP_MAX_MEDIA 16 + +/** + * This enumeration describes the attribute type. + */ +typedef enum pjsdp_attr_type_e +{ + PJSDP_ATTR_RTPMAP, + PJSDP_ATTR_CAT, + PJSDP_ATTR_KEYWORDS, + PJSDP_ATTR_TOOL, + PJSDP_ATTR_PTIME, + PJSDP_ATTR_RECV_ONLY, + PJSDP_ATTR_SEND_ONLY, + PJSDP_ATTR_SEND_RECV, + PJSDP_ATTR_ORIENT, + PJSDP_ATTR_TYPE, + PJSDP_ATTR_CHARSET, + PJSDP_ATTR_SDP_LANG, + PJSDP_ATTR_LANG, + PJSDP_ATTR_FRAME_RATE, + PJSDP_ATTR_QUALITY, + PJSDP_ATTR_FMTP, + PJSDP_ATTR_INACTIVE, + PJSDP_ATTR_GENERIC, + PJSDP_END_OF_ATTR, +} pjsdp_attr_type_e; + + +/** + * This structure keeps the common attributes that all 'descendants' + * will have. + */ +typedef struct pjsdp_attr +{ + pjsdp_attr_type_e type; /**< Attribute type. */ +} pjsdp_attr; + + +/** + * This is the structure to represent generic attribute which has a + * string value. + */ +typedef struct pjsdp_attr_string +{ + pjsdp_attr_type_e type; + pj_str_t value; +} pjsdp_attr_string; + + +/** + * This is the structure to represent generic SDP attribute which has + * a numeric value. + */ +typedef struct pjsdp_attr_num +{ + pjsdp_attr_type_e type; + pj_uint32_t value; +} pjsdp_attr_num; + + +/** + * SDP \a rtpmap attribute. + */ +typedef struct pjsdp_rtpmap_attr +{ + pjsdp_attr_type_e type; + unsigned payload_type; + pj_str_t encoding_name; + unsigned clock_rate; + pj_str_t parameter; +} pjsdp_rtpmap_attr; + + +/** + * SDP \a fmtp attribute. + */ +typedef struct pjsdp_fmtp_attr +{ + pjsdp_attr_type_e type; + pj_str_t format; + pj_str_t param; +} pjsdp_fmtp_attr; + + +/** + * SDP generic attribute. + */ +typedef struct pjsdp_generic_attr +{ + pjsdp_attr_type_e type; + pj_str_t name; + pj_str_t value; +} pjsdp_generic_attr; + + +/** SDP \a cat attribute. */ +typedef struct pjsdp_attr_string pjsdp_cat_attr; + +/** SDP \a keywds attribute. */ +typedef struct pjsdp_attr_string pjsdp_keywds_attr; + +/** SDP \a tool attribute. */ +typedef struct pjsdp_attr_string pjsdp_tool_attr; + +/** SDP \a ptime attribute. */ +typedef struct pjsdp_attr_num pjsdp_ptime_attr; + +/** SDP \a recvonly attribute. */ +typedef struct pjsdp_attr pjsdp_recv_only_attr; + +/** SDP \a sendonly attribute. */ +typedef struct pjsdp_attr pjsdp_send_only_attr; + +/** SDP \a sendrecv attribute. */ +typedef struct pjsdp_attr pjsdp_send_recv_attr; + +/** SDP \a orient attribute. */ +typedef struct pjsdp_attr_string pjsdp_orient_attr; + +/** SDP \a type attribute. */ +typedef struct pjsdp_attr_string pjsdp_type_attr; + +/** SDP \a charset attribute. */ +typedef struct pjsdp_attr_string pjsdp_charset_attr; + +/** SDP \a sdplang attribute. */ +typedef struct pjsdp_attr_string pjsdp_sdp_lang_attr; + +/** SDP \a lang attribute. */ +typedef struct pjsdp_attr_string pjsdp_lang_attr; + +/** SDP \a framerate attribute. */ +typedef struct pjsdp_attr_string pjsdp_frame_rate_attr; + +/** SDP \a quality attribute. */ +typedef struct pjsdp_attr_num pjsdp_quality_attr; + +/** SDP \a inactive attribute. */ +typedef struct pjsdp_attr pjsdp_inactive_attr; + +/** Clone attribute */ +PJ_DECL(pjsdp_attr*) pjsdp_attr_clone (pj_pool_t *pool, const pjsdp_attr *rhs); + +/** Find attribute */ +PJ_DECL(const pjsdp_attr*) pjsdp_attr_find (int count, const pjsdp_attr *attr_array[], int type); + +/** + * SDP connection info. + */ +typedef struct pjsdp_conn_info +{ + pj_str_t net_type; + pj_str_t addr_type; + pj_str_t addr; +} pjsdp_conn_info; + +/** + *Clone connection info. + * + * @param pool Pool to allocate memory for the new connection info. + * @param rhs The connection into to clone. + * + * @return the new connection info. + */ +PJ_DECL(pjsdp_conn_info*) pjsdp_conn_info_clone (pj_pool_t *pool, + const pjsdp_conn_info *rhs); + +/** + * SDP media description. + */ +typedef struct pjsdp_media_desc +{ + struct + { + pj_str_t media; + pj_uint16_t port; + unsigned port_count; + pj_str_t transport; + unsigned fmt_count; + pj_str_t fmt[PJSDP_MAX_FMT]; + } desc; + + pjsdp_conn_info *conn; + unsigned attr_count; + pjsdp_attr *attr[PJSDP_MAX_ATTR]; + +} pjsdp_media_desc; + +/** + * Clone SDP media description. + * + * @param pool Pool to allocate memory for the new media description. + * @param rhs The media descriptin to clone. + * + * @return a new media description. + */ +PJ_DECL(pjsdp_media_desc*) pjsdp_media_desc_clone (pj_pool_t *pool, + const pjsdp_media_desc *rhs); + +/** + * Check if the media description has the specified attribute. + * + * @param m The SDP media description. + * @param attr_type The attribute type. + * + * @return nonzero if true. + */ +PJ_DECL(pj_bool_t) pjsdp_media_desc_has_attr (const pjsdp_media_desc *m, + pjsdp_attr_type_e attr_type); + +/** + * Find rtpmap attribute for the specified payload type. + * + * @param m The SDP media description. + * @param pt RTP payload type. + * + * @return the SDP rtpmap attribute for the payload type, or NULL if not found. + */ +PJ_DECL(const pjsdp_rtpmap_attr*) +pjsdp_media_desc_find_rtpmap (const pjsdp_media_desc *m, unsigned pt); + + +/** + * This structure describes SDP session description. + */ +typedef struct pjsdp_session_desc +{ + struct + { + pj_str_t user; + pj_uint32_t id; + pj_uint32_t version; + pj_str_t net_type; + pj_str_t addr_type; + pj_str_t addr; + } origin; + + pj_str_t name; + pjsdp_conn_info *conn; + + struct + { + pj_uint32_t start; + pj_uint32_t stop; + } time; + + unsigned attr_count; + pjsdp_attr *attr[PJSDP_MAX_ATTR]; + + unsigned media_count; + pjsdp_media_desc *media[PJSDP_MAX_MEDIA]; + +} pjsdp_session_desc; + + +/** + * Parse SDP message. + * + * @param buf The message buffer. + * @param len The length of the message. + * @param pool The pool to allocate SDP session description. + * + * @return SDP session description. + */ +PJ_DECL(pjsdp_session_desc*) pjsdp_parse( char *buf, pj_size_t len, + pj_pool_t *pool); + +/** + * Print SDP description to a buffer. + * + * @param buf The buffer. + * @param size The buffer length. + * @param desc The SDP session description. + * + * @return the length printed, or -1. + */ +PJ_DECL(int) pjsdp_print( const pjsdp_session_desc *desc, + char *buf, pj_size_t size); + + +/** + * @} + */ + +PJ_END_DECL + +#endif /* __PJSDP_SDP_H__ */ + diff --git a/pjmedia/include/pjmedia/session.h b/pjmedia/include/pjmedia/session.h new file mode 100644 index 00000000..d9efeb81 --- /dev/null +++ b/pjmedia/include/pjmedia/session.h @@ -0,0 +1,152 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_SESSION_H__ +#define __PJMEDIA_SESSION_H__ + + +/** + * @file session.h + * @brief Media Session. + */ + +#include +#include +#include +#include + +PJ_BEGIN_DECL + +/** + * @defgroup PJMED_SES Media session + * @ingroup PJMEDIA + * @{ + */ + +/** Opaque declaration of media session. */ +typedef struct pj_media_session_t pj_media_session_t; + +/** Media socket info. */ +typedef struct pj_media_sock_info +{ + pj_sock_t rtp_sock, rtcp_sock; + pj_sockaddr_in rtp_addr_name; +} pj_media_sock_info; + +/** Stream info. */ +typedef struct pj_media_stream_info +{ + pj_str_t type; + pj_media_dir_t dir; + pj_str_t transport; + pj_media_sock_info sock_info; + pj_str_t rem_addr; + unsigned short rem_port; + unsigned fmt_cnt; + pj_codec_id fmt[PJSDP_MAX_FMT]; + +} pj_media_stream_info; + +/** Flag for modifying stream. */ +enum +{ + PJ_MEDIA_STREAM_MODIFY_DIR = 1, +}; + +/** + * Create new session offering. + */ +PJ_DECL(pj_media_session_t*) +pj_media_session_create ( pj_med_mgr_t *mgr, const pj_media_sock_info *skinfo ); + +/** + * Create new session based on peer's offering. + */ +PJ_DECL(pj_media_session_t*) +pj_media_session_create_from_sdp ( pj_med_mgr_t *mgr, const pjsdp_session_desc *sdp, + const pj_media_sock_info *skinfo); + +/** + * Duplicate session. The new session is inactive. + */ +PJ_DECL(pj_media_session_t*) +pj_media_session_clone (const pj_media_session_t *session); + +/** + * Create SDP description from the session. + */ +PJ_DECL(pjsdp_session_desc*) +pj_media_session_create_sdp ( const pj_media_session_t *session, pj_pool_t *pool, + pj_bool_t only_first_fmt); + +/** + * Update session with SDP answer from peer. The session must NOT active. + */ +PJ_DECL(pj_status_t) +pj_media_session_update ( pj_media_session_t *session, + const pjsdp_session_desc *sdp); + +/** + * Enumerate media streams in the session. + * @return the actual number of streams. + */ +PJ_DECL(unsigned) +pj_media_session_enum_streams (const pj_media_session_t *session, + unsigned count, const pj_media_stream_info *info[]); + +/** + * Get stream statistics. + */ +PJ_DECL(pj_status_t) +pj_media_session_get_stat (const pj_media_session_t *session, unsigned index, + pj_media_stream_stat *tx_stat, + pj_media_stream_stat *rx_stat); + +/** + * Modify stream, only when stream is inactive. + */ +PJ_DECL(pj_status_t) +pj_media_session_modify_stream (pj_media_session_t *session, unsigned index, + unsigned modify_flag, const pj_media_stream_info *info); + +/** + * Activate all streams in media session. + */ +PJ_DECL(pj_status_t) +pj_media_session_activate (pj_media_session_t *session); + +/** + * Activate individual stream in media session. + */ +PJ_DECL(pj_status_t) +pj_media_session_activate_stream (pj_media_session_t *session, unsigned index); + +/** + * Destroy media session. + */ +PJ_DECL(pj_status_t) +pj_media_session_destroy (pj_media_session_t *session); + + +/** + * @} + */ + +PJ_END_DECL + +#endif /* __PJMEDIA_SESSION_H__ */ diff --git a/pjmedia/include/pjmedia/sound.h b/pjmedia/include/pjmedia/sound.h new file mode 100644 index 00000000..3fa40db6 --- /dev/null +++ b/pjmedia/include/pjmedia/sound.h @@ -0,0 +1,201 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_SOUND_H__ +#define __PJMEDIA_SOUND_H__ + + +/** + * @file sound.h + * @brief Sound player and recorder device framework. + */ + +#include + +PJ_BEGIN_DECL + +/** + * @defgroup PJMED_SND Sound device abstraction. + * @ingroup PJMEDIA + * @{ + */ + +/** Opaque data type for audio stream. */ +typedef struct pj_snd_stream pj_snd_stream; + +/** + * Device information structure returned by #pj_snd_get_dev_info. + */ +typedef struct pj_snd_dev_info +{ + char name[64]; /**< Device name. */ + unsigned input_count; /**< Max number of input channels. */ + unsigned output_count; /**< Max number of output channels. */ + unsigned default_samples_per_sec;/**< Default sampling rate. */ +} pj_snd_dev_info; + +/** + * Sound device parameter, to be specified when calling #pj_snd_open_recorder + * or #pj_snd_open_player. + */ +typedef struct pj_snd_stream_info +{ + unsigned samples_per_sec; /* Sampling rate. */ + unsigned bits_per_sample; /* No of bits per sample. */ + unsigned samples_per_frame; /* No of samples per frame. */ + unsigned bytes_per_frame; /* No of bytes per frame. */ + unsigned frames_per_packet; /* No of frames per packet. */ +} pj_snd_stream_info; + +/** + * This callback is called by player stream when it needs additional data + * to be played by the device. Application must fill in the whole of output + * buffer with sound samples. + * + * @param user_data User data associated with the stream. + * @param timestamp Timestamp, in samples. + * @param output Buffer to be filled out by application. + * @param size The size requested in bytes, which will be equal to + * the size of one whole packet. + * + * @return Non-zero to stop the stream. + */ +typedef pj_status_t (*pj_snd_play_cb)(/* in */ void *user_data, + /* in */ pj_uint32_t timestamp, + /* out */ void *output, + /* out */ unsigned size); + +/** + * This callback is called by recorder stream when it has captured the whole + * packet worth of audio samples. + * + * @param user_data User data associated with the stream. + * @param timestamp Timestamp, in samples. + * @param output Buffer containing the captured audio samples. + * @param size The size of the data in the buffer, in bytes. + * + * @return Non-zero to stop the stream. + */ +typedef pj_status_t (*pj_snd_rec_cb)(/* in */ void *user_data, + /* in */ pj_uint32_t timestamp, + /* in */ const void *input, + /* in*/ unsigned size); + +/** + * Init the sound library. + * + * @param factory The sound factory. + * + * @return Zero on success. + */ +PJ_DECL(pj_status_t) pj_snd_init(pj_pool_factory *factory); + + +/** + * Get the number of devices detected by the library. + * + * @return Number of devices. + */ +PJ_DECL(int) pj_snd_get_dev_count(void); + + +/** + * Get device info. + * + * @param index The index of the device, which should be in the range + * from zero to #pj_snd_get_dev_count - 1. + */ +PJ_DECL(const pj_snd_dev_info*) pj_snd_get_dev_info(unsigned index); + + +/** + * Create a new audio stream for audio capture purpose. + * + * @param index Device index, or -1 to let the library choose the first + * available device, or -2 to use NULL device. + * @param param Stream parameters. + * @param rec_cb Callback to handle captured audio samples. + * @param user_data User data to be associated with the stream. + * + * @return Audio stream, or NULL if failed. + */ +PJ_DECL(pj_snd_stream*) pj_snd_open_recorder(int index, + const pj_snd_stream_info *param, + pj_snd_rec_cb rec_cb, + void *user_data); + +/** + * Create a new audio stream for playing audio samples. + * + * @param index Device index, or -1 to let the library choose the first + * available device, or -2 to use NULL device. + * @param param Stream parameters. + * @param play_cb Callback to supply audio samples. + * @param user_data User data to be associated with the stream. + * + * @return Audio stream, or NULL if failed. + */ +PJ_DECL(pj_snd_stream*) pj_snd_open_player(int index, + const pj_snd_stream_info *param, + pj_snd_play_cb play_cb, + void *user_data); + +/** + * Start the stream. + * + * @param stream The recorder or player stream. + * + * @return Zero on success. + */ +PJ_DECL(pj_status_t) pj_snd_stream_start(pj_snd_stream *stream); + +/** + * Stop the stream. + * + * @param stream The recorder or player stream. + * + * @return Zero on success. + */ +PJ_DECL(pj_status_t) pj_snd_stream_stop(pj_snd_stream *stream); + +/** + * Destroy the stream. + * + * @param stream The recorder of player stream. + * + * @return Zero on success. + */ +PJ_DECL(pj_status_t) pj_snd_stream_close(pj_snd_stream *stream); + +/** + * Deinitialize sound library. + * + * @return Zero on success. + */ +PJ_DECL(pj_status_t) pj_snd_deinit(void); + + + +/** + * @} + */ + +PJ_END_DECL + + +#endif /* __PJMEDIA_SOUND_H__ */ diff --git a/pjmedia/include/pjmedia/stream.h b/pjmedia/include/pjmedia/stream.h new file mode 100644 index 00000000..09f6acf1 --- /dev/null +++ b/pjmedia/include/pjmedia/stream.h @@ -0,0 +1,99 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono + * + * 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_STREAM_H__ +#define __PJMEDIA_STREAM_H__ + + +/** + * @file stream.h + * @brief Stream of media. + */ + +#include +#include +#include +#include + +PJ_BEGIN_DECL + + +/** + * @defgroup PJMED_SES Media session + * @ingroup PJMEDIA + * @{ + */ + +typedef struct pj_media_stream_t pj_media_stream_t; + +/** Parameter for creating channel. */ +typedef struct pj_media_stream_create_param +{ + /** Codec ID, must NOT be NULL. */ + pj_codec_id *codec_id; + + /** Media manager, must NOT be NULL. */ + pj_med_mgr_t *mediamgr; + + /** Direction: IN_OUT, or IN only, or OUT only. */ + pj_media_dir_t dir; + + /** RTP socket. */ + pj_sock_t rtp_sock; + + /** RTCP socket. */ + pj_sock_t rtcp_sock; + + /** Address of remote */ + pj_sockaddr_in *remote_addr; + + /** RTP SSRC */ + pj_uint32_t ssrc; + + /** Jitter buffer parameters. */ + int jb_min, jb_max, jb_maxcnt; + +} pj_media_stream_create_param; + +typedef struct pj_media_stream_stat +{ + pj_uint32_t pkt_tx, pkt_rx; /* packets transmitted/received */ + pj_uint32_t oct_tx, oct_rx; /* octets transmitted/received */ + pj_uint32_t jitter; /* receive jitter in ms */ + pj_uint32_t pkt_lost; /* total packet lost count */ +} pj_media_stream_stat; + +PJ_DECL(pj_status_t) pj_media_stream_create (pj_pool_t *pool, + pj_media_stream_t **enc_stream, + pj_media_stream_t **dec_stream, + pj_media_stream_create_param *param); +PJ_DECL(pj_status_t) pj_media_stream_start (pj_media_stream_t *stream); +PJ_DECL(pj_status_t) pj_media_stream_get_stat (const pj_media_stream_t *stream, + pj_media_stream_stat *stat); +PJ_DECL(pj_status_t) pj_media_stream_pause (pj_media_stream_t *stream); +PJ_DECL(pj_status_t) pj_media_stream_resume (pj_media_stream_t *stream); +PJ_DECL(pj_status_t) pj_media_stream_destroy (pj_media_stream_t *stream); + +/** + * @} + */ + +PJ_END_DECL + + +#endif /* __PJMEDIA_STREAM_H__ */ -- cgit v1.2.3