Subject: [codec] [PATCH] version string updates

From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:11:10 -0700

Jean-Marc,

Thanks for adding opus_get_version_string() to the reference
implementation. Here are a couple of patches to improve the function.

 -r
From 42eb9330c9a5f63b4f005e3a26b4fe3323e72736 Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Mon, 1 Aug 2011 17:10:00 -0700
Subject: [PATCH 1/4] Define a fallback version string.

The new opus_get_version_string() call just returns a static string
defined by OPUS_VERSION, which is passed in from the build system
through config.h (or a custom compile line). Provide a fallback to
"unknown" if the build system fails to actually provide that definition.

This restores compilation with Makefile.draft.

In general, this means there will be builds out there with non-specific
version strings, since ports won't be forced to update the string. While
that's unfortunate, I think it's more valuable that the library be simple
to build.
---
 src/opus.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/opus.c b/src/opus.c
index 419918b..55e76d9 100644
--- a/src/opus.c
+++ b/src/opus.c
@@ -31,6 +31,10 @@
 
 #include "opus.h"
 
+#ifndef OPUS_VERSION
+#define OPUS_VERSION "Opus version unknown"
+#endif
+
 const char *opus_strerror(int error)
 {
    static const char *error_strings[8] = {
-- 
1.7.6

From 50f933b57f078d7ad25a6c1fe0e8aa70c5c611bc Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 09:34:55 -0700
Subject: [PATCH 2/4] Query git for the repository revision and use that for
 the version string.

Rather than compiling in the fixed version number from the configure
file, it's more helpful for testing and debugging to directly embed
the repository's revision. We use 'git describe --tags' for this, since
for tagged revisions it just returns the tag name, and in other cases
is more readable than a raw commit id.

If git isn't present or can't find a repository to query, we fall back
to the static version number in the configure script.
---
 configure.ac |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8c7a132..747623d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,17 @@ OPUS_MAJOR_VERSION=0
 OPUS_MINOR_VERSION=9
 OPUS_MICRO_VERSION=6
 OPUS_EXTRA_VERSION=
-OPUS_VERSION=$OPUS_MAJOR_VERSION.$OPUS_MINOR_VERSION.$OPUS_MICRO_VERSION$OPUS_EXTRA_VERSION
+
+OPUS_VERSION="$OPUS_MAJOR_VERSION.$OPUS_MINOR_VERSION.$OPUS_MICRO_VERSION$OPUS_EXTRA_VERSION"
+AC_MSG_CHECKING([git revision])
+GIT_VERSION=$(git describe --tags 2>/dev/null)
+if test -z "$GIT_VERSION"; then
+  AC_MSG_RESULT([no])
+else
+  AC_MSG_RESULT([$GIT_VERSION])
+  OPUS_VERSION="$GIT_VERSION"
+fi
+
 LIBOPUS_SUFFIX=0
 
 OPUS_LT_CURRENT=0
@@ -27,6 +37,7 @@ AC_SUBST(LIBOPUS_SUFFIX)
 VERSION=$OPUS_VERSION
 PACKAGE=opus
 
+# For our version string
 AC_SUBST(OPUS_VERSION)
 
 AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
-- 
1.7.6

From e308edf82c5594592b3a1b54e67620572d700313 Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 09:39:54 -0700
Subject: [PATCH 3/4] Prepend "Opus" to the version string.

This lets users print it out without context, which is a little
easier for clients.
---
 src/opus.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/opus.c b/src/opus.c
index 55e76d9..a7d8427 100644
--- a/src/opus.c
+++ b/src/opus.c
@@ -55,5 +55,5 @@ const char *opus_strerror(int error)
 
 const char *opus_get_version_string(void)
 {
-	return OPUS_VERSION;
+	return "Opus " OPUS_VERSION;
 }
-- 
1.7.6

---

From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:19:44 -0700

Two additional improvements.

 -r
From a57e0b986e0ffdfc3fdacb5095689b8a12b20a4c Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:14:36 -0700
Subject: [PATCH 1/2] Print the library version from test_opus.

This lets us verify this part of the API is working.
---
 src/test_opus.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/test_opus.c b/src/test_opus.c
index 2771cb6..d4b1ce3 100644
--- a/src/test_opus.c
+++ b/src/test_opus.c
@@ -122,6 +122,8 @@ int main(int argc, char *argv[])
        return 1;
     }
 
+    fprintf(stderr, "%s\n", opus_get_version_string());
+
     if (strcmp(argv[1], "-e")==0)
     {
         encode_only = 1;
-- 
1.7.6

From b8a30f9ca3776b71adf3a8b344c2351e40256b15 Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:17:44 -0700
Subject: [PATCH 2/2] Use 'libopus' rather than 'Opus' in the version string.

This better distinguishes the reference implementation,
which is what this string is meant to do. Thanks to
Greg Maxwell for the suggestion.
---
 src/opus.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/opus.c b/src/opus.c
index a7d8427..432e650 100644
--- a/src/opus.c
+++ b/src/opus.c
@@ -32,7 +32,7 @@
 #include "opus.h"
 
 #ifndef OPUS_VERSION
-#define OPUS_VERSION "Opus version unknown"
+#define OPUS_VERSION "libopus version unknown"
 #endif

 const char *opus_get_version_string(void)
 {
-	return "Opus " OPUS_VERSION;
+	return "libopus " OPUS_VERSION;
 }
-- 
1.7.6

---

From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:35:23 -0700

And one more,

 -r
From 5840aaf26c83f0e6beff57ced047a31be995dd20 Mon Sep 17 00:00:00 2001
From: Ralph Giles <[email-masked]>
Date: Tue, 2 Aug 2011 10:33:04 -0700
Subject: [PATCH] Remove duplicate 'libopus' from the fallback version string.

Thanks to Tim Terriberry for pointing out the issue.
---
 src/opus.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/opus.c b/src/opus.c
index 432e650..791ec09 100644
--- a/src/opus.c
+++ b/src/opus.c
@@ -32,7 +32,7 @@
 #include "opus.h"
 
 #ifndef OPUS_VERSION
-#define OPUS_VERSION "libopus version unknown"
+#define OPUS_VERSION "unknown"
 #endif