summaryrefslogtreecommitdiff
path: root/pjmedia/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-06-22 18:49:45 +0000
committerBenny Prijono <bennylp@teluu.com>2006-06-22 18:49:45 +0000
commit0935d5a1236d6a78e346c22a0b62442eff95bd41 (patch)
tree0d9da39e6fcdc35c9986d12083cd891e57c9b4ec /pjmedia/include
parentdd4c4eb0397a77c84ca6818e2073b374bef79dd1 (diff)
Added better API for media transport, and fixed bugs with pending RTP write operation in UDP media transport
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@539 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/include')
-rw-r--r--pjmedia/include/pjmedia/transport.h133
-rw-r--r--pjmedia/include/pjmedia/transport_udp.h45
2 files changed, 166 insertions, 12 deletions
diff --git a/pjmedia/include/pjmedia/transport.h b/pjmedia/include/pjmedia/transport.h
index 66678d7f..f1d38a90 100644
--- a/pjmedia/include/pjmedia/transport.h
+++ b/pjmedia/include/pjmedia/transport.h
@@ -66,28 +66,37 @@ struct pjmedia_transport_op
* to be used by the stream for the first time, and it tells the transport
* about remote RTP address to send the packet and some callbacks to be
* called for incoming packets.
+ *
+ * Application should call #pjmedia_transport_attach() instead of
+ * calling this function directly.
*/
pj_status_t (*attach)(pjmedia_transport *tp,
- pjmedia_stream *strm,
+ void *user_data,
const pj_sockaddr_t *rem_addr,
unsigned addr_len,
- void (*rtp_cb)(pjmedia_stream*,
- const void*,
- pj_ssize_t),
- void (*rtcp_cb)(pjmedia_stream*,
- const void*,
- pj_ssize_t));
+ void (*rtp_cb)(void *user_data,
+ const void *pkt,
+ pj_ssize_t size),
+ void (*rtcp_cb)(void *user_data,
+ const void *pkt,
+ pj_ssize_t size));
/**
* This function is called by the stream when the stream is no longer
* need the transport (normally when the stream is about to be closed).
+ *
+ * Application should call #pjmedia_transport_detach() instead of
+ * calling this function directly.
*/
void (*detach)(pjmedia_transport *tp,
- pjmedia_stream *strm);
+ void *user_data);
/**
* This function is called by the stream to send RTP packet using the
* transport.
+ *
+ * Application should call #pjmedia_transport_send_rtp() instead of
+ * calling this function directly.
*/
pj_status_t (*send_rtp)(pjmedia_transport *tp,
const void *pkt,
@@ -96,6 +105,9 @@ struct pjmedia_transport_op
/**
* This function is called by the stream to send RTCP packet using the
* transport.
+ *
+ * Application should call #pjmedia_transport_send_rtcp() instead of
+ * calling this function directly.
*/
pj_status_t (*send_rtcp)(pjmedia_transport *tp,
const void *pkt,
@@ -103,6 +115,9 @@ struct pjmedia_transport_op
/**
* This function can be called to destroy this transport.
+ *
+ * Application should call #pjmedia_transport_close() instead of
+ * calling this function directly.
*/
pj_status_t (*destroy)(pjmedia_transport *tp);
};
@@ -129,6 +144,108 @@ struct pjmedia_transport
};
+
+/**
+ * Attach callbacks to be called on receipt of incoming RTP/RTCP packets.
+ * This is just a simple wrapper which calls <tt>attach()</tt> member of
+ * the transport.
+ *
+ * @param tp The media transport.
+ * @param user_data Arbitrary user data to be set when the callbacks are
+ * called.
+ * @param rem_addr Remote RTP address to send RTP packet to.
+ * @param addr_len Length of the remote address.
+ * @param rtp_cb Callback to be called when RTP packet is received on
+ * the transport.
+ * @param rtcp_cb Callback to be called when RTCP packet is received on
+ * the transport.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_INLINE(pj_status_t) pjmedia_transport_attach(pjmedia_transport *tp,
+ void *user_data,
+ const pj_sockaddr_t *rem_addr,
+ unsigned addr_len,
+ void (*rtp_cb)(void *user_data,
+ const void *pkt,
+ pj_ssize_t),
+ void (*rtcp_cb)(void *usr_data,
+ const void*pkt,
+ pj_ssize_t))
+{
+ return tp->op->attach(tp, user_data, rem_addr, addr_len, rtp_cb, rtcp_cb);
+}
+
+
+/**
+ * Detach callbacks from the transport.
+ * This is just a simple wrapper which calls <tt>attach()</tt> member of
+ * the transport.
+ *
+ * @param tp The media transport.
+ * @param user_data User data which must match the previously set value
+ * on attachment.
+ */
+PJ_INLINE(void) pjmedia_transport_detach(pjmedia_transport *tp,
+ void *user_data)
+{
+ tp->op->detach(tp, user_data);
+}
+
+
+/**
+ * Send RTP packet with the specified media transport. This is just a simple
+ * wrapper which calls <tt>send_rtp()</tt> member of the transport.
+ *
+ * @param tp The media transport.
+ * @param pkt The packet to send.
+ * @param size Size of the packet.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_INLINE(pj_status_t) pjmedia_transport_send_rtp(pjmedia_transport *tp,
+ const void *pkt,
+ pj_size_t size)
+{
+ return (*tp->op->send_rtp)(tp, pkt, size);
+}
+
+
+/**
+ * Send RTCP packet with the specified media transport. This is just a simple
+ * wrapper which calls <tt>send_rtcp()</tt> member of the transport.
+ *
+ * @param tp The media transport.
+ * @param pkt The packet to send.
+ * @param size Size of the packet.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_INLINE(pj_status_t) pjmedia_transport_send_rtcp(pjmedia_transport *tp,
+ const void *pkt,
+ pj_size_t size)
+{
+ return (*tp->op->send_rtcp)(tp, pkt, size);
+}
+
+
+/**
+ * Close media transport. This is just a simple wrapper which calls
+ * <tt>destroy()</tt> member of the transport.
+ *
+ * @param tp The media transport.
+ *
+ * @return PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_INLINE(pj_status_t) pjmedia_transport_close(pjmedia_transport *tp)
+{
+ if (tp->op->destroy)
+ return (*tp->op->destroy)(tp);
+ else
+ return PJ_SUCCESS;
+}
+
+
PJ_END_DECL
/**
diff --git a/pjmedia/include/pjmedia/transport_udp.h b/pjmedia/include/pjmedia/transport_udp.h
index 536aeb7a..bf40f83b 100644
--- a/pjmedia/include/pjmedia/transport_udp.h
+++ b/pjmedia/include/pjmedia/transport_udp.h
@@ -56,7 +56,20 @@ enum pjmedia_transport_udp_options
/**
- * Create an RTP and RTCP sockets and bind RTP the socket to the specified
+ * UDP transport info.
+ */
+typedef struct pjmedia_transport_udp_info
+{
+ /**
+ * Media socket info.
+ */
+ pjmedia_sock_info skinfo;
+
+} pjmedia_transport_udp_info;
+
+
+/**
+ * Create an RTP and RTCP sockets and bind the sockets to the specified
* port to create media transport.
*
* @param endpt The media endpoint instance.
@@ -76,15 +89,39 @@ PJ_DECL(pj_status_t) pjmedia_transport_udp_create(pjmedia_endpt *endpt,
/**
+ * Create an RTP and RTCP sockets and bind the sockets to the specified
+ * address and port to create media transport.
+ *
+ * @param endpt The media endpoint instance.
+ * @param name Optional name to be assigned to the transport.
+ * @param addr Optional local address to bind the sockets to. If this
+ * argument is NULL or empty, the sockets will be bound
+ * to all interface.
+ * @param port UDP port number for the RTP socket. The RTCP port number
+ * will be set to one above RTP port.
+ * @param options Options, bitmask of #pjmedia_transport_udp_options.
+ * @param p_tp Pointer to receive the transport instance.
+ *
+ * @return PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_transport_udp_create2(pjmedia_endpt *endpt,
+ const char *name,
+ const pj_str_t *addr,
+ int port,
+ unsigned options,
+ pjmedia_transport **p_tp);
+
+/**
* Get media socket info from the specified UDP transport.
*
* @param tp The UDP transport interface.
- * @param i Media socket info to be initialized.
+ * @param info Media socket info to be initialized.
*
* @return PJ_SUCCESS on success.
*/
-PJ_DECL(pj_status_t) pjmedia_transport_udp_get_sock_info(pjmedia_transport *tp,
- pjmedia_sock_info *i);
+PJ_DECL(pj_status_t)
+pjmedia_transport_udp_get_info( pjmedia_transport *tp,
+ pjmedia_transport_udp_info *info);
/**