changeset 11311:5e653b34bbea octave-forge

video: patch by Andreas Weber. * remove avctest since these are on each individual cc files * continuing changes on autoconf script * more tests
author carandraug
date Thu, 20 Dec 2012 17:42:26 +0000
parents 74d963f4e995
children 93bcf6148b3a
files main/video/src/AVHandler.cc main/video/src/AVHandler.h main/video/src/Makefile.in main/video/src/addframe.cc main/video/src/avctest.cc main/video/src/avifile.cc main/video/src/aviinfo.cc main/video/src/aviread.cc main/video/src/config.h.in main/video/src/configure.ac main/video/src/oct-avifile.cc main/video/src/oct-avifile.h
diffstat 12 files changed, 233 insertions(+), 166 deletions(-) [+]
line wrap: on
line diff
--- a/main/video/src/AVHandler.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/AVHandler.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -473,4 +473,3 @@
     
     return frame;
 }
-
--- a/main/video/src/AVHandler.h	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/AVHandler.h	Thu Dec 20 17:42:26 2012 +0000
@@ -24,22 +24,16 @@
 
 #ifndef _AVHANDLER_H
 #define _AVHANDLER_H
-
-#define VIDEO_OUTBUF_SIZE 200000
-
-// FIXME: should define -D__STDC_CONSTANT_MACROS instead of the following
-#define INT64_C
-#define UINT64_C
-#define __STDC_CONSTANT_MACROS
+#include "config.h"
 
 #include <errno.h>
 extern "C" {
 #if defined (HAVE_FFMPEG_AVFORMAT_H)
-#include <ffmpeg/avformat.h>
+ #include <ffmpeg/avformat.h>
 #elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H)
-#include <libavformat/avformat.h>
+ #include <libavformat/avformat.h>
 #else
-#error "Missing ffmpeg headers"
+ #error "Missing ffmpeg headers"
 #endif
 }
 #include <iostream>
--- a/main/video/src/Makefile.in	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/Makefile.in	Thu Dec 20 17:42:26 2012 +0000
@@ -1,39 +1,28 @@
 OCTFILES = avifile.oct aviread.oct aviinfo.oct addframe.oct
-
-FFMPEG_CONFIG = @FFMPEG_CONFIG@
-ifdef FFMPEG_CONFIG
-  FFMPEG_LIBS = $(shell pkg-config libavformat libavcodec libavutil libswscale --libs)
-  FFMPEG_CFLAGS = $(shell pkg-config libavformat libavcodec libavutil libswscale --cflags)
-else
-  FFMPEG_LIBS = -lavformat -lavcodec -lavutil -lswscale -lz -lm
-  FFMPEG_CFLAGS =
-endif
-
 AVOBJS = AVHandler.o oct-avifile.o
+FILES_WITH_TESTS = avifile.cc addframe.cc
 
 .PHONY: clean
-clean:
-	rm -f *.o *.oct avctest *~ octave-core
+.PHONY: realclean
+.PHONY: distclean
+
+all: ${OCTFILES}
 
 oct-avifile.o: AVHandler.o
 
 ${AVOBJS}: %.o: %.cc
-	mkoctfile -v -c $(FFMPEG_DEFS) $(FFMPEG_CFLAGS) $< -o $@
+	mkoctfile -Wall -v -c @DEFS@ $< -o $@
 
 ${OCTFILES}: %.oct: %.cc AVHandler.o oct-avifile.o
-	mkoctfile -v $(FFMPEG_DEFS) $< $(filter %.o, $^) $(FFMPEG_LIBS) $(FFMPEG_CFLAGS)
+	mkoctfile -Wall -v @DEFS@ $< $(filter %.o, $^) @LIBS@
 
-avctest.o: avctest.cc
-	g++ -Wall -c avctest.cc -o avctest.o
-
-avctest: AVHandler.o avctest.o
-	g++ $^ -Wall ${FFMPEG_OPTS} -o $@
+clean:
+	rm -f *.o *~ *.orig octave-workspace
 
