From d043e3390ba0e93a818a48cbb5665e07b45b4724 Mon Sep 17 00:00:00 2001 From: Yu You Date: Fri, 13 Nov 2020 15:51:21 +0200 Subject: [PATCH 01/11] used meson for 3rd_party metadata lib and chnaged the lib load path --- build-gst-python.sh | 11 +++++++---- gstreamer/3rd_party/gstreamer/CMakeLists.txt | 4 +++- gstreamer/gst_objects_info_meta.py | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build-gst-python.sh b/build-gst-python.sh index d019e51..5b03d5c 100755 --- a/build-gst-python.sh +++ b/build-gst-python.sh @@ -28,10 +28,13 @@ cd gst-python export PYTHON=$PYTHON git checkout $GST_VERSION -./autogen.sh --disable-gtk-doc --noconfigure -./configure --with-libpython-dir=$LIBPYTHONPATH --prefix $GST_PREFIX -make -make install +#./autogen.sh --disable-gtk-doc --noconfigure +#./configure --with-libpython-dir=$LIBPYTHONPATH --prefix $GST_PREFIX +#make +#make install +meson --prefix=/usr -Dbuildtype=release build +#ninja -C build +ninja -C build install cd ../.. diff --git a/gstreamer/3rd_party/gstreamer/CMakeLists.txt b/gstreamer/3rd_party/gstreamer/CMakeLists.txt index 8132cd9..c8498c8 100644 --- a/gstreamer/3rd_party/gstreamer/CMakeLists.txt +++ b/gstreamer/3rd_party/gstreamer/CMakeLists.txt @@ -24,4 +24,6 @@ message("CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") set_target_properties(gst_objects_info_meta PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS} - LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) \ No newline at end of file + LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) + +install(TARGETS gst_objects_info_meta DESTINATION lib) \ No newline at end of file diff --git a/gstreamer/gst_objects_info_meta.py b/gstreamer/gst_objects_info_meta.py index 5de5cb7..78064c4 100644 --- a/gstreamer/gst_objects_info_meta.py +++ b/gstreamer/gst_objects_info_meta.py @@ -24,8 +24,9 @@ class GstObjectInfoArray(Structure): GstObjectInfoArrayPtr = POINTER(GstObjectInfoArray) -cwd = os.path.dirname(os.path.abspath(__file__)) -libc = CDLL(os.path.join(cwd, "3rd_party/gstreamer/build/libgst_objects_info_meta.so")) +#cwd = os.path.dirname(os.path.abspath(__file__)) +#libc = CDLL(os.path.join(cwd, "3rd_party/gstreamer/build/libgst_objects_info_meta.so")) +libc = CDLL("libgst_objects_info_meta.so") libc.gst_buffer_add_objects_info_meta.argtypes = [c_void_p, GstObjectInfoArrayPtr] libc.gst_buffer_add_objects_info_meta.restype = c_void_p From 256526e9194c2405c8cbe6b4a8c38ae053c26b09 Mon Sep 17 00:00:00 2001 From: Yu You Date: Mon, 30 Nov 2020 09:20:12 +0200 Subject: [PATCH 02/11] use meson/ninja to build 3rd party libs --- gstreamer/3rd_party/build.sh | 7 +++++-- setup.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gstreamer/3rd_party/build.sh b/gstreamer/3rd_party/build.sh index d3ac13c..16d3b9d 100755 --- a/gstreamer/3rd_party/build.sh +++ b/gstreamer/3rd_party/build.sh @@ -3,5 +3,8 @@ ROOT=$PWD echo "PWD: $PWD" # Gstreamer -cd gstreamer -./build.sh \ No newline at end of file +#cd gstreamer +#./build.sh +meson build +#ninja -C build +ninja -C build install diff --git a/setup.py b/setup.py index 0c4b59c..26769ef 100644 --- a/setup.py +++ b/setup.py @@ -42,8 +42,8 @@ def _run_bash_file(bash_file: str): print("Not found ", bash_file) cwd = os.path.dirname(os.path.abspath(__file__)) - if not bool(self.skip_gst_python): - _run_bash_file(os.path.join(cwd, 'build-gst-python.sh')) + #if not bool(self.skip_gst_python): + # _run_bash_file(os.path.join(cwd, 'build-gst-python.sh')) _run_bash_file(os.path.join(cwd, 'build-3rd-party.sh')) _build_py.run(self) From 0c413e3a5b3daa6018fd79143d22b11ed1edcc35 Mon Sep 17 00:00:00 2001 From: Yu You Date: Thu, 3 Dec 2020 15:13:41 +0200 Subject: [PATCH 03/11] added meson build and hack for Mac OSX --- gstreamer/3rd_party/gstreamer/meson.build | 33 +++++++++++++++++++++++ gstreamer/3rd_party/meson.build | 14 ++++++++++ gstreamer/gst_hacks.py | 11 +++++--- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 gstreamer/3rd_party/gstreamer/meson.build create mode 100644 gstreamer/3rd_party/meson.build diff --git a/gstreamer/3rd_party/gstreamer/meson.build b/gstreamer/3rd_party/gstreamer/meson.build new file mode 100644 index 0000000..803ac92 --- /dev/null +++ b/gstreamer/3rd_party/gstreamer/meson.build @@ -0,0 +1,33 @@ +plugin_c_args = ['-DHAVE_CONFIG_H'] + +cdata = configuration_data() +cdata.set_quoted('PACKAGE_VERSION', gst_version) +cdata.set_quoted('PACKAGE', 'gst-itt4rt-plugin') +# Gstreamer license list: https://gitlab.freedesktop.org/gstreamer/gstreamer/blob/1.16.0/gst/gstplugin.c +# BSD or MIT/X11 +cdata.set_quoted('GST_LICENSE', 'Proprietary') +cdata.set_quoted('GST_API_VERSION', api_version) +cdata.set_quoted('GST_PACKAGE_NAME', 'GStreamer template Plug-ins') +cdata.set_quoted('GST_PACKAGE_ORIGIN', 'https://gstreamer.freedesktop.org') +configure_file(output : 'config.h', configuration : cdata) + +#gstaudio_dep = dependency('gstreamer-audio-1.0', +# fallback: ['gst-plugins-base', 'audio_dep']) + +#gstrtp_dep = dependency('gstreamer-rtp-1.0') + + +# Viewport Glib metadata dynamic library +viewport_meta_sources = [ + 'gst_objects_info_meta.c' + ] + +# viewport meta +# create gst_viewport_meta.dll or libgst_viewport_meta.so +gst_objects_info_meta = library('gst_objects_info_meta', + viewport_meta_sources, + c_args: plugin_c_args, + dependencies : [gst_dep], + install : true, + install_dir : get_option('libdir'), +) diff --git a/gstreamer/3rd_party/meson.build b/gstreamer/3rd_party/meson.build new file mode 100644 index 0000000..6bfb0a7 --- /dev/null +++ b/gstreamer/3rd_party/meson.build @@ -0,0 +1,14 @@ +project('gst-rtp-viewport-metadata', 'c', version : '1.0.0.1', license : 'Proprietary') + +plugins_install_dir = join_paths(get_option('libdir'), 'gstreamer-1.0') + +cc = meson.get_compiler('c') + +gst_version = meson.project_version() + +api_version = '1.0' + +gst_dep = dependency('gstreamer-1.0', + fallback : ['gstreamer', 'gst_dep']) + +subdir('gstreamer') diff --git a/gstreamer/gst_hacks.py b/gstreamer/gst_hacks.py index 5041312..fad7e3f 100644 --- a/gstreamer/gst_hacks.py +++ b/gstreamer/gst_hacks.py @@ -5,7 +5,7 @@ from ctypes import * from typing import Tuple from contextlib import contextmanager - +import platform import gi gi.require_version('Gst', '1.0') from gi.repository import Gst # noqa:F401,F402 @@ -24,8 +24,13 @@ class _GstMapInfo(Structure): _GST_MAP_INFO_POINTER = POINTER(_GstMapInfo) - -_libgst = CDLL(os.getenv("LIB_GSTREAMER_PATH", "libgstreamer-1.0.so.0")) +# we need to check the OS +# "libgstreamer-1.0.dylib" +if platform.system() == 'Darwin': + _libgst = CDLL(os.getenv("LIB_GSTREAMER_PATH", "libgstreamer-1.0.dylib")) +else: + _libgst = CDLL(os.getenv("LIB_GSTREAMER_PATH", "libgstreamer-1.0.so.0")) + _libgst.gst_buffer_map.argtypes = [c_void_p, _GST_MAP_INFO_POINTER, c_int] _libgst.gst_buffer_map.restype = c_int From 151efb270a727f7b7963fe838d068209aa1685c2 Mon Sep 17 00:00:00 2001 From: Lucas Koelman Date: Fri, 7 May 2021 13:54:06 +0200 Subject: [PATCH 04/11] Fix python 3.8 compatibility --- build-gst-python.sh | 4 ++-- gstreamer/3rd_party/build.sh | 7 ++++++- gstreamer/3rd_party/gstreamer/meson.build | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build-gst-python.sh b/build-gst-python.sh index 5b03d5c..a1563df 100755 --- a/build-gst-python.sh +++ b/build-gst-python.sh @@ -4,7 +4,7 @@ LIBPYTHONPATH="" PYTHON=${PYTHON:-/usr/bin/python3} -GST_VERSION=${GST_VERSION:-$(gst-launch-1.0 --version | grep version | tr -s ' ' '\n' | tail -1)} +GST_VERSION=${GST_VERSION:-$(gst-launch-1.0 --version | grep version | tr -s ' ' '\n' | tail -1 | $PYTHON -c "import sys; print('.'.join(next(sys.stdin).strip().split('.')[:2]))")} # Ensure pygst to be installed in current environment LIBPYTHON=$($PYTHON -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LDLIBRARY"))') @@ -32,7 +32,7 @@ git checkout $GST_VERSION #./configure --with-libpython-dir=$LIBPYTHONPATH --prefix $GST_PREFIX #make #make install -meson --prefix=/usr -Dbuildtype=release build +meson --prefix=$GST_PREFIX --libdir=$GST_PREFIX/lib -Dpython=$PYTHON -Dlibpython-dir=$LIBPYTHONPATH -Dbuildtype=release build #ninja -C build ninja -C build install diff --git a/gstreamer/3rd_party/build.sh b/gstreamer/3rd_party/build.sh index 16d3b9d..86e49e3 100755 --- a/gstreamer/3rd_party/build.sh +++ b/gstreamer/3rd_party/build.sh @@ -5,6 +5,11 @@ echo "PWD: $PWD" # Gstreamer #cd gstreamer #./build.sh -meson build +BUILD_OPTS="" +if [[ -n "$GST_PREFIX" ]]; then + BUILD_OPTS="${BUILD_OPTS} --prefix ${GST_PREFIX} --libdir=${GST_PREFIX}/lib" +fi +echo $BUILD_OPTS +meson setup --wipe $BUILD_OPTS build #ninja -C build ninja -C build install diff --git a/gstreamer/3rd_party/gstreamer/meson.build b/gstreamer/3rd_party/gstreamer/meson.build index 803ac92..eb6a34d 100644 --- a/gstreamer/3rd_party/gstreamer/meson.build +++ b/gstreamer/3rd_party/gstreamer/meson.build @@ -29,5 +29,5 @@ gst_objects_info_meta = library('gst_objects_info_meta', c_args: plugin_c_args, dependencies : [gst_dep], install : true, - install_dir : get_option('libdir'), + install_dir : join_paths(get_option('libdir'), 'gstreamer-1.0'), ) From f88f4f13097f95d5e92b1ab8867425b17dbd75b6 Mon Sep 17 00:00:00 2001 From: Lucas Koelman Date: Fri, 7 May 2021 14:17:34 +0200 Subject: [PATCH 05/11] Re-enable build script execution in setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 26769ef..edd1206 100644 --- a/setup.py +++ b/setup.py @@ -42,8 +42,8 @@ def _run_bash_file(bash_file: str): print("Not found ", bash_file) cwd = os.path.dirname(os.path.abspath(__file__)) - #if not bool(self.skip_gst_python): - # _run_bash_file(os.path.join(cwd, 'build-gst-python.sh')) + if not bool(self.skip_gst_python): + _run_bash_file(os.path.join(cwd, 'build-gst-python.sh')) _run_bash_file(os.path.join(cwd, 'build-3rd-party.sh')) _build_py.run(self) From 0f7d3dd1b281824e375cb8553ceb2580e99bb154 Mon Sep 17 00:00:00 2001 From: Lucas Koelman Date: Fri, 7 May 2021 16:50:26 +0200 Subject: [PATCH 06/11] Bugfix in 3rd party build script --- gstreamer/3rd_party/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gstreamer/3rd_party/build.sh b/gstreamer/3rd_party/build.sh index 86e49e3..b5e949a 100755 --- a/gstreamer/3rd_party/build.sh +++ b/gstreamer/3rd_party/build.sh @@ -10,6 +10,6 @@ if [[ -n "$GST_PREFIX" ]]; then BUILD_OPTS="${BUILD_OPTS} --prefix ${GST_PREFIX} --libdir=${GST_PREFIX}/lib" fi echo $BUILD_OPTS -meson setup --wipe $BUILD_OPTS build +meson setup $BUILD_OPTS build #ninja -C build ninja -C build install From ad7b7cb150ab8e88af42ea03e4546df8663b766b Mon Sep 17 00:00:00 2001 From: Lucas Koelman Date: Fri, 7 May 2021 20:25:22 +0200 Subject: [PATCH 07/11] Clarify meson build file for 3rd party plugin --- gstreamer/3rd_party/gstreamer/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gstreamer/3rd_party/gstreamer/meson.build b/gstreamer/3rd_party/gstreamer/meson.build index eb6a34d..534e418 100644 --- a/gstreamer/3rd_party/gstreamer/meson.build +++ b/gstreamer/3rd_party/gstreamer/meson.build @@ -29,5 +29,5 @@ gst_objects_info_meta = library('gst_objects_info_meta', c_args: plugin_c_args, dependencies : [gst_dep], install : true, - install_dir : join_paths(get_option('libdir'), 'gstreamer-1.0'), + install_dir : plugins_install_dir, ) From 75ace71a1cb44d41e1bf693b5dd1a90a65119776 Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Fri, 4 Mar 2022 22:27:32 +0800 Subject: [PATCH 08/11] fix LIBPYTHONPATH for venvs Signed-off-by: hyx0329 --- build-gst-python.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build-gst-python.sh b/build-gst-python.sh index a1563df..a2718ce 100755 --- a/build-gst-python.sh +++ b/build-gst-python.sh @@ -3,12 +3,11 @@ # Run current script to override Gstreamer related Scripts LIBPYTHONPATH="" -PYTHON=${PYTHON:-/usr/bin/python3} +PYTHON=${PYTHON:-$(which python3)} GST_VERSION=${GST_VERSION:-$(gst-launch-1.0 --version | grep version | tr -s ' ' '\n' | tail -1 | $PYTHON -c "import sys; print('.'.join(next(sys.stdin).strip().split('.')[:2]))")} # Ensure pygst to be installed in current environment -LIBPYTHON=$($PYTHON -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LDLIBRARY"))') -LIBPYTHONPATH=$(dirname $(ldconfig -p | grep -w $LIBPYTHON | head -1 | tr ' ' '\n' | grep /)) +LIBPYTHONPATH=$($PYTHON -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LIBDIR"))') GST_PREFIX=${GST_PREFIX:-$(dirname $(dirname $(which python)))} From 0e715628fad4c60bfe71242b3c8733b757f26977 Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Sat, 5 Mar 2022 00:33:51 +0800 Subject: [PATCH 09/11] try to deal with the bug between meson and py3.8 Signed-off-by: hyx0329 --- build-3rd-party.sh | 3 +++ build-gst-python.sh | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/build-3rd-party.sh b/build-3rd-party.sh index 5ccf7ea..083a322 100755 --- a/build-3rd-party.sh +++ b/build-3rd-party.sh @@ -1,2 +1,5 @@ cd gstreamer/3rd_party + +export GST_PREFIX=${GST_PREFIX:-$(dirname $(dirname $(which python)))} + ./build.sh \ No newline at end of file diff --git a/build-gst-python.sh b/build-gst-python.sh index a2718ce..913fe7f 100755 --- a/build-gst-python.sh +++ b/build-gst-python.sh @@ -11,10 +11,15 @@ LIBPYTHONPATH=$($PYTHON -c 'from distutils import sysconfig; print(sysconfig.get GST_PREFIX=${GST_PREFIX:-$(dirname $(dirname $(which python)))} +MESON_VERSION=$(meson --version) +PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version.split()[0])') + echo "Python Executable: $PYTHON" +echo "Python Version: $PYTHON_VERSION" echo "Python Library Path: $LIBPYTHONPATH" echo "Current Python Path $GST_PREFIX" echo "Gstreamer Version: $GST_VERSION" +echo "Meson Version: $MESON_VERSION" TEMP_DIR="temp" mkdir $TEMP_DIR @@ -27,6 +32,14 @@ cd gst-python export PYTHON=$PYTHON git checkout $GST_VERSION +# py >= 3.8 && meson >= 0.53, apply patch +TEST_PYVER=$($PYTHON -c "from packaging.version import parse; ans = 1 if parse('$PYTHON_VERSION') >= parse('3.8.0') else 0; print(ans)") +TEST_MESONVER=$($PYTHON -c "from packaging.version import parse; ans = 1 if parse('$MESON_VERSION') >= parse('0.53.0') else 0; print(ans)") +if [ 1 -eq $TEST_PYVER -a 1 -eq $TEST_MESONVER ] ; then + sed -i 's|python.dependency(required : true)|python.dependency(embed:true, required : true)|g' meson.build + sed -i "s|meson_version : '.*',|meson_version : '>= 0.53.0',|g" meson.build +fi + #./autogen.sh --disable-gtk-doc --noconfigure #./configure --with-libpython-dir=$LIBPYTHONPATH --prefix $GST_PREFIX #make From 15952013c7de74982f962300a805938d872ae6d1 Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Sat, 5 Mar 2022 09:07:31 +0800 Subject: [PATCH 10/11] update readme Signed-off-by: hyx0329 --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 7fef0fd..6d4eb9e 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,21 @@ - easy [gst-python](https://github.com/GStreamer/gst-python) installation ### Install + +__FOR ANY VIRTUAL ENVIRONMENT USERS, MAKE SURE YOU COMPILED PYTHON WITH +`--enable-shared`(ESPECTIALLY FOR PYENV USERS) OR GST-PYTHON WON'T BE PROPERLY +INSTALLED.__ + #### Install OS packages - [How to install Gstreamer on Ubuntu](http://lifestyletransfer.com/how-to-install-gstreamer-on-ubuntu/) - [How to install Gstreamer Python Bindings](http://lifestyletransfer.com/how-to-install-gstreamer-python-bindings/) #### in-place + +You need to install meson and ninja first. Usually just search meson and +install it using your package manager and ninja will be automatically +installed. + ```bash python3 -m venv venv @@ -23,6 +33,15 @@ pip install --upgrade --requirement requirements.txt ``` #### pip-package + +You need to install meson and ninja first. Usually just search meson and +install it using your package manager and ninja will be automatically +installed. + +Note this package will not raise an exception for any error that happends. In +the case of any error occurs, you might have a broken installation(e.g. +gst-python not properly installed). + ```bash pip install git+https://github.com/jackersson/gstreamer-python.git@{tag_name}#egg=gstreamer-python From de5cee55ca9a80103d799f14d5a8c957deaf05b2 Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Sat, 5 Mar 2022 13:32:56 +0800 Subject: [PATCH 11/11] add extra version check Signed-off-by: hyx0329 --- build-gst-python.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build-gst-python.sh b/build-gst-python.sh index 913fe7f..a7b24c5 100755 --- a/build-gst-python.sh +++ b/build-gst-python.sh @@ -32,10 +32,11 @@ cd gst-python export PYTHON=$PYTHON git checkout $GST_VERSION -# py >= 3.8 && meson >= 0.53, apply patch +# py >= 3.8 && meson >= 0.53 && gstreamer < 1.19, apply patch TEST_PYVER=$($PYTHON -c "from packaging.version import parse; ans = 1 if parse('$PYTHON_VERSION') >= parse('3.8.0') else 0; print(ans)") TEST_MESONVER=$($PYTHON -c "from packaging.version import parse; ans = 1 if parse('$MESON_VERSION') >= parse('0.53.0') else 0; print(ans)") -if [ 1 -eq $TEST_PYVER -a 1 -eq $TEST_MESONVER ] ; then +TEST_GSTVER=$($PYTHON -c "from packaging.version import parse; ans = 1 if parse('$GST_VERSION') < parse('1.19') else 0; print(ans)") +if [ 1 -eq $TEST_PYVER -a 1 -eq $TEST_MESONVER -a 1 -eq $TEST_GSTVER ] ; then sed -i 's|python.dependency(required : true)|python.dependency(embed:true, required : true)|g' meson.build sed -i "s|meson_version : '.*',|meson_version : '>= 0.53.0',|g" meson.build fi