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/src/pjmedia.h | 38 ----- pjmedia/src/pjmedia/codec.c | 5 +- pjmedia/src/pjmedia/codec.h | 353 ---------------------------------------- pjmedia/src/pjmedia/config.h | 27 --- pjmedia/src/pjmedia/g711.c | 13 +- pjmedia/src/pjmedia/jbuf.c | 6 +- pjmedia/src/pjmedia/jbuf.h | 142 ---------------- pjmedia/src/pjmedia/mediamgr.h | 100 ------------ pjmedia/src/pjmedia/nullsound.c | 120 +++++--------- pjmedia/src/pjmedia/pasound.c | 12 +- pjmedia/src/pjmedia/rtcp.c | 7 +- pjmedia/src/pjmedia/rtcp.h | 192 ---------------------- pjmedia/src/pjmedia/rtp.c | 6 +- pjmedia/src/pjmedia/rtp.h | 256 ----------------------------- pjmedia/src/pjmedia/sdp.c | 47 +++--- pjmedia/src/pjmedia/sdp.h | 332 ------------------------------------- pjmedia/src/pjmedia/session.c | 4 +- pjmedia/src/pjmedia/session.h | 152 ----------------- pjmedia/src/pjmedia/sound.h | 201 ----------------------- pjmedia/src/pjmedia/stream.c | 57 ++++--- pjmedia/src/pjmedia/stream.h | 99 ----------- 21 files changed, 130 insertions(+), 2039 deletions(-) delete mode 100644 pjmedia/src/pjmedia.h delete mode 100644 pjmedia/src/pjmedia/codec.h delete mode 100644 pjmedia/src/pjmedia/config.h delete mode 100644 pjmedia/src/pjmedia/jbuf.h delete mode 100644 pjmedia/src/pjmedia/mediamgr.h delete mode 100644 pjmedia/src/pjmedia/rtcp.h delete mode 100644 pjmedia/src/pjmedia/rtp.h delete mode 100644 pjmedia/src/pjmedia/sdp.h delete mode 100644 pjmedia/src/pjmedia/session.h delete mode 100644 pjmedia/src/pjmedia/sound.h delete mode 100644 pjmedia/src/pjmedia/stream.h (limited to 'pjmedia/src') diff --git a/pjmedia/src/pjmedia.h b/pjmedia/src/pjmedia.h deleted file mode 100644 index c4f2ab64..00000000 --- a/pjmedia/src/pjmedia.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $Id$ - * - */ -/* - * PJMEDIA - Multimedia over IP Stack - * (C)2003-2005 Benny Prijono - * - * Author: - * Benny Prijono - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; 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/src/pjmedia/codec.c b/pjmedia/src/pjmedia/codec.c index b4b64d58..a87c301c 100644 --- a/pjmedia/src/pjmedia/codec.c +++ b/pjmedia/src/pjmedia/codec.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #define THIS_FILE "codec.c" @@ -65,7 +66,7 @@ PJ_DEF(pj_status_t) pj_codec_mgr_register_factory (pj_codec_mgr *mgr, PJ_DEF(void) pj_codec_mgr_unregister_factory (pj_codec_mgr *mgr, pj_codec_factory *factory) { - PJ_UNUSED_ARG(mgr) + PJ_UNUSED_ARG(mgr); pj_list_erase(factory); enum_all_codecs (mgr); } @@ -100,7 +101,7 @@ PJ_DEF(pj_codec*) pj_codec_mgr_alloc_codec (pj_codec_mgr *mgr, const struct pj_c PJ_DEF(void) pj_codec_mgr_dealloc_codec (pj_codec_mgr *mgr, pj_codec *codec) { - PJ_UNUSED_ARG(mgr) + PJ_UNUSED_ARG(mgr); (*codec->factory->op->dealloc_codec)(codec->factory, codec); } diff --git a/pjmedia/src/pjmedia/codec.h b/pjmedia/src/pjmedia/codec.h deleted file mode 100644 index 50a2513b..00000000 --- a/pjmedia/src/pjmedia/codec.h +++ /dev/null @@ -1,353 +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_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/src/pjmedia/config.h b/pjmedia/src/pjmedia/config.h deleted file mode 100644 index 489d5b31..00000000 --- a/pjmedia/src/pjmedia/config.h +++ /dev/null @@ -1,27 +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 __PJMED_CONFIG_H__ -#define __PJMED_CONFIG_H__ - -/** - * @defgroup PJMEDIA Media Stack - */ - - -#endif /* __PJMED_CONFIG_H__ */ diff --git a/pjmedia/src/pjmedia/g711.c b/pjmedia/src/pjmedia/g711.c index 4275943f..9d79bccf 100644 --- a/pjmedia/src/pjmedia/g711.c +++ b/pjmedia/src/pjmedia/g711.c @@ -22,7 +22,8 @@ #include #include #include -#include /* memset */ +#include + #define G711_BPS 64000 #define G711_CODEC_CNT 0 /* number of codec to preallocate in memory */ @@ -128,7 +129,7 @@ PJ_DEF(pj_status_t) g711_deinit_factory (pj_codec_factory *factory) static pj_status_t g711_match_id( pj_codec_factory *factory, const pj_codec_id *id ) { - PJ_UNUSED_ARG(factory) + PJ_UNUSED_ARG(factory); /* It's sufficient to check payload type only. */ return (id->pt==PJ_RTP_PT_PCMU || id->pt==PJ_RTP_PT_PCMA) ? 0 : -1; @@ -138,7 +139,7 @@ static pj_status_t g711_default_attr (pj_codec_factory *factory, const pj_codec_id *id, pj_codec_attr *attr ) { - PJ_UNUSED_ARG(factory) + PJ_UNUSED_ARG(factory); memset(attr, 0, sizeof(pj_codec_attr)); attr->sample_rate = 8000; @@ -155,7 +156,7 @@ static pj_status_t g711_default_attr (pj_codec_factory *factory, static unsigned g711_enum_codecs (pj_codec_factory *factory, unsigned count, pj_codec_id codecs[]) { - PJ_UNUSED_ARG(factory) + PJ_UNUSED_ARG(factory); if (count > 0) { codecs[0].type = PJ_MEDIA_TYPE_AUDIO; @@ -229,8 +230,8 @@ static pj_status_t g711_codec_default_attr (pj_codec *codec, pj_codec_attr *att static pj_status_t g711_init( pj_codec *codec, pj_pool_t *pool ) { /* There's nothing to do here really */ - PJ_UNUSED_ARG(codec) - PJ_UNUSED_ARG(pool) + PJ_UNUSED_ARG(codec); + PJ_UNUSED_ARG(pool); return PJ_SUCCESS; } diff --git a/pjmedia/src/pjmedia/jbuf.c b/pjmedia/src/pjmedia/jbuf.c index b2e1b4da..ce00d970 100644 --- a/pjmedia/src/pjmedia/jbuf.c +++ b/pjmedia/src/pjmedia/jbuf.c @@ -19,7 +19,9 @@ #include #include #include -#include /* memset() */ +#include +#include + /* * At the current state, this is basicly an ugly jitter buffer. @@ -67,7 +69,7 @@ pj_framelist_init( pj_jbframelist *lst, pj_pool_t *pool, unsigned maxcount ) { PJ_LOG(5, (THIS_FILE, "..pj_frame_list_init [lst=%p], maxcount=%d", lst, maxcount)); - memset(lst, 0, sizeof(*lst)); + pj_memset(lst, 0, sizeof(*lst)); lst->maxcount = maxcount; lst->frames = pj_pool_calloc( pool, maxcount, sizeof(*lst->frames) ); if (lst->frames == NULL) { diff --git a/pjmedia/src/pjmedia/jbuf.h b/pjmedia/src/pjmedia/jbuf.h deleted file mode 100644 index 8ad89f38..00000000 --- a/pjmedia/src/pjmedia/jbuf.h +++ /dev/null @@ -1,142 +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_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/src/pjmedia/mediamgr.h b/pjmedia/src/pjmedia/mediamgr.h deleted file mode 100644 index 148038ec..00000000 --- a/pjmedia/src/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/src/pjmedia/nullsound.c b/pjmedia/src/pjmedia/nullsound.c index dc509a7a..fcda5780 100644 --- a/pjmedia/src/pjmedia/nullsound.c +++ b/pjmedia/src/pjmedia/nullsound.c @@ -17,111 +17,77 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include -/* - * Null Factory Operations - */ -static pj_status_t null_sound_init(void); -static const char *null_sound_get_name(void); -static pj_status_t null_sound_destroy(void); -static pj_status_t null_sound_enum_devices(int *count, char *dev_names[]); -static pj_status_t null_sound_create_dev(const char *dev_name, pj_snd_dev *dev); -static pj_status_t null_sound_destroy_dev(pj_snd_dev *dev); - - -/* - * Null Device Operations - */ -static pj_status_t null_sound_dev_open( pj_snd_dev *dev, pj_snd_role_t role ); -static pj_status_t null_sound_dev_close( pj_snd_dev *dev ); -static pj_status_t null_sound_dev_play( pj_snd_dev *dev ); -static pj_status_t null_sound_dev_record( pj_snd_dev *dev ); - - -static pj_snd_dev_factory null_sound_factory = +static pj_snd_dev_info null_info = { - &null_sound_init, - &null_sound_get_name, - &null_sound_destroy, - &null_sound_enum_devices, - &null_sound_create_dev, - &null_sound_destroy_dev + "Null Device", + 1, + 1, + 8000 }; -static struct pj_snd_dev_op null_sound_dev_op = -{ - &null_sound_dev_open, - &null_sound_dev_close, - &null_sound_dev_play, - &null_sound_dev_record -}; -PJ_DEF(pj_snd_dev_factory*) pj_nullsound_get_factory() +PJ_DEF(pj_status_t) pj_snd_init(pj_pool_factory *factory) { - return &null_sound_factory; + PJ_UNUSED_ARG(factory); + return PJ_SUCCESS; } -static pj_status_t null_sound_init(void) +PJ_DEF(int) pj_snd_get_dev_count(void) { - return 0; + return 1; } -static const char *null_sound_get_name(void) +PJ_DEF(const pj_snd_dev_info*) pj_snd_get_dev_info(unsigned index) { - return "nullsound"; + PJ_ASSERT_RETURN(index==0, NULL); + return &null_info; } -static pj_status_t null_sound_destroy(void) +PJ_DEF(pj_snd_stream*) pj_snd_open_recorder( int index, + const pj_snd_stream_info *param, + pj_snd_rec_cb rec_cb, + void *user_data) { - return 0; + PJ_UNUSED_ARG(index); + PJ_UNUSED_ARG(param); + PJ_UNUSED_ARG(rec_cb); + PJ_UNUSED_ARG(user_data); + return (void*)1; } -static pj_status_t null_sound_enum_devices(int *count, char *dev_names[]) +PJ_DEF(pj_snd_stream*) pj_snd_open_player( int index, + const pj_snd_stream_info *param, + pj_snd_play_cb play_cb, + void *user_data) { - *count = 1; - dev_names[0] = "nullsound"; - return 0; + PJ_UNUSED_ARG(index); + PJ_UNUSED_ARG(param); + PJ_UNUSED_ARG(play_cb); + PJ_UNUSED_ARG(user_data); + return (void*)1; } -static pj_status_t null_sound_create_dev(const char *dev_name, pj_snd_dev *dev) +PJ_DEF(pj_status_t) pj_snd_stream_start(pj_snd_stream *stream) { - PJ_UNUSED_ARG(dev_name); - dev->op = &null_sound_dev_op; - return 0; + PJ_UNUSED_ARG(stream); + return PJ_SUCCESS; } -static pj_status_t null_sound_destroy_dev(pj_snd_dev *dev) +PJ_DEF(pj_status_t) pj_snd_stream_stop(pj_snd_stream *stream) { - PJ_UNUSED_ARG(dev); - return 0; + PJ_UNUSED_ARG(stream); + return PJ_SUCCESS; } - -/* - * Null Device Operations - */ -static pj_status_t null_sound_dev_open( pj_snd_dev *dev, pj_snd_role_t role ) -{ - PJ_UNUSED_ARG(dev); - PJ_UNUSED_ARG(role); - return 0; -} - -static pj_status_t null_sound_dev_close( pj_snd_dev *dev ) +PJ_DEF(pj_status_t) pj_snd_stream_close(pj_snd_stream *stream) { - PJ_UNUSED_ARG(dev); - return 0; + PJ_UNUSED_ARG(stream); + return PJ_SUCCESS; } -static pj_status_t null_sound_dev_play( pj_snd_dev *dev ) +PJ_DEF(pj_status_t) pj_snd_deinit(void) { - PJ_UNUSED_ARG(dev); - return 0; + return PJ_SUCCESS; } - -static pj_status_t null_sound_dev_record( pj_snd_dev *dev ) -{ - PJ_UNUSED_ARG(dev); - return 0; -} - diff --git a/pjmedia/src/pjmedia/pasound.c b/pjmedia/src/pjmedia/pasound.c index d3184a7d..5c5c7bd0 100644 --- a/pjmedia/src/pjmedia/pasound.c +++ b/pjmedia/src/pjmedia/pasound.c @@ -60,14 +60,14 @@ static int PaRecorderCallback(const void *input, pj_snd_stream *stream = userData; pj_status_t status; - PJ_UNUSED_ARG(output) - PJ_UNUSED_ARG(timeInfo) + PJ_UNUSED_ARG(output); + PJ_UNUSED_ARG(timeInfo); if (stream->quit_flag) goto on_break; if (stream->thread_initialized == 0) { - stream->thread = pj_thread_register("pa_rec", stream->thread_desc); + status = pj_thread_register("pa_rec", stream->thread_desc, &stream->thread); stream->thread_initialized = 1; } @@ -100,14 +100,14 @@ static int PaPlayerCallback( const void *input, pj_status_t status; unsigned size = frameCount * stream->bytes_per_sample; - PJ_UNUSED_ARG(input) - PJ_UNUSED_ARG(timeInfo) + PJ_UNUSED_ARG(input); + PJ_UNUSED_ARG(timeInfo); if (stream->quit_flag) goto on_break; if (stream->thread_initialized == 0) { - stream->thread = pj_thread_register("pa_rec", stream->thread_desc); + status = pj_thread_register("pa_rec", stream->thread_desc, &stream->thread); stream->thread_initialized = 1; } diff --git a/pjmedia/src/pjmedia/rtcp.c b/pjmedia/src/pjmedia/rtcp.c index 70484388..5f45775a 100644 --- a/pjmedia/src/pjmedia/rtcp.c +++ b/pjmedia/src/pjmedia/rtcp.c @@ -19,7 +19,8 @@ #include #include /* pj_gettimeofday */ #include /* pj_htonx, pj_ntohx */ -#include /* memset */ +#include /* pj_memset */ + #define RTCP_SR 200 #define RTCP_RR 201 @@ -46,7 +47,7 @@ PJ_DEF(void) pj_rtcp_init(pj_rtcp_session *s, pj_uint32_t ssrc) { pj_rtcp_pkt *rtcp_pkt = &s->rtcp_pkt; - memset(rtcp_pkt, 0, sizeof(pj_rtcp_pkt)); + pj_memset(rtcp_pkt, 0, sizeof(pj_rtcp_pkt)); /* Init time */ s->rtcp_lsr.hi = s->rtcp_lsr.lo = 0; @@ -67,7 +68,7 @@ PJ_DEF(void) pj_rtcp_init(pj_rtcp_session *s, pj_uint32_t ssrc) PJ_DEF(void) pj_rtcp_fini(pj_rtcp_session *session) { /* Nothing to do. */ - PJ_UNUSED_ARG(session) + PJ_UNUSED_ARG(session); } static void rtcp_init_seq(pj_rtcp_session *s, pj_uint16_t seq) diff --git a/pjmedia/src/pjmedia/rtcp.h b/pjmedia/src/pjmedia/rtcp.h deleted file mode 100644 index 8a8f8909..00000000 --- a/pjmedia/src/pjmedia/rtcp.h +++ /dev/null @@ -1,192 +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_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/src/pjmedia/rtp.c b/pjmedia/src/pjmedia/rtp.c index 5aadd7c1..5a337937 100644 --- a/pjmedia/src/pjmedia/rtp.c +++ b/pjmedia/src/pjmedia/rtp.c @@ -20,7 +20,9 @@ #include #include /* pj_gettimeofday() */ #include /* pj_htonx, pj_htonx */ -#include /* memset() */ +#include +#include + #define THIS_FILE "rtp.c" @@ -61,7 +63,7 @@ PJ_DEF(pj_status_t) pj_rtp_session_init( pj_rtp_session *ses, /* Sequence number will be initialized when the first RTP packet is receieved. */ /* Build default header for outgoing RTP packet. */ - memset(ses, 0, sizeof(*ses)); + pj_memset(ses, 0, sizeof(*ses)); ses->out_hdr.v = RTP_VERSION; ses->out_hdr.p = 0; ses->out_hdr.x = 0; diff --git a/pjmedia/src/pjmedia/rtp.h b/pjmedia/src/pjmedia/rtp.h deleted file mode 100644 index 54c1e32e..00000000 --- a/pjmedia/src/pjmedia/rtp.h +++ /dev/null @@ -1,256 +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_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/src/pjmedia/sdp.c b/pjmedia/src/pjmedia/sdp.c index 42a1fd4c..afd746ee 100644 --- a/pjmedia/src/pjmedia/sdp.c +++ b/pjmedia/src/pjmedia/sdp.c @@ -17,12 +17,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include -#include +#include #include #include #include #include #include +#include enum { SKIP_WS = 0, @@ -123,7 +124,8 @@ static struct attr_map_rec * Scanner character specification. */ static int is_initialized; -static pj_char_spec cs_token; +static pj_cis_buf_t cis_buf; +static pj_cis_t cs_token; static void init_sdp_parser(void) { @@ -133,9 +135,12 @@ static void init_sdp_parser(void) return; } } - pj_cs_add_alpha(cs_token); - pj_cs_add_num(cs_token); - pj_cs_add_str( cs_token, TOKEN); + + pj_cis_buf_init(&cis_buf); + pj_cis_init(&cis_buf, &cs_token); + pj_cis_add_alpha(&cs_token); + pj_cis_add_num(&cs_token); + pj_cis_add_str(&cs_token, TOKEN); } static int print_rtpmap_attr(const pjsdp_rtpmap_attr *rtpmap, @@ -202,9 +207,9 @@ static int print_generic_num_attr(const pjsdp_attr_num *attr, char *buf, int len static int print_name_only_attr(const pjsdp_attr *attr, char *buf, int len) { - PJ_UNUSED_ARG(attr) - PJ_UNUSED_ARG(buf) - PJ_UNUSED_ARG(len) + PJ_UNUSED_ARG(attr); + PJ_UNUSED_ARG(buf); + PJ_UNUSED_ARG(len); return 0; } @@ -706,12 +711,12 @@ static void parse_media(pj_scanner *scanner, pjsdp_media_desc *med) pj_scan_get_char(scanner); /* port */ - pj_scan_get(scanner, cs_token, &str); + pj_scan_get(scanner, &cs_token, &str); med->desc.port = (unsigned short)pj_strtoul(&str); - if (*scanner->current == '/') { + if (*scanner->curptr == '/') { /* port count */ pj_scan_get_char(scanner); - pj_scan_get(scanner, cs_token, &str); + pj_scan_get(scanner, &cs_token, &str); med->desc.port_count = pj_strtoul(&str); } else { @@ -727,9 +732,9 @@ static void parse_media(pj_scanner *scanner, pjsdp_media_desc *med) /* format list */ med->desc.fmt_count = 0; - while (*scanner->current == ' ') { + while (*scanner->curptr == ' ') { pj_scan_get_char(scanner); - pj_scan_get(scanner, cs_token, &med->desc.fmt[med->desc.fmt_count++]); + pj_scan_get(scanner, &cs_token, &med->desc.fmt[med->desc.fmt_count++]); } /* newline */ @@ -751,10 +756,10 @@ static pjsdp_rtpmap_attr * parse_rtpmap_attr( pj_pool_t *pool, pj_scanner *scann pj_scan_get_until_ch(scanner, '/', &rtpmap->encoding_name); pj_scan_get_char(scanner); - pj_scan_get(scanner, cs_token, &str); + pj_scan_get(scanner, &cs_token, &str); rtpmap->clock_rate = pj_strtoul(&str); - if (*scanner->current == '/') { + if (*scanner->curptr == '/') { pj_scan_get_char(scanner); pj_scan_get_until_ch(scanner, '\r', &rtpmap->parameter); } @@ -793,7 +798,7 @@ static pjsdp_attr * parse_name_only_attr( pj_pool_t *pool, pj_scanner *scanner ) { pjsdp_attr *attr; - PJ_UNUSED_ARG(scanner) + PJ_UNUSED_ARG(scanner); attr = pj_pool_calloc(pool, 1, sizeof(*attr)); return attr; } @@ -824,7 +829,7 @@ static pjsdp_attr *parse_attr( pj_pool_t *pool, pj_scanner *scanner) pj_scan_advance_n(scanner, 2, SKIP_WS); /* get attr name. */ - pj_scan_get(scanner, cs_token, &attrname); + pj_scan_get(scanner, &cs_token, &attrname); /* find entry to handle attrname */ for (i=0; i - * - * 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/src/pjmedia/session.c b/pjmedia/src/pjmedia/session.c index 98b359f2..996ed474 100644 --- a/pjmedia/src/pjmedia/session.c +++ b/pjmedia/src/pjmedia/session.c @@ -21,6 +21,8 @@ #include #include #include +#include + typedef struct pj_media_stream_desc { @@ -771,7 +773,7 @@ pj_media_session_activate_stream (pj_media_session_t *session, unsigned index) scp.rtp_sock = sd->info.sock_info.rtp_sock; scp.rtcp_sock = sd->info.sock_info.rtcp_sock; scp.remote_addr = pj_pool_calloc (session->pool, 1, sizeof(pj_sockaddr_in)); - pj_sockaddr_init (scp.remote_addr, &sd->info.rem_addr, sd->info.rem_port); + pj_sockaddr_in_init(scp.remote_addr, &sd->info.rem_addr, sd->info.rem_port); scp.ssrc = tv.sec; scp.jb_min = 1; scp.jb_max = 15; diff --git a/pjmedia/src/pjmedia/session.h b/pjmedia/src/pjmedia/session.h deleted file mode 100644 index d9efeb81..00000000 --- a/pjmedia/src/pjmedia/session.h +++ /dev/null @@ -1,152 +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_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/src/pjmedia/sound.h b/pjmedia/src/pjmedia/sound.h deleted file mode 100644 index 3fa40db6..00000000 --- a/pjmedia/src/pjmedia/sound.h +++ /dev/null @@ -1,201 +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_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/src/pjmedia/stream.c b/pjmedia/src/pjmedia/stream.c index 718cace1..323e0415 100644 --- a/pjmedia/src/pjmedia/stream.c +++ b/pjmedia/src/pjmedia/stream.c @@ -24,8 +24,13 @@ #include #include /* memcpy() */ #include +#include +#include +#include +#include #include + #define THISFILE "stream.c" #define ERRLEVEL 1 @@ -91,7 +96,7 @@ static pj_status_t play_callback(/* in */ void *user_data, pj_status_t status; struct pj_audio_frame frame_in, frame_out; - PJ_UNUSED_ARG(timestamp) + PJ_UNUSED_ARG(timestamp); /* Lock mutex */ pj_mutex_lock (channel->mutex); @@ -152,12 +157,12 @@ static pj_status_t rec_callback( /* in */ void *user_data, int ts_len; void *rtphdr; int rtphdrlen; - int sent; + pj_ssize_t sent; #if 0 static FILE *fhnd = NULL; #endif - PJ_UNUSED_ARG(timestamp) + PJ_UNUSED_ARG(timestamp); /* Start locking channel mutex */ pj_mutex_lock (channel->mutex); @@ -202,14 +207,11 @@ static pj_status_t rec_callback( /* in */ void *user_data, pj_memcpy(channel->out_pkt, rtphdr, sizeof(pj_rtp_hdr)); /* Send. */ - sent = pj_sock_sendto (channel->rtp_sock, channel->out_pkt, frame_out.size+sizeof(pj_rtp_hdr), 0, + sent = frame_out.size+sizeof(pj_rtp_hdr); + status = pj_sock_sendto (channel->rtp_sock, channel->out_pkt, &sent, 0, &channel->dst_addr, sizeof(channel->dst_addr)); - if (sent != (int)frame_out.size + (int)sizeof(pj_rtp_hdr)) { - pj_perror(THISFILE, "Error sending RTP packet to %s:%d", - pj_sockaddr_get_str_addr(&channel->dst_addr), - pj_sockaddr_get_port(&channel->dst_addr)); + if (status != PJ_SUCCESS) goto on_return; - } /* Update stat */ channel->stat.pkt_tx++; @@ -231,12 +233,12 @@ on_return: } -static void* PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg) +static int PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg) { pj_media_stream_t *channel = arg; while (!channel->thread_quit_flag) { - int len, size; + pj_ssize_t len, size; const pj_rtp_hdr *hdr; const void *payload; unsigned payloadlen; @@ -244,7 +246,7 @@ static void* PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg) struct jb_frame *jb_frame; /* Wait for packet. */ - fd_set fds; + pj_fd_set_t fds; pj_time_val timeout; PJ_FD_ZERO (&fds); @@ -258,15 +260,16 @@ static void* PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg) continue; /* Get packet from socket. */ - len = pj_sock_recv (channel->rtp_sock, channel->in_pkt, channel->in_pkt_size, 0); - if (len < 1) { - if (pj_getlasterror() == PJ_ECONNRESET) { + len = channel->in_pkt_size; + status = pj_sock_recv (channel->rtp_sock, channel->in_pkt, &len, 0); + if (len < 1 || status != PJ_SUCCESS) { + if (pj_get_netos_error() == PJ_STATUS_FROM_OS(OSERR_ECONNRESET)) { /* On Win2K SP2 (or above) and WinXP, recv() will get WSAECONNRESET when the sending side receives ICMP port unreachable. */ continue; } - pj_perror(THISFILE, "Error receiving packet from socket (len=%d)", len); + //pj_perror(THISFILE, "Error receiving packet from socket (len=%d)", len); pj_thread_sleep(1); continue; } @@ -325,7 +328,7 @@ static void* PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg) pj_mutex_unlock (channel->mutex); } - return NULL; + return 0; } static void init_snd_param_from_codec_attr (pj_snd_stream_info *param, @@ -348,7 +351,7 @@ static pj_media_stream_t *create_channel ( pj_pool_t *pool, pj_codec_attr codec_attr; void *ptr; unsigned size; - int status; + pj_status_t status; /* Allocate memory for channel descriptor */ size = sizeof(pj_media_stream_t); @@ -369,8 +372,8 @@ static pj_media_stream_t *create_channel ( pj_pool_t *pool, channel->state = STREAM_STOPPED; /* Create mutex for the channel. */ - channel->mutex = pj_mutex_create(pool, NULL, PJ_MUTEX_SIMPLE); - if (channel->mutex == NULL) + status = pj_mutex_create_simple(pool, NULL, &channel->mutex); + if (status != PJ_SUCCESS) goto err_cleanup; /* Create and initialize codec, only if peer is not present. @@ -484,11 +487,11 @@ static pj_media_stream_t *create_channel ( pj_pool_t *pool, goto err_cleanup; } - channel->transport_thread = pj_thread_create(pool, "decode", - &stream_decoder_transport_thread, channel, - 0, NULL, 0); - if (!channel->transport_thread) { - pj_perror(THISFILE, "Unable to create transport thread"); + status = pj_thread_create(pool, "decode", + &stream_decoder_transport_thread, channel, + 0, 0, &channel->transport_thread); + if (status != PJ_SUCCESS) { + //pj_perror(THISFILE, "Unable to create transport thread"); goto err_cleanup; } } @@ -573,13 +576,13 @@ PJ_DEF(pj_status_t) pj_media_stream_get_stat (const pj_media_stream_t *stream, PJ_DEF(pj_status_t) pj_media_stream_pause (pj_media_stream_t *channel) { - PJ_UNUSED_ARG(channel) + PJ_UNUSED_ARG(channel); return -1; } PJ_DEF(pj_status_t) pj_media_stream_resume (pj_media_stream_t *channel) { - PJ_UNUSED_ARG(channel) + PJ_UNUSED_ARG(channel); return -1; } diff --git a/pjmedia/src/pjmedia/stream.h b/pjmedia/src/pjmedia/stream.h deleted file mode 100644 index 09f6acf1..00000000 --- a/pjmedia/src/pjmedia/stream.h +++ /dev/null @@ -1,99 +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_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