-TEST_CASES =   \
-	avitest
-
-NOT_BROKEN_TEST_CASES = $(TEST_CASES:=.test)
-.PHONY: check
-check: $(NOT_BROKEN_TEST_CASES)
-%.test:
-	octave -q tests/$*.m > /dev/null
+realclean: clean
+	rm -f *.oct avctest
+	
+distclean: realclean
+	rm -rf autom4te.cache
+	rm -f Makefile config.status config.log config.h configure
+	rm -f *.avi
--- a/main/video/src/addframe.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/addframe.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -22,6 +22,7 @@
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
+#include "config.h"
 #include <octave/oct.h>
 #include "oct-avifile.h"
 
@@ -71,6 +72,44 @@
 
 /*
 %!test
-%!  m = avifile("test.avi")
-%!  addframe(m, zeros(2,2))
+%!  fn="test_addframe.avi";
+%!  m = avifile(fn);
+%!  addframe(m, zeros(10,15))
+%!  addframe(m, ones(10,15))
+%!  addframe(m, rand(10,15))
+%!  clear m 
+%!  assert(exist(fn,"file"))
+%!  r=aviinfo(fn);
+%!  assert(r.Filename,fn);
+%!  assert(r.NumFrames,3);
+%!  assert(r.Width,15);
+%!  assert(r.Height,10);
+%! 	delete(fn)
 */
+
+/*
+%!demo
+%!  fn="test_avifile2.avi";
+%!  m = avifile(fn, "codec", "mpeg4");
+%!  for i = 1:100
+%!    I = zeros(100,100,3);
+%!
+%!    for x = 1:100
+%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 1) = 40;
+%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 2) = 40;
+%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 3) = 180;
+%!    endfor
+%!
+%!    I(i,:,1) = 0;
+%!    I(i,:,2) = 50 + i*2;
+%!    I(i,:,3) = 0;
+%!    I(:,i,1) = 200 - i*2;
+%!    I(:,i,2) = 0;
+%!    I(:,i,3) = i*2;
+%!
+%!    addframe(m, I/255)
+%!  endfor
+%!  clear m
+%!  assert(exist(fn,"file"))
+%! 	delete(fn)
+*/
--- a/main/video/src/avctest.cc	Thu Dec 20 17:05:41 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#include "AVHandler.h"
-#include <cmath>
-
-#define FRAMES 255
-
-int output_avi(std::string fn, std::string codec) 
-{
-    AVHandler *av = new AVHandler();
-
-    av->set_filename(fn);
-    av->set_height(100);
-    av->set_width(300);
-    av->set_codec(codec);
-
-    int err = av->setup_write();
-    if (err != 0) {
-        delete av;
-        return err;
-    }
-
-    std::cout << "starting..." << std::endl;
-    for (int i = 0; i < FRAMES; i++) {
-        std::cout << "\r" << i << std::flush;
-        av->draw_background((unsigned char)((1+sin(double(i)/1000*2*M_PI))*255/2),
-                            (unsigned char)((1+cos(double(i)/1000*2*M_PI))*255/2), 200);
-        av->write_frame();
-    }
-
-    delete av;
-    return 0;
-}
-
-int main() {
-#if defined(HAVE_THREADS)
-    std::cout << "Warning: threads are active" << std::endl;
-#endif
-
-    std::cout << "Built for libavcodec " << LIBAVCODEC_BUILD;
-    std::cout << " (using version " << avcodec_build() << ")" << std::endl;
-
-    if (output_avi("testc1.avi", "wmv1") != 0)
-        std::cout << "Error writing testc1.avi" << std::endl;
-    if (output_avi("testc2.avi", "wmv1") != 0)
-        std::cout << "Error writing testc2.avi" << std::endl;
-
-    AVHandler av = AVHandler();
-    av.set_filename("testc2.avi");
-    av.setup_read();
-    for (unsigned int i = 1; i < av.get_total_frames()+1; i++) {
-        std::cout << "Reading frame " << i << "...\r" << std::flush;
-        av.read_frame(i);
-    }
-   
-    return 0;
-}
--- a/main/video/src/avifile.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/avifile.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -22,6 +22,7 @@
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
+#include "config.h"
 #include <octave/oct.h>
 #include "oct-avifile.h"
 
