Skip to content

Commit

Permalink
Issue #24: Added avbin_get_info() function.
Browse files Browse the repository at this point in the history
Added the avbin_get_info() function and removed the avbin_get_libav_(commit|version)() functions that I tried out in AVbin 9, which I never really released.

avbin_get_info() returns an AVbinInfo struct with the following members (all strings except where indicated):
- version                // integer, same as avbin_get_version()
- version_string         // includes potential prerelease info, for example "10-beta1"
- build_date             // %Y-%m-%d %H:%M:%S %z
- repo                   // Git URL
- commit                 // Git commit hash
- backend                // "libav" or "ffmpeg"
- backend_version_string // Most recent backend version tag, i.e. "v0.8.3"
- backend_repo           // Backend git URL
- backend_commit         // Backend git commit hash

Also in this commit:
- Updated examples/avbin_dump.c to dump all info from avbin_get_info()
- Fixed the "--fast" option in build.sh so it actually works
- Started using "backend" to refer to libav or ffmpeg stuff, to avoid future renames.
  • Loading branch information
CleanCut committed Aug 7, 2012
1 parent f59bdf1 commit e145511
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 77 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
# <http://www.gnu.org/licenses/>.

CFLAGS += -DAVBIN_VERSION=$(AVBIN_VERSION) \
-DLIBAV_COMMIT='$(LIBAV_COMMIT)' \
-DLIBAV_VERSION='$(LIBAV_VERSION)'
-DAVBIN_VERSION_STRING='$(AVBIN_VERSION_STRING)' \
-DAVBIN_BUILD_DATE='$(AVBIN_BUILD_DATE)' \
-DAVBIN_REPO='$(AVBIN_REPO)' \
-DAVBIN_COMMIT='$(AVBIN_COMMIT)' \
-DAVBIN_BACKEND='$(AVBIN_BACKEND)' \
-DAVBIN_BACKEND_VERSION_STRING='$(AVBIN_BACKEND_VERSION_STRING)' \
-DAVBIN_BACKEND_REPO='$(AVBIN_BACKEND_REPO)' \
-DAVBIN_BACKEND_COMMIT='$(AVBIN_BACKEND_COMMIT)'

CC = gcc
LD = ld
Expand All @@ -29,7 +35,7 @@ OUTDIR = dist/$(PLATFORM)
OBJNAME = $(BUILDDIR)/avbin.o

INCLUDE_DIRS = -I include \
-I $(LIBAV)
-I $(BACKEND_DIR)

include $(PLATFORM).Makefile

Expand Down
74 changes: 48 additions & 26 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,41 @@
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.

AVBIN_VERSION=`cat VERSION`
# Either "libav" or "ffmpeg"
BACKEND=libav

# Directory holding libav source code.
LIBAV=libav
# Directory holding backend source code.
BACKEND_DIR=$BACKEND

# Make sure the git submodule is initiated and updated (if blank)
if ! ls $LIBAV/Makefile >/dev/null 2> /dev/null ; then
if ! ls $BACKEND_DIR/Makefile >/dev/null 2> /dev/null ; then
git submodule init --quiet
git submodule update
fi

# Get the commit hash and latest version number for libav
pushd $LIBAV > /dev/null
LIBAV_COMMIT="\"`git rev-parse HEAD`\""
LIBAV_VERSION="\"`git describe --abbrev=0 --tags`\""

AVBIN_VERSION=`cat VERSION`
AVBIN_PRERELEASE=`cat PRERELEASE 2>/dev/null`
AVBIN_VERSION_STRING="\"$AVBIN_VERSION$AVBIN_PRERELEASE\""
AVBIN_BUILD_DATE="\"`date +\"%Y-%m-%d %H:%M:%S %z\"`\""
AVBIN_REPO="\"`git remote show -n origin | grep Fetch | cut -b 14-`\""
AVBIN_COMMIT="\"`git rev-parse HEAD`\""

# Backend information
AVBIN_BACKEND="\"$BACKEND\""
pushd $BACKEND_DIR > /dev/null
AVBIN_BACKEND_VERSION_STRING="\"`git describe --abbrev=0 --tags`\""
AVBIN_BACKEND_REPO="\"`git remote show -n origin | grep Fetch | cut -b 14-`\""
AVBIN_BACKEND_COMMIT="\"`git rev-parse HEAD`\""
popd > /dev/null

fail() {
echo "AVbin: Fatal error: $1"
exit 1
}

