Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 45 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,58 @@ cmake_minimum_required (VERSION 3.12)
# Project versioning
########################################

# Set project version from git tag or version.txt file
function(get_versions versionstring VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
string(REGEX REPLACE "^([vV])([0-9]*)([.][0-9]*[.][0-9]*-?.*)$" "\\2" numbers ${versionstring})
set(VERSION_MAJOR ${numbers} PARENT_SCOPE)
string(REGEX REPLACE "^([vV][0-9]*[.])([0-9]*)([.][0-9]*-?.*)$" "\\2" numbers ${versionstring})
set(VERSION_MINOR ${numbers} PARENT_SCOPE)
string(REGEX REPLACE "^([vV][0-9]*[.][0-9]*[.])([0-9]*)(-?.*)$" "\\2" numbers ${versionstring})
set(VERSION_PATCH ${numbers} PARENT_SCOPE)
endfunction()

execute_process(
COMMAND git describe --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=0 --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE OUTPUT)

if(NOT RESULT EQUAL 0)
find_program(GIT_COMMAND "git")
if(GIT_COMMAND)
message(WARNING "There is no valid git repository in your working directory \"${CMAKE_SOURCE_DIR}\" .")
else()
message(WARNING "You have no git tool installed.")
endif()

if(NOT EXISTS "${CMAKE_SOURCE_DIR}/version.txt")
message(FATAL_ERROR
"version.txt file doesn't exist!\n"
"Since your working directory doesn't contain a git repository you must provide \"${CMAKE_SOURCE_DIR}/version.txt\" file containing a valid version string.\n"
"The version string provided to version.txt must match the following format:\n\tv[VERSION_MAJOR].[VERSION_MINOR].[VERSION_PATCH]\n"
"To get the information on version of the downloaded library please follow the link below:\n\t https://github.com/AcademySoftwareFoundation/openapv"
)
endif()

message("Version string has been taken from version.txt file.")
file(STRINGS "version.txt" VERSION_STRING)
set(OAPV_H_HEADER_FILE "${CMAKE_SOURCE_DIR}/inc/oapv.h")

if(NOT EXISTS ${OAPV_H_HEADER_FILE})
message(FATAL_ERROR
"${CMAKE_SOURCE_DIR}/inc/oapv.h file doesn't exist!\n"
"File contains OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH definitions that specifie openAPV project version.\n"
"To get the information on version of the downloaded library please follow the link below:\n\t https://github.com/AcademySoftwareFoundation/openapv"
)
endif()

file(READ ${OAPV_H_HEADER_FILE} HEADER_CONTENT)

# Regular expressions for extracting versions
string(REGEX MATCH "(#define)([ ]+)(OAPV_VER_APISET)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" APISET_MATCH ${HEADER_CONTENT})
string(REGEX MATCH "(#define)([ ]+)(OAPV_VER_MAJOR)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" MAJOR_MATCH ${HEADER_CONTENT})
string(REGEX MATCH "(#define)([ ]+)(OAPV_VER_MINOR)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" MINOR_MATCH ${HEADER_CONTENT})
string(REGEX MATCH "(#define)([ ]+)(OAPV_VER_PATCH)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" PATCH_MATCH ${HEADER_CONTENT})

# Extract the values OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH from the oapv.h file
if(APISET_MATCH)
string(REGEX REPLACE "(#define)([ ]+)(OAPV_VER_APISET)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" "\\7" VERSION_APISET ${APISET_MATCH})
else()
message(WARRNING "In the file oapv.h, no matching string was found for the regular expression (regex) used to match the pattern containing #define OAPV_VER_APISET (number).")
endif()

if(MAJOR_MATCH)
string(REGEX REPLACE "(#define)([ ]+)(OAPV_VER_MAJOR)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" "\\7" VERSION_MAJOR ${MAJOR_MATCH})
else()
message("Version string has been taken from git tag.")
set(VERSION_STRING ${OUTPUT})
string(REGEX REPLACE "\n$" "" VERSION_STRING "${VERSION_STRING}")
message(WARRNING "In the file oapv.h, no matching string was found for the regular expression (regex) used to match the pattern containing #define OAPV_VER_MAJOR (number).")
endif()

if(NOT ${VERSION_STRING} MATCHES "^([vV])([0-9]*)([.][0-9]*[.][0-9]*-?.*)$")
message(FATAL_ERROR "Version string ${VERSION_STRING} doesn't match required format v[VERSION_MAJOR].[VERSION_MINOR].[VERSION_PATCH]")
if(MINOR_MATCH)
string(REGEX REPLACE "(#define)([ ]+)(OAPV_VER_MINOR)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" "\\7" VERSION_MINOR ${MINOR_MATCH})
else()
message(WARRNING "In the file oapv.h, no matching string was found for the regular expression (regex) used to match the pattern containing #define OAPV_VER_MINOR (number).")
endif()

get_versions(${VERSION_STRING} VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
if(VERSION_MAJOR STREQUAL ${VERSION_STRING})
message(FATAL_ERROR "Version string parsing error")
if(PATCH_MATCH)
string(REGEX REPLACE "(#define)([ ]+)(OAPV_VER_PATCH)([ ]+)(\\()([ ]*)([0-9]+)([ ]*)(\\))" "\\7" VERSION_PATCH ${PATCH_MATCH})
else()
message(WARRNING "In the file oapv.h, no matching string was found for the regular expression (regex) used to match the pattern containing #define OAPV_VER_PATCH (number).")
endif()
message("OAPV VERSION=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

project(OAPV VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES C)
message(DEBUG "OAPV_VER_APISET: ${VERSION_APISET}")
message(DEBUG "OAPV_VER_MAJOR: ${VERSION_MAJOR}")
message(DEBUG "OAPV_VER_MINOR: ${VERSION_MINOR}")
message(DEBUG "OAPV_VER_PATCH: ${VERSION_PATCH}")

message(STATUS "OAPV version has been taken from ${OAPV_H_HEADER_FILE} file.")
message(STATUS "OAPV version: ${VERSION_APISET}.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

project(OAPV VERSION ${VERSION_APISET}.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES C)

########################################
# Input arguments.
Expand Down Expand Up @@ -219,10 +218,7 @@ set(CPACK_PACKAGE_CONTACT "https://github.com/AcademySoftwareFoundation")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/AcademySoftwareFoundation/openapv/releases")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/AcademySoftwareFoundation/openapv")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open Advanced Professional Video Codec")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${VERSION_APISET}.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(CPACK_PACKAGE_CHECKSUM MD5)

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "AcademySoftwareFoundation")
Expand Down
38 changes: 29 additions & 9 deletions inc/oapv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,38 @@
extern "C" {
#endif

#include <oapv_config.h>

#if defined(OAPV_LIBVERSION_HEADER)
#include <oapv/oapv_libversion.h>
#if defined(ANDROID) || defined(OAPV_STATIC_DEFINE)
#define OAPV_EXPORT
#else
#include <oapv/oapv_exports.h>
#endif

#if defined(OAPV_EXPORT_HEADER) && !defined(OAPV_STATIC_DEFINE)
#include <oapv/oapv_exports.h>
#else
#define OAPV_EXPORT
#if !defined(ANDROID)
#include <oapv/oapv_version.h>
#endif

/*****************************************************************************
* version and related macro
* the version string follows the rule of API_SET.MAJOR.MINOR.PATCH
*****************************************************************************/
#define OAPV_VER_SET(apiset, major, minor, patch) \
(((apiset & 0xFF) << 24)|((major & 0xFF) << 16)|((minor & 0xFF) << 8)|\
(patch & 0xFF))
#define OAPV_VER_GET_APISET(v) (((v) >> 24) & 0xFF)
#define OAPV_VER_GET_MAJOR(v) (((v) >> 16) & 0xFF)
#define OAPV_VER_GET_MINOR(v) (((v) >> 8) & 0xFF)
#define OAPV_VER_GET_PATCH(v) (((v) >> 0) & 0xFF)

/* version numbers (should be changed in case of new release) */
#define OAPV_VER_APISET (0)
#define OAPV_VER_MAJOR (1)
#define OAPV_VER_MINOR (13)
#define OAPV_VER_PATCH (1)

/* 4-bytes version number */
#define OAPV_VER_NUM \
OAPV_VER_SET(OAPV_VER_APISET,OAPV_VER_MAJOR,OAPV_VER_MINOR,OAPV_VER_PATCH)

/* size of macroblock */
#define OAPV_LOG2_MB (4)
#define OAPV_LOG2_MB_W (4)
Expand Down Expand Up @@ -664,7 +684,7 @@ OAPV_EXPORT int oapvd_info(void *au, int au_size, oapv_au_info_t *aui);
/*****************************************************************************
* openapv version
*****************************************************************************/
OAPV_EXPORT char *oapv_version();
OAPV_EXPORT char *oapv_version(void);

#ifdef __cplusplus
} /* extern "C" */
Expand Down
38 changes: 0 additions & 38 deletions inc/oapv_config.h

This file was deleted.

38 changes: 0 additions & 38 deletions inc/oapv_config.h.in

This file was deleted.

23 changes: 13 additions & 10 deletions inc/oapv_libversion.h.in → inc/oapv_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __OAPV_LIBVERSION_H__8465216516551324987461894651851187416502317561968__
#define __OAPV_LIBVERSION_H__8465216516551324987461894651851187416502317561968__
#ifndef __OAPV_VERSION_H__8465216516551324987461894651851187416502317561968__
#define __OAPV_VERSION_H__8465216516551324987461894651851187416502317561968__

#cmakedefine01 OAPV_BUILD_SHARED_LIB
#if !OAPV_BUILD_SHARED_LIB && !defined(OAPV_STATIC_DEFINE)
#define OAPV_STATIC_DEFINE
#endif
#undef OAPV_BUILD_SHARED_LIB

#define OAPV_LIB_VERSION_MAJOR @LIB_VERSION_MAJOR@
#define OAPV_LIB_VERSION_MINOR @LIB_VERSION_MINOR@
#define OAPV_LIB_VERSION_PATCH @LIB_VERSION_PATCH@
// Project version
#define OAPV_VERSION_APISET @VERSION_APISET@
#define OAPV_VERSION_MAJOR @VERSION_MAJOR@
#define OAPV_VERSION_MINOR @VERSION_MINOR@
#define OAPV_VERSION_PATCH @VERSION_PATCH@

#define OAPV_CHECK_LIB_VERSION(major, minor, patch) \
((major) < OAPV_LIB_VERSION_MAJOR || \
((major) == OAPV_LIB_VERSION_MAJOR && (minor) < OAPV_LIB_VERSION_MINOR) || \
((major) == OAPV_LIB_VERSION_MAJOR && (minor) == OAPV_LIB_VERSION_MINOR && (patch) <= OAPV_LIB_VERSION_PATCH))
#define OAPV_CHECK_VERSION(apiset, major, minor, patch) \
((apiset) < OAPV_VERSION_APISET || \
((apiset) == OAPV_VERSION_APISET && (major) < OAPV_VERSION_MAJOR) || \
((apiset) == OAPV_VERSION_APISET && (major) == OAPV_VERSION_MAJOR && (minor) < OAPV_VERSION_MINOR) || \
((apiset) == OAPV_VERSION_APISET && (major) == OAPV_VERSION_MAJOR && (minor) == OAPV_VERSION_MINOR && (patch) <= OAPV_VERSION_PATCH))

#endif /* __OAPV_LIBVERSION_H__8465216516551324987461894651851187416502317561968__ */
#endif /* __OAPV_VERSION_H__8465216516551324987461894651851187416502317561968__ */
2 changes: 1 addition & 1 deletion pkgconfig/oapv.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ includedir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@LIB_NAME_BASE@
Name: oapv
Description: Advanced Professional Video Codec

Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@
Version: @VERSION_APISET@.@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@

Requires:
Libs: -L${libdir} -l@LIB_NAME_BASE@
Expand Down
16 changes: 4 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
set(LIB_NAME_BASE oapv)

set(LIB_VERSION_MAJOR 1)
set(LIB_VERSION_MINOR 0)
set(LIB_VERSION_PATCH 0)

file(GLOB LIB_INC "../inc/*.h")
file(GLOB LIB_API_SRC "oapv.c")
file(GLOB LIB_BASE_SRC "oapv_*.c")
Expand All @@ -15,17 +11,13 @@ file(GLOB LIB_NEON_INC "../src/neon/oapv_*.h" )
file(GLOB LIB_AVX_SRC "../src/avx/oapv_*.c")
file(GLOB LIB_AVX_INC "../src/avx/oapv_*.h" )

set(LIB_LIBVERSION_HEADER "${CMAKE_BINARY_DIR}/include/${LIB_NAME_BASE}/${LIB_NAME_BASE}_libversion.h")
configure_file("${CMAKE_SOURCE_DIR}/inc/${LIB_NAME_BASE}_libversion.h.in" "${LIB_LIBVERSION_HEADER}" @ONLY)
list(APPEND LIB_INC "${LIB_LIBVERSION_HEADER}")
set(LIB_VERSION_HEADER "${CMAKE_BINARY_DIR}/include/${LIB_NAME_BASE}/${LIB_NAME_BASE}_version.h")
configure_file("${CMAKE_SOURCE_DIR}/inc/${LIB_NAME_BASE}_version.h.in" "${LIB_VERSION_HEADER}" @ONLY)
list(APPEND LIB_INC "${LIB_VERSION_HEADER}")

include(GenerateExportHeader)
include_directories("${CMAKE_BINARY_DIR}/include")

set(LIB_CONFIG_HEADER "${CMAKE_SOURCE_DIR}/inc/${LIB_NAME_BASE}_config.h")
configure_file("${CMAKE_SOURCE_DIR}/inc/${LIB_NAME_BASE}_config.h.in" "${LIB_CONFIG_HEADER}" @ONLY)
list(APPEND LIB_INC "${LIB_CONFIG_HEADER}")


message("SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")

Expand Down Expand Up @@ -67,7 +59,7 @@ endif()

if(OAPV_BUILD_SHARED_LIB)
add_library(${LIB_NAME_BASE}_dynamic SHARED ${SOURCE_FILES})
set_target_properties(${LIB_NAME_BASE}_dynamic PROPERTIES VERSION ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH} SOVERSION ${LIB_VERSION_MAJOR})
set_target_properties(${LIB_NAME_BASE}_dynamic PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} SOVERSION ${VERSION_MAJOR})
set_target_properties(${LIB_NAME_BASE}_dynamic PROPERTIES OUTPUT_NAME ${LIB_NAME_BASE})

