445 lines
16 KiB
Bash
445 lines
16 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# gst-plugin-venc-jpeg build script for AMLbian
|
|
# This script builds gst-plugin-venc-jpeg 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}"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Section 2: Default Configuration
|
|
# ==============================================================================
|
|
|
|
BOARD="${BOARD:-s6-bq201}"
|
|
DEB_VERSION="${GST_PLUGIN_VENC_JPEG_VERSION:-1.0}"
|
|
#ARCH="${ARCH:-arm64}"
|
|
: "${ARCH:=arm64}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: gst-plugin-venc-jpeg Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_gst_plugin_venc_jpeg_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_venc_jpeg_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
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/multimedia/gst-plugin-venc/jpeg"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Copying source from ${source_dir} to ${build_dir}" "info"
|
|
|
|
# 清空构建目录
|
|
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}/jpeg/Makefile" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Makefile not found in source" "warning"
|
|
fi
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __gst_plugin_venc_jpeg_build {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Starting gst-plugin-venc-jpeg build..." "info"
|
|
|
|
# 检查源目录
|
|
local src_dir="${build_dir}/jpeg"
|
|
if [[ ! -d "${src_dir}" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Source directory not found: ${src_dir}" "err"
|
|
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}"
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Using ROOTFS_TEMP as sysroot: ${SYSROOT}" "info"
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "ROOTFS_TEMP not found or invalid: ${ROOTFS_TEMP}" "err"
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "ROOTFS_TEMP should be created by create_base_rootfs function" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Use sysroot configuration
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Using sysroot: ${SYSROOT}" "info"
|
|
|
|
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/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
|
|
unset PKG_CONFIG_PATH
|
|
|
|
# -------------------------------------------------------------------
|
|
# compiler flags
|
|
# -------------------------------------------------------------------
|
|
|
|
export CPPFLAGS="${CPPFLAGS} --sysroot=${SYSROOT}"
|
|
|
|
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
|
|
export CXXFLAGS="${CXXFLAGS} --sysroot=${SYSROOT} -fPIC"
|
|
|
|
export LDFLAGS="${LDFLAGS} --sysroot=${SYSROOT}"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib/aarch64-linux-gnu"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/aarch64-linux-gnu/lib"
|
|
|
|
# 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/libdrm"
|
|
|
|
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}" || {
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Cannot enter source directory: ${src_dir}" "err"
|
|
return 1
|
|
}
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Testing pkg-config to get GStreamer libraries..." "info"
|
|
|
|
# Extract just the library flags
|
|
local gst_libs
|
|
gst_libs=$(PKG_CONFIG="${PKG_CONFIG}" PKG_CONFIG_SYSROOT_DIR="${SYSROOT}" PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig" ${PKG_CONFIG} --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-allocators-1.0 gstreamer-video-1.0 2>/dev/null)
|
|
|
|
if [[ -n "${gst_libs}" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "GStreamer libraries found: ${gst_libs}" "info"
|
|
export LDFLAGS="${LDFLAGS} ${gst_libs}"
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Updated LDFLAGS: ${LDFLAGS}" "info"
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "pkg-config returned empty result for GStreamer libraries!" "error"
|
|
fi
|
|
|
|
# 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 build state
|
|
rm -rf config.cache config.status autom4te.cache
|
|
|
|
# 3. regenerate configure if needed (if using autotools)
|
|
# For now, assume Makefile exists
|
|
|
|
# 4. configure (if using configure script)
|
|
# Skip if no configure script
|
|
|
|
# 5. build
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Building..." "info"
|
|
|
|
local extra_oemake="CROSS=${CROSS_COMPILE} STAGING_DIR=${install_dir} DESTDIR=${install_dir} OUT_DIR=${src_dir} PKG_CONFIG=${PKG_CONFIG}"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib/aarch64-linux-gnu -ljpegenc_api -lge2d -lion -lgstdrmbufferpool -lgstdrmallocator"
|
|
export LDFLAGS="${LDFLAGS} -Wl,--no-as-needed"
|
|
|
|
make -j$(nproc) ${extra_oemake} \
|
|
CC="${CROSS_COMPILE}gcc" \
|
|
CFLAGS="${CFLAGS}" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
PKG_CONFIG="${PKG_CONFIG}" \
|
|
PKG_CONFIG_SYSROOT_DIR="${SYSROOT}" \
|
|
PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${SYSROOT}/usr/share/pkgconfig" \
|
|
2>&1 | tee make.log || {
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "make failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# 6. install - directly copy the plugin file instead of using make install
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Installing plugin directly..." "info"
|
|
|
|
# Debian arm64 uses /usr/lib/aarch64-linux-gnu/ for architecture-specific libs
|
|
mkdir -p ${install_dir}/usr/lib/aarch64-linux-gnu/gstreamer-1.0
|
|
mkdir -p ${install_dir}/usr/include
|
|
mkdir -p ${install_dir}/usr/lib/pkgconfig
|
|
|
|
# Copy the plugin file directly
|
|
local src_plugin="${src_dir}/libgstamljpegenc.so"
|
|
if [[ -f "${src_plugin}" ]]; then
|
|
# Copy to Debian-standard path
|
|
local dst_plugin="${install_dir}/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstamljpegenc.so"
|
|
mkdir -p "${install_dir}/usr/lib/aarch64-linux-gnu/gstreamer-1.0"
|
|
cp "${src_plugin}" "${dst_plugin}"
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Copied plugin to Debian path: ${dst_plugin}" "info"
|
|
|
|
# Also copy any header files if they exist
|
|
if [[ -d "${src_dir}/include" ]]; then
|
|
cp -r "${src_dir}/include/"* "${install_dir}/usr/include/" 2>/dev/null || true
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Copied header files" "info"
|
|
fi
|
|
|
|
# Copy any .pc files if they exist (pkgconfig files are optional)
|
|
local pc_files=$(find "${src_dir}" -name "*.pc" -type f 2>/dev/null || true)
|
|
if [[ -n "${pc_files}" ]]; then
|
|
for pc_file in ${pc_files}; do
|
|
cp "${pc_file}" "${install_dir}/usr/lib/pkgconfig/" 2>/dev/null || true
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Copied pkgconfig file: $(basename "${pc_file}")" "info"
|
|
done
|
|
fi
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Plugin not found: ${src_plugin}" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __gst_plugin_venc_jpeg_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Installing gst-plugin-venc-jpeg library..." "info"
|
|
|
|
# 安装目录已经在构建过程中创建了,这里只需验证
|
|
local src_dir="${build_dir}/jpeg"
|
|
|
|
if [[ ! -d "${install_dir}" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Install directory not found: ${install_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 验证安装的文件
|
|
local lib_dir="${install_dir}/usr/lib/aarch64-linux-gnu/gstreamer-1.0"
|
|
local plugin_file="${lib_dir}/libgstamljpegenc.so"
|
|
|
|
if [[ -f "${plugin_file}" ]]; then
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Plugin file installed successfully: ${plugin_file}" "info"
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "No plugin file found in install directory" "warning"
|
|
fi
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Installation completed" "success"
|
|
return 0
|
|
}
|
|
|
|
function __gst_plugin_venc_jpeg_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# 设置必要的变量
|
|
local pkg_name="gst-plugin-venc-jpeg"
|
|
local version="${DEB_VERSION}"
|
|
local architecture="${ARCH}"
|
|
local maintainer="Armbian Build <[email protected]>"
|
|
local description="Amlogic JPEG hardware encode plugin for GStreamer"
|
|
local description_long="This package provides Amlogic-specific JPEG video encoder plugin for GStreamer. This plugin enables GStreamer to use Amlogic's hardware JPEG encoder for efficient multimedia processing."
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Creating Debian package for ${pkg_name} ${version}..." "info"
|
|
|
|
# 创建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
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "No installed files found in ${install_dir}" "warn"
|
|
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), gstreamer1.0-plugins-good (>= 1.0.0), gstreamer1.0-plugins-bad (>= 1.0.0), gstreamer1.0-libav (>= 1.0.0), libamljpegenc, libge2d, libion
|
|
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-venc-jpeg 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-venc-jpeg"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Building Debian package..." "info"
|
|
|
|
# 构建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-VENC-JPEG" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "GST-PLUGIN-VENC-JPEG" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_gst_plugin_venc_jpeg {
|
|
if ! is_unit_enabled "gst-plugin-venc-jpeg" && ! is_unit_enabled "gst-aml"; then
|
|
display_alert "[SKIP] >> gst-plugin-venc-jpeg disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$MEDIA_FEATURES" "gst-plugin-venc-jpeg"; then
|
|
display_alert "[SKIP] >> gst-plugin-venc-jpeg disable in MEDIA_FEATURES" "" "info"
|
|
return
|
|
fi
|
|
display_alert "AMLOGIC: Building gst-plugin-venc-jpeg ${DEB_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/gst-plugin-venc-jpeg-build-${ARCH:-arm64}"
|
|
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}"
|
|
|
|
display_alert "AMLOGIC: build_dir ${build_dir}" "info"
|
|
display_alert "AMLOGIC: install_dir ${install_dir}" "info"
|
|
display_alert "AMLOGIC: output_dir ${BUILD_DIR}/output" "info"
|
|
|
|
# 准备源代码
|
|
__gst_plugin_venc_jpeg_prepare_source "${build_dir}"
|
|
|
|
# 构建
|
|
if ! __gst_plugin_venc_jpeg_build "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: gst-plugin-venc-jpeg build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __gst_plugin_venc_jpeg_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: gst-plugin-venc-jpeg installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__gst_plugin_venc_jpeg_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_gst_plugin_venc_jpeg_config
|
|
|
|
#chmod -R 777 "${build_root}"
|
|
rm -rf "${build_root}"
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLbian gst-plugin-venc-jpeg Build Script" "Version: ${DEB_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_gst_plugin_venc_jpeg
|
|
|
|
display_alert "AMLOGIC: gst-plugin-venc-jpeg build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-gst-plugin-venc-jpeg.sh
|
|
# ============================================================================== |