clean_libav() {
pushd $LIBAV > /dev/null
clean_backend() {
pushd $BACKEND_DIR > /dev/null
echo -n "Cleaning up..."
make clean 2> /dev/null
make distclean 2> /dev/null
Expand All @@ -53,58 +64,69 @@ clean_libav() {
popd > /dev/null
}

build_libav() {
build_backend() {
config=`pwd`/$PLATFORM.configure
common=`pwd`/common.configure

if [ ! $REBUILD ]; then
clean_libav
clean_backend
fi

pushd $LIBAV > /dev/null
pushd $BACKEND_DIR > /dev/null

# If we're not rebuilding, then we need to configure Libav
# If we're not rebuilding, then we need to configure Backend
if [ ! $REBUILD ]; then
case $OSX_VERSION in
"10.6") SDKPATH="\/Developer\/SDKs\/MacOSX10.6.sdk" ;;
"10.7") SDKPATH="\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/MacOSX.platform\/Developer\/SDKs\/MacOSX10.6.sdk" ;;
*) SDKPATH="" ;;
esac

cat $config $common | egrep -v '^#' | sed s/%%SDKPATH%%/$SDKPATH/g | xargs ./configure || fail "Failed configuring libav."
cat $config $common | egrep -v '^#' | sed s/%%SDKPATH%%/$SDKPATH/g | xargs ./configure || fail "Failed configuring backend."
fi

# Remove -Werror options from config.mak that break builds on some platforms
cat config.mak | sed -e s/-Werror=implicit-function-declaration//g | sed -e s/-Werror=missing-prototypes//g > config.mak2
mv config.mak2 config.mak

# Actually build Libav
make || fail "Failed to build libav."
# Actually build Backend
make $FAST || fail "Failed to build backend."
popd
}

build_avbin() {
# For avbin.c ...
export AVBIN_VERSION
export AVBIN_VERSION_STRING
export AVBIN_BUILD_DATE
export AVBIN_REPO
export AVBIN_COMMIT
export AVBIN_BACKEND
export AVBIN_BACKEND_VERSION_STRING
export AVBIN_BACKEND_REPO
export AVBIN_BACKEND_COMMIT

# For the Makefile ...
export PLATFORM
export LIBAV
export LIBAV_COMMIT
export LIBAV_VERSION
export BACKEND_DIR

if [ ! $REBUILD ]; then
make clean
fi
make $FAST || fail "Failed to build AVbin."

make || fail "Failed to build AVbin."
}

build_macosx_universal() {
if [ ! -e dist/macosx-x86-32/libavbin.$AVBIN_VERSION.dylib ]; then
PLATFORM=macosx-x86-32
build_libav
build_backend
build_avbin
fi

if [ ! -e dist/macosx-x86-64/libavbin.$AVBIN_VERSION.dylib ]; then
PLATFORM=macosx-x86-64
build_libav
build_backend
build_avbin
fi

Expand Down Expand Up @@ -144,7 +166,7 @@ for arg in $* ; do
"--rebuild")
REBUILD=1;;
"--clean")
clean_libav
clean_backend
rm -rf dist
rm -rf build
rm -f example/avbin_dump
Expand Down Expand Up @@ -172,11 +194,11 @@ for PLATFORM in $platforms; do
;;
"macosx-x86-32" | "macosx-x86-64")
OSX_VERSION=`/usr/bin/sw_vers -productVersion | cut -b 1-4`
build_libav
build_backend
build_avbin
;;
"linux-x86-32" | "linux-x86-64" | "win32" | "win64")
build_libav
build_backend
build_avbin
;;
*)
Expand Down
23 changes: 21 additions & 2 deletions example/avbin_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* Example use of AVbin.
*
* Prints out stream details, then exits.
* Prints out AVbin details, then stream details, then exits.
*
* TODO: Optionally print verbose decoding information.
* TODO: Clean up, comment.
Expand All @@ -37,14 +37,33 @@ int main(int argc, char** argv)
if (avbin_init())
exit(-1);

printf("AVbin %d, built with Libav %s on commit %s.\n", avbin_get_version(), avbin_get_libav_version(), avbin_get_libav_commit());
AVbinInfo *info = avbin_get_info();

printf("AVbin %s (feature version %d) built on %s\n Repo: %s\n Commit: %s\n\n",
info->version_string,
info->version,
info->build_date,
info->repo,
info->commit);

printf("Backend: %s %s\n Repo: %s\n Commit: %s\n\n",
info->backend,
info->backend_version_string,
info->repo,
info->backend_commit);

if (argc < 2)
{
printf("Please specify audio or video file, for example:\n./avbin_dump some_file.mp3\n");
exit(-1);
}

AVbinFile* file = avbin_open_filename(argv[1]);
if (!file)
{
printf("Unable to open file '%s'\n", argv[1]);
exit(-1);
}

AVbinFileInfo fileinfo;
fileinfo.structure_size = sizeof(fileinfo);
Expand Down
74 changes: 61 additions & 13 deletions include/avbin.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,58 @@ typedef struct _AVbinPacket {
size_t size;
} AVbinPacket;

