Index: pjproject/branches/projects/2.0-dev/aconfigure
===================================================================
--- pjproject/branches/projects/2.0-dev/aconfigure	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/aconfigure	(revision 3392)
@@ -1,59 +1,82 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for pjproject 1.x.
+# Generated by GNU Autoconf 2.65 for pjproject 1.x.
+#
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+#
+#
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
-## --------------------- ##
-## M4sh Initialization.  ##
-## --------------------- ##
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
 
 # Be more Bourne compatible
 DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
   emulate sh
   NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
   # is contrary to our usage.  Disable this feature.
   alias -g '${1+"$@"}'='"$@"'
   setopt NO_GLOB_SUBST
 else
-  case `(set -o) 2>/dev/null` in
-  *posix*) set -o posix ;;
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
 esac
-
-fi
-
-
-
-
-# PATH needs CR
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
 
 # The user is always right.
 if test "${PATH_SEPARATOR+set}" != set; then
-  echo "#! /bin/sh" >conf$$.sh
-  echo  "exit 0"   >>conf$$.sh
-  chmod +x conf$$.sh
-  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
-    PATH_SEPARATOR=';'
-  else
-    PATH_SEPARATOR=:
-  fi
-  rm -f conf$$.sh
-fi
-
-# Support unset when possible.
-if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
-  as_unset=unset
-else
-  as_unset=false
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
 fi
 
@@ -64,10 +87,8 @@
 # (If _AS_PATH_WALK were called with IFS unset, it would disable word
 # splitting by setting IFS to empty value.)
-as_nl='
-'
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-case $0 in
+case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -76,6 +97,6 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-done
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
 IFS=$as_save_IFS
 
@@ -88,11 +109,15 @@
 fi
 if test ! -f "$as_myself"; then
-  echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  { (exit 1); exit 1; }
-fi
-
-# Work around bugs in pre-3.0 UWIN ksh.
-for as_var in ENV MAIL MAILPATH
-do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
 done
 PS1='$ '
@@ -101,17 +126,251 @@
 
 # NLS nuisances.
-for as_var in \
-  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
-  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
-  LC_TELEPHONE LC_TIME
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
 do
-  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
-    eval $as_var=C; export $as_var
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     # Try only shells that exist, to save several forks.
+	     as_shell=$as_dir/$as_base
+	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+	   done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  # We cannot yet assume a decent shell, so we have to provide a
+	# neutralization value for shells without unset; and this also
+	# works around shells that cannot unset nonexistent variables.
+	BASH_ENV=/dev/null
+	ENV=/dev/null
+	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+	export CONFIG_SHELL
+	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
   else
-    ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+    $as_echo "$0: Please tell bug-autoconf@gnu.org about your system,
+$0: including any error possibly output before this
+$0: message. Then install a modern shell, or manually run
+$0: the script under such a shell if you do have one."
   fi
-done
-
-# Required to use basename.
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with status $?, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
+  fi
+  $as_echo "$as_me: error: $1" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
 if expr a : '\(a\)' >/dev/null 2>&1 &&
    test "X`expr 00001 : '.*\(...\)'`" = X001; then
@@ -127,11 +386,15 @@
 fi
 
-
-# Name of the executable.
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
 as_me=`$as_basename -- "$0" ||
 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 	 X"$0" : 'X\(//\)$' \| \
 	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-echo X/"$0" |
+$as_echo X/"$0" |
     sed '/^.*\/\([^/][^/]*\)\/*$/{
 	    s//\1/
@@ -148,292 +411,17 @@
 	  s/.*/./; q'`
 
-# CDPATH.
-$as_unset CDPATH
-
-
-if test "x$CONFIG_SHELL" = x; then
-  if (eval ":") 2>/dev/null; then
-  as_have_required=yes
-else
-  as_have_required=no
-fi
-
-  if test $as_have_required = yes && 	 (eval ":
-(as_func_return () {
-  (exit \$1)
-}
-as_func_success () {
-  as_func_return 0
-}
-as_func_failure () {
-  as_func_return 1
-}
-as_func_ret_success () {
-  return 0
-}
-as_func_ret_failure () {
-  return 1
-}
-
-exitcode=0
-if as_func_success; then
-  :
-else
-  exitcode=1
-  echo as_func_success failed.
-fi
-
-if as_func_failure; then
-  exitcode=1
-  echo as_func_failure succeeded.
-fi
-
-if as_func_ret_success; then
-  :
-else
-  exitcode=1
-  echo as_func_ret_success failed.
-fi
-
-if as_func_ret_failure; then
-  exitcode=1
-  echo as_func_ret_failure succeeded.
-fi
-
-if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
-  :
-else
-  exitcode=1
-  echo positional parameters were not saved.
-fi
-
-test \$exitcode = 0) || { (exit 1); exit 1; }
-
-(
-  as_lineno_1=\$LINENO
-  as_lineno_2=\$LINENO
-  test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
-  test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
-") 2> /dev/null; then
-  :
-else
-  as_candidate_shells=
-    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  case $as_dir in
-	 /*)
-	   for as_base in sh bash ksh sh5; do
-	     as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
-	   done;;
-       esac
-done
-IFS=$as_save_IFS
-
-
-      for as_shell in $as_candidate_shells $SHELL; do
-	 # Try only shells that exist, to save several forks.
-	 if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
-		{ ("$as_shell") 2> /dev/null <<\_ASEOF
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
-  emulate sh
-  NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '${1+"$@"}'='"$@"'
-  setopt NO_GLOB_SUBST
-else
-  case `(set -o) 2>/dev/null` in
-  *posix*) set -o posix ;;
-esac
-
-fi
-
-
-:
-_ASEOF
-}; then
-  CONFIG_SHELL=$as_shell
-	       as_have_required=yes
-	       if { "$as_shell" 2> /dev/null <<\_ASEOF
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
-  emulate sh
-  NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '${1+"$@"}'='"$@"'
-  setopt NO_GLOB_SUBST
-else
-  case `(set -o) 2>/dev/null` in
-  *posix*) set -o posix ;;
-esac
-
-fi
-
-
-:
-(as_func_return () {
-  (exit $1)
-}
-as_func_success () {
-  as_func_return 0
-}
-as_func_failure () {
-  as_func_return 1
-}
-as_func_ret_success () {
-  return 0
-}
-as_func_ret_failure () {
-  return 1
-}
-
-exitcode=0
-if as_func_success; then
-  :
-else
-  exitcode=1
-  echo as_func_success failed.
-fi
-
-if as_func_failure; then
-  exitcode=1
-  echo as_func_failure succeeded.
-fi
-
-if as_func_ret_success; then
-  :
-else
-  exitcode=1
-  echo as_func_ret_success failed.
-fi
-
-if as_func_ret_failure; then
-  exitcode=1
-  echo as_func_ret_failure succeeded.
-fi
-
-if ( set x; as_func_ret_success y && test x = "$1" ); then
-  :
-else
-  exitcode=1
-  echo positional parameters were not saved.
-fi
-
-test $exitcode = 0) || { (exit 1); exit 1; }
-
-(
-  as_lineno_1=$LINENO
-  as_lineno_2=$LINENO
-  test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; }
-
-_ASEOF
-}; then
-  break
-fi
-
-fi
-
-      done
-
-      if test "x$CONFIG_SHELL" != x; then
-  for as_var in BASH_ENV ENV
-        do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
-        done
-        export CONFIG_SHELL
-        exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
-fi
-
-
-    if test $as_have_required = no; then
-  echo This script requires a shell more modern than all the
-      echo shells that I found on your system.  Please install a
-      echo modern shell, or manually run the script under such a
-      echo shell if you do have one.
-      { (exit 1); exit 1; }
-fi
-
-
-fi
-
-fi
-
-
-
-(eval "as_func_return () {
-  (exit \$1)
-}
-as_func_success () {
-  as_func_return 0
-}
-as_func_failure () {
-  as_func_return 1
-}
-as_func_ret_success () {
-  return 0
-}
-as_func_ret_failure () {
-  return 1
-}
-
-exitcode=0
-if as_func_success; then
-  :
-else
-  exitcode=1
-  echo as_func_success failed.
-fi
-
-if as_func_failure; then
-  exitcode=1
-  echo as_func_failure succeeded.
-fi
-
-if as_func_ret_success; then
-  :
-else
-  exitcode=1
-  echo as_func_ret_success failed.
-fi
-
-if as_func_ret_failure; then
-  exitcode=1
-  echo as_func_ret_failure succeeded.
-fi
-
-if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
-  :
-else
-  exitcode=1
-  echo positional parameters were not saved.
-fi
-
-test \$exitcode = 0") || {
-  echo No shell found that supports shell functions.
-  echo Please tell autoconf@gnu.org about your system,
-  echo including any error possibly output before this
-  echo message
-}
-
-
-
-  as_lineno_1=$LINENO
-  as_lineno_2=$LINENO
-  test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
-
-  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
-  # uniformly replaced by the line number.  The first 'sed' inserts a
-  # line-number line after each line using $LINENO; the second 'sed'
-  # does the real work.  The second script uses 'N' to pair each
-  # line-number line with the line containing $LINENO, and appends
-  # trailing '-' during substitution so that $LINENO is not a special
-  # case at line end.
-  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
-  # scripts with optimization help from Paolo Bonzini.  Blame Lee
-  # E. McMahon (1931-1989) for sed's syntax.  :-)
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
   sed -n '
     p
@@ -452,6 +440,5 @@
     ' >$as_me.lineno &&
   chmod +x "$as_me.lineno" ||
-    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
-   { (exit 1); exit 1; }; }
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
 
   # Don't try to exec as it changes $[0], causing all sort of problems
@@ -463,17 +450,12 @@
 }
 
-
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
-else
-  as_dirname=false
-fi
-
 ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in
+case `echo -n x` in #(((((
 -n*)
-  case `echo 'x\c'` in
+  case `echo 'xy\c'` in
   *c*) ECHO_T='	';;	# ECHO_T is single tab character.
-  *)   ECHO_C='\c';;
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
   esac;;
 *)
@@ -481,11 +463,4 @@
 esac
 
-if expr a : '\(a\)' >/dev/null 2>&1 &&
-   test "X`expr 00001 : '.*\(...\)'`" = X001; then
-  as_expr=expr
-else
-  as_expr=false
-fi
-
 rm -f conf$$ conf$$.exe conf$$.file
 if test -d conf$$.dir; then
@@ -493,17 +468,20 @@
 else
   rm -f conf$$.dir
-  mkdir conf$$.dir
-fi
-echo >conf$$.file
-if ln -s conf$$.file conf$$ 2>/dev/null; then
-  as_ln_s='ln -s'
-  # ... but there are two gotchas:
-  # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
-  # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-  # In both cases, we have to default to `cp -p'.
-  ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
     as_ln_s='cp -p'
-elif ln conf$$.file conf$$ 2>/dev/null; then
-  as_ln_s=ln
+  fi
 else
   as_ln_s='cp -p'
@@ -513,5 +491,5 @@
 
 if mkdir -p . 2>/dev/null; then
-  as_mkdir_p=:
+  as_mkdir_p='mkdir -p "$as_dir"'
 else
   test -d ./-p && rmdir ./-p
@@ -530,10 +508,10 @@
     eval sh -c '\''
       if test -d "$1"; then
-        test -d "$1/.";
+	test -d "$1/.";
       else
-	case $1 in
-        -*)set "./$1";;
+	case $1 in #(
+	-*)set "./$1";;
 	esac;
-	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
 	???[sx]*):;;*)false;;esac;fi
     '\'' sh
@@ -549,6 +527,6 @@
 
 
-
-exec 7<&0 </dev/null 6>&1
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
 
 # Name of the host.
@@ -568,5 +546,4 @@
 MFLAGS=
 MAKEFLAGS=
-SHELL=${CONFIG_SHELL-/bin/sh}
 
 # Identity of this package.
@@ -576,4 +553,5 @@
 PACKAGE_STRING='pjproject 1.x'
 PACKAGE_BUGREPORT=''
+PACKAGE_URL=''
 
 # Factoring default headers for most tests.
@@ -613,108 +591,146 @@
 #endif"
 
-ac_subst_vars='SHELL
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+ac_main_obj
+ac_host
+ac_linux_poll
+ac_cross_compile
+libcrypto_present
+libssl_present
+openssl_h_present
+ac_no_ssl
+ac_v4l2_ldflags
+ac_v4l2_cflags
+ac_ffmpeg_ldflags
+ac_ffmpeg_cflags
+ac_has_ffmpeg
+ac_sdl_ldflags
+ac_sdl_cflags
+ac_no_ilbc_codec
+ac_no_speex_codec
+ac_no_g7221_codec
+ac_no_g722_codec
+ac_no_gsm_codec
+ac_no_l16_codec
+ac_no_g711_codec
+ac_no_speex_aec
+ac_no_large_filter
+ac_no_small_filter
+ac_pa_use_oss
+ac_pa_use_alsa
+ac_pa_cflags
+ac_external_pa
+ac_pjmedia_snd
+ac_external_gsm
+ac_external_speex
+ac_os_objs
+EGREP
+GREP
+CPP
+ac_build_mak_vars
+ac_pjdir
+CC_CFLAGS
+CC_OPTIMIZE
+CC_DEF
+CC_INC
+CC_OUT
+LIBEXT2
+LIBEXT
+RANLIB
+LDOUT
+LD
+AR
+ac_ct_CXX
+CXXFLAGS
+CXX
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+CC
+target_os
+target_vendor
+target_cpu
+target
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
 PATH_SEPARATOR
-PACKAGE_NAME
-PACKAGE_TARNAME
-PACKAGE_VERSION
-PACKAGE_STRING
-PACKAGE_BUGREPORT
-exec_prefix
-prefix
-program_transform_name
-bindir
-sbindir
-libexecdir
-datarootdir
-datadir
-sysconfdir
-sharedstatedir
-localstatedir
-includedir
-oldincludedir
-docdir
-infodir
-htmldir
-dvidir
-pdfdir
-psdir
-libdir
-localedir
-mandir
-DEFS
-ECHO_C
-ECHO_N
-ECHO_T
-LIBS
-build_alias
-host_alias
-target_alias
-build
-build_cpu
-build_vendor
-build_os
-host
-host_cpu
-host_vendor
-host_os
-target
-target_cpu
-target_vendor
-target_os
-CC
-CFLAGS
-LDFLAGS
-CPPFLAGS
-ac_ct_CC
-EXEEXT
-OBJEXT
-CXX
-CXXFLAGS
-ac_ct_CXX
-AR
-LD
-LDOUT
-RANLIB
-LIBEXT
-LIBEXT2
-CC_OUT
-CC_INC
-CC_DEF
-CC_OPTIMIZE
-CC_CFLAGS
-ac_pjdir
-ac_build_mak_vars
-CPP
-GREP
-EGREP
-ac_os_objs
-ac_external_speex
-ac_external_gsm
-ac_pjmedia_snd
-ac_external_pa
-ac_pa_cflags
-ac_pa_use_alsa
-ac_pa_use_oss
-ac_no_small_filter
-ac_no_large_filter
-ac_no_speex_aec
-ac_no_g711_codec
-ac_no_l16_codec
-ac_no_gsm_codec
-ac_no_g722_codec
-ac_no_g7221_codec
-ac_no_speex_codec
-ac_no_ilbc_codec
-ac_no_ssl
-openssl_h_present
-libssl_present
-libcrypto_present
-ac_cross_compile
-ac_linux_poll
-ac_host
-ac_main_obj
-LIBOBJS
-LTLIBOBJS'
+SHELL'
 ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+enable_floating_point
+enable_epoll
+with_external_speex
+with_external_gsm
+enable_sound
+with_external_pa
+enable_oss
+enable_ext_sound
+enable_small_filter
+enable_large_filter
+enable_speex_aec
+enable_g711_codec
+enable_l16_codec
+enable_gsm_codec
+enable_g722_codec
+enable_g7221_codec
+enable_speex_codec
+enable_ilbc_codec
+enable_libsamplerate
+enable_sdl
+enable_ffmpeg
+enable_v4l2
+enable_ipp
+with_ipp
+with_ipp_samples
+with_ipp_arch
+enable_ssl
+'
       ac_precious_vars='build_alias
 host_alias
@@ -734,4 +750,6 @@
 ac_init_help=
 ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
 # The variables have the same names as the options, with
 # dashes changed to underlines.
@@ -832,11 +850,18 @@
 
   -disable-* | --disable-*)
-    ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
-   { (exit 1); exit 1; }; }
-    ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
-    eval enable_$ac_feature=no ;;
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
 
   -docdir | --docdir | --docdi | --doc | --do)
@@ -851,11 +876,18 @@
 
   -enable-* | --enable-*)
-    ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_feature" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
-   { (exit 1); exit 1; }; }
-    ac_feature=`echo $ac_feature | sed 's/[-.]/_/g'`
-    eval enable_$ac_feature=\$ac_optarg ;;
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
 
   -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
@@ -1048,20 +1080,34 @@
 
   -with-* | --with-*)
-    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      { echo "$as_me: error: invalid package name: $ac_package" >&2
-   { (exit 1); exit 1; }; }
-    ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
-    eval with_$ac_package=\$ac_optarg ;;
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
 
   -without-* | --without-*)
-    ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_package" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      { echo "$as_me: error: invalid package name: $ac_package" >&2
-   { (exit 1); exit 1; }; }
-    ac_package=`echo $ac_package | sed 's/[-.]/_/g'`
-    eval with_$ac_package=no ;;
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
 
   --x)
@@ -1083,7 +1129,6 @@
     x_libraries=$ac_optarg ;;
 
-  -*) { echo "$as_me: error: unrecognized option: $ac_option
-Try \`$0 --help' for more information." >&2
-   { (exit 1); exit 1; }; }
+  -*) as_fn_error "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information."
     ;;
 
@@ -1091,7 +1136,8 @@
     ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
     # Reject names that are not valid shell variable names.
-    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
-      { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
-   { (exit 1); exit 1; }; }
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error "invalid variable name: \`$ac_envvar'" ;;
+    esac
     eval $ac_envvar=\$ac_optarg
     export $ac_envvar ;;
@@ -1099,7 +1145,7 @@
   *)
     # FIXME: should be removed in autoconf 3.0.
-    echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
     expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
-      echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
     : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
     ;;
@@ -1110,9 +1156,16 @@
 if test -n "$ac_prev"; then
   ac_option=--`echo $ac_prev | sed 's/_/-/g'`
-  { echo "$as_me: error: missing argument to $ac_option" >&2
-   { (exit 1); exit 1; }; }
-fi
-
-# Be sure to have absolute directory names.
+  as_fn_error "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
@@ -1121,10 +1174,16 @@
 do
   eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
   case $ac_val in
     [\\/$]* | ?:[\\/]* )  continue;;
     NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
   esac
-  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
-   { (exit 1); exit 1; }; }
+  as_fn_error "expected an absolute directory name for --$ac_var: $ac_val"
 done
 
@@ -1140,5 +1199,5 @@
   if test "x$build_alias" = x; then
     cross_compiling=maybe
-    echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
     If a cross compiler is detected then cross compile mode will be used." >&2
   elif test "x$build_alias" != "x$host_alias"; then
@@ -1156,9 +1215,7 @@
 ac_ls_di=`ls -di .` &&
 ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
-  { echo "$as_me: error: Working directory cannot be determined" >&2
-   { (exit 1); exit 1; }; }
+  as_fn_error "working directory cannot be determined"
 test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
-  { echo "$as_me: error: pwd does not report name of working directory" >&2
-   { (exit 1); exit 1; }; }
+  as_fn_error "pwd does not report name of working directory"
 
 
@@ -1167,10 +1224,10 @@
   ac_srcdir_defaulted=yes
   # Try the directory containing this script, then the parent directory.
-  ac_confdir=`$as_dirname -- "$0" ||
-$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$0" : 'X\(//\)[^/]' \| \
-	 X"$0" : 'X\(//\)$' \| \
-	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-echo X"$0" |
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
 	    s//\1/
@@ -1199,11 +1256,9 @@
 if test ! -r "$srcdir/$ac_unique_file"; then
   test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
-  { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
-   { (exit 1); exit 1; }; }
+  as_fn_error "cannot find sources ($ac_unique_file) in $srcdir"
 fi
 ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
 ac_abs_confdir=`(
-	cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2
-   { (exit 1); exit 1; }; }
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg"
 	pwd)`
 # When building in place, set srcdir=.
@@ -1253,7 +1308,7 @@
 Installation directories:
   --prefix=PREFIX         install architecture-independent files in PREFIX
-			  [$ac_default_prefix]
+                          [$ac_default_prefix]
   --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
-			  [PREFIX]
+                          [PREFIX]
 
 By default, \`make install' will install all the files in
@@ -1265,23 +1320,23 @@
 
 Fine tuning of the installation directories:
-  --bindir=DIR           user executables [EPREFIX/bin]
-  --sbindir=DIR          system admin executables [EPREFIX/sbin]
-  --libexecdir=DIR       program executables [EPREFIX/libexec]
-  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
-  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
-  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
-  --libdir=DIR           object code libraries [EPREFIX/lib]
-  --includedir=DIR       C header files [PREFIX/include]
-  --oldincludedir=DIR    C header files for non-gcc [/usr/include]
-  --datarootdir=DIR      read-only arch.-independent data root [PREFIX/share]
-  --datadir=DIR          read-only architecture-independent data [DATAROOTDIR]
-  --infodir=DIR          info documentation [DATAROOTDIR/info]
-  --localedir=DIR        locale-dependent data [DATAROOTDIR/locale]
-  --mandir=DIR           man documentation [DATAROOTDIR/man]
-  --docdir=DIR           documentation root [DATAROOTDIR/doc/pjproject]
-  --htmldir=DIR          html documentation [DOCDIR]
-  --dvidir=DIR           dvi documentation [DOCDIR]
-  --pdfdir=DIR           pdf documentation [DOCDIR]
-  --psdir=DIR            ps documentation [DOCDIR]
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/pjproject]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
 _ACEOF
 
@@ -1302,4 +1357,5 @@
 
 Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
@@ -1309,5 +1365,4 @@
   --disable-sound         Exclude sound (i.e. use null sound)
   --disable-oss           Disable OSS audio (default: not disabled)
-
   --enable-ext-sound      PJMEDIA will not provide any sound device backend
   --disable-small-filter  Exclude small filter in resampling
@@ -1323,4 +1378,7 @@
   --enable-libsamplerate  Link with libsamplerate when available. Note that
                           PJMEDIA_RESAMPLE_IMP must also be configured
+  --disable-sdl           Disable SDL (default: not disabled)
+  --disable-ffmpeg        Disable ffmpeg (default: not disabled)
+  --disable-v4l2          Disable Video4Linux2 (default: not disabled)
   --enable-ipp            Enable Intel IPP support. Specify the Intel IPP
                           package and samples location using IPPROOT and
@@ -1359,5 +1417,5 @@
               nonstandard directory <lib dir>
   LIBS        libraries to pass to the linker, e.g. -l<library>
-  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
               you have headers in a nonstandard directory <include dir>
   CXX         C++ compiler command
@@ -1368,4 +1426,5 @@
 it to find libraries and programs with nonstandard names/locations.
 
+Report bugs to the package provider.
 _ACEOF
 ac_status=$?
@@ -1375,5 +1434,7 @@
   # If there are subdirs, report their specific --help.
   for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
-    test -d "$ac_dir" || continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
     ac_builddir=.
 
@@ -1381,7 +1442,7 @@
 .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
 *)
-  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
   # A ".." for each directory in $ac_dir_suffix.
-  ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
   case $ac_top_builddir_sub in
   "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
@@ -1419,5 +1480,5 @@
       $SHELL "$ac_srcdir/configure" --help=recursive
     else
-      echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
     fi || ac_status=$?
     cd "$ac_pwd" || { ac_status=$?; break; }
@@ -1429,8 +1490,7 @@
   cat <<\_ACEOF
 pjproject configure 1.x
-generated by GNU Autoconf 2.61
-
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+generated by GNU Autoconf 2.65
+
+Copyright (C) 2009 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
@@ -1438,4 +1498,394 @@
   exit
 fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_cxx_try_compile LINENO
+# ----------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_cxx_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+
+} # ac_fn_c_check_func
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
@@ -1443,5 +1893,5 @@
 
 It was created by pjproject $as_me 1.x, which was
-generated by GNU Autoconf 2.61.  Invocation command line was
+generated by GNU Autoconf 2.65.  Invocation command line was
 
   $ $0 $@
@@ -1479,6 +1929,6 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  echo "PATH: $as_dir"
-done
+    $as_echo "PATH: $as_dir"
+  done
 IFS=$as_save_IFS
 
@@ -1514,10 +1964,10 @@
       continue ;;
     *\'*)
-      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
     esac
     case $ac_pass in
-    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
     2)
-      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      as_fn_append ac_configure_args1 " '$ac_arg'"
       if test $ac_must_keep_next = true; then
 	ac_must_keep_next=false # Got value, back to normal.
@@ -1535,11 +1985,11 @@
 	esac
       fi
-      ac_configure_args="$ac_configure_args '$ac_arg'"
+      as_fn_append ac_configure_args " '$ac_arg'"
       ;;
     esac
   done
 done
-$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
-$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
 
 # When interrupted or exit'd, cleanup temporary files, and complete
@@ -1566,10 +2016,11 @@
     *${as_nl}*)
       case $ac_var in #(
-      *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5
-echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;;
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
       esac
       case $ac_var in #(
       _ | IFS | as_nl) ;; #(
-      *) $as_unset $ac_var ;;
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
       esac ;;
     esac
@@ -1600,7 +2051,7 @@
       eval ac_val=\$$ac_var
       case $ac_val in
-      *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
       esac
-      echo "$ac_var='\''$ac_val'\''"
+      $as_echo "$ac_var='\''$ac_val'\''"
     done | sort
     echo
@@ -1617,7 +2068,7 @@
 	eval ac_val=\$$ac_var
 	case $ac_val in
-	*\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
 	esac
-	echo "$ac_var='\''$ac_val'\''"
+	$as_echo "$ac_var='\''$ac_val'\''"
       done | sort
       echo
@@ -1635,6 +2086,6 @@
     fi
     test "$ac_signal" != 0 &&
-      echo "$as_me: caught signal $ac_signal"
-    echo "$as_me: exit $exit_status"
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
   } >&5
   rm -f core *.core core.conftest.* &&
@@ -1643,5 +2094,5 @@
 ' 0
 for ac_signal in 1 2 13 15; do
-  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
 done
 ac_signal=0
@@ -1650,4 +2101,6 @@
 rm -f -r conftest* confdefs.h
 
+$as_echo "/* confdefs.h */" > confdefs.h
+
 # Predefined preprocessor variables.
 
@@ -1656,41 +2109,44 @@
 _ACEOF
 
-
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_TARNAME "$PACKAGE_TARNAME"
 _ACEOF
 
-
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_VERSION "$PACKAGE_VERSION"
 _ACEOF
 
-
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_STRING "$PACKAGE_STRING"
 _ACEOF
 
-
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
 _ACEOF
 
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
 
 # Let the site file select an alternate cache file if it wants to.
-# Prefer explicitly selected file to automatically selected ones.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
 if test -n "$CONFIG_SITE"; then
-  set x "$CONFIG_SITE"
+  ac_site_file1=$CONFIG_SITE
 elif test "x$prefix" != xNONE; then
-  set x "$prefix/share/config.site" "$prefix/etc/config.site"
-else
-  set x "$ac_default_prefix/share/config.site" \
-	"$ac_default_prefix/etc/config.site"
-fi
-shift
-for ac_site_file
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
 do
-  if test -r "$ac_site_file"; then
-    { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
-echo "$as_me: loading site script $ac_site_file" >&6;}
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
     sed 's/^/| /' "$ac_site_file" >&5
     . "$ac_site_file"
@@ -1699,9 +2155,9 @@
 
 if test -r "$cache_file"; then
-  # Some versions of bash will fail to source /dev/null (special
-  # files actually), so we avoid doing that.
-  if test -f "$cache_file"; then
-    { echo "$as_me:$LINENO: loading cache $cache_file" >&5
-echo "$as_me: loading cache $cache_file" >&6;}
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
     case $cache_file in
       [\\/]* | ?:[\\/]* ) . "$cache_file";;
@@ -1710,6 +2166,6 @@
   fi
 else
-  { echo "$as_me:$LINENO: creating cache $cache_file" >&5
-echo "$as_me: creating cache $cache_file" >&6;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
   >$cache_file
 fi
@@ -1725,21 +2181,30 @@
   case $ac_old_set,$ac_new_set in
     set,)
-      { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
-echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
       ac_cache_corrupted=: ;;
     ,set)
-      { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
-echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
       ac_cache_corrupted=: ;;
     ,);;
     *)
       if test "x$ac_old_val" != "x$ac_new_val"; then
-	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
-echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
-	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
-echo "$as_me:   former value:  $ac_old_val" >&2;}
-	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
-echo "$as_me:   current value: $ac_new_val" >&2;}
-	ac_cache_corrupted=:
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
       fi;;
   esac
@@ -1747,44 +2212,23 @@
   if test "$ac_new_set" = set; then
     case $ac_new_val in
-    *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
     *) ac_arg=$ac_var=$ac_new_val ;;
     esac
     case " $ac_configure_args " in
       *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
-      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
     esac
   fi
 done
 if $ac_cache_corrupted; then
-  { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
-echo "$as_me: error: changes in the environment can compromise the build" >&2;}
-  { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
-echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
 
 ac_ext=c
@@ -1800,22 +2244,14 @@
 ac_aux_dir=
 for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
-  if test -f "$ac_dir/install-sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install-sh -c"
-    break
-  elif test -f "$ac_dir/install.sh"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/install.sh -c"
-    break
-  elif test -f "$ac_dir/shtool"; then
-    ac_aux_dir=$ac_dir
-    ac_install_sh="$ac_aux_dir/shtool install -c"
-    break
-  fi
+  for ac_t in install-sh install.sh shtool; do
+    if test -f "$ac_dir/$ac_t"; then
+      ac_aux_dir=$ac_dir
+      ac_install_sh="$ac_aux_dir/$ac_t -c"
+      break 2
+    fi
+  done
 done
 if test -z "$ac_aux_dir"; then
-  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5
-echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;}
-   { (exit 1); exit 1; }; }
+  as_fn_error "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
 fi
 
@@ -1831,12 +2267,10 @@
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
-  { { echo "$as_me:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5
-echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;}
-   { (exit 1); exit 1; }; }
-
-{ echo "$as_me:$LINENO: checking build system type" >&5
-echo $ECHO_N "checking build system type... $ECHO_C" >&6; }
-if test "${ac_cv_build+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+  as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if test "${ac_cv_build+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_build_alias=$build_alias
@@ -1844,20 +2278,14 @@
   ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
 test "x$ac_build_alias" = x &&
-  { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
-echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
-   { (exit 1); exit 1; }; }
+  as_fn_error "cannot guess build type; you must specify one" "$LINENO" 5
 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
-  { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5
-echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;}
-   { (exit 1); exit 1; }; }
-
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_build" >&5
-echo "${ECHO_T}$ac_cv_build" >&6; }
+  as_fn_error "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
 case $ac_cv_build in
 *-*-*) ;;
-*) { { echo "$as_me:$LINENO: error: invalid value of canonical build" >&5
-echo "$as_me: error: invalid value of canonical build" >&2;}
-   { (exit 1); exit 1; }; };;
+*) as_fn_error "invalid value of canonical build" "$LINENO" 5;;
 esac
 build=$ac_cv_build
@@ -1875,8 +2303,8 @@
 
 
-{ echo "$as_me:$LINENO: checking host system type" >&5
-echo $ECHO_N "checking host system type... $ECHO_C" >&6; }
-if test "${ac_cv_host+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if test "${ac_cv_host+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test "x$host_alias" = x; then
@@ -1884,17 +2312,13 @@
 else
   ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
-    { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5
-echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_host" >&5
-echo "${ECHO_T}$ac_cv_host" >&6; }
+    as_fn_error "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
 case $ac_cv_host in
 *-*-*) ;;
-*) { { echo "$as_me:$LINENO: error: invalid value of canonical host" >&5
-echo "$as_me: error: invalid value of canonical host" >&2;}
-   { (exit 1); exit 1; }; };;
+*) as_fn_error "invalid value of canonical host" "$LINENO" 5;;
 esac
 host=$ac_cv_host
@@ -1912,8 +2336,8 @@
 
 
-{ echo "$as_me:$LINENO: checking target system type" >&5
-echo $ECHO_N "checking target system type... $ECHO_C" >&6; }
-if test "${ac_cv_target+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
+$as_echo_n "checking target system type... " >&6; }
+if test "${ac_cv_target+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test "x$target_alias" = x; then
@@ -1921,17 +2345,13 @@
 else
   ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` ||
-    { { echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&5
-echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_target" >&5
-echo "${ECHO_T}$ac_cv_target" >&6; }
+    as_fn_error "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5
+$as_echo "$ac_cv_target" >&6; }
 case $ac_cv_target in
 *-*-*) ;;
-*) { { echo "$as_me:$LINENO: error: invalid value of canonical target" >&5
-echo "$as_me: error: invalid value of canonical target" >&2;}
-   { (exit 1); exit 1; }; };;
+*) as_fn_error "invalid value of canonical target" "$LINENO" 5;;
 esac
 target=$ac_cv_target
@@ -1977,8 +2397,8 @@
   # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
 set dummy ${ac_tool_prefix}gcc; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -1990,12 +2410,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="${ac_tool_prefix}gcc"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2004,9 +2424,9 @@
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2017,8 +2437,8 @@
   # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -2030,12 +2450,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CC="gcc"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2044,9 +2464,9 @@
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-echo "${ECHO_T}$ac_ct_CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2056,10 +2476,6 @@
     case $cross_compiling:$ac_tool_warned in
 yes:)
-{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&5
-echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -2074,8 +2490,8 @@
     # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
 set dummy ${ac_tool_prefix}cc; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2087,12 +2503,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="${ac_tool_prefix}cc"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2101,9 +2517,9 @@
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2114,8 +2530,8 @@
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2128,5 +2544,5 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
@@ -2135,9 +2551,9 @@
      fi
     ac_cv_prog_CC="cc"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2158,9 +2574,9 @@
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2173,8 +2589,8 @@
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -2186,12 +2602,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2200,9 +2616,9 @@
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { echo "$as_me:$LINENO: result: $CC" >&5
-echo "${ECHO_T}$CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2217,8 +2633,8 @@
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -2230,12 +2646,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CC="$ac_prog"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2244,9 +2660,9 @@
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
-echo "${ECHO_T}$ac_ct_CC" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2260,10 +2676,6 @@
     case $cross_compiling:$ac_tool_warned in
 yes:)
-{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&5
-echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -2275,96 +2687,78 @@
 
 
-test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
-See \`config.log' for more details." >&5
-echo "$as_me: error: no acceptable C compiler found in \$PATH
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "no acceptable C compiler found in \$PATH
+See \`config.log' for more details." "$LINENO" 5; }
 
 # Provide some information about the compiler.
-echo "$as_me:$LINENO: checking for C compiler version" >&5
-ac_compiler=`set X $ac_compile; echo $2`
-{ (ac_try="$ac_compiler --version >&5"
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler --version >&5") 2>&5
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
   ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -v >&5"
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler -v >&5") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -V >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler -V >&5") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-ac_clean_files_save=$ac_clean_files
-ac_clean_files="$ac_clean_files a.out a.exe b.out"
-# Try to create an executable without -o first, disregard a.out.
-# It will help us diagnose broken compilers, and finding out an intuition
-# of exeext.
-{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
-echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; }
-ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
-#
-# List of possible output files, starting from the most likely.
-# The algorithm is not robust to junk in `.', hence go to wildcards (a.*)
-# only as a last resort.  b.out is created by i960 compilers.
-ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out'
-#
-# The IRIX 6 linker writes into existing files which may not be
-# executable, retaining their permissions.  Remove them first so a
-# subsequent execution test works.
-ac_rmfiles=
-for ac_file in $ac_files
-do
-  case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;;
-    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
-  esac
-done
-rm -f $ac_rmfiles
-
-if { (ac_try="$ac_link_default"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
   (eval "$ac_link_default") 2>&5
   ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; then
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
   # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
 # So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
@@ -2376,5 +2770,5 @@
   test -f "$ac_file" || continue
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj )
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
 	;;
     [ab].out )
@@ -2383,5 +2777,5 @@
 	break;;
     *.* )
-        if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
 	then :; else
 	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
@@ -2402,76 +2796,40 @@
   ac_file=''
 fi
-
-{ echo "$as_me:$LINENO: result: $ac_file" >&5
-echo "${ECHO_T}$ac_file" >&6; }
-if test -z "$ac_file"; then
-  echo "$as_me: failed program was:" >&5
+if test -z "$ac_file"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-{ { echo "$as_me:$LINENO: error: C compiler cannot create executables
-See \`config.log' for more details." >&5
-echo "$as_me: error: C compiler cannot create executables
-See \`config.log' for more details." >&2;}
-   { (exit 77); exit 77; }; }
-fi
-
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ as_fn_set_status 77
+as_fn_error "C compiler cannot create executables
+See \`config.log' for more details." "$LINENO" 5; }; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
 ac_exeext=$ac_cv_exeext
 
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5
-echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; }
-# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
-# If not cross compiling, check that we can run a simple program.
-if test "$cross_compiling" != yes; then
-  if { ac_try='./$ac_file'
-  { (case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-    cross_compiling=no
-  else
-    if test "$cross_compiling" = maybe; then
-	cross_compiling=yes
-    else
-	{ { echo "$as_me:$LINENO: error: cannot run C compiled programs.
-If you meant to cross compile, use \`--host'.
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot run C compiled programs.
-If you meant to cross compile, use \`--host'.
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-    fi
-  fi
-fi
-{ echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-
-rm -f a.out a.exe conftest$ac_cv_exeext b.out
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
 ac_clean_files=$ac_clean_files_save
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
-echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; }
-{ echo "$as_me:$LINENO: result: $cross_compiling" >&5
-echo "${ECHO_T}$cross_compiling" >&6; }
-
-{ echo "$as_me:$LINENO: checking for suffix of executables" >&5
-echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; }
-if { (ac_try="$ac_link"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
   (eval "$ac_link") 2>&5
   ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; then
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
   # If both `conftest.exe' and `conftest' are `present' (well, observable)
 # catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
@@ -2481,5 +2839,5 @@
   test -f "$ac_file" || continue
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;;
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
     *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
 	  break;;
@@ -2488,33 +2846,24 @@
 done
 else
-  { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-rm -f conftest$ac_cv_exeext
-{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
-echo "${ECHO_T}$ac_cv_exeext" >&6; }
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
 
 rm -f conftest.$ac_ext
 EXEEXT=$ac_cv_exeext
 ac_exeext=$EXEEXT
-{ echo "$as_me:$LINENO: checking for suffix of object files" >&5
-echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; }
-if test "${ac_cv_objext+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
+#include <stdio.h>
 int
 main ()
 {
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
 
   ;
@@ -2522,19 +2871,82 @@
 }
 _ACEOF
-rm -f conftest.o conftest.obj
-if { (ac_try="$ac_compile"
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if test "${ac_cv_objext+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
   (eval "$ac_compile") 2>&5
   ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; then
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
   for ac_file in conftest.o conftest.obj conftest.*; do
   test -f "$ac_file" || continue;
   case $ac_file in
-    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;;
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
     *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
        break;;
@@ -2542,30 +2954,24 @@
 done
 else
-  echo "$as_me: failed program was:" >&5
+  $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
-See \`config.log' for more details." >&5
-echo "$as_me: error: cannot compute suffix of object files: cannot compile
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." "$LINENO" 5; }
+fi
 rm -f conftest.$ac_cv_objext conftest.$ac_ext
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
-echo "${ECHO_T}$ac_cv_objext" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
 OBJEXT=$ac_cv_objext
 ac_objext=$OBJEXT
-{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
-echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; }
-if test "${ac_cv_c_compiler_gnu+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -2581,42 +2987,26 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_compiler_gnu=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_compiler_gnu=no
-fi
-
+  ac_compiler_gnu=no
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_c_compiler_gnu=$ac_compiler_gnu
 
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
-echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; }
-GCC=`test $ac_compiler_gnu = yes && echo yes`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
 ac_test_CFLAGS=${CFLAGS+set}
 ac_save_CFLAGS=$CFLAGS
-{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
-echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; }
-if test "${ac_cv_prog_cc_g+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if test "${ac_cv_prog_cc_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_save_c_werror_flag=$ac_c_werror_flag
@@ -2624,9 +3014,5 @@
    ac_cv_prog_cc_g=no
    CFLAGS="-g"
-   cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -2639,32 +3025,9 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_prog_cc_g=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	CFLAGS=""
-      cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -2677,33 +3040,10 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_c_werror_flag=$ac_save_c_werror_flag
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
 	 CFLAGS="-g"
-	 cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -2716,40 +3056,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_prog_cc_g=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-fi
-
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    ac_c_werror_flag=$ac_save_c_werror_flag
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
-echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
 if test "$ac_test_CFLAGS" = set; then
   CFLAGS=$ac_save_CFLAGS
@@ -2767,16 +3083,12 @@
   fi
 fi
-{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5
-echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; }
-if test "${ac_cv_prog_cc_c89+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if test "${ac_cv_prog_cc_c89+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c89=no
 ac_save_CC=$CC
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdarg.h>
@@ -2835,29 +3147,7 @@
 do
   CC="$ac_save_CC $ac_arg"
-  rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+  if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_prog_cc_c89=$ac_arg
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-fi
-
+fi
 rm -f core conftest.err conftest.$ac_objext
   test "x$ac_cv_prog_cc_c89" != "xno" && break
@@ -2870,15 +3160,17 @@
 case "x$ac_cv_prog_cc_c89" in
   x)
-    { echo "$as_me:$LINENO: result: none needed" >&5
-echo "${ECHO_T}none needed" >&6; } ;;
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
   xno)
-    { echo "$as_me:$LINENO: result: unsupported" >&5
-echo "${ECHO_T}unsupported" >&6; } ;;
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
   *)
     CC="$CC $ac_cv_prog_cc_c89"
-    { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5
-echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;;
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
 esac
-
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
 
 ac_ext=c
@@ -2902,8 +3194,8 @@
     # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_CXX+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_CXX+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$CXX"; then
@@ -2915,12 +3207,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2929,9 +3221,9 @@
 CXX=$ac_cv_prog_CXX
 if test -n "$CXX"; then
-  { echo "$as_me:$LINENO: result: $CXX" >&5
-echo "${ECHO_T}$CXX" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+$as_echo "$CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2946,8 +3238,8 @@
   # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
-{ echo "$as_me:$LINENO: checking for $ac_word" >&5
-echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
-if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CXX"; then
@@ -2959,12 +3251,12 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_exec_ext in '' $ac_executable_extensions; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_CXX="$ac_prog"
-    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-done
+  done
 IFS=$as_save_IFS
 
@@ -2973,9 +3265,9 @@
 ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
 if test -n "$ac_ct_CXX"; then
-  { echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5
-echo "${ECHO_T}$ac_ct_CXX" >&6; }
-else
-  { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5
+$as_echo "$ac_ct_CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
 
@@ -2989,10 +3281,6 @@
     case $cross_compiling:$ac_tool_warned in
 yes:)
-{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&5
-echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools
-whose name does not start with the host triplet.  If you think this
-configuration is useful to you, please write to autoconf@gnu.org." >&2;}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -3004,47 +3292,34 @@
 fi
 # Provide some information about the compiler.
-echo "$as_me:$LINENO: checking for C++ compiler version" >&5
-ac_compiler=`set X $ac_compile; echo $2`
-{ (ac_try="$ac_compiler --version >&5"
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler --version >&5") 2>&5
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
   ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -v >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler -v >&5") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-{ (ac_try="$ac_compiler -V >&5"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compiler -V >&5") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }
-
-{ echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5
-echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6; }
-if test "${ac_cv_cxx_compiler_gnu+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5
+$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; }
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3060,42 +3335,26 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_cxx_try_compile "$LINENO"; then :
   ac_compiler_gnu=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_compiler_gnu=no
-fi
-
+  ac_compiler_gnu=no
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
 
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5
-echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6; }
-GXX=`test $ac_compiler_gnu = yes && echo yes`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5
+$as_echo "$ac_cv_cxx_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GXX=yes
+else
+  GXX=
+fi
 ac_test_CXXFLAGS=${CXXFLAGS+set}
 ac_save_CXXFLAGS=$CXXFLAGS
-{ echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5
-echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6; }
-if test "${ac_cv_prog_cxx_g+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5
+$as_echo_n "checking whether $CXX accepts -g... " >&6; }
+if test "${ac_cv_prog_cxx_g+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_save_cxx_werror_flag=$ac_cxx_werror_flag
@@ -3103,9 +3362,5 @@
    ac_cv_prog_cxx_g=no
    CXXFLAGS="-g"
-   cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3118,32 +3373,9 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_cxx_try_compile "$LINENO"; then :
   ac_cv_prog_cxx_g=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	CXXFLAGS=""
-      cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  CXXFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3156,33 +3388,10 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  ac_cxx_werror_flag=$ac_save_cxx_werror_flag
 	 CXXFLAGS="-g"
-	 cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3195,40 +3404,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_cxx_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_cxx_try_compile "$LINENO"; then :
   ac_cv_prog_cxx_g=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-fi
-
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    ac_cxx_werror_flag=$ac_save_cxx_werror_flag
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5
-echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5
+$as_echo "$ac_cv_prog_cxx_g" >&6; }
 if test "$ac_test_CXXFLAGS" = set; then
   CXXFLAGS=$ac_save_CXXFLAGS
@@ -3308,17 +3493,12 @@
 
 
-
-{ echo "$as_me:$LINENO: checking for pthread_create in -lpthread" >&5
-echo $ECHO_N "checking for pthread_create in -lpthread... $ECHO_C" >&6; }
-if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
+$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
+if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lpthread  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3338,37 +3518,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_pthread_pthread_create=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_pthread_pthread_create=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_pthread_pthread_create=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_pthread_create" >&5
-echo "${ECHO_T}$ac_cv_lib_pthread_pthread_create" >&6; }
-if test $ac_cv_lib_pthread_pthread_create = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
+$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
+if test "x$ac_cv_lib_pthread_pthread_create" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBPTHREAD 1
@@ -3379,17 +3538,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lwsock32" >&5
-echo $ECHO_N "checking for puts in -lwsock32... $ECHO_C" >&6; }
-if test "${ac_cv_lib_wsock32_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lwsock32" >&5
+$as_echo_n "checking for puts in -lwsock32... " >&6; }
+if test "${ac_cv_lib_wsock32_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lwsock32  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3409,37 +3563,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_wsock32_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_wsock32_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_wsock32_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_wsock32_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_wsock32_puts" >&6; }
-if test $ac_cv_lib_wsock32_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wsock32_puts" >&5
+$as_echo "$ac_cv_lib_wsock32_puts" >&6; }
+if test "x$ac_cv_lib_wsock32_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBWSOCK32 1
@@ -3450,17 +3583,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lws2_32" >&5
-echo $ECHO_N "checking for puts in -lws2_32... $ECHO_C" >&6; }
-if test "${ac_cv_lib_ws2_32_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lws2_32" >&5
+$as_echo_n "checking for puts in -lws2_32... " >&6; }
+if test "${ac_cv_lib_ws2_32_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lws2_32  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3480,37 +3608,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_ws2_32_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_ws2_32_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_ws2_32_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_ws2_32_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_ws2_32_puts" >&6; }
-if test $ac_cv_lib_ws2_32_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ws2_32_puts" >&5
+$as_echo "$ac_cv_lib_ws2_32_puts" >&6; }
+if test "x$ac_cv_lib_ws2_32_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBWS2_32 1
@@ -3521,17 +3628,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lole32" >&5
-echo $ECHO_N "checking for puts in -lole32... $ECHO_C" >&6; }
-if test "${ac_cv_lib_ole32_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lole32" >&5
+$as_echo_n "checking for puts in -lole32... " >&6; }
+if test "${ac_cv_lib_ole32_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lole32  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3551,37 +3653,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_ole32_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_ole32_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_ole32_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_ole32_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_ole32_puts" >&6; }
-if test $ac_cv_lib_ole32_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ole32_puts" >&5
+$as_echo "$ac_cv_lib_ole32_puts" >&6; }
+if test "x$ac_cv_lib_ole32_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBOLE32 1
@@ -3592,17 +3673,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lwinmm" >&5
-echo $ECHO_N "checking for puts in -lwinmm... $ECHO_C" >&6; }
-if test "${ac_cv_lib_winmm_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lwinmm" >&5
+$as_echo_n "checking for puts in -lwinmm... " >&6; }
+if test "${ac_cv_lib_winmm_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lwinmm  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3622,37 +3698,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_winmm_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_winmm_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_winmm_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_winmm_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_winmm_puts" >&6; }
-if test $ac_cv_lib_winmm_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_winmm_puts" >&5
+$as_echo "$ac_cv_lib_winmm_puts" >&6; }
+if test "x$ac_cv_lib_winmm_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBWINMM 1
@@ -3663,17 +3718,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lsocket" >&5
-echo $ECHO_N "checking for puts in -lsocket... $ECHO_C" >&6; }
-if test "${ac_cv_lib_socket_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lsocket" >&5
+$as_echo_n "checking for puts in -lsocket... " >&6; }
+if test "${ac_cv_lib_socket_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lsocket  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3693,37 +3743,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_socket_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_socket_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_socket_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_socket_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_socket_puts" >&6; }
-if test $ac_cv_lib_socket_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_puts" >&5
+$as_echo "$ac_cv_lib_socket_puts" >&6; }
+if test "x$ac_cv_lib_socket_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBSOCKET 1
@@ -3734,17 +3763,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lrt" >&5
-echo $ECHO_N "checking for puts in -lrt... $ECHO_C" >&6; }
-if test "${ac_cv_lib_rt_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lrt" >&5
+$as_echo_n "checking for puts in -lrt... " >&6; }
+if test "${ac_cv_lib_rt_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lrt  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3764,37 +3788,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_rt_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_rt_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_rt_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_rt_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_rt_puts" >&6; }
-if test $ac_cv_lib_rt_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_puts" >&5
+$as_echo "$ac_cv_lib_rt_puts" >&6; }
+if test "x$ac_cv_lib_rt_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBRT 1
@@ -3805,17 +3808,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for puts in -lnsl" >&5
-echo $ECHO_N "checking for puts in -lnsl... $ECHO_C" >&6; }
-if test "${ac_cv_lib_nsl_puts+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for puts in -lnsl" >&5
+$as_echo_n "checking for puts in -lnsl... " >&6; }
+if test "${ac_cv_lib_nsl_puts+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lnsl  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3835,37 +3833,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_nsl_puts=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_nsl_puts=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_nsl_puts=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_nsl_puts" >&5
-echo "${ECHO_T}$ac_cv_lib_nsl_puts" >&6; }
-if test $ac_cv_lib_nsl_puts = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_puts" >&5
+$as_echo "$ac_cv_lib_nsl_puts" >&6; }
+if test "x$ac_cv_lib_nsl_puts" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBNSL 1
@@ -3876,17 +3853,12 @@
 fi
 
-
-{ echo "$as_me:$LINENO: checking for uuid_generate in -luuid" >&5
-echo $ECHO_N "checking for uuid_generate in -luuid... $ECHO_C" >&6; }
-if test "${ac_cv_lib_uuid_uuid_generate+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_generate in -luuid" >&5
+$as_echo_n "checking for uuid_generate in -luuid... " >&6; }
+if test "${ac_cv_lib_uuid_uuid_generate+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-luuid  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3906,37 +3878,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_uuid_uuid_generate=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_uuid_uuid_generate=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_uuid_uuid_generate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_uuid_uuid_generate" >&5
-echo "${ECHO_T}$ac_cv_lib_uuid_uuid_generate" >&6; }
-if test $ac_cv_lib_uuid_uuid_generate = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_generate" >&5
+$as_echo "$ac_cv_lib_uuid_uuid_generate" >&6; }
+if test "x$ac_cv_lib_uuid_uuid_generate" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBUUID 1
@@ -3947,16 +3898,12 @@
 fi
 
-{ echo "$as_me:$LINENO: checking for uuid_generate in -luuid" >&5
-echo $ECHO_N "checking for uuid_generate in -luuid... $ECHO_C" >&6; }
-if test "${ac_cv_lib_uuid_uuid_generate+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_generate in -luuid" >&5
+$as_echo_n "checking for uuid_generate in -luuid... " >&6; }
+if test "${ac_cv_lib_uuid_uuid_generate+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-luuid  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -3976,43 +3923,22 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_uuid_uuid_generate=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_uuid_uuid_generate=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_uuid_uuid_generate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_uuid_uuid_generate" >&5
-echo "${ECHO_T}$ac_cv_lib_uuid_uuid_generate" >&6; }
-if test $ac_cv_lib_uuid_uuid_generate = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_generate" >&5
+$as_echo "$ac_cv_lib_uuid_uuid_generate" >&6; }
+if test "x$ac_cv_lib_uuid_uuid_generate" = x""yes; then :
   ac_has_uuid_lib=1
 fi
 
 
-{ echo "$as_me:$LINENO: result: Setting PJ_M_NAME to $target_cpu" >&5
-echo "${ECHO_T}Setting PJ_M_NAME to $target_cpu" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_M_NAME to $target_cpu" >&5
+$as_echo "Setting PJ_M_NAME to $target_cpu" >&6; }
 cat >>confdefs.h <<_ACEOF
 #define PJ_M_NAME "$target_cpu"
@@ -4020,22 +3946,18 @@
 
 
-{ echo "$as_me:$LINENO: checking memory alignment" >&5
-echo $ECHO_N "checking memory alignment... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking memory alignment" >&5
+$as_echo_n "checking memory alignment... " >&6; }
 case $target in
     sparc64-* | ia64-* | x86_64-* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_POOL_ALIGNMENT 8
-_ACEOF
-
-	{ echo "$as_me:$LINENO: result: 8 bytes" >&5
-echo "${ECHO_T}8 bytes" >&6; }
+	$as_echo "#define PJ_POOL_ALIGNMENT 8" >>confdefs.h
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 8 bytes" >&5
+$as_echo "8 bytes" >&6; }
 	;;
     * )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_POOL_ALIGNMENT 4
-_ACEOF
-
-	{ echo "$as_me:$LINENO: result: 4 bytes (default)" >&5
-echo "${ECHO_T}4 bytes (default)" >&6; }
+	$as_echo "#define PJ_POOL_ALIGNMENT 4" >>confdefs.h
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 4 bytes (default)" >&5
+$as_echo "4 bytes (default)" >&6; }
 	;;
 esac
@@ -4047,6 +3969,6 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
-{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
-echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
@@ -4054,6 +3976,6 @@
 fi
 if test -z "$CPP"; then
-  if test "${ac_cv_prog_CPP+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+  if test "${ac_cv_prog_CPP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
       # Double quotes because CPP needs to be expanded
@@ -4069,9 +3991,5 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp. "Syntax error" is here to catch this case.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #ifdef __STDC__
@@ -4082,68 +4000,26 @@
 		     Syntax error
 _ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
   # Broken: fails on valid input.
 continue
 fi
-
 rm -f conftest.err conftest.$ac_ext
 
   # OK, works on sane cases.  Now check whether nonexistent headers
   # can be detected and how.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <ac_nonexistent.h>
 _ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
+if ac_fn_c_try_cpp "$LINENO"; then :
   # Broken: success on invalid input.
 continue
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
   # Passes both tests.
 ac_preproc_ok=:
 break
 fi
-
 rm -f conftest.err conftest.$ac_ext
 
@@ -4151,5 +4027,5 @@
 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
 rm -f conftest.err conftest.$ac_ext
-if $ac_preproc_ok; then
+if $ac_preproc_ok; then :
   break
 fi
@@ -4163,6 +4039,6 @@
   ac_cv_prog_CPP=$CPP
 fi
-{ echo "$as_me:$LINENO: result: $CPP" >&5
-echo "${ECHO_T}$CPP" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
 ac_preproc_ok=false
 for ac_c_preproc_warn_flag in '' yes
@@ -4174,9 +4050,5 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp. "Syntax error" is here to catch this case.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #ifdef __STDC__
@@ -4187,68 +4059,26 @@
 		     Syntax error
 _ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
   # Broken: fails on valid input.
 continue
 fi
-
 rm -f conftest.err conftest.$ac_ext
 
   # OK, works on sane cases.  Now check whether nonexistent headers
   # can be detected and how.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <ac_nonexistent.h>
 _ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
+if ac_fn_c_try_cpp "$LINENO"; then :
   # Broken: success on invalid input.
 continue
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
   # Passes both tests.
 ac_preproc_ok=:
 break
 fi
-
 rm -f conftest.err conftest.$ac_ext
 
@@ -4256,12 +4086,11 @@
 # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
 rm -f conftest.err conftest.$ac_ext
-if $ac_preproc_ok; then
-  :
-else
-  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details." >&5
-echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." "$LINENO" 5; }
 fi
 
@@ -4273,27 +4102,22 @@
 
 
-{ echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5
-echo $ECHO_N "checking for grep that handles long lines and -e... $ECHO_C" >&6; }
-if test "${ac_cv_path_GREP+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  # Extract the first word of "grep ggrep" to use in msg output
-if test -z "$GREP"; then
-set dummy grep ggrep; ac_prog_name=$2
-if test "${ac_cv_path_GREP+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if test "${ac_cv_path_GREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
   ac_path_GREP_found=false
-# Loop through the user's path and test for each of PROGNAME-LIST
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_prog in grep ggrep; do
-  for ac_exec_ext in '' $ac_executable_extensions; do
-    ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
-    { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
-    # Check for GNU ac_path_GREP and select it if it is found.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+# Check for GNU ac_path_GREP and select it if it is found.
   # Check for GNU $ac_path_GREP
 case `"$ac_path_GREP" --version 2>&1` in
@@ -4302,5 +4126,5 @@
 *)
   ac_count=0
-  echo $ECHO_N "0123456789$ECHO_C" >"conftest.in"
+  $as_echo_n 0123456789 >"conftest.in"
   while :
   do
@@ -4308,8 +4132,8 @@
     mv "conftest.tmp" "conftest.in"
     cp "conftest.in" "conftest.nl"
-    echo 'GREP' >> "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
     "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
     diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    ac_count=`expr $ac_count + 1`
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
     if test $ac_count -gt ${ac_path_GREP_max-0}; then
       # Best one so far, save it but keep looking for a better one
@@ -4323,59 +4147,43 @@
 esac
 
-
-    $ac_path_GREP_found && break 3
+      $ac_path_GREP_found && break 3
+    done
   done
-done
-
-done
+  done
 IFS=$as_save_IFS
-
-
-fi
-
-GREP="$ac_cv_path_GREP"
-if test -z "$GREP"; then
-  { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
-echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
 else
   ac_cv_path_GREP=$GREP
 fi
 
-
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5
-echo "${ECHO_T}$ac_cv_path_GREP" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
  GREP="$ac_cv_path_GREP"
 
 
-{ echo "$as_me:$LINENO: checking for egrep" >&5
-echo $ECHO_N "checking for egrep... $ECHO_C" >&6; }
-if test "${ac_cv_path_EGREP+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if test "${ac_cv_path_EGREP+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
    then ac_cv_path_EGREP="$GREP -E"
    else
-     # Extract the first word of "egrep" to use in msg output
-if test -z "$EGREP"; then
-set dummy egrep; ac_prog_name=$2
-if test "${ac_cv_path_EGREP+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
+     if test -z "$EGREP"; then
   ac_path_EGREP_found=false
-# Loop through the user's path and test for each of PROGNAME-LIST
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  for ac_prog in egrep; do
-  for ac_exec_ext in '' $ac_executable_extensions; do
-    ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
-    { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
-    # Check for GNU ac_path_EGREP and select it if it is found.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
   # Check for GNU $ac_path_EGREP
 case `"$ac_path_EGREP" --version 2>&1` in
@@ -4384,5 +4192,5 @@
 *)
   ac_count=0
-  echo $ECHO_N "0123456789$ECHO_C" >"conftest.in"
+  $as_echo_n 0123456789 >"conftest.in"
   while :
   do
@@ -4390,8 +4198,8 @@
     mv "conftest.tmp" "conftest.in"
     cp "conftest.in" "conftest.nl"
-    echo 'EGREP' >> "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
     "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
     diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    ac_count=`expr $ac_count + 1`
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
     if test $ac_count -gt ${ac_path_EGREP_max-0}; then
       # Best one so far, save it but keep looking for a better one
@@ -4405,44 +4213,29 @@
 esac
 
-
-    $ac_path_EGREP_found && break 3
+      $ac_path_EGREP_found && break 3
+    done
   done
-done
-
-done
+  done
 IFS=$as_save_IFS
-
-
-fi
-
-EGREP="$ac_cv_path_EGREP"
-if test -z "$EGREP"; then
-  { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
-echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
 else
   ac_cv_path_EGREP=$EGREP
 fi
 
-
    fi
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5
-echo "${ECHO_T}$ac_cv_path_EGREP" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
  EGREP="$ac_cv_path_EGREP"
 
 
-{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5
-echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdc+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if test "${ac_cv_header_stdc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdlib.h>
@@ -4459,38 +4252,14 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_header_stdc=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_header_stdc=no
-fi
-
+  ac_cv_header_stdc=no
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <string.h>
@@ -4498,10 +4267,10 @@
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "memchr" >/dev/null 2>&1; then
-  :
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
 else
   ac_cv_header_stdc=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
@@ -4509,9 +4278,5 @@
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdlib.h>
@@ -4519,10 +4284,10 @@
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "free" >/dev/null 2>&1; then
-  :
+  $EGREP "free" >/dev/null 2>&1; then :
+
 else
   ac_cv_header_stdc=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
@@ -4530,12 +4295,8 @@
 if test $ac_cv_header_stdc = yes; then
   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
-  if test "$cross_compiling" = yes; then
+  if test "$cross_compiling" = yes; then :
   :
 else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <ctype.h>
@@ -4564,140 +4325,96 @@
 }
 _ACEOF
-rm -f conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  :
-else
-  echo "$as_me: program exited with status $ac_status" >&5
-echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-( exit $ac_status )
-ac_cv_header_stdc=no
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
-fi
-
-
-fi
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
-echo "${ECHO_T}$ac_cv_header_stdc" >&6; }
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
 if test $ac_cv_header_stdc = yes; then
 
-cat >>confdefs.h <<\_ACEOF
-#define STDC_HEADERS 1
-_ACEOF
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
 
 fi
 
 # On IRIX 5.3, sys/types and inttypes.h are conflicting.
-
-
-
-
-
-
-
-
-
 for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
 		  inttypes.h stdint.h unistd.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-{ echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
-if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+eval as_val=\$$as_ac_Header
+   if test "x$as_val" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
+$as_echo_n "checking whether byte ordering is bigendian... " >&6; }
+if test "${ac_cv_c_bigendian+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_bigendian=unknown
+    # See if we're dealing with a universal compiler.
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-$ac_includes_default
-
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  eval "$as_ac_Header=yes"
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	eval "$as_ac_Header=no"
-fi
-
+#ifndef __APPLE_CC__
+	       not a universal capable compiler
+	     #endif
+	     typedef int dummy;
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+	# Check for potential -arch flags.  It is not universal unless
+	# there are at least two -arch flags with different values.
+	ac_arch=
+	ac_prev=
+	for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
+	 if test -n "$ac_prev"; then
+	   case $ac_word in
+	     i?86 | x86_64 | ppc | ppc64)
+	       if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
+		 ac_arch=$ac_word
+	       else
+		 ac_cv_c_bigendian=universal
+		 break
+	       fi
+	       ;;
+	   esac
+	   ac_prev=
+	 elif test "x$ac_word" = "x-arch"; then
+	   ac_prev=arch
+	 fi
+       done
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-ac_res=`eval echo '${'$as_ac_Header'}'`
-	       { echo "$as_me:$LINENO: result: $ac_res" >&5
-echo "${ECHO_T}$ac_res" >&6; }
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-{ echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
-echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6; }
-if test "${ac_cv_c_bigendian+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  # See if sys/param.h defines the BYTE_ORDER macro.
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if sys/param.h defines the BYTE_ORDER macro.
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
-#include <sys/param.h>
+	     #include <sys/param.h>
 
 int
 main ()
 {
-#if  ! (defined BYTE_ORDER && defined BIG_ENDIAN && defined LITTLE_ENDIAN \
-	&& BYTE_ORDER && BIG_ENDIAN && LITTLE_ENDIAN)
- bogus endian macros
-#endif
+#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
+		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
+		     && LITTLE_ENDIAN)
+	      bogus endian macros
+	     #endif
 
   ;
@@ -4705,30 +4422,10 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   # It does; now see whether it defined to BIG_ENDIAN or not.
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
-#include <sys/param.h>
+		#include <sys/param.h>
 
 int
@@ -4736,6 +4433,6 @@
 {
 #if BYTE_ORDER != BIG_ENDIAN
- not big endian
-#endif
+		 not big endian
+		#endif
 
   ;
@@ -4743,100 +4440,102 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_c_bigendian=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_c_bigendian=no
-fi
-
+  ac_cv_c_bigendian=no
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	# It does not; compile a test program.
-if test "$cross_compiling" = yes; then
-  # try to guess the endianness by grepping values into an object file
-  ac_cv_c_bigendian=unknown
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
-short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
-void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
-short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
-short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
-void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }
+#include <limits.h>
+
 int
 main ()
 {
- _ascii (); _ebcdic ();
+#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
+	      bogus endian macros
+	     #endif
+
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
+if ac_fn_c_try_compile "$LINENO"; then :
+  # It does; now see whether it defined to _BIG_ENDIAN or not.
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <limits.h>
+
+int
+main ()
+{
+#ifndef _BIG_ENDIAN
+		 not big endian
+		#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
   ac_cv_c_bigendian=yes
-fi
-if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
-  if test "$ac_cv_c_bigendian" = unknown; then
-    ac_cv_c_bigendian=no
-  else
-    # finding both strings is unlikely to happen, but who knows?
-    ac_cv_c_bigendian=unknown
-  fi
-fi
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-fi
-
+else
+  ac_cv_c_bigendian=no
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # Compile a test program.
+      if test "$cross_compiling" = yes; then :
+  # Try to guess by grepping values from an object file.
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+short int ascii_mm[] =
+		  { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+		short int ascii_ii[] =
+		  { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+		int use_ascii (int i) {
+		  return ascii_mm[i] + ascii_ii[i];
+		}
+		short int ebcdic_ii[] =
+		  { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+		short int ebcdic_mm[] =
+		  { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+		int use_ebcdic (int i) {
+		  return ebcdic_mm[i] + ebcdic_ii[i];
+		}
+		extern int foo;
+
+int
+main ()
+{
+return use_ascii (foo) == use_ebcdic (foo);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
+	      ac_cv_c_bigendian=yes
+	    fi
+	    if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+	      if test "$ac_cv_c_bigendian" = unknown; then
+		ac_cv_c_bigendian=no
+	      else
+		# finding both strings is unlikely to happen, but who knows?
+		ac_cv_c_bigendian=unknown
+	      fi
+	    fi
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 $ac_includes_default
@@ -4845,12 +4544,12 @@
 {
 
-  /* Are we little or big endian?  From Harbison&Steele.  */
-  union
-  {
-    long int l;
-    char c[sizeof (long int)];
-  } u;
-  u.l = 1;
-  return u.c[sizeof (long int) - 1] == 1;
+	     /* Are we little or big endian?  From Harbison&Steele.  */
+	     union
+	     {
+	       long int l;
+	       char c[sizeof (long int)];
+	     } u;
+	     u.l = 1;
+	     return u.c[sizeof (long int) - 1] == 1;
 
   ;
@@ -4858,98 +4557,57 @@
 }
 _ACEOF
-rm -f conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
-  { (case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
+if ac_fn_c_try_run "$LINENO"; then :
   ac_cv_c_bigendian=no
 else
-  echo "$as_me: program exited with status $ac_status" >&5
-echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-( exit $ac_status )
-ac_cv_c_bigendian=yes
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
-fi
-
-
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
-echo "${ECHO_T}$ac_cv_c_bigendian" >&6; }
-case $ac_cv_c_bigendian in
-  yes)
-
-cat >>confdefs.h <<\_ACEOF
-#define WORDS_BIGENDIAN 1
-_ACEOF
- ;;
-  no)
-     ;;
-  *)
-    { { echo "$as_me:$LINENO: error: unknown endianness
-presetting ac_cv_c_bigendian=no (or yes) will help" >&5
-echo "$as_me: error: unknown endianness
-presetting ac_cv_c_bigendian=no (or yes) will help" >&2;}
-   { (exit 1); exit 1; }; } ;;
-esac
+  ac_cv_c_bigendian=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+    fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
+$as_echo "$ac_cv_c_bigendian" >&6; }
+ case $ac_cv_c_bigendian in #(
+   yes)
+     $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h
+;; #(
+   no)
+      ;; #(
+   universal)
+
+$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
+
+     ;; #(
+   *)
+     as_fn_error "unknown endianness
+ presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
+ esac
 
 
 case $target in
     *mingw* | *cygw* | *win32* | *w32* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_WIN32 1
-_ACEOF
-
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_WIN32_WINNT 0x0400
-_ACEOF
-
-	cat >>confdefs.h <<\_ACEOF
-#define WIN32_LEAN_AND_MEAN 1
-_ACEOF
+	$as_echo "#define PJ_WIN32 1" >>confdefs.h
+
+	$as_echo "#define PJ_WIN32_WINNT 0x0400" >>confdefs.h
+
+	$as_echo "#define WIN32_LEAN_AND_MEAN 1" >>confdefs.h
 
 	;;
     *darwin*)
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_DARWINOS 1
-_ACEOF
+	$as_echo "#define PJ_DARWINOS 1" >>confdefs.h
 
 	;;
     *linux*)
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_LINUX 1
-_ACEOF
+	$as_echo "#define PJ_LINUX 1" >>confdefs.h
 
 	;;
     *rtems*)
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_RTEMS 1
-_ACEOF
+	$as_echo "#define PJ_RTEMS 1" >>confdefs.h
 
 	;;
     *sunos* | *solaris* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_SUNOS 1
-_ACEOF
+	$as_echo "#define PJ_SUNOS 1" >>confdefs.h
 
 	;;
@@ -4962,34 +4620,25 @@
 
 # Check whether --enable-floating-point was given.
-if test "${enable_floating_point+set}" = set; then
+if test "${enable_floating_point+set}" = set; then :
   enableval=$enable_floating_point; if test "$enable_floating_point" = "no"; then
-		cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_FLOATING_POINT 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if floating point is disabled... yes" >&5
-echo "${ECHO_T}Checking if floating point is disabled... yes" >&6; }
+		$as_echo "#define PJ_HAS_FLOATING_POINT 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if floating point is disabled... yes" >&5
+$as_echo "Checking if floating point is disabled... yes" >&6; }
 	       fi
 else
 
-		cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_FLOATING_POINT 1
-_ACEOF
-
-	        { echo "$as_me:$LINENO: result: Checking if floating point is disabled... no" >&5
-echo "${ECHO_T}Checking if floating point is disabled... no" >&6; }
-
-{ echo "$as_me:$LINENO: checking for fmod in -lm" >&5
-echo $ECHO_N "checking for fmod in -lm... $ECHO_C" >&6; }
-if test "${ac_cv_lib_m_fmod+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+		$as_echo "#define PJ_HAS_FLOATING_POINT 1" >>confdefs.h
+
+	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if floating point is disabled... no" >&5
+$as_echo "Checking if floating point is disabled... no" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmod in -lm" >&5
+$as_echo_n "checking for fmod in -lm... " >&6; }
+if test "${ac_cv_lib_m_fmod+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lm  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -5009,37 +4658,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_m_fmod=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_m_fmod=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_m_fmod=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_m_fmod" >&5
-echo "${ECHO_T}$ac_cv_lib_m_fmod" >&6; }
-if test $ac_cv_lib_m_fmod = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_fmod" >&5
+$as_echo "$ac_cv_lib_m_fmod" >&6; }
+if test "x$ac_cv_lib_m_fmod" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBM 1
@@ -5055,399 +4683,21 @@
 
 
-if test "${ac_cv_header_arpa_inet_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for arpa/inet.h" >&5
-echo $ECHO_N "checking for arpa/inet.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_arpa_inet_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_arpa_inet_h" >&5
-echo "${ECHO_T}$ac_cv_header_arpa_inet_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking arpa/inet.h usability" >&5
-echo $ECHO_N "checking arpa/inet.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <arpa/inet.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking arpa/inet.h presence" >&5
-echo $ECHO_N "checking arpa/inet.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <arpa/inet.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: arpa/inet.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: arpa/inet.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: arpa/inet.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: arpa/inet.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: arpa/inet.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: arpa/inet.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: arpa/inet.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: arpa/inet.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: arpa/inet.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for arpa/inet.h" >&5
-echo $ECHO_N "checking for arpa/inet.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_arpa_inet_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_arpa_inet_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_arpa_inet_h" >&5
-echo "${ECHO_T}$ac_cv_header_arpa_inet_h" >&6; }
-
-fi
-if test $ac_cv_header_arpa_inet_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_ARPA_INET_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_assert_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for assert.h" >&5
-echo $ECHO_N "checking for assert.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_assert_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_assert_h" >&5
-echo "${ECHO_T}$ac_cv_header_assert_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking assert.h usability" >&5
-echo $ECHO_N "checking assert.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <assert.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking assert.h presence" >&5
-echo $ECHO_N "checking assert.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <assert.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: assert.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: assert.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: assert.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: assert.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: assert.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: assert.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: assert.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: assert.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: assert.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: assert.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: assert.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for assert.h" >&5
-echo $ECHO_N "checking for assert.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_assert_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_assert_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_assert_h" >&5
-echo "${ECHO_T}$ac_cv_header_assert_h" >&6; }
-
-fi
-if test $ac_cv_header_assert_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_ASSERT_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_ctype_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for ctype.h" >&5
-echo $ECHO_N "checking for ctype.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ctype_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ctype_h" >&5
-echo "${ECHO_T}$ac_cv_header_ctype_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking ctype.h usability" >&5
-echo $ECHO_N "checking ctype.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <ctype.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking ctype.h presence" >&5
-echo $ECHO_N "checking ctype.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ctype.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: ctype.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: ctype.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: ctype.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: ctype.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: ctype.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: ctype.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: ctype.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: ctype.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: ctype.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ctype.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: ctype.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for ctype.h" >&5
-echo $ECHO_N "checking for ctype.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ctype_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_ctype_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ctype_h" >&5
-echo "${ECHO_T}$ac_cv_header_ctype_h" >&6; }
-
-fi
-if test $ac_cv_header_ctype_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_CTYPE_H 1
-_ACEOF
+ac_fn_c_check_header_mongrel "$LINENO" "arpa/inet.h" "ac_cv_header_arpa_inet_h" "$ac_includes_default"
+if test "x$ac_cv_header_arpa_inet_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_ARPA_INET_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "assert.h" "ac_cv_header_assert_h" "$ac_includes_default"
+if test "x$ac_cv_header_assert_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_ASSERT_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "ctype.h" "ac_cv_header_ctype_h" "$ac_includes_default"
+if test "x$ac_cv_header_ctype_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_CTYPE_H 1" >>confdefs.h
 
 fi
@@ -5457,139 +4707,11 @@
 case $target in
     *mingw* | *cygw* | *win32* | *w32* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_ERRNO_H 0
-_ACEOF
+	$as_echo "#define PJ_HAS_ERRNO_H 0" >>confdefs.h
 
 	;;
     *)
-	if test "${ac_cv_header_errno_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for errno.h" >&5
-echo $ECHO_N "checking for errno.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_errno_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_errno_h" >&5
-echo "${ECHO_T}$ac_cv_header_errno_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking errno.h usability" >&5
-echo $ECHO_N "checking errno.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <errno.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking errno.h presence" >&5
-echo $ECHO_N "checking errno.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <errno.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: errno.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: errno.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: errno.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: errno.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: errno.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: errno.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: errno.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: errno.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: errno.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: errno.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: errno.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for errno.h" >&5
-echo $ECHO_N "checking for errno.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_errno_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_errno_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_errno_h" >&5
-echo "${ECHO_T}$ac_cv_header_errno_h" >&6; }
-
-fi
-if test $ac_cv_header_errno_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_ERRNO_H 1
-_ACEOF
+	ac_fn_c_check_header_mongrel "$LINENO" "errno.h" "ac_cv_header_errno_h" "$ac_includes_default"
+if test "x$ac_cv_header_errno_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_ERRNO_H 1" >>confdefs.h
 
 fi
@@ -5599,814 +4721,47 @@
 esac
 
-if test "${ac_cv_header_fcntl_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for fcntl.h" >&5
-echo $ECHO_N "checking for fcntl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_fcntl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_fcntl_h" >&5
-echo "${ECHO_T}$ac_cv_header_fcntl_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking fcntl.h usability" >&5
-echo $ECHO_N "checking fcntl.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <fcntl.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking fcntl.h presence" >&5
-echo $ECHO_N "checking fcntl.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <fcntl.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: fcntl.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: fcntl.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: fcntl.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: fcntl.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: fcntl.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: fcntl.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: fcntl.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: fcntl.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: fcntl.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for fcntl.h" >&5
-echo $ECHO_N "checking for fcntl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_fcntl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_fcntl_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_fcntl_h" >&5
-echo "${ECHO_T}$ac_cv_header_fcntl_h" >&6; }
-
-fi
-if test $ac_cv_header_fcntl_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_FCNTL_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_linux_socket_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for linux/socket.h" >&5
-echo $ECHO_N "checking for linux/socket.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_linux_socket_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_linux_socket_h" >&5
-echo "${ECHO_T}$ac_cv_header_linux_socket_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking linux/socket.h usability" >&5
-echo $ECHO_N "checking linux/socket.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <linux/socket.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking linux/socket.h presence" >&5
-echo $ECHO_N "checking linux/socket.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <linux/socket.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: linux/socket.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: linux/socket.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: linux/socket.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: linux/socket.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: linux/socket.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: linux/socket.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: linux/socket.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/socket.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: linux/socket.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for linux/socket.h" >&5
-echo $ECHO_N "checking for linux/socket.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_linux_socket_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_linux_socket_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_linux_socket_h" >&5
-echo "${ECHO_T}$ac_cv_header_linux_socket_h" >&6; }
-
-fi
-if test $ac_cv_header_linux_socket_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_LINUX_SOCKET_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_malloc_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for malloc.h" >&5
-echo $ECHO_N "checking for malloc.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_malloc_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_malloc_h" >&5
-echo "${ECHO_T}$ac_cv_header_malloc_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking malloc.h usability" >&5
-echo $ECHO_N "checking malloc.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <malloc.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking malloc.h presence" >&5
-echo $ECHO_N "checking malloc.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <malloc.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: malloc.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: malloc.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: malloc.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: malloc.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: malloc.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: malloc.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: malloc.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: malloc.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: malloc.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: malloc.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: malloc.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for malloc.h" >&5
-echo $ECHO_N "checking for malloc.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_malloc_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_malloc_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_malloc_h" >&5
-echo "${ECHO_T}$ac_cv_header_malloc_h" >&6; }
-
-fi
-if test $ac_cv_header_malloc_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_MALLOC_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_netdb_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for netdb.h" >&5
-echo $ECHO_N "checking for netdb.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netdb_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netdb_h" >&5
-echo "${ECHO_T}$ac_cv_header_netdb_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking netdb.h usability" >&5
-echo $ECHO_N "checking netdb.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <netdb.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking netdb.h presence" >&5
-echo $ECHO_N "checking netdb.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <netdb.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: netdb.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: netdb.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: netdb.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: netdb.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: netdb.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: netdb.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: netdb.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: netdb.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: netdb.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netdb.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: netdb.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for netdb.h" >&5
-echo $ECHO_N "checking for netdb.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netdb_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_netdb_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netdb_h" >&5
-echo "${ECHO_T}$ac_cv_header_netdb_h" >&6; }
-
-fi
-if test $ac_cv_header_netdb_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NETDB_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_netinet_in_systm_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for netinet/in_systm.h" >&5
-echo $ECHO_N "checking for netinet/in_systm.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_in_systm_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_in_systm_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_in_systm_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking netinet/in_systm.h usability" >&5
-echo $ECHO_N "checking netinet/in_systm.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <netinet/in_systm.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking netinet/in_systm.h presence" >&5
-echo $ECHO_N "checking netinet/in_systm.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <netinet/in_systm.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: netinet/in_systm.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: netinet/in_systm.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in_systm.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: netinet/in_systm.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for netinet/in_systm.h" >&5
-echo $ECHO_N "checking for netinet/in_systm.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_in_systm_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_netinet_in_systm_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_in_systm_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_in_systm_h" >&6; }
-
-fi
-if test $ac_cv_header_netinet_in_systm_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NETINET_IN_SYSTM_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_netinet_in_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for netinet/in.h" >&5
-echo $ECHO_N "checking for netinet/in.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_in_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_in_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_in_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking netinet/in.h usability" >&5
-echo $ECHO_N "checking netinet/in.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <netinet/in.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking netinet/in.h presence" >&5
-echo $ECHO_N "checking netinet/in.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <netinet/in.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: netinet/in.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: netinet/in.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: netinet/in.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: netinet/in.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: netinet/in.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: netinet/in.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: netinet/in.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/in.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: netinet/in.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for netinet/in.h" >&5
-echo $ECHO_N "checking for netinet/in.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_in_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_netinet_in_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_in_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_in_h" >&6; }
-
-fi
-if test $ac_cv_header_netinet_in_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NETINET_IN_H 1
-_ACEOF
-
-fi
-
-
-{ echo "$as_me:$LINENO: checking for netinet/ip.h" >&5
-echo $ECHO_N "checking for netinet/ip.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_ip_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#if PJ_HAS_SYS_TYPES_H
+ac_fn_c_check_header_mongrel "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default"
+if test "x$ac_cv_header_fcntl_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_FCNTL_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "linux/socket.h" "ac_cv_header_linux_socket_h" "$ac_includes_default"
+if test "x$ac_cv_header_linux_socket_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_LINUX_SOCKET_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "malloc.h" "ac_cv_header_malloc_h" "$ac_includes_default"
+if test "x$ac_cv_header_malloc_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_MALLOC_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "netdb.h" "ac_cv_header_netdb_h" "$ac_includes_default"
+if test "x$ac_cv_header_netdb_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NETDB_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "netinet/in_systm.h" "ac_cv_header_netinet_in_systm_h" "$ac_includes_default"
+if test "x$ac_cv_header_netinet_in_systm_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NETINET_IN_SYSTM_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "netinet/in.h" "ac_cv_header_netinet_in_h" "$ac_includes_default"
+if test "x$ac_cv_header_netinet_in_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NETINET_IN_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_compile "$LINENO" "netinet/ip.h" "ac_cv_header_netinet_ip_h" "#if PJ_HAS_SYS_TYPES_H
           	  #	include <sys/types.h>
           	  #endif
@@ -6418,3066 +4773,170 @@
           	  #endif
 
-
-#include <netinet/ip.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_cv_header_netinet_ip_h=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_header_netinet_ip_h=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_ip_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_ip_h" >&6; }
-if test $ac_cv_header_netinet_ip_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NETINET_IP_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_netinet_tcp_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for netinet/tcp.h" >&5
-echo $ECHO_N "checking for netinet/tcp.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_tcp_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_tcp_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_tcp_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking netinet/tcp.h usability" >&5
-echo $ECHO_N "checking netinet/tcp.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <netinet/tcp.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking netinet/tcp.h presence" >&5
-echo $ECHO_N "checking netinet/tcp.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <netinet/tcp.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: netinet/tcp.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: netinet/tcp.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: netinet/tcp.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: netinet/tcp.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: netinet/tcp.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: netinet/tcp.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: netinet/tcp.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: netinet/tcp.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: netinet/tcp.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for netinet/tcp.h" >&5
-echo $ECHO_N "checking for netinet/tcp.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_netinet_tcp_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_netinet_tcp_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_netinet_tcp_h" >&5
-echo "${ECHO_T}$ac_cv_header_netinet_tcp_h" >&6; }
-
-fi
-if test $ac_cv_header_netinet_tcp_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NETINET_TCP_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_ifaddrs_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for ifaddrs.h" >&5
-echo $ECHO_N "checking for ifaddrs.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ifaddrs_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ifaddrs_h" >&5
-echo "${ECHO_T}$ac_cv_header_ifaddrs_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking ifaddrs.h usability" >&5
-echo $ECHO_N "checking ifaddrs.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <ifaddrs.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking ifaddrs.h presence" >&5
-echo $ECHO_N "checking ifaddrs.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ifaddrs.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: ifaddrs.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: ifaddrs.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: ifaddrs.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: ifaddrs.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: ifaddrs.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: ifaddrs.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: ifaddrs.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ifaddrs.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: ifaddrs.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for ifaddrs.h" >&5
-echo $ECHO_N "checking for ifaddrs.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ifaddrs_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_ifaddrs_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ifaddrs_h" >&5
-echo "${ECHO_T}$ac_cv_header_ifaddrs_h" >&6; }
-
-fi
-if test $ac_cv_header_ifaddrs_h = yes; then
-  { echo "$as_me:$LINENO: checking for getifaddrs" >&5
-echo $ECHO_N "checking for getifaddrs... $ECHO_C" >&6; }
-if test "${ac_cv_func_getifaddrs+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-/* Define getifaddrs to an innocuous variant, in case <limits.h> declares getifaddrs.
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
-#define getifaddrs innocuous_getifaddrs
-
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char getifaddrs (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-
-#undef getifaddrs
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char getifaddrs ();
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined __stub_getifaddrs || defined __stub___getifaddrs
-choke me
-#endif
-
-int
-main ()
-{
-return getifaddrs ();
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
-  ac_cv_func_getifaddrs=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_func_getifaddrs=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_func_getifaddrs" >&5
-echo "${ECHO_T}$ac_cv_func_getifaddrs" >&6; }
-if test $ac_cv_func_getifaddrs = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_IFADDRS_H 1
-_ACEOF
-
-fi
-
-fi
-
-
-if test "${ac_cv_header_semaphore_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for semaphore.h" >&5
-echo $ECHO_N "checking for semaphore.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_semaphore_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_semaphore_h" >&5
-echo "${ECHO_T}$ac_cv_header_semaphore_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking semaphore.h usability" >&5
-echo $ECHO_N "checking semaphore.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <semaphore.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking semaphore.h presence" >&5
-echo $ECHO_N "checking semaphore.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <semaphore.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: semaphore.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: semaphore.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: semaphore.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: semaphore.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: semaphore.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: semaphore.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: semaphore.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: semaphore.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: semaphore.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for semaphore.h" >&5
-echo $ECHO_N "checking for semaphore.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_semaphore_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_semaphore_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_semaphore_h" >&5
-echo "${ECHO_T}$ac_cv_header_semaphore_h" >&6; }
-
-fi
-if test $ac_cv_header_semaphore_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SEMAPHORE_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_setjmp_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for setjmp.h" >&5
-echo $ECHO_N "checking for setjmp.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_setjmp_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_setjmp_h" >&5
-echo "${ECHO_T}$ac_cv_header_setjmp_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking setjmp.h usability" >&5
-echo $ECHO_N "checking setjmp.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <setjmp.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking setjmp.h presence" >&5
-echo $ECHO_N "checking setjmp.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <setjmp.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: setjmp.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: setjmp.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: setjmp.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: setjmp.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: setjmp.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: setjmp.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: setjmp.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: setjmp.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: setjmp.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for setjmp.h" >&5
-echo $ECHO_N "checking for setjmp.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_setjmp_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_setjmp_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_setjmp_h" >&5
-echo "${ECHO_T}$ac_cv_header_setjmp_h" >&6; }
-
-fi
-if test $ac_cv_header_setjmp_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SETJMP_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_stdarg_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for stdarg.h" >&5
-echo $ECHO_N "checking for stdarg.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdarg_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdarg_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdarg_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking stdarg.h usability" >&5
-echo $ECHO_N "checking stdarg.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <stdarg.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking stdarg.h presence" >&5
-echo $ECHO_N "checking stdarg.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdarg.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: stdarg.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: stdarg.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: stdarg.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: stdarg.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: stdarg.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: stdarg.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: stdarg.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdarg.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: stdarg.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for stdarg.h" >&5
-echo $ECHO_N "checking for stdarg.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdarg_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_stdarg_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdarg_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdarg_h" >&6; }
-
-fi
-if test $ac_cv_header_stdarg_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STDARG_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_stddef_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for stddef.h" >&5
-echo $ECHO_N "checking for stddef.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stddef_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stddef_h" >&5
-echo "${ECHO_T}$ac_cv_header_stddef_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking stddef.h usability" >&5
-echo $ECHO_N "checking stddef.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <stddef.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking stddef.h presence" >&5
-echo $ECHO_N "checking stddef.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stddef.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: stddef.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: stddef.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: stddef.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: stddef.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: stddef.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: stddef.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: stddef.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: stddef.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: stddef.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stddef.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: stddef.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for stddef.h" >&5
-echo $ECHO_N "checking for stddef.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stddef_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_stddef_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stddef_h" >&5
-echo "${ECHO_T}$ac_cv_header_stddef_h" >&6; }
-
-fi
-if test $ac_cv_header_stddef_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STDDEF_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_stdio_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for stdio.h" >&5
-echo $ECHO_N "checking for stdio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdio_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdio_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking stdio.h usability" >&5
-echo $ECHO_N "checking stdio.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <stdio.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking stdio.h presence" >&5
-echo $ECHO_N "checking stdio.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdio.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: stdio.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: stdio.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: stdio.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: stdio.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: stdio.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: stdio.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: stdio.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: stdio.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: stdio.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdio.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: stdio.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for stdio.h" >&5
-echo $ECHO_N "checking for stdio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_stdio_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdio_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdio_h" >&6; }
-
-fi
-if test $ac_cv_header_stdio_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STDIO_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_stdint_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for stdint.h" >&5
-echo $ECHO_N "checking for stdint.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdint_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdint_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdint_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking stdint.h usability" >&5
-echo $ECHO_N "checking stdint.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <stdint.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking stdint.h presence" >&5
-echo $ECHO_N "checking stdint.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdint.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: stdint.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: stdint.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: stdint.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: stdint.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: stdint.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: stdint.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: stdint.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: stdint.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: stdint.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdint.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: stdint.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for stdint.h" >&5
-echo $ECHO_N "checking for stdint.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdint_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_stdint_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdint_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdint_h" >&6; }
-
-fi
-if test $ac_cv_header_stdint_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STDINT_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_stdlib_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for stdlib.h" >&5
-echo $ECHO_N "checking for stdlib.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdlib_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdlib_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdlib_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking stdlib.h usability" >&5
-echo $ECHO_N "checking stdlib.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <stdlib.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking stdlib.h presence" >&5
-echo $ECHO_N "checking stdlib.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <stdlib.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: stdlib.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: stdlib.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: stdlib.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: stdlib.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: stdlib.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: stdlib.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: stdlib.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: stdlib.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: stdlib.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for stdlib.h" >&5
-echo $ECHO_N "checking for stdlib.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_stdlib_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_stdlib_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_stdlib_h" >&5
-echo "${ECHO_T}$ac_cv_header_stdlib_h" >&6; }
-
-fi
-if test $ac_cv_header_stdlib_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STDLIB_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_string_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for string.h" >&5
-echo $ECHO_N "checking for string.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_string_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_string_h" >&5
-echo "${ECHO_T}$ac_cv_header_string_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking string.h usability" >&5
-echo $ECHO_N "checking string.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <string.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking string.h presence" >&5
-echo $ECHO_N "checking string.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <string.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: string.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: string.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: string.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: string.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: string.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: string.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: string.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: string.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: string.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: string.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: string.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for string.h" >&5
-echo $ECHO_N "checking for string.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_string_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_string_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_string_h" >&5
-echo "${ECHO_T}$ac_cv_header_string_h" >&6; }
-
-fi
-if test $ac_cv_header_string_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_STRING_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_ioctl_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/ioctl.h" >&5
-echo $ECHO_N "checking for sys/ioctl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_ioctl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_ioctl_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_ioctl_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/ioctl.h usability" >&5
-echo $ECHO_N "checking sys/ioctl.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/ioctl.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/ioctl.h presence" >&5
-echo $ECHO_N "checking sys/ioctl.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/ioctl.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/ioctl.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/ioctl.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/ioctl.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/ioctl.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/ioctl.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/ioctl.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/ioctl.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/ioctl.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/ioctl.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/ioctl.h" >&5
-echo $ECHO_N "checking for sys/ioctl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_ioctl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_ioctl_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_ioctl_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_ioctl_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_ioctl_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_IOCTL_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_select_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/select.h" >&5
-echo $ECHO_N "checking for sys/select.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_select_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_select_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_select_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/select.h usability" >&5
-echo $ECHO_N "checking sys/select.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/select.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/select.h presence" >&5
-echo $ECHO_N "checking sys/select.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/select.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/select.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/select.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/select.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/select.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/select.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/select.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/select.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/select.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/select.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/select.h" >&5
-echo $ECHO_N "checking for sys/select.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_select_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_select_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_select_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_select_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_select_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_SELECT_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_socket_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/socket.h" >&5
-echo $ECHO_N "checking for sys/socket.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_socket_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_socket_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_socket_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/socket.h usability" >&5
-echo $ECHO_N "checking sys/socket.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/socket.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/socket.h presence" >&5
-echo $ECHO_N "checking sys/socket.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/socket.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/socket.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/socket.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/socket.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/socket.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/socket.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/socket.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/socket.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/socket.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/socket.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/socket.h" >&5
-echo $ECHO_N "checking for sys/socket.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_socket_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_socket_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_socket_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_socket_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_socket_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_SOCKET_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_time_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/time.h" >&5
-echo $ECHO_N "checking for sys/time.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_time_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_time_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_time_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/time.h usability" >&5
-echo $ECHO_N "checking sys/time.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/time.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/time.h presence" >&5
-echo $ECHO_N "checking sys/time.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/time.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/time.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/time.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/time.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/time.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/time.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/time.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/time.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/time.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/time.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/time.h" >&5
-echo $ECHO_N "checking for sys/time.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_time_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_time_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_time_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_time_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_time_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_TIME_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_timeb_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/timeb.h" >&5
-echo $ECHO_N "checking for sys/timeb.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_timeb_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_timeb_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_timeb_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/timeb.h usability" >&5
-echo $ECHO_N "checking sys/timeb.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/timeb.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/timeb.h presence" >&5
-echo $ECHO_N "checking sys/timeb.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/timeb.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/timeb.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/timeb.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/timeb.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/timeb.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/timeb.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/timeb.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/timeb.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/timeb.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/timeb.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/timeb.h" >&5
-echo $ECHO_N "checking for sys/timeb.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_timeb_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_timeb_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_timeb_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_timeb_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_timeb_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_TIMEB_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_types_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/types.h" >&5
-echo $ECHO_N "checking for sys/types.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_types_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_types_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_types_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/types.h usability" >&5
-echo $ECHO_N "checking sys/types.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/types.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/types.h presence" >&5
-echo $ECHO_N "checking sys/types.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/types.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/types.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/types.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/types.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/types.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/types.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/types.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/types.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/types.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/types.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/types.h" >&5
-echo $ECHO_N "checking for sys/types.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_types_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_types_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_types_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_types_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_types_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_TYPES_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_filio_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/filio.h" >&5
-echo $ECHO_N "checking for sys/filio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_filio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_filio_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_filio_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/filio.h usability" >&5
-echo $ECHO_N "checking sys/filio.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/filio.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/filio.h presence" >&5
-echo $ECHO_N "checking sys/filio.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/filio.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/filio.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/filio.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/filio.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/filio.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/filio.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/filio.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/filio.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/filio.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/filio.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/filio.h" >&5
-echo $ECHO_N "checking for sys/filio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_filio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_filio_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_filio_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_filio_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_filio_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_FILIO_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_sys_sockio_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/sockio.h" >&5
-echo $ECHO_N "checking for sys/sockio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_sockio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_sockio_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_sockio_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/sockio.h usability" >&5
-echo $ECHO_N "checking sys/sockio.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/sockio.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/sockio.h presence" >&5
-echo $ECHO_N "checking sys/sockio.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/sockio.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/sockio.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/sockio.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/sockio.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/sockio.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/sockio.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/sockio.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/sockio.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/sockio.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/sockio.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/sockio.h" >&5
-echo $ECHO_N "checking for sys/sockio.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_sockio_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_sockio_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_sockio_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_sockio_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_sockio_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SYS_SOCKIO_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_time_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for time.h" >&5
-echo $ECHO_N "checking for time.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_time_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_time_h" >&5
-echo "${ECHO_T}$ac_cv_header_time_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking time.h usability" >&5
-echo $ECHO_N "checking time.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <time.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking time.h presence" >&5
-echo $ECHO_N "checking time.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <time.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: time.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: time.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: time.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: time.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: time.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: time.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: time.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: time.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: time.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: time.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: time.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for time.h" >&5
-echo $ECHO_N "checking for time.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_time_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_time_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_time_h" >&5
-echo "${ECHO_T}$ac_cv_header_time_h" >&6; }
-
-fi
-if test $ac_cv_header_time_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_TIME_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_unistd_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for unistd.h" >&5
-echo $ECHO_N "checking for unistd.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_unistd_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_unistd_h" >&5
-echo "${ECHO_T}$ac_cv_header_unistd_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking unistd.h usability" >&5
-echo $ECHO_N "checking unistd.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <unistd.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking unistd.h presence" >&5
-echo $ECHO_N "checking unistd.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <unistd.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: unistd.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: unistd.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: unistd.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: unistd.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: unistd.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: unistd.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: unistd.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: unistd.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: unistd.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: unistd.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: unistd.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for unistd.h" >&5
-echo $ECHO_N "checking for unistd.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_unistd_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_unistd_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_unistd_h" >&5
-echo "${ECHO_T}$ac_cv_header_unistd_h" >&6; }
-
-fi
-if test $ac_cv_header_unistd_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_UNISTD_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_winsock_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for winsock.h" >&5
-echo $ECHO_N "checking for winsock.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_winsock_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_winsock_h" >&5
-echo "${ECHO_T}$ac_cv_header_winsock_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking winsock.h usability" >&5
-echo $ECHO_N "checking winsock.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <winsock.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking winsock.h presence" >&5
-echo $ECHO_N "checking winsock.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <winsock.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: winsock.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: winsock.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: winsock.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: winsock.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: winsock.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: winsock.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: winsock.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: winsock.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: winsock.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: winsock.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for winsock.h" >&5
-echo $ECHO_N "checking for winsock.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_winsock_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_winsock_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_winsock_h" >&5
-echo "${ECHO_T}$ac_cv_header_winsock_h" >&6; }
-
-fi
-if test $ac_cv_header_winsock_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_WINSOCK_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_winsock2_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for winsock2.h" >&5
-echo $ECHO_N "checking for winsock2.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_winsock2_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_winsock2_h" >&5
-echo "${ECHO_T}$ac_cv_header_winsock2_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking winsock2.h usability" >&5
-echo $ECHO_N "checking winsock2.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <winsock2.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking winsock2.h presence" >&5
-echo $ECHO_N "checking winsock2.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <winsock2.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: winsock2.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: winsock2.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: winsock2.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: winsock2.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: winsock2.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: winsock2.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: winsock2.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: winsock2.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: winsock2.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for winsock2.h" >&5
-echo $ECHO_N "checking for winsock2.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_winsock2_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_winsock2_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_winsock2_h" >&5
-echo "${ECHO_T}$ac_cv_header_winsock2_h" >&6; }
-
-fi
-if test $ac_cv_header_winsock2_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_WINSOCK2_H 1
-_ACEOF
-
-fi
-
-
-{ echo "$as_me:$LINENO: checking for mswsock.h" >&5
-echo $ECHO_N "checking for mswsock.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_mswsock_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#if PJ_HAS_WINSOCK2_H
+"
+if test "x$ac_cv_header_netinet_ip_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NETINET_IP_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "netinet/tcp.h" "ac_cv_header_netinet_tcp_h" "$ac_includes_default"
+if test "x$ac_cv_header_netinet_tcp_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NETINET_TCP_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "ifaddrs.h" "ac_cv_header_ifaddrs_h" "$ac_includes_default"
+if test "x$ac_cv_header_ifaddrs_h" = x""yes; then :
+  ac_fn_c_check_func "$LINENO" "getifaddrs" "ac_cv_func_getifaddrs"
+if test "x$ac_cv_func_getifaddrs" = x""yes; then :
+  $as_echo "#define PJ_HAS_IFADDRS_H 1" >>confdefs.h
+
+fi
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "semaphore.h" "ac_cv_header_semaphore_h" "$ac_includes_default"
+if test "x$ac_cv_header_semaphore_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SEMAPHORE_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "setjmp.h" "ac_cv_header_setjmp_h" "$ac_includes_default"
+if test "x$ac_cv_header_setjmp_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SETJMP_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "stdarg.h" "ac_cv_header_stdarg_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdarg_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STDARG_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "stddef.h" "ac_cv_header_stddef_h" "$ac_includes_default"
+if test "x$ac_cv_header_stddef_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STDDEF_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "stdio.h" "ac_cv_header_stdio_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdio_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STDIO_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdint_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STDINT_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default"
+if test "x$ac_cv_header_stdlib_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STDLIB_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "string.h" "ac_cv_header_string_h" "$ac_includes_default"
+if test "x$ac_cv_header_string_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_STRING_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/ioctl.h" "ac_cv_header_sys_ioctl_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_ioctl_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_IOCTL_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/select.h" "ac_cv_header_sys_select_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_select_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_SELECT_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/socket.h" "ac_cv_header_sys_socket_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_socket_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_SOCKET_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/time.h" "ac_cv_header_sys_time_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_time_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_TIME_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/timeb.h" "ac_cv_header_sys_timeb_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_timeb_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_TIMEB_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_types_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_TYPES_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/filio.h" "ac_cv_header_sys_filio_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_filio_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_FILIO_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/sockio.h" "ac_cv_header_sys_sockio_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_sockio_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_SYS_SOCKIO_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "time.h" "ac_cv_header_time_h" "$ac_includes_default"
+if test "x$ac_cv_header_time_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_TIME_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default"
+if test "x$ac_cv_header_unistd_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_UNISTD_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "winsock.h" "ac_cv_header_winsock_h" "$ac_includes_default"
+if test "x$ac_cv_header_winsock_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_WINSOCK_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default"
+if test "x$ac_cv_header_winsock2_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_WINSOCK2_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_compile "$LINENO" "mswsock.h" "ac_cv_header_mswsock_h" "#if PJ_HAS_WINSOCK2_H
           	  #	include <winsock2.h>
 		  #elif PJ_HAS_WINSOCK_H
@@ -9485,319 +4944,25 @@
           	  #endif
 
-
-#include <mswsock.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_cv_header_mswsock_h=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_header_mswsock_h=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_mswsock_h" >&5
-echo "${ECHO_T}$ac_cv_header_mswsock_h" >&6; }
-if test $ac_cv_header_mswsock_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_MSWSOCK_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_ws2tcpip_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for ws2tcpip.h" >&5
-echo $ECHO_N "checking for ws2tcpip.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ws2tcpip_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ws2tcpip_h" >&5
-echo "${ECHO_T}$ac_cv_header_ws2tcpip_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking ws2tcpip.h usability" >&5
-echo $ECHO_N "checking ws2tcpip.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <ws2tcpip.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking ws2tcpip.h presence" >&5
-echo $ECHO_N "checking ws2tcpip.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <ws2tcpip.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: ws2tcpip.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: ws2tcpip.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: ws2tcpip.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: ws2tcpip.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: ws2tcpip.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: ws2tcpip.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: ws2tcpip.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: ws2tcpip.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: ws2tcpip.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for ws2tcpip.h" >&5
-echo $ECHO_N "checking for ws2tcpip.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ws2tcpip_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_ws2tcpip_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ws2tcpip_h" >&5
-echo "${ECHO_T}$ac_cv_header_ws2tcpip_h" >&6; }
-
-fi
-if test $ac_cv_header_ws2tcpip_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_WS2TCPIP_H 1
-_ACEOF
-
-fi
-
-
-if test "${ac_cv_header_uuid_uuid_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for uuid/uuid.h" >&5
-echo $ECHO_N "checking for uuid/uuid.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_uuid_uuid_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_uuid_uuid_h" >&5
-echo "${ECHO_T}$ac_cv_header_uuid_uuid_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking uuid/uuid.h usability" >&5
-echo $ECHO_N "checking uuid/uuid.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <uuid/uuid.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking uuid/uuid.h presence" >&5
-echo $ECHO_N "checking uuid/uuid.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <uuid/uuid.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: uuid/uuid.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: uuid/uuid.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: uuid/uuid.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: uuid/uuid.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: uuid/uuid.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: uuid/uuid.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: uuid/uuid.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: uuid/uuid.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: uuid/uuid.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for uuid/uuid.h" >&5
-echo $ECHO_N "checking for uuid/uuid.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_uuid_uuid_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_uuid_uuid_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_uuid_uuid_h" >&5
-echo "${ECHO_T}$ac_cv_header_uuid_uuid_h" >&6; }
-
-fi
-if test $ac_cv_header_uuid_uuid_h = yes; then
+"
+if test "x$ac_cv_header_mswsock_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_MSWSOCK_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "ws2tcpip.h" "ac_cv_header_ws2tcpip_h" "$ac_includes_default"
+if test "x$ac_cv_header_ws2tcpip_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_WS2TCPIP_H 1" >>confdefs.h
+
+fi
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "uuid/uuid.h" "ac_cv_header_uuid_uuid_h" "$ac_includes_default"
+if test "x$ac_cv_header_uuid_uuid_h" = x""yes; then :
   ac_has_uuid_h=1
 fi
 
 
-{ echo "$as_me:$LINENO: checking for net/if.h" >&5
-echo $ECHO_N "checking for net/if.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_net_if_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#if PJ_HAS_SYS_TYPES_H
+ac_fn_c_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" "#if PJ_HAS_SYS_TYPES_H
           	  #	include <sys/types.h>
           	  #endif
@@ -9807,46 +4972,13 @@
           	  #endif
 
-
-#include <net/if.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_cv_header_net_if_h=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_header_net_if_h=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_net_if_h" >&5
-echo "${ECHO_T}$ac_cv_header_net_if_h" >&6; }
-if test $ac_cv_header_net_if_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_NET_IF_H 1
-_ACEOF
-
-fi
-
-
-{ echo "$as_me:$LINENO: result: Setting PJ_OS_NAME to $target" >&5
-echo "${ECHO_T}Setting PJ_OS_NAME to $target" >&6; }
+"
+if test "x$ac_cv_header_net_if_h" = x""yes; then :
+  $as_echo "#define PJ_HAS_NET_IF_H 1" >>confdefs.h
+
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_OS_NAME to $target" >&5
+$as_echo "Setting PJ_OS_NAME to $target" >&6; }
 cat >>confdefs.h <<_ACEOF
 #define PJ_OS_NAME "$target"
@@ -9854,46 +4986,32 @@
 
 
-{ echo "$as_me:$LINENO: result: Setting PJ_HAS_ERRNO_VAR to 1" >&5
-echo "${ECHO_T}Setting PJ_HAS_ERRNO_VAR to 1" >&6; }
-cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_ERRNO_VAR 1
-_ACEOF
-
-
-{ echo "$as_me:$LINENO: result: Setting PJ_HAS_HIGH_RES_TIMER to 1" >&5
-echo "${ECHO_T}Setting PJ_HAS_HIGH_RES_TIMER to 1" >&6; }
-cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_HIGH_RES_TIMER 1
-_ACEOF
-
-
-{ echo "$as_me:$LINENO: result: Setting PJ_HAS_MALLOC to 1" >&5
-echo "${ECHO_T}Setting PJ_HAS_MALLOC to 1" >&6; }
-cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_MALLOC 1
-_ACEOF
-
-
-{ echo "$as_me:$LINENO: result: Setting PJ_NATIVE_STRING_IS_UNICODE to 0" >&5
-echo "${ECHO_T}Setting PJ_NATIVE_STRING_IS_UNICODE to 0" >&6; }
-cat >>confdefs.h <<\_ACEOF
-#define PJ_NATIVE_STRING_IS_UNICODE 0
-_ACEOF
-
-
-{ echo "$as_me:$LINENO: result: Setting PJ_ATOMIC_VALUE_TYPE to long" >&5
-echo "${ECHO_T}Setting PJ_ATOMIC_VALUE_TYPE to long" >&6; }
-cat >>confdefs.h <<\_ACEOF
-#define PJ_ATOMIC_VALUE_TYPE long
-_ACEOF
-
-
-{ echo "$as_me:$LINENO: checking if inet_aton() is available" >&5
-echo $ECHO_N "checking if inet_aton() is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_HAS_ERRNO_VAR to 1" >&5
+$as_echo "Setting PJ_HAS_ERRNO_VAR to 1" >&6; }
+$as_echo "#define PJ_HAS_ERRNO_VAR 1" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_HAS_HIGH_RES_TIMER to 1" >&5
+$as_echo "Setting PJ_HAS_HIGH_RES_TIMER to 1" >&6; }
+$as_echo "#define PJ_HAS_HIGH_RES_TIMER 1" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_HAS_MALLOC to 1" >&5
+$as_echo "Setting PJ_HAS_MALLOC to 1" >&6; }
+$as_echo "#define PJ_HAS_MALLOC 1" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_NATIVE_STRING_IS_UNICODE to 0" >&5
+$as_echo "Setting PJ_NATIVE_STRING_IS_UNICODE to 0" >&6; }
+$as_echo "#define PJ_NATIVE_STRING_IS_UNICODE 0" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Setting PJ_ATOMIC_VALUE_TYPE to long" >&5
+$as_echo "Setting PJ_ATOMIC_VALUE_TYPE to long" >&6; }
+$as_echo "#define PJ_ATOMIC_VALUE_TYPE long" >>confdefs.h
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if inet_aton() is available" >&5
+$as_echo_n "checking if inet_aton() is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -9908,44 +5026,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_SOCK_HAS_INET_ATON 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_SOCK_HAS_INET_ATON 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if inet_pton() is available" >&5
-echo $ECHO_N "checking if inet_pton() is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if inet_pton() is available" >&5
+$as_echo_n "checking if inet_pton() is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -9960,44 +5052,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_SOCK_HAS_INET_PTON 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_SOCK_HAS_INET_PTON 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if inet_ntop() is available" >&5
-echo $ECHO_N "checking if inet_ntop() is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if inet_ntop() is available" >&5
+$as_echo_n "checking if inet_ntop() is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -10012,44 +5078,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_SOCK_HAS_INET_NTOP 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_SOCK_HAS_INET_NTOP 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if getaddrinfo() is available" >&5
-echo $ECHO_N "checking if getaddrinfo() is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if getaddrinfo() is available" >&5
+$as_echo_n "checking if getaddrinfo() is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -10064,44 +5104,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_SOCK_HAS_GETADDRINFO 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_SOCK_HAS_GETADDRINFO 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if sockaddr_in has sin_len member" >&5
-echo $ECHO_N "checking if sockaddr_in has sin_len member... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if sockaddr_in has sin_len member" >&5
+$as_echo_n "checking if sockaddr_in has sin_len member... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -10117,44 +5131,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_SOCKADDR_HAS_LEN 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_SOCKADDR_HAS_LEN 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if socklen_t is available" >&5
-echo $ECHO_N "checking if socklen_t is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if socklen_t is available" >&5
+$as_echo_n "checking if socklen_t is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -10168,54 +5156,26 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SOCKLEN_T 1
-_ACEOF
-
-		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_HAS_SOCKLEN_T 1" >>confdefs.h
+
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if SO_ERROR is available" >&5
-echo $ECHO_N "checking if SO_ERROR is available... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if SO_ERROR is available" >&5
+$as_echo_n "checking if SO_ERROR is available... " >&6; }
 case $target in
     *mingw* | *cygw* | *win32* | *w32* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SO_ERROR 1
-_ACEOF
-
-	{ echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
+	$as_echo "#define PJ_HAS_SO_ERROR 1" >>confdefs.h
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 	;;
     *)
-	cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <sys/types.h>
@@ -10231,35 +5191,13 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SO_ERROR 1
-_ACEOF
-
-			   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_HAS_SO_ERROR 1" >>confdefs.h
+
+			   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 	;;
@@ -10267,11 +5205,7 @@
 
 
-{ echo "$as_me:$LINENO: checking if pthread_rwlock_t is available" >&5
-echo $ECHO_N "checking if pthread_rwlock_t is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if pthread_rwlock_t is available" >&5
+$as_echo_n "checking if pthread_rwlock_t is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <pthread.h>
@@ -10284,51 +5218,23 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_EMULATE_RWMUTEX 0
-_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_EMULATE_RWMUTEX 0" >>confdefs.h
 
 		   ac_rwmutex="yes"
-  		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_EMULATE_RWMUTEX 1
-_ACEOF
+  		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  $as_echo "#define PJ_EMULATE_RWMUTEX 1" >>confdefs.h
 
 		   ac_rwmutex="no"
-		   { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 if test "$ac_rwmutex" = "no"; then
-    { echo "$as_me:$LINENO: checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS" >&5
-echo $ECHO_N "checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS... $ECHO_C" >&6; }
-    cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS" >&5
+$as_echo_n "checking if pthread_rwlock_t is available with _POSIX_READER_WRITER_LOCKS... " >&6; }
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #define _POSIX_READER_WRITER_LOCKS
@@ -10342,50 +5248,22 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_EMULATE_RWMUTEX 0
-_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_EMULATE_RWMUTEX 0" >>confdefs.h
 
 		       CFLAGS="$CFLAGS -D_POSIX_THREADS -D_POSIX_READER_WRITER_LOCKS"
-		       { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_EMULATE_RWMUTEX 1
-_ACEOF
-
-		       { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+		       { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  $as_echo "#define PJ_EMULATE_RWMUTEX 1" >>confdefs.h
+
+		       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 
-{ echo "$as_me:$LINENO: checking if pthread_mutexattr_settype() is available" >&5
-echo $ECHO_N "checking if pthread_mutexattr_settype() is available... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if pthread_mutexattr_settype() is available" >&5
+$as_echo_n "checking if pthread_mutexattr_settype() is available... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <pthread.h>
@@ -10398,44 +5276,18 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE 1
-_ACEOF
-
-  		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_HAS_PTHREAD_MUTEXATTR_SETTYPE 1" >>confdefs.h
+
+  		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
-{ echo "$as_me:$LINENO: checking if pthread_mutexattr_t has recursive member" >&5
-echo $ECHO_N "checking if pthread_mutexattr_t has recursive member... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if pthread_mutexattr_t has recursive member" >&5
+$as_echo_n "checking if pthread_mutexattr_t has recursive member... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <pthread.h>
@@ -10449,52 +5301,30 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  cat >>confdefs.h <<\_ACEOF
-#define PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE 1
-_ACEOF
-
-  		   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-fi
-
+if ac_fn_c_try_compile "$LINENO"; then :
+  $as_echo "#define PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE 1" >>confdefs.h
+
+  		   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 
-{ echo "$as_me:$LINENO: checking ioqueue backend" >&5
-echo $ECHO_N "checking ioqueue backend... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking ioqueue backend" >&5
+$as_echo_n "checking ioqueue backend... " >&6; }
 # Check whether --enable-epoll was given.
-if test "${enable_epoll+set}" = set; then
+if test "${enable_epoll+set}" = set; then :
   enableval=$enable_epoll;
 		ac_os_objs=ioqueue_epoll.o
-		{ echo "$as_me:$LINENO: result: /dev/epoll" >&5
-echo "${ECHO_T}/dev/epoll" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: /dev/epoll" >&5
+$as_echo "/dev/epoll" >&6; }
 
 else
 
 		ac_os_objs=ioqueue_select.o
-	        { echo "$as_me:$LINENO: result: select()" >&5
-echo "${ECHO_T}select()" >&6; }
+	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: select()" >&5
+$as_echo "select()" >&6; }
 
 fi
@@ -10524,15 +5354,11 @@
 
 # Check whether --with-external-speex was given.
-if test "${with_external_speex+set}" = set; then
+if test "${with_external_speex+set}" = set; then :
   withval=$with_external_speex;
 	if test "x$with_external_speex" != "xno"; then
 		# Test Speex installation
-		{ echo "$as_me:$LINENO: checking if external Speex devkit is installed" >&5
-echo $ECHO_N "checking if external Speex devkit is installed... $ECHO_C" >&6; }
-		cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if external Speex devkit is installed" >&5
+$as_echo_n "checking if external Speex devkit is installed... " >&6; }
+		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <speex/speex.h>
@@ -10547,38 +5373,14 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  { echo "$as_me:$LINENO: result: yes!!" >&5
-echo "${ECHO_T}yes!!" >&6; }
-				   cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_EXTERNAL_SPEEX_CODEC 1
-_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes!!" >&5
+$as_echo "yes!!" >&6; }
+				   $as_echo "#define PJMEDIA_EXTERNAL_SPEEX_CODEC 1" >>confdefs.h
 
 				   ac_external_speex="1"
 
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ { echo "$as_me:$LINENO: error: Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&5
-echo "$as_me: error: Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
+  as_fn_error "Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" "$LINENO" 5
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 	fi
@@ -10592,15 +5394,11 @@
 
 # Check whether --with-external-gsm was given.
-if test "${with_external_gsm+set}" = set; then
+if test "${with_external_gsm+set}" = set; then :
   withval=$with_external_gsm;
 	if test "x$with_external_gsm" != "xno"; then
                 # Test GSM library installation
-                { echo "$as_me:$LINENO: checking if external GSM devkit is installed as gsm/gsm.h" >&5
-echo $ECHO_N "checking if external GSM devkit is installed as gsm/gsm.h... $ECHO_C" >&6; }
-                cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking if external GSM devkit is installed as gsm/gsm.h" >&5
+$as_echo_n "checking if external GSM devkit is installed as gsm/gsm.h... " >&6; }
+                cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <gsm/gsm.h>
@@ -10613,47 +5411,20 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  { echo "$as_me:$LINENO: result: yes!!" >&5
-echo "${ECHO_T}yes!!" >&6; }
-                     cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_EXTERNAL_GSM_CODEC 1
-_ACEOF
-
-                     cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_EXTERNAL_GSM_GSM_H 1
-_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes!!" >&5
+$as_echo "yes!!" >&6; }
+                     $as_echo "#define PJMEDIA_EXTERNAL_GSM_CODEC 1" >>confdefs.h
+
+                     $as_echo "#define PJMEDIA_EXTERNAL_GSM_GSM_H 1" >>confdefs.h
 
                      ac_external_gsm="1"
 
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-                     { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-                     { echo "$as_me:$LINENO: checking if external GSM devkit is installed as gsm.h" >&5
-echo $ECHO_N "checking if external GSM devkit is installed as gsm.h... $ECHO_C" >&6; }
-                     cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+
+                     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+                     { $as_echo "$as_me:${as_lineno-$LINENO}: checking if external GSM devkit is installed as gsm.h" >&5
+$as_echo_n "checking if external GSM devkit is installed as gsm.h... " >&6; }
+                     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <gsm.h>
@@ -10666,49 +5437,22 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  { echo "$as_me:$LINENO: result: yes!!" >&5
-echo "${ECHO_T}yes!!" >&6; }
-                         cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_EXTERNAL_GSM_CODEC 1
-_ACEOF
-
-                         cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_EXTERNAL_GSM_H 1
-_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes!!" >&5
+$as_echo "yes!!" >&6; }
+                         $as_echo "#define PJMEDIA_EXTERNAL_GSM_CODEC 1" >>confdefs.h
+
+                         $as_echo "#define PJMEDIA_EXTERNAL_GSM_H 1" >>confdefs.h
 
                          ac_external_gsm="1"
 
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ { echo "$as_me:$LINENO: error: Unable to use external GSM library. If GSM development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&5
-echo "$as_me: error: Unable to use external GSM library. If GSM development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&2;}
-   { (exit 1); exit 1; }; }
-
-
-fi
-
+  as_fn_error "Unable to use external GSM library. If GSM development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" "$LINENO" 5
+
+
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 
 fi
-
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 	fi
@@ -10722,9 +5466,9 @@
 
 # Check whether --enable-sound was given.
-if test "${enable_sound+set}" = set; then
+if test "${enable_sound+set}" = set; then :
   enableval=$enable_sound; if test "$enable_sound" = "no"; then
 		ac_pjmedia_snd=null
-		{ echo "$as_me:$LINENO: result: Checking if sound is disabled... yes" >&5
-echo "${ECHO_T}Checking if sound is disabled... yes" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if sound is disabled... yes" >&5
+$as_echo "Checking if sound is disabled... yes" >&6; }
 	       fi
 
@@ -10736,15 +5480,11 @@
 
 # Check whether --with-external-pa was given.
-if test "${with_external_pa+set}" = set; then
+if test "${with_external_pa+set}" = set; then :
   withval=$with_external_pa;
 	if test "x$with_external_pa" != "xno"; then
 		# Test PortAudio installation
-		{ echo "$as_me:$LINENO: checking if external PortAudio devkit is installed" >&5
-echo $ECHO_N "checking if external PortAudio devkit is installed... $ECHO_C" >&6; }
-		cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if external PortAudio devkit is installed" >&5
+$as_echo_n "checking if external PortAudio devkit is installed... " >&6; }
+		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <portaudio.h>
@@ -10758,34 +5498,12 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  { echo "$as_me:$LINENO: result: yes!!" >&5
-echo "${ECHO_T}yes!!" >&6; }
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes!!" >&5
+$as_echo "yes!!" >&6; }
 				   ac_external_pa="1"
 
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ { echo "$as_me:$LINENO: error: Unable to use PortAudio. If PortAudio development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&5
-echo "$as_me: error: Unable to use PortAudio. If PortAudio development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
+  as_fn_error "Unable to use PortAudio. If PortAudio development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths" "$LINENO" 5
+fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 	fi
@@ -10796,390 +5514,18 @@
 
 
-if test "${ac_cv_header_sys_soundcard_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for sys/soundcard.h" >&5
-echo $ECHO_N "checking for sys/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_soundcard_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking sys/soundcard.h usability" >&5
-echo $ECHO_N "checking sys/soundcard.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <sys/soundcard.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking sys/soundcard.h presence" >&5
-echo $ECHO_N "checking sys/soundcard.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <sys/soundcard.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: sys/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: sys/soundcard.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: sys/soundcard.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: sys/soundcard.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: sys/soundcard.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: sys/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: sys/soundcard.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: sys/soundcard.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: sys/soundcard.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for sys/soundcard.h" >&5
-echo $ECHO_N "checking for sys/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_sys_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_sys_soundcard_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_sys_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_sys_soundcard_h" >&6; }
-
-fi
-if test $ac_cv_header_sys_soundcard_h = yes; then
+ac_fn_c_check_header_mongrel "$LINENO" "sys/soundcard.h" "ac_cv_header_sys_soundcard_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_soundcard_h" = x""yes; then :
   ac_pa_cflags="$ac_pa_cflags -DHAVE_SYS_SOUNDCARD_H"
 fi
 
 
-if test "${ac_cv_header_linux_soundcard_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for linux/soundcard.h" >&5
-echo $ECHO_N "checking for linux/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_linux_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_linux_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_linux_soundcard_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking linux/soundcard.h usability" >&5
-echo $ECHO_N "checking linux/soundcard.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <linux/soundcard.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking linux/soundcard.h presence" >&5
-echo $ECHO_N "checking linux/soundcard.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <linux/soundcard.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: linux/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: linux/soundcard.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: linux/soundcard.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: linux/soundcard.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: linux/soundcard.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: linux/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: linux/soundcard.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: linux/soundcard.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: linux/soundcard.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for linux/soundcard.h" >&5
-echo $ECHO_N "checking for linux/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_linux_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_linux_soundcard_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_linux_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_linux_soundcard_h" >&6; }
-
-fi
-if test $ac_cv_header_linux_soundcard_h = yes; then
+ac_fn_c_check_header_mongrel "$LINENO" "linux/soundcard.h" "ac_cv_header_linux_soundcard_h" "$ac_includes_default"
+if test "x$ac_cv_header_linux_soundcard_h" = x""yes; then :
   ac_pa_cflags="$ac_pa_cflags -DHAVE_LINUX_SOUNDCARD_H"
 fi
 
 
-if test "${ac_cv_header_machine_soundcard_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for machine/soundcard.h" >&5
-echo $ECHO_N "checking for machine/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_machine_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_machine_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_machine_soundcard_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking machine/soundcard.h usability" >&5
-echo $ECHO_N "checking machine/soundcard.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <machine/soundcard.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking machine/soundcard.h presence" >&5
-echo $ECHO_N "checking machine/soundcard.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <machine/soundcard.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: machine/soundcard.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: machine/soundcard.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: machine/soundcard.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: machine/soundcard.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: machine/soundcard.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: machine/soundcard.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: machine/soundcard.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: machine/soundcard.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: machine/soundcard.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for machine/soundcard.h" >&5
-echo $ECHO_N "checking for machine/soundcard.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_machine_soundcard_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_machine_soundcard_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_machine_soundcard_h" >&5
-echo "${ECHO_T}$ac_cv_header_machine_soundcard_h" >&6; }
-
-fi
-if test $ac_cv_header_machine_soundcard_h = yes; then
+ac_fn_c_check_header_mongrel "$LINENO" "machine/soundcard.h" "ac_cv_header_machine_soundcard_h" "$ac_includes_default"
+if test "x$ac_cv_header_machine_soundcard_h" = x""yes; then :
   ac_pa_cflags="$ac_pa_cflags -DHAVE_MACHINE_SOUNDCARD_H"
 fi
@@ -11199,6 +5545,6 @@
   arm-apple-darwin*)
 	LIBS="$LIBS -framework CoreAudio -framework CoreFoundation -framework AudioToolbox -framework CFNetwork"
-	{ echo "$as_me:$LINENO: result: Checking sound device backend... AudioUnit" >&5
-echo "${ECHO_T}Checking sound device backend... AudioUnit" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... AudioUnit" >&5
+$as_echo "Checking sound device backend... AudioUnit" >&6; }
 	;;
   *darwin*)
@@ -11208,150 +5554,26 @@
 		#AC_MSG_RESULT([Setting additional PortAudio CFLAGS.. -DPA_OLD_CORE_AUDIO -DMOSX_USE_NON_ATOMIC_FLAG_BITS])
 		ac_pjmedia_snd=pa_old_darwinos
-		{ echo "$as_me:$LINENO: result: Checking sound device backend... old coreaudio" >&5
-echo "${ECHO_T}Checking sound device backend... old coreaudio" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... old coreaudio" >&5
+$as_echo "Checking sound device backend... old coreaudio" >&6; }
 	else
 		ac_pjmedia_snd=pa_darwinos
-		{ echo "$as_me:$LINENO: result: Checking sound device backend... coreaudio" >&5
-echo "${ECHO_T}Checking sound device backend... coreaudio" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... coreaudio" >&5
+$as_echo "Checking sound device backend... coreaudio" >&6; }
 	fi
 	;;
   *cygwin* | *mingw*)
 	ac_pjmedia_snd=pa_win32
-	{ echo "$as_me:$LINENO: result: Checking sound device backend... win32 sound" >&5
-echo "${ECHO_T}Checking sound device backend... win32 sound" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... win32 sound" >&5
+$as_echo "Checking sound device backend... win32 sound" >&6; }
 	;;
   *rtems*)
 	ac_pjmedia_snd=null
-	{ echo "$as_me:$LINENO: result: Checking sound device backend... null sound" >&5
-echo "${ECHO_T}Checking sound device backend... null sound" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... null sound" >&5
+$as_echo "Checking sound device backend... null sound" >&6; }
 	;;
   *)
 		ac_pjmedia_snd=pa_unix
-	if test "${ac_cv_header_alsa_version_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for alsa/version.h" >&5
-echo $ECHO_N "checking for alsa/version.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_alsa_version_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_alsa_version_h" >&5
-echo "${ECHO_T}$ac_cv_header_alsa_version_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking alsa/version.h usability" >&5
-echo $ECHO_N "checking alsa/version.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <alsa/version.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking alsa/version.h presence" >&5
-echo $ECHO_N "checking alsa/version.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <alsa/version.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: alsa/version.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: alsa/version.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: alsa/version.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: alsa/version.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: alsa/version.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: alsa/version.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: alsa/version.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: alsa/version.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: alsa/version.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for alsa/version.h" >&5
-echo $ECHO_N "checking for alsa/version.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_alsa_version_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_alsa_version_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_alsa_version_h" >&5
-echo "${ECHO_T}$ac_cv_header_alsa_version_h" >&6; }
-
-fi
-if test $ac_cv_header_alsa_version_h = yes; then
+	ac_fn_c_check_header_mongrel "$LINENO" "alsa/version.h" "ac_cv_header_alsa_version_h" "$ac_includes_default"
+if test "x$ac_cv_header_alsa_version_h" = x""yes; then :
   ac_pa_use_alsa=1
 
@@ -11364,16 +5586,16 @@
 
 
-	{ echo "$as_me:$LINENO: result: Checking sound device backend... unix" >&5
-echo "${ECHO_T}Checking sound device backend... unix" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking sound device backend... unix" >&5
+$as_echo "Checking sound device backend... unix" >&6; }
 
 		ac_pa_use_oss=1
 
 	# Check whether --enable-oss was given.
-if test "${enable_oss+set}" = set; then
+if test "${enable_oss+set}" = set; then :
   enableval=$enable_oss;
 			if test "$enable_oss" = "no"; then
 			 ac_pa_use_oss=0
-			 { echo "$as_me:$LINENO: result: Checking if OSS audio is disabled... yes" >&5
-echo "${ECHO_T}Checking if OSS audio is disabled... yes" >&6; }
+			 { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if OSS audio is disabled... yes" >&5
+$as_echo "Checking if OSS audio is disabled... yes" >&6; }
 			fi
 
@@ -11385,9 +5607,9 @@
 
 # Check whether --enable-ext_sound was given.
-if test "${enable_ext_sound+set}" = set; then
+if test "${enable_ext_sound+set}" = set; then :
   enableval=$enable_ext_sound; if test "$enable_ext_sound" = "yes"; then
 		ac_pjmedia_snd=external
-		{ echo "$as_me:$LINENO: result: Checking if external sound is set... yes" >&5
-echo "${ECHO_T}Checking if external sound is set... yes" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if external sound is set... yes" >&5
+$as_echo "Checking if external sound is set... yes" >&6; }
 	       fi
 
@@ -11397,13 +5619,13 @@
 
 # Check whether --enable-small-filter was given.
-if test "${enable_small_filter+set}" = set; then
+if test "${enable_small_filter+set}" = set; then :
   enableval=$enable_small_filter; if test "$enable_small_filter" = "no"; then
 		ac_no_small_filter='-DPJMEDIA_HAS_SMALL_FILTER=0'
-		{ echo "$as_me:$LINENO: result: Checking if small filter is disabled... yes" >&5
-echo "${ECHO_T}Checking if small filter is disabled... yes" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if small filter is disabled... yes" >&5
+$as_echo "Checking if small filter is disabled... yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if small filter is disabled... no" >&5
-echo "${ECHO_T}Checking if small filter is disabled... no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if small filter is disabled... no" >&5
+$as_echo "Checking if small filter is disabled... no" >&6; }
 fi
 
@@ -11411,13 +5633,13 @@
 
 # Check whether --enable-large-filter was given.
-if test "${enable_large_filter+set}" = set; then
+if test "${enable_large_filter+set}" = set; then :
   enableval=$enable_large_filter; if test "$enable_large_filter" = "no"; then
 		ac_no_large_filter='-DPJMEDIA_HAS_LARGE_FILTER=0'
-		{ echo "$as_me:$LINENO: result: Checking if large filter is disabled... yes" >&5
-echo "${ECHO_T}Checking if large filter is disabled... yes" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if large filter is disabled... yes" >&5
+$as_echo "Checking if large filter is disabled... yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if large filter is disabled... no" >&5
-echo "${ECHO_T}Checking if large filter is disabled... no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if large filter is disabled... no" >&5
+$as_echo "Checking if large filter is disabled... no" >&6; }
 fi
 
@@ -11425,13 +5647,13 @@
 
 # Check whether --enable-speex-aec was given.
-if test "${enable_speex_aec+set}" = set; then
+if test "${enable_speex_aec+set}" = set; then :
   enableval=$enable_speex_aec; if test "$enable_speex_aec" = "no"; then
 		ac_no_speex_aec='-DPJMEDIA_HAS_SPEEX_AEC=0'
-		{ echo "$as_me:$LINENO: result: Checking if Speex AEC is disabled...yes" >&5
-echo "${ECHO_T}Checking if Speex AEC is disabled...yes" >&6; }
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if Speex AEC is disabled...yes" >&5
+$as_echo "Checking if Speex AEC is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if Speex AEC is disabled...no" >&5
-echo "${ECHO_T}Checking if Speex AEC is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if Speex AEC is disabled...no" >&5
+$as_echo "Checking if Speex AEC is disabled...no" >&6; }
 fi
 
@@ -11439,17 +5661,15 @@
 
 # Check whether --enable-g711-codec was given.
-if test "${enable_g711_codec+set}" = set; then
+if test "${enable_g711_codec+set}" = set; then :
   enableval=$enable_g711_codec; if test "$enable_g711_codec" = "no"; then
 		ac_no_g711_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_G711_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if G.711 codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if G.711 codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_G711_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.711 codec is disabled...yes" >&5
+$as_echo "Checking if G.711 codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if G.711 codec is disabled...no" >&5
-echo "${ECHO_T}Checking if G.711 codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.711 codec is disabled...no" >&5
+$as_echo "Checking if G.711 codec is disabled...no" >&6; }
 fi
 
@@ -11458,17 +5678,15 @@
 
 # Check whether --enable-l16-codec was given.
-if test "${enable_l16_codec+set}" = set; then
+if test "${enable_l16_codec+set}" = set; then :
   enableval=$enable_l16_codec; if test "$enable_l16_codec" = "no"; then
 		ac_no_l16_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_L16_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if L16 codecs are disabled...yes" >&5
-echo "${ECHO_T}Checking if L16 codecs are disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_L16_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if L16 codecs are disabled...yes" >&5
+$as_echo "Checking if L16 codecs are disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if L16 codec is disabled...no" >&5
-echo "${ECHO_T}Checking if L16 codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if L16 codec is disabled...no" >&5
+$as_echo "Checking if L16 codec is disabled...no" >&6; }
 fi
 
@@ -11477,17 +5695,15 @@
 
 # Check whether --enable-gsm-codec was given.
-if test "${enable_gsm_codec+set}" = set; then
+if test "${enable_gsm_codec+set}" = set; then :
   enableval=$enable_gsm_codec; if test "$enable_gsm_codec" = "no"; then
 		ac_no_gsm_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_GSM_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if GSM codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if GSM codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_GSM_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if GSM codec is disabled...yes" >&5
+$as_echo "Checking if GSM codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if GSM codec is disabled...no" >&5
-echo "${ECHO_T}Checking if GSM codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if GSM codec is disabled...no" >&5
+$as_echo "Checking if GSM codec is disabled...no" >&6; }
 fi
 
@@ -11495,17 +5711,15 @@
 
 # Check whether --enable-g722-codec was given.
-if test "${enable_g722_codec+set}" = set; then
+if test "${enable_g722_codec+set}" = set; then :
   enableval=$enable_g722_codec; if test "$enable_g722_codec" = "no"; then
 		ac_no_g722_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_G722_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if G.722 codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if G.722 codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_G722_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.722 codec is disabled...yes" >&5
+$as_echo "Checking if G.722 codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if G.722 codec is disabled...no" >&5
-echo "${ECHO_T}Checking if G.722 codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.722 codec is disabled...no" >&5
+$as_echo "Checking if G.722 codec is disabled...no" >&6; }
 fi
 
@@ -11513,17 +5727,15 @@
 
 # Check whether --enable-g7221-codec was given.
-if test "${enable_g7221_codec+set}" = set; then
+if test "${enable_g7221_codec+set}" = set; then :
   enableval=$enable_g7221_codec; if test "$enable_g7221_codec" = "no"; then
 		ac_no_g7221_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_G7221_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if G.722.1 codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if G.722.1 codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_G7221_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.722.1 codec is disabled...yes" >&5
+$as_echo "Checking if G.722.1 codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if G.722.1 codec is disabled...no" >&5
-echo "${ECHO_T}Checking if G.722.1 codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if G.722.1 codec is disabled...no" >&5
+$as_echo "Checking if G.722.1 codec is disabled...no" >&6; }
 fi
 
@@ -11531,17 +5743,15 @@
 
 # Check whether --enable-speex-codec was given.
-if test "${enable_speex_codec+set}" = set; then
+if test "${enable_speex_codec+set}" = set; then :
   enableval=$enable_speex_codec; if test "$enable_speex_codec" = "no"; then
 		ac_no_speex_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_SPEEX_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if Speex codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if Speex codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_SPEEX_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if Speex codec is disabled...yes" >&5
+$as_echo "Checking if Speex codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if Speex codec is disabled...no" >&5
-echo "${ECHO_T}Checking if Speex codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if Speex codec is disabled...no" >&5
+$as_echo "Checking if Speex codec is disabled...no" >&6; }
 fi
 
@@ -11549,35 +5759,28 @@
 
 # Check whether --enable-ilbc-codec was given.
-if test "${enable_ilbc_codec+set}" = set; then
+if test "${enable_ilbc_codec+set}" = set; then :
   enableval=$enable_ilbc_codec; if test "$enable_ilbc_codec" = "no"; then
 		ac_no_ilbc_codec=1
-		cat >>confdefs.h <<\_ACEOF
-#define PJMEDIA_HAS_ILBC_CODEC 0
-_ACEOF
-
-		{ echo "$as_me:$LINENO: result: Checking if iLBC codec is disabled...yes" >&5
-echo "${ECHO_T}Checking if iLBC codec is disabled...yes" >&6; }
+		$as_echo "#define PJMEDIA_HAS_ILBC_CODEC 0" >>confdefs.h
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if iLBC codec is disabled...yes" >&5
+$as_echo "Checking if iLBC codec is disabled...yes" >&6; }
 	       fi
 else
-  { echo "$as_me:$LINENO: result: Checking if iLBC codec is disabled...no" >&5
-echo "${ECHO_T}Checking if iLBC codec is disabled...no" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if iLBC codec is disabled...no" >&5
+$as_echo "Checking if iLBC codec is disabled...no" >&6; }
 fi
 
 
 # Check whether --enable-libsamplerate was given.
-if test "${enable_libsamplerate+set}" = set; then
-  enableval=$enable_libsamplerate;
-{ echo "$as_me:$LINENO: checking for src_new in -lsamplerate" >&5
-echo $ECHO_N "checking for src_new in -lsamplerate... $ECHO_C" >&6; }
-if test "${ac_cv_lib_samplerate_src_new+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+if test "${enable_libsamplerate+set}" = set; then :
+  enableval=$enable_libsamplerate;  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for src_new in -lsamplerate" >&5
+$as_echo_n "checking for src_new in -lsamplerate... " >&6; }
+if test "${ac_cv_lib_samplerate_src_new+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lsamplerate  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -11597,37 +5800,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_samplerate_src_new=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_samplerate_src_new=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_samplerate_src_new=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_samplerate_src_new" >&5
-echo "${ECHO_T}$ac_cv_lib_samplerate_src_new" >&6; }
-if test $ac_cv_lib_samplerate_src_new = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_samplerate_src_new" >&5
+$as_echo "$ac_cv_lib_samplerate_src_new" >&6; }
+if test "x$ac_cv_lib_samplerate_src_new" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
 #define HAVE_LIBSAMPLERATE 1
@@ -11639,13 +5821,373 @@
 
 else
-  { echo "$as_me:$LINENO: result: Skipping libsamplerate detection" >&5
-echo "${ECHO_T}Skipping libsamplerate detection" >&6; }
-
-fi
-
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Skipping libsamplerate detection" >&5
+$as_echo "Skipping libsamplerate detection" >&6; }
+
+fi
+
+
+# Check whether --enable-sdl was given.
+if test "${enable_sdl+set}" = set; then :
+  enableval=$enable_sdl;
+		if test "$enable_sdl" = "no"; then
+		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if SDL is disabled... yes" >&5
+$as_echo "Checking if SDL is disabled... yes" >&6; }
+		fi
+
+else
+
+		  { $as_echo "$as_me:${as_lineno-$LINENO}: checking SDL availability.." >&5
+$as_echo_n "checking SDL availability..... " >&6; }
+		  if sdl-config --version; then
+
+
+			  ac_sdl_cflags=`sdl-config --cflags`
+			  ac_sdl_cflags="-DPJMEDIA_VIDEO_DEV_HAS_SDL=1 $ac_sdl_cflags"
+			  ac_sdl_ldflags=`sdl-config --libs`
+		   fi
+
+fi
+
+
+
+# Check whether --enable-ffmpeg was given.
+if test "${enable_ffmpeg+set}" = set; then :
+  enableval=$enable_ffmpeg;
+	        ac_has_ffmpeg=0
+
+		if test "$enable_ffmpeg" = "no"; then
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if ffmpeg is disabled... yes" >&5
+$as_echo "Checking if ffmpeg is disabled... yes" >&6; }
+		fi
+
+else
+
+
+
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for avdevice_version in -lavdevice" >&5
+$as_echo_n "checking for avdevice_version in -lavdevice... " >&6; }
+if test "${ac_cv_lib_avdevice_avdevice_version+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lavdevice  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char avdevice_version ();
+int
+main ()
+{
+return avdevice_version ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_avdevice_avdevice_version=yes
+else
+  ac_cv_lib_avdevice_avdevice_version=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_avdevice_avdevice_version" >&5
+$as_echo "$ac_cv_lib_avdevice_avdevice_version" >&6; }
+if test "x$ac_cv_lib_avdevice_avdevice_version" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavdevice"
+
+
+fi
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for av_register_all in -lavformat" >&5
+$as_echo_n "checking for av_register_all in -lavformat... " >&6; }
+if test "${ac_cv_lib_avformat_av_register_all+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lavformat  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char av_register_all ();
+int
+main ()
+{
+return av_register_all ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_avformat_av_register_all=yes
+else
+  ac_cv_lib_avformat_av_register_all=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_avformat_av_register_all" >&5
+$as_echo "$ac_cv_lib_avformat_av_register_all" >&6; }
+if test "x$ac_cv_lib_avformat_av_register_all" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavformat"
+
+
+fi
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for avcodec_init in -lavcodec" >&5
+$as_echo_n "checking for avcodec_init in -lavcodec... " >&6; }
+if test "${ac_cv_lib_avcodec_avcodec_init+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lavcodec  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char avcodec_init ();
+int
+main ()
+{
+return avcodec_init ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_avcodec_avcodec_init=yes
+else
+  ac_cv_lib_avcodec_avcodec_init=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_avcodec_avcodec_init" >&5
+$as_echo "$ac_cv_lib_avcodec_avcodec_init" >&6; }
+if test "x$ac_cv_lib_avcodec_avcodec_init" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcodec"
+
+
+fi
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sws_scale in -lswscale" >&5
+$as_echo_n "checking for sws_scale in -lswscale... " >&6; }
+if test "${ac_cv_lib_swscale_sws_scale+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lswscale  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char sws_scale ();
+int
+main ()
+{
+return sws_scale ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_swscale_sws_scale=yes
+else
+  ac_cv_lib_swscale_sws_scale=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_swscale_sws_scale" >&5
+$as_echo "$ac_cv_lib_swscale_sws_scale" >&6; }
+if test "x$ac_cv_lib_swscale_sws_scale" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lswscale"
+
+
+fi
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for av_malloc in -lavutil" >&5
+$as_echo_n "checking for av_malloc in -lavutil... " >&6; }
+if test "${ac_cv_lib_avutil_av_malloc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lavutil  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char av_malloc ();
+int
+main ()
+{
+return av_malloc ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_avutil_av_malloc=yes
+else
+  ac_cv_lib_avutil_av_malloc=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_avutil_av_malloc" >&5
+$as_echo "$ac_cv_lib_avutil_av_malloc" >&6; }
+if test "x$ac_cv_lib_avutil_av_malloc" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavutil"
+
+
+fi
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for avcore_version in -lavcore" >&5
+$as_echo_n "checking for avcore_version in -lavcore... " >&6; }
+if test "${ac_cv_lib_avcore_avcore_version+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lavcore  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char avcore_version ();
+int
+main ()
+{
+return avcore_version ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_avcore_avcore_version=yes
+else
+  ac_cv_lib_avcore_avcore_version=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_avcore_avcore_version" >&5
+$as_echo "$ac_cv_lib_avcore_avcore_version" >&6; }
+if test "x$ac_cv_lib_avcore_avcore_version" = x""yes; then :
+  ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcore"
+
+
+fi
+
+
+
+fi
+
+
+# Check whether --enable-v4l2 was given.
+if test "${enable_v4l2+set}" = set; then :
+  enableval=$enable_v4l2;
+		if test "$enable_v4l2" = "no"; then
+		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if V4L2 is disabled... yes" >&5
+$as_echo "Checking if V4L2 is disabled... yes" >&6; }
+		fi
+
+else
+
+
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for v4l2_open in -lv4l2" >&5
+$as_echo_n "checking for v4l2_open in -lv4l2... " >&6; }
+if test "${ac_cv_lib_v4l2_v4l2_open+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lv4l2  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char v4l2_open ();
+int
+main ()
+{
+return v4l2_open ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_v4l2_v4l2_open=yes
+else
+  ac_cv_lib_v4l2_v4l2_open=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_v4l2_v4l2_open" >&5
+$as_echo "$ac_cv_lib_v4l2_v4l2_open" >&6; }
+if test "x$ac_cv_lib_v4l2_v4l2_open" = x""yes; then :
+  ac_v4l2_cflags="-DPJMEDIA_VIDEO_DEV_HAS_V4L2=1"
+			      ac_v4l2_ldflags="-lv4l2"
+
+
+fi
+
+
+fi
 
 
 # Check whether --enable-ipp was given.
-if test "${enable_ipp+set}" = set; then
+if test "${enable_ipp+set}" = set; then :
   enableval=$enable_ipp;
 else
@@ -11657,5 +6199,5 @@
 
 # Check whether --with-ipp was given.
-if test "${with_ipp+set}" = set; then
+if test "${with_ipp+set}" = set; then :
   withval=$with_ipp;
 else
@@ -11667,5 +6209,5 @@
 
 # Check whether --with-ipp-samples was given.
-if test "${with_ipp_samples+set}" = set; then
+if test "${with_ipp_samples+set}" = set; then :
   withval=$with_ipp_samples;
 else
@@ -11677,5 +6219,5 @@
 
 # Check whether --with-ipp-arch was given.
-if test "${with_ipp_arch+set}" = set; then
+if test "${with_ipp_arch+set}" = set; then :
   withval=$with_ipp_arch;
 else
@@ -11686,44 +6228,38 @@
 
 if test "x$enable_ipp" != "xno"; then
-                { echo "$as_me:$LINENO: checking Intel IPP location" >&5
-echo $ECHO_N "checking Intel IPP location... $ECHO_C" >&6; }
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking Intel IPP location" >&5
+$as_echo_n "checking Intel IPP location... " >&6; }
 
     if test "x$with_ipp" != "xno" -a "x$with_ipp" != "x"; then
-	{ echo "$as_me:$LINENO: result: $with_ipp" >&5
-echo "${ECHO_T}$with_ipp" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_ipp" >&5
+$as_echo "$with_ipp" >&6; }
 	IPPROOT=$with_ipp
     elif test "x$IPPROOT" = "x"; then
 	if test -d /opt/intel/ipp; then
 	    IPPROOT=`ls -d /opt/intel/ipp/*/* | head -1`
-	    { echo "$as_me:$LINENO: result: autodetected in $IPPROOT" >&5
-echo "${ECHO_T}autodetected in $IPPROOT" >&6; }
+	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: autodetected in $IPPROOT" >&5
+$as_echo "autodetected in $IPPROOT" >&6; }
 	fi
     else
-	{ echo "$as_me:$LINENO: result: $IPPROOT" >&5
-echo "${ECHO_T}$IPPROOT" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $IPPROOT" >&5
+$as_echo "$IPPROOT" >&6; }
     fi
 
     if test "x$with_ipp_arch" != "xno"; then
 	IPP_SUFFIX=$with_ipp_arch
-	{ echo "$as_me:$LINENO: result: IPP arch suffix is set to $IPP_SUFFIX" >&5
-echo "${ECHO_T}IPP arch suffix is set to $IPP_SUFFIX" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: IPP arch suffix is set to $IPP_SUFFIX" >&5
+$as_echo "IPP arch suffix is set to $IPP_SUFFIX" >&6; }
     else
 	IPP_SUFFIX=""
-	{ echo "$as_me:$LINENO: result: IPP arch suffix is set to empty" >&5
-echo "${ECHO_T}IPP arch suffix is set to empty" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: IPP arch suffix is set to empty" >&5
+$as_echo "IPP arch suffix is set to empty" >&6; }
     fi
 
     if test x$IPPROOT = x; then
-	{ { echo "$as_me:$LINENO: error: the location is neither specified nor can be guessed. Please specify with IPPROOT env var or with --with-ipp option" >&5
-echo "$as_me: error: the location is neither specified nor can be guessed. Please specify with IPPROOT env var or with --with-ipp option" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "the location is neither specified nor can be guessed. Please specify with IPPROOT env var or with --with-ipp option" "$LINENO" 5
     elif test ! -d $IPPROOT; then
-	{ { echo "$as_me:$LINENO: error: not found" >&5
-echo "$as_me: error: not found" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "not found" "$LINENO" 5
     elif test ! -d $IPPROOT/include; then
-	{ { echo "$as_me:$LINENO: error: directory doesn't seem to be valid" >&5
-echo "$as_me: error: directory doesn't seem to be valid" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "directory doesn't seem to be valid" "$LINENO" 5
     else
 	# IPP directory looks okay.
@@ -11758,11 +6294,7 @@
 
 
-	{ echo "$as_me:$LINENO: checking Intel IPP usability" >&5
-echo $ECHO_N "checking Intel IPP usability... $ECHO_C" >&6; }
-	cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Intel IPP usability" >&5
+$as_echo_n "checking Intel IPP usability... " >&6; }
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <ippcore.h>
@@ -11776,37 +6308,16 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
-  { echo "$as_me:$LINENO: result: ok" >&5
-echo "${ECHO_T}ok" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ { echo "$as_me:$LINENO: error: Error: unable to recognize your IPP installation. Make sure the paths and ARCH suffix are set correctly
-See \`config.log' for more details." >&5
-echo "$as_me: error: Error: unable to recognize your IPP installation. Make sure the paths and ARCH suffix are set correctly
-See \`config.log' for more details." >&2;}
-   { (exit run with --help for more info); exit run with --help for more info; }; }
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+$as_echo "ok" >&6; }
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ as_fn_set_status run with --help for more info
+as_fn_error "Error: unable to recognize your IPP installation. Make sure the paths and ARCH suffix are set correctly
+See \`config.log' for more details." "$LINENO" 5; }; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 
 	CFLAGS="$SAVED_CFLAGS"
@@ -11815,34 +6326,28 @@
     fi
 
-                { echo "$as_me:$LINENO: checking Intel IPP samples location" >&5
-echo $ECHO_N "checking Intel IPP samples location... $ECHO_C" >&6; }
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking Intel IPP samples location" >&5
+$as_echo_n "checking Intel IPP samples location... " >&6; }
 
     if test "x$with_ipp_samples" != "xno" -a "x$with_ipp_samples" != "x"; then
-	{ echo "$as_me:$LINENO: result: $with_ipp_samples" >&5
-echo "${ECHO_T}$with_ipp_samples" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_ipp_samples" >&5
+$as_echo "$with_ipp_samples" >&6; }
 	IPPSAMPLES=$with_ipp_samples
     elif test "x$IPPSAMPLES" = "x"; then
 	if test -d /opt/intel/ipp-samples; then
 	    IPPSAMPLES=/opt/intel/ipp-samples
-	    { echo "$as_me:$LINENO: result: autodetected in $IPPSAMPLES" >&5
-echo "${ECHO_T}autodetected in $IPPSAMPLES" >&6; }
+	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: autodetected in $IPPSAMPLES" >&5
+$as_echo "autodetected in $IPPSAMPLES" >&6; }
 	fi
     else
-	{ echo "$as_me:$LINENO: result: $IPPSAMPLES" >&5
-echo "${ECHO_T}$IPPSAMPLES" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $IPPSAMPLES" >&5
+$as_echo "$IPPSAMPLES" >&6; }
     fi
 
     if test x$IPPSAMPLES = x; then
-	{ { echo "$as_me:$LINENO: error: the location is neither specified nor can be guessed. Please specify with IPPSAMPLES env var or with --with-ipp-samples option" >&5
-echo "$as_me: error: the location is neither specified nor can be guessed. Please specify with IPPSAMPLES env var or with --with-ipp-samples option" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "the location is neither specified nor can be guessed. Please specify with IPPSAMPLES env var or with --with-ipp-samples option" "$LINENO" 5
     elif test ! -d $IPPSAMPLES; then
-	{ { echo "$as_me:$LINENO: error: not found" >&5
-echo "$as_me: error: not found" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "not found" "$LINENO" 5
     elif test ! -d $IPPSAMPLES/speech-codecs; then
-	{ { echo "$as_me:$LINENO: error: directory doesn't seem to be valid" >&5
-echo "$as_me: error: directory doesn't seem to be valid" >&2;}
-   { (exit 1); exit 1; }; }
+	as_fn_error "directory doesn't seem to be valid" "$LINENO" 5
     else
 	# Remove trailing backslash
@@ -11850,6 +6355,6 @@
 
 	# Guess the libusc.a/libspeech.a build location
-	{ echo "$as_me:$LINENO: checking Intel IPP USC build location" >&5
-echo $ECHO_N "checking Intel IPP USC build location... $ECHO_C" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Intel IPP USC build location" >&5
+$as_echo_n "checking Intel IPP USC build location... " >&6; }
 	if test -d $IPPSAMPLES/speech-codecs/bin; then
 	    IPPVER=5
@@ -11864,25 +6369,22 @@
 	    	IPPSAMP_DIR=`ls -d $IPPSAMPLES/speech-codecs/_bin/*icc*/lib | head -1`
 	    else
-		{ { echo "$as_me:$LINENO: error: Unable to find to find built binaries under $IPPSAMPLES/speech-codecs/{bin,_bin}. Have you built the IPP samples?
-See \`config.log' for more details." >&5
-echo "$as_me: error: Unable to find to find built binaries under $IPPSAMPLES/speech-codecs/{bin,_bin}. Have you built the IPP samples?
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+		{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "Unable to find to find built binaries under $IPPSAMPLES/speech-codecs/{bin,_bin}. Have you built the IPP samples?
+See \`config.log' for more details." "$LINENO" 5; }
 	    fi
 	else
-	    { { echo "$as_me:$LINENO: error: unable to find $IPPSAMPLES/speech-codecs/bin/*gcc*/lib or $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib directory. Have you built the samples?
-See \`config.log' for more details." >&5
-echo "$as_me: error: unable to find $IPPSAMPLES/speech-codecs/bin/*gcc*/lib or $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib directory. Have you built the samples?
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+	    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "unable to find $IPPSAMPLES/speech-codecs/bin/*gcc*/lib or $IPPSAMPLES/speech-codecs/_bin/*gcc*/lib directory. Have you built the samples?
+See \`config.log' for more details." "$LINENO" 5; }
 	fi
 
 	# Test the directory
 	if test ! -d $IPPSAMP_DIR; then
-	    { { echo "$as_me:$LINENO: error: There's something wrong with this script, directory $IPPSAMP_DIR does not exist
-See \`config.log' for more details." >&5
-echo "$as_me: error: There's something wrong with this script, directory $IPPSAMP_DIR does not exist
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+	    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "There's something wrong with this script, directory $IPPSAMP_DIR does not exist
+See \`config.log' for more details." "$LINENO" 5; }
 	    exit 1;
 	fi
@@ -11895,21 +6397,19 @@
 	    IPPSAMP_LDLIBS="-lspeech"
 	else
-	    { { echo "$as_me:$LINENO: error: bug in this script: unsupported IPP version
-See \`config.log' for more details." >&5
-echo "$as_me: error: bug in this script: unsupported IPP version
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+	    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "bug in this script: unsupported IPP version
+See \`config.log' for more details." "$LINENO" 5; }
 	fi
 
 	if test ! -f $IPPSAMP_DIR/$IPPSAMP_LIBS; then
-	    { { echo "$as_me:$LINENO: error: $IPPSAMP_LIBS doesn't exist in $IPPSAMP_DIR
-See \`config.log' for more details." >&5
-echo "$as_me: error: $IPPSAMP_LIBS doesn't exist in $IPPSAMP_DIR
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
+	    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "$IPPSAMP_LIBS doesn't exist in $IPPSAMP_DIR
+See \`config.log' for more details." "$LINENO" 5; }
 	fi
 
-	{ echo "$as_me:$LINENO: result: $IPPSAMP_DIR" >&5
-echo "${ECHO_T}$IPPSAMP_DIR" >&6; }
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $IPPSAMP_DIR" >&5
+$as_echo "$IPPSAMP_DIR" >&6; }
 
 	SAVED_CFLAGS="$CFLAGS"
@@ -11922,11 +6422,7 @@
 	LIBS="$IPPSAMP_LDLIBS $LIBS"
 
-	{ echo "$as_me:$LINENO: checking Intel IPP USC usability" >&5
-echo $ECHO_N "checking Intel IPP USC usability... $ECHO_C" >&6; }
-	cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Intel IPP USC usability" >&5
+$as_echo_n "checking Intel IPP USC usability... " >&6; }
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <usc.h>
@@ -11940,37 +6436,15 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
-  { echo "$as_me:$LINENO: result: ok" >&5
-echo "${ECHO_T}ok" >&6; }
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	{ { echo "$as_me:$LINENO: error: failed
-See \`config.log' for more details." >&5
-echo "$as_me: error: failed
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+if ac_fn_c_try_link "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+$as_echo "ok" >&6; }
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "failed
+See \`config.log' for more details." "$LINENO" 5; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 
 	CFLAGS="$SAVED_CFLAGS"
@@ -11992,6 +6466,6 @@
 export IPP_LIBS=$IPP_LIBS"
 else
-    { echo "$as_me:$LINENO: result: Skipping Intel IPP settings (not wanted)" >&5
-echo "${ECHO_T}Skipping Intel IPP settings (not wanted)" >&6; }
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: Skipping Intel IPP settings (not wanted)" >&5
+$as_echo "Skipping Intel IPP settings (not wanted)" >&6; }
 fi
 
@@ -12000,161 +6474,33 @@
 
 # Check whether --enable-ssl was given.
-if test "${enable_ssl+set}" = set; then
+if test "${enable_ssl+set}" = set; then :
   enableval=$enable_ssl;
 		if test "$enable_ssl" = "no"; then
 		 ac_no_ssl=1
-		 { echo "$as_me:$LINENO: result: Checking if SSL support is disabled... yes" >&5
-echo "${ECHO_T}Checking if SSL support is disabled... yes" >&6; }
+		 { $as_echo "$as_me:${as_lineno-$LINENO}: result: Checking if SSL support is disabled... yes" >&5
+$as_echo "Checking if SSL support is disabled... yes" >&6; }
 	        fi
 
 else
 
-		{ echo "$as_me:$LINENO: result: checking for OpenSSL installations.." >&5
-echo "${ECHO_T}checking for OpenSSL installations.." >&6; }
-
-
-
-		if test "${ac_cv_header_openssl_ssl_h+set}" = set; then
-  { echo "$as_me:$LINENO: checking for openssl/ssl.h" >&5
-echo $ECHO_N "checking for openssl/ssl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_openssl_ssl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_openssl_ssl_h" >&5
-echo "${ECHO_T}$ac_cv_header_openssl_ssl_h" >&6; }
-else
-  # Is the header compilable?
-{ echo "$as_me:$LINENO: checking openssl/ssl.h usability" >&5
-echo $ECHO_N "checking openssl/ssl.h usability... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <openssl/ssl.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_header_compiler=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6; }
-
-# Is the header present?
-{ echo "$as_me:$LINENO: checking openssl/ssl.h presence" >&5
-echo $ECHO_N "checking openssl/ssl.h presence... $ECHO_C" >&6; }
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <openssl/ssl.h>
-_ACEOF
-if { (ac_try="$ac_cpp conftest.$ac_ext"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null && {
-	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       }; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-
-rm -f conftest.err conftest.$ac_ext
-{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6; }
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: openssl/ssl.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: openssl/ssl.h: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: openssl/ssl.h: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: openssl/ssl.h:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: openssl/ssl.h: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: openssl/ssl.h:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: openssl/ssl.h: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: openssl/ssl.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: openssl/ssl.h: in the future, the compiler will take precedence" >&2;}
-
-    ;;
-esac
-{ echo "$as_me:$LINENO: checking for openssl/ssl.h" >&5
-echo $ECHO_N "checking for openssl/ssl.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_openssl_ssl_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_cv_header_openssl_ssl_h=$ac_header_preproc
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_openssl_ssl_h" >&5
-echo "${ECHO_T}$ac_cv_header_openssl_ssl_h" >&6; }
-
-fi
-if test $ac_cv_header_openssl_ssl_h = yes; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for OpenSSL installations.." >&5
+$as_echo "checking for OpenSSL installations.." >&6; }
+
+
+
+		ac_fn_c_check_header_mongrel "$LINENO" "openssl/ssl.h" "ac_cv_header_openssl_ssl_h" "$ac_includes_default"
+if test "x$ac_cv_header_openssl_ssl_h" = x""yes; then :
   openssl_h_present=1
 fi
 
 
-		{ echo "$as_me:$LINENO: checking for ERR_load_BIO_strings in -lcrypto" >&5
-echo $ECHO_N "checking for ERR_load_BIO_strings in -lcrypto... $ECHO_C" >&6; }
-if test "${ac_cv_lib_crypto_ERR_load_BIO_strings+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ERR_load_BIO_strings in -lcrypto" >&5
+$as_echo_n "checking for ERR_load_BIO_strings in -lcrypto... " >&6; }
+if test "${ac_cv_lib_crypto_ERR_load_BIO_strings+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lcrypto  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -12174,52 +6520,27 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_crypto_ERR_load_BIO_strings=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_crypto_ERR_load_BIO_strings=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_crypto_ERR_load_BIO_strings=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_crypto_ERR_load_BIO_strings" >&5
-echo "${ECHO_T}$ac_cv_lib_crypto_ERR_load_BIO_strings" >&6; }
-if test $ac_cv_lib_crypto_ERR_load_BIO_strings = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_ERR_load_BIO_strings" >&5
+$as_echo "$ac_cv_lib_crypto_ERR_load_BIO_strings" >&6; }
+if test "x$ac_cv_lib_crypto_ERR_load_BIO_strings" = x""yes; then :
   libcrypto_present=1 && LIBS="$LIBS -lcrypto"
 fi
 
-		{ echo "$as_me:$LINENO: checking for SSL_library_init in -lssl" >&5
-echo $ECHO_N "checking for SSL_library_init in -lssl... $ECHO_C" >&6; }
-if test "${ac_cv_lib_ssl_SSL_library_init+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSL_library_init in -lssl" >&5
+$as_echo_n "checking for SSL_library_init in -lssl... " >&6; }
+if test "${ac_cv_lib_ssl_SSL_library_init+set}" = set; then :
+  $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lssl  $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -12239,52 +6560,29 @@
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_link") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext &&
-       $as_test_x conftest$ac_exeext; then
+if ac_fn_c_try_link "$LINENO"; then :
   ac_cv_lib_ssl_SSL_library_init=yes
 else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_cv_lib_ssl_SSL_library_init=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext conftest.$ac_ext
+  ac_cv_lib_ssl_SSL_library_init=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ echo "$as_me:$LINENO: result: $ac_cv_lib_ssl_SSL_library_init" >&5
-echo "${ECHO_T}$ac_cv_lib_ssl_SSL_library_init" >&6; }
-if test $ac_cv_lib_ssl_SSL_library_init = yes; then
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ssl_SSL_library_init" >&5
+$as_echo "$ac_cv_lib_ssl_SSL_library_init" >&6; }
+if test "x$ac_cv_lib_ssl_SSL_library_init" = x""yes; then :
   libssl_present=1 && LIBS="$LIBS -lssl"
 fi
 
 		if test "x$openssl_h_present" = "x1" -a "x$libssl_present" = "x1" -a "x$libcrypto_present" = "x1"; then
-	        	{ echo "$as_me:$LINENO: result: OpenSSL library found, SSL support enabled" >&5
-echo "${ECHO_T}OpenSSL library found, SSL support enabled" >&6; }
+	        	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: OpenSSL library found, SSL support enabled" >&5
+$as_echo "OpenSSL library found, SSL support enabled" >&6; }
 			# PJSIP_HAS_TLS_TRANSPORT setting follows PJ_HAS_SSL_SOCK
 			#AC_DEFINE(PJSIP_HAS_TLS_TRANSPORT, 1)
-			cat >>confdefs.h <<\_ACEOF
-#define PJ_HAS_SSL_SOCK 1
-_ACEOF
+			$as_echo "#define PJ_HAS_SSL_SOCK 1" >>confdefs.h
 
 		else
-			{ echo "$as_me:$LINENO: result: ** OpenSSL libraries not found, disabling SSL support **" >&5
-echo "${ECHO_T}** OpenSSL libraries not found, disabling SSL support **" >&6; }
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ** OpenSSL libraries not found, disabling SSL support **" >&5
+$as_echo "** OpenSSL libraries not found, disabling SSL support **" >&6; }
 		fi
 
@@ -12295,60 +6593,48 @@
 
 
-{ echo "$as_me:$LINENO: checking if select() needs correct nfds" >&5
-echo $ECHO_N "checking if select() needs correct nfds... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if select() needs correct nfds" >&5
+$as_echo_n "checking if select() needs correct nfds... " >&6; }
 case $target in
-  *rtems*) cat >>confdefs.h <<\_ACEOF
-#define PJ_SELECT_NEEDS_NFDS 1
-_ACEOF
-
-	   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
+  *rtems*) $as_echo "#define PJ_SELECT_NEEDS_NFDS 1" >>confdefs.h
+
+	   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 	;;
-  *) cat >>confdefs.h <<\_ACEOF
-#define PJ_SELECT_NEEDS_NFDS 0
-_ACEOF
-
-     { echo "$as_me:$LINENO: result: no (default)" >&5
-echo "${ECHO_T}no (default)" >&6; }
-     { echo "$as_me:$LINENO: result: ** Decided that select() doesn't need correct nfds (please check)" >&5
-echo "${ECHO_T}** Decided that select() doesn't need correct nfds (please check)" >&6; }
+  *) $as_echo "#define PJ_SELECT_NEEDS_NFDS 0" >>confdefs.h
+
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no (default)" >&5
+$as_echo "no (default)" >&6; }
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: ** Decided that select() doesn't need correct nfds (please check)" >&5
+$as_echo "** Decided that select() doesn't need correct nfds (please check)" >&6; }
 	;;
 esac
 
-{ echo "$as_me:$LINENO: checking if pj_thread_create() should enforce stack size" >&5
-echo $ECHO_N "checking if pj_thread_create() should enforce stack size... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if pj_thread_create() should enforce stack size" >&5
+$as_echo_n "checking if pj_thread_create() should enforce stack size... " >&6; }
 case $target in
-  *rtems*) cat >>confdefs.h <<\_ACEOF
-#define PJ_THREAD_SET_STACK_SIZE 1
-_ACEOF
-
-	   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
+  *rtems*) $as_echo "#define PJ_THREAD_SET_STACK_SIZE 1" >>confdefs.h
+
+	   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 	;;
-  *) cat >>confdefs.h <<\_ACEOF
-#define PJ_THREAD_SET_STACK_SIZE 0
-_ACEOF
-
-     { echo "$as_me:$LINENO: result: no (default)" >&5
-echo "${ECHO_T}no (default)" >&6; }
+  *) $as_echo "#define PJ_THREAD_SET_STACK_SIZE 0" >>confdefs.h
+
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no (default)" >&5
+$as_echo "no (default)" >&6; }
 	;;
 esac
 
-{ echo "$as_me:$LINENO: checking if pj_thread_create() should allocate stack" >&5
-echo $ECHO_N "checking if pj_thread_create() should allocate stack... $ECHO_C" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if pj_thread_create() should allocate stack" >&5
+$as_echo_n "checking if pj_thread_create() should allocate stack... " >&6; }
 case $target in
-  *rtems*) cat >>confdefs.h <<\_ACEOF
-#define PJ_THREAD_ALLOCATE_STACK 1
-_ACEOF
-
-	   { echo "$as_me:$LINENO: result: yes" >&5
-echo "${ECHO_T}yes" >&6; }
+  *rtems*) $as_echo "#define PJ_THREAD_ALLOCATE_STACK 1" >>confdefs.h
+
+	   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 	;;
-  *) cat >>confdefs.h <<\_ACEOF
-#define PJ_THREAD_ALLOCATE_STACK 0
-_ACEOF
-
-     { echo "$as_me:$LINENO: result: no (default)" >&5
-echo "${ECHO_T}no (default)" >&6; }
+  *) $as_echo "#define PJ_THREAD_ALLOCATE_STACK 0" >>confdefs.h
+
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no (default)" >&5
+$as_echo "no (default)" >&6; }
 	;;
 esac
@@ -12356,15 +6642,11 @@
 case $target in
   *mingw* | *cygw* | *win32* | *w32* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_BLOCKING_ERROR_VAL WSAEWOULDBLOCK
-_ACEOF
+	$as_echo "#define PJ_BLOCKING_ERROR_VAL WSAEWOULDBLOCK" >>confdefs.h
 
 	;;
-  *) cat >>confdefs.h <<\_ACEOF
-#define PJ_BLOCKING_ERROR_VAL EAGAIN
-_ACEOF
-
-     { echo "$as_me:$LINENO: result: ** Setting non-blocking recv() retval to EAGAIN (please check)" >&5
-echo "${ECHO_T}** Setting non-blocking recv() retval to EAGAIN (please check)" >&6; }
+  *) $as_echo "#define PJ_BLOCKING_ERROR_VAL EAGAIN" >>confdefs.h
+
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: ** Setting non-blocking recv() retval to EAGAIN (please check)" >&5
+$as_echo "** Setting non-blocking recv() retval to EAGAIN (please check)" >&6; }
 	;;
 esac
@@ -12372,15 +6654,11 @@
 case $target in
   *mingw* | *cygw* | *win32* | *w32* )
-	cat >>confdefs.h <<\_ACEOF
-#define PJ_BLOCKING_CONNECT_ERROR_VAL WSAEWOULDBLOCK
-_ACEOF
+	$as_echo "#define PJ_BLOCKING_CONNECT_ERROR_VAL WSAEWOULDBLOCK" >>confdefs.h
 
 	;;
-  *) cat >>confdefs.h <<\_ACEOF
-#define PJ_BLOCKING_CONNECT_ERROR_VAL EINPROGRESS
-_ACEOF
-
-     { echo "$as_me:$LINENO: result: ** Setting non-blocking connect() retval to EINPROGRESS (please check)" >&5
-echo "${ECHO_T}** Setting non-blocking connect() retval to EINPROGRESS (please check)" >&6; }
+  *) $as_echo "#define PJ_BLOCKING_CONNECT_ERROR_VAL EINPROGRESS" >>confdefs.h
+
+     { $as_echo "$as_me:${as_lineno-$LINENO}: result: ** Setting non-blocking connect() retval to EINPROGRESS (please check)" >&5
+$as_echo "** Setting non-blocking connect() retval to EINPROGRESS (please check)" >&6; }
 	;;
 esac
@@ -12437,10 +6715,11 @@
     *${as_nl}*)
       case $ac_var in #(
-      *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5
-echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;;
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
       esac
       case $ac_var in #(
       _ | IFS | as_nl) ;; #(
-      *) $as_unset $ac_var ;;
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
       esac ;;
     esac
@@ -12450,6 +6729,6 @@
     case $as_nl`(ac_space=' '; set) 2>&1` in #(
     *${as_nl}ac_space=\ *)
-      # `set' does not quote correctly, so add quotes (double-quote
-      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
       sed -n \
 	"s/'/'\\\\''/g;
@@ -12474,10 +6753,10 @@
   if test -w "$cache_file"; then
     test "x$cache_file" != "x/dev/null" &&
-      { echo "$as_me:$LINENO: updating cache $cache_file" >&5
-echo "$as_me: updating cache $cache_file" >&6;}
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
     cat confcache >$cache_file
   else
-    { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5
-echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
   fi
 fi
@@ -12495,9 +6774,9 @@
   # 1. Remove the extension, and $U if already installed.
   ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
-  ac_i=`echo "$ac_i" | sed "$ac_script"`
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
   # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
   #    will be set to the directory where LIBOBJS objects are built.
-  ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext"
-  ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo'
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
 done
 LIBOBJS=$ac_libobjs
@@ -12507,10 +6786,13 @@
 
 
+
 : ${CONFIG_STATUS=./config.status}
+ac_write_fail=0
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files $CONFIG_STATUS"
-{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
-echo "$as_me: creating $CONFIG_STATUS" >&6;}
-cat >$CONFIG_STATUS <<_ACEOF
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
 #! $SHELL
 # Generated by $as_me.
@@ -12522,57 +6804,77 @@
 ac_cs_recheck=false
 ac_cs_silent=false
+
 SHELL=\${CONFIG_SHELL-$SHELL}
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF
-## --------------------- ##
-## M4sh Initialization.  ##
-## --------------------- ##
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
 
 # Be more Bourne compatible
 DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
   emulate sh
   NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
   # is contrary to our usage.  Disable this feature.
   alias -g '${1+"$@"}'='"$@"'
   setopt NO_GLOB_SUBST
 else
-  case `(set -o) 2>/dev/null` in
-  *posix*) set -o posix ;;
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
 esac
-
-fi
-
-
-
-
-# PATH needs CR
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
 
 # The user is always right.
 if test "${PATH_SEPARATOR+set}" != set; then
-  echo "#! /bin/sh" >conf$$.sh
-  echo  "exit 0"   >>conf$$.sh
-  chmod +x conf$$.sh
-  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
-    PATH_SEPARATOR=';'
-  else
-    PATH_SEPARATOR=:
-  fi
-  rm -f conf$$.sh
-fi
-
-# Support unset when possible.
-if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
-  as_unset=unset
-else
-  as_unset=false
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
 fi
 
@@ -12583,10 +6885,8 @@
 # (If _AS_PATH_WALK were called with IFS unset, it would disable word
 # splitting by setting IFS to empty value.)
-as_nl='
-'
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-case $0 in
+case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -12595,6 +6895,6 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-done
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
 IFS=$as_save_IFS
 
@@ -12607,11 +6907,15 @@
 fi
 if test ! -f "$as_myself"; then
-  echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  { (exit 1); exit 1; }
-fi
-
-# Work around bugs in pre-3.0 UWIN ksh.
-for as_var in ENV MAIL MAILPATH
-do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
 done
 PS1='$ '
@@ -12620,17 +6924,92 @@
 
 # NLS nuisances.
-for as_var in \
-  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
-  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
-  LC_TELEPHONE LC_TIME
-do
-  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
-    eval $as_var=C; export $as_var
-  else
-    ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error ERROR [LINENO LOG_FD]
+# ---------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with status $?, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$?; test $as_status -eq 0 && as_status=1
+  if test "$3"; then
+    as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3
   fi
-done
-
-# Required to use basename.
+  $as_echo "$as_me: error: $1" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
 if expr a : '\(a\)' >/dev/null 2>&1 &&
    test "X`expr 00001 : '.*\(...\)'`" = X001; then
@@ -12646,11 +7025,15 @@
 fi
 
-
-# Name of the executable.
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
 as_me=`$as_basename -- "$0" ||
 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 	 X"$0" : 'X\(//\)$' \| \
 	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-echo X/"$0" |
+$as_echo X/"$0" |
     sed '/^.*\/\([^/][^/]*\)\/*$/{
 	    s//\1/
@@ -12667,64 +7050,19 @@
 	  s/.*/./; q'`
 
-# CDPATH.
-$as_unset CDPATH
-
-
-
-  as_lineno_1=$LINENO
-  as_lineno_2=$LINENO
-  test "x$as_lineno_1" != "x$as_lineno_2" &&
-  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
-
-  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
-  # uniformly replaced by the line number.  The first 'sed' inserts a
-  # line-number line after each line using $LINENO; the second 'sed'
-  # does the real work.  The second script uses 'N' to pair each
-  # line-number line with the line containing $LINENO, and appends
-  # trailing '-' during substitution so that $LINENO is not a special
-  # case at line end.
-  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
-  # scripts with optimization help from Paolo Bonzini.  Blame Lee
-  # E. McMahon (1931-1989) for sed's syntax.  :-)
-  sed -n '
-    p
-    /[$]LINENO/=
-  ' <$as_myself |
-    sed '
-      s/[$]LINENO.*/&-/
-      t lineno
-      b
-      :lineno
-      N
-      :loop
-      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
-      t loop
-      s/-\n.*//
-    ' >$as_me.lineno &&
-  chmod +x "$as_me.lineno" ||
-    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
-   { (exit 1); exit 1; }; }
-
-  # Don't try to exec as it changes $[0], causing all sort of problems
-  # (the dirname of $[0] is not the place where we might find the
-  # original and so on.  Autoconf is especially sensitive to this).
-  . "./$as_me.lineno"
-  # Exit status is that of the last command.
-  exit
-}
-
-
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
-else
-  as_dirname=false
-fi
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
 
 ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in
+case `echo -n x` in #(((((
 -n*)
-  case `echo 'x\c'` in
+  case `echo 'xy\c'` in
   *c*) ECHO_T='	';;	# ECHO_T is single tab character.
-  *)   ECHO_C='\c';;
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
   esac;;
 *)
@@ -12732,11 +7070,4 @@
 esac
 
-if expr a : '\(a\)' >/dev/null 2>&1 &&
-   test "X`expr 00001 : '.*\(...\)'`" = X001; then
-  as_expr=expr
-else
-  as_expr=false
-fi
-
 rm -f conf$$ conf$$.exe conf$$.file
 if test -d conf$$.dir; then
@@ -12744,17 +7075,20 @@
 else
   rm -f conf$$.dir
-  mkdir conf$$.dir
-fi
-echo >conf$$.file
-if ln -s conf$$.file conf$$ 2>/dev/null; then
-  as_ln_s='ln -s'
-  # ... but there are two gotchas:
-  # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
-  # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-  # In both cases, we have to default to `cp -p'.
-  ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -p'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -p'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
     as_ln_s='cp -p'
-elif ln conf$$.file conf$$ 2>/dev/null; then
-  as_ln_s=ln
+  fi
 else
   as_ln_s='cp -p'
@@ -12763,574 +7097,19 @@
 rmdir conf$$.dir 2>/dev/null
 
-if mkdir -p . 2>/dev/null; then
-  as_mkdir_p=:
-else
-  test -d ./-p && rmdir ./-p
-  as_mkdir_p=false
-fi
-
-if test -x / >/dev/null 2>&1; then
-  as_test_x='test -x'
-else
-  if ls -dL / >/dev/null 2>&1; then
-    as_ls_L_option=L
-  else
-    as_ls_L_option=
-  fi
-  as_test_x='
-    eval sh -c '\''
-      if test -d "$1"; then
-        test -d "$1/.";
-      else
-	case $1 in
-        -*)set "./$1";;
-	esac;
-	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
-	???[sx]*):;;*)false;;esac;fi
-    '\'' sh
-  '
-fi
-as_executable_p=$as_test_x
-
-# Sed expression to map a string onto a valid CPP name.
-as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
-
-# Sed expression to map a string onto a valid variable name.
-as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
-
-
-exec 6>&1
-
-# Save the log message, to keep $[0] and so on meaningful, and to
-# report actual input values of CONFIG_FILES etc. instead of their
-# values after options handling.
-ac_log="
-This file was extended by pjproject $as_me 1.x, which was
-generated by GNU Autoconf 2.61.  Invocation command line was
-
-  CONFIG_FILES    = $CONFIG_FILES
-  CONFIG_HEADERS  = $CONFIG_HEADERS
-  CONFIG_LINKS    = $CONFIG_LINKS
-  CONFIG_COMMANDS = $CONFIG_COMMANDS
-  $ $0 $@
-
-on `(hostname || uname -n) 2>/dev/null | sed 1q`
-"
-
-_ACEOF
-
-cat >>$CONFIG_STATUS <<_ACEOF
-# Files that config.status was made for.
-config_files="$ac_config_files"
-config_headers="$ac_config_headers"
-
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF
-ac_cs_usage="\
-\`$as_me' instantiates files from templates according to the
-current configuration.
-
-Usage: $0 [OPTIONS] [FILE]...
-
-  -h, --help       print this help, then exit
-  -V, --version    print version number and configuration settings, then exit
-  -q, --quiet      do not print progress messages
-  -d, --debug      don't remove temporary files
-      --recheck    update $as_me by reconfiguring in the same conditions
-  --file=FILE[:TEMPLATE]
-		   instantiate the configuration file FILE
-  --header=FILE[:TEMPLATE]
-		   instantiate the configuration header FILE
-
-Configuration files:
-$config_files
-
-Configuration headers:
-$config_headers
-
-Report bugs to <bug-autoconf@gnu.org>."
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF
-ac_cs_version="\\
-pjproject config.status 1.x
-configured by $0, generated by GNU Autoconf 2.61,
-  with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
-
-Copyright (C) 2006 Free Software Foundation, Inc.
-This config.status script is free software; the Free Software Foundation
-gives unlimited permission to copy, distribute and modify it."
-
-ac_pwd='$ac_pwd'
-srcdir='$srcdir'
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF
-# If no file are specified by the user, then we need to provide default
-# value.  By we need to know if files were specified by the user.
-ac_need_defaults=:
-while test $# != 0
-do
-  case $1 in
-  --*=*)
-    ac_option=`expr "X$1" : 'X\([^=]*\)='`
-    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
-    ac_shift=:
-    ;;
-  *)
-    ac_option=$1
-    ac_optarg=$2
-    ac_shift=shift
-    ;;
-  esac
-
-  case $ac_option in
-  # Handling of the options.
-  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
-    ac_cs_recheck=: ;;
-  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
-    echo "$ac_cs_version"; exit ;;
-  --debug | --debu | --deb | --de | --d | -d )
-    debug=: ;;
-  --file | --fil | --fi | --f )
-    $ac_shift
-    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
-    ac_need_defaults=false;;
-  --header | --heade | --head | --hea )
-    $ac_shift
-    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
-    ac_need_defaults=false;;
-  --he | --h)
-    # Conflict between --help and --header
-    { echo "$as_me: error: ambiguous option: $1
-Try \`$0 --help' for more information." >&2
-   { (exit 1); exit 1; }; };;
-  --help | --hel | -h )
-    echo "$ac_cs_usage"; exit ;;
-  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
-  | -silent | --silent | --silen | --sile | --sil | --si | --s)
-    ac_cs_silent=: ;;
-
-  # This is an error.
-  -*) { echo "$as_me: error: unrecognized option: $1
-Try \`$0 --help' for more information." >&2
-   { (exit 1); exit 1; }; } ;;
-
-  *) ac_config_targets="$ac_config_targets $1"
-     ac_need_defaults=false ;;
-
-  esac
-  shift
-done
-
-ac_configure_extra_args=
-
-if $ac_cs_silent; then
-  exec 6>/dev/null
-  ac_configure_extra_args="$ac_configure_extra_args --silent"
-fi
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF
-if \$ac_cs_recheck; then
-  echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
-  CONFIG_SHELL=$SHELL
-  export CONFIG_SHELL
-  exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
-fi
-
-_ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
-exec 5>>config.log
-{
-  echo
-  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
-## Running $as_me. ##
-_ASBOX
-  echo "$ac_log"
-} >&5
-
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF
-_ACEOF
-
-cat >>$CONFIG_STATUS <<\_ACEOF
-
-# Handling of arguments.
-for ac_config_target in $ac_config_targets
-do
-  case $ac_config_target in
-    "pjlib/include/pj/compat/os_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjlib/include/pj/compat/os_auto.h" ;;
-    "pjlib/include/pj/compat/m_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjlib/include/pj/compat/m_auto.h" ;;
-    "pjmedia/include/pjmedia/config_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjmedia/include/pjmedia/config_auto.h" ;;
-    "pjmedia/include/pjmedia-codec/config_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjmedia/include/pjmedia-codec/config_auto.h" ;;
-    "pjsip/include/pjsip/sip_autoconf.h") CONFIG_HEADERS="$CONFIG_HEADERS pjsip/include/pjsip/sip_autoconf.h" ;;
-    "build.mak") CONFIG_FILES="$CONFIG_FILES build.mak" ;;
-    "build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES build/os-auto.mak" ;;
-    "build/cc-auto.mak") CONFIG_FILES="$CONFIG_FILES build/cc-auto.mak" ;;
-    "pjlib/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib/build/os-auto.mak" ;;
-    "pjlib-util/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib-util/build/os-auto.mak" ;;
-    "pjmedia/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjmedia/build/os-auto.mak" ;;
-    "pjsip/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjsip/build/os-auto.mak" ;;
-    "third_party/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES third_party/build/os-auto.mak" ;;
-    "third_party/build/portaudio/os-auto.mak") CONFIG_FILES="$CONFIG_FILES third_party/build/portaudio/os-auto.mak" ;;
-
-  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
-echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
-   { (exit 1); exit 1; }; };;
-  esac
-done
-
-
-# If the user did not use the arguments to specify the items to instantiate,
-# then the envvar interface is used.  Set only those that are not.
-# We use the long form for the default assignment because of an extremely
-# bizarre bug on SunOS 4.1.3.
-if $ac_need_defaults; then
-  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
-  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
-fi
-
-# Have a temporary directory for convenience.  Make it in the build tree
-# simply because there is no reason against having it here, and in addition,
-# creating and moving files from /tmp can sometimes cause problems.
-# Hook for its removal unless debugging.
-# Note that there is a small window in which the directory will not be cleaned:
-# after its creation but before its name has been assigned to `$tmp'.
-$debug ||
-{
-  tmp=
-  trap 'exit_status=$?
-  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
-' 0
-  trap '{ (exit 1); exit 1; }' 1 2 13 15
-}
-# Create a (secure) tmp directory for tmp files.
-
-{
-  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
-  test -n "$tmp" && test -d "$tmp"
-}  ||
-{
-  tmp=./conf$$-$RANDOM
-  (umask 077 && mkdir "$tmp")
-} ||
-{
-   echo "$me: cannot create a temporary directory in ." >&2
-   { (exit 1); exit 1; }
-}
-
-#
-# Set up the sed scripts for CONFIG_FILES section.
-#
-
-# No need to generate the scripts if there are no CONFIG_FILES.
-# This happens for instance when ./config.status config.h
-if test -n "$CONFIG_FILES"; then
-
-_ACEOF
-
-
-
-ac_delim='%!_!# '
-for ac_last_try in false false false false false :; do
-  cat >conf$$subs.sed <<_ACEOF
-SHELL!$SHELL$ac_delim
-PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim
-PACKAGE_NAME!$PACKAGE_NAME$ac_delim
-PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim
-PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim
-PACKAGE_STRING!$PACKAGE_STRING$ac_delim
-PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim
-exec_prefix!$exec_prefix$ac_delim
-prefix!$prefix$ac_delim
-program_transform_name!$program_transform_name$ac_delim
-bindir!$bindir$ac_delim
-sbindir!$sbindir$ac_delim
-libexecdir!$libexecdir$ac_delim
-datarootdir!$datarootdir$ac_delim
-datadir!$datadir$ac_delim
-sysconfdir!$sysconfdir$ac_delim
-sharedstatedir!$sharedstatedir$ac_delim
-localstatedir!$localstatedir$ac_delim
-includedir!$includedir$ac_delim
-oldincludedir!$oldincludedir$ac_delim
-docdir!$docdir$ac_delim
-infodir!$infodir$ac_delim
-htmldir!$htmldir$ac_delim
-dvidir!$dvidir$ac_delim
-pdfdir!$pdfdir$ac_delim
-psdir!$psdir$ac_delim
-libdir!$libdir$ac_delim
-localedir!$localedir$ac_delim
-mandir!$mandir$ac_delim
-DEFS!$DEFS$ac_delim
-ECHO_C!$ECHO_C$ac_delim
-ECHO_N!$ECHO_N$ac_delim
-ECHO_T!$ECHO_T$ac_delim
-LIBS!$LIBS$ac_delim
-build_alias!$build_alias$ac_delim
-host_alias!$host_alias$ac_delim
-target_alias!$target_alias$ac_delim
-build!$build$ac_delim
-build_cpu!$build_cpu$ac_delim
-build_vendor!$build_vendor$ac_delim
-build_os!$build_os$ac_delim
-host!$host$ac_delim
-host_cpu!$host_cpu$ac_delim
-host_vendor!$host_vendor$ac_delim
-host_os!$host_os$ac_delim
-target!$target$ac_delim
-target_cpu!$target_cpu$ac_delim
-target_vendor!$target_vendor$ac_delim
-target_os!$target_os$ac_delim
-CC!$CC$ac_delim
-CFLAGS!$CFLAGS$ac_delim
-LDFLAGS!$LDFLAGS$ac_delim
-CPPFLAGS!$CPPFLAGS$ac_delim
-ac_ct_CC!$ac_ct_CC$ac_delim
-EXEEXT!$EXEEXT$ac_delim
-OBJEXT!$OBJEXT$ac_delim
-CXX!$CXX$ac_delim
-CXXFLAGS!$CXXFLAGS$ac_delim
-ac_ct_CXX!$ac_ct_CXX$ac_delim
-AR!$AR$ac_delim
-LD!$LD$ac_delim
-LDOUT!$LDOUT$ac_delim
-RANLIB!$RANLIB$ac_delim
-LIBEXT!$LIBEXT$ac_delim
-LIBEXT2!$LIBEXT2$ac_delim
-CC_OUT!$CC_OUT$ac_delim
-CC_INC!$CC_INC$ac_delim
-CC_DEF!$CC_DEF$ac_delim
-CC_OPTIMIZE!$CC_OPTIMIZE$ac_delim
-CC_CFLAGS!$CC_CFLAGS$ac_delim
-ac_pjdir!$ac_pjdir$ac_delim
-ac_build_mak_vars!$ac_build_mak_vars$ac_delim
-CPP!$CPP$ac_delim
-GREP!$GREP$ac_delim
-EGREP!$EGREP$ac_delim
-ac_os_objs!$ac_os_objs$ac_delim
-ac_external_speex!$ac_external_speex$ac_delim
-ac_external_gsm!$ac_external_gsm$ac_delim
-ac_pjmedia_snd!$ac_pjmedia_snd$ac_delim
-ac_external_pa!$ac_external_pa$ac_delim
-ac_pa_cflags!$ac_pa_cflags$ac_delim
-ac_pa_use_alsa!$ac_pa_use_alsa$ac_delim
-ac_pa_use_oss!$ac_pa_use_oss$ac_delim
-ac_no_small_filter!$ac_no_small_filter$ac_delim
-ac_no_large_filter!$ac_no_large_filter$ac_delim
-ac_no_speex_aec!$ac_no_speex_aec$ac_delim
-ac_no_g711_codec!$ac_no_g711_codec$ac_delim
-ac_no_l16_codec!$ac_no_l16_codec$ac_delim
-ac_no_gsm_codec!$ac_no_gsm_codec$ac_delim
-ac_no_g722_codec!$ac_no_g722_codec$ac_delim
-ac_no_g7221_codec!$ac_no_g7221_codec$ac_delim
-ac_no_speex_codec!$ac_no_speex_codec$ac_delim
-ac_no_ilbc_codec!$ac_no_ilbc_codec$ac_delim
-ac_no_ssl!$ac_no_ssl$ac_delim
-openssl_h_present!$openssl_h_present$ac_delim
-libssl_present!$libssl_present$ac_delim
-libcrypto_present!$libcrypto_present$ac_delim
-_ACEOF
-
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
-    break
-  elif $ac_last_try; then
-    { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
-echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
-   { (exit 1); exit 1; }; }
-  else
-    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
-  fi
-done
-
-ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed`
-if test -n "$ac_eof"; then
-  ac_eof=`echo "$ac_eof" | sort -nru | sed 1q`
-  ac_eof=`expr $ac_eof + 1`
-fi
-
-cat >>$CONFIG_STATUS <<_ACEOF
-cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof
-/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
-_ACEOF
-sed '
-s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g
-s/^/s,@/; s/!/@,|#_!!_#|/
-:n
-t n
-s/'"$ac_delim"'$/,g/; t
-s/$/\\/; p
-N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n
-' >>$CONFIG_STATUS <conf$$subs.sed
-rm -f conf$$subs.sed
-cat >>$CONFIG_STATUS <<_ACEOF
-CEOF$ac_eof
-_ACEOF
-
-
-ac_delim='%!_!# '
-for ac_last_try in false false false false false :; do
-  cat >conf$$subs.sed <<_ACEOF
-ac_cross_compile!$ac_cross_compile$ac_delim
-ac_linux_poll!$ac_linux_poll$ac_delim
-ac_host!$ac_host$ac_delim
-ac_main_obj!$ac_main_obj$ac_delim
-LIBOBJS!$LIBOBJS$ac_delim
-LTLIBOBJS!$LTLIBOBJS$ac_delim
-_ACEOF
-
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 6; then
-    break
-  elif $ac_last_try; then
-    { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
-echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
-   { (exit 1); exit 1; }; }
-  else
-    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
-  fi
-done
-
-ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed`
-if test -n "$ac_eof"; then
-  ac_eof=`echo "$ac_eof" | sort -nru | sed 1q`
-  ac_eof=`expr $ac_eof + 1`
-fi
-
-cat >>$CONFIG_STATUS <<_ACEOF
-cat >"\$tmp/subs-2.sed" <<\CEOF$ac_eof
-/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end
-_ACEOF
-sed '
-s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g
-s/^/s,@/; s/!/@,|#_!!_#|/
-:n
-t n
-s/'"$ac_delim"'$/,g/; t
-s/$/\\/; p
-N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n
-' >>$CONFIG_STATUS <conf$$subs.sed
-rm -f conf$$subs.sed
-cat >>$CONFIG_STATUS <<_ACEOF
-:end
-s/|#_!!_#|//g
-CEOF$ac_eof
-_ACEOF
-
-
-# VPATH may cause trouble with some makes, so we remove $(srcdir),
-# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
-# trailing colons and then remove the whole line if VPATH becomes empty
-# (actually we leave an empty line to preserve line numbers).
-if test "x$srcdir" = x.; then
-  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
-s/:*\$(srcdir):*/:/
-s/:*\${srcdir}:*/:/
-s/:*@srcdir@:*/:/
-s/^\([^=]*=[	 ]*\):*/\1/
-s/:*$//
-s/^[^=]*=[	 ]*$//
-}'
-fi
-
-cat >>$CONFIG_STATUS <<\_ACEOF
-fi # test -n "$CONFIG_FILES"
-
-
-for ac_tag in  :F $CONFIG_FILES  :H $CONFIG_HEADERS
-do
-  case $ac_tag in
-  :[FHLC]) ac_mode=$ac_tag; continue;;
-  esac
-  case $ac_mode$ac_tag in
-  :[FHL]*:*);;
-  :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5
-echo "$as_me: error: Invalid tag $ac_tag." >&2;}
-   { (exit 1); exit 1; }; };;
-  :[FH]-) ac_tag=-:-;;
-  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
-  esac
-  ac_save_IFS=$IFS
-  IFS=:
-  set x $ac_tag
-  IFS=$ac_save_IFS
-  shift
-  ac_file=$1
-  shift
-
-  case $ac_mode in
-  :L) ac_source=$1;;
-  :[FH])
-    ac_file_inputs=
-    for ac_f
-    do
-      case $ac_f in
-      -) ac_f="$tmp/stdin";;
-      *) # Look for the file first in the build tree, then in the source tree
-	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
-	 # because $ac_f cannot contain `:'.
-	 test -f "$ac_f" ||
-	   case $ac_f in
-	   [\\/$]*) false;;
-	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
-	   esac ||
-	   { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5
-echo "$as_me: error: cannot find input file: $ac_f" >&2;}
-   { (exit 1); exit 1; }; };;
-      esac
-      ac_file_inputs="$ac_file_inputs $ac_f"
-    done
-
-    # Let's still pretend it is `configure' which instantiates (i.e., don't
-    # use $as_me), people would be surprised to read:
-    #    /* config.h.  Generated by config.status.  */
-    configure_input="Generated from "`IFS=:
-	  echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure."
-    if test x"$ac_file" != x-; then
-      configure_input="$ac_file.  $configure_input"
-      { echo "$as_me:$LINENO: creating $ac_file" >&5
-echo "$as_me: creating $ac_file" >&6;}
-    fi
-
-    case $ac_tag in
-    *:-:* | *:-) cat >"$tmp/stdin";;
-    esac
-    ;;
-  esac
-
-  ac_dir=`$as_dirname -- "$ac_file" ||
-$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$ac_file" : 'X\(//\)[^/]' \| \
-	 X"$ac_file" : 'X\(//\)$' \| \
-	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
-echo X"$ac_file" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)[^/].*/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\).*/{
-	    s//\1/
-	    q
-	  }
-	  s/.*/./; q'`
-  { as_dir="$ac_dir"
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
   case $as_dir in #(
   -*) as_dir=./$as_dir;;
   esac
-  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
+  test -d "$as_dir" || eval $as_mkdir_p || {
     as_dirs=
     while :; do
       case $as_dir in #(
-      *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
       *) as_qdir=$as_dir;;
       esac
@@ -13341,5 +7120,5 @@
 	 X"$as_dir" : 'X\(//\)$' \| \
 	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-echo X"$as_dir" |
+$as_echo X"$as_dir" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
 	    s//\1/
@@ -13362,7 +7141,640 @@
     done
     test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
-echo "$as_me: error: cannot create directory $as_dir" >&2;}
-   { (exit 1); exit 1; }; }; }
+  } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in #(
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by pjproject $as_me 1.x, which was
+generated by GNU Autoconf 2.65.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+case $ac_config_headers in *"
+"*) set x $ac_config_headers; shift; ac_config_headers=$*;;
+esac
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_headers="$ac_config_headers"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+      --header=FILE[:TEMPLATE]
+                   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Report bugs to the package provider."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+pjproject config.status 1.x
+configured by $0, generated by GNU Autoconf 2.65,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2009 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h)
+    # Conflict between --help and --header
+    as_fn_error "ambiguous option: \`$1'
+Try \`$0 --help' for more information.";;
+  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "pjlib/include/pj/compat/os_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjlib/include/pj/compat/os_auto.h" ;;
+    "pjlib/include/pj/compat/m_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjlib/include/pj/compat/m_auto.h" ;;
+    "pjmedia/include/pjmedia/config_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjmedia/include/pjmedia/config_auto.h" ;;
+    "pjmedia/include/pjmedia-codec/config_auto.h") CONFIG_HEADERS="$CONFIG_HEADERS pjmedia/include/pjmedia-codec/config_auto.h" ;;
+    "pjsip/include/pjsip/sip_autoconf.h") CONFIG_HEADERS="$CONFIG_HEADERS pjsip/include/pjsip/sip_autoconf.h" ;;
+    "build.mak") CONFIG_FILES="$CONFIG_FILES build.mak" ;;
+    "build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES build/os-auto.mak" ;;
+    "build/cc-auto.mak") CONFIG_FILES="$CONFIG_FILES build/cc-auto.mak" ;;
+    "pjlib/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib/build/os-auto.mak" ;;
+    "pjlib-util/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjlib-util/build/os-auto.mak" ;;
+    "pjmedia/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjmedia/build/os-auto.mak" ;;
+    "pjsip/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES pjsip/build/os-auto.mak" ;;
+    "third_party/build/os-auto.mak") CONFIG_FILES="$CONFIG_FILES third_party/build/os-auto.mak" ;;
+    "third_party/build/portaudio/os-auto.mak") CONFIG_FILES="$CONFIG_FILES third_party/build/portaudio/os-auto.mak" ;;
+
+  *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp=
+  trap 'exit_status=$?
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error "cannot create a temporary directory in ." "$LINENO" 5
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+  || as_fn_error "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[	 ]*\):*/\1/
+s/:*$//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+# Set up the scripts for CONFIG_HEADERS section.
+# No need to generate them if there are no CONFIG_HEADERS.
+# This happens for instance with `./config.status Makefile'.
+if test -n "$CONFIG_HEADERS"; then
+cat >"$tmp/defines.awk" <<\_ACAWK ||
+BEGIN {
+_ACEOF
+
+# Transform confdefs.h into an awk script `defines.awk', embedded as
+# here-document in config.status, that substitutes the proper values into
+# config.h.in to produce config.h.
+
+# Create a delimiter string that does not exist in confdefs.h, to ease
+# handling of long lines.
+ac_delim='%!_!# '
+for ac_last_try in false false :; do
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
+    break
+  elif $ac_last_try; then
+    as_fn_error "could not make $CONFIG_HEADERS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+
+# For the awk script, D is an array of macro values keyed by name,
+# likewise P contains macro parameters if any.  Preserve backslash
+# newline sequences.
+
+ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
+sed -n '
+s/.\{148\}/&'"$ac_delim"'/g
+t rset
+:rset
+s/^[	 ]*#[	 ]*define[	 ][	 ]*/ /
+t def
+d
+:def
+s/\\$//
+t bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3"/p
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2"/p
+d
+:bsnl
+s/["\\]/\\&/g
+s/^ \('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/P["\1"]="\2"\
+D["\1"]=" \3\\\\\\n"\\/p
+t cont
+s/^ \('"$ac_word_re"'\)[	 ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p
+t cont
+d
+:cont
+n
+s/.\{148\}/&'"$ac_delim"'/g
+t clear
+:clear
+s/\\$//
+t bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/"/p
+d
+:bsnlc
+s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p
+b cont
+' <confdefs.h | sed '
+s/'"$ac_delim"'/"\\\
+"/g' >>$CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  for (key in D) D_is_set[key] = 1
+  FS = ""
+}
+/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ {
+  line = \$ 0
+  split(line, arg, " ")
+  if (arg[1] == "#") {
+    defundef = arg[2]
+    mac1 = arg[3]
+  } else {
+    defundef = substr(arg[1], 2)
+    mac1 = arg[2]
+  }
+  split(mac1, mac2, "(") #)
+  macro = mac2[1]
+  prefix = substr(line, 1, index(line, defundef) - 1)
+  if (D_is_set[macro]) {
+    # Preserve the white space surrounding the "#".
+    print prefix "define", macro P[macro] D[macro]
+    next
+  } else {
+    # Replace #undef with comments.  This is necessary, for example,
+    # in the case of _POSIX_SOURCE, which is predefined and required
+    # on some systems where configure will not decide to define it.
+    if (defundef == "undef") {
+      print "/*", prefix defundef, macro, "*/"
+      next
+    }
+  }
+}
+{ print }
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+  as_fn_error "could not setup config headers machinery" "$LINENO" 5
+fi # test -n "$CONFIG_HEADERS"
+
+
+eval set X "  :F $CONFIG_FILES  :H $CONFIG_HEADERS    "
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   as_fn_error "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || as_fn_error "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
   ac_builddir=.
 
@@ -13370,7 +7782,7 @@
 .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
 *)
-  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
   # A ".." for each directory in $ac_dir_suffix.
-  ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'`
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
   case $ac_top_builddir_sub in
   "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
@@ -13408,10 +7820,10 @@
 _ACEOF
 
-cat >>$CONFIG_STATUS <<\_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # If the template does not know about datarootdir, expand it.
 # FIXME: This hack should be removed a few years after 2.60.
 ac_datarootdir_hack=; ac_datarootdir_seen=
-
-case `sed -n '/datarootdir/ {
+ac_sed_dataroot='
+/datarootdir/ {
   p
   q
@@ -13421,12 +7833,12 @@
 /@infodir@/p
 /@localedir@/p
-/@mandir@/p
-' $ac_file_inputs` in
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
 *datarootdir*) ac_datarootdir_seen=yes;;
 *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
-  { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
-echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
-_ACEOF
-cat >>$CONFIG_STATUS <<_ACEOF
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
   ac_datarootdir_hack='
   s&@datadir@&$datadir&g
@@ -13435,5 +7847,5 @@
   s&@localedir@&$localedir&g
   s&@mandir@&$mandir&g
-    s&\\\${datarootdir}&$datarootdir&g' ;;
+  s&\\\${datarootdir}&$datarootdir&g' ;;
 esac
 _ACEOF
@@ -13442,13 +7854,14 @@
 # Shell code in configure.ac might set extrasub.
 # FIXME: do we really want to maintain this feature?
-cat >>$CONFIG_STATUS <<_ACEOF
-  sed "$ac_vpsub
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
 $extrasub
 _ACEOF
-cat >>$CONFIG_STATUS <<\_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 :t
 /@[a-zA-Z_][a-zA-Z_0-9]*@/!b
-s&@configure_input@&$configure_input&;t t
+s|@configure_input@|$ac_sed_conf_input|;t t
 s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
 s&@srcdir@&$ac_srcdir&;t t
 s&@abs_srcdir@&$ac_abs_srcdir&;t t
@@ -13459,19 +7872,22 @@
 s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 $ac_datarootdir_hack
-" $ac_file_inputs | sed -f "$tmp/subs-1.sed" | sed -f "$tmp/subs-2.sed" >$tmp/out
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
   { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
   { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
-  { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined." >&5
-echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined." >&2;}
 
   rm -f "$tmp/stdin"
   case $ac_file in
-  -) cat "$tmp/out"; rm -f "$tmp/out";;
-  *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;;
-  esac
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error "could not create $ac_file" "$LINENO" 5
  ;;
   :H)
@@ -13479,97 +7895,23 @@
   # CONFIG_HEADER
   #
-_ACEOF
-
-# Transform confdefs.h into a sed script `conftest.defines', that
-# substitutes the proper values into config.h.in to produce config.h.
-rm -f conftest.defines conftest.tail
-# First, append a space to every undef/define line, to ease matching.
-echo 's/$/ /' >conftest.defines
-# Then, protect against being on the right side of a sed subst, or in
-# an unquoted here document, in config.status.  If some macros were
-# called several times there might be several #defines for the same
-# symbol, which is useless.  But do not sort them, since the last
-# AC_DEFINE must be honored.
-ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]*
-# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where
-# NAME is the cpp macro being defined, VALUE is the value it is being given.
-# PARAMS is the parameter list in the macro definition--in most cases, it's
-# just an empty string.
-ac_dA='s,^\\([	 #]*\\)[^	 ]*\\([	 ]*'
-ac_dB='\\)[	 (].*,\\1define\\2'
-ac_dC=' '
-ac_dD=' ,'
-
-uniq confdefs.h |
-  sed -n '
-	t rset
-	:rset
-	s/^[	 ]*#[	 ]*define[	 ][	 ]*//
-	t ok
-	d
-	:ok
-	s/[\\&,]/\\&/g
-	s/^\('"$ac_word_re"'\)\(([^()]*)\)[	 ]*\(.*\)/ '"$ac_dA"'\1'"$ac_dB"'\2'"${ac_dC}"'\3'"$ac_dD"'/p
-	s/^\('"$ac_word_re"'\)[	 ]*\(.*\)/'"$ac_dA"'\1'"$ac_dB$ac_dC"'\2'"$ac_dD"'/p
-  ' >>conftest.defines
-
-# Remove the space that was appended to ease matching.
-# Then replace #undef with comments.  This is necessary, for
-# example, in the case of _POSIX_SOURCE, which is predefined and required
-# on some systems where configure will not decide to define it.
-# (The regexp can be short, since the line contains either #define or #undef.)
-echo 's/ $//
-s,^[	 #]*u.*,/* & */,' >>conftest.defines
-
-# Break up conftest.defines:
-ac_max_sed_lines=50
-
-# First sed command is:	 sed -f defines.sed $ac_file_inputs >"$tmp/out1"
-# Second one is:	 sed -f defines.sed "$tmp/out1" >"$tmp/out2"
-# Third one will be:	 sed -f defines.sed "$tmp/out2" >"$tmp/out1"
-# et cetera.
-ac_in='$ac_file_inputs'
-ac_out='"$tmp/out1"'
-ac_nxt='"$tmp/out2"'
-
-while :
-do
-  # Write a here document:
-    cat >>$CONFIG_STATUS <<_ACEOF
-    # First, check the format of the line:
-    cat >"\$tmp/defines.sed" <<\\CEOF
-/^[	 ]*#[	 ]*undef[	 ][	 ]*$ac_word_re[	 ]*\$/b def
-/^[	 ]*#[	 ]*define[	 ][	 ]*$ac_word_re[(	 ]/b def
-b
-:def
-_ACEOF
-  sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS
-  echo 'CEOF
-    sed -f "$tmp/defines.sed"' "$ac_in >$ac_out" >>$CONFIG_STATUS
-  ac_in=$ac_out; ac_out=$ac_nxt; ac_nxt=$ac_in
-  sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail
-  grep . conftest.tail >/dev/null || break
-  rm -f conftest.defines
-  mv conftest.tail conftest.defines
-done
-rm -f conftest.defines conftest.tail
-
-echo "ac_result=$ac_in" >>$CONFIG_STATUS
-cat >>$CONFIG_STATUS <<\_ACEOF
   if test x"$ac_file" != x-; then
-    echo "/* $configure_input  */" >"$tmp/config.h"
-    cat "$ac_result" >>"$tmp/config.h"
-    if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then
-      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
-echo "$as_me: $ac_file is unchanged" >&6;}
+    {
+      $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
+      || as_fn_error "could not create $ac_file" "$LINENO" 5
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+$as_echo "$as_me: $ac_file is unchanged" >&6;}
     else
-      rm -f $ac_file
-      mv "$tmp/config.h" $ac_file
+      rm -f "$ac_file"
+      mv "$tmp/config.h" "$ac_file" \
+	|| as_fn_error "could not create $ac_file" "$LINENO" 5
     fi
   else
-    echo "/* $configure_input  */"
-    cat "$ac_result"
+    $as_echo "/* $configure_input  */" \
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      || as_fn_error "could not create -" "$LINENO" 5
   fi
-  rm -f "$tmp/out12"
  ;;
 
@@ -13580,8 +7922,10 @@
 
 
-{ (exit 0); exit 0; }
-_ACEOF
-chmod +x $CONFIG_STATUS
+as_fn_exit 0
+_ACEOF
 ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error "write failure creating $CONFIG_STATUS" "$LINENO" 5
 
 
@@ -13604,10 +7948,14 @@
   # Use ||, not &&, to avoid exiting from the if with $? = 1, which
   # would make configure fail if this is the last instruction.
-  $ac_cs_success || { (exit 1); exit 1; }
-fi
-
-
-
-{ echo "$as_me:$LINENO: result:
+  $ac_cs_success || as_fn_exit $?
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result:
 
 Configurations for current target have been written to 'build.mak', and 'os-auto.mak' in various build directories, and pjlib/include/pj/compat/os_auto.h.
@@ -13619,5 +7967,5 @@
 The next step now is to run 'make dep' and 'make'.
 " >&5
-echo "${ECHO_T}
+$as_echo "
 
 Configurations for current target have been written to 'build.mak', and 'os-auto.mak' in various build directories, and pjlib/include/pj/compat/os_auto.h.
Index: pjproject/branches/projects/2.0-dev/aconfigure.ac
===================================================================
--- pjproject/branches/projects/2.0-dev/aconfigure.ac	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/aconfigure.ac	(revision 3392)
@@ -571,6 +571,5 @@
 	AC_ARG_ENABLE(oss,
 		      AC_HELP_STRING([--disable-oss],
-				     [Disable OSS audio (default: not disabled)])
-		      ,
+				     [Disable OSS audio (default: not disabled)]),
 		      [
 			if test "$enable_oss" = "no"; then
@@ -719,4 +718,97 @@
 	     )
 
+dnl # SDL
+AC_ARG_ENABLE(sdl,
+	      AC_HELP_STRING([--disable-sdl],
+			     [Disable SDL (default: not disabled)]),
+	      [
+		if test "$enable_sdl" = "no"; then
+		  AC_MSG_RESULT([Checking if SDL is disabled... yes])
+		fi
+	      ],
+	      [
+		  AC_MSG_CHECKING([SDL availability..])
+		  if sdl-config --version; then
+				  AC_SUBST(ac_sdl_cflags)
+			  AC_SUBST(ac_sdl_ldflags)
+			  ac_sdl_cflags=`sdl-config --cflags`
+			  ac_sdl_cflags="-DPJMEDIA_VIDEO_DEV_HAS_SDL=1 $ac_sdl_cflags"
+			  ac_sdl_ldflags=`sdl-config --libs`
+		   fi
+	      ])
+
+
+dnl # FFMPEG stuffs
+AC_ARG_ENABLE(ffmpeg,
+	      AC_HELP_STRING([--disable-ffmpeg],
+			     [Disable ffmpeg (default: not disabled)]),
+	      [
+	        AC_SUBST(ac_has_ffmpeg,0)
+		if test "$enable_ffmpeg" = "no"; then
+			AC_MSG_RESULT([Checking if ffmpeg is disabled... yes])
+		fi
+	      ],
+	      [
+		AC_SUBST(ac_ffmpeg_cflags)
+		AC_SUBST(ac_ffmpeg_ldflags)
+
+		AC_CHECK_LIB(avdevice,
+			     avdevice_version,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVDEVICE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavdevice"
+			     ]
+			     )
+		AC_CHECK_LIB(avformat,
+			     av_register_all,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVFORMAT=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavformat"
+			     ]
+			     )
+		AC_CHECK_LIB(avcodec,
+			     avcodec_init,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCODEC=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcodec"
+			     ]
+			     )
+		AC_CHECK_LIB(swscale,
+			     sws_scale,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBSWSCALE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lswscale"
+			     ]
+			     )
+		AC_CHECK_LIB(avutil,
+			     av_malloc,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVUTIL=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavutil"
+			     ]
+			     )
+		AC_CHECK_LIB(avcore,
+			     avcore_version,
+			     [ac_ffmpeg_cflags="$ac_ffmpeg_cflags -DPJMEDIA_HAS_LIBAVCORE=1"
+			      ac_ffmpeg_ldflags="$ac_ffmpeg_ldflags -lavcore"
+			     ]
+			     )
+	      ]
+	      )
+
+dnl # Video for Linux 2
+AC_ARG_ENABLE(v4l2,
+	      AC_HELP_STRING([--disable-v4l2],
+			     [Disable Video4Linux2 (default: not disabled)]),
+	      [
+		if test "$enable_v4l2" = "no"; then
+		  AC_MSG_RESULT([Checking if V4L2 is disabled... yes])
+		fi
+	      ],
+	      [
+	        AC_SUBST(ac_v4l2_cflags)
+	        AC_SUBST(ac_v4l2_ldflags)
+		AC_CHECK_LIB(v4l2,
+			     v4l2_open,
+			     [ac_v4l2_cflags="-DPJMEDIA_VIDEO_DEV_HAS_V4L2=1"
+			      ac_v4l2_ldflags="-lv4l2"
+			     ]
+			     )
+	      ])
 
 dnl ########################################################
Index: pjproject/branches/projects/2.0-dev/pjlib/src/pj/config.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjlib/src/pj/config.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjlib/src/pj/config.c	(revision 3392)
@@ -23,5 +23,5 @@
 
 static const char *id = "config.c";
-PJ_DEF_DATA(const char*) PJ_VERSION = "1.8.10-trunk";
+PJ_DEF_DATA(const char*) PJ_VERSION = "2.0-dev";
 
 /*
Index: pjproject/branches/projects/2.0-dev/pjmedia/build/Makefile
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/build/Makefile	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/build/Makefile	(revision 3392)
@@ -19,4 +19,5 @@
 export PJSDP_LIB:=../lib/libpjsdp-$(TARGET_NAME)$(LIBEXT)
 export PJMEDIA_AUDIODEV_LIB:=../lib/libpjmedia-audiodev-$(TARGET_NAME)$(LIBEXT)
+export PJMEDIA_VIDEODEV_LIB:=../lib/libpjmedia-videodev-$(TARGET_NAME)$(LIBEXT)
 
 
@@ -35,4 +36,5 @@
 export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJMEDIA_LIB)) \
 		   $(subst /,$(HOST_PSEP),$(PJMEDIA_AUDIODEV_LIB)) \
+		   $(subst /,$(HOST_PSEP),$(PJMEDIA_VIDEODEV_LIB)) \
 		   $(subst /,$(HOST_PSEP),$(PJMEDIA_CODEC_LIB)) \
 		   $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \
@@ -50,7 +52,10 @@
 export PJMEDIA_SRCDIR = ../src/pjmedia
 export PJMEDIA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
-			alaw_ulaw.o alaw_ulaw_table.o bidirectional.o clock_thread.o codec.o \
-			conference.o conf_switch.o delaybuf.o echo_common.o \
+			alaw_ulaw.o alaw_ulaw_table.o avi_player.o \
+			bidirectional.o clock_thread.o codec.o conference.o \
+			conf_switch.o converter.o  converter_libswscale.o \
+			delaybuf.o echo_common.o \
 			echo_port.o echo_suppress.o endpoint.o errno.o \
+			format.o ffmpeg_util.o \
 			g711.o jbuf.o master_port.o mem_capture.o mem_player.o \
 			null_port.o plc_common.o port.o splitcomb.o \
@@ -61,5 +66,5 @@
 			stream.o tonegen.o transport_adapter_sample.o \
 			transport_ice.o transport_loop.o \
-			transport_srtp.o transport_udp.o \
+			transport_srtp.o transport_udp.o vid_codec.o videoport.o \
 			wav_player.o wav_playlist.o wav_writer.o wave.o \
 			wsola.o
@@ -79,4 +84,13 @@
 
 ###############################################################################
+# Defines for building PJMEDIA-VIDEODEV library
+#
+export PJMEDIA_VIDEODEV_SRCDIR = ../src/pjmedia-videodev
+export PJMEDIA_VIDEODEV_OBJS +=  videodev.o ffmpeg_dev.o sdl_dev.o colorbar_dev.o \
+				 v4l2_dev.o
+export PJMEDIA_VIDEODEV_CFLAGS += $(_CFLAGS)
+
+
+###############################################################################
 # Defines for building PJSDP library
 # Note that SDP functionality is already INCLUDED in PJMEDIA.
@@ -94,5 +108,5 @@
 #
 export PJMEDIA_CODEC_SRCDIR = ../src/pjmedia-codec
-export PJMEDIA_CODEC_OBJS += \
+export PJMEDIA_CODEC_OBJS += ffmpeg_codecs.o \
 			$(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
 			ipp_codecs.o $(CODEC_OBJS)
@@ -105,5 +119,6 @@
 #
 export PJMEDIA_TEST_SRCDIR = ../src/test
-export PJMEDIA_TEST_OBJS += codec_vectors.o jbuf_test.o main.o mips_test.o rtp_test.o test.o
+export PJMEDIA_TEST_OBJS += codec_vectors.o jbuf_test.o main.o mips_test.o \
+			    vid_dev_test.o vid_codec_test.o rtp_test.o test.o
 export PJMEDIA_TEST_OBJS += sdp_neg_test.o 
 export PJMEDIA_TEST_CFLAGS += $(_CFLAGS)
@@ -118,5 +133,5 @@
 # $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
 #
-TARGETS := pjmedia pjmedia-audiodev pjmedia-codec pjsdp pjmedia-test
+TARGETS := pjmedia pjmedia-videodev pjmedia-audiodev pjmedia-codec pjsdp pjmedia-test
 
 all: $(TARGETS)
@@ -133,5 +148,5 @@
 distclean: realclean
 
-.PHONY: dep depend pjmedia pjmedia-codec pjmedia-audiodev pjmedia-test clean realclean distclean
+.PHONY: dep depend pjmedia pjmedia-codec pjmedia-videodev pjmedia-audiodev pjmedia-test clean realclean distclean
 
 pjmedia:
@@ -140,4 +155,7 @@
 pjmedia-codec:
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $(PJMEDIA_CODEC_LIB)
+
+pjmedia-videodev:
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $(PJMEDIA_VIDEODEV_LIB)
 
 pjmedia-audiodev:
@@ -167,4 +185,5 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $@
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_AUDIODEV app=pjmedia-audiodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJSDP app=pjsdp $@
@@ -173,4 +192,5 @@
 realclean:
 	$(subst @@,$(subst /,$(HOST_PSEP),.pjmedia-$(TARGET_NAME).depend),$(HOST_RMR))
+	$(subst @@,$(subst /,$(HOST_PSEP),.pjmedia-videodev-$(TARGET_NAME).depend),$(HOST_RMR))
 	$(subst @@,$(subst /,$(HOST_PSEP),.pjmedia-audiodev-$(TARGET_NAME).depend),$(HOST_RMR))
 	$(subst @@,$(subst /,$(HOST_PSEP),.pjmedia-codec-$(TARGET_NAME).depend),$(HOST_RMR))
@@ -179,4 +199,5 @@
 	
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $@
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_AUDIODEV app=pjmedia-audiodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $@
@@ -186,4 +207,5 @@
 depend:
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA app=pjmedia $@
+	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_VIDEODEV app=pjmedia-videodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_AUDIODEV app=pjmedia-audiodev $@
 	$(MAKE) -f $(RULES_MAK) APP=PJMEDIA_CODEC app=pjmedia-codec $@
Index: pjproject/branches/projects/2.0-dev/pjmedia/build/os-auto.mak.in
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/build/os-auto.mak.in	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/build/os-auto.mak.in	(revision 3392)
@@ -1,6 +1,20 @@
 # @configure_input@
 
+# SDL flags
+SDL_CFLAGS = @ac_sdl_cflags@
+SDL_LDFLAGS = @ac_sdl_ldflags@
+
+# FFMPEG dlags
+FFMPEG_CFLAGS = @ac_ffmpeg_cflags@ 
+FFMPEG_LDFLAGS =  @ac_ffmpeg_ldflags@
+
+# Video4Linux2
+V4L2_CFLAGS = @ac_v4l2_cflags@
+V4L2_LDFLAGS = @ac_v4l2_ldflags@
+
 # PJMEDIA features exclusion
-export CFLAGS += @ac_no_small_filter@ @ac_no_large_filter@ @ac_no_speex_aec@
+export CFLAGS += @ac_no_small_filter@ @ac_no_large_filter@ @ac_no_speex_aec@ \
+		 $(SDL_CFLAGS) $(FFMPEG_CFLAGS) $(V4L2_CFLAGS)
+export LDFLAGS += $(SDL_LDFLAGS) $(FFMPEG_LDFLAGS) $(V4L2_LDFLAGS)
 
 # Define the desired sound device backend
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/audiodev.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/audiodev.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/audiodev.h	(revision 3392)
@@ -27,4 +27,6 @@
 #include <pjmedia-audiodev/config.h>
 #include <pjmedia-audiodev/errno.h>
+#include <pjmedia/format.h>
+#include <pjmedia/frame.h>
 #include <pjmedia/types.h>
 #include <pj/pool.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/config.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/config.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-audiodev/config.h	(revision 3392)
@@ -22,6 +22,6 @@
 
 /**
- * @file audiodev.h
- * @brief Audio device API.
+ * @file config.h
+ * @brief Audio config.
  */
 #include <pjmedia/types.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec.h	(revision 3392)
@@ -27,4 +27,5 @@
 
 #include <pjmedia-codec/l16.h>
+#include <pjmedia-codec/ffmpeg_codecs.h>
 #include <pjmedia-codec/gsm.h>
 #include <pjmedia-codec/speex.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/config.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/config.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/config.h	(revision 3392)
@@ -35,5 +35,4 @@
 #include <pjmedia/types.h>
 
-
 /*
  * Include config_auto.h if autoconf is used (PJ_AUTOCONF is set)
@@ -42,4 +41,5 @@
 #   include <pjmedia-codec/config_auto.h>
 #endif
+
 
 /**
@@ -344,7 +344,19 @@
 #endif
 
+
+/**
+ * Specify if FFMPEG codecs are available.
+ *
+ * Default: PJMEDIA_HAS_LIBAVCODEC
+ */
+#ifndef PJMEDIA_HAS_FFMPEG_CODEC
+#   define PJMEDIA_HAS_FFMPEG_CODEC		PJMEDIA_HAS_LIBAVCODEC
+#endif
+
 /**
  * @}
  */
 
+
+
 #endif	/* __PJMEDIA_CODEC_CONFIG_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/ffmpeg_codecs.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/ffmpeg_codecs.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/ffmpeg_codecs.h	(revision 3392)
@@ -0,0 +1,62 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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_CODECS_FFMPEG_H__
+#define __PJMEDIA_CODECS_FFMPEG_H__
+
+
+#include <pjmedia-codec/types.h>
+#include <pjmedia/vid_codec.h>
+
+PJ_BEGIN_DECL
+
+
+/**
+ * Initialize and register FFMPEG codecs factory to pjmedia endpoint.
+ *
+ * @param mgr	    The video codec manager instance where this codec will
+ * 		    be registered to. Specify NULL to use default instance
+ * 		    (in that case, an instance of video codec manager must
+ * 		    have been created beforehand).
+ * @param pf	    Pool factory.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_codec_ffmpeg_init(pjmedia_vid_codec_mgr *mgr,
+                                               pj_pool_factory *pf);
+
+
+/**
+ * Unregister FFMPEG codecs factory from the video codec manager and
+ * deinitialize the codecs library.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_codec_ffmpeg_deinit(void);
+
+
+PJ_END_DECL
+
+
+/**
+ * @}
+ */
+
+#endif	/* __PJMEDIA_CODECS_FFMPEG_H__ */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/h263_packetizer.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/h263_packetizer.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-codec/h263_packetizer.h	(revision 3392)
@@ -0,0 +1,140 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_H263_PACKETIZER_H__
+#define __PJMEDIA_H263_PACKETIZER_H__
+
+
+/**
+ * @file h263_packetizer.h
+ * @brief Packetizes H.263 bitstream into RTP payload.
+ */
+
+#include <pj/errno.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * Find synchronization point (PSC, slice, GSBC, EOS, EOSBS) in H.263 
+ * bitstream, in reversed manner.
+ */
+PJ_INLINE(pj_uint8_t*) pjmedia_h263_find_sync_point_rev(pj_uint8_t *data,
+                                                        pj_size_t data_len)
+{
+    pj_uint8_t *p = data+data_len-1;
+
+    while (p > data && *p && *(p+1))
+        --p;
+
+    if (p == data)
+        return (data + data_len);
+        
+    return p;
+}
+
+/**
+ * Generate an RTP payload from H.263 frame bitstream, in-place processing.
+ */
+PJ_INLINE(pj_status_t) pjmedia_h263_packetize(pj_uint8_t *buf,
+                                              pj_size_t buf_len,
+                                              unsigned *pos,
+                                              int max_payload_len,
+                                              const pj_uint8_t **payload,
+                                              pj_size_t *payload_len)
+{
+    pj_uint8_t *p, *p_end;
+
+    p = buf + *pos;
+    p_end = buf + buf_len;
+
+    /* Put two octets payload header */
+    if ((p_end-p > 2) && *p==0 && *(p+1)==0) {
+        /* The bitstream starts with synchronization point, just override
+         * the two zero octets (sync point mark) for payload header.
+         */
+        *p = 0x04;
+    } else {
+        /* Not started in synchronization point, we will use two octets
+         * preceeding the bitstream for payload header!
+         */
+        pj_assert(*pos>=2);
+        p -= 2;
+        *p = 0;
+    }
+    *(p+1) = 0;
+
+    /* When bitstream truncation needed because of payload length/MTU 
+     * limitation, try to use sync point for the payload boundary.
+     */
+    if (p_end-p > max_payload_len) {
+        p_end = pjmedia_h263_find_sync_point_rev(p+2, max_payload_len-2);
+    }
+
+    *payload = p;
+    *payload_len = p_end-p;
+    *pos = p_end - buf;
+
+    return PJ_SUCCESS;
+}
+
+/**
+ * Append RTP payload to a H.263 picture bitstream.
+ */
+PJ_INLINE(pj_status_t) pjmedia_h263_unpacketize(const pj_uint8_t *payload,
+                                                pj_size_t   payload_len,
+                                                pj_uint8_t *bits,
+                                                pj_size_t  *bits_len)
+{
+    pj_uint8_t P, V, PLEN;
+    const pj_uint8_t *p=payload;
+    pj_size_t max_len = *bits_len;
+
+    P = *p & 0x04;
+    V = *p & 0x02;
+    PLEN = ((*p & 0x01) << 5) + ((*(p+1) & 0xF8)>>3);
+
+    /* Get bitstream pointer */
+    p += 2;
+    if (V)
+        p += 1; /* Skip VRC data */
+    if (PLEN)
+        p += PLEN; /* Skip extra picture header data */
+
+    /* Get bitstream length */
+    payload_len -= (p-payload);
+
+    *bits_len = payload_len + (P?2:0);
+    PJ_ASSERT_RETURN(max_len >= *bits_len, PJ_ETOOSMALL);
+
+    /* Add two zero octets when payload flagged with sync point */
+    if (P) {
+        *bits++ = 0;
+        *bits++ = 0;
+    }
+
+    /* Add the bitstream */
+    pj_memcpy(bits, p, payload_len);
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_END_DECL
+
+
+#endif	/* __PJMEDIA_H263_PACKETIZER_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/config.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/config.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/config.h	(revision 3392)
@@ -0,0 +1,160 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_VIDEODEV_CONFIG_H__
+#define __PJMEDIA_VIDEODEV_CONFIG_H__
+
+/**
+ * @file config.h
+ * @brief Video config.
+ */
+#include <pjmedia/types.h>
+#include <pj/pool.h>
+
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup video_device_api Video Device API
+ * @brief PJMEDIA video device abstraction API.
+ */
+
+/**
+ * @defgroup s1_video_device_config Compile time configurations
+ * @ingroup video_device_api
+ * @brief Compile time configurations
+ * @{
+ */
+
+/**
+ * This setting controls whether SDL support should be included.
+ *
+ * Default: 0 (or detected by configure)
+ */
+#ifndef PJMEDIA_VIDEO_DEV_HAS_SDL
+#   define PJMEDIA_VIDEO_DEV_HAS_SDL		0
+#endif
+
+
+/**
+ * This setting controls whether Direct Show support should be included.
+ *
+ * Default: 0 (unfinished)
+ */
+#ifndef PJMEDIA_VIDEO_DEV_HAS_DSHOW
+#   define PJMEDIA_VIDEO_DEV_HAS_DSHOW		0 //PJ_WIN32
+#endif
+
+
+/**
+ * This setting controls whether colorbar source support should be included.
+ *
+ * Default: 1
+ */
+#ifndef PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC
+#   define PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC	1
+#endif
+
+
+/**
+ * This setting controls whether ffmpeg support should be included.
+ *
+ * Default: 0 (unfinished)
+ */
+#ifndef PJMEDIA_VIDEO_DEV_HAS_FFMPEG
+#   define PJMEDIA_VIDEO_DEV_HAS_FFMPEG	        0
+#endif
+
+
+/**
+ * Video4Linux2
+ *
+ * Default: 0 (or detected by configure)
+ */
+#ifndef PJMEDIA_VIDEO_DEV_HAS_V4L2
+#   define PJMEDIA_VIDEO_DEV_HAS_V4L2		0
+#endif
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+
+#endif	/* __PJMEDIA_VIDEODEV_CONFIG_H__ */
+
+/*
+ --------------------- DOCUMENTATION FOLLOWS ---------------------------
+ */
+
+/**
+ * @addtogroup video_device_api Video Device API
+ * @{
+
+PJMEDIA Video Device API is a cross-platform video API appropriate for use with
+VoIP applications and many other types of video streaming applications. 
+
+The API abstracts many different video API's on various platforms, such as:
+ - native Direct Show video for Win32 and Windows Mobile devices
+ - null-video implementation
+ - and more to be implemented in the future
+
+The Video Device API/library is an evolution from PJMEDIA @ref PJMED_SND and 
+contains many enhancements:
+
+ - Forward compatibility:
+\n
+   The new API has been designed to be extensible, it will support new API's as 
+   well as new features that may be introduced in the future without breaking 
+   compatibility with applications that use this API as well as compatibility 
+   with existing device implementations. 
+
+ - Device capabilities:
+\n
+   At the heart of the API is device capabilities management, where all possible
+   video capabilities of video devices should be able to be handled in a generic
+   manner. With this framework, new capabilities that may be discovered in the 
+   future can be handled in manner without breaking existing applications. 
+
+ - Built-in features:
+\n
+   The device capabilities framework enables applications to use and control 
+   video features built-in in the device, such as:
+    - built-in formats, 
+    - etc.
+
+ - Codec support:
+\n
+   Some video devices support built-in hardware video codecs, and application
+   can use the video device in encoded mode to make use of these hardware 
+   codecs. 
+
+ - Multiple backends:
+\n
+   The new API supports multiple video backends (called factories or drivers in 
+   the code) to be active simultaneously, and video backends may be added or 
+   removed during run-time. 
+
+*/
+
+
+/**
+ * @}
+ */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/errno.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/errno.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/errno.h	(revision 3392)
@@ -0,0 +1,159 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_VIDEODEV_VIDEODEV_ERRNO_H__
+#define __PJMEDIA_VIDEODEV_VIDEODEV_ERRNO_H__
+
+/**
+ * @file errno.h Error Codes
+ * @brief Videodev specific error codes.
+ */
+
+#include <pjmedia-videodev/config.h>
+#include <pj/errno.h>
+
+/**
+ * @defgroup error_codes Error Codes
+ * @ingroup video_device_api
+ * @brief Video device library specific error codes.
+ * @{
+ */
+
+
+PJ_BEGIN_DECL
+
+
+/**
+ * Start of error code relative to PJ_ERRNO_START_USER.
+ * This value is 470000.
+ */
+#define PJMEDIA_VIDEODEV_ERRNO_START \
+	    (PJ_ERRNO_START_USER + PJ_ERRNO_SPACE_SIZE*6)
+#define PJMEDIA_VIDEODEV_ERRNO_END   \
+	    (PJMEDIA_VIDEODEV_ERRNO_START + PJ_ERRNO_SPACE_SIZE - 1)
+
+
+/************************************************************
+ * Video Device API error codes
+ ***********************************************************/
+/**
+ * @hideinitializer
+ * General/unknown error.
+ */
+#define PJMEDIA_EVID_ERR	(PJMEDIA_VIDEODEV_ERRNO_START+1) /* 470001 */
+
+/**
+ * @hideinitializer
+ * Unknown error from video driver
+ */
+#define PJMEDIA_EVID_SYSERR	(PJMEDIA_VIDEODEV_ERRNO_START+2) /* 470002 */
+
+/**
+ * @hideinitializer
+ * Video subsystem not initialized
+ */
+#define PJMEDIA_EVID_INIT	(PJMEDIA_VIDEODEV_ERRNO_START+3) /* 470003 */
+
+/**
+ * @hideinitializer
+ * Invalid video device
+ */
+#define PJMEDIA_EVID_INVDEV	(PJMEDIA_VIDEODEV_ERRNO_START+4) /* 470004 */
+
+/**
+ * @hideinitializer
+ * Found no devices
+ */
+#define PJMEDIA_EVID_NODEV	(PJMEDIA_VIDEODEV_ERRNO_START+5) /* 470005 */
+
+/**
+ * @hideinitializer
+ * Unable to find default device
+ */
+#define PJMEDIA_EVID_NODEFDEV	(PJMEDIA_VIDEODEV_ERRNO_START+6) /* 470006 */
+
+/**
+ * @hideinitializer
+ * Device not ready
+ */
+#define PJMEDIA_EVID_NOTREADY	(PJMEDIA_VIDEODEV_ERRNO_START+7) /* 470007 */
+
+/**
+ * @hideinitializer
+ * The video capability is invalid or not supported
+ */
+#define PJMEDIA_EVID_INVCAP	(PJMEDIA_VIDEODEV_ERRNO_START+8) /* 470008 */
+
+/**
+ * @hideinitializer
+ * The operation is invalid or not supported
+ */
+#define PJMEDIA_EVID_INVOP	(PJMEDIA_VIDEODEV_ERRNO_START+9) /* 470009 */
+
+/**
+ * @hideinitializer
+ * Bad or invalid video device format
+ */
+#define PJMEDIA_EVID_BADFORMAT	(PJMEDIA_VIDEODEV_ERRNO_START+10) /* 4700010 */
+
+/**
+ * @hideinitializer
+ * Invalid video device sample format
+ */
+#define PJMEDIA_EVID_SAMPFORMAT	(PJMEDIA_VIDEODEV_ERRNO_START+11) /* 4700011 */
+
+/**
+ * @hideinitializer
+ * Bad latency setting
+ */
+#define PJMEDIA_EVID_BADLATENCY	(PJMEDIA_VIDEODEV_ERRNO_START+12) /* 4700012 */
+
+/**
+ * @hideinitializer
+ * Bad/unsupported video size
+ */
+#define PJMEDIA_EVID_BADSIZE	(PJMEDIA_VIDEODEV_ERRNO_START+13) /* 4700013 */
+
+
+/**
+ * Get error message for the specified error code. Note that this
+ * function is only able to decode PJMEDIA Videodev specific error code.
+ * Application should use pj_strerror(), which should be able to
+ * decode all error codes belonging to all subsystems (e.g. pjlib,
+ * pjmedia, pjsip, etc).
+ *
+ * @param status    The error code.
+ * @param buffer    The buffer where to put the error message.
+ * @param bufsize   Size of the buffer.
+ *
+ * @return	    The error message as NULL terminated string,
+ *                  wrapped with pj_str_t.
+ */
+PJ_DECL(pj_str_t) pjmedia_videodev_strerror(pj_status_t status, char *buffer,
+					    pj_size_t bufsize);
+
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+
+#endif	/* __PJMEDIA_VIDEODEV_VIDEODEV_ERRNO_H__ */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev.h	(revision 3392)
@@ -0,0 +1,574 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_VIDEODEV_VIDEODEV_H__
+#define __PJMEDIA_VIDEODEV_VIDEODEV_H__
+
+/**
+ * @file videodev.h
+ * @brief Video device API.
+ */
+#include <pjmedia-videodev/config.h>
+#include <pjmedia-videodev/errno.h>
+#include <pjmedia/frame.h>
+#include <pjmedia/format.h>
+#include <pj/pool.h>
+
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup video_device_reference Video Device API Reference
+ * @ingroup video_device_api
+ * @brief API Reference
+ * @{
+ */
+ 
+/**
+ * Type for device index.
+ */
+typedef pj_int32_t pjmedia_vid_dev_index;
+
+/**
+ * Device index constants.
+ */
+enum
+{
+    /**
+     * Constant to denote default capture device
+     */
+    PJMEDIA_VID_DEFAULT_CAPTURE_DEV = -1,
+
+    /**
+     * Constant to denote default render device
+     */
+    PJMEDIA_VID_DEFAULT_RENDER_DEV = -2,
+
+    /**
+     * Constant to denote invalid device index.
+     */
+    PJMEDIA_VID_INVALID_DEV = -3
+};
+
+
+/**
+ * This enumeration identifies various video device capabilities. These video
+ * capabilities indicates what features are supported by the underlying
+ * video device implementation.
+ *
+ * Applications get these capabilities in the #pjmedia_vid_dev_info structure.
+ *
+ * Application can also set the specific features/capabilities when opening
+ * the video stream by setting the \a flags member of #pjmedia_vid_param
+ * structure.
+ *
+ * Once video stream is running, application can also retrieve or set some
+ * specific video capability, by using #pjmedia_vid_stream_get_cap() and
+ * #pjmedia_vid_stream_set_cap() and specifying the desired capability. The
+ * value of the capability is specified as pointer, and application needs to
+ * supply the pointer with the correct value, according to the documentation
+ * of each of the capability.
+ */
+typedef enum pjmedia_vid_dev_cap
+{
+    /**
+     * Support for video formats. The value of this capability
+     * is represented by #pjmedia_format structure.
+     */
+    PJMEDIA_VID_DEV_CAP_FORMAT = 1,
+
+    /**
+     * Support for video input scaling
+     */
+    PJMEDIA_VID_DEV_CAP_INPUT_SCALE = 2,
+
+    /**
+     * The application can provide a window for the renderer to
+     * display the video.
+     */
+    PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW = 4,
+
+    /**
+     * Support for resizing video output. This capability SHOULD be 
+     * implemented by renderer, to alter the video output dimension on the fly.
+     * Value is pjmedia_rect_size. 
+     */
+    PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE = 8,
+
+    /**
+     * End of capability
+     */
+    PJMEDIA_VID_DEV_CAP_MAX = 16384
+
+} pjmedia_vid_dev_cap;
+
+/**
+ * Device information structure returned by #pjmedia_vid_dev_get_info().
+ */
+typedef struct pjmedia_vid_dev_info
+{
+    /** The device name */
+    char name[64];
+
+    /** The underlying driver name */
+    char driver[32];
+
+    /** 
+     * The supported direction of the video device, i.e. whether it supports 
+     * capture only, render only, or both.
+     */
+    pjmedia_dir dir;
+
+    /** Specify whether the device supports callback */
+    pj_bool_t has_callback;
+
+    /** Device capabilities, as bitmask combination of #pjmedia_vid_dev_cap */
+    unsigned caps;
+
+    /** Number of video formats supported by this device */
+    unsigned fmt_cnt;
+
+    /** 
+     * Array of supported video formats. Some fields in each supported video
+     * format may be set to zero or of "unknown" value, to indicate that the
+     * value is unknown or should be ignored. When these value are not set
+     * to zero, it indicates that the exact format combination is being used. 
+     */
+    pjmedia_format *fmt;
+
+} pjmedia_vid_dev_info;
+
+
+/** Forward declaration for pjmedia_vid_stream */
+typedef struct pjmedia_vid_stream pjmedia_vid_stream;
+
+typedef enum pjmedia_event_type
+{
+    PJMEDIA_EVENT_NONE,
+    PJMEDIA_EVENT_MOUSEBUTTONDOWN,
+    PJMEDIA_EVENT_WINDOW_RESIZE,
+    PJMEDIA_EVENT_WINDOW_FULLSCREEN,
+    PJMEDIA_EVENT_WINDOW_CLOSE,
+} pjmedia_event_type;
+
+typedef struct pjmedia_vid_event
+{
+    pjmedia_event_type  event_type;
+    long	        lparam;
+    void	       *pparam;
+} pjmedia_vid_event;
+
+
+typedef struct pjmedia_vid_cb
+{
+    /**
+    * This callback is called by capturer stream when it has captured the
+    * whole packet worth of video samples.
+    *
+    * @param stream	   The video stream.
+    * @param user_data     User data associated with the stream.
+    * @param frame         Captured frame.
+    *
+    * @return              Returning non-PJ_SUCCESS will cause the video
+    *                      stream to stop
+    */
+    pj_status_t (*capture_cb)(pjmedia_vid_stream *stream,
+		              void *user_data,
+                              pjmedia_frame *frame);
+
+    /**
+    * This callback is called by renderer stream when it needs additional
+    * data to be rendered by the device. Application must fill in the whole
+    * of output buffer with video samples.
+    *
+    * The frame argument contains the following values:
+    *  - timestamp         Rendering timestamp, in samples.
+    *  - buf               Buffer to be filled out by application.
+    *  - size              The size requested in bytes, which will be equal
+    *                      to the size of one whole packet.
+    *
+    * @param stream	   The video stream.
+    * @param user_data     User data associated with the stream.
+    * @param frame         Video frame, which buffer is to be filled in by
+    *                      the application.
+    *
+    * @return              Returning non-PJ_SUCCESS will cause the video 
+    *                      stream to stop
+    */
+    pj_status_t (*render_cb)(pjmedia_vid_stream *stream,
+			     void *user_data,
+                             pjmedia_frame *frame);
+
+    /**
+    * This callback is called by the stream to report the occurence of an
+    * event to the application.
+    *
+    * @param stream	   The video stream.
+    * @param user_data     User data associated with the stream.
+    * @param event	   The event.
+    *
+    * @return              Return PJ_SUCCESS will invoke the video stream's
+    *                      default event-handler (if any), otherwise the
+    *                      video stream will ignore the particular event.
+    */
+    pj_status_t (*on_event_cb)(pjmedia_vid_stream *stream,
+			       void *user_data,
+                               pjmedia_vid_event *event);
+
+} pjmedia_vid_cb;
+
+
+/**
+ * This structure specifies the parameters to open the video stream.
+ */
+typedef struct pjmedia_vid_param
+{
+    /**
+     * The video direction. This setting is mandatory.
+     */
+    pjmedia_dir dir;
+
+    /**
+     * The video capture device ID. This setting is mandatory if the video
+     * direction includes input/capture direction.
+     */
+    pjmedia_vid_dev_index cap_id;
+
+    /**
+     * The video render device ID. This setting is mandatory if the video
+     * direction includes output/render direction.
+     */
+    pjmedia_vid_dev_index rend_id;
+
+    /** 
+     * Video clock rate. This setting is mandatory if the video
+     * direction includes input/capture direction
+     */
+    unsigned clock_rate;
+
+    /**
+     * Video frame rate. This setting is mandatory if the video
+     * direction includes input/capture direction
+     */
+    pjmedia_ratio frame_rate;
+
+    /**
+     * This flags specifies which of the optional settings are valid in this
+     * structure. The flags is bitmask combination of pjmedia_vid_dev_cap.
+     */
+    unsigned flags;
+
+    /**
+     * Set the video format. This setting is mandatory.
+     */
+    pjmedia_format fmt;
+
+    /**
+     * Window for the renderer to display the video. This setting is optional,
+     * and will only be used if PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW is set in 
+     * the flags.
+     */
+    void *window;
+
+    /**
+     * Video display size. This setting is optional, and will only be used 
+     * if PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE is set in the flags.
+     */
+    pjmedia_rect_size disp_size;
+
+} pjmedia_vid_param;
+
+
+/** Forward declaration for video device factory */
+typedef struct pjmedia_vid_dev_factory pjmedia_vid_dev_factory;
+
+/* typedef for factory creation function */
+typedef pjmedia_vid_dev_factory*
+(*pjmedia_vid_dev_factory_create_func_ptr)(pj_pool_factory*);
+
+
+/**
+ * Get string info for the specified capability.
+ *
+ * @param cap       The capability ID.
+ * @param p_desc    Optional pointer which will be filled with longer
+ *                  description about the capability.
+ *
+ * @return          Capability name.
+ */
+PJ_DECL(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
+                                              const char **p_desc);
+
+
+/**
+ * Set a capability field value in #pjmedia_vid_param structure. This will
+ * also set the flags field for the specified capability in the structure.
+ *
+ * @param param     The structure.
+ * @param cap       The video capability which value is to be set.
+ * @param pval      Pointer to value. Please see the type of value to
+ *                  be supplied in the pjmedia_vid_dev_cap documentation.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_param_set_cap(pjmedia_vid_param *param,
+                                               pjmedia_vid_dev_cap cap,
+                                               const void *pval);
+
+
+/**
+ * Get a capability field value from #pjmedia_vid_param structure. This
+ * function will return PJMEDIA_EVID_INVCAP error if the flag for that
+ * capability is not set in the flags field in the structure.
+ *
+ * @param param     The structure.
+ * @param cap       The video capability which value is to be retrieved.
+ * @param pval      Pointer to value. Please see the type of value to
+ *                  be supplied in the pjmedia_vid_dev_cap documentation.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_param_get_cap(const pjmedia_vid_param *param,
+                                               pjmedia_vid_dev_cap cap,
+                                               void *pval);
+
+/**
+ * Initialize the video subsystem. This will register all supported video
+ * device factories to the video subsystem. This function may be called
+ * more than once, but each call to this function must have the
+ * corresponding #pjmedia_vid_subsys_shutdown() call.
+ *
+ * @param pf        The pool factory.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_subsys_init(pj_pool_factory *pf);
+
+
+/**
+ * Get the pool factory registered to the video subsystem.
+ *
+ * @return          The pool factory.
+ */
+PJ_DECL(pj_pool_factory*) pjmedia_vid_subsys_get_pool_factory(void);
+
+
+/**
+ * Shutdown the video subsystem. This will destroy all video device factories
+ * registered in the video subsystem. Note that currently opened video streams
+ * may or may not be closed, depending on the implementation of the video
+ * device factories.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_subsys_shutdown(void);
+
+
+/**
+ * Register a supported video device factory to the video subsystem. This
+ * function can only be called after calling #pjmedia_vid_subsys_init().
+ *
+ * @param vdf       The video device factory.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
+
+
+/**
+ * Unregister an video device factory from the video subsystem. This
+ * function can only be called after calling #pjmedia_vid_subsys_init().
+ * Devices from this factory will be unlisted. If a device from this factory
+ * is currently in use, then the behavior is undefined.
+ *
+ * @param vdf       The video device factory.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_unregister_factory(pjmedia_vid_dev_factory_create_func_ptr vdf);
+
+
+/**
+ * Get the number of video devices installed in the system.
+ *
+ * @return          The number of video devices installed in the system.
+ */
+PJ_DECL(unsigned) pjmedia_vid_dev_count(void);
+
+
+/**
+ * Get device information.
+ *
+ * @param id        The video device ID.
+ * @param info      The device information which will be filled in by this
+ *                  function once it returns successfully.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id,
+                                              pjmedia_vid_dev_info *info);
+
+
+/**
+ * Lookup device index based on the driver and device name.
+ *
+ * @param drv_name  The driver name.
+ * @param dev_name  The device name.
+ * @param id        Pointer to store the returned device ID.
+ *
+ * @return          PJ_SUCCESS if the device can be found.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_dev_lookup(const char *drv_name,
+                                            const char *dev_name,
+                                            pjmedia_vid_dev_index *id);
+
+
+/**
+ * Initialize the video device parameters with default values for the
+ * specified device.
+ *
+ * @param id        The video device ID.
+ * @param param     The video device parameters which will be initialized
+ *                  by this function once it returns successfully.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_dev_default_param(pj_pool_t *pool,
+                                                   pjmedia_vid_dev_index id,
+                                                   pjmedia_vid_param *param);
+
+
+/**
+ * Open video stream object using the specified parameters.
+ *
+ * @param param         Sound device parameters to be used for the stream.
+ * @param cb            Pointer to structure containing video stream
+ *                      callbacks.
+ * @param user_data     Arbitrary user data, which will be given back in the
+ *                      callbacks.
+ * @param p_strm        Pointer to receive the video stream.
+ *
+ * @return              PJ_SUCCESS on successful operation or the appropriate
+ *                      error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_create(const pjmedia_vid_param *param,
+                                               const pjmedia_vid_cb *cb,
+                                               void *user_data,
+                                               pjmedia_vid_stream **p_strm);
+
+/**
+ * Get the running parameters for the specified video stream.
+ *
+ * @param strm      The video stream.
+ * @param param     Video stream parameters to be filled in by this
+ *                  function once it returns successfully.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_get_param(pjmedia_vid_stream *strm,
+                                                  pjmedia_vid_param *param);
+
+/**
+ * Get the value of a specific capability of the video stream.
+ *
+ * @param strm      The video stream.
+ * @param cap       The video capability which value is to be retrieved.
+ * @param value     Pointer to value to be filled in by this function
+ *                  once it returns successfully.  Please see the type
+ *                  of value to be supplied in the pjmedia_vid_dev_cap
+ *                  documentation.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_get_cap(pjmedia_vid_stream *strm,
+                                                pjmedia_vid_dev_cap cap,
+                                                void *value);
+
+/**
+ * Set the value of a specific capability of the video stream.
+ *
+ * @param strm      The video stream.
+ * @param cap       The video capability which value is to be set.
+ * @param value     Pointer to value. Please see the type of value to
+ *                  be supplied in the pjmedia_vid_dev_cap documentation.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_set_cap(pjmedia_vid_stream *strm,
+                                                pjmedia_vid_dev_cap cap,
+                                                const void *value);
+
+/**
+ * Start the stream.
+ *
+ * @param strm      The video stream.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_start(pjmedia_vid_stream *strm);
+
+/* Get/put frame API for passive stream */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_get_frame(pjmedia_vid_stream *strm,
+                                                  pjmedia_frame *frame);
+
+PJ_DECL(pj_status_t) pjmedia_vid_stream_put_frame(pjmedia_vid_stream *strm,
+                                                  const pjmedia_frame *frame);
+
+/**
+ * Stop the stream.
+ *
+ * @param strm      The video stream.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_stop(pjmedia_vid_stream *strm);
+
+/**
+ * Destroy the stream.
+ *
+ * @param strm      The video stream.
+ *
+ * @return          PJ_SUCCESS on successful operation or the appropriate
+ *                  error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_stream_destroy(pjmedia_vid_stream *strm);
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+
+#endif    /* __PJMEDIA_VIDEODEV_VIDEODEV_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev_imp.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev_imp.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia-videodev/videodev_imp.h	(revision 3392)
@@ -0,0 +1,192 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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 __VIDEODEV_IMP_H__
+#define __VIDEODEV_IMP_H__
+
+#include <pjmedia-videodev/videodev.h>
+
+/**
+ * @defgroup s8_video_device_implementors_api Video Device Implementors API
+ * @ingroup video_device_api
+ * @brief API for video device implementors
+ * @{
+ */
+
+/**
+ * Video device factory operations.
+ */
+typedef struct pjmedia_vid_dev_factory_op
+{
+    /**
+     * Initialize the video device factory.
+     *
+     * @param f		The video device factory.
+     */
+    pj_status_t (*init)(pjmedia_vid_dev_factory *f);
+
+    /**
+     * Close this video device factory and release all resources back to the
+     * operating system.
+     *
+     * @param f		The video device factory.
+     */
+    pj_status_t (*destroy)(pjmedia_vid_dev_factory *f);
+
+    /**
+     * Get the number of video devices installed in the system.
+     *
+     * @param f		The video device factory.
+     */
+    unsigned (*get_dev_count)(pjmedia_vid_dev_factory *f);
+
+    /**
+     * Get the video device information and capabilities.
+     *
+     * @param f		The video device factory.
+     * @param index	Device index.
+     * @param info	The video device information structure which will be
+     *			initialized by this function once it returns 
+     *			successfully.
+     */
+    pj_status_t	(*get_dev_info)(pjmedia_vid_dev_factory *f, 
+				unsigned index,
+				pjmedia_vid_dev_info *info);
+
+    /**
+     * Initialize the specified video device parameter with the default
+     * values for the specified device.
+     *
+     * @param f		The video device factory.
+     * @param index	Device index.
+     * @param param	The video device parameter.
+     */
+    pj_status_t (*default_param)(pj_pool_t *pool,
+                                 pjmedia_vid_dev_factory *f,
+				 unsigned index,
+				 pjmedia_vid_param *param);
+
+    /**
+     * Open the video device and create video stream. See
+     * #pjmedia_vid_stream_create()
+     */
+    pj_status_t (*create_stream)(pjmedia_vid_dev_factory *f,
+				 const pjmedia_vid_param *param,
+				 const pjmedia_vid_cb *cb,
+				 void *user_data,
+				 pjmedia_vid_stream **p_vid_strm);
+
+} pjmedia_vid_dev_factory_op;
+
+
+/**
+ * This structure describes a video device factory. 
+ */
+struct pjmedia_vid_dev_factory
+{
+    /** Internal data to be initialized by video subsystem. */
+    struct {
+	/** Driver index */
+	unsigned drv_idx;
+    } sys;
+
+    /** Operations */
+    pjmedia_vid_dev_factory_op *op;
+};
+
+
+/**
+ * Video stream operations.
+ */
+typedef struct pjmedia_vid_stream_op
+{
+    /**
+     * See #pjmedia_vid_stream_get_param()
+     */
+    pj_status_t (*get_param)(pjmedia_vid_stream *strm,
+			     pjmedia_vid_param *param);
+
+    /**
+     * See #pjmedia_vid_stream_get_cap()
+     */
+    pj_status_t (*get_cap)(pjmedia_vid_stream *strm,
+			   pjmedia_vid_dev_cap cap,
+			   void *value);
+
+    /**
+     * See #pjmedia_vid_stream_set_cap()
+     */
+    pj_status_t (*set_cap)(pjmedia_vid_stream *strm,
+			   pjmedia_vid_dev_cap cap,
+			   const void *value);
+
+    /**
+     * See #pjmedia_vid_stream_start()
+     */
+    pj_status_t (*start)(pjmedia_vid_stream *strm);
+
+    /**
+     * See #pjmedia_vid_stream_get_frame()
+     */
+    pj_status_t (*get_frame)(pjmedia_vid_stream *strm,
+                             pjmedia_frame *frame);
+
+    /**
+     * See #pjmedia_vid_stream_put_frame()
+     */
+    pj_status_t (*put_frame)(pjmedia_vid_stream *strm,
+                             const pjmedia_frame *frame);
+
+    /**
+     * See #pjmedia_vid_stream_stop().
+     */
+    pj_status_t (*stop)(pjmedia_vid_stream *strm);
+
+    /**
+     * See #pjmedia_vid_stream_destroy().
+     */
+    pj_status_t (*destroy)(pjmedia_vid_stream *strm);
+
+} pjmedia_vid_stream_op;
+
+
+/**
+ * This structure describes the video device stream.
+ */
+struct pjmedia_vid_stream
+{
+    /** Internal data to be initialized by video subsystem */
+    struct {
+	/** Driver index */
+	unsigned drv_idx;
+    } sys;
+
+    /** Operations */
+    pjmedia_vid_stream_op *op;
+};
+
+
+
+
+/**
+ * @}
+ */
+
+
+
+#endif /* __VIDEODEV_IMP_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia.h	(revision 3392)
@@ -1,5 +1,5 @@
 /* $Id$ */
 /* 
- * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  *
@@ -25,7 +25,6 @@
  * @brief PJMEDIA main header file.
  */
-
-#include <pjmedia/types.h>
 #include <pjmedia/alaw_ulaw.h>
+#include <pjmedia/avi_stream.h>
 #include <pjmedia/bidirectional.h>
 #include <pjmedia/circbuf.h>
@@ -33,9 +32,12 @@
 #include <pjmedia/codec.h>
 #include <pjmedia/conference.h>
+#include <pjmedia/converter.h>
 #include <pjmedia/delaybuf.h>
 #include <pjmedia/echo.h>
 #include <pjmedia/echo_port.h>
+#include <pjmedia/endpoint.h>
 #include <pjmedia/errno.h>
-#include <pjmedia/endpoint.h>
+#include <pjmedia/frame.h>
+#include <pjmedia/format.h>
 #include <pjmedia/g711.h>
 #include <pjmedia/jbuf.h>
@@ -65,4 +67,6 @@
 #include <pjmedia/transport_srtp.h>
 #include <pjmedia/transport_udp.h>
+#include <pjmedia/videoport.h>
+#include <pjmedia/vid_codec.h>
 #include <pjmedia/wav_playlist.h>
 #include <pjmedia/wav_port.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi.h	(revision 3392)
@@ -0,0 +1,202 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_AVI_H__
+#define __PJMEDIA_AVI_H__
+
+
+/**
+ * @file avi.h
+ * @brief AVI file manipulation.
+ */
+
+/**
+ * @defgroup PJMEDIA_FILE_FORMAT File Formats
+ * @brief Supported file formats
+ */
+
+
+/**
+ * @defgroup PJMEDIA_AVI AVI Header
+ * @ingroup PJMEDIA_FILE_FORMAT
+ * @brief Representation of RIFF/AVI file format
+ * @{
+ *
+ * This the the low level representation of RIFF/AVI file format. For
+ * higher abstraction, please see \ref PJMEDIA_FILE_PLAY and 
+ * \ref PJMEDIA_FILE_REC.
+ */
+
+
+PJ_BEGIN_DECL
+
+#define PJMEDIA_AVI_MAX_NUM_STREAMS 4
+
+static const char avi_tags[][4] = {
+    { 'R', 'I', 'F', 'F' }, { 'A', 'V', 'I', ' ' },
+    { 'h', 'd', 'r', 'l' }, { 'a', 'v', 'i', 'h' },
+    { 's', 't', 'r', 'l' }, { 's', 't', 'r', 'h' },
+    { 'a', 'u', 'd', 's' }, { 'v', 'i', 'd', 's' },
+    { 's', 't', 'r', 'f' }, { 'm', 'o', 'v', 'i' },
+    { 'L', 'I', 'S', 'T' }, { 'J', 'U', 'N', 'K' },
+};
+
+typedef enum {
+    PJMEDIA_AVI_RIFF_TAG = 0,
+    PJMEDIA_AVI_AVI_TAG,
+    PJMEDIA_AVI_HDRL_TAG,
+    PJMEDIA_AVI_AVIH_TAG,
+    PJMEDIA_AVI_STRL_TAG,
+    PJMEDIA_AVI_STRH_TAG,
+    PJMEDIA_AVI_AUDS_TAG,
+    PJMEDIA_AVI_VIDS_TAG,
+    PJMEDIA_AVI_STRF_TAG,
+    PJMEDIA_AVI_MOVI_TAG,
+    PJMEDIA_AVI_LIST_TAG,
+    PJMEDIA_AVI_JUNK_TAG,
+} pjmedia_avi_tag;
+
+
+/**
+ * These types describe the simpler/canonical version of an AVI file.
+ * They do not support the full AVI RIFF format specification.
+ */
+#pragma pack(2)
+
+/** This structure describes RIFF AVI file header */
+typedef struct riff_hdr_t {
+    pj_uint32_t riff;		/**< "RIFF" ASCII tag.		*/
+    pj_uint32_t file_len;       /**< File length minus 8 bytes	*/
+    pj_uint32_t avi;		/**< "AVI" ASCII tag.		*/
+} riff_hdr_t;
+
+/** This structure describes avih header  */
+typedef struct avih_hdr_t {
+    pj_uint32_t list_tag;
+    pj_uint32_t list_sz;
+    pj_uint32_t hdrl_tag;
+    pj_uint32_t avih;
+    pj_uint32_t size;
+    pj_uint32_t msec_per_frame;     /**< microsecs between frames   */
+    pj_uint32_t max_Bps;
+    pj_uint32_t pad;
+    pj_uint32_t flags;
+    pj_uint32_t tot_frames;
+    pj_uint32_t init_frames;
+    pj_uint32_t num_streams;
+    pj_uint32_t buf_size;
+    pj_uint32_t width;
+    pj_uint32_t height;
+    pj_uint32_t reserved[4];
+} avih_hdr_t;
+
+/** This structure describes strl header  */
+typedef struct strl_hdr_t {
+    pj_uint32_t list_tag;
+    pj_uint32_t list_sz;
+    pj_uint32_t strl_tag;
+
+    pj_uint32_t strh;
+    pj_uint32_t strh_size;
+    pj_uint32_t data_type;
+    pj_uint32_t codec;
+    pj_uint32_t flags;
+    pj_uint32_t bogus_priority_language; /**< Do not access this data */
+    pj_uint32_t init_frames;
+    pj_uint32_t scale;
+    pj_uint32_t rate;
+    pj_uint32_t start;
+    pj_uint32_t length;
+    pj_uint32_t buf_size;
+    pj_uint32_t quality;
+    pj_uint32_t sample_size;
+    pj_uint32_t bogus_frame[2];          /**< Do not access this data */
+} strl_hdr_t;
+
+typedef struct {
+    pj_uint32_t strf;
+    pj_uint32_t strf_size;
+    pj_uint16_t fmt_tag;	    /**< 1 for PCM			*/
+    pj_uint16_t nchannels;          /**< Number of channels.	        */
+    pj_uint32_t sample_rate;	    /**< Sampling rate.		        */
+    pj_uint32_t bytes_per_sec;	    /**< Average bytes per second.	*/
+    pj_uint16_t block_align;	    /**< nchannels * bits / 8	        */
+    pj_uint16_t bits_per_sample;    /**< Bits per sample.		*/
+    pj_uint16_t extra_size;
+} strf_audio_hdr_t;
+
+/**
+ * Sizes of strf_audio_hdr_t struct, started by the size (in bytes) of
+ * 32-bits struct members, alternated with the size of 16-bits members.
+ */
+static const pj_uint8_t strf_audio_hdr_sizes [] = {8, 4, 8, 6};
+
+typedef struct {
+    pj_uint32_t strf;
+    pj_uint32_t strf_size;
+    pj_uint32_t biSize; 
+    pj_int32_t biWidth; 
+    pj_int32_t biHeight; 
+    pj_uint16_t biPlanes; 
+    pj_uint16_t biBitCount;
+    pj_uint32_t biCompression; 
+    pj_uint32_t biSizeImage; 
+    pj_int32_t biXPelsPerMeter; 
+    pj_int32_t biYPelsPerMeter; 
+    pj_uint32_t biClrUsed; 
+    pj_uint32_t biClrImportant; 
+} strf_video_hdr_t;
+
+static const pj_uint8_t strf_video_hdr_sizes [] = {20, 4, 24};
+
+struct pjmedia_avi_hdr
+{
+    riff_hdr_t  riff_hdr;
+    avih_hdr_t  avih_hdr;
+    strl_hdr_t  strl_hdr[PJMEDIA_AVI_MAX_NUM_STREAMS];
+    union {
+        strf_audio_hdr_t strf_audio_hdr;
+        strf_video_hdr_t strf_video_hdr;
+    } strf_hdr[PJMEDIA_AVI_MAX_NUM_STREAMS];
+};
+
+#pragma pack()
+
+/**
+ * @see pjmedia_avi_hdr
+ */
+typedef struct pjmedia_avi_hdr pjmedia_avi_hdr;
+
+/**
+ * This structure describes generic RIFF subchunk header.
+ */
+typedef struct pjmedia_avi_subchunk
+{
+    pj_uint32_t	    id;			/**< Subchunk ASCII tag.	    */
+    pj_uint32_t	    len;		/**< Length following this field    */
+} pjmedia_avi_subchunk;
+
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+
+#endif	/* __PJMEDIA_AVI_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi_stream.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi_stream.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/avi_stream.h	(revision 3392)
@@ -0,0 +1,132 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_AVI_STREAM_H__
+#define __PJMEDIA_AVI_STREAM_H__
+
+/**
+ * @file avi_stream.h
+ * @brief AVI file player.
+ */
+#include <pjmedia/port.h>
+
+
+
+PJ_BEGIN_DECL
+
+
+/**
+ * @defgroup PJMEDIA_FILE_PLAY AVI File Player
+ * @ingroup PJMEDIA_PORT
+ * @brief Video and audio playback from AVI file
+ * @{
+ */
+
+/**
+ * AVI file player options.
+ */
+enum pjmedia_avi_file_player_option
+{
+    /**
+     * Tell the file player to return NULL frame when the whole
+     * file has been played.
+     */
+    PJMEDIA_AVI_FILE_NO_LOOP = 1
+};
+
+typedef pjmedia_port pjmedia_avi_stream;
+
+typedef struct pjmedia_avi_streams pjmedia_avi_streams;
+
+/**
+ * Create avi streams to play an AVI file. AVI player supports 
+ * reading AVI file with uncompressed video format and 
+ * 16 bit PCM or compressed G.711 A-law/U-law audio format.
+ *
+ * @param pool		Pool to create the streams.
+ * @param filename	File name to open.
+ * @param flags		Avi streams creation flags.
+ * @param p_streams	Pointer to receive the avi streams instance.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_avi_player_create_streams(pj_pool_t *pool,
+                                  const char *filename,
+                                  unsigned flags,
+                                  pjmedia_avi_streams **p_streams);
+
+PJ_DECL(pj_uint8_t)
+pjmedia_avi_streams_get_num_streams(pjmedia_avi_streams *streams);
+
+PJ_DECL(pjmedia_avi_stream *)
+pjmedia_avi_streams_get_stream(pjmedia_avi_streams *streams,
+                               pj_uint8_t idx);
+
+PJ_DECL(pjmedia_avi_stream *)
+pjmedia_avi_streams_get_stream_by_media(pjmedia_avi_streams *streams,
+                                        pj_uint8_t start_idx,
+                                        pjmedia_type media_type);
+
+PJ_INLINE(pjmedia_port *)
+pjmedia_avi_stream_get_port(pjmedia_avi_stream *stream)
+{
+    return (pjmedia_port *)stream;
+}
+
+/**
+ * Get the data length, in bytes.
+ *
+ * @param port		The AVI stream.
+ *
+ * @return		The length of the data, in bytes. Upon error it will
+ *			return negative value.
+ */
+PJ_DECL(pj_ssize_t) pjmedia_avi_stream_get_len(pjmedia_avi_stream *stream);
+
+
+/**
+ * Register a callback to be called when the file reading has reached the
+ * end of file. If the file is set to play repeatedly, then the callback
+ * will be called multiple times. Note that only one callback can be 
+ * registered for each AVI stream.
+ *
+ * @param port		The AVI stream.
+ * @param user_data	User data to be specified in the callback
+ * @param cb		Callback to be called. If the callback returns non-
+ *			PJ_SUCCESS, the playback will stop. Note that if
+ *			application destroys the file port in the callback,
+ *			it must return non-PJ_SUCCESS here.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_avi_stream_set_eof_cb(pjmedia_avi_stream *stream,
+			      void *user_data,
+			      pj_status_t (*cb)(pjmedia_avi_stream *stream,
+					        void *usr_data));
+
+/**
+ * @}
+ */
+
+
+PJ_END_DECL
+
+
+#endif	/* __PJMEDIA_AVI_STREAM_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/circbuf.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/circbuf.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/circbuf.h	(revision 3392)
@@ -30,4 +30,5 @@
 #include <pj/errno.h>
 #include <pj/pool.h>
+#include <pjmedia/frame.h>
 
 /**
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/clock.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/clock.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/clock.h	(revision 3392)
@@ -119,5 +119,10 @@
 
 /**
- * Create media clock.
+ * Create media clock. This creates a media clock object that will run
+ * periodically at an interval that is calculated from the audio parameters.
+ * Once created, application must call #pjmedia_clock_start() to actually
+ * start the clock.
+ *
+ * @see pjmedia_clock_create2()
  *
  * @param pool		    Pool to allocate memory.
@@ -144,4 +149,30 @@
 					   pjmedia_clock **p_clock);
 
+
+/**
+ * Create media clock. This creates a media clock object that will run
+ * periodically at the specified interval. Once created, application must
+ * call #pjmedia_clock_start() to actually start the clock.
+ *
+ * @param pool		    Pool to allocate memory.
+ * @param usec_interval	    The frame interval, in microseconds.
+ * @param clock_rate	    The media clock rate, to determine timestamp
+ * 			    increment for each call.
+ * @param options	    Bitmask of pjmedia_clock_options.
+ * @param cb		    Callback to be called for each clock tick.
+ * @param user_data	    User data, which will be passed to the callback.
+ * @param p_clock	    Pointer to receive the clock instance.
+ *
+ * @return		    PJ_SUCCESS on success, or the appropriate error
+ *			    code.
+ */
+PJ_DECL(pj_status_t) pjmedia_clock_create2(pj_pool_t *pool,
+					   unsigned usec_interval,
+					   unsigned clock_rate,
+					   unsigned options,
+					   pjmedia_clock_callback *cb,
+					   void *user_data,
+					   pjmedia_clock **p_clock);
+
 /**
  * Start the clock. For clock created with asynchronous flag set to TRUE,
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/config.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/config.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/config.h	(revision 3392)
@@ -881,4 +881,91 @@
 
 
+/*
+ * .... new stuffs ...
+ */
+
+/**
+ * Specify if FFMPEG is available. The value here will be used as the default
+ * value for other FFMPEG settings below.
+ *
+ * Default: 0
+ */
+#ifndef PJMEDIA_HAS_FFMPEG
+#   define PJMEDIA_HAS_FFMPEG				0
+#endif
+
+/**
+ * Specify if FFMPEG libavformat is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBAVFORMAT
+#   define PJMEDIA_HAS_LIBAVFORMAT			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Specify if FFMPEG libavformat is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBAVCODEC
+#   define PJMEDIA_HAS_LIBAVCODEC			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Specify if FFMPEG libavutil is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBAVUTIL
+#   define PJMEDIA_HAS_LIBAVUTIL			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Specify if FFMPEG libswscale is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBSWSCALE
+#   define PJMEDIA_HAS_LIBSWSCALE			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Specify if FFMPEG libavdevice is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBAVDEVICE
+#   define PJMEDIA_HAS_LIBAVDEVICE			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Specify if FFMPEG libavcore is available.
+ *
+ * Default: PJMEDIA_HAS_FFMPEG (or detected by configure)
+ */
+#ifndef PJMEDIA_HAS_LIBAVCORE
+#   define PJMEDIA_HAS_LIBAVCORE			PJMEDIA_HAS_FFMPEG
+#endif
+
+/**
+ * Maximum video planes.
+ *
+ * Default: 4
+ */
+#ifndef PJMEDIA_MAX_VIDEO_PLANES
+#   define PJMEDIA_MAX_VIDEO_PLANES			4
+#endif
+
+/**
+ * Maximum number of video formats.
+ *
+ * Default: 32
+ */
+#ifndef PJMEDIA_MAX_VIDEO_FORMATS
+#   define PJMEDIA_MAX_VIDEO_FORMATS			32
+#endif
+
+
 /**
  * @}
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/converter.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/converter.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/converter.h	(revision 3392)
@@ -0,0 +1,322 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_CONVERTER_H__
+#define __PJMEDIA_CONVERTER_H__
+
+
+/**
+ * @file pjmedia/converter.h Format conversion utilities
+ * @brief Format conversion utilities
+ */
+
+#include <pjmedia/frame.h>
+#include <pjmedia/format.h>
+#include <pj/list.h>
+#include <pj/pool.h>
+
+
+/**
+ * @defgroup PJMEDIA_CONVERTER Format converter
+ * @ingroup PJMEDIA_FRAME_OP
+ * @brief Audio and video converter utilities
+ * @{
+ */
+
+PJ_BEGIN_DECL
+
+/**
+ * This describes conversion parameter. It specifies the source and
+ * destination formats of the conversion.
+ */
+typedef struct pjmedia_conversion_param
+{
+    pjmedia_format	src;	/**< Source format.		*/
+    pjmedia_format	dst;	/**< Destination format.	*/
+} pjmedia_conversion_param;
+
+
+/** Forward declaration of factory operation structure */
+typedef struct pjmedia_converter_factory_op pjmedia_converter_factory_op;
+
+/**
+ * Converter priority guides. Converter priority determines which converter
+ * instance to be used if more than one converters are able to perform the
+ * requested conversion. Converter implementor can use this value to order
+ * the preference based on attributes such as quality or performance. Higher
+ * number indicates higher priority.
+ */
+typedef enum pjmedia_converter_priority_guide
+{
+    /** Lowest priority. */
+    PJMEDIA_CONVERTER_PRIORITY_LOWEST 		= 0,
+
+    /** Normal priority. */
+    PJMEDIA_CONVERTER_PRIORITY_NORMAL 		= 15000,
+
+    /** Highest priority. */
+    PJMEDIA_CONVERTER_PRIORITY_HIGHEST 		= 32000
+} pjmedia_converter_priority_guide;
+
+/**
+ * Converter factory. The converter factory registers a callback function
+ * to create converters.
+ */
+typedef struct pjmedia_converter_factory
+{
+    /**
+     * Standard list members.
+     */
+    PJ_DECL_LIST_MEMBER(struct pjmedia_converter_factory);
+
+    /**
+     * Factory name.
+     */
+    const char 			 *name;
+
+    /**
+     * Converter priority determines which converter instance to be used if
+     * more than one converters are able to perform the requested conversion.
+     * Converter implementor can use this value to order the preference based
+     * on attributes such as quality or performance. Higher number indicates
+     * higher priority. The pjmedia_converter_priority_guide enumeration shall
+     * be used as the base value to set the priority.
+     */
+    int priority;
+
+    /**
+     * Pointer to factory operation.
+     */
+    pjmedia_converter_factory_op *op;
+
+} pjmedia_converter_factory;
+
+/** Forward declaration for converter operation. */
+typedef struct pjmedia_converter_op pjmedia_converter_op;
+
+/**
+ * This structure describes a converter instance.
+ */
+typedef struct pjmedia_converter
+{
+    /**
+     * Pointer to converter operation.
+     */
+    pjmedia_converter_op *op;
+
+} pjmedia_converter;
+
+
+/**
+ * Converter factory operation.
+ */
+struct pjmedia_converter_factory_op
+{
+    /**
+     * This function creates a converter with the specified conversion format,
+     * if such format is supported.
+     *
+     * @param cf	The converter factory.
+     * @param pool	Pool to allocate memory from.
+     * @param prm	Conversion parameter.
+     * @param p_cv	Pointer to hold the created converter instance.
+     *
+     * @return		PJ_SUCCESS if converter has been created successfully.
+     */
+    pj_status_t (*create_converter)(pjmedia_converter_factory *cf,
+				    pj_pool_t *pool,
+				    const pjmedia_conversion_param *prm,
+				    pjmedia_converter **p_cv);
+
+    /**
+     * Destroy the factory.
+     *
+     * @param cf	The converter factory.
+     */
+    void (*destroy_factory)(pjmedia_converter_factory *cf);
+};
+
+/**
+ * Converter operation.
+ */
+struct pjmedia_converter_op
+{
+    /**
+     * Convert the buffer in the source frame and save the result in the
+     * buffer of the destination frame, according to conversion format that
+     * was specified when the converter was created.
+     *
+     * Note that application should use #pjmedia_converter_convert() instead
+     * of calling this function directly.
+     *
+     * @param cv	The converter instance.
+     * @param src_frame	The source frame.
+     * @param dst_frame	The destination frame.
+     *
+     * @return		PJ_SUCCESS if conversion has been performed
+     * 			successfully.
+     */
+    pj_status_t (*convert)(pjmedia_converter *cv,
+			   pjmedia_frame *src_frame,
+			   pjmedia_frame *dst_frame);
+
+    /**
+     * Destroy the converter instance.
+     *
+     * Note that application should use #pjmedia_converter_destroy() instead
+     * of calling this function directly.
+     *
+     * @param cv	The converter.
+     */
+    void (*destroy)(pjmedia_converter *cv);
+
+};
+
+
+/**
+ * Opaque data type for conversion manager. Typically, the conversion manager
+ * is a singleton instance, although application may instantiate more than one
+ * instances of this if required.
+ */
+typedef struct pjmedia_converter_mgr pjmedia_converter_mgr;
+
+
+/**
+ * Create a new conversion manager instance. This will also set the pointer
+ * to the singleton instance if the value is still NULL.
+ *
+ * @param pool		Pool to allocate memory from.
+ * @param mgr		Pointer to hold the created instance of the
+ * 			conversion manager.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_converter_mgr_create(pj_pool_t *pool,
+						  pjmedia_converter_mgr **mgr);
+
+/**
+ * Get the singleton instance of the conversion manager.
+ *
+ * @return		The instance.
+ */
+PJ_DECL(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void);
+
+/**
+ * Manually assign a specific video manager instance as the singleton
+ * instance. Normally this is not needed if only one instance is ever
+ * going to be created, as the library automatically assign the singleton
+ * instance.
+ *
+ * @param mgr		The instance to be used as the singleton instance.
+ * 			Application may specify NULL to clear the singleton
+ * 			singleton instance.
+ */
+PJ_DECL(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr);
+
+/**
+ * Destroy a converter manager. If the manager happens to be the singleton
+ * instance, the singleton instance will be set to NULL.
+ *
+ * @param mgr		The converter manager. Specify NULL to use
+ * 			the singleton instance.
+ */
+PJ_DECL(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr);
+
+/**
+ * Register a converter factory to the converter manager.
+ *
+ * @param mgr		The converter manager. Specify NULL to use
+ * 			the singleton instance.
+ * @param f		The converter factory to be registered.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
+				       pjmedia_converter_factory *f);
+
+/**
+ * Unregister a previously registered converter factory from the converter
+ * manager.
+ *
+ * @param mgr		The converter manager. Specify NULL to use
+ * 			the singleton instance.
+ * @param f		The converter factory to be unregistered.
+ * @param call_destroy	If this is set to non-zero, the \a destroy_factory()
+ * 			callback of the factory will be called while
+ * 			unregistering the factory from the manager.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
+				         pjmedia_converter_factory *f,
+				         pj_bool_t call_destroy);
+
+/**
+ * Create a converter instance to perform the specified format conversion
+ * as specified in \a param.
+ *
+ * @param mgr		The converter manager. Specify NULL to use
+ * 			the singleton instance.
+ * @param pool		Pool to allocate the memory from.
+ * @param param		Conversion parameter.
+ * @param p_cv		Pointer to hold the created converter.
+ *
+ * @return		PJ_SUCCESS if a converter has been created successfully
+ * 			or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
+					      pj_pool_t *pool,
+					      pjmedia_conversion_param *param,
+					      pjmedia_converter **p_cv);
+
+/**
+ * Convert the buffer in the source frame and save the result in the
+ * buffer of the destination frame, according to conversion format that
+ * was specified when the converter was created.
+ *
+ * @param cv		The converter instance.
+ * @param src_frame	The source frame.
+ * @param dst_frame	The destination frame.
+ *
+ * @return		PJ_SUCCESS if conversion has been performed
+ * 			successfully.
+ */
+PJ_DECL(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
+					       pjmedia_frame *src_frame,
+					       pjmedia_frame *dst_frame);
+
+/**
+ * Destroy the converter.
+ *
+ * @param cv		The converter instance.
+ */
+PJ_DECL(void) pjmedia_converter_destroy(pjmedia_converter *cv);
+
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+
+#endif /* __PJMEDIA_CONVERTER_H__ */
+
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/endpoint.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/endpoint.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/endpoint.h	(revision 3392)
@@ -40,4 +40,5 @@
 #include <pjmedia/codec.h>
 #include <pjmedia/sdp.h>
+#include <pjmedia/transport.h>
 
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/errno.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/errno.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/errno.h	(revision 3392)
@@ -392,5 +392,9 @@
  */
 #define PJMEDIA_RTP_EREMNORFC2833   (PJMEDIA_ERRNO_START+107)    /* 220107 */
-
+/**
+ * @hideinitializer
+ * Invalid or bad format
+ */
+#define PJMEDIA_EBADFMT             (PJMEDIA_ERRNO_START+108)    /* 220108 */
 
 
@@ -518,4 +522,9 @@
  */
 #define PJMEDIA_EFRMFILETOOBIG	    (PJMEDIA_ERRNO_START+183)    /* 220183 */
+/**
+ * @hideinitializer
+ * Unsupported AVI file.
+ */
+#define PJMEDIA_EAVIUNSUPP	    (PJMEDIA_ERRNO_START+191)    /* 220191 */
 
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/format.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/format.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/format.h	(revision 3392)
@@ -0,0 +1,706 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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_FORMAT_H__
+#define __PJMEDIA_FORMAT_H__
+
+/**
+ * @file pjmedia/format.h Media format
+ * @brief Media format
+ */
+#include <pjmedia/types.h>
+
+/**
+ * @defgroup PJMEDIA_FORMAT Media format
+ * @ingroup PJMEDIA_TYPES
+ * @brief Media format
+ * @{
+ */
+
+PJ_BEGIN_DECL
+
+/**
+ * Macro for packing format from a four character code, similar to FOURCC.
+ * This macro is used for building the constants in pjmedia_format_id
+ * enumeration.
+ */
+#define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 )
+
+/**
+ * This enumeration uniquely identify audio sample and/or video pixel formats.
+ * Some well known formats are listed here. The format ids are built by
+ * combining four character codes, similar to FOURCC. The format id is
+ * extensible, as application may define and use format ids not declared
+ * on this enumeration.
+ *
+ * This format id along with other information will fully describe the media
+ * in #pjmedia_format structure.
+ */
+typedef enum pjmedia_format_id
+{
+    /*
+     * Audio formats
+     */
+
+    /** 16bit signed integer linear PCM audio */
+    PJMEDIA_FORMAT_L16	    = 0,
+
+    /** Alias for PJMEDIA_FORMAT_L16 */
+    PJMEDIA_FORMAT_PCM	    = PJMEDIA_FORMAT_L16,
+
+    /** G.711 ALAW */
+    PJMEDIA_FORMAT_PCMA	    = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'),
+
+    /** Alias for PJMEDIA_FORMAT_PCMA */
+    PJMEDIA_FORMAT_ALAW	    = PJMEDIA_FORMAT_PCMA,
+
+    /** G.711 ULAW */
+    PJMEDIA_FORMAT_PCMU	    = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'),
+
+    /** Aliaw for PJMEDIA_FORMAT_PCMU */
+    PJMEDIA_FORMAT_ULAW	    = PJMEDIA_FORMAT_PCMU,
+
+    /** AMR narrowband */
+    PJMEDIA_FORMAT_AMR	    = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'),
+
+    /** ITU G.729 */
+    PJMEDIA_FORMAT_G729	    = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'),
+
+    /** Internet Low Bit-Rate Codec (ILBC) */
+    PJMEDIA_FORMAT_ILBC	    = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C'),
+
+
+    /*
+     * Video formats.
+     */
+    /**
+     * 24bit RGB
+     */
+    PJMEDIA_FORMAT_RGB24    = PJMEDIA_FORMAT_PACK('R', 'G', 'B', '3'),
+
+    /**
+     * 32bit RGB with alpha channel
+     */
+    PJMEDIA_FORMAT_RGBA     = PJMEDIA_FORMAT_PACK('R', 'G', 'B', 'A'),
+    PJMEDIA_FORMAT_BGRA     = PJMEDIA_FORMAT_PACK('B', 'G', 'R', 'A'),
+
+    /**
+     * Alias for PJMEDIA_FORMAT_RGBA
+     */
+    PJMEDIA_FORMAT_RGB32    = PJMEDIA_FORMAT_RGBA,
+
+    /**
+     * Device Independent Bitmap, alias for 24 bit RGB
+     */
+    PJMEDIA_FORMAT_DIB      = PJMEDIA_FORMAT_PACK('D', 'I', 'B', ' '),
+
+    /**
+     * This is a packed 4:4:4/32bpp format, where each pixel is encoded as
+     * four consecutive bytes, arranged in the following sequence: V0, U0,
+     * Y0, A0. Source:
+     * http://msdn.microsoft.com/en-us/library/dd206750%28v=VS.85%29.aspx#ayuv
+     */
+    PJMEDIA_FORMAT_AYUV	    = PJMEDIA_FORMAT_PACK('A', 'Y', 'U', 'V'),
+
+    /**
+     * This is packed 4:2:2/16bpp YUV format, the data can be treated as
+     * an array of unsigned char values, where the first byte contains
+     * the first Y sample, the second byte contains the first U (Cb) sample,
+     * the third byte contains the second Y sample, and the fourth byte
+     * contains the first V (Cr) sample, and so forth. Source:
+     * http://msdn.microsoft.com/en-us/library/dd206750%28v=VS.85%29.aspx#yuy2
+     */
+    PJMEDIA_FORMAT_YUY2	    = PJMEDIA_FORMAT_PACK('Y', 'U', 'Y', '2'),
+
+    /**
+     * This format is the same as the YUY2 format except the byte order is
+     * reversed -- that is, the chroma and luma bytes are flipped. If the
+     * image is addressed as an array of two little-endian WORD values, the
+     * first WORD contains U in the LSBs and Y0 in the MSBs, and the second
+     * WORD contains V in the LSBs and Y1 in the MSBs. Source:
+     * http://msdn.microsoft.com/en-us/library/dd206750%28v=VS.85%29.aspx#uyvy
+     */
+    PJMEDIA_FORMAT_UYVY	    = PJMEDIA_FORMAT_PACK('U', 'Y', 'V', 'Y'),
+
+    /**
+     * This format is the same as the YUY2 and UYVY format except the byte
+     * order is reversed -- that is, the chroma and luma bytes are flipped.
+     * If the image is addressed as an array of two little-endian WORD values,
+     * the first WORD contains Y0 in the LSBs and V in the MSBs, and the second
+     * WORD contains Y1 in the LSBs and U in the MSBs.
+     */
+    PJMEDIA_FORMAT_YVYU	    = PJMEDIA_FORMAT_PACK('Y', 'V', 'Y', 'U'),
+
+    /**
+     * This is planar 4:2:0/12bpp YUV format, the data can be treated as
+     * three planes of color components, where the first plane contains
+     * only the Y samples, the second plane contains only the U (Cb) samples,
+     * and the third plane contains only the V (Cr) sample.
+     */
+    PJMEDIA_FORMAT_I420	    = PJMEDIA_FORMAT_PACK('I', '4', '2', '0'),
+
+    /**
+     * IYUV is alias for I420.
+     */
+    PJMEDIA_FORMAT_IYUV	    = PJMEDIA_FORMAT_I420,
+
+    /**
+     * This is planar 4:2:2/16bpp YUV format.
+     */
+    PJMEDIA_FORMAT_YV12	    = PJMEDIA_FORMAT_PACK('Y', 'V', '1', '2'),
+
+    /**
+     * The JPEG version of planar 4:2:0/12bpp YUV format.
+     */
+    PJMEDIA_FORMAT_I420JPEG = PJMEDIA_FORMAT_PACK('J', '4', '2', '0'),
+
+    /**
+     * The JPEG version of planar 4:2:2/16bpp YUV format.
+     */
+    PJMEDIA_FORMAT_I422JPEG = PJMEDIA_FORMAT_PACK('J', '4', '2', '2'),
+
+    /**
+     * Encoded video formats
+     */
+
+    PJMEDIA_FORMAT_H261     = PJMEDIA_FORMAT_PACK('H', '2', '6', '1'),
+    PJMEDIA_FORMAT_H263     = PJMEDIA_FORMAT_PACK('H', '2', '6', '3'),
+
+    PJMEDIA_FORMAT_MJPEG    = PJMEDIA_FORMAT_PACK('M', 'J', 'P', 'G'),
+    PJMEDIA_FORMAT_MPEG1VIDEO = PJMEDIA_FORMAT_PACK('M', 'P', '1', 'V'),
+    PJMEDIA_FORMAT_MPEG2VIDEO = PJMEDIA_FORMAT_PACK('M', 'P', '2', 'V'),
+    PJMEDIA_FORMAT_MPEG4    = PJMEDIA_FORMAT_PACK('M', 'P', 'G', '4'),
+
+} pjmedia_format_id;
+
+/**
+ * This enumeration specifies what type of detail is included in a
+ * #pjmedia_format structure.
+ */
+typedef enum pjmedia_format_detail_type
+{
+    /** Format detail is not specified. */
+    PJMEDIA_FORMAT_DETAIL_NONE,
+
+    /** Audio format detail. */
+    PJMEDIA_FORMAT_DETAIL_AUDIO,
+
+    /** Video format detail. */
+    PJMEDIA_FORMAT_DETAIL_VIDEO,
+
+    /** Number of format detail type that has been defined. */
+    PJMEDIA_FORMAT_DETAIL_MAX
+
+} pjmedia_format_detail_type;
+
+/**
+ * This structure is put in \a detail field of #pjmedia_format to describe
+ * detail information about an audio media.
+ */
+typedef struct pjmedia_audio_format_detail
+{
+    unsigned	clock_rate;	/**< Audio clock rate in samples or Hz. */
+    unsigned	channel_count;	/**< Number of channels.		*/
+    unsigned	frame_time_usec;/**< Frame interval, in microseconds.	*/
+    unsigned	bits_per_sample;/**< Number of bits per sample.		*/
+    pj_uint32_t	avg_bps;	/**< Average bitrate			*/
+    pj_uint32_t	max_bps;	/**< Maximum bitrate			*/
+} pjmedia_audio_format_detail;
+
+/**
+ * This structure is put in \a detail field of #pjmedia_format to describe
+ * detail information about a video media.
+ *
+ * Additional information about a video format can also be retrieved by
+ * calling #pjmedia_get_video_format_info().
+ */
+typedef struct pjmedia_video_format_detail
+{
+    pjmedia_rect_size	size;	/**< Video size (width, height) 	*/
+    pjmedia_ratio	fps;	/**< Number of frames per second.	*/
+    pj_uint32_t		avg_bps;/**< Average bitrate.			*/
+    pj_uint32_t		max_bps;/**< Maximum bitrate.			*/
+} pjmedia_video_format_detail;
+
+/**
+ * This macro declares the size of the detail section in #pjmedia_format
+ * to be reserved for user defined detail.
+ */
+#ifndef PJMEDIA_FORMAT_DETAIL_USER_SIZE
+#   define PJMEDIA_FORMAT_DETAIL_USER_SIZE		1
+#endif
+
+/**
+ * This structure contains all the information needed to completely describe
+ * a media.
+ */
+typedef struct pjmedia_format
+{
+    /**
+     * The format id that specifies the audio sample or video pixel format.
+     * Some well known formats ids are declared in pjmedia_format_id
+     * enumeration.
+     *
+     * @see pjmedia_format_id
+     */
+    pj_uint32_t		 	 id;
+
+    /**
+     * The top-most type of the media, as an information.
+     */
+    pjmedia_type		 type;
+
+    /**
+     * The type of detail structure in the \a detail pointer.
+     */
+    pjmedia_format_detail_type	 detail_type;
+
+    /**
+     * Detail section to describe the media.
+     */
+    union
+    {
+	/**
+	 * Detail section for audio format.
+	 */
+	pjmedia_audio_format_detail	aud;
+
+	/**
+	 * Detail section for video format.
+	 */
+	pjmedia_video_format_detail	vid;
+
+	/**
+	 * Reserved area for user-defined format detail.
+	 */
+	char				user[PJMEDIA_FORMAT_DETAIL_USER_SIZE];
+    } det;
+
+} pjmedia_format;
+
+/**
+ * This enumeration describes video color model. It mostly serves as
+ * information only.
+ */
+typedef enum pjmedia_color_model
+{
+    /** The color model is unknown or unspecified. */
+    PJMEDIA_COLOR_MODEL_NONE,
+
+    /** RGB color model. */
+    PJMEDIA_COLOR_MODEL_RGB,
+
+    /** YUV color model. */
+    PJMEDIA_COLOR_MODEL_YUV
+} pjmedia_color_model;
+
+/**
+ * This structure holds information to apply a specific video format
+ * against size and buffer information, and get additional information
+ * from it. To do that, application fills up the input fields of this
+ * structure, and give this structure to \a apply_fmt() function
+ * of #pjmedia_video_format_info structure.
+ */
+typedef struct pjmedia_video_apply_fmt_param
+{
+    /* input fields: */
+
+    /**
+     * [IN] The image size. This field is mandatory, and has to be set
+     * correctly prior to calling \a apply_fmt() function.
+     */
+    pjmedia_rect_size	 size;
+
+    /**
+     * [IN] Pointer to the buffer that holds the frame. The \a apply_fmt()
+     * function uses this pointer to calculate the pointer for each video
+     * planes of the media. This field is optional -- however, the
+     * \a apply_fmt() would still fill up the \a planes[] array with the
+     * correct pointer even though the buffer is set to NULL. This could be
+     * useful to calculate the size (in bytes) of each plane.
+     */
+    pj_uint8_t		*buffer;
+
+    /* output fields: */
+
+    /**
+     * [OUT] The size (in bytes) required of the buffer to hold the video
+     * frame of the particular frame size (width, height).
+     */
+    pj_size_t		 framebytes;
+
+    /**
+     * [OUT] Array of strides value (in bytes) for each video plane.
+     */
+    int		         strides[PJMEDIA_MAX_VIDEO_PLANES];
+
+    /**
+     * [OUT] Array of pointers to each of the video planes. The values are
+     * calculated from the \a buffer field.
+     */
+    pj_uint8_t		*planes[PJMEDIA_MAX_VIDEO_PLANES];
+
+    /**
+     * [OUT] Array of video plane sizes.
+     */
+    pj_size_t		 plane_bytes[PJMEDIA_MAX_VIDEO_PLANES];
+
+} pjmedia_video_apply_fmt_param;
+
+/**
+ * This structure holds information to describe a video format. Application
+ * can retrieve this structure by calling #pjmedia_get_video_format_info()
+ * funcion.
+ */
+typedef struct pjmedia_video_format_info
+{
+    /**
+     * The unique format ID of the media. Well known format ids are declared
+     * in pjmedia_format_id enumeration.
+     */
+    pj_uint32_t		id;
+
+    /**
+     * Null terminated string containing short identification about the
+     * format.
+     */
+    char		name[8];
+
+    /**
+     * Information about the color model of this video format.
+     */
+    pjmedia_color_model	color_model;
+
+    /**
+     * Number of bits needed to store one pixel of this video format.
+     */
+    pj_uint8_t		bpp;
+
+    /**
+     * Number of video planes that this format uses. Value 1 indicates
+     * packed format, while value greater than 1 indicates planar format.
+     */
+    pj_uint8_t		plane_cnt;
+
+    /**
+     * Pointer to function to apply this format against size and buffer
+     * information in pjmedia_video_apply_fmt_param argument. Application
+     * uses this function to obtain various information such as the
+     * memory size of a frame buffer, strides value of the image, the
+     * location of the planes, and so on. See pjmedia_video_apply_fmt_param
+     * for additional information.
+     *
+     * @param vfi	The video format info.
+     * @param vafp	The parameters to investigate.
+     *
+     * @return		PJ_SUCCESS if the function has calculated the
+     * 			information in \a vafp successfully.
+     */
+    pj_status_t (*apply_fmt)(const struct pjmedia_video_format_info *vfi,
+	                     pjmedia_video_apply_fmt_param *vafp);
+
+} pjmedia_video_format_info;
+
+
+/*****************************************************************************
+ * UTILITIES:
+ */
+
+/**
+ * General utility routine to calculate samples per frame value from clock
+ * rate, ptime (in usec), and channel count. Application should use this
+ * macro whenever possible due to possible overflow in the math calculation.
+ *
+ * @param clock_rate		Clock rate.
+ * @param usec_ptime		Frame interval, in microsecond.
+ * @param channel_count		Number of channels.
+ *
+ * @return			The samples per frame value.
+ */
+PJ_INLINE(unsigned) PJMEDIA_SPF(unsigned clock_rate, unsigned usec_ptime,
+				unsigned channel_count)
+{
+#if PJ_HAS_INT64
+    return ((unsigned)((pj_uint64_t)usec_ptime * \
+		       clock_rate / channel_count / 1000000));
+#elif PJ_HAS_FLOATING_POINT
+    return ((unsigned)(usec_ptime * clock_rate / channel_count / 1000000.0));
+#else
+    return ((unsigned)(usec_ptime / 1000L * clock_rate / \
+		       channel_count / 1000));
+#endif
+}
+
+/**
+ * Utility routine to calculate frame size (in bytes) from bitrate and frame
+ * interval values. Application should use this macro whenever possible due
+ * to possible overflow in the math calculation.
+ *
+ * @param bps			The bitrate of the stream.
+ * @param usec_ptime		Frame interval, in microsecond.
+ *
+ * @return			Frame size in bytes.
+ */
+PJ_INLINE(unsigned) PJMEDIA_FSZ(unsigned bps, unsigned usec_ptime)
+{
+#if PJ_HAS_INT64
+    return ((unsigned)(bps * usec_ptime / PJ_UINT64(8000000)));
+#elif PJ_HAS_FLOATING_POINT
+    return ((unsigned)(bps * usec_ptime / 8000000.0));
+#else
+    return ((unsigned)(bps / 8L * usec_ptime / 1000000));
+#endif
+}
+
+
+/**
+ * Utility to retrieve samples_per_frame value from
+ * pjmedia_audio_format_detail.
+ *
+ * @param pafd		Pointer to pjmedia_audio_format_detail
+ * @return		Samples per frame
+ */
+PJ_INLINE(unsigned) PJMEDIA_AFD_SPF(const pjmedia_audio_format_detail *pafd)
+{
+    return PJMEDIA_SPF(pafd->clock_rate, pafd->frame_time_usec,
+		       pafd->channel_count);
+}
+
+/**
+ * Utility to retrieve average frame size from pjmedia_audio_format_detail.
+ * The average frame size is derived from the average bitrate of the audio
+ * stream.
+ *
+ * @param afd		Pointer to pjmedia_audio_format_detail
+ * @return		Average frame size.
+ */
+PJ_INLINE(unsigned) PJMEDIA_AFD_AVG_FSZ(const pjmedia_audio_format_detail *afd)
+{
+    return PJMEDIA_FSZ(afd->avg_bps, afd->frame_time_usec);
+}
+
+/**
+ * Utility to retrieve maximum frame size from pjmedia_audio_format_detail.
+ * The maximum frame size is derived from the maximum bitrate of the audio
+ * stream.
+ *
+ * @param afd		Pointer to pjmedia_audio_format_detail
+ * @return		Average frame size.
+ */
+PJ_INLINE(unsigned) PJMEDIA_AFD_MAX_FSZ(const pjmedia_audio_format_detail *afd)
+{
+    return PJMEDIA_FSZ(afd->max_bps, afd->frame_time_usec);
+}
+
+
+/**
+ * Initialize the format as audio format with the specified parameters.
+ *
+ * @param fmt			The format to be initialized.
+ * @param fmt_id		Format ID. See #pjmedia_format_id
+ * @param clock_rate		Audio clock rate.
+ * @param channel_count		Number of channels.
+ * @param bits_per_sample	Number of bits per sample.
+ * @param frame_time_usec	Frame interval, in microsecond.
+ * @param avg_bps		Average bitrate.
+ * @param max_bps		Maximum bitrate.
+ */
+PJ_DECL(void) pjmedia_format_init_audio(pjmedia_format *fmt,
+				        pj_uint32_t fmt_id,
+					unsigned clock_rate,
+					unsigned channel_count,
+					unsigned bits_per_sample,
+					unsigned frame_time_usec,
+					pj_uint32_t avg_bps,
+					pj_uint32_t max_bps);
+
+/**
+ * Initialize the format as video format with the specified parameters.
+ * A format manager should have been created, as this function will need
+ * to consult to a format manager in order to fill in detailed
+ * information about the format.
+ *
+ * @param fmt		The format to be initialised.
+ * @param fmt_id	Format ID. See #pjmedia_format_id
+ * @param width		Image width.
+ * @param height	Image heigth.
+ * @param fps_num	FPS numerator.
+ * @param fps_denum	FPS denumerator.
+ * @param avg_bps	Average bitrate.
+ * @param max_bps	Maximum bitrate.
+ */
+PJ_DECL(void) pjmedia_format_init_video(pjmedia_format *fmt,
+					pj_uint32_t fmt_id,
+					unsigned width,
+					unsigned height,
+					unsigned fps_num,
+					unsigned fps_denum);
+
+/**
+ * Copy format to another.
+ *
+ * @param dst		The destination format.
+ * @param src		The source format.
+ *
+ * @return		Pointer to destination format.
+ */
+PJ_DECL(pjmedia_format*) pjmedia_format_copy(pjmedia_format *dst,
+					     const pjmedia_format *src);
+
+/**
+ * Check if the format contains audio format, and retrieve the audio format
+ * detail in the format.
+ *
+ * @param fmt		The format structure.
+ * @param assert_valid	If this is set to non-zero, an assertion will be
+ * 			raised if the detail type is not audio or if the
+ * 			the detail is NULL.
+ *
+ * @return		The instance of audio format detail in the format
+ * 			structure, or NULL if the format doesn't contain
+ * 			audio detail.
+ */
+PJ_DECL(pjmedia_audio_format_detail*)
+pjmedia_format_get_audio_format_detail(const pjmedia_format *fmt,
+				       pj_bool_t assert_valid);
+
+/**
+ * Check if the format contains video format, and retrieve the video format
+ * detail in the format.
+ *
+ * @param fmt		The format structure.
+ * @param assert_valid	If this is set to non-zero, an assertion will be
+ * 			raised if the detail type is not video or if the
+ * 			the detail is NULL.
+ *
+ * @return		The instance of video format detail in the format
+ * 			structure, or NULL if the format doesn't contain
+ * 			video detail.
+ */
+PJ_DECL(pjmedia_video_format_detail*)
+pjmedia_format_get_video_format_detail(const pjmedia_format *fmt,
+				       pj_bool_t assert_valid);
+
+/*****************************************************************************
+ * FORMAT MANAGEMENT:
+ */
+
+/**
+ * Opaque data type for video format manager. The video format manager manages
+ * the repository of video formats that the framework recognises. Typically it
+ * is a singleton instance, although application may instantiate more than one
+ * instances of this if required.
+ */
+typedef struct pjmedia_video_format_mgr pjmedia_video_format_mgr;
+
+
+/**
+ * Create a new video format manager instance. This will also set the pointer
+ * to the singleton instance if the value is still NULL.
+ *
+ * @param pool		The pool to allocate memory.
+ * @param max_fmt	Maximum number of formats to accommodate.
+ * @param options	Option flags. Must be zero for now.
+ * @param p_mgr		Pointer to hold the created instance.
+ *
+ * @return		PJ_SUCCESS on success, or the appripriate error value.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_video_format_mgr_create(pj_pool_t *pool,
+				unsigned max_fmt,
+				unsigned options,
+				pjmedia_video_format_mgr **p_mgr);
+
+/**
+ * Get the singleton instance of the video format manager.
+ *
+ * @return		The instance.
+ */
+PJ_DECL(pjmedia_video_format_mgr*) pjmedia_video_format_mgr_instance(void);
+
+/**
+ * Manually assign a specific video manager instance as the singleton
+ * instance. Normally this is not needed if only one instance is ever
+ * going to be created, as the library automatically assign the singleton
+ * instance.
+ *
+ * @param mgr		The instance to be used as the singleton instance.
+ * 			Application may specify NULL to clear the singleton
+ * 			singleton instance.
+ */
+PJ_DECL(void)
+pjmedia_video_format_mgr_set_instance(pjmedia_video_format_mgr *mgr);
+
+/**
+ * Retrieve a video format info for the specified format id.
+ *
+ * @param mgr		The video format manager. Specify NULL to use
+ * 			the singleton instance (however, a video format
+ * 			manager still must have been created prior to
+ * 			calling this function).
+ * @param id		The format id which format info is to be
+ * 			retrieved.
+ *
+ * @return		The video format info.
+ */
+PJ_DECL(const pjmedia_video_format_info*)
+pjmedia_get_video_format_info(pjmedia_video_format_mgr *mgr,
+			      pj_uint32_t id);
+
+/**
+ * Register a new video format to the framework. By default, built-in
+ * formats will be registered automatically to the format manager when
+ * it is created (note: built-in formats are ones which format id is
+ * listed in pjmedia_format_id enumeration). This function allows
+ * application to use user defined format id by registering that format
+ * into the framework.
+ *
+ * @param mgr		The video format manager. Specify NULL to use
+ * 			the singleton instance (however, a video format
+ * 			manager still must have been created prior to
+ * 			calling this function).
+ * @param vfi		The video format info to be registered. This
+ * 			structure must remain valid until the format
+ * 			manager is destroyed.
+ *
+ * @return		PJ_SUCCESS on success, or the appripriate error value.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_register_video_format_info(pjmedia_video_format_mgr *mgr,
+				   pjmedia_video_format_info *vfi);
+
+/**
+ * Destroy a video format manager. If the manager happens to be the singleton
+ * instance, the singleton instance will be set to NULL.
+ *
+ * @param mgr		The video format manager. Specify NULL to use
+ * 			the singleton instance (however, a video format
+ * 			manager still must have been created prior to
+ * 			calling this function).
+ */
+PJ_DECL(void) pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr *mgr);
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+#endif	/* __PJMEDIA_FORMAT_H__ */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/frame.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/frame.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/frame.h	(revision 3392)
@@ -0,0 +1,316 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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_FRAME_H__
+#define __PJMEDIA_FRAME_H__
+
+/**
+ * @file pjmedia/frame.h Media frame
+ * @brief Frame
+ */
+#include <pjmedia/types.h>
+#include <pj/string.h>
+
+/**
+ * @defgroup PJMEDIA_FRAME Media frame
+ * @ingroup PJMEDIA_TYPES
+ * @brief Frame
+ * @{
+ */
+
+PJ_BEGIN_DECL
+
+
+/**
+ * Types of media frame.
+ */
+typedef enum pjmedia_frame_type
+{
+    PJMEDIA_FRAME_TYPE_NONE,	    /**< No frame.		*/
+    PJMEDIA_FRAME_TYPE_AUDIO,	    /**< Normal audio frame.	*/
+    PJMEDIA_FRAME_TYPE_EXTENDED,    /**< Extended audio frame.	*/
+    PJMEDIA_FRAME_TYPE_VIDEO        /**< Video frame.           */
+
+} pjmedia_frame_type;
+
+
+/**
+ * This structure describes a media frame.
+ */
+typedef struct pjmedia_frame
+{
+    pjmedia_frame_type	 type;	    /**< Frame type.			    */
+    void		*buf;	    /**< Pointer to buffer.		    */
+    pj_size_t		 size;	    /**< Frame size in bytes.		    */
+    pj_timestamp	 timestamp; /**< Frame timestamp.		    */
+    pj_uint32_t		 bit_info;  /**< Bit info of the frame, sample case:
+					 a frame may not exactly start and end
+					 at the octet boundary, so this field
+					 may be used for specifying start &
+					 end bit offset.		    */
+} pjmedia_frame;
+
+
+/**
+ * The pjmedia_frame_ext is used to carry a more complex audio frames than
+ * the typical PCM audio frames, and it is signaled by setting the "type"
+ * field of a pjmedia_frame to PJMEDIA_FRAME_TYPE_EXTENDED. With this set,
+ * application may typecast pjmedia_frame to pjmedia_frame_ext.
+ *
+ * This structure may contain more than one audio frames, which subsequently
+ * will be called subframes in this structure. The subframes section
+ * immediately follows the end of this structure, and each subframe is
+ * represented by pjmedia_frame_ext_subframe structure. Every next
+ * subframe immediately follows the previous subframe, and all subframes
+ * are byte-aligned although its payload may not be byte-aligned.
+ */
+
+#pragma pack(1)
+typedef struct pjmedia_frame_ext {
+    pjmedia_frame   base;	    /**< Base frame info */
+    pj_uint16_t     samples_cnt;    /**< Number of samples in this frame */
+    pj_uint16_t     subframe_cnt;   /**< Number of (sub)frames in this frame */
+
+    /* Zero or more (sub)frames follows immediately after this,
+     * each will be represented by pjmedia_frame_ext_subframe
+     */
+} pjmedia_frame_ext;
+#pragma pack()
+
+/**
+ * This structure represents the individual subframes in the
+ * pjmedia_frame_ext structure.
+ */
+#pragma pack(1)
+typedef struct pjmedia_frame_ext_subframe {
+    pj_uint16_t     bitlen;	    /**< Number of bits in the data */
+    pj_uint8_t      data[1];	    /**< Start of encoded data */
+} pjmedia_frame_ext_subframe;
+
+#pragma pack()
+
+
+/**
+ * Append one subframe to #pjmedia_frame_ext.
+ *
+ * @param frm		    The #pjmedia_frame_ext.
+ * @param src		    Subframe data.
+ * @param bitlen	    Lenght of subframe, in bits.
+ * @param samples_cnt	    Number of audio samples in subframe.
+ */
+PJ_INLINE(void) pjmedia_frame_ext_append_subframe(pjmedia_frame_ext *frm,
+						  const void *src,
+					          unsigned bitlen,
+						  unsigned samples_cnt)
+{
+    pjmedia_frame_ext_subframe *fsub;
+    pj_uint8_t *p;
+    unsigned i;
+
+    p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext);
+    for (i = 0; i < frm->subframe_cnt; ++i) {
+	fsub = (pjmedia_frame_ext_subframe*) p;
+	p += sizeof(fsub->bitlen) + ((fsub->bitlen+7) >> 3);
+    }
+
+    fsub = (pjmedia_frame_ext_subframe*) p;
+    fsub->bitlen = (pj_uint16_t)bitlen;
+    if (bitlen)
+	pj_memcpy(fsub->data, src, (bitlen+7) >> 3);
+
+    frm->subframe_cnt++;
+    frm->samples_cnt = (pj_uint16_t)(frm->samples_cnt + samples_cnt);
+}
+
+/**
+ * Get a subframe from #pjmedia_frame_ext.
+ *
+ * @param frm		    The #pjmedia_frame_ext.
+ * @param n		    Subframe index, zero based.
+ *
+ * @return		    The n-th subframe, or NULL if n is out-of-range.
+ */
+PJ_INLINE(pjmedia_frame_ext_subframe*)
+pjmedia_frame_ext_get_subframe(const pjmedia_frame_ext *frm, unsigned n)
+{
+    pjmedia_frame_ext_subframe *sf = NULL;
+
+    if (n < frm->subframe_cnt) {
+	pj_uint8_t *p;
+	unsigned i;
+
+	p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext);
+	for (i = 0; i < n; ++i) {
+	    sf = (pjmedia_frame_ext_subframe*) p;
+	    p += sizeof(sf->bitlen) + ((sf->bitlen+7) >> 3);
+	}
+
+	sf = (pjmedia_frame_ext_subframe*) p;
+    }
+
+    return sf;
+}
+
+/**
+ * Extract all frame payload to the specified buffer.
+ *
+ * @param frm		    The frame.
+ * @param dst		    Destination buffer.
+ * @param maxlen	    Maximum size to copy (i.e. the size of the
+ *			    destination buffer).
+ *
+ * @return		    Total size of payload copied.
+ */
+PJ_INLINE(unsigned)
+pjmedia_frame_ext_copy_payload(const pjmedia_frame_ext *frm,
+			       void *dst,
+			       unsigned maxlen)
+{
+    unsigned i, copied=0;
+    for (i=0; i<frm->subframe_cnt; ++i) {
+	pjmedia_frame_ext_subframe *sf;
+	unsigned sz;
+
+	sf = pjmedia_frame_ext_get_subframe(frm, i);
+	if (!sf)
+	    continue;
+
+	sz = ((sf->bitlen + 7) >> 3);
+	if (sz + copied > maxlen)
+	    break;
+
+	pj_memcpy(((pj_uint8_t*)dst) + copied, sf->data, sz);
+	copied += sz;
+    }
+    return copied;
+}
+
+
+/**
+ * Pop out first n subframes from #pjmedia_frame_ext.
+ *
+ * @param frm		    The #pjmedia_frame_ext.
+ * @param n		    Number of first subframes to be popped out.
+ *
+ * @return		    PJ_SUCCESS when successful.
+ */
+PJ_INLINE(pj_status_t)
+pjmedia_frame_ext_pop_subframes(pjmedia_frame_ext *frm, unsigned n)
+{
+    pjmedia_frame_ext_subframe *sf;
+    pj_uint8_t *move_src;
+    unsigned move_len;
+
+    if (frm->subframe_cnt <= n) {
+	frm->subframe_cnt = 0;
+	frm->samples_cnt = 0;
+	return PJ_SUCCESS;
+    }
+
+    move_src = (pj_uint8_t*)pjmedia_frame_ext_get_subframe(frm, n);
+    sf = pjmedia_frame_ext_get_subframe(frm, frm->subframe_cnt-1);
+    move_len = (pj_uint8_t*)sf - move_src + sizeof(sf->bitlen) +
+	       ((sf->bitlen+7) >> 3);
+    pj_memmove((pj_uint8_t*)frm+sizeof(pjmedia_frame_ext),
+	       move_src, move_len);
+
+    frm->samples_cnt = (pj_uint16_t)
+		   (frm->samples_cnt - n*frm->samples_cnt/frm->subframe_cnt);
+    frm->subframe_cnt = (pj_uint16_t) (frm->subframe_cnt - n);
+
+    return PJ_SUCCESS;
+}
+
+
+/**
+ * This is a general purpose function set PCM samples to zero.
+ * Since this function is needed by many parts of the library,
+ * by putting this functionality in one place, it enables some.
+ * clever people to optimize this function.
+ *
+ * @param samples	The 16bit PCM samples.
+ * @param count		Number of samples.
+ */
+PJ_INLINE(void) pjmedia_zero_samples(pj_int16_t *samples, unsigned count)
+{
+#if 1
+    pj_bzero(samples, (count<<1));
+#elif 0
+    unsigned i;
+    for (i=0; i<count; ++i) samples[i] = 0;
+#else
+    unsigned i;
+    count >>= 1;
+    for (i=0; i<count; ++i) ((pj_int32_t*)samples)[i] = (pj_int32_t)0;
+#endif
+}
+
+
+/**
+ * This is a general purpose function to copy samples from/to buffers with
+ * equal size. Since this function is needed by many parts of the library,
+ * by putting this functionality in one place, it enables some.
+ * clever people to optimize this function.
+ */
+PJ_INLINE(void) pjmedia_copy_samples(pj_int16_t *dst, const pj_int16_t *src,
+				     unsigned count)
+{
+#if 1
+    pj_memcpy(dst, src, (count<<1));
+#elif 0
+    unsigned i;
+    for (i=0; i<count; ++i) dst[i] = src[i];
+#else
+    unsigned i;
+    count >>= 1;
+    for (i=0; i<count; ++i)
+	((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i];
+#endif
+}
+
+
+/**
+ * This is a general purpose function to copy samples from/to buffers with
+ * equal size. Since this function is needed by many parts of the library,
+ * by putting this functionality in one place, it enables some.
+ * clever people to optimize this function.
+ */
+PJ_INLINE(void) pjmedia_move_samples(pj_int16_t *dst, const pj_int16_t *src,
+				     unsigned count)
+{
+#if 1
+    pj_memmove(dst, src, (count<<1));
+#elif 0
+    unsigned i;
+    for (i=0; i<count; ++i) dst[i] = src[i];
+#else
+    unsigned i;
+    count >>= 1;
+    for (i=0; i<count; ++i)
+	((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i];
+#endif
+}
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+#endif /* __PJMEDIA_FRAME_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/port.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/port.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/port.h	(revision 3392)
@@ -1,5 +1,5 @@
 /* $Id$ */
 /* 
- * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  *
@@ -25,5 +25,6 @@
  * @brief Port interface declaration
  */
-#include <pjmedia/types.h>
+#include <pjmedia/format.h>
+#include <pjmedia/frame.h>
 #include <pj/assert.h>
 #include <pj/os.h>
@@ -185,4 +186,11 @@
 
 /**
+ * Create 32bit port signature from ASCII characters.
+ */
+#define PJMEDIA_PORT_SIGNATURE(a,b,c,d)	    \
+	    (a<<24 | b<<16 | c<<8 | d)
+
+
+/**
  * Port operation setting.
  */
@@ -221,17 +229,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);
+}
 
 /**
@@ -255,5 +377,5 @@
      */
     pj_status_t (*put_frame)(struct pjmedia_port *this_port, 
-			     const pjmedia_frame *frame);
+			     pjmedia_frame *frame);
 
     /**
@@ -277,4 +399,5 @@
  *
  * @param info		    The port info to be initialized.
+ * @param pool		    Pool to allocate memory from.
  * @param name		    Port name.
  * @param signature	    Port signature.
@@ -294,4 +417,22 @@
 					     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);
+
 
 /**
@@ -315,5 +456,5 @@
  */
 PJ_DECL(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
-					     const pjmedia_frame *frame );
+					     pjmedia_frame *frame );
 
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/sdp.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/sdp.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/sdp.h	(revision 3392)
@@ -26,5 +26,5 @@
  */
 #include <pjmedia/types.h>
-
+#include <pj/sock.h>
 
 /**
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/stream.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/stream.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/stream.h	(revision 3392)
@@ -33,4 +33,5 @@
 #include <pjmedia/rtcp.h>
 #include <pjmedia/transport.h>
+#include <pjmedia/vid_codec.h>
 #include <pj/sock.h>
 
@@ -134,4 +135,7 @@
 					 is enabled?			    */
 #endif
+
+    pjmedia_vid_codec_info       vid_codec_info;
+    pjmedia_vid_codec_param     *vid_codec_param;
 };
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/transport.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/transport.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/transport.h	(revision 3392)
@@ -29,4 +29,5 @@
 #include <pjmedia/types.h>
 #include <pjmedia/errno.h>
+#include <pj/string.h>
 
 /**
@@ -255,4 +256,33 @@
 
 } pjmedia_tranport_media_option;
+
+
+/**
+ * Media socket info is used to describe the underlying sockets
+ * to be used as media transport.
+ */
+typedef struct pjmedia_sock_info
+{
+    /** The RTP socket handle */
+    pj_sock_t	    rtp_sock;
+
+    /** Address to be advertised as the local address for the RTP
+     *  socket, which does not need to be equal as the bound
+     *  address (for example, this address can be the address resolved
+     *  with STUN).
+     */
+    pj_sockaddr	    rtp_addr_name;
+
+    /** The RTCP socket handle. */
+    pj_sock_t	    rtcp_sock;
+
+    /** Address to be advertised as the local address for the RTCP
+     *  socket, which does not need to be equal as the bound
+     *  address (for example, this address can be the address resolved
+     *  with STUN).
+     */
+    pj_sockaddr	    rtcp_addr_name;
+
+} pjmedia_sock_info;
 
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/types.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/types.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/types.h	(revision 3392)
@@ -1,5 +1,5 @@
 /* $Id$ */
 /* 
- * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  *
@@ -27,6 +27,7 @@
 
 #include <pjmedia/config.h>
-#include <pj/sock.h>	    /* pjmedia_sock_info	*/
-#include <pj/string.h>	    /* pj_memcpy(), pj_memset() */
+#include <pj/sock.h>
+#include <pj/types.h>
+
 
 /**
@@ -53,20 +54,18 @@
 typedef enum pjmedia_type
 {
-    /** No type. */
-    PJMEDIA_TYPE_NONE = 0,
+    /** Type is not specified. */
+    PJMEDIA_TYPE_NONE,
 
     /** The media is audio */
-    PJMEDIA_TYPE_AUDIO = 1,
+    PJMEDIA_TYPE_AUDIO,
 
     /** The media is video. */
-    PJMEDIA_TYPE_VIDEO = 2,
-
-    /** Unknown media type, in this case the name will be specified in
-     *  encoding_name.
-     */
-    PJMEDIA_TYPE_UNKNOWN = 3,
+    PJMEDIA_TYPE_VIDEO,
 
     /** The media is application. */
-    PJMEDIA_TYPE_APPLICATION = 4
+    PJMEDIA_TYPE_APPLICATION,
+
+    /** The media type is unknown or unsupported. */
+    PJMEDIA_TYPE_UNKNOWN
 
 } pjmedia_type;
@@ -101,47 +100,35 @@
     PJMEDIA_DIR_NONE = 0,
 
-    /** Encoding (outgoing to network) stream */
+    /** Encoding (outgoing to network) stream, also known as capture */
     PJMEDIA_DIR_ENCODING = 1,
 
-    /** Decoding (incoming from network) stream. */
+    /** Same as encoding direction. */
+    PJMEDIA_DIR_CAPTURE = PJMEDIA_DIR_ENCODING,
+
+    /** Decoding (incoming from network) stream, also known as playback. */
     PJMEDIA_DIR_DECODING = 2,
 
-    /** Incoming and outgoing stream. */
-    PJMEDIA_DIR_ENCODING_DECODING = 3
+    /** Same as decoding. */
+    PJMEDIA_DIR_PLAYBACK = PJMEDIA_DIR_DECODING,
+
+    /** Same as decoding. */
+    PJMEDIA_DIR_RENDER = PJMEDIA_DIR_DECODING,
+
+    /** Incoming and outgoing stream, same as PJMEDIA_DIR_CAPTURE_PLAYBACK */
+    PJMEDIA_DIR_ENCODING_DECODING = 3,
+
+    /** Same as ENCODING_DECODING */
+    PJMEDIA_DIR_CAPTURE_PLAYBACK = PJMEDIA_DIR_ENCODING_DECODING,
+
+    /** Same as ENCODING_DECODING */
+    PJMEDIA_DIR_CAPTURE_RENDER = PJMEDIA_DIR_ENCODING_DECODING
 
 } pjmedia_dir;
 
 
-
-/* Alternate names for media direction: */
-
-/**
- * Direction is capturing audio frames.
- */
-#define PJMEDIA_DIR_CAPTURE	PJMEDIA_DIR_ENCODING
-
-/**
- * Direction is playback of audio frames.
- */
-#define PJMEDIA_DIR_PLAYBACK	PJMEDIA_DIR_DECODING
-
-/**
- * Direction is both capture and playback.
- */
-#define PJMEDIA_DIR_CAPTURE_PLAYBACK	PJMEDIA_DIR_ENCODING_DECODING
-
-
-/**
- * Create 32bit port signature from ASCII characters.
- */
-#define PJMEDIA_PORT_SIGNATURE(a,b,c,d)	    \
-	    (a<<24 | b<<16 | c<<8 | d)
-
-
 /**
  * Opaque declaration of media endpoint.
  */
 typedef struct pjmedia_endpt pjmedia_endpt;
-
 
 /*
@@ -150,377 +137,59 @@
 typedef struct pjmedia_stream pjmedia_stream;
 
-
-/**
- * Media socket info is used to describe the underlying sockets
- * to be used as media transport.
- */
-typedef struct pjmedia_sock_info
-{
-    /** The RTP socket handle */
-    pj_sock_t	    rtp_sock;
-
-    /** Address to be advertised as the local address for the RTP
-     *  socket, which does not need to be equal as the bound
-     *  address (for example, this address can be the address resolved
-     *  with STUN).
+/**
+ * Enumeration for picture coordinate base.
+ */
+typedef enum pjmedia_coord_base
+{
+    /**
+     * This specifies that the pixel [0, 0] location is at the left-top
+     * position.
      */
-    pj_sockaddr	    rtp_addr_name;
-
-    /** The RTCP socket handle. */
-    pj_sock_t	    rtcp_sock;
-
-    /** Address to be advertised as the local address for the RTCP
-     *  socket, which does not need to be equal as the bound
-     *  address (for example, this address can be the address resolved
-     *  with STUN).
+    PJMEDIA_COORD_BASE_LEFT_TOP,
+
+    /**
+     * This specifies that the pixel [0, 0] location is at the left-bottom
+     * position.
      */
-    pj_sockaddr	    rtcp_addr_name;
-
-} pjmedia_sock_info;
-
-
-/**
- * Macro for packing format.
- */
-#define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 )
-
-/**
- * This enumeration describes format ID. 
- */
-typedef enum pjmedia_format_id
-{
-    /**
-     * 16bit linear
-     */
-    PJMEDIA_FORMAT_L16	    = 0,
-    
-    /**
-     * Alias for PJMEDIA_FORMAT_L16
-     */
-    PJMEDIA_FORMAT_PCM	    = PJMEDIA_FORMAT_L16,
-
-    /**
-     * G.711 ALAW
-     */
-    PJMEDIA_FORMAT_PCMA	    = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'),
-
-    /**
-     * Alias for PJMEDIA_FORMAT_PCMA
-     */
-    PJMEDIA_FORMAT_ALAW	    = PJMEDIA_FORMAT_PCMA,
-
-    /**
-     * G.711 ULAW
-     */
-    PJMEDIA_FORMAT_PCMU	    = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'),
-
-    /**
-     * Aliaw for PJMEDIA_FORMAT_PCMU
-     */
-    PJMEDIA_FORMAT_ULAW	    = PJMEDIA_FORMAT_PCMU,
-
-    /**
-     * AMR narrowband
-     */
-    PJMEDIA_FORMAT_AMR	    = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'),
-
-    /**
-     * ITU G.729
-     */
-    PJMEDIA_FORMAT_G729	    = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'),
-
-    /**
-     * Internet Low Bit-Rate Codec (ILBC)
-     */
-    PJMEDIA_FORMAT_ILBC	    = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
-
-} pjmedia_format_id;
-
-
-/**
- * Media format information.
- */
-typedef struct pjmedia_format
-{
-    /** Format ID */
-    pjmedia_format_id	id;
-
-    /** Bitrate. */
-    pj_uint32_t		bitrate;
-
-    /** Flag to indicate whether VAD is enabled */
-    pj_bool_t		vad;
-
-} pjmedia_format;
-
-
-
-/**
- * This is a general purpose function set PCM samples to zero.
- * Since this function is needed by many parts of the library,
- * by putting this functionality in one place, it enables some.
- * clever people to optimize this function.
- *
- * @param samples	The 16bit PCM samples.
- * @param count		Number of samples.
- */
-PJ_INLINE(void) pjmedia_zero_samples(pj_int16_t *samples, unsigned count)
-{
-#if 1
-    pj_bzero(samples, (count<<1));
-#elif 0
-    unsigned i;
-    for (i=0; i<count; ++i) samples[i] = 0;
-#else
-    unsigned i;
-    count >>= 1;
-    for (i=0; i<count; ++i) ((pj_int32_t*)samples)[i] = (pj_int32_t)0;
-#endif
-}
-
-
-/**
- * This is a general purpose function to copy samples from/to buffers with
- * equal size. Since this function is needed by many parts of the library,
- * by putting this functionality in one place, it enables some.
- * clever people to optimize this function.
- */
-PJ_INLINE(void) pjmedia_copy_samples(pj_int16_t *dst, const pj_int16_t *src,
-				     unsigned count)
-{
-#if 1
-    pj_memcpy(dst, src, (count<<1));
-#elif 0
-    unsigned i;
-    for (i=0; i<count; ++i) dst[i] = src[i];
-#else
-    unsigned i;
-    count >>= 1;
-    for (i=0; i<count; ++i)
-	((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i];
-#endif
-}
-
-
-/**
- * This is a general purpose function to copy samples from/to buffers with
- * equal size. Since this function is needed by many parts of the library,
- * by putting this functionality in one place, it enables some.
- * clever people to optimize this function.
- */
-PJ_INLINE(void) pjmedia_move_samples(pj_int16_t *dst, const pj_int16_t *src,
-				     unsigned count)
-{
-#if 1
-    pj_memmove(dst, src, (count<<1));
-#elif 0
-    unsigned i;
-    for (i=0; i<count; ++i) dst[i] = src[i];
-#else
-    unsigned i;
-    count >>= 1;
-    for (i=0; i<count; ++i)
-	((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i];
-#endif
-}
-
-/** 
- * Types of media frame. 
- */
-typedef enum pjmedia_frame_type
-{
-    PJMEDIA_FRAME_TYPE_NONE,	    /**< No frame.		*/
-    PJMEDIA_FRAME_TYPE_AUDIO,	    /**< Normal audio frame.	*/
-    PJMEDIA_FRAME_TYPE_EXTENDED	    /**< Extended audio frame.	*/
-
-} pjmedia_frame_type;
-
-
-/** 
- * This structure describes a media frame. 
- */
-typedef struct pjmedia_frame
-{
-    pjmedia_frame_type	 type;	    /**< Frame type.			    */
-    void		*buf;	    /**< Pointer to buffer.		    */
-    pj_size_t		 size;	    /**< Frame size in bytes.		    */
-    pj_timestamp	 timestamp; /**< Frame timestamp.		    */
-    pj_uint32_t		 bit_info;  /**< Bit info of the frame, sample case:
-					 a frame may not exactly start and end
-					 at the octet boundary, so this field 
-					 may be used for specifying start & 
-					 end bit offset.		    */
-} pjmedia_frame;
-
-
-/**
- * The pjmedia_frame_ext is used to carry a more complex audio frames than
- * the typical PCM audio frames, and it is signaled by setting the "type"
- * field of a pjmedia_frame to PJMEDIA_FRAME_TYPE_EXTENDED. With this set,
- * application may typecast pjmedia_frame to pjmedia_frame_ext.
- *
- * This structure may contain more than one audio frames, which subsequently
- * will be called subframes in this structure. The subframes section
- * immediately follows the end of this structure, and each subframe is
- * represented by pjmedia_frame_ext_subframe structure. Every next
- * subframe immediately follows the previous subframe, and all subframes
- * are byte-aligned although its payload may not be byte-aligned.
- */
-
-#pragma pack(1)
-typedef struct pjmedia_frame_ext {
-    pjmedia_frame   base;	    /**< Base frame info */
-    pj_uint16_t     samples_cnt;    /**< Number of samples in this frame */
-    pj_uint16_t     subframe_cnt;   /**< Number of (sub)frames in this frame */
-
-    /* Zero or more (sub)frames follows immediately after this,
-     * each will be represented by pjmedia_frame_ext_subframe
-     */
-} pjmedia_frame_ext;
-#pragma pack()
-
-/**
- * This structure represents the individual subframes in the
- * pjmedia_frame_ext structure.
- */
-#pragma pack(1)
-typedef struct pjmedia_frame_ext_subframe {
-    pj_uint16_t     bitlen;	    /**< Number of bits in the data */
-    pj_uint8_t      data[1];	    /**< Start of encoded data */
-} pjmedia_frame_ext_subframe;
-
-#pragma pack()
-
-
-/**
- * Append one subframe to #pjmedia_frame_ext.
- *
- * @param frm		    The #pjmedia_frame_ext.
- * @param src		    Subframe data.
- * @param bitlen	    Lenght of subframe, in bits.
- * @param samples_cnt	    Number of audio samples in subframe.
- */
-PJ_INLINE(void) pjmedia_frame_ext_append_subframe(pjmedia_frame_ext *frm,
-						  const void *src,
-					          unsigned bitlen,
-						  unsigned samples_cnt)
-{
-    pjmedia_frame_ext_subframe *fsub;
-    pj_uint8_t *p;
-    unsigned i;
-
-    p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext);
-    for (i = 0; i < frm->subframe_cnt; ++i) {
-	fsub = (pjmedia_frame_ext_subframe*) p;
-	p += sizeof(fsub->bitlen) + ((fsub->bitlen+7) >> 3);
-    }
-
-    fsub = (pjmedia_frame_ext_subframe*) p;
-    fsub->bitlen = (pj_uint16_t)bitlen;
-    if (bitlen)
-	pj_memcpy(fsub->data, src, (bitlen+7) >> 3);
-
-    frm->subframe_cnt++;
-    frm->samples_cnt = (pj_uint16_t)(frm->samples_cnt + samples_cnt);
-}
-
-/**
- * Get a subframe from #pjmedia_frame_ext.
- *
- * @param frm		    The #pjmedia_frame_ext.
- * @param n		    Subframe index, zero based.
- *
- * @return		    The n-th subframe, or NULL if n is out-of-range.
- */
-PJ_INLINE(pjmedia_frame_ext_subframe*) 
-pjmedia_frame_ext_get_subframe(const pjmedia_frame_ext *frm, unsigned n)
-{
-    pjmedia_frame_ext_subframe *sf = NULL;
-
-    if (n < frm->subframe_cnt) {
-	pj_uint8_t *p;
-	unsigned i;
-
-	p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext);
-	for (i = 0; i < n; ++i) {	
-	    sf = (pjmedia_frame_ext_subframe*) p;
-	    p += sizeof(sf->bitlen) + ((sf->bitlen+7) >> 3);
-	}
-        
-	sf = (pjmedia_frame_ext_subframe*) p;
-    }
-
-    return sf;
-}
-	
-/**
- * Extract all frame payload to the specified buffer. 
- *
- * @param frm		    The frame.
- * @param dst		    Destination buffer.
- * @param maxlen	    Maximum size to copy (i.e. the size of the
- *			    destination buffer).
- *
- * @return		    Total size of payload copied.
- */
-PJ_INLINE(unsigned) 
-pjmedia_frame_ext_copy_payload(const pjmedia_frame_ext *frm,
-			       void *dst, 
-			       unsigned maxlen)
-{
-    unsigned i, copied=0;
-    for (i=0; i<frm->subframe_cnt; ++i) {
-	pjmedia_frame_ext_subframe *sf;
-	unsigned sz;
-
-	sf = pjmedia_frame_ext_get_subframe(frm, i);
-	if (!sf)
-	    continue;
-
-	sz = ((sf->bitlen + 7) >> 3);
-	if (sz + copied > maxlen)
-	    break;
-
-	pj_memcpy(((pj_uint8_t*)dst) + copied, sf->data, sz);
-	copied += sz;
-    }
-    return copied;
-}
-
-
-/**
- * Pop out first n subframes from #pjmedia_frame_ext.
- *
- * @param frm		    The #pjmedia_frame_ext.
- * @param n		    Number of first subframes to be popped out.
- *
- * @return		    PJ_SUCCESS when successful.
- */
-PJ_INLINE(pj_status_t) 
-pjmedia_frame_ext_pop_subframes(pjmedia_frame_ext *frm, unsigned n)
-{
-    pjmedia_frame_ext_subframe *sf;
-    pj_uint8_t *move_src;
-    unsigned move_len;
-
-    if (frm->subframe_cnt <= n) {
-	frm->subframe_cnt = 0;
-	frm->samples_cnt = 0;
-	return PJ_SUCCESS;
-    }
-
-    move_src = (pj_uint8_t*)pjmedia_frame_ext_get_subframe(frm, n);
-    sf = pjmedia_frame_ext_get_subframe(frm, frm->subframe_cnt-1);
-    move_len = (pj_uint8_t*)sf - move_src + sizeof(sf->bitlen) + 
-	       ((sf->bitlen+7) >> 3);
-    pj_memmove((pj_uint8_t*)frm+sizeof(pjmedia_frame_ext), 
-	       move_src, move_len);
-	    
-    frm->samples_cnt = (pj_uint16_t)
-		   (frm->samples_cnt - n*frm->samples_cnt/frm->subframe_cnt);
-    frm->subframe_cnt = (pj_uint16_t) (frm->subframe_cnt - n);
-
-    return PJ_SUCCESS;
-}
+    PJMEDIA_COORD_BASE_LEFT_BOTTOM
+
+} pjmedia_coord_base;
+
+/**
+ * This structure is used to represent rational numbers.
+ */
+typedef struct pjmedia_ratio
+{
+    int		num;    /** < Numerator. */
+    int		denum;  /** < Denumerator. */
+} pjmedia_ratio;
+
+/**
+ * This structure represent a coordinate.
+ */
+typedef struct pjmedia_coord
+{
+    int		x;	/**< X position of the coordinate */
+    int		y;	/**< Y position of the coordinate */
+} pjmedia_coord;
+
+/**
+ * This structure represents rectangle size.
+ */
+typedef struct pjmedia_rect_size
+{
+    unsigned	w;	/**< The width.		*/
+    unsigned 	h;	/**< The height.	*/
+} pjmedia_rect_size;
+
+/**
+ * This structure describes a rectangle.
+ */
+typedef struct pjmedia_rect
+{
+    pjmedia_coord	coord;	/**< The position.	*/
+    pjmedia_rect_size	size;	/**< The size.		*/
+} pjmedia_rect;
+
 
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_codec.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_codec.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/vid_codec.h	(revision 3392)
@@ -0,0 +1,673 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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_VID_CODEC_H__
+#define __PJMEDIA_VID_CODEC_H__
+
+
+/**
+ * @file codec.h
+ * @brief Codec framework.
+ */
+
+#include <pjmedia/codec.h>
+#include <pjmedia/format.h>
+#include <pjmedia/types.h>
+#include <pj/list.h>
+#include <pj/pool.h>
+
+PJ_BEGIN_DECL
+
+#define PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT    8
+#define PJMEDIA_VID_CODEC_MAX_FPS_CNT        16
+
+/** 
+ * Identification used to search for codec factory that supports specific 
+ * codec specification. 
+ */
+typedef struct pjmedia_vid_codec_info
+{
+    pjmedia_format_id   fmt_id;         /**< Encoded format ID              */
+    pj_str_t	        encoding_name;  /**< Encoding name                  */
+    pjmedia_dir         dir;            /**< Direction                      */
+    unsigned            pt;             /**< Payload type (may be 0 for
+                                             dynamic payload type)          */
+    unsigned            clock_rate;     /**< (?) Clock rate                 */
+    unsigned            dec_fmt_id_cnt;
+    pjmedia_format_id   dec_fmt_id[PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT];
+                                        /**< Supported encoding source 
+                                             format IDs                     */
+    unsigned            fps_cnt;        /**< zero if support any fps        */
+    pjmedia_ratio       fps[PJMEDIA_VID_CODEC_MAX_FPS_CNT];    
+                                        /**< (?) supported FPSes, 
+                                             ffmpeg has this                */
+} pjmedia_vid_codec_info;
+
+/** 
+ * Detailed codec attributes used in configuring a codec and in querying
+ * the capability of codec factories. Default attributes of any codecs could
+ * be queried using #pjmedia_vid_codec_mgr_get_default_param() and modified
+ * using #pjmedia_vid_codec_mgr_set_default_param().
+ *
+ * Please note that codec parameter also contains SDP specific setting, 
+ * #dec_fmtp and #enc_fmtp, which may need to be set appropriately based on
+ * the effective setting. See each codec documentation for more detail.
+ */
+typedef struct pjmedia_vid_codec_param
+{
+    pjmedia_dir         dir;            /**< Direction                      */
+    pjmedia_format      enc_fmt;        /**< Encoded format	            */
+    pjmedia_format      dec_fmt;        /**< Decoded format	            */
+
+    pjmedia_codec_fmtp  enc_fmtp;       /**< Encoder fmtp params	    */
+    pjmedia_codec_fmtp  dec_fmtp;       /**< Decoder fmtp params	    */
+
+    unsigned            enc_mtu;        /**< MTU or max payload size setting*/
+    unsigned            pt;             /**< Payload type.                  */
+} pjmedia_vid_codec_param;
+
+
+
+/*
+ * Forward declaration for pjmedia_vid_codec.
+ */
+typedef struct pjmedia_vid_codec pjmedia_vid_codec;
+
+
+/**
+ * This structure describes codec operations. Each codec MUST implement
+ * all of these functions.
+ */
+typedef struct pjmedia_vid_codec_op
+{
+    /** 
+     * Initialize codec using the specified attribute.
+     *
+     * @param codec	The codec instance.
+     * @param pool	Pool to use when the codec needs to allocate
+     *			some memory.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t	(*init)(pjmedia_vid_codec *codec, 
+			pj_pool_t *pool );
+
+    /** 
+     * Open the codec and initialize with the specified parameter.
+     * Upon successful initialization, the codec may modify the parameter
+     * and fills in the unspecified values (such as enc_ptime, when
+     * encoder ptime is different than decoder ptime).
+     *
+     * @param codec	The codec instance.
+     * @param param	Codec initialization parameter.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t	(*open)(pjmedia_vid_codec *codec, 
+			pjmedia_vid_codec_param *param );
+
+    /** 
+     * Close and shutdown codec, releasing all resources allocated by
+     * this codec, if any.
+     *
+     * @param codec	The codec instance.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*close)(pjmedia_vid_codec *codec);
+
+    /** 
+     * Modify the codec parameter after the codec is open. 
+     * Note that not all codec parameters can be modified during run-time. 
+     * When the parameter cannot be changed, this function will return 
+     * non-PJ_SUCCESS, and the original parameters will not be changed.
+     *
+     * Application can expect changing trivial codec settings such as
+     * changing VAD setting to succeed.
+     *
+     * @param codec	The codec instance.
+     * @param param	The new codec parameter.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t	(*modify)(pjmedia_vid_codec *codec, 
+			  const pjmedia_vid_codec_param *param );
+
+    /**
+     * Instruct the codec to inspect the specified payload/packet and
+     * 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_vid_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.
+     * @param frames	On output, specifies the frames that have been
+     *			detected in the packet.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*packetize) (pjmedia_vid_codec *codec,
+                              pj_uint8_t *buf,
+                              pj_size_t buf_len,
+                              unsigned *pos,
+                              const pj_uint8_t **payload,
+                              pj_size_t *payload_len);
+
+    /**
+     * Instruct the codec to inspect the specified payload/packet and
+     * 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_vid_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.
+     * @param frames	On output, specifies the frames that have been
+     *			detected in the packet.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*unpacketize)(pjmedia_vid_codec *codec,
+                               const pj_uint8_t *payload,
+                               pj_size_t   payload_len,
+                               pj_uint8_t *buf,
+                               pj_size_t  *buf_len);
+
+    /** 
+     * Instruct the codec to encode the specified input frame. The input
+     * PCM samples MUST have ptime that is multiplication of base frame
+     * ptime (i.e. the value of info.frm_ptime in #pjmedia_vid_codec_param).
+     *
+     * @param codec	The codec instance.
+     * @param input	The input frame.
+     * @param out_size	The length of buffer in the output frame.
+     * @param output	The output frame.
+     *
+     * @return		PJ_SUCCESS on success;
+     */
+    pj_status_t (*encode)(pjmedia_vid_codec *codec, 
+			  const pjmedia_frame *input,
+			  unsigned out_size, 
+			  pjmedia_frame *output);
+
+    /** 
+     * 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_vid_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.
+     * @param out_size	The length of buffer in the output frame.
+     * @param output	The output frame.
+     *
+     * @return		PJ_SUCCESS on success;
+     */
+    pj_status_t (*decode)(pjmedia_vid_codec *codec, 
+			  const pjmedia_frame *input,
+			  unsigned out_size, 
+			  pjmedia_frame *output);
+
+    /**
+     * Instruct the codec to recover a missing frame.
+     *
+     * @param codec	The codec instance.
+     * @param out_size	The length of buffer in the output frame.
+     * @param output	The output frame where generated signal
+     *			will be placed.
+     *
+     * @return		PJ_SUCCESS on success;
+     */
+    pj_status_t (*recover)(pjmedia_vid_codec *codec,
+			   unsigned out_size,
+			   pjmedia_frame *output);
+} pjmedia_vid_codec_op;
+
+
+
+/*
+ * Forward declaration for pjmedia_vid_codec_factory.
+ */
+typedef struct pjmedia_vid_codec_factory pjmedia_vid_codec_factory;
+
+
+/**
+ * This structure describes a codec instance. 
+ */
+struct pjmedia_vid_codec
+{
+    /** Entries to put this codec instance in codec factory's list. */
+    PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec);
+
+    /** Codec's private data. */
+    void		    *codec_data;
+
+    /** Codec factory where this codec was allocated. */
+    pjmedia_vid_codec_factory   *factory;
+
+    /** Operations to codec. */
+    pjmedia_vid_codec_op	    *op;
+};
+
+
+
+/**
+ * This structure describes operations that must be supported by codec 
+ * factories.
+ */
+typedef struct pjmedia_vid_codec_factory_op
+{
+    /** 
+     * Check whether the factory can create codec with the specified 
+     * codec info.
+     *
+     * @param factory	The codec factory.
+     * @param info	The codec info.
+     *
+     * @return		PJ_SUCCESS if this factory is able to create an
+     *			instance of codec with the specified info.
+     */
+    pj_status_t	(*test_alloc)(pjmedia_vid_codec_factory *factory, 
+			      const pjmedia_vid_codec_info *info );
+
+    /** 
+     * Create default attributes for the specified codec ID. This function
+     * can be called by application to get the capability of the codec.
+     *
+     * @param factory	The codec factory.
+     * @param info	The codec info.
+     * @param attr	The attribute to be initialized.
+     *
+     * @return		PJ_SUCCESS if success.
+     */
+    pj_status_t (*default_attr)(pjmedia_vid_codec_factory *factory, 
+    				const pjmedia_vid_codec_info *info,
+    				pjmedia_vid_codec_param *attr );
+
+    /** 
+     * Enumerate supported codecs that can be created using this factory.
+     * 
+     *  @param factory	The codec factory.
+     *  @param count	On input, specifies the number of elements in
+     *			the array. On output, the value will be set to
+     *			the number of elements that have been initialized
+     *			by this function.
+     *  @param info	The codec info array, which contents will be 
+     *			initialized upon return.
+     *
+     *  @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*enum_info)(pjmedia_vid_codec_factory *factory, 
+			     unsigned *count, 
+			     pjmedia_vid_codec_info codecs[]);
+
+    /** 
+     * Create one instance of the codec with the specified codec info.
+     *
+     * @param factory	The codec factory.
+     * @param info	The codec info.
+     * @param p_codec	Pointer to receive the codec instance.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*alloc_codec)(pjmedia_vid_codec_factory *factory, 
+			       const pjmedia_vid_codec_info *info,
+			       pjmedia_vid_codec **p_codec);
+
+    /** 
+     * This function is called by codec manager to return a particular 
+     * instance of codec back to the codec factory.
+     *
+     * @param factory	The codec factory.
+     * @param codec	The codec instance to be returned.
+     *
+     * @return		PJ_SUCCESS on success.
+     */
+    pj_status_t (*dealloc_codec)(pjmedia_vid_codec_factory *factory, 
+				 pjmedia_vid_codec *codec );
+
+} pjmedia_vid_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 pjmedia_vid_codec_factory
+{
+    /** Entries to put this structure in the codec manager list. */
+    PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec_factory);
+
+    /** The factory's private data. */
+    void		     *factory_data;
+
+    /** Operations to the factory. */
+    pjmedia_vid_codec_factory_op *op;
+
+};
+
+
+/**
+ * Declare maximum codecs
+ */
+#define PJMEDIA_VID_CODEC_MGR_MAX_CODECS	    32
+
+
+/** 
+ * Codec manager maintains array of these structs for each supported
+ * codec.
+ */
+typedef struct pjmedia_vid_codec_desc
+{
+    pjmedia_vid_codec_info	     info;	/**< Codec info.	    */
+    pjmedia_codec_id	             id;        /**< Fully qualified name   */
+    pjmedia_codec_priority           prio;      /**< Priority.		    */
+    pjmedia_vid_codec_factory       *factory;	/**< The factory.	    */
+    pjmedia_vid_codec_param         *def_param; /**< Default codecs 
+					             parameters.	    */
+} pjmedia_vid_codec_desc;
+
+
+/**
+ * The declaration for codec manager. Application doesn't normally need
+ * to see this declaration, but nevertheless this declaration is needed
+ * by media endpoint to instantiate the codec manager.
+ */
+typedef struct pjmedia_vid_codec_mgr
+{
+    /** Codec manager mutex. */
+    pj_mutex_t			*mutex;
+
+    /** List of codec factories registered to codec manager. */
+    pjmedia_vid_codec_factory	 factory_list;
+
+    /** Number of supported codecs. */
+    unsigned			 codec_cnt;
+
+    /** Array of codec descriptor. */
+    pjmedia_vid_codec_desc	 codec_desc[PJMEDIA_CODEC_MGR_MAX_CODECS];
+
+} pjmedia_vid_codec_mgr;
+
+
+
+/**
+ * Initialize codec manager. Normally this function is called by pjmedia
+ * endpoint's initialization code.
+ *
+ * @param mgr	    Codec manager instance.
+ * @param pf	    Pool factory instance.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_create(pj_pool_t *pool,
+                                                  pjmedia_vid_codec_mgr **mgr);
+
+
+/**
+ * Destroy codec manager. Normally this function is called by pjmedia
+ * endpoint's deinitialization code.
+ *
+ * @param mgr	    Codec manager instance.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr *mgr);
+
+PJ_DECL(pjmedia_vid_codec_mgr*) pjmedia_vid_codec_mgr_instance(void);
+PJ_DECL(void) pjmedia_vid_codec_mgr_set_instance(pjmedia_vid_codec_mgr* mgr);
+
+
+/** 
+ * Register codec factory to codec manager. This will also register
+ * all supported codecs in the factory to the codec manager.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param factory   The codec factory to be registered.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_register_factory( pjmedia_vid_codec_mgr *mgr,
+				        pjmedia_vid_codec_factory *factory);
+
+/**
+ * Unregister codec factory from the codec manager. This will also
+ * remove all the codecs registered by the codec factory from the
+ * codec manager's list of supported codecs.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param factory   The codec factory to be unregistered.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_unregister_factory( pjmedia_vid_codec_mgr *mgr, 
+				          pjmedia_vid_codec_factory *factory);
+
+/**
+ * Enumerate all supported codecs that have been registered to the
+ * codec manager by codec factories.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param count	    On input, specifies the number of elements in
+ *		    the array. On output, the value will be set to
+ *		    the number of elements that have been initialized
+ *		    by this function.
+ * @param info	    The codec info array, which contents will be 
+ *		    initialized upon return.
+ * @param prio	    Optional pointer to receive array of codec priorities.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_enum_codecs( 
+                                            pjmedia_vid_codec_mgr *mgr, 
+					    unsigned *count, 
+					    pjmedia_vid_codec_info info[],
+					    unsigned *prio);
+
+/**
+ * Get codec info for the specified static payload type.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param pt	    Static payload type/number.
+ * @param inf	    Pointer to receive codec info.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_get_codec_info( pjmedia_vid_codec_mgr *mgr,
+				      unsigned pt,
+				      const pjmedia_vid_codec_info **inf);
+
+/**
+ * Convert codec info struct into a unique codec identifier.
+ * A codec identifier looks something like "L16/44100/2".
+ *
+ * @param info	    The codec info
+ * @param id	    Buffer to put the codec info string.
+ * @param max_len   The length of the buffer.
+ *
+ * @return	    The null terminated codec info string, or NULL if
+ *		    the buffer is not long enough.
+ */
+PJ_DECL(char*) pjmedia_vid_codec_info_to_id(
+                                        const pjmedia_vid_codec_info *info,
+				        char *id, unsigned max_len );
+
+
+/**
+ * Find codecs by the unique codec identifier. This function will find
+ * all codecs that match the codec identifier prefix. For example, if
+ * "L16" is specified, then it will find "L16/8000/1", "L16/16000/1",
+ * and so on, up to the maximum count specified in the argument.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param codec_id  The full codec ID or codec ID prefix. If an empty
+ *		    string is given, it will match all codecs.
+ * @param count	    Maximum number of codecs to find. On return, it
+ *		    contains the actual number of codecs found.
+ * @param p_info    Array of pointer to codec info to be filled. This
+ *		    argument may be NULL, which in this case, only
+ *		    codec count will be returned.
+ * @param prio	    Optional array of codec priorities.
+ *
+ * @return	    PJ_SUCCESS if at least one codec info is found.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_find_codecs_by_id( pjmedia_vid_codec_mgr *mgr,
+				     const pj_str_t *codec_id,
+				     unsigned *count,
+				     const pjmedia_vid_codec_info *p_info[],
+				     unsigned prio[]);
+
+
+/**
+ * Set codec priority. The codec priority determines the order of
+ * the codec in the SDP created by the endpoint. If more than one codecs
+ * are found with the same codec_id prefix, then the function sets the
+ * priorities of all those codecs.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param codec_id  The full codec ID or codec ID prefix. If an empty
+ *		    string is given, it will match all codecs.
+ * @param prio	    Priority to be set. The priority can have any value
+ *		    between 1 to 255. When the priority is set to zero,
+ *		    the codec will be disabled.
+ *
+ * @return	    PJ_SUCCESS if at least one codec info is found.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_vid_codec_mgr_set_codec_priority(pjmedia_vid_codec_mgr *mgr, 
+				     const pj_str_t *codec_id,
+				     pj_uint8_t prio);
+
+
+/**
+ * Get default codec param for the specified codec info.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param info	    The codec info, which default parameter's is being
+ *		    queried.
+ * @param param	    On return, will be filled with the default codec
+ *		    parameter.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_get_default_param( pjmedia_vid_codec_mgr *mgr,
+				     const pjmedia_vid_codec_info *info,
+				     pjmedia_vid_codec_param *param );
+
+
+/**
+ * Set default codec param for the specified codec info.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param info	    The codec info, which default parameter's is being
+ *		    updated.
+ * @param param	    The new default codec parameter. Set to NULL to reset
+ *		    codec parameter to library default settings.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_set_default_param(pjmedia_vid_codec_mgr *mgr,
+                                        pj_pool_t *pool,
+				        const pjmedia_vid_codec_info *info,
+				        const pjmedia_vid_codec_param *param);
+
+
+/**
+ * Request the codec manager to allocate one instance of codec with the
+ * specified codec info. The codec will enumerate all codec factories
+ * until it finds factory that is able to create the specified codec.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param info	    The information about the codec to be created.
+ * @param p_codec   Pointer to receive the codec instance.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_vid_codec_mgr_alloc_codec( pjmedia_vid_codec_mgr *mgr, 
+			           const pjmedia_vid_codec_info *info,
+			           pjmedia_vid_codec **p_codec);
+
+/**
+ * Deallocate the specified codec instance. The codec manager will return
+ * the instance of the codec back to its factory.
+ *
+ * @param mgr	    The codec manager instance. Application can get the
+ *		    instance by calling #pjmedia_endpt_get_codec_mgr().
+ * @param codec	    The codec instance.
+ *
+ * @return	    PJ_SUCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_dealloc_codec(
+                                                pjmedia_vid_codec_mgr *mgr, 
+						pjmedia_vid_codec *codec);
+
+
+
+
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup PJMEDIA_CODEC_CODECS Supported codecs
+ * @ingroup PJMEDIA_CODEC
+ * @brief Documentation about individual codec supported by PJMEDIA
+ * @{
+ * Please see the APIs provided by the individual codecs below.
+ */
+/**
+ * @}
+ */
+
+
+
+
+PJ_END_DECL
+
+
+#endif	/* __PJMEDIA_VID_CODEC_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/videoport.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/videoport.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/videoport.h	(revision 3392)
@@ -0,0 +1,206 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_VIDPORT_H__
+#define __PJMEDIA_VIDPORT_H__
+
+/**
+ * @file pjmedia/videoport.h Video media port
+ * @brief Video media port
+ */
+
+#include <pjmedia-videodev/videodev.h>
+#include <pjmedia/port.h>
+
+/**
+ * @defgroup PJMEDIA_VIDEO_PORT Video media port
+ * @ingroup PJMEDIA_PORT_CLOCK
+ * @brief Video media port
+ * @{
+ */
+
+PJ_BEGIN_DECL
+
+/**
+ * This structure describes the parameters to create a video port
+ */
+typedef struct pjmedia_vid_port_param
+{
+    /**
+     * Video stream parameter.
+     */
+    pjmedia_vid_param	vidparam;
+
+    /**
+     * Specify whether the video port should use active or passive interface.
+     * If active interface is selected, the video port will perform as
+     * a media clock, automatically calls pjmedia_port_get_frame() and
+     * pjmedia_port_put_frame() of its slave port (depending on the direction
+     * that is specified when opening the video stream). If passive interface
+     * is selected, application can retrieve the media port of this video
+     * port by calling pjmedia_vid_port_get_passive_port(), and subsequently
+     * calls pjmedia_port_put_frame() or pjmedia_port_get_frame() to that
+     * media port.
+     */
+    pj_bool_t		active;
+
+} pjmedia_vid_port_param;
+
+/**
+ * Opaque data type for video port.
+ */
+typedef struct pjmedia_vid_port pjmedia_vid_port;
+
+/**
+ * Initialize the parameter with the default values. Note that this typically
+ * would only fill the structure to zeroes.
+ *
+ * @param prm	The parameter.
+ */
+PJ_DECL(void) pjmedia_vid_port_param_default(pjmedia_vid_port_param *prm);
+
+/**
+ * Create a video port with the specified parameter.
+ *
+ * @param pool		Pool to allocate memory from.
+ * @param prm		The video port parameter.
+ * @param p_vp		Pointer to receive the result.
+ *
+ * @return		PJ_SUCCESS if video port has been created
+ * 			successfully, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_port_create(pj_pool_t *pool,
+					     const pjmedia_vid_port_param *prm,
+					     pjmedia_vid_port **p_vp);
+
+/**
+ * Set the callbacks of the video port's underlying video stream.
+ *
+ * @param vid_port	The video port.
+ * @param cb            Pointer to structure containing video stream
+ *                      callbacks.
+ * @param user_data     Arbitrary user data, which will be given back in the
+ *                      callbacks.
+ */
+PJ_DECL(void) pjmedia_vid_port_set_cb(pjmedia_vid_port *vid_port,
+				      const pjmedia_vid_cb *cb,
+                                      void *user_data);
+
+/**
+ * Return the underlying video stream of the video port.
+ *
+ * @param vid_port	The video port.
+ *
+ * @return		The video stream.
+ */
+PJ_DECL(pjmedia_vid_stream*)
+pjmedia_vid_port_get_stream(pjmedia_vid_port *vid_port);
+
+/**
+ * Return the (passive) media port of the video port. This operation
+ * is only valid for video ports created with passive interface selected.
+ * Retrieving the media port for active video ports may raise an
+ * assertion.
+ *
+ *  @param vid_port	The video port.
+ *
+ *  @return		The media port instance, or NULL.
+ */
+PJ_DECL(pjmedia_port*)
+pjmedia_vid_port_get_passive_port(pjmedia_vid_port *vid_port);
+
+/**
+ * Connect the video port to a downstream (slave) media port. This operation
+ * is only valid for video ports created with active interface selected.
+ * Connecting a passive video port may raise an assertion.
+ *
+ * @param vid_port	The video port.
+ * @param port		A downstream media port to be connected to
+ * 			this video port.
+ * @param destroy	Specify if the downstream media port should also be
+ * 			destroyed by this video port when the video port
+ * 			is destroyed.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_port_connect(pjmedia_vid_port *vid_port,
+					      pjmedia_port *port,
+					      pj_bool_t destroy);
+
+/**
+ * Connect the video port from its downstream (slave) media port, if any.
+ * This operation is only valid for video ports created with active interface
+ * selected, and assertion may be triggered if this is invoked on a passive
+ * video port.
+ *
+ * @param vid_port	The video port.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_port_disconnect(pjmedia_vid_port *vid_port);
+
+/**
+ * Retrieve the media port currently connected as downstream media port of the
+ * specified video port. This operation is only valid for video ports created
+ * with active interface selected, and assertion may be triggered if this is
+ * invoked on a passive video port.
+ *
+ * @param vid_port	The video port.
+ *
+ * @return		Media port currently connected to the video port,
+ * 			if any.
+ */
+PJ_DECL(pjmedia_port*)
+pjmedia_vid_port_get_connected_port(pjmedia_vid_port *vid_port);
+
+/**
+ * Start the video port.
+ *
+ * @param vid_port	The video port.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_port_start(pjmedia_vid_port *vid_port);
+
+/**
+ * Stop the video port.
+ *
+ * @param vid_port	The video port.
+ *
+ * @return		PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pjmedia_vid_port_stop(pjmedia_vid_port *vid_port);
+
+/**
+ * Destroy the video port, along with its video stream. If the video port is
+ * an active one, this may also destroy the downstream media port, if the
+ * destroy flag is set when the media port is connected.
+ *
+ * @param vid_port	The video port.
+ */
+PJ_DECL(void) pjmedia_vid_port_destroy(pjmedia_vid_port *vid_port);
+
+
+PJ_END_DECL
+
+/**
+ * @}
+ */
+
+#endif /* __PJMEDIA_VIDPORT_H__ */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia_videodev.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia_videodev.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia_videodev.h	(revision 3392)
@@ -0,0 +1,30 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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_VIDEODEV_H__
+#define __PJMEDIA_VIDEODEV_H__
+
+/**
+ * @file pjmedia_videodev.h
+ * @brief PJMEDIA main header file.
+ */
+
+#include <pjmedia-videodev/videodev.h>
+#include <pjmedia-videodev/videodev_imp.h>
+
+#endif	/* __PJMEDIA_VIDEODEV_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/audiodev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/audiodev.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/audiodev.c	(revision 3392)
@@ -191,7 +191,9 @@
 	FIELD_INFO(ec_tail_ms);
 	break;
+    /* vad is no longer in "fmt" in 2.0.
     case PJMEDIA_AUD_DEV_CAP_VAD:
 	FIELD_INFO(ext_fmt.vad);
 	break;
+    */
     case PJMEDIA_AUD_DEV_CAP_CNG:
 	FIELD_INFO(cng_enabled);
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/wmme_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/wmme_dev.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-audiodev/wmme_dev.c	(revision 3392)
@@ -251,10 +251,10 @@
     wdi->info.caps |= PJMEDIA_AUD_DEV_CAP_EXT_FORMAT;
     wdi->info.ext_fmt_cnt = 2;
-    wdi->info.ext_fmt[0].id = PJMEDIA_FORMAT_PCMU;
-    wdi->info.ext_fmt[0].bitrate = 64000;
-    wdi->info.ext_fmt[0].vad = 0;
-    wdi->info.ext_fmt[1].id = PJMEDIA_FORMAT_PCMA;
-    wdi->info.ext_fmt[1].bitrate = 64000;
-    wdi->info.ext_fmt[1].vad = 0;
+    pjmedia_format_init_audio(&wdi->info.ext_fmt[0],
+			      PJMEDIA_FORMAT_PCMU, 8000, 1, 8,
+			      20000, 64000, 64000);
+    pjmedia_format_init_audio(&wdi->info.ext_fmt[0],
+			      PJMEDIA_FORMAT_PCMA, 8000, 1, 8,
+			      20000, 64000, 64000);
 }
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-codec/ffmpeg_codecs.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-codec/ffmpeg_codecs.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-codec/ffmpeg_codecs.c	(revision 3392)
@@ -0,0 +1,1054 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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 
+ */
+#include <pjmedia-codec/ffmpeg_codecs.h>
+#include <pjmedia-codec/h263_packetizer.h>
+#include <pjmedia/errno.h>
+#include <pj/assert.h>
+#include <pj/list.h>
+#include <pj/log.h>
+#include <pj/math.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+#include <pj/os.h>
+
+/*
+ * Only build this file if PJMEDIA_HAS_FFMPEG_CODEC != 0
+ */
+#if defined(PJMEDIA_HAS_FFMPEG_CODEC) && PJMEDIA_HAS_FFMPEG_CODEC != 0
+
+#define THIS_FILE   "ffmpeg_codecs.c"
+
+#include "../pjmedia/ffmpeg_util.h"
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+
+
+#define PJMEDIA_FORMAT_FFMPEG_UNKNOWN  PJMEDIA_FORMAT_PACK('f','f','0','0');
+
+
+/* Prototypes for FFMPEG codecs factory */
+static pj_status_t ffmpeg_test_alloc( pjmedia_vid_codec_factory *factory, 
+				      const pjmedia_vid_codec_info *id );
+static pj_status_t ffmpeg_default_attr( pjmedia_vid_codec_factory *factory, 
+				        const pjmedia_vid_codec_info *info, 
+				        pjmedia_vid_codec_param *attr );
+static pj_status_t ffmpeg_enum_codecs( pjmedia_vid_codec_factory *factory, 
+				       unsigned *count, 
+				       pjmedia_vid_codec_info codecs[]);
+static pj_status_t ffmpeg_alloc_codec( pjmedia_vid_codec_factory *factory, 
+				       const pjmedia_vid_codec_info *info, 
+				       pjmedia_vid_codec **p_codec);
+static pj_status_t ffmpeg_dealloc_codec( pjmedia_vid_codec_factory *factory, 
+				         pjmedia_vid_codec *codec );
+
+/* Prototypes for FFMPEG codecs implementation. */
+static pj_status_t  ffmpeg_codec_init( pjmedia_vid_codec *codec, 
+				       pj_pool_t *pool );
+static pj_status_t  ffmpeg_codec_open( pjmedia_vid_codec *codec, 
+				       pjmedia_vid_codec_param *attr );
+static pj_status_t  ffmpeg_codec_close( pjmedia_vid_codec *codec );
+static pj_status_t  ffmpeg_codec_modify(pjmedia_vid_codec *codec, 
+				        const pjmedia_vid_codec_param *attr );
+static pj_status_t  ffmpeg_packetize ( pjmedia_vid_codec *codec,
+                                       pj_uint8_t *buf,
+                                       pj_size_t buf_len,
+                                       unsigned *pos,
+                                       const pj_uint8_t **payload,
+                                       pj_size_t *payload_len);
+static pj_status_t  ffmpeg_unpacketize(pjmedia_vid_codec *codec,
+                                       const pj_uint8_t *payload,
+                                       pj_size_t   payload_len,
+                                       pj_uint8_t *buf,
+                                       pj_size_t  *buf_len);
+static pj_status_t  ffmpeg_codec_encode( pjmedia_vid_codec *codec, 
+				         const pjmedia_frame *input,
+				         unsigned output_buf_len, 
+				         pjmedia_frame *output);
+static pj_status_t  ffmpeg_codec_decode( pjmedia_vid_codec *codec, 
+				         const pjmedia_frame *input,
+				         unsigned output_buf_len, 
+				         pjmedia_frame *output);
+static pj_status_t  ffmpeg_codec_recover( pjmedia_vid_codec *codec, 
+				          unsigned output_buf_len, 
+				          pjmedia_frame *output);
+
+/* Definition for FFMPEG codecs operations. */
+static pjmedia_vid_codec_op ffmpeg_op = 
+{
+    &ffmpeg_codec_init,
+    &ffmpeg_codec_open,
+    &ffmpeg_codec_close,
+    &ffmpeg_codec_modify,
+    &ffmpeg_packetize,
+    &ffmpeg_unpacketize,
+    &ffmpeg_codec_encode,
+    &ffmpeg_codec_decode,
+    NULL //&ffmpeg_codec_recover
+};
+
+/* Definition for FFMPEG codecs factory operations. */
+static pjmedia_vid_codec_factory_op ffmpeg_factory_op =
+{
+    &ffmpeg_test_alloc,
+    &ffmpeg_default_attr,
+    &ffmpeg_enum_codecs,
+    &ffmpeg_alloc_codec,
+    &ffmpeg_dealloc_codec
+};
+
+
+typedef struct ffmpeg_codec_info {
+    PJ_DECL_LIST_MEMBER(struct ffmpeg_codec_info);
+    pjmedia_vid_codec_info       info;
+    AVCodec                     *enc;
+    AVCodec                     *dec;
+} ffmpeg_codec_info;
+
+
+/* FFMPEG codecs factory */
+static struct ffmpeg_factory {
+    pjmedia_vid_codec_factory    base;
+    pjmedia_vid_codec_mgr	*mgr;
+    pj_pool_factory             *pf;
+    pj_pool_t		        *pool;
+    pj_mutex_t		        *mutex;
+    ffmpeg_codec_info            codecs;
+} ffmpeg_factory;
+
+
+/* FFMPEG codecs private data. */
+typedef struct ffmpeg_private {
+    AVCodec                     *enc;
+    AVCodec                     *dec;
+    AVCodecContext              *enc_ctx;
+    AVCodecContext              *dec_ctx;
+    AVCodecParserContext        *dec_parser_ctx;
+
+    /*
+    pjmedia_frame               *pack_frms;
+    unsigned                     pack_frm_cnt;
+    unsigned                     pack_frm_max_cnt;
+    */
+
+    pjmedia_vid_codec_param      param;	    /**< Codec param.		    */
+    pj_pool_t		        *pool;	    /**< Pool for each instance.    */
+    pj_timestamp	         last_tx;   /**< Timestamp of last transmit.*/
+    const pjmedia_video_format_info *vfi;
+    pjmedia_video_apply_fmt_param    vafp;
+} ffmpeg_private;
+
+
+/*
+ * Initialize and register FFMPEG codec factory to pjmedia endpoint.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_ffmpeg_init(pjmedia_vid_codec_mgr *mgr,
+                                              pj_pool_factory *pf)
+{
+    pj_pool_t *pool;
+    AVCodec *c;
+    enum CodecID last_codec_id = CODEC_ID_NONE;
+    pj_status_t status;
+
+    if (ffmpeg_factory.pool != NULL) {
+	/* Already initialized. */
+	return PJ_SUCCESS;
+    }
+
+    if (!mgr) mgr = pjmedia_vid_codec_mgr_instance();
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    /* Create FFMPEG codec factory. */
+    ffmpeg_factory.base.op = &ffmpeg_factory_op;
+    ffmpeg_factory.base.factory_data = NULL;
+    ffmpeg_factory.mgr = mgr;
+    ffmpeg_factory.pf = pf;
+    pj_list_init(&ffmpeg_factory.codecs);
+
+    pool = pj_pool_create(pf, "ffmpeg codec factory", 256, 256, NULL);
+    if (!pool)
+	return PJ_ENOMEM;
+
+    /* Create mutex. */
+    status = pj_mutex_create_simple(pool, "ffmpeg codec factory", 
+				    &ffmpeg_factory.mutex);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    avcodec_init();
+    avcodec_register_all();
+
+    /* Enum FFMPEG codecs */
+    for (c=av_codec_next(NULL); c; c=av_codec_next(c)) 
+    {
+        ffmpeg_codec_info *ci;
+        
+        if (c->type != CODEC_TYPE_VIDEO)
+            continue;
+
+        /* Video encoder and decoder are usually implemented in separate
+         * AVCodec instances.
+         */
+
+        if (c->id == last_codec_id) {
+            /* This codec usually be the decoder, and not as much info as in
+             * encoder can be fetched here.
+             */
+            pj_assert(!pj_list_empty(&ffmpeg_factory.codecs));
+            ci = ffmpeg_factory.codecs.prev;
+            pj_assert(ci->info.dir != PJMEDIA_DIR_ENCODING_DECODING);
+            pj_assert(!ci->dec || !ci->enc);
+        } else {
+            pjmedia_format_id enc_fmt_id;
+            pjmedia_format_id raw_fmt[PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT];
+            unsigned raw_fmt_cnt = 0;
+            unsigned raw_fmt_cnt_should_be = 0;
+
+            /* Get encoded format id */
+            status = CodecID_to_pjmedia_format_id(c->id, &enc_fmt_id);
+            if (status != PJ_SUCCESS) {
+                //PJ_LOG(5, (THIS_FILE, "Unrecognized ffmpeg codec id %d, "
+                //                      "codec [%s/%s] ignored",
+                //                      c->id, c->name, c->long_name));
+                //enc_fmt_id = PJMEDIA_FORMAT_FFMPEG_UNKNOWN;
+
+                /* Skip unrecognized encoding format ID */
+                continue;
+            }
+
+            /* Get raw/decoded format ids */
+            if (c->pix_fmts) {
+                const enum PixelFormat *p = c->pix_fmts;
+                for(;(p && *p != -1) &&
+                     (raw_fmt_cnt < PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT);
+                     ++p)
+                {
+                    pjmedia_format_id fmt_id;
+
+                    raw_fmt_cnt_should_be++;
+                    status = PixelFormat_to_pjmedia_format_id(*p, &fmt_id);
+                    if (status != PJ_SUCCESS) {
+                        PJ_LOG(6, (THIS_FILE, "Unrecognized ffmpeg pixel "
+                                   "format %d", *p));
+                        continue;
+                    }
+                    raw_fmt[raw_fmt_cnt++] = fmt_id;
+                }
+            } else {
+                /* Unknown raw format, ignore this codec? */
+                continue;
+            }
+
+            if (raw_fmt_cnt < raw_fmt_cnt_should_be) {
+                PJ_LOG(6, (THIS_FILE, "Codec [%s/%s] have %d raw formats, "
+                                      "recognized only %d raw formats",
+                                      c->name, c->long_name,
+                                      raw_fmt_cnt_should_be, raw_fmt_cnt));
+            }
+            if (raw_fmt_cnt == 0) {
+                PJ_LOG(5, (THIS_FILE, "No recognized raw format "
+                                      "for codec [%s/%s], codec ignored",
+                                      c->name, c->long_name));
+                /* Comment this to see all ffmpeg codecs */
+                continue;
+            }
+
+            ci = PJ_POOL_ZALLOC_T(pool, ffmpeg_codec_info);
+            ci->info.fmt_id = enc_fmt_id;
+            pj_cstr(&ci->info.encoding_name, c->name);
+            ci->info.clock_rate = 90000;
+            ci->info.dec_fmt_id_cnt = raw_fmt_cnt;
+            pj_memcpy(ci->info.dec_fmt_id, raw_fmt, 
+                      sizeof(raw_fmt[0])*raw_fmt_cnt);
+
+            switch (enc_fmt_id) {
+                case PJMEDIA_FORMAT_H263:
+                    ci->info.pt = PJMEDIA_RTP_PT_H263;
+                    break;
+                case PJMEDIA_FORMAT_H261:
+                    ci->info.pt = PJMEDIA_RTP_PT_H261;
+                    break;
+                default:
+                    break;
+            }
+
+            if (c->supported_framerates) {
+                const AVRational *fr = c->supported_framerates;
+                while ((fr->num != 0 || fr->den != 0) && 
+                       ci->info.fps_cnt < PJMEDIA_VID_CODEC_MAX_FPS_CNT)
+                {
+                    ci->info.fps[ci->info.fps_cnt].num = fr->num;
+                    ci->info.fps[ci->info.fps_cnt].denum = fr->den;
+                    ++ci->info.fps_cnt;
+                    ++fr;
+                }
+            }
+
+            pj_list_push_back(&ffmpeg_factory.codecs, ci);
+        }
+
+        if (c->encode) {
+            ci->info.dir |= PJMEDIA_DIR_ENCODING;
+            ci->enc = c;
+        }
+        if (c->decode) {
+            ci->info.dir |= PJMEDIA_DIR_DECODING;
+            ci->dec = c;
+        }
+
+        last_codec_id = c->id;
+    }
+
+    /* Register codec factory to codec manager. */
+    status = pjmedia_vid_codec_mgr_register_factory(mgr, 
+						    &ffmpeg_factory.base);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    ffmpeg_factory.pool = pool;
+
+    /* Done. */
+    return PJ_SUCCESS;
+
+on_error:
+    pj_pool_release(pool);
+    return status;
+}
+
+/*
+ * Unregister FFMPEG codecs factory from pjmedia endpoint.
+ */
+PJ_DEF(pj_status_t) pjmedia_codec_ffmpeg_deinit(void)
+{
+    pj_status_t status = PJ_SUCCESS;
+
+    if (ffmpeg_factory.pool == NULL) {
+	/* Already deinitialized */
+	return PJ_SUCCESS;
+    }
+
+    pj_mutex_lock(ffmpeg_factory.mutex);
+
+    /* Unregister FFMPEG codecs factory. */
+    status = pjmedia_vid_codec_mgr_unregister_factory(ffmpeg_factory.mgr,
+						      &ffmpeg_factory.base);
+
+    /* Destroy mutex. */
+    pj_mutex_destroy(ffmpeg_factory.mutex);
+
+    /* Destroy pool. */
+    pj_pool_release(ffmpeg_factory.pool);
+    ffmpeg_factory.pool = NULL;
+
+    return status;
+}
+
+
+static ffmpeg_codec_info* find_codec(const pjmedia_vid_codec_info *info)
+{
+    ffmpeg_codec_info *ci = ffmpeg_factory.codecs.next;
+
+    pj_mutex_lock(ffmpeg_factory.mutex);
+
+    while (ci != &ffmpeg_factory.codecs) {
+        if ((ci->info.fmt_id == info->fmt_id) &&
+            ((ci->info.dir & info->dir) == info->dir) &&
+            pj_stricmp(&ci->info.encoding_name, &info->encoding_name)==0)
+        {
+            pj_mutex_unlock(ffmpeg_factory.mutex);
+            return ci;
+        }
+        ci = ci->next;
+    }
+
+    pj_mutex_unlock(ffmpeg_factory.mutex);
+
+    return NULL;
+}
+
+
+/* 
+ * Check if factory can allocate the specified codec. 
+ */
+static pj_status_t ffmpeg_test_alloc( pjmedia_vid_codec_factory *factory, 
+				      const pjmedia_vid_codec_info *info )
+{
+    ffmpeg_codec_info *ci;
+
+    PJ_ASSERT_RETURN(factory==&ffmpeg_factory.base, PJ_EINVAL);
+    PJ_ASSERT_RETURN(info, PJ_EINVAL);
+
+    ci = find_codec(info);
+    if (!ci) {
+        return PJMEDIA_CODEC_EUNSUP;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Generate default attribute.
+ */
+static pj_status_t ffmpeg_default_attr( pjmedia_vid_codec_factory *factory, 
+				        const pjmedia_vid_codec_info *info, 
+				        pjmedia_vid_codec_param *attr )
+{
+    ffmpeg_codec_info *ci;
+
+    PJ_ASSERT_RETURN(factory==&ffmpeg_factory.base, PJ_EINVAL);
+    PJ_ASSERT_RETURN(info && attr, PJ_EINVAL);
+
+    ci = find_codec(info);
+    if (!ci) {
+        return PJMEDIA_CODEC_EUNSUP;
+    }
+
+    pj_bzero(attr, sizeof(pjmedia_vid_codec_param));
+    attr->dir = ci->info.dir;
+    attr->pt = info->pt;
+    pjmedia_format_init_video(&attr->enc_fmt, ci->info.fmt_id,
+                              352, 288, 25, 1);
+    pjmedia_format_init_video(&attr->dec_fmt, ci->info.dec_fmt_id[0],
+                              352, 288, 25, 1);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Enum codecs supported by this factory.
+ */
+static pj_status_t ffmpeg_enum_codecs( pjmedia_vid_codec_factory *factory,
+				       unsigned *count, 
+				       pjmedia_vid_codec_info codecs[])
+{
+    ffmpeg_codec_info *ci;
+    unsigned max;
+
+    PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL);
+    PJ_ASSERT_RETURN(factory == &ffmpeg_factory.base, PJ_EINVAL);
+
+    max = *count;
+    *count = 0;
+    ci = ffmpeg_factory.codecs.next;
+
+    pj_mutex_lock(ffmpeg_factory.mutex);
+    while (*count < max && ci != &ffmpeg_factory.codecs) {
+        pj_memcpy(&codecs[*count], &ci->info, sizeof(pjmedia_vid_codec_info));
+        *count = *count + 1;
+        ci = ci->next;
+    }
+    pj_mutex_unlock(ffmpeg_factory.mutex);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Allocate a new codec instance.
+ */
+static pj_status_t ffmpeg_alloc_codec( pjmedia_vid_codec_factory *factory, 
+				       const pjmedia_vid_codec_info *info,
+				       pjmedia_vid_codec **p_codec)
+{
+    ffmpeg_private *ff;
+    ffmpeg_codec_info *ci;
+    pjmedia_vid_codec *codec;
+    pj_pool_t *pool = NULL;
+    pj_status_t status = PJ_SUCCESS;
+
+    PJ_ASSERT_RETURN(factory && info && p_codec, PJ_EINVAL);
+    PJ_ASSERT_RETURN(factory == &ffmpeg_factory.base, PJ_EINVAL);
+
+    ci = find_codec(info);
+    if (!ci) {
+        return PJMEDIA_CODEC_EUNSUP;
+    }
+
+    /* Create pool for codec instance */
+    pool = pj_pool_create(ffmpeg_factory.pf, "ffmpeg codec", 512, 512, NULL);
+    codec = PJ_POOL_ZALLOC_T(pool, pjmedia_vid_codec);
+    if (!codec) {
+        status = PJ_ENOMEM;
+        goto on_error;
+    }
+    codec->op = &ffmpeg_op;
+    codec->factory = factory;
+    ff = PJ_POOL_ZALLOC_T(pool, ffmpeg_private);
+    if (!ff) {
+        status = PJ_ENOMEM;
+        goto on_error;
+    }
+    codec->codec_data = ff;
+    ff->pool = pool;
+    ff->enc = ci->enc;
+    ff->dec = ci->dec;
+
+    *p_codec = codec;
+    return PJ_SUCCESS;
+
+on_error:
+    if (pool)
+        pj_pool_release(pool);
+    return status;
+}
+
+/*
+ * Free codec.
+ */
+static pj_status_t ffmpeg_dealloc_codec( pjmedia_vid_codec_factory *factory, 
+				         pjmedia_vid_codec *codec )
+{
+    ffmpeg_private *ff;
+    pj_pool_t *pool;
+
+    PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL);
+    PJ_ASSERT_RETURN(factory == &ffmpeg_factory.base, PJ_EINVAL);
+
+    /* Close codec, if it's not closed. */
+    ff = (ffmpeg_private*) codec->codec_data;
+    pool = ff->pool;
+    codec->codec_data = NULL;
+    pj_pool_release(pool);
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Init codec.
+ */
+static pj_status_t ffmpeg_codec_init( pjmedia_vid_codec *codec, 
+				      pj_pool_t *pool )
+{
+    PJ_UNUSED_ARG(codec);
+    PJ_UNUSED_ARG(pool);
+    return PJ_SUCCESS;
+}
+
+static void print_ffmpeg_err(int err)
+{
+#if LIBAVCODEC_VERSION_MAJOR >= 52 && LIBAVCODEC_VERSION_MINOR >= 72
+    char errbuf[512];
+    if (av_strerror(err, errbuf, sizeof(errbuf)) >= 0)
+        PJ_LOG(1, (THIS_FILE, "ffmpeg err %d: %s", err, errbuf));
+#else
+    PJ_LOG(1, (THIS_FILE, "ffmpeg err %d", err));
+#endif
+
+}
+
+/*
+static enum PixelFormat ffdec_nego_format(struct AVCodecContext *s, 
+                                          const enum PixelFormat * fmt)
+{
+    enum PixelFormat pix_fmt;
+
+    PJ_UNUSED_ARG(s);
+    PJ_UNUSED_ARG(fmt);
+
+    pjmedia_format_id_to_PixelFormat(PJMEDIA_FORMAT_BGRA, &pix_fmt);
+    return pix_fmt;
+}
+
+static void enc_got_payload(struct AVCodecContext *avctx,
+                            void *data, int size, int mb_nb);
+*/
+
+
+static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
+                                     pj_mutex_t *ff_mutex)
+{
+    enum PixelFormat pix_fmt;
+    pj_status_t status;
+
+    status = pjmedia_format_id_to_PixelFormat(ff->param.dec_fmt.id,
+                                              &pix_fmt);
+    if (status != PJ_SUCCESS)
+        return status;
+
+    while (((ff->param.dir & PJMEDIA_DIR_ENCODING) && ff->enc_ctx == NULL) ||
+           ((ff->param.dir & PJMEDIA_DIR_DECODING) && ff->dec_ctx == NULL))
+    {
+        pjmedia_dir dir;
+        AVCodecContext *ctx = NULL;
+        AVCodec *codec = NULL;
+        int err;
+
+        /* Set which direction to open */
+        if (ff->param.dir==PJMEDIA_DIR_ENCODING_DECODING && ff->enc!=ff->dec) {
+            dir = ff->enc_ctx? PJMEDIA_DIR_DECODING : PJMEDIA_DIR_ENCODING;
+        } else {
+            dir = ff->param.dir;
+        }
+
+        ctx = avcodec_alloc_context();
+
+        /* Common attributes */
+        ctx->pix_fmt = pix_fmt;
+        ctx->width = ff->param.enc_fmt.det.vid.size.w;
+        ctx->height = ff->param.enc_fmt.det.vid.size.h;
+        ctx->workaround_bugs = FF_BUG_AUTODETECT;
+        ctx->opaque = ff;
+
+        if (dir & PJMEDIA_DIR_ENCODING) {
+            codec = ff->enc;
+
+            /* Encoding only attributes */
+            ctx->time_base.num = ff->param.enc_fmt.det.vid.fps.denum;
+            ctx->time_base.den = ff->param.enc_fmt.det.vid.fps.num;
+            if (ff->param.enc_fmt.det.vid.avg_bps)
+                ctx->bit_rate = ff->param.enc_fmt.det.vid.avg_bps;
+            if (ff->param.enc_fmt.det.vid.max_bps)
+                ctx->rc_max_rate = ff->param.enc_fmt.det.vid.max_bps;
+#if 0
+            if (ff->param.enc_mtu) {
+                //ctx->rtp_payload_size = ff->param.enc_mtu;
+                //ctx->rtp_callback = &enc_got_payload;
+
+                /* Allocate frame array for RTP payload packing */
+                if (ff->param.enc_fmt.det.vid.max_bps)
+                    ff->pack_frm_max_cnt = ff->param.enc_fmt.det.vid.max_bps /
+                                           ff->param.enc_mtu + 1;
+                else
+                    ff->pack_frm_max_cnt = 32;
+
+                ff->pack_frms = (pjmedia_frame*)
+                                pj_pool_calloc(ff->pool, ff->pack_frm_max_cnt,
+                                               sizeof(ff->pack_frms[0]));
+            }
+#endif
+
+            /* For encoder, should be better to be strict to the standards */
+            ctx->strict_std_compliance = FF_COMPLIANCE_STRICT;
+        }
+        if (dir & PJMEDIA_DIR_DECODING) {
+            codec = ff->dec;
+
+            /* Decoding only attributes */
+            ctx->coded_width = ctx->width;
+            ctx->coded_height = ctx->height;
+
+            /* For decoder, be more flexible */
+            if (ff->param.dir!=PJMEDIA_DIR_ENCODING_DECODING || ff->enc!=ff->dec)
+                ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
+
+            //ctx->get_format = &ffdec_nego_format;
+        }
+
+        /* avcodec_open() should be protected */
+        pj_mutex_lock(ff_mutex);
+        err = avcodec_open(ctx, codec);
+        pj_mutex_unlock(ff_mutex);
+        if (err < 0) {
+            print_ffmpeg_err(err);
+            return PJ_EUNKNOWN;
+        }
+
+        if (dir & PJMEDIA_DIR_ENCODING)
+            ff->enc_ctx = ctx;
+        if (dir & PJMEDIA_DIR_DECODING)
+            ff->dec_ctx = ctx;
+    }
+    
+    return PJ_SUCCESS;
+}
+
+/*
+ * Open codec.
+ */
+static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec, 
+				      pjmedia_vid_codec_param *attr )
+{
+    ffmpeg_private *ff;
+    pj_status_t status;
+    pj_mutex_t *ff_mutex;
+
+    PJ_ASSERT_RETURN(codec && attr, PJ_EINVAL);
+    ff = (ffmpeg_private*)codec->codec_data;
+
+    ff->vfi = pjmedia_get_video_format_info(NULL, attr->dec_fmt.id);
+    if (!ff->vfi) {
+        status = PJ_EINVAL;
+        goto on_error;
+    }
+
+    pj_bzero(&ff->vafp, sizeof(ff->vafp));
+    ff->vafp.size = attr->dec_fmt.det.vid.size;
+    ff->vafp.buffer = 0;
+    status = (*ff->vfi->apply_fmt)(ff->vfi, &ff->vafp);
+    if (status != PJ_SUCCESS) {
+        goto on_error;
+    }
+
+    pj_memcpy(&ff->param, attr, sizeof(*attr));
+
+    ff_mutex = ((struct ffmpeg_factory*)codec->factory)->mutex;
+    status = open_ffmpeg_codec(ff, ff_mutex);
+    if (status != PJ_SUCCESS)
+        goto on_error;
+
+    return PJ_SUCCESS;
+
+on_error:
+    ffmpeg_codec_close(codec);
+    return status;
+}
+
+/*
+ * Close codec.
+ */
+static pj_status_t ffmpeg_codec_close( pjmedia_vid_codec *codec )
+{
+    ffmpeg_private *ff;
+    pj_mutex_t *ff_mutex;
+
+    PJ_ASSERT_RETURN(codec, PJ_EINVAL);
+    ff = (ffmpeg_private*)codec->codec_data;
+    ff_mutex = ((struct ffmpeg_factory*)codec->factory)->mutex;
+
+    pj_mutex_lock(ff_mutex);
+    if (ff->enc_ctx) {
+        avcodec_close(ff->enc_ctx);
+        av_free(ff->enc_ctx);
+    }
+    if (ff->dec_ctx && ff->dec_ctx!=ff->enc_ctx) {
+        avcodec_close(ff->dec_ctx);
+        av_free(ff->dec_ctx);
+    }
+    if (ff->dec_parser_ctx) {
+        av_parser_close(ff->dec_parser_ctx);
+
+    }
+    ff->enc_ctx = NULL;
+    ff->dec_ctx = NULL;
+    ff->dec_parser_ctx = NULL;
+    pj_mutex_unlock(ff_mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Modify codec settings.
+ */
+static pj_status_t  ffmpeg_codec_modify( pjmedia_vid_codec *codec, 
+				         const pjmedia_vid_codec_param *attr )
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+
+    PJ_UNUSED_ARG(attr);
+    PJ_UNUSED_ARG(ff);
+
+    return PJ_ENOTSUP;
+}
+
+static pj_status_t  ffmpeg_packetize ( pjmedia_vid_codec *codec,
+                                       pj_uint8_t *buf,
+                                       pj_size_t buf_len,
+                                       unsigned *pos,
+                                       const pj_uint8_t **payload,
+                                       pj_size_t *payload_len)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+
+    switch (ff->param.enc_fmt.id) {
+        case PJMEDIA_FORMAT_H263:
+            return pjmedia_h263_packetize(buf, buf_len, pos,
+                                          ff->param.enc_mtu, payload,
+                                          payload_len);
+            break;
+        default:
+            return PJ_ENOTSUP;
+    }
+}
+
+static pj_status_t  ffmpeg_unpacketize(pjmedia_vid_codec *codec,
+                                       const pj_uint8_t *payload,
+                                       pj_size_t   payload_len,
+                                       pj_uint8_t *buf,
+                                       pj_size_t  *buf_len)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+
+    switch (ff->param.enc_fmt.id) {
+        case PJMEDIA_FORMAT_H263:
+            return pjmedia_h263_unpacketize(payload, payload_len,
+                                            buf, buf_len);
+            break;
+        default:
+            return PJ_ENOTSUP;
+    }
+}
+
+#if 0
+/*
+ * Pack encoded frame to RTP payload frames.
+ */
+static pj_status_t  ffmpeg_codec_pack ( pjmedia_vid_codec *codec,
+				        const pjmedia_frame *enc_frame,
+				        unsigned *frame_cnt,
+				        pjmedia_frame frames[])
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+    unsigned i;
+
+    /* Can only work when encoding MTU is set */
+    PJ_ASSERT_RETURN(ff->param.enc_mtu, PJ_EINVALIDOP);
+
+    /* Validate available payload number */
+    PJ_ASSERT_RETURN(ff->pack_frm_cnt <= *frame_cnt, PJ_EINVALIDOP);
+
+    /* Validate encoded bitstream */
+    PJ_ASSERT_RETURN(ff->pack_frm_cnt==0 || 
+                     ff->pack_frms[0].buf == enc_frame->buf,
+                     PJ_EINVAL);
+
+    /* Return the payloads */
+    *frame_cnt = ff->pack_frm_cnt;
+    for (i = 0; i < *frame_cnt; ++i)
+        frames[i] = ff->pack_frms[i];
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Get frames in the packet.
+ */
+static pj_status_t  ffmpeg_codec_parse( pjmedia_vid_codec *codec,
+				        void *pkt,
+				        pj_size_t pkt_size,
+				        const pj_timestamp *ts,
+				        pjmedia_frame *frame)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+    pj_uint8_t *buf = frame->buf;
+    int buf_size = frame->size;
+    int processed;
+
+
+    if (!ff->dec_parser_ctx) {
+        ff->dec_parser_ctx = av_parser_init(ff->dec->id);
+        if (!ff->dec_parser_ctx)
+            return PJ_ENOTSUP;
+    }
+
+#if LIBAVCODEC_VERSION_MAJOR >= 52 && LIBAVCODEC_VERSION_MINOR >= 72
+    processed = av_parser_parse2(ff->dec_parser_ctx, ff->dec_ctx, 
+                                 &buf, &buf_size, (uint8_t*)pkt, pkt_size,
+                                 ts->u64, ts->u64, AV_NOPTS_VALUE);
+#else
+    processed = av_parser_parse (ff->dec_parser_ctx, ff->dec_ctx, 
+                                 &buf, &buf_size, (uint8_t*)pkt, pkt_size,
+                                 ts->u64, ts->u64);
+#endif
+
+    if (buf_size) {
+        frame->timestamp = *ts;
+        frame->size = buf_size;
+        return PJ_SUCCESS;
+    }
+
+    return PJ_EPENDING;
+}
+
+static void enc_got_payload(struct AVCodecContext *avctx,
+                            void *data, int size, int mb_nb)
+{
+    ffmpeg_private *ff = (ffmpeg_private*) avctx->opaque;
+    pjmedia_frame *payload;
+
+    pj_assert(ff->pack_frm_cnt < ff->pack_frm_max_cnt);
+    payload = &ff->pack_frms[ff->pack_frm_cnt++];
+    payload->buf = data;
+    payload->size = size;
+    payload->bit_info = mb_nb;
+}
+
+#endif
+
+
+/*
+ * Encode frames.
+ */
+static pj_status_t ffmpeg_codec_encode( pjmedia_vid_codec *codec, 
+				        const struct pjmedia_frame *input,
+				        unsigned output_buf_len, 
+				        struct pjmedia_frame *output)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+    pj_uint8_t *p = (pj_uint8_t*)input->buf;
+    AVFrame avframe;
+    pj_uint8_t *out_buf = (pj_uint8_t*)output->buf;
+    int out_buf_len = output_buf_len;
+    int err;
+    unsigned i;
+
+    /* Check if encoder has been opened */
+    PJ_ASSERT_RETURN(ff->enc_ctx, PJ_EINVALIDOP);
+
+    /*
+    ff->pack_frm_cnt = 0;
+    */
+    avcodec_get_frame_defaults(&avframe);
+    
+    for (i = 0; i < ff->vfi->plane_cnt; ++i) {
+        avframe.data[i] = p;
+        avframe.linesize[i] = ff->vafp.strides[i];
+        p += ff->vafp.plane_bytes[i];
+    }
+
+#ifdef _MSC_VER
+    /* Align stack for MSVC environment to avoid 'random' crash, as advised in
+     * http://ffmpeg.arrozcru.org/forum/viewtopic.php?f=1&t=549
+     */
+#   define VHALIGNCALL16(x) \
+    {\
+        _asm { mov ebx, esp }\
+        _asm { and esp, 0xfffffff0 }\
+        _asm { sub esp, 12 }\
+        _asm { push ebx }\
+        x;\
+        _asm { pop ebx }\
+        _asm { mov esp, ebx }\
+     }
+#else
+#   define VHALIGNCALL16(x)
+#endif
+
+    VHALIGNCALL16(err = avcodec_encode_video(ff->enc_ctx, out_buf, 
+                                             out_buf_len, &avframe));
+
+    if (err < 0) {
+        print_ffmpeg_err(err);
+        return PJ_EUNKNOWN;
+    } else {
+        output->size = err;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Decode frame.
+ */
+static pj_status_t ffmpeg_codec_decode( pjmedia_vid_codec *codec, 
+				        const struct pjmedia_frame *input,
+				        unsigned output_buf_len, 
+				        struct pjmedia_frame *output)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+    AVFrame avframe;
+    AVPacket avpacket;
+    int err, got_picture;
+
+    /* Check if decoder has been opened */
+    PJ_ASSERT_RETURN(ff->dec_ctx, PJ_EINVALIDOP);
+
+    PJ_UNUSED_ARG(output_buf_len);
+
+    /* Init frame to receive the decoded data, the ffmpeg codec context will
+     * automatically provide the decoded buffer (single buffer used for the
+     * whole decoding session, and seems to be freed when the codec context
+     * closed).
+     */
+    avcodec_get_frame_defaults(&avframe);
+
+    /* Init packet, the container of the encoded data */
+    av_init_packet(&avpacket);
+    avpacket.data = (pj_uint8_t*)input->buf;
+    avpacket.size = input->size;
+
+    /* ffmpeg warns:
+     * - input buffer padding, at least FF_INPUT_BUFFER_PADDING_SIZE
+     * - null terminated
+     * Normally, encoded buffer is allocated more than needed, so lets just
+     * bzero the input buffer end/pad, hope it will be just fine.
+     */
+    pj_bzero(avpacket.data+avpacket.size, FF_INPUT_BUFFER_PADDING_SIZE);
+
+#if LIBAVCODEC_VERSION_MAJOR >= 52 && LIBAVCODEC_VERSION_MINOR >= 72
+    avpacket.flags = AV_PKT_FLAG_KEY;
+#else
+    avpacket.flags = 0;
+#endif
+
+#if LIBAVCODEC_VERSION_MAJOR >= 52 && LIBAVCODEC_VERSION_MINOR >= 72
+    err = avcodec_decode_video2(ff->dec_ctx, &avframe, 
+                                &got_picture, &avpacket);
+#else
+    err = avcodec_decode_video(ff->dec_ctx, &avframe,
+                               &got_picture, avpacket.data, avpacket.size);
+#endif
+    if (err < 0) {
+        print_ffmpeg_err(err);
+        return PJ_EUNKNOWN;
+    } else if (got_picture) {
+        pjmedia_video_apply_fmt_param *vafp = (pjmedia_video_apply_fmt_param*)
+                                              &ff->vafp;
+        pj_uint8_t *q = (pj_uint8_t*)output->buf;
+        unsigned i;
+
+        /* Get the decoded data */
+        for (i = 0; i < ff->vfi->plane_cnt; ++i) {
+            pj_uint8_t *p = avframe.data[i];
+
+            /* The decoded data may contain padding */
+            if (avframe.linesize[i]==vafp->strides[i]) {
+                /* No padding, copy the whole plane */
+                pj_memcpy(q, p, vafp->plane_bytes[i]);
+                q += vafp->plane_bytes[i];
+            } else {
+                /* Padding exists, copy line by line */
+                pj_uint8_t *q_end;
+                
+                q_end = q+vafp->plane_bytes[i];
+                while(q < q_end) {
+                    pj_memcpy(q, p, vafp->strides[i]);
+                    q += vafp->strides[i];
+                    p += avframe.linesize[i];
+                }
+            }
+        }
+        output->size = vafp->framebytes;
+    } else {
+        return PJ_EUNKNOWN;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* 
+ * Recover lost frame.
+ */
+static pj_status_t  ffmpeg_codec_recover( pjmedia_vid_codec *codec, 
+				          unsigned output_buf_len, 
+				          struct pjmedia_frame *output)
+{
+    ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
+
+    PJ_UNUSED_ARG(output_buf_len);
+    PJ_UNUSED_ARG(output);
+    PJ_UNUSED_ARG(ff);
+
+    return PJ_SUCCESS;
+}
+
+#ifdef _MSC_VER
+#   pragma comment( lib, "avcodec.lib")
+#endif
+
+#endif	/* PJMEDIA_HAS_FFMPEG_CODEC */
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/colorbar_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/colorbar_dev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/colorbar_dev.c	(revision 3392)
@@ -0,0 +1,604 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/os.h>
+#include <pj/rand.h>
+
+#if PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC
+
+#define THIS_FILE		"colorbar_dev.c"
+#define DEFAULT_CLOCK_RATE	90000
+#define DEFAULT_WIDTH		352 //640
+#define DEFAULT_HEIGHT		288 //480
+#define DEFAULT_FPS		25
+
+/* cbar_ device info */
+struct cbar_dev_info
+{
+    pjmedia_vid_dev_info	 info;
+};
+
+/* cbar_ factory */
+struct cbar_factory
+{
+    pjmedia_vid_dev_factory	 base;
+    pj_pool_t			*pool;
+    pj_pool_factory		*pf;
+
+    unsigned			 dev_count;
+    struct cbar_dev_info	*dev_info;
+};
+
+struct cbar_fmt_info {
+    pjmedia_format_id            fmt_id;        /* Format ID                */
+
+    /* Info for packed formats. */
+    unsigned                     c_offset[3];   /* Color component offset, 
+                                                   in bytes                 */
+    unsigned                     c_stride[3];   /* Color component stride,
+                                                   or distance between two 
+                                                   consecutive same color
+                                                   components, in bytes     */
+};
+
+/* Colorbar video source supports */
+static struct cbar_fmt_info cbar_fmts[] =
+{
+    /* Packed formats */
+    { PJMEDIA_FORMAT_YUY2,      {0, 1, 3}, {2, 4, 4} },
+    { PJMEDIA_FORMAT_UYVY,      {1, 0, 2}, {2, 4, 4} },
+    { PJMEDIA_FORMAT_YVYU,      {0, 3, 1}, {2, 4, 4} },
+    { PJMEDIA_FORMAT_RGBA,      {0, 1, 2}, {4, 4, 4} },
+    { PJMEDIA_FORMAT_RGB24,     {0, 1, 2}, {3, 3, 3} },
+    { PJMEDIA_FORMAT_BGRA,      {2, 1, 0}, {4, 4, 4} },
+
+    /* Planar formats */
+    { PJMEDIA_FORMAT_YV12 },
+    { PJMEDIA_FORMAT_I420 },
+    { PJMEDIA_FORMAT_I420JPEG },
+    { PJMEDIA_FORMAT_I422JPEG },
+};
+
+/* Video stream. */
+struct cbar_stream
+{
+    pjmedia_vid_stream	 base;		    /**< Base stream	       */
+    pjmedia_vid_param	 param;		    /**< Settings	       */
+    pj_pool_t           *pool;              /**< Memory pool.          */
+
+    pjmedia_vid_cb       vid_cb;            /**< Stream callback.      */
+    void                *user_data;         /**< Application data.     */
+
+    const struct cbar_fmt_info      *cbfi;
+    const pjmedia_video_format_info *vfi;
+    pjmedia_video_apply_fmt_param    vafp;
+    pj_uint8_t                      *first_line[PJMEDIA_MAX_VIDEO_PLANES];
+};
+
+
+/* Prototypes */
+static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f);
+static pj_status_t cbar_factory_destroy(pjmedia_vid_dev_factory *f);
+static unsigned    cbar_factory_get_dev_count(pjmedia_vid_dev_factory *f);
+static pj_status_t cbar_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					     unsigned index,
+					     pjmedia_vid_dev_info *info);
+static pj_status_t cbar_factory_default_param(pj_pool_t *pool,
+                                              pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_param *param);
+static pj_status_t cbar_factory_create_stream(pjmedia_vid_dev_factory *f,
+					      const pjmedia_vid_param *param,
+					      const pjmedia_vid_cb *cb,
+					      void *user_data,
+					      pjmedia_vid_stream **p_vid_strm);
+
+static pj_status_t cbar_stream_get_param(pjmedia_vid_stream *strm,
+					 pjmedia_vid_param *param);
+static pj_status_t cbar_stream_get_cap(pjmedia_vid_stream *strm,
+				       pjmedia_vid_dev_cap cap,
+				       void *value);
+static pj_status_t cbar_stream_set_cap(pjmedia_vid_stream *strm,
+				       pjmedia_vid_dev_cap cap,
+				       const void *value);
+static pj_status_t cbar_stream_get_frame(pjmedia_vid_stream *strm,
+                                         pjmedia_frame *frame);
+static pj_status_t cbar_stream_start(pjmedia_vid_stream *strm);
+static pj_status_t cbar_stream_stop(pjmedia_vid_stream *strm);
+static pj_status_t cbar_stream_destroy(pjmedia_vid_stream *strm);
+
+/* Operations */
+static pjmedia_vid_dev_factory_op factory_op =
+{
+    &cbar_factory_init,
+    &cbar_factory_destroy,
+    &cbar_factory_get_dev_count,
+    &cbar_factory_get_dev_info,
+    &cbar_factory_default_param,
+    &cbar_factory_create_stream
+};
+
+static pjmedia_vid_stream_op stream_op =
+{
+    &cbar_stream_get_param,
+    &cbar_stream_get_cap,
+    &cbar_stream_set_cap,
+    &cbar_stream_start,
+    &cbar_stream_get_frame,
+    NULL,
+    &cbar_stream_stop,
+    &cbar_stream_destroy
+};
+
+
+/****************************************************************************
+ * Factory operations
+ */
+/*
+ * Init cbar_ video driver.
+ */
+pjmedia_vid_dev_factory* pjmedia_cbar_factory(pj_pool_factory *pf)
+{
+    struct cbar_factory *f;
+    pj_pool_t *pool;
+
+    pool = pj_pool_create(pf, "cbar video", 512, 512, NULL);
+    f = PJ_POOL_ZALLOC_T(pool, struct cbar_factory);
+    f->pf = pf;
+    f->pool = pool;
+    f->base.op = &factory_op;
+
+    return &f->base;
+}
+
+
+/* API: init factory */
+static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+    struct cbar_dev_info *ddi;
+    unsigned i;
+
+    cf->dev_count = 1;
+    cf->dev_info = (struct cbar_dev_info*)
+ 		   pj_pool_calloc(cf->pool, cf->dev_count,
+ 				  sizeof(struct cbar_dev_info));
+
+    ddi = &cf->dev_info[0];
+    pj_bzero(ddi, sizeof(*ddi));
+    strncpy(ddi->info.name, "Colorbar generator",
+            sizeof(ddi->info.name));
+    ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
+    strncpy(ddi->info.driver, "Colorbar", sizeof(ddi->info.driver));
+    ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
+    ddi->info.dir = PJMEDIA_DIR_CAPTURE;
+    ddi->info.has_callback = PJ_FALSE;
+
+    ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
+    ddi->info.fmt_cnt = sizeof(cbar_fmts)/sizeof(cbar_fmts[0]);
+    ddi->info.fmt = (pjmedia_format*)
+ 		    pj_pool_calloc(cf->pool, ddi->info.fmt_cnt,
+ 				   sizeof(pjmedia_format));
+    for (i = 0; i < ddi->info.fmt_cnt; i++) {
+        pjmedia_format *fmt = &ddi->info.fmt[i];
+        pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id,
+				  DEFAULT_WIDTH, DEFAULT_HEIGHT,
+				  DEFAULT_FPS, 1);
+    }
+
+    PJ_LOG(4, (THIS_FILE, "Colorbar video src initialized with %d devices:",
+	       cf->dev_count));
+
+    return PJ_SUCCESS;
+}
+
+/* API: destroy factory */
+static pj_status_t cbar_factory_destroy(pjmedia_vid_dev_factory *f)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+    pj_pool_t *pool = cf->pool;
+
+    cf->pool = NULL;
+    pj_pool_release(pool);
+
+    return PJ_SUCCESS;
+}
+
+/* API: get number of devices */
+static unsigned cbar_factory_get_dev_count(pjmedia_vid_dev_factory *f)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+    return cf->dev_count;
+}
+
+/* API: get device info */
+static pj_status_t cbar_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					     unsigned index,
+					     pjmedia_vid_dev_info *info)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+
+    PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_memcpy(info, &cf->dev_info[index].info, sizeof(*info));
+
+    return PJ_SUCCESS;
+}
+
+/* API: create default device parameter */
+static pj_status_t cbar_factory_default_param(pj_pool_t *pool,
+                                              pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_param *param)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+    struct cbar_dev_info *di = &cf->dev_info[index];
+
+    PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
+
+    PJ_UNUSED_ARG(pool);
+
+    pj_bzero(param, sizeof(*param));
+    param->dir = PJMEDIA_DIR_CAPTURE;
+    param->cap_id = index;
+    param->rend_id = PJMEDIA_VID_INVALID_DEV;
+    param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
+    param->clock_rate = DEFAULT_CLOCK_RATE;
+    param->frame_rate.num = DEFAULT_FPS;
+    param->frame_rate.denum = 1;
+    pj_memcpy(&param->fmt, &di->info.fmt[0], sizeof(param->fmt));
+
+    return PJ_SUCCESS;
+}
+
+static const struct cbar_fmt_info* get_cbar_fmt_info(pjmedia_format_id id)
+{
+    unsigned i;
+
+    for (i = 0; i < sizeof(cbar_fmts)/sizeof(cbar_fmts[0]); i++) {
+        if (cbar_fmts[i].fmt_id == id)
+            return &cbar_fmts[i];
+    }
+
+    return NULL;
+}
+
+static void fill_first_line(pj_uint8_t *first_lines[], 
+                            const struct cbar_fmt_info *cbfi,
+                            const pjmedia_video_format_info *vfi,
+                            const pjmedia_video_apply_fmt_param *vafp)
+{
+    typedef pj_uint8_t color_comp_t[3];
+    color_comp_t rgb_colors[] = 
+    { 
+        {255,255,255}, {255,255,0}, {0,255,255}, {0,255,0},
+        {255,0,255}, {255,0,0}, {0,0,255}, {0,0,0}
+    };
+    color_comp_t yuv_colors[] = 
+    { 
+        //{235,128,128}, {162,44,142}, {131,156,44}, {112,72,58},
+        //{84,184,198}, {65,100,212}, {35,212,114}, {16,128,128}
+        {235,128,128}, {210,16,146}, {170,166,16}, {145,54,34},
+        {106,202,222}, {81,90,240}, {41,240,110}, {16,128,128}
+    };
+
+    unsigned i, j, k;
+
+    if (vfi->plane_cnt == 1) {
+        /* Packed */
+
+        for (i = 0; i < 8; ++i) {
+            /* iterate bars */
+            for (j = 0; j < 3; ++j) {
+                /* iterate color components */
+                pj_uint8_t *p = NULL, c;
+                unsigned bar_width, inc_p;
+
+                if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
+                    c = rgb_colors[i][j];
+                else
+                    c = yuv_colors[i][j];
+
+                bar_width = vafp->size.w/8;
+                bar_width /= (cbfi->c_stride[j] * 8 / vfi->bpp);
+                inc_p = cbfi->c_stride[j];
+                p = first_lines[0] + bar_width*i*inc_p + cbfi->c_offset[j];
+
+                /* draw this color */
+                for (k = 0; k < bar_width; ++k) {
+                    *p = c;
+                    p += inc_p;
+                }
+            }
+        }
+
+    } else if (vfi->plane_cnt == 3) {
+
+        for (i = 0; i < 8; ++i) {
+            /* iterate bars */
+            for (j = 0; j < 3; ++j) {
+                /* iterate planes/color components */
+                pj_uint8_t *p = NULL, c;
+                unsigned bar_width;
+
+                if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
+                    c = rgb_colors[i][j];
+                else
+                    c = yuv_colors[i][j];
+
+                bar_width = vafp->strides[j]/8;
+                p = first_lines[j] + bar_width*i;
+
+                /* draw this plane/color */
+                for (k = 0; k < bar_width; ++k)
+                    *p++ = c;
+            }
+        }
+    }
+}
+
+/* API: create stream */
+static pj_status_t cbar_factory_create_stream(pjmedia_vid_dev_factory *f,
+					      const pjmedia_vid_param *param,
+					      const pjmedia_vid_cb *cb,
+					      void *user_data,
+					      pjmedia_vid_stream **p_vid_strm)
+{
+    struct cbar_factory *cf = (struct cbar_factory*)f;
+    pj_pool_t *pool;
+    struct cbar_stream *strm;
+    const pjmedia_video_format_info *vfi;
+    pjmedia_video_apply_fmt_param vafp;
+    const struct cbar_fmt_info *cbfi;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(f && param && p_vid_strm, PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->fmt.type == PJMEDIA_TYPE_VIDEO &&
+		     param->fmt.detail_type == PJMEDIA_FORMAT_DETAIL_VIDEO,
+		     PJ_EINVAL);
+
+    pj_bzero(&vafp, sizeof(vafp));
+
+    vfi = pjmedia_get_video_format_info(NULL, param->fmt.id);
+    cbfi = get_cbar_fmt_info(param->fmt.id);
+    if (!vfi || !cbfi)
+        return PJMEDIA_EVID_BADFORMAT;
+
+    vafp.size = param->fmt.det.vid.size;
+    if (vfi->apply_fmt(vfi, &vafp) != PJ_SUCCESS)
+        return PJMEDIA_EVID_BADFORMAT;
+
+    /* Create and Initialize stream descriptor */
+    pool = pj_pool_create(cf->pf, "cbar-dev", 512, 512, NULL);
+    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+    strm = PJ_POOL_ZALLOC_T(pool, struct cbar_stream);
+    pj_memcpy(&strm->param, param, sizeof(*param));
+    strm->pool = pool;
+    pj_memcpy(&strm->vid_cb, cb, sizeof(*cb));
+    strm->user_data = user_data;
+    strm->vfi = vfi;
+    strm->cbfi = cbfi;
+    pj_memcpy(&strm->vafp, &vafp, sizeof(vafp));
+
+    for (i = 0; i < vfi->plane_cnt; ++i) {
+        strm->first_line[i] = pj_pool_alloc(pool, vafp.strides[i]);
+        pj_memset(strm->first_line[i], 255, vafp.strides[i]);
+    }
+
+    fill_first_line(strm->first_line, strm->cbfi, vfi, &strm->vafp);
+
+    /* Apply the remaining settings */
+/*    if (param->flags & PJMEDIA_VID_DEV_CAP_INPUT_SCALE) {
+	cbar_stream_set_cap(&strm->base,
+		            PJMEDIA_VID_DEV_CAP_INPUT_SCALE,
+                            &param->fmt);
+    }
+*/
+    /* Done */
+    strm->base.op = &stream_op;
+    *p_vid_strm = &strm->base;
+
+    return PJ_SUCCESS;
+}
+
+/* API: Get stream info. */
+static pj_status_t cbar_stream_get_param(pjmedia_vid_stream *s,
+					 pjmedia_vid_param *pi)
+{
+    struct cbar_stream *strm = (struct cbar_stream*)s;
+
+    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
+
+    pj_memcpy(pi, &strm->param, sizeof(*pi));
+
+/*    if (cbar_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_INPUT_SCALE,
+                            &pi->fmt.info_size) == PJ_SUCCESS)
+    {
+        pi->flags |= PJMEDIA_VID_DEV_CAP_INPUT_SCALE;
+    }
+*/
+    return PJ_SUCCESS;
+}
+
+/* API: get capability */
+static pj_status_t cbar_stream_get_cap(pjmedia_vid_stream *s,
+				       pjmedia_vid_dev_cap cap,
+				       void *pval)
+{
+    struct cbar_stream *strm = (struct cbar_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
+    {
+        return PJMEDIA_EVID_INVCAP;
+//	return PJ_SUCCESS;
+    } else {
+	return PJMEDIA_EVID_INVCAP;
+    }
+}
+
+/* API: set capability */
+static pj_status_t cbar_stream_set_cap(pjmedia_vid_stream *s,
+				       pjmedia_vid_dev_cap cap,
+				       const void *pval)
+{
+    struct cbar_stream *strm = (struct cbar_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
+    {
+	return PJ_SUCCESS;
+    }
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+static pj_status_t spectrum_run(struct cbar_stream *d, pj_uint8_t *p,
+                                pj_size_t size)
+{
+    unsigned i;
+    pj_uint8_t *ptr = p;
+    pj_time_val tv;
+
+    PJ_UNUSED_ARG(size);
+
+    /* Subsequent lines */
+    for (i=0; i<d->vfi->plane_cnt; ++i) {
+        pj_uint8_t *plane_end;
+
+        plane_end = ptr + d->vafp.plane_bytes[i];
+        while (ptr < plane_end) {
+            pj_memcpy(ptr, d->first_line[i], d->vafp.strides[i]);
+            ptr += d->vafp.strides[i]; 
+        }
+    }
+
+    /* blinking dot */
+    pj_gettimeofday(&tv);
+    if (tv.msec < 660) {
+	enum { DOT_SIZE = 8 };
+        pj_uint8_t dot_clr_rgb[3] = {255, 255, 255};
+        pj_uint8_t dot_clr_yuv[3] = {235, 128, 128};
+
+        if (d->vfi->plane_cnt == 1) {
+            for (i = 0; i < 3; ++i) {
+                pj_uint8_t *ptr;
+                unsigned j, k, inc_ptr;
+                pj_size_t dot_size = DOT_SIZE;
+
+                dot_size /= (d->cbfi->c_stride[i] * 8 / d->vfi->bpp);
+                inc_ptr = d->cbfi->c_stride[i];
+                for (j = 0; j < dot_size; ++j) {
+                    ptr = p + d->vafp.strides[0]*(dot_size+j+1) - 
+                          2*dot_size*inc_ptr + d->cbfi->c_offset[i];
+                    for (k = 0; k < dot_size; ++k) {
+                        if (d->vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
+                            *ptr = dot_clr_rgb[i];
+                        else
+                            *ptr = dot_clr_yuv[i];
+                        ptr += inc_ptr;
+                    }
+                }
+            }
+        } else {
+            pj_size_t offset_p = 0;
+
+            for (i = 0; i < 3; ++i) {
+                pj_uint8_t *ptr, c;
+                unsigned j;
+                pj_size_t dot_size = DOT_SIZE;
+
+                if (d->vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
+                    c = dot_clr_rgb[i];
+                else
+                    c = dot_clr_yuv[i];
+
+                dot_size /= (d->vafp.size.w / d->vafp.strides[i]);
+                ptr = p + offset_p + d->vafp.strides[i]*(dot_size+1) - 
+                      2*dot_size;
+                for (j = 0; j < dot_size; ++j) {
+                    pj_memset(ptr, c, dot_size);
+                    ptr += d->vafp.strides[i];
+                }
+                offset_p += d->vafp.plane_bytes[i];
+            }
+        }
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: Get frame from stream */
+static pj_status_t cbar_stream_get_frame(pjmedia_vid_stream *strm,
+                                         pjmedia_frame *frame)
+{
+    struct cbar_stream *stream = (struct cbar_stream*)strm;
+
+    return spectrum_run(stream, frame->buf, frame->size);
+}
+
+/* API: Start stream. */
+static pj_status_t cbar_stream_start(pjmedia_vid_stream *strm)
+{
+    struct cbar_stream *stream = (struct cbar_stream*)strm;
+
+    PJ_UNUSED_ARG(stream);
+
+    PJ_LOG(4, (THIS_FILE, "Starting cbar video stream"));
+
+    return PJ_SUCCESS;
+}
+
+/* API: Stop stream. */
+static pj_status_t cbar_stream_stop(pjmedia_vid_stream *strm)
+{
+    struct cbar_stream *stream = (struct cbar_stream*)strm;
+
+    PJ_UNUSED_ARG(stream);
+
+    PJ_LOG(4, (THIS_FILE, "Stopping cbar video stream"));
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Destroy stream. */
+static pj_status_t cbar_stream_destroy(pjmedia_vid_stream *strm)
+{
+    struct cbar_stream *stream = (struct cbar_stream*)strm;
+
+    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);
+
+    cbar_stream_stop(strm);
+
+    pj_pool_release(stream->pool);
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshow_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshow_dev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshow_dev.c	(revision 3392)
@@ -0,0 +1,903 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/os.h>
+#include <pj/unicode.h>
+
+#if PJMEDIA_VIDEO_DEV_HAS_DSHOW
+
+#ifdef _MSC_VER
+#   pragma warning(push, 3)
+#endif
+
+#include <windows.h>
+#define COBJMACROS
+#include <DShow.h>
+
+#ifdef _MSC_VER
+#   pragma warning(pop)
+#endif
+
+#pragma comment(lib, "Strmiids.lib")
+#pragma comment(lib, "Rpcrt4.lib")
+
+#define THIS_FILE		"dshow_dev.c"
+#define DEFAULT_WIDTH		640
+#define DEFAULT_HEIGHT		480
+#define DEFAULT_FPS		25
+
+typedef void (*input_callback)(void *user_data, IMediaSample *pMediaSample);
+typedef struct NullRenderer NullRenderer;
+IBaseFilter* NullRenderer_Create(input_callback input_cb,
+                                 void *user_data);
+typedef struct SourceFilter SourceFilter;
+IBaseFilter* SourceFilter_Create(SourceFilter **pSrc);
+HRESULT SourceFilter_Deliver(SourceFilter *src, void *buf, long size);
+void SourceFilter_SetBufferSize(SourceFilter *src, long size);
+
+typedef struct dshow_fmt_info
+{
+    pjmedia_format_id    pjmedia_format;
+    const GUID          *dshow_format;
+} dshow_fmt_info;
+
+static dshow_fmt_info dshow_fmts[] =
+{
+    {PJMEDIA_FORMAT_YUY2, &MEDIASUBTYPE_YUY2} ,
+    {PJMEDIA_FORMAT_RGB24, &MEDIASUBTYPE_RGB24} ,
+    {PJMEDIA_FORMAT_RGB32, &MEDIASUBTYPE_RGB32} ,
+};
+
+/* dshow_ device info */
+struct dshow_dev_info
+{
+    pjmedia_vid_dev_info	 info;
+    unsigned			 dev_id;
+    WCHAR                        display_name[192];
+};
+
+/* dshow_ factory */
+struct dshow_factory
+{
+    pjmedia_vid_dev_factory	 base;
+    pj_pool_t			*pool;
+    pj_pool_factory		*pf;
+
+    unsigned			 dev_count;
+    struct dshow_dev_info	*dev_info;
+};
+
+/* Video stream. */
+struct dshow_stream
+{
+    pjmedia_vid_stream	 base;		    /**< Base stream	       */
+    pjmedia_vid_param	 param;		    /**< Settings	       */
+    pj_pool_t           *pool;              /**< Memory pool.          */
+
+    pjmedia_vid_cb       vid_cb;            /**< Stream callback.     */
+    void                *user_data;         /**< Application data.     */
+
+    pj_bool_t            quit_flag;
+    pj_bool_t		 rend_thread_exited;
+    pj_bool_t		 cap_thread_exited;
+    pj_bool_t		 cap_thread_initialized;
+    pj_thread_desc	 cap_thread_desc;
+    pj_thread_t		*cap_thread;
+
+    struct dshow_graph
+    {
+        IFilterGraph        *filter_graph;
+        IMediaFilter        *media_filter;
+        SourceFilter        *csource_filter;
+        IBaseFilter         *source_filter;
+        IBaseFilter         *rend_filter;
+        AM_MEDIA_TYPE       *mediatype;
+    } dgraph[2];
+};
+
+
+/* Prototypes */
+static pj_status_t dshow_factory_init(pjmedia_vid_dev_factory *f);
+static pj_status_t dshow_factory_destroy(pjmedia_vid_dev_factory *f);
+static unsigned    dshow_factory_get_dev_count(pjmedia_vid_dev_factory *f);
+static pj_status_t dshow_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_dev_info *info);
+static pj_status_t dshow_factory_default_param(pj_pool_t *pool,
+                                               pjmedia_vid_dev_factory *f,
+					       unsigned index,
+					       pjmedia_vid_param *param);
+static pj_status_t dshow_factory_create_stream(pjmedia_vid_dev_factory *f,
+					       const pjmedia_vid_param *param,
+					       const pjmedia_vid_cb *cb,
+					       void *user_data,
+					       pjmedia_vid_stream **p_vid_strm);
+
+static pj_status_t dshow_stream_get_param(pjmedia_vid_stream *strm,
+					  pjmedia_vid_param *param);
+static pj_status_t dshow_stream_get_cap(pjmedia_vid_stream *strm,
+				        pjmedia_vid_dev_cap cap,
+				        void *value);
+static pj_status_t dshow_stream_set_cap(pjmedia_vid_stream *strm,
+				        pjmedia_vid_dev_cap cap,
+				        const void *value);
+static pj_status_t dshow_stream_start(pjmedia_vid_stream *strm);
+static pj_status_t dshow_stream_put_frame(pjmedia_vid_stream *strm,
+                                          const pjmedia_frame *frame);
+static pj_status_t dshow_stream_stop(pjmedia_vid_stream *strm);
+static pj_status_t dshow_stream_destroy(pjmedia_vid_stream *strm);
+
+/* Operations */
+static pjmedia_vid_dev_factory_op factory_op =
+{
+    &dshow_factory_init,
+    &dshow_factory_destroy,
+    &dshow_factory_get_dev_count,
+    &dshow_factory_get_dev_info,
+    &dshow_factory_default_param,
+    &dshow_factory_create_stream
+};
+
+static pjmedia_vid_stream_op stream_op =
+{
+    &dshow_stream_get_param,
+    &dshow_stream_get_cap,
+    &dshow_stream_set_cap,
+    &dshow_stream_start,
+    NULL,
+    &dshow_stream_put_frame,
+    &dshow_stream_stop,
+    &dshow_stream_destroy
+};
+
+
+/****************************************************************************
+ * Factory operations
+ */
+/*
+ * Init dshow_ video driver.
+ */
+pjmedia_vid_dev_factory* pjmedia_dshow_factory(pj_pool_factory *pf)
+{
+    struct dshow_factory *f;
+    pj_pool_t *pool;
+
+    pool = pj_pool_create(pf, "dshow video", 1000, 1000, NULL);
+    f = PJ_POOL_ZALLOC_T(pool, struct dshow_factory);
+    f->pf = pf;
+    f->pool = pool;
+    f->base.op = &factory_op;
+
+    return &f->base;
+}
+
+/* API: init factory */
+static pj_status_t dshow_factory_init(pjmedia_vid_dev_factory *f)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+    struct dshow_dev_info *ddi;
+    int dev_count = 0;
+    unsigned c, i;
+    ICreateDevEnum *dev_enum = NULL;
+    IEnumMoniker *enum_cat = NULL;
+    IMoniker *moniker = NULL;
+    HRESULT hr;
+    ULONG fetched;
+
+    df->dev_count = 0;
+
+    CoInitializeEx(NULL, COINIT_MULTITHREADED);
+
+    hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL,
+                          CLSCTX_INPROC_SERVER, &IID_ICreateDevEnum,
+                          (void**)&dev_enum);
+    if (FAILED(hr) ||
+        ICreateDevEnum_CreateClassEnumerator(dev_enum,
+            &CLSID_VideoInputDeviceCategory, &enum_cat, 0) != S_OK) 
+    {
+	PJ_LOG(4,(THIS_FILE, "Windows found no video input devices"));
+        if (dev_enum)
+            ICreateDevEnum_Release(dev_enum);
+	dev_count = 0;
+    } else {
+        while (IEnumMoniker_Next(enum_cat, 1, &moniker, &fetched) == S_OK) {
+            dev_count++;
+        }
+    }
+
+    /* Add renderer device */
+    dev_count += 1;
+    df->dev_info = (struct dshow_dev_info*)
+ 		   pj_pool_calloc(df->pool, dev_count,
+ 				  sizeof(struct dshow_dev_info));
+
+    if (dev_count > 1) {
+        IEnumMoniker_Reset(enum_cat);
+        while (IEnumMoniker_Next(enum_cat, 1, &moniker, &fetched) == S_OK) {
+            IPropertyBag *prop_bag;
+
+            hr = IMoniker_BindToStorage(moniker, 0, 0, &IID_IPropertyBag,
+                                        (void**)&prop_bag);
+            if (SUCCEEDED(hr)) {
+                VARIANT var_name;
+
+                VariantInit(&var_name);
+                hr = IPropertyBag_Read(prop_bag, L"FriendlyName",
+                                       &var_name, NULL);
+                if (SUCCEEDED(hr) && var_name.bstrVal) {
+                    WCHAR *wszDisplayName = NULL;
+
+                    ddi = &df->dev_info[df->dev_count++];
+                    pj_bzero(ddi, sizeof(*ddi));
+                    pj_unicode_to_ansi(var_name.bstrVal,
+                                       wcslen(var_name.bstrVal),
+                                       ddi->info.name,
+                                       sizeof(ddi->info.name));
+
+                    hr = IMoniker_GetDisplayName(moniker, NULL, NULL,
+                                                 &wszDisplayName);
+                    if (hr == S_OK && wszDisplayName) {
+                        pj_memcpy(ddi->display_name, wszDisplayName,
+                                  (wcslen(wszDisplayName)+1) * sizeof(WCHAR));
+                        CoTaskMemFree(wszDisplayName);
+                    }
+
+                    strncpy(ddi->info.driver, "dshow", 
+                            sizeof(ddi->info.driver));
+                    ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
+                    ddi->info.dir = PJMEDIA_DIR_CAPTURE;
+                    ddi->info.has_callback = PJ_TRUE;
+
+                    /* Set the device capabilities here */
+                    ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
+                    // TODO: Query the default width, height, fps, and
+                    // supported formats
+                }
+                VariantClear(&var_name);
+
+                IPropertyBag_Release(prop_bag);
+            }
+            IMoniker_Release(moniker);
+        }
+
+        IEnumMoniker_Release(enum_cat);
+        ICreateDevEnum_Release(dev_enum);
+    }
+
+    ddi = &df->dev_info[df->dev_count++];
+    pj_bzero(ddi, sizeof(*ddi));
+    strncpy(ddi->info.name,  "Video Mixing Renderer",
+            sizeof(ddi->info.name));
+    ddi->info.name[sizeof(ddi->info.name)-1] = '\0';
+    strncpy(ddi->info.driver, "dshow", sizeof(ddi->info.driver));
+    ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
+    ddi->info.dir = PJMEDIA_DIR_RENDER;
+    ddi->info.has_callback = PJ_FALSE;
+    ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
+
+    for (c = 0; c < df->dev_count; c++) {
+        ddi = &df->dev_info[c];
+        ddi->info.fmt_cnt = sizeof(dshow_fmts)/sizeof(dshow_fmts[0]);
+        ddi->info.fmt = (pjmedia_format*)
+                        pj_pool_calloc(df->pool, ddi->info.fmt_cnt,
+                                       sizeof(pjmedia_format));
+
+        for (i = 0; i < ddi->info.fmt_cnt; i++) {
+            pjmedia_format *fmt = &ddi->info.fmt[i];
+
+            if (ddi->info.dir == PJMEDIA_DIR_RENDER && i > 0)
+                break;
+            pjmedia_format_init_video(fmt, dshow_fmts[i].pjmedia_format, 
+				      DEFAULT_WIDTH, DEFAULT_HEIGHT, 
+				      DEFAULT_FPS, 1);
+        }
+    }
+
+//    TODO:
+//    ddi->info.caps = PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW;
+
+    PJ_LOG(4, (THIS_FILE, "DShow initialized, found %d devices:", 
+	       df->dev_count));
+    for (c = 0; c < df->dev_count; ++c) {
+	PJ_LOG(4, (THIS_FILE, " dev_id %d: %s (%s)", 
+	       c,
+	       df->dev_info[c].info.name,
+	       df->dev_info[c].info.dir & PJMEDIA_DIR_CAPTURE ?
+               "capture" : "render"));
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: destroy factory */
+static pj_status_t dshow_factory_destroy(pjmedia_vid_dev_factory *f)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+    pj_pool_t *pool = df->pool;
+
+    df->pool = NULL;
+    pj_pool_release(pool);
+
+    CoUninitialize();
+
+    return PJ_SUCCESS;
+}
+
+/* API: get number of devices */
+static unsigned dshow_factory_get_dev_count(pjmedia_vid_dev_factory *f)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+    return df->dev_count;
+}
+
+/* API: get device info */
+static pj_status_t dshow_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_dev_info *info)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+
+    PJ_ASSERT_RETURN(index < df->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_memcpy(info, &df->dev_info[index].info, sizeof(*info));
+
+    return PJ_SUCCESS;
+}
+
+/* API: create default device parameter */
+static pj_status_t dshow_factory_default_param(pj_pool_t *pool,
+                                               pjmedia_vid_dev_factory *f,
+					       unsigned index,
+					       pjmedia_vid_param *param)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+    struct dshow_dev_info *di = &df->dev_info[index];
+
+    PJ_ASSERT_RETURN(index < df->dev_count, PJMEDIA_EVID_INVDEV);
+
+    PJ_UNUSED_ARG(pool);
+
+    pj_bzero(param, sizeof(*param));
+    if (di->info.dir & PJMEDIA_DIR_CAPTURE_RENDER) {
+	param->dir = PJMEDIA_DIR_CAPTURE_RENDER;
+	param->cap_id = index;
+	param->rend_id = index;
+    } else if (di->info.dir & PJMEDIA_DIR_CAPTURE) {
+	param->dir = PJMEDIA_DIR_CAPTURE;
+	param->cap_id = index;
+	param->rend_id = PJMEDIA_VID_INVALID_DEV;
+    } else if (di->info.dir & PJMEDIA_DIR_RENDER) {
+	param->dir = PJMEDIA_DIR_RENDER;
+	param->rend_id = index;
+	param->cap_id = PJMEDIA_VID_INVALID_DEV;
+    } else {
+	return PJMEDIA_EVID_INVDEV;
+    }
+
+    /* Set the device capabilities here */
+    param->clock_rate = 9000;
+    param->frame_rate.num = 14;
+    param->frame_rate.denum = 1;
+    param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
+
+    pjmedia_format_copy(&param->fmt, &di->info.fmt[0]);
+
+    return PJ_SUCCESS;
+}
+
+static void input_cb(void *user_data, IMediaSample *pMediaSample)
+{
+    struct dshow_stream *strm = (struct dshow_stream*)user_data;
+    unsigned char *buffer;
+    pjmedia_frame frame;
+
+    if (strm->quit_flag) {
+        strm->cap_thread_exited = PJ_TRUE;
+        return;
+    }
+
+    if (strm->cap_thread_initialized == 0 || !pj_thread_is_registered())
+    {
+        pj_status_t status;
+
+	status = pj_thread_register("ds_cap", strm->cap_thread_desc, 
+				    &strm->cap_thread);
+        if (status != PJ_SUCCESS)
+            return;
+	strm->cap_thread_initialized = 1;
+	PJ_LOG(5,(THIS_FILE, "Capture thread started"));
+    }
+
+    IMediaSample_GetPointer(pMediaSample, &buffer);
+
+    frame.type = PJMEDIA_TYPE_VIDEO;
+    IMediaSample_GetPointer(pMediaSample, (BYTE **)&frame.buf);
+    frame.size = IMediaSample_GetActualDataLength(pMediaSample);
+    frame.bit_info = 0;
+    if (strm->vid_cb.capture_cb)
+        (*strm->vid_cb.capture_cb)(&strm->base, strm->user_data, &frame);
+}
+
+/* API: Put frame from stream */
+static pj_status_t dshow_stream_put_frame(pjmedia_vid_stream *strm,
+                                          const pjmedia_frame *frame)
+{
+    struct dshow_stream *stream = (struct dshow_stream*)strm;
+    unsigned i;
+
+    if (stream->quit_flag) {
+        stream->rend_thread_exited = PJ_TRUE;
+        return PJ_SUCCESS;
+    }
+
+    for (i = 0; i < 2; i++) {
+        if (stream->dgraph[i].csource_filter) {
+            HRESULT hr = SourceFilter_Deliver(stream->dgraph[i].csource_filter,
+                frame->buf, frame->size);
+
+            if (FAILED(hr)) {
+                return hr;
+            }
+            break;
+        }
+    }
+
+    return PJ_SUCCESS;
+}
+
+static dshow_fmt_info* get_dshow_format_info(pjmedia_format_id id)
+{
+    unsigned i;
+
+    for (i = 0; i < sizeof(dshow_fmts)/sizeof(dshow_fmts[0]); i++) {
+        if (dshow_fmts[i].pjmedia_format == id)
+            return &dshow_fmts[i];
+    }
+
+    return NULL;
+}
+
+static pj_status_t create_filter_graph(pjmedia_dir dir,
+                                       unsigned id,
+                                       struct dshow_factory *df,
+                                       struct dshow_stream *strm,
+                                       struct dshow_graph *graph)
+{
+    HRESULT hr;
+    IEnumPins *pEnum;
+    IPin *srcpin = NULL;
+    IPin *sinkpin = NULL;
+    AM_MEDIA_TYPE *mediatype= NULL, mtype;
+    VIDEOINFOHEADER *video_info, *vi = NULL;
+    pjmedia_video_format_detail *vfd;
+    const pjmedia_video_format_info *vfi;
+
+    vfi = pjmedia_get_video_format_info(pjmedia_video_format_mgr_instance(),
+                                        strm->param.fmt.id);
+    if (!vfi)
+        return PJMEDIA_EVID_BADFORMAT;
+
+    hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC,
+                          &IID_IFilterGraph, (LPVOID *)&graph->filter_graph);
+    if (FAILED(hr)) {
+        goto on_error;
+    }
+
+    hr = IFilterGraph_QueryInterface(graph->filter_graph, &IID_IMediaFilter,
+                                     (LPVOID *)&graph->media_filter);
+    if (FAILED(hr)) {
+        goto on_error;
+    }
+
+    if (dir == PJMEDIA_DIR_CAPTURE) {
+        IBindCtx *pbc;
+
+        hr = CreateBindCtx(0, &pbc);
+        if (SUCCEEDED (hr)) {
+            IMoniker *moniker;
+            DWORD pchEaten;
+
+            hr = MkParseDisplayName(pbc, 
+                                    df->dev_info[id].display_name,
+                                    &pchEaten, &moniker);
+            if (SUCCEEDED(hr)) {
+                hr = IMoniker_BindToObject(moniker, pbc, NULL,
+                                           &IID_IBaseFilter,
+                                           (LPVOID *)&graph->source_filter);
+                IMoniker_Release(moniker);
+            }
+            IBindCtx_Release(pbc);
+        }
+        if (FAILED(hr)) {
+            goto on_error;
+        }
+    } else {
+        graph->source_filter = SourceFilter_Create(&graph->csource_filter);
+    }
+
+    hr = IFilterGraph_AddFilter(graph->filter_graph, graph->source_filter,
+                                L"capture");
+    if (FAILED(hr)) {
+        goto on_error;
+    }
+
+    if (dir == PJMEDIA_DIR_CAPTURE) {
+        graph->rend_filter = NullRenderer_Create(input_cb, strm);
+    } else {
+        hr = CoCreateInstance(&CLSID_VideoMixingRenderer, NULL,
+                              CLSCTX_INPROC, &IID_IBaseFilter,
+                              (LPVOID *)&graph->rend_filter);
+        if (FAILED (hr)) {
+            goto on_error;
+        }
+    }
+
+    IBaseFilter_EnumPins(graph->rend_filter, &pEnum);
+    if (SUCCEEDED(hr)) {
+        // Loop through all the pins
+	IPin *pPin = NULL;
+
+        while (IEnumPins_Next(pEnum, 1, &pPin, NULL) == S_OK) {
+            PIN_DIRECTION pindirtmp;
+
+            hr = IPin_QueryDirection(pPin, &pindirtmp);
+            if (hr == S_OK && pindirtmp == PINDIR_INPUT) {
+                sinkpin = pPin;
+                break;
+            }
+	    IPin_Release(pPin);
+        }
+        IEnumPins_Release(pEnum);
+    }
+
+    vfd = pjmedia_format_get_video_format_detail(&strm->param.fmt, PJ_TRUE);
+
+    IBaseFilter_EnumPins(graph->source_filter, &pEnum);
+    if (SUCCEEDED(hr)) {
+        // Loop through all the pins
+	IPin *pPin = NULL;
+
+        while (IEnumPins_Next(pEnum, 1, &pPin, NULL) == S_OK) {
+            PIN_DIRECTION pindirtmp;
+            const GUID *dshow_format;
+                
+            dshow_format = get_dshow_format_info(strm->param.fmt.id)->
+                                                 dshow_format;
+
+            hr = IPin_QueryDirection(pPin, &pindirtmp);
+            if (hr != S_OK || pindirtmp != PINDIR_OUTPUT) {
+                if (SUCCEEDED(hr))
+                    IPin_Release(pPin);
+                continue;
+            }
+
+            if (dir == PJMEDIA_DIR_CAPTURE) {
+                IAMStreamConfig *streamcaps;
+
+                hr = IPin_QueryInterface(pPin, &IID_IAMStreamConfig,
+                                         (LPVOID *)&streamcaps);
+                if (SUCCEEDED(hr)) {
+                    VIDEO_STREAM_CONFIG_CAPS vscc;
+                    int i, isize, icount;
+
+                    IAMStreamConfig_GetNumberOfCapabilities(streamcaps,
+                                                            &icount, &isize);
+
+                    for (i = 0; i < icount; i++) {
+                        RPC_STATUS rpcstatus;
+
+                        hr = IAMStreamConfig_GetStreamCaps(streamcaps, i,
+                                                           &mediatype,
+                                                           (BYTE *)&vscc);
+                        if (FAILED (hr))
+                            continue;
+
+                        if (UuidCompare(&mediatype->subtype,
+                                        (UUID *)dshow_format,
+                                        &rpcstatus) == 0 &&
+                            rpcstatus == RPC_S_OK)
+                        {
+                            srcpin = pPin;
+                            graph->mediatype = mediatype;
+                            break;
+                        }
+                    }
+                    IAMStreamConfig_Release(streamcaps);
+                }
+            } else {
+                srcpin = pPin;
+                mediatype = graph->mediatype = &mtype;
+
+                memset (mediatype, 0, sizeof(AM_MEDIA_TYPE));
+                mediatype->majortype = MEDIATYPE_Video;
+                mediatype->subtype = *dshow_format;
+                mediatype->bFixedSizeSamples = TRUE;
+                mediatype->bTemporalCompression = FALSE;
+
+                vi = (VIDEOINFOHEADER *)
+                     CoTaskMemAlloc(sizeof(VIDEOINFOHEADER));
+                memset (vi, 0, sizeof(VIDEOINFOHEADER));
+                mediatype->formattype = FORMAT_VideoInfo;
+                mediatype->cbFormat = sizeof(VIDEOINFOHEADER);
+                mediatype->pbFormat = (BYTE *)vi;
+
+                vi->rcSource.bottom = vfd->size.h;
+                vi->rcSource.right = vfd->size.w;
+                vi->rcTarget.bottom = vfd->size.h;
+                vi->rcTarget.right = vfd->size.w;
+
+                vi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+                vi->bmiHeader.biPlanes = 1;
+                vi->bmiHeader.biBitCount = vfi->bpp;
+                vi->bmiHeader.biCompression = strm->param.fmt.id;
+            }
+            if (srcpin)
+                break;
+            IPin_Release(pPin);
+	}
+        IEnumPins_Release(pEnum);
+    }
+
+    if (!srcpin || !sinkpin || !mediatype) {
+        hr = S_FALSE;
+        goto on_error;
+    }
+    video_info = (VIDEOINFOHEADER *) mediatype->pbFormat;
+    video_info->bmiHeader.biWidth = vfd->size.w;
+    video_info->bmiHeader.biHeight = vfd->size.h;
+    if (vfd->fps.num != 0)
+        video_info->AvgTimePerFrame = (LONGLONG) (10000000 * 
+                                      vfd->fps.denum /
+                                      (double)vfd->fps.num);
+    video_info->bmiHeader.biSizeImage = DIBSIZE(video_info->bmiHeader);
+    mediatype->lSampleSize = DIBSIZE(video_info->bmiHeader);
+    if (graph->csource_filter)
+        SourceFilter_SetBufferSize(graph->csource_filter,
+                                   mediatype->lSampleSize);
+
+    hr = IFilterGraph_AddFilter(graph->filter_graph,
+                                (IBaseFilter *)graph->rend_filter,
+                                L"renderer");
+    if (FAILED(hr))
+        goto on_error;
+
+    hr = IFilterGraph_ConnectDirect(graph->filter_graph, srcpin, sinkpin,
+                                    mediatype);
+
+on_error:
+    if (srcpin)
+        IPin_Release(srcpin);
+    if (sinkpin)
+        IPin_Release(sinkpin);
+    if (vi)
+        CoTaskMemFree(vi);
+    if (FAILED(hr))
+        return hr;
+
+    return PJ_SUCCESS;
+}
+
+/* API: create stream */
+static pj_status_t dshow_factory_create_stream(pjmedia_vid_dev_factory *f,
+					       const pjmedia_vid_param *param,
+					       const pjmedia_vid_cb *cb,
+					       void *user_data,
+					       pjmedia_vid_stream **p_vid_strm)
+{
+    struct dshow_factory *df = (struct dshow_factory*)f;
+    pj_pool_t *pool;
+    struct dshow_stream *strm;
+    unsigned ngraph = 0;
+    pj_status_t status;
+
+    if (!get_dshow_format_info(param->fmt.id))
+        return PJMEDIA_EVID_BADFORMAT;
+
+    /* Create and Initialize stream descriptor */
+    pool = pj_pool_create(df->pf, "dshow-dev", 1000, 1000, NULL);
+    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+    strm = PJ_POOL_ZALLOC_T(pool, struct dshow_stream);
+    pj_memcpy(&strm->param, param, sizeof(*param));
+    strm->pool = pool;
+    pj_memcpy(&strm->vid_cb, cb, sizeof(*cb));
+    strm->user_data = user_data;
+
+    /* Create capture stream here */
+    if (param->dir & PJMEDIA_DIR_CAPTURE) {
+        status = create_filter_graph(PJMEDIA_DIR_CAPTURE, param->cap_id,
+                                     df, strm, &strm->dgraph[ngraph++]);
+        if (status != PJ_SUCCESS)
+            goto on_error;
+    }
+
+    /* Create render stream here */
+    if (param->dir & PJMEDIA_DIR_RENDER) {
+        status = create_filter_graph(PJMEDIA_DIR_RENDER, param->rend_id,
+                                     df, strm, &strm->dgraph[ngraph++]);
+        if (status != PJ_SUCCESS)
+            goto on_error;
+    }
+
+    /* Apply the remaining settings */
+    if (param->flags & PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) {
+	dshow_stream_set_cap(&strm->base,
+		            PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW,
+		            &param->window);
+    }
+
+    /* Done */
+    strm->base.op = &stream_op;
+    *p_vid_strm = &strm->base;
+
+    return PJ_SUCCESS;
+ 
+on_error:
+    dshow_stream_destroy((pjmedia_vid_stream *)strm);
+    return PJ_EUNKNOWN;
+}
+
+/* API: Get stream info. */
+static pj_status_t dshow_stream_get_param(pjmedia_vid_stream *s,
+					  pjmedia_vid_param *pi)
+{
+    struct dshow_stream *strm = (struct dshow_stream*)s;
+
+    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
+
+    pj_memcpy(pi, &strm->param, sizeof(*pi));
+
+    if (dshow_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW,
+			     &pi->window) == PJ_SUCCESS)
+    {
+        pi->flags |= PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: get capability */
+static pj_status_t dshow_stream_get_cap(pjmedia_vid_stream *s,
+				        pjmedia_vid_dev_cap cap,
+				        void *pval)
+{
+    struct dshow_stream *strm = (struct dshow_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW)
+    {
+	*(unsigned*)pval = 0;
+	return PJ_SUCCESS;
+    } else {
+	return PJMEDIA_EVID_INVCAP;
+    }
+}
+
+/* API: set capability */
+static pj_status_t dshow_stream_set_cap(pjmedia_vid_stream *s,
+				        pjmedia_vid_dev_cap cap,
+				        const void *pval)
+{
+    struct dshow_stream *strm = (struct dshow_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW)
+    {
+	// set renderer's window here
+	return PJ_SUCCESS;
+    }
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+/* API: Start stream. */
+static pj_status_t dshow_stream_start(pjmedia_vid_stream *strm)
+{
+    struct dshow_stream *stream = (struct dshow_stream*)strm;
+    unsigned i;
+
+    stream->quit_flag = PJ_FALSE;
+    stream->cap_thread_exited = PJ_FALSE;
+    stream->rend_thread_exited = PJ_FALSE;
+
+    for (i = 0; i < 2; i++) {
+        HRESULT hr;
+
+        if (!stream->dgraph[i].media_filter)
+            continue;
+        hr = IMediaFilter_Run(stream->dgraph[i].media_filter, 0);
+        if (FAILED(hr)) {
+            return hr;
+        }
+    }
+
+    PJ_LOG(4, (THIS_FILE, "Starting dshow video stream"));
+
+    return PJ_SUCCESS;
+}
+
+/* API: Stop stream. */
+static pj_status_t dshow_stream_stop(pjmedia_vid_stream *strm)
+{
+    struct dshow_stream *stream = (struct dshow_stream*)strm;
+    unsigned i;
+
+    stream->quit_flag = PJ_TRUE;
+    if (stream->cap_thread) {
+        for (i=0; !stream->cap_thread_exited && i<100; ++i)
+	    pj_thread_sleep(10);
+    }
+    for (i=0; !stream->rend_thread_exited && i<100; ++i)
+	pj_thread_sleep(10);
+
+    for (i = 0; i < 2; i++) {
+        if (!stream->dgraph[i].media_filter)
+            continue;
+        IMediaFilter_Stop(stream->dgraph[i].media_filter);
+    }
+
+    PJ_LOG(4, (THIS_FILE, "Stopping dshow video stream"));
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Destroy stream. */
+static pj_status_t dshow_stream_destroy(pjmedia_vid_stream *strm)
+{
+    struct dshow_stream *stream = (struct dshow_stream*)strm;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);
+
+    dshow_stream_stop(strm);
+
+    for (i = 0; i < 2; i++) {
+        if (stream->dgraph[i].source_filter) {
+            IBaseFilter_Release(stream->dgraph[i].source_filter);
+            stream->dgraph[i].source_filter = NULL;
+        }
+        if (stream->dgraph[i].rend_filter) {
+            IBaseFilter_Release(stream->dgraph[i].rend_filter);
+            stream->dgraph[i].rend_filter = NULL;
+        }
+        if (stream->dgraph[i].media_filter) {
+            IMediaFilter_Release(stream->dgraph[i].media_filter);
+            stream->dgraph[i].media_filter = NULL;
+        }
+        if (stream->dgraph[i].filter_graph) {
+            IFilterGraph_Release(stream->dgraph[i].filter_graph);
+            stream->dgraph[i].filter_graph = NULL;
+        }
+    }
+
+    pj_pool_release(stream->pool);
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* PJMEDIA_VIDEO_DEV_HAS_DSHOW */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshowclasses.cpp
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshowclasses.cpp	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/dshowclasses.cpp	(revision 3392)
@@ -0,0 +1,209 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#undef _DEBUG
+#undef DEBUG
+
+#include <streams.h>
+
+#pragma comment(lib, "Strmbase.lib")
+
+typedef void (*input_callback)(void *user_data, IMediaSample *pMediaSample);
+
+const GUID CLSID_NullRenderer = {0xF9168C5E, 0xCEB2, 0x4FAA, {0xB6, 0xBF,
+                                 0x32, 0x9B, 0xF3, 0x9F, 0xA1, 0xE4}};
+
+const GUID CLSID_SourceFilter = {0xF9168C5E, 0xCEB2, 0x4FAA, {0xB6, 0xBF,
+                                 0x32, 0x9B, 0xF3, 0x9F, 0xA1, 0xE5}};
+
+class NullRenderer: public CBaseRenderer
+{
+public:
+    NullRenderer(HRESULT *pHr);
+    virtual ~NullRenderer();
+
+    virtual HRESULT CheckMediaType(const CMediaType *pmt);
+    virtual HRESULT DoRenderSample(IMediaSample *pMediaSample);
+
+    input_callback  input_cb;
+    void           *user_data;
+};
+
+class OutputPin: public CBaseOutputPin
+{
+public:
+    OutputPin(CBaseFilter *pFilter, CCritSec *pLock, HRESULT *pHr);
+    ~OutputPin();
+
+    HRESULT Push(void *buf, long size);
+
+    virtual HRESULT CheckMediaType(const CMediaType *pmt);
+    virtual HRESULT DecideBufferSize(IMemAllocator *pAlloc, 
+                                     ALLOCATOR_PROPERTIES *ppropInputRequest);
+
+    long bufSize;
+};
+
+class SourceFilter: public CBaseFilter
+{
+public:
+    SourceFilter();
+    ~SourceFilter();
+
+    int GetPinCount();
+    CBasePin* GetPin(int n);
+
+protected:
+    CCritSec lock;
+    OutputPin* outPin;
+};
+
+OutputPin::OutputPin(CBaseFilter *pFilter, CCritSec *pLock, HRESULT *pHr):
+    CBaseOutputPin("OutputPin", pFilter, pLock, pHr, L"OutputPin")
+{
+}
+
+OutputPin::~OutputPin()
+{
+}
+
+HRESULT OutputPin::CheckMediaType(const CMediaType *pmt)
+{
+    return S_OK;
+}
+
+HRESULT OutputPin::DecideBufferSize(IMemAllocator *pAlloc, 
+                                    ALLOCATOR_PROPERTIES *ppropInputRequest)
+{
+    ALLOCATOR_PROPERTIES properties;
+
+    ppropInputRequest->cbBuffer = bufSize;
+    ppropInputRequest->cBuffers = 1;
+
+    /* First set the buffer descriptions we're interested in */
+    pAlloc->SetProperties(ppropInputRequest, &properties);
+
+    return S_OK;
+}
+
+HRESULT OutputPin::Push(void *buf, long size)
+{
+    HRESULT hr;
+    IMediaSample *pSample;
+    BYTE *dst_buf;
+
+    /**
+     * Hold the critical section here as the pin might get disconnected
+     * during the Deliver() method call.
+     */
+    m_pLock->Lock();
+
+    hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0);
+    if (FAILED(hr))
+        goto on_error;
+
+    pSample->GetPointer(&dst_buf);
+    memcpy(dst_buf, buf, size);
+    pSample->SetActualDataLength(size);
+
+    hr = Deliver(pSample);
+
+    pSample->Release();
+
+on_error:
+    m_pLock->Unlock();
+    return hr;
+}
+
+SourceFilter::SourceFilter(): CBaseFilter("SourceFilter", NULL, &lock, 
+                                          CLSID_SourceFilter)
+{
+    HRESULT hr;
+    outPin = new OutputPin(this, &lock, &hr);
+}
+
+SourceFilter::~SourceFilter()
+{
+}
+
+int SourceFilter::GetPinCount()
+{
+    return 1;
+}
+
+CBasePin* SourceFilter::GetPin(int n)
+{
+    return outPin;
+}
+
+NullRenderer::NullRenderer(HRESULT *pHr): CBaseRenderer(CLSID_NullRenderer,
+                                                        "NullRenderer",
+                                                        NULL, pHr)
+{
+    input_cb = NULL;
+}
+
+NullRenderer::~NullRenderer()
+{
+}
+
+HRESULT NullRenderer::CheckMediaType(const CMediaType *pmt)
+{
+    return S_OK;
+}
+
+HRESULT NullRenderer::DoRenderSample(IMediaSample *pMediaSample)
+{
+    if (input_cb)
+        input_cb(user_data, pMediaSample);
+
+    return S_OK;
+}
+
+extern "C" IBaseFilter* NullRenderer_Create(input_callback input_cb,
+                                             void *user_data)
+{
+    HRESULT hr;
+    NullRenderer *renderer = new NullRenderer(&hr);
+    renderer->AddRef();
+    renderer->input_cb = input_cb;
+    renderer->user_data = user_data;
+
+    return (CBaseFilter *)renderer;
+}
+
+extern "C" IBaseFilter* SourceFilter_Create(SourceFilter **pSrc)
+{
+    SourceFilter *src = new SourceFilter();
+    src->AddRef();
+    *pSrc = src;
+
+    return (CBaseFilter *)src;
+}
+
+extern "C" HRESULT SourceFilter_Deliver(SourceFilter *src,
+                                        void *buf, long size)
+{
+    return ((OutputPin *)src->GetPin(0))->Push(buf, size);
+}
+
+extern "C" void SourceFilter_SetBufferSize(SourceFilter *src,
+                                           long size)
+{
+    ((OutputPin *)src->GetPin(0))->bufSize = size;
+}
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/ffmpeg_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/ffmpeg_dev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/ffmpeg_dev.c	(revision 3392)
@@ -0,0 +1,494 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+
+/* Video device with ffmpeg backend, currently only capture devices are
+ * implemented.
+ *
+ * Issues:
+ * - no device enumeration (ffmpeg limitation), so this uses "host API" enum
+ *   instead
+ * - need stricter filter on "host API" enum, currently audio capture devs are
+ *   still listed.
+ * - no format enumeration, currently hardcoded to PJMEDIA_FORMAT_RGB24 only
+ * - tested on Vista only (vfw backend) with virtual cam
+ * - vfw backend produce bottom up pictures
+ * - using VS IDE, this cannot run under debugger!
+ */
+
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/os.h>
+#include <pj/unicode.h>
+
+#if PJMEDIA_VIDEO_DEV_HAS_FFMPEG
+
+#define THIS_FILE		"ffmpeg.c"
+
+#include "../pjmedia/ffmpeg_util.h"
+#include <libavdevice/avdevice.h>
+#include <libavformat/avformat.h>
+
+#define MAX_DEV_CNT     8
+
+typedef struct ffmpeg_dev_info
+{
+    pjmedia_vid_dev_info         base;
+    AVInputFormat               *host_api;
+    const char                  *def_devname;
+} ffmpeg_dev_info;
+
+
+typedef struct ffmpeg_factory
+{
+    pjmedia_vid_dev_factory	 base;
+    pj_pool_factory		*pf;
+    pj_pool_t                   *pool;
+    unsigned                     dev_count;
+    ffmpeg_dev_info              dev_info[MAX_DEV_CNT];
+} ffmpeg_factory;
+
+
+typedef struct ffmpeg_stream
+{
+    pjmedia_vid_stream           base;
+    ffmpeg_factory              *factory;
+    pj_pool_t                   *pool;
+    pjmedia_vid_param            param;
+    AVFormatContext             *ff_fmt_ctx;
+} ffmpeg_stream;
+
+
+/* Prototypes */
+static pj_status_t ffmpeg_factory_init(pjmedia_vid_dev_factory *f);
+static pj_status_t ffmpeg_factory_destroy(pjmedia_vid_dev_factory *f);
+static unsigned    ffmpeg_factory_get_dev_count(pjmedia_vid_dev_factory *f);
+static pj_status_t ffmpeg_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_dev_info *info);
+static pj_status_t ffmpeg_factory_default_param(pj_pool_t *pool,
+                                                pjmedia_vid_dev_factory *f,
+					        unsigned index,
+					        pjmedia_vid_param *param);
+static pj_status_t ffmpeg_factory_create_stream(pjmedia_vid_dev_factory *f,
+					       const pjmedia_vid_param *param,
+					       const pjmedia_vid_cb *cb,
+					       void *user_data,
+					       pjmedia_vid_stream **p_vid_strm);
+
+static pj_status_t ffmpeg_stream_get_param(pjmedia_vid_stream *strm,
+					  pjmedia_vid_param *param);
+static pj_status_t ffmpeg_stream_get_cap(pjmedia_vid_stream *strm,
+				        pjmedia_vid_dev_cap cap,
+				        void *value);
+static pj_status_t ffmpeg_stream_set_cap(pjmedia_vid_stream *strm,
+				        pjmedia_vid_dev_cap cap,
+				        const void *value);
+static pj_status_t ffmpeg_stream_start(pjmedia_vid_stream *strm);
+static pj_status_t ffmpeg_stream_get_frame(pjmedia_vid_stream *s,
+                                           pjmedia_frame *frame);
+static pj_status_t ffmpeg_stream_stop(pjmedia_vid_stream *strm);
+static pj_status_t ffmpeg_stream_destroy(pjmedia_vid_stream *strm);
+
+/* Operations */
+static pjmedia_vid_dev_factory_op factory_op =
+{
+    &ffmpeg_factory_init,
+    &ffmpeg_factory_destroy,
+    &ffmpeg_factory_get_dev_count,
+    &ffmpeg_factory_get_dev_info,
+    &ffmpeg_factory_default_param,
+    &ffmpeg_factory_create_stream
+};
+
+static pjmedia_vid_stream_op stream_op =
+{
+    &ffmpeg_stream_get_param,
+    &ffmpeg_stream_get_cap,
+    &ffmpeg_stream_set_cap,
+    &ffmpeg_stream_start,
+    &ffmpeg_stream_get_frame,
+    NULL,
+    &ffmpeg_stream_stop,
+    &ffmpeg_stream_destroy
+};
+
+
+static void print_ffmpeg_err(int err)
+{
+    char errbuf[512];
+    if (av_strerror(err, errbuf, sizeof(errbuf)) >= 0)
+        PJ_LOG(1, (THIS_FILE, "ffmpeg err %d: %s", err, errbuf));
+
+}
+
+static void print_ffmpeg_log(void* ptr, int level, const char* fmt, va_list vl)
+{
+    PJ_UNUSED_ARG(ptr);
+    PJ_UNUSED_ARG(level);
+    vfprintf(stdout, fmt, vl);
+}
+
+
+static pj_status_t ffmpeg_capture_open(AVFormatContext **ctx,
+                                       AVInputFormat *ifmt,
+                                       const char *dev_name,
+                                       const pjmedia_vid_param *param)
+{
+    AVFormatParameters fp;
+    pjmedia_video_format_detail *fmt_detail;
+    int err;
+
+    PJ_ASSERT_RETURN(ctx && ifmt && dev_name && param, PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->fmt.detail_type == PJMEDIA_FORMAT_DETAIL_VIDEO,
+                     PJ_EINVAL);
+
+    fmt_detail = (pjmedia_video_format_detail*)param->fmt.detail;
+
+    /* Init ffmpeg format context */
+    *ctx = avformat_alloc_context();
+
+    /* Init ffmpeg format param */
+    pj_bzero(&fp, sizeof(fp));
+    fp.prealloced_context = 1;
+    fp.width = fmt_detail->size.w;
+    fp.height = fmt_detail->size.h;
+    fp.pix_fmt = PIX_FMT_BGR24;
+    fp.time_base.num = param->frame_rate.denum;
+    fp.time_base.den = param->frame_rate.num;
+
+    /* Open capture stream */
+    err = av_open_input_stream(ctx, NULL, dev_name, ifmt, &fp);
+    if (err < 0) {
+        *ctx = NULL; /* ffmpeg freed its states on failure, do we must too */
+        print_ffmpeg_err(err);
+        return PJ_EUNKNOWN;
+    }
+
+    return PJ_SUCCESS;
+}
+
+static void ffmpeg_capture_close(AVFormatContext *ctx)
+{
+    if (ctx)
+        av_close_input_stream(ctx);
+}
+
+
+/****************************************************************************
+ * Factory operations
+ */
+/*
+ * Init ffmpeg_ video driver.
+ */
+pjmedia_vid_dev_factory* pjmedia_ffmpeg_factory(pj_pool_factory *pf)
+{
+    ffmpeg_factory *f;
+    pj_pool_t *pool;
+
+    pool = pj_pool_create(pf, "ffmpeg_cap_dev", 1000, 1000, NULL);
+    f = PJ_POOL_ZALLOC_T(pool, ffmpeg_factory);
+
+    f->pool = pool;
+    f->pf = pf;
+    f->base.op = &factory_op;
+
+    avdevice_register_all();
+
+    return &f->base;
+}
+
+
+/* API: init factory */
+static pj_status_t ffmpeg_factory_init(pjmedia_vid_dev_factory *f)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+    AVInputFormat *p;
+    ffmpeg_dev_info *info;
+
+    av_log_set_callback(&print_ffmpeg_log);
+    av_log_set_level(AV_LOG_DEBUG);
+
+    /* TODO: this should enumerate devices, now it enumerates host APIs */
+    ff->dev_count = 0;
+    p = av_iformat_next(NULL);
+    while (p) {
+        if (p->flags & AVFMT_NOFILE) {
+            unsigned i;
+
+            info = &ff->dev_info[ff->dev_count++];
+            pj_bzero(info, sizeof(*info));
+            pj_ansi_strncpy(info->base.name, "default", 
+                            sizeof(info->base.name));
+            pj_ansi_snprintf(info->base.driver, sizeof(info->base.driver),
+                             "%s (ffmpeg)", p->name);
+            info->base.dir = PJMEDIA_DIR_CAPTURE;
+            info->base.has_callback = PJ_FALSE;
+
+            info->host_api = p;
+
+#if defined(PJ_WIN32) && PJ_WIN32!=0
+            info->def_devname = "0";
+#elif defined(PJ_LINUX) && PJ_LINUX!=0
+            info->def_devname = "/dev/video0";
+#endif
+
+            /* Set supported formats, currently hardcoded to RGB24 only */
+            info->base.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
+            info->base.fmt_cnt = 1;
+            info->base.fmt = (pjmedia_format*)
+ 		             pj_pool_calloc(ff->pool, info->base.fmt_cnt,
+ 				            sizeof(pjmedia_format));
+            for (i = 0; i < info->base.fmt_cnt; ++i) {
+                pjmedia_format *fmt = &info->base.fmt[i];
+
+                fmt->id = PJMEDIA_FORMAT_RGB24;
+                fmt->type = PJMEDIA_TYPE_VIDEO;
+                fmt->detail_type = PJMEDIA_FORMAT_DETAIL_NONE;
+            }
+        }
+        p = av_iformat_next(p);
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: destroy factory */
+static pj_status_t ffmpeg_factory_destroy(pjmedia_vid_dev_factory *f)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+
+    ff->dev_count = 0;
+
+    return PJ_SUCCESS;
+}
+
+/* API: get number of devices */
+static unsigned ffmpeg_factory_get_dev_count(pjmedia_vid_dev_factory *f)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+    return ff->dev_count;
+}
+
+/* API: get device info */
+static pj_status_t ffmpeg_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					      unsigned index,
+					      pjmedia_vid_dev_info *info)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+
+    PJ_ASSERT_RETURN(index < ff->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_memcpy(info, &ff->dev_info[index].base, sizeof(*info));
+
+    return PJ_SUCCESS;
+}
+
+/* API: create default device parameter */
+static pj_status_t ffmpeg_factory_default_param(pj_pool_t *pool,
+                                                pjmedia_vid_dev_factory *f,
+					        unsigned index,
+					        pjmedia_vid_param *param)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+    ffmpeg_dev_info *info;
+    pjmedia_video_format_detail *fmt_detail;
+
+    PJ_ASSERT_RETURN(index < ff->dev_count, PJMEDIA_EVID_INVDEV);
+    info = &ff->dev_info[index];
+
+    pj_bzero(param, sizeof(*param));
+    param->dir = PJMEDIA_DIR_CAPTURE;
+    param->cap_id = index;
+    param->rend_id = PJMEDIA_VID_INVALID_DEV;
+    param->clock_rate = 0;
+
+    /* Set the device capabilities here */
+    param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
+    pj_memcpy(&param->fmt, &info->base.fmt[0], sizeof(param->fmt));
+    param->clock_rate = 90000;
+    pjmedia_format_init_video(pool, &param->fmt, 320, 240, 25, 1,
+                              0, 0);
+    fmt_detail = (pjmedia_video_format_detail*)param->fmt.detail;
+    param->frame_rate.num = fmt_detail->fps.num;
+    param->frame_rate.denum = fmt_detail->fps.denum;
+
+    return PJ_SUCCESS;
+}
+
+
+
+/* API: create stream */
+static pj_status_t ffmpeg_factory_create_stream(pjmedia_vid_dev_factory *f,
+					       const pjmedia_vid_param *param,
+					       const pjmedia_vid_cb *cb,
+					       void *user_data,
+					       pjmedia_vid_stream **p_vid_strm)
+{
+    ffmpeg_factory *ff = (ffmpeg_factory*)f;
+    pj_pool_t *pool;
+    ffmpeg_stream *strm;
+
+    PJ_ASSERT_RETURN(f && param && p_vid_strm, PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->dir == PJMEDIA_DIR_CAPTURE, PJ_EINVAL);
+    PJ_ASSERT_RETURN((unsigned)param->cap_id < ff->dev_count, PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->fmt.detail_type == PJMEDIA_FORMAT_DETAIL_VIDEO &&
+                     param->fmt.detail, PJ_EINVAL);
+
+    PJ_UNUSED_ARG(cb);
+    PJ_UNUSED_ARG(user_data);
+
+    /* Create and Initialize stream descriptor */
+    pool = pj_pool_create(ff->pf, "ffmpeg-dev", 1000, 1000, NULL);
+    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+    strm = PJ_POOL_ZALLOC_T(pool, struct ffmpeg_stream);
+    strm->factory = (ffmpeg_factory*)f;
+    strm->pool = pool;
+    pj_memcpy(&strm->param, param, sizeof(*param));
+
+    /* Done */
+    strm->base.op = &stream_op;
+    *p_vid_strm = &strm->base;
+
+    return PJ_SUCCESS;
+}
+
+/* API: Get stream info. */
+static pj_status_t ffmpeg_stream_get_param(pjmedia_vid_stream *s,
+					   pjmedia_vid_param *pi)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+
+    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
+
+    pj_memcpy(pi, &strm->param, sizeof(*pi));
+
+    return PJ_SUCCESS;
+}
+
+/* API: get capability */
+static pj_status_t ffmpeg_stream_get_cap(pjmedia_vid_stream *s,
+				        pjmedia_vid_dev_cap cap,
+				        void *pval)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+    PJ_UNUSED_ARG(cap);
+    PJ_UNUSED_ARG(pval);
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+/* API: set capability */
+static pj_status_t ffmpeg_stream_set_cap(pjmedia_vid_stream *s,
+				        pjmedia_vid_dev_cap cap,
+				        const void *pval)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+    PJ_UNUSED_ARG(cap);
+    PJ_UNUSED_ARG(pval);
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+
+/* API: Start stream. */
+static pj_status_t ffmpeg_stream_start(pjmedia_vid_stream *s)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+    ffmpeg_dev_info *info;
+    pj_status_t status;
+
+    info = &strm->factory->dev_info[strm->param.cap_id];
+
+    PJ_LOG(4, (THIS_FILE, "Starting ffmpeg capture stream"));
+
+    status = ffmpeg_capture_open(&strm->ff_fmt_ctx, info->host_api,
+                                 info->def_devname, &strm->param);
+    if (status != PJ_SUCCESS) {
+        /* must set ffmpeg states to NULL on any failure */
+        strm->ff_fmt_ctx = NULL;
+    }
+
+    return status;
+}
+
+
+/* API: Get frame from stream */
+static pj_status_t ffmpeg_stream_get_frame(pjmedia_vid_stream *s,
+                                           pjmedia_frame *frame)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+    AVPacket p;
+    int err;
+
+    err = av_read_frame(strm->ff_fmt_ctx, &p);
+    if (err < 0) {
+        print_ffmpeg_err(err);
+        return PJ_EUNKNOWN;
+    }
+
+    pj_bzero(frame, sizeof(*frame));
+    frame->type = PJMEDIA_FRAME_TYPE_VIDEO;
+    frame->buf = p.data;
+    frame->size = p.size;
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Stop stream. */
+static pj_status_t ffmpeg_stream_stop(pjmedia_vid_stream *s)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+
+    PJ_LOG(4, (THIS_FILE, "Stopping ffmpeg capture stream"));
+
+    ffmpeg_capture_close(strm->ff_fmt_ctx);
+    strm->ff_fmt_ctx = NULL;
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Destroy stream. */
+static pj_status_t ffmpeg_stream_destroy(pjmedia_vid_stream *s)
+{
+    ffmpeg_stream *strm = (ffmpeg_stream*)s;
+
+    PJ_ASSERT_RETURN(strm != NULL, PJ_EINVAL);
+
+    ffmpeg_stream_stop(s);
+
+    pj_pool_release(strm->pool);
+
+    return PJ_SUCCESS;
+}
+
+#ifdef _MSC_VER
+#   pragma comment( lib, "avdevice.lib")
+#   pragma comment( lib, "avformat.lib")
+#   pragma comment( lib, "avutil.lib")
+#endif
+
+#endif	/* PJMEDIA_VIDEO_DEV_HAS_FFMPEG */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c	(revision 3392)
@@ -0,0 +1,708 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia/converter.h>
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/os.h>
+
+#if PJMEDIA_VIDEO_DEV_HAS_SDL
+
+#include <SDL.h>
+
+#define THIS_FILE		"sdl_dev.c"
+#define DEFAULT_CLOCK_RATE	90000
+#define DEFAULT_WIDTH		640
+#define DEFAULT_HEIGHT		480
+#define DEFAULT_FPS		25
+
+
+typedef struct sdl_fmt_info
+{
+    pjmedia_format_id   fmt_id;
+    Uint32              sdl_format;
+    Uint32              Rmask;
+    Uint32              Gmask;
+    Uint32              Bmask;
+    Uint32              Amask;
+} sdl_fmt_info;
+
+static sdl_fmt_info sdl_fmts[] =
+{
+#if PJ_IS_BIG_ENDIAN
+    {PJMEDIA_FORMAT_RGBA,  0, 0xFF000000, 0xFF0000, 0xFF00, 0xFF} ,
+    {PJMEDIA_FORMAT_RGB24, 0, 0xFF0000, 0xFF00, 0xFF, 0} ,
+    {PJMEDIA_FORMAT_BGRA,  0, 0xFF00, 0xFF0000, 0xFF000000, 0xFF} ,
+#else
+    {PJMEDIA_FORMAT_RGBA,  0, 0xFF, 0xFF00, 0xFF0000, 0xFF000000} ,
+    {PJMEDIA_FORMAT_RGB24, 0, 0xFF, 0xFF00, 0xFF0000, 0} ,
+    {PJMEDIA_FORMAT_BGRA,  0, 0xFF0000, 0xFF00, 0xFF, 0xFF000000} ,
+#endif
+
+    {PJMEDIA_FORMAT_DIB  , 0, 0xFF0000, 0xFF00, 0xFF, 0} ,
+
+    {PJMEDIA_FORMAT_YUY2, SDL_YUY2_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_UYVY, SDL_UYVY_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_YVYU, SDL_YVYU_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_I420, SDL_IYUV_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_YV12, SDL_YV12_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_I420JPEG, SDL_IYUV_OVERLAY, 0, 0, 0, 0} ,
+    {PJMEDIA_FORMAT_I422JPEG, SDL_YV12_OVERLAY, 0, 0, 0, 0} ,
+};
+
+/* sdl_ device info */
+struct sdl_dev_info
+{
+    pjmedia_vid_dev_info	 info;
+};
+
+/* sdl_ factory */
+struct sdl_factory
+{
+    pjmedia_vid_dev_factory	 base;
+    pj_pool_t			*pool;
+    pj_pool_factory		*pf;
+
+    unsigned			 dev_count;
+    struct sdl_dev_info	        *dev_info;
+};
+
+/* Video stream. */
+struct sdl_stream
+{
+    pjmedia_vid_stream	 base;		    /**< Base stream	       */
+    pjmedia_vid_param	 param;		    /**< Settings	       */
+    pj_pool_t           *pool;              /**< Memory pool.          */
+
+    pjmedia_vid_cb       vid_cb;            /**< Stream callback.      */
+    void                *user_data;         /**< Application data.     */
+
+    pj_thread_t         *sdl_thread;        /**< SDL thread.           */
+    pj_bool_t            is_quitting;
+    pj_bool_t            is_running;
+    pj_bool_t            render_exited;
+    pj_status_t          status;
+
+    SDL_Rect             rect;              /**< Display rectangle.    */
+    SDL_Surface         *screen;            /**< Display screen.       */
+    SDL_Surface         *surf;              /**< RGB surface.          */
+    SDL_Overlay         *overlay;           /**< YUV overlay.          */
+
+    /* For frame conversion */
+    pjmedia_converter       *conv;
+    pjmedia_conversion_param conv_param;
+    pjmedia_frame            conv_buf;
+
+    pjmedia_video_apply_fmt_param vafp;
+};
+
+
+/* Prototypes */
+static pj_status_t sdl_factory_init(pjmedia_vid_dev_factory *f);
+static pj_status_t sdl_factory_destroy(pjmedia_vid_dev_factory *f);
+static unsigned    sdl_factory_get_dev_count(pjmedia_vid_dev_factory *f);
+static pj_status_t sdl_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					    unsigned index,
+					    pjmedia_vid_dev_info *info);
+static pj_status_t sdl_factory_default_param(pj_pool_t *pool,
+                                             pjmedia_vid_dev_factory *f,
+					     unsigned index,
+					     pjmedia_vid_param *param);
+static pj_status_t sdl_factory_create_stream(pjmedia_vid_dev_factory *f,
+					     const pjmedia_vid_param *param,
+					     const pjmedia_vid_cb *cb,
+					     void *user_data,
+					     pjmedia_vid_stream **p_vid_strm);
+
+static pj_status_t sdl_stream_get_param(pjmedia_vid_stream *strm,
+					pjmedia_vid_param *param);
+static pj_status_t sdl_stream_get_cap(pjmedia_vid_stream *strm,
+				      pjmedia_vid_dev_cap cap,
+				      void *value);
+static pj_status_t sdl_stream_set_cap(pjmedia_vid_stream *strm,
+				      pjmedia_vid_dev_cap cap,
+				      const void *value);
+static pj_status_t sdl_stream_put_frame(pjmedia_vid_stream *strm,
+                                        const pjmedia_frame *frame);
+static pj_status_t sdl_stream_start(pjmedia_vid_stream *strm);
+static pj_status_t sdl_stream_stop(pjmedia_vid_stream *strm);
+static pj_status_t sdl_stream_destroy(pjmedia_vid_stream *strm);
+
+/* Operations */
+static pjmedia_vid_dev_factory_op factory_op =
+{
+    &sdl_factory_init,
+    &sdl_factory_destroy,
+    &sdl_factory_get_dev_count,
+    &sdl_factory_get_dev_info,
+    &sdl_factory_default_param,
+    &sdl_factory_create_stream
+};
+
+static pjmedia_vid_stream_op stream_op =
+{
+    &sdl_stream_get_param,
+    &sdl_stream_get_cap,
+    &sdl_stream_set_cap,
+    &sdl_stream_start,
+    NULL,
+    &sdl_stream_put_frame,
+    &sdl_stream_stop,
+    &sdl_stream_destroy
+};
+
+
+/****************************************************************************
+ * Factory operations
+ */
+/*
+ * Init sdl_ video driver.
+ */
+pjmedia_vid_dev_factory* pjmedia_sdl_factory(pj_pool_factory *pf)
+{
+    struct sdl_factory *f;
+    pj_pool_t *pool;
+
+    pool = pj_pool_create(pf, "sdl video", 1000, 1000, NULL);
+    f = PJ_POOL_ZALLOC_T(pool, struct sdl_factory);
+    f->pf = pf;
+    f->pool = pool;
+    f->base.op = &factory_op;
+
+    return &f->base;
+}
+
+
+/* API: init factory */
+static pj_status_t sdl_factory_init(pjmedia_vid_dev_factory *f)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+    struct sdl_dev_info *ddi;
+    unsigned i;
+
+    sf->dev_count = 1;
+    sf->dev_info = (struct sdl_dev_info*)
+ 		   pj_pool_calloc(sf->pool, sf->dev_count,
+ 				  sizeof(struct sdl_dev_info));
+
+    ddi = &sf->dev_info[0];
+    pj_bzero(ddi, sizeof(*ddi));
+    strncpy(ddi->info.name, "SDL renderer", sizeof(ddi->info.name));
+    ddi->info.name[sizeof(ddi->info.name)-1] = '\0';
+    strncpy(ddi->info.driver, "SDL", sizeof(ddi->info.driver));
+    ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
+    ddi->info.dir = PJMEDIA_DIR_RENDER;
+    ddi->info.has_callback = PJ_FALSE;
+    ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT |
+                     PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE;
+
+    ddi->info.fmt_cnt = PJ_ARRAY_SIZE(sdl_fmts);
+    ddi->info.fmt = (pjmedia_format*)
+ 		    pj_pool_calloc(sf->pool, ddi->info.fmt_cnt,
+ 				   sizeof(pjmedia_format));
+    for (i = 0; i < ddi->info.fmt_cnt; i++) {
+        pjmedia_format *fmt = &ddi->info.fmt[i];
+        pjmedia_format_init_video(fmt, sdl_fmts[i].fmt_id,
+				  DEFAULT_WIDTH, DEFAULT_HEIGHT,
+				  DEFAULT_FPS, 1);
+    }
+
+    PJ_LOG(4, (THIS_FILE, "SDL initialized"));
+
+    return PJ_SUCCESS;
+}
+
+/* API: destroy factory */
+static pj_status_t sdl_factory_destroy(pjmedia_vid_dev_factory *f)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+    pj_pool_t *pool = sf->pool;
+
+    sf->pool = NULL;
+    pj_pool_release(pool);
+
+    return PJ_SUCCESS;
+}
+
+/* API: get number of devices */
+static unsigned sdl_factory_get_dev_count(pjmedia_vid_dev_factory *f)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+    return sf->dev_count;
+}
+
+/* API: get device info */
+static pj_status_t sdl_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					    unsigned index,
+					    pjmedia_vid_dev_info *info)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+
+    PJ_ASSERT_RETURN(index < sf->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_memcpy(info, &sf->dev_info[index].info, sizeof(*info));
+
+    return PJ_SUCCESS;
+}
+
+/* API: create default device parameter */
+static pj_status_t sdl_factory_default_param(pj_pool_t *pool,
+                                             pjmedia_vid_dev_factory *f,
+					     unsigned index,
+					     pjmedia_vid_param *param)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+    struct sdl_dev_info *di = &sf->dev_info[index];
+
+    PJ_ASSERT_RETURN(index < sf->dev_count, PJMEDIA_EVID_INVDEV);
+    
+    PJ_UNUSED_ARG(pool);
+
+    pj_bzero(param, sizeof(*param));
+    if (di->info.dir & PJMEDIA_DIR_CAPTURE_RENDER) {
+	param->dir = PJMEDIA_DIR_CAPTURE_RENDER;
+	param->cap_id = index;
+	param->rend_id = index;
+    } else if (di->info.dir & PJMEDIA_DIR_CAPTURE) {
+	param->dir = PJMEDIA_DIR_CAPTURE;
+	param->cap_id = index;
+	param->rend_id = PJMEDIA_VID_INVALID_DEV;
+    } else if (di->info.dir & PJMEDIA_DIR_RENDER) {
+	param->dir = PJMEDIA_DIR_RENDER;
+	param->rend_id = index;
+	param->cap_id = PJMEDIA_VID_INVALID_DEV;
+    } else {
+	return PJMEDIA_EVID_INVDEV;
+    }
+
+    /* Set the device capabilities here */
+    param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
+    param->fmt.type = PJMEDIA_TYPE_VIDEO;
+    param->clock_rate = DEFAULT_CLOCK_RATE;
+    param->frame_rate.num = DEFAULT_FPS;
+    param->frame_rate.denum = 1;
+    pjmedia_format_init_video(&param->fmt, sdl_fmts[0].fmt_id,
+			      DEFAULT_WIDTH, DEFAULT_HEIGHT,
+			      DEFAULT_FPS, 1);
+
+    return PJ_SUCCESS;
+}
+
+static sdl_fmt_info* get_sdl_format_info(pjmedia_format_id id)
+{
+    unsigned i;
+
+    for (i = 0; i < sizeof(sdl_fmts)/sizeof(sdl_fmts[0]); i++) {
+        if (sdl_fmts[i].fmt_id == id)
+            return &sdl_fmts[i];
+    }
+
+    return NULL;
+}
+
+static int create_sdl_thread(void * data)
+{
+    struct sdl_stream *strm = (struct sdl_stream*)data;
+    sdl_fmt_info *sdl_info = get_sdl_format_info(strm->param.fmt.id);
+    const pjmedia_video_format_info *vfi;
+    pjmedia_video_format_detail *vfd;
+
+    vfi = pjmedia_get_video_format_info(pjmedia_video_format_mgr_instance(),
+                                        strm->param.fmt.id);
+    if (!vfi || !sdl_info) {
+        strm->status = PJMEDIA_EVID_BADFORMAT;
+        return strm->status;
+    }
+
+    strm->vafp.size = strm->param.fmt.det.vid.size;
+    strm->vafp.buffer = NULL;
+    if (vfi->apply_fmt(vfi, &strm->vafp) != PJ_SUCCESS) {
+        strm->status = PJMEDIA_EVID_BADFORMAT;
+        return strm->status;
+    }
+
+    /* Initialize the SDL library */
+    if (SDL_Init(SDL_INIT_VIDEO)) {
+        PJ_LOG(4, (THIS_FILE, "Cannot initialize SDL"));
+        strm->status = PJMEDIA_EVID_INIT;
+        return strm->status;
+    }
+
+    vfd = pjmedia_format_get_video_format_detail(&strm->param.fmt, PJ_TRUE);
+    strm->rect.x = strm->rect.y = 0;
+    strm->rect.w = (Uint16)vfd->size.w;
+    strm->rect.h = (Uint16)vfd->size.h;
+
+    /* Initialize the display, requesting a software surface */
+    strm->screen = SDL_SetVideoMode(strm->rect.w, strm->rect.h,
+                                    0, SDL_RESIZABLE | SDL_SWSURFACE);
+    if (strm->screen == NULL) {
+        strm->status = PJMEDIA_EVID_SYSERR;
+        return strm->status;
+    }
+    SDL_WM_SetCaption("pjmedia-SDL video", NULL);
+
+    if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB) {
+        strm->surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
+            strm->rect.w, strm->rect.h,
+            vfi->bpp,
+            sdl_info->Rmask,
+            sdl_info->Gmask,
+            sdl_info->Bmask,
+            sdl_info->Amask);
+        if (strm->surf == NULL) {
+            strm->status = PJMEDIA_EVID_SYSERR;
+            return strm->status;
+        }
+    } else if (vfi->color_model == PJMEDIA_COLOR_MODEL_YUV) {
+        strm->overlay = SDL_CreateYUVOverlay(strm->rect.w, strm->rect.h,
+            sdl_info->sdl_format,
+            strm->screen);
+        if (strm->overlay == NULL) {
+            strm->status = PJMEDIA_EVID_SYSERR;
+            return strm->status;
+        }
+    }
+
+    while(!strm->is_quitting) {
+        SDL_Event sevent;
+        pjmedia_vid_event pevent;
+
+        while (SDL_WaitEvent(&sevent)) {
+            pj_bzero(&pevent, sizeof(pevent));
+
+            switch(sevent.type) {
+		case SDL_USEREVENT:
+		    return 0;
+                case SDL_MOUSEBUTTONDOWN:
+                    pevent.event_type = PJMEDIA_EVENT_MOUSEBUTTONDOWN;
+                    if (strm->vid_cb.on_event_cb)
+                        if ((*strm->vid_cb.on_event_cb)(&strm->base,
+                                                       strm->user_data,
+                                                       &pevent) != PJ_SUCCESS)
+                        {
+                            /* Application wants us to ignore this event */
+                            break;
+                        }
+                    if (strm->is_running)
+                        pjmedia_vid_stream_stop(&strm->base);
+                    else
+                        pjmedia_vid_stream_start(&strm->base);
+                    break;
+                case SDL_VIDEORESIZE:
+                    pevent.event_type = PJMEDIA_EVENT_WINDOW_RESIZE;
+                    if (strm->vid_cb.on_event_cb)
+                        if ((*strm->vid_cb.on_event_cb)(&strm->base,
+                                                       strm->user_data,
+                                                       &pevent) != PJ_SUCCESS)
+                        {
+                            /* Application wants us to ignore this event */
+                            break;
+                        }
+                    /* TODO: move this to OUTPUT_RESIZE cap
+                    strm->screen = SDL_SetVideoMode(sevent.resize.w,
+                                                    sevent.resize.h,
+                                                    0, SDL_RESIZABLE |
+                                                    SDL_SWSURFACE);
+                    */                  
+                    break;
+                case SDL_QUIT:
+                    pevent.event_type = PJMEDIA_EVENT_WINDOW_CLOSE;
+                    /**
+                     * To process PJMEDIA_EVENT_WINDOW_CLOSE event,
+                     * application should do this in the on_event_cb callback:
+                     * 1. stop further calls to #pjmedia_vid_stream_put_frame()
+                     * 2. return PJ_SUCCESS
+                     * Upon returning from the callback, SDL will destroy its
+                     * own stream.
+                     *
+                     * Returning non-PJ_SUCCESS will cause SDL to ignore
+                     * the event
+                     */
+                    if (strm->vid_cb.on_event_cb) {
+                        strm->is_quitting = PJ_TRUE;
+                        if ((*strm->vid_cb.on_event_cb)(&strm->base,
+                                                       strm->user_data,
+                                                       &pevent) != PJ_SUCCESS)
+                        {
+                            /* Application wants us to ignore this event */
+                            strm->is_quitting = PJ_FALSE;
+                            break;
+                        }
+
+                        /* Destroy the stream */
+                        sdl_stream_destroy(&strm->base);
+                        return 0;
+                    }
+
+                    /**
+                     * Default event-handler when there is no user-specified
+                     * callback: close the renderer window. We cannot destroy
+                     * the stream here since there is no callback to notify
+                     * the application.
+                     */
+                    sdl_stream_stop(&strm->base);
+                    SDL_Quit();
+                    strm->screen = NULL;
+                    return 0;
+                default:
+                    break;
+            }
+        }
+
+    }
+
+    return 0;
+}
+
+/* API: create stream */
+static pj_status_t sdl_factory_create_stream(pjmedia_vid_dev_factory *f,
+					     const pjmedia_vid_param *param,
+					     const pjmedia_vid_cb *cb,
+					     void *user_data,
+					     pjmedia_vid_stream **p_vid_strm)
+{
+    struct sdl_factory *sf = (struct sdl_factory*)f;
+    pj_pool_t *pool;
+    struct sdl_stream *strm;
+    pj_status_t status;
+
+    /* Create and Initialize stream descriptor */
+    pool = pj_pool_create(sf->pf, "sdl-dev", 1000, 1000, NULL);
+    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+    strm = PJ_POOL_ZALLOC_T(pool, struct sdl_stream);
+    pj_memcpy(&strm->param, param, sizeof(*param));
+    strm->pool = pool;
+    pj_memcpy(&strm->vid_cb, cb, sizeof(*cb));
+    strm->user_data = user_data;
+
+    /* Create capture stream here */
+    if (param->dir & PJMEDIA_DIR_CAPTURE) {
+    }
+
+    /* Create render stream here */
+    if (param->dir & PJMEDIA_DIR_RENDER) {
+        strm->status = PJ_SUCCESS;
+        status = pj_thread_create(pool, "sdl_thread", create_sdl_thread,
+                                  strm, 0, 0, &strm->sdl_thread);
+        if (status != PJ_SUCCESS) {
+            goto on_error;
+        }
+        while (strm->status == PJ_SUCCESS && !strm->surf && !strm->overlay)
+            pj_thread_sleep(10);
+        if ((status = strm->status) != PJ_SUCCESS) {
+            goto on_error;
+        }
+
+        pjmedia_format_copy(&strm->conv_param.src, &param->fmt);
+        pjmedia_format_copy(&strm->conv_param.dst, &param->fmt);
+
+        status = pjmedia_converter_create(NULL, pool, &strm->conv_param,
+                                          &strm->conv);
+    }
+
+    /* Apply the remaining settings */
+    if (param->flags & PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW) {
+	sdl_stream_set_cap(&strm->base,
+		            PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW,
+                            &param->window);
+    }
+
+    /* Done */
+    strm->base.op = &stream_op;
+    *p_vid_strm = &strm->base;
+
+    return PJ_SUCCESS;
+
+on_error:
+    sdl_stream_destroy(&strm->base);
+    return status;
+}
+
+/* API: Get stream info. */
+static pj_status_t sdl_stream_get_param(pjmedia_vid_stream *s,
+					pjmedia_vid_param *pi)
+{
+    struct sdl_stream *strm = (struct sdl_stream*)s;
+
+    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
+
+    pj_memcpy(pi, &strm->param, sizeof(*pi));
+
+/*    if (sdl_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW,
+                            &pi->fmt.info_size) == PJ_SUCCESS)
+    {
+        pi->flags |= PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW;
+    }
+*/
+    return PJ_SUCCESS;
+}
+
+/* API: get capability */
+static pj_status_t sdl_stream_get_cap(pjmedia_vid_stream *s,
+				      pjmedia_vid_dev_cap cap,
+				      void *pval)
+{
+    struct sdl_stream *strm = (struct sdl_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW)
+    {
+	return PJ_SUCCESS;
+    } else {
+	return PJMEDIA_EVID_INVCAP;
+    }
+}
+
+/* API: set capability */
+static pj_status_t sdl_stream_set_cap(pjmedia_vid_stream *s,
+				      pjmedia_vid_dev_cap cap,
+				      const void *pval)
+{
+    struct sdl_stream *strm = (struct sdl_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW)
+    {
+	return PJ_SUCCESS;
+    }
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+/* API: Put frame from stream */
+static pj_status_t sdl_stream_put_frame(pjmedia_vid_stream *strm,
+                                        const pjmedia_frame *frame)
+{
+    struct sdl_stream *stream = (struct sdl_stream*)strm;
+
+    if (!stream->is_running) {
+        stream->render_exited = PJ_TRUE;
+        return PJ_SUCCESS;
+    }
+
+    if (stream->surf) {
+        if (SDL_MUSTLOCK(stream->surf)) {
+            if (SDL_LockSurface(stream->surf) < 0) {
+                PJ_LOG(3, (THIS_FILE, "Unable to lock SDL surface"));
+                return PJMEDIA_EVID_NOTREADY;
+            }
+        }
+
+        pj_memcpy(stream->surf->pixels, frame->buf, frame->size);
+
+        if (SDL_MUSTLOCK(stream->surf)) {
+            SDL_UnlockSurface(stream->surf);
+        }
+        SDL_BlitSurface(stream->surf, NULL, stream->screen, NULL);
+        SDL_UpdateRect(stream->screen, 0, 0, 0, 0);
+    } else if (stream->overlay) {
+        int i, sz, offset;
+
+        if (SDL_LockYUVOverlay(stream->overlay) < 0) {
+            PJ_LOG(3, (THIS_FILE, "Unable to lock SDL overlay"));
+            return PJMEDIA_EVID_NOTREADY;
+        }
+
+        for (i = 0, offset = 0; i < stream->overlay->planes; i++) {
+            sz = stream->vafp.plane_bytes[i];
+            pj_memcpy(stream->overlay->pixels[i],
+                      (char *)frame->buf + offset, sz);
+            offset += sz;
+        }
+
+        SDL_UnlockYUVOverlay(stream->overlay);
+        SDL_DisplayYUVOverlay(stream->overlay, &stream->rect);
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: Start stream. */
+static pj_status_t sdl_stream_start(pjmedia_vid_stream *strm)
+{
+    struct sdl_stream *stream = (struct sdl_stream*)strm;
+
+    PJ_LOG(4, (THIS_FILE, "Starting sdl video stream"));
+
+    stream->is_running = PJ_TRUE;
+    stream->render_exited = PJ_FALSE;
+
+    return PJ_SUCCESS;
+}
+
+/* API: Stop stream. */
+static pj_status_t sdl_stream_stop(pjmedia_vid_stream *strm)
+{
+    struct sdl_stream *stream = (struct sdl_stream*)strm;
+    unsigned i;
+
+    PJ_LOG(4, (THIS_FILE, "Stopping sdl video stream"));
+
+    /* Wait for renderer put_frame() to finish */
+    stream->is_running = PJ_FALSE;
+    for (i=0; !stream->render_exited && i<100; ++i)
+	pj_thread_sleep(10);
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Destroy stream. */
+static pj_status_t sdl_stream_destroy(pjmedia_vid_stream *strm)
+{
+    struct sdl_stream *stream = (struct sdl_stream*)strm;
+    SDL_Event sevent;
+
+    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);
+
+    if (!stream->is_quitting) {
+        sevent.type = SDL_USEREVENT;
+        SDL_PushEvent(&sevent);
+        pj_thread_join(stream->sdl_thread);
+    }
+
+    sdl_stream_stop(strm);
+
+    if (stream->surf) {
+        SDL_FreeSurface(stream->surf);
+        stream->surf = NULL;
+    }
+
+    if (stream->overlay) {
+        SDL_FreeYUVOverlay(stream->overlay);
+        stream->overlay = NULL;
+    }
+
+    SDL_Quit();
+    stream->screen = NULL;
+
+    pj_pool_release(stream->pool);
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* PJMEDIA_VIDEO_DEV_HAS_SDL */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/v4l2_dev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/v4l2_dev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/v4l2_dev.c	(revision 3392)
@@ -0,0 +1,805 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pjmedia/errno.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+#include <pj/file_access.h>
+#include <pj/log.h>
+#include <pj/os.h>
+#include <pj/rand.h>
+
+#if PJMEDIA_VIDEO_DEV_HAS_V4L2
+
+#include <linux/videodev2.h>
+#include <libv4l2.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/mman.h>
+
+#define THIS_FILE		"v4l2_dev.c"
+#define DRIVER_NAME		"v4l2"
+#define V4L2_MAX_DEVS		4
+#define DEFAULT_WIDTH		640
+#define DEFAULT_HEIGHT		480
+#define DEFAULT_FPS		25
+#define DEFAULT_CLOCK_RATE	90000
+#define INVALID_FD		-1
+#define BUFFER_CNT		2
+#define MAX_IOCTL_RETRY		20
+
+
+/* mapping between pjmedia_fmt_id and v4l2 pixel format */
+typedef struct vid4lin_fmt_map
+{
+    pj_uint32_t pjmedia_fmt_id;
+    pj_uint32_t	v4l2_fmt_id;
+} vid4lin_fmt_map;
+
+/* I/O type being used */
+enum vid4lin_io_type
+{
+    IO_TYPE_NONE,
+    IO_TYPE_READ,
+    IO_TYPE_MMAP,
+    IO_TYPE_MMAP_USER
+};
+
+/* descriptor for each mmap-ed buffer */
+typedef struct vid4lin_buffer
+{
+    void   *start;
+    size_t  length;
+} vid4lin_buffer;
+
+/* v4l2 device info */
+typedef struct vid4lin_dev_info
+{
+    pjmedia_vid_dev_info	 info;
+    char			 dev_name[32];
+    struct v4l2_capability 	 v4l2_cap;
+} vid4lin_dev_info;
+
+/* v4l2 factory */
+typedef struct vid4lin_factory
+{
+    pjmedia_vid_dev_factory	 base;
+    pj_pool_t			*pool;
+    pj_pool_factory		*pf;
+
+    unsigned			 dev_count;
+    vid4lin_dev_info		*dev_info;
+} vid4lin_factory;
+
+/* Video stream. */
+typedef struct vid4lin_stream
+{
+    pjmedia_vid_stream	 	 base;		/**< Base stream	*/
+    pjmedia_vid_param	 	 param;		/**< Settings		*/
+    pj_pool_t           	*pool;		/**< Memory pool.	*/
+
+    int			 	 fd;		/**< Video fd.		*/
+    char			 name[64];	/**< Name for log	*/
+    enum vid4lin_io_type	 io_type;	/**< I/O method.	*/
+    unsigned			 buf_cnt;	/**< MMap buf cnt.  	*/
+    vid4lin_buffer		*buffers;	/**< MMap buffers.  	*/
+    pj_time_val			 start_time;	/**< Time when started	*/
+
+    pjmedia_vid_cb       	 vid_cb;	/**< Stream callback  	*/
+    void                	*user_data;	/**< Application data 	*/
+} vid4lin_stream;
+
+/* Use this to convert between pjmedia_format_id and V4L2 fourcc */
+static vid4lin_fmt_map v4l2_fmt_maps[] =
+{
+    { PJMEDIA_FORMAT_RGB24,	V4L2_PIX_FMT_BGR24 },
+    { PJMEDIA_FORMAT_RGBA,	V4L2_PIX_FMT_BGR32 },
+    { PJMEDIA_FORMAT_RGB32,	V4L2_PIX_FMT_BGR32 },
+    { PJMEDIA_FORMAT_AYUV,	V4L2_PIX_FMT_YUV32 },
+    { PJMEDIA_FORMAT_YUY2,	V4L2_PIX_FMT_YUYV },
+    { PJMEDIA_FORMAT_UYVY,	V4L2_PIX_FMT_UYVY }
+};
+
+/* Prototypes */
+static pj_status_t vid4lin_factory_init(pjmedia_vid_dev_factory *f);
+static pj_status_t vid4lin_factory_destroy(pjmedia_vid_dev_factory *f);
+static unsigned    vid4lin_factory_get_dev_count(pjmedia_vid_dev_factory *f);
+static pj_status_t vid4lin_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					        unsigned index,
+					        pjmedia_vid_dev_info *info);
+static pj_status_t vid4lin_factory_default_param(pj_pool_t *pool,
+                                                 pjmedia_vid_dev_factory *f,
+					         unsigned index,
+					         pjmedia_vid_param *param);
+static pj_status_t vid4lin_factory_create_stream(pjmedia_vid_dev_factory *f,
+						 const pjmedia_vid_param *prm,
+					         const pjmedia_vid_cb *cb,
+					         void *user_data,
+					         pjmedia_vid_stream **p_strm);
+
+static pj_status_t vid4lin_stream_get_param(pjmedia_vid_stream *strm,
+					    pjmedia_vid_param *param);
+static pj_status_t vid4lin_stream_get_cap(pjmedia_vid_stream *strm,
+				          pjmedia_vid_dev_cap cap,
+				          void *value);
+static pj_status_t vid4lin_stream_set_cap(pjmedia_vid_stream *strm,
+				          pjmedia_vid_dev_cap cap,
+				          const void *value);
+static pj_status_t vid4lin_stream_get_frame(pjmedia_vid_stream *strm,
+                                            pjmedia_frame *frame);
+static pj_status_t vid4lin_stream_start(pjmedia_vid_stream *strm);
+static pj_status_t vid4lin_stream_stop(pjmedia_vid_stream *strm);
+static pj_status_t vid4lin_stream_destroy(pjmedia_vid_stream *strm);
+
+/* Operations */
+static pjmedia_vid_dev_factory_op factory_op =
+{
+    &vid4lin_factory_init,
+    &vid4lin_factory_destroy,
+    &vid4lin_factory_get_dev_count,
+    &vid4lin_factory_get_dev_info,
+    &vid4lin_factory_default_param,
+    &vid4lin_factory_create_stream
+};
+
+static pjmedia_vid_stream_op stream_op =
+{
+    &vid4lin_stream_get_param,
+    &vid4lin_stream_get_cap,
+    &vid4lin_stream_set_cap,
+    &vid4lin_stream_start,
+    &vid4lin_stream_get_frame,
+    NULL,
+    &vid4lin_stream_stop,
+    &vid4lin_stream_destroy
+};
+
+
+/****************************************************************************
+ * Factory operations
+ */
+/*
+ * Factory creation function.
+ */
+pjmedia_vid_dev_factory* pjmedia_v4l2_factory(pj_pool_factory *pf)
+{
+    vid4lin_factory *f;
+    pj_pool_t *pool;
+
+    pool = pj_pool_create(pf, DRIVER_NAME, 512, 512, NULL);
+    f = PJ_POOL_ZALLOC_T(pool, vid4lin_factory);
+    f->pf = pf;
+    f->pool = pool;
+    f->base.op = &factory_op;
+
+    return &f->base;
+}
+
+/* util: ioctl that tries harder. */
+static pj_status_t xioctl(int fh, int request, void *arg)
+{
+    enum { RETRY = MAX_IOCTL_RETRY };
+    int r, c=0;
+
+    do {
+	r = v4l2_ioctl(fh, request, arg);
+    } while (r==-1 && c++<RETRY && ((errno==EINTR) || (errno==EAGAIN)));
+
+    return (r == -1) ? pj_get_os_error() : PJ_SUCCESS;
+}
+
+/* Scan V4L2 devices */
+static pj_status_t v4l2_scan_devs(vid4lin_factory *f)
+{
+    vid4lin_dev_info vdi[V4L2_MAX_DEVS];
+    char dev_name[32];
+    unsigned i, old_count;
+    pj_status_t status;
+
+    pj_bzero(vdi, sizeof(vdi));
+    old_count = f->dev_count;
+    f->dev_count = 0;
+
+    for (i=0; i<V4L2_MAX_DEVS && f->dev_count < V4L2_MAX_DEVS; ++i) {
+	int fd;
+	vid4lin_dev_info *pdi;
+	pj_pool_t *pool = f->pool;
+	pj_uint32_t fmt_cap[8];
+	int j, fmt_cnt=0;
+
+	pdi = &vdi[f->dev_count];
+
+	snprintf(dev_name, sizeof(dev_name), "/dev/video%d", i);
+	if (!pj_file_exists(dev_name))
+	    continue;
+
+	fd = v4l2_open(dev_name, O_RDWR, 0);
+	if (fd == -1)
+	    continue;
+
+	status = xioctl(fd, VIDIOC_QUERYCAP, &pdi->v4l2_cap);
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(4,(THIS_FILE, status, "Error querying %s", dev_name));
+	    v4l2_close(fd);
+	    continue;
+	}
+
+	if ((pdi->v4l2_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
+	    v4l2_close(fd);
+	    continue;
+	}
+
+	PJ_LOG(5,(THIS_FILE, "Found capture device %s", pdi->v4l2_cap.card));
+	PJ_LOG(5,(THIS_FILE, "  Enumerating formats:"));
+	for (j=0; fmt_cnt<PJ_ARRAY_SIZE(fmt_cap); ++j) {
+	    struct v4l2_fmtdesc fdesc;
+	    unsigned k;
+
+	    pj_bzero(&fdesc, sizeof(fdesc));
+	    fdesc.index = j;
+	    fdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+	    status = xioctl(fd, VIDIOC_ENUM_FMT, &fdesc);
+	    if (status != PJ_SUCCESS)
+		break;
+
+	    for (k=0; k<PJ_ARRAY_SIZE(v4l2_fmt_maps); ++k) {
+		if (v4l2_fmt_maps[k].v4l2_fmt_id == fdesc.pixelformat) {
+		    fmt_cap[fmt_cnt++] = v4l2_fmt_maps[k].pjmedia_fmt_id;
+		    PJ_LOG(5,(THIS_FILE, "   Supported: %s",
+			      fdesc.description));
+		    break;
+		}
+	    }
+	    if (k==PJ_ARRAY_SIZE(v4l2_fmt_maps)) {
+		PJ_LOG(5,(THIS_FILE, "   Unsupported: %s", fdesc.description));
+	    }
+	}
+
+	v4l2_close(fd);
+
+	if (fmt_cnt==0) {
+	    PJ_LOG(5,(THIS_FILE, "    Found no common format"));
+	    continue;
+	}
+
+	strncpy(pdi->dev_name, dev_name, sizeof(pdi->dev_name));
+	pdi->dev_name[sizeof(pdi->dev_name)-1] = '\0';
+	strncpy(pdi->info.name, (char*)pdi->v4l2_cap.card,
+		sizeof(pdi->info.name));
+	pdi->info.name[sizeof(pdi->info.name)-1] = '\0';
+	strncpy(pdi->info.driver, DRIVER_NAME, sizeof(pdi->info.driver));
+	pdi->info.driver[sizeof(pdi->info.driver)-1] = '\0';
+	pdi->info.dir = PJMEDIA_DIR_CAPTURE;
+	pdi->info.has_callback = PJ_FALSE;
+	pdi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
+
+	pdi->info.fmt_cnt = fmt_cnt;
+	pdi->info.fmt = (pjmedia_format*)
+			pj_pool_calloc(pool, sizeof(pjmedia_format), fmt_cnt);
+
+	for (j=0; j<fmt_cnt; ++j) {
+	    pjmedia_format_init_video(&pdi->info.fmt[j],
+				      fmt_cap[j],
+				      DEFAULT_WIDTH,
+				      DEFAULT_HEIGHT,
+				      DEFAULT_FPS, 1);
+	}
+	if (j < fmt_cnt)
+	    continue;
+
+	f->dev_count++;
+    }
+
+    if (f->dev_count == 0)
+	return PJ_SUCCESS;
+
+    if (f->dev_count > old_count || f->dev_info == NULL) {
+	f->dev_info = (vid4lin_dev_info*)
+		      pj_pool_calloc(f->pool,
+				     f->dev_count,
+				     sizeof(vid4lin_dev_info));
+    }
+    pj_memcpy(f->dev_info, vdi, f->dev_count * sizeof(vid4lin_dev_info));
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: init factory */
+static pj_status_t vid4lin_factory_init(pjmedia_vid_dev_factory *f)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+    pj_status_t status;
+
+    status = v4l2_scan_devs(cf);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    PJ_LOG(4, (THIS_FILE, "Video4Linux2 initialized with %d devices",
+	       cf->dev_count));
+
+    return PJ_SUCCESS;
+}
+
+/* API: destroy factory */
+static pj_status_t vid4lin_factory_destroy(pjmedia_vid_dev_factory *f)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+    pj_pool_t *pool = cf->pool;
+
+    if (cf->pool) {
+	cf->pool = NULL;
+	pj_pool_release(pool);
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* API: get number of devices */
+static unsigned vid4lin_factory_get_dev_count(pjmedia_vid_dev_factory *f)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+    return cf->dev_count;
+}
+
+/* API: get device info */
+static pj_status_t vid4lin_factory_get_dev_info(pjmedia_vid_dev_factory *f,
+					     unsigned index,
+					     pjmedia_vid_dev_info *info)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+
+    PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_memcpy(info, &cf->dev_info[index].info, sizeof(*info));
+
+    return PJ_SUCCESS;
+}
+
+/* API: create default device parameter */
+static pj_status_t vid4lin_factory_default_param(pj_pool_t *pool,
+                                                 pjmedia_vid_dev_factory *f,
+                                                 unsigned index,
+                                                 pjmedia_vid_param *param)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+
+    PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
+
+    pj_bzero(param, sizeof(*param));
+    param->dir = PJMEDIA_DIR_CAPTURE;
+    param->cap_id = index;
+    param->rend_id = PJMEDIA_VID_INVALID_DEV;
+    param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
+    param->clock_rate = DEFAULT_CLOCK_RATE;
+    param->frame_rate.num = DEFAULT_FPS;
+    param->frame_rate.denum = 1;
+    pjmedia_format_copy(&param->fmt, &cf->dev_info[index].info.fmt[0]);
+
+    return PJ_SUCCESS;
+}
+
+static vid4lin_fmt_map* get_v4l2_format_info(pjmedia_format_id id)
+{
+    unsigned i;
+
+    for (i = 0; i < PJ_ARRAY_SIZE(v4l2_fmt_maps); i++) {
+        if (v4l2_fmt_maps[i].pjmedia_fmt_id == id)
+            return &v4l2_fmt_maps[i];
+    }
+
+    return NULL;
+}
+
+/* util: setup format */
+static pj_status_t vid4lin_stream_init_fmt(vid4lin_stream *stream,
+					const pjmedia_vid_param *param,
+					pj_uint32_t pix_fmt)
+{
+    const pjmedia_video_format_detail *vfd;
+    struct v4l2_format v4l2_fmt;
+    pj_status_t status;
+
+    vfd = pjmedia_format_get_video_format_detail(&param->fmt, PJ_TRUE);
+    if (vfd == NULL)
+	return PJMEDIA_EVID_BADFORMAT;
+
+    pj_bzero(&v4l2_fmt, sizeof(v4l2_fmt));
+    v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    v4l2_fmt.fmt.pix.width       = vfd->size.w;
+    v4l2_fmt.fmt.pix.height      = vfd->size.h;
+    v4l2_fmt.fmt.pix.pixelformat = pix_fmt;
+    v4l2_fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
+    status = xioctl(stream->fd, VIDIOC_S_FMT, &v4l2_fmt);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if (v4l2_fmt.fmt.pix.pixelformat != pix_fmt) {
+	status = PJMEDIA_EVID_BADFORMAT;
+	return status;
+    }
+
+    if ((v4l2_fmt.fmt.pix.width != vfd->size.w) ||
+	(v4l2_fmt.fmt.pix.height != vfd->size.h))
+    {
+	status = PJMEDIA_EVID_BADSIZE;
+	return status;
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* Util: initiate v4l2 streaming via mmap */
+static pj_status_t vid4lin_stream_init_streaming(vid4lin_stream *stream)
+{
+    struct v4l2_requestbuffers req;
+    unsigned i;
+    pj_status_t status;
+
+    pj_bzero(&req, sizeof(req));
+    req.count = BUFFER_CNT;
+    req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    req.memory = V4L2_MEMORY_MMAP;
+    status = xioctl(stream->fd, VIDIOC_REQBUFS, &req);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    stream->buffers = pj_pool_calloc(stream->pool, req.count,
+				     sizeof(*stream->buffers));
+    stream->buf_cnt = 0;
+
+    for (i = 0; i < req.count; ++i) {
+	struct v4l2_buffer buf;
+
+	pj_bzero(&buf, sizeof(buf));
+
+	buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	buf.memory      = V4L2_MEMORY_MMAP;
+	buf.index       = i;
+
+	status = xioctl(stream->fd, VIDIOC_QUERYBUF, &buf);
+	if (status != PJ_SUCCESS)
+	    goto on_error;
+
+	stream->buffers[i].length = buf.length;
+	stream->buffers[i].start = v4l2_mmap(NULL, buf.length,
+					     PROT_READ | PROT_WRITE,
+					     MAP_SHARED, stream->fd,
+					     buf.m.offset);
+
+	if (MAP_FAILED == stream->buffers[i].start) {
+	    status = pj_get_os_error();
+	    goto on_error;
+	}
+
+	stream->buf_cnt++;
+    }
+
+    PJ_LOG(5,(THIS_FILE, "  mmap streaming initialized"));
+
+    stream->io_type = IO_TYPE_MMAP;
+    return PJ_SUCCESS;
+
+on_error:
+    return status;
+}
+
+/* init streaming with user pointer */
+static pj_status_t vid4lin_stream_init_streaming_user(vid4lin_stream *stream)
+{
+    return PJ_ENOTSUP;
+}
+
+/* init streaming with read() */
+static pj_status_t vid4lin_stream_init_read_write(vid4lin_stream *stream)
+{
+    return PJ_ENOTSUP;
+}
+
+/* API: create stream */
+static pj_status_t vid4lin_factory_create_stream(pjmedia_vid_dev_factory *f,
+					      const pjmedia_vid_param *param,
+					      const pjmedia_vid_cb *cb,
+					      void *user_data,
+					      pjmedia_vid_stream **p_vid_strm)
+{
+    vid4lin_factory *cf = (vid4lin_factory*)f;
+    pj_pool_t *pool;
+    vid4lin_stream *stream;
+    vid4lin_dev_info *vdi;
+    const vid4lin_fmt_map *fmt_map;
+    const pjmedia_video_format_info *fmt_info;
+    pj_status_t status = PJ_SUCCESS;
+
+    PJ_ASSERT_RETURN(f && param && p_vid_strm, PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->fmt.type == PJMEDIA_TYPE_VIDEO &&
+		     param->fmt.detail_type == PJMEDIA_FORMAT_DETAIL_VIDEO,
+		     PJ_EINVAL);
+    PJ_ASSERT_RETURN(param->cap_id >= 0 && param->cap_id < cf->dev_count,
+		     PJMEDIA_EVID_INVDEV);
+
+    fmt_info = pjmedia_get_video_format_info(NULL, param->fmt.id);
+    if (!fmt_info || (fmt_map=get_v4l2_format_info(param->fmt.id))==NULL)
+        return PJMEDIA_EVID_BADFORMAT;
+
+    vdi = &cf->dev_info[param->cap_id];
+
+    /* Create and Initialize stream descriptor */
+    pool = pj_pool_create(cf->pf, vdi->info.name, 512, 512, NULL);
+    PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
+
+    stream = PJ_POOL_ZALLOC_T(pool, vid4lin_stream);
+    pj_memcpy(&stream->param, param, sizeof(*param));
+    stream->pool = pool;
+    pj_memcpy(&stream->vid_cb, cb, sizeof(*cb));
+    strncpy(stream->name, vdi->info.name, sizeof(stream->name));
+    stream->name[sizeof(stream->name)-1] = '\0';
+    stream->user_data = user_data;
+    stream->fd = INVALID_FD;
+
+    PJ_LOG(4,(THIS_FILE, "Opening video4linux2 device %s: format=%s..",
+	      stream->name, fmt_info->name));
+
+    stream->fd = v4l2_open(vdi->dev_name, O_RDWR | O_NONBLOCK, 0);
+    if (stream->fd < 0)
+	goto on_error;
+
+    status = vid4lin_stream_init_fmt(stream, param, fmt_map->v4l2_fmt_id);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    if (vdi->v4l2_cap.capabilities & V4L2_CAP_STREAMING)
+	status = vid4lin_stream_init_streaming(stream);
+
+    if (status!=PJ_SUCCESS && vdi->v4l2_cap.capabilities & V4L2_CAP_STREAMING)
+	status = vid4lin_stream_init_streaming_user(stream);
+
+    if (status!=PJ_SUCCESS && vdi->v4l2_cap.capabilities & V4L2_CAP_READWRITE)
+	status = vid4lin_stream_init_read_write(stream);
+
+    if (status != PJ_SUCCESS) {
+	PJ_LOG(1,(THIS_FILE, "Error: unable to initiate I/O on %s",
+		  stream->name));
+	goto on_error;
+    }
+
+    /* Done */
+    stream->base.op = &stream_op;
+    *p_vid_strm = &stream->base;
+
+    return PJ_SUCCESS;
+
+on_error:
+    if (status == PJ_SUCCESS)
+	status = PJ_RETURN_OS_ERROR(errno);
+
+    vid4lin_stream_destroy(&stream->base);
+    return status;
+}
+
+/* API: Get stream info. */
+static pj_status_t vid4lin_stream_get_param(pjmedia_vid_stream *s,
+					 pjmedia_vid_param *pi)
+{
+    vid4lin_stream *strm = (vid4lin_stream*)s;
+
+    PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
+
+    pj_memcpy(pi, &strm->param, sizeof(*pi));
+
+    return PJ_SUCCESS;
+}
+
+/* API: get capability */
+static pj_status_t vid4lin_stream_get_cap(pjmedia_vid_stream *s,
+				       pjmedia_vid_dev_cap cap,
+				       void *pval)
+{
+    vid4lin_stream *strm = (vid4lin_stream*)s;
+
+    PJ_UNUSED_ARG(strm);
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
+    {
+        return PJMEDIA_EVID_INVCAP;
+//	return PJ_SUCCESS;
+    } else {
+	return PJMEDIA_EVID_INVCAP;
+    }
+}
+
+/* API: set capability */
+static pj_status_t vid4lin_stream_set_cap(pjmedia_vid_stream *s,
+				       pjmedia_vid_dev_cap cap,
+				       const void *pval)
+{
+    vid4lin_stream *strm = (vid4lin_stream*)s;
+
+
+    PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
+
+    /*
+    if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
+    {
+	return PJ_SUCCESS;
+    }
+    */
+    PJ_UNUSED_ARG(strm);
+    PJ_UNUSED_ARG(cap);
+    PJ_UNUSED_ARG(pval);
+
+    return PJMEDIA_EVID_INVCAP;
+}
+
+/* get frame from mmap */
+static pj_status_t vid4lin_stream_get_frame_mmap(vid4lin_stream *stream,
+                                                 pjmedia_frame *frame)
+{
+    struct v4l2_buffer buf;
+    pj_time_val time;
+    pj_status_t status = PJ_SUCCESS;
+
+    pj_bzero(&buf, sizeof(buf));
+    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf.memory = V4L2_MEMORY_MMAP;
+    status = xioctl(stream->fd, VIDIOC_DQBUF, &buf);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if (frame->size < buf.bytesused) {
+	/* supplied buffer is too small */
+	pj_assert(!"frame buffer is too small for v4l2");
+	status = PJ_ETOOSMALL;
+	goto on_return;
+    }
+
+    time.sec = buf.timestamp.tv_sec;
+    time.msec = buf.timestamp.tv_usec / 1000;
+    PJ_TIME_VAL_SUB(time, stream->start_time);
+
+    frame->type = PJMEDIA_FRAME_TYPE_VIDEO;
+    frame->size = buf.bytesused;
+    frame->timestamp.u64 = PJ_TIME_VAL_MSEC(time) * stream->param.clock_rate
+			   / PJ_UINT64(1000);
+    pj_memcpy(frame->buf, stream->buffers[buf.index].start, buf.bytesused);
+
+on_return:
+    pj_bzero(&buf, sizeof(buf));
+    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    buf.memory = V4L2_MEMORY_MMAP;
+    xioctl(stream->fd, VIDIOC_QBUF, &buf);
+
+    return status;
+}
+
+/* API: Get frame from stream */
+static pj_status_t vid4lin_stream_get_frame(pjmedia_vid_stream *strm,
+                                            pjmedia_frame *frame)
+{
+    vid4lin_stream *stream = (vid4lin_stream*)strm;
+
+    if (stream->io_type == IO_TYPE_MMAP)
+	return vid4lin_stream_get_frame_mmap(stream, frame);
+    else {
+	pj_assert(!"Unsupported i/o type");
+	return PJ_EINVALIDOP;
+    }
+}
+
+/* API: Start stream. */
+static pj_status_t vid4lin_stream_start(pjmedia_vid_stream *strm)
+{
+    vid4lin_stream *stream = (vid4lin_stream*)strm;
+    struct v4l2_buffer buf;
+    enum v4l2_buf_type type;
+    unsigned i;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(stream->fd != -1, PJ_EINVALIDOP);
+
+    PJ_LOG(4, (THIS_FILE, "Starting v4l2 video stream %s", stream->name));
+
+    pj_gettimeofday(&stream->start_time);
+
+    for (i = 0; i < stream->buf_cnt; ++i) {
+	pj_bzero(&buf, sizeof(buf));
+	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	buf.memory = V4L2_MEMORY_MMAP;
+	buf.index = i;
+	status = xioctl(stream->fd, VIDIOC_QBUF, &buf);
+	if (status != PJ_SUCCESS)
+	    goto on_error;
+    }
+    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+    status = xioctl(stream->fd, VIDIOC_STREAMON, &type);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    return PJ_SUCCESS;
+
+on_error:
+    if (i > 0) {
+	/* Dequeue already enqueued buffers. Can we do this while streaming
+	 * is not started?
+	 */
+	unsigned n = i;
+	for (i=0; i<n; ++i) {
+	    pj_bzero(&buf, sizeof(buf));
+	    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	    buf.memory = V4L2_MEMORY_MMAP;
+	    xioctl(stream->fd, VIDIOC_DQBUF, &buf);
+	}
+    }
+    return status;
+}
+
+/* API: Stop stream. */
+static pj_status_t vid4lin_stream_stop(pjmedia_vid_stream *strm)
+{
+    vid4lin_stream *stream = (vid4lin_stream*)strm;
+    enum v4l2_buf_type type;
+    pj_status_t status;
+
+    if (stream->fd < 0)
+	return PJ_SUCCESS;
+
+    PJ_LOG(4, (THIS_FILE, "Stopping v4l2 video stream %s", stream->name));
+
+    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    status = xioctl(stream->fd, VIDIOC_STREAMOFF, &type);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    return PJ_SUCCESS;
+}
+
+
+/* API: Destroy stream. */
+static pj_status_t vid4lin_stream_destroy(pjmedia_vid_stream *strm)
+{
+    vid4lin_stream *stream = (vid4lin_stream*)strm;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);
+
+    vid4lin_stream_stop(strm);
+
+    PJ_LOG(4, (THIS_FILE, "Destroying v4l2 video stream %s", stream->name));
+
+    for (i=0; i<stream->buf_cnt; ++i) {
+	if (stream->buffers[i].start != MAP_FAILED) {
+	    v4l2_munmap(stream->buffers[i].start, stream->buffers[i].length);
+	    stream->buffers[i].start = MAP_FAILED;
+	}
+    }
+
+    if (stream->fd >= 0) {
+	v4l2_close(stream->fd);
+	stream->fd = -1;
+    }
+    pj_pool_release(stream->pool);
+
+    return PJ_SUCCESS;
+}
+
+#endif	/* PJMEDIA_VIDEO_DEV_HAS_V4L2 */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/videodev.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/videodev.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/videodev.c	(revision 3392)
@@ -0,0 +1,728 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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 
+ */
+#include <pjmedia-videodev/videodev_imp.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+
+#define THIS_FILE   "videodev.c"
+
+#define DEFINE_CAP(name, info)	{name, info}
+
+/* Capability names */
+static struct cap_info
+{
+    const char *name;
+    const char *info;
+} cap_infos[] = 
+{
+    DEFINE_CAP("format",        "Video format"),
+    DEFINE_CAP("scale",         "Input dimension"),
+    DEFINE_CAP("window",        "Renderer window"),
+};
+
+
+/*
+ * The device index seen by application and driver is different. 
+ *
+ * At application level, device index is index to global list of device.
+ * At driver level, device index is index to device list on that particular
+ * factory only.
+ */
+#define MAKE_DEV_ID(f_id, index)   (((f_id & 0xFFFF) << 16) | (index & 0xFFFF))
+#define GET_INDEX(dev_id)	   ((dev_id) & 0xFFFF)
+#define GET_FID(dev_id)		   ((dev_id) >> 16)
+#define DEFAULT_DEV_ID		    0
+
+
+/* extern functions to create factories */
+#if PJMEDIA_VIDEO_DEV_HAS_NULL_VIDEO
+pjmedia_vid_dev_factory* pjmedia_null_video_factory(pj_pool_factory *pf);
+#endif
+
+#if PJMEDIA_VIDEO_DEV_HAS_DSHOW
+pjmedia_vid_dev_factory* pjmedia_dshow_factory(pj_pool_factory *pf);
+#endif
+
+#if PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC
+pjmedia_vid_dev_factory* pjmedia_cbar_factory(pj_pool_factory *pf);
+#endif
+
+#if PJMEDIA_VIDEO_DEV_HAS_SDL
+pjmedia_vid_dev_factory* pjmedia_sdl_factory(pj_pool_factory *pf);
+#endif
+
+#if PJMEDIA_VIDEO_DEV_HAS_FFMPEG
+pjmedia_vid_dev_factory* pjmedia_ffmpeg_factory(pj_pool_factory *pf);
+#endif
+
+#if PJMEDIA_VIDEO_DEV_HAS_V4L2
+pjmedia_vid_dev_factory* pjmedia_v4l2_factory(pj_pool_factory *pf);
+#endif
+
+#define MAX_DRIVERS	16
+#define MAX_DEVS	64
+
+
+/* driver structure */
+struct driver
+{
+    /* Creation function */
+    pjmedia_vid_dev_factory_create_func_ptr create;
+    /* Factory instance */
+    pjmedia_vid_dev_factory *f;
+    char		     name[32];	    /* Driver name		    */
+    unsigned		     dev_cnt;	    /* Number of devices	    */
+    unsigned		     start_idx;	    /* Start index in global list   */
+    int			     cap_dev_idx;   /* Default capture device.	    */
+    int			     rend_dev_idx;  /* Default render device	    */
+};
+
+/* The video subsystem */
+static struct vid_subsys
+{
+    unsigned	     init_count;	/* How many times init() is called  */
+    pj_pool_factory *pf;		/* The pool factory.		    */
+
+    unsigned	     drv_cnt;		/* Number of drivers.		    */
+    struct driver    drv[MAX_DRIVERS];	/* Array of drivers.		    */
+
+    unsigned	     dev_cnt;		/* Total number of devices.	    */
+    pj_uint32_t	     dev_list[MAX_DEVS];/* Array of device IDs.		    */
+
+} vid_subsys;
+
+/* API: get capability name/info */
+PJ_DEF(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
+					     const char **p_desc)
+{
+    const char *desc;
+    unsigned i;
+
+    if (p_desc==NULL) p_desc = &desc;
+
+    for (i=0; i<PJ_ARRAY_SIZE(cap_infos); ++i) {
+	if ((1 << i)==cap)
+	    break;
+    }
+
+    if (i==32) {
+	*p_desc = "??";
+	return "??";
+    }
+
+    *p_desc = cap_infos[i].info;
+    return cap_infos[i].name;
+}
+
+static pj_status_t get_cap_pointer(const pjmedia_vid_param *param,
+				   pjmedia_vid_dev_cap cap,
+				   void **ptr,
+				   unsigned *size)
+{
+#define FIELD_INFO(name)    *ptr = (void*)&param->name; \
+			    *size = sizeof(param->name)
+
+    switch (cap) {
+    case PJMEDIA_VID_DEV_CAP_FORMAT:
+	FIELD_INFO(fmt);
+	break;
+    case PJMEDIA_VID_DEV_CAP_INPUT_SCALE:
+	FIELD_INFO(disp_size);
+	break;
+    case PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW:
+	FIELD_INFO(window);
+	break;
+    default:
+	return PJMEDIA_EVID_INVCAP;
+    }
+
+#undef FIELD_INFO
+
+    return PJ_SUCCESS;
+}
+
+/* API: set cap value to param */
+PJ_DEF(pj_status_t) pjmedia_vid_param_set_cap( pjmedia_vid_param *param,
+					       pjmedia_vid_dev_cap cap,
+					       const void *pval)
+{
+    void *cap_ptr;
+    unsigned cap_size;
+    pj_status_t status;
+
+    status = get_cap_pointer(param, cap, &cap_ptr, &cap_size);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    pj_memcpy(cap_ptr, pval, cap_size);
+    param->flags |= cap;
+
+    return PJ_SUCCESS;
+}
+
+/* API: get cap value from param */
+PJ_DEF(pj_status_t) pjmedia_vid_param_get_cap( const pjmedia_vid_param *param,
+					       pjmedia_vid_dev_cap cap,
+					       void *pval)
+{
+    void *cap_ptr;
+    unsigned cap_size;
+    pj_status_t status;
+
+    status = get_cap_pointer(param, cap, &cap_ptr, &cap_size);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if ((param->flags & cap) == 0) {
+	pj_bzero(cap_ptr, cap_size);
+	return PJMEDIA_EVID_INVCAP;
+    }
+
+    pj_memcpy(pval, cap_ptr, cap_size);
+    return PJ_SUCCESS;
+}
+
+/* Internal: init driver */
+static pj_status_t init_driver(unsigned drv_idx)
+{
+    struct driver *drv = &vid_subsys.drv[drv_idx];
+    pjmedia_vid_dev_factory *f;
+    unsigned i, dev_cnt;
+    pj_status_t status;
+
+    /* Create the factory */
+    f = (*drv->create)(vid_subsys.pf);
+    if (!f)
+	return PJ_EUNKNOWN;
+
+    /* Call factory->init() */
+    status = f->op->init(f);
+    if (status != PJ_SUCCESS) {
+	f->op->destroy(f);
+	return status;
+    }
+
+    /* Get number of devices */
+    dev_cnt = f->op->get_dev_count(f);
+    if (dev_cnt + vid_subsys.dev_cnt > MAX_DEVS) {
+	PJ_LOG(4,(THIS_FILE, "%d device(s) cannot be registered because"
+			      " there are too many devices",
+			      vid_subsys.dev_cnt + dev_cnt - MAX_DEVS));
+	dev_cnt = MAX_DEVS - vid_subsys.dev_cnt;
+    }
+
+    /* enabling this will cause pjsua-lib initialization to fail when there
+     * is no video device installed in the system, even when pjsua has been
+     * run with --null-video
+     *
+    if (dev_cnt == 0) {
+	f->op->destroy(f);
+	return PJMEDIA_EVID_NODEV;
+    }
+    */
+
+    /* Fill in default devices */
+    drv->rend_dev_idx = drv->cap_dev_idx = -1;
+    for (i=0; i<dev_cnt; ++i) {
+	pjmedia_vid_dev_info info;
+
+	status = f->op->get_dev_info(f, i, &info);
+	if (status != PJ_SUCCESS) {
+	    f->op->destroy(f);
+	    return status;
+	}
+
+	if (drv->name[0]=='\0') {
+	    /* Set driver name */
+	    pj_ansi_strncpy(drv->name, info.driver, sizeof(drv->name));
+	    drv->name[sizeof(drv->name)-1] = '\0';
+	}
+
+	if (drv->rend_dev_idx < 0 && (info.dir & PJMEDIA_DIR_RENDER)) {
+	    /* Set default render device */
+	    drv->rend_dev_idx = i;
+	}
+	if (drv->cap_dev_idx < 0 && (info.dir & PJMEDIA_DIR_CAPTURE)) {
+	    /* Set default capture device */
+	    drv->cap_dev_idx = i;
+	}
+
+        if (drv->rend_dev_idx >= 0 && drv->cap_dev_idx >= 0) {
+	    /* Done. */
+	    break;
+	}
+    }
+
+    /* Register the factory */
+    drv->f = f;
+    drv->f->sys.drv_idx = drv_idx;
+    drv->start_idx = vid_subsys.dev_cnt;
+    drv->dev_cnt = dev_cnt;
+
+    /* Register devices to global list */
+    for (i=0; i<dev_cnt; ++i) {
+	vid_subsys.dev_list[vid_subsys.dev_cnt++] = MAKE_DEV_ID(drv_idx, i);
+    }
+
+    return PJ_SUCCESS;
+}
+
+/* Internal: deinit driver */
+static void deinit_driver(unsigned drv_idx)
+{
+    struct driver *drv = &vid_subsys.drv[drv_idx];
+
+    if (drv->f) {
+	drv->f->op->destroy(drv->f);
+	drv->f = NULL;
+    }
+
+    drv->dev_cnt = 0;
+    drv->rend_dev_idx = drv->cap_dev_idx = -1;
+}
+
+/* API: Initialize the video subsystem. */
+PJ_DEF(pj_status_t) pjmedia_vid_subsys_init(pj_pool_factory *pf)
+{
+    unsigned i;
+    pj_status_t status = PJ_SUCCESS;
+
+    /* Allow init() to be called multiple times as long as there is matching
+     * number of shutdown().
+     */
+    if (vid_subsys.init_count++ != 0) {
+	return PJ_SUCCESS;
+    }
+
+    /* Register error subsystem */
+    pj_register_strerror(PJMEDIA_VIDEODEV_ERRNO_START, 
+			 PJ_ERRNO_SPACE_SIZE, 
+			 &pjmedia_videodev_strerror);
+
+    /* Init */
+    vid_subsys.pf = pf;
+    vid_subsys.drv_cnt = 0;
+    vid_subsys.dev_cnt = 0;
+
+    /* Register creation functions */
+#if PJMEDIA_VIDEO_DEV_HAS_V4L2
+    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_v4l2_factory;
+#endif
+#if PJMEDIA_VIDEO_DEV_HAS_DSHOW
+    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_dshow_factory;
+#endif
+#if PJMEDIA_VIDEO_DEV_HAS_FFMPEG
+    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_ffmpeg_factory;
+#endif
+#if PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC
+    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_cbar_factory;
+#endif
+#if PJMEDIA_VIDEO_DEV_HAS_SDL
+    vid_subsys.drv[vid_subsys.drv_cnt++].create = &pjmedia_sdl_factory;
+#endif
+
+    /* Initialize each factory and build the device ID list */
+    for (i=0; i<vid_subsys.drv_cnt; ++i) {
+	status = init_driver(i);
+	if (status != PJ_SUCCESS) {
+	    deinit_driver(i);
+	    continue;
+	}
+    }
+
+    return vid_subsys.dev_cnt ? PJ_SUCCESS : status;
+}
+
+/* API: register an video device factory to the video subsystem. */
+PJ_DEF(pj_status_t)
+pjmedia_vid_register_factory(pjmedia_vid_dev_factory_create_func_ptr adf)
+{
+    pj_status_t status;
+
+    if (vid_subsys.init_count == 0)
+	return PJMEDIA_EVID_INIT;
+
+    vid_subsys.drv[vid_subsys.drv_cnt].create = adf;
+    status = init_driver(vid_subsys.drv_cnt);
+    if (status == PJ_SUCCESS) {
+	vid_subsys.drv_cnt++;
+    } else {
+	deinit_driver(vid_subsys.drv_cnt);
+    }
+
+    return status;
+}
+
+/* API: unregister an video device factory from the video subsystem. */
+PJ_DEF(pj_status_t)
+pjmedia_vid_unregister_factory(pjmedia_vid_dev_factory_create_func_ptr adf)
+{
+    unsigned i, j;
+
+    if (vid_subsys.init_count == 0)
+	return PJMEDIA_EVID_INIT;
+
+    for (i=0; i<vid_subsys.drv_cnt; ++i) {
+	struct driver *drv = &vid_subsys.drv[i];
+
+	if (drv->create == adf) {
+	    for (j = drv->start_idx; j < drv->start_idx + drv->dev_cnt; j++)
+	    {
+		vid_subsys.dev_list[j] = (pj_uint32_t)PJMEDIA_VID_INVALID_DEV;
+	    }
+
+	    deinit_driver(i);
+	    pj_bzero(drv, sizeof(*drv));
+	    return PJ_SUCCESS;
+	}
+    }
+
+    return PJMEDIA_EVID_ERR;
+}
+
+/* API: get the pool factory registered to the video subsystem. */
+PJ_DEF(pj_pool_factory*) pjmedia_vid_subsys_get_pool_factory(void)
+{
+    return vid_subsys.pf;
+}
+
+/* API: Shutdown the video subsystem. */
+PJ_DEF(pj_status_t) pjmedia_vid_subsys_shutdown(void)
+{
+    unsigned i;
+
+    /* Allow shutdown() to be called multiple times as long as there is matching
+     * number of init().
+     */
+    if (vid_subsys.init_count == 0) {
+	return PJ_SUCCESS;
+    }
+    --vid_subsys.init_count;
+
+    for (i=0; i<vid_subsys.drv_cnt; ++i) {
+	deinit_driver(i);
+    }
+
+    vid_subsys.pf = NULL;
+    return PJ_SUCCESS;
+}
+
+/* API: Get the number of video devices installed in the system. */
+PJ_DEF(unsigned) pjmedia_vid_dev_count(void)
+{
+    return vid_subsys.dev_cnt;
+}
+
+/* Internal: convert local index to global device index */
+static pj_status_t make_global_index(unsigned drv_idx, 
+				     pjmedia_vid_dev_index *id)
+{
+    if (*id < 0) {
+	return PJ_SUCCESS;
+    }
+
+    /* Check that factory still exists */
+    PJ_ASSERT_RETURN(vid_subsys.drv[drv_idx].f, PJ_EBUG);
+
+    /* Check that device index is valid */
+    PJ_ASSERT_RETURN(*id>=0 && *id<(int)vid_subsys.drv[drv_idx].dev_cnt, 
+		     PJ_EBUG);
+
+    *id += vid_subsys.drv[drv_idx].start_idx;
+    return PJ_SUCCESS;
+}
+
+/* Internal: lookup device id */
+static pj_status_t lookup_dev(pjmedia_vid_dev_index id,
+			      pjmedia_vid_dev_factory **p_f,
+			      unsigned *p_local_index)
+{
+    int f_id, index;
+
+    if (id < 0) {
+	unsigned i;
+
+	if (id == PJMEDIA_VID_INVALID_DEV)
+	    return PJMEDIA_EVID_INVDEV;
+
+	for (i=0; i<vid_subsys.drv_cnt; ++i) {
+	    struct driver *drv = &vid_subsys.drv[i];
+	    if (id==PJMEDIA_VID_DEFAULT_CAPTURE_DEV && 
+		drv->cap_dev_idx >= 0) 
+	    {
+		id = drv->cap_dev_idx;
+		make_global_index(i, &id);
+		break;
+	    } else if (id==PJMEDIA_VID_DEFAULT_RENDER_DEV && 
+		drv->rend_dev_idx >= 0) 
+	    {
+		id = drv->rend_dev_idx;
+		make_global_index(i, &id);
+		break;
+	    }
+	}
+
+	if (id < 0) {
+	    return PJMEDIA_EVID_NODEFDEV;
+	}
+    }
+
+    f_id = GET_FID(vid_subsys.dev_list[id]);
+    index = GET_INDEX(vid_subsys.dev_list[id]);
+
+    if (f_id < 0 || f_id >= (int)vid_subsys.drv_cnt)
+	return PJMEDIA_EVID_INVDEV;
+
+    if (index < 0 || index >= (int)vid_subsys.drv[f_id].dev_cnt)
+	return PJMEDIA_EVID_INVDEV;
+
+    *p_f = vid_subsys.drv[f_id].f;
+    *p_local_index = (unsigned)index;
+
+    return PJ_SUCCESS;
+
+}
+
+/* API: Get device information. */
+PJ_DEF(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id,
+					     pjmedia_vid_dev_info *info)
+{
+    pjmedia_vid_dev_factory *f;
+    unsigned index;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(info && id!=PJMEDIA_VID_INVALID_DEV, PJ_EINVAL);
+    PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT);
+
+    status = lookup_dev(id, &f, &index);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    return f->op->get_dev_info(f, index, info);
+}
+
+/* API: find device */
+PJ_DEF(pj_status_t) pjmedia_vid_dev_lookup( const char *drv_name,
+					    const char *dev_name,
+					    pjmedia_vid_dev_index *id)
+{
+    pjmedia_vid_dev_factory *f = NULL;
+    unsigned drv_idx, dev_idx;
+
+    PJ_ASSERT_RETURN(drv_name && dev_name && id, PJ_EINVAL);
+    PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT);
+
+    for (drv_idx=0; drv_idx<vid_subsys.drv_cnt; ++drv_idx) {
+	if (!pj_ansi_stricmp(drv_name, vid_subsys.drv[drv_idx].name)) {
+	    f = vid_subsys.drv[drv_idx].f;
+	    break;
+	}
+    }
+
+    if (!f)
+	return PJ_ENOTFOUND;
+
+    for (dev_idx=0; dev_idx<vid_subsys.drv[drv_idx].dev_cnt; ++dev_idx) {
+	pjmedia_vid_dev_info info;
+	pj_status_t status;
+
+	status = f->op->get_dev_info(f, dev_idx, &info);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	if (!pj_ansi_stricmp(dev_name, info.name))
+	    break;
+    }
+
+    if (dev_idx==vid_subsys.drv[drv_idx].dev_cnt)
+	return PJ_ENOTFOUND;
+
+    *id = dev_idx;
+    make_global_index(drv_idx, id);
+
+    return PJ_SUCCESS;
+}
+
+/* API: Initialize the video device parameters with default values for the
+ * specified device.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_dev_default_param(pj_pool_t *pool,
+                                                  pjmedia_vid_dev_index id,
+						  pjmedia_vid_param *param)
+{
+    pjmedia_vid_dev_factory *f;
+    unsigned index;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(param && id!=PJMEDIA_VID_INVALID_DEV, PJ_EINVAL);
+    PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT);
+
+    status = lookup_dev(id, &f, &index);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    status = f->op->default_param(pool, f, index, param);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Normalize device IDs */
+    make_global_index(f->sys.drv_idx, &param->cap_id);
+    make_global_index(f->sys.drv_idx, &param->rend_id);
+
+    return PJ_SUCCESS;
+}
+
+/* API: Open video stream object using the specified parameters. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_create(const pjmedia_vid_param *prm,
+                                              const pjmedia_vid_cb *cb,
+					      void *user_data,
+					      pjmedia_vid_stream **p_vid_strm)
+{
+    pjmedia_vid_dev_factory *cap_f=NULL, *rend_f=NULL, *f=NULL;
+    pjmedia_vid_param param;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(prm && prm->dir && p_vid_strm, PJ_EINVAL);
+    PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT);
+    PJ_ASSERT_RETURN(prm->dir==PJMEDIA_DIR_CAPTURE ||
+		     prm->dir==PJMEDIA_DIR_RENDER ||
+		     prm->dir==PJMEDIA_DIR_CAPTURE_RENDER,
+		     PJ_EINVAL);
+
+    /* Must make copy of param because we're changing device ID */
+    pj_memcpy(&param, prm, sizeof(param));
+
+    /* Normalize cap_id */
+    if (param.dir & PJMEDIA_DIR_CAPTURE) {
+	unsigned index;
+
+	if (param.cap_id < 0)
+	    param.cap_id = PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
+
+	status = lookup_dev(param.cap_id, &cap_f, &index);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	param.cap_id = index;
+	f = cap_f;
+    }
+
+    /* Normalize rend_id */
+    if (param.dir & PJMEDIA_DIR_RENDER) {
+	unsigned index;
+
+	if (param.rend_id < 0)
+	    param.rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV;
+
+	status = lookup_dev(param.rend_id, &rend_f, &index);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	param.rend_id = index;
+	f = rend_f;
+    }
+
+    PJ_ASSERT_RETURN(f != NULL, PJ_EBUG);
+
+    /* For now, cap_id and rend_id must belong to the same factory */
+    PJ_ASSERT_RETURN((param.dir != PJMEDIA_DIR_CAPTURE_RENDER) || 
+		     (cap_f == rend_f),
+		     PJMEDIA_EVID_INVDEV);
+
+    /* Create the stream */
+    status = f->op->create_stream(f, &param, cb,
+				  user_data, p_vid_strm);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Assign factory id to the stream */
+    (*p_vid_strm)->sys.drv_idx = f->sys.drv_idx;
+    return PJ_SUCCESS;
+}
+
+/* API: Get the running parameters for the specified video stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_get_param(pjmedia_vid_stream *strm,
+						 pjmedia_vid_param *param)
+{
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(strm && param, PJ_EINVAL);
+    PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT);
+
+    status = strm->op->get_param(strm, param);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Normalize device id's */
+    make_global_index(strm->sys.drv_idx, &param->cap_id);
+    make_global_index(strm->sys.drv_idx, &param->rend_id);
+
+    return PJ_SUCCESS;
+}
+
+/* API: Get the value of a specific capability of the video stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_get_cap(pjmedia_vid_stream *strm,
+					       pjmedia_vid_dev_cap cap,
+					       void *value)
+{
+    return strm->op->get_cap(strm, cap, value);
+}
+
+/* API: Set the value of a specific capability of the video stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_set_cap(pjmedia_vid_stream *strm,
+					       pjmedia_vid_dev_cap cap,
+					       const void *value)
+{
+    return strm->op->set_cap(strm, cap, value);
+}
+
+/* API: Start the stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_start(pjmedia_vid_stream *strm)
+{
+    return strm->op->start(strm);
+}
+
+PJ_DEF(pj_status_t) pjmedia_vid_stream_get_frame(pjmedia_vid_stream *strm,
+                                                 pjmedia_frame *frame)
+{
+    pj_assert(strm->op->get_frame);
+    return strm->op->get_frame(strm, frame);
+}
+
+PJ_DEF(pj_status_t) pjmedia_vid_stream_put_frame(pjmedia_vid_stream *strm,
+                                                 const pjmedia_frame *frame)
+{
+    pj_assert(strm->op->put_frame);
+    return strm->op->put_frame(strm, frame);
+}
+
+/* API: Stop the stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_stop(pjmedia_vid_stream *strm)
+{
+    return strm->op->stop(strm);
+}
+
+/* API: Destroy the stream. */
+PJ_DEF(pj_status_t) pjmedia_vid_stream_destroy(pjmedia_vid_stream *strm)
+{
+    return strm->op->destroy(strm);
+}
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/avi_player.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/avi_player.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/avi_player.c	(revision 3392)
@@ -0,0 +1,710 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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 
+ */
+
+/**
+ * Default file player/writer buffer size.
+ */
+#include <pjmedia/avi_stream.h>
+#include <pjmedia/avi.h>
+#include <pjmedia/errno.h>
+#include <pjmedia/wave.h>
+#include <pj/assert.h>
+#include <pj/file_access.h>
+#include <pj/file_io.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+
+
+#define THIS_FILE   "avi_player.c"
+
+#define AVIF_MUSTUSEINDEX       0x00000020
+#define AVIF_ISINTERLEAVED      0x00000100
+#define AVISF_DISABLED          0x00000001
+#define AVISF_VIDEO_PALCHANGES  0x00010000
+
+#define AVI_EOF 0xFFEEFFEE
+
+#define COMPARE_TAG(doc_tag, tag) (doc_tag == *((pj_uint32_t *)avi_tags[tag]))
+
+#define SIGNATURE	    PJMEDIA_PORT_SIGNATURE('A', 'V', 'I', 'P')
+
+#if 0
+#   define TRACE_(x)	PJ_LOG(4,x)
+#else
+#   define TRACE_(x)
+#endif
+
+#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
+    static void data_to_host(void *data, pj_uint8_t bits, unsigned count)
+    {
+	unsigned i;
+        pj_int32_t *data32 = (pj_int32_t *)data;
+        pj_int16_t *data16 = (pj_int16_t *)data;
+        count /= (bits == 32? 4 : 2);
+	for (i=0; i<count; ++i) {
+	    if (bits == 32)
+                data32[i] = pj_swap32(data32[i]);
+            else
+                data16[i] = pj_swap16(data16[i]);
+	}
+    }
+    static void data_to_host2(void *data, pj_uint8_t nsizes,
+                              pj_uint8_t *sizes)
+    {
+	unsigned i;
+        pj_int8_t *datap = (pj_int8_t *)data;
+        for (i = 0; i < nsizes; i++) {
+            data_to_host(datap, 32, sizes[i]);
+            datap += sizes[i++];
+            if (i >= nsizes)
+                break;
+            data_to_host(datap, 16, sizes[i]);
+            datap += sizes[i];
+	}
+    }
+#else
+#   define data_to_host(data, bits, count)
+#   define data_to_host2(data, nsizes, sizes)
+#endif
+
+struct pjmedia_avi_streams
+{
+    pj_uint8_t      num_streams;
+    pjmedia_port  **streams;
+};
+
+struct avi_reader_port
+{
+    pjmedia_port     base;
+    pj_uint8_t       stream_id;
+    unsigned	     options;
+    pj_uint16_t	     bits_per_sample;
+    pj_bool_t	     eof;
+    pj_off_t	     fsize;
+    pj_off_t	     start_data;
+    pj_uint8_t       pad;
+    pj_oshandle_t    fd;
+    pj_ssize_t       size_left;
+
+    pj_status_t	   (*cb)(pjmedia_port*, void*);
+};
+
+
+static pj_status_t avi_get_frame(pjmedia_port *this_port, 
+			         pjmedia_frame *frame);
+static pj_status_t avi_on_destroy(pjmedia_port *this_port);
+
+static struct avi_reader_port *create_avi_port(pj_pool_t *pool)
+{
+    const pj_str_t name = pj_str("file");
+    struct avi_reader_port *port;
+
+    port = PJ_POOL_ZALLOC_T(pool, struct avi_reader_port);
+    if (!port)
+	return NULL;
+
+    /* Put in default values.
+     * These will be overriden once the file is read.
+     */
+    pjmedia_port_info_init(&port->base.info, &name, SIGNATURE, 
+			   8000, 1, 16, 80);
+
+    port->fd = (pj_oshandle_t)-1;
+    port->base.get_frame = &avi_get_frame;
+    port->base.on_destroy = &avi_on_destroy;
+
+    return port;
+}
+
+#define file_read(fd, data, size) file_read2(fd, data, size, 32)
+#define file_read2(fd, data, size, bits) file_read3(fd, data, size, bits, NULL)
+
+static pj_status_t file_read3(pj_oshandle_t fd, void *data, pj_ssize_t size,
+                              pj_uint16_t bits, pj_ssize_t *psz_read)
+{
+    pj_ssize_t size_read = size, size_to_read = size;
+    pj_status_t status = pj_file_read(fd, data, &size_read);
+    if (status != PJ_SUCCESS)
+        return status;
+
+    /* Normalize AVI header fields values from little-endian to host
+     * byte order.
+     */
+    if (bits > 0)
+        data_to_host(data, bits, size_read);
+
+    if (size_read != size_to_read) {
+        if (psz_read)
+            *psz_read = size_read;
+        return AVI_EOF;
+    }
+
+    return status;
+}
+
+/*
+ * Create AVI player port.
+ */
+PJ_DEF(pj_status_t)
+pjmedia_avi_player_create_streams(pj_pool_t *pool,
+                                  const char *filename,
+				  unsigned options,
+				  pjmedia_avi_streams **p_streams)
+{
+    pjmedia_avi_hdr avi_hdr;
+    struct avi_reader_port *fport[PJMEDIA_AVI_MAX_NUM_STREAMS];
+    pj_off_t pos;
+    pj_uint8_t i, nstr = 0;
+    pj_status_t status = PJ_SUCCESS;
+
+    /* Check arguments. */
+    PJ_ASSERT_RETURN(pool && filename && p_streams, PJ_EINVAL);
+
+    /* Check the file really exists. */
+    if (!pj_file_exists(filename)) {
+	return PJ_ENOTFOUND;
+    }
+
+    /* Create fport instance. */
+    fport[0] = create_avi_port(pool);
+    if (!fport[0]) {
+	return PJ_ENOMEM;
+    }
+
+    /* Get the file size. */
+    fport[0]->fsize = pj_file_size(filename);
+
+    /* Size must be more than AVI header size */
+    if (fport[0]->fsize <= sizeof(riff_hdr_t) + sizeof(avih_hdr_t) + 
+                           sizeof(strl_hdr_t))
+    {
+	return PJMEDIA_EINVALIMEDIATYPE;
+    }
+
+    /* Open file. */
+    status = pj_file_open(pool, filename, PJ_O_RDONLY, &fport[0]->fd);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Read the RIFF + AVIH header. */
+    status = file_read(fport[0]->fd, &avi_hdr,
+                       sizeof(riff_hdr_t) + sizeof(avih_hdr_t));
+    if (status != PJ_SUCCESS)
+        goto on_error;
+
+    /* Validate AVI file. */
+    if (!COMPARE_TAG(avi_hdr.riff_hdr.riff, PJMEDIA_AVI_RIFF_TAG) ||
+	!COMPARE_TAG(avi_hdr.riff_hdr.avi, PJMEDIA_AVI_AVI_TAG) ||
+        !COMPARE_TAG(avi_hdr.avih_hdr.list_tag, PJMEDIA_AVI_LIST_TAG) ||
+        !COMPARE_TAG(avi_hdr.avih_hdr.hdrl_tag, PJMEDIA_AVI_HDRL_TAG) ||
+        !COMPARE_TAG(avi_hdr.avih_hdr.avih, PJMEDIA_AVI_AVIH_TAG))
+    {
+	status = PJMEDIA_EINVALIMEDIATYPE;
+        goto on_error;
+    }
+
+    PJ_LOG(5, (THIS_FILE, "The AVI file has %d streams.",
+               avi_hdr.avih_hdr.num_streams));
+
+    /* Unsupported AVI format. */
+    if (avi_hdr.avih_hdr.num_streams > PJMEDIA_AVI_MAX_NUM_STREAMS) {
+        status = PJMEDIA_EAVIUNSUPP;
+        goto on_error;
+    }
+
+    /** 
+     * TODO: Possibly unsupported AVI format.
+     * If you encounter this warning, verify whether the avi player
+     * is working properly.
+     */
+    if (avi_hdr.avih_hdr.flags & AVIF_MUSTUSEINDEX ||
+        avi_hdr.avih_hdr.pad > 1)
+    {
+        PJ_LOG(3, (THIS_FILE, "Warning!!! Possibly unsupported AVI format: "
+                   "flags:%d, pad:%d", avi_hdr.avih_hdr.flags, 
+                   avi_hdr.avih_hdr.pad));
+    }
+
+    /* Read the headers of each stream. */
+    for (i = 0; i < avi_hdr.avih_hdr.num_streams; i++) {
+        pj_size_t elem = 0;
+        pj_ssize_t size_to_read;
+
+        /* Read strl header */
+        status = file_read(fport[0]->fd, &avi_hdr.strl_hdr[i],
+                           sizeof(strl_hdr_t));
+        if (status != PJ_SUCCESS)
+            goto on_error;
+        
+        elem = COMPARE_TAG(avi_hdr.strl_hdr[i].data_type, 
+                           PJMEDIA_AVI_VIDS_TAG) ? 
+               sizeof(strf_video_hdr_t) :
+               COMPARE_TAG(avi_hdr.strl_hdr[i].data_type, 
+                           PJMEDIA_AVI_AUDS_TAG) ?
+               sizeof(strf_audio_hdr_t) : 0;
+
+        /* Read strf header */
+        status = file_read2(fport[0]->fd, &avi_hdr.strf_hdr[i],
+                            elem, 0);
+        if (status != PJ_SUCCESS)
+            goto on_error;
+
+        /* Normalize the endian */
+        if (elem == sizeof(strf_video_hdr_t))
+            data_to_host2(&avi_hdr.strf_hdr[i],
+                          sizeof(strf_video_hdr_sizes)/
+                          sizeof(strf_video_hdr_sizes[0]),
+                          strf_video_hdr_sizes);
+        else if (elem == sizeof(strf_audio_hdr_t))
+            data_to_host2(&avi_hdr.strf_hdr[i],
+                          sizeof(strf_audio_hdr_sizes)/
+                          sizeof(strf_audio_hdr_sizes[0]),
+                          strf_audio_hdr_sizes);
+
+        /* Skip the remainder of the header */
+        size_to_read = avi_hdr.strl_hdr[i].list_sz - (sizeof(strl_hdr_t) -
+                       8) - elem;
+	status = pj_file_setpos(fport[0]->fd, size_to_read, PJ_SEEK_CUR);
+	if (status != PJ_SUCCESS) {
+            goto on_error;
+	}
+    }
+
+    /* Finish reading the AVIH header */
+    status = pj_file_setpos(fport[0]->fd, avi_hdr.avih_hdr.list_sz +
+                            sizeof(riff_hdr_t) + 8, PJ_SEEK_SET);
+    if (status != PJ_SUCCESS) {
+        goto on_error;
+    }
+
+    /* Skip any JUNK or LIST INFO until we get MOVI tag */
+    do {
+        pjmedia_avi_subchunk ch;
+        int read = 0;
+
+        status = file_read(fport[0]->fd, &ch, sizeof(pjmedia_avi_subchunk));
+        if (status != PJ_SUCCESS) {
+            goto on_error;
+        }
+
+        if (COMPARE_TAG(ch.id, PJMEDIA_AVI_LIST_TAG))
+        {
+            read = 4;
+            status = file_read(fport[0]->fd, &ch, read);
+            if (COMPARE_TAG(ch.id, PJMEDIA_AVI_MOVI_TAG))
+                break;
+        }
+
+        status = pj_file_setpos(fport[0]->fd, ch.len-read, PJ_SEEK_CUR);
+        if (status != PJ_SUCCESS) {
+            goto on_error;
+        }
+    } while(1);
+
+    status = pj_file_getpos(fport[0]->fd, &pos);
+    if (status != PJ_SUCCESS)
+        goto on_error;
+
+    for (i = 0, nstr = 0; i < avi_hdr.avih_hdr.num_streams; i++) {
+        /* Skip non-audio, non-video, or disabled streams) */
+        if ((!COMPARE_TAG(avi_hdr.strl_hdr[i].data_type, 
+                          PJMEDIA_AVI_VIDS_TAG) &&
+             !COMPARE_TAG(avi_hdr.strl_hdr[i].data_type, 
+                          PJMEDIA_AVI_AUDS_TAG)) ||
+            avi_hdr.strl_hdr[i].flags & AVISF_DISABLED)
+        {
+            continue;
+        }
+
+        if (COMPARE_TAG(avi_hdr.strl_hdr[i].data_type, 
+                        PJMEDIA_AVI_VIDS_TAG))
+        {
+            /* Check supported video formats here */
+            if (avi_hdr.strl_hdr[i].flags & AVISF_VIDEO_PALCHANGES ||
+                (avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_MJPEG &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_UYVY &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_YUY2 &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_IYUV &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_I420 &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_DIB &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB24 &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB32))
+            {
+                PJ_LOG(4, (THIS_FILE, "Unsupported video stream"));
+                continue;
+            }
+        } else {
+            /* Check supported audio formats here */
+            if ((avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_PCM &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_ALAW &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_ULAW &&
+                 avi_hdr.strl_hdr[i].codec != PJMEDIA_WAVE_FMT_TAG_PCM) ||
+                avi_hdr.strf_hdr[i].strf_audio_hdr.bits_per_sample != 16)
+            {
+                PJ_LOG(4, (THIS_FILE, "Unsupported audio stream"));
+                continue;
+            }
+        }
+
+        if (nstr == 0) {
+            fport[0]->stream_id = i;
+            nstr++;
+            continue;
+        }
+
+        /* Create fport instance. */
+        fport[nstr] = create_avi_port(pool);
+        if (!fport[nstr]) {
+	    status = PJ_ENOMEM;
+            goto on_error;
+        }
+
+        fport[nstr]->stream_id = i;
+
+        /* Open file. */
+        status = pj_file_open(pool, filename, PJ_O_RDONLY, &fport[nstr]->fd);
+        if (status != PJ_SUCCESS)
+            goto on_error;
+
+        /* Set the file position */
+        status = pj_file_setpos(fport[nstr]->fd, pos, PJ_SEEK_SET);
+        if (status != PJ_SUCCESS) {
+            goto on_error;
+        }
+
+        nstr++;
+    }
+
+    if (nstr == 0) {
+        status = PJMEDIA_EAVIUNSUPP;
+        goto on_error;
+    }
+
+    for (i = 0; i < nstr; i++) {
+        strl_hdr_t *strl_hdr = &avi_hdr.strl_hdr[fport[i]->stream_id];
+
+        /* Initialize */
+        fport[i]->options = options;
+        fport[i]->fsize = fport[0]->fsize;
+        /* Current file position now points to start of data */
+        fport[i]->start_data = pos;
+        
+        if (COMPARE_TAG(strl_hdr->data_type, PJMEDIA_AVI_VIDS_TAG)) {
+            strf_video_hdr_t *strf_hdr =
+                &avi_hdr.strf_hdr[fport[i]->stream_id].strf_video_hdr;
+            const pjmedia_video_format_info *vfi;
+
+            vfi = pjmedia_get_video_format_info(
+                pjmedia_video_format_mgr_instance(),
+                strl_hdr->codec);
+
+            fport[i]->bits_per_sample = (vfi ? vfi->bpp : 0);
+            pjmedia_format_init_video(&fport[i]->base.info.fmt,
+                                      strl_hdr->codec,
+                                      strf_hdr->biWidth,
+                                      strf_hdr->biHeight,
+                                      strl_hdr->rate,
+                                      strl_hdr->scale);
+            
+        } else {
+            strf_audio_hdr_t *strf_hdr =
+                &avi_hdr.strf_hdr[fport[i]->stream_id].strf_audio_hdr;
+
+            fport[i]->bits_per_sample = strf_hdr->bits_per_sample;
+            pjmedia_format_init_audio(&fport[i]->base.info.fmt,
+                                      strl_hdr->codec,
+                                      strf_hdr->sample_rate,
+                                      strf_hdr->nchannels,
+                                      strf_hdr->bits_per_sample,
+                                      20000,
+                                      strf_hdr->bytes_per_sec,
+                                      strf_hdr->bytes_per_sec);
+        }
+
+        pj_strdup2(pool, &fport[i]->base.info.name, filename);
+    }
+
+    /* Done. */
+    *p_streams = pj_pool_alloc(pool, sizeof(pjmedia_avi_streams));
+    (*p_streams)->num_streams = nstr;
+    (*p_streams)->streams = pj_pool_calloc(pool, (*p_streams)->num_streams,
+                                           sizeof(pjmedia_port *));
+    for (i = 0; i < nstr; i++)
+        (*p_streams)->streams[i] = &fport[i]->base;
+
+    PJ_LOG(4,(THIS_FILE, 
+	      "AVI file player '%.*s' created with "
+	      "%d media ports",
+	      (int)fport[0]->base.info.name.slen,
+	      fport[0]->base.info.name.ptr,
+              (*p_streams)->num_streams));
+
+    return PJ_SUCCESS;
+
+on_error:
+    fport[0]->base.on_destroy(&fport[0]->base);
+    for (i = 1; i < nstr; i++)
+        fport[i]->base.on_destroy(&fport[i]->base);
+    if (status == AVI_EOF)
+        return PJMEDIA_EINVALIMEDIATYPE;
+    return status;
+}
+
+PJ_DEF(pj_uint8_t)
+pjmedia_avi_streams_get_num_streams(pjmedia_avi_streams *streams)
+{
+    pj_assert(streams);
+    return streams->num_streams;
+}
+
+PJ_DEF(pjmedia_avi_stream *)
+pjmedia_avi_streams_get_stream(pjmedia_avi_streams *streams,
+                               pj_uint8_t idx)
+{
+    pj_assert(streams);
+    return (idx >=0 && idx < streams->num_streams ?
+            streams->streams[idx] : NULL);
+}
+
+PJ_DEF(pjmedia_avi_stream *)
+pjmedia_avi_streams_get_stream_by_media(pjmedia_avi_streams *streams,
+                                        pj_uint8_t start_idx,
+                                        pjmedia_type media_type)
+{
+    pj_uint8_t i;
+
+    pj_assert(streams);
+    for (i = start_idx; i < streams->num_streams; i++)
+        if (streams->streams[i]->info.fmt.type == media_type)
+            return streams->streams[i];
+    return NULL;
+}
+
+
+/*
+ * Get the data length, in bytes.
+ */
+PJ_DEF(pj_ssize_t) pjmedia_avi_stream_get_len(pjmedia_avi_stream *stream)
+{
+    struct avi_reader_port *fport;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(stream, -PJ_EINVAL);
+
+    /* Check that this is really a player port */
+    PJ_ASSERT_RETURN(stream->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+    fport = (struct avi_reader_port*) stream;
+
+    return (pj_ssize_t)(fport->fsize - fport->start_data);
+}
+
+
+/*
+ * Register a callback to be called when the file reading has reached the
+ * end of file.
+ */
+PJ_DEF(pj_status_t)
+pjmedia_avi_stream_set_eof_cb( pjmedia_avi_stream *stream,
+			       void *user_data,
+			       pj_status_t (*cb)(pjmedia_avi_stream *stream,
+						 void *usr_data))
+{
+    struct avi_reader_port *fport;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(stream, -PJ_EINVAL);
+
+    /* Check that this is really a player port */
+    PJ_ASSERT_RETURN(stream->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+    fport = (struct avi_reader_port*) stream;
+
+    fport->base.port_data.pdata = user_data;
+    fport->cb = cb;
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Get frame from file.
+ */
+static pj_status_t avi_get_frame(pjmedia_port *this_port, 
+			         pjmedia_frame *frame)
+{
+    struct avi_reader_port *fport = (struct avi_reader_port*)this_port;
+    pj_status_t status;
+    pj_ssize_t size_read = 0, size_to_read = 0;
+
+    pj_assert(fport->base.info.signature == SIGNATURE);
+
+    /* We encountered end of file */
+    if (fport->eof) {
+	pj_status_t status = PJ_SUCCESS;
+
+	PJ_LOG(5,(THIS_FILE, "File port %.*s EOF",
+		  (int)fport->base.info.name.slen,
+		  fport->base.info.name.ptr));
+
+	/* Call callback, if any */
+	if (fport->cb)
+	    status = (*fport->cb)(this_port, fport->base.port_data.pdata);
+
+	/* If callback returns non PJ_SUCCESS or 'no loop' is specified,
+	 * return immediately (and don't try to access player port since
+	 * it might have been destroyed by the callback).
+	 */
+	if ((status != PJ_SUCCESS) ||
+            (fport->options & PJMEDIA_AVI_FILE_NO_LOOP)) 
+        {
+	    frame->type = PJMEDIA_FRAME_TYPE_NONE;
+	    frame->size = 0;
+	    return PJ_EEOF;
+	}
+
+        /* Rewind file */
+	PJ_LOG(5,(THIS_FILE, "File port %.*s rewinding..",
+		  (int)fport->base.info.name.slen,
+		  fport->base.info.name.ptr));
+	fport->eof = PJ_FALSE;
+        pj_file_setpos(fport->fd, fport->start_data, PJ_SEEK_SET);
+    }
+
+    /* Fill frame buffer. */
+    size_to_read = frame->size;
+    do {
+        pjmedia_avi_subchunk ch = {0, 0};
+        char *cid;
+        pj_uint8_t stream_id;
+
+        /* We need to read data from the file past the chunk boundary */
+        if (fport->size_left > 0 && fport->size_left < size_to_read) {
+            status = file_read3(fport->fd, frame->buf, fport->size_left,
+                                fport->bits_per_sample, &size_read);
+            if (status != PJ_SUCCESS)
+                goto on_error2;
+            size_to_read -= fport->size_left;
+            fport->size_left = 0;
+        }
+
+        /* Read new chunk data */
+        if (fport->size_left == 0) {
+            pj_off_t pos;
+            pj_file_getpos(fport->fd, &pos);
+
+            /* Data is padded to the nearest WORD boundary */
+            if (fport->pad) {
+                status = pj_file_setpos(fport->fd, fport->pad, PJ_SEEK_CUR);
+                fport->pad = 0;
+            }
+
+            status = file_read(fport->fd, &ch, sizeof(pjmedia_avi_subchunk));
+            if (status != PJ_SUCCESS) {
+                size_read = 0;
+                goto on_error2;
+            }
+
+            cid = (char *)&ch.id;
+            if (cid[0] >= '0' && cid[0] <= '9' &&
+                cid[1] >= '0' && cid[1] <= '9') 
+            {
+                stream_id = (cid[0] - '0') * 10 + (cid[1] - '0');
+            } else
+                stream_id = 100;
+            fport->pad = (pj_uint8_t)ch.len & 1;
+
+            TRACE_((THIS_FILE, "Reading movi data at pos %u (%x), id: %.*s, "
+                               "length: %u", (unsigned long)pos,
+                               (unsigned long)pos, 4, cid, ch.len));
+
+            /* We are only interested in data with our stream id */
+            if (stream_id != fport->stream_id) {
+                if (COMPARE_TAG(ch.id, PJMEDIA_AVI_LIST_TAG))
+                    PJ_LOG(5, (THIS_FILE, "Unsupported LIST tag found in "
+                                          "the movi data."));
+                else if (COMPARE_TAG(ch.id, PJMEDIA_AVI_RIFF_TAG)) {
+                    PJ_LOG(3, (THIS_FILE, "Unsupported format: multiple "
+                           "AVIs in a single file."));
+                    status = AVI_EOF;
+                    goto on_error2;
+                }
+
+                status = pj_file_setpos(fport->fd, ch.len,
+                                        PJ_SEEK_CUR);
+                continue;
+            }
+            fport->size_left = ch.len;
+        }
+
+        frame->type = (fport->base.info.fmt.type == PJMEDIA_TYPE_VIDEO ?
+                       PJMEDIA_FRAME_TYPE_VIDEO : PJMEDIA_FRAME_TYPE_AUDIO);
+        frame->timestamp.u64 = 0;
+        if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) {
+            if (size_to_read > fport->size_left)
+                size_to_read = fport->size_left;
+            status = file_read3(fport->fd, (char *)frame->buf + frame->size -
+                                size_to_read, size_to_read,
+                                fport->bits_per_sample, &size_read);
+            if (status != PJ_SUCCESS)
+                goto on_error2;
+            fport->size_left -= size_to_read;
+        } else {
+            pj_assert(frame->size >= ch.len);
+            status = file_read3(fport->fd, frame->buf, ch.len,
+                                0, &size_read);
+            if (status != PJ_SUCCESS)
+                goto on_error2;
+            frame->size = ch.len;
+            fport->size_left = 0;
+        }
+
+        break;
+
+    } while(1);
+
+    return PJ_SUCCESS;
+
+on_error2:
+    if (status == AVI_EOF) {
+        size_to_read -= size_read;
+        pj_bzero((char *)frame->buf + frame->size - size_to_read,
+                 size_to_read);
+        fport->eof = PJ_TRUE;
+
+        return PJ_SUCCESS;
+    }
+
+    return status;
+}
+
+/*
+ * Destroy port.
+ */
+static pj_status_t avi_on_destroy(pjmedia_port *this_port)
+{
+    struct avi_reader_port *fport = (struct avi_reader_port*) this_port;
+
+    pj_assert(this_port->info.signature == SIGNATURE);
+
+    if (fport->fd != (pj_oshandle_t) -1)
+        pj_file_close(fport->fd);
+    return PJ_SUCCESS;
+}
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/bidirectional.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/bidirectional.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/bidirectional.c	(revision 3392)
@@ -34,5 +34,5 @@
 
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame)
+			     pjmedia_frame *frame)
 {
     struct bidir_port *p = (struct bidir_port*)this_port;
@@ -55,12 +55,14 @@
 {
     struct bidir_port *port;
+    const pjmedia_audio_format_detail *gafd;
 
     port = PJ_POOL_ZALLOC_T(pool, struct bidir_port);
+    gafd = pjmedia_format_get_audio_format_detail(&get_port->info.fmt, 1);
 
     pjmedia_port_info_init(&port->base.info, &get_port->info.name, SIGNATURE,
-			   get_port->info.clock_rate,
-			   get_port->info.channel_count,
-			   get_port->info.bits_per_sample,
-			   get_port->info.samples_per_frame);
+			   gafd->clock_rate,
+			   gafd->channel_count,
+			   gafd->bits_per_sample,
+			   PJMEDIA_AFD_SPF(gafd));
 
     port->get_port = get_port;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/clock_thread.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/clock_thread.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/clock_thread.c	(revision 3392)
@@ -51,4 +51,5 @@
 
 #define MAX_JUMP_MSEC	500
+#define USEC_IN_SEC	(pj_uint64_t)1000000
 
 /*
@@ -64,12 +65,25 @@
 					  pjmedia_clock **p_clock)
 {
+    return pjmedia_clock_create2(pool,
+			         (unsigned)(samples_per_frame * USEC_IN_SEC /
+					    channel_count / clock_rate),
+				 clock_rate, options, cb, user_data, p_clock);
+}
+
+PJ_DEF(pj_status_t) pjmedia_clock_create2(pj_pool_t *pool,
+				          unsigned usec_interval,
+				          unsigned clock_rate,
+				          unsigned options,
+				          pjmedia_clock_callback *cb,
+				          void *user_data,
+				          pjmedia_clock **p_clock)
+{
     pjmedia_clock *clock;
     pj_status_t status;
 
-    PJ_ASSERT_RETURN(pool && clock_rate && samples_per_frame && p_clock,
+    PJ_ASSERT_RETURN(pool && usec_interval && clock_rate && p_clock,
 		     PJ_EINVAL);
 
     clock = PJ_POOL_ALLOC_T(pool, pjmedia_clock);
-
     
     status = pj_get_timestamp_freq(&clock->freq);
@@ -77,10 +91,10 @@
 	return status;
 
-    clock->interval.u64 = samples_per_frame * clock->freq.u64 / 
-			  channel_count / clock_rate;
+    clock->interval.u64 = usec_interval * clock->freq.u64 / USEC_IN_SEC;
     clock->next_tick.u64 = 0;
     clock->timestamp.u64 = 0;
     clock->max_jump = MAX_JUMP_MSEC * clock->freq.u64 / 1000;
-    clock->timestamp_inc = samples_per_frame / channel_count;
+    clock->timestamp_inc = (unsigned)(usec_interval * clock_rate /
+				      USEC_IN_SEC);
     clock->options = options;
     clock->cb = cb;
@@ -111,4 +125,5 @@
 
 
+
 /*
  * Start the clock. 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conf_switch.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conf_switch.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conf_switch.c	(revision 3392)
@@ -24,8 +24,8 @@
 #include <pjmedia/silencedet.h>
 #include <pjmedia/sound_port.h>
-#include <pjmedia/stream.h>
 #include <pj/array.h>
 #include <pj/assert.h>
 #include <pj/log.h>
+#include <pj/math.h>
 #include <pj/pool.h>
 #include <pj/string.h>
@@ -81,4 +81,5 @@
     /* Shortcut for port info. */
     pjmedia_port_info	*info;
+    unsigned		 samples_per_frame;
 
     /* Calculated signal levels: */
@@ -124,5 +125,5 @@
 /* Prototypes */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame);
+			     pjmedia_frame *frame);
 static pj_status_t get_frame(pjmedia_port *this_port, 
 			     pjmedia_frame *frame);
@@ -167,4 +168,5 @@
     conf_port->port = port;
     conf_port->info = &port->info;
+    conf_port->samples_per_frame= PJMEDIA_PINFO_SAMPLES_PER_FRAME(&port->info);
 
     /* Init pjmedia_frame structure in the TX buffer. */
@@ -505,4 +507,5 @@
     struct conf_port *src_port, *dst_port;
     pj_bool_t start_sound = PJ_FALSE;
+    pjmedia_audio_format_detail *src_afd, *dst_afd;
     unsigned i;
 
@@ -524,7 +527,10 @@
     }
 
+    src_afd = pjmedia_format_get_audio_format_detail(&src_port->info->fmt, 1);
+    dst_afd = pjmedia_format_get_audio_format_detail(&dst_port->info->fmt, 1);
+
     /* Format must match. */
-    if (src_port->info->format.id != dst_port->info->format.id ||
-	src_port->info->format.bitrate != dst_port->info->format.bitrate) 
+    if (src_port->info->fmt.id != dst_port->info->fmt.id ||
+	src_afd->avg_bps != dst_afd->avg_bps)
     {
 	pj_mutex_unlock(conf->mutex);
@@ -533,5 +539,5 @@
 
     /* Clock rate must match. */
-    if (src_port->info->clock_rate != dst_port->info->clock_rate) {
+    if (src_afd->clock_rate != dst_afd->clock_rate) {
 	pj_mutex_unlock(conf->mutex);
 	return PJMEDIA_ENCCLOCKRATE;
@@ -539,5 +545,5 @@
 
     /* Channel count must match. */
-    if (src_port->info->channel_count != dst_port->info->channel_count) {
+    if (src_afd->channel_count != dst_afd->channel_count) {
 	pj_mutex_unlock(conf->mutex);
 	return PJMEDIA_ENCCLOCKRATE;
@@ -545,8 +551,6 @@
 
     /* Source and sink ptime must be equal or a multiplication factor. */
-    if ((src_port->info->samples_per_frame % 
-	 dst_port->info->samples_per_frame != 0) &&
-        (dst_port->info->samples_per_frame % 
-         src_port->info->samples_per_frame != 0))
+    if ((src_afd->frame_time_usec % dst_afd->frame_time_usec != 0) &&
+        (dst_afd->frame_time_usec % src_afd->frame_time_usec != 0))
     {
 	pj_mutex_unlock(conf->mutex);
@@ -830,4 +834,5 @@
 {
     struct conf_port *conf_port;
+    const pjmedia_audio_format_detail *afd;
 
     /* Check arguments */
@@ -843,4 +848,6 @@
 	return PJ_EINVAL;
     }
+
+    afd = pjmedia_format_get_audio_format_detail(&conf_port->info->fmt, 1);
 
     pj_bzero(info, sizeof(pjmedia_conf_port_info));
@@ -853,9 +860,9 @@
     info->listener_slots = conf_port->listener_slots;
     info->transmitter_cnt = conf_port->transmitter_cnt;
-    info->clock_rate = conf_port->info->clock_rate;
-    info->channel_count = conf_port->info->channel_count;
-    info->samples_per_frame = conf_port->info->samples_per_frame;
-    info->bits_per_sample = conf_port->info->bits_per_sample;
-    info->format = conf_port->port->info.format;
+    info->clock_rate = afd->clock_rate;
+    info->channel_count = afd->channel_count;
+    info->samples_per_frame = conf_port->samples_per_frame;
+    info->bits_per_sample = afd->bits_per_sample;
+    info->format = conf_port->port->info.fmt;
     info->tx_adj_level = conf_port->tx_adj_level - NORMAL_LEVEL;
     info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL;
@@ -961,5 +968,5 @@
 
     /* Level adjustment is applicable only for ports that work with raw PCM. */
-    PJ_ASSERT_RETURN(conf_port->info->format.id == PJMEDIA_FORMAT_L16,
+    PJ_ASSERT_RETURN(conf_port->info->fmt.id == PJMEDIA_FORMAT_L16,
 		     PJ_EIGNORED);
 
@@ -1003,5 +1010,5 @@
 
     /* Level adjustment is applicable only for ports that work with raw PCM. */
-    PJ_ASSERT_RETURN(conf_port->info->format.id == PJMEDIA_FORMAT_L16,
+    PJ_ASSERT_RETURN(conf_port->info->fmt.id == PJMEDIA_FORMAT_L16,
 		     PJ_EIGNORED);
 
@@ -1047,5 +1054,5 @@
 	     * samples per frame.
 	     */
-	    if (f_dst->samples_cnt >= cport_dst->info->samples_per_frame)
+	    if (f_dst->samples_cnt >= cport_dst->samples_per_frame)
 	    {
 		if (cport_dst->slot) {
@@ -1059,6 +1066,6 @@
 
 		/* Update TX timestamp. */
-		pj_add_timestamp32(&cport_dst->ts_tx, 
-				   cport_dst->info->samples_per_frame);
+		pj_add_timestamp32(&cport_dst->ts_tx,
+				   cport_dst->samples_per_frame);
 	    }
 	}
@@ -1076,5 +1083,5 @@
 	    /* Copy frame to listener's TX buffer. */
 	    nsamples_to_copy = f_end - f_start;
-	    nsamples_req = cport_dst->info->samples_per_frame - 
+	    nsamples_req = cport_dst->samples_per_frame -
 			  (frm_dst->size>>1);
 	    if (nsamples_to_copy > nsamples_req)
@@ -1113,5 +1120,5 @@
 	     * samples per frame.
 	     */
-	    if ((frm_dst->size >> 1) == cport_dst->info->samples_per_frame)
+	    if ((frm_dst->size >> 1) == cport_dst->samples_per_frame)
 	    {
 		if (cport_dst->slot) {
@@ -1124,5 +1131,5 @@
 		/* Update TX timestamp. */
 		pj_add_timestamp32(&cport_dst->ts_tx, 
-				   cport_dst->info->samples_per_frame);
+				   cport_dst->samples_per_frame);
 	    }
 	}
@@ -1132,5 +1139,5 @@
 	/* Check port format. */
 	if (cport_dst->port &&
-	    cport_dst->port->info.format.id == PJMEDIA_FORMAT_L16)
+	    cport_dst->port->info.fmt.id == PJMEDIA_FORMAT_L16)
 	{
 	    /* When there is already some samples in listener's TX buffer, 
@@ -1139,9 +1146,9 @@
 	    if (frm_dst->size != 0) {
 		pjmedia_zero_samples((pj_int16_t*)frm_dst->buf,
-				     cport_dst->info->samples_per_frame - 
+				     cport_dst->samples_per_frame -
 				     (frm_dst->size>>1));
 
 		frm_dst->type = PJMEDIA_FRAME_TYPE_AUDIO;
-		frm_dst->size = cport_dst->info->samples_per_frame << 1;
+		frm_dst->size = cport_dst->samples_per_frame << 1;
 		if (cport_dst->slot) {
 		    pjmedia_port_put_frame(cport_dst->port, frm_dst);
@@ -1153,5 +1160,5 @@
 		/* Update TX timestamp. */
 		pj_add_timestamp32(&cport_dst->ts_tx, 
-				   cport_dst->info->samples_per_frame);
+				   cport_dst->samples_per_frame);
 	    }
 	} else {
@@ -1161,5 +1168,5 @@
 		frm_dst->type = PJMEDIA_FRAME_TYPE_EXTENDED;
 		pjmedia_frame_ext_append_subframe(f_dst, NULL, 0, (pj_uint16_t)
-		    (cport_dst->info->samples_per_frame - f_dst->samples_cnt));
+		    (cport_dst->samples_per_frame - f_dst->samples_cnt));
 		if (cport_dst->slot) {
 		    pjmedia_port_put_frame(cport_dst->port, frm_dst);
@@ -1172,5 +1179,5 @@
 		/* Update TX timestamp. */
 		pj_add_timestamp32(&cport_dst->ts_tx, 
-				   cport_dst->info->samples_per_frame);
+				   cport_dst->samples_per_frame);
 	    }
 	}
@@ -1186,5 +1193,5 @@
 
 	    /* Update TX timestamp. */
-	    pj_add_timestamp32(&cport_dst->ts_tx, cport_dst->info->samples_per_frame);
+	    pj_add_timestamp32(&cport_dst->ts_tx, cport_dst->samples_per_frame);
 	}
     }
@@ -1212,4 +1219,5 @@
     for (i=1, ci=1; i<conf->max_ports && ci<conf->port_cnt; ++i) {
 	struct conf_port *cport = conf->ports[i];
+	unsigned master_samples_per_frame;
 
 	/* Skip empty port. */
@@ -1220,7 +1228,9 @@
 	++ci;
 
+	master_samples_per_frame = PJMEDIA_PINFO_SAMPLES_PER_FRAME(
+					&conf->master_port->info);
+
 	/* Update clock of the port. */
-	pj_add_timestamp32(&cport->ts_clock, 
-			   conf->master_port->info.samples_per_frame);
+	pj_add_timestamp32(&cport->ts_clock, master_samples_per_frame);
 
 	/* Skip if we're not allowed to receive from this port or 
@@ -1231,6 +1241,5 @@
 	{
 	    cport->rx_level = 0;
-	    pj_add_timestamp32(&cport->ts_rx, 
-			       conf->master_port->info.samples_per_frame);
+	    pj_add_timestamp32(&cport->ts_rx, master_samples_per_frame);
 	    continue;
 	}
@@ -1246,8 +1255,8 @@
 	    pj_int32_t level = 0;
 
-	    pj_add_timestamp32(&cport->ts_rx, cport->info->samples_per_frame);
+	    pj_add_timestamp32(&cport->ts_rx, cport->samples_per_frame);
 	    
 	    f->buf = &conf->buf[sizeof(pjmedia_frame)];
-	    f->size = cport->info->samples_per_frame<<1;
+	    f->size = cport->samples_per_frame<<1;
 
 	    /* Get frame from port. */
@@ -1303,5 +1312,5 @@
 		if (listener->tx_setting == PJMEDIA_PORT_DISABLE) {
 		    pj_add_timestamp32(&listener->ts_tx, 
-				       listener->info->samples_per_frame);
+				       listener->samples_per_frame);
 		    listener->tx_level = 0;
 		    continue;
@@ -1362,5 +1371,5 @@
 
 		    pjmedia_port_put_frame(cport->port, &tmp_f);
-		    pj_add_timestamp32(&cport->ts_tx, cport->info->samples_per_frame);
+		    pj_add_timestamp32(&cport->ts_tx, cport->samples_per_frame);
 		}
 	    }
@@ -1381,5 +1390,5 @@
 	    unsigned samples_per_subframe;
 	    
-	    if (f_src_->samples_cnt < this_cport->info->samples_per_frame) {
+	    if (f_src_->samples_cnt < this_cport->samples_per_frame) {
 		f_dst->base.type = PJMEDIA_FRAME_TYPE_NONE;
 		f_dst->samples_cnt = 0;
@@ -1394,5 +1403,5 @@
 
 
-	    while (f_dst->samples_cnt < this_cport->info->samples_per_frame) {
+	    while (f_dst->samples_cnt < this_cport->samples_per_frame) {
 		sf = pjmedia_frame_ext_get_subframe(f_src_, i++);
 		pj_assert(sf);
@@ -1405,5 +1414,5 @@
 
 	} else if (f_src->type == PJMEDIA_FRAME_TYPE_AUDIO) {
-	    if ((f_src->size>>1) < this_cport->info->samples_per_frame) {
+	    if ((f_src->size>>1) < this_cport->samples_per_frame) {
 		frame->type = PJMEDIA_FRAME_TYPE_NONE;
 		frame->size = 0;
@@ -1413,6 +1422,6 @@
 	    pjmedia_copy_samples((pj_int16_t*)frame->buf, 
 				 (pj_int16_t*)f_src->buf, 
-				 this_cport->info->samples_per_frame);
-	    frame->size = this_cport->info->samples_per_frame << 1;
+				 this_cport->samples_per_frame);
+	    frame->size = this_cport->samples_per_frame << 1;
 
 	    /* Shift left TX buffer. */
@@ -1421,5 +1430,5 @@
 		pjmedia_move_samples((pj_int16_t*)f_src->buf,
 				     (pj_int16_t*)f_src->buf + 
-				     this_cport->info->samples_per_frame,
+				     this_cport->samples_per_frame,
 				     f_src->size >> 1);
 	} else { /* PJMEDIA_FRAME_TYPE_NONE */
@@ -1443,5 +1452,5 @@
  */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *f)
+			     pjmedia_frame *f)
 {
     pjmedia_conf *conf = (pjmedia_conf*) this_port->port_data.pdata;
@@ -1461,5 +1470,5 @@
     }
 
-    pj_add_timestamp32(&cport->ts_rx, cport->info->samples_per_frame);
+    pj_add_timestamp32(&cport->ts_rx, cport->samples_per_frame);
     
     /* Skip if this port is muted/disabled. */
@@ -1527,5 +1536,5 @@
 	if (listener->tx_setting == PJMEDIA_PORT_DISABLE) {
 	    pj_add_timestamp32(&listener->ts_tx, 
-			       listener->info->samples_per_frame);
+			       listener->samples_per_frame);
 	    listener->tx_level = 0;
 	    continue;
@@ -1535,5 +1544,5 @@
 	if (listener == cport) {
 	    pj_add_timestamp32(&listener->ts_tx, 
-			       listener->info->samples_per_frame);
+			       listener->samples_per_frame);
 	    listener->tx_level = 0;
 	    continue;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conference.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conference.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/conference.c	(revision 3392)
@@ -27,5 +27,4 @@
 #include <pjmedia/sound_port.h>
 #include <pjmedia/stereo.h>
-#include <pjmedia/stream.h>
 #include <pj/array.h>
 #include <pj/assert.h>
@@ -242,5 +241,5 @@
 /* Prototypes */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame);
+			     pjmedia_frame *frame);
 static pj_status_t get_frame(pjmedia_port *this_port, 
 			     pjmedia_frame *frame);
@@ -286,8 +285,11 @@
     /* Save some port's infos, for convenience. */
     if (port) {
+	pjmedia_audio_format_detail *afd;
+
+	afd = pjmedia_format_get_audio_format_detail(&port->info.fmt, 1);
 	conf_port->port = port;
-	conf_port->clock_rate = port->info.clock_rate;
-	conf_port->samples_per_frame = port->info.samples_per_frame;
-	conf_port->channel_count = port->info.channel_count;
+	conf_port->clock_rate = afd->clock_rate;
+	conf_port->samples_per_frame = PJMEDIA_AFD_SPF(afd);
+	conf_port->channel_count = afd->channel_count;
     } else {
 	conf_port->port = NULL;
@@ -751,6 +753,7 @@
      * - monochannel on port or conference bridge.
      */
-    if (strm_port->info.channel_count != conf->channel_count && 
-	(strm_port->info.channel_count != 1 && conf->channel_count != 1)) 
+    if (PJMEDIA_PIA_CCNT(&strm_port->info) != conf->channel_count &&
+	(PJMEDIA_PIA_CCNT(&strm_port->info) != 1 &&
+	 conf->channel_count != 1))
     {
 	pj_assert(!"Number of channels mismatch");
@@ -2051,5 +2054,5 @@
  */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame)
+			     pjmedia_frame *frame)
 {
     pjmedia_conf *conf = (pjmedia_conf*) this_port->port_data.pdata;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter.c	(revision 3392)
@@ -0,0 +1,162 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia/converter.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+
+
+struct pjmedia_converter_mgr
+{
+    pjmedia_converter_factory  factory_list;
+};
+
+static pjmedia_converter_mgr *converter_manager_instance;
+
+PJ_DEF(pj_status_t) pjmedia_converter_mgr_create(pj_pool_t *pool,
+					         pjmedia_converter_mgr **p_mgr)
+{
+    pjmedia_converter_mgr *mgr;
+
+    mgr = PJ_POOL_ALLOC_T(pool, pjmedia_converter_mgr);
+    pj_list_init(&mgr->factory_list);
+
+    if (!converter_manager_instance)
+	converter_manager_instance = mgr;
+
+    if (p_mgr)
+	*p_mgr = mgr;
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void)
+{
+    pj_assert(converter_manager_instance != NULL);
+    return converter_manager_instance;
+}
+
+PJ_DEF(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr)
+{
+    converter_manager_instance = mgr;
+}
+
+PJ_DEF(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr)
+{
+    pjmedia_converter_factory *f;
+
+    if (!mgr) mgr = pjmedia_converter_mgr_instance();
+
+    PJ_ASSERT_ON_FAIL(mgr != NULL, return);
+
+    f = mgr->factory_list.next;
+    while (f != &mgr->factory_list) {
+	pjmedia_converter_factory *next = f->next;
+	pj_list_erase(f);
+	(*f->op->destroy_factory)(f);
+	f = next;
+    }
+
+    if (converter_manager_instance == mgr)
+	converter_manager_instance = NULL;
+}
+
+PJ_DEF(pj_status_t)
+pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
+				       pjmedia_converter_factory *factory)
+{
+    pjmedia_converter_factory *pf;
+
+    if (!mgr) mgr = pjmedia_converter_mgr_instance();
+
+    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
+
+    PJ_ASSERT_RETURN(!pj_list_find_node(&mgr->factory_list, factory),
+		     PJ_EEXISTS);
+
+    pf = mgr->factory_list.next;
+    while (pf != &mgr->factory_list) {
+	if (pf->priority > factory->priority)
+	    break;
+	pf = pf->next;
+    }
+    pj_list_insert_before(pf, factory);
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t)
+pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
+				         pjmedia_converter_factory *f,
+				         pj_bool_t destroy)
+{
+    if (!mgr) mgr = pjmedia_converter_mgr_instance();
+
+    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
+
+    PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, f), PJ_ENOTFOUND);
+    pj_list_erase(f);
+    if (destroy)
+	(*f->op->destroy_factory)(f);
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
+					      pj_pool_t *pool,
+					      pjmedia_conversion_param *param,
+					      pjmedia_converter **p_cv)
+{
+    pjmedia_converter_factory *f;
+    pjmedia_converter *cv = NULL;
+    pj_status_t status = PJ_ENOTFOUND;
+
+    if (!mgr) mgr = pjmedia_converter_mgr_instance();
+
+    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL);
+
+    *p_cv = NULL;
+
+    f = mgr->factory_list.next;
+    while (f != &mgr->factory_list) {
+	status = (*f->op->create_converter)(f, pool, param, &cv);
+	if (status == PJ_SUCCESS)
+	    break;
+	f = f->next;
+    }
+
+    if (status != PJ_SUCCESS)
+	return status;
+
+    *p_cv = cv;
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
+					       pjmedia_frame *src_frame,
+					       pjmedia_frame *dst_frame)
+{
+    return (*cv->op->convert)(cv, src_frame, dst_frame);
+}
+
+PJ_DEF(void) pjmedia_converter_destroy(pjmedia_converter *cv)
+{
+    (*cv->op->destroy)(cv);
+}
+
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter_libswscale.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter_libswscale.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/converter_libswscale.c	(revision 3392)
@@ -0,0 +1,202 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia/converter.h>
+#include <pj/errno.h>
+
+#if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL
+
+#include "ffmpeg_util.h"
+#include <libswscale/swscale.h>
+
+static pj_status_t factory_create_converter(pjmedia_converter_factory *cf,
+					    pj_pool_t *pool,
+					    const pjmedia_conversion_param*prm,
+					    pjmedia_converter **p_cv);
+static void factory_destroy_factory(pjmedia_converter_factory *cf);
+static pj_status_t libswscale_conv_convert(pjmedia_converter *converter,
+					   pjmedia_frame *src_frame,
+					   pjmedia_frame *dst_frame);
+static void libswscale_conv_destroy(pjmedia_converter *converter);
+
+
+struct fmt_info
+{
+    const pjmedia_video_format_info 	*fmt_info;
+    pjmedia_video_apply_fmt_param 	 apply_param;
+};
+
+struct ffmpeg_converter
+{
+    pjmedia_converter 			 base;
+    struct SwsContext 			*sws_ctx;
+    struct fmt_info			 src,
+					 dst;
+};
+
+static pjmedia_converter_factory_op libswscale_factory_op =
+{
+    &factory_create_converter,
+    &factory_destroy_factory
+};
+
+static pjmedia_converter_op liswscale_converter_op =
+{
+    &libswscale_conv_convert,
+    &libswscale_conv_destroy
+};
+
+static pj_status_t factory_create_converter(pjmedia_converter_factory *cf,
+					    pj_pool_t *pool,
+					    const pjmedia_conversion_param *prm,
+					    pjmedia_converter **p_cv)
+{
+    enum PixelFormat srcFormat, dstFormat;
+    const pjmedia_video_format_detail *src_detail, *dst_detail;
+    const pjmedia_video_format_info *src_fmt_info, *dst_fmt_info;
+    struct SwsContext *sws_ctx;
+    struct ffmpeg_converter *fcv;
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(cf);
+
+    /* Only supports video */
+    if (prm->src.type != PJMEDIA_TYPE_VIDEO ||
+	prm->dst.type != prm->src.type ||
+	prm->src.detail_type != PJMEDIA_FORMAT_DETAIL_VIDEO ||
+	prm->dst.detail_type != prm->src.detail_type)
+    {
+	return PJ_ENOTSUP;
+    }
+
+    /* lookup source format info */
+    src_fmt_info = pjmedia_get_video_format_info(
+		      pjmedia_video_format_mgr_instance(),
+		      prm->src.id);
+    if (!src_fmt_info)
+	return PJ_ENOTSUP;
+
+    /* lookup destination format info */
+    dst_fmt_info = pjmedia_get_video_format_info(
+		      pjmedia_video_format_mgr_instance(),
+		      prm->dst.id);
+    if (!dst_fmt_info)
+	return PJ_ENOTSUP;
+
+    src_detail = pjmedia_format_get_video_format_detail(&prm->src, PJ_TRUE);
+    dst_detail = pjmedia_format_get_video_format_detail(&prm->dst, PJ_TRUE);
+
+    status = pjmedia_format_id_to_PixelFormat(prm->src.id, &srcFormat);
+    if (status != PJ_SUCCESS)
+	return PJ_ENOTSUP;
+
+    status = pjmedia_format_id_to_PixelFormat(prm->dst.id, &dstFormat);
+    if (status != PJ_SUCCESS)
+	return PJ_ENOTSUP;
+
+    sws_ctx = sws_getContext(src_detail->size.w, src_detail->size.h, srcFormat,
+		             dst_detail->size.w, dst_detail->size.h, dstFormat,
+			     SWS_BICUBIC,
+			     NULL, NULL, NULL);
+    if (sws_ctx == NULL)
+	return PJ_ENOTSUP;
+
+    fcv = PJ_POOL_ZALLOC_T(pool, struct ffmpeg_converter);
+    fcv->base.op = &liswscale_converter_op;
+    fcv->sws_ctx = sws_ctx;
+    fcv->src.apply_param.size = src_detail->size;
+    fcv->src.fmt_info = src_fmt_info;
+    fcv->dst.apply_param.size = dst_detail->size;
+    fcv->dst.fmt_info = dst_fmt_info;
+
+    *p_cv = &fcv->base;
+
+    return PJ_SUCCESS;
+}
+
+static void factory_destroy_factory(pjmedia_converter_factory *cf)
+{
+    PJ_UNUSED_ARG(cf);
+}
+
+static pj_status_t libswscale_conv_convert(pjmedia_converter *converter,
+					   pjmedia_frame *src_frame,
+					   pjmedia_frame *dst_frame)
+{
+    struct ffmpeg_converter *fcv = (struct ffmpeg_converter*)converter;
+    struct fmt_info *src = &fcv->src,
+	            *dst = &fcv->dst;
+    int h;
+
+    src->apply_param.buffer = src_frame->buf;
+    (*src->fmt_info->apply_fmt)(src->fmt_info, &src->apply_param);
+
+    dst->apply_param.buffer = dst_frame->buf;
+    (*dst->fmt_info->apply_fmt)(dst->fmt_info, &dst->apply_param);
+
+    h = sws_scale(fcv->sws_ctx,
+	          src->apply_param.planes, src->apply_param.strides,
+		  0, src->apply_param.size.h,
+		  dst->apply_param.planes, dst->apply_param.strides);
+
+    return h==(int)dst->apply_param.size.h ? PJ_SUCCESS : PJ_EUNKNOWN;
+}
+
+static void libswscale_conv_destroy(pjmedia_converter *converter)
+{
+    struct ffmpeg_converter *fcv = (struct ffmpeg_converter*)converter;
+    if (fcv->sws_ctx) {
+	struct SwsContext *tmp = fcv->sws_ctx;
+	fcv->sws_ctx = NULL;
+	sws_freeContext(tmp);
+    }
+}
+
+static pjmedia_converter_factory libswscale_factory =
+{
+    NULL, NULL,					/* list */
+    "libswscale",				/* name */
+    PJMEDIA_CONVERTER_PRIORITY_NORMAL+1,	/* priority */
+    NULL					/* op will be init-ed later  */
+};
+
+PJ_DEF(pj_status_t)
+pjmedia_libswscale_converter_init(pjmedia_converter_mgr *mgr,
+				  pj_pool_t *pool)
+{
+    libswscale_factory.op = &libswscale_factory_op;
+    PJ_UNUSED_ARG(pool);
+    return pjmedia_converter_mgr_register_factory(mgr, &libswscale_factory);
+}
+
+
+PJ_DEF(pj_status_t)
+pjmedia_libswscale_converter_shutdown(pjmedia_converter_mgr *mgr,
+				      pj_pool_t *pool)
+{
+    PJ_UNUSED_ARG(pool);
+    return pjmedia_converter_mgr_unregister_factory(mgr, &libswscale_factory,
+						    PJ_TRUE);
+}
+
+#ifdef _MSC_VER
+#   pragma comment( lib, "avutil.lib")
+#   pragma comment( lib, "swscale.lib")
+#endif
+
+#endif /* #if PJMEDIA_HAS_LIBSWSCALE && PJMEDIA_HAS_LIBAVUTIL */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/delaybuf.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/delaybuf.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/delaybuf.c	(revision 3392)
@@ -22,4 +22,5 @@
 #include <pjmedia/circbuf.h>
 #include <pjmedia/errno.h>
+#include <pjmedia/frame.h>
 #include <pjmedia/wsola.h>
 #include <pj/assert.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/dummy.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/dummy.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/dummy.c	(revision 3392)
@@ -0,0 +1,24 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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
+ */
+
+#include <pjmedia/frame.h>
+#include <pjmedia/port.h>
+#include <pjmedia/types.h>
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_common.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_common.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_common.c	(revision 3392)
@@ -21,4 +21,5 @@
 #include <pjmedia/echo.h>
 #include <pjmedia/delaybuf.h>
+#include <pjmedia/frame.h>
 #include <pjmedia/errno.h>
 #include <pj/assert.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_port.c	(revision 3392)
@@ -39,5 +39,5 @@
 
 static pj_status_t ec_put_frame(pjmedia_port *this_port, 
-				const pjmedia_frame *frame);
+				pjmedia_frame *frame);
 static pj_status_t ec_get_frame(pjmedia_port *this_port, 
 				pjmedia_frame *frame);
@@ -53,9 +53,13 @@
 {
     const pj_str_t AEC = { "EC", 2 };
+    pjmedia_audio_format_detail *afd;
     struct ec *ec;
     pj_status_t status;
 
     PJ_ASSERT_RETURN(pool && dn_port && p_port, PJ_EINVAL);
-    PJ_ASSERT_RETURN(dn_port->info.bits_per_sample==16 && tail_ms, 
+
+    afd = pjmedia_format_get_audio_format_detail(&dn_port->info.fmt, PJ_TRUE);
+
+    PJ_ASSERT_RETURN(afd->bits_per_sample==16 && tail_ms,
 		     PJ_EINVAL);
 
@@ -64,12 +68,12 @@
     
     pjmedia_port_info_init(&ec->base.info, &AEC, SIGNATURE,
-			   dn_port->info.clock_rate, 
-			   dn_port->info.channel_count, 
-			   dn_port->info.bits_per_sample,
-			   dn_port->info.samples_per_frame);
+			   afd->clock_rate,
+			   afd->channel_count,
+			   afd->bits_per_sample,
+			   PJMEDIA_AFD_SPF(afd));
 
-    status = pjmedia_echo_create2(pool, dn_port->info.clock_rate, 
-				  dn_port->info.channel_count,
-				  dn_port->info.samples_per_frame,
+    status = pjmedia_echo_create2(pool, afd->clock_rate,
+				  afd->channel_count,
+				  PJMEDIA_AFD_SPF(afd),
 				  tail_ms, latency_ms, options, &ec->ec);
     if (status != PJ_SUCCESS)
@@ -90,5 +94,5 @@
 
 static pj_status_t ec_put_frame( pjmedia_port *this_port, 
-				 const pjmedia_frame *frame)
+				 pjmedia_frame *frame)
 {
     struct ec *ec = (struct ec*)this_port;
@@ -100,5 +104,5 @@
     }
 
-    PJ_ASSERT_RETURN(frame->size == this_port->info.samples_per_frame * 2,
+    PJ_ASSERT_RETURN(frame->size == PJMEDIA_PIA_AVG_FSZ(&this_port->info),
 		     PJ_EINVAL);
 
@@ -120,5 +124,5 @@
     if (status!=PJ_SUCCESS || frame->type!=PJMEDIA_FRAME_TYPE_AUDIO) {
 	pjmedia_zero_samples((pj_int16_t*)frame->buf, 
-			     this_port->info.samples_per_frame);
+			      PJMEDIA_PIA_SPF(&this_port->info));
     }
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_speex.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_speex.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_speex.c	(revision 3392)
@@ -21,4 +21,5 @@
 #include <pjmedia/echo.h>
 #include <pjmedia/errno.h>
+#include <pjmedia/frame.h>
 #include <pj/assert.h>
 #include <pj/log.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_suppress.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_suppress.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/echo_suppress.c	(revision 3392)
@@ -21,4 +21,5 @@
 #include <pjmedia/alaw_ulaw.h>
 #include <pjmedia/errno.h>
+#include <pjmedia/frame.h>
 #include <pjmedia/silencedet.h>
 #include <pj/array.h>
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/errno.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/errno.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/errno.c	(revision 3392)
@@ -115,4 +115,5 @@
     PJ_BUILD_ERR( PJMEDIA_RTP_EINDTMF,	    "Invalid DTMF digit" ),
     PJ_BUILD_ERR( PJMEDIA_RTP_EREMNORFC2833,"Remote does not support RFC 2833" ),
+    PJ_BUILD_ERR( PJMEDIA_EBADFMT,	    "Bad format"),
 
     /* RTP session errors. */
@@ -143,4 +144,5 @@
     PJ_BUILD_ERR( PJMEDIA_EWAVETOOSHORT,    "WAVE file too short" ),
     PJ_BUILD_ERR( PJMEDIA_EFRMFILETOOBIG,   "Sound frame too large for file buffer"),
+    PJ_BUILD_ERR( PJMEDIA_EAVIUNSUPP,	    "Unsupported AVI file"),
 
     /* Sound device errors: */
@@ -267,2 +269,19 @@
 }
 
+/*
+ * pjmedia_videodev_strerror()
+ */
+PJ_DEF(pj_str_t) pjmedia_videodev_strerror(pj_status_t statcode, 
+					   char *buf, pj_size_t bufsize )
+{
+    pj_str_t errstr;
+
+    /* Error not found. */
+    errstr.ptr = buf;
+    errstr.slen = pj_ansi_snprintf(buf, bufsize, 
+				   "Unknown pjmedia-videodev error %d",
+				   statcode);
+
+    return errstr;
+}
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.c	(revision 3392)
@@ -0,0 +1,148 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia/types.h>
+#include <pj/errno.h>
+
+#if PJMEDIA_HAS_LIBAVFORMAT && PJMEDIA_HAS_LIBAVUTIL
+
+#include "ffmpeg_util.h"
+#include <libavformat/avformat.h>
+
+/* Conversion table between pjmedia_format_id and PixelFormat */
+static const struct ffmpeg_fmt_table_t
+{
+    pjmedia_format_id	id;
+    enum PixelFormat	pf;
+} ffmpeg_fmt_table[] =
+{
+    { PJMEDIA_FORMAT_RGBA, PIX_FMT_RGBA},
+    { PJMEDIA_FORMAT_RGB24,PIX_FMT_RGB24},
+    { PJMEDIA_FORMAT_BGRA, PIX_FMT_BGRA},
+
+    { PJMEDIA_FORMAT_AYUV, PIX_FMT_NONE},
+    { PJMEDIA_FORMAT_YUY2, PIX_FMT_YUYV422},
+    { PJMEDIA_FORMAT_UYVY, PIX_FMT_UYVY422},
+    { PJMEDIA_FORMAT_I420, PIX_FMT_YUV420P},
+    { PJMEDIA_FORMAT_YV12, PIX_FMT_YUV422P},
+    { PJMEDIA_FORMAT_I420JPEG, PIX_FMT_YUVJ420P},
+    { PJMEDIA_FORMAT_I422JPEG, PIX_FMT_YUVJ422P},
+};
+
+/* Conversion table between pjmedia_format_id and CodecID */
+static const struct ffmpeg_codec_table_t
+{
+    pjmedia_format_id	id;
+    enum CodecID	codec_id;
+} ffmpeg_codec_table[] =
+{
+    {PJMEDIA_FORMAT_H261,  CODEC_ID_H261},
+    {PJMEDIA_FORMAT_H263,  CODEC_ID_H263},
+    {PJMEDIA_FORMAT_MPEG1VIDEO,  CODEC_ID_MPEG1VIDEO},
+    {PJMEDIA_FORMAT_MPEG2VIDEO,  CODEC_ID_MPEG2VIDEO},
+    {PJMEDIA_FORMAT_MPEG4,  CODEC_ID_MPEG4},    
+    {PJMEDIA_FORMAT_MJPEG,  CODEC_ID_MJPEG},
+};
+
+static int pjmedia_ffmpeg_ref_cnt;
+
+void pjmedia_ffmpeg_add_ref()
+{
+    if (pjmedia_ffmpeg_ref_cnt++ == 0) {
+	av_register_all();
+    }
+}
+
+void pjmedia_ffmpeg_dec_ref()
+{
+    if (pjmedia_ffmpeg_ref_cnt-- == 1) {
+	/* How to shutdown ffmpeg? */
+    }
+
+    if (pjmedia_ffmpeg_ref_cnt < 0) pjmedia_ffmpeg_ref_cnt = 0;
+}
+
+pj_status_t pjmedia_format_id_to_PixelFormat(pjmedia_format_id fmt_id,
+					     enum PixelFormat *pixel_format)
+{
+    unsigned i;
+    for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_fmt_table); ++i) {
+	const struct ffmpeg_fmt_table_t *t = &ffmpeg_fmt_table[i];
+	if (t->id==fmt_id && t->pf != PIX_FMT_NONE) {
+	    *pixel_format = t->pf;
+	    return PJ_SUCCESS;
+	}
+    }
+
+    *pixel_format = PIX_FMT_NONE;
+    return PJ_ENOTFOUND;
+}
+
+pj_status_t PixelFormat_to_pjmedia_format_id(enum PixelFormat pf,
+					     pjmedia_format_id *fmt_id)
+{
+    unsigned i;
+    for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_fmt_table); ++i) {
+	const struct ffmpeg_fmt_table_t *t = &ffmpeg_fmt_table[i];
+	if (t->pf == pf) {
+	    if (fmt_id) *fmt_id = t->id;
+	    return PJ_SUCCESS;
+	}
+    }
+
+    return PJ_ENOTFOUND;
+}
+
+pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
+					 enum CodecID *codec_id)
+{
+    unsigned i;
+    for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_codec_table); ++i) {
+	const struct ffmpeg_codec_table_t *t = &ffmpeg_codec_table[i];
+	if (t->id==fmt_id && t->codec_id != PIX_FMT_NONE) {
+	    *codec_id = t->codec_id;
+	    return PJ_SUCCESS;
+	}
+    }
+
+    *codec_id = PIX_FMT_NONE;
+    return PJ_ENOTFOUND;
+}
+
+pj_status_t CodecID_to_pjmedia_format_id(enum CodecID codec_id,
+					 pjmedia_format_id *fmt_id)
+{
+    unsigned i;
+    for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_codec_table); ++i) {
+	const struct ffmpeg_codec_table_t *t = &ffmpeg_codec_table[i];
+	if (t->codec_id == codec_id) {
+	    if (fmt_id) *fmt_id = t->id;
+	    return PJ_SUCCESS;
+	}
+    }
+
+    return PJ_ENOTFOUND;
+}
+
+
+#ifdef _MSC_VER
+#   pragma comment( lib, "avformat.lib")
+#   pragma comment( lib, "avutil.lib")
+#endif
+
+#endif	/* #if PJMEDIA_HAS_LIBAVFORMAT && PJMEDIA_HAS_LIBAVUTIL */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.h	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/ffmpeg_util.h	(revision 3392)
@@ -0,0 +1,55 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+
+/*
+ * This file contains common utilities that are useful for pjmedia components
+ * that use ffmpeg. This is not a public API.
+ */
+
+#ifndef __PJMEDIA_FFMPEG_UTIL_H__
+#define __PJMEDIA_FFMPEG_UTIL_H__
+
+#include <pjmedia/format.h>
+
+#ifdef _MSC_VER
+#   ifndef __cplusplus
+#	define inline _inline
+#   endif
+#   pragma warning(disable:4244) /* possible loss of data */
+#endif
+
+#include <libavutil/avutil.h>
+#include <libavcodec/avcodec.h>
+
+void pjmedia_ffmpeg_add_ref();
+void pjmedia_ffmpeg_dec_ref();
+
+pj_status_t pjmedia_format_id_to_PixelFormat(pjmedia_format_id fmt_id,
+					     enum PixelFormat *pixel_format);
+
+pj_status_t PixelFormat_to_pjmedia_format_id(enum PixelFormat pf,
+					     pjmedia_format_id *fmt_id);
+
+pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
+					 enum CodecID *codec_id);
+
+pj_status_t CodecID_to_pjmedia_format_id(enum CodecID codec_id,
+					 pjmedia_format_id *fmt_id);
+
+#endif /* __PJMEDIA_FFMPEG_UTIL_H__ */
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/format.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/format.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/format.c	(revision 3392)
@@ -0,0 +1,366 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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
+ */
+#include <pjmedia/format.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+#include <pj/pool.h>
+#include <pj/string.h>
+
+static pj_status_t apply_packed_fmt(const pjmedia_video_format_info *fi,
+	                            pjmedia_video_apply_fmt_param *aparam);
+
+static pj_status_t apply_planar_420(const pjmedia_video_format_info *fi,
+	                            pjmedia_video_apply_fmt_param *aparam);
+
+static pj_status_t apply_planar_422(const pjmedia_video_format_info *fi,
+	                            pjmedia_video_apply_fmt_param *aparam);
+
+struct pjmedia_video_format_mgr
+{
+    unsigned			max_info;
+    unsigned			info_cnt;
+    pjmedia_video_format_info **infos;
+};
+
+static pjmedia_video_format_mgr *video_format_mgr_instance;
+static pjmedia_video_format_info built_in_vid_fmt_info[] =
+{
+    {PJMEDIA_FORMAT_RGB24, "RGB24", PJMEDIA_COLOR_MODEL_RGB, 24, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_RGBA,  "RGBA", PJMEDIA_COLOR_MODEL_RGB, 32, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_BGRA,  "BGRA", PJMEDIA_COLOR_MODEL_RGB, 32, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_DIB ,  "DIB ", PJMEDIA_COLOR_MODEL_RGB, 24, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_AYUV,  "AYUV", PJMEDIA_COLOR_MODEL_YUV, 32, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_YUY2,  "YUY2", PJMEDIA_COLOR_MODEL_YUV, 16, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_UYVY,  "UYVY", PJMEDIA_COLOR_MODEL_YUV, 16, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_YVYU,  "YVYU", PJMEDIA_COLOR_MODEL_YUV, 16, 1, &apply_packed_fmt},
+    {PJMEDIA_FORMAT_I420,  "I420", PJMEDIA_COLOR_MODEL_YUV, 12, 3, &apply_planar_420},
+    {PJMEDIA_FORMAT_YV12,  "YV12", PJMEDIA_COLOR_MODEL_YUV, 16, 3, &apply_planar_422},
+    {PJMEDIA_FORMAT_I420JPEG, "I420JPG", PJMEDIA_COLOR_MODEL_YUV, 12, 3, &apply_planar_420},
+    {PJMEDIA_FORMAT_I422JPEG, "I422JPG", PJMEDIA_COLOR_MODEL_YUV, 16, 3, &apply_planar_422},
+};
+
+
+PJ_DEF(void) pjmedia_format_init_audio( pjmedia_format *fmt,
+				        pj_uint32_t fmt_id,
+					unsigned clock_rate,
+					unsigned channel_count,
+					unsigned bits_per_sample,
+					unsigned frame_time_usec,
+					pj_uint32_t avg_bps,
+					pj_uint32_t max_bps)
+{
+    fmt->id = fmt_id;
+    fmt->type = PJMEDIA_TYPE_AUDIO;
+    fmt->detail_type = PJMEDIA_FORMAT_DETAIL_AUDIO;
+
+    fmt->det.aud.clock_rate = clock_rate;
+    fmt->det.aud.channel_count = channel_count;
+    fmt->det.aud.bits_per_sample = bits_per_sample;
+    fmt->det.aud.frame_time_usec = frame_time_usec;
+    fmt->det.aud.avg_bps = avg_bps;
+    fmt->det.aud.max_bps = max_bps;
+}
+
+PJ_DEF(void) pjmedia_format_init_video( pjmedia_format *fmt,
+					pj_uint32_t fmt_id,
+					unsigned width,
+					unsigned height,
+					unsigned fps_num,
+					unsigned fps_denum)
+{
+    fmt->id = fmt_id;
+    fmt->type = PJMEDIA_TYPE_VIDEO;
+    fmt->detail_type = PJMEDIA_FORMAT_DETAIL_VIDEO;
+
+    fmt->det.vid.size.w = width;
+    fmt->det.vid.size.h = height;
+    fmt->det.vid.fps.num = fps_num;
+    fmt->det.vid.fps.denum = fps_denum;
+    fmt->det.vid.avg_bps = fmt->det.vid.max_bps = 0;
+
+    if (pjmedia_video_format_mgr_instance()) {
+	const pjmedia_video_format_info *vfi;
+	pjmedia_video_apply_fmt_param vafp;
+	pj_uint32_t bps;
+
+	vfi = pjmedia_get_video_format_info(NULL, fmt->id);
+        if (vfi) {
+	    pj_bzero(&vafp, sizeof(vafp));
+	    vafp.size = fmt->det.vid.size;
+	    vfi->apply_fmt(vfi, &vafp);
+
+	    bps = vafp.framebytes * fps_num * (pj_size_t)8 / fps_denum;
+	    fmt->det.vid.avg_bps = fmt->det.vid.max_bps = bps;
+        }
+    }
+}
+
+PJ_DEF(pjmedia_audio_format_detail*)
+pjmedia_format_get_audio_format_detail(const pjmedia_format *fmt,
+				       pj_bool_t assert_valid)
+{
+    if (fmt->detail_type==PJMEDIA_FORMAT_DETAIL_AUDIO) {
+	return (pjmedia_audio_format_detail*) &fmt->det.aud;
+    } else {
+	pj_assert(!assert_valid || !"Invalid audio format detail");
+	return NULL;
+    }
+}
+
+PJ_DEF(pjmedia_video_format_detail*)
+pjmedia_format_get_video_format_detail(const pjmedia_format *fmt,
+				       pj_bool_t assert_valid)
+{
+    if (fmt->detail_type==PJMEDIA_FORMAT_DETAIL_VIDEO) {
+	return (pjmedia_video_format_detail*)&fmt->det.vid;
+    } else {
+	pj_assert(!assert_valid || !"Invalid video format detail");
+	return NULL;
+    }
+}
+
+PJ_DEF(pjmedia_format*) pjmedia_format_copy(pjmedia_format *dst,
+					    const pjmedia_format *src)
+{
+    return (pjmedia_format*)pj_memcpy(dst, src, sizeof(*src));
+}
+
+
+static pj_status_t apply_packed_fmt(const pjmedia_video_format_info *fi,
+	                            pjmedia_video_apply_fmt_param *aparam)
+{
+    unsigned i;
+    pj_size_t stride;
+
+    stride = (pj_size_t)((aparam->size.w*fi->bpp) >> 3);
+
+    /* Calculate memsize */
+    aparam->framebytes = stride * aparam->size.h;
+
+    /* Packed formats only use 1 plane */
+    aparam->planes[0] = aparam->buffer;
+    aparam->strides[0] = stride;
+    aparam->plane_bytes[0] = aparam->framebytes;
+
+    /* Zero unused planes */
+    for (i=1; i<PJMEDIA_MAX_VIDEO_PLANES; ++i) {
+	aparam->strides[i] = 0;
+	aparam->planes[i] = NULL;
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t apply_planar_420(const pjmedia_video_format_info *fi,
+	                             pjmedia_video_apply_fmt_param *aparam)
+{
+    unsigned i;
+    pj_size_t Y_bytes;
+
+    PJ_UNUSED_ARG(fi);
+
+    /* Calculate memsize */
+    Y_bytes = (pj_size_t)(aparam->size.w * aparam->size.h);
+    aparam->framebytes = Y_bytes + (Y_bytes>>1);
+
+    /* Planar formats use 3 plane */
+    aparam->strides[0] = aparam->size.w;
+    aparam->strides[1] = aparam->strides[2] = (aparam->size.w>>1);
+
+    aparam->planes[0] = aparam->buffer;
+    aparam->planes[1] = aparam->planes[0] + Y_bytes;
+    aparam->planes[2] = aparam->planes[1] + (Y_bytes>>2);
+
+    aparam->plane_bytes[0] = Y_bytes;
+    aparam->plane_bytes[1] = aparam->plane_bytes[2] = (Y_bytes>>2);
+
+    /* Zero unused planes */
+    for (i=3; i<PJMEDIA_MAX_VIDEO_PLANES; ++i) {
+	aparam->strides[i] = 0;
+	aparam->planes[i] = NULL;
+        aparam->plane_bytes[i] = 0;
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t apply_planar_422(const pjmedia_video_format_info *fi,
+	                             pjmedia_video_apply_fmt_param *aparam)
+{
+    unsigned i;
+    pj_size_t Y_bytes;
+
+    PJ_UNUSED_ARG(fi);
+
+    /* Calculate memsize */
+    Y_bytes = (pj_size_t)(aparam->size.w * aparam->size.h);
+    aparam->framebytes = (Y_bytes << 1);
+
+    /* Planar formats use 3 plane */
+    aparam->strides[0] = aparam->size.w;
+    aparam->strides[1] = aparam->strides[2] = (aparam->size.w>>1);
+
+    aparam->planes[0] = aparam->buffer;
+    aparam->planes[1] = aparam->planes[0] + Y_bytes;
+    aparam->planes[2] = aparam->planes[1] + (Y_bytes>>1);
+
+    aparam->plane_bytes[0] = Y_bytes;
+    aparam->plane_bytes[1] = aparam->plane_bytes[2] = (Y_bytes>>1);
+
+    /* Zero unused planes */
+    for (i=3; i<PJMEDIA_MAX_VIDEO_PLANES; ++i) {
+	aparam->strides[i] = 0;
+	aparam->planes[i] = NULL;
+        aparam->plane_bytes[i] = 0;
+    }
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t)
+pjmedia_video_format_mgr_create(pj_pool_t *pool,
+				unsigned max_fmt,
+				unsigned options,
+				pjmedia_video_format_mgr **p_mgr)
+{
+    pjmedia_video_format_mgr *mgr;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(pool && options==0, PJ_EINVAL);
+
+    PJ_UNUSED_ARG(options);
+
+    mgr = PJ_POOL_ALLOC_T(pool, pjmedia_video_format_mgr);
+    mgr->max_info = max_fmt;
+    mgr->info_cnt = 0;
+    mgr->infos = pj_pool_calloc(pool, max_fmt, sizeof(pjmedia_video_format_info *));
+
+    if (video_format_mgr_instance == NULL)
+	video_format_mgr_instance = mgr;
+
+    for (i=0; i<PJ_ARRAY_SIZE(built_in_vid_fmt_info); ++i) {
+	pjmedia_register_video_format_info(mgr,
+					   &built_in_vid_fmt_info[i]);
+    }
+
+    if (p_mgr)
+	*p_mgr = mgr;
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(const pjmedia_video_format_info*)
+pjmedia_get_video_format_info(pjmedia_video_format_mgr *mgr,
+			      pj_uint32_t id)
+{
+    pjmedia_video_format_info **first;
+    int		 comp;
+    unsigned	 n;
+
+    if (!mgr)
+	mgr = pjmedia_video_format_mgr_instance();
+
+    PJ_ASSERT_RETURN(mgr != NULL, NULL);
+
+    /* Binary search for the appropriate format id */
+    comp = -1;
+    first = &mgr->infos[0];
+    n = mgr->info_cnt;
+    for (; n > 0; ) {
+	unsigned half = n / 2;
+	pjmedia_video_format_info **mid = first + half;
+
+	if ((*mid)->id < id) {
+	    first = ++mid;
+	    n -= half + 1;
+	} else if ((*mid)->id==id) {
+	    return *mid;
+	} else {
+	    n = half;
+	}
+    }
+
+    return NULL;
+}
+
+
+PJ_DEF(pj_status_t)
+pjmedia_register_video_format_info(pjmedia_video_format_mgr *mgr,
+				   pjmedia_video_format_info *info)
+{
+    unsigned i;
+
+    if (!mgr)
+	mgr = pjmedia_video_format_mgr_instance();
+
+    PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVALIDOP);
+
+    if (mgr->info_cnt >= mgr->max_info)
+	return PJ_ETOOMANY;
+
+    /* Insert to the array, sorted */
+    for (i=0; i<mgr->info_cnt; ++i) {
+	if (mgr->infos[i]->id >= info->id)
+	    break;
+    }
+
+    if (i < mgr->info_cnt) {
+	if (mgr->infos[i]->id == info->id) {
+	    /* just overwrite */
+	    mgr->infos[i] = info;
+	    return PJ_SUCCESS;
+	}
+
+	pj_memmove(&mgr->infos[i+1], &mgr->infos[i],
+		   (mgr->info_cnt - i) * sizeof(pjmedia_video_format_info*));
+    }
+
+    mgr->infos[i] = info;
+    mgr->info_cnt++;
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pjmedia_video_format_mgr*) pjmedia_video_format_mgr_instance(void)
+{
+    pj_assert(video_format_mgr_instance != NULL);
+    return video_format_mgr_instance;
+}
+
+PJ_DEF(void)
+pjmedia_video_format_mgr_set_instance(pjmedia_video_format_mgr *mgr)
+{
+    video_format_mgr_instance = mgr;
+}
+
+
+PJ_DEF(void) pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr *mgr)
+{
+    if (!mgr)
+	mgr = pjmedia_video_format_mgr_instance();
+
+    PJ_ASSERT_ON_FAIL(mgr != NULL, return);
+
+    mgr->info_cnt = 0;
+    if (video_format_mgr_instance == mgr)
+	video_format_mgr_instance = NULL;
+}
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/master_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/master_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/master_port.c	(revision 3392)
@@ -57,4 +57,5 @@
     unsigned samples_per_frame;
     unsigned bytes_per_frame;
+    pjmedia_audio_format_detail *u_afd, *d_afd;
     pj_status_t status;
 
@@ -62,23 +63,25 @@
     PJ_ASSERT_RETURN(pool && u_port && d_port && p_m, PJ_EINVAL);
 
+    u_afd = pjmedia_format_get_audio_format_detail(&u_port->info.fmt, PJ_TRUE);
+    d_afd = pjmedia_format_get_audio_format_detail(&d_port->info.fmt, PJ_TRUE);
 
     /* Both ports MUST have equal clock rate */
-    PJ_ASSERT_RETURN(u_port->info.clock_rate == d_port->info.clock_rate,
+    PJ_ASSERT_RETURN(u_afd->clock_rate == d_afd->clock_rate,
 		     PJMEDIA_ENCCLOCKRATE);
 
     /* Both ports MUST have equal samples per frame */
-    PJ_ASSERT_RETURN(u_port->info.samples_per_frame==
-		     d_port->info.samples_per_frame,
+    PJ_ASSERT_RETURN(PJMEDIA_PIA_SPF(&u_port->info)==
+			PJMEDIA_PIA_SPF(&d_port->info),
 		     PJMEDIA_ENCSAMPLESPFRAME);
 
     /* Both ports MUST have equal channel count */
-    PJ_ASSERT_RETURN(u_port->info.channel_count == d_port->info.channel_count,
+    PJ_ASSERT_RETURN(u_afd->channel_count == d_afd->channel_count,
 		     PJMEDIA_ENCCHANNEL);
 
 
     /* Get clock_rate and samples_per_frame from one of the port. */
-    clock_rate = u_port->info.clock_rate;
-    samples_per_frame = u_port->info.samples_per_frame;
-    channel_count = u_port->info.channel_count;
+    clock_rate = u_afd->clock_rate;
+    samples_per_frame = PJMEDIA_PIA_SPF(&u_port->info);
+    channel_count = u_afd->channel_count;
 
 
@@ -86,7 +89,7 @@
      * buffer. We take the larger size of the two ports.
      */
-    bytes_per_frame = u_port->info.bytes_per_frame;
-    if (d_port->info.bytes_per_frame > bytes_per_frame)
-	bytes_per_frame = d_port->info.bytes_per_frame;
+    bytes_per_frame = PJMEDIA_AFD_AVG_FSZ(u_afd);
+    if (PJMEDIA_AFD_AVG_FSZ(d_afd) > bytes_per_frame)
+	bytes_per_frame = PJMEDIA_AFD_AVG_FSZ(d_afd);
 
 
@@ -208,4 +211,7 @@
     PJ_ASSERT_RETURN(m && port, PJ_EINVAL);
 
+    /* Only supports audio for now */
+    PJ_ASSERT_RETURN(port->info.fmt.type==PJMEDIA_TYPE_AUDIO, PJ_ENOTSUP);
+
     /* If we have downstream port, make sure they have matching samples per
      * frame.
@@ -213,6 +219,6 @@
     if (m->d_port) {
 	PJ_ASSERT_RETURN(
-	    port->info.clock_rate/port->info.samples_per_frame==
-	    m->d_port->info.clock_rate/m->d_port->info.samples_per_frame,
+	    PJMEDIA_PIA_PTIME(&port->info) ==
+		PJMEDIA_PIA_PTIME(&m->d_port->info),
 	    PJMEDIA_ENCSAMPLESPFRAME
 	);
@@ -246,4 +252,7 @@
 {
     PJ_ASSERT_RETURN(m && port, PJ_EINVAL);
+
+    /* Only supports audio for now */
+    PJ_ASSERT_RETURN(port->info.fmt.type==PJMEDIA_TYPE_AUDIO, PJ_ENOTSUP);
 
     /* If we have upstream port, make sure they have matching samples per
@@ -252,6 +261,6 @@
     if (m->u_port) {
 	PJ_ASSERT_RETURN(
-	    port->info.clock_rate/port->info.samples_per_frame==
-	    m->u_port->info.clock_rate/m->u_port->info.samples_per_frame,
+	    PJMEDIA_PIA_PTIME(&port->info) ==
+		    PJMEDIA_PIA_PTIME(&m->u_port->info),
 	    PJMEDIA_ENCSAMPLESPFRAME
 	);
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_capture.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_capture.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_capture.c	(revision 3392)
@@ -47,5 +47,5 @@
 
 static pj_status_t rec_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame);
+				 pjmedia_frame *frame);
 static pj_status_t rec_get_frame(pjmedia_port *this_port, 
 				  pjmedia_frame *frame);
@@ -141,5 +141,5 @@
 
 static pj_status_t rec_put_frame( pjmedia_port *this_port, 
-				  const pjmedia_frame *frame)
+				  pjmedia_frame *frame)
 {
     struct mem_rec *rec;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_player.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_player.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/mem_player.c	(revision 3392)
@@ -49,5 +49,5 @@
 
 static pj_status_t mem_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame);
+				 pjmedia_frame *frame);
 static pj_status_t mem_get_frame(pjmedia_port *this_port, 
 				  pjmedia_frame *frame);
@@ -126,5 +126,5 @@
 
 static pj_status_t mem_put_frame( pjmedia_port *this_port, 
-				  const pjmedia_frame *frame)
+				  pjmedia_frame *frame)
 {
     PJ_UNUSED_ARG(this_port);
@@ -166,5 +166,5 @@
     }
 
-    size_needed = this_port->info.bytes_per_frame;
+    size_needed = PJMEDIA_PIA_AVG_FSZ(&this_port->info);
     size_written = 0;
     endpos = player->buffer + player->buf_size;
@@ -201,9 +201,9 @@
     }
 
-    frame->size = this_port->info.bytes_per_frame;
+    frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info);
     frame->timestamp.u64 = player->timestamp.u64;
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
 
-    player->timestamp.u64 += this_port->info.samples_per_frame;
+    player->timestamp.u64 += PJMEDIA_PIA_SPF(&this_port->info);
 
     return PJ_SUCCESS;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/null_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/null_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/null_port.c	(revision 3392)
@@ -30,5 +30,5 @@
 				  pjmedia_frame *frame);
 static pj_status_t null_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame);
+				  pjmedia_frame *frame);
 static pj_status_t null_on_destroy(pjmedia_port *this_port);
 
@@ -68,5 +68,5 @@
  */
 static pj_status_t null_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame)
+				  pjmedia_frame *frame)
 {
     PJ_UNUSED_ARG(this_port);
@@ -83,8 +83,8 @@
 {
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
-    frame->size = this_port->info.samples_per_frame * 2;
-    frame->timestamp.u32.lo += this_port->info.samples_per_frame;
+    frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info);
+    frame->timestamp.u32.lo += PJMEDIA_PIA_SPF(&this_port->info);
     pjmedia_zero_samples((pj_int16_t*)frame->buf, 
-			 this_port->info.samples_per_frame);
+			  PJMEDIA_PIA_SPF(&this_port->info));
 
     return PJ_SUCCESS;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/port.c	(revision 3392)
@@ -22,4 +22,5 @@
 #include <pj/assert.h>
 #include <pj/log.h>
+#include <pj/pool.h>
 
 #define THIS_FILE	"port.c"
@@ -38,22 +39,39 @@
 					    unsigned samples_per_frame)
 {
+#define USEC_IN_SEC (pj_uint64_t)1000000
+    unsigned frame_time_usec, avg_bps;
+
     pj_bzero(info, sizeof(*info));
 
+    info->signature = signature;
+    info->dir = PJMEDIA_DIR_ENCODING_DECODING;
     info->name = *name;
-    info->signature = signature;
-    info->type = PJMEDIA_TYPE_AUDIO;
-    info->has_info = PJ_TRUE;
-    info->need_info = PJ_FALSE;
-    info->pt = 0xFF;
-    info->encoding_name = pj_str("pcm");
-    info->clock_rate = clock_rate;
-    info->channel_count = channel_count;
-    info->bits_per_sample = bits_per_sample;
-    info->samples_per_frame = samples_per_frame;
-    info->bytes_per_frame = samples_per_frame * bits_per_sample / 8;
+
+    frame_time_usec = (unsigned)(samples_per_frame * USEC_IN_SEC /
+				 channel_count / clock_rate);
+    avg_bps = clock_rate * channel_count * bits_per_sample;
+
+    pjmedia_format_init_audio(&info->fmt, PJMEDIA_FORMAT_L16, clock_rate,
+			      channel_count, bits_per_sample, frame_time_usec,
+			      avg_bps, avg_bps);
 
     return PJ_SUCCESS;
 }
 
+PJ_DEF(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)
+{
+    pj_bzero(info, sizeof(*info));
+    info->signature = signature;
+    info->dir = dir;
+    info->name = *name;
+
+    pjmedia_format_copy(&info->fmt, fmt);
+
+    return PJ_SUCCESS;
+}
 
 /**
@@ -78,5 +96,5 @@
  */
 PJ_DEF(pj_status_t) pjmedia_port_put_frame( pjmedia_port *port,
-					    const pjmedia_frame *frame )
+					    pjmedia_frame *frame )
 {
     PJ_ASSERT_RETURN(port && frame, PJ_EINVAL);
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/resample_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/resample_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/resample_port.c	(revision 3392)
@@ -43,5 +43,5 @@
 
 static pj_status_t resample_put_frame(pjmedia_port *this_port,
-				      const pjmedia_frame *frame);
+				      pjmedia_frame *frame);
 static pj_status_t resample_get_frame(pjmedia_port *this_port, 
 				      pjmedia_frame *frame);
@@ -58,5 +58,5 @@
     const pj_str_t name = pj_str("resample");
     struct resample_port *rport;
-    unsigned ptime;
+    pjmedia_audio_format_detail *d_afd, *r_afd;
     pj_status_t status;
 
@@ -65,9 +65,9 @@
 
     /* Only supports 16bit samples per frame */
-    PJ_ASSERT_RETURN(dn_port->info.bits_per_sample == 16, PJMEDIA_ENCBITS);
-
-    ptime = dn_port->info.samples_per_frame * 1000 / 
-	    dn_port->info.clock_rate;
-    
+    PJ_ASSERT_RETURN(PJMEDIA_PIA_BITS(&dn_port->info) == 16, PJMEDIA_ENCBITS);
+
+    d_afd = pjmedia_format_get_audio_format_detail(&dn_port->info.fmt, 1);
+    r_afd = pjmedia_format_get_audio_format_detail(&rport->base.info.fmt, 1);
+
     /* Create and initialize port. */
     rport = PJ_POOL_ZALLOC_T(pool, struct resample_port);
@@ -75,6 +75,6 @@
 
     pjmedia_port_info_init(&rport->base.info, &name, SIGNATURE, clock_rate,
-			   dn_port->info.channel_count, BYTES_PER_SAMPLE * 8, 
-			   clock_rate * ptime / 1000);
+		           d_afd->channel_count, BYTES_PER_SAMPLE * 8,
+			   clock_rate * d_afd->frame_time_usec / 1000000);
 
     rport->dn_port = dn_port;
@@ -87,9 +87,9 @@
      */
     rport->get_buf = (pj_int16_t*)
-		     pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
+		     pj_pool_alloc(pool, PJMEDIA_PIA_AVG_FSZ(&dn_port->info));
     PJ_ASSERT_RETURN(rport->get_buf != NULL, PJ_ENOMEM);
 
     rport->put_buf = (pj_int16_t*)
-		     pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
+		     pj_pool_alloc(pool, PJMEDIA_PIA_AVG_FSZ(&dn_port->info));
     PJ_ASSERT_RETURN(rport->put_buf != NULL, PJ_ENOMEM);
 
@@ -99,8 +99,8 @@
 				     (opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0,
 				     (opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0,
-				     dn_port->info.channel_count,
-				     dn_port->info.clock_rate, 
-				     rport->base.info.clock_rate,
-				     dn_port->info.samples_per_frame, 
+				     d_afd->channel_count,
+				     d_afd->clock_rate,
+				     r_afd->clock_rate,
+				     PJMEDIA_PIA_SPF(&dn_port->info),
 				     &rport->resample_get);
     if (status != PJ_SUCCESS)
@@ -111,8 +111,8 @@
 				     (opt&PJMEDIA_RESAMPLE_USE_LINEAR)==0, 
 				     (opt&PJMEDIA_RESAMPLE_USE_SMALL_FILTER)==0,
-				     dn_port->info.channel_count,
-				     rport->base.info.clock_rate, 
-				     dn_port->info.clock_rate,
-				     rport->base.info.samples_per_frame,
+				     d_afd->channel_count,
+				     r_afd->clock_rate,
+				     d_afd->clock_rate,
+				     PJMEDIA_PIA_SPF(&rport->base.info),
 				     &rport->resample_put);
 
@@ -132,5 +132,5 @@
 
 static pj_status_t resample_put_frame(pjmedia_port *this_port,
-				      const pjmedia_frame *frame)
+				      pjmedia_frame *frame)
 {
     struct resample_port *rport = (struct resample_port*) this_port;
@@ -148,5 +148,5 @@
 
 	downstream_frame.buf = rport->put_buf;
-	downstream_frame.size = rport->dn_port->info.bytes_per_frame;
+	downstream_frame.size = PJMEDIA_PIA_AVG_FSZ(&rport->dn_port->info);
     } else {
 	downstream_frame.buf = frame->buf;
@@ -176,5 +176,5 @@
 
     tmp_frame.buf = rport->get_buf;
-    tmp_frame.size = rport->dn_port->info.bytes_per_frame;
+    tmp_frame.size = PJMEDIA_PIA_AVG_FSZ(&rport->dn_port->info);
     tmp_frame.timestamp.u64 = frame->timestamp.u64;
     tmp_frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
@@ -188,6 +188,6 @@
 	frame->timestamp = tmp_frame.timestamp;
 	/* Copy whatever returned as long as the buffer size is enough */
-	frame->size = tmp_frame.size < rport->base.info.bytes_per_frame ?
-		      tmp_frame.size : rport->base.info.bytes_per_frame;
+	frame->size = tmp_frame.size < PJMEDIA_PIA_AVG_FSZ(&rport->base.info) ?
+		      tmp_frame.size : PJMEDIA_PIA_AVG_FSZ(&rport->base.info);
 	if (tmp_frame.size) {
 	    pjmedia_copy_samples((pj_int16_t*)frame->buf, 
@@ -202,5 +202,5 @@
 			  (pj_int16_t*) frame->buf);
 
-    frame->size = rport->base.info.bytes_per_frame;
+    frame->size = PJMEDIA_PIA_AVG_FSZ(&rport->base.info);
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/silencedet.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/silencedet.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/silencedet.c	(revision 3392)
@@ -24,4 +24,5 @@
 #include <pj/log.h>
 #include <pj/pool.h>
+#include <pj/string.h>
 
 #define THIS_FILE   "silencedet.c"
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/sound_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/sound_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/sound_port.c	(revision 3392)
@@ -638,22 +638,23 @@
 					      pjmedia_port *port)
 {
-    pjmedia_port_info *pinfo;
+    pjmedia_audio_format_detail *afd;
 
     PJ_ASSERT_RETURN(snd_port && port, PJ_EINVAL);
+
+    afd = pjmedia_format_get_audio_format_detail(&port->info.fmt, PJ_TRUE);
 
     /* Check that port has the same configuration as the sound device
      * port.
      */
-    pinfo = &port->info;
-    if (pinfo->clock_rate != snd_port->clock_rate)
+    if (afd->clock_rate != snd_port->clock_rate)
 	return PJMEDIA_ENCCLOCKRATE;
 
-    if (pinfo->samples_per_frame != snd_port->samples_per_frame)
+    if (PJMEDIA_AFD_SPF(afd) != snd_port->samples_per_frame)
 	return PJMEDIA_ENCSAMPLESPFRAME;
 
-    if (pinfo->channel_count != snd_port->channel_count)
+    if (afd->channel_count != snd_port->channel_count)
 	return PJMEDIA_ENCCHANNEL;
 
-    if (pinfo->bits_per_sample != snd_port->bits_per_sample)
+    if (afd->bits_per_sample != snd_port->bits_per_sample)
 	return PJMEDIA_ENCBITS;
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/splitcomb.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/splitcomb.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/splitcomb.c	(revision 3392)
@@ -190,5 +190,5 @@
  */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame);
+			     pjmedia_frame *frame);
 static pj_status_t get_frame(pjmedia_port *this_port, 
 			     pjmedia_frame *frame);
@@ -196,5 +196,5 @@
 
 static pj_status_t rport_put_frame(pjmedia_port *this_port, 
-				   const pjmedia_frame *frame);
+				   pjmedia_frame *frame);
 static pj_status_t rport_get_frame(pjmedia_port *this_port, 
 				   pjmedia_frame *frame);
@@ -285,5 +285,5 @@
 
     /* Check the channel number */
-    PJ_ASSERT_RETURN(ch_num < sc->base.info.channel_count, PJ_EINVAL);
+    PJ_ASSERT_RETURN(ch_num < PJMEDIA_PIA_CCNT(&sc->base.info), PJ_EINVAL);
 
     /* options is unused for now */
@@ -309,5 +309,6 @@
     struct splitcomb *sc = (struct splitcomb*) splitcomb;
     struct reverse_port *rport;
-    unsigned buf_cnt, ptime;
+    unsigned buf_cnt;
+    const pjmedia_audio_format_detail *sc_afd, *p_afd;
     pjmedia_port *port;
     pj_status_t status;
@@ -320,8 +321,10 @@
 
     /* Check the channel number */
-    PJ_ASSERT_RETURN(ch_num < sc->base.info.channel_count, PJ_EINVAL);
+    PJ_ASSERT_RETURN(ch_num < PJMEDIA_PIA_CCNT(&sc->base.info), PJ_EINVAL);
 
     /* options is unused for now */
     PJ_UNUSED_ARG(options);
+
+    sc_afd = pjmedia_format_get_audio_format_detail(&splitcomb->info.fmt, 1);
 
     /* Create the port */
@@ -333,8 +336,10 @@
     port = &rport->base;
     pjmedia_port_info_init(&port->info, &name, SIGNATURE_PORT, 
-			   splitcomb->info.clock_rate, 1, 
-			   splitcomb->info.bits_per_sample, 
-			   splitcomb->info.samples_per_frame / 
-				   splitcomb->info.channel_count);
+			   sc_afd->clock_rate, 1,
+			   sc_afd->bits_per_sample,
+			   PJMEDIA_PIA_SPF(&splitcomb->info) /
+				   sc_afd->channel_count);
+
+    p_afd = pjmedia_format_get_audio_format_detail(&port->info.fmt, 1);
 
     /* ... and the callbacks */
@@ -348,7 +353,4 @@
 	buf_cnt = MAX_BUF_CNT;
 
-    ptime = port->info.samples_per_frame * 1000 / port->info.clock_rate /
-	    port->info.channel_count;
-
     rport->max_burst = MAX_BURST;
     rport->max_null_frames = MAX_NULL_FRAMES;
@@ -356,9 +358,9 @@
     /* Create downstream/put buffers */
     status = pjmedia_delay_buf_create(pool, "scombdb-dn",
-				      port->info.clock_rate,
-				      port->info.samples_per_frame,
-				      port->info.channel_count,
-				      buf_cnt * ptime, 0,
-				      &rport->buf[DIR_DOWNSTREAM].dbuf);
+				      p_afd->clock_rate,
+				      PJMEDIA_PIA_SPF(&port->info),
+				      p_afd->channel_count,
+				      buf_cnt * p_afd->frame_time_usec / 1000,
+				      0, &rport->buf[DIR_DOWNSTREAM].dbuf);
     if (status != PJ_SUCCESS) {
 	return status;
@@ -367,9 +369,9 @@
     /* Create upstream/get buffers */
     status = pjmedia_delay_buf_create(pool, "scombdb-up",
-				      port->info.clock_rate,
-				      port->info.samples_per_frame,
-				      port->info.channel_count,
-				      buf_cnt * ptime, 0,
-				      &rport->buf[DIR_UPSTREAM].dbuf);
+				      p_afd->clock_rate,
+				      PJMEDIA_PIA_SPF(&port->info),
+				      p_afd->channel_count,
+				      buf_cnt * p_afd->frame_time_usec / 1000,
+				      0, &rport->buf[DIR_UPSTREAM].dbuf);
     if (status != PJ_SUCCESS) {
 	pjmedia_delay_buf_destroy(rport->buf[DIR_DOWNSTREAM].dbuf);
@@ -379,5 +381,6 @@
     /* And temporary upstream/get buffer */
     rport->tmp_up_buf = (pj_int16_t*)
-	                pj_pool_alloc(pool, port->info.bytes_per_frame);
+	                pj_pool_alloc(pool,
+				      PJMEDIA_PIA_AVG_FSZ(&port->info));
 
     /* Save port in the splitcomb */
@@ -437,5 +440,5 @@
 
     if (op == OP_PUT) {
-	rport->buf[dir].ts.u64 += rport->base.info.samples_per_frame;
+	rport->buf[dir].ts.u64 += PJMEDIA_PIA_SPF(&rport->base.info);
     }
 
@@ -485,5 +488,5 @@
  */
 static pj_status_t put_frame(pjmedia_port *this_port, 
-			     const pjmedia_frame *frame)
+			     pjmedia_frame *frame)
 {
     struct splitcomb *sc = (struct splitcomb*) this_port;
@@ -492,5 +495,5 @@
     /* Handle null frame */
     if (frame->type == PJMEDIA_FRAME_TYPE_NONE) {
-	for (ch=0; ch < this_port->info.channel_count; ++ch) {
+	for (ch=0; ch < PJMEDIA_PIA_CCNT(&this_port->info); ++ch) {
 	    pjmedia_port *port = sc->port_desc[ch].port;
 
@@ -534,5 +537,5 @@
 		/* Generate zero frame. */
 		pjmedia_zero_samples(sc->put_buf, 
-				     this_port->info.samples_per_frame);
+				     PJMEDIA_PIA_SPF(&this_port->info));
 
 		/* Put frame to delay buffer */
@@ -548,5 +551,5 @@
      * it for now.
      */
-    PJ_ASSERT_RETURN(frame->size == this_port->info.bytes_per_frame,
+    PJ_ASSERT_RETURN(frame->size == PJMEDIA_PIA_AVG_FSZ(&this_port->info),
 		     PJ_EINVAL);
 
@@ -554,5 +557,5 @@
      * Write mono frame into each channels 
      */
-    for (ch=0; ch < this_port->info.channel_count; ++ch) {
+    for (ch=0; ch < PJMEDIA_PIA_CCNT(&this_port->info); ++ch) {
 	pjmedia_port *port = sc->port_desc[ch].port;
 
@@ -562,8 +565,8 @@
 	/* Extract the mono frame to temporary buffer */
 	extract_mono_frame((const pj_int16_t*)frame->buf, sc->put_buf, ch, 
-			   this_port->info.channel_count, 
+			   PJMEDIA_PIA_CCNT(&this_port->info),
 			   frame->size * 8 / 
-			     this_port->info.bits_per_sample /
-			     this_port->info.channel_count);
+			     PJMEDIA_PIA_BITS(&this_port->info) /
+			     PJMEDIA_PIA_CCNT(&this_port->info));
 
 	if (!sc->port_desc[ch].reversed) {
@@ -572,5 +575,5 @@
 
 	    mono_frame.buf = sc->put_buf;
-	    mono_frame.size = frame->size / this_port->info.channel_count;
+	    mono_frame.size = frame->size / PJMEDIA_PIA_CCNT(&this_port->info);
 	    mono_frame.type = frame->type;
 	    mono_frame.timestamp.u64 = frame->timestamp.u64;
@@ -613,5 +616,5 @@
 
     /* Read frame from each port */
-    for (ch=0; ch < this_port->info.channel_count; ++ch) {
+    for (ch=0; ch < PJMEDIA_PIA_CCNT(&this_port->info); ++ch) {
 	pjmedia_port *port = sc->port_desc[ch].port;
 	pjmedia_frame mono_frame;
@@ -620,11 +623,11 @@
 	if (!port) {
 	    pjmedia_zero_samples(sc->get_buf, 
-				 this_port->info.samples_per_frame /
-				    this_port->info.channel_count);
+				 PJMEDIA_PIA_SPF(&this_port->info) /
+				  PJMEDIA_PIA_CCNT(&this_port->info));
 
 	} else if (sc->port_desc[ch].reversed == PJ_FALSE) {
 	    /* Read from normal port */
 	    mono_frame.buf = sc->get_buf;
-	    mono_frame.size = port->info.bytes_per_frame;
+	    mono_frame.size = PJMEDIA_PIA_AVG_FSZ(&port->info);
 	    mono_frame.timestamp.u64 = frame->timestamp.u64;
 
@@ -634,5 +637,5 @@
 	    {
 		pjmedia_zero_samples(sc->get_buf, 
-				     port->info.samples_per_frame);
+				     PJMEDIA_PIA_SPF(&port->info));
 	    }
 
@@ -652,5 +655,5 @@
 	    } else {
 		pjmedia_zero_samples(sc->get_buf, 
-				     port->info.samples_per_frame);
+				     PJMEDIA_PIA_SPF(&port->info));
 	    }
 
@@ -661,7 +664,7 @@
 	store_mono_frame(sc->get_buf, 
 			 (pj_int16_t*)frame->buf, ch,
-			 this_port->info.channel_count,
-			 this_port->info.samples_per_frame /
-			 this_port->info.channel_count);
+			 PJMEDIA_PIA_CCNT(&this_port->info),
+			 PJMEDIA_PIA_SPF(&this_port->info) /
+			  PJMEDIA_PIA_CCNT(&this_port->info));
 
 	has_frame = PJ_TRUE;
@@ -671,5 +674,5 @@
     if (has_frame) {
 	frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
-	frame->size = this_port->info.bytes_per_frame;
+	frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info);
     } else
 	frame->type = PJMEDIA_FRAME_TYPE_NONE;
@@ -695,9 +698,9 @@
  */
 static pj_status_t rport_put_frame(pjmedia_port *this_port, 
-				   const pjmedia_frame *frame)
+				   pjmedia_frame *frame)
 {
     struct reverse_port *rport = (struct reverse_port*) this_port;
 
-    pj_assert(frame->size <= rport->base.info.bytes_per_frame);
+    pj_assert(frame->size <= PJMEDIA_PIA_AVG_FSZ(&rport->base.info));
 
     /* Handle NULL frame */
@@ -731,5 +734,5 @@
 	/* Generate zero frame. */
 	pjmedia_zero_samples(rport->tmp_up_buf, 
-			     this_port->info.samples_per_frame);
+			     PJMEDIA_PIA_SPF(&this_port->info));
 
 	/* Put frame to delay buffer */
@@ -739,5 +742,5 @@
 
     /* Not sure how to handle partial frame, so better reject for now */
-    PJ_ASSERT_RETURN(frame->size == this_port->info.bytes_per_frame,
+    PJ_ASSERT_RETURN(frame->size == PJMEDIA_PIA_AVG_FSZ(&this_port->info),
 		     PJ_EINVAL);
 
@@ -756,5 +759,5 @@
      */
     pjmedia_copy_samples(rport->tmp_up_buf, (const pj_int16_t*)frame->buf,
-		         this_port->info.samples_per_frame);
+		         PJMEDIA_PIA_SPF(&this_port->info));
 
     /* Put frame to delay buffer */
@@ -784,5 +787,5 @@
 
     /* Get frame from delay buffer */
-    frame->size = this_port->info.bytes_per_frame;
+    frame->size = PJMEDIA_PIA_AVG_FSZ(&this_port->info);
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
     frame->timestamp.u64 = rport->buf[DIR_DOWNSTREAM].ts.u64;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stereo_port.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stereo_port.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stereo_port.c	(revision 3392)
@@ -40,5 +40,5 @@
 
 static pj_status_t stereo_put_frame(pjmedia_port *this_port,
-				    const pjmedia_frame *frame);
+				    pjmedia_frame *frame);
 static pj_status_t stereo_get_frame(pjmedia_port *this_port, 
 				    pjmedia_frame *frame);
@@ -61,9 +61,12 @@
 
     /* Only supports 16bit samples per frame */
-    PJ_ASSERT_RETURN(dn_port->info.bits_per_sample == 16, PJMEDIA_ENCBITS);
+    PJ_ASSERT_RETURN(PJMEDIA_PIA_BITS(&dn_port->info) == 16,
+		     PJMEDIA_ENCBITS);
 
     /* Validate channel counts */
-    PJ_ASSERT_RETURN(((dn_port->info.channel_count>1 && channel_count==1) ||
-		      (dn_port->info.channel_count==1 && channel_count>1)),
+    PJ_ASSERT_RETURN(((PJMEDIA_PIA_CCNT(&dn_port->info)>1 &&
+			      channel_count==1) ||
+		      (PJMEDIA_PIA_CCNT(&dn_port->info)==1 &&
+			      channel_count>1)),
 		      PJ_EINVAL);
 
@@ -72,11 +75,11 @@
     PJ_ASSERT_RETURN(sport != NULL, PJ_ENOMEM);
 
-    samples_per_frame = dn_port->info.samples_per_frame * channel_count /
-			dn_port->info.channel_count;
+    samples_per_frame = PJMEDIA_PIA_SPF(&dn_port->info) * channel_count /
+	                  PJMEDIA_PIA_CCNT(&dn_port->info);
 
     pjmedia_port_info_init(&sport->base.info, &name, SIGNATURE, 
-			   dn_port->info.clock_rate,
+	                   PJMEDIA_PIA_SRATE(&dn_port->info),
 			   channel_count, 
-			   dn_port->info.bits_per_sample, 
+			   PJMEDIA_PIA_BITS(&dn_port->info),
 			   samples_per_frame);
 
@@ -86,10 +89,12 @@
     /* We always need buffer for put_frame */
     sport->put_buf = (pj_int16_t*)
-		     pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
+		     pj_pool_alloc(pool,
+				   PJMEDIA_PIA_AVG_FSZ(&dn_port->info));
 
     /* See if we need buffer for get_frame */
-    if (dn_port->info.channel_count > channel_count) {
+    if (PJMEDIA_PIA_CCNT(&dn_port->info) > channel_count) {
 	sport->get_buf = (pj_int16_t*)
-			 pj_pool_alloc(pool, dn_port->info.bytes_per_frame);
+			 pj_pool_alloc(pool,
+				       PJMEDIA_PIA_AVG_FSZ(&dn_port->info));
     }
 
@@ -107,7 +112,8 @@
 
 static pj_status_t stereo_put_frame(pjmedia_port *this_port,
-				    const pjmedia_frame *frame)
+				    pjmedia_frame *frame)
 {
     struct stereo_port *sport = (struct stereo_port*) this_port;
+    const pjmedia_audio_format_detail *s_afd, *dn_afd;
     pjmedia_frame tmp_frame;
 
@@ -117,11 +123,15 @@
     }
 
+    s_afd = pjmedia_format_get_audio_format_detail(&this_port->info.fmt, 1);
+    dn_afd = pjmedia_format_get_audio_format_detail(&sport->dn_port->info.fmt,
+						    1);
+
     if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) {
 	tmp_frame.buf = sport->put_buf;
-	if (sport->dn_port->info.channel_count == 1) {
+	if (dn_afd->channel_count == 1) {
 	    pjmedia_convert_channel_nto1((pj_int16_t*)tmp_frame.buf, 
 					 (const pj_int16_t*)frame->buf,
-					 sport->base.info.channel_count, 
-					 sport->base.info.samples_per_frame, 
+					 s_afd->channel_count,
+					 PJMEDIA_AFD_SPF(s_afd),
 					 (sport->options & PJMEDIA_STEREO_MIX),
 					 0);
@@ -129,9 +139,9 @@
 	    pjmedia_convert_channel_1ton((pj_int16_t*)tmp_frame.buf, 
 					 (const pj_int16_t*)frame->buf,
-					 sport->dn_port->info.channel_count, 
-					 sport->base.info.samples_per_frame,
+					 dn_afd->channel_count,
+					 PJMEDIA_AFD_SPF(s_afd),
 					 sport->options);
 	}
-	tmp_frame.size = sport->dn_port->info.bytes_per_frame;
+	tmp_frame.size = PJMEDIA_AFD_AVG_FSZ(dn_afd);
     } else {
 	tmp_frame.buf = frame->buf;
@@ -151,4 +161,5 @@
 {
     struct stereo_port *sport = (struct stereo_port*) this_port;
+    const pjmedia_audio_format_detail *s_afd, *dn_afd;
     pjmedia_frame tmp_frame;
     pj_status_t status;
@@ -160,6 +171,10 @@
     }
 
+    s_afd = pjmedia_format_get_audio_format_detail(&this_port->info.fmt, 1);
+    dn_afd = pjmedia_format_get_audio_format_detail(&sport->dn_port->info.fmt,
+						    1);
+
     tmp_frame.buf = sport->get_buf? sport->get_buf : frame->buf;
-    tmp_frame.size = sport->dn_port->info.bytes_per_frame;
+    tmp_frame.size = PJMEDIA_PIA_AVG_FSZ(&sport->dn_port->info);
     tmp_frame.timestamp.u64 = frame->timestamp.u64;
     tmp_frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
@@ -178,19 +193,19 @@
     }
 
-    if (sport->base.info.channel_count == 1) {
+    if (s_afd->channel_count == 1) {
 	pjmedia_convert_channel_nto1((pj_int16_t*)frame->buf, 
 				     (const pj_int16_t*)tmp_frame.buf,
-				     sport->dn_port->info.channel_count, 
-				     sport->dn_port->info.samples_per_frame, 
+				     dn_afd->channel_count,
+				     PJMEDIA_AFD_SPF(s_afd),
 				     (sport->options & PJMEDIA_STEREO_MIX), 0);
     } else {
 	pjmedia_convert_channel_1ton((pj_int16_t*)frame->buf, 
 				     (const pj_int16_t*)tmp_frame.buf,
-				     sport->base.info.channel_count, 
-				     sport->dn_port->info.samples_per_frame,
+				     s_afd->channel_count,
+				     PJMEDIA_AFD_SPF(dn_afd),
 				     sport->options);
     }
 
-    frame->size = sport->base.info.bytes_per_frame;
+    frame->size = PJMEDIA_AFD_AVG_FSZ(s_afd);
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stream.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stream.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stream.c	(revision 3392)
@@ -78,4 +78,5 @@
     unsigned		    out_pkt_size;   /**< Size of output buffer.	    */
     void		   *out_pkt;	    /**< Output buffer.		    */
+    unsigned                out_pkt_len;    /**< Length of data in buffer.  */
     pjmedia_rtp_session	    rtp;	    /**< RTP session.		    */
 };
@@ -178,6 +179,4 @@
 						 received according to 
 						 'erroneous' definition	    */
-    pj_uint32_t		     rtp_rx_last_ts;/**< Last received RTP timestamp
-						 for timestamp checking	    */
     unsigned		     rtp_rx_last_cnt;/**< Nb of frames in last pkt  */
     unsigned		     rtp_rx_check_cnt;
@@ -209,4 +208,11 @@
     char		   *trace_jb_buf;	    /**< Jitter tracing buffer.	    */
 #endif
+
+    pj_uint32_t		     rtp_rx_last_ts;        /**< Last received RTP timestamp*/
+
+    pjmedia_vid_codec	    *vcodec;	            /**< Codec instance being used. */
+    pjmedia_vid_codec_info   vcodec_info;           /**< Codec param.		    */
+    pjmedia_vid_codec_param  vcodec_param;          /**< Codec param.		    */
+
 };
 
@@ -472,5 +478,5 @@
     pj_mutex_lock( stream->jb_mutex );
 
-    samples_required = stream->port.info.samples_per_frame;
+    samples_required = PJMEDIA_PIA_SPF(&stream->port.info);
     samples_per_frame = stream->codec_param.info.frm_ptime *
 			stream->codec_param.info.clock_rate *
@@ -726,5 +732,5 @@
      */
 
-    samples_required = stream->port.info.samples_per_frame;
+    samples_required = PJMEDIA_PIA_SPF(&stream->port.info);
     samples_per_frame = stream->codec_param.info.frm_ptime *
 			stream->codec_param.info.clock_rate *
@@ -877,5 +883,5 @@
     }
 
-    digit->duration += stream->port.info.samples_per_frame;
+    digit->duration += PJMEDIA_PIA_SPF(&stream->port.info);
 
     event->event = (pj_uint8_t)digit->event;
@@ -1088,5 +1094,5 @@
     /* How many samples are needed */
     count = stream->codec_param.info.enc_ptime * 
-		stream->port.info.clock_rate / 1000;
+	    PJMEDIA_PIA_SRATE(&stream->port.info) / 1000;
 
     /* See if we have enough samples */
@@ -1111,5 +1117,5 @@
  */
 static pj_status_t put_frame_imp( pjmedia_port *port, 
-				  const pjmedia_frame *frame )
+				  pjmedia_frame *frame )
 {
     pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata;
@@ -1152,6 +1158,6 @@
 	ts_len = (frame->size >> 1) / stream->codec_param.info.channel_cnt;
     else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED)
-	ts_len = stream->port.info.samples_per_frame / 
-		 stream->port.info.channel_count;
+	ts_len = PJMEDIA_PIA_SPF(&stream->port.info) /
+		 PJMEDIA_PIA_CCNT(&stream->port.info);
     else
 	ts_len = 0;
@@ -1220,5 +1226,5 @@
     } else if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO &&
 	       frame->buf == NULL &&
-	       stream->port.info.format.id == PJMEDIA_FORMAT_L16 &&
+	       stream->port.info.fmt.id == PJMEDIA_FORMAT_L16 &&
 	       (stream->dir & PJMEDIA_DIR_ENCODING) &&
 	       stream->codec_param.info.frm_ptime *
@@ -1363,5 +1369,5 @@
  */
 static pj_status_t put_frame( pjmedia_port *port, 
-			      const pjmedia_frame *frame )
+			      pjmedia_frame *frame )
 {
     pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata;
@@ -1411,5 +1417,6 @@
     if (stream->vad_enabled != stream->codec_param.setting.vad &&
 	(stream->tx_duration - stream->ts_vad_disabled) > 
-	stream->port.info.clock_rate * PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000)
+           PJMEDIA_PIA_SRATE(&stream->port.info) *
+	  PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000)
     {
 	stream->codec_param.setting.vad = stream->vad_enabled;
@@ -1574,5 +1581,4 @@
     unsigned payloadlen;
     pjmedia_rtp_status seq_st;
-    pj_bool_t check_pt;
     pj_status_t status;
     pj_bool_t pkt_discarded = PJ_FALSE;
@@ -1604,13 +1610,6 @@
      * the incoming packet.
      */
-    check_pt = (hdr->pt != stream->rx_event_pt) && PJMEDIA_STREAM_CHECK_RTP_PT;
-    pjmedia_rtp_session_update2(&channel->rtp, hdr, &seq_st, check_pt);
-#if !PJMEDIA_STREAM_CHECK_RTP_PT
-    if (!check_pt && hdr->pt != channel->rtp.out_pt &&
-	hdr->pt != stream->rx_event_pt)
-    {
-	seq_st.status.flag.badpt = 1;
-    }
-#endif
+    pjmedia_rtp_session_update2(&channel->rtp, hdr, &seq_st,
+			        hdr->pt != stream->rx_event_pt);
     if (seq_st.status.value) {
 	TRC_  ((stream->port.info.name.ptr, 
@@ -1673,4 +1672,61 @@
 	PJ_LOG(4,(stream->port.info.name.ptr, "Jitter buffer reset"));
 
+    } else if (stream->vcodec) {
+        pj_timestamp ts;
+        pj_uint8_t *p;
+        pj_size_t p_len;
+
+        /* Video stream */
+
+        ts.u64 = pj_ntohl(hdr->ts);
+
+        /* Put any buffered bitstream if timestamp is changed,
+         * in case of RTP packet lost.
+         */
+        if (stream->rtp_rx_last_ts != ts.u64 && channel->out_pkt_len)
+        {
+            int seq;
+
+            seq = stream->rtp_rx_last_ts/stream->rtp_rx_ts_len_per_frame;
+            pjmedia_jbuf_put_frame(stream->jb, channel->out_pkt,
+                                   channel->out_pkt_len, seq);
+            channel->out_pkt_len = 0;
+        }
+
+        p = (pj_uint8_t*)channel->out_pkt + channel->out_pkt_len;
+        p_len = channel->out_pkt_size - channel->out_pkt_len;
+
+	/* Parse the payload. */
+	status = (*stream->vcodec->op->unpacketize)(
+                                            stream->vcodec,
+					    payload, payloadlen,
+                                            p, &p_len);
+	if (status != PJ_SUCCESS) {
+	    LOGERR_((stream->port.info.name.ptr, 
+		     "Codec parse() error", 
+		     status));
+            channel->out_pkt_len = 0;
+        } else {
+            channel->out_pkt_len += p_len;
+            if (channel->out_pkt_len > channel->out_pkt_size) {
+                channel->out_pkt_len = channel->out_pkt_size;
+                PJ_LOG(3, (THIS_FILE, "Video bitstream trucated because of"
+                           "not enough buffer"));
+            }
+
+            /* Check if RTP header specifies end of frame mark */
+            PJ_TODO(find_better_way_to_find_out_end_of_frame_mark);
+            if (hdr->m) {
+                int seq;
+
+                seq = (int)(ts.u64/stream->rtp_rx_ts_len_per_frame);
+                pjmedia_jbuf_put_frame(stream->jb, channel->out_pkt,
+                                       channel->out_pkt_len, seq);
+                channel->out_pkt_len = 0;
+            }
+        }
+
+        stream->rtp_rx_last_ts = (pj_uint32_t)ts.u64;
+        
     } else {
 	/*
@@ -1727,8 +1783,8 @@
 		     * to avoid wrong decision because of silence frames.
 		     */
-		    if (stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 &&
-			(peer_frm_ts_diff==stream->port.info.samples_per_frame
+		    if(stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 &&
+		       (peer_frm_ts_diff==PJMEDIA_PIA_SPF(&stream->port.info)
 			 || peer_frm_ts_diff == 
-				    stream->port.info.samples_per_frame >> 1))
+				    PJMEDIA_PIA_SPF(&stream->port.info) >>1))
 		    {
 			if (peer_frm_ts_diff < stream->rtp_rx_ts_len_per_frame)
@@ -1883,11 +1939,17 @@
     /* Allocate buffer for outgoing packet. */
 
-    channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 
-			    stream->codec_param.info.max_bps * 
-			    PJMEDIA_MAX_FRAME_DURATION_MS / 
-			    8 / 1000;
-
-    if (channel->out_pkt_size > PJMEDIA_MAX_MTU)
-	channel->out_pkt_size = PJMEDIA_MAX_MTU;
+    if (param->type == PJMEDIA_TYPE_VIDEO) {
+        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 
+                                stream->frame_size;
+    } else if (param->type == PJMEDIA_TYPE_AUDIO) {
+        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 
+			        stream->codec_param.info.max_bps * 
+			        PJMEDIA_MAX_FRAME_DURATION_MS / 
+			        8 / 1000;
+        if (channel->out_pkt_size > PJMEDIA_MAX_MTU)
+	    channel->out_pkt_size = PJMEDIA_MAX_MTU;
+    } else {
+        return PJ_ENOTSUP;
+    }
 
     /* It should big enough to hold (minimally) RTCP SR with an SDES. */
@@ -1927,4 +1989,11 @@
 }
 
+
+static pj_status_t video_stream_create(pjmedia_endpt *endpt,
+				       pj_pool_t *pool,
+				       const pjmedia_stream_info *info,
+				       pjmedia_transport *tp,
+				       void *user_data,
+				       pjmedia_stream **p_stream);
 
 /*
@@ -1943,4 +2012,5 @@
     pj_str_t name;
     unsigned jb_init, jb_max, jb_min_pre, jb_max_pre, len;
+    pjmedia_audio_format_detail *afd;
     char *p;
     pj_status_t status;
@@ -1948,4 +2018,14 @@
     PJ_ASSERT_RETURN(pool && info && p_stream, PJ_EINVAL);
 
+
+    if (info->type == PJMEDIA_TYPE_VIDEO) {
+        status = video_stream_create(endpt, pool, info, tp, 
+                                     user_data, &stream);
+        if (status != PJ_SUCCESS)
+            goto err_cleanup;
+
+        *p_stream = stream;
+        return PJ_SUCCESS;
+    }
 
     /* Allocate the media stream: */
@@ -1965,10 +2045,12 @@
 			   info->fmt.clock_rate, info->fmt.channel_cnt,
 			   16, 80);
+    afd = pjmedia_format_get_audio_format_detail(&stream->port.info.fmt, 1);
 
     /* Init port. */
 
-    pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name);
-    stream->port.info.clock_rate = info->fmt.clock_rate;
-    stream->port.info.channel_count = info->fmt.channel_cnt;
+    //No longer there in 2.0
+    //pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name);
+    afd->clock_rate = info->fmt.clock_rate;
+    afd->channel_count = info->fmt.channel_cnt;
     stream->port.port_data.pdata = stream;
 
@@ -2041,15 +2123,13 @@
 
     /* Set additional info and callbacks. */
-    stream->port.info.bits_per_sample = 16;
-    stream->port.info.samples_per_frame = info->fmt.clock_rate * 
-					  stream->codec_param.info.channel_cnt *
-					  stream->codec_param.info.frm_ptime *
-					  stream->codec_param.setting.frm_per_pkt /
-					  1000;
-    stream->port.info.format.id = stream->codec_param.info.fmt_id;
+    afd->bits_per_sample = 16;
+    afd->frame_time_usec = stream->codec_param.info.frm_ptime *
+		           stream->codec_param.setting.frm_per_pkt * 1000;
+    stream->port.info.fmt.id = stream->codec_param.info.fmt_id;
     if (stream->codec_param.info.fmt_id == PJMEDIA_FORMAT_L16) {
 	/* Raw format */
-	stream->port.info.bytes_per_frame = stream->port.info.samples_per_frame *
-					    stream->port.info.bits_per_sample / 8;
+	afd->avg_bps = afd->max_bps = afd->clock_rate *
+				      afd->bits_per_sample / 8;
+
 
 	stream->port.put_frame = &put_frame;
@@ -2057,10 +2137,11 @@
     } else {
 	/* Encoded format */
-	stream->port.info.bytes_per_frame = stream->codec_param.info.max_bps * 
-					    stream->codec_param.info.frm_ptime *
-					    stream->codec_param.setting.frm_per_pkt /
-					    8 / 1000;
-	if ((stream->codec_param.info.max_bps * stream->codec_param.info.frm_ptime *
-	    stream->codec_param.setting.frm_per_pkt) % 8000 != 0)
+	afd->avg_bps = stream->codec_param.info.avg_bps;
+	afd->max_bps = stream->codec_param.info.max_bps;
+
+	/* Not applicable for 2.0
+	if ((stream->codec_param.info.max_bps *
+	     stream->codec_param.info.frm_ptime *
+	     stream->codec_param.setting.frm_per_pkt) % 8000 != 0)
 	{
 	    ++stream->port.info.bytes_per_frame;
@@ -2068,4 +2149,5 @@
 	stream->port.info.format.bitrate = stream->codec_param.info.avg_bps;
 	stream->port.info.format.vad = (stream->codec_param.setting.vad != 0);
+	*/
 
 	stream->port.put_frame = &put_frame;
@@ -2084,5 +2166,5 @@
 	stream->enc_samples_per_pkt = stream->codec_param.info.enc_ptime *
 				      stream->codec_param.info.channel_cnt *
-				      stream->port.info.clock_rate / 1000;
+				      afd->clock_rate / 1000;
 
 	/* Set buffer size as twice the largest ptime value between
@@ -2090,6 +2172,5 @@
 	 */
 
-	ptime = stream->port.info.samples_per_frame * 1000 /
-		stream->port.info.clock_rate;
+	ptime = afd->frame_time_usec / 1000;
 
 	if (stream->codec_param.info.enc_ptime > ptime)
@@ -2102,10 +2183,10 @@
 
 	/* Allocate buffer */
-	stream->enc_buf_size = stream->port.info.clock_rate * ptime / 1000;
+	stream->enc_buf_size = afd->clock_rate * ptime / 1000;
 	stream->enc_buf = (pj_int16_t*)
 			  pj_pool_alloc(pool, stream->enc_buf_size * 2);
 
     } else {
-	stream->enc_samples_per_pkt = stream->port.info.samples_per_frame;
+	stream->enc_samples_per_pkt = PJMEDIA_AFD_SPF(afd);
     }
 
@@ -2140,5 +2221,5 @@
     stream->rtp_tx_ts_len_per_pkt = stream->enc_samples_per_pkt /
 				     stream->codec_param.info.channel_cnt;
-    stream->rtp_rx_ts_len_per_frame = stream->port.info.samples_per_frame / 
+    stream->rtp_rx_ts_len_per_frame = PJMEDIA_AFD_SPF(afd) /
 				       stream->codec_param.info.channel_cnt;
 
@@ -2213,5 +2294,5 @@
 	rtcp_setting.rtp_ts_base = pj_ntohl(stream->enc->rtp.out_hdr.ts);
 	rtcp_setting.clock_rate = info->fmt.clock_rate;
-	rtcp_setting.samples_per_frame = stream->port.info.samples_per_frame;
+	rtcp_setting.samples_per_frame = PJMEDIA_AFD_SPF(afd);
 
 #if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0)
@@ -2422,4 +2503,10 @@
 	pjmedia_codec_mgr_dealloc_codec(stream->codec_mgr, stream->codec);
 	stream->codec = NULL;
+    }
+
+    if (stream->vcodec) {
+	stream->vcodec->op->close(stream->vcodec);
+	pjmedia_vid_codec_mgr_dealloc_codec(NULL, stream->vcodec);
+	stream->vcodec = NULL;
     }
 
@@ -2739,2 +2826,524 @@
 }
 
+static pj_status_t put_vid_frame(pjmedia_port *port,
+                                 pjmedia_frame *frame)
+{
+    pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata;
+    pjmedia_channel *channel = stream->enc;
+    pj_status_t status = 0;
+    pjmedia_frame frame_out;
+    unsigned rtp_ts_len;
+    void *rtphdr;
+    int rtphdrlen;
+    unsigned processed = 0;
+
+
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA != 0
+    /* If the interval since last sending packet is greater than
+     * PJMEDIA_STREAM_KA_INTERVAL, send keep-alive packet.
+     */
+    if (stream->use_ka)
+    {
+	pj_uint32_t dtx_duration;
+
+	dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, 
+					   &frame->timestamp);
+	if (dtx_duration >
+	    PJMEDIA_STREAM_KA_INTERVAL * stream->port.info.clock_rate)
+	{
+	    send_keep_alive_packet(stream);
+	    stream->last_frm_ts_sent = frame->timestamp;
+	}
+    }
+#endif
+
+    /* Don't do anything if stream is paused */
+    if (channel->paused) {
+	stream->enc_buf_pos = stream->enc_buf_count = 0;
+	return PJ_SUCCESS;
+    }
+
+    /* Increment transmit duration */
+    rtp_ts_len = stream->rtp_tx_ts_len_per_pkt;
+    stream->tx_duration += rtp_ts_len;
+
+    /* Init frame_out buffer. */
+    frame_out.buf = ((char*)channel->out_pkt) + sizeof(pjmedia_rtp_hdr);
+    frame_out.size = 0;
+
+    /* Encode! */
+    status = (*stream->vcodec->op->encode)(stream->vcodec, frame, 
+				           channel->out_pkt_size - 
+				           sizeof(pjmedia_rtp_hdr),
+				           &frame_out);
+    if (status != PJ_SUCCESS) {
+        LOGERR_((stream->port.info.name.ptr, 
+	        "Codec encode() error", status));
+        return status;
+    }
+
+
+    while (processed < frame_out.size) {
+        pj_uint8_t *payload, *rtp_pkt;
+        pj_size_t payload_len;
+
+        /* Generate RTP payload */
+        status = (*stream->vcodec->op->packetize)(
+                                           stream->vcodec,
+                                           (pj_uint8_t*)frame_out.buf,
+                                           frame_out.size,
+                                           &processed,
+                                           &payload, &payload_len);
+        if (status != PJ_SUCCESS) {
+            LOGERR_((stream->port.info.name.ptr, 
+	            "Codec pack() error", status));
+            return status;
+        }
+
+        /* Encapsulate. */
+        status = pjmedia_rtp_encode_rtp( &channel->rtp, 
+                                         channel->pt,
+                                         (processed==frame_out.size?1:0),
+				         payload_len,
+                                         rtp_ts_len, 
+				         (const void**)&rtphdr, 
+				         &rtphdrlen);
+
+        if (status != PJ_SUCCESS) {
+	    LOGERR_((stream->port.info.name.ptr, 
+		    "RTP encode_rtp() error", status));
+	    return status;
+        }
+
+        /* Next packets use same timestamp */
+        rtp_ts_len = 0;
+
+        rtp_pkt = payload - sizeof(pjmedia_rtp_hdr);
+
+        /* Copy RTP header to the beginning of packet */
+        pj_memcpy(rtp_pkt, rtphdr, sizeof(pjmedia_rtp_hdr));
+
+        /* Send the RTP packet to the transport. */
+        pjmedia_transport_send_rtp(stream->transport, rtp_pkt, 
+			           payload_len + sizeof(pjmedia_rtp_hdr));
+    }
+
+    /* Check if now is the time to transmit RTCP SR/RR report. 
+     * We only do this when stream direction is not "decoding only", because
+     * when it is, check_tx_rtcp() will be handled by get_frame().
+     */
+    if (stream->dir != PJMEDIA_DIR_DECODING) {
+	check_tx_rtcp(stream, pj_ntohl(channel->rtp.out_hdr.ts));
+    }
+
+    /* Do nothing if we have nothing to transmit */
+    if (frame_out.size == 0) {
+	if (stream->is_streaming) {
+	    PJ_LOG(5,(stream->port.info.name.ptr,"Starting silence"));
+	    stream->is_streaming = PJ_FALSE;
+	}
+
+	return PJ_SUCCESS;
+    }
+
+
+    /* Set RTP marker bit if currently not streaming */
+    if (stream->is_streaming == PJ_FALSE) {
+        // RTP header M in video packet is usually for end of frame flag.
+	//pjmedia_rtp_hdr *rtp = (pjmedia_rtp_hdr*) channel->out_pkt;
+	//rtp->m = 1;
+	PJ_LOG(5,(stream->port.info.name.ptr,"Start talksprut.."));
+    }
+
+    stream->is_streaming = PJ_TRUE;
+
+    /* Update stat */
+    pjmedia_rtcp_tx_rtp(&stream->rtcp, frame_out.size);
+    stream->rtcp.stat.rtp_tx_last_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts);
+    stream->rtcp.stat.rtp_tx_last_seq = pj_ntohs(stream->enc->rtp.out_hdr.seq);
+
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
+    /* Update timestamp of last sending packet. */
+    stream->last_frm_ts_sent = frame->timestamp;
+#endif
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t get_vid_frame(pjmedia_port *port,
+                                 pjmedia_frame *frame)
+{
+    pjmedia_stream *stream = (pjmedia_stream*) port->port_data.pdata;
+    pjmedia_channel *channel = stream->dec;
+    pj_uint8_t *p_out_samp;
+    pj_status_t status;
+
+
+    /* Return no frame is channel is paused */
+    if (channel->paused) {
+	frame->type = PJMEDIA_FRAME_TYPE_NONE;
+	return PJ_SUCCESS;
+    }
+
+    /* Repeat get frame from the jitter buffer and decode the frame
+     * until we have enough frames according to codec's ptime.
+     */
+
+    /* Lock jitter buffer mutex first */
+    pj_mutex_lock( stream->jb_mutex );
+
+    p_out_samp = (pj_uint8_t*) frame->buf;
+    {
+	char frame_type;
+	pj_size_t frame_size;
+	pj_uint32_t bit_info;
+
+	/* Get frame from jitter buffer. */
+	pjmedia_jbuf_get_frame2(stream->jb, channel->out_pkt, &frame_size,
+			        &frame_type, &bit_info);
+
+#if TRACE_JB
+	trace_jb_get(stream, frame_type, frame_size);
+#endif
+
+	if (frame_type != PJMEDIA_JB_NORMAL_FRAME) {
+            const char *with_plc = "";
+	    
+	    /* Activate PLC */
+	    if (stream->vcodec->op->recover && 
+		//stream->codec_param.setting.plc &&
+		stream->plc_cnt < stream->max_plc_cnt) 
+	    {
+		status = (*stream->codec->op->recover)(stream->codec,
+						       frame->size,
+						       frame);
+
+		++stream->plc_cnt;
+                with_plc = ", plc invoked";
+	    } else {
+		status = -1;
+	    }
+
+	    if (status != PJ_SUCCESS) {
+		/* Either PLC failed or PLC not supported/enabled */
+		//pjmedia_zero_samples(p_out_samp + samples_count,
+		//		     samples_required - samples_count);
+                frame->size = 0;
+	    }
+
+	    if (frame_type != stream->jb_last_frm) {
+                if (frame_type == PJMEDIA_JB_MISSING_FRAME) {
+		    pjmedia_jb_state jb_state;
+
+		    /* Report changing frame type event */
+		    pjmedia_jbuf_get_state(stream->jb, &jb_state);
+		    PJ_LOG(5,(stream->port.info.name.ptr, 
+			      "Jitter buffer empty (prefetch=%d)%s", 
+			      jb_state.prefetch, with_plc));
+                } else {
+		    /* Report changing frame type event */
+		    PJ_LOG(5,(stream->port.info.name.ptr, "Frame lost%s!",
+		              (status == PJ_SUCCESS? ", recovered":"")));
+                }
+
+		stream->jb_last_frm = frame_type;
+		stream->jb_last_frm_cnt = 1;
+	    } else {
+		stream->jb_last_frm_cnt++;
+	    }
+
+	} else {
+	    /* Got "NORMAL" frame from jitter buffer */
+	    pjmedia_frame frame_in, frame_out;
+
+	    stream->plc_cnt = 0;
+
+	    /* Decode */
+	    frame_in.buf = channel->out_pkt;
+	    frame_in.size = frame_size;
+	    frame_in.bit_info = bit_info;
+	    frame_in.type = PJMEDIA_FRAME_TYPE_VIDEO;  /* ignored */
+
+	    frame_out.buf = p_out_samp;
+	    frame_out.size = frame->size;
+	    status = stream->vcodec->op->decode(stream->vcodec, &frame_in,
+						frame_out.size, &frame_out);
+	    if (status != 0) {
+		LOGERR_((port->info.name.ptr, "codec decode() error", 
+			 status));
+
+		//pjmedia_zero_samples(p_out_samp + samples_count, 
+		//		     samples_per_frame);
+                frame_out.size = 0;
+	    }
+
+	    if (stream->jb_last_frm != frame_type) {
+		/* Report changing frame type event */
+		PJ_LOG(5,(stream->port.info.name.ptr, 
+			  "Jitter buffer starts returning normal frames "
+			  "(after %d empty/lost)",
+			  stream->jb_last_frm_cnt, stream->jb_last_frm));
+
+		stream->jb_last_frm = frame_type;
+		stream->jb_last_frm_cnt = 1;
+	    } else {
+		stream->jb_last_frm_cnt++;
+	    }
+
+            frame->size = frame_out.size;
+	}
+    }
+
+
+    /* Unlock jitter buffer mutex. */
+    pj_mutex_unlock( stream->jb_mutex );
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t video_stream_create(pjmedia_endpt *endpt,
+				       pj_pool_t *pool,
+				       const pjmedia_stream_info *info,
+				       pjmedia_transport *tp,
+				       void *user_data,
+				       pjmedia_stream **p_stream)
+{
+    enum { M = 32 };
+    pjmedia_stream *stream;
+    pj_str_t name;
+    unsigned jb_init, jb_max, jb_min_pre, jb_max_pre, len;
+    pjmedia_video_format_detail *vfd_enc;
+    char *p;
+    pj_status_t status;
+
+    stream = PJ_POOL_ZALLOC_T(pool, pjmedia_stream);
+    PJ_ASSERT_RETURN(stream != NULL, PJ_ENOMEM);
+    PJ_ASSERT_RETURN(pjmedia_vid_codec_mgr_instance(), PJMEDIA_CODEC_EFAILED);
+
+    /* Init stream/port name */
+    name.ptr = (char*) pj_pool_alloc(pool, M);
+    name.slen = pj_ansi_snprintf(name.ptr, M, "vstrm%p", stream);
+
+    /* Create and initialize codec: */
+    stream->vcodec_info = info->vid_codec_info;
+    status = pjmedia_vid_codec_mgr_alloc_codec(NULL, &info->vid_codec_info,
+					       &stream->vcodec);
+    if (status != PJ_SUCCESS)
+	return status;
+
+
+    /* Get codec param: */
+    if (info->vid_codec_param)
+	stream->vcodec_param = *info->vid_codec_param;
+    else {
+	status = pjmedia_vid_codec_mgr_get_default_param(NULL, 
+						         &info->vid_codec_info,
+						         &stream->vcodec_param);
+	if (status != PJ_SUCCESS)
+	    return status;
+    }
+
+    vfd_enc = pjmedia_format_get_video_format_detail(
+                                            &stream->vcodec_param.enc_fmt, 1);
+
+    /* Init stream: */
+    stream->endpt = endpt;
+    stream->dir = info->dir;
+    stream->user_data = user_data;
+    stream->rtcp_interval = (PJMEDIA_RTCP_INTERVAL-500 + (pj_rand()%1000)) *
+			    info->vid_codec_info.clock_rate / 1000;
+
+    stream->jb_last_frm = PJMEDIA_JB_NORMAL_FRAME;
+    stream->tx_event_pt = -1;
+    stream->rx_event_pt = -1;
+
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
+    stream->use_ka = info->use_ka;
+#endif
+
+    /* Build random RTCP CNAME. CNAME has user@host format */
+    stream->cname.ptr = p = (char*) pj_pool_alloc(pool, 20);
+    pj_create_random_string(p, 5);
+    p += 5;
+    *p++ = '@'; *p++ = 'p'; *p++ = 'j';
+    pj_create_random_string(p, 6);
+    p += 6;
+    *p++ = '.'; *p++ = 'o'; *p++ = 'r'; *p++ = 'g';
+    stream->cname.slen = p - stream->cname.ptr;
+
+
+    /* Create mutex to protect jitter buffer: */
+
+    status = pj_mutex_create_simple(pool, NULL, &stream->jb_mutex);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Check for invalid max_bps. */
+ //   if (stream->codec_param.info.max_bps < stream->codec_param.info.avg_bps)
+	//stream->codec_param.info.max_bps = stream->codec_param.info.avg_bps;
+
+    /* Check for invalid frame per packet. */
+ //   if (stream->codec_param.setting.frm_per_pkt < 1)
+	//stream->codec_param.setting.frm_per_pkt = 1;
+
+    /* Open the codec. */
+    stream->vcodec_param.dir = info->dir;
+    stream->vcodec_param.enc_mtu = PJMEDIA_MAX_MTU - 40;
+    status = stream->vcodec->op->init(stream->vcodec, pool);
+    if (status != PJ_SUCCESS)
+	return status;
+    status = stream->vcodec->op->open(stream->vcodec, &stream->vcodec_param);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Set additional info and callbacks. */
+    stream->port.put_frame = &put_vid_frame;
+    stream->port.get_frame = &get_vid_frame;
+
+    /* Get the frame size */
+    //stream->frame_size = vfd_enc->max_bps *
+    //                     vfd_enc->fps.denum / vfd_enc->fps.num;
+    stream->frame_size = 128000;
+
+    /* How many consecutive PLC frames can be generated */
+    stream->max_plc_cnt = MAX_PLC_MSEC *
+                          vfd_enc->fps.num / vfd_enc->fps.denum / 1000;
+
+    stream->rtp_rx_check_cnt = 5;
+    stream->rtp_rx_last_ts = 0;
+    stream->rtp_rx_last_cnt = 0;
+    stream->rtp_tx_ts_len_per_pkt = 
+                            info->vid_codec_info.clock_rate *
+                            vfd_enc->fps.denum / vfd_enc->fps.num;
+    stream->rtp_rx_ts_len_per_frame = stream->rtp_tx_ts_len_per_pkt;
+
+    /* Init jitter buffer parameters: */
+    jb_max     = info->jb_max *
+                 vfd_enc->fps.num / vfd_enc->fps.denum / 1000;
+    jb_min_pre = info->jb_min_pre *
+                 vfd_enc->fps.num / vfd_enc->fps.denum / 1000;
+    jb_max_pre = info->jb_max_pre *
+                 vfd_enc->fps.num / vfd_enc->fps.denum / 1000;
+    jb_init    = info->jb_init *
+                 vfd_enc->fps.num / vfd_enc->fps.denum / 1000;
+
+    /* When JB max frame count==0, set to 0.5s */
+    if (jb_max == 0)
+        jb_max = (vfd_enc->fps.num + vfd_enc->fps.denum/2) /
+                  vfd_enc->fps.denum / 2;
+    
+    /* When JB max prefetch==0, set to (4/5 * jb_max) */
+    if (jb_max_pre == 0)
+        jb_max_pre = jb_max * 4 / 5;
+
+    /* Create jitter buffer */
+    status = pjmedia_jbuf_create(pool, &stream->port.info.name,
+				 stream->frame_size, 
+				 1000 * vfd_enc->fps.denum / vfd_enc->fps.num,
+				 jb_max, &stream->jb);
+    if (status != PJ_SUCCESS)
+	return status;
+
+
+    /* Set up jitter buffer */
+    pjmedia_jbuf_set_adaptive( stream->jb, jb_init, jb_min_pre, jb_max_pre);
+
+    /* Create decoder channel: */
+
+    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 
+			     stream->vcodec_param.pt, info, &stream->dec);
+    if (status != PJ_SUCCESS)
+	return status;
+
+
+    /* Create encoder channel: */
+
+    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 
+			     info->tx_pt, info, &stream->enc);
+    if (status != PJ_SUCCESS)
+	return status;
+
+
+    /* Init RTCP session: */
+
+    {
+	pjmedia_rtcp_session_setting rtcp_setting;
+
+	pjmedia_rtcp_session_setting_default(&rtcp_setting);
+	rtcp_setting.name = stream->port.info.name.ptr;
+	rtcp_setting.ssrc = info->ssrc;
+	rtcp_setting.rtp_ts_base = pj_ntohl(stream->enc->rtp.out_hdr.ts);
+	rtcp_setting.clock_rate = info->vid_codec_info.clock_rate;
+	rtcp_setting.samples_per_frame = stream->rtp_tx_ts_len_per_pkt;
+
+	pjmedia_rtcp_init2(&stream->rtcp, &rtcp_setting);
+    }
+
+    /* Only attach transport when stream is ready. */
+    status = pjmedia_transport_attach(tp, stream, &info->rem_addr, 
+				      &info->rem_rtcp, 
+				      pj_sockaddr_get_len(&info->rem_addr), 
+                                      &on_rx_rtp, &on_rx_rtcp);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    stream->transport = tp;
+
+    /* Send RTCP SDES */
+    len = create_rtcp_sdes(stream, (pj_uint8_t*)stream->enc->out_pkt, 
+			   stream->enc->out_pkt_size);
+    if (len != 0) {
+	pjmedia_transport_send_rtcp(stream->transport, 
+				    stream->enc->out_pkt, len);
+    }
+
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
+    /* NAT hole punching by sending KA packet via RTP transport. */
+    if (stream->use_ka)
+	send_keep_alive_packet(stream);
+#endif
+
+#if TRACE_JB
+    {
+	char trace_name[PJ_MAXPATH];
+	pj_ssize_t len;
+
+	pj_ansi_snprintf(trace_name, sizeof(trace_name), 
+			 TRACE_JB_PATH_PREFIX "%s.csv",
+			 stream->port.info.name.ptr);
+	status = pj_file_open(pool, trace_name, PJ_O_RDWR, &stream->trace_jb_fd);
+	if (status != PJ_SUCCESS) {
+	    stream->trace_jb_fd = TRACE_JB_INVALID_FD;
+	    PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", 
+		      trace_name));
+	} else {
+	    stream->trace_jb_buf = (char*)pj_pool_alloc(pool, PJ_LOG_MAX_SIZE);
+
+	    /* Print column header */
+	    len = pj_ansi_snprintf(stream->trace_jb_buf, PJ_LOG_MAX_SIZE,
+				   "Time, Operation, Size, Frame Count, "
+				   "Frame type, RTP Seq, RTP TS, RTP M, "
+				   "JB size, JB burst level, JB prefetch\n");
+	    pj_file_write(stream->trace_jb_fd, stream->trace_jb_buf, &len);
+	    pj_file_flush(stream->trace_jb_fd);
+	}
+    }
+#endif
+
+    /* Init some port-info. Some parts of the info will be set later
+     * once we have more info about the codec.
+     */
+    pjmedia_port_info_init2(&stream->port.info, &name,
+			    PJMEDIA_PORT_SIGNATURE('S', 'T', 'R', 'M'),
+                            info->dir, &stream->vcodec_param.dec_fmt);
+
+    /* Init port. */
+    stream->port.port_data.pdata = stream;
+
+    /* Success! */
+    *p_stream = stream;
+
+    PJ_LOG(5,(THIS_FILE, "Stream %s created", stream->port.info.name.ptr));
+
+    return PJ_SUCCESS;
+}
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/tonegen.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/tonegen.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/tonegen.c	(revision 3392)
@@ -559,5 +559,5 @@
     struct tonegen *tonegen = (struct tonegen*) port;
     short *dst, *end;
-    unsigned clock_rate = tonegen->base.info.clock_rate;
+    unsigned clock_rate = PJMEDIA_PIA_SRATE(&tonegen->base.info);
 
     PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVAL);
@@ -623,5 +623,5 @@
     
     dst = (short*) frame->buf;
-    end = dst + port->info.samples_per_frame;
+    end = dst + PJMEDIA_PIA_SPF(&port->info);
 
     while (dst < end) {
@@ -637,5 +637,6 @@
 	    (tonegen->count!=1 || !(dig->flags & PJMEDIA_TONE_INITIALIZED)))
 	{
-	    init_generate_tone(&tonegen->state, port->info.clock_rate,
+	    init_generate_tone(&tonegen->state,
+		               PJMEDIA_PIA_SRATE(&port->info),
 			       dig->freq1, dig->freq2, dig->volume);
 	    dig->flags |= PJMEDIA_TONE_INITIALIZED;
@@ -652,5 +653,6 @@
 	    if (cnt > required)
 		cnt = required;
-	    generate_tone(&tonegen->state, port->info.channel_count,
+	    generate_tone(&tonegen->state,
+			  PJMEDIA_PIA_CCNT(&port->info),
 			  cnt, dst);
 
@@ -730,5 +732,5 @@
 
     frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
-    frame->size = port->info.bytes_per_frame;
+    frame->size = PJMEDIA_PIA_AVG_FSZ(&port->info);
 
     TRACE_((THIS_FILE, "tonegen_get_frame(): frame created, level=%u",
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/types.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/types.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/types.c	(revision 3392)
@@ -0,0 +1,24 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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
+ */
+#include <pjmedia/frame.h>
+#include <pjmedia/port.h>
+#include <pjmedia/types.h>
+#include <pj/pool.h>
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_codec.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_codec.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_codec.c	(revision 3392)
@@ -0,0 +1,645 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 
+ */
+#include <pjmedia/vid_codec.h>
+#include <pjmedia/errno.h>
+#include <pj/array.h>
+#include <pj/assert.h>
+#include <pj/log.h>
+#include <pj/string.h>
+
+#define THIS_FILE   "vid_codec.c"
+
+static pjmedia_vid_codec_mgr *def_vid_codec_mgr;
+
+/* Definition of default codecs parameters */
+struct pjmedia_vid_codec_default_param
+{
+    pjmedia_vid_codec_param	*param;
+};
+
+
+/* Sort codecs in codec manager based on priorities */
+static void sort_codecs(pjmedia_vid_codec_mgr *mgr);
+
+
+/*
+ * Initialize codec manager.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_create(
+                                            pj_pool_t *pool,
+                                            pjmedia_vid_codec_mgr **p_mgr)
+{
+    pjmedia_vid_codec_mgr *mgr;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(pool, PJ_EINVAL);
+
+    mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_vid_codec_mgr);
+    pj_list_init (&mgr->factory_list);
+    mgr->codec_cnt = 0;
+
+    /* Create mutex */
+    status = pj_mutex_create_recursive(pool, "vid-codec-mgr", &mgr->mutex);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if (!def_vid_codec_mgr)
+        def_vid_codec_mgr = mgr;
+
+    if (p_mgr)
+        *p_mgr = mgr;
+
+    return PJ_SUCCESS;
+}
+
+/*
+ * Initialize codec manager.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_destroy (pjmedia_vid_codec_mgr *mgr)
+{
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    /* Destroy mutex */
+    if (mgr->mutex)
+	pj_mutex_destroy(mgr->mutex);
+
+    /* Just for safety, set codec manager states to zero */
+    pj_bzero(mgr, sizeof(pjmedia_vid_codec_mgr));
+
+    if (mgr == def_vid_codec_mgr)
+        def_vid_codec_mgr = NULL;
+
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pjmedia_vid_codec_mgr*) pjmedia_vid_codec_mgr_instance(void)
+{
+    pj_assert(def_vid_codec_mgr);
+    return def_vid_codec_mgr;
+}
+
+PJ_DEF(void) pjmedia_vid_codec_mgr_set_instance(pjmedia_vid_codec_mgr* mgr)
+{
+    def_vid_codec_mgr = mgr;
+}
+
+
+/*
+ * Register a codec factory.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_register_factory(
+                                    pjmedia_vid_codec_mgr *mgr,
+				    pjmedia_vid_codec_factory *factory)
+{
+    pjmedia_vid_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
+    unsigned i, count;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(factory, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    /* Enum codecs */
+    count = PJ_ARRAY_SIZE(info);
+    status = factory->op->enum_info(factory, &count, info);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    pj_mutex_lock(mgr->mutex);
+
+    /* Check codec count */
+    if (count + mgr->codec_cnt > PJ_ARRAY_SIZE(mgr->codec_desc)) {
+	pj_mutex_unlock(mgr->mutex);
+	return PJ_ETOOMANY;
+    }
+
+
+    /* Save the codecs */
+    for (i=0; i<count; ++i) {
+	pj_memcpy( &mgr->codec_desc[mgr->codec_cnt+i],
+		   &info[i], sizeof(pjmedia_vid_codec_info));
+	mgr->codec_desc[mgr->codec_cnt+i].prio = PJMEDIA_CODEC_PRIO_NORMAL;
+	mgr->codec_desc[mgr->codec_cnt+i].factory = factory;
+	pjmedia_vid_codec_info_to_id( &info[i],
+				  mgr->codec_desc[mgr->codec_cnt+i].id,
+				  sizeof(pjmedia_codec_id));
+    }
+
+    /* Update count */
+    mgr->codec_cnt += count;
+
+    /* Re-sort codec based on priorities */
+    sort_codecs(mgr);
+
+    /* Add factory to the list */
+    pj_list_push_back(&mgr->factory_list, factory);
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Unregister a codec factory.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_unregister_factory(
+				pjmedia_vid_codec_mgr *mgr, 
+				pjmedia_vid_codec_factory *factory)
+{
+    unsigned i;
+    PJ_ASSERT_RETURN(factory, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    pj_mutex_lock(mgr->mutex);
+
+    /* Factory must be registered. */
+    if (pj_list_find_node(&mgr->factory_list, factory) != factory) {
+	pj_mutex_unlock(mgr->mutex);
+	return PJ_ENOTFOUND;
+    }
+
+    /* Erase factory from the factory list */
+    pj_list_erase(factory);
+
+
+    /* Remove all supported codecs from the codec manager that were created 
+     * by the specified factory.
+     */
+    for (i=0; i<mgr->codec_cnt; ) {
+
+	if (mgr->codec_desc[i].factory == factory) {
+	    /* Remove the codec from array of codec descriptions */
+	    pj_array_erase(mgr->codec_desc, sizeof(mgr->codec_desc[0]), 
+			   mgr->codec_cnt, i);
+	    --mgr->codec_cnt;
+
+	} else {
+	    ++i;
+	}
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Enum all codecs.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_enum_codecs(
+                                pjmedia_vid_codec_mgr *mgr, 
+			        unsigned *count, 
+			        pjmedia_vid_codec_info codecs[],
+			        unsigned *prio)
+{
+    unsigned i;
+
+    PJ_ASSERT_RETURN(count && codecs, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    pj_mutex_lock(mgr->mutex);
+
+    if (*count > mgr->codec_cnt)
+	*count = mgr->codec_cnt;
+    
+    for (i=0; i<*count; ++i) {
+	pj_memcpy(&codecs[i], 
+		  &mgr->codec_desc[i].info, 
+		  sizeof(pjmedia_vid_codec_info));
+    }
+
+    if (prio) {
+	for (i=0; i < *count; ++i)
+	    prio[i] = mgr->codec_desc[i].prio;
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Get codec info for static payload type.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_get_codec_info(
+                                    pjmedia_vid_codec_mgr *mgr,
+				    unsigned pt,
+				    const pjmedia_vid_codec_info **p_info)
+{
+    unsigned i;
+
+    PJ_ASSERT_RETURN(p_info && pt>=0 && pt < 96, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    pj_mutex_lock(mgr->mutex);
+
+    for (i=0; i<mgr->codec_cnt; ++i) {
+	if (mgr->codec_desc[i].info.pt == pt) {
+	    *p_info = &mgr->codec_desc[i].info;
+
+	    pj_mutex_unlock(mgr->mutex);
+	    return PJ_SUCCESS;
+	}
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJMEDIA_CODEC_EUNSUP;
+}
+
+
+/*
+ * Convert codec info struct into a unique codec identifier.
+ * A codec identifier looks something like "L16/44100/2".
+ */
+PJ_DEF(char*) pjmedia_vid_codec_info_to_id(
+                                        const pjmedia_vid_codec_info *info,
+				        char *id, unsigned max_len )
+{
+    int len;
+
+    PJ_ASSERT_RETURN(info && id && max_len, NULL);
+
+    len = pj_ansi_snprintf(id, max_len, "%.*s/%u",
+			   (int)info->encoding_name.slen,
+			   info->encoding_name.ptr,
+			   info->clock_rate);
+
+    if (len < 1 || len >= (int)max_len) {
+	id[0] = '\0';
+	return NULL;
+    }
+
+    return id;
+}
+
+
+/*
+ * Find codecs by the unique codec identifier. This function will find
+ * all codecs that match the codec identifier prefix. For example, if
+ * "L16" is specified, then it will find "L16/8000/1", "L16/16000/1",
+ * and so on, up to the maximum count specified in the argument.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_find_codecs_by_id(
+                                     pjmedia_vid_codec_mgr *mgr,
+				     const pj_str_t *codec_id,
+				     unsigned *count,
+				     const pjmedia_vid_codec_info *p_info[],
+				     unsigned prio[])
+{
+    unsigned i, found = 0;
+
+    PJ_ASSERT_RETURN(codec_id && count && *count, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    pj_mutex_lock(mgr->mutex);
+
+    for (i=0; i<mgr->codec_cnt; ++i) {
+
+	if (codec_id->slen == 0 ||
+	    pj_strnicmp2(codec_id, mgr->codec_desc[i].id, 
+			 codec_id->slen) == 0) 
+	{
+
+	    if (p_info)
+		p_info[found] = &mgr->codec_desc[i].info;
+	    if (prio)
+		prio[found] = mgr->codec_desc[i].prio;
+
+	    ++found;
+
+	    if (found >= *count)
+		break;
+	}
+
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    *count = found;
+
+    return found ? PJ_SUCCESS : PJ_ENOTFOUND;
+}
+
+
+/* Swap two codecs positions in codec manager */
+static void swap_codec(pjmedia_vid_codec_mgr *mgr, unsigned i, unsigned j)
+{
+    pjmedia_vid_codec_desc tmp;
+
+    pj_memcpy(&tmp, &mgr->codec_desc[i], sizeof(pjmedia_vid_codec_desc));
+
+    pj_memcpy(&mgr->codec_desc[i], &mgr->codec_desc[j], 
+	       sizeof(pjmedia_vid_codec_desc));
+
+    pj_memcpy(&mgr->codec_desc[j], &tmp, sizeof(pjmedia_vid_codec_desc));
+}
+
+
+/* Sort codecs in codec manager based on priorities */
+static void sort_codecs(pjmedia_vid_codec_mgr *mgr)
+{
+    unsigned i;
+
+   /* Re-sort */
+    for (i=0; i<mgr->codec_cnt; ++i) {
+	unsigned j, max;
+
+	for (max=i, j=i+1; j<mgr->codec_cnt; ++j) {
+	    if (mgr->codec_desc[j].prio > mgr->codec_desc[max].prio)
+		max = j;
+	}
+
+	if (max != i)
+	    swap_codec(mgr, i, max);
+    }
+
+    /* Change PJMEDIA_CODEC_PRIO_HIGHEST codecs to NEXT_HIGHER */
+    for (i=0; i<mgr->codec_cnt; ++i) {
+	if (mgr->codec_desc[i].prio == PJMEDIA_CODEC_PRIO_HIGHEST)
+	    mgr->codec_desc[i].prio = PJMEDIA_CODEC_PRIO_NEXT_HIGHER;
+	else
+	    break;
+    }
+}
+
+
+/**
+ * Set codec priority. The codec priority determines the order of
+ * the codec in the SDP created by the endpoint. If more than one codecs
+ * are found with the same codec_id prefix, then the function sets the
+ * priorities of all those codecs.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_set_codec_priority(
+				pjmedia_vid_codec_mgr *mgr, 
+				const pj_str_t *codec_id,
+				pj_uint8_t prio)
+{
+    unsigned i, found = 0;
+
+    PJ_ASSERT_RETURN(codec_id, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    pj_mutex_lock(mgr->mutex);
+
+    /* Update the priorities of affected codecs */
+    for (i=0; i<mgr->codec_cnt; ++i) 
+    {
+	if (codec_id->slen == 0 ||
+	    pj_strnicmp2(codec_id, mgr->codec_desc[i].id, 
+			 codec_id->slen) == 0) 
+	{
+	    mgr->codec_desc[i].prio = (pjmedia_codec_priority) prio;
+	    ++found;
+	}
+    }
+
+    if (!found) {
+	pj_mutex_unlock(mgr->mutex);
+	return PJ_ENOTFOUND;
+    }
+
+    /* Re-sort codecs */
+    sort_codecs(mgr);
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Allocate one codec.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_alloc_codec(
+                                        pjmedia_vid_codec_mgr *mgr, 
+					const pjmedia_vid_codec_info *info,
+					pjmedia_vid_codec **p_codec)
+{
+    pjmedia_vid_codec_factory *factory;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(info && p_codec, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    *p_codec = NULL;
+
+    pj_mutex_lock(mgr->mutex);
+
+    factory = mgr->factory_list.next;
+    while (factory != &mgr->factory_list) {
+
+	if ( (*factory->op->test_alloc)(factory, info) == PJ_SUCCESS ) {
+
+	    status = (*factory->op->alloc_codec)(factory, info, p_codec);
+	    if (status == PJ_SUCCESS) {
+		pj_mutex_unlock(mgr->mutex);
+		return PJ_SUCCESS;
+	    }
+
+	}
+
+	factory = factory->next;
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJMEDIA_CODEC_EUNSUP;
+}
+
+
+/*
+ * Get default codec parameter.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_get_default_param(
+                                        pjmedia_vid_codec_mgr *mgr,
+					const pjmedia_vid_codec_info *info,
+					pjmedia_vid_codec_param *param )
+{
+    pjmedia_vid_codec_factory *factory;
+    pj_status_t status;
+    pjmedia_codec_id codec_id;
+    pjmedia_vid_codec_desc *codec_desc = NULL;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(info && param, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    if (!pjmedia_vid_codec_info_to_id(info, (char*)&codec_id, 
+                                      sizeof(codec_id)))
+	return PJ_EINVAL;
+
+    pj_mutex_lock(mgr->mutex);
+
+    /* First, lookup default param in codec desc */
+    for (i=0; i < mgr->codec_cnt; ++i) {
+	if (pj_ansi_stricmp(codec_id, mgr->codec_desc[i].id) == 0) {
+	    codec_desc = &mgr->codec_desc[i];
+	    break;
+	}
+    }
+
+    /* If we found the codec and its default param is set, return it */
+    if (codec_desc && codec_desc->def_param) {
+	pj_memcpy(param, codec_desc->def_param, 
+		  sizeof(pjmedia_vid_codec_param));
+
+	pj_mutex_unlock(mgr->mutex);
+	return PJ_SUCCESS;
+    }
+
+    /* Otherwise query the default param from codec factory */
+    factory = mgr->factory_list.next;
+    while (factory != &mgr->factory_list) {
+
+	if ( (*factory->op->test_alloc)(factory, info) == PJ_SUCCESS ) {
+
+	    status = (*factory->op->default_attr)(factory, info, param);
+	    if (status == PJ_SUCCESS) {
+		/* Check for invalid max_bps. */
+		//if (param->info.max_bps < param->info.avg_bps)
+		//    param->info.max_bps = param->info.avg_bps;
+
+		pj_mutex_unlock(mgr->mutex);
+		return PJ_SUCCESS;
+	    }
+
+	}
+
+	factory = factory->next;
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+
+    return PJMEDIA_CODEC_EUNSUP;
+}
+
+
+/*
+ * Set default codec parameter.
+ */
+PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_set_default_param( 
+					    pjmedia_vid_codec_mgr *mgr,
+                                            pj_pool_t *pool,
+					    const pjmedia_vid_codec_info *info,
+					    const pjmedia_vid_codec_param *param )
+{
+    unsigned i;
+    pjmedia_codec_id codec_id;
+    pjmedia_vid_codec_desc *codec_desc = NULL;
+    pjmedia_vid_codec_param *p;
+
+    PJ_ASSERT_RETURN(info, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    if (!pjmedia_vid_codec_info_to_id(info, (char*)&codec_id, sizeof(codec_id)))
+	return PJ_EINVAL;
+
+    pj_mutex_lock(mgr->mutex);
+
+    /* Lookup codec desc */
+    for (i=0; i < mgr->codec_cnt; ++i) {
+	if (pj_ansi_stricmp(codec_id, mgr->codec_desc[i].id) == 0) {
+	    codec_desc = &mgr->codec_desc[i];
+	    break;
+	}
+    }
+
+    /* Codec not found */
+    if (!codec_desc) {
+	pj_mutex_unlock(mgr->mutex);
+	return PJMEDIA_CODEC_EUNSUP;
+    }
+
+    /* If codec param is previously set */
+    if (codec_desc->def_param) {
+	codec_desc->def_param = NULL;
+    }
+
+    /* When param is set to NULL, i.e: setting default codec param to library
+     * default setting, just return PJ_SUCCESS.
+     */
+    if (NULL == param) {
+	pj_mutex_unlock(mgr->mutex);
+	return PJ_SUCCESS;
+    }
+
+    p = PJ_POOL_ZALLOC_T(pool, pjmedia_vid_codec_param);
+    p = codec_desc->def_param;
+
+    /* Update codec param */
+    pj_memcpy(p, param, sizeof(pjmedia_vid_codec_param));
+    for (i = 0; i < param->dec_fmtp.cnt; ++i) {
+	pj_strdup(pool, &p->dec_fmtp.param[i].name, 
+		  &param->dec_fmtp.param[i].name);
+	pj_strdup(pool, &p->dec_fmtp.param[i].val, 
+		  &param->dec_fmtp.param[i].val);
+    }
+    for (i = 0; i < param->dec_fmtp.cnt; ++i) {
+	pj_strdup(pool, &p->dec_fmtp.param[i].name, 
+		  &param->dec_fmtp.param[i].name);
+	pj_strdup(pool, &p->dec_fmtp.param[i].val, 
+		  &param->dec_fmtp.param[i].val);
+    }
+
+    pj_mutex_unlock(mgr->mutex);
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * Dealloc codec.
+ */
+PJ_DEF(pj_status_t)
+pjmedia_vid_codec_mgr_dealloc_codec(pjmedia_vid_codec_mgr *mgr,
+				    pjmedia_vid_codec *codec)
+{
+    PJ_ASSERT_RETURN(codec, PJ_EINVAL);
+
+    if (!mgr) mgr = def_vid_codec_mgr;
+    PJ_ASSERT_RETURN(mgr, PJ_EINVAL);
+
+    return (*codec->factory->op->dealloc_codec)(codec->factory, codec);
+}
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/videoport.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/videoport.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/videoport.c	(revision 3392)
@@ -0,0 +1,549 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2010 Teluu Inc. (http://www.teluu.com)
+ *
+ * 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
+ */
+#include <pjmedia/videoport.h>
+#include <pjmedia/clock.h>
+#include <pj/log.h>
+#include <pj/pool.h>
+
+#define THIS_FILE	"videoport.c"
+
+typedef struct vid_pasv_port vid_pasv_port;
+
+enum role
+{
+    ROLE_NONE,
+    ROLE_ACTIVE,
+    ROLE_PASSIVE
+};
+
+struct pjmedia_vid_port
+{
+    pj_str_t		 dev_name;
+    pjmedia_dir		 dir;
+    pjmedia_rect_size	 cap_size;
+    pjmedia_vid_stream	*strm;
+    pjmedia_vid_cb       strm_cb;
+    void                *strm_cb_data;
+    enum role		 role,
+			 stream_role;
+    vid_pasv_port	*pasv_port;
+    pjmedia_port	*client_port;
+    pj_bool_t		 destroy_client_port;
+
+    pjmedia_clock	*enc_clock,
+		        *dec_clock;
+
+    pjmedia_frame	*enc_frm_buf,
+		        *dec_frm_buf;
+
+    pj_mutex_t		*enc_frm_mutex,
+			*dec_frm_mutex;
+};
+
+struct vid_pasv_port
+{
+    pjmedia_port	 base;
+    pjmedia_vid_port	*vp;
+};
+
+static pj_status_t vidstream_cap_cb(pjmedia_vid_stream *stream,
+				    void *user_data,
+				    pjmedia_frame *frame);
+static pj_status_t vidstream_render_cb(pjmedia_vid_stream *stream,
+				       void *user_data,
+				       pjmedia_frame *frame);
+static pj_status_t vidstream_event_cb(pjmedia_vid_stream *stream,
+			              void *user_data,
+                                      pjmedia_vid_event *event);
+
+static void enc_clock_cb(const pj_timestamp *ts, void *user_data);
+static void dec_clock_cb(const pj_timestamp *ts, void *user_data);
+
+static pj_status_t vid_pasv_port_put_frame(struct pjmedia_port *this_port,
+					   pjmedia_frame *frame);
+
+static pj_status_t vid_pasv_port_get_frame(struct pjmedia_port *this_port,
+					   pjmedia_frame *frame);
+
+
+PJ_DEF(void) pjmedia_vid_port_param_default(pjmedia_vid_port_param *prm)
+{
+    pj_bzero(prm, sizeof(*prm));
+}
+
+PJ_DEF(pj_status_t) pjmedia_vid_port_create( pj_pool_t *pool,
+					     const pjmedia_vid_port_param *prm,
+					     pjmedia_vid_port **p_vid_port)
+{
+    enum { USEC_IN_SEC = 1000000 };
+    pjmedia_vid_port *vp;
+    pjmedia_vid_dev_index dev_id = PJMEDIA_VID_INVALID_DEV;
+    pjmedia_vid_dev_info di;
+    const pjmedia_video_format_detail *vfd;
+    pjmedia_vid_cb vid_cb;
+    pj_bool_t need_frame_buf = PJ_FALSE;
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(pool && prm && p_vid_port, PJ_EINVAL);
+    PJ_ASSERT_RETURN(prm->vidparam.frame_rate.num, PJ_EINVAL);
+    PJ_ASSERT_RETURN(prm->vidparam.fmt.type == PJMEDIA_TYPE_VIDEO,
+		     PJ_EINVAL);
+
+    /* Retrieve the video format detail */
+    vfd = pjmedia_format_get_video_format_detail(&prm->vidparam.fmt, PJ_TRUE);
+    if (!vfd)
+	return PJ_EINVAL;
+
+    /* Allocate videoport */
+    vp = PJ_POOL_ZALLOC_T(pool, pjmedia_vid_port);
+    vp->role = prm->active ? ROLE_ACTIVE : ROLE_PASSIVE;
+    vp->dir = prm->vidparam.dir;
+    vp->cap_size = vfd->size;
+
+    /* Determine the device id to get the video device info */
+    if ((vp->dir & PJMEDIA_DIR_CAPTURE) &&
+        prm->vidparam.cap_id != PJMEDIA_VID_INVALID_DEV)
+    {
+	dev_id = prm->vidparam.cap_id;
+    } else if ((vp->dir & PJMEDIA_DIR_RENDER) &&
+               prm->vidparam.rend_id != PJMEDIA_VID_INVALID_DEV)
+    {
+	dev_id = prm->vidparam.rend_id;
+    } else
+	return PJ_EINVAL;
+
+    /* Get device info */
+    status = pjmedia_vid_dev_get_info(dev_id, &di);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    PJ_LOG(4,(THIS_FILE, "Opening %s..", di.name));
+
+    pj_strdup2_with_null(pool, &vp->dev_name, di.name);
+    vp->stream_role = di.has_callback ? ROLE_ACTIVE : ROLE_PASSIVE;
+
+    /* Create the video stream */
+    pj_bzero(&vid_cb, sizeof(vid_cb));
+    vid_cb.capture_cb = &vidstream_cap_cb;
+    vid_cb.render_cb = &vidstream_render_cb;
+    vid_cb.on_event_cb = &vidstream_event_cb;
+
+    status = pjmedia_vid_stream_create(&prm->vidparam, &vid_cb, vp,
+				       &vp->strm);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    if (vp->role==ROLE_ACTIVE && vp->stream_role==ROLE_PASSIVE) {
+	/* Active role is wanted, but our device is passive, so create
+	 * master clocks to run the media flow.
+	 */
+	need_frame_buf = PJ_TRUE;
+
+	if (vp->dir & PJMEDIA_DIR_ENCODING) {
+	    status = pjmedia_clock_create2(pool,
+					   USEC_IN_SEC *
+					      prm->vidparam.frame_rate.denum /
+					      prm->vidparam.frame_rate.num,
+					   prm->vidparam.clock_rate,
+					   PJMEDIA_CLOCK_NO_HIGHEST_PRIO,
+					   &enc_clock_cb, vp, &vp->enc_clock);
+	    if (status != PJ_SUCCESS)
+		goto on_error;
+	}
+
+	if (vp->dir & PJMEDIA_DIR_DECODING) {
+	    status = pjmedia_clock_create2(pool,
+					   USEC_IN_SEC *
+					      prm->vidparam.frame_rate.denum /
+					      prm->vidparam.frame_rate.num,
+					   prm->vidparam.clock_rate,
+					   PJMEDIA_CLOCK_NO_HIGHEST_PRIO,
+					   &dec_clock_cb, vp, &vp->dec_clock);
+	    if (status != PJ_SUCCESS)
+		goto on_error;
+	}
+
+    } else if (vp->role==ROLE_PASSIVE) {
+	vid_pasv_port *pp;
+
+	/* Always need to create media port for passive role */
+	vp->pasv_port = pp = PJ_POOL_ZALLOC_T(pool, vid_pasv_port);
+	pp->vp = vp;
+	pp->base.get_frame = &vid_pasv_port_get_frame;
+	pp->base.put_frame = &vid_pasv_port_put_frame;
+	pjmedia_port_info_init2(&pp->base.info, &vp->dev_name,
+				PJMEDIA_PORT_SIGNATURE('v', 'i', 'd', 'p'),
+			        prm->vidparam.dir, &prm->vidparam.fmt);
+
+	if (vp->stream_role == ROLE_ACTIVE) {
+	    need_frame_buf = PJ_TRUE;
+	}
+    }
+
+    if (need_frame_buf) {
+	const pjmedia_video_format_info *vfi;
+	pjmedia_video_apply_fmt_param vafp;
+
+	vfi = pjmedia_get_video_format_info(NULL, prm->vidparam.fmt.id);
+	if (!vfi) {
+	    status = PJ_ENOTFOUND;
+	    goto on_error;
+	}
+
+	pj_bzero(&vafp, sizeof(vafp));
+	vafp.size = vfd->size;
+	status = vfi->apply_fmt(vfi, &vafp);
+	if (status != PJ_SUCCESS)
+	    goto on_error;
+
+	if (vp->dir & PJMEDIA_DIR_ENCODING) {
+	    vp->enc_frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame);
+	    vp->enc_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes);
+	    vp->enc_frm_buf->size = vafp.framebytes;
+	    vp->enc_frm_buf->type = PJMEDIA_FRAME_TYPE_NONE;
+
+	    status = pj_mutex_create_simple(pool, vp->dev_name.ptr,
+					    &vp->enc_frm_mutex);
+	    if (status != PJ_SUCCESS)
+		goto on_error;
+	}
+
+	if (vp->dir & PJMEDIA_DIR_DECODING) {
+	    vp->dec_frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame);
+	    vp->dec_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes);
+	    vp->dec_frm_buf->size = vafp.framebytes;
+	    vp->dec_frm_buf->type = PJMEDIA_FRAME_TYPE_NONE;
+
+	    status = pj_mutex_create_simple(pool, vp->dev_name.ptr,
+					    &vp->dec_frm_mutex);
+	    if (status != PJ_SUCCESS)
+		goto on_error;
+	}
+    }
+
+    *p_vid_port = vp;
+
+    return PJ_SUCCESS;
+
+on_error:
+    pjmedia_vid_port_destroy(vp);
+    return status;
+}
+
+PJ_DEF(void) pjmedia_vid_port_set_cb(pjmedia_vid_port *vid_port,
+				     const pjmedia_vid_cb *cb,
+                                     void *user_data)
+{
+    pj_assert(vid_port && cb);
+    pj_memcpy(&vid_port->strm_cb, cb, sizeof(*cb));
+    vid_port->strm_cb_data = user_data;
+}
+
+PJ_DEF(pjmedia_vid_stream*)
+pjmedia_vid_port_get_stream(pjmedia_vid_port *vp)
+{
+    PJ_ASSERT_RETURN(vp, NULL);
+    return vp->strm;
+}
+
+
+PJ_DEF(pjmedia_port*)
+pjmedia_vid_port_get_passive_port(pjmedia_vid_port *vp)
+{
+    PJ_ASSERT_RETURN(vp && vp->role==ROLE_PASSIVE, NULL);
+    return &vp->pasv_port->base;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_vid_port_connect(pjmedia_vid_port *vp,
+					      pjmedia_port *port,
+					      pj_bool_t destroy)
+{
+    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL);
+    vp->destroy_client_port = destroy;
+    vp->client_port = port;
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_vid_port_disconnect(pjmedia_vid_port *vp)
+{
+    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, PJ_EINVAL);
+    vp->client_port = NULL;
+    return PJ_SUCCESS;
+}
+
+
+PJ_DEF(pjmedia_port*)
+pjmedia_vid_port_get_connected_port(pjmedia_vid_port *vp)
+{
+    PJ_ASSERT_RETURN(vp && vp->role==ROLE_ACTIVE, NULL);
+    return vp->client_port;
+}
+
+PJ_DEF(pj_status_t) pjmedia_vid_port_start(pjmedia_vid_port *vp)
+{
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(vp, PJ_EINVAL);
+
+    status = pjmedia_vid_stream_start(vp->strm);
+    if (status != PJ_SUCCESS)
+	goto on_error;
+
+    if (vp->enc_clock) {
+	status = pjmedia_clock_start(vp->enc_clock);
+	if (status != PJ_SUCCESS)
+	    goto on_error;
+    }
+
+    if (vp->dec_clock) {
+	status = pjmedia_clock_start(vp->dec_clock);
+	if (status != PJ_SUCCESS)
+	    goto on_error;
+    }
+
+    return PJ_SUCCESS;
+
+on_error:
+    pjmedia_vid_port_stop(vp);
+    return status;
+}
+
+PJ_DEF(pj_status_t) pjmedia_vid_port_stop(pjmedia_vid_port *vp)
+{
+    pj_status_t status;
+
+    PJ_ASSERT_RETURN(vp, PJ_EINVAL);
+
+    status = pjmedia_vid_stream_stop(vp->strm);
+
+    if (vp->enc_clock) {
+	status = pjmedia_clock_stop(vp->enc_clock);
+    }
+
+    if (vp->dec_clock) {
+	status = pjmedia_clock_stop(vp->dec_clock);
+    }
+
+    return status;
+}
+
+PJ_DEF(void) pjmedia_vid_port_destroy(pjmedia_vid_port *vp)
+{
+    PJ_ASSERT_ON_FAIL(vp, return);
+
+    PJ_LOG(4,(THIS_FILE, "Closing %s..", vp->dev_name.ptr));
+
+    if (vp->enc_clock) {
+	pjmedia_clock_destroy(vp->enc_clock);
+	vp->enc_clock = NULL;
+    }
+    if (vp->dec_clock) {
+	pjmedia_clock_destroy(vp->dec_clock);
+	vp->dec_clock = NULL;
+    }
+    if (vp->strm) {
+	pjmedia_vid_stream_destroy(vp->strm);
+	vp->strm = NULL;
+    }
+    if (vp->client_port) {
+	if (vp->destroy_client_port)
+	    pjmedia_port_destroy(vp->client_port);
+	vp->client_port = NULL;
+    }
+    if (vp->enc_frm_mutex) {
+	pj_mutex_destroy(vp->enc_frm_mutex);
+	vp->enc_frm_mutex = NULL;
+    }
+    if (vp->dec_frm_mutex) {
+	pj_mutex_destroy(vp->dec_frm_mutex);
+	vp->dec_frm_mutex = NULL;
+    }
+
+}
+
+/*
+static void save_rgb_frame(int width, int height, const pjmedia_frame *frm)
+{
+    static int counter;
+    FILE *pFile;
+    char szFilename[32];
+    const pj_uint8_t *pFrame = (const pj_uint8_t*)frm->buf;
+    int  y;
+
+    if (counter > 10)
+	return;
+
+    // Open file
+    sprintf(szFilename, "frame%02d.ppm", counter++);
+    pFile=fopen(szFilename, "wb");
+    if(pFile==NULL)
+      return;
+
+    // Write header
+    fprintf(pFile, "P6\n%d %d\n255\n", width, height);
+
+    // Write pixel data
+    for(y=0; y<height; y++)
+      fwrite(pFrame+y*width*3, 1, width*3, pFile);
+
+    // Close file
+    fclose(pFile);
+}
+*/
+
+static void enc_clock_cb(const pj_timestamp *ts, void *user_data)
+{
+    /* We are here because user wants us to be active but the stream is
+     * passive. So get a frame from the stream and push it to user.
+     */
+    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
+    pj_status_t status;
+
+    pj_assert(vp->role==ROLE_ACTIVE && vp->stream_role==ROLE_PASSIVE);
+
+    PJ_UNUSED_ARG(ts);
+
+    if (!vp->client_port)
+	return;
+
+    status = pjmedia_vid_stream_get_frame(vp->strm, vp->enc_frm_buf);
+    if (status != PJ_SUCCESS)
+	return;
+
+    //save_rgb_frame(vp->cap_size.w, vp->cap_size.h, vp->enc_frm_buf);
+
+    status = pjmedia_port_put_frame(vp->client_port, vp->enc_frm_buf);
+}
+
+static void dec_clock_cb(const pj_timestamp *ts, void *user_data)
+{
+    /* We are here because user wants us to be active but the stream is
+     * passive. So get a frame from the stream and push it to user.
+     */
+    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
+    pj_status_t status;
+
+    pj_assert(vp->role==ROLE_ACTIVE && vp->stream_role==ROLE_PASSIVE);
+
+    PJ_UNUSED_ARG(ts);
+
+    if (!vp->client_port)
+	return;
+
+    status = pjmedia_port_get_frame(vp->client_port, vp->dec_frm_buf);
+    if (status != PJ_SUCCESS)
+	return;
+
+    status = pjmedia_vid_stream_put_frame(vp->strm, vp->dec_frm_buf);
+}
+
+static void copy_frame(pjmedia_frame *dst, const pjmedia_frame *src)
+{
+    PJ_ASSERT_ON_FAIL(dst->size >= src->size, return);
+
+    pj_memcpy(dst, src, sizeof(*src));
+    pj_memcpy(dst->buf, src->buf, src->size);
+    dst->size = src->size;
+}
+
+static pj_status_t vidstream_cap_cb(pjmedia_vid_stream *stream,
+				    void *user_data,
+				    pjmedia_frame *frame)
+{
+    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
+
+    if (vp->role==ROLE_ACTIVE) {
+	if (vp->client_port)
+	    return pjmedia_port_put_frame(vp->client_port, frame);
+    } else {
+	pj_mutex_lock(vp->enc_frm_mutex);
+	copy_frame(vp->enc_frm_buf, frame);
+	pj_mutex_unlock(vp->enc_frm_mutex);
+    }
+    if (vp->strm_cb.capture_cb)
+        return (*vp->strm_cb.capture_cb)(stream, vp->strm_cb_data, frame);
+    return PJ_SUCCESS;
+}
+
+static pj_status_t vidstream_render_cb(pjmedia_vid_stream *stream,
+				       void *user_data,
+				       pjmedia_frame *frame)
+{
+    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
+
+    if (vp->role==ROLE_ACTIVE) {
+	if (vp->client_port)
+	    return pjmedia_port_get_frame(vp->client_port, frame);
+    } else {
+	pj_mutex_lock(vp->dec_frm_mutex);
+	copy_frame(frame, vp->dec_frm_buf);
+	pj_mutex_unlock(vp->dec_frm_mutex);
+    }
+    if (vp->strm_cb.render_cb)
+        return (*vp->strm_cb.render_cb)(stream, vp->strm_cb_data, frame);
+    return PJ_SUCCESS;
+}
+
+static pj_status_t vidstream_event_cb(pjmedia_vid_stream *stream,
+				      void *user_data,
+				      pjmedia_vid_event *event)
+{
+    pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
+
+    if (vp->strm_cb.on_event_cb)
+        return (*vp->strm_cb.on_event_cb)(stream, vp->strm_cb_data, event);
+    return PJ_SUCCESS;
+}
+
+static pj_status_t vid_pasv_port_put_frame(struct pjmedia_port *this_port,
+					   pjmedia_frame *frame)
+{
+    struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port;
+    pjmedia_vid_port *vp = vpp->vp;
+
+    if (vp->stream_role==ROLE_PASSIVE) {
+	return pjmedia_vid_stream_put_frame(vp->strm, frame);
+    } else {
+	pj_mutex_lock(vp->dec_frm_mutex);
+	copy_frame(vp->dec_frm_buf, frame);
+	pj_mutex_unlock(vp->dec_frm_mutex);
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t vid_pasv_port_get_frame(struct pjmedia_port *this_port,
+					   pjmedia_frame *frame)
+{
+    struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port;
+    pjmedia_vid_port *vp = vpp->vp;
+
+    if (vp->stream_role==ROLE_PASSIVE) {
+	return pjmedia_vid_stream_get_frame(vp->strm, frame);
+    } else {
+	pj_mutex_lock(vp->enc_frm_mutex);
+	copy_frame(frame, vp->enc_frm_buf);
+	pj_mutex_unlock(vp->enc_frm_mutex);
+    }
+
+    return PJ_SUCCESS;
+}
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_player.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_player.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_player.c	(revision 3392)
@@ -169,5 +169,8 @@
     pj_ssize_t size_to_read, size_read;
     struct file_reader_port *fport;
+    pjmedia_audio_format_detail *ad;
     pj_off_t pos;
+    pj_str_t name;
+    unsigned samples_per_frame;
     pj_status_t status = PJ_SUCCESS;
 
@@ -332,15 +335,13 @@
 
     /* Update port info. */
-    fport->base.info.channel_count = wave_hdr.fmt_hdr.nchan;
-    fport->base.info.clock_rate = wave_hdr.fmt_hdr.sample_rate;
-    fport->base.info.bits_per_sample = BITS_PER_SAMPLE;
-    fport->base.info.samples_per_frame = fport->base.info.clock_rate *
-					 wave_hdr.fmt_hdr.nchan *
-					 ptime / 1000;
-    fport->base.info.bytes_per_frame = 
-	fport->base.info.samples_per_frame * 
-	fport->base.info.bits_per_sample / 8;
-
-    pj_strdup2(pool, &fport->base.info.name, filename);
+    ad = pjmedia_format_get_audio_format_detail(&fport->base.info.fmt, 1);
+    pj_strdup2(pool, &name, filename);
+    samples_per_frame = ptime * wave_hdr.fmt_hdr.sample_rate *
+		        wave_hdr.fmt_hdr.nchan / 1000;
+    pjmedia_port_info_init(&fport->base.info, &name, SIGNATURE,
+			   wave_hdr.fmt_hdr.sample_rate,
+			   wave_hdr.fmt_hdr.nchan,
+			   BITS_PER_SAMPLE,
+			   samples_per_frame);
 
     /* If file is shorter than buffer size, adjust buffer size to file
@@ -359,7 +360,5 @@
      * doesn't handle this case).
      */
-    if (fport->base.info.samples_per_frame * fport->bytes_per_sample >=
-	fport->bufsize)
-    {
+    if (samples_per_frame * fport->bytes_per_sample >= fport->bufsize) {
 	pj_file_close(fport->fd);
 	return PJ_EINVAL;
@@ -395,6 +394,6 @@
 	      (int)fport->base.info.name.slen,
 	      fport->base.info.name.ptr,
-	      fport->base.info.clock_rate,
-	      fport->base.info.channel_count,
+	      ad->clock_rate,
+	      ad->channel_count,
 	      fport->bufsize / 1000,
 	      (unsigned long)(fport->fsize / 1000)));
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_playlist.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_playlist.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_playlist.c	(revision 3392)
@@ -237,4 +237,5 @@
 {
     struct playlist_port *fport;
+    pjmedia_audio_format_detail *afd;
     pj_off_t pos;
     pj_status_t status;
@@ -280,4 +281,6 @@
 	return PJ_ENOMEM;
     }
+
+    afd = pjmedia_format_get_audio_format_detail(&fport->base.info.fmt, 1);
 
     /* start with the first file. */
@@ -467,13 +470,11 @@
 	 */
 	if (!has_wave_info) {
-	    fport->base.info.channel_count = wavehdr.fmt_hdr.nchan;
-	    fport->base.info.clock_rate = wavehdr.fmt_hdr.sample_rate;
-	    fport->base.info.bits_per_sample = wavehdr.fmt_hdr.bits_per_sample;
-	    fport->base.info.samples_per_frame = fport->base.info.clock_rate *
-						 wavehdr.fmt_hdr.nchan *
-						 ptime / 1000;
-	    fport->base.info.bytes_per_frame =
-		fport->base.info.samples_per_frame *
-		fport->base.info.bits_per_sample / 8;
+	    afd->channel_count = wavehdr.fmt_hdr.nchan;
+	    afd->clock_rate = wavehdr.fmt_hdr.sample_rate;
+	    afd->bits_per_sample = wavehdr.fmt_hdr.bits_per_sample;
+	    afd->frame_time_usec = ptime * 1000;
+	    afd->avg_bps = afd->max_bps = afd->clock_rate *
+					  afd->channel_count *
+					  afd->bits_per_sample / 8;
 
 	    has_wave_info = PJ_TRUE;
@@ -484,7 +485,7 @@
 	     * files.
 	     */
-	    if (wavehdr.fmt_hdr.nchan != fport->base.info.channel_count ||
-		wavehdr.fmt_hdr.sample_rate != fport->base.info.clock_rate ||
-		wavehdr.fmt_hdr.bits_per_sample != fport->base.info.bits_per_sample)
+	    if (wavehdr.fmt_hdr.nchan != afd->channel_count ||
+		wavehdr.fmt_hdr.sample_rate != afd->clock_rate ||
+		wavehdr.fmt_hdr.bits_per_sample != afd->bits_per_sample)
 	    {
 		/* This file has different characteristics than the other 
@@ -520,6 +521,6 @@
 	     (int)port_label->slen,
 	     port_label->ptr,
-	     fport->base.info.clock_rate,
-	     fport->base.info.channel_count,
+	     afd->clock_rate,
+	     afd->channel_count,
 	     fport->bufsize / 1000));
     
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_writer.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_writer.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/wav_writer.c	(revision 3392)
@@ -52,5 +52,5 @@
 
 static pj_status_t file_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame);
+				  pjmedia_frame *frame);
 static pj_status_t file_get_frame(pjmedia_port *this_port, 
 				  pjmedia_frame *frame);
@@ -199,5 +199,5 @@
 
     /* Check that buffer size is greater than bytes per frame */
-    pj_assert(fport->bufsize >= fport->base.info.bytes_per_frame);
+    pj_assert(fport->bufsize >= PJMEDIA_PIA_AVG_FSZ(&fport->base.info));
 
 
@@ -217,5 +217,5 @@
 	      (int)fport->base.info.name.slen,
 	      fport->base.info.name.ptr,
-	      fport->base.info.clock_rate,
+	      PJMEDIA_PIA_SRATE(&fport->base.info),
 	      fport->bufsize / 1000));
 
@@ -309,5 +309,5 @@
  */
 static pj_status_t file_put_frame(pjmedia_port *this_port, 
-				  const pjmedia_frame *frame)
+				  pjmedia_frame *frame)
 {
     struct file_port *fport = (struct file_port *)this_port;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/test/mips_test.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/test/mips_test.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/test/mips_test.c	(revision 3392)
@@ -685,5 +685,5 @@
 
 static pj_status_t codec_put_frame(struct pjmedia_port *this_port, 
-				   const pjmedia_frame *frame)
+				   pjmedia_frame *frame)
 {
     struct codec_port *cp = (struct codec_port*)this_port;
@@ -1132,5 +1132,5 @@
 
     while (pjmedia_circ_buf_get_len(wp->circbuf) <
-		wp->base.info.samples_per_frame * (CIRC_BUF_FRAME_CNT-1))
+		PJMEDIA_PIA_SPF(&wp->base.info) * (CIRC_BUF_FRAME_CNT-1))
     {
 	status = pjmedia_port_get_frame(wp->gen_port, frame);
@@ -1138,5 +1138,5 @@
 
 	status = pjmedia_circ_buf_write(wp->circbuf, (short*)frame->buf, 
-					wp->base.info.samples_per_frame);
+					PJMEDIA_PIA_SPF(&wp->base.info));
 	pj_assert(status==PJ_SUCCESS);
     }
@@ -1150,5 +1150,5 @@
 					  &reg2, &reg2_len);
 
-	del_cnt = wp->base.info.samples_per_frame;
+	del_cnt = PJMEDIA_PIA_SPF(&wp->base.info);
 	status = pjmedia_wsola_discard(wp->wsola, reg1, reg1_len, reg2, 
 				       reg2_len, &del_cnt);
@@ -2011,5 +2011,5 @@
 
 static pj_status_t delaybuf_put_frame(struct pjmedia_port *this_port, 
-				      const pjmedia_frame *frame)
+				      pjmedia_frame *frame)
 {
     struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
@@ -2220,5 +2220,5 @@
 
     /* Port may decide to use different ptime (e.g. iLBC) */
-    samples_per_frame = port->info.samples_per_frame;
+    samples_per_frame = PJMEDIA_PIA_SPF(&port->info);
 
     gen_port = create_gen_port(pool, clock_rate, 1, 
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.c	(revision 3392)
@@ -57,4 +57,12 @@
     mem = &caching_pool.factory;
 
+#if HAS_VID_DEV_TEST
+    DO_TEST(vid_dev_test());
+#endif
+
+#if HAS_VID_CODEC_TEST
+    DO_TEST(vid_codec_test());
+#endif
+
 #if HAS_SDP_NEG_TEST
     DO_TEST(sdp_neg_test());
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.h
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.h	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/test/test.h	(revision 3392)
@@ -24,4 +24,6 @@
 #include <pjlib.h>
 
+#define HAS_VID_DEV_TEST	1
+#define HAS_VID_CODEC_TEST	1
 #define HAS_SDP_NEG_TEST	1
 #define HAS_JBUF_TEST		1
@@ -36,4 +38,6 @@
 int mips_test(void);
 int codec_test_vectors(void);
+int vid_codec_test(void);
+int vid_dev_test(void);
 
 extern pj_pool_factory *mem;
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_codec_test.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_codec_test.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_codec_test.c	(revision 3392)
@@ -0,0 +1,359 @@
+#include "test.h"
+#include <pjmedia-codec/ffmpeg_codecs.h>
+#include <pjmedia-videodev/videodev.h>
+#include <pjmedia/vid_codec.h>
+#include <pjmedia/port.h>
+
+#define THIS_FILE "vid_codec.c"
+
+#define BYPASS_CODEC 0
+
+typedef struct codec_port_data_t
+{
+    pjmedia_vid_codec   *codec;
+    pjmedia_port        *dn_port;
+    pj_uint8_t          *enc_buf;
+    pj_size_t            enc_buf_size;
+} codec_port_data_t;
+
+static pj_status_t codec_put_frame(pjmedia_port *port,
+			           pjmedia_frame *frame)
+{
+    codec_port_data_t *port_data = (codec_port_data_t*)port->port_data.pdata;
+    pjmedia_vid_codec *codec = port_data->codec;
+    pjmedia_frame enc_frame;
+    pj_status_t status;
+
+    enc_frame.buf = port_data->enc_buf;
+    enc_frame.size = port_data->enc_buf_size;
+
+#if !BYPASS_CODEC
+    status = codec->op->encode(codec, frame, enc_frame.size, &enc_frame);
+    if (status != PJ_SUCCESS) goto on_error;
+    status = codec->op->decode(codec, &enc_frame, frame->size, frame);
+    if (status != PJ_SUCCESS) goto on_error;
+#endif
+
+    status = pjmedia_port_put_frame(port_data->dn_port, frame);
+    if (status != PJ_SUCCESS) goto on_error;
+
+    return PJ_SUCCESS;
+
+on_error:
+    pj_perror(3, THIS_FILE, status, "codec_put_frame() error");
+    return status;
+}
+
+static const char* dump_codec_info(const pjmedia_vid_codec_info *info)
+{
+    static char str[80];
+    unsigned i;
+    char *p = str;
+
+    /* Raw format ids */
+    for (i=0; (i<info->dec_fmt_id_cnt) && (p-str+5<sizeof(str)); ++i) {
+        pj_memcpy(p, &info->dec_fmt_id[i], 4);
+        p += 4;
+        *p++ = ' ';
+    }
+    *p = '\0';
+
+    return str;
+}
+
+static int enum_codecs()
+{
+    unsigned i, cnt;
+    pjmedia_vid_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS];
+    pj_status_t status;
+
+    PJ_LOG(3, (THIS_FILE, "  codec enums"));
+    cnt = PJ_ARRAY_SIZE(info);
+    status = pjmedia_vid_codec_mgr_enum_codecs(NULL, &cnt, info, NULL);
+    if (status != PJ_SUCCESS)
+        return 100;
+
+    for (i = 0; i < cnt; ++i) {
+        PJ_LOG(3, (THIS_FILE, "  %16.*s %c%c %s",
+                   info[i].encoding_name.slen, info[i].encoding_name.ptr,
+                   (info[i].dir & PJMEDIA_DIR_ENCODING? 'E' : ' '),
+                   (info[i].dir & PJMEDIA_DIR_DECODING? 'D' : ' '),
+                   dump_codec_info(&info[i])));
+    }
+
+    return PJ_SUCCESS;
+}
+
+static int encode_decode_test(pj_pool_t *pool, const char *codec_id,
+                              pjmedia_format_id raw_fmt_id)
+{
+
+    pjmedia_vid_codec *codec=NULL;
+    pjmedia_port codec_port;
+    codec_port_data_t codec_port_data;
+    pjmedia_vid_codec_param codec_param;
+    const pjmedia_vid_codec_info *codec_info;
+
+    pjmedia_vid_dev_index cap_idx, rdr_idx;
+    pjmedia_vid_port *capture=NULL, *renderer=NULL;
+    pjmedia_vid_port_param vport_param;
+    pjmedia_video_format_detail *vfd;
+    pj_status_t status;
+    int rc = 0;
+
+    PJ_LOG(3, (THIS_FILE, "  encode decode test"));
+
+    /* Lookup codec */
+    {
+        pj_str_t codec_id_st;
+        unsigned info_cnt = 1;
+
+        /* Lookup codec */
+        pj_cstr(&codec_id_st, codec_id);
+        status = pjmedia_vid_codec_mgr_find_codecs_by_id(NULL, &codec_id_st, 
+                                                         &info_cnt, 
+                                                         &codec_info, NULL);
+        if (status != PJ_SUCCESS) {
+            rc = 205; goto on_return;
+        }
+    }
+
+    /* Lookup colorbar source */
+    status = pjmedia_vid_dev_lookup("Colorbar", "Colorbar generator", &cap_idx);
+    if (status != PJ_SUCCESS) {
+	rc = 206; goto on_return;
+    }
+
+    /* Lookup SDL renderer */
+    status = pjmedia_vid_dev_lookup("SDL", "SDL renderer", &rdr_idx);
+    if (status != PJ_SUCCESS) {
+	rc = 207; goto on_return;
+    }
+
+    /* Raw format ID "not specified", lets find common format among the codec
+     * and the video devices
+     */
+    if (raw_fmt_id == 0) {
+        pjmedia_vid_dev_info cap_info, rdr_info;
+        unsigned i, j, k;
+
+        pjmedia_vid_dev_get_info(cap_idx, &cap_info);
+        pjmedia_vid_dev_get_info(rdr_idx, &rdr_info);
+
+        for (i=0; i<codec_info->dec_fmt_id_cnt && !raw_fmt_id; ++i) {
+            for (j=0; j<cap_info.fmt_cnt && !raw_fmt_id; ++j) {
+                if (codec_info->dec_fmt_id[i]==(int)cap_info.fmt[j].id) {
+                    for (k=0; k<rdr_info.fmt_cnt && !raw_fmt_id; ++k) {
+                        if (codec_info->dec_fmt_id[i]==(int)rdr_info.fmt[k].id)
+                        {
+                            raw_fmt_id = codec_info->dec_fmt_id[i];
+                        }
+                    }
+                }
+            }
+        }
+
+        if (raw_fmt_id == 0) {
+            PJ_LOG(3, (THIS_FILE, "  No common format ID among the codec "
+                       "and the video devices"));
+            status = PJ_ENOTFOUND;
+            rc = 210;
+            goto on_return;
+        }
+    }
+
+    pjmedia_vid_port_param_default(&vport_param);
+
+    /* Create capture, set it to active (master) */
+    status = pjmedia_vid_dev_default_param(pool, cap_idx,
+					   &vport_param.vidparam);
+    if (status != PJ_SUCCESS) {
+	rc = 220; goto on_return;
+    }
+    vport_param.vidparam.fmt.id = raw_fmt_id;
+    vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE;
+    vport_param.active = PJ_TRUE;
+
+    if (vport_param.vidparam.fmt.detail_type != PJMEDIA_FORMAT_DETAIL_VIDEO) {
+	rc = 221; goto on_return;
+    }
+
+    vfd = pjmedia_format_get_video_format_detail(&vport_param.vidparam.fmt,
+						 PJ_TRUE);
+    if (vfd == NULL) {
+	rc = 225; goto on_return;
+    }
+
+    status = pjmedia_vid_port_create(pool, &vport_param, &capture);
+    if (status != PJ_SUCCESS) {
+	rc = 226; goto on_return;
+    }
+
+    /* Create renderer, set it to passive (slave)  */
+    vport_param.active = PJ_FALSE;
+    vport_param.vidparam.dir = PJMEDIA_DIR_RENDER;
+    vport_param.vidparam.rend_id = rdr_idx;
+    vport_param.vidparam.disp_size = vfd->size;
+
+    status = pjmedia_vid_port_create(pool, &vport_param, &renderer);
+    if (status != PJ_SUCCESS) {
+	rc = 230; goto on_return;
+    }
+
+    /* Prepare codec */
+    {
+        pj_str_t codec_id_st;
+        unsigned info_cnt = 1;
+        const pjmedia_vid_codec_info *codec_info;
+        pj_str_t port_name = {"codec", 5};
+        pj_uint8_t *enc_buf = NULL;
+        pj_size_t enc_buf_size = 0;
+
+
+        /* Lookup codec */
+        pj_cstr(&codec_id_st, codec_id);
+        status = pjmedia_vid_codec_mgr_find_codecs_by_id(NULL, &codec_id_st, 
+                                                         &info_cnt, 
+                                                         &codec_info, NULL);
+        if (status != PJ_SUCCESS) {
+            rc = 245; goto on_return;
+        }
+        status = pjmedia_vid_codec_mgr_get_default_param(NULL, codec_info,
+                                                         &codec_param);
+        if (status != PJ_SUCCESS) {
+            rc = 246; goto on_return;
+        }
+
+        pjmedia_format_copy(&codec_param.dec_fmt, &vport_param.vidparam.fmt);
+
+#if !BYPASS_CODEC
+
+        /* Open codec */
+        status = pjmedia_vid_codec_mgr_alloc_codec(NULL, codec_info,
+                                                   &codec);
+        if (status != PJ_SUCCESS) {
+	    rc = 250; goto on_return;
+        }
+
+        status = codec->op->init(codec, pool);
+        if (status != PJ_SUCCESS) {
+	    rc = 251; goto on_return;
+        }
+
+        status = codec->op->open(codec, &codec_param);
+        if (status != PJ_SUCCESS) {
+	    rc = 252; goto on_return;
+        }
+
+        /* Alloc encoding buffer */
+        enc_buf_size =  codec_param.dec_fmt.det.vid.size.w *
+                        codec_param.dec_fmt.det.vid.size.h * 4
+                        + 16; /*< padding, just in case */
+        enc_buf = pj_pool_alloc(pool,enc_buf_size);
+
+#endif /* !BYPASS_CODEC */
+
+        /* Init codec port */
+        pj_bzero(&codec_port, sizeof(codec_port));
+        status = pjmedia_port_info_init2(&codec_port.info, &port_name, 0x1234,
+                                         PJMEDIA_DIR_ENCODING, 
+                                         &codec_param.dec_fmt);
+        if (status != PJ_SUCCESS) {
+	    rc = 260; goto on_return;
+        }
+        codec_port_data.codec = codec;
+        codec_port_data.dn_port = pjmedia_vid_port_get_passive_port(renderer);
+        codec_port_data.enc_buf = enc_buf;
+        codec_port_data.enc_buf_size = enc_buf_size;
+
+        codec_port.put_frame = &codec_put_frame;
+        codec_port.port_data.pdata = &codec_port_data;
+    }
+
+
+    /* Connect capture to codec port */
+    status = pjmedia_vid_port_connect(capture,
+				      &codec_port,
+				      PJ_FALSE);
+    if (status != PJ_SUCCESS) {
+	rc = 270; goto on_return;
+    }
+
+    PJ_LOG(3, (THIS_FILE, "  starting codec test:  %c%c%c%c<->%s %dx%d",
+        ((codec_param.dec_fmt.id & 0x000000FF) >> 0),
+        ((codec_param.dec_fmt.id & 0x0000FF00) >> 8),
+        ((codec_param.dec_fmt.id & 0x00FF0000) >> 16),
+        ((codec_param.dec_fmt.id & 0xFF000000) >> 24),
+        codec_id, 
+        codec_param.dec_fmt.det.vid.size.w,
+        codec_param.dec_fmt.det.vid.size.h
+        ));
+
+    /* Start streaming.. */
+    status = pjmedia_vid_port_start(renderer);
+    if (status != PJ_SUCCESS) {
+	rc = 275; goto on_return;
+    }
+    status = pjmedia_vid_port_start(capture);
+    if (status != PJ_SUCCESS) {
+	rc = 280; goto on_return;
+    }
+
+    /* Sleep while the video is being displayed... */
+    pj_thread_sleep(10000);
+
+on_return:
+    if (status != PJ_SUCCESS) {
+        PJ_PERROR(3, (THIS_FILE, status, "  error"));
+    }
+    if (capture) {
+        pjmedia_vid_port_stop(capture);
+	pjmedia_vid_port_destroy(capture);
+    }
+    if (renderer) {
+        pjmedia_vid_port_stop(renderer);
+	pjmedia_vid_port_destroy(renderer);
+    }
+    if (codec) {
+        codec->op->close(codec);
+        pjmedia_vid_codec_mgr_dealloc_codec(NULL, codec);
+    }
+
+    return rc;
+}
+
+int vid_codec_test(void)
+{
+    pj_pool_t *pool;
+    int rc = 0;
+    pj_status_t status;
+
+    PJ_LOG(3, (THIS_FILE, "Performing video codec tests.."));
+
+    pool = pj_pool_create(mem, "Vid codec test", 256, 256, 0);
+
+    status = pjmedia_vid_subsys_init(mem);
+    if (status != PJ_SUCCESS)
+        return -10;
+
+    status = pjmedia_codec_ffmpeg_init(NULL, mem);
+    if (status != PJ_SUCCESS)
+        return -20;
+
+    rc = enum_codecs();
+    if (rc != 0)
+	goto on_return;
+
+    rc = encode_decode_test(pool, "mjpeg", 0);
+    if (rc != 0)
+	goto on_return;
+
+on_return:
+    pjmedia_codec_ffmpeg_deinit();
+    pjmedia_vid_subsys_shutdown();
+    pj_pool_release(pool);
+
+    return rc;
+}
+
+
Index: pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjmedia/src/test/vid_dev_test.c	(revision 3392)
@@ -0,0 +1,529 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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
+ */
+#include "test.h"
+#include <pjmedia-audiodev/audiodev.h>
+#include <pjmedia-codec/ffmpeg_codecs.h>
+#include <pjmedia/vid_codec.h>
+#include <pjmedia_videodev.h>
+
+#define THIS_FILE "vid_dev_test.c"
+
+pj_status_t pjmedia_libswscale_converter_init(pjmedia_converter_mgr *mgr,
+				              pj_pool_t *pool);
+
+typedef struct codec_port_data_t
+{
+    pjmedia_vid_codec   *codec;
+    pjmedia_port        *src_port;
+    pj_uint8_t          *enc_buf;
+    pj_size_t            enc_buf_size;
+
+    pjmedia_converter   *conv;
+} codec_port_data_t;
+
+typedef struct avi_port_t
+{
+    pjmedia_vid_port   *vid_port;
+    pjmedia_aud_stream *aud_stream;
+    pj_bool_t           is_running;
+} avi_port_t;
+
+static int enum_devs(void)
+{
+    unsigned i, dev_cnt;
+    pj_status_t status;
+
+    PJ_LOG(3, (THIS_FILE, "  device enums"));
+    dev_cnt = pjmedia_vid_dev_count();
+    for (i = 0; i < dev_cnt; ++i) {
+        pjmedia_vid_dev_info info;
+        status = pjmedia_vid_dev_get_info(i, &info);
+        if (status == PJ_SUCCESS) {
+            PJ_LOG(3, (THIS_FILE, "%3d: %s - %s", i, info.driver, info.name));
+        }
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t avi_play_cb(void *user_data, pjmedia_frame *frame)
+{
+    return pjmedia_port_get_frame((pjmedia_port*)user_data, frame);
+}
+
+static pj_status_t avi_event_cb(pjmedia_vid_stream *stream,
+				void *user_data,
+				pjmedia_vid_event *event)
+{
+    avi_port_t *ap = (avi_port_t *)user_data;
+
+    PJ_UNUSED_ARG(stream);
+
+    if (event->event_type != PJMEDIA_EVENT_MOUSEBUTTONDOWN)
+        return PJ_SUCCESS;
+
+    if (ap->is_running) {
+        pjmedia_vid_port_stop(ap->vid_port);
+        if (ap->aud_stream)
+            pjmedia_aud_stream_stop(ap->aud_stream);
+    } else {
+        pjmedia_vid_port_start(ap->vid_port);
+        if (ap->aud_stream)
+            pjmedia_aud_stream_start(ap->aud_stream);
+    }
+    ap->is_running = !ap->is_running;
+
+    /* We handled the event on our own, so return non-PJ_SUCCESS here */
+    return -1;
+}
+
+static pj_status_t codec_get_frame(pjmedia_port *port,
+			           pjmedia_frame *frame)
+{
+    codec_port_data_t *port_data = (codec_port_data_t*)port->port_data.pdata;
+    pjmedia_vid_codec *codec = port_data->codec;
+    pjmedia_frame enc_frame;
+    pj_status_t status;
+
+    enc_frame.buf = port_data->enc_buf;
+    enc_frame.size = port_data->enc_buf_size;
+
+    if (port_data->conv) {
+        pj_size_t frame_size = frame->size;
+
+        status = pjmedia_port_get_frame(port_data->src_port, frame);
+        if (status != PJ_SUCCESS) goto on_error;
+
+        status = codec->op->decode(codec, frame, frame->size, &enc_frame);
+        if (status != PJ_SUCCESS) goto on_error;
+
+        frame->size = frame_size;
+        status = pjmedia_converter_convert(port_data->conv, &enc_frame, frame);
+        if (status != PJ_SUCCESS) goto on_error;
+
+        return PJ_SUCCESS;
+    }
+
+    status = pjmedia_port_get_frame(port_data->src_port, &enc_frame);
+    if (status != PJ_SUCCESS) goto on_error;
+
+    status = codec->op->decode(codec, &enc_frame, frame->size, frame);
+    if (status != PJ_SUCCESS) goto on_error;
+
+    return PJ_SUCCESS;
+
+on_error:
+    pj_perror(3, THIS_FILE, status, "codec_get_frame() error");
+    return status;
+}
+
+static int aviplay_test(pj_pool_t *pool)
+{
+    pjmedia_vid_port *renderer=NULL;
+    pjmedia_vid_port_param param;
+    pjmedia_aud_param aparam;
+    pjmedia_video_format_detail *vfd;
+    pjmedia_audio_format_detail *afd;
+    pjmedia_aud_stream *strm = NULL;
+    pj_status_t status;
+    int rc = 0;
+    pjmedia_avi_streams *avi_streams;
+    pjmedia_avi_stream *vid_stream, *aud_stream;
+    pjmedia_port *vid_port = NULL, *aud_port = NULL;
+    pjmedia_vid_codec *codec=NULL;
+    avi_port_t avi_port;
+#if PJ_WIN32
+    const char *fname = "C:\\Users\\Liong Sauw Ming\\Desktop\\piratesmjpg.avi";
+#else
+    const char *fname = "/home/bennylp/Desktop/installer/video/movies/pirates.avi";
+#endif
+
+    pj_bzero(&avi_port, sizeof(avi_port));
+
+    status = pjmedia_avi_player_create_streams(pool, fname, 0, &avi_streams);
+    if (status != PJ_SUCCESS) {
+	PJ_PERROR(2,("", status, "    Error playing %s (ignored)", fname));
+	rc = 210; goto on_return;
+    }
+
+    vid_stream = pjmedia_avi_streams_get_stream_by_media(avi_streams,
+                                                         0,
+                                                         PJMEDIA_TYPE_VIDEO);
+    vid_port = pjmedia_avi_stream_get_port(vid_stream);
+
+    if (vid_port) {
+        pjmedia_vid_port_param_default(&param);
+
+        status = pjmedia_vid_dev_default_param(pool,
+                                               PJMEDIA_VID_DEFAULT_RENDER_DEV,
+                                               &param.vidparam);
+        if (status != PJ_SUCCESS) {
+    	    rc = 220; goto on_return;
+        }
+
+        /* Create renderer, set it to active  */
+        param.active = PJ_TRUE;
+        param.vidparam.dir = PJMEDIA_DIR_RENDER;
+        vfd = pjmedia_format_get_video_format_detail(&vid_port->info.fmt,
+                                                     PJ_TRUE);
+        pjmedia_format_init_video(&param.vidparam.fmt, 
+                                  vid_port->info.fmt.id,
+                                  vfd->size.w, vfd->size.h,
+                                  vfd->fps.num, vfd->fps.denum);
+
+        if (vid_port->info.fmt.id == PJMEDIA_FORMAT_MJPEG ||
+            vid_port->info.fmt.id == PJMEDIA_FORMAT_H263)
+        {
+            /* Prepare codec */
+            pj_str_t codec_id_st;
+            unsigned info_cnt = 1, i, k;
+            const pjmedia_vid_codec_info *codec_info;
+            pj_str_t port_name = {"codec", 5};
+            pj_uint8_t *enc_buf = NULL;
+            pj_size_t enc_buf_size = 0;
+            pjmedia_vid_dev_info rdr_info;
+            pjmedia_port codec_port;
+            codec_port_data_t codec_port_data;
+            pjmedia_vid_codec_param codec_param;
+            struct {
+                pj_uint32_t     pjmedia_id;
+                const char     *codec_id;
+            } codec_fmts[] = 
+                {{PJMEDIA_FORMAT_MJPEG, "mjpeg"},
+                 {PJMEDIA_FORMAT_H263, "h263"}};
+            const char *codec_id = NULL;
+
+
+            status = pjmedia_codec_ffmpeg_init(NULL, mem);
+            if (status != PJ_SUCCESS)
+                return -20;
+
+            /* Lookup codec */
+            for (i = 0; i < sizeof(codec_fmts)/sizeof(codec_fmts[0]); i++) {
+                if (vid_port->info.fmt.id == codec_fmts[i].pjmedia_id) {
+                    codec_id = codec_fmts[i].codec_id;
+                    break;
+                }
+            }
+            if (!codec_id) {
+                rc = 242; goto on_return;
+            }
+            pj_cstr(&codec_id_st, codec_id);
+            status = pjmedia_vid_codec_mgr_find_codecs_by_id(NULL,
+                                                             &codec_id_st, 
+                                                             &info_cnt, 
+                                                             &codec_info,
+                                                             NULL);
+            if (status != PJ_SUCCESS) {
+                rc = 245; goto on_return;
+            }
+            status = pjmedia_vid_codec_mgr_get_default_param(NULL, codec_info,
+                                                             &codec_param);
+            if (status != PJ_SUCCESS) {
+                rc = 246; goto on_return;
+            }
+
+            pjmedia_vid_dev_get_info(param.vidparam.rend_id, &rdr_info);
+            for (i=0; i<codec_info->dec_fmt_id_cnt; ++i) {
+                for (k=0; k<rdr_info.fmt_cnt; ++k) {
+                    if (codec_info->dec_fmt_id[i]==(int)rdr_info.fmt[k].id)
+                    {
+                        param.vidparam.fmt.id = codec_info->dec_fmt_id[i];
+                    }
+                }
+            }
+
+            /* Open codec */
+            status = pjmedia_vid_codec_mgr_alloc_codec(NULL, codec_info,
+                                                       &codec);
+            if (status != PJ_SUCCESS) {
+                rc = 250; goto on_return;
+            }
+
+            status = codec->op->init(codec, pool);
+            if (status != PJ_SUCCESS) {
+                rc = 251; goto on_return;
+            }
+
+            pjmedia_format_copy(&codec_param.dec_fmt, &param.vidparam.fmt);
+
+            status = codec->op->open(codec, &codec_param);
+            if (status != PJ_SUCCESS) {
+                rc = 252; goto on_return;
+            }
+
+            /* Alloc encoding buffer */
+            enc_buf_size =  codec_param.dec_fmt.det.vid.size.w *
+                            codec_param.dec_fmt.det.vid.size.h * 4
+                            + 16; /*< padding, just in case */
+            enc_buf = pj_pool_alloc(pool,enc_buf_size);
+
+            /* Init codec port */
+            pj_bzero(&codec_port, sizeof(codec_port));
+            status = pjmedia_port_info_init2(&codec_port.info, &port_name,
+                                             0x1234,
+                                             PJMEDIA_DIR_ENCODING, 
+                                             &codec_param.dec_fmt);
+            if (status != PJ_SUCCESS) {
+                rc = 260; goto on_return;
+            }
+            pj_bzero(&codec_port_data, sizeof(codec_port_data));
+            codec_port_data.codec = codec;
+            codec_port_data.src_port = vid_port;
+            codec_port_data.enc_buf = enc_buf;
+            codec_port_data.enc_buf_size = enc_buf_size;
+
+            codec_port.get_frame = &codec_get_frame;
+            codec_port.port_data.pdata = &codec_port_data;
+
+            if (vid_port->info.fmt.id == PJMEDIA_FORMAT_MJPEG) {
+                pjmedia_conversion_param conv_param;
+
+                status = pjmedia_libswscale_converter_init(NULL, pool);
+
+                pjmedia_format_copy(&conv_param.src, &param.vidparam.fmt);
+                pjmedia_format_copy(&conv_param.dst, &param.vidparam.fmt);
+                conv_param.dst.id = PJMEDIA_FORMAT_I420;
+                param.vidparam.fmt.id = conv_param.dst.id;
+
+                status = pjmedia_converter_create(NULL, pool, &conv_param,
+                                                  &codec_port_data.conv);
+                if (status != PJ_SUCCESS) {
+                    rc = 270; goto on_return;
+                }
+            }
+
+            status = pjmedia_vid_port_create(pool, &param, &renderer);
+            if (status != PJ_SUCCESS) {
+                rc = 230; goto on_return;
+            }
+
+            status = pjmedia_vid_port_connect(renderer, &codec_port,
+                                              PJ_FALSE);
+        } else {
+            status = pjmedia_vid_port_create(pool, &param, &renderer);
+            if (status != PJ_SUCCESS) {
+                rc = 230; goto on_return;
+            }
+
+            /* Connect avi port to renderer */
+            status = pjmedia_vid_port_connect(renderer, vid_port,
+                                              PJ_FALSE);
+        }
+
+        if (status != PJ_SUCCESS) {
+            rc = 240; goto on_return;
+        }
+    }
+
+    aud_stream = pjmedia_avi_streams_get_stream_by_media(avi_streams,
+                                                         0,
+                                                         PJMEDIA_TYPE_AUDIO);
+    aud_port = pjmedia_avi_stream_get_port(aud_stream);
+
+    if (aud_port) {
+        status = pjmedia_aud_dev_default_param(
+                     PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV,
+                     &aparam);
+        if (status != PJ_SUCCESS) {
+            rc = 310; goto on_return;
+        }
+
+        aparam.dir = PJMEDIA_DIR_PLAYBACK;
+        afd = pjmedia_format_get_audio_format_detail(&aud_port->info.fmt,
+                                                     PJ_TRUE);
+        aparam.clock_rate = afd->clock_rate;
+        aparam.channel_count = afd->channel_count;
+        aparam.bits_per_sample = afd->bits_per_sample;
+        aparam.samples_per_frame = afd->frame_time_usec * aparam.clock_rate *
+                                   aparam.channel_count / 1000000;
+
+        status = pjmedia_aud_stream_create(&aparam, NULL, &avi_play_cb,
+                                           aud_port,
+                                           &strm);
+        if (status != PJ_SUCCESS) {
+            rc = 320; goto on_return;
+        }
+
+        /* Start audio streaming.. */
+        status = pjmedia_aud_stream_start(strm);
+        if (status != PJ_SUCCESS) {
+            rc = 330; goto on_return;
+        }
+    }
+
+    if (vid_port) {
+        pjmedia_vid_cb cb;
+
+        pj_bzero(&cb, sizeof(cb));
+        cb.on_event_cb = avi_event_cb;
+        avi_port.aud_stream = strm;
+        avi_port.vid_port = renderer;
+        avi_port.is_running = PJ_TRUE;
+        pjmedia_vid_port_set_cb(renderer, &cb, &avi_port);
+
+        /* Start video streaming.. */
+        status = pjmedia_vid_port_start(renderer);
+        if (status != PJ_SUCCESS) {
+            rc = 270; goto on_return;
+        }
+    }
+
+    pj_thread_sleep(150000);
+
+on_return:
+    if (strm) {
+	pjmedia_aud_stream_stop(strm);
+	pjmedia_aud_stream_destroy(strm);
+    }
+    if (renderer)
+        pjmedia_vid_port_destroy(renderer);
+    if (vid_port)
+        pjmedia_port_destroy(vid_port);
+    if (codec) {
+        codec->op->close(codec);
+        pjmedia_vid_codec_mgr_dealloc_codec(NULL, codec);
+    }
+
+    return rc;
+}
+
+static int loopback_test(pj_pool_t *pool)
+{
+    pjmedia_vid_port *capture=NULL, *renderer=NULL;
+    pjmedia_vid_port_param param;
+    pjmedia_video_format_detail *vfd;
+    pj_status_t status;
+    int rc = 0;
+
+    PJ_LOG(3, (THIS_FILE, "  loopback test"));
+
+    pjmedia_vid_port_param_default(&param);
+
+    /* Create capture, set it to active (master) */
+    status = pjmedia_vid_dev_default_param(pool,
+                                           PJMEDIA_VID_DEFAULT_CAPTURE_DEV,
+//                                           3, /* Hard-coded capture device */
+					   &param.vidparam);
+    if (status != PJ_SUCCESS) {
+	rc = 100; goto on_return;
+    }
+    param.vidparam.dir = PJMEDIA_DIR_CAPTURE;
+    param.active = PJ_TRUE;
+
+    if (param.vidparam.fmt.detail_type != PJMEDIA_FORMAT_DETAIL_VIDEO) {
+	rc = 103; goto on_return;
+    }
+
+    vfd = pjmedia_format_get_video_format_detail(&param.vidparam.fmt, PJ_TRUE);
+    if (vfd == NULL) {
+	rc = 105; goto on_return;
+    }
+
+    status = pjmedia_vid_port_create(pool, &param, &capture);
+    if (status != PJ_SUCCESS) {
+	rc = 110; goto on_return;
+    }
+
+    /* Create renderer, set it to passive (slave)  */
+    param.active = PJ_FALSE;
+    param.vidparam.dir = PJMEDIA_DIR_RENDER;
+    param.vidparam.rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV;
+//    param.vidparam.rend_id = 6; /* Hard-coded render device */
+    param.vidparam.disp_size = vfd->size;
+
+    status = pjmedia_vid_port_create(pool, &param, &renderer);
+    if (status != PJ_SUCCESS) {
+	rc = 130; goto on_return;
+    }
+
+    /* Connect capture to renderer */
+    status = pjmedia_vid_port_connect(capture,
+				      pjmedia_vid_port_get_passive_port(renderer),
+				      PJ_FALSE);
+    if (status != PJ_SUCCESS) {
+	rc = 140; goto on_return;
+    }
+
+    /* Start streaming.. */
+    status = pjmedia_vid_port_start(renderer);
+    if (status != PJ_SUCCESS) {
+	rc = 150; goto on_return;
+    }
+    status = pjmedia_vid_port_start(capture);
+    if (status != PJ_SUCCESS) {
+	rc = 160; goto on_return;
+    }
+
+    /* Sleep while the webcam is being displayed... */
+    pj_thread_sleep(20000);
+
+on_return:
+    PJ_PERROR(3, (THIS_FILE, status, "  error"));
+    if (capture)
+	pjmedia_vid_port_destroy(capture);
+    if (renderer)
+	pjmedia_vid_port_destroy(renderer);
+
+    return rc;
+}
+
+int vid_dev_test(void)
+{
+    pj_pool_t *pool;
+    int rc = 0;
+    pj_status_t status;
+
+    PJ_LOG(3, (THIS_FILE, "Video device tests.."));
+
+    pool = pj_pool_create(mem, "Viddev test", 256, 256, 0);
+
+    status = pjmedia_vid_subsys_init(mem);
+    if (status != PJ_SUCCESS)
+        return -10;
+
+    status = pjmedia_aud_subsys_init(mem);
+    if (status != PJ_SUCCESS) {
+        return -20;
+    }
+
+    rc = enum_devs();
+    if (rc != 0)
+	goto on_return;
+
+    rc = aviplay_test(pool);
+    //if (rc != 0)
+    //    goto on_return;
+    // Ignore error
+    rc = 0;
+
+    rc = loopback_test(pool);
+    if (rc != 0)
+	goto on_return;
+
+on_return:
+    pjmedia_aud_subsys_shutdown();
+    pjmedia_vid_subsys_shutdown();
+    pj_pool_release(pool);
+
+    return rc;
+}
+
+
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples-vc.mak
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples-vc.mak	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples-vc.mak	(revision 3392)
@@ -85,5 +85,6 @@
 	  $(BINDIR)\streamutil.exe \
 	  $(BINDIR)\strerror.exe \
-	  $(BINDIR)\tonegen.exe
+	  $(BINDIR)\tonegen.exe \
+	  $(BINDIR)\vstreamutil.exe
 
 
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples.mak
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples.mak	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/build/Samples.mak	(revision 3392)
@@ -39,5 +39,6 @@
 	   streamutil \
 	   strerror \
-	   tonegen
+	   tonegen \
+	   vstreamutil
 
 EXES := $(foreach file, $(SAMPLES), $(BINDIR)/$(file)$(HOST_EXE))
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/pjsystest/systest.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/pjsystest/systest.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/pjsystest/systest.c	(revision 3392)
@@ -651,5 +651,5 @@
     pjmedia_frame frm;
     short *buf;
-    unsigned i, samples_per_frame, read, len;
+    unsigned i, clock_rate, samples_per_frame, read, len;
     unsigned start_pos;
     pj_bool_t first;
@@ -661,5 +661,6 @@
     *lat_max = 0;
 
-    samples_per_frame = wav->info.samples_per_frame;
+    samples_per_frame = PJMEDIA_PIA_SPF(&wav->info);
+    clock_rate = PJMEDIA_PIA_SRATE(&wav->info);
     frm.buf = pj_pool_alloc(pool, samples_per_frame * 2);
     frm.size = samples_per_frame * 2;
@@ -678,5 +679,5 @@
     }
 
-    if (read < 2 * wav->info.clock_rate) {
+    if (read < 2 * clock_rate) {
 	systest_perror("The WAV file is too short", PJ_SUCCESS);
 	return -1;
@@ -686,10 +687,10 @@
      * (keypad press, etc.)
      */
-    pjmedia_zero_samples(buf, wav->info.clock_rate / 2);
+    pjmedia_zero_samples(buf, clock_rate / 2);
 
     /* Loop to calculate latency */
     start_pos = 0;
     first = PJ_TRUE;
-    while (start_pos < len/2 - wav->info.clock_rate) {
+    while (start_pos < len/2 - clock_rate) {
 	int max_signal = 0;
 	unsigned max_signal_pos = start_pos;
@@ -699,5 +700,5 @@
 
 	/* Get the largest signal in the next 0.7s */
-	for (i=start_pos; i<start_pos + wav->info.clock_rate * 700 / 1000; ++i) {
+	for (i=start_pos; i<start_pos + clock_rate * 700 / 1000; ++i) {
 	    if (abs(buf[i]) > max_signal) {
 		max_signal = abs(buf[i]);
@@ -707,10 +708,10 @@
 
 	/* Advance 10ms from max_signal_pos */
-	pos = max_signal_pos + 10 * wav->info.clock_rate / 1000;
+	pos = max_signal_pos + 10 * clock_rate / 1000;
 
 	/* Get the largest signal in the next 800ms */
 	max_signal = 0;
 	max_echo_pos = pos;
-	for (i=pos; i<pos+wav->info.clock_rate * 8 / 10; ++i) {
+	for (i=pos; i<pos+clock_rate * 8 / 10; ++i) {
 	    if (abs(buf[i]) > max_signal) {
 		max_signal = abs(buf[i]);
@@ -719,10 +720,10 @@
 	}
 
-	lat = (max_echo_pos - max_signal_pos) * 1000 / wav->info.clock_rate;
+	lat = (max_echo_pos - max_signal_pos) * 1000 / clock_rate;
 
 #if 0
 	PJ_LOG(4,(THIS_FILE, "Signal at %dms, echo at %d ms, latency %d ms",
-		  max_signal_pos * 1000 / wav->info.clock_rate,
-		  max_echo_pos * 1000 / wav->info.clock_rate,
+		  max_signal_pos * 1000 / clock_rate,
+		  max_echo_pos * 1000 / clock_rate,
 		  lat));
 #endif
@@ -737,8 +738,8 @@
 	/* Advance next loop */
 	if (first) {
-	    start_pos = max_signal_pos + wav->info.clock_rate * 9 / 10;
+	    start_pos = max_signal_pos + clock_rate * 9 / 10;
 	    first = PJ_FALSE;
 	} else {
-	    start_pos += wav->info.clock_rate;
+	    start_pos += clock_rate;
 	}
     }
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/aectest.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/aectest.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/aectest.c	(revision 3392)
@@ -198,5 +198,5 @@
 
     /* play and rec WAVs must have the same clock rate */
-    if (wav_play->info.clock_rate != wav_rec->info.clock_rate) {
+    if (PJMEDIA_PIA_SRATE(&wav_play->info) != PJMEDIA_PIA_SRATE(&wav_rec->info)) {
 	puts("Error: clock rate mismatch in the WAV files");
 	return 1;
@@ -204,5 +204,5 @@
 
     /* .. and channel count */
-    if (wav_play->info.channel_count != wav_rec->info.channel_count) {
+    if (PJMEDIA_PIA_CCNT(&wav_play->info) != PJMEDIA_PIA_CCNT(&wav_rec->info)) {
 	puts("Error: clock rate mismatch in the WAV files");
 	return 1;
@@ -211,8 +211,8 @@
     /* Create output wav */
     status = pjmedia_wav_writer_port_create(pool, argv[pj_optind+2],
-					    wav_play->info.clock_rate,
-					    wav_play->info.channel_count,
-					    wav_play->info.samples_per_frame,
-					    wav_play->info.bits_per_sample,
+					    PJMEDIA_PIA_SRATE(&wav_play->info),
+					    PJMEDIA_PIA_CCNT(&wav_play->info),
+					    PJMEDIA_PIA_SPF(&wav_play->info),
+					    PJMEDIA_PIA_BITS(&wav_play->info),
 					    0, 0, &wav_out);
     if (status != PJ_SUCCESS) {
@@ -222,7 +222,7 @@
 
     /* Create echo canceller */
-    status = pjmedia_echo_create2(pool, wav_play->info.clock_rate,
-				  wav_play->info.channel_count,
-				  wav_play->info.samples_per_frame,
+    status = pjmedia_echo_create2(pool, PJMEDIA_PIA_SRATE(&wav_play->info),
+				  PJMEDIA_PIA_CCNT(&wav_play->info),
+				  PJMEDIA_PIA_SPF(&wav_play->info),
 				  tail_ms, latency_ms,
 				  opt, &ec);
@@ -234,10 +234,10 @@
 
     /* Processing loop */
-    play_frame.buf = pj_pool_alloc(pool, wav_play->info.samples_per_frame<<1);
-    rec_frame.buf = pj_pool_alloc(pool, wav_play->info.samples_per_frame<<1);
+    play_frame.buf = pj_pool_alloc(pool, PJMEDIA_PIA_SPF(&wav_play->info)<<1);
+    rec_frame.buf = pj_pool_alloc(pool, PJMEDIA_PIA_SPF(&wav_play->info)<<1);
     pj_get_timestamp(&t0);
     for (i=0; i < repeat; ++i) {
 	for (;;) {
-	    play_frame.size = wav_play->info.samples_per_frame << 1;
+	    play_frame.size = PJMEDIA_PIA_SPF(&wav_play->info) << 1;
 	    status = pjmedia_port_get_frame(wav_play, &play_frame);
 	    if (status != PJ_SUCCESS)
@@ -246,5 +246,5 @@
 	    status = pjmedia_echo_playback(ec, (short*)play_frame.buf);
 
-	    rec_frame.size = wav_play->info.samples_per_frame << 1;
+	    rec_frame.size = PJMEDIA_PIA_SPF(&wav_play->info) << 1;
 	    status = pjmedia_port_get_frame(wav_rec, &rec_frame);
 	    if (status != PJ_SUCCESS)
@@ -265,5 +265,5 @@
 
     i = pjmedia_wav_writer_port_get_pos(wav_out) / sizeof(pj_int16_t) * 1000 / 
-	(wav_out->info.clock_rate * wav_out->info.channel_count);
+	 (PJMEDIA_PIA_SRATE(&wav_out->info) * PJMEDIA_PIA_CCNT(&wav_out->info));
     PJ_LOG(3,(THIS_FILE, "Processed %3d.%03ds audio",
 	      i / 1000, i % 1000));
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/auddemo.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/auddemo.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/auddemo.c	(revision 3392)
@@ -145,5 +145,5 @@
 		break;
 	    }
-	    sprintf(bitrate, "%u", info.ext_fmt[i].bitrate);
+	    sprintf(bitrate, "%u", info.ext_fmt[i].det.aud.avg_bps);
 	    strcat(formats, bitrate);
 	    strcat(formats, " ");
@@ -277,8 +277,8 @@
 
     param.dir = PJMEDIA_DIR_CAPTURE;
-    param.clock_rate = wav->info.clock_rate;
-    param.samples_per_frame = wav->info.samples_per_frame;
-    param.channel_count = wav->info.channel_count;
-    param.bits_per_sample = wav->info.bits_per_sample;
+    param.clock_rate = PJMEDIA_PIA_SRATE(&wav->info);
+    param.samples_per_frame = PJMEDIA_PIA_SPF(&wav->info);
+    param.channel_count = PJMEDIA_PIA_CCNT(&wav->info);
+    param.bits_per_sample = PJMEDIA_PIA_BITS(&wav->info);
 
     status = pjmedia_aud_stream_create(&param, &wav_rec_cb, NULL, wav,
@@ -344,8 +344,8 @@
 
     param.dir = PJMEDIA_DIR_PLAYBACK;
-    param.clock_rate = wav->info.clock_rate;
-    param.samples_per_frame = wav->info.samples_per_frame;
-    param.channel_count = wav->info.channel_count;
-    param.bits_per_sample = wav->info.bits_per_sample;
+    param.clock_rate = PJMEDIA_PIA_SRATE(&wav->info);
+    param.samples_per_frame = PJMEDIA_PIA_SPF(&wav->info);
+    param.channel_count = PJMEDIA_PIA_CCNT(&wav->info);
+    param.bits_per_sample = PJMEDIA_PIA_BITS(&wav->info);
 
     status = pjmedia_aud_stream_create(&param, NULL, &wav_play_cb, wav,
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/jbsim.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/jbsim.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/jbsim.c	(revision 3392)
@@ -531,6 +531,6 @@
 
     /* Make sure stream and WAV parameters match */
-    if (g_app.tx_wav->info.clock_rate != g_app.tx->port->info.clock_rate ||
-	g_app.tx_wav->info.channel_count != g_app.tx->port->info.channel_count)
+    if (PJMEDIA_PIA_SRATE(&g_app.tx_wav->info) != PJMEDIA_PIA_SRATE(&g_app.tx->port->info) ||
+	PJMEDIA_PIA_CCNT(&g_app.tx_wav->info) != PJMEDIA_PIA_CCNT(&g_app.tx->port->info))
     {
 	jbsim_perror("Error: Input WAV file has different clock rate "
@@ -555,8 +555,8 @@
     status = pjmedia_wav_writer_port_create(g_app.pool, 
 					    g_app.cfg.rx_wav_out,
-					    g_app.rx->port->info.clock_rate,
-					    g_app.rx->port->info.channel_count,
-					    g_app.rx->port->info.samples_per_frame,
-					    g_app.rx->port->info.bits_per_sample,
+					    PJMEDIA_PIA_SRATE(&g_app.rx->port->info),
+					    PJMEDIA_PIA_CCNT(&g_app.rx->port->info),
+					    PJMEDIA_PIA_SPF(&g_app.rx->port->info),
+					    PJMEDIA_PIA_BITS(&g_app.rx->port->info),
 					    0,
 					    0,
@@ -571,6 +571,6 @@
     g_app.framebuf = (pj_int16_t*)
 		     pj_pool_alloc(g_app.pool,
-				   MAX(g_app.rx->port->info.samples_per_frame,
-				       g_app.tx->port->info.samples_per_frame) * sizeof(pj_int16_t));
+				   MAX(PJMEDIA_PIA_SPF(&g_app.rx->port->info),
+				       PJMEDIA_PIA_SPF(&g_app.tx->port->info)) * sizeof(pj_int16_t));
 
 
@@ -595,5 +595,5 @@
     frame.type = PJMEDIA_FRAME_TYPE_AUDIO;
     frame.buf = g_app.framebuf;
-    frame.size = dst->info.samples_per_frame * 2;
+    frame.size = PJMEDIA_PIA_SPF(&dst->info) * 2;
     
     status = pjmedia_port_get_frame(src, &frame);
@@ -602,6 +602,6 @@
     if (status!= PJ_SUCCESS || frame.type != PJMEDIA_FRAME_TYPE_AUDIO) {
 	frame.buf = g_app.framebuf;
-	pjmedia_zero_samples(g_app.framebuf, src->info.samples_per_frame);
-	frame.size = src->info.samples_per_frame * 2;
+	pjmedia_zero_samples(g_app.framebuf, PJMEDIA_PIA_SPF(&src->info));
+	frame.size = PJMEDIA_PIA_SPF(&src->info) * 2;
 	if (has_frame)
 	    *has_frame = PJ_FALSE;
@@ -629,6 +629,6 @@
 
     /* packet interval, without jitter */
-    pkt_interval = port->info.samples_per_frame * 1000 /
-		   port->info.clock_rate;
+    pkt_interval = PJMEDIA_PIA_SPF(&port->info) * 1000 /
+		   PJMEDIA_PIA_SRATE(&port->info);
 
     while (PJ_TIME_VAL_GTE(*t, strm->state.tx.next_schedule)) {
@@ -778,6 +778,6 @@
     long pkt_interval;
 
-    pkt_interval = port->info.samples_per_frame * 1000 /
-		   port->info.clock_rate *
+    pkt_interval = PJMEDIA_PIA_SPF(&port->info) * 1000 /
+		   PJMEDIA_PIA_SRATE(&port->info) *
 		   g_app.cfg.rx_snd_burst;
 
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/latency.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/latency.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/latency.c	(revision 3392)
@@ -61,5 +61,5 @@
 	     lat_max = 0;
 
-    samples_per_frame = wav->info.samples_per_frame;
+    samples_per_frame = PJMEDIA_PIA_SPF(&wav->info);
     frm.buf = pj_pool_alloc(pool, samples_per_frame * 2);
     frm.size = samples_per_frame * 2;
@@ -77,5 +77,5 @@
     }
 
-    if (read < 2 * wav->info.clock_rate) {
+    if (read < 2 * PJMEDIA_PIA_SRATE(&wav->info)) {
 	puts("Error: too short");
 	return -1;
@@ -83,5 +83,5 @@
 
     start_pos = 0;
-    while (start_pos < len/2 - wav->info.clock_rate) {
+    while (start_pos < len/2 - PJMEDIA_PIA_SRATE(&wav->info)) {
 	int max_signal = 0;
 	unsigned max_signal_pos = start_pos;
@@ -91,5 +91,5 @@
 
 	/* Get the largest signal in the next 0.7s */
-	for (i=start_pos; i<start_pos + wav->info.clock_rate * 700 / 1000; ++i) {
+	for (i=start_pos; i<start_pos + PJMEDIA_PIA_SRATE(&wav->info) * 700 / 1000; ++i) {
 	    if (abs(buf[i]) > max_signal) {
 		max_signal = abs(buf[i]);
@@ -99,10 +99,10 @@
 
 	/* Advance 10ms from max_signal_pos */
-	pos = max_signal_pos + 10 * wav->info.clock_rate / 1000;
+	pos = max_signal_pos + 10 * PJMEDIA_PIA_SRATE(&wav->info) / 1000;
 
 	/* Get the largest signal in the next 500ms */
 	max_signal = 0;
 	max_echo_pos = pos;
-	for (i=pos; i<pos+wav->info.clock_rate/2; ++i) {
+	for (i=pos; i<pos+PJMEDIA_PIA_SRATE(&wav->info)/2; ++i) {
 	    if (abs(buf[i]) > max_signal) {
 		max_signal = abs(buf[i]);
@@ -111,5 +111,5 @@
 	}
 
-	lat = (max_echo_pos - max_signal_pos) * 1000 / wav->info.clock_rate;
+	lat = (max_echo_pos - max_signal_pos) * 1000 / PJMEDIA_PIA_SRATE(&wav->info);
 	
 #if 0
@@ -125,5 +125,5 @@
 
 	/* Advance next loop */
-	start_pos += wav->info.clock_rate;
+	start_pos += PJMEDIA_PIA_SRATE(&wav->info);
     }
 
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/level.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/level.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/level.c	(revision 3392)
@@ -125,5 +125,5 @@
     }
 
-    if (file_port->info.samples_per_frame > NSAMPLES) {
+    if (PJMEDIA_PIA_SPF(&file_port->info) > NSAMPLES) {
 	app_perror(THIS_FILE, "WAV clock rate is too big", PJ_EINVAL);
 	return 1;
@@ -146,9 +146,9 @@
 
 	level32 = pjmedia_calc_avg_signal(framebuf, 
-					  file_port->info.samples_per_frame);
+					  PJMEDIA_PIA_SPF(&file_port->info));
 	level = pjmedia_linear2ulaw(level32) ^ 0xFF;
 
-	ms = i * 1000 * file_port->info.samples_per_frame /
-			file_port->info.clock_rate;
+	ms = i * 1000 * PJMEDIA_PIA_SPF(&file_port->info) /
+		PJMEDIA_PIA_SRATE(&file_port->info);
 	printf("%03d.%03d\t%7d\t%7d\n", 
 	        ms/1000, ms%1000, level, level32);
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/mix.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/mix.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/mix.c	(revision 3392)
@@ -182,5 +182,5 @@
 	len = pjmedia_wav_player_get_len(wav_input[i].port);
 	len = (pj_ssize_t)(len * 1.0 * clock_rate / 
-			    wav_input[i].port->info.clock_rate);
+			   PJMEDIA_PIA_SRATE(&wav_input[i].port->info));
 	if (len > (pj_ssize_t)longest)
 	    longest = len;
@@ -200,5 +200,5 @@
 
 	frame.buf = framebuf;
-	frame.size = cp->info.samples_per_frame * 2;
+	frame.size = PJMEDIA_PIA_SPF(&cp->info) * 2;
 	pj_assert(frame.size <= sizeof(framebuf));
 	
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/pcaputil.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/pcaputil.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/pcaputil.c	(revision 3392)
@@ -88,5 +88,5 @@
         if (pos >= 0) {
             unsigned msec;
-            msec = pos / 2 * 1000 / app.wav->info.clock_rate;
+            msec = pos / 2 * 1000 / PJMEDIA_PIA_SRATE(&app.wav->info);
             printf("Written: %dm:%02ds.%03d\n",
                     msec / 1000 / 60,
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playfile.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playfile.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playfile.c	(revision 3392)
@@ -140,8 +140,8 @@
 		 pool,				    /* pool		    */
 		 -1,				    /* use default dev.	    */
-		 file_port->info.clock_rate,	    /* clock rate.	    */
-		 file_port->info.channel_count,	    /* # of channels.	    */
-		 file_port->info.samples_per_frame, /* samples per frame.   */
-		 file_port->info.bits_per_sample,   /* bits per sample.	    */
+		 PJMEDIA_PIA_SRATE(&file_port->info),/* clock rate.	    */
+		 PJMEDIA_PIA_CCNT(&file_port->info),/* # of channels.	    */
+		 PJMEDIA_PIA_SPF(&file_port->info), /* samples per frame.   */
+		 PJMEDIA_PIA_BITS(&file_port->info),/* bits per sample.	    */
 		 0,				    /* options		    */
 		 &snd_port			    /* returned port	    */
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playsine.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playsine.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/playsine.c	(revision 3392)
@@ -87,5 +87,5 @@
 
     /* Get number of samples */
-    count = frame->size / 2 / port->info.channel_count;
+    count = frame->size / 2 / PJMEDIA_PIA_CCNT(&port->info);
 
     left = 0;
@@ -96,5 +96,5 @@
 	++left;
 
-	if (port->info.channel_count == 2) {
+	if (PJMEDIA_PIA_CCNT(&port->info) == 2) {
 	    *samples++ = sine->samples[right];
 	    right += 2; /* higher pitch so we can distinguish left and right. */
@@ -127,4 +127,5 @@
     unsigned i;
     unsigned count;
+    pj_str_t name;
     port_data *sine;
 
@@ -136,15 +137,10 @@
 
     /* Fill in port info. */
-    port->info.bits_per_sample = 16;
-    port->info.channel_count = channel_count;
-    port->info.encoding_name = pj_str("pcm");
-    port->info.has_info = 1;
-    port->info.name = pj_str("sine generator");
-    port->info.need_info = 0;
-    port->info.pt = 0xFF;
-    port->info.clock_rate = sampling_rate;
-    port->info.samples_per_frame = sampling_rate * 20 / 1000 * channel_count;
-    port->info.bytes_per_frame = port->info.samples_per_frame * 2;
-    port->info.type = PJMEDIA_TYPE_AUDIO;
+    name = pj_str("sine generator");
+    pjmedia_port_info_init(&port->info, &name,
+			   PJMEDIA_PORT_SIGNATURE('s', 'i', 'n', 'e'),
+			   sampling_rate,
+			   channel_count,
+			   16, sampling_rate * 20 / 1000 * channel_count);
     
     /* Set the function to feed frame */
@@ -155,5 +151,5 @@
 
     /* Create samples */
-    count = port->info.samples_per_frame / channel_count;
+    count = PJMEDIA_PIA_SPF(&port->info) / channel_count;
     sine->samples = pj_pool_alloc(pool, count * sizeof(pj_int16_t));
     PJ_ASSERT_RETURN(sine->samples != NULL, PJ_ENOMEM);
@@ -245,8 +241,8 @@
 		 pool,				    /* pool		    */
 		 -1,				    /* use default dev.	    */
-		 sine_port->info.clock_rate,	    /* clock rate.	    */
-		 sine_port->info.channel_count,	    /* # of channels.	    */
-		 sine_port->info.samples_per_frame, /* samples per frame.   */
-		 sine_port->info.bits_per_sample,   /* bits per sample.	    */
+		 PJMEDIA_PIA_SRATE(&sine_port->info),/* clock rate.	    */
+		 PJMEDIA_PIA_CCNT(&sine_port->info),/* # of channels.	    */
+		 PJMEDIA_PIA_SPF(&sine_port->info), /* samples per frame.   */
+		 PJMEDIA_PIA_BITS(&sine_port->info),/* bits per sample.	    */
 		 0,				    /* options		    */
 		 &snd_port			    /* returned port	    */
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/recfile.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/recfile.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/recfile.c	(revision 3392)
@@ -135,8 +135,8 @@
 		 pool,				    /* pool		    */
 		 -1,				    /* use default dev.	    */
-		 file_port->info.clock_rate,	    /* clock rate.	    */
-		 file_port->info.channel_count,	    /* # of channels.	    */
-		 file_port->info.samples_per_frame, /* samples per frame.   */
-		 file_port->info.bits_per_sample,   /* bits per sample.	    */
+		 PJMEDIA_PIA_SRATE(&file_port->info),/* clock rate.	    */
+		 PJMEDIA_PIA_CCNT(&file_port->info),/* # of channels.	    */
+		 PJMEDIA_PIA_SPF(&file_port->info), /* samples per frame.   */
+		 PJMEDIA_PIA_BITS(&file_port->info),/* bits per sample.	    */
 		 0,				    /* options		    */
 		 &snd_port			    /* returned port	    */
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/resampleplay.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/resampleplay.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/resampleplay.c	(revision 3392)
@@ -130,5 +130,5 @@
 
     /* File must have same number of channels. */
-    if (file_port->info.channel_count != (unsigned)channel_count) {
+    if (PJMEDIA_PIA_CCNT(&file_port->info) != (unsigned)channel_count) {
 	PJ_LOG(3,(THIS_FILE, "Error: file has different number of channels. "
 			     "Perhaps you'd need -c option?"));
@@ -187,5 +187,6 @@
 
     printf("Playing %s at sampling rate %d (original file sampling rate=%d)\n",
-	   argv[pj_optind], sampling_rate, file_port->info.clock_rate);
+	   argv[pj_optind], sampling_rate,
+	   PJMEDIA_PIA_SRATE(&file_port->info));
     puts("");
     puts("Press <ENTER> to stop playing and quit");
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c	(revision 3392)
@@ -707,8 +707,8 @@
 		    inv->pool,				/* pool		    */
 		    -1,					/* sound dev id	    */
-		    media_port->info.clock_rate,	/* clock rate	    */
-		    media_port->info.channel_count,	/* channel count    */
-		    media_port->info.samples_per_frame, /* samples per frame*/
-		    media_port->info.bits_per_sample,   /* bits per sample  */
+		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
+		    PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
+		    PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
+		    PJMEDIA_PIA_BITS(&media_port->info),/* bits per sample  */
 		    0,					/* options	    */
 		    &g_snd_player);
@@ -716,8 +716,8 @@
 	app_perror( THIS_FILE, "Unable to create sound player", status);
 	PJ_LOG(3,(THIS_FILE, "%d %d %d %d",
-	    	    media_port->info.clock_rate,	/* clock rate	    */
-		    media_port->info.channel_count,	/* channel count    */
-		    media_port->info.samples_per_frame, /* samples per frame*/
-		    media_port->info.bits_per_sample    /* bits per sample  */
+		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
+		    PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
+		    PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
+		    PJMEDIA_PIA_BITS(&media_port->info) /* bits per sample  */
 	    ));
 	return;
@@ -733,8 +733,8 @@
 		    inv->pool,				/* pool		    */
 		    -1,					/* sound dev id	    */
-		    media_port->info.clock_rate,	/* clock rate	    */
-		    media_port->info.channel_count,	/* channel count    */
-		    media_port->info.samples_per_frame, /* samples per frame*/
-		    media_port->info.bits_per_sample,   /* bits per sample  */
+		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
+		    PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
+		    PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
+		    PJMEDIA_PIA_BITS(&media_port->info),/* bits per sample  */
 		    0,					/* options	    */
 		    &g_snd_rec);
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/stereotest.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/stereotest.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/stereotest.c	(revision 3392)
@@ -190,9 +190,9 @@
 		     pool,				/* pool		      */
 		     dev_id,				/* device id.	      */
-		     file_port->info.clock_rate,	/* clock rate.	      */
+		     PJMEDIA_PIA_SRATE(&file_port->info),/* clock rate.	      */
 		     snd_ch_cnt,			/* # of channels.     */
 		     snd_ch_cnt * PTIME *		/* samples per frame. */
-		     file_port->info.clock_rate / 1000,
-		     file_port->info.bits_per_sample,   /* bits per sample.   */
+		     PJMEDIA_PIA_SRATE(&file_port->info) / 1000,
+		     PJMEDIA_PIA_BITS(&file_port->info),/* bits per sample.   */
 		     0,					/* options	      */
 		     &snd_port				/* returned port      */
@@ -203,5 +203,5 @@
 	}
 
-	if (snd_ch_cnt != file_port->info.channel_count) {
+	if (snd_ch_cnt != PJMEDIA_PIA_CCNT(&file_port->info)) {
 	    status = pjmedia_stereo_port_create( pool,
 						 file_port,
@@ -290,7 +290,7 @@
 
     printf("Mode = %s\n", (mode == MODE_PLAY? "playing" : "recording") );
-    printf("File  port channel count = %d\n", file_port->info.channel_count);
+    printf("File  port channel count = %d\n", PJMEDIA_PIA_CCNT(&file_port->info));
     printf("Sound port channel count = %d\n", 
-	   pjmedia_snd_port_get_port(snd_port)->info.channel_count);
+	    PJMEDIA_PIA_CCNT(&pjmedia_snd_port_get_port(snd_port)->info));
     puts("");
     puts("Press <ENTER> to stop and quit");
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/streamutil.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/streamutil.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/streamutil.c	(revision 3392)
@@ -506,6 +506,5 @@
 	unsigned wav_ptime;
 
-	wav_ptime = stream_port->info.samples_per_frame * 1000 /
-		    stream_port->info.clock_rate;
+	wav_ptime = PJMEDIA_PIA_PTIME(&stream_port->info);
 	status = pjmedia_wav_player_port_create(pool, play_file, wav_ptime,
 						0, -1, &play_file_port);
@@ -533,8 +532,8 @@
 
 	status = pjmedia_wav_writer_port_create(pool, rec_file,
-					        stream_port->info.clock_rate,
-						stream_port->info.channel_count,
-						stream_port->info.samples_per_frame,
-						stream_port->info.bits_per_sample,
+					        PJMEDIA_PIA_SRATE(&stream_port->info),
+					        PJMEDIA_PIA_CCNT(&stream_port->info),
+					        PJMEDIA_PIA_SPF(&stream_port->info),
+					        PJMEDIA_PIA_BITS(&stream_port->info),
 						0, 0, &rec_file_port);
 	if (status != PJ_SUCCESS) {
@@ -563,22 +562,22 @@
 	if (dir == PJMEDIA_DIR_ENCODING_DECODING)
 	    status = pjmedia_snd_port_create(pool, -1, -1, 
-					stream_port->info.clock_rate,
-					stream_port->info.channel_count,
-					stream_port->info.samples_per_frame,
-					stream_port->info.bits_per_sample,
+					PJMEDIA_PIA_SRATE(&stream_port->info),
+					PJMEDIA_PIA_CCNT(&stream_port->info),
+					PJMEDIA_PIA_SPF(&stream_port->info),
+					PJMEDIA_PIA_BITS(&stream_port->info),
 					0, &snd_port);
 	else if (dir == PJMEDIA_DIR_ENCODING)
 	    status = pjmedia_snd_port_create_rec(pool, -1, 
-					stream_port->info.clock_rate,
-					stream_port->info.channel_count,
-					stream_port->info.samples_per_frame,
-					stream_port->info.bits_per_sample,
+					PJMEDIA_PIA_SRATE(&stream_port->info),
+					PJMEDIA_PIA_CCNT(&stream_port->info),
+					PJMEDIA_PIA_SPF(&stream_port->info),
+					PJMEDIA_PIA_BITS(&stream_port->info),
 					0, &snd_port);
 	else
 	    status = pjmedia_snd_port_create_player(pool, -1, 
-					stream_port->info.clock_rate,
-					stream_port->info.channel_count,
-					stream_port->info.samples_per_frame,
-					stream_port->info.bits_per_sample,
+					PJMEDIA_PIA_SRATE(&stream_port->info),
+					PJMEDIA_PIA_CCNT(&stream_port->info),
+					PJMEDIA_PIA_SPF(&stream_port->info),
+					PJMEDIA_PIA_BITS(&stream_port->info),
 					0, &snd_port);
 
@@ -758,9 +757,7 @@
 
 
-    printf(" Info: audio %.*s@%dHz, %dms/frame, %sB/s (%sB/s +IP hdr)\n",
-   	(int)port->info.encoding_name.slen,
-	port->info.encoding_name.ptr,
-	port->info.clock_rate,
-	port->info.samples_per_frame * 1000 / port->info.clock_rate,
+    printf(" Info: audio %dHz, %dms/frame, %sB/s (%sB/s +IP hdr)\n",
+	PJMEDIA_PIA_SRATE(&port->info),
+	PJMEDIA_PIA_PTIME(&port->info),
 	good_number(bps, (codec_param->info.avg_bps+7)/8),
 	good_number(ipbps, ((codec_param->info.avg_bps+7)/8) + 
Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/vstreamutil.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/vstreamutil.c	(revision 3392)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/vstreamutil.c	(revision 3392)
@@ -0,0 +1,1259 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * 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 
+ */
+
+
+/**
+ * \page page_pjmedia_samples_streamutil_c Samples: Remote Streaming
+ *
+ * This example mainly demonstrates how to stream media file to remote
+ * peer using RTP.
+ *
+ * This file is pjsip-apps/src/samples/streamutil.c
+ *
+ * \includelineno streamutil.c
+ */
+
+#include <pjlib.h>
+#include <pjlib-util.h>
+#include <pjmedia.h>
+#include <pjmedia-codec.h>
+#include <pjmedia/transport_srtp.h>
+
+#include <stdlib.h>	/* atoi() */
+#include <stdio.h>
+
+#include "util.h"
+
+
+static const char *desc = 
+ " streamutil								\n"
+ "									\n"
+ " PURPOSE:								\n"
+ "  Demonstrate how to use pjmedia stream component to transmit/receive \n"
+ "  RTP packets to/from sound device.		    			\n"
+ "\n"
+ "\n"
+ " USAGE:								\n"
+ "  streamutil [options]                                                \n"
+ "\n"
+ "\n"
+ " Options:\n"
+ "  --codec=CODEC         Set the codec name.                           \n"
+ "  --local-port=PORT     Set local RTP port (default=4000)		\n"
+ "  --remote=IP:PORT      Set the remote peer. If this option is set,	\n"
+ "                        the program will transmit RTP audio to the	\n"
+ "                        specified address. (default: recv only)	\n"
+ /*
+ "  --play-file=WAV       Send audio from the WAV file instead of from	\n"
+ "                        the sound device.				\n"
+ "  --record-file=WAV     Record incoming audio to WAV file instead of	\n"
+ "                        playing it to sound device.			\n"
+ */
+ "  --send-recv           Set stream direction to bidirectional.        \n"
+ "  --send-only           Set stream direction to send only		\n"
+ "  --recv-only           Set stream direction to recv only (default)   \n"
+
+ "  --recv-width          Video width to be received                    \n"
+ "  --recv-height         Video height to be received                   \n"
+ "  --recv-pt             Payload type for receiving                    \n"
+
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+ "  --use-srtp[=NAME]     Enable SRTP with crypto suite NAME            \n"
+ "                        e.g: AES_CM_128_HMAC_SHA1_80 (default),       \n"
+ "                             AES_CM_128_HMAC_SHA1_32                  \n"
+ "                        Use this option along with the TX & RX keys,  \n"
+ "                        formated of 60 hex digits (e.g: E148DA..)      \n"
+ "  --srtp-tx-key         SRTP key for transmiting                      \n"
+ "  --srtp-rx-key         SRTP key for receiving                        \n"
+#endif
+
+ "\n"
+;
+
+
+
+
+#define THIS_FILE	"stream.c"
+
+
+
+/* Prototype */
+static void print_stream_stat(pjmedia_stream *stream, 
+			      const pjmedia_codec_param *codec_param);
+
+/* Prototype for LIBSRTP utility in file datatypes.c */
+int hex_string_to_octet_string(char *raw, char *hex, int len);
+
+/* 
+ * Register all codecs. 
+ */
+static pj_status_t init_codecs(pj_pool_factory *pf)
+{
+    pj_status_t status;
+
+    /* To suppress warning about unused var when all codecs are disabled */
+    PJ_UNUSED_ARG(status);
+
+#if defined(PJMEDIA_HAS_FFMPEG_CODEC) && PJMEDIA_HAS_FFMPEG_CODEC != 0
+    status = pjmedia_codec_ffmpeg_init(NULL, pf);
+    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
+#endif
+
+    return PJ_SUCCESS;
+}
+
+
+/* 
+ * Create stream based on the codec, dir, remote address, etc. 
+ */
+static pj_status_t create_stream( pj_pool_t *pool,
+				  pjmedia_endpt *med_endpt,
+				  const pjmedia_vid_codec_info *codec_info,
+                                  pjmedia_vid_codec_param *codec_param,
+				  pjmedia_dir dir,
+				  pj_uint16_t local_port,
+				  const pj_sockaddr_in *rem_addr,
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+				  pj_bool_t use_srtp,
+				  const pj_str_t *crypto_suite,
+				  const pj_str_t *srtp_tx_key,
+				  const pj_str_t *srtp_rx_key,
+#endif
+				  pjmedia_stream **p_stream )
+{
+    pjmedia_stream_info info;
+    pjmedia_transport *transport = NULL;
+    pj_status_t status;
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+    pjmedia_transport *srtp_tp = NULL;
+#endif
+
+
+    /* Reset stream info. */
+    pj_bzero(&info, sizeof(info));
+
+
+    /* Initialize stream info formats */
+    info.type = PJMEDIA_TYPE_VIDEO;
+    info.dir = dir;
+    info.vid_codec_info = *codec_info;
+    info.tx_pt = codec_info->pt;
+    info.ssrc = pj_rand();
+    if (codec_param)
+        info.vid_codec_param = codec_param;
+    
+#if PJMEDIA_HAS_RTCP_XR && PJMEDIA_STREAM_ENABLE_XR
+    /* Set default RTCP XR enabled/disabled */
+    info.rtcp_xr_enabled = PJ_TRUE;
+#endif
+
+    /* Copy remote address */
+    pj_memcpy(&info.rem_addr, rem_addr, sizeof(pj_sockaddr_in));
+
+    /* If remote address is not set, set to an arbitrary address
+     * (otherwise stream will assert).
+     */
+    if (info.rem_addr.addr.sa_family == 0) {
+	const pj_str_t addr = pj_str("127.0.0.1");
+	pj_sockaddr_in_init(&info.rem_addr.ipv4, &addr, 0);
+    }
+
+    /* Create media transport */
+    status = pjmedia_transport_udp_create(med_endpt, NULL, local_port,
+					  0, &transport);
+    if (status != PJ_SUCCESS)
+	return status;
+
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+    /* Check if SRTP enabled */
+    if (use_srtp) {
+	pjmedia_srtp_crypto tx_plc, rx_plc;
+
+	status = pjmedia_transport_srtp_create(med_endpt, transport, 
+					       NULL, &srtp_tp);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto));
+	pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto));
+
+	tx_plc.key = *srtp_tx_key;
+	tx_plc.name = *crypto_suite;
+	rx_plc.key = *srtp_rx_key;
+	rx_plc.name = *crypto_suite;
+	
+	status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	transport = srtp_tp;
+    }
+#endif
+
+    /* Now that the stream info is initialized, we can create the 
+     * stream.
+     */
+
+    status = pjmedia_stream_create( med_endpt, pool, &info, 
+				    transport, 
+				    NULL, p_stream);
+
+    if (status != PJ_SUCCESS) {
+	app_perror(THIS_FILE, "Error creating stream", status);
+	pjmedia_transport_close(transport);
+	return status;
+    }
+
+
+    return PJ_SUCCESS;
+}
+
+
+/*
+ * usage()
+ */
+static void usage()
+{
+    puts(desc);
+}
+
+/*
+ * main()
+ */
+int main(int argc, char *argv[])
+{
+    pj_caching_pool cp;
+    pjmedia_endpt *med_endpt;
+    pj_pool_t *pool;
+    pjmedia_port *rec_file_port = NULL, *play_file_port = NULL;
+    pjmedia_master_port *master_port = NULL;
+    pjmedia_stream *stream = NULL;
+    pjmedia_port *stream_port;
+    char tmp[10];
+    pj_status_t status; 
+
+    pjmedia_vid_port *capture=NULL, *renderer=NULL;
+    pjmedia_vid_port_param vpp;
+
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+    /* SRTP variables */
+    pj_bool_t use_srtp = PJ_FALSE;
+    char tmp_tx_key[64];
+    char tmp_rx_key[64];
+    pj_str_t  srtp_tx_key = {NULL, 0};
+    pj_str_t  srtp_rx_key = {NULL, 0};
+    pj_str_t  srtp_crypto_suite = {NULL, 0};
+    int	tmp_key_len;
+#endif
+
+    /* Default values */
+    const pjmedia_vid_codec_info *codec_info;
+    pjmedia_vid_codec_param codec_param;
+    pjmedia_dir dir = PJMEDIA_DIR_DECODING;
+    pj_sockaddr_in remote_addr;
+    pj_uint16_t local_port = 4000;
+    char *codec_id = NULL;
+    char *rec_file = NULL;
+    char *play_file = NULL;
+    pjmedia_rect_size rx_size = {0};
+    pj_int8_t rx_pt = -1;
+
+    enum {
+	OPT_CODEC	= 'c',
+	OPT_LOCAL_PORT	= 'p',
+	OPT_REMOTE	= 'r',
+	OPT_PLAY_FILE	= 'I',
+	OPT_RECORD_FILE	= 'O',
+	OPT_SEND_RECV	= 'b',
+	OPT_SEND_ONLY	= 's',
+	OPT_RECV_ONLY	= 'i',
+	OPT_RECV_WIDTH	= 'W',
+	OPT_RECV_HEIGHT	= 'H',
+	OPT_RECV_PT	= 't',
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+	OPT_USE_SRTP	= 'S',
+#endif
+	OPT_SRTP_TX_KEY	= 'x',
+	OPT_SRTP_RX_KEY	= 'y',
+	OPT_HELP	= 'h',
+    };
+
+    struct pj_getopt_option long_options[] = {
+	{ "codec",	    1, 0, OPT_CODEC },
+	{ "local-port",	    1, 0, OPT_LOCAL_PORT },
+	{ "remote",	    1, 0, OPT_REMOTE },
+	{ "play-file",	    1, 0, OPT_PLAY_FILE },
+	{ "record-file",    1, 0, OPT_RECORD_FILE },
+	{ "send-recv",      0, 0, OPT_SEND_RECV },
+	{ "send-only",      0, 0, OPT_SEND_ONLY },
+	{ "recv-only",      0, 0, OPT_RECV_ONLY },
+	{ "recv-width",     1, 0, OPT_RECV_WIDTH },
+	{ "recv-height",    1, 0, OPT_RECV_HEIGHT },
+	{ "recv-pt",        1, 0, OPT_RECV_PT },
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+	{ "use-srtp",	    2, 0, OPT_USE_SRTP },
+	{ "srtp-tx-key",    1, 0, OPT_SRTP_TX_KEY },
+	{ "srtp-rx-key",    1, 0, OPT_SRTP_RX_KEY },
+#endif
+	{ "help",	    0, 0, OPT_HELP },
+	{ NULL, 0, 0, 0 },
+    };
+
+    int c;
+    int option_index;
+
+
+    pj_bzero(&remote_addr, sizeof(remote_addr));
+
+
+    /* init PJLIB : */
+    status = pj_init();
+    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+
+    /* Parse arguments */
+    pj_optind = 0;
+    while((c=pj_getopt_long(argc,argv, "h", long_options, &option_index))!=-1) {
+
+	switch (c) {
+	case OPT_CODEC:
+	    codec_id = pj_optarg;
+	    break;
+
+	case OPT_LOCAL_PORT:
+	    local_port = (pj_uint16_t) atoi(pj_optarg);
+	    if (local_port < 1) {
+		printf("Error: invalid local port %s\n", pj_optarg);
+		return 1;
+	    }
+	    break;
+
+	case OPT_REMOTE:
+	    {
+		pj_str_t ip = pj_str(strtok(pj_optarg, ":"));
+		pj_uint16_t port = (pj_uint16_t) atoi(strtok(NULL, ":"));
+
+		status = pj_sockaddr_in_init(&remote_addr, &ip, port);
+		if (status != PJ_SUCCESS) {
+		    app_perror(THIS_FILE, "Invalid remote address", status);
+		    return 1;
+		}
+	    }
+	    break;
+
+	case OPT_PLAY_FILE:
+	    play_file = pj_optarg;
+	    break;
+
+	case OPT_RECORD_FILE:
+	    rec_file = pj_optarg;
+	    break;
+
+	case OPT_SEND_RECV:
+	    dir = PJMEDIA_DIR_ENCODING_DECODING;
+	    break;
+
+	case OPT_SEND_ONLY:
+	    dir = PJMEDIA_DIR_ENCODING;
+	    break;
+
+	case OPT_RECV_ONLY:
+	    dir = PJMEDIA_DIR_DECODING;
+	    break;
+
+	case OPT_RECV_WIDTH:
+	    rx_size.w = (unsigned)atoi(pj_optarg);
+	    break;
+
+	case OPT_RECV_HEIGHT:
+	    rx_size.h = (unsigned)atoi(pj_optarg);
+	    break;
+
+	case OPT_RECV_PT:
+	    rx_pt = (pj_int8_t)atoi(pj_optarg);
+	    break;
+
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+	case OPT_USE_SRTP:
+	    use_srtp = PJ_TRUE;
+	    if (pj_optarg) {
+		pj_strset(&srtp_crypto_suite, pj_optarg, strlen(pj_optarg));
+	    } else {
+		srtp_crypto_suite = pj_str("AES_CM_128_HMAC_SHA1_80");
+	    }
+	    break;
+
+	case OPT_SRTP_TX_KEY:
+	    tmp_key_len = hex_string_to_octet_string(tmp_tx_key, pj_optarg, strlen(pj_optarg));
+	    pj_strset(&srtp_tx_key, tmp_tx_key, tmp_key_len/2);
+	    break;
+
+	case OPT_SRTP_RX_KEY:
+	    tmp_key_len = hex_string_to_octet_string(tmp_rx_key, pj_optarg, strlen(pj_optarg));
+	    pj_strset(&srtp_rx_key, tmp_rx_key, tmp_key_len/2);
+	    break;
+#endif
+
+	case OPT_HELP:
+	    usage();
+	    return 1;
+
+	default:
+	    printf("Invalid options %s\n", argv[pj_optind]);
+	    return 1;
+	}
+
+    }
+
+
+    /* Verify arguments. */
+    if (dir & PJMEDIA_DIR_ENCODING) {
+	if (remote_addr.sin_addr.s_addr == 0) {
+	    printf("Error: remote address must be set\n");
+	    return 1;
+	}
+    }
+
+    if (play_file != NULL && dir != PJMEDIA_DIR_ENCODING) {
+	printf("Direction is set to --send-only because of --play-file\n");
+	dir = PJMEDIA_DIR_ENCODING;
+    }
+
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+    /* SRTP validation */
+    if (use_srtp) {
+	if (!srtp_tx_key.slen || !srtp_rx_key.slen)
+	{
+	    printf("Error: Key for each SRTP stream direction must be set\n");
+	    return 1;
+	}
+    }
+#endif
+
+    /* Must create a pool factory before we can allocate any memory. */
+    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
+
+    /* 
+     * Initialize media endpoint.
+     * This will implicitly initialize PJMEDIA too.
+     */
+    status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
+    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+    /* Create memory pool for application purpose */
+    pool = pj_pool_create( &cp.factory,	    /* pool factory	    */
+			   "app",	    /* pool name.	    */
+			   4000,	    /* init size	    */
+			   4000,	    /* increment size	    */
+			   NULL		    /* callback on error    */
+			   );
+
+    /* Init video format manager */
+    pjmedia_video_format_mgr_create(pool, 64, 0, NULL);
+
+    /* Init video codec manager */
+    pjmedia_vid_codec_mgr_create(pool, NULL);
+
+    /* Init video subsystem */
+    pjmedia_vid_subsys_init(&cp.factory);
+
+    /* Register all supported codecs */
+    status = init_codecs(&cp.factory);
+    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+
+    /* Find which codec to use. */
+    if (codec_id) {
+	unsigned count = 1;
+	pj_str_t str_codec_id = pj_str(codec_id);
+
+        status = pjmedia_vid_codec_mgr_find_codecs_by_id(NULL,
+						         &str_codec_id, &count,
+						         &codec_info, NULL);
+	if (status != PJ_SUCCESS) {
+	    printf("Error: unable to find codec %s\n", codec_id);
+	    return 1;
+	}
+    } else {
+        static pjmedia_vid_codec_info info[1];
+        unsigned count = PJ_ARRAY_SIZE(info);
+
+	/* Default to first codec */
+	pjmedia_vid_codec_mgr_enum_codecs(NULL, &count, info, NULL);
+        codec_info = &info[0];
+    }
+
+    /* Get codec default param for info */
+    status = pjmedia_vid_codec_mgr_get_default_param(NULL, codec_info, 
+				                     &codec_param);
+    /* Should be ok, as create_stream() above succeeded */
+    pj_assert(status == PJ_SUCCESS);
+    if (rx_pt >= 0)
+        codec_param.pt = rx_pt;
+    if (rx_size.w && rx_size.h)
+        codec_param.dec_fmt.det.vid.size = rx_size;
+
+    /* Create stream based on program arguments */
+    status = create_stream(pool, med_endpt, codec_info, &codec_param,
+                           dir, local_port, &remote_addr, 
+#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
+			   use_srtp, &srtp_crypto_suite, 
+			   &srtp_tx_key, &srtp_rx_key,
+#endif
+			   &stream);
+    if (status != PJ_SUCCESS)
+	goto on_exit;
+
+    /* Get the port interface of the stream */
+    status = pjmedia_stream_get_port( stream, &stream_port);
+    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+
+    if (play_file) {
+        /*
+	unsigned wav_ptime;
+
+	wav_ptime = PJMEDIA_PIA_PTIME(&stream_port->info);
+	status = pjmedia_wav_player_port_create(pool, play_file, wav_ptime,
+						0, -1, &play_file_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Unable to use file", status);
+	    goto on_exit;
+	}
+
+	status = pjmedia_master_port_create(pool, play_file_port, stream_port,
+					    0, &master_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Unable to create master port", status);
+	    goto on_exit;
+	}
+
+	status = pjmedia_master_port_start(master_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Error starting master port", status);
+	    goto on_exit;
+	}
+
+	printf("Playing from WAV file %s..\n", play_file);
+        */
+
+    } else if (rec_file) {
+        /*
+
+	status = pjmedia_wav_writer_port_create(pool, rec_file,
+					        PJMEDIA_PIA_SRATE(&stream_port->info),
+					        PJMEDIA_PIA_CCNT(&stream_port->info),
+					        PJMEDIA_PIA_SPF(&stream_port->info),
+					        PJMEDIA_PIA_BITS(&stream_port->info),
+						0, 0, &rec_file_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Unable to use file", status);
+	    goto on_exit;
+	}
+
+	status = pjmedia_master_port_create(pool, stream_port, rec_file_port, 
+					    0, &master_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Unable to create master port", status);
+	    goto on_exit;
+	}
+
+	status = pjmedia_master_port_start(master_port);
+	if (status != PJ_SUCCESS) {
+	    app_perror(THIS_FILE, "Error starting master port", status);
+	    goto on_exit;
+	}
+
+	printf("Recording to WAV file %s..\n", rec_file);
+        */
+	
+    } else {
+
+        pjmedia_vid_port_param_default(&vpp);
+
+        /* Set as active for all video devices */
+        vpp.active = PJ_TRUE;
+
+	/* Create video device port. */
+        if (dir & PJMEDIA_DIR_ENCODING) {
+            /* Create capture */
+            status = pjmedia_vid_dev_default_param(pool,
+                                                   0,//PJMEDIA_VID_DEFAULT_CAPTURE_DEV,
+					           &vpp.vidparam);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+
+            pjmedia_format_copy(&vpp.vidparam.fmt, &codec_param.dec_fmt);
+            vpp.vidparam.dir = PJMEDIA_DIR_CAPTURE;
+            
+            status = pjmedia_vid_port_create(pool, &vpp, &capture);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+
+            status = pjmedia_vid_port_connect(capture, stream_port, PJ_FALSE);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+        }
+	
+        if (dir & PJMEDIA_DIR_DECODING) {
+            /* Create renderer */
+            status = pjmedia_vid_dev_default_param(pool,
+                                                   1,//PJMEDIA_VID_DEFAULT_RENDER_DEV,
+					           &vpp.vidparam);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+
+            pjmedia_format_copy(&vpp.vidparam.fmt, &codec_param.dec_fmt);
+            vpp.vidparam.dir = PJMEDIA_DIR_RENDER;
+            vpp.vidparam.disp_size = vpp.vidparam.fmt.det.vid.size;
+
+            status = pjmedia_vid_port_create(pool, &vpp, &renderer);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+
+            status = pjmedia_vid_port_connect(renderer, stream_port, PJ_FALSE);
+            if (status != PJ_SUCCESS)
+	        goto on_exit;
+        }
+    }
+
+    /* Start streaming */
+    status = pjmedia_stream_start(stream);
+    if (status != PJ_SUCCESS)
+        goto on_exit;
+    if (renderer) {
+        status = pjmedia_vid_port_start(renderer);
+        if (status != PJ_SUCCESS)
+            goto on_exit;
+    }
+    if (capture) {
+        status = pjmedia_vid_port_start(capture);
+        if (status != PJ_SUCCESS)
+            goto on_exit;
+    }
+
+
+    /* Done */
+
+    if (dir == PJMEDIA_DIR_DECODING)
+	printf("Stream is active, dir is recv-only, local port is %d\n",
+	       local_port);
+    else if (dir == PJMEDIA_DIR_ENCODING)
+	printf("Stream is active, dir is send-only, sending to %s:%d\n",
+	       pj_inet_ntoa(remote_addr.sin_addr),
+	       pj_ntohs(remote_addr.sin_port));
+    else
+	printf("Stream is active, send/recv, local port is %d, "
+	       "sending to %s:%d\n",
+	       local_port,
+	       pj_inet_ntoa(remote_addr.sin_addr),
+	       pj_ntohs(remote_addr.sin_port));
+
+
+    for (;;) {
+
+	puts("");
+	puts("Commands:");
+	puts("  s     Display media statistics");
+	puts("  q     Quit");
+	puts("");
+
+	printf("Command: "); fflush(stdout);
+
+	if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    break;
+	}
+
+	if (tmp[0] == 's')
+	    ;//print_stream_stat(stream, &codec_param);
+	else if (tmp[0] == 'q')
+	    break;
+
+    }
+
+
+
+    /* Start deinitialization: */
+on_exit:
+
+    /* Destroy video devices */
+    if (capture)
+	pjmedia_vid_port_destroy(capture);
+    if (renderer)
+	pjmedia_vid_port_destroy(renderer);
+
+    /* If there is master port, then we just need to destroy master port
+     * (it will recursively destroy upstream and downstream ports, which
+     * in this case are file_port and stream_port).
+     */
+    if (master_port) {
+	pjmedia_master_port_destroy(master_port, PJ_TRUE);
+	play_file_port = NULL;
+	stream = NULL;
+    }
+
+    /* Destroy stream */
+    if (stream) {
+	pjmedia_transport *tp;
+
+	tp = pjmedia_stream_get_transport(stream);
+	pjmedia_stream_destroy(stream);
+	
+	pjmedia_transport_close(tp);
+    }
+
+    /* Destroy file ports */
+    if (play_file_port)
+	pjmedia_port_destroy( play_file_port );
+    if (rec_file_port)
+	pjmedia_port_destroy( rec_file_port );
+
+    /* Shutdown video subsystem */
+    pjmedia_vid_subsys_shutdown();
+
+    /* Release application pool */
+    pj_pool_release( pool );
+
+    /* Destroy media endpoint. */
+    pjmedia_endpt_destroy( med_endpt );
+
+    /* Destroy pool factory */
+    pj_caching_pool_destroy( &cp );
+
+    /* Shutdown PJLIB */
+    pj_shutdown();
+
+
+    return (status == PJ_SUCCESS) ? 0 : 1;
+}
+
+
+
+
+static const char *good_number(char *buf, pj_int32_t val)
+{
+    if (val < 1000) {
+	pj_ansi_sprintf(buf, "%d", val);
+    } else if (val < 1000000) {
+	pj_ansi_sprintf(buf, "%d.%dK", 
+			val / 1000,
+			(val % 1000) / 100);
+    } else {
+	pj_ansi_sprintf(buf, "%d.%02dM", 
+			val / 1000000,
+			(val % 1000000) / 10000);
+    }
+
+    return buf;
+}
+
+
+#define SAMPLES_TO_USEC(usec, samples, clock_rate) \
+    do { \
+	if (samples <= 4294) \
+	    usec = samples * 1000000 / clock_rate; \
+	else { \
+	    usec = samples * 1000 / clock_rate; \
+	    usec *= 1000; \
+	} \
+    } while(0)
+
+#define PRINT_VOIP_MTC_VAL(s, v) \
+    if (v == 127) \
+	sprintf(s, "(na)"); \
+    else \
+	sprintf(s, "%d", v)
+
+
+/*
+ * Print stream statistics
+ */
+static void print_stream_stat(pjmedia_stream *stream,
+			      const pjmedia_codec_param *codec_param)
+{
+    char duration[80], last_update[80];
+    char bps[16], ipbps[16], packets[16], bytes[16], ipbytes[16];
+    pjmedia_port *port;
+    pjmedia_rtcp_stat stat;
+    pj_time_val now;
+
+
+    pj_gettimeofday(&now);
+    pjmedia_stream_get_stat(stream, &stat);
+    pjmedia_stream_get_port(stream, &port);
+
+    puts("Stream statistics:");
+
+    /* Print duration */
+    PJ_TIME_VAL_SUB(now, stat.start);
+    sprintf(duration, " Duration: %02ld:%02ld:%02ld.%03ld",
+	    now.sec / 3600,
+	    (now.sec % 3600) / 60,
+	    (now.sec % 60),
+	    now.msec);
+
+
+    printf(" Info: audio %dHz, %dms/frame, %sB/s (%sB/s +IP hdr)\n",
+	PJMEDIA_PIA_SRATE(&port->info),
+	PJMEDIA_PIA_PTIME(&port->info),
+	good_number(bps, (codec_param->info.avg_bps+7)/8),
+	good_number(ipbps, ((codec_param->info.avg_bps+7)/8) + 
+			   (40 * 1000 /
+			    codec_param->setting.frm_per_pkt /
+			    codec_param->info.frm_ptime)));
+
+    if (stat.rx.update_cnt == 0)
+	strcpy(last_update, "never");
+    else {
+	pj_gettimeofday(&now);
+	PJ_TIME_VAL_SUB(now, stat.rx.update);
+	sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		now.sec / 3600,
+		(now.sec % 3600) / 60,
+		now.sec % 60,
+		now.msec);
+    }
+
+    printf(" RX stat last update: %s\n"
+	   "    total %s packets %sB received (%sB +IP hdr)%s\n"
+	   "    pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
+	   "          (msec)    min     avg     max     last    dev\n"
+	   "    loss period: %7.3f %7.3f %7.3f %7.3f %7.3f%s\n"
+	   "    jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n",
+	   last_update,
+	   good_number(packets, stat.rx.pkt),
+	   good_number(bytes, stat.rx.bytes),
+	   good_number(ipbytes, stat.rx.bytes + stat.rx.pkt * 32),
+	   "",
+	   stat.rx.loss,
+	   stat.rx.loss * 100.0 / (stat.rx.pkt + stat.rx.loss),
+	   stat.rx.dup, 
+	   stat.rx.dup * 100.0 / (stat.rx.pkt + stat.rx.loss),
+	   stat.rx.reorder, 
+	   stat.rx.reorder * 100.0 / (stat.rx.pkt + stat.rx.loss),
+	   "",
+	   stat.rx.loss_period.min / 1000.0, 
+	   stat.rx.loss_period.mean / 1000.0, 
+	   stat.rx.loss_period.max / 1000.0,
+	   stat.rx.loss_period.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rx.loss_period) / 1000.0,
+	   "",
+	   stat.rx.jitter.min / 1000.0,
+	   stat.rx.jitter.mean / 1000.0,
+	   stat.rx.jitter.max / 1000.0,
+	   stat.rx.jitter.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rx.jitter) / 1000.0,
+	   ""
+	   );
+
+
+    if (stat.tx.update_cnt == 0)
+	strcpy(last_update, "never");
+    else {
+	pj_gettimeofday(&now);
+	PJ_TIME_VAL_SUB(now, stat.tx.update);
+	sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		now.sec / 3600,
+		(now.sec % 3600) / 60,
+		now.sec % 60,
+		now.msec);
+    }
+
+    printf(" TX stat last update: %s\n"
+	   "    total %s packets %sB sent (%sB +IP hdr)%s\n"
+	   "    pkt loss=%d (%3.1f%%), dup=%d (%3.1f%%), reorder=%d (%3.1f%%)%s\n"
+	   "          (msec)    min     avg     max     last    dev\n"
+	   "    loss period: %7.3f %7.3f %7.3f %7.3f %7.3f%s\n"
+	   "    jitter     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n",
+	   last_update,
+	   good_number(packets, stat.tx.pkt),
+	   good_number(bytes, stat.tx.bytes),
+	   good_number(ipbytes, stat.tx.bytes + stat.tx.pkt * 32),
+	   "",
+	   stat.tx.loss,
+	   stat.tx.loss * 100.0 / (stat.tx.pkt + stat.tx.loss),
+	   stat.tx.dup, 
+	   stat.tx.dup * 100.0 / (stat.tx.pkt + stat.tx.loss),
+	   stat.tx.reorder, 
+	   stat.tx.reorder * 100.0 / (stat.tx.pkt + stat.tx.loss),
+	   "",
+	   stat.tx.loss_period.min / 1000.0, 
+	   stat.tx.loss_period.mean / 1000.0, 
+	   stat.tx.loss_period.max / 1000.0,
+	   stat.tx.loss_period.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.tx.loss_period) / 1000.0,
+	   "",
+	   stat.tx.jitter.min / 1000.0,
+	   stat.tx.jitter.mean / 1000.0,
+	   stat.tx.jitter.max / 1000.0,
+	   stat.tx.jitter.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.tx.jitter) / 1000.0,
+	   ""
+	   );
+
+
+    printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n", 
+	   stat.rtt.min / 1000.0,
+	   stat.rtt.mean / 1000.0,
+	   stat.rtt.max / 1000.0,
+	   stat.rtt.last / 1000.0,
+	   pj_math_stat_get_stddev(&stat.rtt) / 1000.0,
+	   ""
+	   );
+
+#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
+    /* RTCP XR Reports */
+    do {
+	char loss[16], dup[16];
+	char jitter[80];
+	char toh[80];
+	char plc[16], jba[16], jbr[16];
+	char signal_lvl[16], noise_lvl[16], rerl[16];
+	char r_factor[16], ext_r_factor[16], mos_lq[16], mos_cq[16];
+	pjmedia_rtcp_xr_stat xr_stat;
+
+	if (pjmedia_stream_get_stat_xr(stream, &xr_stat) != PJ_SUCCESS)
+	    break;
+
+	puts("\nExtended reports:");
+
+	/* Statistics Summary */
+	puts(" Statistics Summary");
+
+	if (xr_stat.rx.stat_sum.l)
+	    sprintf(loss, "%d", xr_stat.rx.stat_sum.lost);
+	else
+	    sprintf(loss, "(na)");
+
+	if (xr_stat.rx.stat_sum.d)
+	    sprintf(dup, "%d", xr_stat.rx.stat_sum.dup);
+	else
+	    sprintf(dup, "(na)");
+
+	if (xr_stat.rx.stat_sum.j) {
+	    unsigned jmin, jmax, jmean, jdev;
+
+	    SAMPLES_TO_USEC(jmin, xr_stat.rx.stat_sum.jitter.min, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jmax, xr_stat.rx.stat_sum.jitter.max, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jmean, xr_stat.rx.stat_sum.jitter.mean, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jdev, 
+			   pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.jitter),
+			   port->info.clock_rate);
+	    sprintf(jitter, "%7.3f %7.3f %7.3f %7.3f", 
+		    jmin/1000.0, jmean/1000.0, jmax/1000.0, jdev/1000.0);
+	} else
+	    sprintf(jitter, "(report not available)");
+
+	if (xr_stat.rx.stat_sum.t) {
+	    sprintf(toh, "%11d %11d %11d %11d", 
+		    xr_stat.rx.stat_sum.toh.min,
+		    xr_stat.rx.stat_sum.toh.mean,
+		    xr_stat.rx.stat_sum.toh.max,
+		    pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.toh));
+	} else
+	    sprintf(toh, "(report not available)");
+
+	if (xr_stat.rx.stat_sum.update.sec == 0)
+	    strcpy(last_update, "never");
+	else {
+	    pj_gettimeofday(&now);
+	    PJ_TIME_VAL_SUB(now, xr_stat.rx.stat_sum.update);
+	    sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		    now.sec / 3600,
+		    (now.sec % 3600) / 60,
+		    now.sec % 60,
+		    now.msec);
+	}
+
+	printf(" RX last update: %s\n"
+	       "    begin seq=%d, end seq=%d%s\n"
+	       "    pkt loss=%s, dup=%s%s\n"
+	       "          (msec)    min     avg     max     dev\n"
+	       "    jitter     : %s\n"
+	       "    toh        : %s\n",
+	       last_update,
+	       xr_stat.rx.stat_sum.begin_seq, xr_stat.rx.stat_sum.end_seq,
+	       "",
+	       loss, dup,
+	       "",
+	       jitter,
+	       toh
+	       );
+
+	if (xr_stat.tx.stat_sum.l)
+	    sprintf(loss, "%d", xr_stat.tx.stat_sum.lost);
+	else
+	    sprintf(loss, "(na)");
+
+	if (xr_stat.tx.stat_sum.d)
+	    sprintf(dup, "%d", xr_stat.tx.stat_sum.dup);
+	else
+	    sprintf(dup, "(na)");
+
+	if (xr_stat.tx.stat_sum.j) {
+	    unsigned jmin, jmax, jmean, jdev;
+
+	    SAMPLES_TO_USEC(jmin, xr_stat.tx.stat_sum.jitter.min, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jmax, xr_stat.tx.stat_sum.jitter.max, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jmean, xr_stat.tx.stat_sum.jitter.mean, 
+			    port->info.clock_rate);
+	    SAMPLES_TO_USEC(jdev, 
+			   pj_math_stat_get_stddev(&xr_stat.tx.stat_sum.jitter),
+			   port->info.clock_rate);
+	    sprintf(jitter, "%7.3f %7.3f %7.3f %7.3f", 
+		    jmin/1000.0, jmean/1000.0, jmax/1000.0, jdev/1000.0);
+	} else
+	    sprintf(jitter, "(report not available)");
+
+	if (xr_stat.tx.stat_sum.t) {
+	    sprintf(toh, "%11d %11d %11d %11d", 
+		    xr_stat.tx.stat_sum.toh.min,
+		    xr_stat.tx.stat_sum.toh.mean,
+		    xr_stat.tx.stat_sum.toh.max,
+		    pj_math_stat_get_stddev(&xr_stat.rx.stat_sum.toh));
+	} else
+	    sprintf(toh,    "(report not available)");
+
+	if (xr_stat.tx.stat_sum.update.sec == 0)
+	    strcpy(last_update, "never");
+	else {
+	    pj_gettimeofday(&now);
+	    PJ_TIME_VAL_SUB(now, xr_stat.tx.stat_sum.update);
+	    sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		    now.sec / 3600,
+		    (now.sec % 3600) / 60,
+		    now.sec % 60,
+		    now.msec);
+	}
+
+	printf(" TX last update: %s\n"
+	       "    begin seq=%d, end seq=%d%s\n"
+	       "    pkt loss=%s, dup=%s%s\n"
+	       "          (msec)    min     avg     max     dev\n"
+	       "    jitter     : %s\n"
+	       "    toh        : %s\n",
+	       last_update,
+	       xr_stat.tx.stat_sum.begin_seq, xr_stat.tx.stat_sum.end_seq,
+	       "",
+	       loss, dup,
+	       "",
+	       jitter,
+	       toh
+	       );
+
+	/* VoIP Metrics */
+	puts(" VoIP Metrics");
+
+	PRINT_VOIP_MTC_VAL(signal_lvl, xr_stat.rx.voip_mtc.signal_lvl);
+	PRINT_VOIP_MTC_VAL(noise_lvl, xr_stat.rx.voip_mtc.noise_lvl);
+	PRINT_VOIP_MTC_VAL(rerl, xr_stat.rx.voip_mtc.rerl);
+	PRINT_VOIP_MTC_VAL(r_factor, xr_stat.rx.voip_mtc.r_factor);
+	PRINT_VOIP_MTC_VAL(ext_r_factor, xr_stat.rx.voip_mtc.ext_r_factor);
+	PRINT_VOIP_MTC_VAL(mos_lq, xr_stat.rx.voip_mtc.mos_lq);
+	PRINT_VOIP_MTC_VAL(mos_cq, xr_stat.rx.voip_mtc.mos_cq);
+
+	switch ((xr_stat.rx.voip_mtc.rx_config>>6) & 3) {
+	    case PJMEDIA_RTCP_XR_PLC_DIS:
+		sprintf(plc, "DISABLED");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_ENH:
+		sprintf(plc, "ENHANCED");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_STD:
+		sprintf(plc, "STANDARD");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_UNK:
+	    default:
+		sprintf(plc, "UNKNOWN");
+		break;
+	}
+
+	switch ((xr_stat.rx.voip_mtc.rx_config>>4) & 3) {
+	    case PJMEDIA_RTCP_XR_JB_FIXED:
+		sprintf(jba, "FIXED");
+		break;
+	    case PJMEDIA_RTCP_XR_JB_ADAPTIVE:
+		sprintf(jba, "ADAPTIVE");
+		break;
+	    default:
+		sprintf(jba, "UNKNOWN");
+		break;
+	}
+
+	sprintf(jbr, "%d", xr_stat.rx.voip_mtc.rx_config & 0x0F);
+
+	if (xr_stat.rx.voip_mtc.update.sec == 0)
+	    strcpy(last_update, "never");
+	else {
+	    pj_gettimeofday(&now);
+	    PJ_TIME_VAL_SUB(now, xr_stat.rx.voip_mtc.update);
+	    sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		    now.sec / 3600,
+		    (now.sec % 3600) / 60,
+		    now.sec % 60,
+		    now.msec);
+	}
+
+	printf(" RX last update: %s\n"
+	       "    packets    : loss rate=%d (%.2f%%), discard rate=%d (%.2f%%)\n"
+	       "    burst      : density=%d (%.2f%%), duration=%d%s\n"
+	       "    gap        : density=%d (%.2f%%), duration=%d%s\n"
+	       "    delay      : round trip=%d%s, end system=%d%s\n"
+	       "    level      : signal=%s%s, noise=%s%s, RERL=%s%s\n"
+	       "    quality    : R factor=%s, ext R factor=%s\n"
+	       "                 MOS LQ=%s, MOS CQ=%s\n"
+	       "    config     : PLC=%s, JB=%s, JB rate=%s, Gmin=%d\n"
+	       "    JB delay   : cur=%d%s, max=%d%s, abs max=%d%s\n",
+	       last_update,
+	       /* pakcets */
+	       xr_stat.rx.voip_mtc.loss_rate, xr_stat.rx.voip_mtc.loss_rate*100.0/256,
+	       xr_stat.rx.voip_mtc.discard_rate, xr_stat.rx.voip_mtc.discard_rate*100.0/256,
+	       /* burst */
+	       xr_stat.rx.voip_mtc.burst_den, xr_stat.rx.voip_mtc.burst_den*100.0/256,
+	       xr_stat.rx.voip_mtc.burst_dur, "ms",
+	       /* gap */
+	       xr_stat.rx.voip_mtc.gap_den, xr_stat.rx.voip_mtc.gap_den*100.0/256,
+	       xr_stat.rx.voip_mtc.gap_dur, "ms",
+	       /* delay */
+	       xr_stat.rx.voip_mtc.rnd_trip_delay, "ms",
+	       xr_stat.rx.voip_mtc.end_sys_delay, "ms",
+	       /* level */
+	       signal_lvl, "dB",
+	       noise_lvl, "dB",
+	       rerl, "",
+	       /* quality */
+	       r_factor, ext_r_factor, mos_lq, mos_cq,
+	       /* config */
+	       plc, jba, jbr, xr_stat.rx.voip_mtc.gmin,
+	       /* JB delay */
+	       xr_stat.rx.voip_mtc.jb_nom, "ms",
+	       xr_stat.rx.voip_mtc.jb_max, "ms",
+	       xr_stat.rx.voip_mtc.jb_abs_max, "ms"
+	       );
+
+	PRINT_VOIP_MTC_VAL(signal_lvl, xr_stat.tx.voip_mtc.signal_lvl);
+	PRINT_VOIP_MTC_VAL(noise_lvl, xr_stat.tx.voip_mtc.noise_lvl);
+	PRINT_VOIP_MTC_VAL(rerl, xr_stat.tx.voip_mtc.rerl);
+	PRINT_VOIP_MTC_VAL(r_factor, xr_stat.tx.voip_mtc.r_factor);
+	PRINT_VOIP_MTC_VAL(ext_r_factor, xr_stat.tx.voip_mtc.ext_r_factor);
+	PRINT_VOIP_MTC_VAL(mos_lq, xr_stat.tx.voip_mtc.mos_lq);
+	PRINT_VOIP_MTC_VAL(mos_cq, xr_stat.tx.voip_mtc.mos_cq);
+
+	switch ((xr_stat.tx.voip_mtc.rx_config>>6) & 3) {
+	    case PJMEDIA_RTCP_XR_PLC_DIS:
+		sprintf(plc, "DISABLED");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_ENH:
+		sprintf(plc, "ENHANCED");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_STD:
+		sprintf(plc, "STANDARD");
+		break;
+	    case PJMEDIA_RTCP_XR_PLC_UNK:
+	    default:
+		sprintf(plc, "unknown");
+		break;
+	}
+
+	switch ((xr_stat.tx.voip_mtc.rx_config>>4) & 3) {
+	    case PJMEDIA_RTCP_XR_JB_FIXED:
+		sprintf(jba, "FIXED");
+		break;
+	    case PJMEDIA_RTCP_XR_JB_ADAPTIVE:
+		sprintf(jba, "ADAPTIVE");
+		break;
+	    default:
+		sprintf(jba, "unknown");
+		break;
+	}
+
+	sprintf(jbr, "%d", xr_stat.tx.voip_mtc.rx_config & 0x0F);
+
+	if (xr_stat.tx.voip_mtc.update.sec == 0)
+	    strcpy(last_update, "never");
+	else {
+	    pj_gettimeofday(&now);
+	    PJ_TIME_VAL_SUB(now, xr_stat.tx.voip_mtc.update);
+	    sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
+		    now.sec / 3600,
+		    (now.sec % 3600) / 60,
+		    now.sec % 60,
+		    now.msec);
+	}
+
+	printf(" TX last update: %s\n"
+	       "    packets    : loss rate=%d (%.2f%%), discard rate=%d (%.2f%%)\n"
+	       "    burst      : density=%d (%.2f%%), duration=%d%s\n"
+	       "    gap        : density=%d (%.2f%%), duration=%d%s\n"
+	       "    delay      : round trip=%d%s, end system=%d%s\n"
+	       "    level      : signal=%s%s, noise=%s%s, RERL=%s%s\n"
+	       "    quality    : R factor=%s, ext R factor=%s\n"
+	       "                 MOS LQ=%s, MOS CQ=%s\n"
+	       "    config     : PLC=%s, JB=%s, JB rate=%s, Gmin=%d\n"
+	       "    JB delay   : cur=%d%s, max=%d%s, abs max=%d%s\n",
+	       last_update,
+	       /* pakcets */
+	       xr_stat.tx.voip_mtc.loss_rate, xr_stat.tx.voip_mtc.loss_rate*100.0/256,
+	       xr_stat.tx.voip_mtc.discard_rate, xr_stat.tx.voip_mtc.discard_rate*100.0/256,
+	       /* burst */
+	       xr_stat.tx.voip_mtc.burst_den, xr_stat.tx.voip_mtc.burst_den*100.0/256,
+	       xr_stat.tx.voip_mtc.burst_dur, "ms",
+	       /* gap */
+	       xr_stat.tx.voip_mtc.gap_den, xr_stat.tx.voip_mtc.gap_den*100.0/256,
+	       xr_stat.tx.voip_mtc.gap_dur, "ms",
+	       /* delay */
+	       xr_stat.tx.voip_mtc.rnd_trip_delay, "ms",
+	       xr_stat.tx.voip_mtc.end_sys_delay, "ms",
+	       /* level */
+	       signal_lvl, "dB",
+	       noise_lvl, "dB",
+	       rerl, "",
+	       /* quality */
+	       r_factor, ext_r_factor, mos_lq, mos_cq,
+	       /* config */
+	       plc, jba, jbr, xr_stat.tx.voip_mtc.gmin,
+	       /* JB delay */
+	       xr_stat.tx.voip_mtc.jb_nom, "ms",
+	       xr_stat.tx.voip_mtc.jb_max, "ms",
+	       xr_stat.tx.voip_mtc.jb_abs_max, "ms"
+	       );
+
+
+	/* RTT delay (by receiver side) */
+	printf("          (msec)    min     avg     max     last    dev\n");
+	printf(" RTT delay     : %7.3f %7.3f %7.3f %7.3f %7.3f%s\n", 
+	       xr_stat.rtt.min / 1000.0,
+	       xr_stat.rtt.mean / 1000.0,
+	       xr_stat.rtt.max / 1000.0,
+	       xr_stat.rtt.last / 1000.0,
+	       pj_math_stat_get_stddev(&xr_stat.rtt) / 1000.0,
+	       ""
+	       );
+    } while (0);
+#endif /* PJMEDIA_HAS_RTCP_XR */
+
+}
+
Index: pjproject/branches/projects/2.0-dev/pjsip/src/pjsip-ua/sip_100rel.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip/src/pjsip-ua/sip_100rel.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip/src/pjsip-ua/sip_100rel.c	(revision 3392)
@@ -29,4 +29,5 @@
 #include <pj/pool.h>
 #include <pj/rand.h>
+#include <pj/string.h>
 
 #define THIS_FILE	"sip_100rel.c"
Index: pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3392)
@@ -1969,7 +1969,8 @@
 	{
 	    need_reopen = (peer_info.format.id != port0_info.format.id ||
-			   peer_info.format.bitrate != port0_info.format.bitrate ||
+			   peer_info.format.det.aud.avg_bps !=
+				   port0_info.format.det.aud.avg_bps ||
 			   peer_info.clock_rate != port0_info.clock_rate ||
-			   peer_info.channel_count != port0_info.channel_count);
+			   peer_info.channel_count!=port0_info.channel_count);
 	}
 
@@ -1986,5 +1987,6 @@
 					  peer_info.bits_per_sample);
 		if (status != PJ_SUCCESS) {
-		    pjsua_perror(THIS_FILE, "Error opening sound device", status);
+		    pjsua_perror(THIS_FILE, "Error opening sound device",
+				 status);
 		    return status;
 		}
@@ -1998,12 +2000,15 @@
 		status = open_snd_dev(&param);
 		if (status != PJ_SUCCESS) {
-		    pjsua_perror(THIS_FILE, "Error opening sound device", status);
+		    pjsua_perror(THIS_FILE, "Error opening sound device",
+				 status);
 		    return status;
 		}
 	    } else {
 		/* Null-audio */
-		status = pjsua_set_snd_dev(pjsua_var.cap_dev, pjsua_var.play_dev);
+		status = pjsua_set_snd_dev(pjsua_var.cap_dev,
+					   pjsua_var.play_dev);
 		if (status != PJ_SUCCESS) {
-		    pjsua_perror(THIS_FILE, "Error opening sound device", status);
+		    pjsua_perror(THIS_FILE, "Error opening sound device",
+				 status);
 		    return status;
 		}
@@ -2142,5 +2147,5 @@
 				    pool, path,
 				    pjsua_var.mconf_cfg.samples_per_frame *
-				    1000 / pjsua_var.media_cfg.channel_count / 
+				    1000 / pjsua_var.media_cfg.channel_count /
 				    pjsua_var.media_cfg.clock_rate, 
 				    options, 0, &port);
@@ -2706,5 +2711,5 @@
     if (!pjsua_var.is_mswitch &&
 	param->ext_fmt.id == PJMEDIA_FORMAT_PCM &&
-	conf_port->info.clock_rate != param->clock_rate)
+	PJMEDIA_PIA_SRATE(&conf_port->info) != param->clock_rate)
     {
 	pjmedia_port *resample_port;
@@ -2742,11 +2747,14 @@
      */
     if (pjsua_var.is_mswitch) {
-	pj_memcpy(&conf_port->info.format, &param->ext_fmt, 
-		  sizeof(conf_port->info.format));
-	conf_port->info.clock_rate = param->clock_rate;
-	conf_port->info.samples_per_frame = param->samples_per_frame;
-	conf_port->info.channel_count = param->channel_count;
-	conf_port->info.bits_per_sample = 16;
-    }
+	pj_memcpy(&conf_port->info.fmt, &param->ext_fmt,
+		  sizeof(conf_port->info.fmt));
+	conf_port->info.fmt.det.aud.clock_rate = param->clock_rate;
+	conf_port->info.fmt.det.aud.frame_time_usec = param->samples_per_frame*
+						      1000000 /
+						      param->clock_rate;
+	conf_port->info.fmt.det.aud.channel_count = param->channel_count;
+	conf_port->info.fmt.det.aud.bits_per_sample = 16;
+    }
+
 
     /* Connect sound port to the bridge */
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/400_fmtp_g7221_with_bitrate.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/400_fmtp_g7221_with_bitrate.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/400_fmtp_g7221_with_bitrate.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_24000.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_24000.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_24000.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_32000.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_32000.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/401_fmtp_g7221_with_bitrate_32000.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/410_fmtp_amrnb_offer_octet_align.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/410_fmtp_amrnb_offer_octet_align.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/410_fmtp_amrnb_offer_octet_align.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/411_fmtp_amrnb_offer_band_eff.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/411_fmtp_amrnb_offer_band_eff.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/411_fmtp_amrnb_offer_band_eff.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/412_fmtp_amrnb_offer_band_eff2.py
===================================================================
--- pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/412_fmtp_amrnb_offer_band_eff2.py	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/tests/pjsua/scripts-sendto/412_fmtp_amrnb_offer_band_eff2.py	(revision 3392)
@@ -1,3 +1,3 @@
-# $Id $
+# $Id$
 import inc_sip as sip
 import inc_sdp as sdp
Index: pjproject/branches/projects/2.0-dev/version.mak
===================================================================
--- pjproject/branches/projects/2.0-dev/version.mak	(revision 3391)
+++ pjproject/branches/projects/2.0-dev/version.mak	(revision 3392)
@@ -1,1 +1,1 @@
-export PJ_VERSION := 1.8.10-trunk
+export PJ_VERSION := 2.0-dev
