Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let command line util peaq load the plugin statically #29

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ GST_API_VERSION=1.0
gstreamer_1_0_packages="gstreamer-1.0 gstreamer-base-1.0 gstreamer-fft-1.0"
PKG_CHECK_MODULES(PKGCONF, [$gstreamer_1_0_packages])
AC_SUBST(GST_API_VERSION)
PKG_CHECK_MODULES(PKGCONF_BIN, [gstreamer-$GST_API_VERSION])

GST_SET_PLUGINDIR

Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ libgstpeaq_la_SOURCES = gstpeaq.c gstpeaqplugin.c earmodel.c \
libgstpeaq_la_CFLAGS = @PKGCONF_CFLAGS@
libgstpeaq_la_LIBADD = @PKGCONF_LIBS@
libgstpeaq_la_LDFLAGS = -module
peaq_SOURCES = peaq.c
peaq_SOURCES = peaq.c gstpeaq.c gstpeaqplugin.c earmodel.c \
leveladapter.c modpatt.c fftearmodel.c fbearmodel.c movaccum.c movs.c nn.c
peaq_CFLAGS = @PKGCONF_CFLAGS@
peaq_LDADD = @PKGCONF_BIN_LIBS@
peaq_LDADD = @PKGCONF_LIBS@
testpeaq_SOURCES = testpeaq.c earmodel.c leveladapter.c modpatt.c \
fftearmodel.c fbearmodel.c movaccum.c
testpeaq_CFLAGS = @PKGCONF_CFLAGS@
Expand Down
13 changes: 12 additions & 1 deletion src/peaq.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <glib/gprintf.h>
#include <stdlib.h>

#include <gst/gstplugin.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down Expand Up @@ -81,6 +83,8 @@ static void on_pad_added(GstElement *element, GstPad *pad, gpointer data) {
gst_object_unref(sinkpad);
}

GST_PLUGIN_STATIC_DECLARE(peaq);

