From 2b13dfbb4396e8e323915a1bfefe0d58cfaa4291 Mon Sep 17 00:00:00 2001
From: Amar Takhar <verm@aegisub.org>
Date: Tue, 28 Oct 2008 02:18:14 +0000
Subject: [PATCH] Add support for FFmpegSource2, it's enabled by default if
 libpostproc is there.

Originally committed to SVN as r2425.
---
 FFmpegSource2/Makefile.am | 31 +++++++++++++++++++++++++++++++
 Makefile.am               |  4 ++++
 aegisub/Makefile.am       | 12 ++++++++----
 aegisub/posix/defines.h   |  8 ++++++++
 configure.in              | 33 +++++++++++++++++++++++++++++----
 5 files changed, 80 insertions(+), 8 deletions(-)
 create mode 100644 FFmpegSource2/Makefile.am

diff --git a/FFmpegSource2/Makefile.am b/FFmpegSource2/Makefile.am
new file mode 100644
index 000000000..637506803
--- /dev/null
+++ b/FFmpegSource2/Makefile.am
@@ -0,0 +1,31 @@
+noinst_LIBRARIES = libffmpegsource2_aegisub.a
+
+AM_CPPFLAGS = -include ../aegisub/posix/defines.h -I../aegisub
+
+libffmpegsource2_aegisub_a_SOURCES = \
+	ffaudiosource.cpp \
+	ffms.cpp \
+	ffvideosource.cpp \
+	indexing.cpp \
+	MatroskaParser.c \
+	stdiostream.c \
+	utils.cpp \
+	wave64writer.cpp
+
+
+libffmpegsource2_aegisub_a_SOURCES += \
+	MatroskaParser.h \
+	avisynth.h \
+	ffaudiosource.h \
+	ffavisynth.h \
+	ffms.h \
+	ffpp.h \
+	ffswscale.h \
+	ffvideosource.h \
+	indexing.h \
+	stdiostream.h \
+	utils.h \
+	wave64writer.h
+
+EXTRA_DIST = \
+	ffms2.html
diff --git a/Makefile.am b/Makefile.am
index 208ff391d..4cbf59ebc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,11 +13,15 @@ if WITH_LIBASS
 libass = libass
 endif
 
+if HAVE_FFMPEGSOURCE
+ffmpegsource = FFmpegSource2
+endif
 
 SUBDIRS = \
 	$(univchardet) \
 	$(auto3) \
     $(libass) \
+	$(ffmpegsource) \
 	aegisub \
 	automation \
 	po \
diff --git a/aegisub/Makefile.am b/aegisub/Makefile.am
index 5b7a8c5ff..461620cdc 100644
--- a/aegisub/Makefile.am
+++ b/aegisub/Makefile.am
@@ -53,6 +53,13 @@ aegisub_LDFLAGS += @AVFORMAT_LDFLAGS@ @AVCODEC_LDFLAGS@ @SWSCALE_LDFLAGS@
 aegisub_LDADD += libaudiovideo_ffmpeg.a
 endif
 
+if HAVE_FFMPEGSOURCE
+noinst_LIBRARIES += libaudiovideo_ffmpegsource.a
+libaudiovideo_ffmpegsource_a_SOURCES = audio_provider_ffmpegsource.cpp video_provider_ffmpegsource.cpp ffmpegsource_common.cpp
+aegisub_LDFLAGS += @AVFORMAT_LDFLAGS@ @AVCODEC_LDFLAGS@ @SWSCALE_LDFLAGS@ @POSTPROC_LDFLAGS@
+aegisub_LDADD += libaudiovideo_ffmpegsource.a ../FFmpegSource2/libffmpegsource2_aegisub.a
+endif
+
 noinst_LIBRARIES += libsubtitle_provider.a
 libsubtitle_provider_a_SOURCES = subtitles_provider.cpp
 libsubtitle_provider_a_CPPFLAGS = @CSRI_CFLAGS@
@@ -144,7 +151,6 @@ EXTRA_aegisub_SOURCES = \
 	audio_player_pulse.cpp \
 	audio_provider_avs.cpp \
 	audio_provider_lavc.cpp \
-	audio_provider_ffmpegsource.cpp \
 	auto4_auto3.cpp \
 	auto4_lua.cpp \
 	auto4_lua_assfile.cpp \
@@ -155,7 +161,6 @@ EXTRA_aegisub_SOURCES = \
 	auto4_ruby_dialog.cpp \
 	avisynth_wrap.cpp \
 	dialog_associations.cpp \
