Skip site navigation (1)Skip section navigation (2)
Date:      18 Jul 2005 20:00:44 -0000
From:      Sven Berkvens-Matthijsse <sven@berkvens.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/83689: [PATCH] mjpegtools: 1) libpng problem and 2) FreeBSD 4 mplex problem
Message-ID:  <20050718200044.19651.qmail@cat.berkvens.net>
Resent-Message-ID: <200507182010.j6IKA7gx076264@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         83689
>Category:       ports
>Synopsis:       [PATCH] mjpegtools: 1) libpng problem and 2) FreeBSD 4 mplex problem
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 18 20:10:07 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Sven Berkvens-Matthijsse
>Release:        FreeBSD 4.10-STABLE i386
>Organization:
>Environment:
System: FreeBSD cat.berkvens.net 4.10-STABLE FreeBSD 4.10-STABLE #4: Sun Oct 31 01:46:30 CEST 2004 sven@cat.berkvens.net:/extra0/usr_obj/usr/src/sys/CAT i386
>Description:
	There are two problems with this ports on my FreeBSD 4.10 system.
	The first of the two probably also applies to FreeBSD 5.x.

	First problem: libpng is not detected by mjpegtools' configure. This
	is because pkg-config is asked to check for a package named "libpng",
	but on my FreeBSD 4.10 system, the png port installs itself as a
	pkg-config "libpng12" package, and thus, the mjpegtools does not
	compile the png2yuv package, which I need :-) I have contacted the
	mjpegtools developer at Sourceforge regarding this problem, so it
	could be that they will fix the problem themselves. In the meantime,
	the patch provided below will fix the problem.

	Second problem: this only applies to FreeBSD 4.x because FreeBSD 5.x
	uses another threading library by default. The problem with the
	FreeBSD 4.x threading library is that it is a simulation of threads.
	This means, amongst other things, that all file descriptors that are
	open when a threaded program is started, are changed to non-blocking
	mode. In itself, this is no problem. But here's the catch: if I tell
	mplex to write its results to /dev/stdout, mplex will open /dev/stdout.
	Internally in the kernel, this will just clone file descriptor 1,
	which is already set to non-blocking mode! Now, the threading library
	checks which flags the newly opened file has and adapts its behaviour
	accordingly. This means that the newly opened file is non-blocking in
	the userland thread as well! Now when mplex writes to dvdauthor, for
	example, and mplex is faster than dvdauthor, it will get short writes
	and abort. This is obviously unwanted behaviour. I realize that the
	real problem lies in the way in which threads work in FreeBSD 4.x, but
	there is no chance of things being fixed on that side. The patch
	provided should not interfere with FreeBSD 5.x, by the way. It simply
	sets all opened file descriptors to blocking mode (at least, the
	threading library's behaviour).

>How-To-Repeat:
	First problem: try installing this port and then running png2yuv.

	Second problem: only applicable on FreeBSD 4.x. Run mplex with
	/dev/stdout as the output file and make mplex's stdout something
	slow, like piping it through sleep 60 :-)

>Fix:
	First problem's patch:

	/usr/ports/multimedia/mjpegtools/files/patch-configure

-----8<------8<------8<-----
--- configure.orig	Mon Jul 18 10:11:33 2005
+++ configure	Mon Jul 18 10:12:48 2005
@@ -24288,6 +24288,104 @@
      have_libpng=false
   fi
 
