Index: pjproject/trunk/pjmedia/include/pjmedia/port.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/port.h	(revision 3553)
+++ pjproject/trunk/pjmedia/include/pjmedia/port.h	(revision 3664)
@@ -25,5 +25,9 @@
  * @brief Port interface declaration
  */
-#include <pjmedia/types.h>
+#include <pjmedia/clock.h>
+#include <pjmedia/event.h>
+#include <pjmedia/format.h>
+#include <pjmedia/frame.h>
+#include <pjmedia/signatures.h>
 #include <pj/assert.h>
 #include <pj/os.h>
@@ -185,4 +189,10 @@
 
 /**
+ * Create 32bit port signature from ASCII characters.
+ */
+#define PJMEDIA_PORT_SIG(a,b,c,d)	    	PJMEDIA_OBJ_SIG(a,b,c,d)
+
+
+/**
  * Port operation setting.
  */
@@ -221,17 +231,131 @@
     pj_str_t	    name;		/**< Port name.			    */
     pj_uint32_t	    signature;		/**< Port signature.		    */
-    pjmedia_type    type;		/**< Media type.		    */
-    pj_bool_t	    has_info;		/**< Has info?			    */
-    pj_bool_t	    need_info;		/**< Need info on connect?	    */
-    unsigned	    pt;			/**< Payload type (can be dynamic). */
-    pjmedia_format  format;		/**< Format.			    */
-    pj_str_t	    encoding_name;	/**< Encoding name.		    */
-    unsigned	    clock_rate;		/**< Sampling rate.		    */
-    unsigned	    channel_count;	/**< Number of channels.	    */
-    unsigned	    bits_per_sample;	/**< Bits/sample		    */
-    unsigned	    samples_per_frame;	/**< No of samples per frame.	    */
-    unsigned	    bytes_per_frame;	/**< No of bytes per frame.	    */
+    pjmedia_dir     dir;                /**< Port direction.                */
+    pjmedia_format  fmt;                /**< Format.		            */
 } pjmedia_port_info;
 
+/**
+ * Utility to retrieve audio clock rate/sampling rate value from
+ * pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Audio clock rate.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_SRATE(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.clock_rate;
+}
+
+/**
+ * Utility to retrieve audio channel count value from pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Audio channel count.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_CCNT(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.channel_count;
+}
+
+/**
+ * Utility to retrieve audio bits per sample value from pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Number of bits per sample.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_BITS(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.bits_per_sample;
+}
+
+/**
+ * Utility to retrieve audio frame interval (ptime) value from
+ * pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Frame interval in msec.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_PTIME(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.frame_time_usec / 1000;
+}
+
+/**
+ * This is a utility routine to retrieve the audio samples_per_frame value
+ * from port info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Samples per frame value.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_SPF(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return PJMEDIA_AFD_SPF(&pia->fmt.det.aud);
+}
+
+/**
+ * This is a utility routine to retrieve the average bitrate value
+ * from port info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Bitrate, in bits per second.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_AVG_BPS(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.avg_bps;
+}
+
+/**
+ * This is a utility routine to retrieve the maximum bitrate value
+ * from port info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Bitrate, in bits per second.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_MAX_BPS(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return pia->fmt.det.aud.max_bps;
+}
+
+/**
+ * This is a utility routine to retrieve the average audio frame size value
+ * from pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Frame size in bytes.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_AVG_FSZ(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return PJMEDIA_AFD_AVG_FSZ(&pia->fmt.det.aud);
+}
+
+/**
+ * Utility to retrieve audio frame size from maximum bitrate from
+ * pjmedia_port_info.
+ *
+ * @param pia		Pointer to port info containing audio format.
+ * @return		Frame size in bytes.
+ */
+PJ_INLINE(unsigned) PJMEDIA_PIA_MAX_FSZ(const pjmedia_port_info *pia)
+{
+    pj_assert(pia->fmt.type==PJMEDIA_TYPE_AUDIO &&
+	      pia->fmt.detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO);
+    return PJMEDIA_AFD_MAX_FSZ(&pia->fmt.det.aud);
+}
 
 /**
@@ -251,9 +375,16 @@
 
     /**
+     * Get clock source.
+     * This should only be called by #pjmedia_port_get_clock_src().
+     */
+    pjmedia_clock_src* (*get_clock_src)(struct pjmedia_port *this_port,
+                                        pjmedia_dir dir);
+
+    /**
      * Sink interface. 
      * This should only be called by #pjmedia_port_put_frame().
      */
     pj_status_t (*put_frame)(struct pjmedia_port *this_port, 
-			     const pjmedia_frame *frame);
+			     pjmedia_frame *frame);
 
     /**
@@ -268,4 +399,9 @@
      */
     pj_status_t (*on_destroy)(struct pjmedia_port *this_port);
+
+    /**
+     * Get event publisher for this media port, if any.
+     */
+    pjmedia_event_publisher *(*get_event_pub)(struct pjmedia_port *this_port);
 
 } pjmedia_port;
@@ -294,4 +430,35 @@
 					     unsigned samples_per_frame);
 
+/**
+ * This is an auxiliary function to initialize port info for
+ * ports which deal with PCM audio.
+ *
+ * @param info		    The port info to be initialized.
+ * @param name		    Port name.
+ * @param signature	    Port signature.
+ * @param dir	            Port's direction.
+ * @param fmt	            Port's media format.
+ *
+ * @return		    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_port_info_init2(pjmedia_port_info *info,
+					     const pj_str_t *name,
+					     unsigned signature,
+					     pjmedia_dir dir,
+					     const pjmedia_format *fmt);
+
+
+/**
+ * Get a clock source from the port.
+ *
+ * @param port	    The media port.
+ * @param dir       Media port's direction.
+ *
+ * @return	    The clock source or NULL if clock source is not present
+ *                  in the port.
+ */
+PJ_DECL(pjmedia_clock_src *) pjmedia_port_get_clock_src( pjmedia_port *port,
+                                                         pjmedia_dir dir );
+
 
 /**
@@ -315,6 +482,16 @@
  */
 PJ_DECL(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
-					     const pjmedia_frame *frame );
-
+					     pjmedia_frame *frame );
+
+/**
+ * Get the event publisher for the media port, if any.
+ *
+ * @param port	    The media port.
+ *
+ * @return	    The event publisher, or NULL if the port does not publish
+ * 		    events.
+ */
+PJ_DECL(pjmedia_event_publisher*)
+pjmedia_port_get_event_publisher(pjmedia_port *port);
 
 /**