@@ -81,7 +82,7 @@
     }
 
     // Parse parameters
-    std::string codec = "msmpeg4v2";
+    std::string codec = "mpeg4";
     unsigned int bitrate = 400000;
     int gop_size = 10;
     double fps = 25;
@@ -128,42 +129,15 @@
 
 /*
 %!test
-%!  avifile("codecs")
-
-%!test
-%!  m = avifile("test.avi", "codec", "msmpeg4v2")
+%!  fn="test_avifile1.avi";
+%!  m = avifile(fn, "codec", "mpeg4");
 %!  for i = 1:100
 %!    I = zeros(100,100);
 %!    I(i,:) = i;
 %!    I(:,i) = 200-i;
-%!    addframe(m, I/255)
-%!    printf(".")
+%!    addframe(m, I/255);
 %!  endfor
-%!  printf("\n")
 %!  clear m
-
-%!test
-%!  m = avifile("test2.avi", "codec", "msmpeg4v2")
-%!  for i = 1:100
-%!    I = zeros(100,100,3);
-%!
-%!    for x = 1:100
-%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 1) = 40;
-%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 2) = 40;
-%!       I(round(50+10*sin((x+i)/100*4*pi)), x, 3) = 180;
-%!    endfor
-%!
-%!    I(i,:,1) = 0;
-%!    I(i,:,2) = 50 + i*2;
-%!    I(i,:,3) = 0;
-%!    I(:,i,1) = 200 - i*2;
-%!    I(:,i,2) = 0;
-%!    I(:,i,3) = i*2;
-%!
-%!    addframe(m, I/255)
-%!    printf(".")
-%!  endfor
-%!  printf("\n")
-%!  clear m
-
+%!  assert(exist(fn,"file"))
+%! 	delete(fn)
 */
--- a/main/video/src/aviinfo.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/aviinfo.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -22,6 +22,7 @@
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
+#include "config.h"
 #include <octave/oct.h>
 #include <octave/oct-map.h>
 
--- a/main/video/src/aviread.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/aviread.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -22,6 +22,7 @@
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
+#include "config.h"
 #include <octave/oct.h>
 #include "AVHandler.h"
 
@@ -92,15 +93,51 @@
 %! I = cat(3, I, 0.3*ones(256,256));
 %!
 %! # Display the picture
-%! imshow(I(:,:,1), I(:,:,2), I(:,:,3));
+%! figure(1)
+%! imshow(I);
 %! 
 %! # Write it to the AVI and close the AVI
 %! addframe(x, I);
+%! addframe(x, I);
 %! clear x
 %! 
 %! # Read the first frame from the AVI
 %! I = aviread("test.avi", 1);
 %!
 %! # Display the frame read
-%! imshow(I(:,:,1), I(:,:,2), I(:,:,3));
+%! figure(2) 
+%! imshow(I);
 */