+  if test x$have_libpng = xfalse ; then
+
+  succeeded=no
+
+  if test -z "$PKG_CONFIG"; then
+    # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; 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_path_PKG_CONFIG+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+
+if test -n "$PKG_CONFIG"; then
+  echo "$as_me:$LINENO: result: $PKG_CONFIG" >&5
+echo "${ECHO_T}$PKG_CONFIG" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  fi
+
+  if test "$PKG_CONFIG" = "no" ; then
+     echo "*** The pkg-config script could not be found. Make sure it is"
+     echo "*** in your path, or set the PKG_CONFIG environment variable"
+     echo "*** to the full path to pkg-config."
+     echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
+  else
+     PKG_CONFIG_MIN_VERSION=0.9.0
+     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
+        echo "$as_me:$LINENO: checking for libpng12" >&5
+echo $ECHO_N "checking for libpng12... $ECHO_C" >&6
+
+        if $PKG_CONFIG --exists "libpng12" ; then
+            echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+            succeeded=yes
+
+            echo "$as_me:$LINENO: checking LIBPNG_CFLAGS" >&5
+echo $ECHO_N "checking LIBPNG_CFLAGS... $ECHO_C" >&6
+            LIBPNG_CFLAGS=`$PKG_CONFIG --cflags "libpng12"`
+            echo "$as_me:$LINENO: result: $LIBPNG_CFLAGS" >&5
+echo "${ECHO_T}$LIBPNG_CFLAGS" >&6
+
+            echo "$as_me:$LINENO: checking LIBPNG_LIBS" >&5
+echo $ECHO_N "checking LIBPNG_LIBS... $ECHO_C" >&6
+            LIBPNG_LIBS=`$PKG_CONFIG --libs "libpng12"`
+            echo "$as_me:$LINENO: result: $LIBPNG_LIBS" >&5
+echo "${ECHO_T}$LIBPNG_LIBS" >&6
+        else
+            LIBPNG_CFLAGS=""
+            LIBPNG_LIBS=""
+            ## If we have a custom action on failure, don't print errors, but
+            ## do set a variable so people can do so.
+            LIBPNG_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libpng12"`
+
+        fi
+
+
+
+     else
+        echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
+        echo "*** See http://www.freedesktop.org/software/pkgconfig"
+     fi
+  fi
+
+  if test $succeeded = yes; then
+     have_libpng=true
+  else
+     have_libpng=false
+  fi
+
+  fi
 fi


-----8<------8<------8<----- 

	Also for the first problem:
	/usr/ports/multimedia/mjpegtools/files/patch-configure.ac

-----8<------8<------8<----- 
--- configure.ac.orig	Mon Jul 18 10:01:36 2005
+++ configure.ac	Mon Jul 18 10:02:35 2005
@@ -247,6 +247,9 @@
 have_libpng=false
 if test x$with_libpng != xno ; then
   PKG_CHECK_MODULES(LIBPNG, [libpng], [have_libpng=true], [have_libpng=false])
+  if test x$have_libpng = xfalse ; then
+    PKG_CHECK_MODULES(LIBPNG, [libpng12], [have_libpng=true], [have_libpng=false])
+  fi
 fi
 AM_CONDITIONAL(HAVE_LIBPNG, test x$have_libpng = xtrue)

-----8<------8<------8<-----


	For the second problem:
	/usr/ports/multimedia/mjpegtools/files/patch-mplex::main.cpp

-----8<------8<------8<-----
--- mplex/main.cpp.orig	Thu Dec  9 21:13:26 2004
+++ mplex/main.cpp	Mon Jul 18 21:11:07 2005
@@ -38,6 +38,7 @@
 #endif
 #include <ctype.h>
 #include <math.h>
+#include <fcntl.h>
 #include "cpu_accel.h"
 #include "mjpeg_types.h"
 #include "mjpeg_logging.h"
@@ -107,6 +108,13 @@
 		mjpeg_error_exit1( "Could not open for writing: %s", cur_filename );
 	}
 
+	{
+		int	flags;
+
+		(void)fcntl(fileno(strm), F_GETFL, &flags);
+		(void)fcntl(fileno(strm), F_SETFL, flags & ~O_NONBLOCK);
+	}
+
 	return 0;
 }
 
@@ -144,6 +152,12 @@
 	{
 		mjpeg_error_exit1( "Could not open for writing: %s", cur_filename );
 	}
+	{
+		int	flags;
+
+		(void)fcntl(fileno(strm), F_GETFL, &flags);
+		(void)fcntl(fileno(strm), F_SETFL, flags & ~O_NONBLOCK);
+	}
 }
 
 void
@@ -200,6 +214,14 @@
 	{
 		mjpeg_error_exit1( "Unable to open file %s for reading.", bs_filename);
 	}
+
+	{
+		int	flags;
+
+		(void)fcntl(fileno(fileh), F_GETFL, &flags);
+		(void)fcntl(fileno(fileh), F_SETFL, flags & ~O_NONBLOCK);
+	}
+
 	filename = strcpy( new char[strlen(bs_filename)+1], bs_filename );
     streamname = filename;
 
-----8<------8<------8<-----

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050718200044.19651.qmail>