From 2d93f2a120a24a93d0e6fe773a4c50b22a7be8bd Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Thu, 29 Jul 2021 15:09:41 -0400 Subject: media-libs/x265: add --- media-libs/x265/Manifest | 1 + media-libs/x265/files/arm-r1.patch | 42 ++++ media-libs/x265/files/neon.patch | 16 ++ media-libs/x265/files/test-ns.patch | 295 +++++++++++++++++++++++++++++ media-libs/x265/files/tests.patch | 16 ++ media-libs/x265/files/x265-3.3-ppc64.patch | 15 ++ media-libs/x265/metadata.xml | 10 + media-libs/x265/x265-3.5.ebuild | 214 +++++++++++++++++++++ media-libs/x265/x265-9999.ebuild | 214 +++++++++++++++++++++ 9 files changed, 823 insertions(+) create mode 100644 media-libs/x265/Manifest create mode 100644 media-libs/x265/files/arm-r1.patch create mode 100644 media-libs/x265/files/neon.patch create mode 100644 media-libs/x265/files/test-ns.patch create mode 100644 media-libs/x265/files/tests.patch create mode 100644 media-libs/x265/files/x265-3.3-ppc64.patch create mode 100644 media-libs/x265/metadata.xml create mode 100644 media-libs/x265/x265-3.5.ebuild create mode 100644 media-libs/x265/x265-9999.ebuild (limited to 'media-libs') diff --git a/media-libs/x265/Manifest b/media-libs/x265/Manifest new file mode 100644 index 0000000..c27eb27 --- /dev/null +++ b/media-libs/x265/Manifest @@ -0,0 +1 @@ +DIST x265_3.5.tar.gz 1537044 BLAKE2B 4fe15b762eda08a4379f69df622bef603fed784a237381d5c95876412020c113d053af829fa1eb66468462a6edc0de32dc597b1a98a63e9aa0250a47f4e76d05 SHA512 230e683239c3e262096ba96246c6f67229a1625d163f86647a411733bb1cf349685858aee3017bce818bb6992448d0abaa9241615a5b620561ce47ecb164f997 diff --git a/media-libs/x265/files/arm-r1.patch b/media-libs/x265/files/arm-r1.patch new file mode 100644 index 0000000..8a8102d --- /dev/null +++ b/media-libs/x265/files/arm-r1.patch @@ -0,0 +1,42 @@ +More aliases for ARM. +Do not force CFLAGS for ARM. + +Index: source/CMakeLists.txt +=================================================================== +--- source.orig/CMakeLists.txt ++++ source/CMakeLists.txt +@@ -40,7 +40,7 @@ SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_ + # System architecture detection + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSPROC) + set(X86_ALIASES x86 i386 i686 x86_64 amd64) +-set(ARM_ALIASES armv6l armv7l aarch64) ++set(ARM_ALIASES armv6l armv6l armv7l armv7a aarch64) + list(FIND X86_ALIASES "${SYSPROC}" X86MATCH) + list(FIND ARM_ALIASES "${SYSPROC}" ARMMATCH) + set(POWER_ALIASES ppc64 ppc64le) +@@ -239,11 +239,7 @@ if(GCC) + endif() + endif() + if(ARM AND CROSS_COMPILE_ARM) +- if(ARM64) +- set(ARM_ARGS -fPIC) +- else() +- set(ARM_ARGS -march=armv6 -mfloat-abi=soft -mfpu=vfp -marm -fPIC) +- endif() ++ set(ARM_ARGS -fPIC) + message(STATUS "cross compile arm") + elseif(ARM) + if(ARM64) +@@ -252,10 +248,10 @@ if(GCC) + else() + find_package(Neon) + if(CPU_HAS_NEON) +- set(ARM_ARGS -mcpu=native -mfloat-abi=hard -mfpu=neon -marm -fPIC) ++ set(ARM_ARGS -mfpu=neon -fPIC) + add_definitions(-DHAVE_NEON) + else() +- set(ARM_ARGS -mcpu=native -mfloat-abi=hard -mfpu=vfp -marm) ++ set(ARM_ARGS -fPIC) + endif() + endif() + endif() diff --git a/media-libs/x265/files/neon.patch b/media-libs/x265/files/neon.patch new file mode 100644 index 0000000..444c899 --- /dev/null +++ b/media-libs/x265/files/neon.patch @@ -0,0 +1,16 @@ +These functions are only built when enabling assembly on ARM; use proper check +to avoid undefined symbols. + +Index: source/common/primitives.cpp +=================================================================== +--- source.orig/common/primitives.cpp ++++ source/common/primitives.cpp +@@ -270,7 +270,7 @@ void PFX(cpu_emms)(void) {} + void PFX(cpu_cpuid)(uint32_t, uint32_t *eax, uint32_t *, uint32_t *, uint32_t *) { *eax = 0; } + void PFX(cpu_xgetbv)(uint32_t, uint32_t *, uint32_t *) {} + +-#if X265_ARCH_ARM == 0 ++#if X265_ARCH_ARM == 0 || !defined(ENABLE_ASSEMBLY) + void PFX(cpu_neon_test)(void) {} + int PFX(cpu_fast_neon_mrc_test)(void) { return 0; } + #endif // X265_ARCH_ARM diff --git a/media-libs/x265/files/test-ns.patch b/media-libs/x265/files/test-ns.patch new file mode 100644 index 0000000..898751a --- /dev/null +++ b/media-libs/x265/files/test-ns.patch @@ -0,0 +1,295 @@ +Namespace functions for multi-bitdepth builds so that libraries are self-contained. + +Index: source/common/param.h +=================================================================== +--- source.orig/common/param.h ++++ source/common/param.h +@@ -53,6 +53,18 @@ int x265_param_default_preset(x265_param + int x265_param_apply_profile(x265_param *, const char *profile); + int x265_param_parse(x265_param *p, const char *name, const char *value); + int x265_zone_param_parse(x265_param* p, const char* name, const char* value); ++void x265_free_analysis_data(x265_param *param, x265_analysis_data* analysis); ++void x265_alloc_analysis_data(x265_param *param, x265_analysis_data* analysis); ++void x265_picture_free(x265_picture *); ++x265_zone *x265_zone_alloc(int zoneCount, int isZoneFile); ++void x265_zone_free(x265_param *param); ++FILE* x265_csvlog_open(const x265_param *); ++void x265_csvlog_frame(const x265_param *, const x265_picture *); ++void x265_csvlog_encode(const x265_param*, const x265_stats *, int padx, int pady, int argc, char** argv); ++void x265_dither_image(x265_picture *, int picWidth, int picHeight, int16_t *errorBuf, int bitDepth); ++int x265_encoder_reconfig(x265_encoder *, x265_param *); ++x265_picture *x265_picture_alloc(void); ++void x265_picture_init(x265_param *param, x265_picture *pic); + #define PARAM_NS X265_NS + #endif + } +Index: source/encoder/api.cpp +=================================================================== +--- source.orig/encoder/api.cpp ++++ source/encoder/api.cpp +@@ -106,9 +106,9 @@ x265_encoder *x265_encoder_open(x265_par + if (p->rc.zoneCount || p->rc.zonefileCount) + { + int zoneCount = p->rc.zonefileCount ? p->rc.zonefileCount : p->rc.zoneCount; +- param->rc.zones = x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); +- latestParam->rc.zones = x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); +- zoneParam->rc.zones = x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); ++ param->rc.zones = PARAM_NS::x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); ++ latestParam->rc.zones = PARAM_NS::x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); ++ zoneParam->rc.zones = PARAM_NS::x265_zone_alloc(zoneCount, !!p->rc.zonefileCount); + } + + x265_copy_params(param, p); +@@ -216,7 +216,7 @@ x265_encoder *x265_encoder_open(x265_par + /* Try to open CSV file handle */ + if (encoder->m_param->csvfn) + { +- encoder->m_param->csvfpt = x265_csvlog_open(encoder->m_param); ++ encoder->m_param->csvfpt = PARAM_NS::x265_csvlog_open(encoder->m_param); + if (!encoder->m_param->csvfpt) + { + x265_log(encoder->m_param, X265_LOG_ERROR, "Unable to open CSV log file <%s>, aborting\n", encoder->m_param->csvfn); +@@ -321,7 +321,7 @@ int x265_encoder_reconfig(x265_encoder* + if (encoder->m_latestParam->rc.zoneCount || encoder->m_latestParam->rc.zonefileCount) + { + int zoneCount = encoder->m_latestParam->rc.zonefileCount ? encoder->m_latestParam->rc.zonefileCount : encoder->m_latestParam->rc.zoneCount; +- save.rc.zones = x265_zone_alloc(zoneCount, !!encoder->m_latestParam->rc.zonefileCount); ++ save.rc.zones = PARAM_NS::x265_zone_alloc(zoneCount, !!encoder->m_latestParam->rc.zonefileCount); + } + x265_copy_params(&save, encoder->m_latestParam); + int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in); +@@ -604,7 +604,7 @@ fail: + *pi_nal = 0; + + if (numEncoded && encoder->m_param->csvLogLevel && encoder->m_outputCount >= encoder->m_latestParam->chunkStart) +- x265_csvlog_frame(encoder->m_param, pic_out); ++ PARAM_NS::x265_csvlog_frame(encoder->m_param, pic_out); + + if (numEncoded < 0) + encoder->m_aborted = true; +@@ -637,7 +637,7 @@ void x265_vmaf_encoder_log(x265_encoder* + encoder->fetchStats(&stats, sizeof(stats)); + int padx = encoder->m_sps.conformanceWindow.rightOffset; + int pady = encoder->m_sps.conformanceWindow.bottomOffset; +- x265_csvlog_encode(encoder->m_param, &stats, padx, pady, argc, argv); ++ PARAM_NS::x265_csvlog_encode(encoder->m_param, &stats, padx, pady, argc, argv); + } + } + #endif +@@ -651,7 +651,7 @@ void x265_encoder_log(x265_encoder* enc, + encoder->fetchStats(&stats, sizeof(stats)); + int padx = encoder->m_sps.conformanceWindow.rightOffset; + int pady = encoder->m_sps.conformanceWindow.bottomOffset; +- x265_csvlog_encode(encoder->m_param, &stats, padx, pady, argc, argv); ++ PARAM_NS::x265_csvlog_encode(encoder->m_param, &stats, padx, pady, argc, argv); + } + } + +@@ -872,7 +872,7 @@ void x265_alloc_analysis_data(x265_param + return; + + fail: +- x265_free_analysis_data(param, analysis); ++ PARAM_NS::x265_free_analysis_data(param, analysis); + } + + void x265_free_analysis_data(x265_param *param, x265_analysis_data* analysis) +Index: source/encoder/encoder.cpp +=================================================================== +--- source.orig/encoder/encoder.cpp ++++ source/encoder/encoder.cpp +@@ -186,8 +186,8 @@ void Encoder::create() + { + m_dupBuffer[i] = (AdaptiveFrameDuplication*)x265_malloc(sizeof(AdaptiveFrameDuplication)); + m_dupBuffer[i]->dupPic = NULL; +- m_dupBuffer[i]->dupPic = x265_picture_alloc(); +- x265_picture_init(p, m_dupBuffer[i]->dupPic); ++ m_dupBuffer[i]->dupPic = PARAM_NS::x265_picture_alloc(); ++ PARAM_NS::x265_picture_init(p, m_dupBuffer[i]->dupPic); + m_dupBuffer[i]->dupPlane = NULL; + m_dupBuffer[i]->dupPlane = X265_MALLOC(char, framesize); + m_dupBuffer[i]->dupPic->planes[0] = m_dupBuffer[i]->dupPlane; +@@ -756,7 +756,7 @@ int Encoder::setAnalysisData(x265_analys + curFrame->m_analysisData = (*analysis_data); + curFrame->m_analysisData.numCUsInFrame = widthInCU * heightInCU; + curFrame->m_analysisData.numPartitions = m_param->num4x4Partitions; +- x265_alloc_analysis_data(m_param, &curFrame->m_analysisData); ++ PARAM_NS::x265_alloc_analysis_data(m_param, &curFrame->m_analysisData); + if (m_param->maxCUSize == 16) + { + if (analysis_data->sliceType == X265_TYPE_IDR || analysis_data->sliceType == X265_TYPE_I) +@@ -860,7 +860,7 @@ void Encoder::destroy() + for (uint32_t i = 0; i < DUP_BUFFER; i++) + { + X265_FREE(m_dupBuffer[i]->dupPlane); +- x265_picture_free(m_dupBuffer[i]->dupPic); ++ PARAM_NS::x265_picture_free(m_dupBuffer[i]->dupPic); + X265_FREE(m_dupBuffer[i]); + } + +@@ -1592,7 +1592,7 @@ int Encoder::encode(const x265_picture* + if (m_exportedPic) + { + if (!m_param->bUseAnalysisFile && m_param->analysisSave) +- x265_free_analysis_data(m_param, &m_exportedPic->m_analysisData); ++ PARAM_NS::x265_free_analysis_data(m_param, &m_exportedPic->m_analysisData); + ATOMIC_DEC(&m_exportedPic->m_countRefEncoders); + m_exportedPic = NULL; + m_dpb->recycleUnreferenced(); +@@ -1968,7 +1968,7 @@ int Encoder::encode(const x265_picture* + + /* Free up inputPic->analysisData since it has already been used */ + if ((m_param->analysisLoad && !m_param->analysisSave) || ((m_param->bAnalysisType == AVC_INFO) && slice->m_sliceType != I_SLICE)) +- x265_free_analysis_data(m_param, &outFrame->m_analysisData); ++ PARAM_NS::x265_free_analysis_data(m_param, &outFrame->m_analysisData); + + if (pic_out) + { +@@ -2046,7 +2046,7 @@ int Encoder::encode(const x265_picture* + writeAnalysisFile(&pic_out->analysisData, *outFrame->m_encData); + pic_out->analysisData.saveParam = pic_out->analysisData.saveParam; + if (m_param->bUseAnalysisFile) +- x265_free_analysis_data(m_param, &pic_out->analysisData); ++ PARAM_NS::x265_free_analysis_data(m_param, &pic_out->analysisData); + } + } + if (m_param->rc.bStatWrite && (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion)) +@@ -2061,7 +2061,7 @@ int Encoder::encode(const x265_picture* + writeAnalysisFileRefine(&outFrame->m_analysisData, *outFrame->m_encData); + } + if (m_param->analysisMultiPassRefine || m_param->analysisMultiPassDistortion) +- x265_free_analysis_data(m_param, &outFrame->m_analysisData); ++ PARAM_NS::x265_free_analysis_data(m_param, &outFrame->m_analysisData); + if (m_param->internalCsp == X265_CSP_I400) + { + if (slice->m_sliceType == P_SLICE) +@@ -2199,7 +2199,7 @@ int Encoder::encode(const x265_picture* + uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize; + frameEnc->m_analysisData.numCUsInFrame = widthInCU * heightInCU; + frameEnc->m_analysisData.numPartitions = m_param->num4x4Partitions; +- x265_alloc_analysis_data(m_param, &frameEnc->m_analysisData); ++ PARAM_NS::x265_alloc_analysis_data(m_param, &frameEnc->m_analysisData); + frameEnc->m_analysisData.poc = frameEnc->m_poc; + if (m_param->rc.bStatRead) + readAnalysisFile(&frameEnc->m_analysisData, frameEnc->m_poc, frameEnc->m_lowres.sliceType); +@@ -2210,7 +2210,7 @@ int Encoder::encode(const x265_picture* + for (int i = 0; i < m_param->rc.zonefileCount; i++) + { + if (m_param->rc.zones[i].startFrame == frameEnc->m_poc) +- x265_encoder_reconfig(this, m_param->rc.zones[i].zoneParam); ++ PARAM_NS::x265_encoder_reconfig(this, m_param->rc.zones[i].zoneParam); + } + } + +@@ -2353,7 +2353,7 @@ int Encoder::encode(const x265_picture* + analysis->numCUsInFrame = numCUsInFrame; + analysis->numCuInHeight = heightInCU; + analysis->numPartitions = m_param->num4x4Partitions; +- x265_alloc_analysis_data(m_param, analysis); ++ PARAM_NS::x265_alloc_analysis_data(m_param, analysis); + } + /* determine references, setup RPS, etc */ + m_dpb->prepareEncode(frameEnc); +@@ -4264,7 +4264,7 @@ void Encoder::readAnalysisFile(x265_anal + else if (fread(val, size, readSize, fileOffset) != readSize)\ + {\ + x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\ +- x265_free_analysis_data(m_param, analysis);\ ++ PARAM_NS::x265_free_analysis_data(m_param, analysis);\ + m_aborted = true;\ + return;\ + }\ +@@ -4300,7 +4300,7 @@ void Encoder::readAnalysisFile(x265_anal + if (poc != curPoc || feof(m_analysisFileIn)) + { + x265_log(NULL, X265_LOG_WARNING, "Error reading analysis data: Cannot find POC %d\n", curPoc); +- x265_free_analysis_data(m_param, analysis); ++ PARAM_NS::x265_free_analysis_data(m_param, analysis); + return; + } + } +@@ -4334,7 +4334,7 @@ void Encoder::readAnalysisFile(x265_anal + if (m_param->scaleFactor) + analysis->numPartitions *= factor; + /* Memory is allocated for inter and intra analysis data based on the slicetype */ +- x265_alloc_analysis_data(m_param, analysis); ++ PARAM_NS::x265_alloc_analysis_data(m_param, analysis); + + if (m_param->ctuDistortionRefine == CTU_DISTORTION_INTERNAL) + { +@@ -4587,7 +4587,7 @@ void Encoder::readAnalysisFile(x265_anal + else if (fread(val, size, readSize, fileOffset) != readSize)\ + {\ + x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\ +- x265_free_analysis_data(m_param, analysis);\ ++ PARAM_NS::x265_free_analysis_data(m_param, analysis);\ + m_aborted = true;\ + return;\ + }\ +@@ -4624,7 +4624,7 @@ void Encoder::readAnalysisFile(x265_anal + if (poc != curPoc || feof(m_analysisFileIn)) + { + x265_log(NULL, X265_LOG_WARNING, "Error reading analysis data: Cannot find POC %d\n", curPoc); +- x265_free_analysis_data(m_param, analysis); ++ PARAM_NS::x265_free_analysis_data(m_param, analysis); + return; + } + } +@@ -4655,7 +4655,7 @@ void Encoder::readAnalysisFile(x265_anal + analysis->numCuInHeight = cuLoc.heightInCU; + + /* Memory is allocated for inter and intra analysis data based on the slicetype */ +- x265_alloc_analysis_data(m_param, analysis); ++ PARAM_NS::x265_alloc_analysis_data(m_param, analysis); + + if (m_param->ctuDistortionRefine == CTU_DISTORTION_INTERNAL) + { +@@ -5257,7 +5257,7 @@ void Encoder::readAnalysisFile(x265_anal + if (fread(val, size, readSize, fileOffset) != readSize)\ + {\ + x265_log(NULL, X265_LOG_ERROR, "Error reading analysis 2 pass data\n"); \ +- x265_alloc_analysis_data(m_param, analysis); \ ++ PARAM_NS::x265_alloc_analysis_data(m_param, analysis); \ + m_aborted = true; \ + return; \ + }\ +@@ -5271,7 +5271,7 @@ void Encoder::readAnalysisFile(x265_anal + if (poc != curPoc || feof(m_analysisFileIn)) + { + x265_log(NULL, X265_LOG_WARNING, "Error reading analysis 2 pass data: Cannot find POC %d\n", curPoc); +- x265_free_analysis_data(m_param, analysis); ++ PARAM_NS::x265_free_analysis_data(m_param, analysis); + return; + } + /* Now arrived at the right frame, read the record */ +@@ -5378,7 +5378,7 @@ void Encoder::writeAnalysisFile(x265_ana + if (fwrite(val, size, writeSize, fileOffset) < writeSize)\ + {\ + x265_log(NULL, X265_LOG_ERROR, "Error writing analysis data\n");\ +- x265_free_analysis_data(m_param, analysis);\ ++ PARAM_NS::x265_free_analysis_data(m_param, analysis);\ + m_aborted = true;\ + return;\ + }\ +@@ -5600,7 +5600,7 @@ void Encoder::writeAnalysisFileRefine(x2 + if (fwrite(val, size, writeSize, fileOffset) < writeSize)\ + {\ + x265_log(NULL, X265_LOG_ERROR, "Error writing analysis 2 pass data\n"); \ +- x265_free_analysis_data(m_param, analysis); \ ++ PARAM_NS::x265_free_analysis_data(m_param, analysis); \ + m_aborted = true; \ + return; \ + }\ +Index: source/common/param.cpp +=================================================================== +--- source.orig/common/param.cpp ++++ source/common/param.cpp +@@ -102,7 +102,7 @@ x265_param *x265_param_alloc() + + void x265_param_free(x265_param* p) + { +- x265_zone_free(p); ++ PARAM_NS::x265_zone_free(p); + #ifdef SVT_HEVC + x265_free(p->svtHevcParam); + #endif diff --git a/media-libs/x265/files/tests.patch b/media-libs/x265/files/tests.patch new file mode 100644 index 0000000..6c85829 --- /dev/null +++ b/media-libs/x265/files/tests.patch @@ -0,0 +1,16 @@ +Tests run against static library (upstream build system): +We build main as both shared & static, main10 & 12 are static only and linked into main. +All need PLATFORM_LIBS, so instruct cmake to also link them. + +Index: source/CMakeLists.txt +=================================================================== +--- source.orig/CMakeLists.txt ++++ source/CMakeLists.txt +@@ -578,6 +578,7 @@ endif() + if(SVTHEVC_FOUND) + target_link_libraries(x265-static ${SVT_HEVC_LIBRARY}) + endif() ++target_link_libraries(x265-static ${PLATFORM_LIBS}) + install(TARGETS x265-static + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) diff --git a/media-libs/x265/files/x265-3.3-ppc64.patch b/media-libs/x265/files/x265-3.3-ppc64.patch new file mode 100644 index 0000000..8e739e3 --- /dev/null +++ b/media-libs/x265/files/x265-3.3-ppc64.patch @@ -0,0 +1,15 @@ +More complete ppc64 matches. + +Index: x265_2.2/source/CMakeLists.txt +=================================================================== +--- old/CMakeLists.txt ++++ new/CMakeLists.txt +@@ -44,7 +44,7 @@ set(X86_ALIASES x86 i386 i686 x86_64 amd + set(ARM_ALIASES armv6l armv6j armv7l armv7a) + list(FIND X86_ALIASES "${SYSPROC}" X86MATCH) + list(FIND ARM_ALIASES "${SYSPROC}" ARMMATCH) +-set(POWER_ALIASES ppc64 ppc64le) ++set(POWER_ALIASES ppc64 ppc64le powerpc64 powerpc64le) + list(FIND POWER_ALIASES "${SYSPROC}" POWERMATCH) + if("${SYSPROC}" STREQUAL "" OR X86MATCH GREATER "-1") + set(X86 1) diff --git a/media-libs/x265/metadata.xml b/media-libs/x265/metadata.xml new file mode 100644 index 0000000..a565e32 --- /dev/null +++ b/media-libs/x265/metadata.xml @@ -0,0 +1,10 @@ + + + + + Add support for producing 10bits HEVC. + Add support for producing 12bits HEVC. + Build with support for NUMA nodes. + Disable optimized assembly code that is not PIC friendly + + diff --git a/media-libs/x265/x265-3.5.ebuild b/media-libs/x265/x265-3.5.ebuild new file mode 100644 index 0000000..e86af73 --- /dev/null +++ b/media-libs/x265/x265-3.5.ebuild @@ -0,0 +1,214 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +inherit cmake multilib-minimal multilib multibuild flag-o-matic + +if [[ ${PV} = 9999* ]]; then + inherit git-r3 + EGIT_REPO_URI="https://bitbucket.org/multicoreware/x265_git.git" +else + SRC_URI="https://bitbucket.org/multicoreware/x265_git/downloads/${PN}_${PV}.tar.gz" + KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~x86" +fi + +DESCRIPTION="Library for encoding video streams into the H.265/HEVC format" +HOMEPAGE="http://x265.org/ https://bitbucket.org/multicoreware/x265_git/wiki/Home" + +LICENSE="GPL-2" +# subslot = libx265 soname +SLOT="0/199" +IUSE="+10bit +12bit cpu_flags_arm_neon cpu_flags_ppc_vsx2 numa pic test" +RESTRICT="!test? ( test )" + +RDEPEND="numa? ( >=sys-process/numactl-2.0.10-r1[${MULTILIB_USEDEP}] )" +DEPEND="${RDEPEND}" +ASM_DEPEND=">=dev-lang/nasm-2.13" +BDEPEND=" + abi_x86_32? ( ${ASM_DEPEND} ) + abi_x86_64? ( ${ASM_DEPEND} )" + +PATCHES=( + "${FILESDIR}/arm-r1.patch" + "${FILESDIR}/neon.patch" + "${FILESDIR}/x265-3.3-ppc64.patch" + "${FILESDIR}/tests.patch" + "${FILESDIR}/test-ns.patch" +) + +if [[ ${PV} = 9999* ]]; then + S=${WORKDIR}/${PN}/source +else + S=${WORKDIR}/${PN}_${PV}/source +fi + +# By default, the library and the encoder is configured for only one output bit +# depth. Meaning, one has to rebuild libx265 if (s)he wants to produce HEVC +# files with a different bit depth, which is annoying. However, upstream +# supports proper namespacing for 8bits, 10bits & 12bits HEVC and linking all +# that together so that the resulting library can produce all three of them +# instead of only one. +# The API requires the bit depth parameter, so that libx265 can then chose which +# variant of the encoder to use. +# To achieve this, we have to build one (static) library for each non-main +# variant, and link it into the main library. +# Upstream documents using the 8bit variant as main library, hence we do not +# allow disabling it: "main" *MUST* come last in the following list. + +x265_get_variants() { + local variants="" + use 12bit && variants+="main12 " + use 10bit && variants+="main10 " + variants+="main" + echo "${variants}" +} + +x265_variant_src_configure() { + mkdir -p "${BUILD_DIR}" || die + pushd "${BUILD_DIR}" >/dev/null || die + + einfo "Configuring variant: ${MULTIBUILD_VARIANT} for ABI: ${ABI}" + + local mycmakeargs=( "${myabicmakeargs[@]}" ) + case "${MULTIBUILD_VARIANT}" in + "main12") + mycmakeargs+=( + -DHIGH_BIT_DEPTH=ON + -DEXPORT_C_API=OFF + -DENABLE_SHARED=OFF + -DENABLE_CLI=OFF + -DMAIN12=ON + ) + if [[ ${ABI} = x86 ]] ; then + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + if [[ ${ABI} = arm* ]] ; then + # 589674 + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + # disable altivec for 12bit build #607802#c5 + if [[ ${ABI} = ppc* ]] ; then + mycmakeargs+=( + -DENABLE_ALTIVEC=OFF + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + ;; + "main10") + mycmakeargs+=( + -DHIGH_BIT_DEPTH=ON + -DEXPORT_C_API=OFF + -DENABLE_SHARED=OFF + -DENABLE_CLI=OFF + ) + if [[ ${ABI} = x86 ]] ; then + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + if [[ ${ABI} = arm* ]] ; then + # 589674 + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + # disable altivec for 10bit build #607802#c5 + if [[ ${ABI} = ppc* ]] ; then + mycmakeargs+=( + -DENABLE_ALTIVEC=OFF + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + ;; + "main") + if (( "${#MULTIBUILD_VARIANTS[@]}" > 1 )) ; then + local myvariants=( "${MULTIBUILD_VARIANTS[@]}" ) + unset myvariants[${#MULTIBUILD_VARIANTS[@]}-1] + local liblist="" v= + for v in "${myvariants[@]}" ; do + ln -s "${BUILD_DIR%-*}-${v}/libx265.a" "libx265_${v}.a" || die + liblist+="libx265_${v}.a;" + done + mycmakeargs+=( + -DEXTRA_LIB="${liblist}" + -DEXTRA_LINK_FLAGS=-L. + -DLINKED_10BIT=$(usex 10bit) + -DLINKED_12BIT=$(usex 12bit) + ) + if [[ ${ABI} = ppc* ]] ; then + # upstream uses mix of altivec + power8 vectors + # it's impossible to enable altivec without CPU_POWER8 + # and it does not work on ppc32 + # so we toggle both variables together + mycmakeargs+=( + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + -DENABLE_ALTIVEC=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + fi + ;; + *) + die "Unknown variant: ${MULTIBUILD_VARIANT}";; + esac + cmake_src_configure + popd >/dev/null || die +} + +multilib_src_configure() { + local myabicmakeargs=( + -DENABLE_TESTS=$(usex test ON OFF) + $(multilib_is_native_abi || echo "-DENABLE_CLI=OFF") + -DENABLE_PIC=ON + -DENABLE_LIBNUMA=$(usex numa ON OFF) + -DLIB_INSTALL_DIR="$(get_libdir)" + ) + + if [[ ${ABI} = x86 ]] ; then + # Bug #528202 + if use pic ; then + ewarn "PIC has been requested but x86 asm is not PIC-safe, disabling it." + myabicmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + elif [[ ${ABI} = x32 ]] ; then + # bug #510890 + myabicmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + elif [[ ${ABI} = arm ]] ; then + myabicmakeargs+=( -DENABLE_ASSEMBLY=$(usex pic OFF $(usex cpu_flags_arm_neon ON OFF)) ) + use cpu_flags_arm_neon && use pic && ewarn "PIC has been requested but arm neon asm is not PIC-safe, disabling it." + fi + + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant x265_variant_src_configure +} + +multilib_src_compile() { + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant cmake_src_compile +} + +x265_variant_src_test() { + if [ -x "${BUILD_DIR}/test/TestBench" ] ; then + "${BUILD_DIR}/test/TestBench" || die + else + einfo "Unit tests check only assembly." + einfo "You do not seem to have any for ABI=${ABI}, x265 variant=${MULTIBUILD_VARIANT}" + einfo "Skipping tests." + fi +} + +multilib_src_test() { + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant x265_variant_src_test +} + +multilib_src_install() { + # Install only "main" variant since the others are already linked into it. + local MULTIBUILD_VARIANTS=( "main" ) + multibuild_foreach_variant cmake_src_install +} + +multilib_src_install_all() { + dodoc -r "${S}/../doc/"* + + # we don't install *.a files for all variants, + # so just delete these files instead of pretending + # real USE=static-libs support + find "${ED}" -name "*.a" -delete || die +} diff --git a/media-libs/x265/x265-9999.ebuild b/media-libs/x265/x265-9999.ebuild new file mode 100644 index 0000000..e86af73 --- /dev/null +++ b/media-libs/x265/x265-9999.ebuild @@ -0,0 +1,214 @@ +# Copyright 1999-2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +inherit cmake multilib-minimal multilib multibuild flag-o-matic + +if [[ ${PV} = 9999* ]]; then + inherit git-r3 + EGIT_REPO_URI="https://bitbucket.org/multicoreware/x265_git.git" +else + SRC_URI="https://bitbucket.org/multicoreware/x265_git/downloads/${PN}_${PV}.tar.gz" + KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~x86" +fi + +DESCRIPTION="Library for encoding video streams into the H.265/HEVC format" +HOMEPAGE="http://x265.org/ https://bitbucket.org/multicoreware/x265_git/wiki/Home" + +LICENSE="GPL-2" +# subslot = libx265 soname +SLOT="0/199" +IUSE="+10bit +12bit cpu_flags_arm_neon cpu_flags_ppc_vsx2 numa pic test" +RESTRICT="!test? ( test )" + +RDEPEND="numa? ( >=sys-process/numactl-2.0.10-r1[${MULTILIB_USEDEP}] )" +DEPEND="${RDEPEND}" +ASM_DEPEND=">=dev-lang/nasm-2.13" +BDEPEND=" + abi_x86_32? ( ${ASM_DEPEND} ) + abi_x86_64? ( ${ASM_DEPEND} )" + +PATCHES=( + "${FILESDIR}/arm-r1.patch" + "${FILESDIR}/neon.patch" + "${FILESDIR}/x265-3.3-ppc64.patch" + "${FILESDIR}/tests.patch" + "${FILESDIR}/test-ns.patch" +) + +if [[ ${PV} = 9999* ]]; then + S=${WORKDIR}/${PN}/source +else + S=${WORKDIR}/${PN}_${PV}/source +fi + +# By default, the library and the encoder is configured for only one output bit +# depth. Meaning, one has to rebuild libx265 if (s)he wants to produce HEVC +# files with a different bit depth, which is annoying. However, upstream +# supports proper namespacing for 8bits, 10bits & 12bits HEVC and linking all +# that together so that the resulting library can produce all three of them +# instead of only one. +# The API requires the bit depth parameter, so that libx265 can then chose which +# variant of the encoder to use. +# To achieve this, we have to build one (static) library for each non-main +# variant, and link it into the main library. +# Upstream documents using the 8bit variant as main library, hence we do not +# allow disabling it: "main" *MUST* come last in the following list. + +x265_get_variants() { + local variants="" + use 12bit && variants+="main12 " + use 10bit && variants+="main10 " + variants+="main" + echo "${variants}" +} + +x265_variant_src_configure() { + mkdir -p "${BUILD_DIR}" || die + pushd "${BUILD_DIR}" >/dev/null || die + + einfo "Configuring variant: ${MULTIBUILD_VARIANT} for ABI: ${ABI}" + + local mycmakeargs=( "${myabicmakeargs[@]}" ) + case "${MULTIBUILD_VARIANT}" in + "main12") + mycmakeargs+=( + -DHIGH_BIT_DEPTH=ON + -DEXPORT_C_API=OFF + -DENABLE_SHARED=OFF + -DENABLE_CLI=OFF + -DMAIN12=ON + ) + if [[ ${ABI} = x86 ]] ; then + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + if [[ ${ABI} = arm* ]] ; then + # 589674 + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + # disable altivec for 12bit build #607802#c5 + if [[ ${ABI} = ppc* ]] ; then + mycmakeargs+=( + -DENABLE_ALTIVEC=OFF + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + ;; + "main10") + mycmakeargs+=( + -DHIGH_BIT_DEPTH=ON + -DEXPORT_C_API=OFF + -DENABLE_SHARED=OFF + -DENABLE_CLI=OFF + ) + if [[ ${ABI} = x86 ]] ; then + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + if [[ ${ABI} = arm* ]] ; then + # 589674 + mycmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + # disable altivec for 10bit build #607802#c5 + if [[ ${ABI} = ppc* ]] ; then + mycmakeargs+=( + -DENABLE_ALTIVEC=OFF + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + ;; + "main") + if (( "${#MULTIBUILD_VARIANTS[@]}" > 1 )) ; then + local myvariants=( "${MULTIBUILD_VARIANTS[@]}" ) + unset myvariants[${#MULTIBUILD_VARIANTS[@]}-1] + local liblist="" v= + for v in "${myvariants[@]}" ; do + ln -s "${BUILD_DIR%-*}-${v}/libx265.a" "libx265_${v}.a" || die + liblist+="libx265_${v}.a;" + done + mycmakeargs+=( + -DEXTRA_LIB="${liblist}" + -DEXTRA_LINK_FLAGS=-L. + -DLINKED_10BIT=$(usex 10bit) + -DLINKED_12BIT=$(usex 12bit) + ) + if [[ ${ABI} = ppc* ]] ; then + # upstream uses mix of altivec + power8 vectors + # it's impossible to enable altivec without CPU_POWER8 + # and it does not work on ppc32 + # so we toggle both variables together + mycmakeargs+=( + -DCPU_POWER8=$(usex cpu_flags_ppc_vsx2 ON OFF) + -DENABLE_ALTIVEC=$(usex cpu_flags_ppc_vsx2 ON OFF) + ) + fi + fi + ;; + *) + die "Unknown variant: ${MULTIBUILD_VARIANT}";; + esac + cmake_src_configure + popd >/dev/null || die +} + +multilib_src_configure() { + local myabicmakeargs=( + -DENABLE_TESTS=$(usex test ON OFF) + $(multilib_is_native_abi || echo "-DENABLE_CLI=OFF") + -DENABLE_PIC=ON + -DENABLE_LIBNUMA=$(usex numa ON OFF) + -DLIB_INSTALL_DIR="$(get_libdir)" + ) + + if [[ ${ABI} = x86 ]] ; then + # Bug #528202 + if use pic ; then + ewarn "PIC has been requested but x86 asm is not PIC-safe, disabling it." + myabicmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + fi + elif [[ ${ABI} = x32 ]] ; then + # bug #510890 + myabicmakeargs+=( -DENABLE_ASSEMBLY=OFF ) + elif [[ ${ABI} = arm ]] ; then + myabicmakeargs+=( -DENABLE_ASSEMBLY=$(usex pic OFF $(usex cpu_flags_arm_neon ON OFF)) ) + use cpu_flags_arm_neon && use pic && ewarn "PIC has been requested but arm neon asm is not PIC-safe, disabling it." + fi + + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant x265_variant_src_configure +} + +multilib_src_compile() { + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant cmake_src_compile +} + +x265_variant_src_test() { + if [ -x "${BUILD_DIR}/test/TestBench" ] ; then + "${BUILD_DIR}/test/TestBench" || die + else + einfo "Unit tests check only assembly." + einfo "You do not seem to have any for ABI=${ABI}, x265 variant=${MULTIBUILD_VARIANT}" + einfo "Skipping tests." + fi +} + +multilib_src_test() { + local MULTIBUILD_VARIANTS=( $(x265_get_variants) ) + multibuild_foreach_variant x265_variant_src_test +} + +multilib_src_install() { + # Install only "main" variant since the others are already linked into it. + local MULTIBUILD_VARIANTS=( "main" ) + multibuild_foreach_variant cmake_src_install +} + +multilib_src_install_all() { + dodoc -r "${S}/../doc/"* + + # we don't install *.a files for all variants, + # so just delete these files instead of pretending + # real USE=static-libs support + find "${ED}" -name "*.a" -delete || die +} -- cgit v1.2.3-54-g00ecf