+
+/*
+%!test
+%! fn = tmpnam; 
+%! x = avifile(fn);
+%!
+%! # Generate some picture
+%! I = repmat(0:255, 256, 1)/255;
+%! I = cat(3, I, repmat([0:255]', 1, 256)/255);
+%! I = cat(3, I, 0.3*ones(256,256));
+%!
+%! # Write it to the AVI and close the AVI
+%! addframe(x, I);
+%! addframe(x, I);  #FIXME: aviread currently fails if only 1 frame
+%! clear x
+%! assert(exist(fn,"file"))
+%! I2 = aviread(fn, 1);
+%!
+%! #allow max. 5% difference between pixels
+%! assert(!any((I-I2)(:)>0.05))
+%! delete(fn);
+*/
+
+/*
+%!xtest
+%! fn = tmpnam; 
+%! x = avifile(fn);
+%! I = ones(256,256);
+%! addframe(x, I);
+%! clear x
+%! #FIXME: This fails if there is only 1 frame
+%! I = aviread(fn, 1);
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/video/src/config.h.in	Thu Dec 20 17:42:26 2012 +0000
@@ -0,0 +1,86 @@
+/* config.h.in.  Generated from configure.ac by autoheader and edited by hand */
+
+/* Define to 1 if you have the <ffmpeg/avcodec.h> header file. */
+#undef HAVE_FFMPEG_AVCODEC_H
+
+/* Define to 1 if you have the <ffmpeg/avformat.h> header file. */
+#undef HAVE_FFMPEG_AVFORMAT_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the `avcodec' library (-lavcodec). */
+#undef HAVE_LIBAVCODEC
+
+/* Define to 1 if you have the <libavcodec/avcodec.h> header file. */
+#undef HAVE_LIBAVCODEC_AVCODEC_H
+
+/* Define to 1 if you have the `avformat' library (-lavformat). */
+#undef HAVE_LIBAVFORMAT
+
+/* Define to 1 if you have the <libavformat/avformat.h> header file. */
+#undef HAVE_LIBAVFORMAT_AVFORMAT_H
+
+/* Define to 1 if you have the `swscale' library (-lswscale). */
+#undef HAVE_LIBSWSCALE
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to 1 if the system has the type `_Bool'. */
+#undef HAVE__BOOL
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* size of video buffer */
+#undef VIDEO_OUTBUF_SIZE
+
+/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
+   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
+   #define below would cause a syntax error. */
+#undef _UINT64_T
+
+/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
+   <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
+   #define below would cause a syntax error. */
+#undef _UINT8_T
+
+/* workaraound for C++ programs to use C99 makros */
+#undef __STDC_CONSTANT_MACROS
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to the type of an unsigned integer type of width exactly 64 bits if
+   such a type exists and the standard includes do not define it. */
+#undef uint64_t
+
+/* Define to the type of an unsigned integer type of width exactly 8 bits if
+   such a type exists and the standard includes do not define it. */
+#undef uint8_t
--- a/main/video/src/configure.ac	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/configure.ac	Thu Dec 20 17:42:26 2012 +0000
@@ -1,51 +1,40 @@
-dnl Process this file with autoconf to produce a configure script.
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
 
 AC_PREREQ([2.67])
 AC_INIT([Octave-Forge video package], [1.1.0+])
+AC_CONFIG_HEADERS([config.h])
 
+# Checks for programs.
 AC_PROG_CXX
 AC_LANG(C++)
 
+# Define macros needed for libav
+AC_DEFINE(__STDC_CONSTANT_MACROS, [], [workaround for C++ programs to use C99 macros])
+AC_DEFINE(VIDEO_OUTBUF_SIZE, [200000], [size of video buffer])
+
 AC_CHECK_PROG([HAVE_MKOCTFILE], [mkoctfile], [yes], [no])
 if [test $HAVE_MKOCTFILE = "no"]; then
   AC_MSG_ERROR([mkoctfile required to install $PACKAGE_NAME])
 fi
 
-dnl Check for ffmpeg
-AC_CHECK_PROG([FFMPEG_CONFIG], [pkg-config], [pkg-config])
-if test -z $FFMPEG_CONFIG ; then
-  AC_MSG_WARN([`pkg-config' not found -- using default configuration])
-  FFMPEG_FLAGS="-lavcodec -lavutil -lm"
-  echo $FFMPEG_FLAGS
-else
-  FFMPEG_FLAGS=`pkg-config libavformat libavcodec libavutil libswscale --libs --cflags`
-  echo $FFMPEG_FLAGS
-fi
+# Checks for libraries.
 
 AC_CHECK_LIB([avformat], [av_write_frame], [],
-             [AC_MSG_ERROR([$PACKAGE_NAME requires libavformat from FFmpeg])],
-             [$FFMPEG_FLAGS])
+             [AC_MSG_ERROR([$PACKAGE_NAME requires libavformat from FFmpeg])])
 AC_CHECK_LIB([avcodec], [av_malloc], [],
-             [AC_MSG_ERROR([$PACKAGE_NAME requires libavcodec from FFmpeg])],
-             [$FFMPEG_FLAGS])
+             [AC_MSG_ERROR([$PACKAGE_NAME requires libavcodec from FFmpeg])])
 AC_CHECK_LIB([swscale], [sws_scale], [],
-             [AC_MSG_ERROR([$PACKAGE_NAME requires libswscale from FFmpeg])],
-             [$FFMPEG_FLAGS])
+             [AC_MSG_ERROR([$PACKAGE_NAME requires libswscale from FFmpeg])])
+             
+# Checks for header files.
 