int
main(int argc, char *argv[])
{
Expand Down Expand Up @@ -152,9 +156,16 @@ main(int argc, char *argv[])

peaq = gst_element_factory_make ("peaq", "peaq");
if (!peaq) {
puts ("Error: peaq element could not be instantiated - is the plugin installed correctly?");
puts ("Warning: peaq plugin is not installed - registering statically");
GST_PLUGIN_STATIC_REGISTER(peaq);
}

peaq = gst_element_factory_make ("peaq", "peaq");
if (!peaq) {
puts ("Error: peaq element could not be instantiated");
Comment on lines 157 to +165
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe unconditionally doing GST_PLUGIN_STATIC_REGISTER(peaq) is better? The only benefit of first trying to load the plugin dynamically seems to be that one could swap out the plugin for another version/implementation without modifying the executable. But that seem rather niche. OTOH, one could fall in the trap of updating the executable but not realizing that an outdated plugin is lingering somewhere. Opinion on that, @mincequi?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @martinholters,
well it depends, if you plan to re-use your plugin system-wide. But my assumption is: the gstreamer element is only supposed to be used within that tool and therefore no system-wide installation is needed.
In general i prefer statically linked stuff nowadays for easier library handling (installing shared libraries by bypassing the package manager is a mess).
Just my two cents ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, either way, installation of the plugin (in a suitable location) would be optional. Actually, building it would be optional. And that's good, because I agree that most users won't deal with the plugin directly, but just use the executable. But if the plugin is built and installed, should it then be used by the executable, although it is statically linked anyway? I see no benefit in that. Or is there any problem if the executable invokes GST_PLUGIN_STATIC_REGISTER although the plugin is available dynamically? I'll try and see if anything can be made to break with an unconditional GST_PLUGIN_STATIC_REGISTER...

Maybe a compile-time setting would be nice:

  • Option 1: Basically the status quo before this PR. Plugin and (slim) executable are built, plugin needs to be installed for executable to work.
  • Option 2: No separate plugin is built, instead it is linked statically to and registered by the executable. No installation required.

But that might just not be worth it. Will need to ponder this a bit...

exit (2);
}

gst_object_ref_sink (peaq);
g_object_set (G_OBJECT (peaq), "advanced", advanced,
"console_output", FALSE, NULL);
Expand Down
4 changes: 2 additions & 2 deletions src/runtest-1.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ if [ x$ODG != x-2.007 ]; then
exit 1
fi

ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 --gst-plugin-load=.libs/libgstpeaq.so \
ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 \
${srcdir}/../test/stimulus_ref.flac ${srcdir}/../test/stimulus_test.wav \
| grep "Objective Difference Grade:" | cut -d " " -f4`
echo $ODG
if [ x$ODG != x-1.077 ]; then
exit 1
fi
ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 --gst-plugin-load=.libs/libgstpeaq.so \
ODG=`LC_ALL=C ./peaq --gst-disable-segtrap --gst-debug-level=2 \
${srcdir}/../test/stimulus_test.wav ${srcdir}/../test/stimulus_ref.flac \
| grep "Objective Difference Grade:" | cut -d " " -f4`
echo $ODG
Expand Down
22 changes: 22 additions & 0 deletions vs/peaq.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,29 @@
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-fft-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="gstpeaq.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-fft-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="gstpeaq.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-fft-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="gstpeaq.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-fft-1.0.props" Condition="exists('$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-base-1.0.props')" />
<Import Project="gstpeaq.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
Expand Down Expand Up @@ -95,6 +103,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_USE_MATH_DEFINES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -108,6 +117,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_USE_MATH_DEFINES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -123,6 +133,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_USE_MATH_DEFINES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -140,6 +151,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_USE_MATH_DEFINES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -150,6 +162,16 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\earmodel.c" />
<ClCompile Include="..\src\fbearmodel.c" />
<ClCompile Include="..\src\fftearmodel.c" />
<ClCompile Include="..\src\gstpeaq.c" />
<ClCompile Include="..\src\gstpeaqplugin.c" />
<ClCompile Include="..\src\leveladapter.c" />
<ClCompile Include="..\src\modpatt.c" />
<ClCompile Include="..\src\movaccum.c" />
<ClCompile Include="..\src\movs.c" />
<ClCompile Include="..\src\nn.c" />
<ClCompile Include="..\src\peaq.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions vs/runtest-win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ if ($ODG -ne -2.007) {
}

$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\win32\Release\gstpeaq.dll " + `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe " + `
"$PSScriptRoot\..\test\stimulus_ref.flac $PSScriptRoot\..\test\stimulus_test.wav") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -1.077) {
throw "$ODG -ne -1.077"
}
$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\win32\Release\gstpeaq.dll " + `
Invoke-Expression ("$PSScriptRoot\win32\Release\peaq.exe " + `
"$PSScriptRoot\..\test\stimulus_test.wav $PSScriptRoot\..\test\stimulus_ref.flac ") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -3.096) {
Expand Down
4 changes: 2 additions & 2 deletions vs/runtest-x64.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ if ($ODG -ne -2.007) {
}

$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\x64\Release\gstpeaq.dll " + `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe " + `
"$PSScriptRoot\..\test\stimulus_ref.flac $PSScriptRoot\..\test\stimulus_test.wav") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -1.077) {
throw "$ODG -ne -1.077"
}
$ODG = [convert]::ToDouble(( `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe --gst-plugin-load=$PSScriptRoot\x64\Release\gstpeaq.dll " + `
Invoke-Expression ("$PSScriptRoot\x64\Release\peaq.exe " + `
"$PSScriptRoot\..\test\stimulus_test.wav $PSScriptRoot\..\test\stimulus_ref.flac ") `
| Select-String -Pattern 'Objective Difference Grade: (.*)').Matches.Groups[1].Value)
if ($ODG -ne -3.096) {
Expand Down