diff --git a/Makefile.am b/Makefile.am index f02b5283..c940954c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,6 @@ # https://www.gnu.org/licenses/lgpl-3.0.en.html # Remember to update ocnfigure.ac when we re-enable doc -#SUBDIRS = src man plugins python specfiles tests doc doc/latex_manuals $(BE_VIEWER_DIR) SUBDIRS = src src/tests man python specfiles tests diff --git a/plugins/AUTHORS b/plugins/AUTHORS deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/ChangeLog b/plugins/ChangeLog deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/INSTALL b/plugins/INSTALL deleted file mode 100644 index 007e9396..00000000 --- a/plugins/INSTALL +++ /dev/null @@ -1,370 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, -Inc. - - Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. This file is offered as-is, -without warranty of any kind. - -Basic Installation -================== - - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for -instructions specific to this package. Some packages provide this -`INSTALL' file but do not implement all of the features documented -below. The lack of an optional feature in a given package is not -necessarily a bug. More recommendations for GNU packages can be found -in *note Makefile Conventions: (standards)Makefile Conventions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. - - The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package, generally using the just-built uninstalled binaries. - - 4. Type `make install' to install the programs and any data files and - documentation. When installing into a prefix owned by root, it is - recommended that the package be configured and built as a regular - user, and only the `make install' phase executed with root - privileges. - - 5. Optionally, type `make installcheck' to repeat any self-tests, but - this time using the binaries in their final installed location. - This target does not install anything. Running this target as a - regular user, particularly if the prior `make install' required - root privileges, verifies that the installation completed - correctly. - - 6. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 7. Often, you can also type `make uninstall' to remove the installed - files again. In practice, not all packages have tested that - uninstallation works correctly, even though it is required by the - GNU Coding Standards. - - 8. Some packages, particularly those that use Automake, provide `make - distcheck', which can by used by developers to test that all other - targets like `make install' and `make uninstall' work correctly. - This target is generally not run by end users. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. This -is known as a "VPATH" build. - - With a non-GNU `make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before -reconfiguring for another architecture. - - On MacOS X 10.5 and later systems, you can create libraries and -executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like -this: - - ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CPP="gcc -E" CXXCPP="g++ -E" - - This is not guaranteed to produce working output in all cases, you -may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. - -Installation Names -================== - - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX', where PREFIX must be an -absolute file name. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the -default for these options is expressed in terms of `${prefix}', so that -specifying just `--prefix' will affect all of the other directory -specifications that were not explicitly provided. - - The most portable way to affect installation locations is to pass the -correct locations to `configure'; however, many packages provide one or -both of the following shortcuts of passing variable assignments to the -`make install' command line to change installation locations without -having to reconfigure or recompile. - - The first method involves providing an override variable for each -affected directory. For example, `make install -prefix=/alternate/directory' will choose an alternate location for all -directory configuration variables that were expressed in terms of -`${prefix}'. Any directories that were specified during `configure', -but not in terms of `${prefix}', must each be overridden at install -time for the entire installation to be relocated. The approach of -makefile variable overrides for each directory variable is required by -the GNU Coding Standards, and ideally causes no recompilation. -However, some platforms have known limitations with the semantics of -shared libraries that end up requiring recompilation when using this -method, particularly noticeable in packages that use GNU Libtool. - - The second method involves providing the `DESTDIR' variable. For -example, `make install DESTDIR=/alternate/directory' will prepend -`/alternate/directory' before all installation names. The approach of -`DESTDIR' overrides is not required by the GNU Coding Standards, and -does not work on platforms that have drive letters. On the other hand, -it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of `${prefix}' -at `configure' time. - -Optional Features -================= - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - - Some packages offer the ability to configure how verbose the -execution of `make' will be. For these packages, running `./configure ---enable-silent-rules' sets the default to minimal output, which can be -overridden with `make V=1'; while running `./configure ---disable-silent-rules' sets the default to verbose, which can be -overridden with `make V=0'. - -Particular systems -================== - - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in -order to use an ANSI C compiler: - - ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" - -and if that doesn't work, install pre-built binaries of GCC for HP-UX. - - HP-UX `make' updates targets which have the same time stamps as -their prerequisites, which makes it generally unusable when shipped -generated files such as `configure' are involved. Use GNU `make' -instead. - - On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try - - ./configure CC="cc" - -and if that doesn't work, try - - ./configure CC="cc -nodtk" - - On Solaris, don't put `/usr/ucb' early in your `PATH'. This -directory contains several dysfunctional programs; working variants of -these programs are available in `/usr/bin'. So, if you need `/usr/ucb' -in your `PATH', put it _after_ `/usr/bin'. - - On Haiku, software installed for all users goes in `/boot/common', -not `/usr/local'. It is recommended to use the following options: - - ./configure --prefix=/boot/common - -Specifying the System Type -========================== - - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS - KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf limitation. Until the limitation is lifted, you can use -this workaround: - - CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash - -`configure' Invocation -====================== - - `configure' recognizes the following options to control how it -operates. - -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. - -`--help=short' -`--help=recursive' - Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. - -`--no-create' -`-n' - Run the configure checks, but stop before creating any output - files. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. diff --git a/plugins/Makefile.am b/plugins/Makefile.am deleted file mode 100644 index 647cf9dc..00000000 --- a/plugins/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -# -# make bulk_extractor plugins -# stand - -AM_CPPFLAGS = -I.. -I../src -I../src/be13_api -I$(top_srcdir)/src/be13_api - -bin_PROGRAMS = plugin_test - -plugin_test_SOURCES = plugin_test.cpp - -EXTRA_DIST = scan_demo.cpp scan_flexdemo.flex be13_api - -# lib_LTLIBRARIES = scan_demo.so scan_flexdemo.so - - -plugins: - $(MAKE) scan_demo.so scan_flexdemo.so - @echo "Available Plugins:" - ls -l *.so - -# scan_demo_so_SOURCES = scan_demo.cpp -# scan_demo_dll_SOURCES = scan_demo.cpp -# scan_flexdemo_so_SOURCES = scan_flexdemo.cpp -# scan_flexdemo_dll_SOURCES = scan_flexdemo.cpp - -scan_demo.so: scan_demo.cpp -scan_flexdemo.so: scan_flexdemo.flex - -scan_demo.dll: scan_demo.cpp -scan_flexdemo.dll: scan_flexdemo.flex - -# -# Rule to compile .flex into a .o -# -# Note: Not clear if we should be using $(CXX) or $(CXXCOMPILE) below - -CLEANFILES=scan_demo.d scan_demo.o scan_demo.so \ - sscan_flexdemo.d can_flexdemo.cpp scan_flexdemo.o scan_flexdemo.so - -SUFFIXES = .so .flex -.cpp.so: - $(CXX) -shared -fPIC -o $@ $(CXXFLAGS) $(AM_CPPFLAGS) $< - -FLEX_CXXFLAGS=-Wno-shadow -Wno-effc++ -Wno-redundant-decls -Wno-missing-noreturn -.flex.so: - flex -o `basename $@ .so`.cpp $< - $(CXX) $(FLEX_CXXFLAGS) -shared -fPIC $(CXXFLAGS) $(AM_CPPFLAGS) -o $@ `basename $@ .so`.cpp diff --git a/plugins/NEWS b/plugins/NEWS deleted file mode 100644 index 899dc06c..00000000 --- a/plugins/NEWS +++ /dev/null @@ -1 +0,0 @@ -plugin news NEWS diff --git a/plugins/README b/plugins/README deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/README_PLUGINS.txt b/plugins/README_PLUGINS.txt deleted file mode 100644 index 4aac4c1d..00000000 --- a/plugins/README_PLUGINS.txt +++ /dev/null @@ -1,51 +0,0 @@ -This directory contains: - -1 - plugin_test.cpp --- a stand-alone tester for bulk_extractor plugins. - -2 - scan_demo.cpp --- a demonstration plugin - -3 - scan_flexdemo.flex --- a demonstration plugin written in GNU Flex - - -This directory should not be built as part of the standard -bulk_extractor release. - - -bulk_extractor scanner plugins are implemented as shared libraries -that begin with the name "scan_". For example, the demo plug-in that -counts the number of blank sectors and prints a report of the -percentage of the disk that is blank is called scan_blank.so on -Linux/Mac and scan_blank.DLL on Windows. - -When bulk_extractor starts up it examines the plugins directory for -all of the shared libraries whose name begins "scan_". Each one is -loaded into the address space. The plugin interface is a single C++ -function with the same name as the shared library. The plugin must be -compiled with C linkage, rather than C++ linkage, to avoid name -mangling issues. For example: - - - extern "C" - void scan_bulk(const class scanner_params &sp, - const class recursion_control_block &rcb); - - -The plugin takes two arguments, both of which are references to C++ -objects. The first class provides the scanner parameters. This -includes a "phase" instance variable that denotes whether the scanner -is called to start-up, examine a block of data, or shut down. The -second is the recursion control block, which provides information for -use by recursive scanners (e.g. scanners that perform some kind of -transformation on the data and then request re-analysis). - -The file bulk_extractor_i.h contains the bulk_extractor plug-in -interface. It is the only file that needs to be included for -plugins. By design this file contains the minimum necessary for a -functional plug-in. This approach minimizes possible interactions -between the bulk_extractor system and the plugin system. - -For complete information, please refer to The bulk_extractor plugin -developer's manual, which you can download from: - - http://digitalcorpora.org/downloads/bulk_extractor/BEProgrammersManual.pdf - diff --git a/plugins/WHY_ARE_THERE_SYMLINKS_HERE.md b/plugins/WHY_ARE_THERE_SYMLINKS_HERE.md deleted file mode 100644 index a16e5334..00000000 --- a/plugins/WHY_ARE_THERE_SYMLINKS_HERE.md +++ /dev/null @@ -1,2 +0,0 @@ -Please leave the symlinks in this directory. They are currently needed -to build the windows executable with mingw. diff --git a/plugins/bootstrap.sh b/plugins/bootstrap.sh deleted file mode 100644 index c8e8e7d1..00000000 --- a/plugins/bootstrap.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# build the makefiles -autoheader -f -aclocal -I m4 -autoconf -f -automake --add-missing --copy -echo be sure to run ./configure diff --git a/plugins/configure.ac b/plugins/configure.ac deleted file mode 100644 index 2b30581a..00000000 --- a/plugins/configure.ac +++ /dev/null @@ -1,355 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. -# Order is largely irrevellant, although it must start with AC_INIT and end with AC_OUTPUT -# See http://autotoolset.sourceforge.net/tutorial.html -# and http://www.openismus.com/documents/linux/automake/automake.shtml - -AC_PREREQ(2.57) - -AC_INIT(BE_PLUGIN_TESTER, 1.4, bugs@digitalcorpora.org) -AC_CONFIG_MACRO_DIR(m4) - -AC_CONFIG_FILES([Makefile]) -AC_CONFIG_HEADER([config.h]) -AM_INIT_AUTOMAKE -AM_MAINTAINER_MODE -AC_PREFIX_PROGRAM -AC_PROG_CC -AC_PROG_CXX -AC_PROG_INSTALL -AC_PROG_LEX - -## -## Standard macros -## -AC_TYPE_INT64_T -AC_SYS_LARGEFILE -AC_SYS_POSIX_TERMIOS -AC_HEADER_STDC - - -if test "$LEX" != flex; then - AC_MSG_ERROR([flex not installed; required for compiling regular expressions. Try 'apt-get install flex' or 'yum install flex' or 'port install flex' or whatever package manager you happen to be using....]) -fi - -################################################################ -## See if we are running on mingw -# http://osdir.com/ml/gnu.mingw.devel/2003-09/msg00040.html -# Note: Windows 95 WINVER=0x400 -# Windows 98 WINVER=0x400 _WIN32_WINDOWS=0x0410 -# Windows Me WINVER=0x400 _WIN32_WINDOWS=0x0490 -# Windows NT 4.0 WINVER=0x0400 _WIN32_WINNT=0x0400 -# Windows NT 4.0 SP3 WINVER=0x0400 _WIN32_WINNT=0x0403 -# Windows 2000 WINVER=0x500 _WIN32_WINNT=0x0500 -# Windows XP WINVER=0x501 _WIN32_WINNT=0x0501 -# Windows Server 2003 WINVER=0x502 _WIN32_WINNT=0x0502 -# -# mingw32 includes i686-w64-mingw32 and x86_64-w64-mingw32 - -mingw="no" -case $host in - *-*-*linux*-*) - AC_DEFINE([__LINUX__],1,[Linux operating system functions]) - ;; - - *-*-mingw32*) - LIBS="-lpsapi -lws2_32 -lgdi32 $LIBS" # previously had -liberty - CPPFLAGS="-DUNICODE -D_UNICODE -D__MSVCRT_VERSION__=0x0601 -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -g $CPPFLAGS" - # Removed: -DHAVE_STRUCT_TIMESPEC - CXXFLAGS="$CXXFLAGS -Wno-format " # compiler mingw-4.3.0 is broken on I64u formats - CFLAGS="$CFLAGS --static" - CPPFLAGS="$CPPFLAGS --static" - CXXFLAGS="$CXXFLAGS --static" - LDFLAGS="$LDFLAGS --static" - # Removed - # LDFLAGS="$LDFLAGS -shared-libgcc" # allows exiv2 to throw an exception that's caught elsewhere - mingw="yes" - ;; -esac - -if test x"${mingw}" == "xno" ; then - # Bring additional directories where things might be found into our - # search path. I don't know why autoconf doesn't do this by default - for spfx in /usr/local /opt/local /sw /usr/local/ssl; do - AC_MSG_NOTICE([checking ${spfx}/include]) - if test -d ${spfx}/include; then - CPPFLAGS="-I${spfx}/include $CPPFLAGS" - LDFLAGS="-L${spfx}/lib $LDFLAGS" - AC_MSG_NOTICE([ *** ADDING ${spfx}/include to CPPFLAGS *** ]) - AC_MSG_NOTICE([ *** ADDING ${spfx}/lib to LDFLAGS *** ]) - fi - done - AC_MSG_NOTICE([ CPPFLAGS = ${CPPFLAGS} ]) - AC_MSG_NOTICE([ LDFLAGS = ${LDFLAGS} ]) -fi - -if test -r /bin/uname.exe ; then - if test `uname -o` == "Msys" ; then - AC_MSG_NOTICE([Compiling with Msys. Setting flags appropriately.]) - LIBS="$LIBS -lws2_32 -lgdi32" - LDFLAGS="$LDFLAGS -Wl,--enable-auto-import" - fi -fi -################################################################ -# -# Enable all the compiler debugging we can find -# -# This is originally from PhotoRec, but modified substantially by Simson -# Figure out which flags we can use with the compiler. -# -# These I don't like: -# -Wdeclaration-after-statement -Wconversion -# doesn't work: -Wunreachable-code -# causes configure to crash on gcc-4.2.1: -Wsign-compare-Winline -# causes warnings with unistd.h: -Wnested-externs -# Just causes too much annoyance: -Wmissing-format-attribute - -# Check GCC -WARNINGS_TO_TEST="-MD -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes \ - -Wshadow -Wwrite-strings -Wcast-align -Waggregate-return \ - -Wbad-function-cast -Wcast-qual -Wundef -Wredundant-decls -Wdisabled-optimization \ - -Wfloat-equal -Wmultichar -Wc++-compat -Wmissing-noreturn -funit-at-a-time " - -if test x"${mingw}" == "xno" ; then - # add the warnings we do not want to do on mingw - WARNINGS_TO_TEST="$WARNINGS_TO_TEST -Wall -Wstrict-prototypes" -fi - -echo "Warnings to test: $WARNINGS_TO_TEST" - -for option in $WARNINGS_TO_TEST -do - SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $option" - AC_MSG_CHECKING([whether gcc understands $option]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [has_option=yes], - [has_option=no; CFLAGS="$SAVE_CFLAGS"]) - AC_MSG_RESULT($has_option) - unset has_option - unset SAVE_CFLAGS - if test $option = "-Wmissing-format-attribute" ; then - AC_DEFINE(HAVE_MISSING_FORMAT_ATTRIBUTE_WARNING,1, - [Indicates that we have the -Wmissing-format-attribute G++ warning]) - fi -done -unset option - -################################################################ -## mcheck support -## enable memory analysis support for detecting memory leaks -## and detecting multiply deallocated memory resources -## see http://en.wikipedia.org/wiki/Mtrace -## here is the basic workflow: -## 1. example usage and recompile: "./configure --enable-mcheck" -## 2. export the environment variable for the output file, -## e.g. "export MALLOC_TRACE=~/malloc_outfile.txt" -## 3. improve readability of malloc_outfile.txt using mtrace, -## e.g. "mtrace /usr/local/bin/bulk_extractor ~/malloc_outfile.txt -AC_ARG_ENABLE([mcheck], AS_HELP_STRING([--enable-mcheck], - [enable memory analysis support for detecting memory leaks and detecting multiply deallocated memory resources]), - AC_DEFINE(HAVE_MCHECK, 1, - [define the output file using global variable MALLOC_TRACE, - for example "MALLOC_TRACE=./mcheck.out; export MALLOC_TRACE". - Then post-process unreadable file mcheck.out using the mtrace command line tool, - for example "mtrace /usr/local/bin/bulk_extractor mcheck.out". - Unfortunately, only addresses with written code are looked up, - in otherwords, use of malloc is looked up, but use of new is not.])) - - -################################################################ -# Check G++ -# We don't use these warnings: -# -Waggregate-return -- aggregate returns are GOOD; they simplify code design -# We can use these warnings after ZLIB gets upgraded: -# -Wundef --- causes problems with zlib -# -Wcast-qual -# -Wmissing-format-attribute --- Just too annoying -AC_LANG_PUSH(C++) -CXX_WARNINGS_TO_TEST="-Wall -MD -Wpointer-arith \ - -Wshadow -Wwrite-strings -Wcast-align \ - -Wredundant-decls -Wdisabled-optimization \ - -Wfloat-equal -Wmultichar -Wmissing-noreturn \ - -Woverloaded-virtual -Wsign-promo -funit-at-a-time" - -if test x$CXX != "xclang++" && x`uname` != `Darwin` ; then - # -Wstrict-null-sentinel is not supported under clang or Darwin g++ - CXX_WARNINGS_TO_TEST="$CXX_WARNINGS_TO_TEST -Wstrict-null-sentinel" -fi - -if test x"${mingw}" == "xno" ; then - # add the warnings we don't want to do on mingw - CXX_WARNINGS_TO_TEST="$CXX_WARNINGS_TO_TEST -Weffc++" -fi - -for option in $CXX_WARNINGS_TO_TEST -do - SAVE_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $option" - AC_MSG_CHECKING([whether g++ understands $option]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], - [has_option=yes], - [has_option=no; CXXFLAGS="$SAVE_CXXFLAGS"]) - AC_MSG_RESULT($has_option) - unset has_option - unset SAVE_CXXFLAGS -done -unset option -AC_LANG_POP() - -# Determine UTC date offset -CPPFLAGS="$CPPFLAGS -DUTC_OFFSET=`date +%z`" - - -################################################################ -# DFXML support -m4_include([dfxml_cpp/src/dfxml_configure.m4]) - -################################################################ -# BE13_API -m4_include([be13_api/be13_configure.m4]) - -################################################################ -# PTHREAD support -# With special nods to compiling under mingw - -if test x"$mingw" = x"yes"; then - #AC_DEFINE([HAVE_STRUCT_TIMESPEC],1,[Required for mingw]) - CFLAGS="$CFLAGS -mthreads " - CPPFLAGS="-DPTW32_STATIC_LIB $CPPFLAGS" - CXXFLAGS="$CXXFLAGS -mthreads " - AC_DEFINE(HAVE_PTHREAD,1,[Defined to POSIX threads for mingw]) -else - m4_include([m4/ax_pthread.m4]) - AX_PTHREAD([ - [echo Using settings from AX_PTHREAD] - LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS=" $PTHREAD_CFLAGS $CFLAGS" - CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS " - CPPFLAGS="$PTHREAD_CFLAGS $CPPFLAGS " - CC="$PTHREAD_CC" - ]) -fi - -AC_CHECK_HEADERS([pthread.h]) -AC_CHECK_LIB([pthreadGC2],[pthread_create]) - -################################################################ -## -## Multithreading stuff - -# On mingw, be sure to use the static version and be sure we are using mthread option -# (which should be a no-op on later version of G++ anyway) - -AC_CHECK_FUNCS([pthread_win32_process_attach_np pthread_win32_process_detach_np pthread_win32_thread_attach_np pthread_win32_thread_detach_np ]) - -AC_MSG_CHECKING([for __sync_fetch_and_add]) -AC_LINK_IFELSE( - [AC_LANG_SOURCE([ - int main(void) { int i; return __sync_fetch_and_add(&i, 0); } - ])], - [ - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE___SYNC_FETCH_AND_ADD,1,[Defined if __sync_fetch_and_add was detected]) - ], - [AC_MSG_RESULT([no])] -) - -# end PTHREAD SUPPORT -################################################################ - -# Specific include files and functions for bulk-extractor - -## Check for headers used by bulk Extractor -## do not put pthread here -AC_CHECK_HEADERS([alloca.h dirent.h dlfcn.h err.h errno.h fcntl.h inttypes.h libgen.h limits.h malloc.h mmap.h pwd.h signal.h stdarg.h stdint.h stdio.h strings.h string.h stdlib.h sys/cdefs.h sys/disk.h sys/fcntl.h sys/ioctl.h sys/mman.h sys/mmap.h sys/mount.h sys/param.h sys/stat.h sys/types.h sys/time.h sys/resource.h sys/sysctl.h time.h unistd.h windows.h CoreServices/CoreServices.h]) -AC_CHECK_FUNCS([err errx getuid getpwuid gethostname getrusage gmtime_r isxdigit ishexnumber le64toh localtime_r _lseeki64 inet_ntop pread64 pread printf mmap munmap MD5 mkstemp mktemp sleep SleepEx strptime usleep vasprintf warn warnx]) -AC_CHECK_FUNCS([CreateProcess LoadLibrary IncrementAtomic InterlockedIncrement]) - -## dlopen is now itself in a different library -## Explicitly check for dlopen library before checking for dlopen -## -ldl (see http://stackoverflow.com/questions/956640/linux-c-error-undefined-reference-to-dlopen) -AC_CHECK_LIB([dl],[dlopen]) -AC_CHECK_FUNCS([dlopen dlopen_preflight]) - -## Look for a regular expression system to use -## tre is better than regex - -AC_CHECK_HEADER([tre/tre.h]) -AC_CHECK_LIB([tre],[tre_have_approx]) -AC_CHECK_FUNCS([tre_have_approx]) - -AC_CHECK_HEADER([regex.h]) -AC_CHECK_LIB([regex],[regexec]) dnl sometimes its in a library -AC_CHECK_FUNCS([regcomp]) - -# Test for sin_len -AC_CHECK_HEADERS([arpa/inet.h netinet/in.h netinet/ip.h wsipx.h]) -AC_CHECK_MEMBER([struct sockaddr_in.sin_len], - [AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr.sin_len?])], - [], - [ -#include -#include -#ifdef HAVE_NETINET_IN_H -#include -#endif - ]) - -# Should we disable optimization? -AC_ARG_WITH([opt], AC_HELP_STRING([--without-opt], [Drop all -O C flags])) -# Or maybe just tone it down a bit? -AC_ARG_WITH([o3], AC_HELP_STRING([--without-o3], [Do not force O3 optimization; use default level])) - -# ZLIB is required: -# Not you cannot put comments in the AC_MSG_ERROR for some reason -AC_CHECK_LIB([z],[uncompress],, - AC_MSG_ERROR([zlib libraries not installed; try installing zlib-dev zlib-devel zlib1g-dev or libz-dev])) - -################################################################ -AC_TRY_COMPILE([#pragma GCC diagnostic ignored "-Wshadow"],[int a=3;], - [AC_DEFINE(GNUC_HAS_DIAGNOSTIC_PRAGMA,1,[define 1 if GCC supports #pragma GCC diagnostic])] -) - -################################################################ -############## drop optimization flags and add -g if requested ################ -if test x"${AFF_NOOPT}" != "x" ; then - with_noopt="yes"; -fi - -if test "${with_opt}" = "no" ; then - CFLAGS=`echo -g "$CFLAGS" | sed s/-O[[0-9]]//` # note the double quoting! - CXXFLAGS=`echo -g "$CXXFLAGS" | sed s/-O[[0-9]]//` -else - # If we are not stripping the optimizer, add fortify source - CFLAGS=" $CFLAGS -D_FORTIFY_SOURCE=2 " - CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 " - - # and increase optimizer from -O2 to -O3 if not explicitly forbidden - if test "${with_o3}" != "no" ; then - CFLAGS=`echo -g "$CFLAGS" | sed s/-O2/-O3/` # note the double quoting! - CXXFLAGS=`echo -g "$CXXFLAGS" | sed s/-O2/-O3/` - fi -fi - - -AC_MSG_NOTICE([*************************************]) -AC_MSG_NOTICE([*************************************]) -AC_MSG_NOTICE([ PACKAGE_NAME: $PACKAGE_NAME]) -AC_MSG_NOTICE([ PACKAGE_VERSION: $PACKAGE_VERSION]) -AC_MSG_NOTICE([ CC: $CC]) -AC_MSG_NOTICE([ CXX: $CXX]) -AC_MSG_NOTICE([ CPPFLAGS: $CPPFLAGS]) -AC_MSG_NOTICE([ CFLAGS: $CFLAGS]) -AC_MSG_NOTICE([ CXXFLAGS: $CXXFLAGS]) -AC_MSG_NOTICE([ LIBS: $LIBS]) -AC_MSG_NOTICE([ LDFLAGS: $LDFLAGS]) - -AC_OUTPUT - -## Finally, record the values of CFLAGS, CPPFLAGS, and CXXFLAGS for DFXML -echo "#define CPPFLAGS \"$CPPFLAGS\"" >> config.h -echo "#define CFLAGS \"$CFLAGS\"" >> config.h -echo "#define CXXFLAGS \"$CXXFLAGS\"" >> config.h -echo "#define LIBS \"$LIBS\"" >> config.h -echo "#define LDFLAGS \"$LDFLAGS\"" >> config.h diff --git a/plugins/m4/ax_pthread.m4 b/plugins/m4/ax_pthread.m4 deleted file mode 100644 index a6bf596c..00000000 --- a/plugins/m4/ax_pthread.m4 +++ /dev/null @@ -1,302 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_pthread.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -# -# DESCRIPTION -# -# This macro figures out how to build C programs using POSIX threads. It -# sets the PTHREAD_LIBS output variable to the threads library and linker -# flags, and the PTHREAD_CFLAGS output variable to any special C compiler -# flags that are needed. (The user can also force certain compiler -# flags/libs to be tested by setting these environment variables.) -# -# Also sets PTHREAD_CC to any special C compiler that is needed for -# multi-threaded programs (defaults to the value of CC otherwise). (This -# is necessary on AIX to use the special cc_r compiler alias.) -# -# NOTE: You are assumed to not only compile your program with these flags, -# but also link it with them as well. e.g. you should link with -# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# -# If you are only building threads programs, you may wish to use these -# variables in your default LIBS, CFLAGS, and CC: -# -# LIBS="$PTHREAD_LIBS $LIBS" -# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -# CC="$PTHREAD_CC" -# -# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant -# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name -# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -# -# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the -# PTHREAD_PRIO_INHERIT symbol is defined when compiling with -# PTHREAD_CFLAGS. -# -# ACTION-IF-FOUND is a list of shell commands to run if a threads library -# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it -# is not found. If ACTION-IF-FOUND is not specified, the default action -# will define HAVE_PTHREAD. -# -# Please let the authors know if this macro fails on any platform, or if -# you have any other suggestions or comments. This macro was based on work -# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help -# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by -# Alejandro Forero Cuervo to the autoconf macro repository. We are also -# grateful for the helpful feedback of numerous users. -# -# Updated for Autoconf 2.68 by Daniel Richard G. -# -# LICENSE -# -# Copyright (c) 2008 Steven G. Johnson -# Copyright (c) 2011 Daniel Richard G. -# -# 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 3 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, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 16 - -AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) -AC_DEFUN([AX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -AC_LANG_PUSH([C]) -ax_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) - AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) - AC_MSG_RESULT($ax_pthread_ok) - if test x"$ax_pthread_ok" = xno; then - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" - fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. - -ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# ... -mt is also the pthreads flag for HP/aCC -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -case "${host_cpu}-${host_os}" in - *solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthreads/-mt/ - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: - - ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" - ;; - - *-darwin*) - ax_pthread_flags="-pthread $ax_pthread_flags" - ;; -esac - -if test x"$ax_pthread_ok" = xno; then -for flag in $ax_pthread_flags; do - - case $flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $flag]) - PTHREAD_CFLAGS="$flag" - ;; - - pthread-config) - AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) - if test x"$ax_pthread_config" = xno; then continue; fi - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$flag]) - PTHREAD_LIBS="-l$flag" - ;; - esac - - save_LIBS="$LIBS" - save_CFLAGS="$CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include - static void routine(void *a) { a = 0; } - static void *start_routine(void *a) { return a; }], - [pthread_t th; pthread_attr_t attr; - pthread_create(&th, 0, start_routine, 0); - pthread_join(th, 0); - pthread_attr_init(&attr); - pthread_cleanup_push(routine, 0); - pthread_cleanup_pop(0) /* ; */])], - [ax_pthread_ok=yes], - []) - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - AC_MSG_RESULT($ax_pthread_ok) - if test "x$ax_pthread_ok" = xyes; then - break; - fi - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi - -# Various other checks: -if test "x$ax_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - - # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. - AC_MSG_CHECKING([for joinable pthread attribute]) - attr_name=unknown - for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], - [int attr = $attr; return attr /* ; */])], - [attr_name=$attr; break], - []) - done - AC_MSG_RESULT($attr_name) - if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then - AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - fi - - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" - fi - - AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], - ax_cv_PTHREAD_PRIO_INHERIT, [ - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([[#include ]], [[int i = PTHREAD_PRIO_INHERIT;]])], - [ax_cv_PTHREAD_PRIO_INHERIT=yes], - [ax_cv_PTHREAD_PRIO_INHERIT=no]) - ]) - AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"], - AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.])) - - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" - - # More AIX lossage: must compile with xlc_r or cc_r - if test x"$GCC" != xyes; then - AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) - else - PTHREAD_CC=$CC - fi -else - PTHREAD_CC="$CC" -fi - -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CFLAGS) -AC_SUBST(PTHREAD_CC) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$ax_pthread_ok" = xyes; then - ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) - : -else - ax_pthread_ok=no - $2 -fi -AC_LANG_POP -])dnl AX_PTHREAD diff --git a/plugins/plugin_test.cpp b/plugins/plugin_test.cpp deleted file mode 100644 index f7a93203..00000000 --- a/plugins/plugin_test.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/** - * plugin_test.cpp: - * - * This program will load a bulk_extractor .so or .dll plug-in and - * perform a rudimentary test. - */ - - -#include "config.h" // from ../config.h -//#include "be13_api/bulk_extractor_i.h" // from ../src/be13_api/bulk_extractor_i.h -//#include "be13_api/beregex.cpp" - -#include -#include -#include - -#include - -#ifdef HAVE_DLFCN_H -#include -#endif - -#ifdef HAVE_WINDOWS_H -#include -typedef int (__cdecl *MYPROC)(LPWSTR); -#endif - -#if 0 - - -static std::string hash_name("md5"); -static std::string hash_func(const uint8_t *buf,size_t bufsize) -{ - if(hash_name=="md5" || hash_name=="MD5"){ - return md5_generator::hash_buf(buf,bufsize).hexdigest(); - } - if(hash_name=="sha1" || hash_name=="SHA1" || hash_name=="sha-1" || hash_name=="SHA-1"){ - return sha1_generator::hash_buf(buf,bufsize).hexdigest(); - } - if(hash_name=="sha256" || hash_name=="SHA256" || hash_name=="sha-256" || hash_name=="SHA-256"){ - return sha256_generator::hash_buf(buf,bufsize).hexdigest(); - } - std::cerr << "Invalid hash name: " << hash_name << "\n"; - std::cerr << "This version of bulk_extractor only supports MD5, SHA1, and SHA256\n"; - exit(1); -} -static feature_recorder_set::hash_def my_hasher(hash_name,hash_func); - -scanner_params::PrintOptions scanner_params::no_options; -#endif - -int main(int argc,char **argv) -{ - if(argc!=2){ - fprintf(stderr,"usage: %s scanner.so\n",argv[0]); - fprintf(stderr,"type 'make plugins' to make available plugins\n"); - exit(1); - } - -#if 0 - /* Strip extension and path */ - std::string fname = argv[1]; - scanner_t *fn=0; - std::string name = fname; - size_t dot = name.rfind('.'); - if(dot==std::string::npos){ - fprintf(stderr,"%s: cannot strip extension\n",name.c_str()); - exit(1); - } - name = name.substr(0,dot); - - /* Strip dir */ - size_t slash = name.rfind('.'); - if(slash!=std::string::npos){ - name = name.substr(slash+1); - } - -#ifdef HAVE_DLOPEN - if(fname.find('.')==std::string::npos){ - fname = "./" + fname; // fedora requires a complete path name - } - -#ifdef HAVE_DLOPEN_PREFLIGHT - if(!dlopen_preflight(fname.c_str())){ - fprintf(stderr,"dlopen_preflight - cannot open %s: %s",fname.c_str(),dlerror()); - exit(1); - } -#endif - - void *lib=dlopen(fname.c_str(), RTLD_LAZY); - if(lib==0){ - fprintf(stderr,"fname=%s\n",fname.c_str()); - fprintf(stderr,"dlopen: %s\n",dlerror()); - exit(1); - } - - fn=(scanner_t *)dlsym(lib, name.c_str()); - if(fn==0){ - fprintf(stderr,"dlsym: %s\n",dlerror()); - exit(1); - } - -#endif -#ifdef HAVE_LOADLIBRARY - /* Use Win32 LoadLibrary function */ - /* See http://msdn.microsoft.com/en-us/library/ms686944(v=vs.85).aspx */ - HINSTANCE hinstLib = LoadLibrary(TEXT(fname.c_str())); - if(hinstLib==0){ - fprintf(stderr,"LoadLibrary(%s) failed",fname.c_str()); - exit(1); - } - MYPROC fn = (MYPROC)GetProcAddress(hinstLib,name.c_str()); - if(fn==0){ - fprintf(stderr,"GetProcAddress(%s) failed",name.c_str()); - exit(1); - } -#endif - - feature_recorder_set fs(0,my_hasher,feature_recorder_set::NO_INPUT,feature_recorder_set::NO_OUTDIR); - uint8_t buf[100]; - pos0_t p0(""); - sbuf_t sbuf(p0, buf, sizeof(buf), sizeof(buf), 0, false); - scanner_params sp(scanner_params::PHASE_STARTUP,sbuf,fs); - recursion_control_block rcb(0,"STAND"); - scanner_info si; - sp.info = &si; - (*fn)(sp,rcb); - std::cout << "Loaded scanner '" << si.name << "' by " << si.author << "\n"; -#ifdef HAVE_DLOPEN - dlclose(lib); -#endif -#endif - return 0; -} - -#if 0 -/*** bogus feature recorder set ***/ -const std::string feature_recorder_set::ALERT_RECORDER_NAME = "alerts"; -const std::string feature_recorder_set::DISABLED_RECORDER_NAME = "disabled"; -const std::string outdir("outdir"); -const std::string feature_recorder_set::NO_INPUT = ""; -const std::string feature_recorder_set::NO_OUTDIR = ""; - -bool feature_recorder_set::check_previously_processed(const uint8_t *buf,size_t bufsize){return false;} -feature_recorder *feature_recorder_set::get_name(const std::string &name) const { return 0;} -feature_recorder *feature_recorder_set::get_alert_recorder() const { return 0;} -void feature_recorder_set::create_name(const std::string &name,bool create_stop_also){} -void feature_recorder_set::get_feature_file_list(std::vector &ret){} -void feature_recorder_set::db_close(){} -BEAPI_SQLITE3 *feature_recorder_set::db_create_empty(const std::string &s){return 0;} -void feature_recorder_set::db_send_sql(BEAPI_SQLITE3 *s,char const **val, ...){} -feature_recorder *feature_recorder_set::create_name_factory(const std::string &name_) -{ - return 0; -} - - -feature_recorder_set::feature_recorder_set(uint32_t f,const feature_recorder_set::hash_def &hasher_, - const std::string &input_fname_,const std::string &outdir_): - flags(f),seen_set(),input_fname(),outdir(),frm(),Mscanner_stats(),histogram_defs(),Min_transaction(),in_transaction(),db3(),alert_list(),stop_list(),scanner_stats(),hasher(hasher_) -{ - /* not here */ -} - - -/* http://stackoverflow.com/questions/9406580/c-undefined-reference-to-vtable-and-inheritance - * Must provide definitions for all virtual functions - */ - -void scanner_info::get_config(const scanner_info::config_t &c, const std::string &n,std::string *val,const std::string &help){} -void scanner_info::get_config(const std::string &n,std::string *val,const std::string &help) {} -void scanner_info::get_config(const std::string &n,uint64_t *val,const std::string &help) {} -void scanner_info::get_config(const std::string &n,int32_t *val,const std::string &help) {} -void scanner_info::get_config(const std::string &n,uint32_t *val,const std::string &help) {} -void scanner_info::get_config(const std::string &n,uint16_t *val,const std::string &help) {} -void scanner_info::get_config(const std::string &n,uint8_t *val,const std::string &help) {} -#ifdef __APPLE__ -void scanner_info::get_config(const std::string &n,size_t *val,const std::string &help) {} -#define HAVE_GET_CONFIG_SIZE_T -#endif -void scanner_info::get_config(const std::string &n,bool *val,const std::string &help) {} -#endif diff --git a/plugins/sbuf_flex_scanner.h b/plugins/sbuf_flex_scanner.h deleted file mode 100644 index b767c485..00000000 --- a/plugins/sbuf_flex_scanner.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* sbuf_flex_scanner.h: - * Used to build a C++ class that can interoperate with sbufs. - * Previously we used the flex c++ option, but it had cross-platform problems. - */ - -#pragma GCC diagnostic ignored "-Wshadow" -#pragma GCC diagnostic ignored "-Wredundant-decls" -#pragma GCC diagnostic ignored "-Wmissing-noreturn" - -#ifdef HAVE_DIAGNOSTIC_EFFCPP -#pragma GCC diagnostic ignored "-Weffc++" -#endif - -//2018-03-03: slg - this doesn't seem to be an issue anymore -//#ifdef HAVE_DIAGNOSTIC_DEPRECATED_REGISTER -//#pragma GCC diagnostic ignored "-Wdeprecated-register" -//#endif - -#define YY_NO_INPUT - -/* Needed for flex: */ -#define ECHO {} /* Never echo anything */ -#define YY_SKIP_YYWRAP /* Never wrap */ -#define YY_NO_INPUT - -class sbuf_scanner { -public: - class sbuf_scanner_exception: public std::exception { - public: - const char *msg; - sbuf_scanner_exception(const char *m):msg(m){} - virtual const char *what() const throw() { - return msg; - } - }; - explicit sbuf_scanner(const sbuf_t *sbuf_): sbuf(sbuf_),pos(0),point(0){} - virtual ~sbuf_scanner(){} - const sbuf_t *sbuf; - // pos & point may be redundent. - // pos counts the number of bytes into the buffer and is incremented by the flex rules - // point counts the point where we are removing characters - size_t pos; /* The position regex is matching from---visible for C++ called by Flex */ - size_t point; /* The position we are reading from---visible to Flex machine */ - - size_t get_input(char *buf,size_t max_size){ - if((int)max_size < 0) return 0; - int count=0; - while ((max_size > 0) && (point < sbuf->bufsize) /* && (pos < sbuf->pagesize) */ ){ - *buf++ = (char)sbuf->buf[point++]; - max_size--; - count++; - } - return count; - }; -}; - -#define YY_INPUT(buf,result,max_size) result = get_extra(yyscanner)->get_input(buf,max_size); -#define POS s.pos -#define SBUF (*s.sbuf) -#define YY_FATAL_ERROR(msg) {throw sbuf_scanner::sbuf_scanner_exception(msg);} - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wsign-compare" diff --git a/plugins/scan-video/Makefile.am b/plugins/scan-video/Makefile.am deleted file mode 100644 index b438d6b1..00000000 --- a/plugins/scan-video/Makefile.am +++ /dev/null @@ -1,154 +0,0 @@ -# See http://sources.redhat.com/autobook/autobook/autobook_88.html - -# http://stackoverflow.com/questions/917948/automake-and-files-with-the-same-name -AUTOMAKE_OPTIONS = subdir-objects - -AM_CFLAGS=-I../src -I../ -AM_CXXFLAGS=-I../src -I../ - -AM_CXXFLAGS+=-fPIC -D__STDC_CONSTANT_MACROS - -EXTRA_DIST = scan_bulk.cpp demo.cpp hello.cpp scan_rar.cpp scan_hello.cpp scan_avi.cpp scan_mp4.cpp scan_3gp.cpp scan_3g2.cpp scan_asf.cpp scan_mov.cpp video_processor.cpp isomf.cpp isomf_factory.cpp fix_mp4.cpp h264_model.cpp bitstream_reader.cpp bitstream_writer.cpp extract_keyframes.cpp process_histogram.cpp keyframe_utils.cpp bytestream_reader.cpp -# scan_lzma.cpp -PLUGINS = libvideo_util.so scan_bulk.so scan_rar.so scan_hello.so scan_avi.so scan_mp4.so scan_3gp.so scan_3g2.so scan_asf.so scan_mov.so - -# I could use libutil: -# http://stackoverflow.com/questions/5671681/how-do-you-make-a-so-library-with-autoconf-rather-that-a-la-library/5674708#5674708 -# but what we have below seems to work -# pkglib_LTLIBRARIES = scan_bulk.la -# scan_bulk_la_LDFLAGS = -module -avoid-version -shar -#lib_LTLIBRARIES = libscan_bulk.la -#libscan_bulk_la_SOURCES = scan_bulk.cpp - -pkglib_LTLIBRARIES = - -#pkglib_LTLIBRARIES += libvideo_util.la -#libvideo_util_la_LDFLAGS = -avoid-version -shar -#libvideo_util_la_SOURCES = video_processor.cpp isomf.cpp isomf_factory.cpp fix_mp4.cpp extract_keyframes.cpp process_histogram.cpp - -pkglib_LTLIBRARIES += scan_hello.la -scan_hello_la_LDFLAGS = -module -avoid-version -shar -scan_hello_la_SOURCES = scan_hello.cpp - -pkglib_LTLIBRARIES += scan_avi.la -scan_avi_la_LDFLAGS = -module -avoid-version -shar -scan_avi_la_SOURCES = scan_avi.cpp - -pkglib_LTLIBRARIES += scan_mp4.la -scan_mp4_la_LDFLAGS = -module -avoid-version -shar -scan_mp4_la_SOURCES = scan_mp4.cpp - -pkglib_LTLIBRARIES += scan_3gp.la -scan_3gp_la_LDFLAGS = -module -avoid-version -shar -scan_3gp_la_SOURCES = scan_3gp.cpp - -pkglib_LTLIBRARIES += scan_3g2.la -scan_3g2_la_LDFLAGS = -module -avoid-version -shar -scan_3g2_la_SOURCES = scan_3g2.cpp - -pkglib_LTLIBRARIES += scan_asf.la -scan_asf_la_LDFLAGS = -module -avoid-version -shar -scan_asf_la_SOURCES = scan_asf.cpp - -pkglib_LTLIBRARIES += scan_mov.la -scan_mov_la_LDFLAGS = -module -avoid-version -shar -scan_mov_la_SOURCES = scan_mov.cpp - -all: - echo type \"make plugins\" to make the plugins - echo type \"make demo\" to make the shared library demo - -plugins: $(PLUGINS) - -# LZMA Support -# This is largely taken from AFFLIB's LZMA support. - -#INCLUDES = \ -# -I@top_srcdir@/lzma443/C \ -# -I@top_srcdir@/lzma443/C/7zip/Compress/LZMA_Alone - -#SLZMA = \ -# scan_lzma.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA_C/LzmaDecode.c \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/Branch/BranchX86.c \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA/LZMADecoder.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZMA/LZMAEncoder.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZ/LZInWindow.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/LZ/LZOutWindow.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Common/InBuffer.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Common/OutBuffer.cpp \ -# @top_srcdir@/plugins/lzma443/C/7zip/Common/StreamUtils.cpp \ -# @top_srcdir@/plugins/lzma443/C/Common/Alloc.cpp \ -# @top_srcdir@/plugins/lzma443/C/Common/CRC.cpp \ -# @top_srcdir@/plugins/lzma443/C/Common/Vector.cpp - - -#scan_lzma.so: libscan_lzma.la -# cp libscan_lzma.la scan_lzma.so - -#scan_bulk.so: scan_bulk.cpp -scan_hello.so: scan_hello.cpp -scan_avi.so: scan_avi.cpp -scan_mp4.so: scan_mp4.cpp -scan_3gp.so: scan_3gp.cpp -scan_3g2.so: scan_3g2.cpp -scan_asf.so: scan_asf.cpp -scan_mov.so: scan_mov.cpp - -OPENCV_LIBS=-lopencv_core -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_imgproc -FFMPEG_LIBS=-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale - -video_processor.o: video_processor.cpp video_processor.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c video_processor.cpp -o video_processor.o - -isomf.o: isomf.cpp isomf.h type_io.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c isomf.cpp -o isomf.o - -h264_model.o: h264_model.cpp h264_model.h isomf.h type_io.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c h264_model.cpp -o h264_model.o - -bitstream_reader.o: bitstream_reader.cpp bitstream_reader.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bitstream_reader.cpp -o bitstream_reader.o - -bitstream_writer.o: bitstream_writer.cpp bitstream_writer.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bitstream_writer.cpp -o bitstream_writer.o - -bytestream_reader.o: bytestream_reader.cpp bytestream_reader.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bytestream_reader.cpp -o bytestream_reader.o - -isomf_factory.o: isomf_factory.cpp isomf_factory.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c isomf_factory.cpp -o isomf_factory.o - -fix_mp4.o: fix_mp4.cpp fix_mp4.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c fix_mp4.cpp -o fix_mp4.o - -keyframe_utils.o: keyframe_utils.cpp keyframe_utils.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c keyframe_utils.cpp -o keyframe_utils.o - -extract_keyframes.o: extract_keyframes.cpp extract_keyframes.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c extract_keyframes.cpp -o extract_keyframes.o - -histogram_process.o: histogram_process.cpp histogram_process.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c histogram_process.cpp -o histogram_process.o - -VIDEO_UTIL_OBJS=video_processor.o isomf.o isomf_factory.o fix_mp4.o h264_model.o bitstream_reader.o bitstream_writer.o extract_keyframes.o histogram_process.o keyframe_utils.o bytestream_reader.o - -libvideo_util.so: $(VIDEO_UTIL_OBJS) - g++ -shared -fPIC $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o libvideo_util.so $(VIDEO_UTIL_OBJS) $(OPENCV_LIBS) $(FFMPEG_LIBS) - -demo: demo.cpp hello.so - g++ -o demo demo.cpp -ldl - -# lib_LTLIBRARIES = libscan_lzma.la -# libscan_lzma_la_SOURCES = $(SLZMA) - -CLEANFILES = scan_rar.so scan_bulk.so.dSYM scan_rar.so.dSYM scan_hello.so.dSYM scan_avi.so.dSYM scan_3gp.so.dSYM scan_mp4.so.dSYM *.d - -SUFFIXES = .so -.cpp.so: libvideo_util.so - g++ -shared -fPIC -D__STDC_CONSTANT_MACROS -o $@ $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -I${top_srcdir} -I${srcdir} -I.. -L. $< $(OPENCV_LIBS) $(FFMPEG_LIBS) -lvideo_util - diff --git a/plugins/scan-video/Makefile.mingw b/plugins/scan-video/Makefile.mingw deleted file mode 100644 index f30a0b7e..00000000 --- a/plugins/scan-video/Makefile.mingw +++ /dev/null @@ -1,725 +0,0 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. -# plugins/Makefile. Generated from Makefile.in by configure. - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - - - -# See http://sources.redhat.com/autobook/autobook/autobook_88.html - - -pkgdatadir = $(datadir)/bulk_extractor -pkgincludedir = $(includedir)/bulk_extractor -pkglibdir = $(libdir)/bulk_extractor -pkglibexecdir = $(libexecdir)/bulk_extractor -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = i686-pc-mingw32 -host_triplet = i686-pc-mingw32 -subdir = plugins -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(pkglibdir)" -LTLIBRARIES = $(pkglib_LTLIBRARIES) -scan_3g2_la_LIBADD = -am_scan_3g2_la_OBJECTS = scan_3g2.lo -scan_3g2_la_OBJECTS = $(am_scan_3g2_la_OBJECTS) -scan_3g2_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_3g2_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_3gp_la_LIBADD = -am_scan_3gp_la_OBJECTS = scan_3gp.lo -scan_3gp_la_OBJECTS = $(am_scan_3gp_la_OBJECTS) -scan_3gp_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_3gp_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_asf_la_LIBADD = -am_scan_asf_la_OBJECTS = scan_asf.lo -scan_asf_la_OBJECTS = $(am_scan_asf_la_OBJECTS) -scan_asf_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_asf_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_avi_la_LIBADD = -am_scan_avi_la_OBJECTS = scan_avi.lo -scan_avi_la_OBJECTS = $(am_scan_avi_la_OBJECTS) -scan_avi_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_avi_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_hello_la_LIBADD = -am_scan_hello_la_OBJECTS = scan_hello.lo -scan_hello_la_OBJECTS = $(am_scan_hello_la_OBJECTS) -scan_hello_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_hello_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_mov_la_LIBADD = -am_scan_mov_la_OBJECTS = scan_mov.lo -scan_mov_la_OBJECTS = $(am_scan_mov_la_OBJECTS) -scan_mov_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_mov_la_LDFLAGS) $(LDFLAGS) -o $@ -scan_mp4_la_LIBADD = -am_scan_mp4_la_OBJECTS = scan_mp4.lo -scan_mp4_la_OBJECTS = $(am_scan_mp4_la_OBJECTS) -scan_mp4_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(scan_mp4_la_LDFLAGS) $(LDFLAGS) -o $@ -DEFAULT_INCLUDES = -I. -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ -SOURCES = $(scan_3g2_la_SOURCES) $(scan_3gp_la_SOURCES) \ - $(scan_asf_la_SOURCES) $(scan_avi_la_SOURCES) \ - $(scan_hello_la_SOURCES) $(scan_mov_la_SOURCES) \ - $(scan_mp4_la_SOURCES) -DIST_SOURCES = $(scan_3g2_la_SOURCES) $(scan_3gp_la_SOURCES) \ - $(scan_asf_la_SOURCES) $(scan_avi_la_SOURCES) \ - $(scan_hello_la_SOURCES) $(scan_mov_la_SOURCES) \ - $(scan_mp4_la_SOURCES) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = ${SHELL} /d/da/nps/src/trunk/missing --run aclocal-1.11 -AMTAR = ${SHELL} /d/da/nps/src/trunk/missing --run tar -AR = ar -AUTOCONF = ${SHELL} /d/da/nps/src/trunk/missing --run autoconf -AUTOHEADER = ${SHELL} /d/da/nps/src/trunk/missing --run autoheader -AUTOMAKE = ${SHELL} /d/da/nps/src/trunk/missing --run automake-1.11 -AWK = gawk -CC = gcc -CCDEPMODE = depmode=gcc3 -CFLAGS = -g -O2 -MD -D_FORTIFY_SOURCE=2 -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes -Wshadow -Wwrite-strings -Wcast-align -Waggregate-return -Wbad-function-cast -Wcast-qual -Wundef -Wredundant-decls -Wdisabled-optimization -Wfloat-equal -Wmultichar -Wc++-compat -Wmissing-noreturn -funit-at-a-time -mthreads -CPP = gcc -E -CPPFLAGS = -DPTW32_STATIC_LIB -DUNICODE -D_UNICODE -D__MSVCRT_VERSION__=0x0601 -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -DHAVE_STRUCT_TIMESPEC -O3 -march=i686 -I/usr/include -I/include -I/usr/local/include -I/mingw/include -I/d/sw/src/opencv/build/include -DUTC_OFFSET=+0800 -CXX = g++ -CXXCPP = g++ -E -CXXDEPMODE = depmode=gcc3 -CXXFLAGS = -g -O2 -Wno-format -Wall -MD -D_FORTIFY_SOURCE=2 -Wpointer-arith -Wshadow -Wwrite-strings -Wcast-align -Wredundant-decls -Wdisabled-optimization -Wfloat-equal -Wmultichar -Wmissing-noreturn -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo -funit-at-a-time -mthreads -CYGPATH_W = echo -DEFS = -DHAVE_CONFIG_H -DEPDIR = .deps -DLLTOOL = dlltool -DSYMUTIL = -DUMPBIN = -ECHO_C = -ECHO_N = -n -ECHO_T = -EGREP = /bin/grep -E -EXEEXT = .exe -FGREP = /bin/grep -F -GREP = /bin/grep -INSTALL = /bin/install -c -INSTALL_DATA = ${INSTALL} -m 644 -INSTALL_PROGRAM = ${INSTALL} -INSTALL_SCRIPT = ${INSTALL} -INSTALL_STRIP_PROGRAM = $(install_sh) -c -s -LD = d:/mingw/mingw32/bin/ld.exe -LDFLAGS = -L/usr/lib -L/lib -L/usr/local/lib -L/mingw/bin -L/mingw/lib -L/d/sw/src/opencv/build/x86/mingw/lib -shared-libgcc -Wl,--enable-auto-import -LEX = flex -LEXLIB = -lfl -LEX_OUTPUT_ROOT = lex.yy -LIBOBJS = -LIBS = -liconv -lewf -lregex -lz -lws2_32 -lgdi32 -lpthread -lws2_32 -lgdi32 -LIBTOOL = $(SHELL) $(top_builddir)/libtool -LIPO = -LN_S = cp -p -LTLIBOBJS = -MAINT = # -MAKEINFO = ${SHELL} /d/da/nps/src/trunk/missing --run makeinfo -MANIFEST_TOOL = : -MKDIR_P = /bin/mkdir -p -NM = /mingw/bin/nm -NMEDIT = -OBJDUMP = objdump -OBJEXT = o -OTOOL = -OTOOL64 = -PACKAGE = bulk_extractor -PACKAGE_BUGREPORT = bugs@afflib.org -PACKAGE_NAME = BULK_EXTRACTOR -PACKAGE_STRING = BULK_EXTRACTOR 1.2.0 -PACKAGE_TARNAME = bulk_extractor -PACKAGE_URL = -PACKAGE_VERSION = 1.2.0 -PATH_SEPARATOR = : -PTHREAD_CC = -PTHREAD_CFLAGS = -PTHREAD_LIBS = -RANLIB = ranlib -SED = /bin/sed -SET_MAKE = -SHELL = /bin/sh -STRIP = strip -VERSION = 1.2.0 -abs_builddir = /d/da/nps/src/trunk/plugins -abs_srcdir = /d/da/nps/src/trunk/plugins -abs_top_builddir = /d/da/nps/src/trunk -abs_top_srcdir = /d/da/nps/src/trunk -ac_ct_AR = ar -ac_ct_CC = gcc -ac_ct_CXX = g++ -ac_ct_DUMPBIN = -ac_prefix_program = -am__include = include -am__leading_dot = . -am__quote = -am__tar = ${AMTAR} chof - "$$tardir" -am__untar = ${AMTAR} xf - -ax_pthread_config = -bindir = ${exec_prefix}/bin -build = i686-pc-mingw32 -build_alias = -build_cpu = i686 -build_os = mingw32 -build_vendor = pc -builddir = . -datadir = ${datarootdir} -datarootdir = ${prefix}/share -docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} -dvidir = ${docdir} -exec_prefix = ${prefix} -host = i686-pc-mingw32 -host_alias = -host_cpu = i686 -host_os = mingw32 -host_vendor = pc -htmldir = ${docdir} -includedir = ${prefix}/include -infodir = ${datarootdir}/info -install_sh = ${SHELL} /d/da/nps/src/trunk/install-sh -libdir = ${exec_prefix}/lib -libexecdir = ${exec_prefix}/libexec -localedir = ${datarootdir}/locale -localstatedir = ${prefix}/var -mandir = ${datarootdir}/man -mkdir_p = /bin/mkdir -p -oldincludedir = /usr/include -pdfdir = ${docdir} -prefix = /usr/local -program_transform_name = s,x,x, -psdir = ${docdir} -sbindir = ${exec_prefix}/sbin -sharedstatedir = ${prefix}/com -srcdir = . -sysconfdir = ${prefix}/etc -target_alias = -top_build_prefix = ../ -top_builddir = .. -top_srcdir = .. - -# http://stackoverflow.com/questions/917948/automake-and-files-with-the-same-name -AUTOMAKE_OPTIONS = subdir-objects -AM_CFLAGS = -I../src -I../ -AM_CXXFLAGS = -I../src -I../ -fPIC -D__STDC_CONSTANT_MACROS -EXTRA_DIST = scan_bulk.cpp demo.cpp hello.cpp scan_rar.cpp scan_hello.cpp scan_avi.cpp scan_mp4.cpp scan_3gp.cpp scan_3g2.cpp scan_asf.cpp scan_mov.cpp video_processor.cpp isomf.cpp isomf_factory.cpp fix_mp4.cpp h264_model.cpp bitstream_reader.cpp bitstream_writer.cpp extract_keyframes.cpp process_histogram.cpp keyframe_utils.cpp bytestream_reader.cpp -# scan_lzma.cpp -PLUGINS = libvideo_util.so scan_bulk.so scan_rar.so scan_hello.so scan_avi.so scan_mp4.so scan_3gp.so scan_3g2.so scan_asf.so scan_mov.so - -# I could use libutil: -# http://stackoverflow.com/questions/5671681/how-do-you-make-a-so-library-with-autoconf-rather-that-a-la-library/5674708#5674708 -# but what we have below seems to work -# pkglib_LTLIBRARIES = scan_bulk.la -# scan_bulk_la_LDFLAGS = -module -avoid-version -shar -#lib_LTLIBRARIES = libscan_bulk.la -#libscan_bulk_la_SOURCES = scan_bulk.cpp - -#pkglib_LTLIBRARIES += libvideo_util.la -#libvideo_util_la_LDFLAGS = -avoid-version -shar -#libvideo_util_la_SOURCES = video_processor.cpp isomf.cpp isomf_factory.cpp fix_mp4.cpp extract_keyframes.cpp process_histogram.cpp -pkglib_LTLIBRARIES = scan_hello.la scan_avi.la scan_mp4.la scan_3gp.la \ - scan_3g2.la scan_asf.la scan_mov.la -scan_hello_la_LDFLAGS = -module -avoid-version -shar -scan_hello_la_SOURCES = scan_hello.cpp -scan_avi_la_LDFLAGS = -module -avoid-version -shar -scan_avi_la_SOURCES = scan_avi.cpp -scan_mp4_la_LDFLAGS = -module -avoid-version -shar -scan_mp4_la_SOURCES = scan_mp4.cpp -scan_3gp_la_LDFLAGS = -module -avoid-version -shar -scan_3gp_la_SOURCES = scan_3gp.cpp -scan_3g2_la_LDFLAGS = -module -avoid-version -shar -scan_3g2_la_SOURCES = scan_3g2.cpp -scan_asf_la_LDFLAGS = -module -avoid-version -shar -scan_asf_la_SOURCES = scan_asf.cpp -scan_mov_la_LDFLAGS = -module -avoid-version -shar -scan_mov_la_SOURCES = scan_mov.cpp -OPENCV_LIBS = -lopencv_core242 -lopencv_highgui242 -lopencv_ml242 -lopencv_video242 -lopencv_imgproc242 -FFMPEG_LIBS = -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale -VIDEO_UTIL_OBJS = video_processor.o isomf.o isomf_factory.o fix_mp4.o h264_model.o bitstream_reader.o bitstream_writer.o extract_keyframes.o histogram_process.o keyframe_utils.o bytestream_reader.o - -# lib_LTLIBRARIES = libscan_lzma.la -# libscan_lzma_la_SOURCES = $(SLZMA) -CLEANFILES = scan_rar.so scan_bulk.so.dSYM scan_rar.so.dSYM scan_hello.so.dSYM scan_avi.so.dSYM scan_3gp.so.dSYM scan_mp4.so.dSYM *.d -SUFFIXES = .so -all: all-am - -.SUFFIXES: -.SUFFIXES: .so .cpp .lo .o .obj -$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu plugins/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu plugins/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: # $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): # $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): -install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) - @$(NORMAL_INSTALL) - test -z "$(pkglibdir)" || $(MKDIR_P) "$(DESTDIR)$(pkglibdir)" - @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ - list2=; for p in $$list; do \ - if test -f $$p; then \ - list2="$$list2 $$p"; \ - else :; fi; \ - done; \ - test -z "$$list2" || { \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkglibdir)'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkglibdir)"; \ - } - -uninstall-pkglibLTLIBRARIES: - @$(NORMAL_UNINSTALL) - @list='$(pkglib_LTLIBRARIES)'; test -n "$(pkglibdir)" || list=; \ - for p in $$list; do \ - $(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \ - done - -clean-pkglibLTLIBRARIES: - -test -z "$(pkglib_LTLIBRARIES)" || rm -f $(pkglib_LTLIBRARIES) - @list='$(pkglib_LTLIBRARIES)'; for p in $$list; do \ - dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ - test "$$dir" != "$$p" || dir=.; \ - echo "rm -f \"$${dir}/so_locations\""; \ - rm -f "$${dir}/so_locations"; \ - done -scan_3g2.la: $(scan_3g2_la_OBJECTS) $(scan_3g2_la_DEPENDENCIES) - $(scan_3g2_la_LINK) -rpath $(pkglibdir) $(scan_3g2_la_OBJECTS) $(scan_3g2_la_LIBADD) $(LIBS) -scan_3gp.la: $(scan_3gp_la_OBJECTS) $(scan_3gp_la_DEPENDENCIES) - $(scan_3gp_la_LINK) -rpath $(pkglibdir) $(scan_3gp_la_OBJECTS) $(scan_3gp_la_LIBADD) $(LIBS) -scan_asf.la: $(scan_asf_la_OBJECTS) $(scan_asf_la_DEPENDENCIES) - $(scan_asf_la_LINK) -rpath $(pkglibdir) $(scan_asf_la_OBJECTS) $(scan_asf_la_LIBADD) $(LIBS) -scan_avi.la: $(scan_avi_la_OBJECTS) $(scan_avi_la_DEPENDENCIES) - $(scan_avi_la_LINK) -rpath $(pkglibdir) $(scan_avi_la_OBJECTS) $(scan_avi_la_LIBADD) $(LIBS) -scan_hello.la: $(scan_hello_la_OBJECTS) $(scan_hello_la_DEPENDENCIES) - $(scan_hello_la_LINK) -rpath $(pkglibdir) $(scan_hello_la_OBJECTS) $(scan_hello_la_LIBADD) $(LIBS) -scan_mov.la: $(scan_mov_la_OBJECTS) $(scan_mov_la_DEPENDENCIES) - $(scan_mov_la_LINK) -rpath $(pkglibdir) $(scan_mov_la_OBJECTS) $(scan_mov_la_LIBADD) $(LIBS) -scan_mp4.la: $(scan_mp4_la_OBJECTS) $(scan_mp4_la_DEPENDENCIES) - $(scan_mp4_la_LINK) -rpath $(pkglibdir) $(scan_mp4_la_OBJECTS) $(scan_mp4_la_LIBADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -include ./$(DEPDIR)/scan_3g2.Plo -include ./$(DEPDIR)/scan_3gp.Plo -include ./$(DEPDIR)/scan_asf.Plo -include ./$(DEPDIR)/scan_avi.Plo -include ./$(DEPDIR)/scan_hello.Plo -include ./$(DEPDIR)/scan_mov.Plo -include ./$(DEPDIR)/scan_mp4.Plo - -.cpp.o: - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - $(am__mv) $$depbase.Tpo $$depbase.Po -# source='$<' object='$@' libtool=no \ -# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ -# $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ - $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ - $(am__mv) $$depbase.Tpo $$depbase.Po -# source='$<' object='$@' libtool=no \ -# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ -# $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cpp.lo: - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ - $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - $(am__mv) $$depbase.Tpo $$depbase.Plo -# source='$<' object='$@' libtool=yes \ -# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ -# $(LTCXXCOMPILE) -c -o $@ $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - set x; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(LTLIBRARIES) -installdirs: - for dir in "$(DESTDIR)$(pkglibdir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \ - mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: install-pkglibLTLIBRARIES - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-pkglibLTLIBRARIES - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-pkglibLTLIBRARIES ctags distclean \ - distclean-compile distclean-generic distclean-libtool \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-pkglibLTLIBRARIES \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-pkglibLTLIBRARIES - -all: - echo type \"make plugins\" to make the plugins - echo type \"make demo\" to make the shared library demo - -plugins: $(PLUGINS) - -# LZMA Support -# This is largely taken from AFFLIB's LZMA support. - -#INCLUDES = \ -# -I../lzma443/C \ -# -I../lzma443/C/7zip/Compress/LZMA_Alone - -#SLZMA = \ -# scan_lzma.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c \ -# ../plugins/lzma443/C/7zip/Compress/LZMA_C/LzmaDecode.c \ -# ../plugins/lzma443/C/7zip/Compress/Branch/BranchX86.c \ -# ../plugins/lzma443/C/7zip/Compress/LZMA/LZMADecoder.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZMA/LZMAEncoder.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZ/LZInWindow.cpp \ -# ../plugins/lzma443/C/7zip/Compress/LZ/LZOutWindow.cpp \ -# ../plugins/lzma443/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp \ -# ../plugins/lzma443/C/7zip/Common/InBuffer.cpp \ -# ../plugins/lzma443/C/7zip/Common/OutBuffer.cpp \ -# ../plugins/lzma443/C/7zip/Common/StreamUtils.cpp \ -# ../plugins/lzma443/C/Common/Alloc.cpp \ -# ../plugins/lzma443/C/Common/CRC.cpp \ -# ../plugins/lzma443/C/Common/Vector.cpp - -#scan_lzma.so: libscan_lzma.la -# cp libscan_lzma.la scan_lzma.so - -#scan_bulk.so: scan_bulk.cpp -scan_hello.so: scan_hello.cpp -scan_avi.so: scan_avi.cpp -scan_mp4.so: scan_mp4.cpp -scan_3gp.so: scan_3gp.cpp -scan_3g2.so: scan_3g2.cpp -scan_asf.so: scan_asf.cpp -scan_mov.so: scan_mov.cpp - -video_processor.o: video_processor.cpp video_processor.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c video_processor.cpp -o video_processor.o - -isomf.o: isomf.cpp isomf.h type_io.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c isomf.cpp -o isomf.o - -h264_model.o: h264_model.cpp h264_model.h isomf.h type_io.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c h264_model.cpp -o h264_model.o - -bitstream_reader.o: bitstream_reader.cpp bitstream_reader.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bitstream_reader.cpp -o bitstream_reader.o - -bitstream_writer.o: bitstream_writer.cpp bitstream_writer.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bitstream_writer.cpp -o bitstream_writer.o - -bytestream_reader.o: bytestream_reader.cpp bytestream_reader.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c bytestream_reader.cpp -o bytestream_reader.o - -isomf_factory.o: isomf_factory.cpp isomf_factory.h - g++ -fPIC $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c isomf_factory.cpp -o isomf_factory.o - -fix_mp4.o: fix_mp4.cpp fix_mp4.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c fix_mp4.cpp -o fix_mp4.o - -keyframe_utils.o: keyframe_utils.cpp keyframe_utils.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c keyframe_utils.cpp -o keyframe_utils.o - -extract_keyframes.o: extract_keyframes.cpp extract_keyframes.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c extract_keyframes.cpp -o extract_keyframes.o - -histogram_process.o: histogram_process.cpp histogram_process.h - g++ -fPIC -D__STDC_CONSTANT_MACROS $(CXXFLAGS) $(CPPFLAGS) -I${top_srcdir} -I${srcdir} -I.. -c histogram_process.cpp -o histogram_process.o - -libvideo_util.so: $(VIDEO_UTIL_OBJS) - g++ -shared -fPIC $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o libvideo_util.so $(VIDEO_UTIL_OBJS) $(OPENCV_LIBS) $(FFMPEG_LIBS) - -demo: demo.cpp hello.so - g++ -o demo demo.cpp -ldl -.cpp.so: libvideo_util.so - g++ -shared -fPIC -D__STDC_CONSTANT_MACROS -o $@ $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -I${top_srcdir} -I${srcdir} -I.. -L. $< $(OPENCV_LIBS) $(FFMPEG_LIBS) -L. -lvideo_util - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/plugins/scan-video/analyze_parsed_avcc.pl b/plugins/scan-video/analyze_parsed_avcc.pl deleted file mode 100644 index bbe22638..00000000 --- a/plugins/scan-video/analyze_parsed_avcc.pl +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/perl -w -use strict; -$|++; - -use JSON; - -my @sps; -my @pps; -my %stat; - -sub usage -{ - my $me=`basename $0`; - chomp $me; - print "Usage: $me [avcc_parser_output] ...\n"; - exit 0; -} - -sub process_json_text -{ - my $json_text = shift || return; - - my $ref = decode_json $json_text; - if ($ref) { - my $type = $ref->{"type"}; - if ($type) { - if ($type eq "sequence_parameter_set") { - push @sps, $ref; - } elsif ($type eq "picture_parameter_set") { - push @pps, $ref; - } - print STDERR "JSON object of type $type found.\n"; - } else { - print STDERR "!! JSON object of unknown type found.\n"; - } - } else { - print STDERR "!! Failed to decode JSON text: $json_text\n"; - } -} - -sub process_file -{ - my $file = shift || return; - print STDERR "Processing $file...\n"; - - open F,"<$file" or die "Unable to open $file: $!"; - - my $json_text = ""; - my $in_json = 0; - - foreach () { - chomp; - if (/^{\s*$/) { - $in_json = 1; - } - - if ($in_json) { - $json_text .= $_; - } - - if (/^}\s*$/) { - $in_json = 0; - process_json_text $json_text; - $json_text = ""; - } - } - close F; -} - -sub process_result_json -{ - my $name = shift || ""; - my $ref = shift || return; - - if (ref($ref) ne "HASH") { - die "Result object is not hash?"; - } - - my $subname = $ref->{'type'} || "object"; - my $fullname = $name ? "$name.$subname" : $subname; - - foreach my $key (keys %{$ref}) { - my $value = $ref->{$key}; - if (ref($value) eq "HASH") { - process_result_json($fullname, $value); - } elsif (ref($value) eq "ARRAY") { - $stat{"$fullname.$key"}->{"[" . join ',',@{$value} . "]"}++; - } else { - $stat{"$fullname.$key"}->{"$value"}++; - } - } -} - -sub process_result -{ - my $name = shift || ""; - my $ref = shift || return; - - if (ref($ref) ne "ARRAY") { - die "Result argument is not an array."; - } - - if (scalar @{$ref} == 0) { - print STDERR "Nothing in the results to process.\n"; - } - - foreach my $json_ref (@{$ref}) { - process_result_json($name, $json_ref); - } -} - -sub process_stat -{ - foreach my $key (keys %stat) { - print "$key: "; - - my $ref=$stat{$key}; - foreach my $item (keys %{$ref}) { - my $value = $ref->{"$item"}; - print "$item=$value "; - } - print "\n"; - } -} - -### Main - -if (scalar @ARGV == 0) { - usage(); -} - -foreach my $file (@ARGV) { - process_file($file); -} - -process_result("", \@pps); -process_result("", \@sps); - -process_stat(); - -exit 0; - diff --git a/plugins/scan-video/bitstream_reader.cpp b/plugins/scan-video/bitstream_reader.cpp deleted file mode 100644 index 2322e831..00000000 --- a/plugins/scan-video/bitstream_reader.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include -#include - -#include "bitstream_reader.h" - -using namespace std; - -bitstream_reader::bitstream_reader() - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_read(0) -{ -} - -bitstream_reader::bitstream_reader(const char* data, size_t size) - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_read(0) -{ - set_data(data, size); -} - -bitstream_reader::bitstream_reader(const bitstream_reader& reader) - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_read(0) -{ - reader.copy_data(*this); -} - -bitstream_reader::~bitstream_reader() -{ - if (_data) { - delete[] _data; - } -} - -void bitstream_reader::set_data(const char* data, size_t size) -{ - if (data && size > 0) { - _data = new char[size]; - memcpy(_data, data, size); - _data_size = size; - _bit_pos = 0; - _byte_pos = 0; - _bits_read = 0; - } -} - -void bitstream_reader::copy_data(bitstream_reader& reader) const -{ - reader.set_data(_data, _data_size); -} - -bitstream_reader& bitstream_reader::operator=(const bitstream_reader& reader) -{ - reader.copy_data(*this); - return *this; -} - -int bitstream_reader::read_bit() -{ - if (_data == NULL || _data_size == 0 || (size_t)_byte_pos >= _data_size) - { - cerr << "*** Error reading bit at byte: " << _byte_pos - << ", bit: " << _bit_pos << ", total: " << _data_size << endl; - return -1; - } - int b = (_data[_byte_pos] >> (7 - _bit_pos)) & 1; - _bit_pos++; - if (_bit_pos > 7) { - _bit_pos = 0; - _byte_pos++; - } - _bits_read++; - return b; -} - -long long bitstream_reader::read_bits(int n) -{ - if (_data == NULL || _data_size == 0 || - n < 0 || (size_t)n > sizeof(long long)*8) - { - return -1; - } - if (n == 0) { return 0; } - - long long v = 0; - for (int i=0; i= _data_size) { - return -1; - } - - // move to the next byte - if (_bit_pos > 0) { - _bits_read += (8-_bit_pos); - _bit_pos = 0; - _byte_pos++; - } - - int byte = _data[_byte_pos]; - _byte_pos++; - _bits_read += 8; - return byte; -} - -int bitstream_reader::read_remaining_byte() -{ - if (_data == NULL || _data_size == 0 || (size_t)_byte_pos >= _data_size) { - return -1; - } - return read_bits(8-_bit_pos); -} - -int bitstream_reader::read_UE() -{ - int cnt = 0; - while (read_bit() == 0) { cnt++; } - - int res = 0; - if (cnt > 0) { - long val = read_bits(cnt); - res = (int) ((1 << cnt) - 1 + val); - } - return res; -} - -int bitstream_reader::read_SE() -{ - int val = read_UE(); - if (val == -1) { return -1; } - - int sign = ((val & 0x1) << 1) -1; - val = ((val >> 1) + (val & 0x1)) * sign; - return val; -} - -bool bitstream_reader::read_bool() -{ - return (read_bit() == 1); -} - -int bitstream_reader::read_U(int i) -{ - return read_bits(i); -} - -int bitstream_reader::read_TE(int max) -{ - if (max > 1) { return read_UE(); } - return ~read_bit() & 0x1; -} - -char* bitstream_reader::read_bytes(int size) -{ - if (size <= 0) { return NULL; } - - char* result = new char[size]; - for (int i=0; i= _data_size) { - return false; - } - - int cur_byte = _data[_byte_pos] & 0xff; - int next_byte = _byte_pos == _data_size-1 ? -1 : _data[_byte_pos+1] & 0xff; - - int tail = 1 << (8-_bit_pos-1); - int mask = ((tail << 1) -1); - bool has_tail = (cur_byte & mask) == tail; - - return ! (next_byte == -1 && has_tail); -} - - diff --git a/plugins/scan-video/bitstream_reader.h b/plugins/scan-video/bitstream_reader.h deleted file mode 100644 index 9a62bb2f..00000000 --- a/plugins/scan-video/bitstream_reader.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef BITSTREAM_READER_H -#define BITSTREAM_READER_H - -class bitstream_reader -{ - public: - bitstream_reader(); - bitstream_reader(const bitstream_reader& reader); - bitstream_reader(const char* data, size_t size); - ~bitstream_reader(); - - void set_data(const char* data, size_t size); - void copy_data(bitstream_reader& reader) const; - - bitstream_reader& operator=(const bitstream_reader& reader); - - int read_bit(); - long long read_bits(int n); - - // discard unread partial bits and read the next byte - int read_byte(); - - // read partial bytes in the current byte position - int read_remaining_byte(); - - int read_UE(); - int read_SE(); - bool read_bool(); - int read_U(int i); - int read_TE(int max); - - char* read_bytes(int size); - - int read_zero_bit_count(); - - void read_trailing_bits(); - - size_t read_count() const - { return _bit_pos > 0 ? _byte_pos + 1 : _byte_pos; }; - - size_t read_bit_count() const - { return _bits_read; } - - bool more_rbsp_data(); - - protected: - char* _data; - size_t _data_size; - - int _bit_pos; - size_t _byte_pos; - - size_t _bits_read; -}; - -#endif diff --git a/plugins/scan-video/bitstream_writer.cpp b/plugins/scan-video/bitstream_writer.cpp deleted file mode 100644 index 6e0b9193..00000000 --- a/plugins/scan-video/bitstream_writer.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include - -#include "bitstream_writer.h" - -bitstream_writer::bitstream_writer() - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_written(0) -{ -} - -bitstream_writer::bitstream_writer(char* data, size_t size) - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_written(0) -{ - set_data(data, size); -} - -bitstream_writer::bitstream_writer(const bitstream_writer& writer) - :_data(NULL),_data_size(0),_bit_pos(0),_byte_pos(0),_bits_written(0) -{ - writer.copy_data(*this); -} - -bitstream_writer::~bitstream_writer() -{ -} - -void bitstream_writer::set_data(char* data, size_t size) -{ - if (data && size > 0) { - _data = data; - _data_size = size; - _bit_pos = 0; - _byte_pos = 0; - _bits_written = 0; - } -} - -void bitstream_writer::copy_data(bitstream_writer& writer) const -{ - writer.set_data(_data, _data_size); -} - -bitstream_writer& bitstream_writer::operator=(const bitstream_writer& writer) -{ - writer.copy_data(*this); - return *this; -} - -int bitstream_writer::write_bit(int bit) -{ - if (_data == NULL || _data_size == 0 || (size_t)_byte_pos >= _data_size) - { - return -1; - } - - int mask = 1 << (7-_bit_pos); - if (bit == 1) { - _data[_byte_pos] |= (mask & 0xff); - } else { - mask = 0xff - mask; - _data[_byte_pos] &= mask; - } - - _bit_pos++; - if (_bit_pos > 7) { - _bit_pos = 0; - _byte_pos++; - } - _bits_written++; - return 1; -} - -int bitstream_writer::write_bits(long long value, int n) -{ - if (_data == NULL || _data_size == 0 || - n < 0 || (size_t)n > sizeof(long long)*8) - { - return -1; - } - if (n == 0) { return 0; } - - for (int i=n-1; i>=0; i--) { - int result; - if ((value >> i) & 1) { - result = write_bit(1); - } else { - result = write_bit(0); - } - if (result != 1) { - return i; - } - } - return n; -} - -int bitstream_writer::write_byte(int byte) -{ - if (_data == NULL || _data_size == 0 || (size_t)_byte_pos >= _data_size) { - return -1; - } - - // move to the next byte - int nb = 0; - if (_bit_pos > 0) { - _bits_written += (8-_bit_pos); - nb += (8-_bit_pos); - _bit_pos = 0; - _byte_pos++; - } - - _data[_byte_pos] = byte; - _byte_pos++; - _bits_written += 8; - nb += 8; - return nb; -} - -int bitstream_writer::write_remaining_zero() -{ - if (_data == NULL || _data_size == 0 || (size_t)_byte_pos >= _data_size) { - return -1; - } - return write_bits(0, 8-_bit_pos); -} - -int bitstream_writer::write_U(int value, int n) -{ - return write_bits(value, n); -} - - -int bitstream_writer::write_UE(int value) -{ - int bits = 0; - int cumul = 0; - - for (int i = 0; i < 15; i++) { - if (value < cumul + (1 << i)) { - bits = i; - break; - } - cumul += (1 << i); - } - int nb = 0; - nb += write_bits(0, bits); - nb += write_bit(1); - nb += write_bits(value - cumul, bits); - return nb; -} - -int bitstream_writer::write_SE(int value) -{ - return write_UE((value << 1) * (value < 0 ? -1 : 1) + (value > 0 ? 1 : 0)); -} - -int bitstream_writer::write_bool(bool value) -{ - return write_bit(value ? 1 : 0); -} - -int bitstream_writer::write_trailing_bits() -{ - int nb = write_bit(1); - if (nb <= 0) { return nb;} - return 1 + write_remaining_zero(); -} - diff --git a/plugins/scan-video/bitstream_writer.h b/plugins/scan-video/bitstream_writer.h deleted file mode 100644 index 22396923..00000000 --- a/plugins/scan-video/bitstream_writer.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef BITSTREAM_WRITER_H -#define BITSTREAM_WRITER_H - -class bitstream_writer -{ - public: - bitstream_writer(); - bitstream_writer(const bitstream_writer& writer); - bitstream_writer(char* data, size_t size); - ~bitstream_writer(); - - void set_data(char* data, size_t size); - void copy_data(bitstream_writer& writer) const; - - bitstream_writer& operator=(const bitstream_writer& writer); - - int write_bit(int bit); - int write_bits(long long value, int n); - int write_byte(int byte); - - int write_remaining_zero(); - int write_U(int value, int n); - int write_UE(int value); - int write_SE(int value); - int write_bool(bool value); - int write_trailing_bits(); - - size_t write_count() const - { return _bit_pos > 0 ? _byte_pos + 1 : _byte_pos; }; - - size_t write_bit_count() const - { return _bits_written; } - - protected: - char* _data; - size_t _data_size; - - int _bit_pos; - size_t _byte_pos; - - size_t _bits_written; -}; - -#endif diff --git a/plugins/scan-video/bytestream_reader.cpp b/plugins/scan-video/bytestream_reader.cpp deleted file mode 100644 index 52e9c703..00000000 --- a/plugins/scan-video/bytestream_reader.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include - -#include "bytestream_reader.h" - -using namespace std; - -bytestream_reader::bytestream_reader() - :_data(NULL),_data_size(0),_pos(0) -{ -} - -bytestream_reader::bytestream_reader(const char* data, size_t size) - :_data(NULL),_data_size(0),_pos(0) -{ - set_data(data, size); -} - -bytestream_reader::bytestream_reader(const bytestream_reader& reader) - :_data(NULL),_data_size(0),_pos(0) -{ - reader.copy_data(*this); -} - -bytestream_reader::~bytestream_reader() -{ - if (_data) { - delete[] _data; - } -} - -void bytestream_reader::set_data(const char* data, size_t size) -{ - if (data && size > 0) { - _data = new char[size]; - memcpy(_data, data, size); - _data_size = size; - _pos = 0; - } -} - -void bytestream_reader::copy_data(bytestream_reader& reader) const -{ - reader.set_data(_data, _data_size); -} - -bytestream_reader& bytestream_reader::operator=(const bytestream_reader& reader) -{ - reader.copy_data(*this); - return *this; -} - -int bytestream_reader::read_byte() -{ - if (_data == NULL || _data_size == 0 || _pos >= _data_size) { - cerr << "*** Error reading byte at offset: " << _pos - << ", total: " << _data_size << endl; - return -1; - } - int value = _data[_pos]; - _pos++; - return value; -} - -long long bytestream_reader::read_bytes(int n) -{ - if (_data == NULL || _data_size == 0 || n < 0 || - (size_t)n > sizeof(long long) || n + _pos > _data_size) - { - cerr << "*** Error reading bytes at offset: " << _pos - << ", total: " << _data_size << endl; - return -1; - } - if (n == 0) { return 0; } - - char* buf = _data + _pos; - long long v = 0; - for (int i=0; i _data_size) - { - cerr << "*** Error reading array at offset: " << _pos - << ", total: " << _data_size << endl; - return -1; - } - if (n == 0) { return 0; } - - memcpy(dest, _data+_pos, n); - _pos += n; - return n; -} - -std::string* bytestream_reader::read_fourcc() -{ - if (_data == NULL || _data_size == 0 || _pos + 4 > _data_size) - { - cerr << "*** Error reading fourcc code at offset: " << _pos - << ", total: " << _data_size << endl; - return NULL; - } - char fourcc[5] = {0}; - memcpy(fourcc, _data+_pos, 4); - _pos += 4; - return new std::string(fourcc); -} - diff --git a/plugins/scan-video/bytestream_reader.h b/plugins/scan-video/bytestream_reader.h deleted file mode 100644 index 52b00d7f..00000000 --- a/plugins/scan-video/bytestream_reader.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef BYTESTREAM_READER_H -#define BYTESTREAM_READER_H - -class bytestream_reader -{ - public: - bytestream_reader(); - bytestream_reader(const bytestream_reader& reader); - bytestream_reader(const char* data, size_t size); - ~bytestream_reader(); - - void set_data(const char* data, size_t size); - void copy_data(bytestream_reader& reader) const; - - bytestream_reader& operator=(const bytestream_reader& reader); - - int read_byte(); - long long read_bytes(int n); - - inline int read_uint8() { return (int) read_bytes(1); } - inline int read_uint16() { return (int) read_bytes(2); } - inline long read_uint32() { return (long) read_bytes(4); } - inline long long read_uint64() { return read_bytes(8); } - - std::string* read_fourcc(); - - int read_array(char* dest, int n); - - inline size_t read_count() const { return _pos; } - inline size_t available() const { return _data_size - _pos; } - inline void skip(int n) { if (n > 0) { _pos += n; } } - - protected: - char* _data; - size_t _data_size; - size_t _pos; -}; - -#endif diff --git a/plugins/scan-video/demo.cpp b/plugins/scan-video/demo.cpp deleted file mode 100644 index 989fb663..00000000 --- a/plugins/scan-video/demo.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "../config.h" - -#include - -#ifdef HAVE_DLFCN_H -#include -#endif - -#ifdef HAVE_WINDOWS_H -#include -typedef int (__cdecl *MYPROC)(LPWSTR); -#endif - - -int main(int argc,char **argv) -{ - void (*fn)(char*)=0; - -#ifdef HAVE_DLOPEN - const char *fname = "hello.so"; - - if(!dlopen_preflight(fname)){ - err(1,"dlopen_preflight - cannot open %s: %s",fname,dlerror()); - } - - void *lib=dlopen(fname, RTLD_LAZY); - - if(lib==0) errx(1,"dlopen: %s\n",dlerror()); - fn=(void (*)(char*))dlsym(lib, "hello"); - if(fn==0) errx(1,"dlsym: %s\n",dlerror()); -#else -#ifdef HAVE_LOADLIBRARY - /* Use Win32 LoadLibrary function */ - /* See http://msdn.microsoft.com/en-us/library/ms686944(v=vs.85).aspx */ - const char *fname = "hello.DLL"; - HINSTANCE hinstLib = LoadLibrary(TEXT(fname)); - if(hinstLib==0) errx(1,"LoadLibrary(%s) failed",fname); - MYPROC fn = (MYPROC)GetProcAddress(hinstLib,"hello"); - if(fn==0) errx(1,"GetProcAddress(%s) failed","hello"); -#endif -#endif - - fn("Sent to demo."); - - dlclose(lib); - return 0; -} diff --git a/plugins/scan-video/extract_keyframes.cpp b/plugins/scan-video/extract_keyframes.cpp deleted file mode 100644 index 8033b5de..00000000 --- a/plugins/scan-video/extract_keyframes.cpp +++ /dev/null @@ -1,529 +0,0 @@ -#include "extract_keyframes.h" -#include "video_processor.h" - -#include -#include -#include - -#include -#include -#include - -// Install Signal Actions -#include -#include -#ifndef WIN32 -#include -#endif -#include - -using namespace std; - -shot_segment::shot_segment():_start_pos(0), _end_pos(0), _start_frm(0), _end_frm(0){} - -shot_segment::~shot_segment(){} - -extract_keyframes::extract_keyframes():_firsttime(true), _hp(NULL){ - _util.reset(); - _dir.clear(); - av_init_packet(&_packet); -} - -extract_keyframes::~extract_keyframes(){ - if(NULL != _hp){ - delete _hp; - _hp = NULL; - } - _util.reset(); -} - -void extract_keyframes::initialize(const AVCodecContext *codec_context){ - - _util.reset(); - _util.initialize(codec_context); - av_init_packet(&_packet); - - if(NULL != _hp){ - delete _hp; - _hp = NULL; - } - _hp = new histogram_process(_util); - return; -} - -bool extract_keyframes::next_frame(AVFormatContext *format_context, AVCodecContext *codec_context, - int videoStream, AVFrame *frame){ - - int bytesDecoded; - int frameFinished; // returns function status - if (_firsttime) { - _firsttime = false; - _packet.data = NULL; - _packet.size = 0; - } - - while (true) { - // Decode the packet to frame. Use as many packets until a single frame is decoded. - while (_packet.size > 0) { - bytesDecoded = avcodec_decode_video2(codec_context, frame, &frameFinished, &_packet); - if (bytesDecoded < 0) { - std::cerr << __FILE__ << " : " << __LINE__ << - " Error while decoding frame\n"; - return false; - } - _packet.size -= bytesDecoded; - _packet.data += bytesDecoded; - // If a complete frame has been decoded, return. - if (frameFinished) - return true; - } - do { - // read packets. - if (av_read_frame(format_context, &_packet) < 0){ - bytesDecoded = avcodec_decode_video2(codec_context, frame, &frameFinished, &_packet); - return frameFinished != 0; - } - } while (_packet.stream_index != videoStream); - } - - // decode last packet to frame - bytesDecoded = avcodec_decode_video2(codec_context, frame, &frameFinished, &_packet); - return frameFinished != 0; -} - -bool extract_keyframes::segmentation(AVFormatContext *format_context, AVCodecContext *codec_context, int video_handle){ - - // Allocate video frame - AVFrame *frame = avcodec_alloc_frame(); - // Allocate histograms to track - - // i_frame - Previous I frame for scene change comparison - // key_frame - Previous key frame for key frame extraction - // curr - Holds the histogram for the current frame. - cv::MatND i_frame, key_frame, curr; - - // Holds the shot segment information for scene change detection. - shot_segment sc; - - // first time - get frame and calc histogram. For each I frame note down the byte position - if(next_frame(format_context, codec_context, video_handle, frame)){ - _hp->get_histogram(frame, codec_context, i_frame); - key_frame = i_frame.clone(); // use first frame as key reference. although this frame is not saved. - curr = i_frame.clone(); // use first frame as key reference. although this frame is not saved. - sc._end_pos = 0; sc._end_frm = 0; - - }else { - std::cerr << __FILE__ << " : " << __LINE__ << - " Error decoding the video stream\n"; - av_free(frame); - return false; - } - - - double motion_score = 0, intra_likelihood = 0; - double dist_intra = 0.0, dist_key = 0.0; - bool do_only_hist = false, save_first = false; - int picture_number = 0; - - double frame_rate = 1.0; - if((codec_context->time_base.num != 0) && (codec_context->time_base.den != 0)) - frame_rate = 1.0 * codec_context->time_base.den / codec_context->time_base.num; - - // Scene Change Output - std::string sc_file = _dir + "/" + "scene_change.txt"; - std::ofstream fp_sc(sc_file.c_str(), ios::binary | ios::out); - if(NULL == fp_sc){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Unable to create scene change file\n"; - return false; - } - - // Decode until last frame - while (next_frame(format_context, codec_context, video_handle, frame)) { - - //shot segmentation - ++picture_number; - // Process I-Frames - if((frame->key_frame) || (frame->pict_type == AV_PICTURE_TYPE_I) || (do_only_hist)){ - - // Save first I frame as a key frame. This is essential for frames with a very low motion score. - // If none of the frames have the required motion activity then no frame will be saved - // To prevent that we save the first I frame as a key frame. - if(!save_first){ - // Copy histograms for the next keyframe and scene change calculation - key_frame = curr.clone(); - i_frame = curr.clone(); - // Generate the key frame name - stringstream name; - name <<"key_" << picture_number << ".jpg"; - std::string kf = _dir + "/" + name.str(); - if(!_util.save_keyframe(kf, codec_context, frame)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error saving key frame " << kf << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - save_first = true; - continue; - } - - // Copy histograms & shot boundaries for the next keyframe and scene change calculation - sc._start_pos = sc._end_pos; sc._start_frm = sc._end_frm; - sc._end_pos = frame->pts; - sc._end_frm = frame->coded_picture_number; - // if picture numbers are not coded, use local count - if(0 == frame->coded_picture_number) - sc._end_frm = picture_number; - //Calculate histogram for the current frame - _hp->get_histogram(frame, codec_context, curr); - - // compute distance to the previous intra frame histogram - if(!_hp->compare(curr, i_frame, dist_intra)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error calculating histogram distance" << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - i_frame = curr.clone(); - - if(dist_intra > 0.91){ //THRESHOLD_SHOT_SEG = 0.91 - // Output to scene_change.txt - if(sc._start_pos < 0) - fp_sc << "Timestamp : NULL - NULL | Frame Number : " << sc._start_frm <<" - " << sc._end_frm << endl; - else - fp_sc << "Timestamp : " << (1.0 * sc._start_pos / frame_rate) <<" - " << (1.0 * sc._end_pos / frame_rate) << " | Frame Number : " << sc._start_frm <<" - " << sc._end_frm << endl; - - // compute distance to previous key frame histogram - if(!_hp->compare(curr, key_frame, dist_key)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error calculating histogram distance" << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - - if(dist_key > 0.26){ //THRESHOLD_SHOT_KEY = 0.26 - //Current frame is also a key frame; Save frame - key_frame = curr.clone(); - stringstream name; - name <<"key_" << picture_number << ".jpg"; - std::string kf = _dir + "/" + name.str(); - if(!_util.save_keyframe(kf, codec_context, frame)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error saving frames" << kf << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - } - } - }else { - // Process P-frames and B-frames - // Calculate motion score and intra likelihood - if(!_util.calculate_motion_score(frame, codec_context, motion_score, intra_likelihood)){ - // error computing the motion score. Use only the histogram method - do_only_hist = true; - continue; - } - // Check thresholds for THRESHOLD_AVG_MOTION_SCORE & THRESHOLD_INTRA_LIKELIHOOD - if((motion_score > 2.57) || (intra_likelihood > 0.4)){ - _hp->get_histogram(frame, codec_context, curr); - // Compute distances between the current frame and the previous I frame and Key frame. - if(!_hp->compare(curr, i_frame, dist_intra)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error calculating histogram distance" << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - - if(!_hp->compare(curr, key_frame, dist_key)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error calculating histogram distance" << std::endl; - fp_sc.close(); - av_free(frame); - return false; - } - - if((dist_key > 0.26) && (dist_intra > 0.9)){ - sc._start_pos = sc._end_pos; sc._start_frm = sc._end_frm; - sc._end_pos = frame->pts; - sc._end_frm = frame->coded_picture_number; - if(0 == frame->coded_picture_number) sc._end_frm = picture_number; - if(sc._start_pos < 0) - fp_sc << "Timestamp : NULL - NULL | Frame Number : " << sc._start_frm <<" - " << sc._end_frm << endl; - else - fp_sc << "Timestamp : " << (1.0 * sc._start_pos / frame_rate) <<" - " << (1.0 * sc._end_pos / frame_rate) << " | Frame Number : " << sc._start_frm <<" - " << sc._end_frm << endl; - - key_frame = curr.clone(); - - stringstream name; - name <<"key_" << picture_number << ".jpg"; - std::string kf = _dir + "/" + name.str(); - if(!_util.save_keyframe(kf, codec_context, frame)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Error saving frames" << std::endl; - fp_sc.close(); - av_free(frame); - return false; - - } - } - } - } - } - - fp_sc.close(); - av_free(frame); - return true; -} - -bool extract_keyframes::create_outdir(const std::string name){ - //remove all dots - _dir.assign(name); - if(_dir.size() == 0) { - std::cerr << __FILE__ << " : " << __LINE__ << " Invalid directory name\n"; - return false; - } - // Generate Directory name, by replacing all dots with '_' - size_t position = name.find_last_of('.'); - if(position != std::string::npos){ - _dir.replace(position, 1, "_"); - } -#ifdef WIN32 - if(mkdir(_dir.c_str())){ - std::cerr << __FILE__ << " : " << __LINE__ << " Could not make directory " << _dir << "\n"; - return false; - } -#else - if(mkdir(_dir.c_str(),0777)){ - std::cerr << __FILE__ << " : " << __LINE__ << " Could not make directory " << _dir << "\n"; - return false; - } -#endif - return true; -} - -bool extract_keyframes::extract(const sbuf_t& sbuf, size_t offset, feature_recorder& recorder){ - - char* data = (char*) (sbuf.buf + offset); - size_t l = sbuf.pagesize; - size_t length = l - offset; - const pos0_t &pos0 = sbuf.pos0; - std::string fpath = pos0.path; - // Get the memory buffer pointer and length of buffer - if (! data || length == 0) { - std::cerr << __FILE__ << " : " << __LINE__ << " Invalid argument to extract_keyframes::extract" << std::endl; - return false; - } - // construct output file name - std::stringstream ss; - ss << recorder.name << "-p" << fpath << "-" << pos0.offset - << "-" << offset << "-" << rand() << "." << recorder.name; - std::string outfile = recorder.outdir + "/" + ss.str(); - std::fstream fs(outfile.c_str(), std::ios_base::out | std::ios_base::binary); - fs.write(data, length); - bool ok = ! fs.bad(); - if (! ok) { - std::cerr << __FILE__ << " : " << __LINE__ << " >> ERROR writing buffer to output file: " << outfile << std::endl; - } - fs.close(); - ok &= extract(outfile); - return ok; -} - -bool extract_keyframes::extract(std::string input_file){ - - if(input_file.empty()){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Invalid input file name\n"; - return false; - } - bool ok = true; -#ifndef WIN32 - pid_t pid = fork(); - if (pid == 0) { - install_signal_actions(); - - try { - if(!create_outdir(input_file)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Creation of Output Directory failed\n"; - throw new std::exception(); - } - - // Initialize all the ffmpeg constructs - AVCodec, AVFormat, AVPacket. - av_register_all(); - avcodec_register_all(); - av_init_packet(&_packet); - - // Open the input file - AVFormatContext *format_context = NULL; - if (avformat_open_input(&format_context, input_file.c_str(), NULL, NULL) != 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed to open the input file\n"; - throw new std::exception(); - } - - // Retrieve stream information - if (avformat_find_stream_info(format_context,NULL) < 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed find stream parameters in the input file\n"; - throw new std::exception(); - } - - // Identify the video handle - int video_handle = -1; - AVCodecContext *temp_context = NULL; - for (int i = 0; i < format_context->nb_streams; i++) { - temp_context = format_context->streams[i]->codec; - if (temp_context->codec_type == AVMEDIA_TYPE_VIDEO) { - video_handle = i; - break; - } - } - if (video_handle == -1){ - std::cerr << __FILE__ << " : " << __LINE__ << - " No valid video handle identified in the input file\n"; - throw new std::exception(); - } - - // Get a pointer to the codec context for the video stream - AVCodecContext *codec_context = format_context->streams[video_handle]->codec; - // Find the decoder for the video stream - AVCodec *codec = avcodec_find_decoder(codec_context->codec_id); - if (codec == NULL){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Invalid video parameters in the input file\n"; - throw new std::exception(); - } - - // Inform the codec that we can handle truncated bitstreams - if (codec->capabilities & CODEC_CAP_TRUNCATED) - codec_context->flags |= CODEC_FLAG_TRUNCATED; - - // Initialize the identified video codec - if (avcodec_open2(codec_context, codec, NULL) < 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed to initialize the video decoder\n"; - throw new std::exception(); - } - - // Based on the identified codec - initialize the histogram process - // and keyframe utilities. - initialize(codec_context); - - // Segment the video based on the motion score and identify - // scene changes. Process the segmented video and extract - // key frames. - ok = segmentation(format_context, codec_context, video_handle); - - // release the ffmpeg constructs. - avcodec_close(codec_context); - avformat_close_input(&format_context); - } catch (std::exception& e) { - std::cerr << __FILE__ << " : " << __LINE__<< " extract key frames failed: " << e.what() << std::endl; - exit(1); - } - exit(0); - } else { - //std::cerr << "ExtractKeyframes >> Waiting for pid " << pid << std::endl; - int stat; - pid_t child_pid = waitpid(pid, &stat, 0); - if (child_pid == -1) { - std::cerr << __FILE__ << ":" << __LINE__ <<" ExtractKeyframes >> Child process " << pid << " failed." << std::endl; - return false; - } else if (stat != 0) { - std::cerr << __FILE__ << ":" << __LINE__ <<" ExtractKeyframes >> Child process " << pid << " finished with error " - << (stat & 0xff00 >> 8) - << "," << (stat & 0xff) << std::endl; - } else { - //std::cerr << "ExtractKeyframes >> Child process " << pid << " succeeded." << std::endl; - } - } -#else - - try { - if(!create_outdir(input_file)){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Creation of Output Directory failed\n"; - throw new std::exception(); - } - - // Initialize all the ffmpeg constructs - AVCodec, AVFormat, AVPacket. - av_register_all(); - avcodec_register_all(); - av_init_packet(&_packet); - - // Open the input file - AVFormatContext *format_context = NULL; - if (avformat_open_input(&format_context, input_file.c_str(), NULL, NULL) != 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed to open the input file\n"; - throw new std::exception(); - } - - // Retrieve stream information - if (avformat_find_stream_info(format_context,NULL) < 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed find stream parameters in the input file\n"; - throw new std::exception(); - } - - // Identify the video handle - int video_handle = -1; - AVCodecContext *temp_context = NULL; - for (int i = 0; i < format_context->nb_streams; i++) { - temp_context = format_context->streams[i]->codec; - if (temp_context->codec_type == AVMEDIA_TYPE_VIDEO) { - video_handle = i; - break; - } - } - if (video_handle == -1){ - std::cerr << __FILE__ << " : " << __LINE__ << - " No valid video handle identified in the input file\n"; - throw new std::exception(); - } - - // Get a pointer to the codec context for the video stream - AVCodecContext *codec_context = format_context->streams[video_handle]->codec; - // Find the decoder for the video stream - AVCodec *codec = avcodec_find_decoder(codec_context->codec_id); - if (codec == NULL){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Invalid video parameters in the input file\n"; - throw new std::exception(); - } - - // Inform the codec that we can handle truncated bitstreams - if (codec->capabilities & CODEC_CAP_TRUNCATED) - codec_context->flags |= CODEC_FLAG_TRUNCATED; - - // Initialize the identified video codec - if (avcodec_open2(codec_context, codec, NULL) < 0){ - std::cerr << __FILE__ << " : " << __LINE__ << - " Failed to initialize the video decoder\n"; - throw new std::exception(); - } - - // Based on the identified codec - initialize the histogram process - // and keyframe utilities. - initialize(codec_context); - - // Segment the video based on the motion score and identify - // scene changes. Process the segmented video and extract - // key frames. - ok = segmentation(format_context, codec_context, video_handle); - - // release the ffmpeg constructs. - avcodec_close(codec_context); - avformat_close_input(&format_context); - } catch (std::exception& e) { - std::cerr << __FILE__ << " : " << __LINE__<< " extract key frames failed: " << e.what() << std::endl; - exit(1); - } -#endif - return ok; -} diff --git a/plugins/scan-video/extract_keyframes.h b/plugins/scan-video/extract_keyframes.h deleted file mode 100644 index bbd8fba7..00000000 --- a/plugins/scan-video/extract_keyframes.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef _EXTRACT_KEYFRAME_H_ -#define _EXTRACT_KEYFRAME_H_ - - -#include "../src/bulk_extractor.h" -#include "histogram_process.h" - -extern "C" { -#include "libavcodec/avcodec.h" -#include "libavformat/avformat.h" -#include "libavutil/avutil.h" -#include "libswscale/swscale.h" -} -#include - -/// \class shot_segment extract_keyframes.h -/// \brief The class represents the boundaries of a video segment "shot" -/// - -class shot_segment{ -public: - // default constructor - shot_segment(); - // default destructor - ~shot_segment(); - - // the starting and ending histograms - cv::MatND _start_hist; - cv::MatND _end_hist; - - // the starting and ending presentation times (AVFrame::pts defined in avcodec/avcodec.h) - uint64_t _start_pos; - uint64_t _end_pos; - - // the starting and ending frame numbers. - uint64_t _start_frm; - uint64_t _end_frm; -}; - -/// \class extract_keyframes extract_keyframes.h -/// \brief The class implements all the methods needed to extract keyframes and identify scene changes. -/// - -class extract_keyframes { -public: - - // default constructor - extract_keyframes(); - - // default destructor - ~extract_keyframes(); - - /// \brief The main worker function. - /// \param (input_file) The input video file from which needs to be processed - /// \return the status of the function. - /// - /// This function extracts key frames and identifies scene changes for the given - /// input file. It initializes the ffmpeg constructs and also frees them accordingly. - /// - bool extract(std::string input_file); - - /// If the input file is in memory (sbuf, offset) then this function - /// saves the output file to the output folder (specified by the recorder) - /// and then invokes the overloaded function extract(std::string), to - /// extract key frames. - bool extract(const sbuf_t& sbuf, size_t offset, feature_recorder& recorder); - -private: - - /// \brief Decodes the compressed bitstream packet to AVFrame - /// \param (format_context) FFMPEG video decoder constructs (libavformat/avformat.h) - /// \param (codec_context) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// \param (video_stream) Video decoder handle. - /// \param (frame) Decoded output frame - /// \return the status of the function. - /// - bool next_frame(AVFormatContext *format_context, AVCodecContext *codec_context, int video_stream, AVFrame *frame); - - /// \brief Segments the video, calculates the motion score for each frame. extracts key frames and identifies scene changes. - /// \param (format_context) FFMPEG video decoder constructs (libavformat/avformat.h) - /// \param (codec_context) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// \param (video_stream) Video decoder handle. - /// \return the status of the function. - /// - bool segmentation(AVFormatContext *format_context, AVCodecContext *codec_context, int video_stream); - - /// \brief Initializes the key frame utilities and the histogram process methods. - /// \param (codec_context) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// - void initialize(const AVCodecContext *codec_context); - - /// \brief Creates the output directory as specified by the input file - /// The extracted keyframes & the scene_change.txt file will be saved - /// in this folder. - /// \param (name) The name of the input file, from which the directory name is - /// generated - /// \return the status of the function - /// - bool create_outdir(const std::string name); - - // Instance of the histogram process interface. - histogram_process* _hp; - // Instance of the keyframe utilities. - keyframe_utils _util; - - //Instance of FFMPEG video decoder constructs - AVPacket (libavcodec/avcodec.h) - AVPacket _packet; - // Tracks the initialization process for the AVPacket - bool _firsttime; - - //output directory name. - std::string _dir; - -}; - -#endif \ No newline at end of file diff --git a/plugins/scan-video/fix_mp4.cpp b/plugins/scan-video/fix_mp4.cpp deleted file mode 100644 index 4454b005..00000000 --- a/plugins/scan-video/fix_mp4.cpp +++ /dev/null @@ -1,970 +0,0 @@ -#include "fix_mp4.h" - -#include -#include -#include -#include - -using namespace std; -using namespace isomf; - -// Scanner return status -typedef enum { - SCANNER_STATUS_FAILURE = -1, - SCANNER_STATUS_OK = 0, - SCANNER_STATUS_LEAF -}SCANNER_STATUS; - -// List of Keywords -const char fix_mp4::ATOM_NAMES[NO_OF_ATOMS ][LENGTH_OF_ATOM_NAME] = { - {'m', 'd', 'a', 't'}, {'m', 'o', 'o', 'v'}, {'m', 'v', 'h', 'd'}, {'h', 'd', 'l', 'r'}, {'m', 'd', 'h', 'd'}, - {'m', 'd', 'i', 'a'}, {'t', 'k', 'h', 'd'}, {'t', 'r', 'a', 'k'}, {'s', 't', 'b', 'l'}, {'s', 't', 'c', 'o'}, - {'s', 't', 's', 'z'}, {'s', 't', 's', 'c'}, {'c', 'o', '6', '4'}, {'u', 'd', 't', 'a'}, {'e', 'd', 't', 's'}, - {'f', 'r', 'e', 'e'}, {'m', 'i', 'n', 'f'}, {'s', 't', 'd', 'p'}, {'s', 't', 's', 'd'}, {'e', 'l', 's', 't'}, - {'s', 't', 's', 'h'}, {'s', 't', 's', 's'}, {'s', 't', 't', 's'}, {'s', 't', 'z', '2'}, {'w', 'i', 'd', 'e'}, - {'p', 'n', 'o', 't'}, {'a', 'l', 'b', 'm'}, {'a', 'u', 't', 'h'}, {'b', 'p', 'c', 'c'}, {'b', 'x', 'm', 'l'}, - {'c', 'c', 'i', 'd'}, {'c', 'd', 'e', 'f'}, {'c', 'l', 's', 'f'}, {'c', 'm', 'a', 'p'}, {'c', 'o', 'l', 'r'}, - {'c', 'p', 'r', 't'}, {'c', 'r', 'h', 'd'}, {'c', 't', 't', 's'}, {'c', 'v', 'r', 'u'}, {'d', 'c', 'f', 'D'}, - {'d', 'r', 'e', 'f'}, {'d', 's', 'c', 'p'}, {'f', 'r', 'm', 'a'}, {'g', 'n', 'r', 'e'}, {'g', 'r', 'p', 'i'}, - {'h', 'm', 'h', 'd'}, {'i', 'c', 'n', 'u'}, {'i', 'h', 'd', 'r'}, {'i', 'i', 'n', 'f'}, {'i', 'l', 'o', 'c'}, - {'i', 'm', 'i', 'f'}, {'i', 'n', 'f', 'u'}, {'i', 'o', 'd', 's'}, {'i', 'p', 'h', 'd'}, {'i', 'p', 'm', 'c'}, - {'i', 'p', 'r', 'o'}, {'j', 'p', '2', 'c'}, {'j', 'p', '2', 'h'}, {'j', 'p', '2', 'i'}, {'k', 'y', 'w', 'd'}, - {'p', 'n', 'o', 't'}, {'l', 'o', 'c', 'i'}, {'l', 'r', 'c', 'u'}, {'m', '7', 'h', 'd'}, {'m', 'a', 't', 't'}, - {'m', 'd', 'r', 'i'}, {'m', 'e', 'h', 'd'}, {'m', 'e', 't', 'a'}, {'m', 'f', 'h', 'd'}, {'m', 'f', 'r', 'a'}, - {'m', 'f', 'r', 'o'}, {'m', 'j', 'h', 'd'}, {'m', 'o', 'o', 'f'}, {'m', 'v', 'e', 'x'}, {'n', 'm', 'h', 'd'}, - {'o', 'c', 'h', 'd'}, {'o', 'd', 'a', 'f'}, {'o', 'd', 'd', 'a'}, {'o', 'd', 'h', 'd'}, {'o', 'd', 'h', 'e'}, - {'o', 'd', 'r', 'b'}, {'o', 'd', 'r', 'm'}, {'o', 'd', 't', 't'}, {'o', 'h', 'd', 'r'}, {'p', 'a', 'd', 'b'}, - {'p', 'c', 'l', 'r'}, {'p', 'd', 'i', 'n'}, {'p', 'e', 'r', 'f'}, {'p', 'i', 't', 'm'}, {'r', 'e', 's', 'c'}, - {'k', 'm', 'a', 't'}, {'r', 'e', 's', 'd'}, {'r', 't', 'n', 'g'}, {'s', 'b', 'g', 'p'}, {'s', 'c', 'h', 'i'}, - {'s', 'c', 'h', 'm'}, {'s', 'd', 'e', 'p'}, {'s', 'd', 'h', 'd'}, {'s', 'd', 't', 'p'}, {'s', 'd', 'v', 'p'}, - {'s', 'g', 'p', 'd'}, {'s', 'i', 'n', 'f'}, {'s', 'k', 'i', 'p'}, {'s', 'm', 'h', 'd'}, {'s', 'u', 'b', 's'}, - {'t', 'f', 'h', 'd'}, {'t', 'f', 'r', 'a'}, {'t', 'i', 't', 'l'}, {'t', 'r', 'a', 'f'}, {'t', 'r', 'e', 'f'}, - {'t', 'r', 'e', 'x'}, {'t', 'r', 'u', 'n'}, {'d', 'i', 'n', 'f'}, {'t', 's', 'e', 'l'}, {'u', 'i', 'n', 'f'}, - {'u', 'l', 's', 't'}, {'u', 'u', 'i', 'd'}, {'v', 'm', 'h', 'd'}, {'y', 'r', 'r', 'c'}, {'c', 'l', 'i', 'p'}, - {'c', 'r', 'g', 'n'}, {'c', 't', 'a', 'b'}, {'i', 'm', 'a', 'p'}, {'l', 'o', 'a', 'd'}, {'l', 'g', 'p', 'n'}, - {'l', 'g', 't', 'n'} -}; - -fix_mp4::fix_mp4(){ - - o = NULL; - output_file_size = 0; - - _moov.num_tracks = 0; - _moov.trak.clear(); - _moov.offset = 0; - _moov.size = 0; - - _mdat.offset = _mdat.size = 0; - reset(_tk); - _stsd = NULL; -} - -fix_mp4::~fix_mp4(){ - _moov.num_tracks = 0; - _moov.trak.clear(); - reset(_tk); - release_output_file(); - -} - -bool fix_mp4::release_output_file(){ - if(NULL != o){ - delete []o; - o = NULL; - output_file_size = 0; - } - return true; -} - -void fix_mp4::reset(trak_box &tk){ - _tk.self.offset = _tk.tkhd.self.offset = _tk.mdia.self.offset = _tk.mdia.mdhd.self.offset = _tk.mdia.hdlr.offset = - _tk.mdia.minf.self.offset = _tk.mdia.minf.vmhd.offset = _tk.mdia.minf.dinf.self.offset = - _tk.mdia.minf.dinf.dref.offset = _tk.mdia.minf.stbl.self.offset = _tk.mdia.minf.stbl.stsd.self.offset = - _tk.mdia.minf.stbl.stsd.codec.offset = _tk.mdia.minf.stbl.stts.offset = _tk.mdia.minf.stbl.stss.offset = - _tk.mdia.minf.stbl.stsc.offset = _tk.mdia.minf.stbl.stsz.offset = _tk.mdia.minf.stbl.stco.offset = 0; - - _tk.self.present = _tk.tkhd.self.present = _tk.mdia.self.present = _tk.mdia.mdhd.self.present = _tk.mdia.hdlr.present = - _tk.mdia.minf.self.present = _tk.mdia.minf.vmhd.present = _tk.mdia.minf.dinf.self.present = - _tk.mdia.minf.dinf.dref.present = _tk.mdia.minf.stbl.self.present = _tk.mdia.minf.stbl.stsd.self.present = - _tk.mdia.minf.stbl.stsd.codec.present = _tk.mdia.minf.stbl.stts.present = _tk.mdia.minf.stbl.stss.present = - _tk.mdia.minf.stbl.stsc.present = _tk.mdia.minf.stbl.stsz.present = _tk.mdia.minf.stbl.stco.present = false; - _tk.mdia.minf.stbl.stsd.children.clear(); - _tk.mdia.minf.stbl.stsd.name.clear(); - - release_output_file(); - -} - -bool fix_mp4::reconstruct_stsd(unsigned int width, unsigned int height, CODEC_TYPE ct){ - - if(0 == width || 0 == height){ - std::cerr << __FILE__ << ":" << __LINE__ << "Invalid input parameters\n"; - return false; - } - /// The "stsd" box holds codec initialization parameters. Reconstruct according to codec type. - switch(ct) { - case CODEC_AVC: - _stsd = box_factory::get_avc_stsd(width, height); - break; - case CODEC_MP4V: - _stsd = box_factory::get_mp4v_stsd(width, height); - break; - case CODEC_S263: - _stsd = box_factory::get_h263_stsd(width, height); - break; - case CODEC_MJPG: - case CODEC_AMR: - case CODEC_MP4A: - case NO_CODEC: - default: return false; - } - return true; -} - -size_t fix_mp4::write_stsd(size_t index){ - // write stsd - size_t sz = _stsd->size(); - size_t nb = _stsd->write((char *)(o + index), sz); - fix_mp4::write_big_endian_int32(sz, o, index, output_file_size); - return sz; -} - -bool fix_mp4::reconstruct_stsz(const unsigned char *s, size_t l, CODEC_TYPE primary, CODEC_TYPE secondary, std::vector &stsz_table){ - size_t index = 0; - if((s == NULL) || (l == 0) || (_moov.num_tracks != _moov.trak.size()) || (_mdat.offset + _mdat.size > l)){ - std::cerr << __FILE__ << ":" << __LINE__ << "Invalid input parameters\n"; - return false; - } - - stsz_table.clear(); - size_t primary_entry = 0, sec_entry = 0, next_entry = 0, table_entry = 0; - index = _mdat.offset; - bool do_sec = secondary != NO_CODEC; - for(;index < _mdat.offset + _mdat.size; ){ - // get offset of the primary codec. - if(!get_offset(s, l, index, primary, primary_entry)) - break; - // get the next offset of the primary codec - if(!get_offset(s, l, (primary_entry + 1), primary, next_entry)) - break; - // get the offset of the secondary codec - if(do_sec){ - if(!get_offset(s, l, index, secondary, sec_entry)) - break; - } - - // we can have consecutive samples from the same codec type. to calculate the sample sizes, use the value that is the closest. - // the interleaving process need not be uniform. - if(do_sec && (sec_entry < next_entry)){ - table_entry = sec_entry - primary_entry; // interleaved samples - index = sec_entry + 1; - }else{ - table_entry = next_entry - primary_entry; // non-interleaved samples - index = primary_entry + 1; - } - stsz_table.push_back(table_entry); table_entry = 0; - } - - // Hack for "mp4a", since the codec does not have a per sample signature, we are skipping audio samples entirely. - // Since each sample has sufficient information for just one video frame and associated audio, no artifacts are - // introduced to the video. - if(1 == stsz_table.size()){ - index = _mdat.offset; - get_offset(s, l, index, secondary, sec_entry); - index = sec_entry + 1; - for(;index < _mdat.offset + _mdat.size; ){ - // get offset of the primary codec. - if(!get_offset(s, l, index, primary, primary_entry)) - break; - // get the next offset of the primary codec - if(!get_offset(s, l, (primary_entry + 1), primary, next_entry)) - break; - - // we can have consecutive samples from the same codec type. to calculate the sample sizes, use the value that is the closest. - // the interleaving process need not be uniform. - - table_entry = next_entry - primary_entry; // non-interleaved samples - index = primary_entry + 1; - stsz_table.push_back(table_entry); table_entry = 0; - } - - } - - return true; -} - -bool fix_mp4::identify_moov_tree(const unsigned char *s, size_t l){ - size_t index = 0, size = 0; - size_t moov_idx = 0, mdat_idx = 0; - bool moov = false, mdat = false; - - for(;((index < l - 0x8) && !(moov && mdat));){ - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - - if( memcmp((s + index + LENGTH_SIZE), ATOM_NAMES[1], LENGTH_OF_ATOM_NAME) == 0){ - _moov.offset = moov_idx = index; - moov = true; - }else if( memcmp((s + index + LENGTH_SIZE), ATOM_NAMES[0], LENGTH_OF_ATOM_NAME) == 0){ - _mdat.offset = mdat_idx = index; - _mdat.size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - mdat = true; - } - if((size <= 0 )){ - break; - } - index += size; - } - - // Reconstruction is possible only if "moov" occurs after "mdat" and start of "moov" is recovered. - if((mdat_idx > moov_idx) || (!mdat ) || (!moov)) - return false; - - size = (s[moov_idx] << 24) | (s[moov_idx + 1] << 16) | (s[moov_idx + 2] << 8) | (s[moov_idx + 3]); - if((moov_idx + size) > l){ - // Proceed even if the expected size is greater than actual size, Since we know the file is incomplete/partial - _moov.offset = moov_idx; - _moov.size = size; - // parse the "moov" tree and identify which boxes are missing. - parse_moov((s + moov_idx), 0, size); - } - return true; -} - -bool fix_mp4::parse_moov(const unsigned char *p, size_t offset, size_t total_bytes){ - size_t index = 0, size = 0; - bool is_found = false; - const unsigned char *s = p + offset; - - if(total_bytes == 0) - return true; - // leaf atom check - if(index < total_bytes - 0x8){ - is_found = false; - for(int i = 0; i < NO_OF_ATOMS; ++i){ - if( memcmp((s + index + LENGTH_SIZE), ATOM_NAMES[i], LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - break; - } - } - if(is_found == false){ - return true; - } - }else { - return true; - } - - int curr_trak = _moov.num_tracks - 1; - for(;index < total_bytes - 0x8;){ - - if( memcmp((s + index + LENGTH_SIZE), "moov", LENGTH_OF_ATOM_NAME) == 0){ - //_moov.self.offset = index + offset; _moov.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "mvhd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.mvhd.offset = index + offset + offset; _moov.mvhd.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "trak", LENGTH_OF_ATOM_NAME) == 0){ - reset(_tk); - _tk.self.offset = index + offset; _tk.self.present = true; - _moov.trak.push_back(_tk); - curr_trak = _moov.num_tracks; - ++_moov.num_tracks; - }else { - if(curr_trak < _moov.num_tracks){ - if(memcmp((s + index + LENGTH_SIZE), "tkhd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].tkhd.self.offset = index + offset; - _moov.trak[curr_trak].tkhd.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "mdia", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.self.offset = index + offset; - _moov.trak[curr_trak].mdia.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "mdhd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.mdhd.self.offset = index + offset; - _moov.trak[curr_trak].mdia.mdhd.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "hdlr", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.hdlr.offset = index + offset; - _moov.trak[curr_trak].mdia.hdlr.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "minf", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.self.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "vmhd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.vmhd.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.vmhd.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "smhd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.smhd.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.smhd.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "dinf", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.dinf.self.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.dinf.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "dref", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.dinf.dref.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.dinf.dref.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stbl", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.self.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stsd", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsd.self.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsd.self.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stts", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stts.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stts.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stss", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stss.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stss.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stsc", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsc.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsc.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stsz", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsz.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsz.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "stco", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stco.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stco.present = true; - }else if(memcmp((s + index + LENGTH_SIZE), "mp4v", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.present = true; - _tk.mdia.minf.stbl.stsd.name.assign("mp4v"); - // child esds - }else if(memcmp((s + index + LENGTH_SIZE), "mp4a", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.present = true; - _tk.mdia.minf.stbl.stsd.name.assign("mp4a"); - //child esds - }else if(memcmp((s + index + LENGTH_SIZE), "s263", LENGTH_OF_ATOM_NAME) == 0){ - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.offset = index + offset; - _moov.trak[curr_trak].mdia.minf.stbl.stsd.codec.present = true; - _tk.mdia.minf.stbl.stsd.name.assign("s263"); - //child d263 - }else{ - } - }else{ - } - } - - - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(size < 0 ) { - return false; - }else if (size == 1 ){ - //std::cerr << "64 bit atom size. Add support\n"; - }else if (size == 0 ){ - return false; - } - // recursively parse the tree upto the child atoms. we validate the entire structure. - if(parse_moov(p, (offset + index + LENGTH_OF_ATOM_NAME + LENGTH_SIZE), (size - LENGTH_OF_ATOM_NAME - LENGTH_SIZE))){ - index += size; - }else{ - return false; - } - } - return true; -} - -bool fix_mp4::reconstruct_stco(const unsigned char *s, size_t l, CODEC_TYPE ct, std::vector &stco_table){ - size_t index = 0; - - // Check if input parameters are valid - if((s == NULL) || (l == 0) || (_moov.num_tracks != _moov.trak.size()) || (_mdat.offset + _mdat.size > l)){ - std::cerr << __FILE__ << ":" << __LINE__ << "Invalid input parameters\n"; - return false; - } - - //Since we won't know the number of entries, calculate the entries and add to vector. Translate vector entries to atom later - stco_table.clear(); - size_t table_entry = 0; - index = _mdat.offset; - for(;index < _mdat.offset + _mdat.size; ){ - if(!get_offset(s, l, index, ct, table_entry)) - break; - index = table_entry + 1; // +1 moves the pointer forward, s.t. the same signature is not picked up agn - stco_table.push_back(table_entry); table_entry = 0; - } - - return true; -} - -bool fix_mp4::identify_codecs(const unsigned char *s, size_t l, std::vector &codec_type){ - // This will look through the mdat box and identify the embedded codecs. - // The output container will contain the codec signatures. - - // Go to the mdat box - if(_mdat.offset + _mdat.size > l){ - std::cerr << __FILE__ << ":" << __LINE__ << "Invalid input parameters\n"; - return false; - } - - size_t index = 0; - bool video_found = false, audio_found = false; - // search file signatures. - for(index = 0; ((index < _mdat.size - 0xF) && !(video_found && audio_found)); ++index){ - - if(!video_found && ((s[index] == 0) && (s[index + 1] == 0) && (s[index + 2] == 0) && (s[index + 4] == 0x6))){ - if((s[index + 3] == 0x0B) || (s[index + 3] == 0x0C)){ - // Add AVC to output - codec_type.push_back(CODEC_AVC); - video_found = true; - } - }else if (!video_found && ((s[index] == 0xff) && (s[index + 1] == 0xd9) && (s[index + 2] == 0xFF) && (s[index + 3] == 0xDB))){ - // Add MJPG to output - codec_type.push_back(CODEC_MJPG); video_found = true; - - }else if (!video_found && ((s[index] == 0x0) && (s[index + 1] == 0x0) && (s[index + 2] == 0x01) && ((s[index + 3] == 0xB3) ||(s[index + 3] == 0xB6)))){ - // Add MP4V to output - codec_type.push_back(CODEC_MP4V); video_found = true; - - }else if (!video_found && ((s[index] == 0x0) && (s[index + 1] == 0x0) && (s[index + 2] >= 0x80) && (s[index + 2] < 0x84))) { - // Add H263 to output - codec_type.push_back(CODEC_S263); video_found = true; // 3byte signature, high likelihood of false positives - ///if 0x00000000 are found immediately after, then the signature is not counted. use this for offset calc - - }else if (!audio_found && (((s[index] == 0xde) && (s[index + 1] == 0x04) && (s[index + 2] == 0x0) && (s[index + 3] == 0x0) - && (s[index + 4] == 0x6c) && (s[index + 5] == 0x69) && (s[index + 6] == 0x62) && (s[index + 7] == 0x66) - && (s[index + 8] == 0x61) && (s[index + 9] == 0x61) && (s[index + 10] == 0x63)) || - ((s[index] == 0x21) && (s[index + 1] == 0x47) && (s[index + 2] == 0xFE) && (s[index + 3] == 0xFF)))){ - // Add MP4A to output DE04 00 00 "libfaac" - codec_type.push_back(CODEC_MP4A); audio_found = true; - - }else if (!audio_found && ((s[index] == 0x3c) && ((s[index + 1] == 0x91) || (s[index + 1] == 0x48) || - (s[index + 1] == 0x55)) && (s[index + 10] == 0x01) && (s[index + 11] == 0xE7))){ - // Add AMR to output - codec_type.push_back(CODEC_AMR); audio_found = true; - - } - } - - if(codec_type.empty()) return false; - return true; -} - -bool fix_mp4::get_avc_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature for AVC - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0; ((input_offset + index < _mdat.offset + _mdat.size - 0x4)); ++index){ - if((s[index] == 0) && (s[index + 1] == 0) && (s[index + 2] == 0) && (s[index + 4] == 0x6)){ - if((s[index + 3] == 0x0B) || (s[index + 3] == 0x0C) || (s[index + 3] == 0x15)){ - output_offset = input_offset + index; - break; - } - } - } - if(0 == output_offset) return false; - - return true; - -} - -bool fix_mp4::get_mp4v_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature for MP4V - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0; ((input_offset + index < _mdat.offset + _mdat.size - 0x4)); ++index){ - if((s[index] == 0x0) && (s[index + 1] == 0x0) && (s[index + 2] == 0x01) && ((s[index + 3] == 0xB3) ||(s[index + 3] == 0xB6))){ - output_offset = input_offset + index; - break; - } - } - if(0 == output_offset) return false; - - return true; - -} - -bool fix_mp4::get_s263_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature S263 - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0; ((input_offset + index < _mdat.offset + _mdat.size - 0x8)); ++index){ - if((s[index] == 0x0) && (s[index + 1] == 0x0) && (s[index + 2] >= 0x80) && (s[index + 2] < 0x84)){ - if((s[index + 4] == 0x0) && (s[index + 5] == 0x0) && (s[index + 6] == 0x0) && (s[index + 7] == 0x0)){ - continue; - } - output_offset = input_offset + index; - break; - } - } - if(0 == output_offset) - return false; - - return true; - -} - -bool fix_mp4::get_mjpg_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature MJPG - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0; ((input_offset + index < _mdat.offset + _mdat.size - 0x4)); ++index){ - if((s[index] == 0xff) && (s[index + 1] == 0xd8) && (s[index + 2] == 0xff) && (s[index + 3] == 0xdb)){ - output_offset = input_offset + index; - break; - } - } - if(0 == output_offset) return false; - - return true; -} - -bool fix_mp4::get_amr_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature AMR - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0; ((input_offset + index < _mdat.offset + _mdat.size - 0xC)); ++index){ - if((s[index] == 0x3c) && ((s[index + 1] == 0x91) || (s[index + 1] == 0x48) || - (s[index + 1] == 0x55)) && (s[index + 10] == 0x01) && (s[index + 11] == 0xE7)){ - output_offset = input_offset + index; - break; - } - } - if(0 == output_offset) return false; - - return true; -} - -bool fix_mp4::get_mp4a_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset){ - // from the given offset, it calculates the offset to the next signature MP4A - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - const unsigned char *s = p + input_offset; - size_t index; - output_offset = 0; - for(index = 0;((input_offset + index < _mdat.offset + _mdat.size - 0xB)); ++index){ - if(((s[index] == 0xde) && (s[index + 1] == 0x04) && (s[index + 2] == 0x0) && (s[index + 3] == 0x0) - && (s[index + 4] == 0x6c) && (s[index + 5] == 0x69) && (s[index + 6] == 0x62) && (s[index + 7] == 0x66) - && (s[index + 8] == 0x61) && (s[index + 9] == 0x61) && (s[index + 10] == 0x63)) || - ((s[index] == 0x21) && (s[index + 1] == 0x47) && (s[index + 2] == 0xFE) && (s[index + 3] == 0xFF))){ - output_offset = input_offset + index; - break; - } - } - if(0 == output_offset) - return false; - return true; -} - -bool fix_mp4::get_offset(const unsigned char *s, size_t l, size_t input_offset, CODEC_TYPE ct, size_t &output_offset){ - - // from the given offset, it calculates the offset to the next signature. - if(( input_offset > l ) || (input_offset > (_mdat.size + _mdat.offset))) - return false; - - switch(ct) { - case CODEC_AVC: - return get_avc_offset(s, l, input_offset, output_offset); - case CODEC_MP4V: - return get_mp4v_offset(s, l, input_offset, output_offset); - case CODEC_S263: - return get_s263_offset(s, l, input_offset, output_offset); - case CODEC_MJPG: - return get_mjpg_offset(s, l, input_offset, output_offset); - case CODEC_AMR: - return get_amr_offset(s, l, input_offset, output_offset); - case CODEC_MP4A: - return get_mp4a_offset(s, l, input_offset, output_offset); - case NO_CODEC: - default: break; - } - return true; -} - -bool fix_mp4::parse_tkhd(const unsigned char *s, size_t l, unsigned int trak_id){ - - if(trak_id >= _moov.num_tracks) - return false; - tkhd_box *curr = &(_moov.trak[trak_id].tkhd); - - if((!curr->self.present) || (curr->self.offset + _moov.offset > l)) - return false; - - size_t index = curr->self.offset + _moov.offset; - size_t length = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(index + length > l) - return false; - curr->size = length; - index += (LENGTH_OF_ATOM_ENTRY + LENGTH_OF_ATOM_ENTRY); - curr->version = s[index]; - - // Reference - ISO_14496-12_ISOBMFF.pdf : 8.3.2 Track Header Box - // version 0, has 32 bit representation for time - index += 74; - - if(curr->version){ - // version 1, has 64 bit representation for time - index += 12; - } - - curr->width = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - index += LENGTH_OF_ATOM_ENTRY; - curr->height = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - - return true; -} - - -bool fix_mp4::parse_mdhd(const unsigned char *s, size_t l, unsigned int trak_id){ - - if(trak_id >= _moov.num_tracks) - return false; - mdhd_box *curr = &(_moov.trak[trak_id].mdia.mdhd); - - if((!curr->self.present) || (curr->self.offset + _moov.offset > l)) - return false; - - size_t index = curr->self.offset + _moov.offset; - size_t length = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - curr->size = length; - if(index + length > l) - return false; - - curr->size = length; - index += (LENGTH_OF_ATOM_ENTRY + LENGTH_OF_ATOM_ENTRY); - curr->version = s[index]; - uint64_t lsb = 0, msb = 0; - if(curr->version){ - // version 1, has 64 bit representation for time - index += 24; //1+3+8+8+4 - msb = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - index += 4; - lsb = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - curr->duration = ((msb & 0x00000000ffffffffL) << 32) | lsb; - - }else{ - // version 0, has 32 bit representation for time - index += 16; //1+3+4+4+4 - curr->duration = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - } - return true; -} - -bool fix_mp4::write_moov(const unsigned char *s, size_t total_bytes, std::vector &stco_table, std::vector &stsz_table){ - - size_t length_to_mdhd = _moov.offset + _moov.trak[0].mdia.mdhd.self.offset + _moov.trak[0].mdia.mdhd.size; - if(NULL == s || 0 == total_bytes || NULL == _stsd){ - std::cerr << __FILE__ << ":" << __LINE__ << " Input parameters are invalid \n"; - return false; - } - - // Calculate output file length - output_file_size = 0; - if(1 > _moov.num_tracks) - return false; - - // This includes only one of the reconstructed traks - // Since the current trak reconstruction is possible if and only if the current trak's tkhd and mdia.mdhd boxes are present. - // start point is set at the offset and size of the mdhd box for the first trak; - - // default atom sizes. - const size_t HDLR_BOX_SZ = 45, VMHD_BOX_SZ = 20, DINF_BOX_SZ = 36, STTS_BOX_SZ = 24, STSC_BOX_SZ = 28; ; - size_t stco_length = LENGTH_SIZE + LENGTH_OF_ATOM_NAME + LENGTH_OF_ATOM_ENTRY + LENGTH_OF_ATOM_ENTRY + (LENGTH_OF_ATOM_ENTRY * stco_table.size()); - size_t stsz_length = LENGTH_SIZE + LENGTH_OF_ATOM_NAME + LENGTH_OF_ATOM_ENTRY + LENGTH_OF_ATOM_ENTRY + LENGTH_OF_ATOM_ENTRY + (LENGTH_OF_ATOM_ENTRY * stsz_table.size()); - // Choose stsd - size_t stsd_box_sz = _stsd->size(); - size_t index = _moov.offset; - // If original file contains stsd, copy it over. Dont reconstruct - if(_moov.trak[0].mdia.minf.stbl.stsd.self.present){ - index += _moov.trak[0].mdia.minf.stbl.stsd.self.offset; - stsd_box_sz = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - } - - size_t stbl_sz = stsd_box_sz + stco_length + stsz_length + STTS_BOX_SZ + STSC_BOX_SZ + LENGTH_OF_ATOM_NAME + LENGTH_SIZE; - - _moov.trak[0].mdia.minf.size = LENGTH_OF_ATOM_NAME + LENGTH_SIZE + stbl_sz + DINF_BOX_SZ + VMHD_BOX_SZ; - - output_file_size = _moov.offset + _moov.trak[0].mdia.mdhd.self.offset + _moov.trak[0].mdia.mdhd.size + HDLR_BOX_SZ + _moov.trak[0].mdia.minf.size; - // Allocate memory - o = new (std::nothrow) unsigned char[output_file_size]; - if(NULL == o || length_to_mdhd >= output_file_size) return false; - - // Copy data until the mdhd box (ftyp, mdat, moov.tkhd, moov.trak.mdia.mdhd) - if(length_to_mdhd > output_file_size) return false; - memcpy(o, s, length_to_mdhd); - - // we need to correct the moov size, trak size and mdia size as per the new file size - size_t mdia_sz = LENGTH_OF_ATOM_NAME + LENGTH_SIZE + _moov.trak[0].mdia.mdhd.size + _moov.trak[0].mdia.minf.size + HDLR_BOX_SZ; - size_t trak_sz = LENGTH_OF_ATOM_NAME + LENGTH_SIZE + _moov.trak[0].tkhd.size + mdia_sz; - size_t moov_sz = output_file_size - _moov.offset; - - index = _moov.offset; - if(!fix_mp4::write_big_endian_int32(moov_sz, o, index, output_file_size)) return false; - - index = _moov.offset + _moov.trak[0].self.offset; - if(!fix_mp4::write_big_endian_int32(trak_sz, o, index, output_file_size)) return false; - - index = _moov.offset + _moov.trak[0].mdia.self.offset; - if(!fix_mp4::write_big_endian_int32(mdia_sz, o, index, output_file_size)) return false; - - index = length_to_mdhd; - - // write hdlr - const unsigned char hdlr_arr[HDLR_BOX_SZ] = { 0x00, 0x00, 0x00, 0x2D, 0x68, 0x64, 0x6C, 0x72, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x64, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x56, 0x69, 0x64, 0x65, 0x6F, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x72 - }; - if(index + HDLR_BOX_SZ > output_file_size) return false; - memcpy((o + index), hdlr_arr, HDLR_BOX_SZ); - index += HDLR_BOX_SZ; - - unsigned int kw = 0; - //write minf - if(!fix_mp4::write_big_endian_int32(_moov.trak[0].mdia.minf.size, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - kw = 0x6D696E66; //minf - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - // vmhd and dinf boxes - const size_t ARR_SZ = VMHD_BOX_SZ + DINF_BOX_SZ; - const unsigned char minf_arr[ARR_SZ] = { 0x00, 0x00, 0x00, 0x14, 0x76, 0x6D, 0x68, 0x64, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x64, 0x69, 0x6E, 0x66, 0x00, - 0x00, 0x00, 0x1C, 0x64, 0x72, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x0C, 0x75, 0x72, 0x6C, 0x20, 0x00, 0x00, 0x00, 0x01 - }; - if(index + ARR_SZ > output_file_size) return false; - memcpy((o + index), minf_arr, ARR_SZ); - index += ARR_SZ; - - //write stbl - if(!fix_mp4::write_big_endian_int32(_moov.trak[0].mdia.minf.size, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - kw = 0x7374626C; //stbl - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) - return false; - index += LENGTH_OF_ATOM_ENTRY; - - // write stsd - // If original file contains stsd, copy it over. Dont reconstruct - if(_moov.trak[0].mdia.minf.stbl.stsd.self.present){ - size_t input_index = _moov.offset + _moov.trak[0].mdia.minf.stbl.stsd.self.offset; - if((index + stsd_box_sz) > output_file_size) return false; - if((input_index + stsd_box_sz) > total_bytes) return false; - memcpy((o + index), (s + input_index), stsd_box_sz); - index += stsd_box_sz; - }else{ - size_t check = write_stsd(index); - if(0 == check) return false; - index += check; - } - // write stts: Implementation - The mdhd must be parsed and we need to have a "valid" value for the duration & stsz must be written out to know the number of samples. - // default implementation where all the samples have the same delta value. - - //if(trak_id >= _moov.num_tracks) - // return false; - size_t trak_id = 0; - - if(!fix_mp4::write_big_endian_int32(STTS_BOX_SZ, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - kw = 0x73747473; //stts - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(0, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int num_entries = 1; - if(!fix_mp4::write_big_endian_int32(num_entries, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int sample_count = stsz_table.size(); - if(!fix_mp4::write_big_endian_int32(sample_count, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int delta = static_cast (_moov.trak[trak_id].mdia.mdhd.duration * 1.0 / sample_count); - if(0 == delta) delta = 1; - if(!fix_mp4::write_big_endian_int32(delta, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - //write stsc - // 0000001C737473630000000000000001000000010000000100000001 - if(!fix_mp4::write_big_endian_int32(STSC_BOX_SZ, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - kw = 0x73747363; //stsc - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(0, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - num_entries = 1; - if(!fix_mp4::write_big_endian_int32(num_entries, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int first_chunk = 1; - if(!fix_mp4::write_big_endian_int32(first_chunk, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int samples_per_chunk = 1; - if(!fix_mp4::write_big_endian_int32(samples_per_chunk, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - unsigned int sample_description_index = 1; - if(!fix_mp4::write_big_endian_int32(sample_description_index, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - //write stsz - if(!fix_mp4::write_big_endian_int32(stsz_length, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - kw = 0x7374737A; //stsz - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(0, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(0, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - num_entries = stsz_table.size(); - if(!fix_mp4::write_big_endian_int32(num_entries, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - for(size_t i = 0; i < num_entries; ++i){ - if(!fix_mp4::write_big_endian_int32(stsz_table[i], o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - } - - // write stco - num_entries = stco_table.size(); - if(!fix_mp4::write_big_endian_int32(stco_length, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - kw = 0x7374636F; //stco - if(!fix_mp4::write_big_endian_int32(kw, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(0, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - if(!fix_mp4::write_big_endian_int32(num_entries, o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - - for(size_t i = 0; i < num_entries; ++i){ - if(!fix_mp4::write_big_endian_int32(stco_table[i], o, index, output_file_size)) return false; - index += LENGTH_OF_ATOM_ENTRY; - } - - return true; -} - -bool fix_mp4::write_to_file(const std::string& out_file_name){ - if(out_file_name.empty()) - return false; - - std::ofstream fp(out_file_name.c_str(), std::ios_base::out | std::ios_base::binary); - if(NULL == fp) - return false; - - fp.write((char*) o, output_file_size); - - bool ok = ! fp.bad(); - if (! ok) { - std::cerr << __FILE__ << ":" << __LINE__ << " Unable to create output file\n"; - return false; - } - - fp.close(); - release_output_file(); - return true; -} - -bool fix_mp4::do_fix(const sbuf_t& sbuf, size_t offset, feature_recorder& recorder){ - - unsigned char* s = (unsigned char*) (sbuf.buf + offset); - size_t len = sbuf.pagesize; - size_t l = len - offset; - const pos0_t &pos0 = sbuf.pos0; - std::string fpath = pos0.path; - - - if(!identify_moov_tree(s,l)){ - // parses the moov structure. If the mdat box occurs after the moov box, - // then there is nothing to reconstruct. - std::cerr << __FILE__ << ":" << __LINE__ << " Reconstruction for this file is not supported as mdat box occurs at the end of file\n"; - return false; - } - std::vector ct; - - // identify the embedded codec types. This is needed to reconstruct the tables - if(!identify_codecs(s,l, ct)){ - std::cerr << __FILE__ << ":" << __LINE__ << " Unsupported codec types embedded in video, Reconstruction failed\n"; - return false; - } - - size_t sz = ct.size(); - if(sz == 0){ - std::cerr << __FILE__ << ":" << __LINE__ << " Unsupported codec types embedded in video, Reconstruction failed\n"; - return false; - }else if(sz == 1) - ct.push_back(NO_CODEC); // no audio codec detected - - - // parse tkhd to identify the height and width - needed for "stsd" reconstruction - if(!parse_tkhd(s, l, 0)){ - std::cerr << __FILE__ << ":" << __LINE__ << " Invalid tkhd box - unable to calculate duration of the stream, Reconstruction failed\n"; - return false; - } - - // parse mdhd to identify the duration - needed for "stts" reconstruction - if(!parse_mdhd(s, l, 0)){ - std::cerr << __FILE__ << ":" << __LINE__ << " Invalid mdhd box - unable to calculate duration, height and width of the video stream, Reconstruction failed\n"; - return false; - } - - // Based on the identified codecs, reconstruct the tables. - if(!reconstruct_stsd(_moov.trak[0].tkhd.width, _moov.trak[0].tkhd.height, ct[0])){ - std::cerr << __FILE__ << ":" << __LINE__ << " Reconstruction of the stsd box failed, Invalid codec initialization parameters" << std::endl; - return false; - } - - std::vector stco, stsz; - if(!reconstruct_stco(s, l, ct[0], stco)){ - std::cerr << __FILE__ << ":" << __LINE__ << " Reconstruction of the stco box failed, Invalid index table" << std::endl; - return false; - } - - if(!reconstruct_stsz(s, l, ct[0], ct[1], stsz)){ - std::cerr << __FILE__ << ":" << __LINE__ << " Reconstruction of the stsz box failed, Invalid index table" << std::endl; - return false; - } - - if(!write_moov(s, l, stco, stsz)){ - std::cerr << __FILE__ << ":" << __LINE__ << "Failed to reconstruct playback information" << std::endl; - return false; - } - - std::stringstream ss_a, ss_b; - ss_a << recorder.name << "-p" << fpath << "-" << pos0.offset - << "-" << offset << "-" << rand() << "." << recorder.name; - - - std::string outfile_a = recorder.outdir + "/" + ss_a.str(); - set_file_name(outfile_a); - std::stringstream i; - i << "file_size: " << output_file_size << " height : " << _moov.trak[0].tkhd.height << - " width : " << _moov.trak[0].tkhd.width << " frame_count: " << stsz.size() <<" file_name: " ; - - if(!write_to_file(outfile_a)){ - std::cerr << __FILE__ << ":" << __LINE__ << "Failed to write reconstructed file to disk" << std::endl; - return false; - } - - // Record changes to output file. - recorder.write(pos0+offset, i.str(), ss_a.str()); - - return true; -} - - diff --git a/plugins/scan-video/fix_mp4.h b/plugins/scan-video/fix_mp4.h deleted file mode 100644 index 17b04cda..00000000 --- a/plugins/scan-video/fix_mp4.h +++ /dev/null @@ -1,279 +0,0 @@ -#ifndef INCLUDED_FIX_MP4 -#define INCLUDED_FIX_MP4 - -#include "isomf.h" -#include "isomf_factory.h" -#include "type_io.h" -#include "../src/bulk_extractor.h" - -#include -#include -#include -#include -#include - - -/// The below structures implement the hierarchical box structure for the ISO-MBFF (ISO_14496-12_ISOBMFF.pdf) - -typedef struct { - bool present; //Is the box present? - size_t offset; // Offset from the start of file -}box_id; - -typedef struct{ - box_id self; - box_id codec; - std::vector children; - std::string name; -}stsd_box; - - -typedef struct{ - box_id self; - stsd_box stsd; - box_id stts; - box_id stss; - box_id stsc; - box_id stsz; - box_id stco; -}stbl_box; - -typedef struct{ - box_id self; - box_id dref; -}dinf_box; - -typedef struct{ - box_id self; - size_t size; - box_id vmhd; - box_id smhd; - dinf_box dinf; - stbl_box stbl; -}minf_box; - -typedef struct{ - box_id self; - unsigned int version; - uint64_t duration; - size_t size; -}mdhd_box; - -typedef struct{ - box_id self; - mdhd_box mdhd; - box_id hdlr; - minf_box minf; -}mdia_box; - - -typedef struct{ - box_id self; - size_t size; - unsigned int version; - unsigned int height; - unsigned int width; -}tkhd_box; - -typedef struct{ - box_id self; - tkhd_box tkhd; - mdia_box mdia; -}trak_box; - -typedef struct{ - size_t num_tracks; - box_id mvhd; - std::vector trak; - size_t offset; - size_t size; -}moov_box; - -typedef struct{ - size_t offset; - size_t size; -}mdat_box; - -/// Supported Codec types -typedef enum { - NO_CODEC = -1, - CODEC_AVC = 0, - CODEC_MP4V, //1 - CODEC_S263, //2 - CODEC_MJPG, //3 - CODEC_AMR, //4 - CODEC_MP4A //5 -}CODEC_TYPE; - - -/// \class fix_mp4 fix_mp4.h -/// \brief The class implements all the methods needed to identify and reconstruct -/// missing playback information for MP4, MOV, 3G2, 3GP files -/// - -class fix_mp4{ - -public: - - /// Default Constructor - fix_mp4(); - - /// Default Destructor - ~fix_mp4(); - - /// \brief - main worker function, manages all the calls - /// Given a memory buffer, it identifies & estimates the missing playback chunks. - /// It writes the output file to folder specified by hte recorder. - bool do_fix(const sbuf_t& sbuf, size_t offset, feature_recorder& recorder); - - /// Write the new file to disk - unsigned char* get_output_file_ptr(){ return o;} - size_t get_output_file_size(){ return output_file_size;} - bool write_to_file(const std::string& o); - /// Frees the memory allocated for the newly reconstructed file. Called after write to disk - bool release_output_file(); - - /// Tracks the output file name. This is needed extract_keyframe module - void set_file_name(const std::string &o) { _outfile.assign(o);} - const std::string& get_file_name() {return _outfile;} - - /// Constants that define various box parameters - - static const int HEADER_SIZE = 4; - static const int LENGTH_SIZE = 4; - static const int LENGTH_OF_ATOM_NAME = 4; - static const int LENGTH_OF_ATOM_ENTRY = 4; - static const int NO_OF_ATOMS = 126; - static const char ATOM_NAMES[NO_OF_ATOMS][LENGTH_OF_ATOM_NAME]; - -private: - /// The below methods reconstruct the various "boxes" that are part of the playback information - "moov" box. - /// Each method reconstructs a different "box". They analyze the input media data "mdat" box and reconstruct - /// appropriate information. The embedded codec type is identified and used for the reconstruction. - - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - length of buffer - /// \param(ct) - embedded codec type - /// \param(stco_table) - index of chunk offset values. (output parameter) - /// \return - status of function - /// - bool reconstruct_stco(const unsigned char *s, size_t l, CODEC_TYPE ct, std::vector &stco_table); - - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - length of buffer - /// \param(primary, secondary) - embedded audio and video codec types - /// \param(stsz_table) - index of sample size values. (output parameter) - /// \return - status of function - /// - bool reconstruct_stsz(const unsigned char *s, size_t l, CODEC_TYPE primary, CODEC_TYPE secondary, std::vector &stsz_table); - - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - length of buffer - /// \param(ct) - embedded audio and video codec types - /// \return - status of function - /// - bool reconstruct_stsd(unsigned int width, unsigned int height, CODEC_TYPE ct); - - /// \brief This function identifies the location of the moov box and the mdat box - /// and determines if the file needs to be reconstructed. - /// \param(s) - Pointer to input buffer - /// \param(l) - length of buffer - /// \return - status of function - /// - bool identify_moov_tree(const unsigned char *s, size_t l); - - /// \brief This function parses the moov box identifies which boxes are present and which are missing - /// and notes the locations of the various boxes - /// \param(p) - Pointer to input buffer, mdat box - /// \param(offset) - offset to moov box within buffer - /// \param(total_bytes) - length of buffer - /// \return - status of function - /// - bool parse_moov(const unsigned char *p, size_t offset, size_t total_bytes); - - /// \brief This function parses the mdat box identifies the embedded audio codec - /// type and the embedded video codec type. - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - offset to moov box within buffer - /// \param(codec_type) - vector of codec ids - /// \return - status of function - /// - bool identify_codecs(const unsigned char *s, size_t l, std::vector &codec_type); - - /// \brief Within the mdat box, it calculates the offsets to the next media sample - /// from a given offset. Calls codec specific functions to identify signatures. - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - offset to moov box within buffer - /// \param(ct) - codec id - /// \param(output_offset) - offset to signature. - /// \return - status of function - /// - bool get_offset(const unsigned char *s, size_t l, size_t input_offset, CODEC_TYPE ct, size_t &output_offset); - /// Calculate offset to the next AVC signature - bool get_avc_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - /// Calculate offset to the next MP4V signature - bool get_mp4v_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - /// Calculate offset to the next MP4A signature - bool get_mp4a_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - /// Calculate offset to the next S263 signature - bool get_s263_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - /// Calculate offset to the next MJPG signature - bool get_mjpg_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - /// Calculate offset to the next AMR signature - bool get_amr_offset(const unsigned char *p, size_t l, size_t input_offset, size_t &output_offset); - - /// \brief parse tkhd box for the given track. This holds the "duration" for the stream - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - offset to moov box within buffer - /// \param(trak_id) - Track id - /// \return - status of function - /// - bool parse_tkhd(const unsigned char *s, size_t l, unsigned int trak_id); - - /// \brief parse mdhd box for the given track. This holds the "height" & "width" parameters - /// for the stream - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - offset to moov box within buffer - /// \param(trak_id) - Track id - /// \return - status of function - /// - bool parse_mdhd(const unsigned char *s, size_t l, unsigned int trak_id); - - /// \brief Write the newly reconstructed moov box to the output file. This function - /// merges all the individually reconstructed parameters into a single "moov" box - /// \param(s) - Pointer to input buffer, mdat box - /// \param(l) - offset to moov box within buffer - /// \param(stco_table) - Reconstructed stco table - /// \param(stsz_table) - Reconstructed stsz table - /// \return - status of function - /// - bool write_moov(const unsigned char *s, size_t total_bytes, std::vector &stco_table, std::vector &stsz_table); - - /// The reconstructed moov box has to be written to file as "big endian" 32-bit values. This function handles that operation. - static bool write_big_endian_int32(unsigned int i, unsigned char* s, size_t offset, size_t l){ - if(offset + 4 > l) // sizeof(unsigned int) = 4 - return false; - s[offset] = (i & 0xff000000) >> 24; - s[offset + 1] = (i & 0x00ff0000) >> 16; - s[offset + 2] = (i & 0x0000ff00) >> 8; - s[offset + 3] = (i & 0x000000ff); - return true; - } - - /// helper function for reconstruct_stsd() & write_moov() - size_t write_stsd(size_t index); - - /// resets all the values to for a given "trak" box. - void reset(trak_box &tk); - - /// Instances of the "moov", "trak", "mdat" and "stsd" box - moov_box _moov; - trak_box _tk; - mdat_box _mdat; - isomf::sample_description_box* _stsd; - - /// Output file buffer, size and file name. - unsigned char* o; - size_t output_file_size; - std::string _outfile; -}; -#endif diff --git a/plugins/scan-video/h264_model.cpp b/plugins/scan-video/h264_model.cpp deleted file mode 100644 index 1973301d..00000000 --- a/plugins/scan-video/h264_model.cpp +++ /dev/null @@ -1,1246 +0,0 @@ -#include -#include -#include - -#include "isomf.h" -#include "h264_model.h" - -using namespace std; - -namespace isomf -{ - -// class json_serializer - -json_serializer::json_serializer(stringstream& s, const string& type, unsigned ind) - :_s_type(type),_s_indent(ind),_s_stream(&s) -{ -} - -json_serializer::~json_serializer() -{ -} - -void json_serializer::indent() -{ - if (_s_stream) { - for (unsigned i = 0; i < _s_indent; i++) { - (*_s_stream) << " "; - } - } -} - -json_serializer& json_serializer::start_json() -{ - indent(); - (*_s_stream) << "{" << endl; - return *this; -} - -json_serializer& json_serializer::write_field(const string& name, int value) -{ - indent(); - (*_s_stream) << " \"" << name << "\":" << value << "," << endl; - return *this; -} - -json_serializer& json_serializer::write_array(const string& name, const int* array, unsigned length) -{ - if (array == NULL) { return *this; } - - indent(); - (*_s_stream) << " \"" << name << "\":" << "[ "; - for (unsigned i=0; istr(); -} - -// class parameter_set - -parameter_set::parameter_set() -{ -} - -parameter_set::~parameter_set() -{ -} - -parameter_set::parameter_set(const parameter_set& s) -{ - operator=(s); -} - -parameter_set& parameter_set::operator=(const parameter_set& s) -{ - return *this; -} - -size_t parameter_set::parse(const char* buf, size_t sz) -{ - return 0; -} - -size_t parameter_set::write(char* buf, size_t sz) const -{ - return 0; -} - -size_t parameter_set::size() -{ - char buf[MAX_SIZE]; - size_t nb = this->write(buf, MAX_SIZE); - //cerr << " >> parameter set written " << nb << " bytes.\n"; - return nb; -} - -// class chroma_format - -const chroma_format chroma_format::MONOCHROME(0,0,0); -const chroma_format chroma_format::YUV_420(1,2,2); -const chroma_format chroma_format::YUV_422(2,2,1); -const chroma_format chroma_format::YUV_444(3,1,1); - -chroma_format::chroma_format(int id, int sub_width, int sub_height) - :_id(id),_sub_width(sub_width),_sub_height(sub_height) -{ -} - -const chroma_format* chroma_format::from_id(int id) -{ - if (id == MONOCHROME.get_id()) { - return &MONOCHROME; - } else if (id == YUV_420.get_id()) { - return &YUV_420; - } else if (id == YUV_422.get_id()) { - return &YUV_422; - } else if (id == YUV_444.get_id()) { - return &YUV_444; - } - return NULL; -} - -string chroma_format::str(unsigned indent) const -{ - stringstream stream; - json_serializer s(stream, "chroma_format", indent); - s.start_json(); - s.write_field("id", _id); - s.write_field("sub_width", _sub_width); - s.write_field("sub_height", _sub_height); - s.end_json(); - return s.str(); -} - -// class VUI_parameters - -size_t VUI_parameters::parse(bitstream_reader& reader) -{ - size_t start = reader.read_bit_count(); - - //cerr << "VUI parameter starts at offset: " << start << endl; - - aspect_ratio_info_present_flag = reader.read_bool(); - if (aspect_ratio_info_present_flag) { - aspectratio = new aspect_ratio(); - aspectratio->parse(reader); - - if ((*aspectratio) == aspect_ratio::EXTENDED_SAR) { - sar_width = reader.read_bits(16); - sar_height = reader.read_bits(16); - } - } - - //cerr << "Position after SAR: "<parse(reader); - } - - //cerr << "Position after nal HRD: "<parse(reader); - } - - //cerr << "Position after vcl HRD: "<parse(reader); - } - - //cerr << "VUI ends at: "<write(writer); - if ((*aspectratio) == aspect_ratio::EXTENDED_SAR) { - writer.write_bits(sar_width, 16); - writer.write_bits(sar_height, 16); - } - } - //cerr << "Position after SAR: "<write(writer); - } else { - writer.write_bool(false); - } - //cerr << "Position after nal HRD: "<write(writer); - } else { - writer.write_bool(false); - } - //cerr << "Position after vcl HRD: "<write(writer); - } else { - writer.write_bool(false); - } - - //cerr << "VUI ends at: "<str(indent+1)); - } - if (vcl_HRD_params) { - s.write_object("vcl_HRD_params", vcl_HRD_params->str(indent+1)); - } - if (bitstreamrestriction) { - s.write_object("bitstreamrestriction", bitstreamrestriction->str(indent+1)); - } - if (aspectratio) { - s.write_object("aspectratio", aspectratio->str(indent+1)); - } - - s.end_json(); - return s.str(); -} - -// class HRD_parameters - -size_t HRD_parameters::parse(bitstream_reader& reader) -{ - size_t start = reader.read_bit_count(); - - //cerr << "HRD parameter starts at: " << start << endl; - - cpb_cnt_minus1 = reader.read_UE(); - //cerr << "Position after cpb_cnt_minus1: "<str(indent+1)); - } - - s.write_field("log2_max_frame_num_minus4", log2_max_frame_num_minus4); - s.write_field("log2_max_pic_order_cnt_lsb_minus4", log2_max_pic_order_cnt_lsb_minus4); - s.write_field("pic_height_in_map_units_minus1", pic_height_in_map_units_minus1); - s.write_field("pic_width_in_mbs_minus1", pic_width_in_mbs_minus1); - s.write_field("bit_depth_luma_minus8", bit_depth_luma_minus8); - s.write_field("bit_depth_chroma_minus8", bit_depth_chroma_minus8); - s.write_field("qpprime_y_zero_transform_bypass_flag", qpprime_y_zero_transform_bypass_flag); - s.write_field("profile_idc", profile_idc); - s.write_field("constraint_set_0_flag", constraint_set_0_flag); - s.write_field("constraint_set_1_flag", constraint_set_1_flag); - s.write_field("constraint_set_2_flag", constraint_set_2_flag); - s.write_field("constraint_set_3_flag", constraint_set_3_flag); - s.write_field("level_idc", level_idc); - s.write_field("seq_parameter_set_id", seq_parameter_set_id); - s.write_field("residual_color_transform_flag", residual_color_transform_flag); - s.write_field("offset_for_non_ref_pic", offset_for_non_ref_pic); - s.write_field("offset_for_top_to_bottom_field", offset_for_top_to_bottom_field); - s.write_field("num_ref_frames", num_ref_frames); - s.write_field("gaps_in_frame_num_value_allowed_flag", gaps_in_frame_num_value_allowed_flag); - s.write_field("frame_mbs_only_flag", frame_mbs_only_flag); - s.write_field("frame_cropping_flag", frame_cropping_flag); - s.write_field("frame_crop_left_offset", frame_crop_left_offset); - s.write_field("frame_crop_right_offset", frame_crop_right_offset); - s.write_field("frame_crop_top_offset", frame_crop_top_offset); - s.write_field("frame_crop_bottom_offset", frame_crop_bottom_offset); - s.write_array("offset_for_ref_frame", offset_for_ref_frame, - num_ref_frames_in_pic_order_cnt_cycle); - - if (vui_params) { - s.write_object("vui_params", vui_params->str(indent+1)); - } - - if (scalingmatrix) { - s.write_object("scalingmatrix", scalingmatrix->str(indent+1)); - } - - s.write_field("num_ref_frames_in_pic_order_cnt_cycle", num_ref_frames_in_pic_order_cnt_cycle); - s.write_field("reserved", reserved); - s.end_json(); - return s.str(); -} - -size_t sequence_parameter_set::parse(const char* buf, size_t sz) -{ - bitstream_reader r(buf, sz); - - profile_idc = r.read_bits(8); - constraint_set_0_flag = r.read_bool(); - constraint_set_1_flag = r.read_bool(); - constraint_set_2_flag = r.read_bool(); - constraint_set_3_flag = r.read_bool(); - reserved = r.read_bits(4); - - level_idc = r.read_bits(8); - seq_parameter_set_id = r.read_UE(); - - if (profile_idc == 100 || profile_idc == 110 || - profile_idc == 122 || profile_idc == 144) - { - chroma_format_idc = chroma_format::from_id(r.read_UE()); - if (chroma_format_idc == &chroma_format::YUV_444) { - residual_color_transform_flag = r.read_bool(); - } - - bit_depth_luma_minus8 = r.read_UE(); - bit_depth_chroma_minus8 = r.read_UE(); - qpprime_y_zero_transform_bypass_flag = r.read_bool(); - - bool seq_scaling_matrix_present = r.read_bool(); - if (seq_scaling_matrix_present) { - scalingmatrix = new scaling_matrix(); - scalingmatrix->parse(r); - } - } else { - chroma_format_idc = &chroma_format::YUV_420; - } - - log2_max_frame_num_minus4 = r.read_UE(); - pic_order_cnt_type = r.read_UE(); - - if (pic_order_cnt_type == 0) { - log2_max_pic_order_cnt_lsb_minus4 = r.read_UE(); - } else if (pic_order_cnt_type == 1) { - delta_pic_order_always_zero_flag = r.read_bool(); - offset_for_non_ref_pic = r.read_SE(); - offset_for_top_to_bottom_field = r.read_SE(); - num_ref_frames_in_pic_order_cnt_cycle = r.read_UE(); - offset_for_ref_frame = new int[num_ref_frames_in_pic_order_cnt_cycle]; - for (int i=0; iparse(r); - } - r.read_trailing_bits(); - - return r.read_count(); -} - -size_t sequence_parameter_set::write(char* buf, size_t sz) const -{ - bitstream_writer* writer = new bitstream_writer(buf, sz); - - writer->write_bits(profile_idc, 8); - writer->write_bool(constraint_set_0_flag); - writer->write_bool(constraint_set_1_flag); - writer->write_bool(constraint_set_2_flag); - writer->write_bool(constraint_set_3_flag); - writer->write_bits(reserved, 4); - - writer->write_bits(level_idc, 8); - writer->write_UE(seq_parameter_set_id); - - if (profile_idc == 100 || profile_idc == 110 || - profile_idc == 122 || profile_idc == 144) - { - writer->write_UE(chroma_format_idc->get_id()); - if ((*chroma_format_idc) == chroma_format::YUV_444) { - writer->write_bool(residual_color_transform_flag); - } - writer->write_UE(bit_depth_luma_minus8); - writer->write_UE(bit_depth_chroma_minus8); - writer->write_bool(qpprime_y_zero_transform_bypass_flag); - - if (scalingmatrix) { - writer->write_bool(true); - for (int i = 0; i < 8; i++) { - if (i < 6) { - if (scalingmatrix->scaling_list_4x4[i]) { - writer->write_bool(true); - scalingmatrix->scaling_list_4x4[i]->write(*writer); - } else { - writer->write_bool(false); - } - } else { - if (scalingmatrix->scaling_list_8x8[i - 6]) { - writer->write_bool(true); - scalingmatrix->scaling_list_8x8[i - 6]->write(*writer); - } else { - writer->write_bool(false); - } - } - } - } else { - writer->write_bool(false); - } - } - - writer->write_UE(log2_max_frame_num_minus4); - writer->write_UE(pic_order_cnt_type); - if (pic_order_cnt_type == 0) { - writer->write_UE(log2_max_pic_order_cnt_lsb_minus4); - } else if (pic_order_cnt_type == 1) { - writer->write_bool(delta_pic_order_always_zero_flag); - writer->write_SE(offset_for_non_ref_pic); - writer->write_SE(offset_for_top_to_bottom_field); - // size of offset_for_ref_frame array - writer->write_UE(num_ref_frames_in_pic_order_cnt_cycle); - for (int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) { - writer->write_SE(offset_for_ref_frame[i]); - } - } - writer->write_UE(num_ref_frames); - writer->write_bool(gaps_in_frame_num_value_allowed_flag); - writer->write_UE(pic_width_in_mbs_minus1); - writer->write_UE(pic_height_in_map_units_minus1); - writer->write_bool(frame_mbs_only_flag); - if (! frame_mbs_only_flag) { - writer->write_bool(mb_adaptive_frame_field_flag); - } - writer->write_bool(direct_8x8_inference_flag); - writer->write_bool(frame_cropping_flag); - if (frame_cropping_flag) { - writer->write_UE(frame_crop_left_offset); - writer->write_UE(frame_crop_right_offset); - writer->write_UE(frame_crop_top_offset); - writer->write_UE(frame_crop_bottom_offset); - } - - if (vui_params) { - writer->write_bool(true); - vui_params->write(*writer); - } else { - writer->write_bool(false); - } - writer->write_trailing_bits(); - - return writer->write_count(); -} - -// class aspect_ratio -aspect_ratio aspect_ratio::EXTENDED_SAR(255); - -size_t aspect_ratio::parse(bitstream_reader& reader) -{ - _value = reader.read_bits(8); - return 8; -} - -size_t aspect_ratio::write(bitstream_writer& writer) const -{ - return writer.write_bits(_value, 8); -} - -string aspect_ratio::str(unsigned indent) const -{ - stringstream stream; - json_serializer s(stream, "aspect_ratio", indent); - s.start_json(); - - s.write_field("value", _value); - - s.end_json(); - return s.str(); -} - -// class scaling list - -scaling_list* scaling_list::read(bitstream_reader& reader, int list_size) -{ - if (list_size <= 0) { - return NULL; - } - - scaling_list* sl = new scaling_list(); - sl->scalinglist = new int[list_size]; - sl->list_length = list_size; - int last_scale = 8; - int next_scale = 8; - - for (int j=0; juse_default_scaling_matrix_flag = (j==0 && next_scale==0); - } - sl->scalinglist[j] = next_scale == 0 ? last_scale : next_scale; - last_scale = sl->scalinglist[j]; - } - return sl; -} - -size_t scaling_list::write(bitstream_writer& writer) const -{ - if (use_default_scaling_matrix_flag) { - writer.write_SE(0); - return writer.write_count(); - } - - int lastScale = 8; - int nextScale = 8; - for (int j = 0; j < list_length; j++) { - if (nextScale != 0) { - int deltaScale = scalinglist[j] - lastScale - 256; - writer.write_SE(deltaScale); - } - lastScale = scalinglist[j]; - } - return writer.write_count(); -} - -string scaling_list::str(unsigned indent) const -{ - stringstream stream; - json_serializer s(stream, "scaling_list", indent); - s.start_json(); - - s.write_field("use_default_scaling_matrix_flag", use_default_scaling_matrix_flag); - if (! use_default_scaling_matrix_flag) { - s.write_array("scalinglist", scalinglist, list_length); - } - - s.end_json(); - return s.str(); -} - -// class scaling_matrix - -size_t scaling_matrix::parse(bitstream_reader& reader) -{ - size_t start = reader.read_bit_count(); - - scaling_list_4x4 = new scaling_list*[6]; - scaling_list_8x8 = new scaling_list*[2]; - - for (int i=0; i<6; i++) { - if (reader.read_bool()) { - scaling_list_4x4[i] = scaling_list::read(reader, 16); - } else { - scaling_list_4x4[i] = NULL; - } - } - - for (int i=0; i<2; i++) { - if (reader.read_bool()) { - scaling_list_8x8[i] = scaling_list::read(reader, 64); - } else { - scaling_list_8x8[i] = NULL; - } - } - - return reader.read_bit_count() - start; -} - -size_t scaling_matrix::write(bitstream_writer& writer) const -{ - if (! scaling_list_4x4 || ! scaling_list_8x8) { return 0; } - - size_t start = writer.write_bit_count(); - - for (int i=0; i<6; i++) { - if (scaling_list_4x4[i]) { - writer.write_bool(true); - scaling_list_4x4[i]->write(writer); - } else { - writer.write_bool(false); - } - } - - for (int i=0; i<2; i++) { - if (scaling_list_8x8[i]) { - writer.write_bool(true); - scaling_list_8x8[i]->write(writer); - } else { - writer.write_bool(false); - } - } - - return writer.write_bit_count() - start; -} - -string scaling_matrix::str(unsigned indent) const -{ - stringstream stream; - json_serializer s(stream, "scaling_matrix", indent); - s.start_json(); - - char buf[64]; - if (scaling_list_4x4) { - for (int i=0; i<6; i++) { - if (scaling_list_4x4[i]) { - sprintf(buf, "scaling_list_4x4[%d]", i); - s.write_object(buf, scaling_list_4x4[i]->str()); - } - } - } - - if (scaling_list_8x8) { - for (int i=0; i<2; i++) { - if (scaling_list_8x8[i]) { - sprintf(buf, "scaling_list_8x8[%d]", i); - s.write_object(buf, scaling_list_8x8[i]->str()); - } - } - } - - s.end_json(); - return s.str(); -} - -// class picture_parameter_set - -picture_parameter_set::picture_parameter_set() - : entropy_coding_mode_flag(false), - num_ref_idx_l0_active_minus1(0), - num_ref_idx_l1_active_minus1(0), - slice_group_change_rate_minus1(0), - pic_parameter_set_id(0), - seq_parameter_set_id(0), - pic_order_present_flag(false), - num_slice_groups_minus1(0), - slice_group_map_type(0), - weighted_pred_flag(false), - weighted_bipred_idc(0), - pic_init_qp_minus26(0), - pic_init_qs_minus26(0), - chroma_qp_index_offset(0), - deblocking_filter_control_present_flag(false), - constrained_intra_pred_flag(false), - redundant_pic_cnt_present_flag(false), - top_left(NULL), - bottom_right(NULL), - run_length_minus1(NULL), - slice_group_change_direction_flag(false), - pic_size_map_units_minus1(0), - slice_group_id(NULL), - extended(NULL) -{ -} - -size_t picture_parameter_set::parse(const char* buf, size_t sz) -{ - bitstream_reader r(buf, sz); - - pic_parameter_set_id = r.read_UE(); - seq_parameter_set_id = r.read_UE(); - entropy_coding_mode_flag = r.read_bool(); - pic_order_present_flag = r.read_bool(); - num_slice_groups_minus1 = r.read_UE(); - - if (num_slice_groups_minus1 > 0) { - slice_group_map_type = r.read_UE(); - top_left = new int[num_slice_groups_minus1 + 1]; - bottom_right = new int[num_slice_groups_minus1 + 1]; - run_length_minus1 = new int[num_slice_groups_minus1 + 1]; - - if (slice_group_map_type == 0) { - for (int i_group = 0; i_group <= num_slice_groups_minus1; i_group++) { - run_length_minus1[i_group] = r.read_UE(); - } - } else if (slice_group_map_type == 2) { - for (int i_group = 0; i_group < num_slice_groups_minus1; i_group++) { - top_left[i_group] = r.read_UE(); - bottom_right[i_group] = r.read_UE(); - } - } else if (slice_group_map_type == 3 || - slice_group_map_type == 4 || - slice_group_map_type == 5) { - slice_group_change_direction_flag = r.read_bool(); - slice_group_change_rate_minus1 = r.read_UE(); - } else if (slice_group_map_type == 6) { - int number_bits_per_slice_group_id = 0; - if (num_slice_groups_minus1 + 1 > 4) { - number_bits_per_slice_group_id = 3; - } else if (num_slice_groups_minus1 + 1 > 2) { - number_bits_per_slice_group_id = 2; - } else { - number_bits_per_slice_group_id = 1; - } - - pic_size_map_units_minus1 = r.read_UE(); - slice_group_id = new int[pic_size_map_units_minus1 + 1]; - for (int i=0; itransform_8x8_mode_flag = r.read_bool(); - bool pic_scaling_matrix_present_flag = r.read_bool(); - if (pic_scaling_matrix_present_flag) { - for (int i=0; i<6+2*(extended->transform_8x8_mode_flag ? 1 : 0); i++) { - bool pic_scalinglist_present_flag = r.read_bool(); - if (pic_scalinglist_present_flag) { - extended->scalingmatrix->scaling_list_4x4 = new scaling_list*[8]; - extended->scalingmatrix->scaling_list_8x8 = new scaling_list*[8]; - if (i<6) { - extended->scalingmatrix->scaling_list_4x4[i] = - scaling_list::read(r, 16); - } else { - extended->scalingmatrix->scaling_list_8x8[i-6] = - scaling_list::read(r, 64); - } - } - } - } - extended->second_chroma_qp_index_offset = r.read_SE(); - } - - //cerr << "+++ pps read bit count: " << r.read_bit_count() << endl; - - r.read_trailing_bits(); - - return r.read_count(); -} - -size_t picture_parameter_set::write(char* buf, size_t sz) const -{ - bool flag; - bitstream_writer writer(buf, sz); - writer.write_UE(pic_parameter_set_id); - writer.write_UE(seq_parameter_set_id); - writer.write_bool(entropy_coding_mode_flag); - writer.write_bool(pic_order_present_flag); - writer.write_UE(num_slice_groups_minus1); - - if (num_slice_groups_minus1 > 0) { - writer.write_UE(slice_group_map_type); - if (slice_group_map_type == 0) { - for (int iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++) { - writer.write_UE(run_length_minus1[iGroup]); - } - } else if (slice_group_map_type == 2) { - for (int iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++) { - writer.write_UE(top_left[iGroup]); - writer.write_UE(bottom_right[iGroup]); - } - } else if (slice_group_map_type == 3 || slice_group_map_type == 4 - || slice_group_map_type == 5) { - writer.write_bool(slice_group_change_direction_flag); - writer.write_UE(slice_group_change_rate_minus1); - } else if (slice_group_map_type == 6) { - int NumberBitsPerSliceGroupId; - if (num_slice_groups_minus1 + 1 > 4) - NumberBitsPerSliceGroupId = 3; - else if (num_slice_groups_minus1 + 1 > 2) - NumberBitsPerSliceGroupId = 2; - else - NumberBitsPerSliceGroupId = 1; - - int slice_group_id_length = pic_size_map_units_minus1 + 1; - writer.write_UE(slice_group_id_length); - for (int i = 0; i <= slice_group_id_length; i++) { - writer.write_U(slice_group_id[i], NumberBitsPerSliceGroupId); - } - } - } - writer.write_UE(num_ref_idx_l0_active_minus1); - writer.write_UE(num_ref_idx_l1_active_minus1); - writer.write_bool(weighted_pred_flag); - writer.write_bits(weighted_bipred_idc, 2); - writer.write_SE(pic_init_qp_minus26); - writer.write_SE(pic_init_qs_minus26); - writer.write_SE(chroma_qp_index_offset); - writer.write_bool(deblocking_filter_control_present_flag); - writer.write_bool(constrained_intra_pred_flag); - writer.write_bool(redundant_pic_cnt_present_flag); - - if (extended) { - writer.write_bool(extended->transform_8x8_mode_flag); - - flag = extended->scalingmatrix != NULL; - writer.write_bool(flag); - if (flag) { - for (int i=0; i< 6+2*(extended->transform_8x8_mode_flag ? 1 : 0); i++) { - if (i < 6) { - flag = extended->scalingmatrix->scaling_list_4x4[i] != NULL; - writer.write_bool(flag); - if (flag) { - extended->scalingmatrix->scaling_list_4x4[i]->write(writer); - } - - } else { - flag = extended->scalingmatrix->scaling_list_8x8[i - 6] != NULL; - writer.write_bool(flag); - if (flag) { - extended->scalingmatrix->scaling_list_8x8[i - 6]->write(writer); - } - } - } - } - writer.write_SE(extended->second_chroma_qp_index_offset); - } - - //cerr << "+++ pps write bit count: " << writer.write_bit_count() << endl; - - writer.write_trailing_bits(); - return writer.write_count(); -} - -std::string picture_parameter_set::str(unsigned indent) const -{ - std::stringstream stream; - json_serializer s(stream, "picture_parameter_set", indent); - - s.start_json(); - - s.write_field("entropy_coding_mode_flag", entropy_coding_mode_flag); - s.write_field("num_ref_idx_l0_active_minus1", num_ref_idx_l0_active_minus1); - s.write_field("num_ref_idx_l1_active_minus1", num_ref_idx_l1_active_minus1); - s.write_field("slice_group_change_rate_minus1", slice_group_change_rate_minus1); - s.write_field("pic_parameter_set_id", pic_parameter_set_id); - s.write_field("seq_parameter_set_id", seq_parameter_set_id); - s.write_field("pic_order_present_flag", pic_order_present_flag); - s.write_field("num_slice_groups_minus1", num_slice_groups_minus1); - s.write_field("slice_group_map_type", slice_group_map_type); - s.write_field("weighted_pred_flag", weighted_pred_flag); - s.write_field("weighted_bipred_idc", weighted_bipred_idc); - s.write_field("pic_init_qp_minus26", pic_init_qp_minus26); - s.write_field("pic_init_qs_minus26", pic_init_qs_minus26); - s.write_field("chroma_qp_index_offset", chroma_qp_index_offset); - s.write_field("deblocking_filter_control_present_flag", deblocking_filter_control_present_flag); - s.write_field("constrained_intra_pred_flag", constrained_intra_pred_flag); - s.write_field("redundant_pic_cnt_present_flag", redundant_pic_cnt_present_flag); - s.write_array("top_left", top_left, num_slice_groups_minus1 + 1); - s.write_array("bottom_right", bottom_right, num_slice_groups_minus1 + 1); - s.write_array("run_length_minus1", run_length_minus1, num_slice_groups_minus1 + 1); - s.write_field("slice_group_change_direction_flag", slice_group_change_direction_flag); - s.write_field("pic_size_map_units_minus1", pic_size_map_units_minus1); - s.write_array("slice_group_id", slice_group_id, pic_size_map_units_minus1); - - if (extended) { - s.write_object("extended", extended->str(indent+1)); - } - - s.end_json(); - return s.str(); -} - -// class pps_ext - -string pps_ext::str(unsigned indent) const -{ - std::stringstream stream; - json_serializer s(stream, "pps_ext", indent); - - s.start_json(); - - // TODO: serialize PPS Ext data structure. - - s.end_json(); - - return s.str(); -} - -}; // namespace isomf - diff --git a/plugins/scan-video/h264_model.h b/plugins/scan-video/h264_model.h deleted file mode 100644 index 615e8e4d..00000000 --- a/plugins/scan-video/h264_model.h +++ /dev/null @@ -1,319 +0,0 @@ -#ifndef H264_MODEL -#define H264_MODEL - -#include "bitstream_reader.h" -#include "bitstream_writer.h" -#include "isomf_base.h" - -using namespace std; - -namespace isomf -{ - -class json_serializer -{ - public: - json_serializer(stringstream& s, const string& type, unsigned ind); - ~json_serializer(); - - json_serializer& start_json(); - json_serializer& write_field(const string& f, int value); - json_serializer& write_field(const string& f, bool value); - json_serializer& write_field(const string& f, const string& value); - json_serializer& write_object(const string& f, const string& obj); - json_serializer& write_array(const string& f, const int* array, unsigned length); - json_serializer& write_array(const string& f, const bool* array, unsigned length); - json_serializer& end_json(); - - string str(); - - protected: - void indent(); - - const string _s_type; - unsigned _s_indent; - stringstream* _s_stream; -}; - -/// Base class for parameter sets -class parameter_set -{ - public: - static const size_t MAX_SIZE = 1024; - - parameter_set(); - parameter_set(const parameter_set& s); - virtual ~parameter_set(); - - parameter_set& operator=(const parameter_set& s); - - virtual size_t size(); - - virtual size_t parse(const char* buf, size_t size); - virtual size_t write(char* buf, size_t size) const; - - protected: - -}; - -/// Chroma format -class chroma_format -{ - public: - static const chroma_format MONOCHROME; - static const chroma_format YUV_420; - static const chroma_format YUV_422; - static const chroma_format YUV_444; - - chroma_format(int id, int sub_width, int sub_height); - ~chroma_format() {}; - - static const chroma_format* from_id(int id); - - bool operator==(const chroma_format& cf) const - { return cf.get_id() == _id; }; - - int get_id() const { return _id; } - int get_sub_width() const { return _sub_width; } - int get_sub_height() const { return _sub_height; } - - string str(unsigned indent = 0) const; - - private: - int _id; - int _sub_width; - int _sub_height; -}; - -class bitstream_restriction -{ - public: - bool motion_vectors_over_pic_boundaries_flag; - int max_bytes_per_pic_denom; - int max_bits_per_mb_denom; - int log2_max_mv_length_horizontal; - int log2_max_mv_length_vertical; - int num_reorder_frames; - int max_dec_frame_buffering; - - size_t parse(bitstream_reader& reader); - size_t write(bitstream_writer& writer) const; - string str(unsigned indent=0) const; -}; - -class HRD_parameters -{ - public: - int cpb_cnt_minus1; - int bit_rate_scale; - int cpb_size_scale; - int* bit_rate_value_minus1; - int* cpb_size_value_minus1; - bool* cbr_flag; - int initial_cpb_removal_delay_length_minus1; - int cpb_removal_delay_length_minus1; - int dpb_output_delay_length_minus1; - int time_offset_length; - - size_t parse(bitstream_reader& reader); - size_t write(bitstream_writer& writer) const; - string str(unsigned indent = 0) const; -}; - -class aspect_ratio -{ - public: - static aspect_ratio EXTENDED_SAR; - - aspect_ratio():_value(0) {}; - - aspect_ratio(int value):_value(value) {}; - int get_value() const { return _value; } - - bool operator==(const aspect_ratio& ar) - { return _value == ar.get_value(); } - - aspect_ratio& operator=(const aspect_ratio& ar) - { _value = ar.get_value(); return *this; } - - size_t parse(bitstream_reader& reader); - size_t write(bitstream_writer& writer) const; - string str(unsigned indent = 0) const; - private: - int _value; -}; - -class scaling_list -{ - public: - int* scalinglist; - int list_length; - bool use_default_scaling_matrix_flag; - - static scaling_list* read(bitstream_reader& reader, int list_size); - size_t write(bitstream_writer& writer) const; - - string str(unsigned indent = 0) const; -}; - -class scaling_matrix -{ - public: - scaling_list** scaling_list_4x4; - scaling_list** scaling_list_8x8; - - size_t parse(bitstream_reader& reader); - size_t write(bitstream_writer& writer) const; - string str(unsigned indent = 0) const; -}; - -/// VUI parameters -class VUI_parameters -{ - public: - bool aspect_ratio_info_present_flag; - int sar_width; - int sar_height; - bool overscan_info_present_flag; - bool overscan_appropriate_flag; - bool video_signal_type_present_flag; - int video_format; - bool video_full_range_flag; - bool colour_description_present_flag; - int colour_primaries; - int transfer_characteristics; - int matrix_coefficients; - bool chroma_loc_info_present_flag; - int chroma_sample_loc_type_top_field; - int chroma_sample_loc_type_bottom_field; - bool timing_info_present_flag; - int num_units_in_tick; - int time_scale; - bool fixed_frame_rate_flag; - bool low_delay_hrd_flag; - bool pic_struct_present_flag; - HRD_parameters* nal_HRD_params; - HRD_parameters* vcl_HRD_params; - bitstream_restriction* bitstreamrestriction; - aspect_ratio* aspectratio; - - size_t parse(bitstream_reader& reader); - size_t write(bitstream_writer& writer) const; - string str(unsigned indent = 0) const; -}; - -/// Sequence Parameter Set -class sequence_parameter_set : public parameter_set -{ - public: - sequence_parameter_set(); - virtual ~sequence_parameter_set() {}; - - virtual size_t parse(const char* buf, size_t sz); - virtual size_t write(char* buf, size_t sz) const; - - int pic_order_cnt_type; - bool field_pic_flag; - bool delta_pic_order_always_zero_flag; - bool entropy_coding_mode_flag; - bool mb_adaptive_frame_field_flag; - bool direct_8x8_inference_flag; - const chroma_format* chroma_format_idc; - int log2_max_frame_num_minus4; - int log2_max_pic_order_cnt_lsb_minus4; - int pic_height_in_map_units_minus1; - int pic_width_in_mbs_minus1; - int bit_depth_luma_minus8; - int bit_depth_chroma_minus8; - bool qpprime_y_zero_transform_bypass_flag; - int profile_idc; - bool constraint_set_0_flag; - bool constraint_set_1_flag; - bool constraint_set_2_flag; - bool constraint_set_3_flag; - int level_idc; - int seq_parameter_set_id; - bool residual_color_transform_flag; - int offset_for_non_ref_pic; - int offset_for_top_to_bottom_field; - int num_ref_frames; - bool gaps_in_frame_num_value_allowed_flag; - bool frame_mbs_only_flag; - bool frame_cropping_flag; - int frame_crop_left_offset; - int frame_crop_right_offset; - int frame_crop_top_offset; - int frame_crop_bottom_offset; - int* offset_for_ref_frame; - - VUI_parameters* vui_params; - scaling_matrix* scalingmatrix; - int num_ref_frames_in_pic_order_cnt_cycle; - - int reserved; - - string str(unsigned indent = 0) const; - - protected: - - private: - typedef parameter_set super; -}; - -class pps_ext -{ - public: - bool transform_8x8_mode_flag; - scaling_matrix* scalingmatrix; - int second_chroma_qp_index_offset; - bool* pic_scaling_list_present_flag; - - std::string str(unsigned indent = 0) const; -}; - -/// Picture Parameter Set -class picture_parameter_set : public parameter_set -{ - public: - bool entropy_coding_mode_flag; - int num_ref_idx_l0_active_minus1; - int num_ref_idx_l1_active_minus1; - int slice_group_change_rate_minus1; - int pic_parameter_set_id; - int seq_parameter_set_id; - bool pic_order_present_flag; - int num_slice_groups_minus1; - int slice_group_map_type; - bool weighted_pred_flag; - int weighted_bipred_idc; - int pic_init_qp_minus26; - int pic_init_qs_minus26; - int chroma_qp_index_offset; - bool deblocking_filter_control_present_flag; - bool constrained_intra_pred_flag; - bool redundant_pic_cnt_present_flag; - int* top_left; - int* bottom_right; - int* run_length_minus1; - bool slice_group_change_direction_flag; - int pic_size_map_units_minus1; - int* slice_group_id; - pps_ext* extended; - - picture_parameter_set(); - virtual ~picture_parameter_set() {}; - - virtual size_t parse(const char* buf, size_t sz); - virtual size_t write(char* buf, size_t sz) const; - - std::string str(unsigned indent = 0) const; - protected: - - private: - typedef parameter_set super; -}; - - -}; // namespace isomf - -#endif diff --git a/plugins/scan-video/hello.cpp b/plugins/scan-video/hello.cpp deleted file mode 100644 index 885c60da..00000000 --- a/plugins/scan-video/hello.cpp +++ /dev/null @@ -1,9 +0,0 @@ -//#include "bulk_extractor_api.h" - -#include - -extern "C" -void hello(const char *param) -{ - std::cout << "Received from caller: " << param << "\n"; -} diff --git a/plugins/scan-video/histogram_process.cpp b/plugins/scan-video/histogram_process.cpp deleted file mode 100644 index bee06810..00000000 --- a/plugins/scan-video/histogram_process.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "histogram_process.h" -#include "libavutil/avconfig.h" -#include -#include -#include -#include - -using namespace cv; -using namespace std; - -histogram_process::histogram_process(keyframe_utils& u){ - _util = u; -} - -histogram_process::~histogram_process(){ -} - -bool histogram_process::get_histogram(const cv::Mat& src, cv::MatND& hist){ - try { - Mat hsv, rgb; - cvtColor(src, hsv, CV_BGR2HSV); - - // Quantize the hue to 30 levels - // and the saturation to 32 levels - //int hbins = 30, sbins = 32; - int histSize[2] = {30, 32}; - - // hue varies from 0 to 179, see cvtColor - float hranges[2] = { 0, 180 }; - - // saturation varies from 0 (black-gray-white) to - // 255 (pure spectrum color) - float sranges[2] = { 0, 256 }; - const float* ranges[] = { hranges, sranges }; - - // we compute the histogram from the 0-th and 1-st channels - int channels[2] = {0, 1}; - - calcHist( &hsv, 1, channels, Mat(), hist, 2, histSize, ranges,true, false ); - normalize( hist, hist, 1, 0, NORM_L2, -1, Mat() ); - } catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ - << ":get_histogram fails.\n"; - return false; - } - return true; -} - -bool histogram_process::get_histogram(const AVFrame *pic, const AVCodecContext *codec, cv::MatND& hist){ - Mat m; - _util.initialize(codec); - if(!_util.convert_frame_to_mat(pic, m, codec)) { - std::cerr << __FILE__ << ":" << __LINE__ - << ":conversting frame to matrix fails.\n"; - return false; - } - return get_histogram(m, hist); - -} - -bool histogram_process::compare(const cv::MatND& h1, const cv::MatND& h2, double& dist){ - try { - dist = compareHist(h1, h2, CV_COMP_CHISQR); - } catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ - << ":comparing histograms fails.\n"; - return false; - } - return true; - -} - -bool histogram_process::compare(const AVFrame *pic1, const cv::MatND& h2, const AVCodecContext *codec, double& dist){ - - Mat m1; - _util.initialize(codec); - if(!_util.convert_frame_to_mat(pic1, m1, codec)){ - std::cerr << __FILE__ << ":" << __LINE__ - << ":conversting frame to matrix fails.\n"; - return false; - } - - MatND h1; - if(!get_histogram(m1, h1)){ - std::cerr << __FILE__ << ":" << __LINE__ - << ":compare fails.\n"; - return false; - } - - return compare(h1, h2, dist); - -} - -bool histogram_process::compare(const AVFrame *pic1, const AVFrame *pic2, const AVCodecContext *codec, double& dist){ - - Mat m1; - _util.initialize(codec); - if(!_util.convert_frame_to_mat(pic1, m1, codec)) - return false; - MatND h1; - if(!get_histogram(m1, h1)) - return false; - return compare(pic2, h1, codec, dist); -} \ No newline at end of file diff --git a/plugins/scan-video/histogram_process.h b/plugins/scan-video/histogram_process.h deleted file mode 100644 index d61f844b..00000000 --- a/plugins/scan-video/histogram_process.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _HISTOGRAM_PROCESS_H_ -#define _HISTOGRAM_PROCESS_H_ - -#include -#include -#include - - -extern "C" { -#include "libavcodec/avcodec.h" -#include "libavformat/avformat.h" -#include "libavutil/avutil.h" -#include "libswscale/swscale.h" -} - -#include "keyframe_utils.h" - -/// \class histogram_process histogram_process.h -/// \brief The class implements all the methods needed to compute and compare histograms -/// -class histogram_process{ -public: - /// Copy constructor for this class. - /// Utilizes the codec construct to allocate memory for the histograms - /// - histogram_process(keyframe_utils& u); - - /// Default destructor - ~histogram_process(); - - /// \brief Computes histogram for a cv::Mat object and saves it as a cv::MatND object - /// \param (src) - input matrix - /// \param (hist) - output hostogram - /// \return the status of the function. - /// - bool get_histogram(const cv::Mat& src, cv::MatND& hist); - /// \brief Converts an AVFrame to a cv::Mat and then computes histogram. - bool get_histogram(const AVFrame *pic, const AVCodecContext *codec, cv::MatND& hist); - - /// \brief - Compares histograms and computes the chi-squared distance - /// \param(h1, h2) - input histograms - /// \param(dist) - output parameter, chi-squared distance - /// \return - status - bool compare(const cv::MatND& h1, const cv::MatND& h2, double& dist); - /// \brief - Computes histogram over a picture and compares it to another histogram and calculates distance - bool compare(const AVFrame *pic1, const cv::MatND& h2, const AVCodecContext *codec, double& dist); - /// \brief - Computes histograms for both pictures and compares their histograms and calculates distance - bool compare(const AVFrame *pic1, const AVFrame *pic2, const AVCodecContext *codec, double& dist); -private: - AVFrame *avFrameRGB; - struct SwsContext *img_convert_ctx; - keyframe_utils _util; - -}; - -#endif \ No newline at end of file diff --git a/plugins/scan-video/isomf.cpp b/plugins/scan-video/isomf.cpp deleted file mode 100644 index dc362b8c..00000000 --- a/plugins/scan-video/isomf.cpp +++ /dev/null @@ -1,699 +0,0 @@ -#include -#include -#include - -#include "type_io.h" -#include "bytestream_reader.h" -#include "isomf.h" - -#define MAX_AVCC_SIZE 4096 - -namespace isomf { - -// class box - -box::box() - : _type(""),_parent(NULL),_children() -{ - memset(_extended_type, 0, 16); -} - -box::box(const std::string& box_type) - : _type(box_type),_parent(NULL),_children() -{ - memset(_extended_type, 0, 16); -} - -box::box(const box& b) - : _type(""),_parent(NULL),_children() -{ - operator=(b); -} - -void box::get_extended_type(char* type_buf) const -{ - if (! type_buf) { return; } - memcpy(type_buf, _extended_type, 16); -} - -void box::set_extended_type(char* type_buf) -{ - if (! type_buf) { return; } - memcpy(_extended_type, type_buf, 16); -} - -size_t box::size() const -{ - size_t total = 0; - total += 8; // size | type - total += is_small() ? 0 : 8; // large size - total += _type == "uuid" ? 16 : 0; // extended type - total += content_size(); - - return total; -} - -void box::add(const box& c) -{ - _children.push_back(&c); -} - -void box::remove(const box& c) -{ - _children.remove(&c); -} - -bool box::is_small() const -{ - return true; - /* - size_t header_size = 8; - if (_type == "uuid") { - header_size += 16; - } - - unsigned long long total_size = content_size(); - total_size += header_size; - - if ((total_size >> 32) == 0) { - return true; - } else { - return false; - } - */ -} - -size_t box::content_size() const -{ - size_t sz = 0; - std::list::const_iterator itr = _children.begin(); - for (; itr != _children.end(); itr++) { - sz += (*itr)->size(); - } - return sz; -} - -box& box::operator=(const box& b) -{ - _type = b.type(); - _parent = b.parent(); - _children = b.children(); - - if (_type == "uuid") { - b.get_extended_type(_extended_type); - } - return *this; -} - -size_t box::write(char* buf, size_t sz) const -{ - char* t = buf; - t += write_header(t, sz); - std::cerr << "Header written: " << t-buf << " bytes.\n"; - - t += write_box_content(t, sz); - std::cerr << "Box content written: " << t-buf << " bytes.\n"; - - t += write_children(t, sz); - std::cerr << "Children boxes written: " << t-buf << " bytes.\n"; - - return t-buf; -} - -size_t box::write_header(char* buf, size_t sz) const -{ - if (! buf) { return 0; } - - if (sz < size()) { - std::cerr << "Buffer too small for the box header." << std::endl; - return 0; - } - - std::cerr << "Writing header for type=" << _type << " and size=" << size() << "\n"; - - char* t = buf; - if (is_small()) { - t += type_io::write_uint32((unsigned) size(), t); - t += type_io::write_fourcc(_type, t); - } else { - t += type_io::write_uint32((unsigned) 1, t); - t += type_io::write_fourcc(_type, t); - t += type_io::write_uint64(size(), t); - } - - if (_type == "uuid") { - memcpy(buf, _extended_type, 16); - t += 16; - } - return (t-buf); -} - -size_t box::write_box_content(char* buf, size_t sz) const -{ - return 0; -} - -size_t box::write_children(char* buf, size_t sz) const -{ - char* t = buf; - size_t total = 0; - size_t nb = 0; - - std::list::const_iterator itr = _children.begin(); - for (; itr != _children.end(); itr++) { - nb += (*itr)->write(t, sz-total); - t += nb; - total += nb; - if (total >= sz) { - return total; - } - } - return t-buf; -} - -size_t box::parse(char* buf, size_t sz) -{ - char* t = buf; - t += parse_header(t, sz); - std::cerr << "Header parsed: " << t-buf << " bytes.\n"; - - t += parse_box_content(t, sz); - std::cerr << "Box content parsed: " << t-buf << " bytes.\n"; - - t += parse_children(t, sz); - std::cerr << "Children boxes written: " << t-buf << " bytes.\n"; - - return t-buf; -} - -size_t box::parse_header(char* buf, size_t sz) -{ - bytestream_reader reader(buf, sz); - - long long s = reader.read_uint32(); - if (s < 0) { return 0; } - - std::cerr << " >> Parsed header size: " << s << "\n"; - - std::string* fourcc = reader.read_fourcc(); - if (fourcc == NULL) { return 0; } - _type = *fourcc; - - std::cerr << " >> Parsed header fourcc code: " << _type << "\n"; - - if (s == 1) { - s = reader.read_uint64(); - if (s < 0) { return 0; } - } - - if (_type == "uuid") { - if (reader.available() < 16) { return 0; } - reader.read_array(_extended_type, 16); - } - return reader.read_count(); -} - -size_t box::parse_box_content(char* buf, size_t sz) -{ - // no content for the base box class - return 0; -} - -size_t box::parse_children(char* buf, size_t sz) -{ - // TODO: - return 0; -} - -// class full_box - -full_box::full_box() :_version(0),_flags(0) -{ -} - -size_t full_box::parse_box_content(char* buf, size_t sz) -{ - if (buf == NULL || sz < 4) { - std::cerr << "Buffer is NULL or too small for fullbox content.\n"; - return 0; - } - _version = type_io::read_uint8(buf); - buf++; - _flags = type_io::read_uint24(buf); - return 4; -} - -size_t full_box::write_box_content(char* buf, size_t sz) const -{ - if (buf == NULL || sz < 4) { - std::cerr << "Buffer is NULL or too small for fullbox content.\n"; - return 0; - } - type_io::write_uint8(_version, buf); - buf++; - type_io::write_uint24(_flags, buf); - return 4; -} - -full_box& full_box::operator=(const full_box& b) -{ - super::operator=(b); - _version = b.version(); - _flags = b.flags(); - return *this; -} - -// class sample_description_box - -sample_description_box::sample_description_box() -{ - _type = "stsd"; -} - -sample_description_box::~sample_description_box() -{ -} - -size_t sample_description_box::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += super::write_box_content(t, sz); - t += type_io::write_uint32((unsigned)_children.size(), t); - return t-buf; -} - -size_t sample_description_box::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -// class sample_entry - -sample_entry::sample_entry() :_data_ref_index(1) -{ -} - -sample_entry::~sample_entry() -{ -} - -size_t sample_entry::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += super::write_box_content(t, sz); - t += type_io::write_unsigned(0, t, 6); - t += type_io::write_uint16(_data_ref_index, t); - return t-buf; -} - -size_t sample_entry::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -// class visual_sample_entry - -visual_sample_entry::visual_sample_entry() - :_width(0),_height(0),_frame_count(1),_depth(0x18), - _hres(0x00480000),_vres(0x00480000),_compressor() -{ - _type = "avc1"; -} - -visual_sample_entry::visual_sample_entry(const std::string& t) - :_width(0),_height(0),_frame_count(1),_depth(0x18), - _hres(0x00480000),_vres(0x00480000),_compressor() -{ - _type = t; -} - -visual_sample_entry::~visual_sample_entry() -{ -} - -size_t visual_sample_entry::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += super::write_box_content(t, sz); - t += type_io::write_uint16(0, t); // 16 bit 'pre_defined' - t += type_io::write_uint16(0, t); // 16 bit 'reserved' - - // array of three 32-bit 'pre_defined' - t += type_io::write_uint32(0, t); - t += type_io::write_uint32(0, t); - t += type_io::write_uint32(0, t); - - t += type_io::write_uint16(_width, t); - t += type_io::write_uint16(_height, t); - t += type_io::write_uint32(_hres, t); - t += type_io::write_uint32(_vres, t); - - t += type_io::write_uint32(0, t); // 32-bit 'reserved' - - t += type_io::write_uint16(_frame_count, t); - t += type_io::write_string(_compressor, 32, t); - t += type_io::write_uint16(_depth, t); - - t += type_io::write_uint16(0xffff, t); // 16-bit 'pre-defined' -1 - - return t-buf; -} - -size_t visual_sample_entry::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -// class audio_sample_entry - -audio_sample_entry::audio_sample_entry() - :_sound_version(0),_channel_count(2),_sample_size(16), - _compression_id(0),_packet_size(0),_sample_rate(8000), - _samples_per_packet(0),_bytes_per_packet(0),_bytes_per_frame(0), - _bytes_per_sample(0) -{ - _type = "mp4a"; - memset(_version2_data, 0, sizeof(_version2_data)); -} - -audio_sample_entry::audio_sample_entry(const std::string& codec_type) - :_sound_version(0),_channel_count(2),_sample_size(16), - _compression_id(0),_packet_size(0),_sample_rate(8000), - _samples_per_packet(0),_bytes_per_packet(0),_bytes_per_frame(0), - _bytes_per_sample(0) -{ - _type = codec_type; - memset(_version2_data, 0, sizeof(_version2_data)); -} - -size_t audio_sample_entry::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += super::write_box_content(t, sz); - - t += type_io::write_uint16(_sound_version, t); - - t += type_io::write_uint16(0, t); - t += type_io::write_uint32(0, t); - - t += type_io::write_uint16(_channel_count, t); - t += type_io::write_uint16(_sample_size, t); - t += type_io::write_uint16(_compression_id, t); - t += type_io::write_uint16(_packet_size, t); - - if (_type == "mlpa") { - t += type_io::write_uint32(_sample_rate, t); - } else { - t += type_io::write_uint32(_sample_rate << 16, t); - } - - if (_sound_version > 0) { - t += type_io::write_uint32(_samples_per_packet, t); - t += type_io::write_uint32(_bytes_per_packet, t); - t += type_io::write_uint32(_bytes_per_frame, t); - t += type_io::write_uint32(_bytes_per_sample, t); - } - - if (_sound_version == 2) { - t += type_io::write_bytes(_version2_data, sizeof(_version2_data), t); - } - - return (t-buf); -} - -size_t audio_sample_entry::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -size_t audio_sample_entry::content_size() const -{ - size_t sz = super::content_size(); - sz += 20; - if (_sound_version > 0) { sz += 16; } - if (_sound_version == 2) { sz += 20; } - return sz; -} - -// class data_holder - -data_holder::data_holder() - :_data(NULL),_data_size(0) -{ -} - -data_holder::data_holder(const data_holder& d) - :_data(NULL),_data_size(0) -{ - operator=(d); -} - -data_holder::~data_holder() -{ - clear(); -} - -data_holder& data_holder::operator=(const data_holder& d) -{ - clear(); - - _data_size = d.size(); - if (_data_size > 0) { - _data = new char[_data_size]; - d.get_data(_data, _data_size); - } - return *this; -} - -size_t data_holder::set_data(const char* data, size_t sz) -{ - clear(); - if (data && sz > 0) { - _data_size = sz; - _data = new char[sz]; - memcpy(_data, data, sz); - return parse(data, sz); - } - return 0; -} - -size_t data_holder::get_data(char* data, size_t sz) const -{ - if (_data_size == 0 || ! _data || ! data || sz < _data_size) { - return 0; - } - - if (_data) { - size_t nb = _data_size > sz ? sz : _data_size; - memcpy(data, _data, nb); - return nb; - } else { - return write(data, sz); - } -} - -void data_holder::clear() -{ - if (_data) { - delete _data; - _data = NULL; - } - _data_size = 0; -} - - -// class avc_configuration_box - -avc_configuration_box::avc_configuration_box() - :_configuration_version(1), - _avc_profile_indication(66), - _profile_compatibility(192), - _avc_level_indication(13), - _length_size_minus_one(3), - _sps(), - _pps() -{ - _type = "avcC"; -} - -size_t avc_configuration_box::content_size() const -{ - size_t sz = 7; // fixed length - - // variable part - std::list::const_iterator itr1 = _sps.begin(); - for (; itr1 != _sps.end(); itr1++) { - sz += 2; - sz += (*itr1)->size(); - } - - std::list::const_iterator itr2 = _pps.begin(); - for (; itr2 != _pps.end(); itr2++) { - sz += 2; - sz += (*itr2)->size(); - } - - return sz; -} - -size_t avc_configuration_box::parse_box_content(char* buf, size_t sz) -{ - if (! buf || sz == 0) { return 0; } - - char* t = buf; - t += super::parse_box_content(t, sz); - sz -= (t-buf); - - bytestream_reader reader(t, sz); - - if (reader.available() < 7) { - std::cerr << "Not enough data for avc box.\n"; - return 0; - } - - _configuration_version = (unsigned) reader.read_uint8(); - _avc_profile_indication = (unsigned) reader.read_uint8(); - _profile_compatibility = (unsigned) reader.read_uint8(); - _avc_level_indication = (unsigned) reader.read_uint8(); - _length_size_minus_one = (unsigned) reader.read_uint8() & 0x03; - int num_sps = (int) reader.read_byte() & 0x1F; - - for (int i=0; iparse(t+offset, sps_size); - if (nb != sps_size) { - std::cerr << "WARN: Only " << nb << " bytes parsed in SPS, " - << sps_size << " bytes expected.\n"; - } - _sps.push_back(sps); - reader.skip(sps_size); - } - - int num_pps = (int) reader.read_uint8(); - if (num_pps < 0) { return reader.read_count(); } - - for (int i=0; iparse(t + offset, pps_size); - if (nb != pps_size) { - std::cerr << "WARN: Only " << nb << " bytes parsed in PPS, " - << pps_size << " bytes expected.\n"; - } - _pps.push_back(pps); - reader.skip(pps_size); - } - - return reader.read_count(); -} - -size_t avc_configuration_box::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += super::write_box_content(t, sz); - t += type_io::write_uint8(_configuration_version, t); - t += type_io::write_uint8(_avc_profile_indication, t); - t += type_io::write_uint8(_profile_compatibility, t); - t += type_io::write_uint8(_avc_level_indication, t); - t += type_io::write_uint8(_length_size_minus_one | 0xFC, t); - - t += type_io::write_uint8(_sps.size() | 0xE0, t); - - std::list::const_iterator itr1 = _sps.begin(); - for (; itr1 != _sps.end(); itr1++) { - int sz = (*itr1)->size(); - t += type_io::write_uint16(sz, t); - t += (*itr1)->write(t, sz); - } - - t += type_io::write_uint8(_pps.size(), t); - - std::list::const_iterator itr2 = _pps.begin(); - for (; itr2 != _pps.end(); itr2++) { - int sz = (*itr2)->size(); - t += type_io::write_uint16(sz, t); - t += (*itr2)->write(t, sz); - } - - return t-buf; -} - -// class descriptor_box - -descriptor_box::descriptor_box() -{ -} - -descriptor_box::~descriptor_box() -{ -} - -size_t descriptor_box::content_size() const -{ - return full_box::content_size() + data_holder::size(); -} - -size_t descriptor_box::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -size_t descriptor_box::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += full_box::write_box_content(t, sz); - t += data_holder::get_data(t, _data_size); - return t-buf; -} - -// class es_descriptor_box - -es_descriptor_box::es_descriptor_box() -{ - _type = "esds"; -} - -// class d263_box - -d263_box::d263_box() -{ - _type = "d263"; -} - -d263_box::~d263_box() -{ -} - -size_t d263_box::content_size() const -{ - return box::content_size() + data_holder::size(); -} - -size_t d263_box::parse_box_content(char* buf, size_t sz) -{ - return 0; -} - -size_t d263_box::write_box_content(char* buf, size_t sz) const -{ - char* t = buf; - t += box::write_box_content(t, sz); - t += data_holder::get_data(t, _data_size); - return t-buf; -} - -}; //namespace isomf - diff --git a/plugins/scan-video/isomf.h b/plugins/scan-video/isomf.h deleted file mode 100644 index e65fa43e..00000000 --- a/plugins/scan-video/isomf.h +++ /dev/null @@ -1,257 +0,0 @@ -#ifndef _ISOMF_H_ -#define _ISOMF_H_ - -#include -#include - -#include "isomf_base.h" -#include "h264_model.h" - -namespace isomf { - -/// Sample Description Box (ISO/IEC 14496-12 8.5.2) -class sample_description_box : public full_box -{ - public: - sample_description_box(); - ~sample_description_box(); - - virtual size_t content_size() const - { - // 4 byte entry count - return super::content_size() + 4; - } - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - private: - typedef full_box super; -}; - -/// Sample Entry Box (ISO/IEC 14496-12 8.5.2.2) -class sample_entry : public box -{ - public: - sample_entry(); - virtual ~sample_entry(); - - unsigned data_reference_index() const { return _data_ref_index; } - void data_reference_index(unsigned index) { _data_ref_index = index; } - - virtual size_t content_size() const - { - // 2 byte data reference index + 6 byte reserved data - return super::content_size() + 8; - } - - protected: - unsigned _data_ref_index; - - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - private: - typedef box super; -}; - -/// Visual Sample Entry Box (ISO/IEC 14496-12 8.5.2.2) -class visual_sample_entry : public sample_entry -{ - public: - visual_sample_entry(); - visual_sample_entry(const std::string& t); - virtual ~visual_sample_entry(); - - unsigned width() const { return _width; } - void width(unsigned w) { _width = w; } - - unsigned height() const { return _height; } - void height(unsigned h) { _height = h; } - - unsigned hres() const { return _hres; } - void hres(unsigned hr) { _hres = hr; } - - unsigned vres() const { return _vres; } - void vres(unsigned vr) { _vres = vr; } - - unsigned frame_count() const { return _frame_count; } - void frame_count(unsigned fc) { _frame_count = fc; } - - unsigned depth() const { return _depth; } - void depth(unsigned d) { _depth = d; } - - std::string compressor() const { return _compressor; } - void compressor(std::string& name) { _compressor = name; } - - virtual size_t content_size() const - { return super::content_size() + 70; } - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - unsigned _width; - unsigned _height; - unsigned _frame_count; - unsigned _depth; - // 16.16 fixed point horizontal resolution - unsigned _hres; - // 16.16 fixed point vertical resolution - unsigned _vres; - std::string _compressor; - - private: - typedef sample_entry super; -}; - -/// Audio Sample Entry Box (ISO/IEC 14496-12 8.5.2.2) -class audio_sample_entry : public sample_entry -{ - public: - audio_sample_entry(); - audio_sample_entry(const std::string& codec_type); - ~audio_sample_entry() {}; - - unsigned channel_count() const { return _channel_count; } - void channel_count(unsigned ch_cnt) { _channel_count = ch_cnt; } - - unsigned sample_size() const { return _sample_size; } - void sample_size(unsigned sz) { _sample_size = sz; } - - unsigned compression_id() const { return _compression_id; } - void compression_id(unsigned id) { _compression_id = id; } - - unsigned packet_size() const { return _packet_size; } - void packet_size(unsigned sz) { _packet_size = sz; } - - unsigned sample_rate() const { return _sample_rate; } - void sample_rate(unsigned rate) { _sample_rate = rate; } - - unsigned samples_per_packet() const { return _samples_per_packet; } - void samples_per_packet(unsigned n) { _samples_per_packet = n; } - - unsigned bytes_per_packet() const { return _bytes_per_packet; } - void bytes_per_packet(unsigned n) { _bytes_per_packet = n; } - - unsigned bytes_per_frame() const { return _bytes_per_frame; } - void bytes_per_frame(unsigned n) { _bytes_per_frame = n; } - - unsigned bytes_per_sample() const { return _bytes_per_sample; } - void bytes_per_sample(unsigned n) { _bytes_per_sample = n; } - - virtual size_t content_size() const; - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - unsigned _sound_version; - unsigned _channel_count; - unsigned _sample_size; - unsigned _compression_id; - unsigned _packet_size; - unsigned _sample_rate; - - unsigned _samples_per_packet; - unsigned _bytes_per_packet; - unsigned _bytes_per_frame; - unsigned _bytes_per_sample; - - char _version2_data[20]; - - private: - typedef sample_entry super; -}; - - -/// AVC Configuration Box (ISO 14496-15 5.2.4.1) -class avc_configuration_box : public box -{ - public: - avc_configuration_box(); - virtual ~avc_configuration_box() {}; - - virtual size_t content_size() const; - - unsigned configuration_version() const { return _configuration_version; } - void configuration_version(unsigned v) { _configuration_version = v; } - - unsigned avc_profile_indication() const {return _avc_profile_indication;} - void avc_profile_indication(unsigned v) {_avc_profile_indication = v;} - - unsigned profile_compatibility() const {return _profile_compatibility;} - void profile_compatibility(unsigned v) {_profile_compatibility = v;} - - unsigned avc_level_indication() const {return _avc_level_indication;} - void avc_level_indication(unsigned v) {_avc_level_indication = v;} - - unsigned length_size_minus_one() const {return _length_size_minus_one;} - void length_size_minus_one(unsigned v) {_length_size_minus_one = v;} - - void add(sequence_parameter_set& set) {_sps.push_back(&set);} - void add(picture_parameter_set& set) {_pps.push_back(&set);} - - void remove(sequence_parameter_set& set) {_sps.remove(&set);} - void remove(picture_parameter_set& set) {_pps.remove(&set);} - - std::list& get_sps_list() { return _sps; } - std::list& get_pps_list() { return _pps; } - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - unsigned _configuration_version; - unsigned _avc_profile_indication; - unsigned _profile_compatibility; - unsigned _avc_level_indication; - unsigned _length_size_minus_one; - - std::list _sps; - std::list _pps; - - private: - typedef box super; -}; - -// base class for descriptor classes - -class descriptor_box : public full_box, public data_holder -{ - public: - descriptor_box(); - virtual ~descriptor_box(); - - virtual size_t content_size() const; - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; -}; - -class es_descriptor_box : public descriptor_box -{ - public: - es_descriptor_box(); - virtual ~es_descriptor_box() {}; -}; - -class d263_box : public box, public data_holder -{ - public: - d263_box(); - virtual ~d263_box(); - - virtual size_t content_size() const; - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; -}; - -}; //namespace isomf - -#endif - diff --git a/plugins/scan-video/isomf_base.h b/plugins/scan-video/isomf_base.h deleted file mode 100644 index 8c887350..00000000 --- a/plugins/scan-video/isomf_base.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef ISOMF_BASE_H -#define ISOMF_BASE_H - -namespace isomf { - -/// Generic Box (ISO/IEC 14496-12 4.2) -class box -{ - public: - box(); - box(const std::string& box_type); - box(const box& b); - virtual ~box() {}; - - std::string type() const { return _type; } - void get_extended_type(char* type_buf) const; - void set_extended_type(char* type_buf); - - virtual size_t content_size() const; - virtual size_t size() const; - bool is_small() const; - - box& operator=(const box& box); - - virtual size_t parse(char* buf, size_t sz); - virtual size_t write(char* buf, size_t sz) const; - - const box* parent() const { return _parent; } - void parent(const box& p) { _parent = &p; } - - std::list children() const { return _children; } - void add(const box& c); - void remove(const box& c); - - protected: - size_t parse_header(char* buf, size_t sz); - size_t parse_children(char* buf, size_t sz); - - size_t write_header(char* buf, size_t sz) const; - size_t write_children(char* buf, size_t sz) const; - - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - std::string _type; - char _extended_type[16]; - - const box* _parent; - std::list _children; -}; - -/// Full Box (ISO/IEC 14496-12 4.2) -class full_box : public box -{ - public: - full_box(); - virtual ~full_box() {}; - - unsigned version() const { return _version; } - void version(unsigned v) { _version = v; } - unsigned flags() const { return _flags; } - void flags(unsigned f) { _flags = f; } - - virtual size_t content_size() const - { return super::content_size() + 4; } - - full_box& operator=(const full_box& box); - - protected: - virtual size_t parse_box_content(char* buf, size_t sz); - virtual size_t write_box_content(char* buf, size_t sz) const; - - unsigned _version; - unsigned _flags; - - private: - typedef box super; -}; - -/// Generic data holder -class data_holder -{ - public: - data_holder(); - data_holder(const data_holder& d); - virtual ~data_holder(); - - unsigned size() const { return _data_size; } - - void clear(); - size_t set_data(const char* data, size_t size); - size_t get_data(char* data, size_t size) const; - - virtual size_t parse(const char* buf, size_t sz) { return 0; }; - virtual size_t write(char* buf, size_t sz) const { return 0; }; - - data_holder& operator=(const data_holder& d); - - protected: - char* _data; - unsigned _data_size; -}; - -}; // namespace isomf - -#endif diff --git a/plugins/scan-video/isomf_factory.cpp b/plugins/scan-video/isomf_factory.cpp deleted file mode 100644 index 3d613abe..00000000 --- a/plugins/scan-video/isomf_factory.cpp +++ /dev/null @@ -1,232 +0,0 @@ -#include -#include - -#include "isomf.h" -#include "isomf_factory.h" -#include "type_io.h" - -namespace isomf { - -// sample sequence parameter set from a real video. -// unfortunately this part varies from video to video. -static char _sample_sps[27] = { - 0x67, 0x42, 0xc0, 0x0d, 0xab, 0x40, 0xa0, 0xfd, - 0xff, 0x80, 0x07, 0x80, 0x08, 0x08, 0x00, 0x00, - 0x03, 0x00, 0xc8, 0x00, 0x00, 0x0f, 0xc4, 0x78, - 0xa1, 0x55, 0x01 -}; - -// sample picture parameter set from a real video. more stable than sps. -static char _sample_pps[4] = {0x68, 0xce, 0x3c, 0x80}; - -// sample description box. -static char _sample_esds[44] = { - 0x03, 0x2a, 0x00, 0x00, 0x10, 0x04, 0x22, 0x20, - 0x11, 0x00, 0x50, 0x00, 0x00, 0x01, 0x64, 0x90, - 0x00, 0x01, 0x39, 0xe9, 0x05, 0x13, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0xc8, - 0x88, 0x80, 0x07, 0xd0, 0x58, 0x41, 0x21, 0x41, - 0x03, 0x06, 0x01, 0x02 -}; - -static char _sample_d263[7] = { - 0x46, 0x46, 0x4d, 0x50, 0x00, 0x0a, 0x00 -}; - -/* -static char _sample_d263[7] = { - 0x73, 0x36, 0x30, 0x20, 0x00, 0x0a, 0x00 -}; -*/ - -// class parameter_set_factory - -sequence_parameter_set* parameter_set_factory::get_avc_sps() -{ - sequence_parameter_set* sps = new sequence_parameter_set(); - - // The following sets SPS from raw data - //size_t nb = sps->parse(_sample_sps, sizeof(_sample_sps)); - //cerr << "SPS parsed " << nb << " bytes." << endl; - - // Instead, we can set it to be most frequently occurred values. - sps->pic_order_cnt_type = 0; - sps->field_pic_flag = false; - sps->delta_pic_order_always_zero_flag = false; - sps->entropy_coding_mode_flag = false; - sps->mb_adaptive_frame_field_flag = false; - sps->direct_8x8_inference_flag = true; - sps->chroma_format_idc = &(chroma_format::YUV_420); - sps->log2_max_frame_num_minus4 = 1; - sps->log2_max_pic_order_cnt_lsb_minus4 = 1; - sps->pic_height_in_map_units_minus1 = 39; - sps->pic_width_in_mbs_minus1 = 2; - sps->bit_depth_luma_minus8 = 0; - sps->bit_depth_chroma_minus8 = 0; - sps->qpprime_y_zero_transform_bypass_flag = false; - sps->profile_idc = 39; - sps->constraint_set_0_flag = false; - sps->constraint_set_1_flag = true; - sps->constraint_set_2_flag = false; - sps->constraint_set_3_flag = false; - sps->level_idc = 224; - sps->seq_parameter_set_id = 14; - sps->residual_color_transform_flag = false; - sps->offset_for_non_ref_pic = 0; - sps->offset_for_top_to_bottom_field = 0; - sps->num_ref_frames = 1; - sps->gaps_in_frame_num_value_allowed_flag = false; - sps->frame_mbs_only_flag = true; - sps->frame_cropping_flag = true; - sps->frame_crop_left_offset = 0; - sps->frame_crop_right_offset = 0; - sps->frame_crop_top_offset = 0; - sps->frame_crop_bottom_offset = 0; - sps->offset_for_ref_frame = NULL; - sps->num_ref_frames_in_pic_order_cnt_cycle = 0; - sps->reserved = 2; - - sps->vui_params = NULL; - sps->scalingmatrix = NULL; - - return sps; -} - -picture_parameter_set* parameter_set_factory::get_avc_pps() -{ - picture_parameter_set* pps = new picture_parameter_set(); - - // The following line generates PPS from a sample - //pps->parse(_sample_pps, sizeof(_sample_pps)); - - // Instead we can set common values - pps->entropy_coding_mode_flag = false; - pps->num_ref_idx_l0_active_minus1 = 37; - pps->num_ref_idx_l1_active_minus1 = 3; - pps->slice_group_change_rate_minus1 = 0; - pps->pic_parameter_set_id = 4; - pps->seq_parameter_set_id = 12; - pps->pic_order_present_flag = true; - pps->num_slice_groups_minus1 = 0; - pps->slice_group_map_type = 0; - pps->weighted_pred_flag = false; - pps->weighted_bipred_idc = 0; - pps->pic_init_qp_minus26 = 0; - pps->pic_init_qs_minus26 = 0; - pps->chroma_qp_index_offset = 0; - pps->deblocking_filter_control_present_flag = false; - pps->constrained_intra_pred_flag = false; - pps->redundant_pic_cnt_present_flag = false; - pps->top_left = NULL; - pps->bottom_right = NULL; - pps->run_length_minus1 = NULL; - pps->slice_group_change_direction_flag = false; - pps->pic_size_map_units_minus1 = 0; - pps->slice_group_id = NULL; - pps->extended = NULL; - - return pps; -} - -// class box_factory - -es_descriptor_box* box_factory::get_esds() -{ - es_descriptor_box* esds = new es_descriptor_box(); - esds->set_data(_sample_esds, sizeof(_sample_esds)); - return esds; -} - -sample_description_box* -box_factory::get_avc_stsd(unsigned width, unsigned height) -{ - sample_description_box* box = new sample_description_box(); - - visual_sample_entry* entry = new visual_sample_entry("avc1"); - entry->width(width); - entry->height(height); - - box->add(*entry); - - avc_configuration_box* avcc = new avc_configuration_box(); - entry->add(*avcc); - - sequence_parameter_set* sps = parameter_set_factory::get_avc_sps(); - picture_parameter_set* pps = parameter_set_factory::get_avc_pps(); - - avcc->add(*sps); - avcc->add(*pps); - - //std::cerr << " >> Got avcC box of size: " << avcc->size() - // << ", content size: " << avcc->content_size() << "\n"; - - return box; -} - -sample_description_box* -box_factory::get_mp4a_stsd() -{ - sample_description_box* box = new sample_description_box(); - - audio_sample_entry* entry = new audio_sample_entry("mp4a"); - box->add(*entry); - - es_descriptor_box* esds = get_esds(); - entry->add(*esds); - - return box; -} - -sample_description_box* -box_factory::get_mp4v_stsd(unsigned width, unsigned height) -{ - sample_description_box* box = new sample_description_box(); - - visual_sample_entry* entry = new visual_sample_entry("mp4v"); - entry->width(width); - entry->height(height); - - box->add(*entry); - - es_descriptor_box* esds = box_factory::get_esds(); - entry->add(*esds); - - return box; -} - -sample_description_box* -box_factory::get_h263_stsd(unsigned width, unsigned height) -{ - sample_description_box* box = new sample_description_box(); - - visual_sample_entry* entry = new visual_sample_entry("h263"); - entry->width(width); - entry->height(height); - - box->add(*entry); - - d263_box* d263 = new d263_box(); - d263->set_data(_sample_d263, sizeof(_sample_d263)); - entry->add(*d263); - - return box; -} - -void box_factory::print_stsd(sample_description_box* box) -{ - if (! box) { - return; - } - - size_t sz = box->size(); - std::cout << "===== STSD sample description box: " << sz << " bytes\n"; - char* buf = new char[sz]; - memset(buf, 0xfe, sz); - size_t nb = box->write(buf, sz); - std::cerr << "===== STSD Written " << nb << " bytes.\n"; - type_io::print_hex(buf, static_cast(nb)); - std::cerr << "===== STSD DONE\n"; -} - - -}; // namespace isomf diff --git a/plugins/scan-video/isomf_factory.h b/plugins/scan-video/isomf_factory.h deleted file mode 100644 index a354bdda..00000000 --- a/plugins/scan-video/isomf_factory.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _ISOMF_FACTORY_H_ -#define _ISOMF_FACTORY_H_ - -#include -#include "isomf.h" - -namespace isomf { - -// factory class to generaet parameter set - -class parameter_set_factory -{ - public: - static sequence_parameter_set* get_avc_sps(); - static picture_parameter_set* get_avc_pps(); -}; - -// factory class to generaet boxes -class box_factory -{ - public: - static es_descriptor_box* get_esds(); - - static sample_description_box* - get_avc_stsd(unsigned width, unsigned height); - - static sample_description_box* - get_mp4a_stsd(); - - static sample_description_box* - get_mp4v_stsd(unsigned width, unsigned height); - - static sample_description_box* - get_h263_stsd(unsigned width, unsigned height); - - static void print_stsd(sample_description_box* box); -}; - -}; // namespace isomf - -#endif diff --git a/plugins/scan-video/keyframe_utils.cpp b/plugins/scan-video/keyframe_utils.cpp deleted file mode 100644 index 746b5efb..00000000 --- a/plugins/scan-video/keyframe_utils.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "keyframe_utils.h" -#include - -using namespace cv; -using namespace std; - -keyframe_utils::keyframe_utils(): av_frame_rgb(NULL), img_convert_ctx(NULL), is_initialzed(false){} - -keyframe_utils::~keyframe_utils(){} - -keyframe_utils::keyframe_utils(const keyframe_utils& u): av_frame_rgb(u.av_frame_rgb), img_convert_ctx(u.img_convert_ctx), is_initialzed(u.is_initialzed){} - -keyframe_utils& keyframe_utils::operator= (const keyframe_utils& u){ - av_frame_rgb = u.av_frame_rgb; - img_convert_ctx = u.img_convert_ctx; - is_initialzed = u.is_initialzed; - return *this; -} - - -bool keyframe_utils::initialize(const AVCodecContext *codec){ - if(is_initialzed) - return true; - is_initialzed = true; - unsigned int h = codec->height; - unsigned int w = codec->width; - try { - /// Initialze SwsContext to convert compressed videos from native format (YUV420, YVY12 etc) - /// to BGR24 using bicubic interpolation - if(img_convert_ctx == NULL) { - img_convert_ctx = sws_getContext(w, h, codec->pix_fmt, w, h, PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL); - if(img_convert_ctx == NULL) { - std::cerr << __FILE__ << " : " << __LINE__ << " Cannot initialize the conversion context. w = "<< w << " h = " << h << endl; - return false; - } - } - // Allocate memory for a BGR 24 frame of resolution w x h - av_frame_rgb = avcodec_alloc_frame(); - if (!av_frame_rgb){ - std::cerr << __FILE__ << " : " << __LINE__ << "Unable to allocate frame memory\n"; - return false; - } - - uint8_t *picture_buf; - int size = avpicture_get_size(PIX_FMT_BGR24, w, h); - picture_buf = (uint8_t *) av_malloc(size); - if (!picture_buf) { - std::cerr << __FILE__ << " : " << __LINE__ << "Unable to allocate frame memory\n"; - av_free(av_frame_rgb); - return false; - } - avpicture_fill((AVPicture *)av_frame_rgb, picture_buf,PIX_FMT_BGR24, w, h); - }catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ - << ": Unable to create cv::Mat object.\n"; - return false; - } - return true; -} - -bool keyframe_utils::reset(){ - sws_freeContext(img_convert_ctx); - av_free(av_frame_rgb); - is_initialzed = false; - return true; -} - -bool keyframe_utils::convert_frame_to_mat(const AVFrame *src, cv::Mat& dst, const AVCodecContext *codec){ - unsigned int h = codec->height; - unsigned int w = codec->width; - - try{ - sws_scale(img_convert_ctx, src->data, src->linesize, 0, h, av_frame_rgb->data, av_frame_rgb->linesize); - unsigned char* data = av_frame_rgb->data[0]; - unsigned int data_size = av_frame_rgb->linesize[0]; - dst.create(h, w, CV_8UC3); - for(size_t y = 0; y < h; ++y){ - for (size_t x = 0; x < w; ++x){ - dst.at(y,x)[0] = data[y * data_size + x * 3 + 0]; - dst.at(y,x)[1] = data[y * data_size + x * 3 + 1]; - dst.at(y,x)[2] = data[y * data_size + x * 3 + 2]; - } - } - } catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ - << ": Unable to create cv::Mat object.\n"; - return false; - } - return true; -} - -bool keyframe_utils::save_keyframe(const std::string file_name, const AVCodecContext *codec, const AVFrame *src){ - try { - Mat dst; - if(!convert_frame_to_mat(src, dst, codec)) - return false; - imwrite(file_name.c_str(), dst); - - } catch (...) { - std::cerr << __FILE__ << ":" << __LINE__ - << ": Unable to save key frame.\n"; - return false; - } - return true; -} - -bool keyframe_utils::calculate_motion_score(const AVFrame *f, const AVCodecContext *codec, double& score, double &intra_likelihood){ - - // Calculate MB stride and set parameters to use sub-pel Motion vectors - int mb_width = (codec->width + 15) / 16; - int mb_height = (codec->height + 15) / 16; - int mb_stride = mb_width + 1; - int mv_sample_log2 = 4 - f->motion_subsample_log2; - int mv_stride = (mb_width << mv_sample_log2) + (codec->codec_id == CODEC_ID_H264 ? 0 : 1); - int quarter_sample = (codec->flags & CODEC_FLAG_QPEL) != 0; - int shift = 1 + quarter_sample; - int direction = 0; - double intra_count = 0.0; - - if ((NULL == f->motion_val) || (NULL == f->motion_val[direction]) || (NULL == f->motion_val[direction][0])){ - cerr << "MV Array is NULL\n"; - return false; - } - - int mb_index = 0; - int xy = 0, dx = 0, dy = 0; - score = 0; intra_likelihood = 0; - - - // Iterate through all the Macroblocks in the frame and check if - - // * Is it intra or not? - // * If it has a motion vector, get magnitude - // Calculate final scores - for (int mb_y = 0; mb_y < mb_height; ++mb_y) { - for (int mb_x = 0; mb_x < mb_width; ++mb_x) { - mb_index = mb_x + mb_y * mb_stride; - - if (!USES_LIST(f->mb_type[mb_index], direction)) { - if (IS_8X8(f->mb_type[mb_index])) { - intra_count += 0.25; - } else if ((IS_16X8(f->mb_type[mb_index])) || (IS_8X16(f->mb_type[mb_index]))){ - intra_count += 0.5; - }else if((IS_INTRA(f->mb_type[mb_index])) || (IS_IPCM(f->mb_type[mb_index])) || (IS_INTRA16x16(f->mb_type[mb_index]))){ - intra_count += 1.0; - }else { - intra_count += 1.0; - } - continue; - } - - if (IS_8X8(f->mb_type[mb_index])) { - for (int i = 0; i < 4; i++) { - xy = (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1); - dx = (f->motion_val[direction][xy][0]>>shift); - dy = (f->motion_val[direction][xy][1]>>shift); - - score += get_magnitude(dx, dy); - } - } else if (IS_16X8(f->mb_type[mb_index])) { - for (int i = 0; i < 2; i++) { - xy = (mb_x*2 + (mb_y*2 + i)*mv_stride) << (mv_sample_log2-1); - dx = (f->motion_val[direction][xy][0]>>shift); - dy = (f->motion_val[direction][xy][1]>>shift); - - if (IS_INTERLACED(f->mb_type[mb_index])) - dy *= 2; - - score += get_magnitude(dx, dy); - } - } else if (IS_8X16(f->mb_type[mb_index])) { - for (int i = 0; i < 2; i++) { - xy = (mb_x*2 + i + mb_y*2*mv_stride) << (mv_sample_log2-1); - dx = (f->motion_val[direction][xy][0]>>shift); - dy = (f->motion_val[direction][xy][1]>>shift); - - if (IS_INTERLACED(f->mb_type[mb_index])) - dy *= 2; - - score += get_magnitude(dx, dy); - } - } else { - xy = (mb_x + mb_y*mv_stride) << mv_sample_log2; - dx = (f->motion_val[direction][xy][0]>>shift); - dy = (f->motion_val[direction][xy][1]>>shift); - - score += get_magnitude(dx, dy); - } - - } - - intra_likelihood = intra_count / (mb_height * mb_width * 1.0); - score = score / (mb_height * mb_width * 1.0); - } - return true; -} \ No newline at end of file diff --git a/plugins/scan-video/keyframe_utils.h b/plugins/scan-video/keyframe_utils.h deleted file mode 100644 index acf62284..00000000 --- a/plugins/scan-video/keyframe_utils.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef _KEYFRAME_UTILS_H_ -#define _KEYFRAME_UTILS_H_ - -#include -#include -#include - - -extern "C" { -#include "libavcodec/avcodec.h" -#include "libavformat/avformat.h" -#include "libavutil/avutil.h" -#include "libswscale/swscale.h" -} -#include - -/// \class keyframe_utils keyframe_utils.h -/// \brief The class implements utilities needed by the extract_keyframes class -/// and the histogram_process class. -/// - -class keyframe_utils{ -public: - - /// Default constructor - keyframe_utils(); - - /// Copy constructor - uses the FFMPEG codec construct to allocate memory - /// which will be used by the histogram process. - keyframe_utils(const keyframe_utils& u); - - /// Default Destructor - ~keyframe_utils(); - - /// Assignment operator - keyframe_utils& operator= (const keyframe_utils& u); - - /// \brief Interfaces FFMPEG data structures (AVFrame) to OpenCV data structures (cv::Mat) - /// \param (src) - input frame - AVFrame (libavcodec/avcodec.h) - /// \param (dst) - output matrix - /// \param (codec) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// \return the status of the function. - /// - bool convert_frame_to_mat(const AVFrame *src, cv::Mat& dst, const AVCodecContext *codec); - - /// \brief Saves the AVFrame to disk as a jpeg file - /// \param (src) - input frame - AVFrame (libavcodec/avcodec.h) - /// \param (file_name) - name & path of the output jpeg file - /// \param (codec) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// \return the status of the function. - /// - bool save_keyframe(const std::string file_name, const AVCodecContext *codec, const AVFrame *src); - - /// \brief - Initializes all the parameters based on the codec parameters. - bool initialize(const AVCodecContext *codec); - - /// \brief - resets all the parameters to default values - bool reset(); - - /// \brief - Calulates the motion_score and intra_likelihood - /// \param (f) - input frame - AVFrame (libavcodec/avcodec.h) - /// \param (codec) FFMPEG video decoder constructs (libavcodec/avcodec.h) - /// \param(score) - motion score for the given input frame - /// \param(intra_likelihood) - ratio of intra macroblock to the frame size - /// \return the status of the function. - /// - bool calculate_motion_score(const AVFrame *f, const AVCodecContext *codec, double& score, double &intra_likelihood); - - /// The below utility functions identify the macro block type - static inline bool IS_INTERLACED(int a) { if((a) & MB_TYPE_INTERLACED) return true; return false; } - - static inline bool IS_16X16(int a) { if((a) & MB_TYPE_16x16) return true; return false; } - - static inline bool IS_16X8(int a) { if((a) & MB_TYPE_16x8) return true; return false; } - - static inline bool IS_8X16(int a) { if((a) & MB_TYPE_8x16) return true; return false; } - - static inline bool IS_8X8(int a) { if((a) & MB_TYPE_8x8) return true; return false; } - - static inline bool USES_LIST(int a, int list){ if ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) return true; return false; } - - static inline bool IS_INTRA4x4(int a) { if((a) & MB_TYPE_INTRA4x4) return true; return false; } - - static inline bool IS_INTRA16x16(int a) { if((a) & MB_TYPE_INTRA16x16) return true; return false; } - - static inline bool IS_IPCM(int a) { if((a) & MB_TYPE_INTRA_PCM) return true; return false; } - - static inline bool IS_INTRA(int a) { if((a) & 7) return true; return false; } - - static inline bool IS_INTER(int a) { if((a) & (MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8)) return true; return false; } - - static inline bool IS_SKIP(int a) { if((a) & MB_TYPE_SKIP) return true; return false; } - - static inline float get_magnitude(int x, int y){ return sqrt((x * x) + (y * y)); } - - -private: - AVFrame *av_frame_rgb; /// FFMPEG construct - libavcodec/avcodec.h - struct SwsContext *img_convert_ctx; /// FFMPEG construct - libswscale/swscale.h - bool is_initialzed; - -}; - -#endif \ No newline at end of file diff --git a/plugins/scan-video/run_parse_avcc.sh b/plugins/scan-video/run_parse_avcc.sh deleted file mode 100644 index 67d2a1f3..00000000 --- a/plugins/scan-video/run_parse_avcc.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -if [ -z "$*" ]; then - echo "Usage: $0 [[raw_avc_file] ...]"; -fi - -/bin/mkdir -p out - -for f in $*; do - echo $f - name=`basename $f` - ./test/test_parse_avcc.t $f > out/"$name".log 2>&1 -done - diff --git a/plugins/scan-video/scan_3g2.cpp b/plugins/scan-video/scan_3g2.cpp deleted file mode 100644 index 3d306d71..00000000 --- a/plugins/scan-video/scan_3g2.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/** -* -* scan_3g2: -*/ - - -#include "../src/bulk_extractor.h" -#include "fix_mp4.h" -#include "extract_keyframes.h" -#include "video_processor.h" - -#include -#include -#include - -#include -#include - -// Header keywords - signatures found at the start of file -static const char _3G2_MAIN_HEADER[ fix_mp4::HEADER_SIZE] = {'f', 't', 'y', 'p'}; -static const int _3G2_SUB_HEADER_NO = 5; -static const int _3G2_SUB_HEADER_SIZE = 3; -static const char _3G2_SUB_HEADER[_3G2_SUB_HEADER_SIZE] = {'3', 'g', '2'}; - -// Scanner return status -typedef enum { - SCANNER_STATUS_FAILURE = -1, - SCANNER_STATUS_OK = 0, - SCANNER_STATUS_LEAF -}SCANNER_STATUS; - -// Parse last 2 entries of all the "stco" chunks. -bool parse_stco(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stco - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STCO[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 'c', 'o'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STCO, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - if((size < 0) || (size + offset > total_bytes) || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)) - return false; - - - //index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - size_t stco_tmp; - for(size_t i = 0; i < loop_sz; ++i){ - // the values of the stco entries will not be validated here. They should be checked at the time of usage. - // This is so, because we dont have the complete stbl info here. - stco_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stco_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - - return true; -} - -bool parse_stsz(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stsz - - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSZ[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'z'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSZ, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 2); - size_t u_sz = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - - size_t num_entries = (s[16] << 24) | (s[17] << 16) | (s[18] << 8) | (s[19]); - - size_t loop_sz = 20; - if(0 == u_sz) { - if(loop_sz > num_entries) - loop_sz = num_entries; - } - - if((size < 0) || (size + offset > total_bytes) || (((loop_sz * fix_mp4::LENGTH_SIZE) > size) && (0 == u_sz))) - return false; - - index += fix_mp4::LENGTH_SIZE; - size_t stsz_tmp = 0; - if(0 == u_sz){ - // Mode - 2 - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - - for(size_t i = 0; i < loop_sz; ++i){ - stsz_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stsz_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - }else{ - // Mode - 1 - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(u_sz); - } - } - return true; -} - - -bool parse_stsc(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - //Ref - isoiec 14496-12.pdf 8.7.4.2 Syntax We are not parsing the entire stsc chunk, - // here we are just going to parse the "samples_per_chunk" - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSC[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'c'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSC, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - - if((size < 0) || (size + offset > total_bytes)/* || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)*/) - return false; - - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - size_t stsc_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - //if(arr_sz == -1){ - index = (size - (fix_mp4::LENGTH_SIZE * 2)); - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(stsc_tmp); - } - /*}else{ - //std::cerr << "Support needs to be added to parse the 'stsc' chunk. We currently support parsing the last entry alone\n"; - }*/ - return true; -} - -bool is_footer(const unsigned char *p, size_t offset, size_t total_bytes, int last_atom_idx, - std::vector &stco, std::vector &stsz, std::vector &stsc){ - // the last atom is "mdat" we cannot validate this file. - if(last_atom_idx == 0) - return false; - - if((last_atom_idx == 9) || (last_atom_idx == 10) || (last_atom_idx == 11)){ // stco, stsz, stsc - if(stco.size() == stsz.size()){ - // 1. use the largest stco entry and its corresponding stsc and stsz entries and check for the presence of a kw. - // * also mark the id for the second largest entry. - size_t max_id = 0, prev_id = 0, max = 0; - for(size_t i = 0; i < stco.size(); ++i){ - if(stco[i] > max) { - max = stco[i]; - prev_id = max_id; - max_id = i; - } - } - size_t offset_2_kw = stco[max_id] + (stsc[0] * stsz[max_id]); - if((offset_2_kw + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME) > total_bytes) return false; - int index = offset_2_kw + fix_mp4::LENGTH_SIZE; - bool is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((p + index), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - break; - } - } - if(!is_found) return false; - - bool is_footer = false; - // 2. if stco is the last entry then try to validate the last entry. - if(last_atom_idx == 9){ - // if max_id is the last entry, then choose the next largest entry add the stsz - // else subtract - size_t last_id = stco.size() - 1; - size_t check_offset = 0; - if(max_id == last_id){ - check_offset = stco[prev_id] + stsz[prev_id]; - if(check_offset == stco[max_id]){ - is_footer = true; - } - }else if(prev_id == last_id){ - check_offset = stco[max_id] - stsz[max_id]; - if(check_offset == stco[prev_id]){ - is_footer = true; - } - }else{ - for(size_t i = 0; i < last_id; ++i){ - check_offset = stco[i] + stsz[i]; - if(check_offset == stco[last_id]){ - is_footer = true; - break; - } - } - } - - } - return is_footer; - }else{ - } - }else if(last_atom_idx == 116){ - size_t size = (p[offset] << 24) | (p[offset + 1] << 16) | (p[offset + 2] << 8) | (p[offset + 3]); - if((size < 0) || (offset + size > total_bytes)){ - return false; - } - if(p[offset + 12] == 0xff && p[offset + 13] == 0xd8 && - p[offset + size - 2] == 0xff && p[offset + size - 1] == 0xd9){ - return true; - } - } - return false; -} - -SCANNER_STATUS carve_from_keyword(const unsigned char *p, size_t offset, size_t total_bytes, size_t &length, int &last_atom_idx, std::vector &stco, std::vector &stsz, std::vector &stsc, bool footer){ - size_t index = 0, size = 0, prev_index = 0; - bool is_found = false; - const unsigned char *s = p + offset; - - if(total_bytes == 0) - return SCANNER_STATUS_OK; - // leaf atom check - if we have reached a leaf atom, we can terminate the recursive search for children atoms. - if((offset + index) < total_bytes - 0x8){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - if(is_found == false){ - return SCANNER_STATUS_LEAF; - } - }else { - return SCANNER_STATUS_LEAF; - } - size_t child_length = 0; - for(;(offset + index) < total_bytes - 0x8;){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - // No key word found - implies that either we have reached end of file or the file is truncated. - if(is_found == false){ - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else{ - if(index == total_bytes){ - length += index; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME; - } - return SCANNER_STATUS_OK; - } - } - - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - }else if (size == 1 ){ - //std::cerr << "64 bit atom size. Add support\n"; - }else if (size == 0 ){ - // size = 0 indicates that this atom extends to the end of file. which we have no method of identifying for now. - // This is seen only with mdat atoms so far. With "mdat" as the last atom, validation is not possible. - // verify if stbl atoms occur with a zero size and support. - if(last_atom_idx == 0){ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - - return SCANNER_STATUS_FAILURE; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(size + index + offset > total_bytes){ - return SCANNER_STATUS_FAILURE; - } - - if(last_atom_idx == 9){ - // stco - if(!parse_stco((s + index), 0, size, stco)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 10){ - //stsz - if(!parse_stsz((s + index), 0, size, stsz)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 11){ - //stsc - if(!parse_stsc((s + index), 0, size, stsc)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - - prev_index = index; - // recursively parse the tree upto the child atoms. we validate the entire structure. - if(SCANNER_STATUS_FAILURE != carve_from_keyword((s + index), (fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE), (size - fix_mp4::LENGTH_OF_ATOM_NAME - fix_mp4::LENGTH_SIZE), - child_length, last_atom_idx, stco, stsz, stsc, false)){ - index += size; - }else{ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + child_length + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - // Footer check is performed only at the first call of carve_from_keyword. Subsequently, we parse for the children atoms. - if(footer){ - if(is_footer(p, (offset + prev_index), total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - return SCANNER_STATUS_OK; -} - - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0, size = 0; - index = fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE; - - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME; - return false; - } - index = size; - length += index; - int last_atom_idx = -1; - std::vector stco, stsz, stsc; - if(carve_from_keyword(s, index, total_bytes, length, last_atom_idx, stco, stsz, stsc, true) == SCANNER_STATUS_OK){ - return true; - }else - return false; -} - - - -extern "C" - void scan_3g2(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.version != 1){ - cerr << "scan_3g2 requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "3g2"; - sp.info->feature_names.insert("3g2"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *recorder = fs.get_name("3g2"); - recorder->set_quoting_enabled(false); - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - - - size_t offset = 0; - size_t length = 0; - bool status; - - fix_mp4 fixer; - extract_keyframes ek; - std::string file_name; - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 0x10))); ++cc){ - - if( memcmp((cc + fix_mp4::LENGTH_SIZE), _3G2_MAIN_HEADER, fix_mp4::HEADER_SIZE) == 0){ - if((memcmp((cc + fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE), _3G2_SUB_HEADER, (_3G2_SUB_HEADER_SIZE)) == 0)){ - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - recorder->write(sp.sbuf.pos0+offset, " ", b2); - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *recorder); - }else{ - // partial header found, try reconstruction instead. - //use the video processor to convert/store the video found - video_processor vp; - status = true; - if(!vp.process_header(sbuf, offset, *recorder)){ - // Video processor failed, Try to fix the video using fixmp4 - if(!fixer.do_fix(sbuf, offset, *recorder)){ - status = false; - - }else{ - file_name = fixer.get_file_name(); - } - }else{ - file_name = vp.get_file_name(); - } - // Extract key frames based on output file - if(!file_name.empty() && status){ - ek.extract(file_name); - file_name.clear(); - } - - } - - } - - - } - cc += length; - length = 0; - } - return; -} - diff --git a/plugins/scan-video/scan_3gp.cpp b/plugins/scan-video/scan_3gp.cpp deleted file mode 100644 index 18b01fb4..00000000 --- a/plugins/scan-video/scan_3gp.cpp +++ /dev/null @@ -1,421 +0,0 @@ -/** -* -* scan_3gp: -*/ - -#include -#include -#include -#include "../src/bulk_extractor.h" -#include "fix_mp4.h" - -#include -#include - -#include "video_processor.h" -#include "extract_keyframes.h" - -// Header keywords - signatures found at the start of file -static const char _3GP_MAIN_HEADER[ fix_mp4::HEADER_SIZE] = {'f', 't', 'y', 'p'}; -static const int _3GP_SUB_HEADER_NO = 5; -static const int _3GP_SUB_HEADER_SIZE = 3; -static const char _3GP_SUB_HEADER[_3GP_SUB_HEADER_SIZE] = {'3', 'g', 'p'}; - -// Scanner return status -typedef enum { - SCANNER_STATUS_FAILURE = -1, - SCANNER_STATUS_OK = 0, - SCANNER_STATUS_LEAF -}SCANNER_STATUS; - -// Parse last 2 entries of all the "stco" chunks. -bool parse_stco(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stco - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STCO[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 'c', 'o'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STCO, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - if((size < 0) || (size + offset > total_bytes) || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)) - return false; - - - //index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - size_t stco_tmp; - for(size_t i = 0; i < loop_sz; ++i){ - // the values of the stco entries will not be validated here. They should be checked at the time of usage. - // This is so, because we dont have the complete stbl info here. - stco_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stco_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - - return true; -} - -bool parse_stsz(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stsz - - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSZ[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'z'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSZ, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 2); - size_t u_sz = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - - size_t num_entries = (s[16] << 24) | (s[17] << 16) | (s[18] << 8) | (s[19]); - - size_t loop_sz = 20; - if(0 == u_sz) { - if(loop_sz > num_entries) - loop_sz = num_entries; - } - - if((size < 0) || (size + offset > total_bytes) || (((loop_sz * fix_mp4::LENGTH_SIZE) > size) && (0 == u_sz))) - return false; - - index += fix_mp4::LENGTH_SIZE; - size_t stsz_tmp = 0; - if(0 == u_sz){ - // Mode - 2 - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - - for(size_t i = 0; i < loop_sz; ++i){ - stsz_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stsz_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - }else{ - // Mode - 1 - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(u_sz); - } - } - return true; -} - - -bool parse_stsc(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - //Ref - isoiec 14496-12.pdf 8.7.4.2 Syntax We are not parsing the entire stsc chunk, - // here we are just going to parse the "samples_per_chunk" - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSC[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'c'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSC, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - - if((size < 0) || (size + offset > total_bytes)/* || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)*/) - return false; - - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - size_t stsc_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - //if(arr_sz == -1){ - index = (size - (fix_mp4::LENGTH_SIZE * 2)); - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(stsc_tmp); - } - return true; -} - -bool is_footer(const unsigned char *p, size_t offset, size_t total_bytes, int last_atom_idx, - std::vector &stco, std::vector &stsz, std::vector &stsc){ - // the last atom is "mdat" we cannot validate this file. - if(last_atom_idx == 0) - return false; - - if((last_atom_idx == 9) || (last_atom_idx == 10) || (last_atom_idx == 11)){ // stco, stsz, stsc - if(stco.size() == stsz.size()){ - // 1. use the largest stco entry and its corresponding stsc and stsz entries and check for the presence of a kw. - // * also mark the id for the second largest entry. - size_t max_id = 0, prev_id = 0, max = 0; - for(size_t i = 0; i < stco.size(); ++i){ - if(stco[i] > max) { - max = stco[i]; - prev_id = max_id; - max_id = i; - } - } - size_t offset_2_kw = stco[max_id] + (stsc[0] * stsz[max_id]); - if((offset_2_kw + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME) > total_bytes) return false; - int index = offset_2_kw + fix_mp4::LENGTH_SIZE; - bool is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((p + index), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - break; - } - } - if(!is_found) return false; - - bool is_footer = false; - // 2. if stco is the last entry then try to validate the last entry. - if(last_atom_idx == 9){ - // if max_id is the last entry, then choose the next largest entry add the stsz - // else subtract - size_t last_id = stco.size() - 1; - size_t check_offset = 0; - if(max_id == last_id){ - check_offset = stco[prev_id] + stsz[prev_id]; - if(check_offset == stco[max_id]){ - is_footer = true; - } - }else if(prev_id == last_id){ - check_offset = stco[max_id] - stsz[max_id]; - if(check_offset == stco[prev_id]){ - is_footer = true; - } - }else{ - for(size_t i = 0; i < last_id; ++i){ - check_offset = stco[i] + stsz[i]; - if(check_offset == stco[last_id]){ - is_footer = true; - break; - } - } - } - - } - return is_footer; - } - } - return false; -} - -SCANNER_STATUS carve_from_keyword(const unsigned char *p, size_t offset, size_t total_bytes, size_t &length, int &last_atom_idx, std::vector &stco, std::vector &stsz, std::vector &stsc, bool footer){ - size_t index = 0, size = 0, prev_index = 0; - bool is_found = false; - const unsigned char *s = p + offset; - - if(total_bytes == 0) - return SCANNER_STATUS_OK; - - // leaf atom check - if we have reached a leaf atom, we can terminate the recursive search for children atoms. - if((offset + index) < total_bytes - 0x8){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - if(is_found == false){ - return SCANNER_STATUS_LEAF; - } - }else { - return SCANNER_STATUS_LEAF; - } - size_t child_length = 0; - for(;(offset + index) < total_bytes - 0x8;){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - // No key word found - implies that either we have reached end of file or the file is truncated. - if(is_found == false){ - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else{ - if(index == total_bytes){ - length += index; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME; - } - return SCANNER_STATUS_OK; - } - } - - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - }else if (size == 0 ){ - // size = 0 indicates that this atom extends to the end of file. which we have no method of identifying for now. - // This is seen only with mdat atoms so far. With "mdat" as the last atom, validation is not possible. - // verify if stbl atoms occur with a zero size and support. - if(last_atom_idx == 0){ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - - return SCANNER_STATUS_FAILURE; - }else{ - - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(size + index + offset > total_bytes){ - return SCANNER_STATUS_FAILURE; - } - - if(last_atom_idx == 9){ - // stco - if(!parse_stco((s + index), 0, size, stco)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 10){ - //stsz - if(!parse_stsz((s + index), 0, size, stsz)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 11){ - //stsc - if(!parse_stsc((s + index), 0, size, stsc)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - - prev_index = index; - // recursively parse the tree upto the child atoms. we validate the entire structure. - if(SCANNER_STATUS_FAILURE != carve_from_keyword((s + index), (fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE), (size - fix_mp4::LENGTH_OF_ATOM_NAME - fix_mp4::LENGTH_SIZE), - child_length, last_atom_idx, stco, stsz, stsc, false)){ - index += size; - }else{ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + child_length + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - // Footer check is performed only at the first call of carve_from_keyword. Subsequently, we parse for the children atoms. - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - return SCANNER_STATUS_OK; -} - - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0, size = 0; - index = fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE; - - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME; - return false; - } - index = size; - length += index; - int last_atom_idx = -1; - std::vector stco, stsz, stsc; - if(carve_from_keyword(s, index, total_bytes, length, last_atom_idx, stco, stsz, stsc, true) == SCANNER_STATUS_OK){ - return true; - }else - return false; -} - - -extern "C" - void scan_3gp(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.version != 1){ - cerr << "scan_3gp requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "3gp"; - sp.info->feature_names.insert("3gp"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *recorder = fs.get_name("3gp"); - recorder->set_quoting_enabled(false); - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - bool print = false; - - size_t offset = 0; - size_t length = 0; - bool status; - fix_mp4 fixer; - extract_keyframes ek; - std::string file_name; - - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 0x10))); ++cc){ - - if( memcmp((cc + fix_mp4::LENGTH_SIZE), _3GP_MAIN_HEADER, fix_mp4::HEADER_SIZE) == 0){ - if((memcmp((cc + fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE), _3GP_SUB_HEADER, (_3GP_SUB_HEADER_SIZE)) == 0)){ - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - print = true; - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *recorder); - }else{ - // partial header found, try reconstruction instead. - //use the video processor to convert/store the video found - video_processor vp; - status = true; - if(!vp.process_header(sbuf, offset, *recorder)){ - // Video processor failed, Try to fix the video using fixmp4 - if(!fixer.do_fix(sbuf, offset, *recorder)){ - status = false; - }else{ - file_name = fixer.get_file_name(); - } - }else{ - file_name = vp.get_file_name(); - } - // Extract key frames based on output file - if(!file_name.empty() && status){ - ek.extract(file_name); - file_name.clear(); - } - } - } - } - - if(print){ - recorder->write(sp.sbuf.pos0+offset, " ", b2); - //recorder->carve(sbuf,offset, length); - print = false; - } - cc += length; - length = 0; - } - return; -} diff --git a/plugins/scan-video/scan_asf.cpp b/plugins/scan-video/scan_asf.cpp deleted file mode 100644 index 00374623..00000000 --- a/plugins/scan-video/scan_asf.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/** -* -* scan_asf, wmv: -*/ - -#include -#include -#include -#include "../src/bulk_extractor.h" - -#include "video_processor.h" -#include "extract_keyframes.h" - -// Header keywords - signatures found at the start of file -static const unsigned int ASF_HEADER_SIZE = 16; -static const unsigned int ASF_LENGTH_SIZE = 8; -static const unsigned char ASF_MAIN_HEADER[ASF_HEADER_SIZE + 1] = {0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}; -static const unsigned int ASF_KW_NO = 5; - -// keywords found through out the file. -static const unsigned char ASF_KW[ASF_KW_NO][ASF_HEADER_SIZE] = { - {0x36, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}, //ASF_Data_Object - {0x90, 0x08, 0x00, 0x33, 0xB1, 0xE5, 0xCF, 0x11, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}, //ASF_Simple_Index_Object - {0xD3, 0x29, 0xE2, 0xD6, 0xDA, 0x35, 0xD1, 0x11, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE}, //ASF_Index_Object - {0xF8, 0x03, 0xB1, 0xFE, 0xAD, 0x12, 0x64, 0x4C, 0x84, 0x0F, 0x2A, 0x1D, 0x2F, 0x7A, 0xD4, 0x8C}, //ASF_Media_Object_Index_Object -}; - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0, prev_index = 0; - unsigned long long size = 0, size_lsb = 0, size_usb = 0; - bool is_found = false; - index = ASF_HEADER_SIZE; - for(;index < (total_bytes - 24);){ - size_usb = (s[index + 7] << 24) | (s[index + 6] << 16) | (s[index + 5] << 8) | (s[index + 4]); - size_lsb = (s[index + 3] << 24) | (s[index + 2] << 16) | (s[index + 1] << 8) | (s[index + 0]); - size = static_cast((size_usb << 32) | size_lsb); - if(((index + size - ASF_HEADER_SIZE) > total_bytes) || (size <= 0 )) { - length = index + ASF_HEADER_SIZE; - return false; - } - prev_index = index; - index += size - ASF_HEADER_SIZE; - - is_found = false; - for(size_t i = 0; i < ASF_KW_NO; ++i){ - if( memcmp((s + index), ASF_KW[i], ASF_HEADER_SIZE) == 0){ - is_found = true; - break; - } - } - - if(!is_found){ - length = prev_index; - return false; - } - index += ASF_HEADER_SIZE; - } - length = prev_index; - return false; // we cannot validate an asf/wmv file currently. hence the "false" status return. -} - -extern "C" - void scan_asf(const class scanner_params &sp,const recursion_control_block &rcb) -{ - - if(sp.version != 1){ - cerr << "scan_asf requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "asf"; - sp.info->feature_names.insert("asf"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *recorder = fs.get_name("asf"); - recorder->set_quoting_enabled(false); - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - bool print = false; - - size_t offset = 0; - size_t length = 0; - bool status; - extract_keyframes ek; - std::string file_name; - - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 24))); ++cc){ //24 = ASF_HEADER_SIZE + ASF_LENGTH_SIZE - - if( memcmp(cc, ASF_MAIN_HEADER, ASF_HEADER_SIZE) == 0){ - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - print = true; - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *recorder); - }else{ - // partial header found, try reconstruction instead. - //use the video processor to convert/store the video found - video_processor vp; - if(vp.process_header(sbuf, offset, *recorder)){ - file_name = vp.get_file_name(); - // Extract key frames based on output file - if(!file_name.empty()){ - ek.extract(file_name); - file_name.clear(); - } - } - } - - } - if(print){ - recorder->write(sp.sbuf.pos0+offset, " ", b2); - //recorder->carve(sbuf,offset, length); - print = false; - } - cc += length; - length = 0; - } - return; -} - diff --git a/plugins/scan-video/scan_avi.cpp b/plugins/scan-video/scan_avi.cpp deleted file mode 100644 index b428050d..00000000 --- a/plugins/scan-video/scan_avi.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/** -* -* scan_avi: -*/ - -#include -#include -#include -#include "../src/bulk_extractor.h" - -#include "video_processor.h" -#include "extract_keyframes.h" - -// Header keywords - signatures found at the start of file -static const int RIFF_HEADER_SIZE = 4; -static const int RIFF_LENGTH_SIZE = 4; -static const char RIFF_MAIN_HEADER[RIFF_HEADER_SIZE + 1] = "RIFF"; -static const int RIFF_SUB_HEADER_NO = 2; -static const char RIFF_SUB_HEADER[RIFF_SUB_HEADER_NO][RIFF_HEADER_SIZE] = { - {'W','A','V','E' }, {'A','V','I',' '} -}; - -// keywords found through out the file. -static const int RIFF_CHUNK_NAME_SIZE = 4; -static const int RIFF_CHUNK_NAMES_NO = 8; -static const char RIFF_CHUNK_NAMES[RIFF_CHUNK_NAMES_NO][RIFF_CHUNK_NAME_SIZE] = { - {'L','I','S','T'},{'J','U','N','K' }, - {'i','d','x','1'},{'f','m','t',' '}, - {'d','a','t','a'},{'f','a','c','t'}, - {'F','I','L','T' },{'m','o','v','i' } -}; - -bool is_footer(const unsigned char *p, size_t offset, size_t offset_movi, size_t total_bytes){ - // parse and verify the last chunk. - size_t size = 0, kw1 = 0, kw2 = 0, index = 0; - unsigned long loc = 0; - const unsigned char *s = p + offset; - // parse an idx1 chunk. - RIFF_CHUNK_NAMES[2] = "idx1" - if( memcmp(s, RIFF_CHUNK_NAMES[2], RIFF_CHUNK_NAME_SIZE) == 0){ - if(offset + 12 > total_bytes) return false; - size = (s[7] << 24) | (s[6] << 16) | (s[5] << 8) | (s[4]); - if(size < 0 || ((size + offset + 8 ) > total_bytes)){ - return false; - } - index = size - 0x8; //size + 0x8 - 0x10; - if(offset + index + 4 > total_bytes) return false; - kw1 = (s[index + 3] << 24) | (s[index + 2] << 16) | (s[index + 1] << 8) | (s[index]); - index += 4; - if(offset + index + 4 > total_bytes) return false; - //l = (s[index + 3] << 24) | (s[index + 2] << 16) | (s[index + 1] << 8) | (s[index]); - index += 4; - if(offset + index + 4 > total_bytes) return false; - loc = (s[index + 3] << 24) | (s[index + 2] << 16) | (s[index + 1] << 8) | (s[index]); - if((loc + offset_movi + 4)> total_bytes) - return false; - index = loc + offset_movi + 0xC; - if(index + 4 > total_bytes) return false; - kw2 = (p[index + 3] << 24) | (p[index + 2] << 16) | (p[index + 1] << 8) | (p[index]); - if(kw2 == kw1) - return true; - } - return false; -} - -bool carve_from_keyword(const unsigned char *p, size_t offset, size_t total_bytes, size_t &length){ - size_t index = 0, size = 0, prev_index = 0; - bool is_found = false; - const unsigned char *s = p + offset; - size_t offset_movi = 0; - - for(;(offset + index) < total_bytes - 0x10;){ - is_found = false; - - for(int i = 0; i < RIFF_CHUNK_NAMES_NO; ++i){ - if( memcmp((s + index), RIFF_CHUNK_NAMES[i], RIFF_CHUNK_NAME_SIZE) == 0){ - is_found = true; - break; - } - } - // parse "LIST" to id "movi". calculate offset_movi - if( memcmp((s + index), RIFF_CHUNK_NAMES[0], RIFF_CHUNK_NAME_SIZE) == 0){ - // we have a list chunk - if( memcmp((s + index + 8), RIFF_CHUNK_NAMES[7], RIFF_CHUNK_NAME_SIZE) == 0){ - offset_movi = index + 8; - } - } - // No key word found - implies that either we have reached end of file or the file is truncated. - if(is_found == false){ - if(is_footer(p, (offset + prev_index), offset_movi, total_bytes)){ - length += index; - return true; - } - else{ - length += prev_index + RIFF_CHUNK_NAME_SIZE; - return false; - } - } - - size = (s[index + 7] << 24) | (s[index + 6] << 16) | (s[index + 5] << 8) | (s[index + 4]); - if(size < 0 ) { - length += index + RIFF_CHUNK_NAME_SIZE; - return false; - } - prev_index = index; - index += 8 + size; - } - - if((index + 4) < total_bytes){ - if(is_footer(p, (offset + prev_index), offset_movi, total_bytes)){ - length += index; - return true; - } - else{ - length += prev_index + RIFF_CHUNK_NAME_SIZE; - return false; - } - }else{ - length += prev_index + RIFF_CHUNK_NAME_SIZE; - return false; - } -} - - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0; - bool is_found = false; - index = RIFF_HEADER_SIZE + RIFF_LENGTH_SIZE; - - is_found = false; - for(int i = 0; i < RIFF_SUB_HEADER_NO; ++i){ - if( memcmp((s + index), RIFF_SUB_HEADER[i], RIFF_HEADER_SIZE) == 0){ - is_found = true; - break; - } - } - - if(is_found == false){ - return false; - - } - index += RIFF_HEADER_SIZE; - length += index; - return carve_from_keyword(s, index, total_bytes, length); - -} - -extern "C" - void scan_avi(const class scanner_params &sp,const recursion_control_block &rcb) -{ - - if(sp.version != 1){ - cerr << "scan_avi requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "avi"; - sp.info->feature_names.insert("avi"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *avi_recorder = fs.get_name("avi"); - avi_recorder->set_quoting_enabled(false); - - - size_t offset = 0; - size_t length = 0; - int status = 0; - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - bool print = false; - extract_keyframes ek; - std::string file_name; - - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 0x10))); ++cc){ - - if( memcmp(cc, RIFF_MAIN_HEADER, RIFF_HEADER_SIZE) == 0){ - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - print = true; - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *avi_recorder); - }else{ - // partial header found, try reconstruction instead. - //use the video processor to convert/store the video found - video_processor vp; - if(vp.process_header(sbuf, offset, *avi_recorder)){ - file_name = vp.get_file_name(); - // Extract key frames based on output file - if(!file_name.empty()){ - ek.extract(file_name); - file_name.clear(); - } - } - - } - - } - if(print){ - avi_recorder->write(sp.sbuf.pos0+offset, " ", b2); - //avi_recorder->carve(sbuf,offset, length); - print = false; - } - cc += length; - length = 0; - //avi_recorder->flush(); - } - - return; -} - diff --git a/plugins/scan-video/scan_bulk.cpp b/plugins/scan-video/scan_bulk.cpp deleted file mode 100644 index 1a8584b9..00000000 --- a/plugins/scan-video/scan_bulk.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * scan_bulk: - * plug-in demonstration that shows how to write a simple plug-in scanner. - * This scanner tabulates the percentage of blocks that are null. - * It also generates a feature report for every likely JPEG. - */ - -#include -#include - -#include "../src/bulk_extractor.h" - -static uint64_t count_null512=0; -static uint64_t count_jpeg=0; -static uint64_t count_total=0; - -const ssize_t blocksize = 512; - -static bool is_zero(const u_char *buf,size_t count) -{ - while(count>0){ - if(buf[0]) return false; - count--; - buf++; - } - return true; -} - - - -extern "C" -void scan_bulk(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.version!=1){ - cerr << "scan_bulk requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - /* Check for phase 0 --- startup */ - if(sp.phase==0){ - sp.info->name = "bulk"; - sp.info->flags = 0; - return; /* No feature files created */ - } - - /* Check for phase 2 --- shutdown */ - if(sp.phase==2){ - feature_recorder *alert = sp.fs.get_alert_recorder(); - alert->printf("total sectors: %" PRId64,count_total); - alert->printf("total jpegs: %" PRId64,count_jpeg); - alert->printf("total nulls: %" PRId64,count_null512); - return; - } - - for(const u_char *b0 = sp.sbuf.buf ; - b0 -#include - -#include "../src/bulk_extractor.h" - -static int cnt = 0; - -extern "C" -void scan_hello(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.version!=1){ - cerr << "scan_hello requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - /* Check for phase 0 --- startup */ - if(sp.phase==0){ - sp.info->name = "hello"; - sp.info->flags = 0; - return; /* No feature files created */ - } - - /* Check for phase 2 --- shutdown */ - if(sp.phase==2){ -// feature_recorder *alert = sp.fs->get_alert_recorder(); -// alert->printf("Hello World! - Phase 2"); - return; - } - - cnt++; - cerr << "scan_hello: Hello World! (" << cnt << ")" << endl; - - const sbuf_t &sbuf = sp.sbuf; - const pos0_t &pos0 = sp.sbuf.pos0; - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - - cerr << "Path: " << pos0.path << endl; - cerr << "Offset: " << pos0.offset << endl; - cerr << "Page size: " << l << endl; - -} diff --git a/plugins/scan-video/scan_mov.cpp b/plugins/scan-video/scan_mov.cpp deleted file mode 100644 index 22b9cd74..00000000 --- a/plugins/scan-video/scan_mov.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/** -* -* scan_mov: -*/ - -#include -#include -#include -#include "../src/bulk_extractor.h" -#include -#include -#include "fix_mp4.h" - -#include "video_processor.h" -#include "extract_keyframes.h" - -// Header keywords - signatures found at the start of file -static const char MOV_MAIN_HEADER[ fix_mp4::HEADER_SIZE] = {'f', 't', 'y', 'p'}; -static const int MOV_SUB_HEADER_NO = 5; -static const int MOV_SUB_HEADER_SIZE = 2; -static const char MOV_SUB_HEADER[ fix_mp4::HEADER_SIZE] = {'q', 't'}; - -// Scanner return status -typedef enum { - SCANNER_STATUS_FAILURE = -1, - SCANNER_STATUS_OK = 0, - SCANNER_STATUS_LEAF -}SCANNER_STATUS; - -// Parse last 2 entries of all the "stco" chunks. -bool parse_stco(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stco - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STCO[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 'c', 'o'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STCO, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - if((size < 0) || (size + offset > total_bytes) || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)) - return false; - - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) - return false; - size_t stco_tmp; - for(size_t i = 0; i < loop_sz; ++i){ - // the values of the stco entries will not be validated here. They should be checked at the time of usage. - // This is so, because we dont have the complete stbl info here. - stco_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stco_tmp); - index += fix_mp4::LENGTH_SIZE; - if(index + offset > total_bytes) - return false; - } - return true; -} - -bool parse_stsz(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stsz - - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSZ[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'z'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSZ, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 2); - size_t u_sz = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - - size_t num_entries = (s[16] << 24) | (s[17] << 16) | (s[18] << 8) | (s[19]); - - size_t loop_sz = 20; - if(0 == u_sz) { - if(loop_sz > num_entries) - loop_sz = num_entries; - } - - if((size < 0) || (size + offset > total_bytes) || (((loop_sz * fix_mp4::LENGTH_SIZE) > size) && (0 == u_sz))) - return false; - - index += fix_mp4::LENGTH_SIZE; - size_t stsz_tmp = 0; - if(0 == u_sz){ - // Mode - 2 - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) - return false; - - for(size_t i = 0; i < loop_sz; ++i){ - stsz_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stsz_tmp); - index += fix_mp4::LENGTH_SIZE; - if(index + offset > total_bytes) - return false; - } - }else{ - // Mode - 1 - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(u_sz); - } - } - return true; -} - - -bool parse_stsc(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - //Ref - isoiec 14496-12.pdf 8.7.4.2 Syntax We are not parsing the entire stsc chunk, - // here we are just going to parse the "samples_per_chunk" - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSC[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'c'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSC, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - - if((size < 0) || (size + offset > total_bytes)/* || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)*/) - return false; - - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - size_t stsc_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - //if(arr_sz == -1){ - index = (size - (fix_mp4::LENGTH_SIZE * 2)); - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(stsc_tmp); - } - return true; -} - -bool is_footer(const unsigned char *p, size_t offset, size_t total_bytes, int last_atom_idx, - std::vector &stco, std::vector &stsz, std::vector &stsc){ - // based on all the elements found, we will try to validate the end of file. - // the last atom is "mdat" we cannot validate this file. - if(last_atom_idx == 0) - return false; - - if((last_atom_idx == 9) || (last_atom_idx == 10) || (last_atom_idx == 11)){ // stco, stsz, stsc - if(stco.size() == stsz.size()){ - // 1. use the largest stco entry and its corresponding stsc and stsz entries and check for the presence of a kw. - // * also mark the id for the second largest entry. - size_t max_id = 0, prev_id = 0, max = 0; - for(size_t i = 0; i < stco.size(); ++i){ - if(stco[i] > max) { - max = stco[i]; - prev_id = max_id; - max_id = i; - } - } - size_t offset_2_kw = stco[max_id] + (stsc[0] * stsz[max_id]); - if((offset_2_kw + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME) > total_bytes) - return false; - int index = offset_2_kw + fix_mp4::LENGTH_SIZE; - bool is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((p + index), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - break; - } - } - if(!is_found) - return false; - - bool is_footer = false; - // 2. if stco is the last entry then try to validate the last entry. - if(last_atom_idx == 9){ - // if max_id is the last entry, then choose the next largest entry add the stsz - // else subtract - size_t last_id = stco.size() - 1; - size_t check_offset = 0; - if(max_id == last_id){ - check_offset = stco[prev_id] + stsz[prev_id]; - if(check_offset == stco[max_id]){ - is_footer = true; - } - }else if(prev_id == last_id){ - check_offset = stco[max_id] - stsz[max_id]; - if(check_offset == stco[prev_id]){ - is_footer = true; - } - }else{ - for(size_t i = 0; i < last_id; ++i){ - check_offset = stco[i] + stsz[i]; - if(check_offset == stco[last_id]){ - is_footer = true; - break; - } - } - } - - } - return is_footer; - }else{ - } - }else if(last_atom_idx == 116){ - size_t size = (p[offset] << 24) | (p[offset + 1] << 16) | (p[offset + 2] << 8) | (p[offset + 3]); - if((size < 0) || (offset + size > total_bytes)){ - return false; - } - if(p[offset + 12] == 0xff && p[offset + 13] == 0xd8 && - p[offset + size - 2] == 0xff && p[offset + size - 1] == 0xd9){ - return true; - } - } - return false; -} - -SCANNER_STATUS carve_from_keyword(const unsigned char *p, size_t offset, size_t total_bytes, size_t &length, int &last_atom_idx, std::vector &stco, std::vector &stsz, std::vector &stsc, bool footer){ - size_t index = 0, size = 0, prev_index = 0; - bool is_found = false; - const unsigned char *s = p + offset; - if(total_bytes == 0) - return SCANNER_STATUS_OK; - // leaf atom check - if we have reached a leaf atom, we can terminate the recursive search for children atoms. - if((offset + index) < total_bytes - 0x8){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - if(is_found == false){ - return SCANNER_STATUS_LEAF; - } - }else { - return SCANNER_STATUS_LEAF; - } - size_t child_length = 0; - for(;(offset + index) < total_bytes - 0x8;){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - }else if (size == 1 ){ - - }else if (size == 0 ){ - // size = 0 indicates that this atom extends to the end of file. which we have no method of identifying for now. - // This is seen only with mdat atoms so far. With "mdat" as the last atom, validation is not possible. - // verify if stbl atoms occur with a zero size and support. - if(last_atom_idx == 0){ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - - return SCANNER_STATUS_FAILURE; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(size + index + offset > total_bytes){ - return SCANNER_STATUS_FAILURE; - } - - if(is_found){ - if(last_atom_idx == 9){ - // stco - if(!parse_stco((s + index), 0, size, stco)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 10){ - //stsz - if(!parse_stsz((s + index), 0, size, stsz)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 11){ - //stsc - if(!parse_stsc((s + index), 0, size, stsc)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - } - prev_index = index; - // recursively parse the tree upto the child atoms. we validate the entire structure. - if(SCANNER_STATUS_FAILURE != carve_from_keyword((s + index), (fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE), (size - fix_mp4::LENGTH_OF_ATOM_NAME - fix_mp4::LENGTH_SIZE), - child_length, last_atom_idx, stco, stsz, stsc, false)){ - if(is_found) - index += size; - }else{ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + child_length + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - if(!is_found){ - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else{ - if(index == total_bytes){ - length += index; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME; - } - return SCANNER_STATUS_OK; - } - } - - } - // Footer check is performed only at the first call of carve_from_keyword. Subsequently, we parse for the children atoms. - if(footer){ - if(is_footer(p, (offset + prev_index), total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - return SCANNER_STATUS_OK; -} - - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0, size = 0; - index = fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME; - return false; - } - index = size; - length += index; - int last_atom_idx = -1; - std::vector stco, stsz, stsc; - if(carve_from_keyword(s, index, total_bytes, length, last_atom_idx, stco, stsz, stsc, true) == SCANNER_STATUS_OK){ - return true; - }else - return false; -} - - -extern "C" - void scan_mov(const class scanner_params &sp,const recursion_control_block &rcb) -{ - - if(sp.version != 1){ - cerr << "scan_mov requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "mov"; - sp.info->feature_names.insert("mov"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *recorder = fs.get_name("mov"); - recorder->set_quoting_enabled(false); - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - bool print = false; - - size_t offset = 0; - size_t length = 0; - bool status; - fix_mp4 fixer; - extract_keyframes ek; - std::string file_name; - - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 0x10))); ++cc){ - - if( memcmp((cc + fix_mp4::LENGTH_SIZE), MOV_MAIN_HEADER, fix_mp4::HEADER_SIZE) == 0){ - if((memcmp((cc + fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE), MOV_SUB_HEADER, (MOV_SUB_HEADER_SIZE)) == 0)){ - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - print = true; - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *recorder); - }else{ - //use the video processor to convert/store the video found - video_processor vp; - status = true; - if(!vp.process_header(sbuf, offset, *recorder)){ - // Video processor failed, Try to fix the video using fixmp4 - if(!fixer.do_fix(sbuf, offset, *recorder)){ - status = false; - }else{ - file_name = fixer.get_file_name(); - } - }else{ - file_name = vp.get_file_name(); - } - // Extract key frames based on output file - if(!file_name.empty() && status){ - ek.extract(file_name); - file_name.clear(); - } - } - - } - } - if(print){ - recorder->write(sp.sbuf.pos0+offset, " ", b2); - print = false; - } - cc += length; - length = 0; - } - - return; -} - diff --git a/plugins/scan-video/scan_mp4.cpp b/plugins/scan-video/scan_mp4.cpp deleted file mode 100644 index fd99d4fb..00000000 --- a/plugins/scan-video/scan_mp4.cpp +++ /dev/null @@ -1,409 +0,0 @@ -/** -* -* scan_mp4: -*/ - -#include -#include -#include -#include "../src/bulk_extractor.h" -#include "fix_mp4.h" - -#include "video_processor.h" -#include "extract_keyframes.h" - -// Header keywords - signatures found at the start of file -static const char MP4_MAIN_HEADER[fix_mp4::HEADER_SIZE + 1] = {'f', 't', 'y', 'p'}; -static const int MP4_SUB_HEADER_NO = 5; -static const char MP4_SUB_HEADER[MP4_SUB_HEADER_NO][fix_mp4::HEADER_SIZE] = { - {'i', 's', 'o', 'm'}, {'i', 's', 'o', '2'}, {'a', 'v', 'c', '1'}, {'m', 'p', '4', '1'}, {'m', 'p', '4', '2'}, -}; - -// Scanner return status -typedef enum { - SCANNER_STATUS_FAILURE = -1, - SCANNER_STATUS_OK = 0, - SCANNER_STATUS_LEAF -}SCANNER_STATUS; - -// Parse last 2 entries of all the "stco" chunks. -bool parse_stco(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stco - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STCO[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 'c', 'o'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STCO, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - if((size < 0) || (size + offset > total_bytes) || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)) - return false; - - - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - size_t stco_tmp; - for(size_t i = 0; i < loop_sz; ++i){ - // the values of the stco entries will not be validated here. They should be checked at the time of usage. - // This is so, because we dont have the complete stbl info here. - stco_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stco_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - - return true; -} - -bool parse_stsz(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - // Ref: http://wiki.multimedia.cx/index.php?title=QuickTime_container#stsz - - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSZ[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'z'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSZ, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[16] << 24) | (s[17] << 16) | (s[18] << 8) | (s[19]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - - if((size < 0) || (size + offset > total_bytes) || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)) - return false; - - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 2); - - - size_t u_sz = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - index += fix_mp4::LENGTH_SIZE; - size_t stsz_tmp = 0; - if(0 == u_sz){ - // Mode - 2 - index = (size - (fix_mp4::LENGTH_SIZE * loop_sz)); - if(index + offset > total_bytes) return false; - - for(size_t i = 0; i < loop_sz; ++i){ - stsz_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - arr.push_back(stsz_tmp); - index += fix_mp4::LENGTH_SIZE; if(index + offset > total_bytes) return false; - } - }else{ - // Mode - 1 - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(u_sz); - } - } - return true; -} - - -bool parse_stsc(const unsigned char *p, size_t offset, size_t total_bytes, std::vector &arr){ - //Ref - isoiec 14496-12.pdf 8.7.4.2 Syntax We are not parsing the entire stsc chunk, - // here we are just going to parse the "samples_per_chunk" - size_t index = 0, size = 0; - const unsigned char *s = p + offset; - const char ATOM_STSC[fix_mp4::LENGTH_OF_ATOM_NAME] = {'s', 't', 's', 'c'}; - - if( memcmp((s + fix_mp4::LENGTH_SIZE), ATOM_STSC, fix_mp4::LENGTH_OF_ATOM_NAME) != 0) - return false; - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - size_t num_entries = (s[12] << 24) | (s[13] << 16) | (s[14] << 8) | (s[15]); - size_t loop_sz = 20; - if(loop_sz > num_entries) loop_sz = num_entries; - - if((size < 0) || (size + offset > total_bytes)/* || ((loop_sz * fix_mp4::LENGTH_SIZE) > size)*/) - return false; - - index = fix_mp4::LENGTH_OF_ATOM_NAME + (fix_mp4::LENGTH_SIZE * 3); - size_t stsc_tmp = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - index = (size - (fix_mp4::LENGTH_SIZE * 2)); - for(size_t i = 0; i < loop_sz; ++i){ - arr.push_back(stsc_tmp); - } - return true; -} - -bool is_footer(const unsigned char *p, size_t offset, size_t total_bytes, int last_atom_idx, - std::vector &stco, std::vector &stsz, std::vector &stsc){ - // based on all the elements found, we will try to validate the end of file. - // the last atom is "mdat" we cannot validate this file. - if(last_atom_idx == 0) - return false; - - if((last_atom_idx == 9) || (last_atom_idx == 10) || (last_atom_idx == 11)){ // stco, stsz, stsc - if(stco.size() != stsz.size()) return false; - // 1. use the largest stco entry and its corresponding stsc and stsz entries and check for the presence of a kw. - // * also mark the id for the second largest entry. - size_t max_id = 0, prev_id = 0, max = 0; - for(size_t i = 0; i < stco.size(); ++i){ - if(stco[i] > max) { - max = stco[i]; - prev_id = max_id; - max_id = i; - } - } - size_t offset_2_kw = stco[max_id] + (stsc[0] * stsz[max_id]); - if((offset_2_kw + fix_mp4::LENGTH_SIZE + fix_mp4::LENGTH_OF_ATOM_NAME) > total_bytes) return false; - int index = offset_2_kw + fix_mp4::LENGTH_SIZE; - bool is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((p + index), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - break; - } - } - if(!is_found) return false; - - bool is_footer = false; - // 2. if stco is the last entry then try to validate the last entry. - if(last_atom_idx == 9){ - // if max_id is the last entry, then choose the next largest entry add the stsz - // else subtract - size_t last_id = stco.size() - 1; - size_t check_offset = 0; - if(max_id == last_id){ - check_offset = stco[prev_id] + stsz[prev_id]; - if(check_offset == stco[max_id]){ - is_footer = true; - } - }else if(prev_id == last_id){ - check_offset = stco[max_id] - stsz[max_id]; - if(check_offset == stco[prev_id]){ - is_footer = true; - } - }else{ - for(size_t i = 0; i < last_id; ++i){ - check_offset = stco[i] + stsz[i]; - if(check_offset == stco[last_id]){ - is_footer = true; - break; - } - } - } - - } - return is_footer; - } - return false; -} - -SCANNER_STATUS carve_from_keyword(const unsigned char *p, size_t offset, size_t total_bytes, size_t &length, int &last_atom_idx, std::vector &stco, std::vector &stsz, std::vector &stsc, bool footer){ - size_t index = 0, size = 0, prev_index = 0; - bool is_found = false; - const unsigned char *s = p + offset; - - if(total_bytes == 0) - return SCANNER_STATUS_OK; - // leaf atom check - if we have reached a leaf atom, we can terminate the recursive search for children atoms. - if((offset + index) < total_bytes - 0x8){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - if(is_found == false){ - return SCANNER_STATUS_LEAF; - } - }else { - return SCANNER_STATUS_LEAF; - } - size_t child_length = 0; - for(;(offset + index) < total_bytes - 0x8;){ - is_found = false; - for(int i = 0; i < fix_mp4::NO_OF_ATOMS; ++i){ - if( memcmp((s + index + fix_mp4::LENGTH_SIZE), fix_mp4::ATOM_NAMES[i], fix_mp4::LENGTH_OF_ATOM_NAME) == 0){ - is_found = true; - last_atom_idx = i; - break; - } - } - // No key word found - implies that either we have reached end of file or the file is truncated. - if(is_found == false){ - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else{ - if(index == total_bytes){ - length += index; - }else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME; - } - return SCANNER_STATUS_OK; - } - } - - size = (s[index] << 24) | (s[index + 1] << 16) | (s[index + 2] << 8) | (s[index + 3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - }else if(size + index + offset > total_bytes){ - return SCANNER_STATUS_FAILURE; - } - - if(last_atom_idx == 9){ - // stco - if(!parse_stco((s + index), 0, size, stco)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 10){ - //stsz - if(!parse_stsz((s + index), 0, size, stsz)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - }else if(last_atom_idx == 11){ - //stsc - if(!parse_stsc((s + index), 0, size, stsc)){ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - - prev_index = index; - // recursively parse the tree upto the child atoms. we validate the entire structure. - if(SCANNER_STATUS_FAILURE != carve_from_keyword((s + index), (fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE), (size - fix_mp4::LENGTH_OF_ATOM_NAME - fix_mp4::LENGTH_SIZE), - child_length, last_atom_idx, stco, stsz, stsc, false)){ - index += size; - }else{ - length += index + fix_mp4::LENGTH_OF_ATOM_NAME + child_length + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - - // Footer check is performed only at the first call of carve_from_keyword. Subsequently, we parse for the children atoms. - if(footer){ - if(is_footer(p, offset, total_bytes, last_atom_idx, stco, stsz, stsc)){ - length += index; - return SCANNER_STATUS_OK; - } - else{ - length += prev_index + fix_mp4::LENGTH_OF_ATOM_NAME + fix_mp4::LENGTH_SIZE; - return SCANNER_STATUS_FAILURE; - } - } - return SCANNER_STATUS_OK; -} - -bool carve_from_header(const unsigned char *s, size_t total_bytes, size_t &length){ - size_t index = 0, size = 0; - index = fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE; - - size = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | (s[3]); - if(size < 0 ) { - length += index + fix_mp4::LENGTH_OF_ATOM_NAME; - return false; - } - index = size; - length += index; - int last_atom_idx = -1; - std::vector stco, stsz, stsc; - if(carve_from_keyword(s, index, total_bytes, length, last_atom_idx, stco, stsz, stsc, true) == SCANNER_STATUS_OK){ - return true; - }else - return false; -} - - -extern "C" - void scan_mp4(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.version != 1){ - cerr << "scan_mp4 requires sp version 1; got version " << sp.version << "\n"; - exit(1); - } - - if(sp.phase == 0){ - sp.info->name = "mp4"; - sp.info->feature_names.insert("mp4"); - return; - } - - if(sp.phase == 2) return; - - const sbuf_t &sbuf = sp.sbuf; - - feature_recorder_set &fs = sp.fs; - feature_recorder *recorder = fs.get_name("mp4"); - recorder->set_quoting_enabled(false); - - const unsigned char* s = sbuf.buf; - size_t l = sbuf.pagesize; - char b2[1024]; - bool print = false; - - size_t offset = 0; - size_t length = 0; - bool is_found = false, status; - fix_mp4 fixer; - extract_keyframes ek; - std::string file_name; - - for(const unsigned char *cc = s; ((cc < (s + l)) && (cc < (s + l - 0x10))); ++cc){ - - if( memcmp((cc + fix_mp4::LENGTH_SIZE), MP4_MAIN_HEADER, fix_mp4::HEADER_SIZE) == 0){ - is_found = false; - for(int i = 0; i < MP4_SUB_HEADER_NO; ++i){ - if( memcmp((cc + fix_mp4::HEADER_SIZE + fix_mp4::LENGTH_SIZE), MP4_SUB_HEADER[i], fix_mp4::HEADER_SIZE) == 0){ - is_found = true; - break; - } - } - if(!is_found) - continue; // Not an MP4 file - offset = cc - s; - status = carve_from_header(cc, (l - offset), length); - // Status true implies that an intact file was recovered. - if(status) { - snprintf(b2,sizeof(b2), "\t%ld\t%ld\tC", offset, length); - print = true; - // Extract key frames based complete file in memory. This function also saves file to disk - ek.extract(sbuf, offset, *recorder); - }else{ - // partial header found, try reconstruction instead. - //use the video processor to convert/store the video found - video_processor vp; - status = true; - if(!vp.process_header(sbuf, offset, *recorder)){ - // Video processor failed, Try to fix the video using fixmp4 - if(!fixer.do_fix(sbuf, offset, *recorder)){ - status = false; - }else{ - file_name = fixer.get_file_name(); - } - }else{ - file_name = vp.get_file_name(); - } - // Extract key frames based on output file - if(!file_name.empty() && status){ - ek.extract(file_name); - file_name.clear(); - } - - } - - } - - if(print){ - recorder->write(sp.sbuf.pos0+offset, " ", b2); - print = false; - } - cc += length; - length = 0; - } - - return; -} - diff --git a/plugins/scan-video/scan_rar.cpp b/plugins/scan-video/scan_rar.cpp deleted file mode 100644 index 8ef26ceb..00000000 --- a/plugins/scan-video/scan_rar.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * scan_rar: - * Plug-in provides decoding of RAR files. - */ - -#include -#include - -#include "../src/bulk_extractor.h" - -extern "C" -void scan_rar(const class scanner_params &sp, - const recursion_control_block &rcb) -{ - if(sp.version!=1){ - cerr << "scan_rar requires sp version 1; got version " - << sp.version << "\n"; - exit(1); - } - - /* Check for phase 0 --- startup */ - if(sp.phase==0){ - sp.info->name = "rar"; - sp.info->flags = 0; - return; /* No feature files created */ - } - - /* Check for phase 2 --- shutdown */ - if(sp.phase==2){ - return; - } - - for(size_t i = 0 ; i -#include -#include -#include -#include -#include - -#include "bitstream_reader.h" -#include "bitstream_writer.h" - -std::random_device rd; //Will be used to obtain a seed for the random number engine -std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() -std::uniform_int_distribution<> char_distrib(0, 255); -std::uniform_int_distribution<> distrib_17(1, 7); - -char random_char() -{ - return (char)( distrib(gen)); -} - -int random_bit17() -{ - int v = distrib_17(gen); - assert (v>=1 && v<=7); - return v; -} - -int test1() -{ - - - printf("Starting test 1: single bit reads.\n"); - - bitstream_reader* reader = new bitstream_reader(); - - static const int N=100; - char data[N]; - for (int i=0; iset_data(data, N); - - char buf[N]; - for (int i=0; iread_bit(); - if (bit < 0) { - printf("Bit is -1 at byte %d bit %d\n", i,j); - return 1; - } - byte <<= 1; - byte |= (bit & 1); - } - - buf[i] = byte & (0xff); - } - - for (int i=0; iset_data(data, N); - - char buf[N]; - for (int i=0; iread_bits(num_bits); - if (bits < 0) { - printf("Bits -1 at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - - int remaining = reader->read_remaining_byte(); - if (remaining < 0) { - printf("Remaining byte -1 at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - - byte = bits; - byte <<= (8-num_bits); - byte |= remaining; - - buf[i] = byte & (0xff); - } - - for (int i=0; iset_data(data, N); - - char buf[N]; - for (int i=0; iread_byte(); - } - - for (int i=0; iset_data(data2, N); - - for (int i=0; iwrite_bit((byte >> (7-j)) & 1); - if (nb < 0) { - printf("Failed to write byte bit %d at byte %d\n", j,i); - return 1; - } - } - } - - for (int i=0; iset_data(data, N); - - char buf[N]; - writer->set_data(buf, N); - - for (int i=0; iread_bits(num_bits); - if (bits < 0) { - printf("Failed to read at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - - int nb = writer->write_bits(bits, num_bits); - if (nb <= 0) { - printf("Failed to write at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - - int remaining = reader->read_remaining_byte(); - if (remaining < 0) { - printf("Remaining byte -1 at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - - nb = writer->write_bits(remaining, 8-num_bits); - if (nb <= 0) { - printf("Failed to write reminaing bits at byte %d, num_bits = %d\n", i, num_bits); - return 1; - } - } - - for (int i=0; iset_data(buf, N); - - for (int i=0; iwrite_byte(data[i]); - } - - for (int i=0; i -#include - -#include "isomf.h" -#include "isomf_factory.h" -#include "type_io.h" - -using namespace std; -using namespace isomf; - -/* -void usage(char* me) { - cout << me << ": [input_file]" << endl; -} -*/ - -int main(int argc, char** argv) { - /* - if (argc < 2) { - usage(argv[0]); - return 0; - } - */ - sample_description_box* box = NULL; - - box = box_factory::get_avc_stsd(320, 240); - box_factory::print_stsd(box); - - box = box_factory::get_mp4a_stsd(); - box_factory::print_stsd(box); - - box = box_factory::get_mp4v_stsd(176, 144); - box_factory::print_stsd(box); - - box = box_factory::get_h263_stsd(176, 144); - box_factory::print_stsd(box); - - return 0; -} diff --git a/plugins/scan-video/test/test_keyframe.cpp b/plugins/scan-video/test/test_keyframe.cpp deleted file mode 100644 index b4daf64d..00000000 --- a/plugins/scan-video/test/test_keyframe.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "extract_keyframes.h" -#include "histogram_process.h" - -#include - -using namespace std; - -int main(int argc, char** argv){ - - - extract_keyframes *ek = new extract_keyframes(); - std::string file_name(argv[1]); - ek->extract(file_name); - delete ek; - return 0; -} - diff --git a/plugins/scan-video/test/test_parse_avcc.cpp b/plugins/scan-video/test/test_parse_avcc.cpp deleted file mode 100644 index 77d1a9dc..00000000 --- a/plugins/scan-video/test/test_parse_avcc.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include - -#include "isomf.h" - -using namespace std; -using namespace isomf; - -void usage(char* me) -{ - cerr << "Usage: " << me << " raw_avcc_box_dump" << endl; -} - -char* read_file(const char* filename, size_t* filesize) -{ - if (! filename) { return NULL; } - - FILE* fp = fopen(filename, "r"); - if (! fp) { - cerr << "Failed to open " << filename << endl; - return NULL; - } - - if (fseek(fp, 0, SEEK_END)) { - cerr << "Failed to seek " << filename << endl; - fclose(fp); - return NULL; - } - long sz = ftell(fp); - *filesize = (size_t)sz; - rewind(fp); - - char* buf = new char[sz]; - - size_t nb = fread(buf, 1, sz, fp); - fclose(fp); - - if (nb < (size_t) sz) { - cerr << "Failed to read " << filename << endl; - return NULL; - } - - cerr << "Read " << nb << " bytes from " << filename << endl; - - return buf; -} - -int main(int argc, char** argv) -{ - if (argc < 2) { - usage(argv[0]); - return 1; - } - char* filename = argv[1]; - size_t filesize = 0; - - char* buf = read_file(filename, &filesize); - if (! buf) { return 1; } - - avc_configuration_box avcc; - size_t nb = avcc.parse(buf, filesize); - cerr << "Parsed " << nb << " bytes from " << filename << endl; - - list& sps_list = avcc.get_sps_list(); - list& pps_list = avcc.get_pps_list(); - - list::iterator itr = sps_list.begin(); - while (itr != sps_list.end()) { - cout << (*itr)->str() << endl; - itr++; - } - - list::iterator pps_itr = pps_list.begin(); - while (pps_itr != pps_list.end()) { - cout << (*pps_itr)->str() << endl; - pps_itr++; - } - - return 0; -} - diff --git a/plugins/scan-video/test/test_pps.cpp b/plugins/scan-video/test/test_pps.cpp deleted file mode 100644 index 9d16149f..00000000 --- a/plugins/scan-video/test/test_pps.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -#include "isomf.h" -#include "isomf_factory.h" -#include "type_io.h" - -using namespace std; -using namespace isomf; - -/* -void usage(char* me) { - cout << me << ": [input_file]" << endl; -} -*/ - -int main(int argc, char** argv) { - picture_parameter_set* pps = parameter_set_factory::get_avc_pps(); - cout << pps->str() << endl; - cout << "PPS size: " << pps->size() << endl; - - size_t sz = 1024; - char buf[sz]; - memset(buf, 0, sz); - - size_t nb = pps->write(buf, sz); - cout << "Written " << nb << " bytes into buffer."; - - type_io::print_hex(buf, nb); - - return 0; -} diff --git a/plugins/scan-video/test/test_sps.cpp b/plugins/scan-video/test/test_sps.cpp deleted file mode 100644 index 31a6ac19..00000000 --- a/plugins/scan-video/test/test_sps.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -#include "isomf.h" -#include "isomf_factory.h" -#include "type_io.h" - -using namespace std; -using namespace isomf; - -/* -void usage(char* me) { - cout << me << ": [input_file]" << endl; -} -*/ - -int main(int argc, char** argv) { - sequence_parameter_set* sps = parameter_set_factory::get_avc_sps(); - cout << sps->str() << endl; - cout << "SPS size: " << sps->size() << endl; - - size_t sz = 1024; - char buf[sz]; - memset(buf, 0, sz); - - size_t nb = sps->write(buf, sz); - cout << "Written " << nb << " bytes into buffer." << endl; - - type_io::print_hex(buf, nb); - - return 0; -} diff --git a/plugins/scan-video/test/test_type_io.cpp b/plugins/scan-video/test/test_type_io.cpp deleted file mode 100644 index 5fffba6b..00000000 --- a/plugins/scan-video/test/test_type_io.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#include "type_io.h" -using namespace std; - -int main(int argc, char** argv) { - - char buf[8]; - int n = (1 << 24) + (2 << 16) + (3 << 8) + 4; - - type_io::write_uint32(n, buf); - type_io::print_hex(buf, 4); - - for (int i=1; i<=8; i++) { - memset(buf, 0, 8); - type_io::write_unsigned(n, buf, i); - type_io::print_hex(buf, 8); - } - - return 0; -} diff --git a/plugins/scan-video/test/test_video_convert.cpp b/plugins/scan-video/test/test_video_convert.cpp deleted file mode 100644 index d677379a..00000000 --- a/plugins/scan-video/test/test_video_convert.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include -#include -#include "video_processor.h" - -using namespace cv; -using namespace std; - -void usage(char* me) { - cout << me << ": [input_file] [output_file]" << endl; -} - -int main(int argc, char** argv) { - if (argc < 3) { - usage(argv[0]); - return 0; - } - - video_processor p; - video_info info; - p.convert(argv[1], argv[2], info, video_processor::CODEC_MP4); - - return 0; -} diff --git a/plugins/scan-video/test/test_video_info.cpp b/plugins/scan-video/test/test_video_info.cpp deleted file mode 100644 index b935854a..00000000 --- a/plugins/scan-video/test/test_video_info.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include -#include -#include "video_processor.h" - -using namespace cv; -using namespace std; - -void usage(char* me) { - cout << me << ": [video_file] ..." << endl; -} - -int main(int argc, char** argv) { - if (argc < 2) { - usage(argv[0]); - return 0; - } - - video_info info; - video_processor p; - for (int i=1; i -#include -#include "video_processor.h" - -using namespace cv; -using namespace std; - - -int main(int argc, char** argv) { - VideoCapture cap(0); // open the default camera - if(!cap.isOpened()) // check if we succeeded - return -1; - - Mat frame; - cap >> frame; - - Size size = frame.size(); - - //int codec = CV_FOURCC('M','J','P','G'); - //int codec = CV_FOURCC('I', 'Y', 'U', 'V'); - int codec = CV_FOURCC('m','p','4','v'); - //int codec = CV_FOURCC('X','V','I','D'); - //int codec = CV_FOURCC('X','2','6','4'); - double fps = 10; - - VideoWriter writer; - writer.open("recording.avi", codec, fps, size, true); - if (! writer.isOpened()) { - cerr << "Failed to open video stream \n"; - return -1; - } - - Mat edges; - namedWindow("edges",1); - for(;;) - { - Mat frame; - cap >> frame; // get a new frame from camera - /* - cvtColor(frame, edges, CV_BGR2GRAY); - GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5); - Canny(edges, edges, 0, 30, 3); - imshow("edges", edges); - */ - - cvtColor(frame, edges, CV_BGR2YUV); - writer << frame; - imshow("edges", frame); - if(waitKey(30) >= 0) break; - } - // the camera will be deinitialized automatically in VideoCapture destructor - return 0; - -} - diff --git a/plugins/scan-video/type_io.h b/plugins/scan-video/type_io.h deleted file mode 100644 index 333376d3..00000000 --- a/plugins/scan-video/type_io.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef _TYPE_IO_H_ -#define _TYPE_IO_H_ - -#include -#include - -class type_io -{ - public: - inline static size_t write_string(const std::string& s, size_t n, char* buf) - { - if (! buf || n <= 1) { return 0; }; - write_uint8(static_cast(s.length()), buf); - size_t nb = 1 + s.copy(buf+1, n, 0); - if (nb < n) { - memset(buf+nb, 0, (n-nb)); - } - return n; - } - - inline static size_t write_fourcc(const std::string& s, char* buf) - { - if (! buf) { return 0; } - size_t nb = s.copy(buf, 4, 0); - if (nb < 4) { - memset(buf + nb, 0, (4-nb)); - } - return 4; - } - - inline static std::string* read_fourcc(char* buf) - { - if (! buf) { return NULL; } - char fourcc[5] = {0}; - memcpy(fourcc, buf, 4); - return new std::string(fourcc); - } - - inline static size_t write_bytes(const char* data, size_t size, char* buf) - { - if (! data || size == 0 || ! buf) { - return 0; - } - memcpy(buf, data, size); - return size; - } - - inline static unsigned long read_unsigned(char* buf, int size = 1) - { - if (! buf) { return 0; } - - unsigned long result = 0; - for (int i=0; i((v >> shift) & 0xff); - } - return size; - } - - inline static unsigned read_uint8(char* buf) - { - return (unsigned) read_unsigned(buf, 1); - }; - - inline static unsigned read_uint16(char* buf) - { - return (unsigned) read_unsigned(buf, 2); - } - - inline static unsigned read_uint24(char* buf) - { - return (unsigned) read_unsigned(buf, 3); - } - - inline static unsigned read_uint32(char* buf) - { - return (unsigned) read_unsigned(buf, 4); - } - - inline static unsigned long read_uint64(char* buf) - { - return read_unsigned(buf, 8); - } - - inline static size_t write_uint8(unsigned v, char* buf) - { - return write_unsigned(v, buf, 1); - } - - inline static size_t write_uint16(unsigned v, char* buf) - { - return write_unsigned(v, buf, 2); - } - - inline static size_t write_uint24(unsigned v, char* buf) - { - return write_unsigned(v, buf, 3); - } - - inline static size_t write_uint32(unsigned v, char* buf) - { - return write_unsigned(v, buf, 4); - } - - inline static size_t write_uint64(unsigned long v, char* buf) - { - return write_unsigned(v, buf, 8); - } - - static void print_hex(char* buf, int len) { - int cnt = 0; - while (cnt < len) { - int rem = len - cnt; - int n = rem > 16 ? 16 : rem; - - for (int i=0; i -#include -#include -#include - -#include -#include -#include - -#ifndef WIN32 -#include -#include -#endif - -#include "video_processor.h" - -#ifndef WIN32 -void sig_action(int signal, siginfo_t *si, void *arg) -{ - //std::cerr << "Caught segfault at address " << si->si_addr << std::endl; - exit(2); -} - -void install_signal_actions() { - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - sigemptyset(&sa.sa_mask); - sa.sa_sigaction = sig_action; - sa.sa_flags = SA_SIGINFO; - - sigaction(SIGSEGV, &sa, NULL); - sigaction(SIGABRT, &sa, NULL); - sigaction(SIGFPE, &sa, NULL); - sigaction(SIGILL, &sa, NULL); - sigaction(SIGQUIT, &sa, NULL); - sigaction(SIGTRAP, &sa, NULL); - sigaction(SIGBUS, &sa, NULL); - sigaction(SIGXCPU, &sa, NULL); - sigaction(SIGXFSZ, &sa, NULL); -} -#endif - -video_info::video_info():width(0),height(0),fps(1),codec(-1),frame_count(0) -{ -} - -video_info::~video_info() -{ -} - -void video_info::init() -{ - width = 0; - height = 0; - fps = 1; - codec = -1; - frame_count = 0; -} - -char* video_info::codec_str() -{ - char* buf = new char[5]; - buf[0] = codec & 0XFF; - buf[1] = (codec & 0XFF00) >> 8; - buf[2] = (codec & 0XFF0000) >> 16; - buf[3] = (codec & 0XFF000000) >> 24; - buf[4] = 0; - return buf; -} - -std::string video_info::str() -{ - std::stringstream s; - s << "width=" << width << ",height=" << height - << ",fps=" << fps << ",codec=" << codec_str() - << ",frame_count=" << frame_count; - return s.str(); -} - -void video_info::copy(video_info& dst) -{ - dst.width = width; - dst.height = height; - dst.fps = fps; - dst.codec = codec; - dst.frame_count = frame_count; -} - -const int video_processor::CODEC_MJPG = CV_FOURCC('M','J','P','G'); -const int video_processor::CODEC_YUV = CV_FOURCC('I','Y','U','V'); -const int video_processor::CODEC_MP4 = CV_FOURCC('m','p','4','v'); -const int video_processor::CODEC_XVID = CV_FOURCC('X','V','I','D'); -const int video_processor::CODEC_H264 = CV_FOURCC('H','2','6','4'); -const int video_processor::DEFAULT_CODEC = video_processor::CODEC_MP4; - -video_processor::video_processor() { -} - -bool video_processor::get_info(const std::string& infile, video_info& info) -{ -#ifndef WIN32 - key_t key = IPC_PRIVATE; - int shmid = shmget(key, sizeof(video_info), IPC_CREAT | 0666); - if (shmid == -1) { - std::cerr << " !! Failed to create shared memory.\n"; - return false; - } - - video_info* var = (video_info*) shmat(shmid, NULL, 0); - if (! var) { - std::cerr << " !! Failed to map shared memory.\n"; - return false; - } - var->init(); - - pid_t pid = fork(); - if (pid == 0) { - install_signal_actions(); - - try { - cv::VideoCapture cap(infile); - if (! cap.isOpened()) { - throw new std::exception(); - } - info.codec = (int) cap.get(CV_CAP_PROP_FOURCC); - info.width = (int) cap.get(CV_CAP_PROP_FRAME_WIDTH); - info.height = (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT); - info.fps = (int) cap.get(CV_CAP_PROP_FPS); - info.frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT); - info.copy(*var); - } catch (std::exception& e) { - std::cerr << "Failed to get video info: " << e.what() << std::endl; - shmdt(var); - exit(1); - } - shmdt(var); - exit(0); - } else { - // std::cerr << "VideoProcessor >> Waiting for pid " << pid << std::endl; - int stat; - pid_t child_pid = waitpid(pid, &stat, 0); - if (child_pid == -1) { - std::cerr << " VideoProcessor >> Child process " << pid << " failed." << std::endl; - return false; - } else if (stat != 0) { - std::cerr << " VideoProcessor >> Child process " << pid << " finished with error " - << (stat & 0xff00 >> 8) - << "," << (stat & 0xff) << std::endl; - return false; - } else { - // std::cerr << " VideoProcessor >> Child process " << pid << " succeeded." << std::endl; - } - } - return true; - -#else - try { - cv::VideoCapture cap(infile); - if (! cap.isOpened()) { - throw new std::exception(); - } - info.codec = (int) cap.get(CV_CAP_PROP_FOURCC); - info.width = (int) cap.get(CV_CAP_PROP_FRAME_WIDTH); - info.height = (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT); - info.fps = (int) cap.get(CV_CAP_PROP_FPS); - info.frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT); - } catch (std::exception& e) { - std::cerr << "Failed to get video info: " << e.what() << std::endl; - return false; - } - return true; -#endif -} - -bool video_processor::convert(const char* data, size_t length, - const std::string& outfile, video_info& info, int codec) -{ - if (! data || length == 0) { - std::cerr << "Invalid argument to video_processor::convert" << std::endl; - return false; - } - - char* t = tmpnam(NULL); - if (! t) { - std::cerr << "Unable to get a temp file name!" << std::endl; - return false; - } - //std::cerr << " >> Writing buffer to temp file: " << t << std::endl; - std::fstream fs(t, std::ios_base::out | std::ios_base::binary); - fs.write(data, length); - - bool ok = ! fs.bad(); - if (! ok) { - std::cerr << " >> ERROR writing buffer to temp file: " << t << std::endl; - } - fs.close(); - - std::string tmpfilename(t); - - //std::cerr << " >> start to convert " << tmpfilename << std::endl; - ok &= convert(tmpfilename, outfile, info, codec); - //std::cerr << " >> convertsion ended. remove " << tmpfilename << std::endl; - - if (0 != remove(tmpfilename.c_str())) { - std::cerr << "Unable to remove tmp file " << tmpfilename << std::endl; - } - //std::cerr << " >> removed tmp file: " << tmpfilename << std::endl; - - return ok; -} - -bool video_processor::convert(const std::string& infile, - const std::string& outfile, video_info& info, int codec) -{ -#ifndef WIN32 - key_t key = IPC_PRIVATE; - int shmid = shmget(key, sizeof(video_info), IPC_CREAT | 0666); - if (shmid == -1) { - std::cerr << " !! Failed to create shared memory.\n"; - return false; - } - - video_info* var = (video_info*) shmat(shmid, NULL, 0); - if (! var) { - std::cerr << " !! Failed to map shared memory.\n"; - return false; - } - var->init(); - - pid_t pid = fork(); - if (pid == 0) { - //std::cerr << " ** Start worker process "<"<isOpened()) { - throw new std::exception(); - } - - cv::Mat frame; - while (cap.read(frame)) { - (*writer) << frame; - } - //std::cerr << " ** Done writing to " << outfile << std::endl; - - delete writer; - - } catch (std::exception& e) { - std::cerr << " ** Conversion failed: " << e.what() << std::endl; - shmdt(var); - exit(1); - } - - shmdt(var); - exit(0); - - } else { - //std::cerr << " VideoProcessor >> Waiting for pid " << pid << std::endl; - int stat; - pid_t child_pid = waitpid(pid, &stat, 0); - if (child_pid == -1) { - std::cerr << " VideoProcessor >> Child process " << pid << " failed." << std::endl; - } else if (stat != 0) { - std::cerr << " VideoProcessor >> Child process " << pid << " finished with error " - << (stat & 0xff00 >> 8) - << "," << (stat & 0xff) << std::endl; - } else { - // std::cerr << " VideoProcessor >> Child process " << pid << " succeeded." << std::endl; - //std::cerr << " ** Has var parent: " << var->str() << "\n"; - var->copy(info); - } - shmdt(var); - } - - //std::cerr << " >> Conversion done. Now test if it was successful.\n"; - - std::fstream fs; - fs.open(outfile.c_str(), std::ios_base::in | std::ios_base::binary); - if (! fs.is_open()) { - //std::cerr << "output file " << outfile << " couldn't be opened.\n"; - return false; - } - return true; - -#else - - try { - //std::cerr << " ** before opening input file\n"; - cv::VideoCapture cap(infile); - if (! cap.isOpened()) { - throw new std::exception(); - } - //std::cerr << " ** input file opened\n"; - - info.codec = (int) cap.get(CV_CAP_PROP_FOURCC); - info.width = (int) cap.get(CV_CAP_PROP_FRAME_WIDTH); - info.height = (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT); - info.fps = (int) cap.get(CV_CAP_PROP_FPS); - info.frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT); - - if (info.width == 0 || info.height == 0 || info.fps == 1) { - // unable to get video info from file. - // the file could not be processed by opencv. - throw new std::exception(); - } - - if (codec == -1) { - codec = info.codec; - } - //std::cerr << " ** Has video info: width=" << info.str() << std::endl; - - cv::Size size; - size.width = info.width; - size.height = info.height; - - //std::cerr << " ** writing to " << outfile << std::endl; - - cv::VideoWriter* writer = - new cv::VideoWriter(outfile, codec, info.fps, size, true); - if (! writer || ! writer->isOpened()) { - throw new std::exception(); - } - - cv::Mat frame; - while (cap.read(frame)) { - (*writer) << frame; - } - //std::cerr << " ** Done writing to " << outfile << std::endl; - - delete writer; - - } catch (std::exception& e) { - std::cerr << " ** Conversion failed: " << e.what() << std::endl; - return false; - } - - return true; - -#endif -} - -bool video_processor::process_header(const sbuf_t& sbuf, size_t offset, - feature_recorder& recorder) -{ - /*std::cerr << " >> Processing header at " << sbuf.pos0 - << ", offset=" << offset << "\n";*/ - - char* data = (char*) (sbuf.buf + offset); - size_t l = sbuf.pagesize; - size_t len = l-offset; - const pos0_t &pos0 = sbuf.pos0; - std::string fpath = pos0.path; - - // construct output file name - std::stringstream s; - s << recorder.name << "-p" << fpath << "-" << pos0.offset - << "-" << offset << "-" << rand() << ".avi"; - std::string outfile = recorder.outdir + "/" + s.str(); - set_file_name(outfile); - video_info info; - bool ok = convert(data, len, outfile, info); - if (ok) { - //std::cerr << " ** Has outer video info: " << info.str() << std::endl; - recorder.write(pos0+offset, info.str(), s.str()); - //recorder.write(pos0+offset, " ", s.str()); - } else { - // recorder.write(pos0+offset, "FAILED", ""); - } - - //std::cerr << " >> Done processing header at " << sbuf.pos0 - // << ", offset=" << offset << "\n"; - - return ok; -} - diff --git a/plugins/scan-video/video_processor.h b/plugins/scan-video/video_processor.h deleted file mode 100644 index 6ee6ed91..00000000 --- a/plugins/scan-video/video_processor.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _VIDEO_PROCESSOR_H_ -#define _VIDEO_PROCESSOR_H_ - -#include - -#include "../src/bulk_extractor.h" - -#ifndef WIN32 -void sig_action(int signal, siginfo_t *si, void *arg); -void install_signal_actions(); -#endif - -class video_info { - public: - int width; - int height; - int fps; - int codec; - double frame_count; - - video_info(); - ~video_info(); - - void init(); - void copy(video_info& dst); - char* codec_str(); - std::string str(); -}; - -class video_processor { - public: - static const int DEFAULT_CODEC; - static const int CODEC_MJPG; - static const int CODEC_YUV; - static const int CODEC_MP4; - static const int CODEC_H264; - static const int CODEC_XVID; - - static inline int read_int(const unsigned char* s) { - if (! s) { return 0; } - return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; - }; - - video_processor(); - - bool process_header(const sbuf_t& sbuf, size_t offset, - feature_recorder& recorder); - - bool get_info(const std::string& infile, video_info& info); - - bool convert(const std::string& infile, const std::string& outfile, - video_info& info, int codec = DEFAULT_CODEC); - - bool convert(const char* data, size_t length, const std::string& outfile, - video_info& info, int codec = DEFAULT_CODEC); - void set_file_name(const std::string &o) { _outfile.assign(o);} - const std::string& get_file_name() {return _outfile;} - - protected: - std::string _outfile; - -}; - -#endif diff --git a/plugins/scan_demo.cpp b/plugins/scan_demo.cpp deleted file mode 100644 index b56e84e5..00000000 --- a/plugins/scan_demo.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * scan_demo: - * - * demonstration that shows how to write a simple plug-in scanner. - * - * This scanner tabulates the percentage of blocks that are null and possible JPEGs. - * It also generates a feature report for every likely JPEG. - */ - -#include "../config.h" -#include "be13_api/bulk_extractor_i.h" - -#include -#include - -static uint64_t count_null512=0; -static uint64_t count_jpeg=0; -static uint64_t count_total=0; - -const ssize_t blocksize = 512; - -static bool is_zero(const u_char *buf,size_t count) -{ - while(count>0){ - if(buf[0]) return false; - count--; - buf++; - } - return true; -} - - - -extern "C" -void scan_demo(const class scanner_params &sp,const recursion_control_block &rcb) -{ - if(sp.sp_version!=scanner_params::CURRENT_SP_VERSION){ - std::cerr << "scan_demo requires sp version " << scanner_params::CURRENT_SP_VERSION << "; " - << "got version " << sp.sp_version << "\n"; - exit(1); - } - - /* Check for phase 0 --- startup */ - if(sp.phase==scanner_params::PHASE_STARTUP){ - sp.info->name = "demo"; - sp.info->author = "Simson L. Garfinkel"; - sp.info->flags = 0; - return; /* No feature files created */ - } - - /* Check for phase 2 --- shutdown */ - if(sp.phase==scanner_params::PHASE_SHUTDOWN){ - feature_recorder *alert = sp.fs.get_alert_recorder(); - alert->printf("total sectors: %" PRId64,count_total); - alert->printf("total jpegs: %" PRId64,count_jpeg); - alert->printf("total nulls: %" PRId64,count_null512); - return; - } - - if(sp.phase==scanner_params::PHASE_SCAN){ - for(const u_char *b0 = sp.sbuf.buf ; - b0 -#include -#include - -#define FEATURE_NAME "demo" - -class flex_scanner : public sbuf_scanner { -private: - flex_scanner(const flex_scanner &that):sbuf_scanner(that.sbuf),demo_recorder(){} - flex_scanner &operator=(const flex_scanner &that){return *this;} -public: - flex_scanner(const scanner_params &sp): - sbuf_scanner(&sp.sbuf),demo_recorder(){ - demo_recorder = sp.fs.get_name(FEATURE_NAME); - } - virtual ~flex_scanner(){} - class feature_recorder *demo_recorder; -}; -#define YY_EXTRA_TYPE flex_scanner * /* holds our class pointer */ - -inline class flex_scanner *get_extra(yyscan_t yyscanner) { - /* placing decl here avoids redundent declaration warning */ - YY_EXTRA_TYPE yyflexdemo_get_extra (yyscan_t yyscanner ); - return yyflexdemo_get_extra(yyscanner); -} - -%} - -%option reentrant -%option noyywrap -%option 8bit -%option batch -%option case-insensitive -%option pointer -%option noyymore -%option prefix="yyflexdemo_" - -%% - -"[ ]"+demo[0-9]*/"[ ]" { - /** Look for the word demo preceeded and followed by a space. - ** Note that we are looking for one letter more than we care capturing, so - ** we need to add a character to s.pos and remove one from yyleng - ** - ** NEVER modify yyleng, or else pos will not reflect the current position in the buffer. - */ - flex_scanner &s = * yyflexdemo_get_extra(yyscanner); - s.demo_recorder->write_buf(SBUF,s.pos+1,yyleng-1); - s.pos += yyleng; - -} - -.|\n { - /** - * The no-match rule. VERY IMPORTANT! - */ - flex_scanner &s = *yyflexdemo_get_extra(yyscanner); - s.pos++; -} -%% - -extern "C" -void scan_flexdemo(const class scanner_params &sp,const recursion_control_block &rcb) -{ - assert(sp.sp_version==scanner_params::CURRENT_SP_VERSION); - if(sp.phase==scanner_params::PHASE_STARTUP){ - assert(sp.info->si_version==scanner_info::CURRENT_SI_VERSION); - sp.info->name = "flexdemo"; - sp.info->author = "Simson L. Garfinkel"; - sp.info->description = "Scans for the word 'demo' optionally followed by a number with gnuflex"; - sp.info->scanner_version= "1.0"; - - /* define the feature files this scanner created */ - sp.info->feature_names.insert(FEATURE_NAME); - - /* define the histograms to make */ - sp.info->histogram_defs.insert(histogram_def(FEATURE_NAME,"","histogram")); - return; - } - if(sp.phase==scanner_params::PHASE_SHUTDOWN){ - return; - } - if(sp.phase==scanner_params::PHASE_SCAN){ - /* Set up the buffer. Scan it. Exit */ - flex_scanner lexer(sp); - yyscan_t scanner; - yyflexdemo_lex_init(&scanner); - yyflexdemo_set_extra(&lexer,scanner); - yyflexdemo_lex(scanner); - yyflexdemo_lex_destroy(scanner); - (void)yyunput; // avoids defined but not used - } -} -