-OLD_CPPFLAGS=$CPPFLAGS
-CPPFLAGS="$CPPFLAGS $FFMPEG_FLAGS"
-FFMPEG_DEFS=
-AC_SUBST(FFMPEG_DEFS)
-AC_CHECK_HEADERS(ffmpeg/avformat.h,
-  FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_FFMPEG_AVFORMAT_H", [
-  AC_CHECK_HEADERS(libavformat/avformat.h, 
-    FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_LIBAVFORMAT_AVFORMAT_H",
-    AC_MSG_ERROR([FFMpeg header files not found]))])
-AC_CHECK_HEADERS(ffmpeg/avcodec.h, 
-  FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_FFMPEG_AVCODEC_H", [
-  AC_CHECK_HEADERS(libavcodec/avcodec.h, 
-    FFMPEG_DEFS="$FFMPEG_DEFS -DHAVE_LIBAVCODEC_AVCODEC_H",
-    AC_MSG_ERROR([FFMpeg header files not found]))])
+AC_CHECK_HEADERS([ffmpeg/avformat.h], [], [AC_CHECK_HEADERS([libavformat/avformat.h], [],
+  AC_MSG_ERROR([FFMpeg header avformat.h not found]))])
+
+AC_CHECK_HEADERS([ffmpeg/avcodec.h], [], [AC_CHECK_HEADERS([libavcodec/avcodec.h], [],
+  AC_MSG_ERROR([FFMpeg header avcodec.h not found]))])
+
 AC_CHECK_DECL(AVSEEK_FLAG_BACKWARD, [],
               AC_MSG_ERROR([need a newer version of FFMpeg]), [
 #if defined(HAVE_FFMPEG_AVFORMAT_H)
@@ -53,8 +42,23 @@
 #elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H)
 #include <libavformat/avformat.h>
 #endif])
-CPPFLAGS=$OLD_CPPFLAGS
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_CHECK_HEADER_STDBOOL
+AC_TYPE_UINT64_T
+AC_TYPE_UINT8_T
+
+# Checks for library functions.
+AC_FUNC_ERROR_AT_LINE
+AC_FUNC_MALLOC
 
 AC_CONFIG_FILES([Makefile])
-AC_SUBST([FFMPEG_CONFIG])
 AC_OUTPUT
+
+AC_MSG_NOTICE([
+
+$PACKAGE_NAME is now configured with
+
+   FFMPEG LIBS:       $LIBS
+   DEFS:              $DEFS
+])
--- a/main/video/src/oct-avifile.cc	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/oct-avifile.cc	Thu Dec 20 17:42:26 2012 +0000
@@ -22,6 +22,7 @@
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
+#include "config.h"
 #include <octave/oct.h>
 #include "oct-avifile.h"
 
@@ -126,7 +127,6 @@
 }
 
 Avifile::~Avifile(void) {
-    octave_stdout << "avifile: writing headers and closing " << filename << std::endl;
+    //octave_stdout << "avifile: writing headers and closing " << filename << std::endl;
     delete av;
 }
-
--- a/main/video/src/oct-avifile.h	Thu Dec 20 17:05:41 2012 +0000
+++ b/main/video/src/oct-avifile.h	Thu Dec 20 17:42:26 2012 +0000
@@ -60,5 +60,4 @@
   DECLARE_OCTAVE_ALLOCATOR
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };
-
 #endif