-	ffmpegsource_common.cpp \
 	lavc_file.cpp \
 	lavc_keyframes.cpp \
 	macosx/bevelButton.cpp \
@@ -167,8 +172,7 @@ EXTRA_aegisub_SOURCES = \
 	subtitles_provider_libass.cpp \
 	video_provider_avs.cpp \
 	video_provider_dshow.cpp \
-	video_provider_lavc.cpp \
-	video_provider_ffmpegsource.cpp
+	video_provider_lavc.cpp
 
 
 aegisub_SOURCES = \
diff --git a/aegisub/posix/defines.h b/aegisub/posix/defines.h
index 69a55ff24..c5dbbed6f 100644
--- a/aegisub/posix/defines.h
+++ b/aegisub/posix/defines.h
@@ -18,6 +18,14 @@
 
 #include <stdwx.h>
 
+#ifdef WITH_FFMPEGSOURCE
+/* FIXME: For FFMPEGSource2, this needs to be fixed but should be
+          harmless for the rest of aegisub. */
+#define _snprintf snprintf
+#define _ftelli64 ftello
+#define _fseeki64 fseeko
+#endif
+
 // These shouldn't be needed any longer, if there are
 // any occurrences of __int64 replace them with long long.
 //typedef int64_t __int64;
diff --git a/configure.in b/configure.in
index d75e07592..3164c70e9 100644
--- a/configure.in
+++ b/configure.in
@@ -164,6 +164,13 @@ AC_C_CONST
 AC_C_INLINE
 AC_C_VOLATILE
 AC_CHECK_LIB([m], [main])
+
+AC_CHECK_FUNC([strlcpy], [
+	AC_DEFINE([HAVE_STRLCPY], [1], [strlcpy() exists in the c library.])
+], [])
+
+
+
 AC_LIBTOOL_DLOPEN_SELF
 AC_MSG_CHECKING([[whether preprocessor supports #pragma once]])
 AC_PREPROC_IFELSE(
@@ -420,9 +427,9 @@ fi
 
 
 
-#################
-# Video Providers
-#################
+#########################
+# Video / Audio Providers
+#########################
 
 AC_ARG_WITH(ffmpeg, [  --without-ffmpeg        build without FFMPEG video provider. (default: auto)], ffmpeg_disabled="(disabled)")
 
@@ -449,14 +456,30 @@ if test "$with_ffmpeg" != "no"; then
   fi
 fi
 
-
 AC_SUBST(SWSCALE_LDFLAGS)
 AC_SUBST(AVCODEC_LDFLAGS)
 AC_SUBST(AVFORMAT_LDFLAGS)
 AC_SUBST(AVUTIL_LDFLAGS)
+
 AM_CONDITIONAL([HAVE_FFMPEG], [test "$with_ffmpeg" = "yes"])
 
 
+AC_ARG_WITH(ffmpegsource, [  --without-ffmpegsource        build without FFmpegSource video provider. (default: auto)], ffmpegsource_disabled="(disabled)")
+
+if test "$with_ffmpegsource" != "no"; then
+  AC_CHECK_LIB([postproc], [pp_postprocess],[POSTPROC_LDFLAGS="-lpostproc"; with_postproc="yes"], [with_postproc="no"])
+
+  if test "$with_postproc" = "yes"; then
+    found_video_provider="yes"
+    with_ffmpegsource="yes"
+    AC_DEFINE(WITH_FFMPEGSOURCE, 1, [Enable FFmpegSource2 Video Provider])
+  fi
+fi
+
+AC_SUBST(POSTPROC_LDFLAGS)
+
+AM_CONDITIONAL([HAVE_FFMPEGSOURCE], [test "$with_ffmpegsource" = "yes"])
+
 
 
 ###################
@@ -856,6 +879,7 @@ aegisub/Makefile
 aegisub/bitmaps/Makefile
 aegisub/posix/Makefile
 universalchardet/Makefile
+FFmpegSource2/Makefile
 auto3/Makefile
 libass/Makefile
 automation/Makefile
@@ -914,6 +938,7 @@ Audio Players:
 
 Video Providers
   ffmpeg:                $with_ffmpeg $ffmpeg_disabled
+  ffmpegsource:          $with_ffmpegsource $ffmpegsource_disabled
 
 Subtitle Providers:
   csri (asa):            $with_csri (requires iconv, fontconfig) $csri_disabled
-- 
GitLab