diff options
Diffstat (limited to 'pjmedia/include')
-rw-r--r-- | pjmedia/include/pjmedia/codec.h | 85 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/config.h | 2 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/errno.h | 5 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/jbuf.h | 27 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/session.h | 78 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/stream.h | 20 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/types.h | 48 |
7 files changed, 177 insertions, 88 deletions
diff --git a/pjmedia/include/pjmedia/codec.h b/pjmedia/include/pjmedia/codec.h index 04bf449e..00e60e52 100644 --- a/pjmedia/include/pjmedia/codec.h +++ b/pjmedia/include/pjmedia/codec.h @@ -110,22 +110,38 @@ typedef struct pjmedia_codec_info pjmedia_codec_info; */ struct pjmedia_codec_param { - unsigned clock_rate; /**< Sampling rate in Hz */ - unsigned channel_cnt; /**< Channel count. */ - pj_uint32_t avg_bps; /**< Average bandwidth in bits/sec */ - - pj_uint16_t ptime; /**< Packet time in miliseconds */ - pj_uint8_t pcm_bits_per_sample;/**< Bits/sample in the PCM side */ - - unsigned pt:8; /**< Payload type. */ - unsigned vad:1; /**< Voice Activity Detector. */ - unsigned cng:1; /**< Comfort Noise Generator. */ - unsigned lpf:1; /**< Low pass filter */ - unsigned hpf:1; /**< High pass filter */ - unsigned penh:1; /**< Perceptual Enhancement */ - unsigned concl:1; /**< Packet loss concealment */ - unsigned reserved:1; /**< Reserved, must be NULL. */ + /** + * The "info" part of codec param describes the capability of the codec, + * and the value should NOT be changed by application. + */ + struct { + unsigned clock_rate; /**< Sampling rate in Hz */ + unsigned channel_cnt; /**< Channel count. */ + pj_uint32_t avg_bps; /**< Average bandwidth in bits/sec */ + pj_uint16_t frm_ptime; /**< Base frame ptime in msec. */ + pj_uint8_t pcm_bits_per_sample; /**< Bits/sample in the PCM side */ + pj_uint8_t pt; /**< Payload type. */ + } info; + /** + * The "setting" part of codec param describes various settings to be + * applied to the codec. When the codec param is retrieved from the codec + * or codec factory, the values of these will be filled by the capability + * of the codec. Any features that are supported by the codec (e.g. vad + * or plc) will be turned on, so that application can query which + * capabilities are supported by the codec. Application may change the + * settings here before instantiating the codec/stream. + */ + struct { + pj_uint8_t frm_per_pkt; /**< Number of frames per packet. */ + unsigned vad:1; /**< Voice Activity Detector. */ + unsigned cng:1; /**< Comfort Noise Generator. */ + unsigned lpf:1; /**< Low pass filter */ + unsigned hpf:1; /**< High pass filter */ + unsigned penh:1; /**< Perceptual Enhancement */ + unsigned plc:1; /**< Packet loss concealment */ + unsigned reserved:1; /**< Reserved, must be zero. */ + } setting; }; /** @@ -182,11 +198,14 @@ struct pjmedia_codec_op /** * Instruct the codec to inspect the specified payload/packet and - * split the packet info individual frames. + * split the packet into individual base frames. Each output frames will + * have ptime that is equal to basic frame ptime (i.e. the value of + * info.frm_ptime in #pjmedia_codec_param). * * @param codec The codec instance * @param pkt The input packet. * @param pkt_size Size of the packet. + * @param timestamp The timestamp of the first sample in the packet. * @param frame_cnt On input, specifies the maximum number of frames * in the array. On output, the codec must fill * with number of frames detected in the packet. @@ -195,14 +214,17 @@ struct pjmedia_codec_op * * @return PJ_SUCCESS on success. */ - pj_status_t (*get_frames)(pjmedia_codec *codec, - void *pkt, - pj_size_t pkt_size, - unsigned *frame_cnt, - pjmedia_frame frames[]); + pj_status_t (*parse)( pjmedia_codec *codec, + void *pkt, + pj_size_t pkt_size, + const pj_timestamp *timestamp, + unsigned *frame_cnt, + pjmedia_frame frames[]); /** - * Instruct the codec to encode the specified input frame. + * Instruct the codec to encode the specified input frame. The input + * PCM samples MUST have ptime that is exactly equal to base frame + * ptime (i.e. the value of info.frm_ptime in #pjmedia_codec_param). * * @param codec The codec instance. * @param input The input frame. @@ -217,7 +239,11 @@ struct pjmedia_codec_op struct pjmedia_frame *output); /** - * Instruct the codec to decode the specified input frame. + * Instruct the codec to decode the specified input frame. The input + * frame MUST have ptime that is exactly equal to base frame + * ptime (i.e. the value of info.frm_ptime in #pjmedia_codec_param). + * Application can achieve this by parsing the packet into base + * frames before decoding each frame. * * @param codec The codec instance. * @param input The input frame. @@ -231,6 +257,19 @@ struct pjmedia_codec_op unsigned out_size, struct pjmedia_frame *output); + /** + * Instruct the codec to recover a missing frame. Not all codec has + * this capability, so this function may be NULL. + * + * @param codec The codec instance. + * @param out_size The length of buffer in the output frame. + * @param output The output frame. + * + * @return PJ_SUCCESS on success; + */ + pj_status_t (*recover)(pjmedia_codec *codec, + unsigned out_size, + struct pjmedia_frame *output); }; diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h index 980d377f..7a71ae5f 100644 --- a/pjmedia/include/pjmedia/config.h +++ b/pjmedia/include/pjmedia/config.h @@ -77,6 +77,8 @@ /** * Maximum frame duration (in msec) to be supported. + * This (among other thing) will affect the size of buffers to be allocated + * for outgoing packets. */ #ifndef PJMEDIA_MAX_FRAME_DURATION_MS # define PJMEDIA_MAX_FRAME_DURATION_MS 200 diff --git a/pjmedia/include/pjmedia/errno.h b/pjmedia/include/pjmedia/errno.h index 1dab1863..7909b557 100644 --- a/pjmedia/include/pjmedia/errno.h +++ b/pjmedia/include/pjmedia/errno.h @@ -275,6 +275,11 @@ PJ_BEGIN_DECL * PCM buffer is too short. */ #define PJMEDIA_CODEC_EPCMTOOSHORT (PJMEDIA_ERRNO_START+83) /* 220083 */ +/** + * @hideinitializer + * Invalid codec frame length. + */ +#define PJMEDIA_CODEC_EFRMINLEN (PJMEDIA_ERRNO_START+84) /* 220084 */ /************************************************************ diff --git a/pjmedia/include/pjmedia/jbuf.h b/pjmedia/include/pjmedia/jbuf.h index c9bf495f..9bb1a995 100644 --- a/pjmedia/include/pjmedia/jbuf.h +++ b/pjmedia/include/pjmedia/jbuf.h @@ -55,6 +55,12 @@ enum pjmedia_jb_frame_type /** + * @see pjmedia_jb_frame_type. + */ +typedef enum pjmedia_jb_frame_type pjmedia_jb_frame_type; + + +/** * This structure describes jitter buffer current status. */ struct pjmedia_jb_state @@ -79,6 +85,11 @@ typedef struct pjmedia_jb_state pjmedia_jb_state; */ #define PJMEDIA_JB_DEFAULT_INIT_DELAY 15 +/** + * Opaque declaration for jitter buffer. + */ +typedef struct pjmedia_jbuf pjmedia_jbuf; + /** * Create an adaptive jitter buffer according to the specification. If @@ -181,10 +192,10 @@ PJ_DECL(pj_status_t) pjmedia_jbuf_reset(pjmedia_jbuf *jb); * * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pjmedia_jbuf_put_frame(pjmedia_jbuf *jb, - const void *frame, - pj_size_t size, - int frame_seq); +PJ_DECL(void) pjmedia_jbuf_put_frame( pjmedia_jbuf *jb, + const void *frame, + pj_size_t size, + int frame_seq); /** * Get a frame from the jitter buffer. The jitter buffer will return the @@ -210,12 +221,10 @@ PJ_DECL(pj_status_t) pjmedia_jbuf_put_frame(pjmedia_jbuf *jb, * frame will be copied. If there is a frame, the jitter * buffer will copy the frame to the buffer, and frame * type will be set to PJMEDIA_JB_NORMAL_FRAME. - * - * @return Always returns PJ_SUCCESS. */ -PJ_DECL(pj_status_t) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb, - void *frame, - char *p_frm_type); +PJ_DECL(void) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb, + void *frame, + char *p_frm_type); /** diff --git a/pjmedia/include/pjmedia/session.h b/pjmedia/include/pjmedia/session.h index cfc1bf8e..c93d4343 100644 --- a/pjmedia/include/pjmedia/session.h +++ b/pjmedia/include/pjmedia/session.h @@ -66,26 +66,73 @@ struct pjmedia_session_info }; +/** + * Opaque declaration of media session. + */ +typedef struct pjmedia_session pjmedia_session; + + /** - * Initialize stream info from SDP media lines. + * @see pjmedia_session_info. + */ +typedef struct pjmedia_session_info pjmedia_session_info; + + +/** + * This function will initialize the session info based on information + * in both SDP session descriptors. The remaining information will be + * taken from default codec parameters. If socket info array is specified, + * the socket will be copied to the session info as well. * - * @param si Stream info structure to be initialized. - * @param pool Pool. + * @param pool Pool to allocate memory. * @param endpt Pjmedia endpoint. + * @param max_streams Maximum number of stream infos to be created. + * @param si Session info structure to be initialized. + * @param skinfo Optional array of media socket info to be copied + * to the stream info. If this argument is specified, + * the array must contain sufficient elements for + * each stream to be initialized. * @param local Local SDP session descriptor. * @param remote Remote SDP session descriptor. * @param stream_idx Media stream index in the session descriptor. * * @return PJ_SUCCESS if stream info is successfully initialized. */ -PJ_DECL(pj_status_t) pjmedia_stream_info_from_sdp( - pjmedia_stream_info *si, - pj_pool_t *pool, - pjmedia_endpt *endpt, - const pjmedia_sdp_session *local, - const pjmedia_sdp_session *remote, - unsigned stream_idx); - +PJ_DECL(pj_status_t) +pjmedia_session_info_from_sdp( pj_pool_t *pool, + pjmedia_endpt *endpt, + unsigned max_streams, + pjmedia_session_info *si, + const pjmedia_sock_info skinfo[], + const pjmedia_sdp_session *local, + const pjmedia_sdp_session *remote); + + +/* + * This function will initialize the stream info based on information + * in both SDP session descriptors for the specified stream index. + * The remaining information will be taken from default codec parameters. + * If socket info array is specified, the socket will be copied to the + * session info as well. + * + * @param si Stream info structure to be initialized. + * @param pool Pool to allocate memory. + * @param endpt PJMEDIA endpoint instance. + * @param skinfo Optional socket info to be copied to the stream info. + * @param local Local SDP session descriptor. + * @param remote Remote SDP session descriptor. + * @param stream_idx Media stream index in the session descriptor. + * + * @return PJ_SUCCESS if stream info is successfully initialized. + */ +PJ_DECL(pj_status_t) +pjmedia_stream_info_from_sdp( pjmedia_stream_info *si, + pj_pool_t *pool, + pjmedia_endpt *endpt, + const pjmedia_sock_info *skinfo, + const pjmedia_sdp_session *local, + const pjmedia_sdp_session *remote, + unsigned stream_idx); /** * Create media session based on the local and remote SDP. After the session @@ -101,10 +148,6 @@ PJ_DECL(pj_status_t) pjmedia_stream_info_from_sdp( * @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 user_data Arbitrary user data to be kept in the session. @@ -115,10 +158,7 @@ PJ_DECL(pj_status_t) pjmedia_stream_info_from_sdp( */ 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, + const pjmedia_session_info *si, void *user_data, pjmedia_session **p_session ); diff --git a/pjmedia/include/pjmedia/stream.h b/pjmedia/include/pjmedia/stream.h index 41f690bd..335a40e2 100644 --- a/pjmedia/include/pjmedia/stream.h +++ b/pjmedia/include/pjmedia/stream.h @@ -72,16 +72,34 @@ struct pjmedia_stream_info pjmedia_sock_info sock_info; /**< Media transport (RTP/RTCP sockets) */ pj_sockaddr_in rem_addr; /**< Remote RTP address */ pjmedia_codec_info fmt; /**< Incoming codec format info. */ + pjmedia_codec_param *param; /**< Optional codec param. */ unsigned tx_pt; /**< Outgoing codec paylaod type. */ int tx_event_pt;/**< Outgoing pt for telephone-events. */ int rx_event_pt;/**< Incoming pt for telephone-events. */ pj_uint32_t ssrc; /**< RTP SSRC. */ - int jb_init; /**< Jitter buffer init delay in msec. */ + int jb_init; /**< Jitter buffer init delay in msec. + (-1 for default). */ + int jb_min_pre; /**< Jitter buffer minimum prefetch + delay in msec (-1 for default). */ + int jb_max_pre; /**< Jitter buffer maximum prefetch + delay in msec (-1 for default). */ int jb_max; /**< Jitter buffer max delay in msec. */ }; /** + * @see pjmedia_stream_info. + */ +typedef struct pjmedia_stream_info pjmedia_stream_info; + + +/** + * Opaque declaration for media stream. + */ +typedef struct pjmedia_stream pjmedia_stream; + + +/** * Create a media stream based on the specified parameter. After the stream * has been created, application normally would want to get the media port * interface of the streams, by calling pjmedia_stream_get_port(). The diff --git a/pjmedia/include/pjmedia/types.h b/pjmedia/include/pjmedia/types.h index 297e2f8f..f41edeb9 100644 --- a/pjmedia/include/pjmedia/types.h +++ b/pjmedia/include/pjmedia/types.h @@ -114,44 +114,20 @@ typedef struct 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; - -/** - * Media session info. - */ -typedef struct pjmedia_session_info pjmedia_session_info; - -/** - * Types of frame returned from jitter buffer (jbuf.h). + * This is a general purpose function set PCM samples to zero. + * Since this function is needed by many parts of the library, it is important + * that the library should select the best performance for this. + * + * @param samples The 16bit PCM samples. + * @param count Number of samples. */ -typedef enum pjmedia_jb_frame_type pjmedia_jb_frame_type; +PJ_INLINE(void) pjmedia_zero_samples(pj_int16_t *samples, unsigned count) +{ + unsigned i; + for (i=0; i<count; ++i) + samples[i] = 0; +} -/** - * Opaque declaration for jitter buffer. - */ -typedef struct pjmedia_jbuf pjmedia_jbuf; #endif /* __PJMEDIA_TYPES_H__ */ |