2026-08-13 11:28:40 +08:00
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2026 AMLOGIC
#
# gst-plugin-conv build script for AMLbian
# This script builds gst-plugin-conv library for Amlogic SoCs
set -e
umask 022
# Get script directory
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
AMLBIAN_DIR = " $( dirname " ${ SCRIPT_DIR } " ) " # amlbian/scripts/multimedia
AMLBIAN_DIR = " $( dirname " ${ AMLBIAN_DIR } " ) " # amlbian/scripts
AMLBIAN_DIR = " $( dirname " ${ AMLBIAN_DIR } " ) " # amlbian
BUILD_DIR = " ${ SRC } "
2026-11-11 08:50:43 +08:00
MODULE_BUILD_DIR = " ${ SRC } /output/.tmp"
2026-08-13 11:28:40 +08:00
# ==============================================================================
# Section 2: Default Configuration
# ==============================================================================
BOARD = " ${ BOARD :- s6 -bq201 } "
DEB_VERSION = " ${ GST_PLUGIN_CONV_VERSION :- 1 .0 } "
#ARCH="${ARCH:-arm64}"
: " ${ ARCH :=arm64 } "
# ==============================================================================
# Section 4: gst-plugin-conv Build Functions
# ==============================================================================
function __unset_gst_plugin_conv_config {
# Clean up any environment variables set during build
unset EXTRA_OEMAKE
unset SYSROOT
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
unset CPPFLAGS
}
function __gst_plugin_conv_prepare_source {
local build_dir = " ${ 1 } "
local aml_comp_path = " $( amlbian_get_aml_comp_dir) "
if [[ -z " ${ aml_comp_path } " ]] || [[ ! -d " ${ aml_comp_path } " ]] ; then
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "aml-comp not found: ${ aml_comp_path } "
2026-08-13 11:28:40 +08:00
exit 1
fi
local source_dir = " ${ aml_comp_path } /multimedia/gst-aml-utils/gst-plugin-conv"
if [[ ! -d " ${ source_dir } " ]] ; then
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "Source directory not found: ${ source_dir } "
2026-08-13 11:28:40 +08:00
exit 1
fi
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Copying source from ${ source_dir } to ${ build_dir } "
2026-08-13 11:28:40 +08:00
# 清空构建目录
rm -rf " ${ build_dir } "
mkdir -p " ${ build_dir } "
# 复制源代码到构建目录
cp -r " ${ source_dir } " " ${ build_dir } /" 2>/dev/null || true
# Check for necessary source files
if [[ ! -f " ${ build_dir } /gst-plugin-conv/configure.ac" ]] && [[ ! -f " ${ build_dir } /gst-plugin-conv/configure" ]] ; then
2026-11-11 08:50:43 +08:00
aml_log warn "GST-PLUGIN-CONV" "Configure script not found in source"
2026-08-13 11:28:40 +08:00
fi
display_alert "GST-PLUGIN-CONV" "Source prepared successfully" "success"
}
function __gst_plugin_conv_build {
local build_dir = " ${ 1 } "
local install_dir = " ${ 2 } "
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Starting gst-plugin-conv build..."
2026-08-13 11:28:40 +08:00
# 检查源目录
local src_dir = " ${ build_dir } /gst-plugin-conv"
if [[ ! -d " ${ src_dir } " ]] ; then
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "Source directory not found: ${ src_dir } "
2026-08-13 11:28:40 +08:00
return 1
fi
# 设置编译环境
#ARCH="${ARCH:-arm64}"
: " ${ ARCH :=arm64 } "
CROSS_COMPILE = " ${ CROSS_COMPILE :- aarch64 -linux-gnu- } "
export ARCH
export CROSS_COMPILE = " ${ CROSS_COMPILE } "
# amlbian_checkout_toolchain
# Check if ROOTFS_TEMP exists, use it as sysroot, otherwise error
local SYSROOT = ""
if [[ -n " ${ ROOTFS_TEMP } " ]] && [[ -d " ${ ROOTFS_TEMP } " ]] && [[ -d " ${ ROOTFS_TEMP } /usr/lib/aarch64-linux-gnu" ]] ; then
SYSROOT = " ${ ROOTFS_TEMP } "
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Using ROOTFS_TEMP as sysroot: ${ SYSROOT } "
2026-08-13 11:28:40 +08:00
else
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "ROOTFS_TEMP not found or invalid: ${ ROOTFS_TEMP } "
aml_log error "GST-PLUGIN-CONV" "ROOTFS_TEMP should be created by create_base_rootfs function"
2026-08-13 11:28:40 +08:00
return 1
fi
# Use sysroot configuration
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Using sysroot: ${ SYSROOT } "
2026-08-13 11:28:40 +08:00
export PKG_CONFIG = /usr/bin/pkg-config
export PKG_CONFIG_SYSROOT_DIR = " ${ SYSROOT } "
export PKG_CONFIG_LIBDIR = " ${ SYSROOT } /usr/lib/aarch64-linux-gnu/pkgconfig: ${ SYSROOT } /usr/share/pkgconfig"
unset PKG_CONFIG_PATH
# Set up flags with sysroot
export CPPFLAGS = " ${ CPPFLAGS } --sysroot= ${ SYSROOT } "
export CFLAGS = " ${ CFLAGS } --sysroot= ${ SYSROOT } -fPIC"
export CXXFLAGS = " ${ CXXFLAGS } --sysroot= ${ SYSROOT } -fPIC"
export LDFLAGS = " ${ LDFLAGS } --sysroot= ${ SYSROOT } "
# Add sysroot-specific include paths
local include_flags = "-I ${ SYSROOT } /usr/include/aarch64-linux-gnu \
-I ${ SYSROOT } /usr/include/gstreamer-1.0 \
-I ${ SYSROOT } /usr/include/glib-2.0 \
-I ${ SYSROOT } /usr/lib/aarch64-linux-gnu/glib-2.0/include \
-I ${ SYSROOT } /usr/include/libge2d \
-I ${ SYSROOT } /usr/include/libdrm \
-I ${ src_dir } /inc"
export CPPFLAGS = " ${ CPPFLAGS } ${ include_flags } "
export CFLAGS = " ${ CFLAGS } ${ include_flags } "
export CXXFLAGS = " ${ CXXFLAGS } ${ include_flags } "
# Add sysroot-specific library paths
export LDFLAGS = " ${ LDFLAGS } -L ${ SYSROOT } /usr/lib/aarch64-linux-gnu -L ${ SYSROOT } /usr/aarch64-linux-gnu/lib"
# 进入源代码目录
cd " ${ src_dir } " || {
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "Cannot enter source directory: ${ src_dir } "
2026-08-13 11:28:40 +08:00
return 1
}
# 1. version config (non-fatal)
if [[ -f "version_config.sh" ]] ; then
chmod +x version_config.sh
./version_config.sh " ${ src_dir } " 2>& 1 | tee version.log || true
fi
# 2. clean autotools state
rm -rf config.cache config.status autom4te.cache
# 3. regenerate configure if needed
if [[ ! -f "./configure" ]] ; then
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Regenerating configure script..."
2026-08-13 11:28:40 +08:00
autoreconf -fi 2>& 1 | tee autoreconf.log || {
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "autoreconf failed"
2026-08-13 11:28:40 +08:00
return 1
}
fi
# 4. configure
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Configuring build..."
2026-08-13 11:28:40 +08:00
./configure \
--prefix= /usr \
--libdir= /usr/lib/aarch64-linux-gnu \
--host= aarch64-linux-gnu \
--build= x86_64-linux-gnu \
CC = " ${ CROSS_COMPILE } gcc" \
CFLAGS = " ${ CFLAGS } " \
LDFLAGS = " ${ LDFLAGS } " \
2>& 1 | tee config.log || {
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "configure failed"
2026-08-13 11:28:40 +08:00
return 1
}
# 5. build
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Building..."
2026-08-13 11:28:40 +08:00
local extra_oemake = "CROSS= ${ CROSS_COMPILE } STAGING_DIR= ${ install_dir } DESTDIR= ${ install_dir } "
make -j$( nproc) ${ extra_oemake } \
LDFLAGS = " ${ LDFLAGS } " \
2>& 1 | tee make.log || {
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "make failed"
2026-08-13 11:28:40 +08:00
return 1
}
# 6. install
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Installing..."
2026-08-13 11:28:40 +08:00
make DESTDIR = ${ install_dir } install 2>& 1 | tee install.log || {
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "install failed"
2026-08-13 11:28:40 +08:00
return 1
}
display_alert "GST-PLUGIN-CONV" "Build completed successfully" "success"
return 0
}
function __gst_plugin_conv_install {
local build_dir = " ${ 1 } "
local install_dir = " ${ 2 } "
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Installing gst-plugin-conv library..."
2026-08-13 11:28:40 +08:00
# 安装目录已经在构建过程中创建了,这里只需验证
local src_dir = " ${ build_dir } /gst-plugin-conv"
if [[ ! -d " ${ install_dir } " ]] ; then
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "Install directory not found: ${ install_dir } "
2026-08-13 11:28:40 +08:00
return 1
fi
# 验证安装的文件
local lib_dir = " ${ install_dir } /usr/lib/aarch64-linux-gnu/gstreamer-1.0"
if [[ -f " ${ lib_dir } /libgstamlvconv.so" ]] ; then
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Library file installed successfully"
2026-08-13 11:28:40 +08:00
else
2026-11-11 08:50:43 +08:00
aml_log warn "GST-PLUGIN-CONV" "No library file found in install directory"
2026-08-13 11:28:40 +08:00
fi
display_alert "GST-PLUGIN-CONV" "Installation completed" "success"
return 0
}
function __gst_plugin_conv_create_deb {
local build_dir = " ${ 1 } "
local install_dir = " ${ 2 } "
# 设置必要的变量
local pkg_name = "gst-plugin-conv"
local version = " ${ DEB_VERSION } "
local architecture = " ${ ARCH } "
local maintainer = "Armbian Build <build@armbian.com>"
local description = "Amlogic video conversion GStreamer plugin with GE2D HW"
local description_long = "This package provides Amlogic-specific video conversion plugin for GStreamer. This plugin enables GStreamer to use Amlogic's GE2D hardware-accelerated video conversion operations for multimedia processing. It depends on gst-aml-dma-allocator, gst-aml-gfx2d, and gst-aml-drmbufferpool-plugins."
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Creating Debian package for ${ pkg_name } ${ version } ..."
2026-08-13 11:28:40 +08:00
# 创建Debian包控制文件
local deb_dir = " ${ build_dir } /deb/ ${ pkg_name } - ${ version } "
local debian_dir = " ${ deb_dir } /DEBIAN"
mkdir -p " ${ debian_dir } "
# 将安装目录的内容复制到debian-root
if [[ -d " ${ install_dir } " ]] && [[ " $( ls -A " ${ install_dir } " ) " ]] ; then
cp -r " ${ install_dir } " /* " ${ deb_dir } /" 2>/dev/null || true
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Copied installed files to ${ deb_dir } "
2026-08-13 11:28:40 +08:00
else
2026-11-11 08:50:43 +08:00
aml_log warn "GST-PLUGIN-CONV" "No installed files found in ${ install_dir } "
2026-08-13 11:28:40 +08:00
return 0
fi
# 创建control文件
cat > " ${ debian_dir } /control" <<EOF
Package: ${pkg_name}
Version: ${version}
Architecture: ${architecture}
Maintainer: ${maintainer}
Description: ${description}
${description_long}
Depends: libgstreamer1.0-0 (>= 1.0.0), gstreamer1.0-plugins-base (>= 1.0.0), libge2d, libdrm2 (>= 2.4.0), gst-aml-dma-allocator, gst-aml-gfx2d, gst-aml-drmbufferpool-plugins
Section: libs
Priority: optional
EOF
# 创建postinst脚本,用于更新ldconfig和GStreamer插件缓存
cat > " ${ debian_dir } /postinst" <<EOF
#!/bin/sh
set -e
if [ "\$1" = "configure" ]; then
# 更新ldconfig缓存
if command -v ldconfig >/dev/null 2>&1; then
ldconfig
fi
# 更新GStreamer插件缓存
if command -v gst-inspect-1.0 >/dev/null 2>&1; then
gst-inspect-1.0 --gst-info >/dev/null 2>&1 || true
fi
echo "gst-plugin-conv installed successfully"
fi
exit 0
EOF
chmod 755 " ${ debian_dir } /postinst"
# 创建prerm脚本
cat > " ${ debian_dir } /prerm" <<EOF
#!/bin/sh
set -e
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
# Update ldconfig
if command -v ldconfig >/dev/null 2>&1; then
ldconfig
fi
echo "Removing gst-plugin-conv"
fi
exit 0
EOF
chmod 755 " ${ debian_dir } /prerm"
2026-11-11 08:50:43 +08:00
aml_log info "GST-PLUGIN-CONV" "Building Debian package..."
2026-08-13 11:28:40 +08:00
# 构建Debian包
cd " ${ build_dir } /deb"
dpkg-deb --build " ${ pkg_name } - ${ version } "
local deb_file = " ${ pkg_name } - ${ version } .deb"
if [[ -f " ${ deb_file } " ]] ; then
local output_dir = " ${ BUILD_DIR } /output"
mkdir -p " ${ output_dir } "
mv " ${ deb_file } " " ${ output_dir } /linux- ${ pkg_name } - ${ BOARD } -amlbian_ ${ version } _ ${ architecture } .deb"
chmod 755 " ${ output_dir } /linux- ${ pkg_name } - ${ BOARD } -amlbian_ ${ version } _ ${ architecture } .deb"
display_alert "GST-PLUGIN-CONV" "Debian package created: ${ output_dir } /linux- ${ pkg_name } - ${ BOARD } -amlbian_ ${ version } _ ${ architecture } .deb" "success"
else
2026-11-11 08:50:43 +08:00
aml_log error "GST-PLUGIN-CONV" "Failed to build Debian package"
2026-08-13 11:28:40 +08:00
return 1
fi
return 0
}
function amlbian_build_gst_plugin_conv {
if ! is_unit_enabled "gst-plugin-conv" && ! is_unit_enabled "gst-aml" ; then
2026-11-11 08:50:43 +08:00
aml_log info "[SKIP] >> gst-plugin-conv disable in BUILD_UNITS"
2026-08-13 11:28:40 +08:00
return
fi
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Building gst-plugin-conv ${ DEB_VERSION } ${ BOARD } "
2026-08-13 11:28:40 +08:00
# Define all directory paths (in .tmp directory)
2026-11-11 08:50:43 +08:00
local build_root = " ${ MODULE_BUILD_DIR } /gst-plugin-conv-build- ${ ARCH :- arm64 } "
2026-08-13 11:28:40 +08:00
local build_dir = " ${ build_root } /build" # Build directory with source code
local install_dir = " ${ build_root } /install" # Install directory
rm -rf " ${ build_root } "
# 创建目录
mkdir -p " ${ build_dir } " " ${ install_dir } "
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: build_dir ${ build_dir } "
aml_log info "AMLOGIC: install_dir ${ install_dir } "
aml_log info "AMLOGIC: output_dir ${ BUILD_DIR } /output"
2026-08-13 11:28:40 +08:00
# 准备源代码
__gst_plugin_conv_prepare_source " ${ build_dir } "
# 构建
if ! __gst_plugin_conv_build " ${ build_dir } " " ${ install_dir } " ; then
2026-11-11 08:50:43 +08:00
aml_log error "AMLOGIC: gst-plugin-conv build failed"
2026-08-13 11:28:40 +08:00
return 1
fi
# 安装到安装目录
if ! __gst_plugin_conv_install " ${ build_dir } " " ${ install_dir } " ; then
2026-11-11 08:50:43 +08:00
aml_log error "AMLOGIC: gst-plugin-conv installation failed"
2026-08-13 11:28:40 +08:00
return 1
fi
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: Creating Debian package..."
2026-08-13 11:28:40 +08:00
__gst_plugin_conv_create_deb " ${ build_dir } " " ${ install_dir } "
__unset_gst_plugin_conv_config
#chmod -R 777 "${build_root}"
return 0
}
# ==============================================================================
# Section 5: Main
# ==============================================================================
2026-11-11 08:50:43 +08:00
aml_log info "AMLbian gst-plugin-conv Build Script" "Version: ${ DEB_VERSION } , Board: ${ BOARD } "
2026-08-13 11:28:40 +08:00
amlbian_build_gst_plugin_conv
2026-11-11 08:50:43 +08:00
aml_log info "AMLOGIC: gst-plugin-conv build completed" " ${ BUILD_DIR } /output"
2026-08-13 11:28:40 +08:00
# ==============================================================================
# End of build-gst-plugin-conv.sh
2026-11-11 08:50:43 +08:00
# ==============================================================================