/**
* Information about the AVbin library.
*/
typedef struct _AVbinInfo {
/**
* AVbin version as an integer. This value is the same as returned by
* the avbin_get_version() function. Consider using version_string instead.
*/
int version;

/**
* AVbin version string, including pre-release information, i.e. "10-beta1".
*/
char *version_string;

/**
* When the library was built, in strftime format "%Y-%m-%d %H:%M:%S %z"
*/
char *build_date;

/**
* URL to the AVbin repository used.
*/
char *repo;

/**
* The commit of the AVbin repository used.
*/
char *commit;

/**
* Which backend we are using: "libav" or "ffmpeg"
*/
char *backend;

/**
* The version string of the most recent tag of the backend. Note: There
* may be custom patches *on top* of the backend version.
*/
char *backend_version_string;

/**
* URL to the backend repository used for this release.
*/
char *backend_repo;

/**
* The commit hash of the backend repo used for the backend.
*/
char *backend_commit;
} AVbinInfo;

/**
* Callback for log information.
*
Expand All @@ -400,30 +452,26 @@ typedef void (*AVbinLogCallback)(const char *module,
*/
int32_t avbin_get_version();

/**
* Get information about the linked version of AVbin.
*
* See the AVbinInfo definition.
*/
AVbinInfo *avbin_get_info();

/**
* Get the SVN revision of FFmpeg.
*
* This is built into AVbin as it is built.
*
* DEPRECATED: Use avbin_get_libav_commit or avbin_get_libav_version instead.
* This always returns 0 now that we use Libav from Git. This
* function will be removed in AVbin 11.
* function will be removed in AVbin 12.
*/
int32_t avbin_get_ffmpeg_revision() __attribute__((deprecated));

/**
* Get the git commit hash of the Libav submodule that was used at build time.
*
* This is built into AVbin as it is built.
*/
char * avbin_get_libav_commit();

/**
* Get the version string of the Libav submodule that was used at build time.
*
* This is built into AVbin as it is built.
*/
char * avbin_get_libav_version();


/**
* Get the minimum audio buffer size, in bytes.
Expand Down
8 changes: 4 additions & 4 deletions linux-x86-32.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ CFLAGS += -fPIC -fno-stack-protector -O3 -m32 --std=gnu99
LDFLAGS += -shared -soname $(SONAME) -melf_i386 -zmuldefs

STATIC_LIBS = -whole-archive \
$(LIBAV)/libavformat/libavformat.a \
$(LIBAV)/libavcodec/libavcodec.a \
$(LIBAV)/libavutil/libavutil.a \
$(LIBAV)/libswscale/libswscale.a \
$(BACKEND_DIR)/libavformat/libavformat.a \
$(BACKEND_DIR)/libavcodec/libavcodec.a \
$(BACKEND_DIR)/libavutil/libavutil.a \
$(BACKEND_DIR)/libswscale/libswscale.a \
-no-whole-archive

LIBS =
Expand Down
8 changes: 4 additions & 4 deletions linux-x86-64.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ CFLAGS += -fPIC -fno-stack-protector -O3 -m64 --std=gnu89
LDFLAGS += -shared -soname $(SONAME) -Bsymbolic -zmuldefs

STATIC_LIBS = -whole-archive \
$(LIBAV)/libavformat/libavformat.a \
$(LIBAV)/libavcodec/libavcodec.a \
$(LIBAV)/libavutil/libavutil.a \
$(LIBAV)/libswscale/libswscale.a \
$(BACKEND_DIR)/libavformat/libavformat.a \
$(BACKEND_DIR)/libavcodec/libavcodec.a \
$(BACKEND_DIR)/libavutil/libavutil.a \
$(BACKEND_DIR)/libswscale/libswscale.a \
-no-whole-archive \
-R /usr/local/lib \
-R .
Expand Down
8 changes: 4 additions & 4 deletions macosx-x86-32.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ LDFLAGS += -dylib \
-framework VideoDecodeAcceleration \
-read_only_relocs suppress

STATIC_LIBS = $(LIBAV)/libavformat/libavformat.a \
$(LIBAV)/libavcodec/libavcodec.a \
$(LIBAV)/libavutil/libavutil.a \
$(LIBAV)/libswscale/libswscale.a
STATIC_LIBS = $(BACKEND_DIR)/libavformat/libavformat.a \
$(BACKEND_DIR)/libavcodec/libavcodec.a \
$(BACKEND_DIR)/libavutil/libavutil.a \
$(BACKEND_DIR)/libswscale/libswscale.a

LIBS = -lSystem \
-lz \
Expand Down
8 changes: 4 additions & 4 deletions macosx-x86-64.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ LDFLAGS += -dylib \
-framework CoreVideo \
-framework VideoDecodeAcceleration

STATIC_LIBS = $(LIBAV)/libavformat/libavformat.a \
$(LIBAV)/libavcodec/libavcodec.a \
$(LIBAV)/libavutil/libavutil.a \
$(LIBAV)/libswscale/libswscale.a
STATIC_LIBS = $(BACKEND_DIR)/libavformat/libavformat.a \
$(BACKEND_DIR)/libavcodec/libavcodec.a \
$(BACKEND_DIR)/libavutil/libavutil.a \
$(BACKEND_DIR)/libswscale/libswscale.a

LIBS = -lSystem \
-lz \
Expand Down
Loading

0 comments on commit e145511

Please sign in to comment.