From 66f9158fa3c12ebd3b2d317cf42e461e0b86a6aa Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 8 Feb 2006 22:43:39 +0000 Subject: Finished new pjmedia rewrite git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@159 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/codec.h | 504 +++++++++++++++++++++---------------- pjmedia/include/pjmedia/endpoint.h | 131 ++++++++++ pjmedia/include/pjmedia/errno.h | 36 +++ pjmedia/include/pjmedia/mediamgr.h | 100 -------- pjmedia/include/pjmedia/rtp.h | 16 +- pjmedia/include/pjmedia/session.h | 180 +++++++------ pjmedia/include/pjmedia/stream.h | 147 ++++++++--- pjmedia/include/pjmedia/types.h | 142 +++++++++++ 8 files changed, 823 insertions(+), 433 deletions(-) create mode 100644 pjmedia/include/pjmedia/endpoint.h delete mode 100644 pjmedia/include/pjmedia/mediamgr.h (limited to 'pjmedia/include') diff --git a/pjmedia/include/pjmedia/codec.h b/pjmedia/include/pjmedia/codec.h index 3069f31c..75135d62 100644 --- a/pjmedia/include/pjmedia/codec.h +++ b/pjmedia/include/pjmedia/codec.h @@ -25,6 +25,7 @@ * @brief Codec framework. */ +#include #include PJ_BEGIN_DECL @@ -36,312 +37,393 @@ PJ_BEGIN_DECL * @{ */ -/** 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. +/** + * Standard RTP static payload types, as defined by RFC 3551. */ -typedef struct pj_codec_id +enum pjmedia_rtp_pt { - /** Media type. */ - pj_media_type type; + PJMEDIA_RTP_PT_PCMU = 0, /* audio PCMU */ + PJMEDIA_RTP_PT_GSM = 3, /* audio GSM */ + PJMEDIA_RTP_PT_G723 = 4, /* audio G723 */ + PJMEDIA_RTP_PT_DVI4_8K = 5, /* audio DVI4 8KHz */ + PJMEDIA_RTP_PT_DVI4_16K = 6, /* audio DVI4 16Khz */ + PJMEDIA_RTP_PT_LPC = 7, /* audio LPC */ + PJMEDIA_RTP_PT_PCMA = 8, /* audio PCMA */ + PJMEDIA_RTP_PT_G722 = 9, /* audio G722 */ + PJMEDIA_RTP_PT_L16_2 = 10, /* audio 16bit linear 44.1KHz stereo */ + PJMEDIA_RTP_PT_L16_1 = 11, /* audio 16bit linear 44.1KHz mono */ + PJMEDIA_RTP_PT_QCELP = 12, /* audio QCELP */ + PJMEDIA_RTP_PT_CN = 13, /* audio Comfort Noise */ + PJMEDIA_RTP_PT_MPA = 14, /* audio MPEG1/MPEG2 elementary streams */ + PJMEDIA_RTP_PT_G728 = 15, /* audio G728 */ + PJMEDIA_RTP_PT_DVI4_11K = 16, /* audio DVI4 11.025KHz mono */ + PJMEDIA_RTP_PT_DVI4_22K = 17, /* audio DVI4 22.050KHz mono */ + PJMEDIA_RTP_PT_G729 = 18, /* audio G729 */ + + PJMEDIA_RTP_PT_CELB = 25, /* video/comb Cell-B by Sun (RFC 2029) */ + PJMEDIA_RTP_PT_JPEG = 26, /* video JPEG */ + PJMEDIA_RTP_PT_NV = 28, /* video NV by nv program by Xerox */ + PJMEDIA_RTP_PT_H261 = 31, /* video H261 */ + PJMEDIA_RTP_PT_MPV = 32, /* video MPEG1 or MPEG2 elementary */ + PJMEDIA_RTP_PT_MP2T = 33, /* video MPEG2 transport */ + PJMEDIA_RTP_PT_H263 = 34, /* video H263 */ + + PJMEDIA_RTP_PT_DYNAMIC = 96, /* start of dynamic RTP payload */ - /** 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. +/** + * Identification used to search for codec factory that supports specific + * codec specification. */ -typedef struct pj_codec_attr +struct pjmedia_codec_info { - 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; + pjmedia_type type; /**< Media type. */ + unsigned pt; /**< Payload type (can be dynamic). */ + pj_str_t encoding_name; /**< Encoding name. */ + unsigned sample_rate; /**< Sampling rate. */ +}; -} pj_codec_attr; -/** Types of audio frame. */ -typedef enum pj_audio_frame_type +/** + * Detailed codec attributes used both to configure a codec and to query + * the capability of codec factories. + */ +struct pjmedia_codec_param { - /** The frame is a silence audio frame. */ - PJ_AUDIO_FRAME_SILENCE, + pj_uint32_t sample_rate; /**< Sampling rate in Hz */ + pj_uint32_t avg_bps; /**< Average bandwidth in bits/sec */ - /** The frame is a non-silence audio frame. */ - PJ_AUDIO_FRAME_AUDIO, + pj_uint8_t pcm_bits_per_sample;/**< Bits/sample in the PCM side */ + pj_uint16_t ptime; /**< Packet time in miliseconds */ -} pj_audio_frame_type; + 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; /**< Reserved, must be NULL. */ -typedef struct pj_codec pj_codec; -typedef struct pj_codec_factory pj_codec_factory; +}; -/** This structure describes an audio frame. */ -struct pj_audio_frame +/** + * Types of media frame. + */ +enum pjmedia_frame_type { - /** Type: silence or non-silence. */ - pj_audio_frame_type type; + PJMEDIA_FRAME_TYPE_SILENCE_AUDIO, /**< Silence audio frame. */ + PJMEDIA_FRAME_TYPE_AUDIO, /**< Normal audio frame. */ - /** Pointer to buffer. */ - void *buf; +}; - /** Frame size in bytes. */ - unsigned size; +/** + * 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. */ }; /** - * Operations that must be supported by the codec. + * This structure describes codec operations. Each codec MUST implement + * all of these functions. */ -typedef struct pj_codec_op +struct pjmedia_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. + /** + * Get default attributes for this codec. + * + * @param codec The codec instance. + * @param attr Pointer to receive default codec attributes. + * + * @return PJ_SUCCESS on success. */ - pj_status_t (*init)( pj_codec *codec, pj_pool_t *pool ); - - /** Close and shutdown codec. + pj_status_t (*default_attr)(pjmedia_codec *codec, + pjmedia_codec_param *attr); + + /** + * Initialize codec using the specified attribute. + * + * @param codec The codec instance. + * @param pool Pool to use when the codec needs to allocate + * some memory. + * + * @return PJ_SUCCESS on success. */ - pj_status_t (*open)( pj_codec *codec, pj_codec_attr *attr ); - - /** Close and shutdown codec. + pj_status_t (*init)(pjmedia_codec *codec, + pj_pool_t *pool ); + + /** + * Open the codec and initialize with the specified parameter.. + * + * @param codec The codec instance. + * @param param Codec initialization parameter. + * + * @return PJ_SUCCESS on success. */ - pj_status_t (*close)( pj_codec *codec ); - - /** Encode frame. + pj_status_t (*open)(pjmedia_codec *codec, + pjmedia_codec_param *param ); + + /** + * Close and shutdown codec, releasing all resources allocated by + * this codec, if any. + * + * @param codec The codec instance. + * + * @return PJ_SUCCESS on success. */ - 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 (*close)(pjmedia_codec *codec); + + + /** + * Instruct the codec to encode the specified input frame. + * + * @param codec The codec instance. + * @param input The input frame. + * @param out_size The length of buffer in the output frame. + * @param output The output frame. + * + * @return PJ_SUCCESS on success; */ - pj_status_t (*decode)( pj_codec *codec, const struct pj_audio_frame *input, - unsigned output_buf_len, struct pj_audio_frame *output); + pj_status_t (*encode)(pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned out_size, + struct pjmedia_frame *output); + + /** + * Instruct the codec to decode the specified input frame. + * + * @param codec The codec instance. + * @param input The input frame. + * @param out_size The length of buffer in the output frame. + * @param output The output frame. + * + * @return PJ_SUCCESS on success; + */ + pj_status_t (*decode)(pjmedia_codec *codec, + const struct pjmedia_frame *input, + unsigned out_size, + struct pjmedia_frame *output); + +}; -} pj_codec_op; /** - * A codec describes an instance to encode or decode media frames. + * This structure describes a codec instance. */ -struct pj_codec +struct pjmedia_codec { /** Entries to put this codec instance in codec factory's list. */ - PJ_DECL_LIST_MEMBER(struct pj_codec); + PJ_DECL_LIST_MEMBER(struct pjmedia_codec); /** Codec's private data. */ void *codec_data; /** Codec factory where this codec was allocated. */ - pj_codec_factory *factory; + pjmedia_codec_factory *factory; /** Operations to codec. */ - pj_codec_op *op; + pjmedia_codec_op *op; }; + /** - * This structure describes operations that must be supported by codec factories. + * This structure describes operations that must be supported by codec + * factories. */ -typedef struct pj_codec_factory_op +struct pjmedia_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. + /** + * Check whether the factory can create codec with the specified + * codec info. + * + * @param factory The codec factory. + * @param info The codec info. + * + * @return PJ_SUCCESS if this factory is able to create an + * instance of codec with the specified info. */ - 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 (*test_alloc)(pjmedia_codec_factory *factory, + const pjmedia_codec_info *info ); + + /** + * 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 info The codec info. + * @param attr The attribute to be initialized. + * + * @return PJ_SUCCESS 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. + pj_status_t (*default_attr)(pjmedia_codec_factory *factory, + const pjmedia_codec_info *info, + pjmedia_codec_param *attr ); + + /** + * Enumerate supported codecs that can be created using this factory. + * + * @param factory The codec factory. + * @param count On input, specifies the number of elements in + * the array. On output, the value will be set to + * the number of elements that have been initialized + * by this function. + * @param info The codec info array, which contents will be + * initialized upon return. + * + * @return PJ_SUCCESS on success. */ - 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_status_t (*enum_info)(pjmedia_codec_factory *factory, + unsigned *count, + pjmedia_codec_info codecs[]); + + /** + * Create one instance of the codec with the specified codec info. + * + * @param factory The codec factory. + * @param info The codec info. + * @param p_codec Pointer to receive the codec instance. + * + * @return PJ_SUCCESS on success. */ - 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. + pj_status_t (*alloc_codec)(pjmedia_codec_factory *factory, + const pjmedia_codec_info *info, + pjmedia_codec **p_codec); + + /** + * 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. + * + * @return PJ_SUCCESS on success. */ - void (*dealloc_codec)( pj_codec_factory *factory, pj_codec *codec ); + pj_status_t (*dealloc_codec)(pjmedia_codec_factory *factory, + pjmedia_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 +struct pjmedia_codec_factory { /** Entries to put this structure in the codec manager list. */ - PJ_DECL_LIST_MEMBER(struct pj_codec_factory); + PJ_DECL_LIST_MEMBER(struct pjmedia_codec_factory); /** The factory's private data. */ - void *factory_data; + void *factory_data; /** Operations to the factory. */ - pj_codec_factory_op *op; + pjmedia_codec_factory_op *op; }; /** * Declare maximum codecs */ -#define PJ_CODEC_MGR_MAX_CODECS 32 +#define PJMEDIA_CODEC_MGR_MAX_CODECS 32 /** * Codec manager maintains codec factory etc. */ -typedef struct pj_codec_mgr +typedef struct pjmedia_codec_mgr { - pj_codec_factory factory_list; - unsigned codec_cnt; - pj_codec_id codecs[PJ_CODEC_MGR_MAX_CODECS]; -} pj_codec_mgr; + pjmedia_codec_factory factory_list; + unsigned codec_cnt; + pjmedia_codec_info codecs[PJMEDIA_CODEC_MGR_MAX_CODECS]; +} pjmedia_codec_mgr; + + /** - * Init codec manager. + * Initialize codec manager. + * + * @param mgr Codec manager instance. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) -pj_codec_mgr_init (pj_codec_mgr *mgr); +PJ_DECL(pj_status_t) pjmedia_codec_mgr_init(pjmedia_codec_mgr *mgr); + /** - * Register codec to codec manager. + * Register codec factory to codec manager. + * + * @param mgr The codec manager. + * @param factory The codec factory to be registered. + * + * @return PJ_SUCCESS on success. */ PJ_DECL(pj_status_t) -pj_codec_mgr_register_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); +pjmedia_codec_mgr_register_factory( pjmedia_codec_mgr *mgr, + pjmedia_codec_factory *factory); /** - * Unregister codec. + * Unregister codec factory from the codec manager. + * + * @param mgr The codec manager. + * @param factory The codec factory to be unregistered. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(void) -pj_codec_mgr_unregister_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); +PJ_DECL(pj_status_t) +pjmedia_codec_mgr_unregister_factory( pjmedia_codec_mgr *mgr, + pjmedia_codec_factory *factory); /** - * Enumerate codecs. + * Enumerate all supported codec. + * + * @param mgr The codec manager. + * @param count On input, specifies the number of elements in + * the array. On output, the value will be set to + * the number of elements that have been initialized + * by this function. + * @param info The codec info array, which contents will be + * initialized upon return. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(unsigned) -pj_codec_mgr_enum_codecs (pj_codec_mgr *mgr, unsigned count, const pj_codec_id *codecs[]); +PJ_DECL(pj_status_t) pjmedia_codec_mgr_enum_codecs( pjmedia_codec_mgr *mgr, + unsigned *count, + pjmedia_codec_info info[]); /** - * Open codec. + * Request the codec manager to allocate one instance of codec with the + * specified codec info. The codec will enumerate all codec factories + * until it finds factory that is able to create the specified codec. + * + * @param mgr The codec manager. + * @param info The information about the codec to be created. + * @param p_codec Pointer to receive the codec instance. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_codec*) -pj_codec_mgr_alloc_codec (pj_codec_mgr *mgr, const struct pj_codec_id *id); +PJ_DECL(pj_status_t) pjmedia_codec_mgr_alloc_codec(pjmedia_codec_mgr *mgr, + const pjmedia_codec_info *info, + pjmedia_codec **p_codec); /** - * Close codec. + * Deallocate the specified codec instance. The codec manager will return + * the instance of the codec back to its factory. + * + * @param mgr The codec manager. + * @param codec The codec instance. + * + * @return PJ_SUCESS on success. */ -PJ_DECL(void) -pj_codec_mgr_dealloc_codec (pj_codec_mgr *mgr, pj_codec *codec); +PJ_DECL(pj_status_t) pjmedia_codec_mgr_dealloc_codec(pjmedia_codec_mgr *mgr, + pjmedia_codec *codec); /** * @} diff --git a/pjmedia/include/pjmedia/endpoint.h b/pjmedia/include/pjmedia/endpoint.h new file mode 100644 index 00000000..27e8f4bf --- /dev/null +++ b/pjmedia/include/pjmedia/endpoint.h @@ -0,0 +1,131 @@ +/* $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_ENDPT Media Endpoint + * @ingroup PJMEDIA + * @{ + * + * The media endpoint acts as placeholder for endpoint capabilities. Each + * media endpoint will have a codec manager to manage list of codecs installed + * in the endpoint and a sound device factory. + * + * A reference to media endpoint 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 + + + +/** + * Create an instance of media endpoint. + * + * @param pf Pool factory, which will be used by the media endpoint + * throughout its lifetime. + * @param p_endpt Pointer to receive the endpoint instance. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_endpt_create( pj_pool_factory *pf, + pjmedia_endpt **p_endpt); + +/** + * Destroy media endpoint instance. + * + * @param endpt Media endpoint instance. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_endpt_destroy(pjmedia_endpt *endpt); + + +/** + * Request the media endpoint to create pool. + * + * @param endpt The media endpoint instance. + * @param name Name to be assigned to the pool. + * @param initial Initial pool size, in bytes. + * @param increment Increment size, in bytes. + * + * @return Memory pool. + */ +PJ_DECL(pj_pool_t*) pjmedia_endpt_create_pool( pjmedia_endpt *endpt, + const char *name, + pj_size_t initial, + pj_size_t increment); + +/** + * Get the codec manager instance of the media endpoint. + * + * @param endpt The media endpoint instance. + * + * @return The instance of codec manager belonging to + * this media endpoint. + */ +PJ_DECL(pjmedia_codec_mgr*) pjmedia_endpt_get_codec_mgr(pjmedia_endpt *mgr); + + +/** + * Create a SDP session description that describes the endpoint + * capability. + * + * @param endpt The media endpoint. + * @param pool Pool to use to create the SDP descriptor. + * @param stream_cnt Number of elements in the sock_info array. This + * also denotes the maximum number of streams (i.e. + * the "m=" lines) that will be created in the SDP. + * @param sock_info Array of socket transport information. One + * transport is needed for each media stream, and + * each transport consists of an RTP and RTCP socket + * pair. + * @param p_sdp Pointer to receive SDP session descriptor. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_endpt_create_sdp( pjmedia_endpt *endpt, + pj_pool_t *pool, + unsigned stream_cnt, + const pjmedia_sock_info sock_info[], + pjmedia_sdp_session **p_sdp ); + + + +PJ_END_DECL + + +/** + * @} + */ + + + +#endif /* __PJMEDIA_MEDIAMGR_H__ */ diff --git a/pjmedia/include/pjmedia/errno.h b/pjmedia/include/pjmedia/errno.h index 14da37de..8d1f6e14 100644 --- a/pjmedia/include/pjmedia/errno.h +++ b/pjmedia/include/pjmedia/errno.h @@ -259,6 +259,42 @@ PJ_DECL(pj_str_t) pjmedia_strerror( pj_status_t status, char *buffer, #define PJMEDIA_SDP_ETIMENOTEQUAL (PJMEDIA_ERRNO_START+72) /* 220072 */ +/************************************************************ + * CODEC + ***********************************************************/ +/** + * @hideinitializer + * Unsupported codec. + */ +#define PJMEDIA_CODEC_EUNSUP (PJMEDIA_ERRNO_START+80) /* 220080 */ + + +/************************************************************ + * MEDIA + ***********************************************************/ +/** + * @hideinitializer + * Invalid remote IP address (in SDP). + */ +#define PJMEDIA_EINVALIDIP (PJMEDIA_ERRNO_START+100) /* 220100 */ +/** + * @hideinitializer + * Asymetric codec is not supported. + */ +#define PJMEDIA_EASYMCODEC (PJMEDIA_ERRNO_START+101) /* 220101 */ +/** + * @hideinitializer + * Invalid payload type. + */ +#define PJMEDIA_EINVALIDPT (PJMEDIA_ERRNO_START+102) /* 220102 */ +/** + * @hideinitializer + * Missing rtpmap. + */ +#define PJMEDIA_EMISSINGRTPMAP (PJMEDIA_ERRNO_START+103) /* 220103 */ + + + PJ_END_DECL #endif /* __PJMEDIA_ERRNO_H__ */ diff --git a/pjmedia/include/pjmedia/mediamgr.h b/pjmedia/include/pjmedia/mediamgr.h deleted file mode 100644 index 148038ec..00000000 --- a/pjmedia/include/pjmedia/mediamgr.h +++ /dev/null @@ -1,100 +0,0 @@ -/* $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/rtp.h b/pjmedia/include/pjmedia/rtp.h index 54c1e32e..bbb38f53 100644 --- a/pjmedia/include/pjmedia/rtp.h +++ b/pjmedia/include/pjmedia/rtp.h @@ -79,14 +79,14 @@ PJ_BEGIN_DECL */ 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. */ + PJMEDIA_RTP_ERR_RTP_PACKING, /**< Invalid RTP packet. */ + PJMEDIA_RTP_ERR_INVALID_VERSION, /**< Invalid RTP version. */ + PJMEDIA_RTP_ERR_INVALID_SSRC, /**< Invalid SSRC. */ + PJMEDIA_RTP_ERR_INVALID_PT, /**< Invalid payload type. */ + PJMEDIA_RTP_ERR_INVALID_PACKET, /**< Invalid packet. */ + PJMEDIA_RTP_ERR_SESSION_RESTARTED, /**< Session has just been restarted. */ + PJMEDIA_RTP_ERR_SESSION_PROBATION, /**< Session in probation. */ + PJMEDIA_RTP_ERR_BAD_SEQUENCE, /**< Bad RTP sequence number. */ }; #pragma pack(1) diff --git a/pjmedia/include/pjmedia/session.h b/pjmedia/include/pjmedia/session.h index d9efeb81..f6a9fc11 100644 --- a/pjmedia/include/pjmedia/session.h +++ b/pjmedia/include/pjmedia/session.h @@ -25,8 +25,7 @@ * @brief Media Session. */ -#include -#include +#include #include #include @@ -38,109 +37,140 @@ PJ_BEGIN_DECL * @{ */ -/** 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. + * Create new session offering based on the local and remote SDP. + * The session initially will be inactive. + * + * @param endpt The PJMEDIA endpoint instance. + * @param stream_cnt Maximum number of streams to be created. This + * also denotes the number of elements in the + * socket information. + * @param skinfo Array of socket informations. The argument stream_cnt + * specifies the number of elements in this array. One + * element is needed for each media stream to be + * created in the session. + * @param local_sdp The SDP describing local capability. + * @param rem_sdp The SDP describing remote capability. + * @param p_session Pointer to receive the media session. + * + * @return PJ_SUCCESS if media session can be created + * successfully. */ -PJ_DECL(pj_media_session_t*) -pj_media_session_create ( pj_med_mgr_t *mgr, const pj_media_sock_info *skinfo ); +PJ_DECL(pj_status_t) pjmedia_session_create( pjmedia_endpt *endpt, + unsigned stream_cnt, + const pjmedia_sock_info skinfo[], + const pjmedia_sdp_session *local_sdp, + const pjmedia_sdp_session *rem_sdp, + pjmedia_session **p_session ); -/** - * 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. + * Activate all streams in media session for the specified direction. + * + * @param session The media session. + * @param dir The direction to activate. + * + * @return PJ_SUCCESS if success. */ -PJ_DECL(pj_media_session_t*) -pj_media_session_clone (const pj_media_session_t *session); +PJ_DECL(pj_status_t) pjmedia_session_resume(pjmedia_session *session, + pjmedia_dir dir); -/** - * 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. + * Suspend receipt and transmission of all streams in media session + * for the specified direction. + * + * @param session The media session. + * @param dir The media direction to suspend. + * + * @return PJ_SUCCESS if success. */ -PJ_DECL(pj_status_t) -pj_media_session_update ( pj_media_session_t *session, - const pjsdp_session_desc *sdp); +PJ_DECL(pj_status_t) pjmedia_session_pause(pjmedia_session *session, + pjmedia_dir dir); /** - * Enumerate media streams in the session. - * @return the actual number of streams. + * Suspend receipt and transmission of individual stream in media session + * for the specified direction. + * + * @param session The media session. + * @param index The stream index. + * @param dir The media direction to pause. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(unsigned) -pj_media_session_enum_streams (const pj_media_session_t *session, - unsigned count, const pj_media_stream_info *info[]); +PJ_DECL(pj_status_t) pjmedia_session_pause_stream( pjmedia_session *session, + unsigned index, + pjmedia_dir dir); /** - * Get stream statistics. + * Activate individual stream in media session for the specified direction. + * + * @param session The media session. + * @param index The stream index. + * @param dir The media direction to activate. + * + * @return PJ_SUCCESS on success. */ -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); +PJ_DECL(pj_status_t) pjmedia_session_resume_stream(pjmedia_session *session, + unsigned index, + pjmedia_dir dir); /** - * Modify stream, only when stream is inactive. + * Enumerate media streams in the session. + * + * @param session The media session. + * @param count On input, specifies the number of elements in + * the array. On output, the number will be filled + * with number of streams in the session. + * @param strm_info Array of stream info. + * + * @return PJ_SUCCESS on success. */ -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); +PJ_DECL(pj_status_t) pjmedia_session_enum_streams(const pjmedia_session *session, + unsigned *count, + pjmedia_stream_info strm_info[]); + /** - * Activate all streams in media session. + * Get session statistics. The stream statistic shows various + * indicators such as packet count, packet lost, jitter, delay, etc. + * + * @param session The media session. + * @param count On input, specifies the number of elements in + * the array. On output, the number will be filled + * with number of streams in the session. + * @param stat Array of stream statistics. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) -pj_media_session_activate (pj_media_session_t *session); +PJ_DECL(pj_status_t) pjmedia_session_get_stat(const pjmedia_session *session, + unsigned *count, + pjmedia_stream_stat stat[]); /** - * Activate individual stream in media session. + * Get individual stream statistics. The stream statistic shows various + * indicators such as packet count, packet lost, jitter, delay, etc. + * + * @param s The media session. + * @param index The stream index. + * @param stat Stream statistics. + * + * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) -pj_media_session_activate_stream (pj_media_session_t *session, unsigned index); +PJ_DECL(pj_status_t) pjmedia_session_get_stream_stat(const pjmedia_session *s, + unsigned index, + pjmedia_stream_stat *stat); /** * Destroy media session. + * + * @param session The media session. + * + * @return PJ_SUCCESS if success. */ -PJ_DECL(pj_status_t) -pj_media_session_destroy (pj_media_session_t *session); +PJ_DECL(pj_status_t) pjmedia_session_destroy(pjmedia_session *session); + /** diff --git a/pjmedia/include/pjmedia/stream.h b/pjmedia/include/pjmedia/stream.h index 09f6acf1..83f7e14e 100644 --- a/pjmedia/include/pjmedia/stream.h +++ b/pjmedia/include/pjmedia/stream.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include PJ_BEGIN_DECL @@ -39,55 +39,124 @@ PJ_BEGIN_DECL * @{ */ -typedef struct pj_media_stream_t pj_media_stream_t; +/** + * Opaque declaration for media channel. + * Media channel is unidirectional flow of media from sender to + * receiver. + */ +typedef struct pjmedia_channel pjmedia_channel; -/** Parameter for creating channel. */ -typedef struct pj_media_stream_create_param +/** + * This structure describes media stream information. Each media stream + * corresponds to one "m=" line in SDP session descriptor, and it has + * its own RTP/RTCP socket pair. + */ +struct pjmedia_stream_info { - /** Codec ID, must NOT be NULL. */ - pj_codec_id *codec_id; + pjmedia_type type; /**< Media type (audio, video) */ + pjmedia_dir dir; /**< Media direction. */ + pjmedia_sock_info sock_info; /**< Media transport (RTP/RTCP sockets) */ + pj_sockaddr_in rem_addr; /**< Remote RTP address */ + pjmedia_codec_info fmt; /**< Codec format info. */ + pj_uint32_t ssrc; /**< RTP SSRC. */ + int jb_min; /**< Jitter buffer min delay. */ + int jb_max; /**< Jitter buffer max delay. */ + int jb_maxcnt; /**< Jitter buffer max delay. */ +}; - /** 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; +/** + * Individual channel statistic. + */ +struct pjmedia_channel_stat +{ + pj_uint32_t pkt; /**< Total number of packets. */ + pj_uint32_t bytes; /**< Total number of bytes, including RTP hdr. */ + pj_uint32_t lost; /**< Total number of packet lost */ +}; - /** RTP socket. */ - pj_sock_t rtp_sock; +/** + * Stream statistic. + */ +struct pjmedia_stream_stat +{ + pjmedia_channel_stat enc; /**< Encoder statistics. */ + pjmedia_channel_stat dec; /**< Decoder statistics. */ +}; - /** RTCP socket. */ - pj_sock_t rtcp_sock; - /** Address of remote */ - pj_sockaddr_in *remote_addr; +/** + * Create a media stream based on the specified stream parameter. + * All channels in the stream initially will be inactive. + * + * @param endpt Media endpoint. + * @param pool Pool to allocate memory for the stream. A large + * number of memory may be needed because jitter + * buffer needs to preallocate some storage. + * @param info Stream information. + * @param p_stream Pointer to receive the media stream. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_stream_create(pjmedia_endpt *endpt, + pj_pool_t *pool, + const pjmedia_stream_info *info, + pjmedia_stream **p_stream); - /** RTP SSRC */ - pj_uint32_t ssrc; +/** + * Destroy the media stream. + * + * @param stream The media stream. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_stream_destroy(pjmedia_stream *stream); - /** Jitter buffer parameters. */ - int jb_min, jb_max, jb_maxcnt; +/** + * Start the media stream. This will start the appropriate channels + * in the media stream, depending on the media direction that was set + * when the stream was created. + * + * @param stream The media stream. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_stream_start(pjmedia_stream *stream); -} 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); +/** + * Get the stream statistics. + * + * @param stream The media stream. + * @param stat Media stream statistics. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_stream_get_stat( const pjmedia_stream *stream, + pjmedia_stream_stat *stat); + +/** + * Pause the individual channel in the stream. + * + * @param channel The media channel. + * @param dir Which direction to pause. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjmedia_stream_pause( pjmedia_stream *stream, + pjmedia_dir dir); + +/** + * Resume the individual channel in the stream. + * + * @param channel The media channel. + * @param dir Which direction to resume. + * + * @return PJ_SUCCESS on success; + */ +PJ_DECL(pj_status_t) pjmedia_stream_resume(pjmedia_stream *stream, + pjmedia_dir dir); + /** * @} diff --git a/pjmedia/include/pjmedia/types.h b/pjmedia/include/pjmedia/types.h index 217a001b..6dd44bf7 100644 --- a/pjmedia/include/pjmedia/types.h +++ b/pjmedia/include/pjmedia/types.h @@ -20,8 +20,150 @@ #define __PJMEDIA_TYPES_H__ #include +#include +/** + * Top most media type. + */ +enum pjmedia_type +{ + /** No type. */ + PJMEDIA_TYPE_NONE = 0, + + /** The media is audio */ + PJMEDIA_TYPE_AUDIO = 1, + + /** The media is video. */ + PJMEDIA_TYPE_VIDEO = 2, + + /** Unknown media type, in this case the name will be specified in + * encoding_name. + */ + PJMEDIA_TYPE_UNKNOWN = 3, + +}; + + +/** + * Media direction. + */ +enum pjmedia_dir +{ + /** None */ + PJMEDIA_DIR_NONE = 0, + + /** Encoding (outgoing to network) stream */ + PJMEDIA_DIR_ENCODING = 1, + + /** Decoding (incoming from network) stream. */ + PJMEDIA_DIR_DECODING = 2, + + /** Incoming and outgoing stream. */ + PJMEDIA_DIR_ENCODING_DECODING = 3, + +}; + + +/** + * Top level media type. + */ +typedef enum pjmedia_type pjmedia_type; + +/** + * Media direction. + */ +typedef enum pjmedia_dir pjmedia_dir; + +/** + * Codec info. + */ +typedef struct pjmedia_codec_info pjmedia_codec_info; + +/** + * Codec initialization parameter. + */ +typedef struct pjmedia_codec_param pjmedia_codec_param; + +/** + * Types of media frames. + */ +typedef enum pjmedia_frame_type pjmedia_frame_type; + +/** + * This structure describes a media frame. + */ +typedef struct pjmedia_frame pjmedia_frame; + +/** + * Codec instance. + */ +typedef struct pjmedia_codec pjmedia_codec; + +/** + * Codec factory. + */ +typedef struct pjmedia_codec_factory pjmedia_codec_factory; + +/** + * Codec operation. + */ +typedef struct pjmedia_codec_op pjmedia_codec_op; + +/** + * Codec factory operation. + */ +typedef struct pjmedia_codec_factory_op pjmedia_codec_factory_op; + +/** + * Codec manager. + */ +typedef struct pjmedia_codec_mgr pjmedia_codec_mgr; + +/** + * Opague declaration of media endpoint. + */ +typedef struct pjmedia_endpt pjmedia_endpt; + + +/** + * Media socket info. + */ +typedef struct pjmedia_sock_info +{ + + pj_sock_t rtp_sock; + pj_sock_t rtcp_sock; + pj_sockaddr_in rtp_addr_name; + +} pjmedia_sock_info; + + +/** + * Typedef for media stream information. + */ +typedef struct pjmedia_stream_info pjmedia_stream_info; + +/** + * Typedef for media stream statistic. + */ +typedef struct pjmedia_stream_stat pjmedia_stream_stat; + +/** + * Typedef for media stream. + */ +typedef struct pjmedia_stream pjmedia_stream; + +/** + * Individual channel statistic. + */ +typedef struct pjmedia_channel_stat pjmedia_channel_stat; + +/** + * Opaque declaration of media session. + */ +typedef struct pjmedia_session pjmedia_session; + /** * Forward declaration for SDP attribute (sdp.h) */ -- cgit v1.2.3