# @todo Consider using WINDOWS_EXPORT_ALL_SYMBOLS instead of generate_export_header
Expand Down
10 changes: 8 additions & 2 deletions src/oapv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2153,5 +2153,11 @@ int oapvd_info(void *au, int au_size, oapv_au_info_t *aui)
#endif // ENABLE_DECODER
///////////////////////////////////////////////////////////////////////////////

static char *oapv_ver = "0.1.13.1";
char * oapv_version() { return oapv_ver; }
char *oapv_version(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be made a const char* instead? With CMake it's trivial to generate the "0.1.13.1" string at configure time, but i assume the issue is with Android?
As is, this looks potentially racy. If it can't be const, then it should allocate a buffer and return it, and the user should then free it.

Also, an int version is still extremely useful for runtime checks, so please add it as a separate function, like unsigned int oapv_version_int()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is macro OAPV_VER_SET from inc/oapv.h is sufficient in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To generate the int to be returned? Yes

unsigned int oapv_version_int()
{
    return OAPV_VER_SET(OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH);
}

Without a function like this, API users that want the version in integer form would need to parse the output of oapv_version()

Copy link
Collaborator

@cpncf cpncf Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend to use OAPV_VER_NUM constant defined in oapv.h, which is the integer type version number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for compile time checks. A function is needed for runtime checks.

I see it was added and then removed because of this comment. It would have been nice to wait a bit instead of being so hasty. Now it will need to be added as a separate PR.

Copy link
Collaborator

@kpchoi kpchoi Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for compile time checks. A function is needed for runtime checks.

I see it was added and then removed because of this comment. It would have been nice to wait a bit instead of being so hasty. Now it will need to be added as a separate PR.

I hope that the PR #104 can be an answer of your considerations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function may return not just the version number but also an error code, which is a negative value, despite the return type being unsigned, and as such can't be checked at all. For all the API user knows, it just returned a valid version number they can parse with OAPV_VER_GET_*.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function may return not just the version number but also an error code, which is a negative value, despite the return type being unsigned, and as such can't be checked at all. For all the API user knows, it just returned a valid version number they can parse with OAPV_VER_GET_*.

Again, oapv_version() has changed to support your comments.
Check the PR #105 .

{
static char oapv_version_string[16];
snprintf(oapv_version_string, sizeof(oapv_version_string), "%d.%d.%d.%d",
OAPV_VER_APISET, OAPV_VER_MAJOR, OAPV_VER_MINOR, OAPV_VER_PATCH);
return (char*)oapv_version_string;
}

1 change: 0 additions & 1 deletion version.txt

This file was deleted.